Skip to content
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
5 changes: 1 addition & 4 deletions packages/cozy-search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@
},
"dependencies": {
"@assistant-ui/react": "^0.12.5",
"class-variance-authority": "^0.7.1",
"classnames": "^2.5.1",
"clsx": "^2.1.1",
"lodash": "^4.17.21",
"lucide-react": "^0.563.0",
"mime-types": "2.1.35",
"react-type-animation": "3.2.0",
"rooks": "7.14.1"
Expand Down Expand Up @@ -86,7 +83,7 @@
"directory": "packages/cozy-search"
},
"scripts": {
"build": "yarn build:clean && yarn build:types && babel --extensions .ts,.tsx,.js,.jsx --ignore '**/*.spec.tsx','**/*.spec.ts','**/*.d.ts' ./src -d ./dist --copy-files",
"build": "yarn build:clean && yarn build:types && babel --extensions .ts,.tsx,.js,.jsx --ignore '**/*.spec.tsx','**/*.spec.ts','**/*.spec.js','**/*.spec.jsx','**/*.d.ts' ./src -d ./dist --copy-files",
"build:clean": "rm -rf ./dist",
"build:types": "tsc -p tsconfig-build.json",
"build:watch": "yarn build --watch",
Expand Down
2 changes: 1 addition & 1 deletion packages/cozy-search/src/actions/delete.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const remove = ({ t }) => {
Component: makeComponent(label, icon),
displayCondition: () => true,
action: () => {
// TO DO: Add action to remove
// TO DO: Add action to remove due to this action does not exist yet in backend, we will implement it later
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is to remove a conversation? If yes, you can simply remove it with a await client.destroy(conversation)

}
}
}
2 changes: 1 addition & 1 deletion packages/cozy-search/src/actions/rename.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const rename = ({ t }) => {
Component: makeComponent(label, icon),
displayCondition: () => true,
action: () => {
// TO DO: Add action to remove
// TO DO: Add action to rename due to this action does not exist yet in backend, we will implement it later
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You can rename a conversation like this

const newConversation = {...conversation, title: newTitle }
await client.save(newConversation)

But I don't think title currently exist in conversations: https://github.com/cozy/cozy-doctypes/blob/master/docs/io.cozy.ai.chat.conversations.md
So it needs to be added in cozy-stack, you can use your current PR for that. Do you any other field that should be added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Currently, we don't have title field and I think we should implement this function in another PR, this one is use to resolve the current issues of assistant. Also, it will take time to implement and I'm working on calendar team so I cannot implement it at this moment.
What do you think @paultranvan

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, this can done later

}
Comment thread
lethemanh marked this conversation as resolved.
}
}
2 changes: 1 addition & 1 deletion packages/cozy-search/src/actions/share.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const share = ({ t }) => {
Component: makeComponent(label, icon),
displayCondition: () => true,
action: () => {
// TO DO: Add action to remove
// TO DO: Add action to share due to this action does not exist yet in backend, we will implement it later
}
Comment thread
lethemanh marked this conversation as resolved.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import styles from './styles.styl'
import { DEFAULT_ASSISTANT } from '../constants'

const AssistantAvatar = ({ assistant, isSmall, className }) => {
if (!assistant) return
if (!assistant) return null

if (assistant.id !== DEFAULT_ASSISTANT.id && !assistant.icon) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import cx from 'classnames'
import React from 'react'

import flag from 'cozy-flags'
import Divider from 'cozy-ui/transpiled/react/Divider'
import { useCozyTheme } from 'cozy-ui-plus/dist/providers/CozyTheme'

import { useAssistant } from '../AssistantProvider'
import styles from './styles.styl'
import PrettyScrollbar from '../Containers/PrettyScrollbar'
import Conversation from '../Conversations/Conversation'
import CozyAssistantRuntimeProvider from '../CozyAssistantRuntimeProvider'
import CozyAssistantRuntimeProviderWithErrorBoundary from '../CozyAssistantRuntimeProvider'
import SearchConversation from '../Search/SearchConversation'
import Sidebar from '../Sidebar'
import TwakeKnowledgePanel from '../TwakeKnowledges/TwakeKnowledgePanel'
Expand All @@ -19,6 +19,7 @@ const AssistantContainer = () => {
openedKnowledgePanel,
setOpenedKnowledgePanel
} = useAssistant()
const { type: theme } = useCozyTheme()
Comment thread
lethemanh marked this conversation as resolved.

return (
<div
Expand All @@ -27,23 +28,26 @@ const AssistantContainer = () => {
styles['assistant-container']
)}
>
<Sidebar className="u-w-5 u-pb-1 u-bg-white" />
<Sidebar className="u-w-5 u-pb-0-t u-pb-1" />

<Divider orientation="vertical" flexItem />

<PrettyScrollbar className="u-flex-auto u-flex u-flex-column u-pb-1 u-ov-hidden u-bg-white">
<PrettyScrollbar className="u-flex-auto u-flex u-flex-column u-pb-0-t u-pb-1 u-ov-hidden">
{isOpenSearchConversation &&
flag('cozy.search-conversation.enabled') ? (
<SearchConversation />
) : (
<CozyAssistantRuntimeProvider>
<CozyAssistantRuntimeProviderWithErrorBoundary>
<Conversation />
</CozyAssistantRuntimeProvider>
</CozyAssistantRuntimeProviderWithErrorBoundary>
)}
</PrettyScrollbar>

{openedKnowledgePanel && flag('cozy.source-knowledge.enabled') && (
<div className="u-ml-half u-h-100 u-maw-7">
<div
className={cx(
'u-h-100 u-maw-7 u-pl-half',
styles[`knowledge-panel--${theme}`]
)}
>
<TwakeKnowledgePanel
onClose={() => setOpenedKnowledgePanel(undefined)}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import cx from 'classnames'
import React, { useState, useRef } from 'react'
import React, { useState, useRef, useEffect } from 'react'
import { useI18n } from 'twake-i18n'

import { useQuery } from 'cozy-client'
import ActionsMenu from 'cozy-ui/transpiled/react/ActionsMenu'
import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
import Chips from 'cozy-ui/transpiled/react/Chips'
import Icon from 'cozy-ui/transpiled/react/Icon'
import DropdownIcon from 'cozy-ui/transpiled/react/Icons/Dropdown'
import PlusIcon from 'cozy-ui/transpiled/react/Icons/Plus'
import Typography from 'cozy-ui/transpiled/react/Typography'
import { useBreakpoints } from 'cozy-ui/transpiled/react/providers/Breakpoints'

import styles from './styles.styl'
import { useAssistant } from '../AssistantProvider'
Expand All @@ -16,7 +19,9 @@ import { buildAssistantsQuery } from '../queries'
import AssistantAvatar from './AssistantAvatar'
import AssistantSelectionItem from './AssistantSelectionItem'

const AssistantSelection = ({ className }) => {
const AssistantSelection = ({ className, disabled }) => {
const { t } = useI18n()
Comment thread
coderabbitai[bot] marked this conversation as resolved.
const { isMobile } = useBreakpoints()
const buttonRef = useRef(null)
const [open, setOpen] = useState(false)
const {
Expand All @@ -28,11 +33,18 @@ const AssistantSelection = ({ className }) => {
setSelectedAssistantId
} = useAssistant()

useEffect(() => {
if (disabled) {
setOpen(false)
}
}, [disabled])

const assistantsQuery = buildAssistantsQuery()
const assistants =
useQuery(assistantsQuery.definition, assistantsQuery.options)?.data || []

const handleClick = () => {
if (disabled) return
setOpen(true)
}

Expand Down Expand Up @@ -60,9 +72,16 @@ const AssistantSelection = ({ className }) => {
assistant={selectedAssistant}
/>
}
label={selectedAssistant.name}
label={
isMobile ? (
<Icon className={styles['dropdown-icon']} icon={DropdownIcon} />
) : (
selectedAssistant.name
)
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: I always prefer to put the truthy value first it is easier to understand withouth a !

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed

clickable
onClick={handleClick}
disabled={disabled}
/>
</div>
{open && (
Expand Down Expand Up @@ -101,7 +120,9 @@ const AssistantSelection = ({ className }) => {
>
<div className="u-flex u-flex-items-center">
<Icon icon={PlusIcon} className={styles['create-icon']} />
<Typography variant="body1">Create Assistant</Typography>
<Typography variant="body1">
{t('assistant_create.title')}
</Typography>
</div>
</ActionsMenuItem>
</ActionsMenu>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import React from 'react'
import cx from 'classnames'
import React, { useMemo } from 'react'

import ActionsMenuItem from 'cozy-ui/transpiled/react/ActionsMenu/ActionsMenuItem'
import Badge from 'cozy-ui/transpiled/react/Badge'
import Icon from 'cozy-ui/transpiled/react/Icon'
import IconButton from 'cozy-ui/transpiled/react/IconButton'
import CheckIcon from 'cozy-ui/transpiled/react/Icons/Check'
import PenIcon from 'cozy-ui/transpiled/react/Icons/Pen'
import TrashIcon from 'cozy-ui/transpiled/react/Icons/Trash'
import Typography from 'cozy-ui/transpiled/react/Typography'
import { useBreakpoints } from 'cozy-ui/transpiled/react/providers/Breakpoints'

import styles from './styles.styl'
import AssistantAvatar from '../Assistant/AssistantAvatar'
Expand All @@ -21,6 +24,8 @@ const AssistantSelectionItem = ({
setIsOpenEditAssistant,
disableActions = false
}) => {
const { isMobile } = useBreakpoints()

const handleSelect = assistant => {
onSelect(assistant)
onClose()
Expand All @@ -40,33 +45,67 @@ const AssistantSelectionItem = ({
e.stopPropagation()
}

const isSelected = useMemo(
() => selectedAssistant?.id === assistant.id,
[selectedAssistant?.id, assistant.id]
)

return (
<ActionsMenuItem
onClick={() => handleSelect(assistant)}
className={styles['menu-item']}
>
<div className="u-flex u-flex-items-center">
<AssistantAvatar assistant={assistant} />
{isMobile && isSelected ? (
<Badge
badgeContent={
<Icon
icon={CheckIcon}
size={10}
className={styles['selected-item--mobile']}
/>
}
variant="standard"
size="small"
anchorOrigin={{
vertical: 'bottom',
horizontal: 'right'
}}
overlap="circular"
>
<AssistantAvatar assistant={assistant} />
</Badge>
) : (
<AssistantAvatar assistant={assistant} />
)}
<Typography variant="body1">{assistant.name}</Typography>
</div>
<div className="u-flex u-flex-items-center u-flex-justify-between">
{selectedAssistant?.id === assistant.id && (
{isSelected && !isMobile && (
<Icon icon={CheckIcon} className="u-success" />
)}
{!disableActions && (
<>
<IconButton
aria-label="Edit assistant"
size="small"
className={styles['menu-item-icon-button']}
className={cx({
[styles['menu-item-icon-button']]:
!isMobile || (!isSelected && isMobile),
'u-db': isSelected && isMobile
})}
onClick={handleEdit}
>
<Icon icon={PenIcon} color="var(--primaryColor)" />
</IconButton>
<IconButton
aria-label="Delete assistant"
size="small"
className={styles['menu-item-icon-button']}
className={cx({
[styles['menu-item-icon-button']]:
!isMobile || (!isSelected && isMobile),
'u-db': isSelected && isMobile
})}
onClick={handleDelete}
>
<Icon icon={TrashIcon} className="u-error" />
Expand Down
18 changes: 17 additions & 1 deletion packages/cozy-search/src/components/Assistant/styles.styl
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.assistant-container
z-index 1

.knowledge-panel
&--light
background-color var(--primaryBackgroundLight)

&--dark
background-color var(--greyA400)

.trigger-button
border-radius 20px
padding 4px 12px
Expand Down Expand Up @@ -36,4 +43,13 @@
display none !important

.create-icon
margin-right 8px
margin-right 0.5rem

.dropdown-icon
margin-top 0.25rem

.selected-item--mobile
padding 1px
border-radius 100%
color var(--white)
background-color var(--malachite)
43 changes: 43 additions & 0 deletions packages/cozy-search/src/components/AssistantProvider.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react'

export interface AssistantState {
message: Record<string, string>
status: 'idle' | 'writing' | 'pending'
messagesId: string[]
}

export interface TwakeKnowledgeState {
drive: { id: string; name: string }[]
mail: { id: string; name: string }[]
chat: { id: string; name: string }[]
}

export interface AssistantContextValue {
assistantState: AssistantState
isOpenCreateAssistant: boolean
isOpenDeleteAssistant: boolean
isOpenEditAssistant: boolean
assistantIdInAction: string | null
selectedAssistantId: string
isOpenSearchConversation: boolean
openedKnowledgePanel: string | null
selectedTwakeKnowledge: TwakeKnowledgeState
setAssistantIdInAction: (id: string | null) => void
setIsOpenDeleteAssistant: (isOpen: boolean) => void
setAssistantState: React.Dispatch<React.SetStateAction<AssistantState>>
clearAssistant: () => void
onAssistantExecute: (
params: { value: string; conversationId: string },
callback?: () => void
) => Promise<void>
setIsOpenCreateAssistant: (isOpen: boolean) => void
setIsOpenEditAssistant: (isOpen: boolean) => void
setSelectedAssistantId: (id: string) => void
setIsOpenSearchConversation: (isOpen: boolean) => void
setOpenedKnowledgePanel: (panel: string | null) => void
setSelectedTwakeKnowledge: React.Dispatch<
React.SetStateAction<TwakeKnowledgeState>
>
}

export function useAssistant(): AssistantContextValue
3 changes: 3 additions & 0 deletions packages/cozy-search/src/components/AssistantProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { CHAT_EVENTS_DOCTYPE, CHAT_CONVERSATIONS_DOCTYPE } from './queries'

export const AssistantContext = React.createContext()

/**
* @returns {import('./AssistantProvider').AssistantContextValue}
*/
export const useAssistant = () => {
const context = useContext(AssistantContext)

Expand Down
Loading
Loading