@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.js
CHANGED
|
@@ -876,6 +876,26 @@ var CustomTools = class {
|
|
|
876
876
|
* This is just an in memory registry and is not persisted.
|
|
877
877
|
* @param {CustomToolOptions} toolOptions CustomToolOptions
|
|
878
878
|
* @returns {Tool} The tool created
|
|
879
|
+
*
|
|
880
|
+
* @example
|
|
881
|
+
* ```typescript
|
|
882
|
+
* // Create a custom tool with input parameters
|
|
883
|
+
* const customTool = await composio.customTools.createTool({
|
|
884
|
+
* name: 'My Custom Tool',
|
|
885
|
+
* description: 'A tool that performs a custom operation',
|
|
886
|
+
* slug: 'MY_CUSTOM_TOOL',
|
|
887
|
+
* inputParams: z.object({
|
|
888
|
+
* query: z.string().describe('The search query'),
|
|
889
|
+
* limit: z.number().optional().describe('Maximum number of results')
|
|
890
|
+
* }),
|
|
891
|
+
* execute: async (input, authCredentials, executeToolRequest) => {
|
|
892
|
+
* // Custom implementation logic
|
|
893
|
+
* return {
|
|
894
|
+
* data: { results: ['result1', 'result2'] }
|
|
895
|
+
* };
|
|
896
|
+
* }
|
|
897
|
+
* });
|
|
898
|
+
* ```
|
|
879
899
|
*/
|
|
880
900
|
async createTool(toolOptions) {
|
|
881
901
|
const { slug, execute, inputParams, name, description } = toolOptions;
|
|
@@ -916,6 +936,17 @@ var CustomTools = class {
|
|
|
916
936
|
* Get all the custom tools from the registry.
|
|
917
937
|
* @param {string[]} param0.toolSlugs The slugs of the tools to get
|
|
918
938
|
* @returns {ToolList} The list of tools
|
|
939
|
+
*
|
|
940
|
+
* @example
|
|
941
|
+
* ```typescript
|
|
942
|
+
* // Get all custom tools
|
|
943
|
+
* const allTools = await composio.customTools.getCustomTools({});
|
|
944
|
+
*
|
|
945
|
+
* // Get specific custom tools by slug
|
|
946
|
+
* const specificTools = await composio.customTools.getCustomTools({
|
|
947
|
+
* toolSlugs: ['MY_CUSTOM_TOOL', 'ANOTHER_CUSTOM_TOOL']
|
|
948
|
+
* });
|
|
949
|
+
* ```
|
|
919
950
|
*/
|
|
920
951
|
async getCustomTools({ toolSlugs }) {
|
|
921
952
|
const tools = [];
|
|
@@ -935,6 +966,17 @@ var CustomTools = class {
|
|
|
935
966
|
* Get a custom tool by slug from the registry.
|
|
936
967
|
* @param {string} slug The slug of the tool to get
|
|
937
968
|
* @returns {Tool} The tool
|
|
969
|
+
*
|
|
970
|
+
* @example
|
|
971
|
+
* ```typescript
|
|
972
|
+
* // Get a specific custom tool by its slug
|
|
973
|
+
* const myTool = await composio.customTools.getCustomToolBySlug('MY_CUSTOM_TOOL');
|
|
974
|
+
* if (myTool) {
|
|
975
|
+
* console.log(`Found tool: ${myTool.name}`);
|
|
976
|
+
* } else {
|
|
977
|
+
* console.log('Tool not found');
|
|
978
|
+
* }
|
|
979
|
+
* ```
|
|
938
980
|
*/
|
|
939
981
|
async getCustomToolBySlug(slug) {
|
|
940
982
|
if (!slug) {
|
|
@@ -1491,9 +1533,16 @@ var Tools = class {
|
|
|
1491
1533
|
/**
|
|
1492
1534
|
* Fetches the list of all available tools in the Composio SDK.
|
|
1493
1535
|
*
|
|
1494
|
-
* This method is mostly used by the CLI
|
|
1536
|
+
* This method is mostly used by the CLI to get the list of tools.
|
|
1495
1537
|
* No filtering is done on the tools, the list is cached in the backend, no further optimization is required.
|
|
1496
|
-
* @returns {
|
|
1538
|
+
* @returns {Promise<ToolRetrieveEnumResponse>} The complete list of all available tools with their metadata
|
|
1539
|
+
*
|
|
1540
|
+
* @example
|
|
1541
|
+
* ```typescript
|
|
1542
|
+
* // Get all available tools as an enum
|
|
1543
|
+
* const toolsEnum = await composio.tools.getToolsEnum();
|
|
1544
|
+
* console.log(toolsEnum.items);
|
|
1545
|
+
* ```
|
|
1497
1546
|
*/
|
|
1498
1547
|
async getToolsEnum() {
|
|
1499
1548
|
return this.client.tools.retrieveEnum();
|
|
@@ -1505,15 +1554,42 @@ var Tools = class {
|
|
|
1505
1554
|
*
|
|
1506
1555
|
* @param {string} slug - The ID of the tool to find input for
|
|
1507
1556
|
* @param {ToolGetInputParams} body - The parameters to be passed to the tool
|
|
1508
|
-
* @returns
|
|
1557
|
+
* @returns {Promise<ToolGetInputResponse>} The input parameters schema for the specified tool
|
|
1558
|
+
*
|
|
1559
|
+
* @example
|
|
1560
|
+
* ```typescript
|
|
1561
|
+
* // Get input parameters for a specific tool
|
|
1562
|
+
* const inputParams = await composio.tools.getInput('GITHUB_CREATE_ISSUE', {
|
|
1563
|
+
* userId: 'default'
|
|
1564
|
+
* });
|
|
1565
|
+
* console.log(inputParams.schema);
|
|
1566
|
+
* ```
|
|
1509
1567
|
*/
|
|
1510
1568
|
async getInput(slug, body) {
|
|
1511
1569
|
return this.client.tools.getInput(slug, body);
|
|
1512
1570
|
}
|
|
1513
1571
|
/**
|
|
1514
|
-
* Proxies a custom request to a toolkit/integration
|
|
1515
|
-
*
|
|
1516
|
-
*
|
|
1572
|
+
* Proxies a custom request to a toolkit/integration.
|
|
1573
|
+
*
|
|
1574
|
+
* This method allows sending custom requests to a specific toolkit or integration
|
|
1575
|
+
* when you need more flexibility than the standard tool execution methods provide.
|
|
1576
|
+
*
|
|
1577
|
+
* @param {ToolProxyParams} body - The parameters for the proxy request including toolkit slug and custom data
|
|
1578
|
+
* @returns {Promise<ToolProxyResponse>} The response from the proxied request
|
|
1579
|
+
*
|
|
1580
|
+
* @example
|
|
1581
|
+
* ```typescript
|
|
1582
|
+
* // Send a custom request to a toolkit
|
|
1583
|
+
* const response = await composio.tools.proxyExecute({
|
|
1584
|
+
* toolkitSlug: 'github',
|
|
1585
|
+
* userId: 'default',
|
|
1586
|
+
* data: {
|
|
1587
|
+
* endpoint: '/repos/owner/repo/issues',
|
|
1588
|
+
* method: 'GET'
|
|
1589
|
+
* }
|
|
1590
|
+
* });
|
|
1591
|
+
* console.log(response.data);
|
|
1592
|
+
* ```
|
|
1517
1593
|
*/
|
|
1518
1594
|
async proxyExecute(body) {
|
|
1519
1595
|
return this.client.tools.proxy(body);
|
|
@@ -2630,8 +2706,21 @@ var ConnectedAccounts = class {
|
|
|
2630
2706
|
* Update the status of a connected account
|
|
2631
2707
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
2632
2708
|
* @param {ConnectedAccountUpdateStatusParams} params - Parameters for updating the status
|
|
2633
|
-
* @param {RequestOptions} options - Request options
|
|
2634
2709
|
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
2710
|
+
*
|
|
2711
|
+
* @example
|
|
2712
|
+
* ```typescript
|
|
2713
|
+
* // Enable a connected account
|
|
2714
|
+
* const updatedAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
2715
|
+
* enabled: true
|
|
2716
|
+
* });
|
|
2717
|
+
*
|
|
2718
|
+
* // Disable a connected account with a reason
|
|
2719
|
+
* const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
2720
|
+
* enabled: false,
|
|
2721
|
+
* reason: 'Token expired'
|
|
2722
|
+
* });
|
|
2723
|
+
* ```
|
|
2635
2724
|
*/
|
|
2636
2725
|
async updateStatus(nanoid, params) {
|
|
2637
2726
|
return this.client.connectedAccounts.updateStatus(nanoid, params);
|
|
@@ -2639,8 +2728,14 @@ var ConnectedAccounts = class {
|
|
|
2639
2728
|
/**
|
|
2640
2729
|
* Enable a connected account
|
|
2641
2730
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
2642
|
-
* @param {RequestOptions} options - Request options
|
|
2643
2731
|
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
2732
|
+
*
|
|
2733
|
+
* @example
|
|
2734
|
+
* ```typescript
|
|
2735
|
+
* // Enable a previously disabled connected account
|
|
2736
|
+
* const enabledAccount = await composio.connectedAccounts.enable('conn_abc123');
|
|
2737
|
+
* console.log(enabledAccount.isDisabled); // false
|
|
2738
|
+
* ```
|
|
2644
2739
|
*/
|
|
2645
2740
|
async enable(nanoid) {
|
|
2646
2741
|
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: true });
|
|
@@ -2648,8 +2743,20 @@ var ConnectedAccounts = class {
|
|
|
2648
2743
|
/**
|
|
2649
2744
|
* Disable a connected account
|
|
2650
2745
|
* @param {string} nanoid - Unique identifier of the connected account
|
|
2651
|
-
* @param {RequestOptions} options - Request options
|
|
2652
2746
|
* @returns {Promise<ConnectedAccountUpdateStatusResponse>} Updated connected account details
|
|
2747
|
+
*
|
|
2748
|
+
* @example
|
|
2749
|
+
* ```typescript
|
|
2750
|
+
* // Disable a connected account
|
|
2751
|
+
* const disabledAccount = await composio.connectedAccounts.disable('conn_abc123');
|
|
2752
|
+
* console.log(disabledAccount.isDisabled); // true
|
|
2753
|
+
*
|
|
2754
|
+
* // You can also use updateStatus with a reason
|
|
2755
|
+
* // const disabledAccount = await composio.connectedAccounts.updateStatus('conn_abc123', {
|
|
2756
|
+
* // enabled: false,
|
|
2757
|
+
* // reason: 'No longer needed'
|
|
2758
|
+
* // });
|
|
2759
|
+
* ```
|
|
2653
2760
|
*/
|
|
2654
2761
|
async disable(nanoid) {
|
|
2655
2762
|
return this.client.connectedAccounts.updateStatus(nanoid, { enabled: false });
|
|
@@ -3626,10 +3733,54 @@ var BaseAgenticProvider = class extends BaseProvider {
|
|
|
3626
3733
|
var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
3627
3734
|
name = "openai";
|
|
3628
3735
|
/**
|
|
3629
|
-
*
|
|
3630
|
-
*
|
|
3631
|
-
*
|
|
3632
|
-
*
|
|
3736
|
+
* Creates a new instance of the OpenAIProvider.
|
|
3737
|
+
*
|
|
3738
|
+
* This is the default provider for the Composio SDK and is automatically
|
|
3739
|
+
* available without additional installation.
|
|
3740
|
+
*
|
|
3741
|
+
* @example
|
|
3742
|
+
* ```typescript
|
|
3743
|
+
* // The OpenAIProvider is used by default when initializing Composio
|
|
3744
|
+
* const composio = new Composio({
|
|
3745
|
+
* apiKey: 'your-api-key'
|
|
3746
|
+
* });
|
|
3747
|
+
*
|
|
3748
|
+
* // You can also explicitly specify it
|
|
3749
|
+
* const composio = new Composio({
|
|
3750
|
+
* apiKey: 'your-api-key',
|
|
3751
|
+
* provider: new OpenAIProvider()
|
|
3752
|
+
* });
|
|
3753
|
+
* ```
|
|
3754
|
+
*/
|
|
3755
|
+
constructor() {
|
|
3756
|
+
super();
|
|
3757
|
+
}
|
|
3758
|
+
/**
|
|
3759
|
+
* Wraps a Composio tool in the OpenAI function calling format.
|
|
3760
|
+
*
|
|
3761
|
+
* This method transforms a Composio tool definition into the format
|
|
3762
|
+
* expected by OpenAI's function calling API.
|
|
3763
|
+
*
|
|
3764
|
+
* @param tool - The Composio tool to wrap
|
|
3765
|
+
* @returns The wrapped tool in OpenAI format
|
|
3766
|
+
*
|
|
3767
|
+
* @example
|
|
3768
|
+
* ```typescript
|
|
3769
|
+
* // Wrap a single tool for use with OpenAI
|
|
3770
|
+
* const composioTool = {
|
|
3771
|
+
* slug: 'SEARCH_TOOL',
|
|
3772
|
+
* description: 'Search for information',
|
|
3773
|
+
* inputParameters: {
|
|
3774
|
+
* type: 'object',
|
|
3775
|
+
* properties: {
|
|
3776
|
+
* query: { type: 'string' }
|
|
3777
|
+
* },
|
|
3778
|
+
* required: ['query']
|
|
3779
|
+
* }
|
|
3780
|
+
* };
|
|
3781
|
+
*
|
|
3782
|
+
* const openAITool = provider.wrapTool(composioTool);
|
|
3783
|
+
* ```
|
|
3633
3784
|
*/
|
|
3634
3785
|
wrapTool = (tool) => {
|
|
3635
3786
|
const formattedSchema = {
|
|
@@ -3642,14 +3793,78 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3642
3793
|
function: formattedSchema
|
|
3643
3794
|
};
|
|
3644
3795
|
};
|
|
3796
|
+
/**
|
|
3797
|
+
* Wraps multiple Composio tools in the OpenAI function calling format.
|
|
3798
|
+
*
|
|
3799
|
+
* This method transforms a list of Composio tools into the format
|
|
3800
|
+
* expected by OpenAI's function calling API.
|
|
3801
|
+
*
|
|
3802
|
+
* @param tools - Array of Composio tools to wrap
|
|
3803
|
+
* @returns Array of wrapped tools in OpenAI format
|
|
3804
|
+
*
|
|
3805
|
+
* @example
|
|
3806
|
+
* ```typescript
|
|
3807
|
+
* // Wrap multiple tools for use with OpenAI
|
|
3808
|
+
* const composioTools = [
|
|
3809
|
+
* {
|
|
3810
|
+
* slug: 'SEARCH_TOOL',
|
|
3811
|
+
* description: 'Search for information',
|
|
3812
|
+
* inputParameters: {
|
|
3813
|
+
* type: 'object',
|
|
3814
|
+
* properties: {
|
|
3815
|
+
* query: { type: 'string' }
|
|
3816
|
+
* }
|
|
3817
|
+
* }
|
|
3818
|
+
* },
|
|
3819
|
+
* {
|
|
3820
|
+
* slug: 'WEATHER_TOOL',
|
|
3821
|
+
* description: 'Get weather information',
|
|
3822
|
+
* inputParameters: {
|
|
3823
|
+
* type: 'object',
|
|
3824
|
+
* properties: {
|
|
3825
|
+
* location: { type: 'string' }
|
|
3826
|
+
* }
|
|
3827
|
+
* }
|
|
3828
|
+
* }
|
|
3829
|
+
* ];
|
|
3830
|
+
*
|
|
3831
|
+
* const openAITools = provider.wrapTools(composioTools);
|
|
3832
|
+
* ```
|
|
3833
|
+
*/
|
|
3645
3834
|
wrapTools = (tools) => {
|
|
3646
3835
|
return tools.map((tool) => this.wrapTool(tool));
|
|
3647
3836
|
};
|
|
3648
3837
|
/**
|
|
3649
|
-
*
|
|
3650
|
-
*
|
|
3651
|
-
*
|
|
3652
|
-
*
|
|
3838
|
+
* Executes a tool call from OpenAI's chat completion.
|
|
3839
|
+
*
|
|
3840
|
+
* This method processes a tool call from OpenAI's chat completion API,
|
|
3841
|
+
* executes the corresponding Composio tool, and returns the result.
|
|
3842
|
+
*
|
|
3843
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
3844
|
+
* @param {OpenAI.ChatCompletionMessageToolCall} tool - The tool call from OpenAI
|
|
3845
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
3846
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
3847
|
+
* @returns {Promise<string>} The result of the tool call as a JSON string
|
|
3848
|
+
*
|
|
3849
|
+
* @example
|
|
3850
|
+
* ```typescript
|
|
3851
|
+
* // Execute a tool call from OpenAI
|
|
3852
|
+
* const toolCall = {
|
|
3853
|
+
* id: 'call_abc123',
|
|
3854
|
+
* type: 'function',
|
|
3855
|
+
* function: {
|
|
3856
|
+
* name: 'SEARCH_TOOL',
|
|
3857
|
+
* arguments: '{"query":"composio documentation"}'
|
|
3858
|
+
* }
|
|
3859
|
+
* };
|
|
3860
|
+
*
|
|
3861
|
+
* const result = await provider.executeToolCall(
|
|
3862
|
+
* 'user123',
|
|
3863
|
+
* toolCall,
|
|
3864
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
3865
|
+
* );
|
|
3866
|
+
* console.log(JSON.parse(result));
|
|
3867
|
+
* ```
|
|
3653
3868
|
*/
|
|
3654
3869
|
async executeToolCall(userId, tool, options, modifiers) {
|
|
3655
3870
|
const payload = {
|
|
@@ -3662,11 +3877,46 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3662
3877
|
return JSON.stringify(result);
|
|
3663
3878
|
}
|
|
3664
3879
|
/**
|
|
3665
|
-
*
|
|
3880
|
+
* Handles tool calls from OpenAI's chat completion response.
|
|
3666
3881
|
*
|
|
3667
|
-
*
|
|
3668
|
-
*
|
|
3669
|
-
*
|
|
3882
|
+
* This method processes tool calls from an OpenAI chat completion response,
|
|
3883
|
+
* executes each tool call, and returns the results.
|
|
3884
|
+
*
|
|
3885
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
3886
|
+
* @param {OpenAI.ChatCompletion} chatCompletion - The chat completion response from OpenAI
|
|
3887
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
3888
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
3889
|
+
* @returns {Promise<string[]>} Array of tool execution results as JSON strings
|
|
3890
|
+
*
|
|
3891
|
+
* @example
|
|
3892
|
+
* ```typescript
|
|
3893
|
+
* // Handle tool calls from a chat completion response
|
|
3894
|
+
* const chatCompletion = {
|
|
3895
|
+
* choices: [
|
|
3896
|
+
* {
|
|
3897
|
+
* message: {
|
|
3898
|
+
* tool_calls: [
|
|
3899
|
+
* {
|
|
3900
|
+
* id: 'call_abc123',
|
|
3901
|
+
* type: 'function',
|
|
3902
|
+
* function: {
|
|
3903
|
+
* name: 'SEARCH_TOOL',
|
|
3904
|
+
* arguments: '{"query":"composio documentation"}'
|
|
3905
|
+
* }
|
|
3906
|
+
* }
|
|
3907
|
+
* ]
|
|
3908
|
+
* }
|
|
3909
|
+
* }
|
|
3910
|
+
* ]
|
|
3911
|
+
* };
|
|
3912
|
+
*
|
|
3913
|
+
* const results = await provider.handleToolCalls(
|
|
3914
|
+
* 'user123',
|
|
3915
|
+
* chatCompletion,
|
|
3916
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
3917
|
+
* );
|
|
3918
|
+
* console.log(results); // Array of tool execution results
|
|
3919
|
+
* ```
|
|
3670
3920
|
*/
|
|
3671
3921
|
async handleToolCalls(userId, chatCompletion, options, modifiers) {
|
|
3672
3922
|
const outputs = [];
|
|
@@ -3680,11 +3930,51 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3680
3930
|
return outputs;
|
|
3681
3931
|
}
|
|
3682
3932
|
/**
|
|
3683
|
-
* Handles all the tool calls from the
|
|
3933
|
+
* Handles all the tool calls from the OpenAI Assistant API.
|
|
3684
3934
|
*
|
|
3685
|
-
*
|
|
3686
|
-
*
|
|
3687
|
-
*
|
|
3935
|
+
* This method processes tool calls from an OpenAI Assistant run,
|
|
3936
|
+
* executes each tool call, and returns the tool outputs for submission.
|
|
3937
|
+
*
|
|
3938
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
3939
|
+
* @param {OpenAI.Beta.Threads.Run} run - The Assistant run object containing tool calls
|
|
3940
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
3941
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
3942
|
+
* @returns {Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>} Array of tool outputs for submission
|
|
3943
|
+
*
|
|
3944
|
+
* @example
|
|
3945
|
+
* ```typescript
|
|
3946
|
+
* // Handle tool calls from an OpenAI Assistant run
|
|
3947
|
+
* const run = {
|
|
3948
|
+
* id: 'run_abc123',
|
|
3949
|
+
* required_action: {
|
|
3950
|
+
* submit_tool_outputs: {
|
|
3951
|
+
* tool_calls: [
|
|
3952
|
+
* {
|
|
3953
|
+
* id: 'call_xyz789',
|
|
3954
|
+
* type: 'function',
|
|
3955
|
+
* function: {
|
|
3956
|
+
* name: 'SEARCH_TOOL',
|
|
3957
|
+
* arguments: '{"query":"composio documentation"}'
|
|
3958
|
+
* }
|
|
3959
|
+
* }
|
|
3960
|
+
* ]
|
|
3961
|
+
* }
|
|
3962
|
+
* }
|
|
3963
|
+
* };
|
|
3964
|
+
*
|
|
3965
|
+
* const toolOutputs = await provider.handleAssistantMessage(
|
|
3966
|
+
* 'user123',
|
|
3967
|
+
* run,
|
|
3968
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
3969
|
+
* );
|
|
3970
|
+
*
|
|
3971
|
+
* // Submit tool outputs back to OpenAI
|
|
3972
|
+
* await openai.beta.threads.runs.submitToolOutputs(
|
|
3973
|
+
* thread.id,
|
|
3974
|
+
* run.id,
|
|
3975
|
+
* { tool_outputs: toolOutputs }
|
|
3976
|
+
* );
|
|
3977
|
+
* ```
|
|
3688
3978
|
*/
|
|
3689
3979
|
async handleAssistantMessage(userId, run, options, modifiers) {
|
|
3690
3980
|
const tool_calls = run.required_action?.submit_tool_outputs?.tool_calls || [];
|
|
@@ -3709,11 +3999,43 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3709
3999
|
/**
|
|
3710
4000
|
* Waits for the assistant stream and handles the tool calls.
|
|
3711
4001
|
*
|
|
3712
|
-
*
|
|
3713
|
-
*
|
|
3714
|
-
*
|
|
3715
|
-
*
|
|
3716
|
-
* @
|
|
4002
|
+
* This method processes an OpenAI Assistant stream, handles any tool calls
|
|
4003
|
+
* that require action, and yields each event from the stream. It's designed
|
|
4004
|
+
* for streaming Assistant responses while handling tool calls in real-time.
|
|
4005
|
+
*
|
|
4006
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
4007
|
+
* @param {OpenAI} client - The OpenAI client instance
|
|
4008
|
+
* @param {Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>} runStream - The Assistant run stream
|
|
4009
|
+
* @param {OpenAI.Beta.Threads.Thread} thread - The thread object
|
|
4010
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
4011
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
4012
|
+
* @returns {AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>} Generator yielding stream events
|
|
4013
|
+
*
|
|
4014
|
+
* @example
|
|
4015
|
+
* ```typescript
|
|
4016
|
+
* // Process an OpenAI Assistant stream with tool calls
|
|
4017
|
+
* const thread = await openai.beta.threads.create();
|
|
4018
|
+
* const runStream = openai.beta.threads.runs.stream(thread.id, {
|
|
4019
|
+
* assistant_id: 'asst_abc123',
|
|
4020
|
+
* tools: provider.wrapTools(composioTools)
|
|
4021
|
+
* });
|
|
4022
|
+
*
|
|
4023
|
+
* // Process the stream and handle tool calls
|
|
4024
|
+
* const streamProcessor = provider.waitAndHandleAssistantStreamToolCalls(
|
|
4025
|
+
* 'user123',
|
|
4026
|
+
* openai,
|
|
4027
|
+
* runStream,
|
|
4028
|
+
* thread,
|
|
4029
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
4030
|
+
* );
|
|
4031
|
+
*
|
|
4032
|
+
* // Consume the stream events
|
|
4033
|
+
* for await (const event of streamProcessor) {
|
|
4034
|
+
* if (event.event === 'thread.message.delta') {
|
|
4035
|
+
* console.log(event.data.delta.content);
|
|
4036
|
+
* }
|
|
4037
|
+
* }
|
|
4038
|
+
* ```
|
|
3717
4039
|
*/
|
|
3718
4040
|
async *waitAndHandleAssistantStreamToolCalls(userId, client, runStream, thread, options, modifiers) {
|
|
3719
4041
|
let runId = null;
|
|
@@ -3765,11 +4087,45 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3765
4087
|
/**
|
|
3766
4088
|
* Waits for the assistant tool calls and handles them.
|
|
3767
4089
|
*
|
|
3768
|
-
*
|
|
3769
|
-
*
|
|
3770
|
-
*
|
|
3771
|
-
*
|
|
3772
|
-
* @
|
|
4090
|
+
* This method polls an OpenAI Assistant run until it completes or requires action,
|
|
4091
|
+
* handles any tool calls, and returns the final run object. It's designed for
|
|
4092
|
+
* non-streaming Assistant interactions.
|
|
4093
|
+
*
|
|
4094
|
+
* @param {string} userId - The user ID for authentication and tracking
|
|
4095
|
+
* @param {OpenAI} client - The OpenAI client instance
|
|
4096
|
+
* @param {OpenAI.Beta.Threads.Run} run - The initial run object
|
|
4097
|
+
* @param {OpenAI.Beta.Threads.Thread} thread - The thread object
|
|
4098
|
+
* @param {ExecuteToolFnOptions} [options] - Optional execution options
|
|
4099
|
+
* @param {ExecuteToolModifiers} [modifiers] - Optional execution modifiers
|
|
4100
|
+
* @returns {Promise<OpenAI.Beta.Threads.Run>} The final run object after completion
|
|
4101
|
+
*
|
|
4102
|
+
* @example
|
|
4103
|
+
* ```typescript
|
|
4104
|
+
* // Process an OpenAI Assistant run with tool calls
|
|
4105
|
+
* const thread = await openai.beta.threads.create();
|
|
4106
|
+
* await openai.beta.threads.messages.create(thread.id, {
|
|
4107
|
+
* role: 'user',
|
|
4108
|
+
* content: 'Find information about Composio'
|
|
4109
|
+
* });
|
|
4110
|
+
*
|
|
4111
|
+
* let run = await openai.beta.threads.runs.create(thread.id, {
|
|
4112
|
+
* assistant_id: 'asst_abc123',
|
|
4113
|
+
* tools: provider.wrapTools(composioTools)
|
|
4114
|
+
* });
|
|
4115
|
+
*
|
|
4116
|
+
* // Wait for the run to complete, handling any tool calls
|
|
4117
|
+
* run = await provider.waitAndHandleAssistantToolCalls(
|
|
4118
|
+
* 'user123',
|
|
4119
|
+
* openai,
|
|
4120
|
+
* run,
|
|
4121
|
+
* thread,
|
|
4122
|
+
* { connectedAccountId: 'conn_xyz456' }
|
|
4123
|
+
* );
|
|
4124
|
+
*
|
|
4125
|
+
* // Get the final messages after run completion
|
|
4126
|
+
* const messages = await openai.beta.threads.messages.list(thread.id);
|
|
4127
|
+
* console.log(messages.data[0].content);
|
|
4128
|
+
* ```
|
|
3773
4129
|
*/
|
|
3774
4130
|
async waitAndHandleAssistantToolCalls(userId, client, run, thread, options, modifiers) {
|
|
3775
4131
|
while (["queued", "in_progress", "requires_action"].includes(run.status)) {
|
|
@@ -3788,7 +4144,7 @@ var OpenAIProvider = class extends BaseNonAgenticProvider {
|
|
|
3788
4144
|
};
|
|
3789
4145
|
|
|
3790
4146
|
// package.json
|
|
3791
|
-
var version = "0.1.12-alpha.
|
|
4147
|
+
var version = "0.1.12-alpha.15";
|
|
3792
4148
|
|
|
3793
4149
|
// src/composio.ts
|
|
3794
4150
|
var Composio = class {
|
|
@@ -3814,13 +4170,36 @@ var Composio = class {
|
|
|
3814
4170
|
// connected accounts
|
|
3815
4171
|
connectedAccounts;
|
|
3816
4172
|
/**
|
|
3817
|
-
*
|
|
3818
|
-
*
|
|
3819
|
-
*
|
|
3820
|
-
*
|
|
3821
|
-
*
|
|
3822
|
-
* @param {
|
|
3823
|
-
* @param {
|
|
4173
|
+
* Creates a new instance of the Composio SDK.
|
|
4174
|
+
*
|
|
4175
|
+
* The constructor initializes the SDK with the provided configuration options,
|
|
4176
|
+
* sets up the API client, and initializes all core models (tools, toolkits, etc.).
|
|
4177
|
+
*
|
|
4178
|
+
* @param {ComposioConfig<TProvider>} config - Configuration options for the Composio SDK
|
|
4179
|
+
* @param {string} [config.apiKey] - The API key for authenticating with the Composio API
|
|
4180
|
+
* @param {string} [config.baseURL] - The base URL for the Composio API (defaults to production URL)
|
|
4181
|
+
* @param {boolean} [config.allowTracking=true] - Whether to allow anonymous usage analytics
|
|
4182
|
+
* @param {boolean} [config.allowTracing=true] - Whether to allow request tracing for debugging
|
|
4183
|
+
* @param {TProvider} [config.provider] - The provider to use for this Composio instance (defaults to OpenAIProvider)
|
|
4184
|
+
* @param {BaseTelemetryTransport} [config.telemetryTransport] - Custom telemetry transport implementation
|
|
4185
|
+
*
|
|
4186
|
+
* @example
|
|
4187
|
+
* ```typescript
|
|
4188
|
+
* // Initialize with default configuration
|
|
4189
|
+
* const composio = new Composio();
|
|
4190
|
+
*
|
|
4191
|
+
* // Initialize with custom API key and base URL
|
|
4192
|
+
* const composio = new Composio({
|
|
4193
|
+
* apiKey: 'your-api-key',
|
|
4194
|
+
* baseURL: 'https://api.composio.dev'
|
|
4195
|
+
* });
|
|
4196
|
+
*
|
|
4197
|
+
* // Initialize with custom provider
|
|
4198
|
+
* const composio = new Composio({
|
|
4199
|
+
* apiKey: 'your-api-key',
|
|
4200
|
+
* provider: new CustomProvider()
|
|
4201
|
+
* });
|
|
4202
|
+
* ```
|
|
3824
4203
|
*/
|
|
3825
4204
|
constructor(config) {
|
|
3826
4205
|
const { baseURL: baseURLParsed, apiKey: apiKeyParsed } = getSDKConfig(
|