@composio/core 0.1.51 → 0.1.52

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 CHANGED
@@ -288,6 +288,7 @@ Composio supports various authentication schemes:
288
288
  - `COMPOSIO_BASE_URL`: Custom API base URL
289
289
  - `COMPOSIO_LOGGING_LEVEL`: Logging level (silent, error, warn, info, debug)
290
290
  - `DEVELOPMENT`: Development mode flag
291
+ - `COMPOSIO_TOOLKIT_VERSION_<TOOLKITNAME>`: Version of the specific tool
291
292
  - `CI`: CI environment flag
292
293
 
293
294
  ## Contributing
package/dist/index.cjs CHANGED
@@ -849,10 +849,11 @@ var ToolSchema = import_zod3.z.object({
849
849
  description: import_zod3.z.string().optional().describe("The description of the tool"),
850
850
  inputParameters: ParametersSchema.optional().describe("The input parameters of the tool"),
851
851
  outputParameters: ParametersSchema.optional().describe("The output parameters of the tool"),
852
- tags: import_zod3.z.optional(import_zod3.z.array(import_zod3.z.string())).describe("The tags of the tool. eg: Important").default([]),
853
- toolkit: import_zod3.z.optional(ToolkitSchema).describe("The toolkit of the tool"),
854
- version: import_zod3.z.optional(import_zod3.z.string()).describe('The version of the tool, e.g. "1.0.0"'),
855
- scopes: import_zod3.z.optional(import_zod3.z.array(import_zod3.z.string())).describe('The scopes of the tool. eg: ["task:add"]')
852
+ tags: import_zod3.z.array(import_zod3.z.string()).describe("The tags of the tool. eg: Important").default([]).optional(),
853
+ toolkit: ToolkitSchema.describe("The toolkit of the tool").optional(),
854
+ version: import_zod3.z.string().describe('The version of the tool, e.g. "20250909_00"').optional(),
855
+ availableVersions: import_zod3.z.array(import_zod3.z.string()).describe("Available versions of the tool.").default([]).optional(),
856
+ scopes: import_zod3.z.array(import_zod3.z.string()).describe('The scopes of the tool. eg: ["task:add"]').optional()
856
857
  });
