@ckeditor/ckeditor5-ai 41.3.1 → 41.4.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 (323) hide show
  1. package/README.md +1 -1
  2. package/build/ai.js +7 -7
  3. package/build/translations/af.js +1 -1
  4. package/build/translations/ar.js +1 -1
  5. package/build/translations/bg.js +1 -1
  6. package/build/translations/bn.js +1 -1
  7. package/build/translations/bs.js +1 -1
  8. package/build/translations/ca.js +1 -1
  9. package/build/translations/cs.js +1 -1
  10. package/build/translations/da.js +1 -1
  11. package/build/translations/de-ch.js +1 -1
  12. package/build/translations/de.js +1 -1
  13. package/build/translations/el.js +1 -1
  14. package/build/translations/en-au.js +1 -1
  15. package/build/translations/es-co.js +1 -1
  16. package/build/translations/es.js +1 -1
  17. package/build/translations/et.js +1 -1
  18. package/build/translations/fa.js +1 -1
  19. package/build/translations/fi.js +1 -1
  20. package/build/translations/fr.js +1 -1
  21. package/build/translations/gl.js +1 -1
  22. package/build/translations/he.js +1 -1
  23. package/build/translations/hi.js +1 -1
  24. package/build/translations/hr.js +1 -1
  25. package/build/translations/hu.js +1 -1
  26. package/build/translations/id.js +1 -1
  27. package/build/translations/it.js +1 -1
  28. package/build/translations/ja.js +1 -1
  29. package/build/translations/jv.js +1 -1
  30. package/build/translations/ko.js +1 -1
  31. package/build/translations/lt.js +1 -1
  32. package/build/translations/lv.js +1 -1
  33. package/build/translations/ms.js +1 -1
  34. package/build/translations/nl.js +1 -1
  35. package/build/translations/no.js +1 -1
  36. package/build/translations/pl.js +1 -1
  37. package/build/translations/pt-br.js +1 -1
  38. package/build/translations/pt.js +1 -1
  39. package/build/translations/ro.js +1 -1
  40. package/build/translations/ru.js +1 -1
  41. package/build/translations/sk.js +1 -1
  42. package/build/translations/sr-latn.js +1 -1
  43. package/build/translations/sr.js +1 -1
  44. package/build/translations/sv.js +1 -1
  45. package/build/translations/th.js +1 -1
  46. package/build/translations/ti.js +1 -0
  47. package/build/translations/tk.js +1 -1
  48. package/build/translations/tr.js +1 -1
  49. package/build/translations/ug.js +1 -1
  50. package/build/translations/uk.js +1 -1
  51. package/build/translations/ur.js +1 -1
  52. package/build/translations/uz.js +1 -1
  53. package/build/translations/vi.js +1 -1
  54. package/build/translations/zh-cn.js +1 -1
  55. package/build/translations/zh.js +1 -1
  56. package/dist/index-content.css +4 -0
  57. package/dist/index-editor.css +267 -0
  58. package/dist/index.css +396 -0
  59. package/dist/index.js +23 -0
  60. package/dist/translations/af.d.ts +8 -0
  61. package/dist/translations/af.js +23 -0
  62. package/dist/translations/af.umd.js +23 -0
  63. package/dist/translations/ar.d.ts +8 -0
  64. package/dist/translations/ar.js +23 -0
  65. package/dist/translations/ar.umd.js +23 -0
  66. package/dist/translations/bg.d.ts +8 -0
  67. package/dist/translations/bg.js +23 -0
  68. package/dist/translations/bg.umd.js +23 -0
  69. package/dist/translations/bn.d.ts +8 -0
  70. package/dist/translations/bn.js +23 -0
  71. package/dist/translations/bn.umd.js +23 -0
  72. package/dist/translations/bs.d.ts +8 -0
  73. package/dist/translations/bs.js +23 -0
  74. package/dist/translations/bs.umd.js +23 -0
  75. package/dist/translations/ca.d.ts +8 -0
  76. package/dist/translations/ca.js +23 -0
  77. package/dist/translations/ca.umd.js +23 -0
  78. package/dist/translations/cs.d.ts +8 -0
  79. package/dist/translations/cs.js +23 -0
  80. package/dist/translations/cs.umd.js +23 -0
  81. package/dist/translations/da.d.ts +8 -0
  82. package/dist/translations/da.js +23 -0
  83. package/dist/translations/da.umd.js +23 -0
  84. package/dist/translations/de-ch.d.ts +8 -0
  85. package/dist/translations/de-ch.js +23 -0
  86. package/dist/translations/de-ch.umd.js +23 -0
  87. package/dist/translations/de.d.ts +8 -0
  88. package/dist/translations/de.js +23 -0
  89. package/dist/translations/de.umd.js +23 -0
  90. package/dist/translations/el.d.ts +8 -0
  91. package/dist/translations/el.js +23 -0
  92. package/dist/translations/el.umd.js +23 -0
  93. package/dist/translations/en-au.d.ts +8 -0
  94. package/dist/translations/en-au.js +23 -0
  95. package/dist/translations/en-au.umd.js +23 -0
  96. package/dist/translations/en.d.ts +8 -0
  97. package/dist/translations/en.js +23 -0
  98. package/dist/translations/en.umd.js +23 -0
  99. package/dist/translations/es-co.d.ts +8 -0
  100. package/dist/translations/es-co.js +23 -0
  101. package/dist/translations/es-co.umd.js +23 -0
  102. package/dist/translations/es.d.ts +8 -0
  103. package/dist/translations/es.js +23 -0
  104. package/dist/translations/es.umd.js +23 -0
  105. package/dist/translations/et.d.ts +8 -0
  106. package/dist/translations/et.js +23 -0
  107. package/dist/translations/et.umd.js +23 -0
  108. package/dist/translations/fa.d.ts +8 -0
  109. package/dist/translations/fa.js +23 -0
  110. package/dist/translations/fa.umd.js +23 -0
  111. package/dist/translations/fi.d.ts +8 -0
  112. package/dist/translations/fi.js +23 -0
  113. package/dist/translations/fi.umd.js +23 -0
  114. package/dist/translations/fr.d.ts +8 -0
  115. package/dist/translations/fr.js +23 -0
  116. package/dist/translations/fr.umd.js +23 -0
  117. package/dist/translations/gl.d.ts +8 -0
  118. package/dist/translations/gl.js +23 -0
  119. package/dist/translations/gl.umd.js +23 -0
  120. package/dist/translations/he.d.ts +8 -0
  121. package/dist/translations/he.js +23 -0
  122. package/dist/translations/he.umd.js +23 -0
  123. package/dist/translations/hi.d.ts +8 -0
  124. package/dist/translations/hi.js +23 -0
  125. package/dist/translations/hi.umd.js +23 -0
  126. package/dist/translations/hr.d.ts +8 -0
  127. package/dist/translations/hr.js +23 -0
  128. package/dist/translations/hr.umd.js +23 -0
  129. package/dist/translations/hu.d.ts +8 -0
  130. package/dist/translations/hu.js +23 -0
  131. package/dist/translations/hu.umd.js +23 -0
  132. package/dist/translations/id.d.ts +8 -0
  133. package/dist/translations/id.js +23 -0
  134. package/dist/translations/id.umd.js +23 -0
  135. package/dist/translations/it.d.ts +8 -0
  136. package/dist/translations/it.js +23 -0
  137. package/dist/translations/it.umd.js +23 -0
  138. package/dist/translations/ja.d.ts +8 -0
  139. package/dist/translations/ja.js +23 -0
  140. package/dist/translations/ja.umd.js +23 -0
  141. package/dist/translations/jv.d.ts +8 -0
  142. package/dist/translations/jv.js +23 -0
  143. package/dist/translations/jv.umd.js +23 -0
  144. package/dist/translations/ko.d.ts +8 -0
  145. package/dist/translations/ko.js +23 -0
  146. package/dist/translations/ko.umd.js +23 -0
  147. package/dist/translations/lt.d.ts +8 -0
  148. package/dist/translations/lt.js +23 -0
  149. package/dist/translations/lt.umd.js +23 -0
  150. package/dist/translations/lv.d.ts +8 -0
  151. package/dist/translations/lv.js +23 -0
  152. package/dist/translations/lv.umd.js +23 -0
  153. package/dist/translations/ms.d.ts +8 -0
  154. package/dist/translations/ms.js +23 -0
  155. package/dist/translations/ms.umd.js +23 -0
  156. package/dist/translations/nl.d.ts +8 -0
  157. package/dist/translations/nl.js +23 -0
  158. package/dist/translations/nl.umd.js +23 -0
  159. package/dist/translations/no.d.ts +8 -0
  160. package/dist/translations/no.js +23 -0
  161. package/dist/translations/no.umd.js +23 -0
  162. package/dist/translations/pl.d.ts +8 -0
  163. package/dist/translations/pl.js +23 -0
  164. package/dist/translations/pl.umd.js +23 -0
  165. package/dist/translations/pt-br.d.ts +8 -0
  166. package/dist/translations/pt-br.js +23 -0
  167. package/dist/translations/pt-br.umd.js +23 -0
  168. package/dist/translations/pt.d.ts +8 -0
  169. package/dist/translations/pt.js +23 -0
  170. package/dist/translations/pt.umd.js +23 -0
  171. package/dist/translations/ro.d.ts +8 -0
  172. package/dist/translations/ro.js +23 -0
  173. package/dist/translations/ro.umd.js +23 -0
  174. package/dist/translations/ru.d.ts +8 -0
  175. package/dist/translations/ru.js +23 -0
  176. package/dist/translations/ru.umd.js +23 -0
  177. package/dist/translations/sk.d.ts +8 -0
  178. package/dist/translations/sk.js +23 -0
  179. package/dist/translations/sk.umd.js +23 -0
  180. package/dist/translations/sr-latn.d.ts +8 -0
  181. package/dist/translations/sr-latn.js +23 -0
  182. package/dist/translations/sr-latn.umd.js +23 -0
  183. package/dist/translations/sr.d.ts +8 -0
  184. package/dist/translations/sr.js +23 -0
  185. package/dist/translations/sr.umd.js +23 -0
  186. package/dist/translations/sv.d.ts +8 -0
  187. package/dist/translations/sv.js +23 -0
  188. package/dist/translations/sv.umd.js +23 -0
  189. package/dist/translations/th.d.ts +8 -0
  190. package/dist/translations/th.js +23 -0
  191. package/dist/translations/th.umd.js +23 -0
  192. package/dist/translations/ti.d.ts +8 -0
  193. package/dist/translations/ti.js +23 -0
  194. package/dist/translations/ti.umd.js +23 -0
  195. package/dist/translations/tk.d.ts +8 -0
  196. package/dist/translations/tk.js +23 -0
  197. package/dist/translations/tk.umd.js +23 -0
  198. package/dist/translations/tr.d.ts +8 -0
  199. package/dist/translations/tr.js +23 -0
  200. package/dist/translations/tr.umd.js +23 -0
  201. package/dist/translations/ug.d.ts +8 -0
  202. package/dist/translations/ug.js +23 -0
  203. package/dist/translations/ug.umd.js +23 -0
  204. package/dist/translations/uk.d.ts +8 -0
  205. package/dist/translations/uk.js +23 -0
  206. package/dist/translations/uk.umd.js +23 -0
  207. package/dist/translations/ur.d.ts +8 -0
  208. package/dist/translations/ur.js +23 -0
  209. package/dist/translations/ur.umd.js +23 -0
  210. package/dist/translations/uz.d.ts +8 -0
  211. package/dist/translations/uz.js +23 -0
  212. package/dist/translations/uz.umd.js +23 -0
  213. package/dist/translations/vi.d.ts +8 -0
  214. package/dist/translations/vi.js +23 -0
  215. package/dist/translations/vi.umd.js +23 -0
  216. package/dist/translations/zh-cn.d.ts +8 -0
  217. package/dist/translations/zh-cn.js +23 -0
  218. package/dist/translations/zh-cn.umd.js +23 -0
  219. package/dist/translations/zh.d.ts +8 -0
  220. package/dist/translations/zh.js +23 -0
  221. package/dist/translations/zh.umd.js +23 -0
  222. package/dist/types/adapters/aiadapter.d.ts +52 -0
  223. package/dist/types/adapters/aitextadapter.d.ts +150 -0
  224. package/dist/types/adapters/awstextadapter.d.ts +183 -0
  225. package/dist/types/adapters/openaitextadapter.d.ts +187 -0
  226. package/dist/types/aiassistant.d.ts +390 -0
  227. package/dist/types/aiassistantediting.d.ts +50 -0
  228. package/dist/types/aiassistantui.d.ts +57 -0
  229. package/dist/types/aiconfig.d.ts +73 -0
  230. package/dist/types/augmentation.d.ts +31 -0
  231. package/dist/types/index.d.ts +17 -0
  232. package/dist/types/ui/aiassistantcontroller.d.ts +113 -0
  233. package/dist/types/ui/dropdown/aicommandslistview.d.ts +37 -0
  234. package/dist/types/ui/dropdown/buttonlabelwithhighlightview.d.ts +33 -0
  235. package/dist/types/ui/dropdown/labelwithhighlightview.d.ts +29 -0
  236. package/dist/types/ui/form/aiformcontentarea.d.ts +52 -0
  237. package/dist/types/ui/form/aiformerrorview.d.ts +30 -0
  238. package/dist/types/ui/form/aiformpromptview.d.ts +50 -0
  239. package/dist/types/ui/form/aiformtoolbarview.d.ts +62 -0
  240. package/dist/types/ui/form/aiformview.d.ts +145 -0
  241. package/dist/types/ui/form/aihistorylistitemview.d.ts +22 -0
  242. package/dist/types/ui/form/aihistorylistview.d.ts +39 -0
  243. package/dist/types/ui/form/prompthistory.d.ts +24 -0
  244. package/dist/types/ui/showaiassistantcommand.d.ts +44 -0
  245. package/dist/types/utils/common-translations.d.ts +13 -0
  246. package/lang/contexts.json +4 -0
  247. package/lang/translations/af.po +16 -0
  248. package/lang/translations/ar.po +16 -0
  249. package/lang/translations/bg.po +16 -0
  250. package/lang/translations/bn.po +16 -0
  251. package/lang/translations/bs.po +16 -0
  252. package/lang/translations/ca.po +16 -0
  253. package/lang/translations/cs.po +16 -0
  254. package/lang/translations/da.po +16 -0
  255. package/lang/translations/de-ch.po +16 -0
  256. package/lang/translations/de.po +16 -0
  257. package/lang/translations/el.po +16 -0
  258. package/lang/translations/en-au.po +16 -0
  259. package/lang/translations/en.po +16 -0
  260. package/lang/translations/es-co.po +16 -0
  261. package/lang/translations/es.po +16 -0
  262. package/lang/translations/et.po +16 -0
  263. package/lang/translations/fa.po +16 -0
  264. package/lang/translations/fi.po +16 -0
  265. package/lang/translations/fr.po +16 -0
  266. package/lang/translations/gl.po +16 -0
  267. package/lang/translations/he.po +16 -0
  268. package/lang/translations/hi.po +16 -0
  269. package/lang/translations/hr.po +16 -0
  270. package/lang/translations/hu.po +16 -0
  271. package/lang/translations/id.po +16 -0
  272. package/lang/translations/it.po +16 -0
  273. package/lang/translations/ja.po +16 -0
  274. package/lang/translations/jv.po +16 -0
  275. package/lang/translations/ko.po +16 -0
  276. package/lang/translations/lt.po +16 -0
  277. package/lang/translations/lv.po +16 -0
  278. package/lang/translations/ms.po +16 -0
  279. package/lang/translations/nl.po +16 -0
  280. package/lang/translations/no.po +16 -0
  281. package/lang/translations/pl.po +16 -0
  282. package/lang/translations/pt-br.po +16 -0
  283. package/lang/translations/pt.po +16 -0
  284. package/lang/translations/ro.po +16 -0
  285. package/lang/translations/ru.po +16 -0
  286. package/lang/translations/sk.po +16 -0
  287. package/lang/translations/sr-latn.po +16 -0
  288. package/lang/translations/sr.po +16 -0
  289. package/lang/translations/sv.po +16 -0
  290. package/lang/translations/th.po +16 -0
  291. package/lang/translations/ti.po +250 -0
  292. package/lang/translations/tk.po +16 -0
  293. package/lang/translations/tr.po +16 -0
  294. package/lang/translations/ug.po +16 -0
  295. package/lang/translations/uk.po +16 -0
  296. package/lang/translations/ur.po +16 -0
  297. package/lang/translations/uz.po +16 -0
  298. package/lang/translations/vi.po +16 -0
  299. package/lang/translations/zh-cn.po +16 -0
  300. package/lang/translations/zh.po +16 -0
  301. package/package.json +5 -4
  302. package/src/adapters/aiadapter.js +1 -1
  303. package/src/adapters/aitextadapter.js +1 -1
  304. package/src/adapters/awstextadapter.js +1 -1
  305. package/src/adapters/openaitextadapter.js +1 -1
  306. package/src/aiassistant.js +1 -1
  307. package/src/aiassistantediting.js +1 -1
  308. package/src/aiassistantui.js +1 -1
  309. package/src/index.js +1 -1
  310. package/src/ui/aiassistantcontroller.js +1 -1
  311. package/src/ui/dropdown/aicommandslistview.js +1 -1
  312. package/src/ui/dropdown/buttonlabelwithhighlightview.js +1 -1
  313. package/src/ui/dropdown/labelwithhighlightview.js +1 -1
  314. package/src/ui/form/aiformcontentarea.js +1 -1
  315. package/src/ui/form/aiformerrorview.js +1 -1
  316. package/src/ui/form/aiformpromptview.js +1 -1
  317. package/src/ui/form/aiformtoolbarview.js +1 -1
  318. package/src/ui/form/aiformview.js +1 -1
  319. package/src/ui/form/aihistorylistitemview.js +1 -1
  320. package/src/ui/form/aihistorylistview.js +1 -1
  321. package/src/ui/form/prompthistory.js +1 -1
  322. package/src/ui/showaiassistantcommand.js +1 -1
  323. package/src/utils/common-translations.js +1 -1
