@widgetic/editor 4.1.13 → 4.1.14

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.
@@ -0,0 +1,443 @@
1
+ import { describeFailure } from './compositionEditorController.js';
2
+ import { KNOWLEDGE_TITLE_MAX_LENGTH } from './knowledgeDocuments.js';
3
+ const DEFAULT_POLL_DELAY_MS = 4_000;
4
+ const DEFAULT_MAX_POLLS = 15;
5
+ const DEFAULT_REMOVAL_CONFIRMATION_MS = 6_000;
6
+ /** More problems than this would push the list off the screen: the rest are summed up in one line. */
7
+ const MAX_NOTICES = 4;
8
+ /** The page's own clock. */
9
+ const PAGE_TIMERS = {
10
+ set: (callback, delayMs) => setTimeout(callback, delayMs),
11
+ clear: (handle) => clearTimeout(handle)
12
+ };
13
+ const INITIAL_STATE = {
14
+ documents: [],
15
+ totals: null,
16
+ loadFailure: null,
17
+ sending: null,
18
+ removing: [],
19
+ confirmingRemoval: null,
20
+ notices: []
21
+ };
22
+ /**
23
+ * The sentence for a failure of a call about the knowledge base. `about` names what was being added (a file's name, a
24
+ * document's title), for the sentences that say which one it was. The API's own sentence is kept only when the editor has
25
+ * none of its own for the code: those are written for the owner and say what to do, but only in English.
26
+ */
27
+ export function describeKnowledgeFailure(failure, about = {}) {
28
+ const name = about.name?.trim() || '';
29
+ switch (failure.code) {
30
+ case 'KNOWLEDGE_TITLE_REQUIRED':
31
+ return { messageKey: 'editor.knowledgeError.titleRequired' };
32
+ case 'KNOWLEDGE_TITLE_TOO_LONG':
33
+ return {
34
+ messageKey: 'editor.knowledgeError.titleTooLong',
35
+ messageValues: { max: KNOWLEDGE_TITLE_MAX_LENGTH }
36
+ };
37
+ case 'KNOWLEDGE_TEXT_REQUIRED':
38
+ return { messageKey: 'editor.knowledgeError.textRequired' };
39
+ case 'KNOWLEDGE_TEXT_TOO_LONG':
40
+ return { messageKey: 'editor.knowledgeError.textTooLong' };
41
+ case 'KNOWLEDGE_FILE_REQUIRED':
42
+ return { messageKey: 'editor.knowledgeError.fileRequired' };
43
+ case 'KNOWLEDGE_FILE_TOO_LARGE':
44
+ return { messageKey: 'editor.knowledgeError.fileTooLarge', messageValues: { name } };
45
+ case 'KNOWLEDGE_FILE_TYPE_UNSUPPORTED':
46
+ return { messageKey: 'editor.knowledgeError.fileTypeUnsupported', messageValues: { name } };
47
+ case 'KNOWLEDGE_FILE_UNREADABLE':
48
+ return { messageKey: 'editor.knowledgeError.fileUnreadable', messageValues: { name } };
49
+ case 'KNOWLEDGE_FILE_NO_TEXT':
50
+ return { messageKey: 'editor.knowledgeError.fileNoText', messageValues: { name } };
51
+ case 'KNOWLEDGE_DUPLICATE_DOCUMENT':
52
+ return { messageKey: 'editor.knowledgeError.duplicate', messageValues: { name } };
53
+ case 'KNOWLEDGE_LIMIT_DOCUMENTS':
54
+ return { messageKey: 'editor.knowledgeError.limitDocuments' };
55
+ case 'KNOWLEDGE_LIMIT_TOTAL_TEXT':
56
+ return { messageKey: 'editor.knowledgeError.limitText' };
57
+ case 'KNOWLEDGE_UNAVAILABLE':
58
+ case 'KNOWLEDGE_BUSY':
59
+ case 'KNOWLEDGE_NOT_COMPLETED':
60
+ return { messageKey: 'editor.knowledgeError.tryLater' };
61
+ default:
62
+ break;
63
+ }
64
+ if (failure.sessionEnded)
65
+ return { messageKey: 'editor.failure.sessionEnded' };
66
+ if (failure.status === 403)
67
+ return { messageKey: 'editor.failure.noAccess' };
68
+ if (failure.status === 404)
69
+ return { messageKey: 'editor.failure.compositionNotFound' };
70
+ if (failure.status === 429)
71
+ return { messageKey: 'editor.knowledgeError.tooManyAdds' };
72
+ if (failure.code === 'NETWORK' || failure.code === 'TIMEOUT') {
73
+ return { messageKey: 'editor.knowledgeError.connection' };
74
+ }
75
+ // A server that failed has said nothing the person can use ("Internal server error"): the editor's own words.
76
+ if (failure.status >= 500)
77
+ return { messageKey: 'editor.knowledgeError.generic' };
78
+ // What the API said is shown as it came, as everywhere in the editor; the editor's own words only when it said nothing.
79
+ const apiSentence = failure.code === 'UNKNOWN' ? '' : failure.message.trim();
80
+ return apiSentence
81
+ ? { messageKey: 'editor.knowledgeError.generic', verbatim: apiSentence }
82
+ : { messageKey: 'editor.knowledgeError.generic' };
83
+ }
84
+ /**
85
+ * True when what failed would fail again for the next file in the batch, so the rest are not sent: the session is over, the
86
+ * person may not touch this composition, it is gone, the adds are being limited, the connection is down, the server failed,
87
+ * or the knowledge base has no room for one more document.
88
+ */
89
+ function stopsTheBatch(failure) {
90
+ return (failure.sessionEnded ||
91
+ failure.status === 403 ||
92
+ failure.status === 404 ||
93
+ failure.status === 429 ||
94
+ failure.retryable ||
95
+ failure.code === 'KNOWLEDGE_LIMIT_DOCUMENTS');
96
+ }
97
+ /** True for a request that was cancelled on purpose (the panel went away): nothing to tell anybody. */
98
+ function wasCancelled(failure) {
99
+ return failure.code === 'ABORTED';
100
+ }
101
+ export class KnowledgeDocumentsPanel {
102
+ client;
103
+ pollDelayMs;
104
+ maxPolls;
105
+ removalConfirmationMs;
106
+ timers;
107
+ listeners = new Set();
108
+ /** Cancels every request that is on its way when the panel goes away. */
109
+ cancellation = new AbortController();
110
+ state;
111
+ started = false;
112
+ destroyed = false;
113
+ loading = null;
114
+ pollsSoFar = 0;
115
+ latestRefresh = 0;
116
+ pollHandle = null;
117
+ confirmationHandle = null;
118
+ nextNoticeId = 1;
119
+ constructor(options) {
120
+ this.client = options.client;
121
+ this.pollDelayMs = options.pollDelayMs ?? DEFAULT_POLL_DELAY_MS;
122
+ this.maxPolls = options.maxPolls ?? DEFAULT_MAX_POLLS;
123
+ this.removalConfirmationMs = options.removalConfirmationMs ?? DEFAULT_REMOVAL_CONFIRMATION_MS;
124
+ this.timers = options.timers ?? PAGE_TIMERS;
125
+ this.state = {
126
+ ...INITIAL_STATE,
127
+ phase: this.client ? 'loading' : 'unavailable'
128
+ };
129
+ }
130
+ // --- the state, as a store ------------------------------------------------------------------------
131
+ getState() {
132
+ return this.state;
133
+ }
134
+ /** The store contract: the listener hears the state now and at every change; the returned function stops it. */
135
+ subscribe(listener) {
136
+ this.listeners.add(listener);
137
+ listener(this.state);
138
+ return () => {
139
+ this.listeners.delete(listener);
140
+ };
141
+ }
142
+ setState(changes) {
143
+ if (this.destroyed)
144
+ return;
145
+ this.state = { ...this.state, ...changes };
146
+ for (const listener of [...this.listeners])
147
+ listener(this.state);
148
+ }
149
+ // --- loading ---------------------------------------------------------------------------------------
150
+ /** Loads the list. Called once, when the panel is on the screen; calling it again does nothing. */
151
+ start() {
152
+ if (this.started || !this.client)
153
+ return this.loading ?? Promise.resolve();
154
+ this.started = true;
155
+ return this.load();
156
+ }
157
+ /** Loads the list again after it failed ("try again"). */
158
+ retry() {
159
+ if (!this.client || this.destroyed)
160
+ return Promise.resolve();
161
+ this.setState({ phase: 'loading', loadFailure: null });
162
+ return this.load();
163
+ }
164
+ load() {
165
+ if (this.loading)
166
+ return this.loading;
167
+ this.loading = this.loadList().finally(() => {
168
+ this.loading = null;
169
+ });
170
+ return this.loading;
171
+ }
172
+ async loadList() {
173
+ const client = this.client;
174
+ if (!client)
175
+ return;
176
+ try {
177
+ const listing = await client.list({ signal: this.cancellation.signal });
178
+ this.setState({
179
+ phase: 'ready',
180
+ documents: listing.documents,
181
+ totals: listing.totals,
182
+ loadFailure: null
183
+ });
184
+ this.watchDocumentsBeingRead();
185
+ }
186
+ catch (error) {
187
+ const failure = describeFailure(error);
188
+ if (wasCancelled(failure))
189
+ return;
190
+ console.warn('[KnowledgeDocuments] The list of documents could not be loaded:', error);
191
+ this.setState({ phase: 'failed', loadFailure: describeKnowledgeFailure(failure) });
192
+ }
193
+ }
194
+ /**
195
+ * Looks at the list again, without any sign of it on the screen, to bring the totals up to date after a change, or to see
196
+ * a document become ready. A failure is only logged: the list that is on the screen is still the best the panel has.
197
+ */
198
+ async refresh() {
199
+ const client = this.client;
200
+ if (!client || this.destroyed)
201
+ return;
202
+ // Answers can arrive in another order than the questions were asked: only the newest question's answer is used.
203
+ this.latestRefresh += 1;
204
+ const thisRefresh = this.latestRefresh;
205
+ try {
206
+ const listing = await client.list({ signal: this.cancellation.signal });
207
+ if (thisRefresh !== this.latestRefresh)
208
+ return;
209
+ // While something is being sent or removed the list on the screen is ahead of the API's: leave it to the end of that.
210
+ if (this.state.sending || this.state.removing.length > 0)
211
+ return;
212
+ this.setState({ documents: listing.documents, totals: listing.totals });
213
+ this.watchDocumentsBeingRead();
214
+ }
215
+ catch (error) {
216
+ if (!wasCancelled(describeFailure(error))) {
217
+ console.warn('[KnowledgeDocuments] The list of documents could not be refreshed:', error);
218
+ }
219
+ }
220
+ }
221
+ /** While a document is being read, look again every few seconds (a limited number of times), so it turns ready on its own. */
222
+ watchDocumentsBeingRead() {
223
+ this.stopWatching();
224
+ if (this.destroyed)
225
+ return;
226
+ if (!this.state.documents.some((document) => document.status === 'processing')) {
227
+ this.pollsSoFar = 0;
228
+ return;
229
+ }
230
+ if (this.pollsSoFar >= this.maxPolls) {
231
+ console.warn('[KnowledgeDocuments] A document is still being read; the panel stops looking at it');
232
+ return;
233
+ }
234
+ this.pollsSoFar += 1;
235
+ this.pollHandle = this.timers.set(() => {
236
+ this.pollHandle = null;
237
+ void this.refresh();
238
+ }, this.pollDelayMs);
239
+ }
240
+ stopWatching() {
241
+ if (this.pollHandle !== null) {
242
+ this.timers.clear(this.pollHandle);
243
+ this.pollHandle = null;
244
+ }
245
+ }
246
+ // --- adding ----------------------------------------------------------------------------------------
247
+ /** True while the panel is busy with something that must end before the next thing starts. */
248
+ isBusy() {
249
+ return this.state.sending !== null || this.state.removing.length > 0;
250
+ }
251
+ /** Sends the files one after the other (see the top of this file). Resolves when the last one is done. */
252
+ async addFiles(files) {
253
+ const client = this.client;
254
+ if (!client || this.destroyed || this.state.phase !== 'ready' || this.isBusy())
255
+ return;
256
+ const batch = files.filter((file) => file && typeof file.name === 'string');
257
+ if (batch.length === 0)
258
+ return;
259
+ this.cancelRemoval();
260
+ this.setState({ notices: [] });
261
+ const problems = [];
262
+ let notSent = 0;
263
+ for (let index = 0; index < batch.length; index += 1) {
264
+ if (this.destroyed)
265
+ return;
266
+ const file = batch[index];
267
+ this.setState({ sending: { name: file.name, position: index + 1, count: batch.length } });
268
+ try {
269
+ const document = await client.addFile({ file, fileName: file.name }, { signal: this.cancellation.signal });
270
+ if (this.destroyed)
271
+ return;
272
+ this.setState({ documents: [...this.state.documents, document] });
273
+ }
274
+ catch (error) {
275
+ const failure = describeFailure(error);
276
+ if (wasCancelled(failure))
277
+ return;
278
+ console.warn(`[KnowledgeDocuments] "${file.name}" could not be added:`, error);
279
+ problems.push(describeKnowledgeFailure(failure, { name: file.name }));
280
+ if (stopsTheBatch(failure)) {
281
+ notSent = batch.length - index - 1;
282
+ break;
283
+ }
284
+ }
285
+ }
286
+ this.finishSending(problems, notSent);
287
+ await this.refresh();
288
+ }
289
+ /**
290
+ * Adds a document made of text the person typed or pasted. Resolves `true` when it was added, so the form can close, and
291
+ * `false` when it was not (the reason is in `notices`) or the panel was busy.
292
+ */
293
+ async addText(input) {
294
+ const client = this.client;
295
+ if (!client || this.destroyed || this.state.phase !== 'ready' || this.isBusy())
296
+ return false;
297
+ const title = input.title.trim();
298
+ const text = input.text.trim();
299
+ // Said at once, without a round trip: the same two sentences the API would give for an empty title or text.
300
+ if (title === '') {
301
+ this.setState({ notices: [this.noticeFor({ messageKey: 'editor.knowledgeError.titleRequired' })] });
302
+ return false;
303
+ }
304
+ if (text === '') {
305
+ this.setState({ notices: [this.noticeFor({ messageKey: 'editor.knowledgeError.textRequired' })] });
306
+ return false;
307
+ }
308
+ this.cancelRemoval();
309
+ this.setState({ notices: [], sending: { name: title, position: 1, count: 1 } });
310
+ try {
311
+ const document = await client.addText({ title, text }, { signal: this.cancellation.signal });
312
+ if (this.destroyed)
313
+ return false;
314
+ this.setState({ documents: [...this.state.documents, document], sending: null });
315
+ await this.refresh();
316
+ return true;
317
+ }
318
+ catch (error) {
319
+ const failure = describeFailure(error);
320
+ if (wasCancelled(failure))
321
+ return false;
322
+ console.warn(`[KnowledgeDocuments] "${title}" could not be added:`, error);
323
+ this.setState({
324
+ sending: null,
325
+ notices: [this.noticeFor(describeKnowledgeFailure(failure, { name: title }))]
326
+ });
327
+ return false;
328
+ }
329
+ }
330
+ /** Ends a batch: the problems become notices (a few, and a line for the rest), and nothing is being sent any more. */
331
+ finishSending(problems, notSent) {
332
+ const notices = problems.slice(0, MAX_NOTICES).map((message) => this.noticeFor(message));
333
+ const hidden = problems.length - notices.length;
334
+ if (hidden > 0) {
335
+ notices.push(this.noticeFor({ messageKey: 'editor.knowledgeError.moreProblems', messageValues: { count: hidden } }));
336
+ }
337
+ if (notSent > 0) {
338
+ notices.push(this.noticeFor({ messageKey: 'editor.knowledgeError.notSent', messageValues: { count: notSent } }));
339
+ }
340
+ this.setState({ sending: null, notices });
341
+ }
342
+ noticeFor(message) {
343
+ const notice = { id: this.nextNoticeId, message };
344
+ this.nextNoticeId += 1;
345
+ return notice;
346
+ }
347
+ /** Takes the problems off the screen. */
348
+ dismissNotices() {
349
+ if (this.state.notices.length > 0)
350
+ this.setState({ notices: [] });
351
+ }
352
+ // --- removing --------------------------------------------------------------------------------------
353
+ /** The first press on "remove": asks the person to press it again. */
354
+ askToRemove(documentId) {
355
+ if (!this.client || this.destroyed || this.isBusy())
356
+ return;
357
+ if (!this.state.documents.some((document) => document.id === documentId))
358
+ return;
359
+ this.clearConfirmationTimer();
360
+ this.setState({ confirmingRemoval: documentId });
361
+ this.confirmationHandle = this.timers.set(() => {
362
+ this.confirmationHandle = null;
363
+ this.setState({ confirmingRemoval: null });
364
+ }, this.removalConfirmationMs);
365
+ }
366
+ /** Takes the question back (the person chose to keep the document, or went on to something else). */
367
+ cancelRemoval() {
368
+ this.clearConfirmationTimer();
369
+ if (this.state.confirmingRemoval !== null)
370
+ this.setState({ confirmingRemoval: null });
371
+ }
372
+ clearConfirmationTimer() {
373
+ if (this.confirmationHandle !== null) {
374
+ this.timers.clear(this.confirmationHandle);
375
+ this.confirmationHandle = null;
376
+ }
377
+ }
378
+ /** The second press: takes the document out. Does nothing unless the first press came for this very document. */
379
+ async confirmRemoval(documentId) {
380
+ const client = this.client;
381
+ if (!client || this.destroyed || this.state.confirmingRemoval !== documentId)
382
+ return;
383
+ if (this.state.removing.includes(documentId) || this.state.sending)
384
+ return;
385
+ this.clearConfirmationTimer();
386
+ this.setState({
387
+ confirmingRemoval: null,
388
+ notices: [],
389
+ removing: [...this.state.removing, documentId]
390
+ });
391
+ try {
392
+ await client.remove(documentId, { signal: this.cancellation.signal });
393
+ if (this.destroyed)
394
+ return;
395
+ this.dropDocument(documentId);
396
+ }
397
+ catch (error) {
398
+ const failure = describeFailure(error);
399
+ if (wasCancelled(failure))
400
+ return;
401
+ if (failure.code === 'KNOWLEDGE_DOCUMENT_NOT_FOUND') {
402
+ // Already gone (removed in another tab): the list was wrong, not the person. Show it as it is.
403
+ this.dropDocument(documentId);
404
+ }
405
+ else {
406
+ console.warn('[KnowledgeDocuments] A document could not be removed:', error);
407
+ this.setState({ notices: [this.noticeFor(describeKnowledgeFailure(failure))] });
408
+ }
409
+ }
410
+ finally {
411
+ this.setState({ removing: this.state.removing.filter((id) => id !== documentId) });
412
+ }
413
+ await this.refresh();
414
+ }
415
+ /** Takes a document off the list and its share off the totals, so the screen is right before the API is asked again. */
416
+ dropDocument(documentId) {
417
+ const gone = this.state.documents.find((document) => document.id === documentId);
418
+ if (!gone)
419
+ return;
420
+ const totals = this.state.totals;
421
+ this.setState({
422
+ documents: this.state.documents.filter((document) => document.id !== documentId),
423
+ totals: totals
424
+ ? {
425
+ ...totals,
426
+ documents: Math.max(0, totals.documents - 1),
427
+ characters: Math.max(0, totals.characters - gone.charCount)
428
+ }
429
+ : totals
430
+ });
431
+ }
432
+ // --- going away ------------------------------------------------------------------------------------
433
+ /** Cancels what is on its way and stops every timer. The panel says nothing more after this. */
434
+ destroy() {
435
+ if (this.destroyed)
436
+ return;
437
+ this.destroyed = true;
438
+ this.cancellation.abort();
439
+ this.stopWatching();
440
+ this.clearConfirmationTimer();
441
+ this.listeners.clear();
442
+ }
443
+ }
@@ -192,6 +192,49 @@ export declare const EDITOR_CATALOGS: {
192
192
  readonly 'editor.dateField.dayLabel': "Day input";
193
193
  readonly 'editor.dateField.monthLabel': "Month input";
194
194
  readonly 'editor.dateField.yearLabel': "Year input";
195
+ readonly 'editor.knowledge.loading': "Loading documents…";
196
+ readonly 'editor.knowledge.unavailable': "Documents can be added when you edit a composition made with this widget.";
197
+ readonly 'editor.knowledge.retry': "Try again";
198
+ readonly 'editor.knowledge.empty': "No documents yet. The AI can only answer from the documents you add.";
199
+ readonly 'editor.knowledge.listLabel': "Documents";
200
+ readonly 'editor.knowledge.characters': "{count, plural, one {# character} other {# characters}}";
201
+ readonly 'editor.knowledge.processing': "Reading the document…";
202
+ readonly 'editor.knowledge.removeLabel': "Remove {title}";
203
+ readonly 'editor.knowledge.removeConfirm': "Remove";
204
+ readonly 'editor.knowledge.keep': "Keep";
205
+ readonly 'editor.knowledge.removing': "Removing…";
206
+ readonly 'editor.knowledge.sending': "Reading {name}…";
207
+ readonly 'editor.knowledge.sendingOf': "Reading {name} ({position} of {count})…";
208
+ readonly 'editor.knowledge.addFiles': "Add files…";
209
+ readonly 'editor.knowledge.dropHint': "or drop them here";
210
+ readonly 'editor.knowledge.addText': "Paste text…";
211
+ readonly 'editor.knowledge.documentsUsed': "Documents: {documents} of {maxDocuments}";
212
+ readonly 'editor.knowledge.textUsed': "Text: {characters} of {maxCharacters} characters";
213
+ readonly 'editor.knowledge.titleLabel': "Title";
214
+ readonly 'editor.knowledge.titlePlaceholder': "For example: Shipping policy";
215
+ readonly 'editor.knowledge.textLabel': "Text";
216
+ readonly 'editor.knowledge.textPlaceholder': "Paste the text the answers should be written from";
217
+ readonly 'editor.knowledge.addDocument': "Add document";
218
+ readonly 'editor.knowledge.cancel': "Cancel";
219
+ readonly 'editor.knowledge.dismiss': "Dismiss";
220
+ readonly 'editor.knowledgeError.titleRequired': "Give the document a title.";
221
+ readonly 'editor.knowledgeError.titleTooLong': "Titles can be up to {max} characters.";
222
+ readonly 'editor.knowledgeError.textRequired': "Paste some text first.";
223
+ readonly 'editor.knowledgeError.textTooLong': "This text is too long for one document. Split it into several documents.";
224
+ readonly 'editor.knowledgeError.fileRequired': "Choose a file first.";
225
+ readonly 'editor.knowledgeError.fileTooLarge': "{name} is too large. Try a smaller file, or split it into several.";
226
+ readonly 'editor.knowledgeError.fileTypeUnsupported': "{name} is not a kind of file that can be added. PDF files are not read yet: use a text, Markdown or CSV file, a picture of the page, or paste the text.";
227
+ readonly 'editor.knowledgeError.fileUnreadable': "{name} could not be read. It may be damaged or protected with a password.";
228
+ readonly 'editor.knowledgeError.fileNoText': "{name} has no text that can be read. If it is a scan, add its pages as pictures.";
229
+ readonly 'editor.knowledgeError.duplicate': "The text of {name} is already in the knowledge base.";
230
+ readonly 'editor.knowledgeError.limitDocuments': "The knowledge base is full. Remove a document to add another.";
231
+ readonly 'editor.knowledgeError.limitText': "There is not enough room left for this much text. Remove a document, or add a shorter one.";
232
+ readonly 'editor.knowledgeError.tryLater': "Documents cannot be added right now. Try again in a moment.";
233
+ readonly 'editor.knowledgeError.tooManyAdds': "Too many documents were added in a short time. Wait a few minutes and try again.";
234
+ readonly 'editor.knowledgeError.connection': "Could not reach Widgetic. Check the connection and try again.";
235
+ readonly 'editor.knowledgeError.generic': "Something went wrong. Try again in a moment.";
236
+ readonly 'editor.knowledgeError.moreProblems': "{count, plural, one {# more file had a problem.} other {# more files had a problem.}}";
237
+ readonly 'editor.knowledgeError.notSent': "{count, plural, one {# file was not sent.} other {# files were not sent.}}";
195
238
  readonly 'editor.dropdown.select': "Select an option";
196
239
  readonly 'editor.switch.off': "Off";
197
240
  readonly 'editor.switch.on': "On";
@@ -247,6 +247,62 @@ export declare const EDITOR_MESSAGES: {
247
247
  readonly 'editor.dateField.dayLabel': "Day input";
248
248
  readonly 'editor.dateField.monthLabel': "Month input";
249
249
  readonly 'editor.dateField.yearLabel': "Year input";
250
+ readonly 'editor.knowledge.loading': "Loading documents…";
251
+ /** Where there is no composition to put documents in (the widget creator): the panel says so instead of staying empty. */
252
+ readonly 'editor.knowledge.unavailable': "Documents can be added when you edit a composition made with this widget.";
253
+ readonly 'editor.knowledge.retry': "Try again";
254
+ readonly 'editor.knowledge.empty': "No documents yet. The AI can only answer from the documents you add.";
255
+ /** The name a screen reader gives the list of documents. */
256
+ readonly 'editor.knowledge.listLabel': "Documents";
257
+ /** Beside a document: how much text it holds. */
258
+ readonly 'editor.knowledge.characters': "{count, plural, one {# character} other {# characters}}";
259
+ /** Beside a document that the AI cannot use yet: its text is still being read. */
260
+ readonly 'editor.knowledge.processing': "Reading the document…";
261
+ /** The name a screen reader gives the button that removes a document; `{title}` is the document's. */
262
+ readonly 'editor.knowledge.removeLabel': "Remove {title}";
263
+ /** The two buttons that replace it after the first press: take the document out, or keep it. */
264
+ readonly 'editor.knowledge.removeConfirm': "Remove";
265
+ readonly 'editor.knowledge.keep': "Keep";
266
+ readonly 'editor.knowledge.removing': "Removing…";
267
+ /** While a file is read: `{name}` is its name, and for several files `{position}` of `{count}` is how far along they are. */
268
+ readonly 'editor.knowledge.sending': "Reading {name}…";
269
+ readonly 'editor.knowledge.sendingOf': "Reading {name} ({position} of {count})…";
270
+ readonly 'editor.knowledge.addFiles': "Add files…";
271
+ /** Beside the button that adds files: files can also be dropped on the panel. */
272
+ readonly 'editor.knowledge.dropHint': "or drop them here";
273
+ readonly 'editor.knowledge.addText': "Paste text…";
274
+ /** How much of the knowledge base is used, in two short lines. */
275
+ readonly 'editor.knowledge.documentsUsed': "Documents: {documents} of {maxDocuments}";
276
+ readonly 'editor.knowledge.textUsed': "Text: {characters} of {maxCharacters} characters";
277
+ /** The form for text that is typed or pasted instead of sent as a file. */
278
+ readonly 'editor.knowledge.titleLabel': "Title";
279
+ readonly 'editor.knowledge.titlePlaceholder': "For example: Shipping policy";
280
+ readonly 'editor.knowledge.textLabel': "Text";
281
+ readonly 'editor.knowledge.textPlaceholder': "Paste the text the answers should be written from";
282
+ readonly 'editor.knowledge.addDocument': "Add document";
283
+ readonly 'editor.knowledge.cancel': "Cancel";
284
+ /** The name a screen reader gives the button that closes the list of problems. */
285
+ readonly 'editor.knowledge.dismiss': "Dismiss";
286
+ /** What went wrong, and what to do about it. `{name}` is the file's name, or the title of the text. */
287
+ readonly 'editor.knowledgeError.titleRequired': "Give the document a title.";
288
+ readonly 'editor.knowledgeError.titleTooLong': "Titles can be up to {max} characters.";
289
+ readonly 'editor.knowledgeError.textRequired': "Paste some text first.";
290
+ readonly 'editor.knowledgeError.textTooLong': "This text is too long for one document. Split it into several documents.";
291
+ readonly 'editor.knowledgeError.fileRequired': "Choose a file first.";
292
+ readonly 'editor.knowledgeError.fileTooLarge': "{name} is too large. Try a smaller file, or split it into several.";
293
+ readonly 'editor.knowledgeError.fileTypeUnsupported': "{name} is not a kind of file that can be added. PDF files are not read yet: use a text, Markdown or CSV file, a picture of the page, or paste the text.";
294
+ readonly 'editor.knowledgeError.fileUnreadable': "{name} could not be read. It may be damaged or protected with a password.";
295
+ readonly 'editor.knowledgeError.fileNoText': "{name} has no text that can be read. If it is a scan, add its pages as pictures.";
296
+ readonly 'editor.knowledgeError.duplicate': "The text of {name} is already in the knowledge base.";
297
+ readonly 'editor.knowledgeError.limitDocuments': "The knowledge base is full. Remove a document to add another.";
298
+ readonly 'editor.knowledgeError.limitText': "There is not enough room left for this much text. Remove a document, or add a shorter one.";
299
+ readonly 'editor.knowledgeError.tryLater': "Documents cannot be added right now. Try again in a moment.";
300
+ readonly 'editor.knowledgeError.tooManyAdds': "Too many documents were added in a short time. Wait a few minutes and try again.";
301
+ readonly 'editor.knowledgeError.connection': "Could not reach Widgetic. Check the connection and try again.";
302
+ readonly 'editor.knowledgeError.generic': "Something went wrong. Try again in a moment.";
303
+ /** After a batch of files: how many more had a problem than are listed, and how many were not even sent. */
304
+ readonly 'editor.knowledgeError.moreProblems': "{count, plural, one {# more file had a problem.} other {# more files had a problem.}}";
305
+ readonly 'editor.knowledgeError.notSent': "{count, plural, one {# file was not sent.} other {# files were not sent.}}";
250
306
  readonly 'editor.dropdown.select': "Select an option";
251
307
  readonly 'editor.switch.off': "Off";
252
308
  readonly 'editor.switch.on': "On";
@@ -260,6 +260,63 @@ export const EDITOR_MESSAGES = {
260
260
  'editor.dateField.dayLabel': 'Day input',
261
261
  'editor.dateField.monthLabel': 'Month input',
262
262
  'editor.dateField.yearLabel': 'Year input',
263
+ // ===== The Documents panel of AI Answers: what the widget's AI writes its answers from =====
264
+ 'editor.knowledge.loading': 'Loading documents…',
265
+ /** Where there is no composition to put documents in (the widget creator): the panel says so instead of staying empty. */
266
+ 'editor.knowledge.unavailable': 'Documents can be added when you edit a composition made with this widget.',
267
+ 'editor.knowledge.retry': 'Try again',
268
+ 'editor.knowledge.empty': 'No documents yet. The AI can only answer from the documents you add.',
269
+ /** The name a screen reader gives the list of documents. */
270
+ 'editor.knowledge.listLabel': 'Documents',
271
+ /** Beside a document: how much text it holds. */
272
+ 'editor.knowledge.characters': '{count, plural, one {# character} other {# characters}}',
273
+ /** Beside a document that the AI cannot use yet: its text is still being read. */
274
+ 'editor.knowledge.processing': 'Reading the document…',
275
+ /** The name a screen reader gives the button that removes a document; `{title}` is the document's. */
276
+ 'editor.knowledge.removeLabel': 'Remove {title}',
277
+ /** The two buttons that replace it after the first press: take the document out, or keep it. */
278
+ 'editor.knowledge.removeConfirm': 'Remove',
279
+ 'editor.knowledge.keep': 'Keep',
280
+ 'editor.knowledge.removing': 'Removing…',
281
+ /** While a file is read: `{name}` is its name, and for several files `{position}` of `{count}` is how far along they are. */
282
+ 'editor.knowledge.sending': 'Reading {name}…',
283
+ 'editor.knowledge.sendingOf': 'Reading {name} ({position} of {count})…',
284
+ 'editor.knowledge.addFiles': 'Add files…',
285
+ /** Beside the button that adds files: files can also be dropped on the panel. */
286
+ 'editor.knowledge.dropHint': 'or drop them here',
287
+ 'editor.knowledge.addText': 'Paste text…',
288
+ /** How much of the knowledge base is used, in two short lines. */
289
+ 'editor.knowledge.documentsUsed': 'Documents: {documents} of {maxDocuments}',
290
+ 'editor.knowledge.textUsed': 'Text: {characters} of {maxCharacters} characters',
291
+ /** The form for text that is typed or pasted instead of sent as a file. */
292
+ 'editor.knowledge.titleLabel': 'Title',
293
+ 'editor.knowledge.titlePlaceholder': 'For example: Shipping policy',
294
+ 'editor.knowledge.textLabel': 'Text',
295
+ 'editor.knowledge.textPlaceholder': 'Paste the text the answers should be written from',
296
+ 'editor.knowledge.addDocument': 'Add document',
297
+ 'editor.knowledge.cancel': 'Cancel',
298
+ /** The name a screen reader gives the button that closes the list of problems. */
299
+ 'editor.knowledge.dismiss': 'Dismiss',
300
+ /** What went wrong, and what to do about it. `{name}` is the file's name, or the title of the text. */
301
+ 'editor.knowledgeError.titleRequired': 'Give the document a title.',
302
+ 'editor.knowledgeError.titleTooLong': 'Titles can be up to {max} characters.',
303
+ 'editor.knowledgeError.textRequired': 'Paste some text first.',
304
+ 'editor.knowledgeError.textTooLong': 'This text is too long for one document. Split it into several documents.',
305
+ 'editor.knowledgeError.fileRequired': 'Choose a file first.',
306
+ 'editor.knowledgeError.fileTooLarge': '{name} is too large. Try a smaller file, or split it into several.',
307
+ 'editor.knowledgeError.fileTypeUnsupported': '{name} is not a kind of file that can be added. PDF files are not read yet: use a text, Markdown or CSV file, a picture of the page, or paste the text.',
308
+ 'editor.knowledgeError.fileUnreadable': '{name} could not be read. It may be damaged or protected with a password.',
309
+ 'editor.knowledgeError.fileNoText': '{name} has no text that can be read. If it is a scan, add its pages as pictures.',
310
+ 'editor.knowledgeError.duplicate': 'The text of {name} is already in the knowledge base.',
311
+ 'editor.knowledgeError.limitDocuments': 'The knowledge base is full. Remove a document to add another.',
312
+ 'editor.knowledgeError.limitText': 'There is not enough room left for this much text. Remove a document, or add a shorter one.',
313
+ 'editor.knowledgeError.tryLater': 'Documents cannot be added right now. Try again in a moment.',
314
+ 'editor.knowledgeError.tooManyAdds': 'Too many documents were added in a short time. Wait a few minutes and try again.',
315
+ 'editor.knowledgeError.connection': 'Could not reach Widgetic. Check the connection and try again.',
316
+ 'editor.knowledgeError.generic': 'Something went wrong. Try again in a moment.',
317
+ /** After a batch of files: how many more had a problem than are listed, and how many were not even sent. */
318
+ 'editor.knowledgeError.moreProblems': '{count, plural, one {# more file had a problem.} other {# more files had a problem.}}',
319
+ 'editor.knowledgeError.notSent': '{count, plural, one {# file was not sent.} other {# files were not sent.}}',
263
320
  // ===== Small controls =====
264
321
  'editor.dropdown.select': 'Select an option',
265
322
  'editor.switch.off': 'Off',