kibana/x-pack/platform/plugins/shared/onechat/server/plugin.ts
Dennis Tismenko 37c930a542
[onechat] Add tools page, show registered tools (#224330)
## Summary

Implements the tools page in the Onechat UI and retrieves the registered
tools from the Kibana API to display a list of all tools and
descriptions — descriptions are truncated at the first `\n` character.

![Screenshot 2025-06-24 at 2 10
37 PM](https://github.com/user-attachments/assets/f4ea70bd-0675-4d39-b120-123d2185752b)


### Checklist

Check the PR satisfies following conditions. 

Reviewers should verify this PR satisfies this list as well.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/src/platform/packages/shared/kbn-i18n/README.md)
- [ ]
~[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials~
- [ ] ~[Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios~
- [ ] ~If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)~
- [ ] ~This was checked for breaking HTTP API changes, and any breaking
changes have been approved by the breaking-change committee. The
`release_note:breaking` label should be applied in these situations.~
- [ ] ~[Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed~
- [ ] ~The PR description includes the appropriate Release Notes
section, and the correct `release_note:*` label is applied per the
[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)~

### Identify risks

Does this PR introduce any risks? For example, consider risks like hard
to test bugs, performance regression, potential of data loss.
__No risks are introduced in this PR.__

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
2025-06-26 09:34:53 -04:00

116 lines
3.2 KiB
TypeScript

/*
* 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 type { CoreSetup, CoreStart, Plugin, PluginInitializerContext } from '@kbn/core/server';
import type { Logger } from '@kbn/logging';
import type { OnechatConfig } from './config';
import { registerFeatures } from './features';
import { registerRoutes } from './routes';
import { ServiceManager } from './services';
import { registerTools } from './tools';
import type {
OnechatPluginSetup,
OnechatPluginStart,
OnechatSetupDependencies,
OnechatStartDependencies,
} from './types';
import { registerUISettings } from './ui_settings';
export class OnechatPlugin
implements
Plugin<
OnechatPluginSetup,
OnechatPluginStart,
OnechatSetupDependencies,
OnechatStartDependencies
>
{
private logger: Logger;
// @ts-expect-error unused for now
private config: OnechatConfig;
private serviceManager = new ServiceManager();
constructor(context: PluginInitializerContext<OnechatConfig>) {
this.logger = context.logger.get();
this.config = context.config.get();
}
setup(
coreSetup: CoreSetup<OnechatStartDependencies, OnechatPluginStart>,
pluginsSetup: OnechatSetupDependencies
): OnechatPluginSetup {
const serviceSetups = this.serviceManager.setupServices({
logger: this.logger.get('services'),
});
registerFeatures({ features: pluginsSetup.features });
registerTools({ tools: serviceSetups.tools });
registerUISettings({ uiSettings: coreSetup.uiSettings });
const router = coreSetup.http.createRouter();
registerRoutes({
router,
coreSetup,
logger: this.logger,
getInternalServices: () => {
const services = this.serviceManager.internalStart;
if (!services) {
throw new Error('getInternalServices called before service init');
}
return services;
},
});
return {
tools: {
register: serviceSetups.tools.register.bind(serviceSetups.tools),
registerProvider: serviceSetups.tools.registerProvider.bind(serviceSetups.tools),
},
};
}
start(
{ elasticsearch, security }: CoreStart,
{ actions, inference }: OnechatStartDependencies
): OnechatPluginStart {
const startServices = this.serviceManager.startServices({
logger: this.logger.get('services'),
security,
elasticsearch,
actions,
inference,
});
const { tools, agents, runnerFactory } = startServices;
const runner = runnerFactory.getRunner();
return {
tools: {
registry: tools.registry.asPublicRegistry(),
execute: runner.runTool.bind(runner),
asScoped: ({ request }) => {
return {
registry: tools.registry.asScopedPublicRegistry({ request }),
execute: (args) => {
return runner.runTool({ ...args, request });
},
};
},
},
agents: {
registry: agents.registry.asPublicRegistry(),
execute: async (args) => {
return agents.execute(args);
},
},
};
}
stop() {}
}