Skip to content

Commit

Permalink
chore: prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-dixit committed Jan 10, 2025
1 parent 0f847f4 commit 139c691
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 40 deletions.
26 changes: 12 additions & 14 deletions js/src/frameworks/vercel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { beforeAll, describe, expect, it } from "@jest/globals";
import { z } from "zod";
import { getTestConfig } from "../../config/getTestConfig";
import { VercelAIToolSet } from "./vercel";
import type { CreateActionOptions } from "../sdk/actionRegistry";

describe("Apps class tests", () => {
let vercelAIToolSet: VercelAIToolSet;
Expand Down Expand Up @@ -36,24 +35,25 @@ describe("Apps class tests", () => {
beforeAll(async () => {
const params = z.object({
owner: z.string().describe("The owner of the repository"),
repo: z.string().describe("The name of the repository without the `.git` extension."),
})

repo: z
.string()
.describe("The name of the repository without the `.git` extension."),
});

customAction = await vercelAIToolSet.createAction({
actionName: "starRepositoryCustomAction",
toolName: "github",
description: "Star A Github Repository For Given `Repo` And `Owner`",
inputParams: params,
callback: async (
inputParams,
) => ({ successful: true, data: inputParams })
})
callback: async (inputParams) => ({
successful: true,
data: inputParams,
}),
});

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

});

it("check if custom actions are coming", async () => {
Expand All @@ -66,14 +66,12 @@ describe("Apps class tests", () => {
action: customAction.name,
params: {
owner: "composioHQ",
repo: "composio"
repo: "composio",
},
})
});
expect(res.successful).toBe(true);
expect(res.data).toHaveProperty("owner", "composioHQ");
expect(res.data).toHaveProperty("repo", "composio");
});
})


});
});
10 changes: 4 additions & 6 deletions js/src/frameworks/vercel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jsonSchema, tool, CoreTool } 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 @@ -84,14 +84,12 @@ export class VercelAIToolSet extends BaseComposioToolSet {
tags,
useCase,
useCaseLimit: usecaseLimit,
filterByAvailableApps
})
filterByAvailableApps,
});

const tools: { [key: string]: CoreTool } = {};
actionsList.forEach((actionSchema) => {
tools[actionSchema.name!] = this.generateVercelTool(
actionSchema
);
tools[actionSchema.name!] = this.generateVercelTool(actionSchema);
});

return tools;
Expand Down
25 changes: 12 additions & 13 deletions js/src/sdk/actionRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@ type RawExecuteRequestParam = {
};
};


type ValidParameters = ZodObject<{ [key: string]: ZodString | ZodOptional<ZodString> }>
export type Parameters = ValidParameters | z.ZodObject<{}>
type ValidParameters = ZodObject<{
[key: string]: ZodString | ZodOptional<ZodString>;
}>;
export type Parameters = ValidParameters | z.ZodObject<{}>;

type inferParameters<PARAMETERS extends Parameters> =
PARAMETERS extends ValidParameters
? z.infer<PARAMETERS>
: z.infer<z.ZodObject<{}>>

? z.infer<PARAMETERS>
: z.infer<z.ZodObject<{}>>;

export type CreateActionOptions<
P extends Parameters = z.ZodObject<{}>
> = {
export type CreateActionOptions<P extends Parameters = z.ZodObject<{}>> = {
actionName?: string;
toolName?: string;
description?: string;
Expand Down Expand Up @@ -64,7 +62,7 @@ export class ActionRegistry {
string,
{
metadata: CreateActionOptions;
schema: Record<string, unknown>
schema: Record<string, unknown>;
}
>;

Expand All @@ -73,8 +71,9 @@ export class ActionRegistry {
this.customActions = new Map();
}


async createAction<P extends Parameters = z.ZodObject<{}>>(options: CreateActionOptions<P>): Promise<RawActionData> {
async createAction<P extends Parameters = z.ZodObject<{}>>(
options: CreateActionOptions<P>
): Promise<RawActionData> {
const { callback } = options;
if (typeof callback !== "function") {
throw new Error("Callback must be a function");
Expand All @@ -83,7 +82,7 @@ export class ActionRegistry {
throw new Error("You must provide actionName for this action");
}
if (!options.inputParams) {
options.inputParams = z.object({}) as P
options.inputParams = z.object({}) as P;
}
const params = options.inputParams;
const actionName = options.actionName || callback.name || "";
Expand Down
20 changes: 13 additions & 7 deletions js/src/sdk/base.toolset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { z, ZodObject } from "zod";
import { z } from "zod";
import { Composio } from "../sdk";
import {
RawActionData,
Expand All @@ -10,7 +10,11 @@ import {
} from "../types/base_toolset";
import type { Optional, Sequence } from "../types/util";
import { getEnvVariable } from "../utils/shared";
import { ActionRegistry, CreateActionOptions, Parameters } from "./actionRegistry";
import {
ActionRegistry,
CreateActionOptions,
Parameters,
} from "./actionRegistry";
import { ActionExecutionResDto } from "./client/types.gen";
import { ActionExecuteResponse, Actions } from "./models/actions";
import { ActiveTriggers } from "./models/activeTriggers";
Expand Down Expand Up @@ -54,10 +58,10 @@ export class ComposioToolSet {
post: TPostProcessor[];
schema: TSchemaProcessor[];
} = {
pre: [fileInputProcessor],
post: [fileResponseProcessor],
schema: [fileSchemaProcessor],
};
pre: [fileInputProcessor],
post: [fileResponseProcessor],
schema: [fileSchemaProcessor],
};

private userDefinedProcessors: {
pre?: TPreProcessor;
Expand Down Expand Up @@ -172,7 +176,9 @@ export class ComposioToolSet {
});
}

async createAction<P extends Parameters = z.ZodObject<{}>>(options: CreateActionOptions<P>) {
async createAction<P extends Parameters = z.ZodObject<{}>>(
options: CreateActionOptions<P>
) {
return this.userActionRegistry.createAction<P>(options);
}

Expand Down

0 comments on commit 139c691

Please sign in to comment.