857
858
  var ToolListResponseSchema = import_zod3.z.object({
858
859
  items: import_zod3.z.array(ToolSchema),
@@ -886,8 +887,8 @@ var ToolExecuteParamsSchema = import_zod3.z.object({
886
887
  customConnectionData: CustomConnectionDataSchema.optional(),
887
888
  arguments: import_zod3.z.record(import_zod3.z.string(), import_zod3.z.unknown()).optional(),
888
889
  userId: import_zod3.z.string().optional(),
889
- //
890
- version: import_zod3.z.string().optional(),
890
+ // we have no auth apps which can be execute
891
+ version: import_zod3.z.union([import_zod3.z.literal("latest"), import_zod3.z.string()]).optional(),
891
892
  text: import_zod3.z.string().optional()
892
893
  });
893
894
  var ToolExecuteResponseSchema = import_zod3.z.object({
@@ -940,6 +941,19 @@ var getEnvVariable = (name, defaultValue = void 0) => {
940
941
  return defaultValue;
941
942
  }
942
943
  };
944
+ var getEnvsWithPrefix = (prefix) => {
945
+ try {
946
+ if (process && process.env) {
947
+ return Object.fromEntries(
948
+ Object.entries(process.env).filter(([key]) => key.startsWith(prefix))
949
+ );
950
+ } else {
951
+ return {};
952
+ }
953
+ } catch (error) {
954
+ return {};
955
+ }
956
+ };
943
957
 
944
958
  // src/utils/constants.ts
945
959
  var COMPOSIO_DIR = ".composio";
@@ -2679,13 +2693,26 @@ var FileToolModifier = class {
2679
2693
  }
2680
2694
  };
2681
2695
 
2696
+ // src/utils/toolkitVersion.ts
2697
+ var getToolkitVersion = (toolkitSlug, toolkitVersions) => {
2698
+ if (typeof toolkitVersions === "string") {
2699
+ return toolkitVersions;
2700
+ }
2701
+ const hasToolkitVersion = toolkitVersions && Object.keys(toolkitVersions).length > 0;
2702
+ if (hasToolkitVersion) {
2703
+ return toolkitVersions[toolkitSlug] ?? "latest";
2704
+ }
2705
+ return "latest";
2706
+ };
2707
+
2682
2708
  // src/models/Tools.ts
2683
2709
  var Tools = class {
2684
2710
  client;
2685
2711
  customTools;
2686
2712
  provider;
2687
2713
  autoUploadDownloadFiles;
2688
- constructor(client, provider, options) {
2714
+ toolkitVersions;
2715
+ constructor(client, provider, config) {
2689
2716
  if (!client) {
2690
2717
  throw new Error("ComposioClient is required");
2691
2718
  }
@@ -2695,7 +2722,8 @@ var Tools = class {
2695
2722
  this.client = client;
2696
2723
  this.customTools = new CustomTools(client);
2697
2724
  this.provider = provider;
2698
- this.autoUploadDownloadFiles = options?.autoUploadDownloadFiles ?? true;
2725
+ this.autoUploadDownloadFiles = config?.autoUploadDownloadFiles ?? true;
2726
+ this.toolkitVersions = config?.toolkitVersions ?? "latest";
2699
2727
  this.execute = this.execute.bind(this);
2700
2728
  this.provider._setExecuteToolFn(this.execute);
2701
2729
  this.getRawComposioToolBySlug = this.getRawComposioToolBySlug.bind(this);
@@ -2717,7 +2745,8 @@ var Tools = class {
2717
2745
  return ToolSchema.parse({
2718
2746
  ...tool,
2719
2747
  inputParameters: tool.input_parameters,
2720
- outputParameters: tool.output_parameters
2748
+ outputParameters: tool.output_parameters,
2749
+ availableVersions: tool.available_versions
2721
2750
  });
2722
2751
  }
2723
2752
  /**
@@ -2740,46 +2769,6 @@ var Tools = class {
2740
2769
  sessionInfo: response.session_info
2741
2770
  });
2742
2771
  }
2743
- /**
2744
- * Check if the connected account exists for the given tools.
2745
- * @param {string} userId - The user id.
2746
- * @param {ToolList} tools - The tools to check.
2747
- * @returns {Promise<boolean>} True if the connected account exists for the given tools, false otherwise.
2748
- */
2749
- async checkIfConnectedAccountExistsForTools(userIds, tools) {
2750
- if (!tools.length) {
2751
- return true;
2752
- }
2753
- const connectedAccounts = await this.client.connectedAccounts.list({
2754
- user_ids: userIds
2755
- });
2756
- if (connectedAccounts.items.length === 0) {
2757
- return false;
2758
- }
2759
- const connectedToolkitSlugs = connectedAccounts.items.reduce(
2760
- (acc, account) => {
2761
- if (account.toolkit.slug) {
2762
- acc[account.toolkit.slug] = true;
2763
- }
2764
- return acc;
2765
- },
2766
- {}
2767
- );
2768
- const toolSlugs = tools.reduce(
2769
- (acc, tool) => {
2770
- acc[tool.slug] = true;
2771
- return acc;
2772
- },
2773
- {}
2774
- );
2775
- for (const tool of Object.keys(toolSlugs)) {
2776
- if (!connectedToolkitSlugs[tool]) {
2777
- logger_default.warn(`Tool ${tool} requires a connected account but no connected account was found`);
2778
- return false;
2779
- }
2780
- }
2781
- return true;
2782
- }
2783
2772
  /**
2784
2773
  * Get the connected account id for a given tool
2785
2774
  * @param {string} userId - The user id
@@ -2905,32 +2894,59 @@ var Tools = class {
2905
2894
  *
2906
2895
  * This method fetches tools from the Composio API in raw format and combines them with
2907
2896
  * any registered custom tools. The response can be filtered and modified as needed.
2897
+ * It provides access to the underlying tool data without provider-specific wrapping.
2908
2898
  *
2909
- * @param {ToolListParams} [query={}] - Optional query parameters to filter the tools
2910
- * @param {TransformToolSchemaModifier} [modifier] - Optional function to transform tool schemas
2899
+ * @param {ToolListParams} query - Query parameters to filter the tools (required)
2900
+ * @param {GetRawComposioToolsOptions} [options] - Optional configuration for tool retrieval
2901
+ * @param {TransformToolSchemaModifier} [options.modifySchema] - Function to transform tool schemas
2911
2902
  * @returns {Promise<ToolList>} List of tools matching the query criteria
2912
2903
  *
2913
2904
  * @example
2914
2905
  * ```typescript
2915
- * // Get all tools
2916
- * const tools = await composio.tools.getRawComposioTools();
2906
+ * // Get tools from specific toolkits
2907
+ * const githubTools = await composio.tools.getRawComposioTools({
2908
+ * toolkits: ['github'],
2909
+ * limit: 10
2910
+ * });
2917
2911
  *
2918
- * // Get tools with filters
2912
+ * // Get specific tools by slug
2913
+ * const specificTools = await composio.tools.getRawComposioTools({
2914
+ * tools: ['GITHUB_GET_REPOS', 'HACKERNEWS_GET_USER']
2915
+ * });
2916
+ *
2917
+ * // Get tools from specific toolkits
2919
2918
  * const githubTools = await composio.tools.getRawComposioTools({
2920
2919
  * toolkits: ['github'],
2921
2920
  * limit: 10
2922
2921
  * });
2923
2922
  *
2924
2923
  * // Get tools with schema transformation
2925
- * const tools = await composio.tools.getRawComposioTools({},
2926
- * (toolSlug, toolkitSlug, tool) => {
2924
+ * const customizedTools = await composio.tools.getRawComposioTools({
2925
+ * toolkits: ['github'],
2926
+ * limit: 5
2927
+ * }, {
2928
+ * modifySchema: ({ toolSlug, toolkitSlug, schema }) => {
2927
2929
  * // Add custom properties to tool schema
2928
- * return {...tool, customProperty: 'value'};
2930
+ * return {
2931
+ * ...schema,
2932
+ * customProperty: `Modified ${toolSlug} from ${toolkitSlug}`,
2933
+ * tags: [...(schema.tags || []), 'customized']
2934
+ * };
2929
2935
  * }
2930
- * );
2936
+ * });
2937
+ *
2938
+ * // Search for tools
2939
+ * const searchResults = await composio.tools.getRawComposioTools({
2940
+ * search: 'user management'
2941
+ * });
2942
+ *
2943
+ * // Get tools by authentication config
2944
+ * const authSpecificTools = await composio.tools.getRawComposioTools({
2945
+ * authConfigIds: ['auth_config_123']
2946
+ * });
2931
2947
  * ```
2932
2948
  */
2933
- async getRawComposioTools(query, modifier) {
2949
+ async getRawComposioTools(query, options) {
2934
2950
  if ("tools" in query && "toolkits" in query) {
2935
2951
  throw new ValidationError(
2936
2952
  "Invalid tool list parameters. You should not use tools and toolkits filter together."
@@ -2958,7 +2974,8 @@ var Tools = class {
2958
2974
  ..."tags" in queryParams.data ? { tags: queryParams.data.tags } : {},
2959
2975
  ..."scopes" in queryParams.data ? { scopes: queryParams.data.scopes } : {},
2960
2976
  ..."search" in queryParams.data ? { search: queryParams.data.search } : {},
2961
- ..."authConfigIds" in queryParams.data ? { auth_config_ids: queryParams.data.authConfigIds } : {}
2977
+ ..."authConfigIds" in queryParams.data ? { auth_config_ids: queryParams.data.authConfigIds } : {},
2978
+ ...{ toolkit_versions: this.toolkitVersions }
2962
2979
  };
2963
2980
  logger_default.debug(`Fetching tools with filters: ${JSON.stringify(filters, null, 2)}`);
2964
2981
  const tools = await this.client.tools.list(filters);
@@ -2973,7 +2990,8 @@ var Tools = class {
2973
2990
  ...caseTransformedTools,
2974
2991
  ...customTools
2975
2992
  ]);
2976
- if (modifier) {
2993
+ if (options?.modifySchema) {
2994
+ const modifier = options.modifySchema;
2977
2995
  if (typeof modifier === "function") {
2978
2996
  const modifiedPromises = modifiedTools.map(
2979
2997
  (tool) => modifier({
@@ -2990,17 +3008,56 @@ var Tools = class {
2990
3008
  return modifiedTools;
2991
3009
  }
2992
3010
  /**
2993
- * Retrieves a tool by its Slug.
2994
- * This method is used to get the raw tools from the composio API.
2995
- * @param slug The ID of the tool to be retrieved
2996
- * @returns {Promise<Tool>} The tool
3011
+ * Retrieves a specific tool by its slug from the Composio API.
3012
+ *
3013
+ * This method fetches a single tool in raw format without provider-specific wrapping,
3014
+ * providing direct access to the tool's schema and metadata. Tool versions are controlled
3015
+ * at the Composio SDK initialization level through the `toolkitVersions` configuration.
3016
+ *
3017
+ * @param {string} slug - The unique identifier of the tool (e.g., 'GITHUB_GET_REPOS')
3018
+ * @param {GetRawComposioToolBySlugOptions} [options] - Optional configuration for tool retrieval
3019
+ * @param {TransformToolSchemaModifier} [options.modifySchema] - Function to transform the tool schema
3020
+ * @returns {Promise<Tool>} The requested tool with its complete schema and metadata
2997
3021
  *
2998
3022
  * @example
2999
- * ```ts
3000
- * const tool = await composio.tools.getRawComposioToolBySlug('github');
3023
+ * ```typescript
3024
+ * // Get a tool by slug
3025
+ * const tool = await composio.tools.getRawComposioToolBySlug('GITHUB_GET_REPOS');
3026
+ * console.log(tool.name, tool.description);
3027
+ *
3028
+ * // Get a tool with schema transformation
3029
+ * const customizedTool = await composio.tools.getRawComposioToolBySlug(
3030
+ * 'SLACK_SEND_MESSAGE',
3031
+ * {
3032
+ * modifySchema: ({ toolSlug, toolkitSlug, schema }) => {
3033
+ * return {
3034
+ * ...schema,
3035
+ * description: `Enhanced ${schema.description} with custom modifications`,
3036
+ * customMetadata: {
3037
+ * lastModified: new Date().toISOString(),
3038
+ * toolkit: toolkitSlug
3039
+ * }
3040
+ * };
3041
+ * }
3042
+ * }
3043
+ * );
3044
+ *
3045
+ * // Get a custom tool (will check custom tools first)
3046
+ * const customTool = await composio.tools.getRawComposioToolBySlug('MY_CUSTOM_TOOL');
3047
+ *
3048
+ * // Access tool properties
3049
+ * const githubTool = await composio.tools.getRawComposioToolBySlug('GITHUB_CREATE_ISSUE');
3050
+ * console.log({
3051
+ * slug: githubTool.slug,
3052
+ * name: githubTool.name,
3053
+ * toolkit: githubTool.toolkit?.name,
3054
+ * version: githubTool.version,
3055
+ * availableVersions: githubTool.availableVersions,
3056
+ * inputParameters: githubTool.inputParameters
3057
+ * });
3001
3058
  * ```
3002
3059
  */
3003
- async getRawComposioToolBySlug(slug, modifier) {
3060
+ async getRawComposioToolBySlug(slug, options) {
3004
3061
  const customTool = await this.customTools.getCustomToolBySlug(slug);
3005
3062
  if (customTool) {
3006
3063
  logger_default.debug(`Found ${slug} to be a custom tool`, JSON.stringify(customTool, null, 2));
@@ -3010,14 +3067,17 @@ var Tools = class {
3010
3067
  }
3011
3068
  let tool;
3012
3069
  try {
3013
- tool = await this.client.tools.retrieve(slug);
3070
+ tool = await this.client.tools.retrieve(slug, {
3071
+ toolkit_versions: this.toolkitVersions
3072
+ });
3014
3073
  } catch (error) {
3015
3074
  throw new ComposioToolNotFoundError(`Unable to retrieve tool with slug ${slug}`, {
3016
3075
  cause: error
3017
3076
  });
3018
3077
  }
3019
3078
  let [modifiedTool] = await this.applyDefaultSchemaModifiers([this.transformToolCases(tool)]);
3020
- if (modifier) {
3079
+ if (options?.modifySchema) {
3080
+ const modifier = options.modifySchema;
3021
3081
  if (typeof modifier === "function") {
3022
3082
  modifiedTool = await modifier({
3023
3083
  toolSlug: slug,
@@ -3032,20 +3092,26 @@ var Tools = class {
3032
3092
  }
3033
3093
  /**
3034
3094
  * Get a tool or list of tools based on the provided arguments.
3035
- * This is an implementation method that handles both overloads.
3095
+ * This is an implementation method that handles all overloads.
3036
3096
  *
3037
3097
  * @param {string} userId - The user id to get the tool(s) for
3038
3098
  * @param {ToolListParams | string} arg2 - Either a slug string or filters object
3039
- * @param {ProviderOptions<TProvider>} [options] - Optional provider options
3099
+ * @param {ProviderOptions<TProvider> | ToolkitVersion} [arg3] - Optional provider options or version string
3100
+ * @param {ProviderOptions<TProvider>} [arg4] - Optional provider options (when arg3 is version)
3040
3101
  * @returns {Promise<TToolCollection>} The tool collection
3041
3102
  */
3042
- async get(userId, arg2, options) {
3103
+ async get(userId, arg2, arg3) {
3104
+ const options = arg3;
3043
3105
  const executeToolFn = this.createExecuteToolFn(userId, options);
3044
3106
  if (typeof arg2 === "string") {
3045
- const tool = await this.getRawComposioToolBySlug(arg2, options?.modifySchema);
3107
+ const tool = await this.getRawComposioToolBySlug(arg2, {
3108
+ modifySchema: options?.modifySchema
3109
+ });
3046
3110
  return this.provider.wrapTools([tool], executeToolFn);
3047
3111
  } else {
3048
- const tools = await this.getRawComposioTools(arg2, options?.modifySchema);
3112
+ const tools = await this.getRawComposioTools(arg2, {
3113
+ modifySchema: options?.modifySchema
3114
+ });
3049
3115
  return this.provider.wrapTools(tools, executeToolFn);
3050
3116
  }
3051
3117
  }
@@ -3135,7 +3201,7 @@ var Tools = class {
3135
3201
  custom_connection_data: body.customConnectionData,
3136
3202
  arguments: body.arguments,
3137
3203
  user_id: body.userId,
3138
- version: body.version,
3204
+ version: body.version ?? getToolkitVersion(tool.toolkit?.slug ?? "unknown", this.toolkitVersions),
3139
3205
  text: body.text
3140
3206
  });
3141
3207
  result = this.transformToolExecuteResponse(result);
@@ -3195,25 +3261,34 @@ var Tools = class {
3195
3261
  "CustomTools not initialized. Make sure Tools class is properly constructed."
3196
3262
  );
3197
3263
  }
3264
+ const executeParams = ToolExecuteParamsSchema.safeParse(body);
3265
+ if (!executeParams.success) {
3266
+ throw new ValidationError("Invalid tool execute parameters", { cause: executeParams.error });
3267
+ }
3198
3268
  try {
3199
3269
  const customTool = await this.customTools.getCustomToolBySlug(slug);
3200
3270
  if (customTool) {
3201
- return this.handleCustomToolExecution(customTool, body, modifiers);
3271
+ return this.handleCustomToolExecution(customTool, executeParams.data, modifiers);
3202
3272
  } else {
3203
3273
  const composioTool = await this.getRawComposioToolBySlug(slug);
3204
3274
  if (!composioTool) {
3205
- throw new ComposioToolNotFoundError(`Tool with slug ${slug} not found`);
3275
+ throw new ComposioToolNotFoundError(
3276
+ `Tool with slug ${slug} version:${executeParams.data.version} not found`
3277
+ );
3206
3278
  }
3207
- return this.handleComposioToolExecution(composioTool, body, modifiers);
3279
+ return this.handleComposioToolExecution(composioTool, executeParams.data, modifiers);
3208
3280
  }
3209
3281
  } catch (error) {
3210
- throw new ComposioToolExecutionError(`Error executing tool ${slug}`, {
3211
- originalError: error,
3212
- meta: {
3213
- toolSlug: slug,
3214
- body
3282
+ throw new ComposioToolExecutionError(
3283
+ `Error executing tool ${slug} version:${executeParams.data.version}`,
3284
+ {
3285
+ originalError: error,
3286
+ meta: {
3287
+ toolSlug: slug,
3288
+ body
3289
+ }
3215
3290
  }
3216
- });
3291
+ );
3217
3292
  }
3218
3293
  }
3219
3294
  /**
@@ -6238,6 +6313,31 @@ function getSDKConfig(baseUrl, apiKey) {
6238
6313
  logger_default.debug("Environment", `Base URL: ${baseURLParsed}`);
6239
6314
  return { baseURL: baseURLParsed, apiKey: apiKeyParsed };
6240
6315
  }
6316
+ function getToolkitVersionsFromEnv(defaultVersions) {
6317
+ if (defaultVersions && typeof defaultVersions === "string") {
6318
+ return defaultVersions;
6319
+ }
6320
+ const envPrefixedVersions = getEnvsWithPrefix(`COMPOSIO_TOOLKIT_VERSION_`);
6321
+ const toolkitVersionsFromEnv = Object.entries(envPrefixedVersions).reduce((acc, [key, value]) => {
6322
+ const toolkitName = key.replace("COMPOSIO_TOOLKIT_VERSION_", "");
6323
+ acc[toolkitName.toLowerCase()] = value;
6324
+ return acc;
6325
+ }, {});
6326
+ let userProvidedToolkitVersions = {};
6327
+ if (defaultVersions && typeof defaultVersions === "object") {
6328
+ userProvidedToolkitVersions = Object.fromEntries(
6329
+ Object.entries(defaultVersions).map(([key, value]) => [key.toLowerCase(), value])
6330
+ );
6331
+ }
6332
+ const toolkitVersions = {
6333
+ ...toolkitVersionsFromEnv,
6334
+ ...userProvidedToolkitVersions
6335
+ };
6336
+ if (Object.keys(toolkitVersions).length === 0) {
6337
+ return "latest";
6338
+ }
6339
+ return toolkitVersions;
6340
+ }
6241
6341
 
6242
6342
  // src/utils/version.ts
6243
6343
  var import_semver = __toESM(require("semver"), 1);
@@ -6759,7 +6859,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
6759
6859
  };
6760
6860
 
6761
6861
  // package.json
6762
- var version = "0.1.51";
6862
+ var version = "0.1.52";
6763
6863
 
6764
6864
  // src/models/Files.ts
6765
6865
  var Files = class {
@@ -6882,7 +6982,11 @@ var Composio = class _Composio {
6882
6982
  }
6883
6983
  this.config = {
6884
6984
  ...config,
6885
- allowTracking: config?.allowTracking ?? true
6985
+ baseURL: baseURLParsed,
6986
+ apiKey: apiKeyParsed,
6987
+ toolkitVersions: getToolkitVersionsFromEnv(config?.toolkitVersions),
6988
+ allowTracking: config?.allowTracking ?? true,
6989
+ autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? true
6886
6990
  };
6887
6991
  this.provider = config?.provider ?? new OpenAIProvider();
6888
6992
  const defaultHeaders = getDefaultHeaders(this.config.defaultHeaders, this.provider);
@@ -6892,9 +6996,7 @@ var Composio = class _Composio {
6892
6996
  defaultHeaders,
6893
6997
  logLevel: COMPOSIO_LOG_LEVEL
6894
6998
  });
6895
- this.tools = new Tools(this.client, this.provider, {
6896
- autoUploadDownloadFiles: config?.autoUploadDownloadFiles ?? true
6897
- });
6999
+ this.tools = new Tools(this.client, this.provider, this.config);
6898
7000
  this.mcp = new MCP(this.client, this.provider);
6899
7001
  this.toolkits = new Toolkits(this.client);
6900
7002
  this.triggers = new Triggers(this.client);
@@ -6928,6 +7030,13 @@ var Composio = class _Composio {
6928
7030
  }
6929
7031
  return this.client;
6930
7032
  }
7033
+ /**
7034
+ * Get the configuration SDK is initialized with
7035
+ * @returns {ComposioConfig<TProvider>} The configuration SDK is initialized with
7036
+ */
7037
+ getConfig() {
7038
+ return this.config;
7039
+ }
6931
7040
  /**
6932
7041
  * Creates a new instance of the Composio SDK with custom request options while preserving the existing configuration.
6933
7042
  * This method is particularly useful when you need to: