@ckeditor/ckeditor5-ai 40.0.0 → 40.1.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.
- package/LICENSE.md +2 -2
- package/build/ai.js +2 -2
- package/build/translations/af.js +1 -1
- package/build/translations/ar.js +1 -1
- package/build/translations/bg.js +1 -1
- package/build/translations/bn.js +1 -1
- package/build/translations/bs.js +1 -1
- package/build/translations/ca.js +1 -1
- package/build/translations/cs.js +1 -1
- package/build/translations/da.js +1 -1
- package/build/translations/de-ch.js +1 -1
- package/build/translations/de.js +1 -1
- package/build/translations/el.js +1 -1
- package/build/translations/en-au.js +1 -1
- package/build/translations/es-co.js +1 -1
- package/build/translations/es.js +1 -1
- package/build/translations/et.js +1 -1
- package/build/translations/fa.js +1 -1
- package/build/translations/fi.js +1 -1
- package/build/translations/fr.js +1 -1
- package/build/translations/gl.js +1 -1
- package/build/translations/he.js +1 -1
- package/build/translations/hi.js +1 -1
- package/build/translations/hr.js +1 -1
- package/build/translations/hu.js +1 -1
- package/build/translations/id.js +1 -1
- package/build/translations/it.js +1 -1
- package/build/translations/ja.js +1 -1
- package/build/translations/jv.js +1 -1
- package/build/translations/ko.js +1 -1
- package/build/translations/lt.js +1 -1
- package/build/translations/lv.js +1 -1
- package/build/translations/ms.js +1 -1
- package/build/translations/nl.js +1 -1
- package/build/translations/no.js +1 -1
- package/build/translations/pl.js +1 -1
- package/build/translations/pt-br.js +1 -1
- package/build/translations/pt.js +1 -1
- package/build/translations/ro.js +1 -1
- package/build/translations/ru.js +1 -1
- package/build/translations/sk.js +1 -1
- package/build/translations/sr-latn.js +1 -1
- package/build/translations/sr.js +1 -1
- package/build/translations/sv.js +1 -1
- package/build/translations/th.js +1 -1
- package/build/translations/tk.js +1 -1
- package/build/translations/tr.js +1 -1
- package/build/translations/ug.js +1 -1
- package/build/translations/uk.js +1 -1
- package/build/translations/ur.js +1 -1
- package/build/translations/uz.js +1 -0
- package/build/translations/vi.js +1 -1
- package/build/translations/zh-cn.js +1 -1
- package/build/translations/zh.js +1 -1
- package/lang/contexts.json +1 -0
- package/lang/translations/af.po +60 -16
- package/lang/translations/ar.po +60 -16
- package/lang/translations/bg.po +60 -16
- package/lang/translations/bn.po +60 -16
- package/lang/translations/bs.po +60 -16
- package/lang/translations/ca.po +60 -16
- package/lang/translations/cs.po +60 -16
- package/lang/translations/da.po +60 -16
- package/lang/translations/de-ch.po +60 -16
- package/lang/translations/de.po +60 -16
- package/lang/translations/el.po +60 -16
- package/lang/translations/en-au.po +60 -16
- package/lang/translations/en.po +60 -16
- package/lang/translations/es-co.po +60 -16
- package/lang/translations/es.po +60 -16
- package/lang/translations/et.po +60 -16
- package/lang/translations/fa.po +60 -16
- package/lang/translations/fi.po +60 -16
- package/lang/translations/fr.po +60 -16
- package/lang/translations/gl.po +60 -16
- package/lang/translations/he.po +60 -16
- package/lang/translations/hi.po +60 -16
- package/lang/translations/hr.po +93 -49
- package/lang/translations/hu.po +60 -16
- package/lang/translations/id.po +60 -16
- package/lang/translations/it.po +60 -16
- package/lang/translations/ja.po +60 -16
- package/lang/translations/jv.po +60 -16
- package/lang/translations/ko.po +60 -16
- package/lang/translations/lt.po +60 -16
- package/lang/translations/lv.po +60 -16
- package/lang/translations/ms.po +60 -16
- package/lang/translations/nl.po +60 -16
- package/lang/translations/no.po +60 -16
- package/lang/translations/pl.po +60 -16
- package/lang/translations/pt-br.po +60 -16
- package/lang/translations/pt.po +60 -16
- package/lang/translations/ro.po +60 -16
- package/lang/translations/ru.po +60 -16
- package/lang/translations/sk.po +60 -16
- package/lang/translations/sr-latn.po +60 -16
- package/lang/translations/sr.po +60 -16
- package/lang/translations/sv.po +60 -16
- package/lang/translations/th.po +60 -16
- package/lang/translations/tk.po +60 -16
- package/lang/translations/tr.po +60 -16
- package/lang/translations/ug.po +94 -50
- package/lang/translations/uk.po +60 -16
- package/lang/translations/ur.po +60 -16
- package/lang/translations/uz.po +226 -0
- package/lang/translations/vi.po +60 -16
- package/lang/translations/zh-cn.po +60 -16
- package/lang/translations/zh.po +60 -16
- package/package.json +3 -3
- package/src/aiassistant.d.ts +458 -419
- package/src/aiassistant.js +1 -1
- package/src/aiassistantediting.d.ts +45 -45
- package/src/aiassistantediting.js +1 -1
- package/src/aiassistantui.d.ts +44 -46
- package/src/aiassistantui.js +1 -1
- package/src/aiconnector.d.ts +45 -44
- package/src/aiconnector.js +1 -1
- package/src/augmentation.d.ts +26 -26
- package/src/index.d.ts +9 -9
- package/src/ui/aiassistantcontroller.d.ts +96 -59
- package/src/ui/aiassistantcontroller.js +1 -1
- package/src/ui/dropdown/aicommandslistview.d.ts +22 -22
- package/src/ui/dropdown/aicommandslistview.js +1 -1
- package/src/ui/dropdown/buttonlabelwithhighlightview.d.ts +29 -29
- package/src/ui/dropdown/buttonlabelwithhighlightview.js +1 -1
- package/src/ui/dropdown/labelwithhighlightview.d.ts +25 -0
- package/src/ui/dropdown/labelwithhighlightview.js +23 -0
- package/src/ui/form/aiformcontentarea.d.ts +48 -48
- package/src/ui/form/aiformcontentarea.js +1 -1
- package/src/ui/form/aiformerrorview.d.ts +26 -26
- package/src/ui/form/aiformerrorview.js +1 -1
- package/src/ui/form/aiformpromptview.d.ts +46 -46
- package/src/ui/form/aiformpromptview.js +1 -1
- package/src/ui/form/aiformtoolbarview.d.ts +54 -41
- package/src/ui/form/aiformtoolbarview.js +1 -1
- package/src/ui/form/aiformview.d.ts +142 -131
- package/src/ui/form/aiformview.js +1 -1
- package/src/ui/form/aihistorylistitemview.d.ts +18 -18
- package/src/ui/form/aihistorylistitemview.js +1 -1
- package/src/ui/form/aihistorylistview.d.ts +35 -35
- package/src/ui/form/aihistorylistview.js +1 -1
- package/src/ui/form/prompthistory.d.ts +20 -20
- package/src/ui/form/prompthistory.js +1 -1
- package/src/ui/showaiassistantcommand.d.ts +26 -26
- package/src/ui/showaiassistantcommand.js +1 -1
- package/src/utils/common-translations.d.ts +9 -9
- package/src/utils/common-translations.js +1 -1
- package/theme/ai-form.css +58 -11
- package/theme/ai.css +20 -15
package/src/aiassistant.d.ts
CHANGED
|
@@ -1,419 +1,458 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license Copyright (c) 2003-2023, 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
|
-
* @module ai/aiassistant
|
|
7
|
-
* @publicApi
|
|
8
|
-
*/
|
|
9
|
-
import { type Locale } from 'ckeditor5/src/utils';
|
|
10
|
-
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
11
|
-
import AIAssistantUI from './aiassistantui';
|
|
12
|
-
import AIAssistantEditing from './aiassistantediting';
|
|
13
|
-
import AIConnector from './aiconnector';
|
|
14
|
-
/**
|
|
15
|
-
* A function that returns the list of default AI commands definitions in the given localization context.
|
|
16
|
-
*/
|
|
17
|
-
export declare const getDefaultCommands: (locale: Locale) => Array<GroupDefinition>;
|
|
18
|
-
/**
|
|
19
|
-
* AI assistant plugin that allows you to use external AI models to generate content or improve existing content.
|
|
20
|
-
*/
|
|
21
|
-
export default class AIAssistant extends Plugin {
|
|
22
|
-
/**
|
|
23
|
-
* @inheritDoc
|
|
24
|
-
*/
|
|
25
|
-
static get requires(): readonly [typeof AIAssistantUI, typeof AIAssistantEditing, typeof AIConnector];
|
|
26
|
-
/**
|
|
27
|
-
* @inheritDoc
|
|
28
|
-
*/
|
|
29
|
-
static get pluginName(): "AIAssistant";
|
|
30
|
-
/**
|
|
31
|
-
* @inheritDoc
|
|
32
|
-
*/
|
|
33
|
-
constructor(editor: Editor);
|
|
34
|
-
/**
|
|
35
|
-
* @inheritDoc
|
|
36
|
-
*/
|
|
37
|
-
init(): void;
|
|
38
|
-
/**
|
|
39
|
-
* @inheritDoc
|
|
40
|
-
*/
|
|
41
|
-
destroy(): void;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* The configuration of the AI assistant feature.
|
|
45
|
-
*
|
|
46
|
-
* ```ts
|
|
47
|
-
* ClassicEditor
|
|
48
|
-
* .create( editorElement, {
|
|
49
|
-
* aiAssistant: ... // AI assistant options.
|
|
50
|
-
* } )
|
|
51
|
-
* .then( ... )
|
|
52
|
-
* .catch( ... );
|
|
53
|
-
* ```
|
|
54
|
-
*
|
|
55
|
-
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
56
|
-
*/
|
|
57
|
-
export interface AIAssistantConfig {
|
|
58
|
-
/**
|
|
59
|
-
* The URL to which the API request will be sent.
|
|
60
|
-
*
|
|
61
|
-
* Defaults to `'https://api.openai.com/v1/chat/completions'`.
|
|
62
|
-
*/
|
|
63
|
-
apiUrl?: string;
|
|
64
|
-
/**
|
|
65
|
-
* A key used to authorize the request to the AI service.
|
|
66
|
-
*
|
|
67
|
-
* If you are connecting directly to the OpenAI API, use your OpenAI API key as `authKey`.
|
|
68
|
-
*
|
|
69
|
-
* **Important: use your API key ONLY in a development environment or for testing purposes!**
|
|
70
|
-
* In the production environment, {@glink features/ai-assistant#using-proxy-endpoint pass your request through a proxy}.
|
|
71
|
-
*
|
|
72
|
-
* If you are using a proxy service to send requests to the AI service, `authKey` can be used to implement authorization for your
|
|
73
|
-
* requests.
|
|
74
|
-
*
|
|
75
|
-
* If the key is provided, it is added to the `Authorization` header of the request call, using the bearer scheme:
|
|
76
|
-
*
|
|
77
|
-
* ```
|
|
78
|
-
* Authorization: Bearer <authKey>
|
|
79
|
-
* ```
|
|
80
|
-
*
|
|
81
|
-
* If the provided value is a `string`, it is simply used as provided.
|
|
82
|
-
*
|
|
83
|
-
* If the provided value is a function, it should be a function that returns a `Promise` which resolves with the authorization token.
|
|
84
|
-
* This way, you can perform an authorization request to your application and receive the authorization token (and also implement
|
|
85
|
-
* any custom logic that you need). The authorization token is then used to make the actual call to the AI service.
|
|
86
|
-
*
|
|
87
|
-
* ```js
|
|
88
|
-
* {
|
|
89
|
-
* aiAssistant: {
|
|
90
|
-
* authKey: async () => {
|
|
91
|
-
* return await fetch( 'https://example.com/jwt-endpoint' );
|
|
92
|
-
* }
|
|
93
|
-
* // ...
|
|
94
|
-
* }
|
|
95
|
-
* }
|
|
96
|
-
* ```
|
|
97
|
-
*
|
|
98
|
-
* If the authorization request fails, the promise should be rejected. In this case, the feature will display an error notification.
|
|
99
|
-
*/
|
|
100
|
-
authKey?: string | (() => Promise<string>);
|
|
101
|
-
/**
|
|
102
|
-
* A list of all AI commands groups definitions to be displayed in the `'aiCommands'` UI dropdown.
|
|
103
|
-
*
|
|
104
|
-
* Setting this property will overwrite the default list of predefined commands.
|
|
105
|
-
*
|
|
106
|
-
* The default configuration is as follows:
|
|
107
|
-
*
|
|
108
|
-
* ```json
|
|
109
|
-
* {
|
|
110
|
-
* groupId: 'editOrReview',
|
|
111
|
-
* groupLabel: 'Edit or review',
|
|
112
|
-
* commands: [
|
|
113
|
-
* {
|
|
114
|
-
* id: 'improveWriting',
|
|
115
|
-
* label: 'Improve writing',
|
|
116
|
-
* prompt: 'Rewrite this content with no spelling mistakes, proper grammar, ' +
|
|
117
|
-
* 'and with more descriptive language, using best writing practices without losing the original meaning.'
|
|
118
|
-
* },
|
|
119
|
-
* {
|
|
120
|
-
* id: 'makeShorter',
|
|
121
|
-
* label: 'Make shorter',
|
|
122
|
-
* prompt: 'Remove any repetitive, redundant, or non-essential writing in this content ' +
|
|
123
|
-
* 'without changing the meaning or losing any key information.'
|
|
124
|
-
* },
|
|
125
|
-
* {
|
|
126
|
-
* id: 'makeLonger',
|
|
127
|
-
* label: 'Make longer',
|
|
128
|
-
* prompt: 'Expand upon this content with descriptive language and more detailed explanations, ' +
|
|
129
|
-
* 'to make the writing easier to understand and increase the length of the content.'
|
|
130
|
-
* },
|
|
131
|
-
* {
|
|
132
|
-
* id: 'simplifyLanguage',
|
|
133
|
-
* label: 'Simplify language',
|
|
134
|
-
* prompt: 'Rewrite this content with simplified language ' +
|
|
135
|
-
* 'and reduce the complexity of the writing, so that the content is easier to understand.'
|
|
136
|
-
* }
|
|
137
|
-
* ]
|
|
138
|
-
* },
|
|
139
|
-
* {
|
|
140
|
-
* groupId: 'generate',
|
|
141
|
-
* groupLabel: 'Generate from selection',
|
|
142
|
-
* commands: [
|
|
143
|
-
* {
|
|
144
|
-
* id: 'summarize',
|
|
145
|
-
* label: 'Summarize',
|
|
146
|
-
* prompt: 'Provide the key points and concepts in this content in a succinct summary.'
|
|
147
|
-
* },
|
|
148
|
-
* {
|
|
149
|
-
* id: 'continue',
|
|
150
|
-
* label: 'Continue',
|
|
151
|
-
* prompt: 'Continue this text.'
|
|
152
|
-
* }
|
|
153
|
-
* ]
|
|
154
|
-
* },
|
|
155
|
-
* {
|
|
156
|
-
* groupId: 'changeTone',
|
|
157
|
-
* groupLabel: 'Change tone',
|
|
158
|
-
* commands: [
|
|
159
|
-
* {
|
|
160
|
-
* id: 'professional',
|
|
161
|
-
* label: 'Professional',
|
|
162
|
-
* prompt: 'Rewrite this content using polished, formal, and respectful language ' +
|
|
163
|
-
* 'to convey professional expertise and competence.'
|
|
164
|
-
* },
|
|
165
|
-
* {
|
|
166
|
-
* id: 'casual',
|
|
167
|
-
* label: 'Casual',
|
|
168
|
-
* prompt: 'Rewrite this content with casual, informal language to convey a casual conversation with a real person.'
|
|
169
|
-
* },
|
|
170
|
-
* {
|
|
171
|
-
* id: 'direct',
|
|
172
|
-
* label: 'Direct',
|
|
173
|
-
* prompt: 'Rewrite this content with direct language using only the essential information.'
|
|
174
|
-
* },
|
|
175
|
-
* {
|
|
176
|
-
* id: 'confident',
|
|
177
|
-
* label: 'Confident',
|
|
178
|
-
* prompt: 'Rewrite this content using compelling, optimistic language to convey confidence in the writing.'
|
|
179
|
-
* },
|
|
180
|
-
* {
|
|
181
|
-
* id: 'friendly',
|
|
182
|
-
* label: 'Friendly',
|
|
183
|
-
* prompt: 'Rewrite this content using friendly, comforting language, to convey understanding and empathy.'
|
|
184
|
-
* }
|
|
185
|
-
* ]
|
|
186
|
-
* },
|
|
187
|
-
* {
|
|
188
|
-
* groupId: 'changeStyle',
|
|
189
|
-
* groupLabel: 'Change style',
|
|
190
|
-
* commands: [
|
|
191
|
-
* {
|
|
192
|
-
* id: 'business',
|
|
193
|
-
* label: 'Business',
|
|
194
|
-
* prompt: 'Rewrite this content as a business professional with formal language.'
|
|
195
|
-
* },
|
|
196
|
-
* {
|
|
197
|
-
* id: 'legal',
|
|
198
|
-
* label: 'Legal',
|
|
199
|
-
* prompt: 'Rewrite this content as a legal professional using valid legal terminology.'
|
|
200
|
-
* },
|
|
201
|
-
* {
|
|
202
|
-
* id: 'journalism',
|
|
203
|
-
* label: 'Journalism',
|
|
204
|
-
* prompt: 'Rewrite this content as a journalist using engaging language to convey the importance of the information.'
|
|
205
|
-
* },
|
|
206
|
-
* {
|
|
207
|
-
* id: 'poetic',
|
|
208
|
-
* label: 'Poetic',
|
|
209
|
-
* prompt: 'Rewrite this content as a poem using poetic techniques without losing the original meaning.'
|
|
210
|
-
* }
|
|
211
|
-
* ]
|
|
212
|
-
* },
|
|
213
|
-
* {
|
|
214
|
-
* groupId: 'translate',
|
|
215
|
-
* groupLabel: 'Translate',
|
|
216
|
-
* commands: [
|
|
217
|
-
* {
|
|
218
|
-
* id: 'translateEnglish',
|
|
219
|
-
* label: 'Translate to English',
|
|
220
|
-
* prompt: 'Translate to English language.'
|
|
221
|
-
* },
|
|
222
|
-
* {
|
|
223
|
-
* id: 'translateSpanish',
|
|
224
|
-
* label: 'Translate to Spanish',
|
|
225
|
-
* prompt: 'Translate to Spanish language.'
|
|
226
|
-
* },
|
|
227
|
-
* {
|
|
228
|
-
* id: 'translatePortuguese',
|
|
229
|
-
* label: 'Translate to Portuguese',
|
|
230
|
-
* prompt: 'Translate to Portuguese language.'
|
|
231
|
-
* },
|
|
232
|
-
* {
|
|
233
|
-
* id: 'translateGerman',
|
|
234
|
-
* label: 'Translate to German',
|
|
235
|
-
* prompt: 'Translate to German language.'
|
|
236
|
-
* },
|
|
237
|
-
* {
|
|
238
|
-
* id: 'translateFrench',
|
|
239
|
-
* label: 'Translate to French',
|
|
240
|
-
* prompt: 'Translate to French language.'
|
|
241
|
-
* },
|
|
242
|
-
* {
|
|
243
|
-
* id: 'translateChinese',
|
|
244
|
-
* label: 'Translate to Simplified Chinese',
|
|
245
|
-
* prompt: 'Translate to Simplified Chinese language.'
|
|
246
|
-
* },
|
|
247
|
-
* {
|
|
248
|
-
* id: 'translateHindi',
|
|
249
|
-
* label: 'Translate to Hindi',
|
|
250
|
-
* prompt: 'Translate to Hindi language.'
|
|
251
|
-
* },
|
|
252
|
-
* {
|
|
253
|
-
* id: 'translateArabic',
|
|
254
|
-
* label: 'Translate to Arabic',
|
|
255
|
-
* prompt: 'Translate to Arabic language.'
|
|
256
|
-
* }
|
|
257
|
-
* ]
|
|
258
|
-
* }
|
|
259
|
-
* ```
|
|
260
|
-
*/
|
|
261
|
-
commands?: Array<GroupDefinition>;
|
|
262
|
-
/**
|
|
263
|
-
* A list of additional AI commands groups definitions that will extend
|
|
264
|
-
* {@link module:ai/aiassistant~AIAssistantConfig#commands default commands}.
|
|
265
|
-
*
|
|
266
|
-
* You can define new AI commands groups or add new AI commands to existing groups. If you add AI commands to an existing group,
|
|
267
|
-
* you do not need to specify `groupLabel` property.
|
|
268
|
-
*
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
* {
|
|
314
|
-
*
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
338
|
-
*/
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
*
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
*
|
|
350
|
-
*
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
*
|
|
354
|
-
*
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
*
|
|
367
|
-
*
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
*
|
|
388
|
-
*/
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
*
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license Copyright (c) 2003-2023, 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
|
+
* @module ai/aiassistant
|
|
7
|
+
* @publicApi
|
|
8
|
+
*/
|
|
9
|
+
import { type Locale } from 'ckeditor5/src/utils';
|
|
10
|
+
import { Plugin, type Editor } from 'ckeditor5/src/core';
|
|
11
|
+
import AIAssistantUI from './aiassistantui';
|
|
12
|
+
import AIAssistantEditing from './aiassistantediting';
|
|
13
|
+
import AIConnector from './aiconnector';
|
|
14
|
+
/**
|
|
15
|
+
* A function that returns the list of default AI commands definitions in the given localization context.
|
|
16
|
+
*/
|
|
17
|
+
export declare const getDefaultCommands: (locale: Locale) => Array<GroupDefinition>;
|
|
18
|
+
/**
|
|
19
|
+
* AI assistant plugin that allows you to use external AI models to generate content or improve existing content.
|
|
20
|
+
*/
|
|
21
|
+
export default class AIAssistant extends Plugin {
|
|
22
|
+
/**
|
|
23
|
+
* @inheritDoc
|
|
24
|
+
*/
|
|
25
|
+
static get requires(): readonly [typeof AIAssistantUI, typeof AIAssistantEditing, typeof AIConnector];
|
|
26
|
+
/**
|
|
27
|
+
* @inheritDoc
|
|
28
|
+
*/
|
|
29
|
+
static get pluginName(): "AIAssistant";
|
|
30
|
+
/**
|
|
31
|
+
* @inheritDoc
|
|
32
|
+
*/
|
|
33
|
+
constructor(editor: Editor);
|
|
34
|
+
/**
|
|
35
|
+
* @inheritDoc
|
|
36
|
+
*/
|
|
37
|
+
init(): void;
|
|
38
|
+
/**
|
|
39
|
+
* @inheritDoc
|
|
40
|
+
*/
|
|
41
|
+
destroy(): void;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The configuration of the AI assistant feature.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* ClassicEditor
|
|
48
|
+
* .create( editorElement, {
|
|
49
|
+
* aiAssistant: ... // AI assistant options.
|
|
50
|
+
* } )
|
|
51
|
+
* .then( ... )
|
|
52
|
+
* .catch( ... );
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
|
|
56
|
+
*/
|
|
57
|
+
export interface AIAssistantConfig {
|
|
58
|
+
/**
|
|
59
|
+
* The URL to which the API request will be sent.
|
|
60
|
+
*
|
|
61
|
+
* Defaults to `'https://api.openai.com/v1/chat/completions'`.
|
|
62
|
+
*/
|
|
63
|
+
apiUrl?: string;
|
|
64
|
+
/**
|
|
65
|
+
* A key used to authorize the request to the AI service.
|
|
66
|
+
*
|
|
67
|
+
* If you are connecting directly to the OpenAI API, use your OpenAI API key as `authKey`.
|
|
68
|
+
*
|
|
69
|
+
* **Important: use your API key ONLY in a development environment or for testing purposes!**
|
|
70
|
+
* In the production environment, {@glink features/ai-assistant#using-proxy-endpoint pass your request through a proxy}.
|
|
71
|
+
*
|
|
72
|
+
* If you are using a proxy service to send requests to the AI service, `authKey` can be used to implement authorization for your
|
|
73
|
+
* requests.
|
|
74
|
+
*
|
|
75
|
+
* If the key is provided, it is added to the `Authorization` header of the request call, using the bearer scheme:
|
|
76
|
+
*
|
|
77
|
+
* ```
|
|
78
|
+
* Authorization: Bearer <authKey>
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* If the provided value is a `string`, it is simply used as provided.
|
|
82
|
+
*
|
|
83
|
+
* If the provided value is a function, it should be a function that returns a `Promise` which resolves with the authorization token.
|
|
84
|
+
* This way, you can perform an authorization request to your application and receive the authorization token (and also implement
|
|
85
|
+
* any custom logic that you need). The authorization token is then used to make the actual call to the AI service.
|
|
86
|
+
*
|
|
87
|
+
* ```js
|
|
88
|
+
* {
|
|
89
|
+
* aiAssistant: {
|
|
90
|
+
* authKey: async () => {
|
|
91
|
+
* return await fetch( 'https://example.com/jwt-endpoint' );
|
|
92
|
+
* }
|
|
93
|
+
* // ...
|
|
94
|
+
* }
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* If the authorization request fails, the promise should be rejected. In this case, the feature will display an error notification.
|
|
99
|
+
*/
|
|
100
|
+
authKey?: string | (() => Promise<string>);
|
|
101
|
+
/**
|
|
102
|
+
* A list of all AI commands groups definitions to be displayed in the `'aiCommands'` UI dropdown.
|
|
103
|
+
*
|
|
104
|
+
* Setting this property will overwrite the default list of predefined commands.
|
|
105
|
+
*
|
|
106
|
+
* The default configuration is as follows:
|
|
107
|
+
*
|
|
108
|
+
* ```json
|
|
109
|
+
* {
|
|
110
|
+
* groupId: 'editOrReview',
|
|
111
|
+
* groupLabel: 'Edit or review',
|
|
112
|
+
* commands: [
|
|
113
|
+
* {
|
|
114
|
+
* id: 'improveWriting',
|
|
115
|
+
* label: 'Improve writing',
|
|
116
|
+
* prompt: 'Rewrite this content with no spelling mistakes, proper grammar, ' +
|
|
117
|
+
* 'and with more descriptive language, using best writing practices without losing the original meaning.'
|
|
118
|
+
* },
|
|
119
|
+
* {
|
|
120
|
+
* id: 'makeShorter',
|
|
121
|
+
* label: 'Make shorter',
|
|
122
|
+
* prompt: 'Remove any repetitive, redundant, or non-essential writing in this content ' +
|
|
123
|
+
* 'without changing the meaning or losing any key information.'
|
|
124
|
+
* },
|
|
125
|
+
* {
|
|
126
|
+
* id: 'makeLonger',
|
|
127
|
+
* label: 'Make longer',
|
|
128
|
+
* prompt: 'Expand upon this content with descriptive language and more detailed explanations, ' +
|
|
129
|
+
* 'to make the writing easier to understand and increase the length of the content.'
|
|
130
|
+
* },
|
|
131
|
+
* {
|
|
132
|
+
* id: 'simplifyLanguage',
|
|
133
|
+
* label: 'Simplify language',
|
|
134
|
+
* prompt: 'Rewrite this content with simplified language ' +
|
|
135
|
+
* 'and reduce the complexity of the writing, so that the content is easier to understand.'
|
|
136
|
+
* }
|
|
137
|
+
* ]
|
|
138
|
+
* },
|
|
139
|
+
* {
|
|
140
|
+
* groupId: 'generate',
|
|
141
|
+
* groupLabel: 'Generate from selection',
|
|
142
|
+
* commands: [
|
|
143
|
+
* {
|
|
144
|
+
* id: 'summarize',
|
|
145
|
+
* label: 'Summarize',
|
|
146
|
+
* prompt: 'Provide the key points and concepts in this content in a succinct summary.'
|
|
147
|
+
* },
|
|
148
|
+
* {
|
|
149
|
+
* id: 'continue',
|
|
150
|
+
* label: 'Continue',
|
|
151
|
+
* prompt: 'Continue this text.'
|
|
152
|
+
* }
|
|
153
|
+
* ]
|
|
154
|
+
* },
|
|
155
|
+
* {
|
|
156
|
+
* groupId: 'changeTone',
|
|
157
|
+
* groupLabel: 'Change tone',
|
|
158
|
+
* commands: [
|
|
159
|
+
* {
|
|
160
|
+
* id: 'professional',
|
|
161
|
+
* label: 'Professional',
|
|
162
|
+
* prompt: 'Rewrite this content using polished, formal, and respectful language ' +
|
|
163
|
+
* 'to convey professional expertise and competence.'
|
|
164
|
+
* },
|
|
165
|
+
* {
|
|
166
|
+
* id: 'casual',
|
|
167
|
+
* label: 'Casual',
|
|
168
|
+
* prompt: 'Rewrite this content with casual, informal language to convey a casual conversation with a real person.'
|
|
169
|
+
* },
|
|
170
|
+
* {
|
|
171
|
+
* id: 'direct',
|
|
172
|
+
* label: 'Direct',
|
|
173
|
+
* prompt: 'Rewrite this content with direct language using only the essential information.'
|
|
174
|
+
* },
|
|
175
|
+
* {
|
|
176
|
+
* id: 'confident',
|
|
177
|
+
* label: 'Confident',
|
|
178
|
+
* prompt: 'Rewrite this content using compelling, optimistic language to convey confidence in the writing.'
|
|
179
|
+
* },
|
|
180
|
+
* {
|
|
181
|
+
* id: 'friendly',
|
|
182
|
+
* label: 'Friendly',
|
|
183
|
+
* prompt: 'Rewrite this content using friendly, comforting language, to convey understanding and empathy.'
|
|
184
|
+
* }
|
|
185
|
+
* ]
|
|
186
|
+
* },
|
|
187
|
+
* {
|
|
188
|
+
* groupId: 'changeStyle',
|
|
189
|
+
* groupLabel: 'Change style',
|
|
190
|
+
* commands: [
|
|
191
|
+
* {
|
|
192
|
+
* id: 'business',
|
|
193
|
+
* label: 'Business',
|
|
194
|
+
* prompt: 'Rewrite this content as a business professional with formal language.'
|
|
195
|
+
* },
|
|
196
|
+
* {
|
|
197
|
+
* id: 'legal',
|
|
198
|
+
* label: 'Legal',
|
|
199
|
+
* prompt: 'Rewrite this content as a legal professional using valid legal terminology.'
|
|
200
|
+
* },
|
|
201
|
+
* {
|
|
202
|
+
* id: 'journalism',
|
|
203
|
+
* label: 'Journalism',
|
|
204
|
+
* prompt: 'Rewrite this content as a journalist using engaging language to convey the importance of the information.'
|
|
205
|
+
* },
|
|
206
|
+
* {
|
|
207
|
+
* id: 'poetic',
|
|
208
|
+
* label: 'Poetic',
|
|
209
|
+
* prompt: 'Rewrite this content as a poem using poetic techniques without losing the original meaning.'
|
|
210
|
+
* }
|
|
211
|
+
* ]
|
|
212
|
+
* },
|
|
213
|
+
* {
|
|
214
|
+
* groupId: 'translate',
|
|
215
|
+
* groupLabel: 'Translate',
|
|
216
|
+
* commands: [
|
|
217
|
+
* {
|
|
218
|
+
* id: 'translateEnglish',
|
|
219
|
+
* label: 'Translate to English',
|
|
220
|
+
* prompt: 'Translate to English language.'
|
|
221
|
+
* },
|
|
222
|
+
* {
|
|
223
|
+
* id: 'translateSpanish',
|
|
224
|
+
* label: 'Translate to Spanish',
|
|
225
|
+
* prompt: 'Translate to Spanish language.'
|
|
226
|
+
* },
|
|
227
|
+
* {
|
|
228
|
+
* id: 'translatePortuguese',
|
|
229
|
+
* label: 'Translate to Portuguese',
|
|
230
|
+
* prompt: 'Translate to Portuguese language.'
|
|
231
|
+
* },
|
|
232
|
+
* {
|
|
233
|
+
* id: 'translateGerman',
|
|
234
|
+
* label: 'Translate to German',
|
|
235
|
+
* prompt: 'Translate to German language.'
|
|
236
|
+
* },
|
|
237
|
+
* {
|
|
238
|
+
* id: 'translateFrench',
|
|
239
|
+
* label: 'Translate to French',
|
|
240
|
+
* prompt: 'Translate to French language.'
|
|
241
|
+
* },
|
|
242
|
+
* {
|
|
243
|
+
* id: 'translateChinese',
|
|
244
|
+
* label: 'Translate to Simplified Chinese',
|
|
245
|
+
* prompt: 'Translate to Simplified Chinese language.'
|
|
246
|
+
* },
|
|
247
|
+
* {
|
|
248
|
+
* id: 'translateHindi',
|
|
249
|
+
* label: 'Translate to Hindi',
|
|
250
|
+
* prompt: 'Translate to Hindi language.'
|
|
251
|
+
* },
|
|
252
|
+
* {
|
|
253
|
+
* id: 'translateArabic',
|
|
254
|
+
* label: 'Translate to Arabic',
|
|
255
|
+
* prompt: 'Translate to Arabic language.'
|
|
256
|
+
* }
|
|
257
|
+
* ]
|
|
258
|
+
* }
|
|
259
|
+
* ```
|
|
260
|
+
*/
|
|
261
|
+
commands?: Array<GroupDefinition>;
|
|
262
|
+
/**
|
|
263
|
+
* A list of additional AI commands groups definitions that will extend
|
|
264
|
+
* {@link module:ai/aiassistant~AIAssistantConfig#commands default commands}.
|
|
265
|
+
*
|
|
266
|
+
* You can define new AI commands groups or add new AI commands to existing groups. If you add AI commands to an existing group,
|
|
267
|
+
* you do not need to specify `groupLabel` property. Use the (optional) `order` property to control the position of new groups
|
|
268
|
+
* and commands.
|
|
269
|
+
*
|
|
270
|
+
* An example configuration:
|
|
271
|
+
*
|
|
272
|
+
* ```json
|
|
273
|
+
* {
|
|
274
|
+
* aiAssistant: {
|
|
275
|
+
* extraCommandGroups: [
|
|
276
|
+
* // Add an AI command to an existing group:
|
|
277
|
+
* {
|
|
278
|
+
* groupId: 'changeTone',
|
|
279
|
+
* commands: [
|
|
280
|
+
* {
|
|
281
|
+
* id: 'sad',
|
|
282
|
+
* label: 'Sad',
|
|
283
|
+
* prompt: 'Rewrite this text to make it sound sad and depressing.',
|
|
284
|
+
* // You can specify the position of this command among existing ones. Commands use zero-based numbering.
|
|
285
|
+
* order: 2
|
|
286
|
+
* }
|
|
287
|
+
* ]
|
|
288
|
+
* },
|
|
289
|
+
* // Create a new AI commands group:
|
|
290
|
+
* {
|
|
291
|
+
* groupId: 'transformations',
|
|
292
|
+
* groupLabel: 'Transformations',
|
|
293
|
+
* // You can specify the position of this group among existing ones. Groups use zero-based numbering.
|
|
294
|
+
* order: 3,
|
|
295
|
+
* commands: [
|
|
296
|
+
* {
|
|
297
|
+
* id: 'addEmojis',
|
|
298
|
+
* label: 'Add emojis',
|
|
299
|
+
* prompt: 'Analyze each sentence of this text. After each sentence add an emoji that summarizes the sentence.'
|
|
300
|
+
* },
|
|
301
|
+
* // ...
|
|
302
|
+
* ]
|
|
303
|
+
* },
|
|
304
|
+
* ],
|
|
305
|
+
* // ...
|
|
306
|
+
* }
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
extraCommandGroups?: Array<GroupDefinition>;
|
|
310
|
+
/**
|
|
311
|
+
* A list of ids of AI commands to be removed.
|
|
312
|
+
*
|
|
313
|
+
* Learn more about {@link module:ai/aiassistant~CommandDefinition command definition and its id}.
|
|
314
|
+
*
|
|
315
|
+
* An example configuration:
|
|
316
|
+
*
|
|
317
|
+
* ```json
|
|
318
|
+
* {
|
|
319
|
+
* aiAssistant: {
|
|
320
|
+
* removeCommands: [
|
|
321
|
+
* 'improveWriting',
|
|
322
|
+
* // ...
|
|
323
|
+
* ],
|
|
324
|
+
* // ...
|
|
325
|
+
* }
|
|
326
|
+
* ```
|
|
327
|
+
*/
|
|
328
|
+
removeCommands?: Array<string>;
|
|
329
|
+
/**
|
|
330
|
+
* Enables or disables the AI assistant UI theme.
|
|
331
|
+
*
|
|
332
|
+
* * Leaving this property unset will preserve the default theme on AI Assistant UI elements.
|
|
333
|
+
* * Setting this property to **`false`** will remove the default theme from AI assistant UI elements.
|
|
334
|
+
*
|
|
335
|
+
* {@glink features/ai-assistant#ui-customization Learn more about AI assistant UI customization.}
|
|
336
|
+
*
|
|
337
|
+
* @default true
|
|
338
|
+
*/
|
|
339
|
+
useTheme?: boolean;
|
|
340
|
+
/**
|
|
341
|
+
* An additional CSS class name (or names) added to the AI assistant content area (model response area).
|
|
342
|
+
*
|
|
343
|
+
* Because the content area is usually detached from the flow of the document, this configuration
|
|
344
|
+
* allows for better integration with application's stylesheets and improves the consistency of content
|
|
345
|
+
* styles.
|
|
346
|
+
*/
|
|
347
|
+
contentAreaCssClass?: string;
|
|
348
|
+
/**
|
|
349
|
+
* Additional configuration parameters for the AI request. Use it to customize how the AI service generates responses.
|
|
350
|
+
*
|
|
351
|
+
* See [OpenAI API reference](https://platform.openai.com/docs/api-reference/chat/create) to learn more.
|
|
352
|
+
*
|
|
353
|
+
* Defaults to:
|
|
354
|
+
*
|
|
355
|
+
* ```json
|
|
356
|
+
* {
|
|
357
|
+
* model: 'gpt-3.5-turbo',
|
|
358
|
+
* max_tokens: 2000,
|
|
359
|
+
* temperature: 1,
|
|
360
|
+
* top_p: 1
|
|
361
|
+
* }
|
|
362
|
+
* ```
|
|
363
|
+
*/
|
|
364
|
+
requestParameters?: RequestParameters;
|
|
365
|
+
/**
|
|
366
|
+
* The AI assistant feature will be disabled if the document selection includes any of these elements.
|
|
367
|
+
*
|
|
368
|
+
* Use this property if AI assistant does not work properly with your custom features.
|
|
369
|
+
*
|
|
370
|
+
* Currently, by default, AI assistant is disabled for following model elements:
|
|
371
|
+
*
|
|
372
|
+
* * Media embed (`'media'`) -- does not display in response area,
|
|
373
|
+
* * HTML embed (`'rawHtml'`) -- sometimes does not display in response area, security uncertainty,
|
|
374
|
+
* * Table of contents (`'tableOfContents'`) -- does not display properly in response area, long processing time.
|
|
375
|
+
*
|
|
376
|
+
* You can set this list to include more model elements or clear it to enable the above features.
|
|
377
|
+
*
|
|
378
|
+
* Note, that all or some of these features may become enabled in the future.
|
|
379
|
+
*
|
|
380
|
+
* @default [ 'media', 'rawHtml', 'tableOfContents' ]
|
|
381
|
+
*/
|
|
382
|
+
disabledElements?: Array<string>;
|
|
383
|
+
}
|
|
384
|
+
export type GroupDefinition = {
|
|
385
|
+
/**
|
|
386
|
+
* The unique identifier of the group. It can be referenced while extending existing groups
|
|
387
|
+
* using {@link module:ai/aiassistant~AIAssistantConfig#extraCommandGroups}.
|
|
388
|
+
*/
|
|
389
|
+
groupId: string;
|
|
390
|
+
/**
|
|
391
|
+
* The human-readable label of the group.
|
|
392
|
+
*/
|
|
393
|
+
groupLabel?: string;
|
|
394
|
+
/**
|
|
395
|
+
* The array of command definitions that belong to the group.
|
|
396
|
+
*/
|
|
397
|
+
commands: Array<CommandDefinition>;
|
|
398
|
+
/**
|
|
399
|
+
* The order of the group on the list. The lower the number, the higher the group is displayed on the list.
|
|
400
|
+
* If not specified, the position of this group will be determined by the order of
|
|
401
|
+
* {@link module:ai/aiassistant~AIAssistantConfig#commands configuration}.
|
|
402
|
+
*
|
|
403
|
+
* If a new group is added without `order` property, it will be added at the end.
|
|
404
|
+
*
|
|
405
|
+
* The order uses zero-based numbering (the first group's order is `0`).
|
|
406
|
+
*/
|
|
407
|
+
order?: number;
|
|
408
|
+
};
|
|
409
|
+
export type CommandDefinition = {
|
|
410
|
+
/**
|
|
411
|
+
* The unique identifier of the command. It can be referenced while removing commands. See
|
|
412
|
+
* {@link module:ai/aiassistant~AIAssistantConfig#removeCommands} to learn more.
|
|
413
|
+
*/
|
|
414
|
+
id: string;
|
|
415
|
+
/**
|
|
416
|
+
* The human-readable label of the command.
|
|
417
|
+
*/
|
|
418
|
+
label: string;
|
|
419
|
+
/**
|
|
420
|
+
* The instruction that will be passed to the AI model.
|
|
421
|
+
*
|
|
422
|
+
* It is wrapped in a "full prompt template" for better results.
|
|
423
|
+
*/
|
|
424
|
+
prompt: string;
|
|
425
|
+
/**
|
|
426
|
+
* By default, all commands require a selection for the assistant to work on. If the selection is collapsed,
|
|
427
|
+
* it automatically expands to the nearest block boundaries to provide the AI context.
|
|
428
|
+
*
|
|
429
|
+
* Setting this to `false` allows the command to work on a collapsed selection and prevent selection expansion.
|
|
430
|
+
* This is helpful, for instance, for commands that generate content from scratch.
|
|
431
|
+
*
|
|
432
|
+
* **Note**: If not specified, the default is `true`.
|
|
433
|
+
*/
|
|
434
|
+
requiresContent?: boolean;
|
|
435
|
+
/**
|
|
436
|
+
* The order of the command on the list. The lower the number, the higher the command is displayed on the list.
|
|
437
|
+
* If not specified, the position of this command will be determined by the order of
|
|
438
|
+
* {@link module:ai/aiassistant~AIAssistantConfig#commands configuration}.
|
|
439
|
+
*
|
|
440
|
+
* If a new command is added without `order` property, it will be added at the end of the group.
|
|
441
|
+
*
|
|
442
|
+
* The order uses zero-based numbering (the first command's order is `0`).
|
|
443
|
+
*/
|
|
444
|
+
order?: number;
|
|
445
|
+
};
|
|
446
|
+
/**
|
|
447
|
+
* OpenAI request parameters that will influence how the response is generated.
|
|
448
|
+
*
|
|
449
|
+
* See OpenAI API reference to learn more.
|
|
450
|
+
*/
|
|
451
|
+
export type RequestParameters = {
|
|
452
|
+
model?: string;
|
|
453
|
+
max_tokens?: number;
|
|
454
|
+
temperature?: number;
|
|
455
|
+
top_p?: number;
|
|
456
|
+
user?: string;
|
|
457
|
+
stream?: boolean;
|
|
458
|
+
};
|