Skip to content

Commit

Permalink
Merge branch 'master' into ENG-3322
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar-composio authored Jan 2, 2025
2 parents 90f03e5 + 27df7e5 commit fd52d47
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 23 deletions.
22 changes: 15 additions & 7 deletions js/examples/e2e/demo.mjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import { Composio, LangchainToolSet } from "composio-core";
import { z } from "zod";

const toolset = new LangchainToolSet();
const toolset = new LangchainToolSet({});

(async() => {
console.log("Creating action");
try {
await toolset.createAction({
actionName: "helloWorld",
description: "This is a test action for handling hello world",
params: z.object({
inputParams: z.object({
name: z.string().optional()
}),
callback: async (params) => {
const { name } = params;
return `Hello ${name || "World"} from the function`;
return {
successful: true,
data: {
name: name || "World"
}
}
}
});
console.log("Tools are registered", await toolset.getTools({actions: ["helloWorld"]}));

// Sending params to the action
const result = await toolset.executeAction("helloWorld", { name: "Alice" }, {});
console.log("Action result:", result);
console.log("Tools are registered", await toolset.getTools({
actions: ["helloWorld"]
}));
} catch (error) {
console.error("Error creating action", error);
}
})();
27 changes: 20 additions & 7 deletions js/examples/e2e/demo.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,32 @@

import { Composio, LangchainToolSet } from "composio-core";
import { z } from "zod";

const toolset = new LangchainToolSet();

(async() => {
console.log("Creating action");
try {
await toolset.createAction({
actionName: "helloWorld",
description: "This is a test action for handling hello world",
callback: async () => {
return "Hello World from the function";
inputParams: z.object({
name: z.string().optional()
}),
callback: async (params) => {
const { name } = params;
return {
successful: true,
data: {
name: name || "World"
}
}
}
});

console.log("Tools are registered", toolset.getTools());
})


console.log("Tools are registered", await toolset.getTools({
actions: ["helloWorld"]
}));
} catch (error) {
console.error("Error creating action", error);
}
})();
4 changes: 4 additions & 0 deletions js/src/frameworks/langchain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ describe("Apps class tests", () => {
},
});

langchainToolSet.getTools({
actions: ["starRepositoryCustomAction"],
});

const actionOuput = await langchainToolSet.executeAction({
action: "starRepositoryCustomAction",
params: {
Expand Down
2 changes: 1 addition & 1 deletion js/src/frameworks/langchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class LangchainToolSet extends BaseComposioToolSet {
}

async getTools(
filters: z.infer<typeof ZToolSchemaFilter>,
filters: z.infer<typeof ZToolSchemaFilter> = {},
entityId: Optional<string> = null
): Promise<Sequence<DynamicStructuredTool>> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
Expand Down
2 changes: 1 addition & 1 deletion js/src/sdk/actionRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export class ActionRegistry {
throw new Error(`Action with name ${name} could not be retrieved`);
}

const { callback, toolName } = action.metadata;
const { callback, toolName } = action.metadata || {};
let authCredentials = {};
if (toolName) {
const entity = await this.client.getEntity(metadata.entityId);
Expand Down
6 changes: 3 additions & 3 deletions js/src/sdk/base.toolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ export class ComposioToolSet {
const toolsWithCustomActions = (
await this.userActionRegistry.getAllActions()
).filter((action) => {
const { actionName, toolName } = action.metadata;
const { name: actionName, toolName } = action.metadata || {};
return (
(!filters.actions ||
filters.actions.some(
(name) => name.toLowerCase() === actionName!.toLowerCase()
(name) => name.toLowerCase() === actionName?.toLowerCase()
)) &&
(!filters.apps ||
filters.apps.some(
(name) => name.toLowerCase() === toolName!.toLowerCase()
(name) => name.toLowerCase() === toolName?.toLowerCase()
)) &&
(!filters.tags ||
filters.tags.some((tag) => tag.toLowerCase() === "custom"))
Expand Down
4 changes: 2 additions & 2 deletions js/src/sdk/models/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { BackendClient } from "./backendClient";
export type ActionListParams = z.infer<typeof ZGetListActionsParams>;
export type HeaderSingleParameters = z.infer<typeof ZParameter>;
export type CustomAuth = z.infer<typeof ZCustomAuthParams>;
export type ActionxExecuteParam = z.infer<typeof ZExecuteParams>;
export type ActionExecuteParam = z.infer<typeof ZExecuteParams>;
export type ActionItemParam = z.infer<typeof ZActionGetParams>;
export type FindActionEnumsByUseCaseParam = z.infer<
typeof ZFindActionEnumsByUseCaseParams
Expand Down Expand Up @@ -142,7 +142,7 @@ export class Actions {
* @returns {Promise<ActionExecuteResponse>} A promise that resolves to the execution status and response data.
* @throws {ComposioError} If the request fails.
*/
async execute(data: ActionxExecuteParam): Promise<ActionExecuteResponse> {
async execute(data: ActionExecuteParam): Promise<ActionExecuteResponse> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "execute",
file: this.fileName,
Expand Down
4 changes: 2 additions & 2 deletions js/src/types/base_toolset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export const ZRawActionSchema = z.object({
}),
response: z.record(z.any()),
metadata: z.object({
actionName: z.string(),
toolName: z.string(),
name: z.string(),
toolName: z.string().optional(),
}),
});

Expand Down

0 comments on commit fd52d47

Please sign in to comment.