Skip to content

Commit

Permalink
feat: switch from client.actions to getToolsSchema
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-dixit committed Jan 9, 2025
1 parent 94f1584 commit 8e4f421
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 20 deletions.
32 changes: 32 additions & 0 deletions js/src/frameworks/vercel.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { beforeAll, describe, expect, it } from "@jest/globals";
import { z } from "zod";
import { getTestConfig } from "../../config/getTestConfig";
import { ActionExecuteResponse } from "../sdk/models/actions";
import { VercelAIToolSet } from "./vercel";

describe("Apps class tests", () => {
Expand All @@ -25,4 +27,34 @@ describe("Apps class tests", () => {
});
expect(Object.keys(tools).length).toBe(1);
});

it("Should create custom action to star a repository", async () => {
await vercelAIToolSet.createAction({
actionName: "starRepositoryCustomAction",
toolName: "github",
description: "This action stars a repository",
inputParams: z.object({
owner: z.string(),
repo: z.string(),
}),
callback: async (
inputParams,
_authCredentials,
executeRequest
): Promise<ActionExecuteResponse> => {
const res = await executeRequest({
endpoint: `/user/starred/${inputParams.owner}/${inputParams.repo}`,
method: "PUT",
parameters: [],
});
return res;
},
});

const tools = await vercelAIToolSet.getTools({
actions: ["starRepositoryCustomAction"],
});

await expect(Object.keys(tools).length).toBe(1);
});
});
39 changes: 19 additions & 20 deletions js/src/frameworks/vercel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jsonSchema, tool } from "ai";
import { CoreTool, jsonSchema, tool } from "ai";
import { z } from "zod";
import { ComposioToolSet as BaseComposioToolSet } from "../sdk/base.toolset";
import { TELEMETRY_LOGGER } from "../sdk/utils/telemetry";
Expand Down Expand Up @@ -62,7 +62,7 @@ export class VercelAIToolSet extends BaseComposioToolSet {
useCase?: Optional<string>;
usecaseLimit?: Optional<number>;
filterByAvailableApps?: Optional<boolean>;
}): Promise<{ [key: string]: RawActionData }> {
}): Promise<{ [key: string]: CoreTool }> {
TELEMETRY_LOGGER.manualTelemetry(TELEMETRY_EVENTS.SDK_METHOD_INVOKED, {
method: "getTools",
file: this.fileName,
Expand All @@ -78,25 +78,24 @@ export class VercelAIToolSet extends BaseComposioToolSet {
actions,
} = ZExecuteToolCallParams.parse(filters);

const actionsList = await this.client.actions.list({
...(apps && { apps: apps?.join(",") }),
...(tags && { tags: tags?.join(",") }),
...(useCase && { useCase: useCase }),
...(actions && { actions: actions?.join(",") }),
...(usecaseLimit && { usecaseLimit: usecaseLimit }),
filterByAvailableApps: filterByAvailableApps ?? undefined,
});

const tools = {};
actionsList.items?.forEach((actionSchema) => {
// @ts-ignore
tools[actionSchema.name!] = this.generateVercelTool(
// @ts-ignore
actionSchema as ActionData
);
});
const tools = await this.getToolsSchema(
{
apps,
tags,
useCase,
filterByAvailableApps,
actions,
useCaseLimit: usecaseLimit,
},
this.entityId
);

return tools;
return Object.fromEntries(
tools.map((tool) => [
tool.name,
this.generateVercelTool(tool as RawActionData),
])
);
}

async executeToolCall(
Expand Down

0 comments on commit 8e4f421

Please sign in to comment.