Skip to content

Commit

Permalink
distinct tool use styles
Browse files Browse the repository at this point in the history
  • Loading branch information
nl0 committed Aug 9, 2024
1 parent 8ecac84 commit 1209b8d
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions catalog/app/components/Assistant/UI/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import Input from './Input'
import backgroundPattern from './bg.svg'

Check warning on line 13 in catalog/app/components/Assistant/UI/Chat/Chat.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/components/Assistant/UI/Chat/Chat.tsx#L12-L13

Added lines #L12 - L13 were not covered by tests

const USER_BG = M.colors.cyan[100]
const TOOL_BG = M.colors.amber[100]

Check warning on line 16 in catalog/app/components/Assistant/UI/Chat/Chat.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/components/Assistant/UI/Chat/Chat.tsx#L15-L16

Added lines #L15 - L16 were not covered by tests

const useMessageContainerStyles = M.makeStyles((t) => ({

Check warning on line 18 in catalog/app/components/Assistant/UI/Chat/Chat.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/components/Assistant/UI/Chat/Chat.tsx#L18

Added line #L18 was not covered by tests
role_user: {},
role_assistant: {},
role_tool: {},
messageContainer: {
alignItems: 'flex-end',
display: 'flex',
Expand All @@ -25,7 +27,7 @@ const useMessageContainerStyles = M.makeStyles((t) => ({
alignSelf: 'flex-end',
flexFlow: 'row-reverse',
},
'&$role_assistant': {
'&$role_assistant, &$role_tool': {
alignSelf: 'flex-start',
},
},
Expand All @@ -39,6 +41,9 @@ const useMessageContainerStyles = M.makeStyles((t) => ({
'$role_assistant &': {
background: t.palette.background.paper,
},
'$role_tool &': {
background: TOOL_BG,
},
},
contentArea: {
borderRadius: `${t.spacing(1)}px`,
Expand All @@ -50,6 +55,10 @@ const useMessageContainerStyles = M.makeStyles((t) => ({
background: t.palette.background.paper,
borderBottomLeftRadius: 0,
},
'$role_tool &': {
background: TOOL_BG,
borderBottomLeftRadius: 0,
},
},
contents: {
...t.typography.body2,
Expand Down Expand Up @@ -78,8 +87,14 @@ const useMessageContainerStyles = M.makeStyles((t) => ({
},
}))

const ICONS = {

Check warning on line 90 in catalog/app/components/Assistant/UI/Chat/Chat.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/components/Assistant/UI/Chat/Chat.tsx#L90

Added line #L90 was not covered by tests
user: 'person',
assistant: 'assistant',
tool: 'build',
}

interface MessageContainerProps {
role: 'user' | 'assistant'
role: 'user' | 'assistant' | 'tool'
children: React.ReactNode
actions?: React.ReactNode
timestamp?: Date
Expand All @@ -90,7 +105,7 @@ function MessageContainer({ role, children, actions, timestamp }: MessageContain
return (

Check warning on line 105 in catalog/app/components/Assistant/UI/Chat/Chat.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/components/Assistant/UI/Chat/Chat.tsx#L103-L105

Added lines #L103 - L105 were not covered by tests
<div className={cx(classes.messageContainer, classes[`role_${role}`])}>
<M.Avatar className={classes.avatar}>
<M.Icon fontSize="small">{role === 'user' ? 'person' : 'assistant'}</M.Icon>
<M.Icon fontSize="small">{ICONS[role]}</M.Icon>
</M.Avatar>
<div className={classes.contentArea}>
<div className={classes.contents}>{children}</div>
Expand Down Expand Up @@ -198,7 +213,7 @@ function ToolUseEvent({
)
return (

Check warning on line 214 in catalog/app/components/Assistant/UI/Chat/Chat.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/components/Assistant/UI/Chat/Chat.tsx#L214

Added line #L214 was not covered by tests
<MessageContainer
role="assistant"
role="tool"
timestamp={timestamp}
actions={discard && <MessageAction onClick={discard}>discard</MessageAction>}
>
Expand Down Expand Up @@ -232,7 +247,7 @@ function ToolUseState({ timestamp, dispatch, calls }: ToolUseStateProps) {

return (

Check warning on line 248 in catalog/app/components/Assistant/UI/Chat/Chat.tsx

View check run for this annotation

Codecov / codecov/patch/informational

catalog/app/components/Assistant/UI/Chat/Chat.tsx#L248

Added line #L248 was not covered by tests
<MessageContainer
role="assistant"
role="tool"
timestamp={timestamp}
actions={<MessageAction onClick={abort}>abort</MessageAction>}
>
Expand Down

0 comments on commit 1209b8d

Please sign in to comment.