All files / sdk/models actions.ts

100% Statements 10/10
100% Branches 1/1
100% Functions 5/5
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175  9x                                                                                                                                                                                                       9x       13x                         3x           3x                         11x                       11x 11x                           4x             4x      
import { ActionsListResponseDTO, ExecuteActionResDTO } from "../client";
import apiClient from "../client/client";
import { BackendClient } from "./backendClient";
 
/**
 * The `Actions` class provides methods to interact with the Composio platform's actions.
 * It allows fetching details of specific actions, listing all actions, and executing actions.
 *
 * - `get` method retrieves details of a specific action.
 * - `list` method retrieves a list of all actions.
 * - `execute` method executes a specific action.
 *
 * Each method returns a `CancelablePromise` which can be canceled. If canceled, the promise
 * will reject with a `Cancellation` object.
 *
 * @typeParam Composio The client configuration object type.
 * @groupDescription Methods
 * The methods in this class are grouped under 'Actions Methods' and provide functionalities
 * to interact with actions in the Composio platform. This includes fetching, listing, and
 * executing actions.
 */
 
export type GetListActionsData = {
    /**
     * Name of the apps like "github", "linear" separated by a comma
     */
    apps?: string;
    /**
     * Filter by Action names
     */
    actions?: string;
    /**
     * Filter by Action tags
     */
    tags?: string;
    /**
     * Filter by use case
     */
    useCase?: string | undefined;
    /**
     * Limit of use-cases based search
     */
    usecaseLimit?: string;
    /**
     * Show all actions - i.e disable pagination
     */
    showAll?: boolean;
    /**
     * Show actions enabled for the API Key
     */
    showEnabledOnly?: boolean;
    /**
     * Use smart tag filtering
     */
    filterImportantActions?: boolean;
}
 
export type ExecuteActionData = {
    /**
     * The name of the action to execute.
     */
    actionName: string;
    requestBody?: {
        /**
         * The unique identifier of the connection to use for executing the action.
         */
        connectedAccountId?: string;
        /**
         * An object containing the input parameters for the action. If you want to execute 
         * NLP based action (i.e text), you can use text parameter instead of input.
         */
        input?: {
            [key: string]: unknown;
        };
        appName?: string;
        /**
         * The text to supply to the action which will be automatically converted to 
         * appropriate input parameters.
         */
        text?: string;
    };
};
 
export type ExecuteActionResponse = {
    /**
     * An object containing the details of the action execution.
     */
    execution_details?: {
        /**
         * A boolean indicating whether the action was executed successfully.
         *
         */
        executed?: boolean;
    };
    /**
     * An object containing the response data from the action execution.
     */
    response_data?: {
        [key: string]: unknown;
    };
};
export class Actions {
    backendClient: BackendClient;
 
    constructor(backendClient: BackendClient) {
        this.backendClient = backendClient;
    }
 
    /**
     * Retrieves details of a specific action in the Composio platform by providing its action name.
     * 
     * The response includes the action's name, display name, description, input parameters, expected response, associated app information, and enabled status.
     * 
     * @param {GetActionData} data The data for the request.
     * @returns {CancelablePromise<GetActionResponse[0]>} A promise that resolves to the details of the action.
     * @throws {ApiError} If the request fails.
     */
    async get(data: { actionName: string; }) {
        const actions = await apiClient.actionsV1.v1GetAction({
            path: {
                actionId: data.actionName
            }
        });
 
        return (actions.data! as unknown as any[])[0];
    }
 
    /**
     * Retrieves a list of all actions in the Composio platform.
     * 
     * This method allows you to fetch a list of all the available actions. It supports pagination to handle large numbers of actions. The response includes an array of action objects, each containing information such as the action's name, display name, description, input parameters, expected response, associated app information, and enabled status.
     * 
     * @param {GetListActionsData} data The data for the request.
     * @returns {CancelablePromise<GetListActionsResponse>} A promise that resolves to the list of all actions.
     * @throws {ApiError} If the request fails.
     */
    list(data: GetListActionsData = {}): Promise<ActionsListResponseDTO> {
        return apiClient.actionsV2.v2ListActions({
            query: {
                actions: data.actions,
                apps: data.apps,
                showAll: data.showAll,
                tags: data.tags,
                useCase: data.useCase as string,
                filterImportantActions: data.filterImportantActions,
                showEnabledOnly: data.showEnabledOnly
 
            }
        }).then(res => {
            const resp = res;
            return res.data!
        })
    }
 
    /**
     * Executes a specific action in the Composio platform.
     * 
     * This method allows you to trigger the execution of an action by providing its name and the necessary input parameters. The request includes the connected account ID to identify the app connection to use for the action, and the input parameters required by the action. The response provides details about the execution status and the response data returned by the action.
     * 
     * @param {ExecuteActionData} data The data for the request.
     * @returns {CancelablePromise<ExecuteActionResponse>} A promise that resolves to the execution status and response data.
     * @throws {ApiError} If the request fails.
     */
    async execute(data: ExecuteActionData): Promise<ExecuteActionResDTO> {
        const {data:res,error} = await apiClient.actionsV2.v2ExecuteAction({
            body: data.requestBody,
            path: {
                actionId: data.actionName
            }
        })
 
        return res!
    }
}