Skip to content

Commit

Permalink
Merge branch 'obs-ai-assistant-2' of github.com:dgieselaar/kibana int…
Browse files Browse the repository at this point in the history
…o obs-ai-assistant-2
  • Loading branch information
dgieselaar committed Aug 10, 2023
2 parents 668b2ba + 90dc879 commit 798a2b7
Show file tree
Hide file tree
Showing 7 changed files with 336 additions and 282 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/observability_ai_assistant/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface Message {
function_call?: {
name: string;
arguments?: string;
trigger: MessageRole.Assistant | MessageRole.User | MessageRole.Elastic;
trigger: MessageRole;
};
data?: string;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export interface ChatItemProps extends ChatTimelineItem {
}

const normalMessageClassName = css`
.euiCommentEvent__header {
padding: 4px 8px;
}
.euiCommentEvent__body {
padding: 0;
}
Expand All @@ -42,17 +46,17 @@ const normalMessageClassName = css`
`;

const noPanelMessageClassName = css`
.euiCommentEvent {
border: none;
}
.euiCommentEvent__header {
background: transparent;
border-block-end: none;
}
.euiCommentEvent__body {
padding: 0;
}
.euiCommentEvent {
border: none;
display: none;
}
`;

Expand Down Expand Up @@ -89,6 +93,10 @@ export function ChatItem({
const actions = [canCopy, collapsed, canCopy].filter(Boolean);

const noBodyMessageClassName = css`
.euiCommentEvent__header {
padding: 4px 8px;
}
.euiCommentEvent__body {
padding: 0;
height: ${expanded ? 'fit-content' : '0px'};
Expand All @@ -105,8 +113,8 @@ export function ChatItem({
};

const handleToggleEdit = () => {
if (collapsed) {
setExpanded(false);
if (collapsed && !expanded) {
setExpanded(true);
}
setEditing(!editing);
};
Expand Down Expand Up @@ -155,9 +163,10 @@ export function ChatItem({
actions={
<ChatItemActions
canCopy={canCopy}
collapsed={collapsed}
canEdit={canEdit}
isCollapsed={expanded}
collapsed={collapsed}
editing={editing}
expanded={expanded}
onCopyToClipboard={handleCopyToClipboard}
onToggleEdit={handleToggleEdit}
onToggleExpand={handleToggleExpand}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,21 @@ import React, { useEffect, useState } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiButtonIcon, EuiPopover, EuiText } from '@elastic/eui';

export interface ChatItemAction {
id: string;
label: string;
icon: string;
handler: () => void;
}

export function ChatItemActions({
canCopy,
canEdit,
collapsed,
canCopy,
isCollapsed,
editing,
expanded,
onToggleEdit,
onToggleExpand,
onCopyToClipboard,
}: {
canCopy: boolean;
canEdit: boolean;
collapsed: boolean;
canCopy: boolean;
isCollapsed: boolean;
editing: boolean;
expanded: boolean;
onToggleEdit: () => void;
onToggleExpand: () => void;
onCopyToClipboard: () => void;
Expand All @@ -47,85 +42,73 @@ export function ChatItemActions({
};
}, [isPopoverOpen]);

const actions: ChatItemAction[] = [
...(canEdit
? [
{
id: 'edit',
icon: 'documentEdit',
label: '',
handler: () => {
onToggleEdit();
},
},
]
: []),
...(collapsed
? [
{
id: 'expand',
icon: isCollapsed ? 'eyeClosed' : 'eye',
label: '',
handler: () => {
onToggleExpand();
},
},
]
: []),
...(canCopy
? [
{
id: 'copy',
icon: 'copyClipboard',
label: i18n.translate(
'xpack.observabilityAiAssistant.chatTimeline.actions.copyMessage',
{
defaultMessage: 'Copied message',
}
),
handler: () => {
onCopyToClipboard();
},
},
]
: []),
];
return (
<>
{actions.map(({ id, icon, label, handler }) =>
label ? (
<EuiPopover
key={id}
button={
<EuiButtonIcon
aria-label={label}
key={id}
iconType={icon}
onClick={() => {
setIsPopoverOpen(id);
handler();
}}
color="text"
/>
{canEdit ? (
<EuiButtonIcon
aria-label={i18n.translate(
'xpack.observabilityAiAssistant.chatTimeline.actions.editPrompt',
{
defaultMessage: 'Edit prompt',
}
)}
color="text"
display={editing ? 'fill' : 'empty'}
iconType="documentEdit"
onClick={onToggleEdit}
/>
) : null}

{collapsed ? (
<EuiButtonIcon
aria-label={i18n.translate(
'xpack.observabilityAiAssistant.chatTimeline.actions.inspectPrompt',
{
defaultMessage: 'Inspect prompt',
}
isOpen={isPopoverOpen === id}
closePopover={() => setIsPopoverOpen(undefined)}
panelPaddingSize="s"
>
<EuiText size="s">
<p>{label}</p>
</EuiText>
</EuiPopover>
) : (
<EuiButtonIcon
aria-label={label}
key={id}
iconType={icon}
onClick={handler}
color="text"
/>
)
)}
)}
color="text"
display={expanded ? 'fill' : 'empty'}
iconType={expanded ? 'eyeClosed' : 'eye'}
onClick={onToggleExpand}
/>
) : null}

{canCopy ? (
<EuiPopover
button={
<EuiButtonIcon
aria-label={i18n.translate(
'xpack.observabilityAiAssistant.chatTimeline.actions.copyMessage',
{
defaultMessage: 'Copy message',
}
)}
color="text"
iconType="copyClipboard"
display={isPopoverOpen === 'copy' ? 'fill' : 'empty'}
onClick={() => {
setIsPopoverOpen('copy');
onCopyToClipboard();
}}
/>
}
isOpen={isPopoverOpen === 'copy'}
panelPaddingSize="s"
closePopover={() => setIsPopoverOpen(undefined)}
>
<EuiText size="s">
<p>
{i18n.translate(
'xpack.observabilityAiAssistant.chatTimeline.actions.copyMessageSuccessful',
{
defaultMessage: 'Copied message',
}
)}
</p>
</EuiText>
</EuiPopover>
) : null}
</>
);
}
Loading

0 comments on commit 798a2b7

Please sign in to comment.