-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[OneChat] Test Tool Flyout #230484
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
Merged
meghanmurphy1
merged 19 commits into
elastic:main
from
meghanmurphy1:onechat-test-tool-flyout
Aug 28, 2025
Merged
[OneChat] Test Tool Flyout #230484
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
42adccc
test tool flyout
meghanmurphy1 a5ed989
use just list of parameters and add execute
meghanmurphy1 5991a0a
use form data
meghanmurphy1 8bf5889
use 'save and test' button
meghanmurphy1 d1c2463
revert some fixes
meghanmurphy1 3348b52
fix
meghanmurphy1 64b623e
put save and test on latest pages
meghanmurphy1 35d372e
rename folder
meghanmurphy1 b5d6c3b
address feedback
meghanmurphy1 19303c3
merge main
meghanmurphy1 c1ce978
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine 0821a1a
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine f7e49a8
configure height of codediter and move Response title to left
meghanmurphy1 ddfdbbb
move height a little
meghanmurphy1 57a6f04
add 75vh
meghanmurphy1 5e29369
use code block and use useTool hook
meghanmurphy1 fb9b791
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine 90a022f
use css and watch
meghanmurphy1 a80a658
Merge branch 'main' into onechat-test-tool-flyout
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
220 changes: 220 additions & 0 deletions
220
...latform/plugins/shared/onechat/public/application/components/tools/execute/test_tools.tsx
This file contains hidden or 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,220 @@ | ||
| /* | ||
| * 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 { | ||
| EuiButton, | ||
| EuiFieldText, | ||
| EuiFieldNumber, | ||
| EuiFlexGroup, | ||
| EuiFlexItem, | ||
| EuiFlyout, | ||
| EuiFlyoutBody, | ||
| EuiFlyoutHeader, | ||
| EuiForm, | ||
| EuiFormRow, | ||
| EuiSpacer, | ||
| EuiTitle, | ||
| EuiCodeBlock, | ||
| } from '@elastic/eui'; | ||
| import { css } from '@emotion/react'; | ||
| import React, { useState } from 'react'; | ||
| import { useForm, FormProvider, Controller } from 'react-hook-form'; | ||
| import type { ToolDefinition } from '@kbn/onechat-common'; | ||
| import { i18n } from '@kbn/i18n'; | ||
| import { useExecuteTool } from '../../../hooks/tools/use_execute_tools'; | ||
| import type { ExecuteToolResponse } from '../../../../../common/http_api/tools'; | ||
| import { useTool } from '../../../hooks/tools/use_tools'; | ||
|
|
||
| interface OnechatTestToolFlyout { | ||
| isOpen: boolean; | ||
| isLoading?: boolean; | ||
| toolId: string; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| interface ToolParameter { | ||
| name: string; | ||
| label: string; | ||
| value: string; | ||
| type: string; | ||
| } | ||
|
|
||
| const getParameters = (tool: ToolDefinition | undefined): Array<ToolParameter> => { | ||
| if (!tool) return []; | ||
|
|
||
| const fields: Array<ToolParameter> = []; | ||
| if (tool.configuration && tool.configuration.params) { | ||
| const params = tool.configuration.params as Record<string, any>; | ||
| Object.entries(params).forEach(([paramName, paramConfig]) => { | ||
| fields.push({ | ||
| name: paramName, | ||
| label: paramName, | ||
| value: '', | ||
| type: paramConfig.type || 'text', | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| return fields; | ||
| }; | ||
|
|
||
| export const OnechatTestFlyout: React.FC<OnechatTestToolFlyout> = ({ toolId, onClose }) => { | ||
| const [response, setResponse] = useState<string>('{}'); | ||
|
|
||
| const form = useForm<Record<string, any>>({ | ||
| mode: 'onChange', | ||
| }); | ||
|
|
||
| const { | ||
| handleSubmit, | ||
| formState: { errors }, | ||
| } = form; | ||
|
|
||
| const { tool } = useTool({ toolId }); | ||
|
|
||
| const { executeTool, isLoading: isExecuting } = useExecuteTool({ | ||
| onSuccess: (data: ExecuteToolResponse) => { | ||
| setResponse(JSON.stringify(data, null, 2)); | ||
| }, | ||
| onError: (error: Error) => { | ||
| setResponse(JSON.stringify({ error: error.message }, null, 2)); | ||
| }, | ||
| }); | ||
|
|
||
| const onSubmit = async (formData: Record<string, any>) => { | ||
| const toolParams: Record<string, any> = {}; | ||
| getParameters(tool).forEach((field) => { | ||
| if (field.name) { | ||
| let value = formData[field.name]; | ||
| if (field.type === 'integer' || field.type === 'long') { | ||
| value = parseInt(value, 10); | ||
| } else if (field.type === 'double' || field.type === 'float') { | ||
| value = parseFloat(value); | ||
| } | ||
| toolParams[field.name] = value; | ||
| } | ||
| }); | ||
|
|
||
| await executeTool({ | ||
| toolId: tool!.id, | ||
| toolParams, | ||
| }); | ||
| }; | ||
|
|
||
| return ( | ||
| <EuiFlyout onClose={onClose} aria-labelledby="flyoutTitle"> | ||
| <EuiFlyoutHeader hasBorder> | ||
| <EuiFlexGroup justifyContent="spaceBetween" alignItems="center"> | ||
| <EuiFlexItem> | ||
| <EuiTitle size="m"> | ||
| <h2 id="flyoutTitle"> | ||
| {i18n.translate('xpack.onechat.tools.testFlyout.title', { | ||
| defaultMessage: 'Test Tool', | ||
| })} | ||
| </h2> | ||
| </EuiTitle> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </EuiFlyoutHeader> | ||
| <EuiFlyoutBody> | ||
| <FormProvider {...form}> | ||
| <EuiFlexGroup gutterSize="l" responsive={false}> | ||
| <EuiFlexItem | ||
| grow={false} | ||
| css={css` | ||
| min-width: 200px; | ||
| max-width: 300px; | ||
| `} | ||
| > | ||
| <EuiTitle size="s"> | ||
| <h5> | ||
| {i18n.translate('xpack.onechat.tools.testTool.inputsTitle', { | ||
| defaultMessage: 'Inputs', | ||
| })} | ||
| </h5> | ||
| </EuiTitle> | ||
| <EuiSpacer size="m" /> | ||
| <EuiForm component="form" onSubmit={handleSubmit(onSubmit)}> | ||
| {getParameters(tool)?.map((field) => ( | ||
| <EuiFormRow | ||
| key={field.name} | ||
| label={field.label} | ||
| isInvalid={!!errors[field.name]} | ||
| error={errors[field.name]?.message as string} | ||
| > | ||
| {field.type === 'integer' || | ||
| field.type === 'long' || | ||
| field.type === 'double' || | ||
| field.type === 'float' ? ( | ||
| <Controller | ||
| name={field.name} | ||
| control={form.control} | ||
| rules={{ required: `${field.label} is required` }} | ||
| render={({ field: { onChange, value, name } }) => ( | ||
| <EuiFieldNumber | ||
| name={name} | ||
| value={value || ''} | ||
| onChange={(e) => onChange(e.target.value)} | ||
| placeholder={`Enter ${field.label.toLowerCase()}`} | ||
| fullWidth | ||
| /> | ||
| )} | ||
| /> | ||
| ) : ( | ||
| <Controller | ||
| name={field.name} | ||
| control={form.control} | ||
| rules={{ required: `${field.label} is required` }} | ||
| render={({ field: { onChange, value, name } }) => ( | ||
| <EuiFieldText | ||
| name={name} | ||
| value={value || ''} | ||
| onChange={(e) => onChange(e.target.value)} | ||
| placeholder={`Enter ${field.label.toLowerCase()}`} | ||
| fullWidth | ||
| /> | ||
| )} | ||
| /> | ||
| )} | ||
| </EuiFormRow> | ||
| ))} | ||
| <EuiSpacer size="m" /> | ||
| <EuiButton type="submit" size="s" fill isLoading={isExecuting} disabled={!tool}> | ||
| {i18n.translate('xpack.onechat.tools.testTool.executeButton', { | ||
| defaultMessage: 'Submit', | ||
| })} | ||
| </EuiButton> | ||
| </EuiForm> | ||
| </EuiFlexItem> | ||
| <EuiFlexItem> | ||
| <EuiTitle size="s"> | ||
| <h5> | ||
| {i18n.translate('xpack.onechat.tools.testTool.responseTitle', { | ||
| defaultMessage: 'Response', | ||
| })} | ||
| </h5> | ||
| </EuiTitle> | ||
| <EuiSpacer size="m" /> | ||
| <EuiCodeBlock | ||
| language="json" | ||
| fontSize="s" | ||
| paddingSize="m" | ||
| isCopyable={true} | ||
| css={css` | ||
| height: 75vh; | ||
| overflow: auto; | ||
| `} | ||
| > | ||
| {response} | ||
| </EuiCodeBlock> | ||
| </EuiFlexItem> | ||
| </EuiFlexGroup> | ||
| </FormProvider> | ||
| </EuiFlyoutBody> | ||
| </EuiFlyout> | ||
| ); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.