Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support custom actions in vercel toolkit (with type safety improvements) #1175

Merged

Conversation

nicolas-angelo
Copy link
Contributor

@nicolas-angelo nicolas-angelo commented Jan 9, 2025

This PR introduces two small enhancements:

Generics-Based Inference in createAction

  • Refactors the createAction function to accept a generic parameter P (extending a Zod schema type)
  • inputParams in the callback are now automatically inferred based on the provided Zod schema, reducing manual type annotations.

Inclusion of Custom Actions in Vercel Toolkit’s getTools

  • Updates the Vercel toolkit to include custom actions when calling getTools,
  • Previously, getTools did not include custom actions, preventing them from being automatically included in the generated toolset used with the Vercel AI SDK. With this update, custom actions are now part of the toolkit, making them seamlessly available for integration.

Important

Enhance createAction with generics-based inference and integrate custom actions into Vercel Toolkit's getTools.

  • Generics-Based Inference in createAction:
    • Refactor createAction in actionRegistry.ts to accept a generic parameter P extending a Zod schema type.
    • inputParams in the callback are inferred based on the provided Zod schema.
  • Inclusion of Custom Actions in Vercel Toolkit’s getTools:
    • Update getTools in vercel.ts to include custom actions.
    • Modify getToolsSchema in base.toolset.ts to filter and include custom actions.
  • Tests:
    • Add tests in vercel.spec.ts to verify inclusion and execution of custom actions.

This description was created by Ellipsis for b5aac36. It will automatically update as commits are pushed.

Copy link

vercel bot commented Jan 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
composio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 10, 2025 7:46am

Copy link
Contributor

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Looks good to me! Reviewed everything up to b5aac36 in 36 seconds

More details
  • Looked at 231 lines of code in 4 files
  • Skipped 0 files when reviewing.
  • Skipped posting 2 drafted comments based on config settings.
1. js/src/frameworks/vercel.spec.ts:28
  • Draft comment:
    The test case is checking if Object.keys(tools) is an instance of Array, which is incorrect. Object.keys() always returns an array. Consider using Array.isArray() to check if the result is an array.
    expect(Array.isArray(Object.keys(tools))).toBe(true);
  • Reason this comment was not posted:
    Comment was not on a valid diff hunk.
2. js/src/frameworks/vercel.spec.ts:60
  • Draft comment:
    The test case is checking if Object.keys(tools) is an instance of Array, which is incorrect. Object.keys() always returns an array. Consider using Array.isArray() to check if the result is an array.
      expect(Array.isArray(Object.keys(tools))).toBe(true);
  • Reason this comment was not posted:
    Marked as duplicate.

Workflow ID: wflow_xyMOK3rkaMgHorl0


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

Comment on lines 172 to 179
});
}

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

private isCustomAction(action: string) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor: The change ensures type safety by using generics, aligning with the ActionRegistry class.


actionsList.items?.forEach((actionSchema) => {
// @ts-ignore
const tools: { [key: string]: CoreTool } = {};
actionsList.forEach((actionSchema) => {
tools[actionSchema.name!] = this.generateVercelTool(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a type guard instead of non-null assertion on actionSchema.name. This could prevent runtime errors if the name is undefined. Example:

if (!actionSchema.name) {
  console.warn('Action schema missing name, skipping...');
  return;
}
tools[actionSchema.name] = this.generateVercelTool(actionSchema);

@@ -67,7 +83,7 @@ export class ActionRegistry {
throw new Error("You must provide actionName for this action");
}
if (!options.inputParams) {
options.inputParams = z.object({});
options.inputParams = z.object({}) as P
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type assertion as P here could be unsafe. Consider adding a type guard or validation to ensure the empty object conforms to the expected type P. Alternatively, you could make inputParams required and remove this default initialization.

toolName: "github",
description: "Star A Github Repository For Given `Repo` And `Owner`",
inputParams: params,
callback: async (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error case tests for the callback function. The current test only covers the success case. Add tests for scenarios where the callback might fail or return unsuccessful results.

@shreysingla11
Copy link
Collaborator

Code Review Summary

Overall Assessment

The changes introduce valuable improvements to the Vercel toolkit's custom actions system with better type safety and generic inference. The code quality is good, but there are a few areas that could be improved for better reliability and maintainability.

Strengths

  • ✅ Good type system improvements with generic parameters
  • ✅ Clean implementation of custom actions
  • ✅ Well-structured test coverage for happy paths
  • ✅ Improved type safety in action creation and execution

Areas for Improvement

  • 🔸 Several uses of type assertions and non-null assertions that could be replaced with safer alternatives
  • 🔸 Limited error case testing
  • 🔸 Some potential runtime type safety issues

Recommendations

  1. Replace type assertions with proper type guards where possible
  2. Add error case tests for custom action execution
  3. Consider making inputParams required in CreateActionOptions
  4. Add validation for action schema properties

Overall, this is a solid PR that improves the codebase. With the suggested improvements implemented, it would be ready for merge.

@nicolas-angelo nicolas-angelo marked this pull request as draft January 10, 2025 02:18
@nicolas-angelo nicolas-angelo changed the title Integrate Custom Actions in Vercel Toolkit & Enhance Generic Inference for createAction feat: support custom Actions in vercel toolkit (with type safety improvements) Jan 10, 2025
@nicolas-angelo nicolas-angelo marked this pull request as ready for review January 10, 2025 02:20
@nicolas-angelo nicolas-angelo changed the title feat: support custom Actions in vercel toolkit (with type safety improvements) feat: support custom actions in vercel toolkit (with type safety improvements) Jan 10, 2025
@himanshu-dixit
Copy link
Collaborator

Thanks for the fix @nicolas-angelo 🚀 . Merging the PR.

@himanshu-dixit himanshu-dixit merged commit fe49261 into ComposioHQ:develop Jan 13, 2025
5 of 13 checks passed
abhishekpatil4 pushed a commit that referenced this pull request Jan 20, 2025
…ovements) (#1175)

Co-authored-by: Himanshu Dixit <hudixt@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants