Skip to content

Commit

Permalink
fixed execute cli parity
Browse files Browse the repository at this point in the history
  • Loading branch information
plxity committed Dec 12, 2024
1 parent 051bfa0 commit c58c202
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
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);
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

0 comments on commit c58c202

Please sign in to comment.