@composio/core 0.1.12-alpha.13 → 0.1.12-alpha.15

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.d.ts CHANGED
@@ -973,9 +973,16 @@ declare class Tools<TToolCollection, TTool, TProvider extends BaseComposioProvid
973
973
  /**
974
974
  * Fetches the list of all available tools in the Composio SDK.
975
975
  *
976
- * This method is mostly used by the CLI to get the list of tools.
976
+ * This method is mostly used by the CLI to get the list of tools.
977
977
  * No filtering is done on the tools, the list is cached in the backend, no further optimization is required.
978
- * @returns {string} - The list of all available tools as a string
978
+ * @returns {Promise<ToolRetrieveEnumResponse>} The complete list of all available tools with their metadata
979
+ *
980
+ * @example
981
+ * ```typescript
982
+ * // Get all available tools as an enum
983
+ * const toolsEnum = await composio.tools.getToolsEnum();
984
+ * console.log(toolsEnum.items);
985
+ * ```
979
986
  */
980
987
  getToolsEnum(): Promise<ToolRetrieveEnumResponse>;
981
988
  /**
@@ -985,13 +992,40 @@ declare class Tools<TToolCollection, TTool, TProvider extends BaseComposioProvid
985
992
  *
986
993
  * @param {string} slug - The ID of the tool to find input for
987
994
  * @param {ToolGetInputParams} body - The parameters to be passed to the tool
988
- * @returns
995
+ * @returns {Promise<ToolGetInputResponse>} The input parameters schema for the specified tool
996
+ *
997
+ * @example
998
+ * ```typescript
999
+ * // Get input parameters for a specific tool
1000
+ * const inputParams = await composio.tools.getInput('GITHUB_CREATE_ISSUE', {
1001
+ * userId: 'default'
1002
+ * });
1003
+ * console.log(inputParams.schema);
1004
+ * ```
989
1005
  */
990
1006
  getInput(slug: string, body: ToolGetInputParams): Promise<ToolGetInputResponse>;
991
1007
  /**
992
- * Proxies a custom request to a toolkit/integration
993
- * @param body
994
- * @returns
1008
+ * Proxies a custom request to a toolkit/integration.
1009
+ *
1010
+ * This method allows sending custom requests to a specific toolkit or integration
1011
+ * when you need more flexibility than the standard tool execution methods provide.
1012
+ *
1013
+ * @param {ToolProxyParams} body - The parameters for the proxy request including toolkit slug and custom data
1014
+ * @returns {Promise<ToolProxyResponse>} The response from the proxied request
1015
+ *
1016
+ * @example
1017
+ * ```typescript
1018
+ * // Send a custom request to a toolkit
1019
+ * const response = await composio.tools.proxyExecute({
1020
+ * toolkitSlug: 'github',
1021
+ * userId: 'default',
1022
+ * data: {
1023
+ * endpoint: '/repos/owner/repo/issues',
1024
+ * method: 'GET'
1025
+ * }
1026
+ * });
1027
+ * console.log(response.data);
1028
+ * ```
995
1029
  */
996
1030
  proxyExecute(body: ToolProxyParams): Promise<ToolProxyResponse>;
997
1031
  /**
@@ -3117,22 +3151,53 @@ declare class ConnectedAccounts {
3117
3151
  * Update the status of a connected account
3118
3152
  * @param {string} nanoid - Unique identifier of the connected account
3119
3153
  * @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
3120
- * @param {RequestOptions} options - Request options
3121
3154
  * @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
3155
+ *
3156
+ * @example
3157
+ * ```typescript
3158
+ * // Enable a connected account
3159
+ * const updatedAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
3160
+ * enabled: true
3161
+ * });
3162
+ *
3163
+ * // Disable a connected account with a reason
3164
+ * const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
3165
+ * enabled: false,
3166
+ * reason: 'Token expired'
3167
+ * });
3168
+ * ```
3122
3169
  */
3123
3170
  updateStatus(nanoid: string, params: ConnectedAccountUpdateStatusParams): Promise<ConnectedAccountUpdateStatusResponse>;
3124
3171
  /**
3125
3172
  * Enable a connected account
3126
3173
  * @param {string} nanoid - Unique identifier of the connected account
3127
- * @param {RequestOptions} options - Request options
3128
3174
  * @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
3175
+ *
3176
+ * @example
3177
+ * ```typescript
3178
+ * // Enable a previously disabled connected account
3179
+ * const enabledAccount = await composio.connectedAccounts.enable('conn_abc123');
3180
+ * console.log(enabledAccount.isDisabled); // false
3181
+ * ```
3129
3182
  */
