@ckeditor/ckeditor5-ai 41.3.0 → 41.4.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/README.md +1 -1
  2. package/build/ai.js +6 -6
  3. package/dist/index-content.css +4 -0
  4. package/dist/index-editor.css +267 -0
  5. package/dist/index.css +396 -0
  6. package/dist/index.js +23 -0
  7. package/dist/translations/af.d.ts +8 -0
  8. package/dist/translations/af.js +23 -0
  9. package/dist/translations/ar.d.ts +8 -0
  10. package/dist/translations/ar.js +23 -0
  11. package/dist/translations/bg.d.ts +8 -0
  12. package/dist/translations/bg.js +23 -0
  13. package/dist/translations/bn.d.ts +8 -0
  14. package/dist/translations/bn.js +23 -0
  15. package/dist/translations/bs.d.ts +8 -0
  16. package/dist/translations/bs.js +23 -0
  17. package/dist/translations/ca.d.ts +8 -0
  18. package/dist/translations/ca.js +23 -0
  19. package/dist/translations/cs.d.ts +8 -0
  20. package/dist/translations/cs.js +23 -0
  21. package/dist/translations/da.d.ts +8 -0
  22. package/dist/translations/da.js +23 -0
  23. package/dist/translations/de-ch.d.ts +8 -0
  24. package/dist/translations/de-ch.js +23 -0
  25. package/dist/translations/de.d.ts +8 -0
  26. package/dist/translations/de.js +23 -0
  27. package/dist/translations/el.d.ts +8 -0
  28. package/dist/translations/el.js +23 -0
  29. package/dist/translations/en-au.d.ts +8 -0
  30. package/dist/translations/en-au.js +23 -0
  31. package/dist/translations/en.d.ts +8 -0
  32. package/dist/translations/en.js +23 -0
  33. package/dist/translations/es-co.d.ts +8 -0
  34. package/dist/translations/es-co.js +23 -0
  35. package/dist/translations/es.d.ts +8 -0
  36. package/dist/translations/es.js +23 -0
  37. package/dist/translations/et.d.ts +8 -0
  38. package/dist/translations/et.js +23 -0
  39. package/dist/translations/fa.d.ts +8 -0
  40. package/dist/translations/fa.js +23 -0
  41. package/dist/translations/fi.d.ts +8 -0
  42. package/dist/translations/fi.js +23 -0
  43. package/dist/translations/fr.d.ts +8 -0
  44. package/dist/translations/fr.js +23 -0
  45. package/dist/translations/gl.d.ts +8 -0
  46. package/dist/translations/gl.js +23 -0
  47. package/dist/translations/he.d.ts +8 -0
  48. package/dist/translations/he.js +23 -0
  49. package/dist/translations/hi.d.ts +8 -0
  50. package/dist/translations/hi.js +23 -0
  51. package/dist/translations/hr.d.ts +8 -0
  52. package/dist/translations/hr.js +23 -0
  53. package/dist/translations/hu.d.ts +8 -0
  54. package/dist/translations/hu.js +23 -0
  55. package/dist/translations/id.d.ts +8 -0
  56. package/dist/translations/id.js +23 -0
  57. package/dist/translations/it.d.ts +8 -0
  58. package/dist/translations/it.js +23 -0
  59. package/dist/translations/ja.d.ts +8 -0
  60. package/dist/translations/ja.js +23 -0
  61. package/dist/translations/jv.d.ts +8 -0
  62. package/dist/translations/jv.js +23 -0
  63. package/dist/translations/ko.d.ts +8 -0
  64. package/dist/translations/ko.js +23 -0
  65. package/dist/translations/lt.d.ts +8 -0
  66. package/dist/translations/lt.js +23 -0
  67. package/dist/translations/lv.d.ts +8 -0
  68. package/dist/translations/lv.js +23 -0
  69. package/dist/translations/ms.d.ts +8 -0
  70. package/dist/translations/ms.js +23 -0
  71. package/dist/translations/nl.d.ts +8 -0
  72. package/dist/translations/nl.js +23 -0
  73. package/dist/translations/no.d.ts +8 -0
  74. package/dist/translations/no.js +23 -0
  75. package/dist/translations/pl.d.ts +8 -0
  76. package/dist/translations/pl.js +23 -0
  77. package/dist/translations/pt-br.d.ts +8 -0
  78. package/dist/translations/pt-br.js +23 -0
  79. package/dist/translations/pt.d.ts +8 -0
  80. package/dist/translations/pt.js +23 -0
  81. package/dist/translations/ro.d.ts +8 -0
  82. package/dist/translations/ro.js +23 -0
  83. package/dist/translations/ru.d.ts +8 -0
  84. package/dist/translations/ru.js +23 -0
  85. package/dist/translations/sk.d.ts +8 -0
  86. package/dist/translations/sk.js +23 -0
  87. package/dist/translations/sr-latn.d.ts +8 -0
  88. package/dist/translations/sr-latn.js +23 -0
  89. package/dist/translations/sr.d.ts +8 -0
  90. package/dist/translations/sr.js +23 -0
  91. package/dist/translations/sv.d.ts +8 -0
  92. package/dist/translations/sv.js +23 -0
  93. package/dist/translations/th.d.ts +8 -0
  94. package/dist/translations/th.js +23 -0
  95. package/dist/translations/tk.d.ts +8 -0
  96. package/dist/translations/tk.js +23 -0
  97. package/dist/translations/tr.d.ts +8 -0
  98. package/dist/translations/tr.js +23 -0
  99. package/dist/translations/ug.d.ts +8 -0
  100. package/dist/translations/ug.js +23 -0
  101. package/dist/translations/uk.d.ts +8 -0
  102. package/dist/translations/uk.js +23 -0
  103. package/dist/translations/ur.d.ts +8 -0
  104. package/dist/translations/ur.js +23 -0
  105. package/dist/translations/uz.d.ts +8 -0
  106. package/dist/translations/uz.js +23 -0
  107. package/dist/translations/vi.d.ts +8 -0
  108. package/dist/translations/vi.js +23 -0
  109. package/dist/translations/zh-cn.d.ts +8 -0
  110. package/dist/translations/zh-cn.js +23 -0
  111. package/dist/translations/zh.d.ts +8 -0
  112. package/dist/translations/zh.js +23 -0
  113. package/dist/types/adapters/aiadapter.d.ts +52 -0
  114. package/dist/types/adapters/aitextadapter.d.ts +150 -0
  115. package/dist/types/adapters/awstextadapter.d.ts +183 -0
  116. package/dist/types/adapters/openaitextadapter.d.ts +187 -0
  117. package/dist/types/aiassistant.d.ts +390 -0
  118. package/dist/types/aiassistantediting.d.ts +50 -0
  119. package/dist/types/aiassistantui.d.ts +57 -0
  120. package/dist/types/aiconfig.d.ts +73 -0
  121. package/dist/types/augmentation.d.ts +31 -0
  122. package/dist/types/index.d.ts +17 -0
  123. package/dist/types/ui/aiassistantcontroller.d.ts +113 -0
  124. package/dist/types/ui/dropdown/aicommandslistview.d.ts +37 -0
  125. package/dist/types/ui/dropdown/buttonlabelwithhighlightview.d.ts +33 -0
  126. package/dist/types/ui/dropdown/labelwithhighlightview.d.ts +29 -0
  127. package/dist/types/ui/form/aiformcontentarea.d.ts +52 -0
  128. package/dist/types/ui/form/aiformerrorview.d.ts +30 -0
  129. package/dist/types/ui/form/aiformpromptview.d.ts +50 -0
  130. package/dist/types/ui/form/aiformtoolbarview.d.ts +62 -0
  131. package/dist/types/ui/form/aiformview.d.ts +145 -0
  132. package/dist/types/ui/form/aihistorylistitemview.d.ts +22 -0
  133. package/dist/types/ui/form/aihistorylistview.d.ts +39 -0
  134. package/dist/types/ui/form/prompthistory.d.ts +24 -0
  135. package/dist/types/ui/showaiassistantcommand.d.ts +44 -0
  136. package/dist/types/utils/common-translations.d.ts +13 -0
  137. package/lang/contexts.json +4 -0
  138. package/package.json +5 -4
  139. package/src/adapters/aiadapter.js +1 -1
  140. package/src/adapters/aitextadapter.js +1 -1
  141. package/src/adapters/awstextadapter.js +1 -1
  142. package/src/adapters/openaitextadapter.js +1 -1
  143. package/src/aiassistant.js +1 -1
  144. package/src/aiassistantediting.js +1 -1
  145. package/src/aiassistantui.js +1 -1
  146. package/src/index.js +1 -1
  147. package/src/ui/aiassistantcontroller.js +1 -1
  148. package/src/ui/dropdown/aicommandslistview.js +1 -1
  149. package/src/ui/dropdown/buttonlabelwithhighlightview.js +1 -1
  150. package/src/ui/dropdown/labelwithhighlightview.js +1 -1
  151. package/src/ui/form/aiformcontentarea.js +1 -1
  152. package/src/ui/form/aiformerrorview.js +1 -1
  153. package/src/ui/form/aiformpromptview.js +1 -1
  154. package/src/ui/form/aiformtoolbarview.js +1 -1
  155. package/src/ui/form/aiformview.js +1 -1
  156. package/src/ui/form/aihistorylistitemview.js +1 -1
  157. package/src/ui/form/aihistorylistview.js +1 -1
  158. package/src/ui/form/prompthistory.js +1 -1
  159. package/src/ui/showaiassistantcommand.js +1 -1
  160. package/src/utils/common-translations.js +1 -1