@@ -0,0 +1,187 @@
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/adapters/openaitextadapter
11
+ * @publicApi
12
+ */
13
+ import { type Editor } from 'ckeditor5/src/core.js';
14
+ import { default as AITextAdapter, type AITextAdapterRequestData, type RequestHeaders, type RequestParameters } from './aitextadapter.js';
15
+ /**
16
+ * Adapter for AI text-related requests that supports OpenAI and Azure OpenAI services.
17
+ *
18
+ * See also {@link module:ai/adapters/aitextadapter~AITextAdapter}.
19
+ */
20
+ export default class OpenAITextAdapter extends AITextAdapter {
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ static get pluginName(): "OpenAITextAdapter";
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ constructor(editor: Editor);
29
+ /**
30
+ * Performs the request to the OpenAI service, Azure OpenAI service, or to the endpoint provided in the editor configuration.
31
+ *
32
+ * If you want to extend this adapter, you can overload this method to do some additional processing or make an external call.
33
+ */
34
+ sendRequest({ query, context, onData, actionId }: AITextAdapterRequestData): Promise<void>;
35
+ /**
36
+ * Prepares the actual request messages to be sent as a part of the request to the AI service.
37
+ *
38
+ * See [OpenAI API reference](https://platform.openai.com/docs/api-reference/chat/create) to learn more.
39
+ *
40
+ * This method returns two messages, one "system message" with general instructions for the model and one "user message"
41
+ * with the actual instruction to perform.
42
+ *
43
+ * The messages are different, based on whether there is any `context` provided. If no `context` is provided, it is assumed that
44
+ * the user wants to generate new content. If `context` is provided, it is assumed that the user wants to process this `context`
45
+ * (e.g. translate) or generate something based on `context` (e.g. summary).
46
+ *
47
+ * You can overload this method to customize the messages that are sent to the AI service.
48
+ *
49
+ * @param query The user's query. The instruction which the model should perform.
50
+ * @param context The context for the instruction. Usually this will be a part of the editor content. Can be empty.
51
+ * @param actionId ID of the performed action. See {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId}.
52
+ */
53
+ prepareMessages(query: string, context: string, actionId: string): Promise<Array<RequestMessageItem>>;
54
+ }
55
+ /**
56
+ * The configuration for the OpenAI adapter.
57
+ *
58
+ * The properties defined in this config are set in the `config.ai.openAI` namespace.
59
+ *
60
+ * ```ts
61
+ * ClassicEditor
62
+ * .create( editorElement, {
63
+ * ai: {
64
+ * openAI: {
65
+ * requestHeaders: {
66
+ * Authorization: 'Bearer OPENAI_API_KEY'
67
+ * }
68
+ * }
69
+ * }
70
+ * } )
71
+ * .then( ... )
72
+ * .catch( ... );
73
+ * ```
74
+ *
75
+ * See {@link module:ai/aiconfig~AIConfig the full AI configuration}.
76
+ *
77
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
78
+ */
79
+ export interface OpenAITextAdapterConfig {
80
+ /**
81
+ * The URL to which the AI service request will be sent.
82
+ *
83
+ * By default, requests are sent to the OpenAI API service. Change this value to make requests to Azure OpenAI API or use proxy endpoint
84
+ * in your application instead.
85
+ *
86
+ * Defaults to `'https://api.openai.com/v1/chat/completions'`.
87
+ */
88
+ apiUrl?: string;
89
+ /**
90
+ * Object with headers to set in the request to the AI service API.
91
+ *
92
+ * If the provided value is an `object`, it is simply used as provided.
93
+ *
94
+ * If you are connecting directly to the OpenAI API, use your OpenAI API key in the following way:
95
+ *
96
+ * ```js
97
+ * {
98
+ * ai: {
99
+ * openAI: {
100
+ * requestHeaders: {
101
+ * 'Authorization': 'Bearer YOUR_API_KEY'
102
+ * }
103
+ * // ...
104
+ * }
105
+ * // ..
106
+ * }
107
+ * }
108
+ * ```
109
+ *
110
+ * **Important: use your API key ONLY in a development environment or for testing purposes!**
111
+ * In the production environment, pass your request through a proxy endpoint.
112
+ *
113
+ * If you are using a proxy service to send requests to the OpenAI API, `requestHeaders` can be used to implement authorization for your
114
+ * requests.
115
+ *
116
+ * If the provided value is a function, it should be a function that returns a `Promise` which resolves with the headers object.
117
+ * This way, you can perform an authorization request to your application and receive the authorization token (and also implement
118
+ * any custom logic on the back-end side). The headers object is then used to make the actual call to the AI service.
119
+ *
120
+ * The function is passed {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId `actionId`} parameter to make it
121
+ * possible to further customize the headers.
122
+ *
123
+ * ```js
124
+ * {
125
+ * ai: {
126
+ * openAI: {
127
+ * requestHeaders: async () => {
128
+ * const jwt = await fetch( 'https://example.com/jwt-endpoint' );
129
+ *
130
+ * return {
131
+ * 'Authorization': 'Bearer ' + jwt
132
+ * };
133
+ * }
134
+ * // ...
135
+ * }
136
+ * }
137
+ * }
138
+ * ```
139
+ *
140
+ * If the function fails for any reason, the promise should be rejected. In this case, a feature that made the request should display
141
+ * an error notification.
142
+ */
143
+ requestHeaders?: RequestHeaders;
144
+ /**
145
+ * Additional configuration parameters for the AI service request. Use it to customize how the AI service generates responses.
146
+ * Note that the value you will set here will fully overwrite the default value.
147
+ *
148
+ * See [OpenAI API reference](https://platform.openai.com/docs/api-reference/chat/create) to learn more about available parameters.
149
+ *
150
+ * If the provided value is an `object`, it is passed to the request as provided.
151
+ *
152
+ * If the provided value is a function, it should be a function that returns a `Promise` which resolves with the request parameters
153
+ * object. This gives you more flexibility to provide parameters for the AI model.
154
+ *
155
+ * The function is passed {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId `actionId`} parameter to make it
156
+ * possible to further customize the parameters.
157
+ *
158
+ * If the function fails for any reason, the promise should be rejected. In this case, the feature that made the request should display
159
+ * an error notification.
160
+ *
161
+ * Defaults to:
162
+ *
163
+ * ```json
164
+ * {
165
+ * model: 'gpt-3.5-turbo',
166
+ * max_tokens: 2000,
167
+ * temperature: 1,
168
+ * top_p: 1,
169
+ * stream: true
170
+ * }
171
+ * ```
172
+ */
173
+ requestParameters?: RequestParameters;
174
+ }
175
+ /**
176
+ * Single message item, in the format required for the OpenAI request.
177
+ *
178
+ * Example:
179
+ *
180
+ * ```json
181
+ * { role: 'system', content: 'You are a helpful assistant.' }
182
+ * ```
183
+ *
184
+ * See [OpenAI API reference](https://platform.openai.com/docs/api-reference/chat/create) to learn more.
185
+ */
186
+ type RequestMessageItem = Record<string, string>;
187
+ export {};
@@ -0,0 +1,390 @@
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/aiassistant
11
+ * @publicApi
12
+ */
13
+ import { type Locale } from 'ckeditor5/src/utils.js';
14
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
15
+ import AIAssistantUI from './aiassistantui.js';
16
+ import AIAssistantEditing from './aiassistantediting.js';
17
+ /**
18
+ * AI assistant plugin that allows you to use external AI models to generate content or improve existing content.
19
+ *
20
+ * The feature uses following {@link module:ai/adapters/aitextadapter~AITextAdapterRequestData#actionId `actionId`} values:
21
+ *
22
+ * * `aiAssistant:command:<commandId>` for the predefined commands, where `<commandId>` is the ID of the predefined command,
23
+ * * `aiAssistant:custom` for custom queries provided by the user.
24
+ */
25
+ export default class AIAssistant extends Plugin {
26
+ /**
27
+ * @inheritDoc
28
+ */
29
+ static get requires(): readonly [typeof AIAssistantUI, typeof AIAssistantEditing];
30
+ /**
31
+ * @inheritDoc
32
+ */
33
+ static get pluginName(): "AIAssistant";
34
+ /**
35
+ * @inheritDoc
36
+ */
37
+ constructor(editor: Editor);
38
+ /**
39
+ * @inheritDoc
40
+ */
41
+ init(): void;
42
+ /**
43
+ * @inheritDoc
44
+ */
45
+ destroy(): void;
46
+ }
47
+ /**
48
+ * A function that returns the list of the default AI commands definitions in the given localization context.
49
+ */
50
+ export declare function getDefaultCommands(locale: Locale): Array<GroupDefinition>;
51
+ /**
52
+ * The configuration of the AI Assistant feature.
53
+ *
54
+ * The properties defined in this config are set in the `config.ai.aiAssistant` namespace.
55
+ *
56
+ * ```ts
57
+ * ClassicEditor
58
+ * .create( editorElement, {
59
+ * ai: {
60
+ * aiAssistant: {
61
+ * // AI Assistant configuration.
62
+ * }
63
+ * }
64
+ * } )
65
+ * .then( ... )
66
+ * .catch( ... );
67
+ * ```
68
+ *
69
+ * See {@link module:ai/aiconfig~AIConfig the full AI configuration}.
70
+ *
71
+ * See {@link module:core/editor/editorconfig~EditorConfig all editor options}.
72
+ */
73
+ export interface AIAssistantConfig {
74
+ /**
75
+ * A list of all AI commands groups definitions to be displayed in the `'aiCommands'` UI dropdown.
76
+ *
77
+ * Setting this property will overwrite the default list of predefined commands.
78
+ *
79
+ * The default configuration is as follows. It can be obtained through {@link ~getDefaultCommands}:
80
+ *
81
+ * ```json
82
+ * [ {
83
+ * groupId: 'editOrReview',
84
+ * groupLabel: 'Edit or review',
85
+ * commands: [
86
+ * {
87
+ * id: 'improveWriting',
88
+ * label: 'Improve writing',
89
+ * prompt: 'Fix spelling mistakes, use proper grammar and apply good writing practices. Do not lose the original meaning.'
90
+ * },
91
+ * {
92
+ * id: 'makeShorter',
93
+ * label: 'Make shorter',
94
+ * prompt: 'Remove any repetitive, redundant, or non-essential writing in this content ' +
95
+ * 'without changing the meaning or losing any key information.'
96
+ * },
97
+ * {
98
+ * id: 'makeLonger',
99
+ * label: 'Make longer',
100
+ * prompt: 'Improve this content by using descriptive language and inserting more information and more detailed explanations.'
101
+ * },
102
+ * {
103
+ * id: 'simplifyLanguage',
104
+ * label: 'Simplify language',
105
+ * prompt: 'Simplify the writing style of this content ' +
106
+ * 'and reduce the complexity, so that the content is easy to understand.'
107
+ * }
108
+ * ]
109
+ * },
110
+ * {
111
+ * groupId: 'generate',
112
+ * groupLabel: 'Generate from selection',
113
+ * commands: [
114
+ * {
115
+ * id: 'summarize',
116
+ * label: 'Summarize',
117
+ * prompt: 'Summarize this content into one paragraph of text. Include only the key ideas and conclusions. Keep it short. '
118
+ * },
119
+ * {
120
+ * id: 'continue',
121
+ * label: 'Continue',
122
+ * prompt: 'Start with the provided content and write at the end of it continuing this topic. Keep the added part short.'
123
+ * }
124
+ * ]
125
+ * },
126
+ * {
127
+ * groupId: 'changeTone',
128
+ * groupLabel: 'Change tone',
129
+ * commands: [
130
+ * {
131
+ * id: 'professional',
132
+ * label: 'Professional',
133
+ * prompt: 'Improve using polished, formal, and respectful language ' +
134
+ * 'to convey professional expertise and competence.'
135
+ * },
136
+ * {
137
+ * id: 'casual',
138
+ * label: 'Casual',
139
+ * prompt: 'Improve using casual, informal language to convey a casual conversation with a real person.'
140
+ * },
141
+ * {
142
+ * id: 'direct',
143
+ * label: 'Direct',
144
+ * prompt: 'Improve using direct language using only the essential information.'
145
+ * },
146
+ * {
147
+ * id: 'confident',
148
+ * label: 'Confident',
149
+ * prompt: 'Improve using compelling, optimistic language to convey confidence in the writing.'
150
+ * },
151
+ * {
152
+ * id: 'friendly',
153
+ * label: 'Friendly',
154
+ * prompt: 'Improve using friendly, comforting language, to convey understanding and empathy.'
155
+ * }
156
+ * ]
157
+ * },
158
+ * {
159
+ * groupId: 'changeStyle',
160
+ * groupLabel: 'Change style',
161
+ * commands: [
162
+ * {
163
+ * id: 'business',
164
+ * label: 'Business',
165
+ * prompt: 'Rewrite this content as a business professional with formal language.'
166
+ * },
167
+ * {
168
+ * id: 'legal',
169
+ * label: 'Legal',
170
+ * prompt: 'Rewrite this content as a legal professional using valid legal terminology.'
171
+ * },
172
+ * {
173
+ * id: 'journalism',
174
+ * label: 'Journalism',
175
+ * prompt: 'Rewrite this content as a journalist using engaging language to convey the importance of the information.'
176
+ * },
177
+ * {
178
+ * id: 'poetic',
179
+ * label: 'Poetic',
180
+ * prompt: 'Rewrite this content as a poem using poetic techniques without losing the original meaning.'
181
+ * }
182
+ * ]
183
+ * },
184
+ * {
185
+ * groupId: 'translate',
186
+ * groupLabel: 'Translate',
187
+ * commands: [
188
+ * {
189
+ * id: 'translateEnglish',
190
+ * label: 'Translate to English',
191
+ * prompt: 'Translate the content to English language.'
192
+ * },
193
+ * {
194
+ * id: 'translateSpanish',
195
+ * label: 'Translate to Spanish',
196
+ * prompt: 'Translate the content to Spanish language.'
197
+ * },
198
+ * {
199
+ * id: 'translatePortuguese',
200
+ * label: 'Translate to Portuguese',
201
+ * prompt: 'Translate the content to Portuguese language.'
202
+ * },
203
+ * {
204
+ * id: 'translateGerman',
205
+ * label: 'Translate to German',
206
+ * prompt: 'Translate the content to German language.'
207
+ * },
208
+ * {
209
+ * id: 'translateFrench',
210
+ * label: 'Translate to French',
211
+ * prompt: 'Translate the content to French language.'
212
+ * },
213
+ * {
214
+ * id: 'translateChinese',
215
+ * label: 'Translate to Simplified Chinese',
216
+ * prompt: 'Translate the content to Simplified Chinese language.'
217
+ * },
218
+ * {
219
+ * id: 'translateHindi',
220
+ * label: 'Translate to Hindi',
221
+ * prompt: 'Translate the content to Hindi language.'
222
+ * },
223
+ * {
224
+ * id: 'translateArabic',
225
+ * label: 'Translate to Arabic',
226
+ * prompt: 'Translate the content to Arabic language.'
227
+ * }
228
+ * ]
229
+ * } ]
230
+ * ```
231
+ */
232
+ commands?: Array<GroupDefinition>;
233
+ /**
234
+ * A list of additional AI commands groups definitions that will extend
235
+ * {@link module:ai/aiassistant~AIAssistantConfig#commands default commands}.
236
+ *
237
+ * You can define new AI commands groups or add new AI commands to existing groups. If you add AI commands to an existing group,
238
+ * you do not need to specify `groupLabel` property. Use the (optional) `order` property to control the position of new groups
239
+ * and commands.
240
+ *
241
+ * An example configuration:
242
+ *
243
+ * ```json
244
+ * {
245
+ * aiAssistant: {
246
+ * extraCommandGroups: [
247
+ * // Add an AI command to an existing group:
248
+ * {
249
+ * groupId: 'changeTone',
250
+ * commands: [
251
+ * {
252
+ * id: 'sad',
253
+ * label: 'Sad',
254
+ * prompt: 'Rewrite this text to make it sound sad and depressing.',
255
+ * // You can specify the position of this command among existing ones. Commands use zero-based numbering.
256
+ * order: 2
257
+ * }
258
+ * ]
259
+ * },
260
+ * // Create a new AI commands group:
261
+ * {
262
+ * groupId: 'transformations',
263
+ * groupLabel: 'Transformations',
264
+ * // You can specify the position of this group among existing ones. Groups use zero-based numbering.
265
+ * order: 3,
266
+ * commands: [
267
+ * {
268
+ * id: 'addEmojis',
269
+ * label: 'Add emojis',
270
+ * prompt: 'Analyze each sentence of this text. After each sentence add an emoji that summarizes the sentence.'
271
+ * },
272
+ * // ...
273
+ * ]
274
+ * },
275
+ * ],
276
+ * // ...
277
+ * }
278
+ * }
279
+ * ```
280
+ */
281
+ extraCommandGroups?: Array<GroupDefinition>;
282
+ /**
283
+ * A list of ids of AI commands to be removed.
284
+ *
285
+ * Learn more about {@link module:ai/aiassistant~CommandDefinition command definition and its id}.
286
+ *
287
+ * An example configuration:
288
+ *
289
+ * ```json
290
+ * {
291
+ * aiAssistant: {
292
+ * removeCommands: [
293
+ * 'improveWriting',
294
+ * // ...
295
+ * ],
296
+ * // ...
297
+ * }
298
+ * }
299
+ * ```
300
+ */
301
+ removeCommands?: Array<string>;
302
+ /**
303
+ * An additional CSS class name (or names) added to the AI assistant content area (model response area).
304
+ *
305
+ * Because the content area is usually detached from the flow of the document, this configuration
306
+ * allows for better integration with application's stylesheets and improves the consistency of content
307
+ * styles.
308
+ */
309
+ contentAreaCssClass?: string;
310
+ /**
311
+ * The AI assistant feature will be disabled if the document selection includes any of these elements.
312
+ *
313
+ * Use this property if AI assistant does not work properly with your custom features.
314
+ *
315
+ * Currently, by default, AI assistant is disabled for following model elements:
316
+ *
317
+ * * Media embed (`'media'`) -- does not display in response area,
318
+ * * HTML embed (`'rawHtml'`) -- sometimes does not display in response area, security uncertainty,
319
+ * * Table of contents (`'tableOfContents'`) -- does not display properly in response area, long processing time.
320
+ *
321
+ * You can set this list to include more model elements or clear it to enable the above features.
322
+ *
323
+ * Note, that all or some of these features may become enabled in the future.
324
+ *
325
+ * @default [ 'media', 'rawHtml', 'tableOfContents' ]
326
+ */
327
+ disabledElements?: Array<string>;
328
+ }
329
+ export type GroupDefinition = {
330
+ /**
331
+ * The unique identifier of the group. It can be referenced while extending existing groups
332
+ * using {@link module:ai/aiassistant~AIAssistantConfig#extraCommandGroups}.
333
+ */
334
+ groupId: string;
335
+ /**
336
+ * The human-readable label of the group.
337
+ */
338
+ groupLabel?: string;
339
+ /**
340
+ * The array of command definitions that belong to the group.
341
+ */
342
+ commands: Array<CommandDefinition>;
343
+ /**
344
+ * The order of the group on the list. The lower the number, the higher the group is displayed on the list.
345
+ * If not specified, the position of this group will be determined by the order of
346
+ * {@link module:ai/aiassistant~AIAssistantConfig#commands configuration}.
347
+ *
348
+ * If a new group is added without `order` property, it will be added at the end.
349
+ *
350
+ * The order uses zero-based numbering (the first group's order is `0`).
351
+ */
352
+ order?: number;
353
+ };
354
+ export type CommandDefinition = {
355
+ /**
356
+ * The unique identifier of the command. It can be referenced while removing commands. See
357
+ * {@link module:ai/aiassistant~AIAssistantConfig#removeCommands} to learn more.
358
+ */
359
+ id: string;
360
+ /**
361
+ * The human-readable label of the command.
362
+ */
363
+ label: string;
364
+ /**
365
+ * The instruction that will be passed to the AI model.
366
+ *
367
+ * It is wrapped in a "full prompt template" for better results.
368
+ */
369
+ prompt: string;
370
+ /**
371
+ * By default, all commands require a selection for the assistant to work on. If the selection is collapsed,
372
+ * it automatically expands to the nearest block boundaries to provide the AI context.
373
+ *
374
+ * Setting this to `false` allows the command to work on a collapsed selection and prevent selection expansion.
375
+ * This is helpful, for instance, for commands that generate content from scratch.
376
+ *
377
+ * **Note**: If not specified, the default is `true`.
378
+ */
379
+ requiresContent?: boolean;
380
+ /**
381
+ * The order of the command on the list. The lower the number, the higher the command is displayed on the list.
382
+ * If not specified, the position of this command will be determined by the order of
383
+ * {@link module:ai/aiassistant~AIAssistantConfig#commands configuration}.
384
+ *
385
+ * If a new command is added without `order` property, it will be added at the end of the group.
386
+ *
387
+ * The order uses zero-based numbering (the first command's order is `0`).
388
+ */
389
+ order?: number;
390
+ };
@@ -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/aiassistantediting
11
+ */
12
+ import { Plugin } from 'ckeditor5/src/core.js';
13
+ import type { Position } from 'ckeditor5/src/engine.js';
14
+ /**
15
+ * The AI assistant editing plugin.
16
+ */
17
+ export default class AIAssistantEditing extends Plugin {
18
+ /**
19
+ * @inheritDoc
20
+ */
21
+ static get pluginName(): "AIAssistantEditing";
22
+ /**
23
+ * @inheritDoc
24
+ */
25
+ init(): void;
26
+ /**
27
+ * Displays a fake visual selection.
28
+ *
29
+ * This adds a 'ai-ui-candidate' (for the commands dropdown) or 'ai-ui' (for the assistant dialog)
30
+ * marker into the document that is rendered as a highlight on selected text fragment.
31
+ */
32
+ showFakeVisualSelection(isCandidate?: boolean): void;
33
+ /**
34
+ * Removes a fake visual selection.
35
+ *
36
+ * This clears a 'ai-ui-candidate' (for the commands dropdown) or 'ai-ui' (for the assistant dialog)
37
+ * marker from the document.
38
+ */
39
+ hideFakeVisualSelection(isCandidate?: boolean): void;
40
+ /**
41
+ * Converts the HTML string into the model fragment and inserts it at the specified position.
42
+ *
43
+ * If a position is not provided, the insertion will replace the visual selection marker.
44
+ */
45
+ insertContent(content: string, position?: Position): void;
46
+ /**
47
+ * Converts the HTML string into the model fragment and inserts it below the visual selection marker.
48
+ */
49
+ insertContentBelow(content: string): void;
50
+ }
@@ -0,0 +1,57 @@
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/aiassistantui
11
+ * @publicApi
12
+ */
13
+ import { Plugin, type Editor } from 'ckeditor5/src/core.js';
14
+ import { Dialog } from 'ckeditor5/src/ui.js';
15
+ import AIAssistantEditing from './aiassistantediting.js';
16
+ import AIAdapter from './adapters/aiadapter.js';
17
+ import '../theme/ai.css';
18
+ import '../theme/ai-dropdown.css';
19
+ import '../theme/ai-form.css';
20
+ import { ClipboardMarkersUtils } from 'ckeditor5/src/clipboard.js';
21
+ /**
22
+ * The UI plugin of the AI assistant.
23
+ */
24
+ export default class AIAssistantUI extends Plugin {
25
+ /**
26
+ * @inheritDoc
27
+ */
28
+ static get pluginName(): "AIAssistantUI";
29
+ /**
30
+ * @inheritDoc
31
+ */
32
+ static get requires(): readonly [typeof ClipboardMarkersUtils, typeof AIAssistantEditing, typeof AIAdapter, typeof Dialog];
33
+ /**
34
+ * @inheritDoc
35
+ */
36
+ constructor(editor: Editor);
37
+ /**
38
+ * @inheritDoc
39
+ */
40
+ init(): void;
41
+ /**
42
+ * @inheritDoc
43
+ */
44
+ afterInit(): void;
45
+ /**
46
+ * Initializes the AI Assistant main view and displays it in a dialog, based on the selection. Also, shows fake selection marker.
47
+ *
48
+ * @param query The initial query. If set, the AI assistant will automatically submit given query to the AI service.
49
+ * @param label Label to be displayed in the AI assistant query input field while the AI assistant processes the initial query.
50
+ * @param actionId The id of the executed action. It can be used in extended and custom adapters to customize the request.
51
+ */
52
+ showUI(query?: string, label?: string, actionId?: string): void;
53
+ /**
54
+ * Hides the AI dialog.
55
+ */
56
+ hideUI(): void;
57
+ }