chore: Send example structure to slash commands (#23016)
## Description Ask AI trigger from slash commands requires the expected type and example structure of response to generate better results. This PR ensures that we send this info from code editor component. ## Type of change - Chore (housekeeping or task changes that don't impact user perception) ## How Has This Been Tested? - Manual ### 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 - [x] My code follows the style guidelines of this project - [x] 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 - [x] 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 - [x] PR is being merged under a feature flag ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test
This commit is contained in:
parent
8b378fdc76
commit
b5869c521c
|
|
@ -3,6 +3,7 @@ import type { DataTree, ENTITY_TYPE } from "entities/DataTree/dataTreeFactory";
|
|||
import type { AdditionalDynamicDataTree } from "utils/autocomplete/customTreeTypeDefCreator";
|
||||
import type { AutocompleteDataType } from "utils/autocomplete/CodemirrorTernService";
|
||||
import type { EntityNavigationData } from "selectors/navigationSelectors";
|
||||
import type { ExpectedValueExample } from "utils/validation/common";
|
||||
|
||||
export enum EditorModes {
|
||||
TEXT = "text/plain",
|
||||
|
|
@ -53,6 +54,8 @@ export type FieldEntityInformation = {
|
|||
entityId?: string;
|
||||
propertyPath?: string;
|
||||
blockCompletions?: Array<{ parentPath: string; subPath: string }>;
|
||||
example?: ExpectedValueExample;
|
||||
mode?: EditorModes;
|
||||
};
|
||||
|
||||
export type HintHelper = (
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import CodeMirror from "codemirror";
|
||||
import type { HintHelper } from "components/editorComponents/CodeEditor/EditorConfig";
|
||||
import type {
|
||||
FieldEntityInformation,
|
||||
HintHelper,
|
||||
} from "components/editorComponents/CodeEditor/EditorConfig";
|
||||
import type { CommandsCompletion } from "utils/autocomplete/CodemirrorTernService";
|
||||
import { AutocompleteDataType } from "utils/autocomplete/CodemirrorTernService";
|
||||
import { generateQuickCommands } from "./generateQuickCommands";
|
||||
|
|
@ -29,7 +32,7 @@ export const commandsHelper: HintHelper = (editor, data: DataTree) => {
|
|||
return {
|
||||
showHint: (
|
||||
editor: CodeMirror.Editor,
|
||||
{ entityId, entityType, expectedType, propertyPath },
|
||||
entityInfo: FieldEntityInformation,
|
||||
{
|
||||
datasources,
|
||||
executeCommand,
|
||||
|
|
@ -47,6 +50,7 @@ export const commandsHelper: HintHelper = (editor, data: DataTree) => {
|
|||
featureFlags: FeatureFlags;
|
||||
},
|
||||
): boolean => {
|
||||
const { entityType } = entityInfo;
|
||||
const currentEntityType =
|
||||
entityType || ENTITY_TYPE.ACTION || ENTITY_TYPE.JSACTION;
|
||||
entitiesForSuggestions = entitiesForSuggestions.filter((entity: any) => {
|
||||
|
|
@ -71,9 +75,7 @@ export const commandsHelper: HintHelper = (editor, data: DataTree) => {
|
|||
recentEntities,
|
||||
featureFlags,
|
||||
},
|
||||
expectedType || "string",
|
||||
entityId,
|
||||
propertyPath,
|
||||
entityInfo,
|
||||
);
|
||||
let currentSelection: CommandsCompletion = {
|
||||
origin: "",
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ import { getAssetUrl } from "@appsmith/utils/airgapHelpers";
|
|||
import MagicIcon from "remixicon-react/MagicLineIcon";
|
||||
import { addAISlashCommand } from "@appsmith/components/editorComponents/GPT/trigger";
|
||||
import type FeatureFlags from "entities/FeatureFlags";
|
||||
import type { FieldEntityInformation } from "./EditorConfig";
|
||||
import { EditorModes } from "./EditorConfig";
|
||||
|
||||
enum Shortcuts {
|
||||
PLUS = "PLUS",
|
||||
|
|
@ -141,10 +143,15 @@ export const generateQuickCommands = (
|
|||
recentEntities: string[];
|
||||
featureFlags: FeatureFlags;
|
||||
},
|
||||
expectedType: string,
|
||||
entityId: any,
|
||||
propertyPath: any,
|
||||
entityInfo: FieldEntityInformation,
|
||||
) => {
|
||||
const {
|
||||
entityId,
|
||||
example,
|
||||
expectedType = "string",
|
||||
mode,
|
||||
propertyPath,
|
||||
} = entityInfo || {};
|
||||
const suggestionsHeader: CommandsCompletion = commandsHeader("Bind Data");
|
||||
const createNewHeader: CommandsCompletion = commandsHeader("Create a Query");
|
||||
recentEntities.reverse();
|
||||
|
|
@ -252,7 +259,9 @@ export const generateQuickCommands = (
|
|||
if (
|
||||
addAISlashCommand &&
|
||||
featureFlags.ask_ai &&
|
||||
currentEntityType !== ENTITY_TYPE.ACTION
|
||||
(currentEntityType !== ENTITY_TYPE.ACTION ||
|
||||
mode === EditorModes.SQL ||
|
||||
mode === EditorModes.SQL_WITH_BINDING)
|
||||
) {
|
||||
const askGPT: CommandsCompletion = generateCreateNewCommand({
|
||||
text: "",
|
||||
|
|
@ -266,6 +275,8 @@ export const generateQuickCommands = (
|
|||
expectedType: expectedType,
|
||||
entityId: entityId,
|
||||
propertyPath: propertyPath,
|
||||
example,
|
||||
mode,
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1049,6 +1049,8 @@ class CodeEditor extends Component<Props, State> {
|
|||
const configTree = ConfigTreeActions.getConfigTree();
|
||||
const entityInformation: FieldEntityInformation = {
|
||||
expectedType: expected?.autocompleteDataType,
|
||||
example: expected?.example,
|
||||
mode: this.props.mode,
|
||||
};
|
||||
|
||||
if (dataTreePath) {
|
||||
|
|
|
|||
|
|
@ -957,9 +957,17 @@ function* executeCommandSaga(actionPayload: ReduxAction<SlashCommandPayload>) {
|
|||
const API = yield take(ReduxActionTypes.CREATE_ACTION_SUCCESS);
|
||||
if (callback) callback(`{{${API.payload.name}.data}}`);
|
||||
break;
|
||||
case SlashCommand.ASK_AI:
|
||||
yield put({ type: ReduxActionTypes.TOGGLE_AI_WINDOW, payload: true });
|
||||
case SlashCommand.ASK_AI: {
|
||||
const context = get(actionPayload, "payload.args", {});
|
||||
yield put({
|
||||
type: ReduxActionTypes.TOGGLE_AI_WINDOW,
|
||||
payload: {
|
||||
show: true,
|
||||
context,
|
||||
},
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user