3130
3183
  enable(nanoid: string): Promise<ConnectedAccountUpdateStatusResponse>;
3131
3184
  /**
3132
3185
  * Disable a connected account
3133
3186
  * @param {string} nanoid - Unique identifier of the connected account
3134
- * @param {RequestOptions} options - Request options
3135
3187
  * @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
3188
+ *
3189
+ * @example
3190
+ * ```typescript
3191
+ * // Disable a connected account
3192
+ * const disabledAccount = await composio.connectedAccounts.disable('conn_abc123');
3193
+ * console.log(disabledAccount.isDisabled); // true
3194
+ *
3195
+ * // You can also use updateStatus with a reason
3196
+ * // const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
3197
+ * // enabled: false,
3198
+ * // reason: 'No longer needed'
3199
+ * // });
3200
+ * ```
3136
3201
  */
3137
3202
  disable(nanoid: string): Promise<ConnectedAccountUpdateStatusResponse>;
3138
3203
  }
@@ -3175,54 +3240,301 @@ type OpenAiToolCollection = Array<OpenAiTool>;
3175
3240
  declare class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection, OpenAiTool> {
3176
3241
  readonly name = "openai";
3177
3242
  /**
3178
- * Absract method to wrap a tool in the provider.
3179
- * This method is implemented by the provider.
3180
- * @param tool - The tool to wrap.
3181
- * @returns The wrapped tool.
3243
+ * Creates a new instance of the OpenAIProvider.
3244
+ *
3245
+ * This is the default provider for the Composio SDK and is automatically
3246
+ * available without additional installation.
3247
+ *
3248
+ * @example
3249
+ * ```typescript
3250
+ * // The OpenAIProvider is used by default when initializing Composio
3251
+ * const composio = new Composio({
3252
+ * apiKey: 'your-api-key'
3253
+ * });
3254
+ *
3255
+ * // You can also explicitly specify it
3256
+ * const composio = new Composio({
3257
+ * apiKey: 'your-api-key',
3258
+ * provider: new OpenAIProvider()
3259
+ * });
3260
+ * ```
3261
+ */
3262
+ constructor();
3263
+ /**
3264
+ * Wraps a Composio tool in the OpenAI function calling format.
3265
+ *
3266
+ * This method transforms a Composio tool definition into the format
3267
+ * expected by OpenAI's function calling API.
3268
+ *
3269
+ * @param tool - The Composio tool to wrap
3270
+ * @returns The wrapped tool in OpenAI format
3271
+ *
3272
+ * @example
3273
+ * ```typescript
3274
+ * // Wrap a single tool for use with OpenAI
3275
+ * const composioTool = {
3276
+ * slug: 'SEARCH_TOOL',
3277
+ * description: 'Search for information',
3278
+ * inputParameters: {
3279
+ * type: 'object',
3280
+ * properties: {
3281
+ * query: { type: 'string' }
3282
+ * },
3283
+ * required: ['query']
3284
+ * }
3285
+ * };
3286
+ *
3287
+ * const openAITool = provider.wrapTool(composioTool);
3288
+ * ```
3182
3289
  */
3183
3290
  wrapTool: (tool: Tool) => OpenAiTool;
3291
+ /**
3292
+ * Wraps multiple Composio tools in the OpenAI function calling format.
3293
+ *
3294
+ * This method transforms a list of Composio tools into the format
3295
+ * expected by OpenAI's function calling API.
3296
+ *
3297
+ * @param tools - Array of Composio tools to wrap
3298
+ * @returns Array of wrapped tools in OpenAI format
3299
+ *
3300
+ * @example
3301
+ * ```typescript
3302
+ * // Wrap multiple tools for use with OpenAI
3303
+ * const composioTools = [
3304
+ * {
3305
+ * slug: 'SEARCH_TOOL',
3306
+ * description: 'Search for information',
3307
+ * inputParameters: {
3308
+ * type: 'object',
3309
+ * properties: {
3310
+ * query: { type: 'string' }
3311
+ * }
3312
+ * }
3313
+ * },
3314
+ * {
3315
+ * slug: 'WEATHER_TOOL',
3316
+ * description: 'Get weather information',
3317
+ * inputParameters: {
3318
+ * type: 'object',
3319
+ * properties: {
3320
+ * location: { type: 'string' }
3321
+ * }
3322
+ * }
3323
+ * }
3324
+ * ];
3325
+ *
3326
+ * const openAITools = provider.wrapTools(composioTools);
3327
+ * ```
3328
+ */
3184
3329
  wrapTools: (tools: Tool[]) => OpenAiToolCollection;
3185
3330
  /**
3186
- * Execute a tool call.
3187
- * @param {OpenAI.ChatCompletionMessageToolCall} tool - The tool to execute.
3188
- * @param {string} userId - The user id.
3189
- * @returns {Promise<string>} The result of the tool call.
3331
+ * Executes a tool call from OpenAI's chat completion.
3332
+ *
3333
+ * This method processes a tool call from OpenAI's chat completion API,
3334
+ * executes the corresponding Composio tool, and returns the result.
3335
+ *
3336
+ * @param {string} userId - The user ID for authentication and tracking
3337
+ * @param {OpenAI.ChatCompletionMessageToolCall} tool - The tool call from OpenAI
3338
+ * @param {ExecuteToolFnOptions} [options] - Optional execution options
3339
+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
3340
+ * @returns {Promise<string>} The result of the tool call as a JSON string
3341
+ *
3342
+ * @example
3343
+ * ```typescript
3344
+ * // Execute a tool call from OpenAI
3345
+ * const toolCall = {
3346
+ * id: 'call_abc123',
3347
+ * type: 'function',
3348
+ * function: {
3349
+ * name: 'SEARCH_TOOL',
3350
+ * arguments: '{"query":"composio documentation"}'
3351
+ * }
3352
+ * };
3353
+ *
3354
+ * const result = await provider.executeToolCall(
3355
+ * 'user123',
3356
+ * toolCall,
3357
+ * { connectedAccountId: 'conn_xyz456' }
3358
+ * );
3359
+ * console.log(JSON.parse(result));
3360
+ * ```
3190
3361
  */
3191
3362
  executeToolCall(userId: string, tool: OpenAI.ChatCompletionMessageToolCall, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<string>;
3192
3363
  /**
3193
- * Handle the tool call from the assistant.
3364
+ * Handles tool calls from OpenAI's chat completion response.
3194
3365
  *
3195
- * @param {OpenAI.ChatCompletion} chatCompletion - The chat completion object.
3196
- * @param {string} userId - The user id.
3197
- * @returns {Promise<string[]>} The results of the tool call.
3366
+ * This method processes tool calls from an OpenAI chat completion response,
3367
+ * executes each tool call, and returns the results.
3368
+ *
3369
+ * @param {string} userId - The user ID for authentication and tracking
3370
+ * @param {OpenAI.ChatCompletion} chatCompletion - The chat completion response from OpenAI
3371
+ * @param {ExecuteToolFnOptions} [options] - Optional execution options
3372
+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
3373
+ * @returns {Promise<string[]>} Array of tool execution results as JSON strings
3374
+ *
3375
+ * @example
3376
+ * ```typescript
3377
+ * // Handle tool calls from a chat completion response
3378
+ * const chatCompletion = {
3379
+ * choices: [
3380
+ * {
3381
+ * message: {
3382
+ * tool_calls: [
3383
+ * {
3384
+ * id: 'call_abc123',
3385
+ * type: 'function',
3386
+ * function: {
3387
+ * name: 'SEARCH_TOOL',
3388
+ * arguments: '{"query":"composio documentation"}'
3389
+ * }
3390
+ * }
3391
+ * ]
3392
+ * }
3393
+ * }
3394
+ * ]
3395
+ * };
3396
+ *
3397
+ * const results = await provider.handleToolCalls(
3398
+ * 'user123',
3399
+ * chatCompletion,
3400
+ * { connectedAccountId: 'conn_xyz456' }
3401
+ * );
3402
+ * console.log(results); // Array of tool execution results
3403
+ * ```
3198
3404
  */
3199
3405
  handleToolCalls(userId: string, chatCompletion: OpenAI.ChatCompletion, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<string[]>;
3200
3406
  /**
3201
- * Handles all the tool calls from the assistant.
3407
+ * Handles all the tool calls from the OpenAI Assistant API.
3202
3408
  *
3203
- * @param {OpenAI.Beta.Threads.Run} run - The run object.
3204
- * @param {string} userId - The user id.
3205
- * @returns {Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>} The tool outputs.
3409
+ * This method processes tool calls from an OpenAI Assistant run,
3410
+ * executes each tool call, and returns the tool outputs for submission.
3411
+ *
3412
+ * @param {string} userId - The user ID for authentication and tracking
3413
+ * @param {OpenAI.Beta.Threads.Run} run - The Assistant run object containing tool calls
3414
+ * @param {ExecuteToolFnOptions} [options] - Optional execution options
3415
+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
3416
+ * @returns {Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>} Array of tool outputs for submission
3417
+ *
3418
+ * @example
3419
+ * ```typescript
3420
+ * // Handle tool calls from an OpenAI Assistant run
3421
+ * const run = {
3422
+ * id: 'run_abc123',
3423
+ * required_action: {
3424
+ * submit_tool_outputs: {
3425
+ * tool_calls: [
3426
+ * {
3427
+ * id: 'call_xyz789',
3428
+ * type: 'function',
3429
+ * function: {
3430
+ * name: 'SEARCH_TOOL',
3431
+ * arguments: '{"query":"composio documentation"}'
3432
+ * }
3433
+ * }
3434
+ * ]
3435
+ * }
3436
+ * }
3437
+ * };
3438
+ *
3439
+ * const toolOutputs = await provider.handleAssistantMessage(
3440
+ * 'user123',
3441
+ * run,
3442
+ * { connectedAccountId: 'conn_xyz456' }
3443
+ * );
3444
+ *
3445
+ * // Submit tool outputs back to OpenAI
3446
+ * await openai.beta.threads.runs.submitToolOutputs(
3447
+ * thread.id,
3448
+ * run.id,
3449
+ * { tool_outputs: toolOutputs }
3450
+ * );
3451
+ * ```
3206
3452
  */
3207
3453
  handleAssistantMessage(userId: string, run: OpenAI.Beta.Threads.Run, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>;
3208
3454
  /**
3209
3455
  * Waits for the assistant stream and handles the tool calls.
3210
3456
  *
3211
- * @param {OpenAI} client - The OpenAI client.
3212
- * @param {Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>} runStream - The run stream.
3213
- * @param {OpenAI.Beta.Threads.Thread} thread - The thread object.
3214
- * @param {string} userId - The user id.
3215
- * @returns {AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>} The run stream.
3457
+ * This method processes an OpenAI Assistant stream, handles any tool calls
3458
+ * that require action, and yields each event from the stream. It's designed
3459
+ * for streaming Assistant responses while handling tool calls in real-time.
3460
+ *
3461
+ * @param {string} userId - The user ID for authentication and tracking
3462
+ * @param {OpenAI} client - The OpenAI client instance
3463
+ * @param {Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>} runStream - The Assistant run stream
3464
+ * @param {OpenAI.Beta.Threads.Thread} thread - The thread object
3465
+ * @param {ExecuteToolFnOptions} [options] - Optional execution options
3466
+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
3467
+ * @returns {AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>} Generator yielding stream events
3468
+ *
3469
+ * @example
3470
+ * ```typescript
3471
+ * // Process an OpenAI Assistant stream with tool calls
3472
+ * const thread = await openai.beta.threads.create();
3473
+ * const runStream = openai.beta.threads.runs.stream(thread.id, {
3474
+ * assistant_id: 'asst_abc123',
3475
+ * tools: provider.wrapTools(composioTools)
3476
+ * });
3477
+ *
3478
+ * // Process the stream and handle tool calls
3479
+ * const streamProcessor = provider.waitAndHandleAssistantStreamToolCalls(
3480
+ * 'user123',
3481
+ * openai,
3482
+ * runStream,
3483
+ * thread,
3484
+ * { connectedAccountId: 'conn_xyz456' }
3485
+ * );
3486
+ *
3487
+ * // Consume the stream events
3488
+ * for await (const event of streamProcessor) {
3489
+ * if (event.event === 'thread.message.delta') {
3490
+ * console.log(event.data.delta.content);
3491
+ * }
3492
+ * }
3493
+ * ```
3216
3494
  */
3217
3495
  waitAndHandleAssistantStreamToolCalls(userId: string, client: OpenAI, runStream: Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>, thread: OpenAI.Beta.Threads.Thread, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>;
3218
3496
  /**
3219
3497
  * Waits for the assistant tool calls and handles them.
3220
3498
  *
3221
- * @param {OpenAI} client - The OpenAI client.
3222
- * @param {OpenAI.Beta.Threads.Run} run - The run object.
3223
- * @param {OpenAI.Beta.Threads.Thread} thread - The thread object.
3224
- * @param {string} userId - The user id.
3225
- * @returns {Promise<OpenAI.Beta.Threads.Run>} The run object.
3499
+ * This method polls an OpenAI Assistant run until it completes or requires action,
3500
+ * handles any tool calls, and returns the final run object. It's designed for
3501
+ * non-streaming Assistant interactions.
3502
+ *
3503
+ * @param {string} userId - The user ID for authentication and tracking
3504
+ * @param {OpenAI} client - The OpenAI client instance
3505
+ * @param {OpenAI.Beta.Threads.Run} run - The initial run object
3506
+ * @param {OpenAI.Beta.Threads.Thread} thread - The thread object
3507
+ * @param {ExecuteToolFnOptions} [options] - Optional execution options
3508
+ * @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
3509
+ * @returns {Promise<OpenAI.Beta.Threads.Run>} The final run object after completion
3510
+ *
3511
+ * @example
3512
+ * ```typescript
3513
+ * // Process an OpenAI Assistant run with tool calls
3514
+ * const thread = await openai.beta.threads.create();
3515
+ * await openai.beta.threads.messages.create(thread.id, {
3516
+ * role: 'user',
3517
+ * content: 'Find information about Composio'
3518
+ * });
3519
+ *
3520
+ * let run = await openai.beta.threads.runs.create(thread.id, {
3521
+ * assistant_id: 'asst_abc123',
3522
+ * tools: provider.wrapTools(composioTools)
3523
+ * });
3524
+ *
3525
+ * // Wait for the run to complete, handling any tool calls
3526
+ * run = await provider.waitAndHandleAssistantToolCalls(
3527
+ * 'user123',
3528
+ * openai,
3529
+ * run,
3530
+ * thread,
3531
+ * { connectedAccountId: 'conn_xyz456' }
3532
+ * );
3533
+ *
3534
+ * // Get the final messages after run completion
3535
+ * const messages = await openai.beta.threads.messages.list(thread.id);
3536
+ * console.log(messages.data[0].content);
3537
+ * ```
3226
3538
  */
3227
3539
  waitAndHandleAssistantToolCalls(userId: string, client: OpenAI, run: OpenAI.Beta.Threads.Run, thread: OpenAI.Beta.Threads.Thread, options?: ExecuteToolFnOptions, modifiers?: ExecuteToolModifiers): Promise<OpenAI.Beta.Threads.Runs.Run>;
3228
3540
  }
@@ -3260,13 +3572,36 @@ declare class Composio<TProvider extends BaseComposioProvider<unknown, unknown>
3260
3572
  authConfigs: AuthConfigs;
3261
3573
  connectedAccounts: ConnectedAccounts;
3262
3574
  /**
3263
- * @param {Object} config Configuration for the Composio SDK.
3264
- * @param {string} config.apiKey The API key for the Composio SDK.
3265
- * @param {string} config.baseURL The base URL for the Composio SDK.
3266
- * @param {string} config.runtime The runtime for the Composio SDK.
3267
- * @param {boolean} config.allowTracking Whether to allow analytics / tracking. Defaults to true.
3268
- * @param {boolean} config.allowTracing Whether to allow tracing. Defaults to true.
3269
- * @param {TProvider} config.provider The provider to use for this Composio instance.
3575
+ * Creates a new instance of the Composio SDK.
3576
+ *
3577
+ * The constructor initializes the SDK with the provided configuration options,
3578
+ * sets up the API client, and initializes all core models (tools, toolkits, etc.).
3579
+ *
3580
+ * @param {ComposioConfig<TProvider>} config - Configuration options for the Composio SDK
3581
+ * @param {string} [config.apiKey] - The API key for authenticating with the Composio API
3582
+ * @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
3583
+ * @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
3584
+ * @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
3585
+ * @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
3586
+ * @param {BaseTelemetryTransport} [config.telemetryTransport] - Custom telemetry transport implementation
3587
+ *
3588
+ * @example
3589
+ * ```typescript
3590
+ * // Initialize with default configuration
3591
+ * const composio = new Composio();
3592
+ *
3593
+ * // Initialize with custom API key and base URL
3594
+ * const composio = new Composio({
3595
+ * apiKey: 'your-api-key',
3596
+ * baseURL: 'https://api.composio.dev'
3597
+ * });
3598
+ *
3599
+ * // Initialize with custom provider
3600
+ * const composio = new Composio({
3601
+ * apiKey: 'your-api-key',
3602
+ * provider: new CustomProvider()
3603
+ * });
3604
+ * ```
3270
3605
  */
3271
3606
  constructor(config?: ComposioConfig<TProvider>);
3272
3607
  /**