@@ -0,0 +1,73 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai/aiconfig
11
+ * @publicApi
12
+ */
13
+ import type { AIAssistantConfig } from './aiassistant.js';
14
+ import type { OpenAITextAdapterConfig } from './adapters/openaitextadapter.js';
15
+ import type { AWSTextAdapterConfig } from './adapters/awstextadapter.js';
16
+ /**
17
+ * The configuration for all AI-related functionalities.
18
+ *
19
+ * Provides configuration properties for both AI features and AI adapters (which connect to the external AI services),
20
+ *
21
+ * ```ts
22
+ * ClassicEditor
23
+ * .create( editorElement, {
24
+ * ai: {
25
+ * openAI: {
26
+ * requestHeaders: {
27
+ * Authorization: 'Bearer API_KEY'
28
+ * }
29
+ * },
30
+ * useTheme: false
31
+ * }
32
+ * } )
33
+ * .then( ... )
34
+ * .catch( ... );
35
+ * ```
36
+ *
37
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor configuration options}.
38
+ */
39
+ export default interface AIConfig {
40
+ /**
41
+ * The configuration of the {@link module:ai/aiassistant~AIAssistant AI Assistant feature}.
42
+ *
43
+ * Read more in {@link module:ai/aiassistant~AIAssistantConfig}.
44
+ */
45
+ aiAssistant?: AIAssistantConfig;
46
+ /**
47
+ * The configuration for the {@link module:ai/adapters/openaitextadapter~OpenAITextAdapter `OpenAITextAdapter`}.
48
+ *
49
+ * This is required only if you connect to OpenAI or Azure OpenAI service.
50
+ *
51
+ * Read more in {@link module:ai/adapters/openaitextadapter~OpenAITextAdapterConfig}.
52
+ */
53
+ openAI?: OpenAITextAdapterConfig;
54
+ /**
55
+ * The configuration for the {@link module:ai/adapters/awstextadapter~AWSTextAdapter `AWSTextAdapter`}.
56
+ *
57
+ * This is required only if you connect to Amazon Bedrock service.
58
+ *
59
+ * Read more in {@link module:ai/adapters/awstextadapter~AWSTextAdapterConfig}.
60
+ */
61
+ aws?: AWSTextAdapterConfig;
62
+ /**
63
+ * Enables or disables the colored UI theme for AI features.
64
+ *
65
+ * * Leaving this property unset will preserve the default theme on AI features UI elements.
66
+ * * Setting this property to **`false`** will remove the default theme from AI features UI elements.
67
+ *
68
+ * See the AI Assistant integration guide to learn how you can use CSS variables to change the default theme to a different color.
69
+ *
70
+ * @default true
71
+ */
72
+ useTheme?: boolean;
73
+ }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import type AIAssistant from './aiassistant.js';
10
+ import type ShowAIAssistantCommand from './ui/showaiassistantcommand.js';
11
+ import type AIAssistantEditing from './aiassistantediting.js';
12
+ import type AIAssistantUI from './aiassistantui.js';
13
+ import type AIConfig from './aiconfig.js';
14
+ import type AIAdapter from './adapters/aiadapter.js';
15
+ declare module '@ckeditor/ckeditor5-core' {
16
+ interface EditorConfig {
17
+ /**
18
+ * Configuration for AI features.
19
+ */
20
+ ai?: AIConfig;
21
+ }
22
+ interface PluginsMap {
23
+ [AIAdapter.pluginName]: AIAdapter;
24
+ [AIAssistant.pluginName]: AIAssistant;
25
+ [AIAssistantUI.pluginName]: AIAssistantUI;
26
+ [AIAssistantEditing.pluginName]: AIAssistantEditing;
27
+ }
28
+ interface CommandsMap {
29
+ showAIAssistant: ShowAIAssistantCommand;
30
+ }
31
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai
11
+ */
12
+ export { default as AIAssistant } from './aiassistant.js';
13
+ export { default as AIAdapter, AIRequestError } from './adapters/aiadapter.js';
14
+ export { default as AITextAdapter, type AITextAdapterRequestData, type RequestHeaders, type RequestParameters, type AITextAdapterDataCallback } from './adapters/aitextadapter.js';
15
+ export { default as OpenAITextAdapter, type OpenAITextAdapterConfig } from './adapters/openaitextadapter.js';
16
+ export { default as AWSTextAdapter, type AWSTextAdapterConfig } from './adapters/awstextadapter.js';
17
+ import './augmentation.js';
@@ -0,0 +1,113 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ import type AITextAdapter from '../adapters/aitextadapter.js';
10
+ import type { default as AIFormView } from './form/aiformview.js';
11
+ import type { AIFormToolbarViewMainActionLabel } from './form/aiformtoolbarview.js';
12
+ import type { Editor } from 'ckeditor5/src/core.js';
13
+ declare const AIAssistantController_base: {
14
+ new (): import("ckeditor5/src/utils.js").Observable;
15
+ prototype: import("ckeditor5/src/utils.js").Observable;
16
+ };
17
+ /**
18
+ * Controller for the AI assistant.
19
+ *
20
+ * It takes a AI form view, listens to events fired by that view and based on them performs actions on an AI handler.
21
+ * This controller is also responsible for streaming the AI response for the UI.
22
+ */
23
+ export default class AIAssistantController extends AIAssistantController_base {
24
+ /**
25
+ * The editor instance.
26
+ */
27
+ readonly editor: Editor;
28
+ /**
29
+ * An instance of the {@link module:ai/adapters/aitextadapter~AITextAdapter}.
30
+ */
31
+ readonly textAdapter: AITextAdapter;
32
+ /**
33
+ * An instance of the {@link module:ai/ui/aiformview~AIFormView}.
34
+ */
35
+ readonly view: AIFormView;
36
+ /**
37
+ * It is the selected HTML content from the editor on which the dialog has been initialized.
38
+ */
39
+ initialContext: string;
40
+ /**
41
+ * The latest value returned by the AI while executing the request. It is before parsing and normalization.
42
+ */
43
+ currentResponse: string;
44
+ /**
45
+ * The latest value returned by the AI while executing the request. It is after parsing and normalization. It will be used as context
46
+ * for the next calls.
47
+ *
48
+ * This value is also displayed in the view (after sanitization).
49
+ */
50
+ currentContext: string;
51
+ /**
52
+ * The previous value of the context for the AI request. It is kept to handle the try again event.
53
+ *
54
+ * Initially it is the selected HTML content from the editor. Subsequently, the context is replaced by each response from AI.
55
+ *
56
+ * @observable
57
+ */
58
+ previousContext?: string;
59
+ /**
60
+ * The previous value of the user query. It is kept to handle the try again event.
61
+ *
62
+ * @observable
63
+ */
64
+ previousQuery?: string;
65
+ /**
66
+ * The label of the previous executed query. It is connected to {@link ~AIAssistantController#previousQuery `previousQuery`} and is kept
67
+ * to handle the "try again" event.
68
+ *
69
+ * @observable
70
+ */
71
+ previousLabel?: string;
72
+ /**
73
+ * The id of the previous executed action. It is kept to handle the try again event.
74
+ *
75
+ * @observable
76
+ */
77
+ previousActionId?: string;
78
+ /**
79
+ * Flag that indicates if the processing is in progress.
80
+ *
81
+ * @observable
82
+ */
83
+ isProcessing: boolean;
84
+ /**
85
+ * @param adapter AI connector instance.
86
+ * @param view AI form view.
87
+ */
88
+ constructor(editor: Editor, adapter: AITextAdapter, view: AIFormView);
89
+ /**
90
+ * Destroys `AIAssistantController` instance.
91
+ */
92
+ destroy(): void;
93
+ /**
94
+ * Handles the initial query for a new context and inits the listener for the visible view.
95
+ *
96
+ * This function should be called whenever the AI dialog is displayed.
97
+ *
98
+ * @param options
99
+ * @param options.actionId ID of the performed action. See {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId}.
100
+ * @param options.htmlContent The selected HTML content on which the AI should base.
101
+ * @param options.query The initial query to be processed.
102
+ * @param options.label The label that will be displayed in the view.
103
+ * @param options.mainActionLabel The action label for the main insertion button.
104
+ */
105
+ updateView({ actionId, query, htmlContent, label, mainActionLabel }: {
106
+ actionId: string;
107
+ query: string;
108
+ htmlContent: string;
109
+ label: string;
110
+ mainActionLabel: typeof AIFormToolbarViewMainActionLabel[keyof typeof AIFormToolbarViewMainActionLabel];
111
+ }): Promise<void>;
112
+ }
113
+ export {};
@@ -0,0 +1,37 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai/ui/aicommandslistview
11
+ */
12
+ import { ListView, type FilteredView } from 'ckeditor5/src/ui.js';
13
+ import type { Locale } from 'ckeditor5/src/utils.js';
14
+ /**
15
+ * A list view that displays a list of AI commands with filtering capabilities.
16
+ *
17
+ * @private
18
+ */
19
+ export default class AICommandsListView extends ListView implements FilteredView {
20
+ /**
21
+ * An array with ids of the enabled AI commands.
22
+ *
23
+ * @observable
24
+ */
25
+ enabledCommandsIds: Array<string>;
26
+ /**
27
+ * Creates an instance of the {@link module:ai/ui/aicommandslistview~AICommandsListView} class.
28
+ */
29
+ constructor(locale: Locale);
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ filter(regExp: RegExp | null): {
34
+ resultsCount: number;
35
+ totalItemsCount: number;
36
+ };
37
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai/ui/buttonlabelwithhighlightview
11
+ */
12
+ import { type ButtonLabel, HighlightedTextView } from 'ckeditor5/src/ui.js';
13
+ /**
14
+ * A button label view that can highlight a text fragment.
15
+ */
16
+ export default class ButtonLabelWithHighlightView extends HighlightedTextView implements ButtonLabel {
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ style: string | undefined;
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ text: string | undefined;
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ id: string | undefined;
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ constructor();
33
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai/ui/labelwithhighlightview
11
+ */
12
+ import { type LabelView, HighlightedTextView } from 'ckeditor5/src/ui.js';
13
+ /**
14
+ * A label view that can highlight a text fragment.
15
+ */
16
+ export default class LabelWithHighlightView extends HighlightedTextView implements LabelView {
17
+ /**
18
+ * @inheritDoc
19
+ */
20
+ readonly id: string;
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ for: string | undefined;
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ constructor();
29
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai/ui/aiformcontentarea
11
+ */
12
+ import { type Locale } from 'ckeditor5/src/utils.js';
13
+ import { View, ButtonView } from 'ckeditor5/src/ui.js';
14
+ /**
15
+ * A class representing the text area view of the AI assistant.
16
+ */
17
+ export default class AIFormContentArea extends View {
18
+ /**
19
+ * The value which is displayed in the content field.
20
+ *
21
+ * @observable
22
+ */
23
+ value: string | null;
24
+ /**
25
+ * Controls whether the content area is visible.
26
+ *
27
+ * @observable
28
+ * @default false
29
+ */
30
+ isVisible: boolean;
31
+ /**
32
+ * Indicates if the content area is during processing which can change inner values.
33
+ */
34
+ isProcessing: boolean;
35
+ /**
36
+ * The textarea view.
37
+ */
38
+ contentFieldView: ContentFieldView;
39
+ /**
40
+ * The copy button displayed in the bottom-right corner of text area.
41
+ */
42
+ copyButtonView: ButtonView;
43
+ /**
44
+ * @inheritDoc
45
+ */
46
+ constructor(locale: Locale, extraCssClass?: string);
47
+ /**
48
+ * @inheritDoc
49
+ */
50
+ render(): void;
51
+ focus(): void;
52
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai/ui/aiformerrorview
11
+ */
12
+ import type { Locale } from 'ckeditor5/src/utils.js';
13
+ import { View } from 'ckeditor5/src/ui.js';
14
+ /**
15
+ * A class representing the error view of the AI assistant.
16
+ */
17
+ export default class AIFormErrorView extends View {
18
+ /**
19
+ * The text of the error.
20
+ *
21
+ * @observable
22
+ */
23
+ text: string;
24
+ /**
25
+ * Creates an instance of the {@link module:ai/ui/aiformerrorview~AIFormErrorView} class.
26
+ *
27
+ * @param locale The localization services instance.
28
+ */
29
+ constructor(locale: Locale, text?: string);
30
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai/ui/aiformpromptview
11
+ */
12
+ import { type Locale } from 'ckeditor5/src/utils.js';
13
+ import { AutocompleteView, ButtonView, type TextareaView, type AutocompleteViewConfig } from 'ckeditor5/src/ui.js';
14
+ /**
15
+ * A textarea field allowing to ask AI.
16
+ */
17
+ export default class AIFormPromptView extends AutocompleteView<TextareaView> {
18
+ /**
19
+ * The submit button view.
20
+ */
21
+ submitButtonView: ButtonView;
22
+ /**
23
+ * The button that shows and hides the history autocomplete panel.
24
+ */
25
+ showHistoryButtonView: ButtonView;
26
+ /**
27
+ * Creates `AIFormPromptView` instance.
28
+ *
29
+ * @param locale The localization services instance.
30
+ * @param config Autocomplete config.
31
+ */
32
+ constructor(locale: Locale, config: AutocompleteViewConfig<TextareaView>);
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ render(): void;
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ focus(direction?: 1 | -1): void;
41
+ }
42
+ /**
43
+ * Fired when the query is submitted by the user.
44
+ *
45
+ * @eventName ~AIFormPromptView#submit
46
+ */
47
+ export type AIFormPromptViewSubmitEvent = {
48
+ name: 'submit';
49
+ args: [query: string];
50
+ };
@@ -0,0 +1,62 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai/ui/aiformtoolbarview
11
+ */
12
+ import type { Locale } from 'ckeditor5/src/utils.js';
13
+ import { ToolbarView, ButtonView } from 'ckeditor5/src/ui.js';
14
+ /**
15
+ * The action name affecting the label of {@link ~AIFormToolbarView#replaceButton}.
16
+ *
17
+ * Available keys are:
18
+ * * `AIFormToolbarViewMainActionLabel.REPLACE`,
19
+ * * `AIFormToolbarViewMainActionLabel.INSERT`
20
+ */
21
+ export declare const AIFormToolbarViewMainActionLabel: {
22
+ readonly REPLACE: "replace";
23
+ readonly INSERT: "insert";
24
+ };
25
+ /**
26
+ * A class representing the text area view of the AI assistant.
27
+ */
28
+ export default class AIFormToolbarView extends ToolbarView {
29
+ /**
30
+ * Controls whether the toolbar is visible.
31
+ *
32
+ * @observable
33
+ * @default false
34
+ */
35
+ isVisible: boolean;
36
+ /**
37
+ * Button that is used to replace the selected content by the generated one.
38
+ */
39
+ replaceButton: ButtonView;
40
+ /**
41
+ * Button that is used to insert the generated content below the selection.
42
+ */
43
+ insertButton: ButtonView;
44
+ /**
45
+ * Button that is used to regenerate the response.
46
+ */
47
+ tryAgainButton: ButtonView;
48
+ /**
49
+ * Button that is used to stop the processing of the request.
50
+ */
51
+ stopButton: ButtonView;
52
+ /**
53
+ * The action name affecting the label of {@link #replaceButton}.
54
+ *
55
+ * @default 'replace'
56
+ */
57
+ mainAction: typeof AIFormToolbarViewMainActionLabel[keyof typeof AIFormToolbarViewMainActionLabel];
58
+ /**
59
+ * @inheritDoc
60
+ */
61
+ constructor(locale: Locale);
62
+ }
@@ -0,0 +1,145 @@
1
+ /**
2
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
3
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
4
+ */
5
+ /**
6
+ * @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
7
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
8
+ */
9
+ /**
10
+ * @module ai/ui/aiformview
11
+ */
12
+ import { FocusTracker, KeystrokeHandler, type Locale } from 'ckeditor5/src/utils.js';
13
+ import { View, type ViewWithFocusCycler } from 'ckeditor5/src/ui.js';
14
+ import AIFormToolbarView, { AIFormToolbarViewMainActionLabel } from './aiformtoolbarview.js';
15
+ import AIFormContentArea from './aiformcontentarea.js';
16
+ import AIFormErrorView from './aiformerrorview.js';
17
+ import AIFormPromptView from './aiformpromptview.js';
18
+ /**
19
+ * A class representing the form view of the AI assistant.
20
+ */
21
+ export default class AIFormView extends View implements ViewWithFocusCycler {
22
+ /**
23
+ * Tracks information about the DOM focus in the form.
24
+ *
25
+ * @readonly
26
+ */
27
+ focusTracker: FocusTracker;
28
+ /**
29
+ * An instance of the {@link module:utils/keystrokehandler~KeystrokeHandler}.
30
+ *
31
+ * @readonly
32
+ */
33
+ keystrokes: KeystrokeHandler;
34
+ /**
35
+ * The text area view that is used to display AI response.
36
+ */
37
+ contentArea: AIFormContentArea;
38
+ /**
39
+ * Toolbar view containing button views that manage the AI response and this form itself.
40
+ */
41
+ toolbar: AIFormToolbarView;
42
+ /**
43
+ * The component used for handling the user's query, including history and submit buttons.
44
+ */
45
+ promptView: AIFormPromptView;
46
+ /**
47
+ * View that is used to display the error message.
48
+ */
49
+ errorView: AIFormErrorView;
50
+ /**
51
+ * The prompt text can be configured either during construction when the AI command has been selected,
52
+ * or later by submitting the {@link #labeledInput}, if it hasn't been previously initialized.
53
+ * After setting this value the AI request is triggered.
54
+ */
55
+ prompt: string;
56
+ /**
57
+ * The value that is generated after user submitting the user prompt.
58
+ */
59
+ value: string;
60
+ /**
61
+ * Flag that indicates if the AI assistant form view is enabled or disabled.
62
+ *
63
+ * If it is disabled, all interactive elements of this view are disabled as well.
64
+ */
65
+ isEnabled: boolean;
66
+ /**
67
+ * Indicates if the AI request is processing.
68
+ */
69
+ isProcessing: boolean;
70
+ /**
71
+ * Indicates if the AI request failed.
72
+ */
73
+ isError: boolean;
74
+ /**
75
+ * The action name for the main insertion button in the {@link #toolbar}.
76
+ *
77
+ * See {@link module:ai/ui/aiformtoolbarview~AIFormToolbarView#replaceButton}.
78
+ *
79
+ * @default 'replace'
80
+ */
81
+ mainAction: typeof AIFormToolbarViewMainActionLabel[keyof typeof AIFormToolbarViewMainActionLabel];
82
+ /**
83
+ * Creates an instance of the {@link module:ai/ui/aiformview~AIFormView} class.
84
+ *
85
+ * @param locale The localization services instance.
86
+ */
87
+ constructor(locale: Locale, uiClasses: string, contentAreaCssClass?: string);
88
+ /**
89
+ * @inheritDoc
90
+ */
91
+ render(): void;
92
+ /**
93
+ * @inheritDoc
94
+ */
95
+ focus(direction?: 1 | -1): void;
96
+ /**
97
+ * Resets the form to the initial values.
98
+ */
99
+ reset(): void;
100
+ }
101
+ /**
102
+ * Fired when a user performed an action that should lead to replace the current selection by generated content.
103
+ *
104
+ * @eventName ~AIFormView#replaceContent
105
+ */
106
+ export type ReplaceContentEvent = {
107
+ name: 'replaceContent';
108
+ args: [];
109
+ };
110
+ /**
111
+ * Fired when a user performed an action that should lead to insert generated content below the current selection.
112
+ *
113
+ * @eventName ~AIFormView#insertContentBelow
114
+ */
115
+ export type InsertContentBelowEvent = {
116
+ name: 'insertContentBelow';
117
+ args: [];
118
+ };
119
+ /**
120
+ * Fired when a user performed an action that should lead to retry the previous request to AI.
121
+ *
122
+ * @eventName ~AIFormView#tryAgainEvent
123
+ */
124
+ export type TryAgainEvent = {
125
+ name: 'tryAgainEvent';
126
+ args: [];
127
+ };
128
+ /**
129
+ * Fired when a user performed an action that should lead to stop the processing of AI.
130
+ *
131
+ * @eventName ~AIFormView#stopProcessing
132
+ */
133
+ export type StopProcessingEvent = {
134
+ name: 'stopProcessing';
135
+ args: [];
136
+ };
137
+ /**
138
+ * Fired when a user performed an action that should lead to ask AI.
139
+ *
140
+ * @eventName ~AIFormView#submitPrompt
141
+ */
142
+ export type SubmitPromptEvent = {
143
+ name: 'submitPrompt';
144
+ args: [prompt: string];
145
+ };