-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat: add initial assistant message #36798
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
Merged
znamenskii-ilia
merged 2 commits into
release
from
feat/36776-add-default-assistant-prompt
Oct 10, 2024
+388
−44
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...widgets/src/components/AIChat/src/AssistantSuggestionButton/AssistantSuggestionButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { Text } from "@appsmith/wds"; | ||
| import { clsx } from "clsx"; | ||
| import React from "react"; | ||
| import { Button as HeadlessButton } from "react-aria-components"; | ||
| import styles from "./styles.module.css"; | ||
| import type { AssistantSuggestionButtonProps } from "./types"; | ||
|
|
||
| export const AssistantSuggestionButton = ({ | ||
| children, | ||
| className, | ||
| ...rest | ||
| }: AssistantSuggestionButtonProps) => { | ||
| return ( | ||
| <HeadlessButton className={clsx(styles.root, className)} {...rest}> | ||
| <Text>{children}</Text> | ||
| </HeadlessButton> | ||
| ); | ||
| }; | ||
2 changes: 2 additions & 0 deletions
2
...ckages/design-system/widgets/src/components/AIChat/src/AssistantSuggestionButton/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| export * from "./AssistantSuggestionButton"; | ||
| export * from "./types"; |
20 changes: 20 additions & 0 deletions
20
...sign-system/widgets/src/components/AIChat/src/AssistantSuggestionButton/styles.module.css
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| .root { | ||
| height: 30px; | ||
| padding: 0 var(--inner-spacing-4); | ||
| background-color: var(--bg-neutral-subtle-alt, #e7e8e8); | ||
| border-radius: var(--radius-inner-button, 1.8px); | ||
|
|
||
| &:hover { | ||
| background-color: var(--bg-neutral-subtle-alt-hover, #f0f1f1); | ||
| } | ||
|
|
||
| &:focus-visible { | ||
| box-shadow: | ||
| 0 0 0 2px var(--color-bg), | ||
| 0 0 0 4px var(--color-bd-focus); | ||
| } | ||
|
|
||
| &:active { | ||
| background-color: var(--bg-neutral-subtle-alt-active, #e1e2e2); | ||
| } | ||
| } |
5 changes: 5 additions & 0 deletions
5
...ckages/design-system/widgets/src/components/AIChat/src/AssistantSuggestionButton/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| import type { PropsWithChildren } from "react"; | ||
| import type { ButtonProps as HeadlessButtonProps } from "react-aria-components"; | ||
|
|
||
| export interface AssistantSuggestionButtonProps | ||
| extends PropsWithChildren<HeadlessButtonProps> {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import { Text } from "@appsmith/wds"; | ||
| import { Flex, Text } from "@appsmith/wds"; | ||
| import { clsx } from "clsx"; | ||
| import React from "react"; | ||
| import Markdown from "react-markdown"; | ||
| import SyntaxHighlighter from "react-syntax-highlighter"; | ||
| import { monokai } from "react-syntax-highlighter/dist/cjs/styles/hljs"; | ||
| import { AssistantSuggestionButton } from "../AssistantSuggestionButton"; | ||
| import { UserAvatar } from "../UserAvatar"; | ||
| import styles from "./styles.module.css"; | ||
| import type { ThreadMessageProps } from "./types"; | ||
|
|
@@ -12,6 +13,8 @@ export const ThreadMessage = ({ | |
| className, | ||
| content, | ||
| isAssistant, | ||
| onApplyAssistantSuggestion, | ||
| promptSuggestions = [], | ||
| username, | ||
| ...rest | ||
| }: ThreadMessageProps) => { | ||
|
|
@@ -50,6 +53,25 @@ export const ThreadMessage = ({ | |
| {content} | ||
| </Markdown> | ||
| </Text> | ||
|
|
||
| {promptSuggestions.length > 0 && ( | ||
| <Flex | ||
| className={styles.suggestions} | ||
| gap="var(--inner-spacing-5)" | ||
| paddingTop="spacing-4" | ||
| wrap="wrap" | ||
| > | ||
| {promptSuggestions.map((suggestion) => ( | ||
| <AssistantSuggestionButton | ||
| key={suggestion} | ||
| // eslint-disable-next-line react-perf/jsx-no-new-function-as-prop | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please do not suppress linter errors. If you don't agree on how this rule works, then you can bring it up for discussion and do something about it. |
||
| onPress={() => onApplyAssistantSuggestion?.(suggestion)} | ||
| > | ||
| {suggestion} | ||
| </AssistantSuggestionButton> | ||
| ))} | ||
| </Flex> | ||
| )} | ||
| </div> | ||
| ) : ( | ||
| <> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
app/client/src/components/propertyControls/ArrayComponent.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import { Button } from "@appsmith/ads"; | ||
| import { debounce } from "lodash"; | ||
| import React, { useCallback, useEffect, useState } from "react"; | ||
| import styled from "styled-components"; | ||
| import { ControlWrapper, InputGroup } from "./StyledControls"; | ||
|
|
||
| function updateOptionLabel<T>( | ||
| items: Array<T>, | ||
| index: number, | ||
| updatedLabel: string, | ||
| ) { | ||
| return items.map((option: T, optionIndex) => { | ||
| if (index !== optionIndex) { | ||
| return option; | ||
| } | ||
|
|
||
| return updatedLabel; | ||
| }); | ||
| } | ||
|
|
||
| const StyledBox = styled.div` | ||
| width: 10px; | ||
| `; | ||
|
|
||
| type UpdateItemsFunction = ( | ||
| items: string[], | ||
| isUpdatedViaKeyboard?: boolean, | ||
| ) => void; | ||
|
|
||
| interface ArrayComponentProps { | ||
| items: string[]; | ||
| updateItems: UpdateItemsFunction; | ||
| addLabel?: string; | ||
| } | ||
|
|
||
| const StyledInputGroup = styled(InputGroup)` | ||
| > .ads-v2-input__input-section > div { | ||
| flex: 1; | ||
| min-width: 0px; | ||
| } | ||
| `; | ||
|
|
||
| export function ArrayComponent(props: ArrayComponentProps) { | ||
| const [renderItems, setRenderItems] = useState<string[]>([]); | ||
| const [typing, setTyping] = useState<boolean>(false); | ||
| const { items } = props; | ||
|
|
||
| useEffect(() => { | ||
| let { items } = props; | ||
|
|
||
| items = Array.isArray(items) ? items.slice() : []; | ||
|
|
||
| items.length !== 0 && !typing && setRenderItems(items); | ||
| }, [props, items.length, renderItems.length, typing]); | ||
znamenskii-ilia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| const debouncedUpdateItems = useCallback( | ||
| debounce((updatedItems: string[]) => { | ||
| props.updateItems(updatedItems, true); | ||
| }, 200), | ||
| [props.updateItems], | ||
| ); | ||
znamenskii-ilia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function updateKey(index: number, updatedKey: string) { | ||
| let { items } = props; | ||
|
|
||
| items = Array.isArray(items) ? items : []; | ||
| const updatedItems = updateOptionLabel(items, index, updatedKey); | ||
| const updatedRenderItems = updateOptionLabel( | ||
| renderItems, | ||
| index, | ||
| updatedKey, | ||
| ); | ||
|
|
||
| setRenderItems(updatedRenderItems); | ||
| debouncedUpdateItems(updatedItems); | ||
| } | ||
|
|
||
| function deleteItem(index: number, isUpdatedViaKeyboard = false) { | ||
| let { items } = props; | ||
|
|
||
| items = Array.isArray(items) ? items : []; | ||
|
|
||
| const newItems = items.filter((o, i) => i !== index); | ||
| const newRenderItems = renderItems.filter((o, i) => i !== index); | ||
|
|
||
| setRenderItems(newRenderItems); | ||
| props.updateItems(newItems, isUpdatedViaKeyboard); | ||
| } | ||
|
|
||
| function addItem(e: React.MouseEvent) { | ||
| let { items } = props; | ||
|
|
||
| items = Array.isArray(items) ? items.slice() : []; | ||
|
|
||
| items.push(""); | ||
|
|
||
| const updatedRenderItems = renderItems.slice(); | ||
|
|
||
| updatedRenderItems.push(""); | ||
|
|
||
| setRenderItems(updatedRenderItems); | ||
| props.updateItems(items, e.detail === 0); | ||
| } | ||
znamenskii-ilia marked this conversation as resolved.
Show resolved
Hide resolved
znamenskii-ilia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| function onInputFocus() { | ||
| setTyping(true); | ||
| } | ||
|
|
||
| function onInputBlur() { | ||
| setTyping(false); | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| {renderItems.map((item: string, index) => { | ||
| return ( | ||
| <ControlWrapper key={index} orientation={"HORIZONTAL"}> | ||
znamenskii-ilia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <StyledInputGroup | ||
| dataType={"text"} | ||
| onBlur={onInputBlur} | ||
| onChange={(value: string) => updateKey(index, value)} | ||
| onFocus={onInputFocus} | ||
| value={item} | ||
| /> | ||
| <StyledBox /> | ||
| <Button | ||
| isIconButton | ||
| kind="tertiary" | ||
| onClick={(e: React.MouseEvent) => | ||
| deleteItem(index, e.detail === 0) | ||
| } | ||
| size="sm" | ||
| startIcon="delete-bin-line" | ||
| /> | ||
| </ControlWrapper> | ||
| ); | ||
| })} | ||
znamenskii-ilia marked this conversation as resolved.
Show resolved
Hide resolved
KelvinOm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| <div className="flex flex-row-reverse mt-1"> | ||
| <Button | ||
| className="t--property-control-options-add" | ||
| kind="tertiary" | ||
| onClick={addItem} | ||
| size="sm" | ||
| startIcon="plus" | ||
| > | ||
| {props.addLabel || "Add suggestion"} | ||
| </Button> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
48 changes: 48 additions & 0 deletions
48
app/client/src/components/propertyControls/ArrayControl.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { objectKeys } from "@appsmith/utils"; | ||
| import type { DropdownOption } from "components/constants"; | ||
| import React from "react"; | ||
| import { isDynamicValue } from "utils/DynamicBindingUtils"; | ||
| import { ArrayComponent } from "./ArrayComponent"; | ||
| import type { ControlData, ControlProps } from "./BaseControl"; | ||
| import BaseControl from "./BaseControl"; | ||
|
|
||
| class ArrayControl extends BaseControl<ControlProps> { | ||
| render() { | ||
| return ( | ||
| <ArrayComponent | ||
| items={this.props.propertyValue} | ||
| updateItems={this.updateItems} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| updateItems = (items: string[], isUpdatedViaKeyboard = false) => { | ||
| this.updateProperty(this.props.propertyName, items, isUpdatedViaKeyboard); | ||
| }; | ||
|
|
||
| static getControlType() { | ||
| return "ARRAY_INPUT"; | ||
| } | ||
|
|
||
| static canDisplayValueInUI(_config: ControlData, value: string): boolean { | ||
| if (isDynamicValue(value)) return false; | ||
|
|
||
| try { | ||
| const items: DropdownOption[] = JSON.parse(value); | ||
|
|
||
| for (const x of items) { | ||
| const keys = objectKeys(x); | ||
|
|
||
| if (!keys.includes("label") || !keys.includes("value")) { | ||
| return false; | ||
| } | ||
| } | ||
| } catch { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
KelvinOm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export default ArrayControl; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.