@composio/core 0.1.12-alpha.14 → 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.cjs +422 -43
- package/dist/index.d.cts +377 -42
- package/dist/index.d.ts +377 -42
- package/dist/index.js +422 -43
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -939,6 +939,26 @@ var CustomTools = class {
|
|
|
939
939
|
* This is just an in memory registry and is not persisted.
|
|
940
940
|
* @param {CustomToolOptions} toolOptions CustomToolOptions
|
|
941
941
|
* @returns {Tool} The tool created
|
|
942
|
+
*
|
|
943
|
+
* @example
|
|
944
|
+
* ```typescript
|
|
945
|
+
* // Create a custom tool with input parameters
|
|
946
|
+
* const customTool = await composio.customTools.createTool({
|
|
947
|
+
* name: 'My Custom Tool',
|
|
948
|
+
* description: 'A tool that performs a custom operation',
|
|
949
|
+
* slug: 'MY_CUSTOM_TOOL',
|
|
950
|
+
* inputParams: z.object({
|
|
951
|
+
* query: z.string().describe('The search query'),
|
|
952
|
+
* limit: z.number().optional().describe('Maximum number of results')
|
|
953
|
+
* }),
|
|
954
|
+
* execute: async (input, authCredentials, executeToolRequest) => {
|
|
955
|
+
* // Custom implementation logic
|
|
956
|
+
* return {
|
|
957
|
+
* data: { results: ['result1', 'result2'] }
|
|
958
|
+
* };
|
|
959
|
+
* }
|
|
960
|
+
* });
|
|
961
|
+
* ```
|
|
942
962
|
*/
|
|
943
963
|
async createTool(toolOptions) {
|
|
944
964
|
const { slug, execute, inputParams, name, description } = toolOptions;
|
|
@@ -979,6 +999,17 @@ var CustomTools = class {
|
|
|
979
999
|
* Get all the custom tools from the registry.
|
|
980
1000
|
* @param {string[]} param0.toolSlugs The slugs of the tools to get
|
|
981
1001
|
* @returns {ToolList} The list of tools
|
|
1002
|
+
*
|
|
1003
|
+
* @example
|
|
1004
|
+
* ```typescript
|
|
1005
|
+
* // Get all custom tools
|
|
1006
|
+
* const allTools = await composio.customTools.getCustomTools({});
|
|
1007
|
+
*
|
|
1008
|
+
* // Get specific custom tools by slug
|
|
1009
|
+
* const specificTools = await composio.customTools.getCustomTools({
|
|
1010
|
+
* toolSlugs: ['MY_CUSTOM_TOOL', 'ANOTHER_CUSTOM_TOOL']
|
|
1011
|
+
* });
|
|
1012
|
+
* ```
|
|
982
1013
|
*/
|
|
983
1014
|
async getCustomTools({ toolSlugs }) {
|
|
984
1015
|
const tools = [];
|
|
@@ -998,6 +1029,17 @@ var CustomTools = class {
|
|
|
998
1029
|
* Get a custom tool by slug from the registry.
|
|
999
1030
|
* @param {string} slug The slug of the tool to get
|
|
1000
1031
|
* @returns {Tool} The tool
|
|
1032
|
+
*
|
|
1033
|
+
* @example
|
|
1034
|
+
* ```typescript
|
|
1035
|
+
* // Get a specific custom tool by its slug
|
|
1036
|
+
* const myTool = await composio.customTools.getCustomToolBySlug('MY_CUSTOM_TOOL');
|
|
1037
|
+
* if (myTool) {
|
|
1038
|
+
* console.log(`Found tool: ${myTool.name}`);
|
|
1039
|
+
* } else {
|
|
1040
|
+
* console.log('Tool not found');
|
|
1041
|
+
* }
|
|
1042
|
+
* ```
|
|
1001
1043
|
*/
|
|
1002
1044
|
async getCustomToolBySlug(slug) {
|
|
1003
1045
|
if (!slug) {
|
|
@@ -1554,9 +1596,16 @@ var Tools = class {
|
|
|
1554
1596
|
/**
|
|
1555
1597
|
* Fetches the list of all available tools in the Composio SDK.
|
|
1556
1598
|
*
|
|
1557
|
-
* This method is mostly used by the CLI
|
|
1599
|
+
* This method is mostly used by the CLI to get the list of tools.
|
|
1558
1600
|
* No filtering is done on the tools, the list is cached in the backend, no further optimization is required.
|
|
1559
|
-
* @returns {
|
|
1601
|
+
* @returns {Promise<ToolRetrieveEnumResponse>} The complete list of all available tools with their metadata
|
|
1602
|
+
*
|
|
1603
|
+
* @example
|
|
1604
|
+
* ```typescript
|
|
1605
|
+
* // Get all available tools as an enum
|
|
1606
|
+
* const toolsEnum = await composio.tools.getToolsEnum();
|
|
1607
|
+
* console.log(toolsEnum.items);
|
|
1608
|
+
* ```
|
|
1560
1609
|
*/
|
|
1561
1610
|
async getToolsEnum() {
|
|
1562
1611
|
return this.client.tools.retrieveEnum();
|
|
@@ -1568,15 +1617,42 @@ var Tools = class {
|
|
|
1568
1617
|
*
|
|
1569
1618
|
* @param {string} slug - The ID of the tool to find input for
|
|
1570
1619
|
* @param {ToolGetInputParams} body - The parameters to be passed to the tool
|
|
1571
|
-
* @returns
|
|
1620
|
+
* @returns {Promise<ToolGetInputResponse>} The input parameters schema for the specified tool
|
|
1621
|
+
*
|
|
1622
|
+
* @example
|
|
1623
|
+
* ```typescript
|
|
1624
|
+
* // Get input parameters for a specific tool
|
|
1625
|
+
* const inputParams = await composio.tools.getInput('GITHUB_CREATE_ISSUE', {
|
|
1626
|
+
* userId: 'default'
|
|
1627
|
+
* });
|
|
1628
|
+
* console.log(inputParams.schema);
|
|
1629
|
+
* ```
|
|
1572
1630
|
*/
|
|
1573
1631
|
async getInput(slug, body) {
|
|
1574
1632
|
return this.client.tools.getInput(slug, body);
|
|
1575
1633
|
}
|
|
1576
1634
|
/**
|
|
1577
|
-
* Proxies a custom request to a toolkit/integration
|
|
1578
|
-
*
|
|
1579
|
-
*
|
|
1635
|
+
* Proxies a custom request to a toolkit/integration.
|
|
1636
|
+
*
|
|
1637
|
+
* This method allows sending custom requests to a specific toolkit or integration
|
|
1638
|
+
* when you need more flexibility than the standard tool execution methods provide.
|
|
1639
|
+
*
|
|
1640
|
+
* @param {ToolProxyParams} body - The parameters for the proxy request including toolkit slug and custom data
|
|
1641
|
+
* @returns {Promise<ToolProxyResponse>} The response from the proxied request
|
|
1642
|
+
*
|
|
1643
|
+
* @example
|
|
1644
|
+
* ```typescript
|
|
1645
|
+
* // Send a custom request to a toolkit
|
|
1646
|
+
* const response = await composio.tools.proxyExecute({
|
|
1647
|
+
* toolkitSlug: 'github',
|
|
1648
|
+
* userId: 'default',
|
|
1649
|
+
* data: {
|
|
1650
|
+
* endpoint: '/repos/owner/repo/issues',
|
|
1651
|
+
* method: 'GET'
|
|
1652
|
+
* }
|
|
1653
|
+
* });
|
|
1654
|
+
* console.log(response.data);
|
|
1655
|
+
* ```
|
|
1580
1656
|
*/
|
|
1581
1657
|
async proxyExecute(body) {
|
|
1582
1658
|
return this.client.tools.proxy(body);
|
|
@@ -2693,8 +2769,21 @@ var ConnectedAccounts = class {
|
|
|
2693
2769
|
* Update the status of a connected account
|
|
2694
2770
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
2695
2771
|
* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
|
|
2696
|
-
* @param {RequestOptions} options - Request options
|
|
2697
2772
|
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
2773
|
+
*
|
|
2774
|
+
* @example
|
|
2775
|
+
* ```typescript
|
|
2776
|
+
* // Enable a connected account
|
|
2777
|
+
* const updatedAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
2778
|
+
* enabled: true
|
|
2779
|
+
* });
|
|
2780
|
+
*
|
|
2781
|
+
* // Disable a connected account with a reason
|
|
2782
|
+
* const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
2783
|
+
* enabled: false,
|
|
2784
|
+
* reason: 'Token expired'
|
|
2785
|
+
* });
|
|
2786
|
+
* ```
|
|
2698
2787
|
*/
|
|
2699
2788
|
async updateStatus(nanoid, params) {
|
|
2700
2789
|
return this.client.connectedAccounts.updateStatus(nanoid, params);
|
|
@@ -2702,8 +2791,14 @@ var ConnectedAccounts = class {
|
|
|
2702
2791
|
/**
|
|
2703
2792
|
* Enable a connected account
|
|
2704
2793
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
2705
|
-
* @param {RequestOptions} options - Request options
|
|
2706
2794
|
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
2795
|
+
*
|
|
2796
|
+
* @example
|
|
2797
|
+
* ```typescript
|
|
2798
|
+
* // Enable a previously disabled connected account
|
|
2799
|
+
* const enabledAccount = await composio.connectedAccounts.enable('conn_abc123');
|
|
2800
|
+
* console.log(enabledAccount.isDisabled); // false
|
|
2801
|
+
* ```
|
|
2707
2802
|
*/
|
|
2708
2803
|
async enable(nanoid) {
|
|
2709
2804
|
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
|
|
@@ -2711,8 +2806,20 @@ var ConnectedAccounts = class {
|
|
|
2711
2806
|
/**
|
|
2712
2807
|
* Disable a connected account
|
|
2713
2808
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
2714
|
-
* @param {RequestOptions} options - Request options
|
|
2715
2809
|
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
2810
|
+
*
|
|
2811
|
+
* @example
|
|
2812
|
+
* ```typescript
|
|
2813
|
+
* // Disable a connected account
|
|
2814
|
+
* const disabledAccount = await composio.connectedAccounts.disable('conn_abc123');
|
|
2815
|
+
* console.log(disabledAccount.isDisabled); // true
|
|
2816
|
+
*
|
|
2817
|
+
* // You can also use updateStatus with a reason
|
|
2818
|
+
* // const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
2819
|
+
* // enabled: false,
|
|
2820
|
+
* // reason: 'No longer needed'
|
|
2821
|
+
* // });
|
|
2822
|
+
* ```
|
|
2716
2823
|
*/
|
|
2717
2824
|
async disable(nanoid) {
|
|
2718
2825
|
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
|
|
@@ -3689,10 +3796,54 @@ var BaseAgenticProvider = class extends BaseProvider {
|
|
|
3689
3796
|
var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
3690
3797
|
name = "openai";
|
|
3691
3798
|
/**
|
|
3692
|
-
*
|
|
3693
|
-
*
|
|
3694
|
-
*
|
|
3695
|
-
*
|
|
3799
|
+
* Creates a new instance of the OpenAIProvider.
|
|
3800
|
+
*
|
|
3801
|
+
* This is the default provider for the Composio SDK and is automatically
|
|
3802
|
+
* available without additional installation.
|
|
3803
|
+
*
|
|
3804
|
+
* @example
|
|
3805
|
+
* ```typescript
|
|
3806
|
+
* // The OpenAIProvider is used by default when initializing Composio
|
|
3807
|
+
* const composio = new Composio({
|
|
3808
|
+
* apiKey: 'your-api-key'
|
|
3809
|
+
* });
|
|
3810
|
+
*
|
|
3811
|
+
* // You can also explicitly specify it
|
|
3812
|
+
* const composio = new Composio({
|
|
3813
|
+
* apiKey: 'your-api-key',
|
|
3814
|
+
* provider: new OpenAIProvider()
|
|
3815
|
+
* });
|
|
3816
|
+
* ```
|
|
3817
|
+
*/
|
|
3818
|
+
constructor() {
|
|
3819
|
+
super();
|
|
3820
|
+
}
|
|
3821
|
+
/**
|
|
3822
|
+
* Wraps a Composio tool in the OpenAI function calling format.
|
|
3823
|
+
*
|
|
3824
|
+
* This method transforms a Composio tool definition into the format
|
|
3825
|
+
* expected by OpenAI's function calling API.
|
|
3826
|
+
*
|
|
3827
|
+
* @param tool - The Composio tool to wrap
|
|
3828
|
+
* @returns The wrapped tool in OpenAI format
|
|
3829
|
+
*
|
|
3830
|
+
* @example
|
|
3831
|
+
* ```typescript
|
|
3832
|
+
* // Wrap a single tool for use with OpenAI
|
|
3833
|
+
* const composioTool = {
|
|
3834
|
+
* slug: 'SEARCH_TOOL',
|
|
3835
|
+
* description: 'Search for information',
|
|
3836
|
+
* inputParameters: {
|
|
3837
|
+
* type: 'object',
|
|
3838
|
+
* properties: {
|
|
3839
|
+
* query: { type: 'string' }
|
|
3840
|
+
* },
|
|
3841
|
+
* required: ['query']
|
|
3842
|
+
* }
|
|
3843
|
+
* };
|
|
3844
|
+
*
|
|
3845
|
+
* const openAITool = provider.wrapTool(composioTool);
|
|
3846
|
+
* ```
|
|
3696
3847
|
*/
|
|
3697
3848
|
wrapTool = (tool) => {
|
|
3698
3849
|
const formattedSchema = {
|
|
@@ -3705,14 +3856,78 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3705
3856
|
function: formattedSchema
|
|
3706
3857
|
};
|
|
3707
3858
|
};
|
|
3859
|
+
/**
|
|
3860
|
+
* Wraps multiple Composio tools in the OpenAI function calling format.
|
|
3861
|
+
*
|
|
3862
|
+
* This method transforms a list of Composio tools into the format
|
|
3863
|
+
* expected by OpenAI's function calling API.
|
|
3864
|
+
*
|
|
3865
|
+
* @param tools - Array of Composio tools to wrap
|
|
3866
|
+
* @returns Array of wrapped tools in OpenAI format
|
|
3867
|
+
*
|
|
3868
|
+
* @example
|
|
3869
|
+
* ```typescript
|
|
3870
|
+
* // Wrap multiple tools for use with OpenAI
|
|
3871
|
+
* const composioTools = [
|
|
3872
|
+
* {
|
|
3873
|
+
* slug: 'SEARCH_TOOL',
|
|
3874
|
+
* description: 'Search for information',
|
|
3875
|
+
* inputParameters: {
|
|
3876
|
+
* type: 'object',
|
|
3877
|
+
* properties: {
|
|
3878
|
+
* query: { type: 'string' }
|
|
3879
|
+
* }
|
|
3880
|
+
* }
|
|
3881
|
+
* },
|
|
3882
|
+
* {
|
|
3883
|
+
* slug: 'WEATHER_TOOL',
|
|
3884
|
+
* description: 'Get weather information',
|
|
3885
|
+
* inputParameters: {
|
|
3886
|
+
* type: 'object',
|
|
3887
|
+
* properties: {
|
|
3888
|
+
* location: { type: 'string' }
|
|
3889
|
+
* }
|
|
3890
|
+
* }
|
|
3891
|
+
* }
|
|
3892
|
+
* ];
|
|
3893
|
+
*
|
|
3894
|
+
* const openAITools = provider.wrapTools(composioTools);
|
|
3895
|
+
* ```
|
|
3896
|
+
*/
|
|
3708
3897
|
wrapTools = (tools) => {
|
|
3709
3898
|
return tools.map((tool) => this.wrapTool(tool));
|
|
3710
3899
|
};
|
|
3711
3900
|
/**
|
|
3712
|
-
*
|
|
3713
|
-
*
|
|
3714
|
-
*
|
|
3715
|
-
*
|
|
3901
|
+
* Executes a tool call from OpenAI's chat completion.
|
|
3902
|
+
*
|
|
3903
|
+
* This method processes a tool call from OpenAI's chat completion API,
|
|
3904
|
+
* executes the corresponding Composio tool, and returns the result.
|
|
3905
|
+
*
|
|
3906
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
3907
|
+
* @param {OpenAI.ChatCompletionMessageToolCall} tool - The tool call from OpenAI
|
|
3908
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
3909
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
3910
|
+
* @returns {Promise<string>} The result of the tool call as a JSON string
|
|
3911
|
+
*
|
|
3912
|
+
* @example
|
|
3913
|
+
* ```typescript
|
|
3914
|
+
* // Execute a tool call from OpenAI
|
|
3915
|
+
* const toolCall = {
|
|
3916
|
+
* id: 'call_abc123',
|
|
3917
|
+
* type: 'function',
|
|
3918
|
+
* function: {
|
|
3919
|
+
* name: 'SEARCH_TOOL',
|
|
3920
|
+
* arguments: '{"query":"composio documentation"}'
|
|
3921
|
+
* }
|
|
3922
|
+
* };
|
|
3923
|
+
*
|
|
3924
|
+
* const result = await provider.executeToolCall(
|
|
3925
|
+
* 'user123',
|
|
3926
|
+
* toolCall,
|
|
3927
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
3928
|
+
* );
|
|
3929
|
+
* console.log(JSON.parse(result));
|
|
3930
|
+
* ```
|
|
3716
3931
|
*/
|
|
3717
3932
|
async executeToolCall(userId, tool, options, modifiers) {
|
|
3718
3933
|
const payload = {
|
|
@@ -3725,11 +3940,46 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3725
3940
|
return JSON.stringify(result);
|
|
3726
3941
|
}
|
|
3727
3942
|
/**
|
|
3728
|
-
*
|
|
3943
|
+
* Handles tool calls from OpenAI's chat completion response.
|
|
3729
3944
|
*
|
|
3730
|
-
*
|
|
3731
|
-
*
|
|
3732
|
-
*
|
|
3945
|
+
* This method processes tool calls from an OpenAI chat completion response,
|
|
3946
|
+
* executes each tool call, and returns the results.
|
|
3947
|
+
*
|
|
3948
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
3949
|
+
* @param {OpenAI.ChatCompletion} chatCompletion - The chat completion response from OpenAI
|
|
3950
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
3951
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
3952
|
+
* @returns {Promise<string[]>} Array of tool execution results as JSON strings
|
|
3953
|
+
*
|
|
3954
|
+
* @example
|
|
3955
|
+
* ```typescript
|
|
3956
|
+
* // Handle tool calls from a chat completion response
|
|
3957
|
+
* const chatCompletion = {
|
|
3958
|
+
* choices: [
|
|
3959
|
+
* {
|
|
3960
|
+
* message: {
|
|
3961
|
+
* tool_calls: [
|
|
3962
|
+
* {
|
|
3963
|
+
* id: 'call_abc123',
|
|
3964
|
+
* type: 'function',
|
|
3965
|
+
* function: {
|
|
3966
|
+
* name: 'SEARCH_TOOL',
|
|
3967
|
+
* arguments: '{"query":"composio documentation"}'
|
|
3968
|
+
* }
|
|
3969
|
+
* }
|
|
3970
|
+
* ]
|
|
3971
|
+
* }
|
|
3972
|
+
* }
|
|
3973
|
+
* ]
|
|
3974
|
+
* };
|
|
3975
|
+
*
|
|
3976
|
+
* const results = await provider.handleToolCalls(
|
|
3977
|
+
* 'user123',
|
|
3978
|
+
* chatCompletion,
|
|
3979
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
3980
|
+
* );
|
|
3981
|
+
* console.log(results); // Array of tool execution results
|
|
3982
|
+
* ```
|
|
3733
3983
|
*/
|
|
3734
3984
|
async handleToolCalls(userId, chatCompletion, options, modifiers) {
|
|
3735
3985
|
const outputs = [];
|
|
@@ -3743,11 +3993,51 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3743
3993
|
return outputs;
|
|
3744
3994
|
}
|
|
3745
3995
|
/**
|
|
3746
|
-
* Handles all the tool calls from the
|
|
3996
|
+
* Handles all the tool calls from the OpenAI Assistant API.
|
|
3747
3997
|
*
|
|
3748
|
-
*
|
|
3749
|
-
*
|
|
3750
|
-
*
|
|
3998
|
+
* This method processes tool calls from an OpenAI Assistant run,
|
|
3999
|
+
* executes each tool call, and returns the tool outputs for submission.
|
|
4000
|
+
*
|
|
4001
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
4002
|
+
* @param {OpenAI.Beta.Threads.Run} run - The Assistant run object containing tool calls
|
|
4003
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
4004
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
4005
|
+
* @returns {Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>} Array of tool outputs for submission
|
|
4006
|
+
*
|
|
4007
|
+
* @example
|
|
4008
|
+
* ```typescript
|
|
4009
|
+
* // Handle tool calls from an OpenAI Assistant run
|
|
4010
|
+
* const run = {
|
|
4011
|
+
* id: 'run_abc123',
|
|
4012
|
+
* required_action: {
|
|
4013
|
+
* submit_tool_outputs: {
|
|
4014
|
+
* tool_calls: [
|
|
4015
|
+
* {
|
|
4016
|
+
* id: 'call_xyz789',
|
|
4017
|
+
* type: 'function',
|
|
4018
|
+
* function: {
|
|
4019
|
+
* name: 'SEARCH_TOOL',
|
|
4020
|
+
* arguments: '{"query":"composio documentation"}'
|
|
4021
|
+
* }
|
|
4022
|
+
* }
|
|
4023
|
+
* ]
|
|
4024
|
+
* }
|
|
4025
|
+
* }
|
|
4026
|
+
* };
|
|
4027
|
+
*
|
|
4028
|
+
* const toolOutputs = await provider.handleAssistantMessage(
|
|
4029
|
+
* 'user123',
|
|
4030
|
+
* run,
|
|
4031
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
4032
|
+
* );
|
|
4033
|
+
*
|
|
4034
|
+
* // Submit tool outputs back to OpenAI
|
|
4035
|
+
* await openai.beta.threads.runs.submitToolOutputs(
|
|
4036
|
+
* thread.id,
|
|
4037
|
+
* run.id,
|
|
4038
|
+
* { tool_outputs: toolOutputs }
|
|
4039
|
+
* );
|
|
4040
|
+
* ```
|
|
3751
4041
|
*/
|
|
3752
4042
|
async handleAssistantMessage(userId, run, options, modifiers) {
|
|
3753
4043
|
const tool_calls = run.required_action?.submit_tool_outputs?.tool_calls || [];
|
|
@@ -3772,11 +4062,43 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3772
4062
|
/**
|
|
3773
4063
|
* Waits for the assistant stream and handles the tool calls.
|
|
3774
4064
|
*
|
|
3775
|
-
*
|
|
3776
|
-
*
|
|
3777
|
-
*
|
|
3778
|
-
*
|
|
3779
|
-
* @
|
|
4065
|
+
* This method processes an OpenAI Assistant stream, handles any tool calls
|
|
4066
|
+
* that require action, and yields each event from the stream. It's designed
|
|
4067
|
+
* for streaming Assistant responses while handling tool calls in real-time.
|
|
4068
|
+
*
|
|
4069
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
4070
|
+
* @param {OpenAI} client - The OpenAI client instance
|
|
4071
|
+
* @param {Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>} runStream - The Assistant run stream
|
|
4072
|
+
* @param {OpenAI.Beta.Threads.Thread} thread - The thread object
|
|
4073
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
4074
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
4075
|
+
* @returns {AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>} Generator yielding stream events
|
|
4076
|
+
*
|
|
4077
|
+
* @example
|
|
4078
|
+
* ```typescript
|
|
4079
|
+
* // Process an OpenAI Assistant stream with tool calls
|
|
4080
|
+
* const thread = await openai.beta.threads.create();
|
|
4081
|
+
* const runStream = openai.beta.threads.runs.stream(thread.id, {
|
|
4082
|
+
* assistant_id: 'asst_abc123',
|
|
4083
|
+
* tools: provider.wrapTools(composioTools)
|
|
4084
|
+
* });
|
|
4085
|
+
*
|
|
4086
|
+
* // Process the stream and handle tool calls
|
|
4087
|
+
* const streamProcessor = provider.waitAndHandleAssistantStreamToolCalls(
|
|
4088
|
+
* 'user123',
|
|
4089
|
+
* openai,
|
|
4090
|
+
* runStream,
|
|
4091
|
+
* thread,
|
|
4092
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
4093
|
+
* );
|
|
4094
|
+
*
|
|
4095
|
+
* // Consume the stream events
|
|
4096
|
+
* for await (const event of streamProcessor) {
|
|
4097
|
+
* if (event.event === 'thread.message.delta') {
|
|
4098
|
+
* console.log(event.data.delta.content);
|
|
4099
|
+
* }
|
|
4100
|
+
* }
|
|
4101
|
+
* ```
|
|
3780
4102
|
*/
|
|
3781
4103
|
async *waitAndHandleAssistantStreamToolCalls(userId, client, runStream, thread, options, modifiers) {
|
|
3782
4104
|
let runId = null;
|
|
@@ -3828,11 +4150,45 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3828
4150
|
/**
|
|
3829
4151
|
* Waits for the assistant tool calls and handles them.
|
|
3830
4152
|
*
|
|
3831
|
-
*
|
|
3832
|
-
*
|
|
3833
|
-
*
|
|
3834
|
-
*
|
|
3835
|
-
* @
|
|
4153
|
+
* This method polls an OpenAI Assistant run until it completes or requires action,
|
|
4154
|
+
* handles any tool calls, and returns the final run object. It's designed for
|
|
4155
|
+
* non-streaming Assistant interactions.
|
|
4156
|
+
*
|
|
4157
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
4158
|
+
* @param {OpenAI} client - The OpenAI client instance
|
|
4159
|
+
* @param {OpenAI.Beta.Threads.Run} run - The initial run object
|
|
4160
|
+
* @param {OpenAI.Beta.Threads.Thread} thread - The thread object
|
|
4161
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
4162
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
4163
|
+
* @returns {Promise<OpenAI.Beta.Threads.Run>} The final run object after completion
|
|
4164
|
+
*
|
|
4165
|
+
* @example
|
|
4166
|
+
* ```typescript
|
|
4167
|
+
* // Process an OpenAI Assistant run with tool calls
|
|
4168
|
+
* const thread = await openai.beta.threads.create();
|
|
4169
|
+
* await openai.beta.threads.messages.create(thread.id, {
|
|
4170
|
+
* role: 'user',
|
|
4171
|
+
* content: 'Find information about Composio'
|
|
4172
|
+
* });
|
|
4173
|
+
*
|
|
4174
|
+
* let run = await openai.beta.threads.runs.create(thread.id, {
|
|
4175
|
+
* assistant_id: 'asst_abc123',
|
|
4176
|
+
* tools: provider.wrapTools(composioTools)
|
|
4177
|
+
* });
|
|
4178
|
+
*
|
|
4179
|
+
* // Wait for the run to complete, handling any tool calls
|
|
4180
|
+
* run = await provider.waitAndHandleAssistantToolCalls(
|
|
4181
|
+
* 'user123',
|
|
4182
|
+
* openai,
|
|
4183
|
+
* run,
|
|
4184
|
+
* thread,
|
|
4185
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
4186
|
+
* );
|
|
4187
|
+
*
|
|
4188
|
+
* // Get the final messages after run completion
|
|
4189
|
+
* const messages = await openai.beta.threads.messages.list(thread.id);
|
|
4190
|
+
* console.log(messages.data[0].content);
|
|
4191
|
+
* ```
|
|
3836
4192
|
*/
|
|
3837
4193
|
async waitAndHandleAssistantToolCalls(userId, client, run, thread, options, modifiers) {
|
|
3838
4194
|
while (["queued", "in_progress", "requires_action"].includes(run.status)) {
|
|
@@ -3851,7 +4207,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3851
4207
|
};
|
|
3852
4208
|
|
|
3853
4209
|
// package.json
|
|
3854
|
-
var version = "0.1.12-alpha.
|
|
4210
|
+
var version = "0.1.12-alpha.15";
|
|
3855
4211
|
|
|
3856
4212
|
// src/composio.ts
|
|
3857
4213
|
var Composio = class {
|
|
@@ -3877,13 +4233,36 @@ var Composio = class {
|
|
|
3877
4233
|
// connected accounts
|
|
3878
4234
|
connectedAccounts;
|
|
3879
4235
|
/**
|
|
3880
|
-
*
|
|
3881
|
-
*
|
|
3882
|
-
*
|
|
3883
|
-
*
|
|
3884
|
-
*
|
|
3885
|
-
* @param {
|
|
3886
|
-
* @param {
|
|
4236
|
+
* Creates a new instance of the Composio SDK.
|
|
4237
|
+
*
|
|
4238
|
+
* The constructor initializes the SDK with the provided configuration options,
|
|
4239
|
+
* sets up the API client, and initializes all core models (tools, toolkits, etc.).
|
|
4240
|
+
*
|
|
4241
|
+
* @param {ComposioConfig<TProvider>} config - Configuration options for the Composio SDK
|
|
4242
|
+
* @param {string} [config.apiKey] - The API key for authenticating with the Composio API
|
|
4243
|
+
* @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
|
|
4244
|
+
* @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
|
|
4245
|
+
* @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
|
|
4246
|
+
* @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
|
|
4247
|
+
* @param {BaseTelemetryTransport} [config.telemetryTransport] - Custom telemetry transport implementation
|
|
4248
|
+
*
|
|
4249
|
+
* @example
|
|
4250
|
+
* ```typescript
|
|
4251
|
+
* // Initialize with default configuration
|
|
4252
|
+
* const composio = new Composio();
|
|
4253
|
+
*
|
|
4254
|
+
* // Initialize with custom API key and base URL
|
|
4255
|
+
* const composio = new Composio({
|
|
4256
|
+
* apiKey: 'your-api-key',
|
|
4257
|
+
* baseURL: 'https://api.composio.dev'
|
|
4258
|
+
* });
|
|
4259
|
+
*
|
|
4260
|
+
* // Initialize with custom provider
|
|
4261
|
+
* const composio = new Composio({
|
|
4262
|
+
* apiKey: 'your-api-key',
|
|
4263
|
+
* provider: new CustomProvider()
|
|
4264
|
+
* });
|
|
4265
|
+
* ```
|
|
3887
4266
|
*/
|
|
3888
4267
|
constructor(config) {
|
|
3889
4268
|
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(
|