From 2abe9000aa1d9f46cec17c3b8b61fc9520266a05 Mon Sep 17 00:00:00 2001 From: pgayvallet Date: Fri, 25 Jul 2025 11:46:05 +0200 Subject: [PATCH] [onechat] use `.chat-*` prefix for our system indices --- .../shared/onechat/onechat-server/index.ts | 1 + .../onechat/onechat-server/src/indices.ts | 20 +++++++++++++++++++ .../server/services/agents/client/storage.ts | 5 +++-- .../server/services/conversation/storage.ts | 3 ++- .../server/services/tools/client/storage.ts | 3 ++- 5 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 x-pack/platform/packages/shared/onechat/onechat-server/src/indices.ts diff --git a/x-pack/platform/packages/shared/onechat/onechat-server/index.ts b/x-pack/platform/packages/shared/onechat/onechat-server/index.ts index 62b32ab25892d..cb3809d3d95ae 100644 --- a/x-pack/platform/packages/shared/onechat/onechat-server/index.ts +++ b/x-pack/platform/packages/shared/onechat/onechat-server/index.ts @@ -50,3 +50,4 @@ export type { AgentEventEmitter, RunAgentOnEventFn, } from './agents'; +export { chatSystemIndex, chatSystemIndexPrefix } from './src/indices'; diff --git a/x-pack/platform/packages/shared/onechat/onechat-server/src/indices.ts b/x-pack/platform/packages/shared/onechat/onechat-server/src/indices.ts new file mode 100644 index 0000000000000..4bd508d6f234e --- /dev/null +++ b/x-pack/platform/packages/shared/onechat/onechat-server/src/indices.ts @@ -0,0 +1,20 @@ +/* + * 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. + */ + +/** + * Prefix of the chat system indices. + * + * The Kibana system user has the same permission on those indices than it has on Kibana system indices. + */ +export const chatSystemIndexPrefix = '.chat-'; + +/** + * Helper function to define chat system indices. + */ +export const chatSystemIndex = (suffix: string): string => { + return `${chatSystemIndexPrefix}${suffix}`; +}; diff --git a/x-pack/platform/plugins/shared/onechat/server/services/agents/client/storage.ts b/x-pack/platform/plugins/shared/onechat/server/services/agents/client/storage.ts index 893fd36e096af..f8a8f1839a1ac 100644 --- a/x-pack/platform/plugins/shared/onechat/server/services/agents/client/storage.ts +++ b/x-pack/platform/plugins/shared/onechat/server/services/agents/client/storage.ts @@ -8,11 +8,12 @@ import { IndexStorageSettings, StorageIndexAdapter, types } from '@kbn/storage-adapter'; import type { Logger, ElasticsearchClient } from '@kbn/core/server'; import type { AgentType, ToolSelection } from '@kbn/onechat-common'; +import { chatSystemIndex } from '@kbn/onechat-server'; -export const agentProfilesIndexName = '.kibana_onechat_agents'; +export const agentsIndexName = chatSystemIndex('agents'); const storageSettings = { - name: agentProfilesIndexName, + name: agentsIndexName, schema: { properties: { name: types.keyword({}), diff --git a/x-pack/platform/plugins/shared/onechat/server/services/conversation/storage.ts b/x-pack/platform/plugins/shared/onechat/server/services/conversation/storage.ts index 325e5101eb9fb..c989596435498 100644 --- a/x-pack/platform/plugins/shared/onechat/server/services/conversation/storage.ts +++ b/x-pack/platform/plugins/shared/onechat/server/services/conversation/storage.ts @@ -8,8 +8,9 @@ import type { Logger, ElasticsearchClient } from '@kbn/core/server'; import { IndexStorageSettings, StorageIndexAdapter, types } from '@kbn/storage-adapter'; import type { ConversationRound } from '@kbn/onechat-common'; +import { chatSystemIndex } from '@kbn/onechat-server'; -export const conversationIndexName = '.kibana_onechat_conversations'; +export const conversationIndexName = chatSystemIndex('conversations'); const storageSettings = { name: conversationIndexName, diff --git a/x-pack/platform/plugins/shared/onechat/server/services/tools/client/storage.ts b/x-pack/platform/plugins/shared/onechat/server/services/tools/client/storage.ts index 3a4b8adb525a6..d678793d1ebc6 100644 --- a/x-pack/platform/plugins/shared/onechat/server/services/tools/client/storage.ts +++ b/x-pack/platform/plugins/shared/onechat/server/services/tools/client/storage.ts @@ -8,8 +8,9 @@ import type { Logger, ElasticsearchClient } from '@kbn/core/server'; import { ToolType } from '@kbn/onechat-common'; import { IndexStorageSettings, StorageIndexAdapter, types } from '@kbn/storage-adapter'; +import { chatSystemIndex } from '@kbn/onechat-server'; -export const toolIndexName = '.kibana_onechat_tools'; +export const toolIndexName = chatSystemIndex('tools'); const storageSettings = { name: toolIndexName,