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

fix: Execute cli parity #1005

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions js/src/cli/execute.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { Command } from "commander";
import client from "../sdk/client/client";
import chalk from "chalk";
import { getOpenAPIClient } from "../sdk/utils/config";

export default class ExecuteCommand {
private program: Command;
constructor(program: Command) {
this.program = program;
this.program
.command("execute <action>")
.description("Execute a Composio action")
.option("-p, --params <params>", "Action parameters as a JSON string")
.action(this.handleAction.bind(this));
}
private async handleAction(
action: string,
options: {
params?: string;
}
): Promise<void> {
getOpenAPIClient();
const { params } = options;
try {
const res = await client.actionsV2.executeActionV2({
body: params ? JSON.parse(params) : {},
path: {
actionId: action,
},
});
console.log(
chalk.green(
"Action executed successfully",
JSON.stringify(res?.data?.data, null, 2)
)
);
} catch (error) {
console.log(error);
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider removing the console.log(error); statement as it may expose sensitive information and is redundant with the error message logging.

console.log(
chalk.red(`Error executing action: ${(error as Error).message}`)
);
return;
}
}
}
2 changes: 2 additions & 0 deletions js/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import logout from "./logout";
import triggers from "./triggers";
import whoami from "./whoami";
import actions from "./actions";
import execute from './execute'

// SDK Imports
import { TELEMETRY_EVENTS } from "../sdk/utils/telemetry/events";
Expand All @@ -30,6 +31,7 @@ new integrations(program);
new triggers(program);
new add(program);
new actions(program);
new execute(program)

function formatLine(content: string): string {
return `${content}`;
Expand Down
Loading