Skip to content
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

AI Chat: fix action menu #26555

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions components/ai_chat/resources/page/state/conversation_context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
// You can obtain one at https://mozilla.org/MPL/2.0/.

import * as React from 'react'

import * as mojom from 'gen/brave/components/ai_chat/core/common/mojom/ai_chat.mojom.m.js'
import usePromise from '$web-common/usePromise'
import * as API from '../api/'
import { useAIChat } from './ai_chat_context'
import { isLeoModel } from '../model_utils'
import { useAIChat } from './ai_chat_context'

const MAX_INPUT_CHAR = 2000
const CHAR_LIMIT_THRESHOLD = MAX_INPUT_CHAR * 0.8
Expand Down Expand Up @@ -125,10 +123,8 @@ export const getFirstValidAction = (actionList: mojom.ActionGroup[]) =>

export function useActionMenu(
filter: string,
getActions: () => Promise<mojom.ActionGroup[]>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't see the advantage of a "getter" param instead vs the data

actionList: mojom.ActionGroup[]
) {
const { result: actionList = [] } = usePromise(getActions, [])

return React.useMemo(() => {
const reg = new RegExp(/^\/\w+/)

Expand Down Expand Up @@ -314,8 +310,7 @@ export function ConversationContextProvider(
})
}, [context.conversationUuid, context.faviconCacheKey])

const actionList = useActionMenu(context.inputText, () =>
Promise.resolve(aiChatContext.allActions)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very confused about this 😆

const actionList = useActionMenu(context.inputText, aiChatContext.allActions
)

const shouldShowLongConversationInfo = React.useMemo(() => {
Expand Down
10 changes: 8 additions & 2 deletions components/ai_rewriter/resources/page/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,21 @@ export default function Context(props: React.PropsWithChildren) {
const [forwardHistory, setForwardHistory] = React.useState<string[]>([])
const [backHistory, setBackHistory] = React.useState<string[]>([])
const [isGenerating, setIsGenerating] = React.useState(false)
const [allActions, setAllActions] = React.useState<ActionGroup[]>([])

const actionList = useActionMenu(instructionsText, () => getRewriterPageHandler().getActionMenuList().then(({ actionList }) => actionList))
const actionList = useActionMenu(instructionsText, allActions)
const charCountContext = useCharCountInfo(instructionsText)

React.useEffect(() => {
getRewriterPageHandler()
const rewriterAPI = getRewriterPageHandler()
rewriterAPI
.getInitialText()
.then(({ initialText }) => setInitialText(initialText))

rewriterAPI
.getActionMenuList()
.then(({ actionList }) => setAllActions(actionList))

const callbackRouter = getCallbackRouter()
callbackRouter.onUpdatedGeneratedText.addListener(setGeneratedText)
return () => {
Expand Down
Loading