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: switch from client.actions to getToolsSchema #1174

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

himanshu-dixit
Copy link
Collaborator

@himanshu-dixit himanshu-dixit commented Jan 9, 2025

Important

Switch getTools in VercelAIToolSet to use getToolsSchema and add a test for custom action creation.

  • Behavior:
    • getTools in VercelAIToolSet now uses getToolsSchema instead of client.actions.list.
    • Adds test for creating a custom action starRepositoryCustomAction in vercel.spec.ts.
  • Types:
    • Changes return type of getTools to { [key: string]: CoreTool }.
  • Imports:
    • Adds CoreTool and ActionExecuteResponse imports in vercel.ts and vercel.spec.ts respectively.

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

@himanshu-dixit himanshu-dixit requested a review from plxity as a code owner January 9, 2025 15:25
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 8:07am

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 8e4f421 in 26 seconds

More details
  • Looked at 110 lines of code in 2 files
  • Skipped 0 files when reviewing.
  • Skipped posting 4 drafted comments based on config settings.
1. js/src/frameworks/vercel.spec.ts:27
  • Draft comment:
    Consider renaming the test to something more descriptive, like "should return tools for specified actions".
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The test description should be more descriptive to reflect the test's purpose.
2. js/src/frameworks/vercel.spec.ts:31
  • Draft comment:
    Consider renaming the test to something more descriptive, like "should create and retrieve custom action to star a repository".
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The test description should be more descriptive to reflect the test's purpose.
3. js/src/frameworks/vercel.spec.ts:58
  • Draft comment:
    The await keyword is unnecessary here. expect is not a promise and does not need to be awaited.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The use of await with expect is unnecessary and can be removed for clarity.
4. js/src/frameworks/vercel.ts:88
  • Draft comment:
    Ensure that useCaseLimit is correctly mapped and used consistently. Consider renaming to usecaseLimit to match the parsed object if necessary.
  • Reason this comment was not posted:
    Confidence changes required: 50%
    The getTools method has a potential issue with the useCaseLimit parameter name, which should be consistent with the parsed object.

Workflow ID: wflow_QhoDZleBeFOzCV2v


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

actionSchema as ActionData
);
});
const tools = await this.getToolsSchema(
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 handling for the getToolsSchema call. If the API call fails, it could lead to an unhandled rejection. Something like:

const tools = await this.getToolsSchema(
  {
    apps,
    tags,
    useCase,
    filterByAvailableApps,
    actions,
    useCaseLimit: usecaseLimit,
  },
  this.entityId
).catch(error => {
  TELEMETRY_LOGGER.error('Failed to fetch tools schema', { error });
  throw error;
});

return Object.fromEntries(
tools.map((tool) => [
tool.name,
this.generateVercelTool(tool as RawActionData),
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 cast to RawActionData here could be unsafe. Consider adding a type guard or validation to ensure the tool object matches the RawActionData interface before casting. This would prevent potential runtime errors if the tool schema doesn't match expected format.

Copy link

github-actions bot commented Jan 9, 2025

This comment was generated by github-actions[bot]!

JS SDK Coverage Report

📊 Coverage report for JS SDK can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/coverage-12705630949/coverage/index.html

📁 Test report folder can be found at the following URL:
https://pub-92e668239ab84bfd80ee07d61e9d2f40.r2.dev/html-report-12705630949/html-report/report.html

actions: ["starRepositoryCustomAction"],
});

await expect(Object.keys(tools).length).toBe(1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test case could benefit from additional assertions to verify the created action's properties. Consider adding checks for:

  1. The returned tool's description
  2. The input parameter schema structure
  3. The actual functionality by making a mock request

This would ensure the action is created correctly with all expected properties.

@shreysingla11
Copy link
Collaborator

Code Review Summary

Overall Assessment

The changes look good and improve the codebase by switching from client.actions to getToolsSchema. The code is generally well-structured with proper type definitions and test coverage.

Positive Aspects

  1. Good use of TypeScript features and Zod for runtime validation
  2. Improved return type from RawActionData to CoreTool
  3. Added comprehensive test for custom action creation
  4. Clean refactoring of the getTools method

Areas for Improvement

  1. Error handling could be enhanced for the getToolsSchema call
  2. Type safety could be improved around the RawActionData casting
  3. Test coverage could be expanded with more specific assertions

Suggestions Made

  1. Added error handling with proper logging for getToolsSchema
  2. Recommended type guard for RawActionData casting
  3. Suggested additional test assertions for custom action creation

The changes are ready to be merged after addressing the suggested improvements. The code quality is good with minor areas for enhancement.

Comment on lines 27 to +34
});
expect(Object.keys(tools).length).toBe(1);
});

it("Should create custom action to star a repository", async () => {
await vercelAIToolSet.createAction({
actionName: "starRepositoryCustomAction",
toolName: "github",

Choose a reason for hiding this comment

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

Code Quality: The added test case for creating a custom action to star a repository is a good addition. However, ensure that the test case is complete and follows the existing test structure. Consider adding assertions to verify the expected behavior of the createAction method. This will enhance the test's robustness and ensure it validates the intended functionality effectively.

🔧 Suggested Code Diff:
  it("Should create custom action to star a repository", async () => {
    await vercelAIToolSet.createAction({
      actionName: "starRepositoryCustomAction",
      toolName: "github",
+     // Add assertions to verify the action was created successfully
+     const action = tools.getAction("starRepositoryCustomAction");
+     expect(action).toBeDefined();
+     expect(action.toolName).toBe("github");
    });
  });
📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
});
expect(Object.keys(tools).length).toBe(1);
});
it("Should create custom action to star a repository", async () => {
await vercelAIToolSet.createAction({
actionName: "starRepositoryCustomAction",
toolName: "github",
it("Should create custom action to star a repository", async () => {
await vercelAIToolSet.createAction({
actionName: "starRepositoryCustomAction",
toolName: "github"
});
// Add assertions to verify the action was created successfully
const action = tools.getAction("starRepositoryCustomAction");
expect(action).toBeDefined();
expect(action.toolName).toBe("github");
});

Comment on lines 62 to 68
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,

Choose a reason for hiding this comment

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

Potential Issue: The change in the return type from RawActionData to CoreTool indicates a significant alteration in the data structure. This could lead to compatibility issues in parts of the codebase that rely on the previous return type. It's crucial to ensure that all dependent modules or functions are updated to handle the new CoreTool structure appropriately. This change might affect data processing, serialization, or any logic that interacts with the returned data.


@@ -39,7 +39,7 @@ export type OpenAPIConfig = {
};
};

export const COMPOSIO_BASE_URL = "https://backend.composio.dev/";
export const COMPOSIO_BASE_URL = "https://backend.composio.dev";

Choose a reason for hiding this comment

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

The COMPOSIO_BASE_URL should not have a trailing slash. This can lead to double slashes in URLs when combined with other path segments.

📝 Committable Code Suggestion

‼️ Ensure you review the code suggestion before committing it to the branch. Make sure it replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
export const COMPOSIO_BASE_URL = "https://backend.composio.dev";
export const COMPOSIO_BASE_URL = "https://backend.composio.dev";

@@ -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 }> {

Choose a reason for hiding this comment

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

The type of tools should be CoreTool[] instead of an object, as the getToolsSchema returns an array of CoreTool.

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.

2 participants