PromucFlow_constructor/app/client/src/ce/utils/actionExecutionUtils.ts
Diljit f4d7de241d
chore: Increase Appsmith ai query timeout and add extra metadata to RUN_API analytics event (#30496)
## Description
This PR has the following changes
Frontend Changes
- Increase the default timeout for Appsmith AI Queries from 10s to 60s
- Add usecase details to the Api run mixpanel events. 

Backend Changes
- Add a new plugin execution error type for rate limit errors

#### PR fixes following issue(s)
Fixes # (issue number)
- https://github.com/appsmithorg/appsmith/issues/30491
- https://github.com/appsmithorg/appsmith/issues/30492
- https://github.com/appsmithorg/appsmith-ee/issues/3360

#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [x] Manual
- [ ] JUnit
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

## Summary by CodeRabbit

- **New Features**
- Added functionality to map plugin names to action property keys for
analytics purposes.
- Introduced a new logic for extracting and organizing action
properties.

- **Refactor**
- Updated timeout settings for AI-related queries to enhance performance
and reliability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Nirmal Sarswat <nirmal@appsmith.com>
Co-authored-by: Arpit Mohan <mohanarpit@users.noreply.github.com>
2024-01-24 22:19:55 +05:30

77 lines
2.1 KiB
TypeScript

import type { Action } from "entities/Action";
import type { JSAction, JSCollection } from "entities/JSCollection";
import type { ApplicationPayload } from "@appsmith/constants/ReduxActionConstants";
import store from "store";
import { getAppMode } from "@appsmith/selectors/applicationSelectors";
import { getDatasource } from "@appsmith/selectors/entitiesSelector";
import { getCurrentEnvironmentDetails } from "@appsmith/selectors/environmentSelectors";
import type { Plugin } from "api/PluginApi";
import { get, isNil } from "lodash";
export function getPluginActionNameToDisplay(action: Action) {
return action.name;
}
export const getActionProperties = (
action: Action,
keyConfig: Record<string, string>,
) => {
const actionProperties: Record<string, unknown> = {};
Object.keys(keyConfig).forEach((key) => {
const value = get(action, key);
if (!isNil(value)) {
actionProperties[keyConfig[key]] = get(action, key);
}
});
return actionProperties;
};
export function getJSActionPathNameToDisplay(
action: JSAction,
collection: JSCollection,
) {
return collection.name + "." + action.name;
}
export function getJSActionNameToDisplay(action: JSAction) {
return action.name;
}
export function getActionExecutionAnalytics(
action: Action,
plugin: Plugin,
params: Record<string, unknown>,
currentApp: ApplicationPayload,
datasourceId: string,
) {
let appMode;
const state = store.getState();
const datasource = getDatasource(state, datasourceId);
const currentEnvDetails = getCurrentEnvironmentDetails(state);
const resultObj = {
type: action?.pluginType,
name: action?.name,
environmentId: currentEnvDetails.id,
environmentName: currentEnvDetails.name,
pluginName: plugin?.name,
datasourceId: datasourceId,
isMock: !!datasource?.isMock,
actionId: action?.id,
inputParams: Object.keys(params).length,
};
if (!!currentApp) {
appMode = getAppMode(state);
return {
...resultObj,
isExampleApp: currentApp.appIsExample,
pageId: action?.pageId,
appId: currentApp.id,
appMode: appMode,
appName: currentApp.name,
};
}
return resultObj;
}