-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AI Assistant] Add setting for preferred type
- Loading branch information
1 parent
084af44
commit c97d92f
Showing
18 changed files
with
299 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
14 changes: 14 additions & 0 deletions
14
src/plugins/ai_assistant_management/selection/common/ai_assistant_type.ts
This file contains 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,14 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export enum AIAssistantType { | ||
Security = 'security', | ||
Observability = 'observability', | ||
Default = 'default', | ||
Never = 'never', | ||
} |
9 changes: 9 additions & 0 deletions
9
src/plugins/ai_assistant_management/selection/common/ui_setting_keys.ts
This file contains 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,9 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
export const PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY = 'aiAssistant:preferredAIAssistantType'; |
This file contains 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 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 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 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
13 changes: 13 additions & 0 deletions
13
src/plugins/ai_assistant_management/selection/public/types.ts
This file contains 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,13 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { AIAssistantType } from '../common/ai_assistant_type'; | ||
|
||
export interface ConfigSchema { | ||
preferredAIAssistantType: AIAssistantType; | ||
} |
33 changes: 33 additions & 0 deletions
33
src/plugins/ai_assistant_management/selection/server/config.ts
This file contains 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,33 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { schema, TypeOf } from '@kbn/config-schema'; | ||
import { PluginConfigDescriptor } from '@kbn/core-plugins-server'; | ||
import { AIAssistantType } from '../common/ai_assistant_type'; | ||
|
||
const configSchema = schema.object({ | ||
enabled: schema.boolean({ defaultValue: true }), | ||
preferredAIAssistantType: schema.oneOf( | ||
[ | ||
schema.literal(AIAssistantType.Default), | ||
schema.literal(AIAssistantType.Never), | ||
schema.literal(AIAssistantType.Observability), | ||
schema.literal(AIAssistantType.Security), | ||
], | ||
{ defaultValue: AIAssistantType.Default } | ||
), | ||
}); | ||
|
||
export type AIAssistantManagementSelectionConfig = TypeOf<typeof configSchema>; | ||
|
||
export const config: PluginConfigDescriptor<AIAssistantManagementSelectionConfig> = { | ||
schema: configSchema, | ||
exposeToBrowser: { | ||
preferredAIAssistantType: true, | ||
}, | ||
}; |
16 changes: 16 additions & 0 deletions
16
src/plugins/ai_assistant_management/selection/server/index.ts
This file contains 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,16 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { PluginInitializerContext } from '@kbn/core/server'; | ||
|
||
export { config } from './config'; | ||
|
||
export const plugin = async (initContext: PluginInitializerContext) => { | ||
const { AIAssistantManagementSelectionPlugin } = await import('./plugin'); | ||
return new AIAssistantManagementSelectionPlugin(initContext); | ||
}; |
90 changes: 90 additions & 0 deletions
90
src/plugins/ai_assistant_management/selection/server/plugin.ts
This file contains 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,90 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import type { PluginInitializerContext, CoreSetup, CoreStart, Plugin } from '@kbn/core/server'; | ||
import { schema } from '@kbn/config-schema'; | ||
import type { AIAssistantManagementSelectionConfig } from './config'; | ||
import type { | ||
AIAssistantManagementSelectionPluginServerSetup, | ||
AIAssistantManagementSelectionPluginServerStart, | ||
} from './types'; | ||
import { AIAssistantType } from '../common/ai_assistant_type'; | ||
import { PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY } from '../common/ui_setting_keys'; | ||
|
||
export class AIAssistantManagementSelectionPlugin | ||
implements | ||
Plugin< | ||
AIAssistantManagementSelectionPluginServerSetup, | ||
AIAssistantManagementSelectionPluginServerStart | ||
> | ||
{ | ||
private readonly config: AIAssistantManagementSelectionConfig; | ||
|
||
constructor(initializerContext: PluginInitializerContext) { | ||
this.config = initializerContext.config.get(); | ||
} | ||
|
||
public setup(core: CoreSetup) { | ||
core.uiSettings.register({ | ||
[PREFERRED_AI_ASSISTANT_TYPE_SETTING_KEY]: { | ||
name: i18n.translate('aiAssistantManagementSelection.preferredAIAssistantTypeSettingName', { | ||
defaultMessage: 'AI Assistant type', | ||
}), | ||
value: this.config.preferredAIAssistantType, | ||
description: i18n.translate( | ||
'aiAssistantManagementSelection.preferredAIAssistantTypeSettingDescription', | ||
{ defaultMessage: 'Select an AI Assistant to use, or disable it entirely' } | ||
), | ||
schema: schema.oneOf( | ||
[ | ||
schema.literal(AIAssistantType.Default), | ||
schema.literal(AIAssistantType.Observability), | ||
schema.literal(AIAssistantType.Security), | ||
schema.literal(AIAssistantType.Never), | ||
], | ||
{ defaultValue: this.config.preferredAIAssistantType } | ||
), | ||
options: [ | ||
AIAssistantType.Default, | ||
AIAssistantType.Observability, | ||
AIAssistantType.Security, | ||
AIAssistantType.Never, | ||
], | ||
type: 'select', | ||
optionLabels: { | ||
[AIAssistantType.Default]: i18n.translate( | ||
'aiAssistantManagementSelection.preferredAIAssistantTypeSettingValueDefault', | ||
{ defaultMessage: 'Default' } | ||
), | ||
[AIAssistantType.Observability]: i18n.translate( | ||
'aiAssistantManagementSelection.preferredAIAssistantTypeSettingValueObservability', | ||
{ defaultMessage: 'Observability' } | ||
), | ||
[AIAssistantType.Security]: i18n.translate( | ||
'aiAssistantManagementSelection.preferredAIAssistantTypeSettingValueSecurity', | ||
{ defaultMessage: 'Security' } | ||
), | ||
[AIAssistantType.Never]: i18n.translate( | ||
'aiAssistantManagementSelection.preferredAIAssistantTypeSettingValueNever', | ||
{ defaultMessage: 'Disable everywhere' } | ||
), | ||
}, | ||
requiresPageReload: true, | ||
}, | ||
}); | ||
|
||
return {}; | ||
} | ||
|
||
public start(core: CoreStart) { | ||
return {}; | ||
} | ||
|
||
public stop() {} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/plugins/ai_assistant_management/selection/server/types.ts
This file contains 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,18 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface AIAssistantManagementSelectionPluginServerDependenciesStart {} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface AIAssistantManagementSelectionPluginServerDependenciesSetup {} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface AIAssistantManagementSelectionPluginServerStart {} | ||
// eslint-disable-next-line @typescript-eslint/no-empty-interface | ||
export interface AIAssistantManagementSelectionPluginServerSetup {} |
This file contains 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 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 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
Oops, something went wrong.