File tree Expand file tree Collapse file tree 8 files changed +48
-23
lines changed Expand file tree Collapse file tree 8 files changed +48
-23
lines changed Original file line number Diff line number Diff line change 1
1
import { Composio , LangchainToolSet } from "composio-core" ;
2
2
import { z } from "zod" ;
3
3
4
- const toolset = new LangchainToolSet ( ) ;
4
+ const toolset = new LangchainToolSet ( { } ) ;
5
5
6
6
( async ( ) => {
7
7
console . log ( "Creating action" ) ;
8
+ try {
8
9
await toolset . createAction ( {
9
10
actionName : "helloWorld" ,
10
11
description : "This is a test action for handling hello world" ,
11
- params : z . object ( {
12
+ inputParams : z . object ( {
12
13
name : z . string ( ) . optional ( )
13
14
} ) ,
14
15
callback : async ( params ) => {
15
16
const { name } = params ;
16
- return `Hello ${ name || "World" } from the function` ;
17
+ return {
18
+ successful : true ,
19
+ data : {
20
+ name : name || "World"
21
+ }
22
+ }
17
23
}
18
24
} ) ;
19
- console . log ( "Tools are registered" , await toolset . getTools ( { actions : [ "helloWorld" ] } ) ) ;
20
25
21
- // Sending params to the action
22
- const result = await toolset . executeAction ( "helloWorld" , { name : "Alice" } , { } ) ;
23
- console . log ( "Action result:" , result ) ;
26
+ console . log ( "Tools are registered" , await toolset . getTools ( {
27
+ actions : [ "helloWorld" ]
28
+ } ) ) ;
29
+ } catch ( error ) {
30
+ console . error ( "Error creating action" , error ) ;
31
+ }
24
32
} ) ( ) ;
Original file line number Diff line number Diff line change 1
-
2
1
import { Composio , LangchainToolSet } from "composio-core" ;
2
+ import { z } from "zod" ;
3
3
4
4
const toolset = new LangchainToolSet ( ) ;
5
5
6
6
( async ( ) => {
7
7
console . log ( "Creating action" ) ;
8
+ try {
8
9
await toolset . createAction ( {
9
10
actionName : "helloWorld" ,
10
11
description : "This is a test action for handling hello world" ,
11
- callback : async ( ) => {
12
- return "Hello World from the function" ;
12
+ inputParams : z . object ( {
13
+ name : z . string ( ) . optional ( )
14
+ } ) ,
15
+ callback : async ( params ) => {
16
+ const { name } = params ;
17
+ return {
18
+ successful : true ,
19
+ data : {
20
+ name : name || "World"
21
+ }
22
+ }
13
23
}
14
24
} ) ;
15
25
16
- console . log ( "Tools are registered" , toolset . getTools ( ) ) ;
17
- } )
18
-
19
-
26
+ console . log ( "Tools are registered" , await toolset . getTools ( {
27
+ actions : [ "helloWorld" ]
28
+ } ) ) ;
29
+ } catch ( error ) {
30
+ console . error ( "Error creating action" , error ) ;
31
+ }
32
+ } ) ( ) ;
Original file line number Diff line number Diff line change @@ -60,6 +60,10 @@ describe("Apps class tests", () => {
60
60
} ,
61
61
} ) ;
62
62
63
+ langchainToolSet . getTools ( {
64
+ actions : [ "starRepositoryCustomAction" ] ,
65
+ } ) ;
66
+
63
67
const actionOuput = await langchainToolSet . executeAction ( {
64
68
action : "starRepositoryCustomAction" ,
65
69
params : {
Original file line number Diff line number Diff line change @@ -69,7 +69,7 @@ export class LangchainToolSet extends BaseComposioToolSet {
69
69
}
70
70
71
71
async getTools (
72
- filters : z . infer < typeof ZToolSchemaFilter > ,
72
+ filters : z . infer < typeof ZToolSchemaFilter > = { } ,
73
73
entityId : Optional < string > = null
74
74
) : Promise < Sequence < DynamicStructuredTool > > {
75
75
TELEMETRY_LOGGER . manualTelemetry ( TELEMETRY_EVENTS . SDK_METHOD_INVOKED , {
Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ export class ActionRegistry {
135
135
throw new Error ( `Action with name ${ name } could not be retrieved` ) ;
136
136
}
137
137
138
- const { callback, toolName } = action . metadata ;
138
+ const { callback, toolName } = action . metadata || { } ;
139
139
let authCredentials = { } ;
140
140
if ( toolName ) {
141
141
const entity = await this . client . getEntity ( metadata . entityId ) ;
Original file line number Diff line number Diff line change @@ -141,15 +141,15 @@ export class ComposioToolSet {
141
141
const toolsWithCustomActions = (
142
142
await this . userActionRegistry . getAllActions ( )
143
143
) . filter ( ( action ) => {
144
- const { actionName, toolName } = action . metadata ;
144
+ const { name : actionName , toolName } = action . metadata || { } ;
145
145
return (
146
146
( ! filters . actions ||
147
147
filters . actions . some (
148
- ( name ) => name . toLowerCase ( ) === actionName ! . toLowerCase ( )
148
+ ( name ) => name . toLowerCase ( ) === actionName ? .toLowerCase ( )
149
149
) ) &&
150
150
( ! filters . apps ||
151
151
filters . apps . some (
152
- ( name ) => name . toLowerCase ( ) === toolName ! . toLowerCase ( )
152
+ ( name ) => name . toLowerCase ( ) === toolName ? .toLowerCase ( )
153
153
) ) &&
154
154
( ! filters . tags ||
155
155
filters . tags . some ( ( tag ) => tag . toLowerCase ( ) === "custom" ) )
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ import { BackendClient } from "./backendClient";
26
26
export type ActionListParams = z . infer < typeof ZGetListActionsParams > ;
27
27
export type HeaderSingleParameters = z . infer < typeof ZParameter > ;
28
28
export type CustomAuth = z . infer < typeof ZCustomAuthParams > ;
29
- export type ActionxExecuteParam = z . infer < typeof ZExecuteParams > ;
29
+ export type ActionExecuteParam = z . infer < typeof ZExecuteParams > ;
30
30
export type ActionItemParam = z . infer < typeof ZActionGetParams > ;
31
31
export type FindActionEnumsByUseCaseParam = z . infer <
32
32
typeof ZFindActionEnumsByUseCaseParams
@@ -142,7 +142,7 @@ export class Actions {
142
142
* @returns {Promise<ActionExecuteResponse> } A promise that resolves to the execution status and response data.
143
143
* @throws {ComposioError } If the request fails.
144
144
*/
145
- async execute ( data : ActionxExecuteParam ) : Promise < ActionExecuteResponse > {
145
+ async execute ( data : ActionExecuteParam ) : Promise < ActionExecuteResponse > {
146
146
TELEMETRY_LOGGER . manualTelemetry ( TELEMETRY_EVENTS . SDK_METHOD_INVOKED , {
147
147
method : "execute" ,
148
148
file : this . fileName ,
Original file line number Diff line number Diff line change @@ -24,8 +24,8 @@ export const ZRawActionSchema = z.object({
24
24
} ) ,
25
25
response : z . record ( z . any ( ) ) ,
26
26
metadata : z . object ( {
27
- actionName : z . string ( ) ,
28
- toolName : z . string ( ) ,
27
+ name : z . string ( ) ,
28
+ toolName : z . string ( ) . optional ( ) ,
29
29
} ) ,
30
30
} ) ;
31
31
You can’t perform that action at this time.
0 commit comments