mirror of
https://github.com/elastic/kibana.git
synced 2025-06-27 10:40:07 -04:00
## Summary Implements the onechat tool registry RFC. Fix https://github.com/elastic/search-team/issues/9938 Fix https://github.com/elastic/search-team/issues/10019 This PR introduces the following artifacts: **plugins:** - `onechat` **packages:** - `@kbn/onechat-common` - `@kbn/onechat-server` - `@kbn/onechat-browser` ## Tool APIs overview ### Registering a tool ```ts class MyPlugin { setup(core: CoreSetup, { onechat }: { onechat: OnechatPluginSetup }) { onechat.tools.register({ id: 'my_tool', name: 'My Tool', description: 'My very first tool', meta: { tags: ['foo', 'bar'], }, schema: z.object({ someNumber: z.number().describe('Some random number'), }), handler: ({ someNumber }, context) => { return 42 + someNumber; }, }); } } ``` ### Executing a tool Using the `execute` API: ```ts const { result } = await onechat.tools.execute({ toolId: 'my_tool', toolParams: { someNumber: 9000 }, request, }); ``` Using a tool descriptor: ```ts const tool = await onechat.tools.registry.get({ toolId: 'my_tool', request }); const { result } = await tool.execute({ toolParams: { someNumber: 9000 } }); ``` With error handling: ```ts import { isToolNotFoundError } from '@kbn/onechat-common'; try { const { result } = await onechat.tools.execute({ toolId: 'my_tool', toolParams: { someNumber: 9000 }, request, }); } catch (e) { if (isToolNotFoundError(e)) { throw new Error(`run ${e.meta.runId} failed because tool was not found`); } } ``` ### Listing tools ```ts const tools = await onechat.tools.registry.list({ request }); ``` *More details and example in the plugin's readme.* ### What is **not** included in this PR: - tool access control / authorization - we have a dedicated RFC - dynamic tool registration / permissions checks part/of depends on the authorization RFC - feature / capabilities - will come with browser-side and HTTP APIs - fully defining tool meta - hard to do now - filter parameters for the tool list API - depends on the meta being defined *Those will be follow-ups*. Everything else from the RFC should be there. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> |
||
---|---|---|
.. | ||
kbn-babel-preset | ||
kbn-bazel-runner | ||
kbn-capture-oas-snapshot-cli | ||
kbn-check-mappings-update-cli | ||
kbn-check-prod-native-modules-cli | ||
kbn-ci-stats-performance-metrics | ||
kbn-ci-stats-shipper-cli | ||
kbn-cli-dev-mode | ||
kbn-dependency-ownership | ||
kbn-dependency-usage | ||
kbn-docs-utils | ||
kbn-eslint-config | ||
kbn-eslint-plugin-disable | ||
kbn-eslint-plugin-eslint | ||
kbn-eslint-plugin-eui-a11y | ||
kbn-eslint-plugin-i18n | ||
kbn-eslint-plugin-imports | ||
kbn-eslint-plugin-telemetry | ||
kbn-failed-test-reporter-cli | ||
kbn-find-used-node-modules | ||
kbn-generate | ||
kbn-generate-console-definitions | ||
kbn-import-locator | ||
kbn-json-ast | ||
kbn-kibana-manifest-schema | ||
kbn-lint-packages-cli | ||
kbn-lint-ts-projects-cli | ||
kbn-lock-manager | ||
kbn-managed-vscode-config | ||
kbn-managed-vscode-config-cli | ||
kbn-manifest | ||
kbn-mock-idp-plugin | ||
kbn-optimizer | ||
kbn-peggy-loader | ||
kbn-performance-testing-dataset-extractor | ||
kbn-picomatcher | ||
kbn-plugin-check | ||
kbn-plugin-generator | ||
kbn-plugin-helpers | ||
kbn-relocate | ||
kbn-repo-file-maps | ||
kbn-repo-linter | ||
kbn-repo-source-classifier | ||
kbn-repo-source-classifier-cli | ||
kbn-set-map | ||
kbn-sort-package-json | ||
kbn-styled-components-mapping-cli | ||
kbn-ts-projects | ||
kbn-ts-type-check-cli | ||
kbn-validate-next-docs-cli | ||
kbn-web-worker-stub | ||
kbn-whereis-pkg-cli | ||
kbn-yarn-lock-validator |