Skip to content

Commit 27df7e5

Browse files
fix: type typo and getTools w custom action (#1121)
1 parent 33beb02 commit 27df7e5

File tree

8 files changed

+48
-23
lines changed

8 files changed

+48
-23
lines changed

js/examples/e2e/demo.mjs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,32 @@
11
import { Composio, LangchainToolSet } from "composio-core";
22
import { z } from "zod";
33

4-
const toolset = new LangchainToolSet();
4+
const toolset = new LangchainToolSet({});
55

66
(async() => {
77
console.log("Creating action");
8+
try {
89
await toolset.createAction({
910
actionName: "helloWorld",
1011
description: "This is a test action for handling hello world",
11-
params: z.object({
12+
inputParams: z.object({
1213
name: z.string().optional()
1314
}),
1415
callback: async (params) => {
1516
const { name } = params;
16-
return `Hello ${name || "World"} from the function`;
17+
return {
18+
successful: true,
19+
data: {
20+
name: name || "World"
21+
}
22+
}
1723
}
1824
});
19-
console.log("Tools are registered", await toolset.getTools({actions: ["helloWorld"]}));
2025

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+
}
2432
})();

js/examples/e2e/demo.ts

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,32 @@
1-
21
import { Composio, LangchainToolSet } from "composio-core";
2+
import { z } from "zod";
33

44
const toolset = new LangchainToolSet();
55

66
(async() => {
77
console.log("Creating action");
8+
try {
89
await toolset.createAction({
910
actionName: "helloWorld",
1011
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+
}
1323
}
1424
});
1525

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+
})();

js/src/frameworks/langchain.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ describe("Apps class tests", () => {
6060
},
6161
});
6262

63+
langchainToolSet.getTools({
64+
actions: ["starRepositoryCustomAction"],
65+
});
66+
6367
const actionOuput = await langchainToolSet.executeAction({
6468
action: "starRepositoryCustomAction",
6569
params: {

js/src/frameworks/langchain.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export class LangchainToolSet extends BaseComposioToolSet {
6969
}
7070

7171
async getTools(
72-
filters: z.infer<typeof ZToolSchemaFilter>,
72+
filters: z.infer<typeof ZToolSchemaFilter> = {},
7373
entityId: Optional<string> = null
7474
): Promise<Sequence<DynamicStructuredTool>> {
7575
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {

js/src/sdk/actionRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class ActionRegistry {
135135
throw new Error(`Action with name ${name} could not be retrieved`);
136136
}
137137

138-
const { callback, toolName } = action.metadata;
138+
const { callback, toolName } = action.metadata || {};
139139
let authCredentials = {};
140140
if (toolName) {
141141
const entity = await this.client.getEntity(metadata.entityId);

js/src/sdk/base.toolset.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,15 @@ export class ComposioToolSet {
141141
const toolsWithCustomActions = (
142142
await this.userActionRegistry.getAllActions()
143143
).filter((action) => {
144-
const { actionName, toolName } = action.metadata;
144+
const { name: actionName, toolName } = action.metadata || {};
145145
return (
146146
(!filters.actions ||
147147
filters.actions.some(
148-
(name) => name.toLowerCase() === actionName!.toLowerCase()
148+
(name) => name.toLowerCase() === actionName?.toLowerCase()
149149
)) &&
150150
(!filters.apps ||
151151
filters.apps.some(
152-
(name) => name.toLowerCase() === toolName!.toLowerCase()
152+
(name) => name.toLowerCase() === toolName?.toLowerCase()
153153
)) &&
154154
(!filters.tags ||
155155
filters.tags.some((tag) => tag.toLowerCase() === "custom"))

js/src/sdk/models/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { BackendClient } from "./backendClient";
2626
export type ActionListParams = z.infer<typeof ZGetListActionsParams>;
2727
export type HeaderSingleParameters = z.infer<typeof ZParameter>;
2828
export type CustomAuth = z.infer<typeof ZCustomAuthParams>;
29-
export type ActionxExecuteParam = z.infer<typeof ZExecuteParams>;
29+
export type ActionExecuteParam = z.infer<typeof ZExecuteParams>;
3030
export type ActionItemParam = z.infer<typeof ZActionGetParams>;
3131
export type FindActionEnumsByUseCaseParam = z.infer<
3232
typeof ZFindActionEnumsByUseCaseParams
@@ -142,7 +142,7 @@ export class Actions {
142142
* @returns {Promise<ActionExecuteResponse>} A promise that resolves to the execution status and response data.
143143
* @throws {ComposioError} If the request fails.
144144
*/
145-
async execute(data: ActionxExecuteParam): Promise<ActionExecuteResponse> {
145+
async execute(data: ActionExecuteParam): Promise<ActionExecuteResponse> {
146146
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
147147
method: "execute",
148148
file: this.fileName,

js/src/types/base_toolset.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ export const ZRawActionSchema = z.object({
2424
}),
2525
response: z.record(z.any()),
2626
metadata: z.object({
27-
actionName: z.string(),
28-
toolName: z.string(),
27+
name: z.string(),
28+
toolName: z.string().optional(),
2929
}),
3030
});
3131

0 commit comments

Comments
 (0)