forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add JSON schema validation for Prompt Editor
- Loading branch information
1 parent
f1426b6
commit 264d09f
Showing
10 changed files
with
373 additions
and
155 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
92 changes: 92 additions & 0 deletions
92
x-pack/plugins/observability_ai_assistant/public/components/chat/function_list_popover.tsx
This file contains 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,92 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useEffect, useState } from 'react'; | ||
import { | ||
EuiButtonEmpty, | ||
EuiContextMenuItem, | ||
EuiContextMenuPanel, | ||
EuiPopover, | ||
EuiSpacer, | ||
EuiText, | ||
} from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { FunctionDefinition } from '../../../common/types'; | ||
|
||
export function FunctionListPopover({ | ||
functions, | ||
selectedFunction, | ||
onSelectFunction, | ||
}: { | ||
functions: FunctionDefinition[]; | ||
selectedFunction?: FunctionDefinition; | ||
onSelectFunction: (func: FunctionDefinition) => void; | ||
}) { | ||
const [isFunctionListOpen, setIsFunctionListOpen] = useState(false); | ||
|
||
const handleClickFunctionList = () => { | ||
setIsFunctionListOpen(!isFunctionListOpen); | ||
}; | ||
|
||
const handleSelectFunction = (func: FunctionDefinition) => { | ||
setIsFunctionListOpen(false); | ||
onSelectFunction(func); | ||
}; | ||
|
||
useEffect(() => { | ||
const keyboardListener = (event: KeyboardEvent) => { | ||
if (event.code === 'Digit4') { | ||
setIsFunctionListOpen(true); | ||
} | ||
}; | ||
|
||
window.addEventListener('keyup', keyboardListener); | ||
|
||
return () => { | ||
window.removeEventListener('keyup', keyboardListener); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<EuiPopover | ||
anchorPosition="downLeft" | ||
button={ | ||
<EuiButtonEmpty | ||
iconType="arrowRight" | ||
iconSide="right" | ||
size="xs" | ||
onClick={handleClickFunctionList} | ||
> | ||
{selectedFunction | ||
? selectedFunction.options.name | ||
: i18n.translate('xpack.observabilityAiAssistant.prompt.callFunction', { | ||
defaultMessage: 'Call function', | ||
})} | ||
</EuiButtonEmpty> | ||
} | ||
closePopover={handleClickFunctionList} | ||
panelPaddingSize="none" | ||
isOpen={isFunctionListOpen} | ||
> | ||
<EuiContextMenuPanel size="s"> | ||
{functions.map((func) => ( | ||
<EuiContextMenuItem key={func.options.name} onClick={() => handleSelectFunction(func)}> | ||
<EuiText size="s"> | ||
<p> | ||
<strong>{func.options.name}</strong> | ||
</p> | ||
</EuiText> | ||
<EuiSpacer size="xs" /> | ||
<EuiText size="s"> | ||
<p>{func.options.description}</p> | ||
</EuiText> | ||
</EuiContextMenuItem> | ||
))} | ||
</EuiContextMenuPanel> | ||
</EuiPopover> | ||
); | ||
} |
Oops, something went wrong.