kibana/docs/extend
Pierre Gayvallet f3b4975c8c
[onechat] Introduce plugin and tool registry (#220889)
## 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>
2025-05-28 00:45:01 +03:00
..
images [docs] Miscellaneous docs clean up (#215260) 2025-03-25 12:57:00 +00:00
add-data-tutorials.md
advanced.md
application-service.md
building-kibana.md
ci-metrics.md
configuration-service.md
contributing.md
core-packages.md
dashboard-enhanced-plugin.md
dependencies-versions.md [Docs] Add link to dependencies page (#218588) 2025-04-21 14:54:05 -04:00
development-basepath.md
development-best-practices.md
development-documentation.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
development-getting-started.md
development-github.md
development-plugin-resources.md
development-pull-request.md
development-security.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
development-telemetry.md
development-tests.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
development-visualize-index.md
elasticsearch-service.md
enhanced-embeddables-plugin.md
external-plugin-development.md
external-plugin-functional-tests.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
external-plugin-localization.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
http-service.md
index.md [Docs] Add link to dependencies page (#218588) 2025-04-21 14:54:05 -04:00
interpreting-ci-failures.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
kibana-architecture.md
kibana-dashboard-plugin.md
kibana-debugging.md [docs] Fix image paths for docs-assembler (#218344) 2025-04-15 16:59:57 -05:00
kibana-expressions-plugin.md [docs] Fix image paths for docs-assembler (#218344) 2025-04-15 16:59:57 -05:00
kibana-issue-reporting.md
kibana-linting.md
kibana-navigation.md [docs] Miscellaneous docs clean up (#215260) 2025-03-25 12:57:00 +00:00
kibana-platform-api.md
kibana-platform-plugin-api.md
legacy-url-aliases.md
logging-config-changes.md
logging-service.md
monorepo-packages.md
patterns.md
plugin-list.md [onechat] Introduce plugin and tool registry (#220889) 2025-05-28 00:45:01 +03:00
plugin-performance.md
plugin-tooling.md
pr-review.md
reporting-integration.md
running-elasticsearch.md
running-kibana-advanced.md
sample-data.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
saved-objects-service.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
security-best-practices.md
sharing-saved-objects.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
stability.md [docs] Fix various syntax and rendering errors (#218883) 2025-05-22 10:10:07 +02:00
testing-kibana-plugin.md
toc.yml [Docs] Add link to dependencies page (#218588) 2025-04-21 14:54:05 -04:00
translations-plugin.md
typescript.md
ui-settings-service.md
uiactions-plugin.md [docs] Remove jsx from typescript code blocks (#213955) 2025-03-11 15:48:24 +00:00
upgrading-nodejs.md