@widgetic/chat 0.1.45 → 0.1.47
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/README.md +148 -20
- package/dist/components/AttachmentDisplay.svelte +22 -130
- package/dist/components/AttachmentPreviewDialog.svelte +428 -0
- package/dist/components/AttachmentPreviewDialog.svelte.d.ts +14 -0
- package/dist/components/Chat.svelte +509 -94
- package/dist/components/Chat.svelte.d.ts +15 -2
- package/dist/components/ChatComposer.svelte +63 -69
- package/dist/components/ChatComposer.svelte.d.ts +8 -3
- package/dist/components/ChatDropOverlay.svelte +58 -0
- package/dist/components/ChatDropOverlay.svelte.d.ts +8 -0
- package/dist/components/ChatMessages.svelte +322 -98
- package/dist/components/ChatMessages.svelte.d.ts +11 -2
- package/dist/components/ComposerAttachmentsTray.svelte +144 -56
- package/dist/components/ComposerAttachmentsTray.svelte.d.ts +11 -1
- package/dist/components/FileGlyphIcon.svelte +34 -0
- package/dist/components/FileGlyphIcon.svelte.d.ts +8 -0
- package/dist/components/RestoreCheckpointDialog.svelte +66 -0
- package/dist/components/RestoreCheckpointDialog.svelte.d.ts +11 -0
- package/dist/components/SentAttachments.svelte +118 -0
- package/dist/components/SentAttachments.svelte.d.ts +12 -0
- package/dist/components/agent/AgentTurn.svelte +17 -2
- package/dist/components/agent/CodeCard.svelte +9 -3
- package/dist/i18n/messages.d.ts +43 -3
- package/dist/i18n/messages.js +49 -5
- package/dist/services/index.d.ts +4 -2
- package/dist/services/index.js +2 -1
- package/dist/services/limitRefusal.d.ts +42 -0
- package/dist/services/limitRefusal.js +60 -0
- package/dist/services/sketchAssistantClient.d.ts +11 -3
- package/dist/services/sketchAssistantClient.js +37 -10
- package/dist/services/sketchAssistantErrors.d.ts +16 -1
- package/dist/services/sketchAssistantErrors.js +25 -4
- package/dist/services/sketchAssistantOrchestrator.d.ts +7 -1
- package/dist/services/sketchAssistantOrchestrator.js +2 -2
- package/dist/types/attachment.d.ts +11 -0
- package/dist/utils/agentTurn.d.ts +32 -1
- package/dist/utils/agentTurn.js +46 -3
- package/dist/utils/attachmentDuplicates.d.ts +48 -0
- package/dist/utils/attachmentDuplicates.js +70 -0
- package/dist/utils/attachmentPolicy.d.ts +88 -0
- package/dist/utils/attachmentPolicy.js +135 -0
- package/dist/utils/attachmentPreview.d.ts +146 -0
- package/dist/utils/attachmentPreview.js +224 -0
- package/dist/utils/attachmentTray.d.ts +35 -0
- package/dist/utils/attachmentTray.js +27 -0
- package/dist/utils/chatFileDrag.d.ts +39 -0
- package/dist/utils/chatFileDrag.js +29 -0
- package/dist/utils/composerPreview.d.ts +33 -0
- package/dist/utils/composerPreview.js +31 -0
- package/dist/utils/generationArchiveStore.d.ts +5 -1
- package/dist/utils/generationArchiveStore.js +9 -4
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/limitFailureLine.d.ts +20 -0
- package/dist/utils/limitFailureLine.js +40 -0
- package/dist/utils/panelListPadding.d.ts +20 -0
- package/dist/utils/panelListPadding.js +31 -0
- package/dist/utils/pasteInsertion.d.ts +43 -0
- package/dist/utils/pasteInsertion.js +94 -0
- package/dist/utils/pastedContent.d.ts +13 -0
- package/dist/utils/pastedContent.js +18 -1
- package/dist/utils/referenceItems.js +11 -3
- package/dist/utils/sentAttachments.d.ts +43 -0
- package/dist/utils/sentAttachments.js +38 -0
- package/dist/utils/sentReferenceBadges.d.ts +11 -1
- package/dist/utils/sentReferenceBadges.js +47 -2
- package/package.json +3 -3
package/dist/i18n/messages.d.ts
CHANGED
|
@@ -213,7 +213,6 @@ export declare const CHAT_MESSAGES: {
|
|
|
213
213
|
readonly 'chat.queue.sendNowTimeout': "The agent did not stop in time, so the message stays in the queue.";
|
|
214
214
|
readonly 'chat.input.completionHint': "Tab to accept";
|
|
215
215
|
readonly 'chat.input.completionHintTouch': "Tap the suggestion to accept";
|
|
216
|
-
readonly 'chat.input.referenceHint': "Type # to reference an attached file";
|
|
217
216
|
readonly 'chat.input.referenceMenuLabel': "Attached files";
|
|
218
217
|
readonly 'chat.input.referenceRemove': "Remove {name}";
|
|
219
218
|
readonly 'chat.messages.scrollToBottom': "Scroll to latest messages";
|
|
@@ -240,6 +239,11 @@ export declare const CHAT_MESSAGES: {
|
|
|
240
239
|
readonly 'chat.checkpoint.version': "Version {n}";
|
|
241
240
|
readonly 'chat.checkpoint.redo': "Redo";
|
|
242
241
|
readonly 'chat.checkpoint.restored': "Restored to version {n}";
|
|
242
|
+
/** The question before the widget goes back to an earlier checkpoint: what is asked, what it costs, and the two buttons. */
|
|
243
|
+
readonly 'chat.checkpoint.confirmTitle': "Restore this checkpoint?";
|
|
244
|
+
readonly 'chat.checkpoint.confirmMessage': "You will lose the changes made after this checkpoint.";
|
|
245
|
+
readonly 'chat.checkpoint.confirmRestore': "Restore";
|
|
246
|
+
readonly 'chat.checkpoint.confirmCancel': "Cancel";
|
|
243
247
|
readonly 'chat.actions.screenshot': "Screenshot";
|
|
244
248
|
readonly 'chat.actions.screenshotTitle': "Take Screenshot";
|
|
245
249
|
readonly 'chat.actions.screenshotLabel': "Take screenshot of current content";
|
|
@@ -252,6 +256,11 @@ export declare const CHAT_MESSAGES: {
|
|
|
252
256
|
readonly 'chat.actions.upload': "Upload";
|
|
253
257
|
readonly 'chat.actions.uploadTitle': "Upload File";
|
|
254
258
|
readonly 'chat.actions.uploadLabel': "Upload file";
|
|
259
|
+
/**
|
|
260
|
+
* The tooltip of the "+" of the message box, after the pointer rests on it: what it adds. The box takes video and PDF too (they
|
|
261
|
+
* are kept with the message), but the builder reads only pictures, CSV and text, so the tooltip does not promise more.
|
|
262
|
+
*/
|
|
263
|
+
readonly 'chat.actions.uploadTooltip': "Add images, CSV or text files. The builder does not read video or PDF yet.";
|
|
255
264
|
readonly 'chat.actions.selector': "Selector";
|
|
256
265
|
readonly 'chat.actions.selectorTitle': "Select a specific part of the widget to reference in chat";
|
|
257
266
|
readonly 'chat.actions.selectorActiveTitle': "Disable widget element selector";
|
|
@@ -284,7 +293,6 @@ export declare const CHAT_MESSAGES: {
|
|
|
284
293
|
/** What a picture of a typed message is called when its file has no name. */
|
|
285
294
|
readonly 'chat.attachment.namelessAlt': "attachment";
|
|
286
295
|
readonly 'chat.attachment.previewAlt': "Attachment preview";
|
|
287
|
-
readonly 'chat.attachment.pdfTitle': "PDF Document";
|
|
288
296
|
readonly 'chat.attachment.noVideo': "Your browser does not support video playback.";
|
|
289
297
|
readonly 'chat.attachment.view': "Click to view {name}";
|
|
290
298
|
readonly 'chat.attachment.viewFile': "Click to view file";
|
|
@@ -293,6 +301,36 @@ export declare const CHAT_MESSAGES: {
|
|
|
293
301
|
/** What a screen reader says for a file chip while its file goes up: `{percent}` is the share sent, from 1 to 99. */
|
|
294
302
|
readonly 'chat.attachment.uploadProgress': "Uploading, {percent}%";
|
|
295
303
|
readonly 'chat.attachment.close': "Close";
|
|
304
|
+
/** The name of the group of files (and the group of pictures) a person sent with a message, for screen readers. */
|
|
305
|
+
readonly 'chat.attachment.sentFiles': "Files sent with this message";
|
|
306
|
+
readonly 'chat.attachment.sentPictures': "Pictures sent with this message";
|
|
307
|
+
/** The preview that opens from a file of the message box or of a sent message (the look of the File Browser's preview). */
|
|
308
|
+
readonly 'chat.preview.previous': "Previous file";
|
|
309
|
+
readonly 'chat.preview.next': "Next file";
|
|
310
|
+
readonly 'chat.preview.loading': "Loading preview";
|
|
311
|
+
readonly 'chat.preview.failed': "This file could not be loaded.";
|
|
312
|
+
readonly 'chat.preview.unavailable': "This kind of file has no preview.";
|
|
313
|
+
readonly 'chat.preview.truncated': "The rest of this file is not shown.";
|
|
314
|
+
/** The words of the PDF viewer inside that preview (`{page}` and `{total}` are the number of the page and of the pages). */
|
|
315
|
+
readonly 'chat.preview.pdfLoading': "Loading PDF…";
|
|
316
|
+
readonly 'chat.preview.pdfFailed': "Failed to load PDF";
|
|
317
|
+
readonly 'chat.preview.pdfPage': "Page {page} of {total}";
|
|
318
|
+
readonly 'chat.preview.pdfPreviousPage': "Previous page";
|
|
319
|
+
readonly 'chat.preview.pdfNextPage': "Next page";
|
|
320
|
+
/**
|
|
321
|
+
* What the whole chat says while files are dragged over it (Figma: Chat / Drop files, Chat / Drop not allowed). The kinds named
|
|
322
|
+
* are the ones the builder reads, as the tooltip of the "+" says (`chat.actions.uploadTooltip`).
|
|
323
|
+
*/
|
|
324
|
+
readonly 'chat.drop.title': "Drop to attach";
|
|
325
|
+
readonly 'chat.drop.hint': "Images, CSV or text files";
|
|
326
|
+
readonly 'chat.drop.refusedTitle': "This file type is not supported";
|
|
327
|
+
readonly 'chat.drop.refusedHint': "Use images, CSV or text files";
|
|
328
|
+
/** Toasts for files that were dropped, picked or pasted and left out. `{name}` is the file's name, `{limit}` its kind's size limit ("10 MB"), `{count}` how many. */
|
|
329
|
+
readonly 'chat.attachment.refusedTypeOne': "“{name}” can’t be attached. Use images, video, PDF, CSV or text files.";
|
|
330
|
+
readonly 'chat.attachment.refusedTypeMany': "{count} files can’t be attached. Use images, video, PDF, CSV or text files.";
|
|
331
|
+
readonly 'chat.attachment.refusedSizeOne': "“{name}” is too large to attach. The limit is {limit}.";
|
|
332
|
+
readonly 'chat.attachment.refusedSizeMany': "{count} files are too large to attach.";
|
|
333
|
+
readonly 'chat.attachment.refusedFolder': "Folders can’t be attached. Drop the files inside them instead.";
|
|
296
334
|
/** The size of a file, from bytes to gigabytes: `{size}` is the number, written the way the language writes numbers ("1.5", "1,5"). */
|
|
297
335
|
readonly 'chat.size.bytes': "{size} B";
|
|
298
336
|
readonly 'chat.size.kb': "{size} KB";
|
|
@@ -366,7 +404,9 @@ export declare const CHAT_MESSAGES: {
|
|
|
366
404
|
readonly 'chat.sketch.failed': "Could not update the sketch. Please try again.";
|
|
367
405
|
readonly 'chat.sketch.failedUnknown': "Could not update the sketch.";
|
|
368
406
|
readonly 'chat.sketch.stepCap': "Sketch assistant stopped after too many steps.";
|
|
369
|
-
readonly 'chat.sketch.noCredits': "You
|
|
407
|
+
readonly 'chat.sketch.noCredits': "You're out of credits.";
|
|
408
|
+
readonly 'chat.sketch.planRequired': "Your plan doesn't include this.";
|
|
409
|
+
readonly 'chat.sketch.limitReached': "You've reached a usage limit.";
|
|
370
410
|
readonly 'chat.sketch.busy': "A sketch is already being drawn, or you have sent too many requests. Try again in a moment.";
|
|
371
411
|
readonly 'chat.sketch.unavailable': "The sketch assistant is not available right now. Please try again in a moment.";
|
|
372
412
|
readonly 'chat.sketch.stopped': "Stopped drawing.";
|
package/dist/i18n/messages.js
CHANGED
|
@@ -221,9 +221,9 @@ export const CHAT_MESSAGES = {
|
|
|
221
221
|
// What to do with the grey suggestion after the caret: shown in the toolbar while one shows, and said to a screen reader with it
|
|
222
222
|
'chat.input.completionHint': 'Tab to accept',
|
|
223
223
|
'chat.input.completionHintTouch': 'Tap the suggestion to accept',
|
|
224
|
-
// Referring to an attached file with # in the message: the
|
|
225
|
-
//
|
|
226
|
-
|
|
224
|
+
// Referring to an attached file with # in the message: the name a screen reader gives the list of files that # opens, and the name
|
|
225
|
+
// of the X of a badge in the text ({name} is the file's own name). There is no line of help about it: nothing under the box, and
|
|
226
|
+
// nothing told to a screen reader either.
|
|
227
227
|
'chat.input.referenceMenuLabel': 'Attached files',
|
|
228
228
|
'chat.input.referenceRemove': 'Remove {name}',
|
|
229
229
|
'chat.messages.scrollToBottom': 'Scroll to latest messages',
|
|
@@ -250,6 +250,11 @@ export const CHAT_MESSAGES = {
|
|
|
250
250
|
'chat.checkpoint.version': 'Version {n}',
|
|
251
251
|
'chat.checkpoint.redo': 'Redo',
|
|
252
252
|
'chat.checkpoint.restored': 'Restored to version {n}',
|
|
253
|
+
/** The question before the widget goes back to an earlier checkpoint: what is asked, what it costs, and the two buttons. */
|
|
254
|
+
'chat.checkpoint.confirmTitle': 'Restore this checkpoint?',
|
|
255
|
+
'chat.checkpoint.confirmMessage': 'You will lose the changes made after this checkpoint.',
|
|
256
|
+
'chat.checkpoint.confirmRestore': 'Restore',
|
|
257
|
+
'chat.checkpoint.confirmCancel': 'Cancel',
|
|
253
258
|
// ===== The buttons under the messages =====
|
|
254
259
|
'chat.actions.screenshot': 'Screenshot',
|
|
255
260
|
'chat.actions.screenshotTitle': 'Take Screenshot',
|
|
@@ -263,6 +268,11 @@ export const CHAT_MESSAGES = {
|
|
|
263
268
|
'chat.actions.upload': 'Upload',
|
|
264
269
|
'chat.actions.uploadTitle': 'Upload File',
|
|
265
270
|
'chat.actions.uploadLabel': 'Upload file',
|
|
271
|
+
/**
|
|
272
|
+
* The tooltip of the "+" of the message box, after the pointer rests on it: what it adds. The box takes video and PDF too (they
|
|
273
|
+
* are kept with the message), but the builder reads only pictures, CSV and text, so the tooltip does not promise more.
|
|
274
|
+
*/
|
|
275
|
+
'chat.actions.uploadTooltip': 'Add images, CSV or text files. The builder does not read video or PDF yet.',
|
|
266
276
|
'chat.actions.selector': 'Selector',
|
|
267
277
|
'chat.actions.selectorTitle': 'Select a specific part of the widget to reference in chat',
|
|
268
278
|
'chat.actions.selectorActiveTitle': 'Disable widget element selector',
|
|
@@ -297,7 +307,6 @@ export const CHAT_MESSAGES = {
|
|
|
297
307
|
/** What a picture of a typed message is called when its file has no name. */
|
|
298
308
|
'chat.attachment.namelessAlt': 'attachment',
|
|
299
309
|
'chat.attachment.previewAlt': 'Attachment preview',
|
|
300
|
-
'chat.attachment.pdfTitle': 'PDF Document',
|
|
301
310
|
'chat.attachment.noVideo': 'Your browser does not support video playback.',
|
|
302
311
|
'chat.attachment.view': 'Click to view {name}',
|
|
303
312
|
'chat.attachment.viewFile': 'Click to view file',
|
|
@@ -306,6 +315,36 @@ export const CHAT_MESSAGES = {
|
|
|
306
315
|
/** What a screen reader says for a file chip while its file goes up: `{percent}` is the share sent, from 1 to 99. */
|
|
307
316
|
'chat.attachment.uploadProgress': 'Uploading, {percent}%',
|
|
308
317
|
'chat.attachment.close': 'Close',
|
|
318
|
+
/** The name of the group of files (and the group of pictures) a person sent with a message, for screen readers. */
|
|
319
|
+
'chat.attachment.sentFiles': 'Files sent with this message',
|
|
320
|
+
'chat.attachment.sentPictures': 'Pictures sent with this message',
|
|
321
|
+
/** The preview that opens from a file of the message box or of a sent message (the look of the File Browser's preview). */
|
|
322
|
+
'chat.preview.previous': 'Previous file',
|
|
323
|
+
'chat.preview.next': 'Next file',
|
|
324
|
+
'chat.preview.loading': 'Loading preview',
|
|
325
|
+
'chat.preview.failed': 'This file could not be loaded.',
|
|
326
|
+
'chat.preview.unavailable': 'This kind of file has no preview.',
|
|
327
|
+
'chat.preview.truncated': 'The rest of this file is not shown.',
|
|
328
|
+
/** The words of the PDF viewer inside that preview (`{page}` and `{total}` are the number of the page and of the pages). */
|
|
329
|
+
'chat.preview.pdfLoading': 'Loading PDF…',
|
|
330
|
+
'chat.preview.pdfFailed': 'Failed to load PDF',
|
|
331
|
+
'chat.preview.pdfPage': 'Page {page} of {total}',
|
|
332
|
+
'chat.preview.pdfPreviousPage': 'Previous page',
|
|
333
|
+
'chat.preview.pdfNextPage': 'Next page',
|
|
334
|
+
/**
|
|
335
|
+
* What the whole chat says while files are dragged over it (Figma: Chat / Drop files, Chat / Drop not allowed). The kinds named
|
|
336
|
+
* are the ones the builder reads, as the tooltip of the "+" says (`chat.actions.uploadTooltip`).
|
|
337
|
+
*/
|
|
338
|
+
'chat.drop.title': 'Drop to attach',
|
|
339
|
+
'chat.drop.hint': 'Images, CSV or text files',
|
|
340
|
+
'chat.drop.refusedTitle': 'This file type is not supported',
|
|
341
|
+
'chat.drop.refusedHint': 'Use images, CSV or text files',
|
|
342
|
+
/** Toasts for files that were dropped, picked or pasted and left out. `{name}` is the file's name, `{limit}` its kind's size limit ("10 MB"), `{count}` how many. */
|
|
343
|
+
'chat.attachment.refusedTypeOne': '“{name}” can’t be attached. Use images, video, PDF, CSV or text files.',
|
|
344
|
+
'chat.attachment.refusedTypeMany': '{count} files can’t be attached. Use images, video, PDF, CSV or text files.',
|
|
345
|
+
'chat.attachment.refusedSizeOne': '“{name}” is too large to attach. The limit is {limit}.',
|
|
346
|
+
'chat.attachment.refusedSizeMany': '{count} files are too large to attach.',
|
|
347
|
+
'chat.attachment.refusedFolder': 'Folders can’t be attached. Drop the files inside them instead.',
|
|
309
348
|
/** The size of a file, from bytes to gigabytes: `{size}` is the number, written the way the language writes numbers ("1.5", "1,5"). */
|
|
310
349
|
'chat.size.bytes': '{size} B',
|
|
311
350
|
'chat.size.kb': '{size} KB',
|
|
@@ -384,7 +423,12 @@ export const CHAT_MESSAGES = {
|
|
|
384
423
|
'chat.sketch.failed': 'Could not update the sketch. Please try again.',
|
|
385
424
|
'chat.sketch.failedUnknown': 'Could not update the sketch.',
|
|
386
425
|
'chat.sketch.stepCap': 'Sketch assistant stopped after too many steps.',
|
|
387
|
-
|
|
426
|
+
// The three sentences for a refusal because of money. The chat knows them by their exact words (to draw "Upgrade" under them),
|
|
427
|
+
// so each is one whole sentence that no reply of the model is likely to be. The widget creator says the first two the same way.
|
|
428
|
+
'chat.sketch.noCredits': "You're out of credits.",
|
|
429
|
+
'chat.sketch.planRequired': "Your plan doesn't include this.",
|
|
430
|
+
// For the visitor of a page that is not their own: they have no credits or plan to name
|
|
431
|
+
'chat.sketch.limitReached': "You've reached a usage limit.",
|
|
388
432
|
'chat.sketch.busy': 'A sketch is already being drawn, or you have sent too many requests. Try again in a moment.',
|
|
389
433
|
'chat.sketch.unavailable': 'The sketch assistant is not available right now. Please try again in a moment.',
|
|
390
434
|
'chat.sketch.stopped': 'Stopped drawing.',
|
package/dist/services/index.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { WidgeticChatService, createChatService } from './chatService.js';
|
|
|
2
2
|
export type { ChatService, ChatInstance, ChatFactory } from '../types/index.js';
|
|
3
3
|
export { startSketchAssistantRequest, sketchAssistantStepRequest, SketchAssistantRequestError } from './sketchAssistantClient.js';
|
|
4
4
|
export type { SketchToolCall, SketchAssistantStartResponse, SketchSceneSummary, SketchAssistantContext } from './sketchAssistantClient.js';
|
|
5
|
-
export { runSketchAssistantLoop, describeSketchRequestFailure } from './sketchAssistantOrchestrator.js';
|
|
6
|
-
export type { CanvasSketchExecutor, SketchAssistantLoopResult } from './sketchAssistantOrchestrator.js';
|
|
5
|
+
export { runSketchAssistantLoop, describeSketchRequestFailure, limitKindOfSketchFailure } from './sketchAssistantOrchestrator.js';
|
|
6
|
+
export type { CanvasSketchExecutor, SketchAssistantLoopResult, SketchFailureWording } from './sketchAssistantOrchestrator.js';
|
|
7
|
+
export { limitFailureKindOfRefusal } from './limitRefusal.js';
|
|
8
|
+
export type { LimitFailureKind, RefusalFacts } from './limitRefusal.js';
|
|
7
9
|
export { buildSketchAssistantReply } from './sketchAssistantReply.js';
|
package/dist/services/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Chat Service
|
|
2
2
|
export { WidgeticChatService, createChatService } from './chatService.js';
|
|
3
3
|
export { startSketchAssistantRequest, sketchAssistantStepRequest, SketchAssistantRequestError } from './sketchAssistantClient.js';
|
|
4
|
-
export { runSketchAssistantLoop, describeSketchRequestFailure } from './sketchAssistantOrchestrator.js';
|
|
4
|
+
export { runSketchAssistantLoop, describeSketchRequestFailure, limitKindOfSketchFailure } from './sketchAssistantOrchestrator.js';
|
|
5
|
+
export { limitFailureKindOfRefusal } from './limitRefusal.js';
|
|
5
6
|
export { buildSketchAssistantReply } from './sketchAssistantReply.js';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a refusal of the gateway says about money.
|
|
3
|
+
*
|
|
4
|
+
* A request can be refused because the credits are used up, or because the plan does not include what was asked (a free
|
|
5
|
+
* trial that ended, an account that is not subscribed). Both end the same way for the person: nothing is wrong with the
|
|
6
|
+
* request, and the way out is to upgrade. Every other refusal (busy, down, a bad request) is not that, and is worded
|
|
7
|
+
* elsewhere. This file decides which is which, from what the gateway answered, in one place.
|
|
8
|
+
*
|
|
9
|
+
* What the gateway sends for each, as of this writing:
|
|
10
|
+
*
|
|
11
|
+
* - 402 `BILLING_INSUFFICIENT_CREDITS`: the credits are used up. Two other 402s are NOT a shortage and must never say so:
|
|
12
|
+
* "Could not read your credit balance. Please try again in a moment." (a lookup that failed) and "Credits are only
|
|
13
|
+
* supported for user accounts." (this kind of account holds none).
|
|
14
|
+
* - 403 `AUTHZ_PLAN_RESTRICTION`: the plan lacks the feature. The same refusal also arrives as a plain 403 whose only
|
|
15
|
+
* mark is its sentence ("…free trial has ended, so widget generation is not available in your plan…"), so the
|
|
16
|
+
* sentence is read for those.
|
|
17
|
+
* - An editor session (a partner's visitor) is refused with `error.details.limit` set to `credits` or `plan`.
|
|
18
|
+
*
|
|
19
|
+
* A 403 is also what an ordinary refusal looks like (a route a session may not use), so a 403 with none of those marks
|
|
20
|
+
* is not a limit.
|
|
21
|
+
*
|
|
22
|
+
* The widget creator keeps the same rules for its own failures (`host/limitRefusal.ts` and `errors/toUserFriendlyError.ts`
|
|
23
|
+
* there): the two packages are published apart, so each holds its copy, and each is tested against the words above.
|
|
24
|
+
*/
|
|
25
|
+
/** Which limit refused the request. */
|
|
26
|
+
export type LimitFailureKind = 'credits' | 'plan';
|
|
27
|
+
/** What the gateway answered when it did not take a request. */
|
|
28
|
+
export interface RefusalFacts {
|
|
29
|
+
/** The HTTP status. */
|
|
30
|
+
status: number;
|
|
31
|
+
/** The code of the error envelope (for example `BILLING_INSUFFICIENT_CREDITS`). */
|
|
32
|
+
code?: string | null;
|
|
33
|
+
/** The gateway's own sentence. */
|
|
34
|
+
message?: string | null;
|
|
35
|
+
/** The `error.details` of the envelope; an editor session's refusal marks `limit` in it. */
|
|
36
|
+
details?: unknown;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Which limit refused a request, or `null` when the refusal is not about credits or the plan.
|
|
40
|
+
* Pure: nothing is logged here, so a caller can ask as often as it likes.
|
|
41
|
+
*/
|
|
42
|
+
export declare function limitFailureKindOfRefusal(refusal: RefusalFacts): LimitFailureKind | null;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a refusal of the gateway says about money.
|
|
3
|
+
*
|
|
4
|
+
* A request can be refused because the credits are used up, or because the plan does not include what was asked (a free
|
|
5
|
+
* trial that ended, an account that is not subscribed). Both end the same way for the person: nothing is wrong with the
|
|
6
|
+
* request, and the way out is to upgrade. Every other refusal (busy, down, a bad request) is not that, and is worded
|
|
7
|
+
* elsewhere. This file decides which is which, from what the gateway answered, in one place.
|
|
8
|
+
*
|
|
9
|
+
* What the gateway sends for each, as of this writing:
|
|
10
|
+
*
|
|
11
|
+
* - 402 `BILLING_INSUFFICIENT_CREDITS`: the credits are used up. Two other 402s are NOT a shortage and must never say so:
|
|
12
|
+
* "Could not read your credit balance. Please try again in a moment." (a lookup that failed) and "Credits are only
|
|
13
|
+
* supported for user accounts." (this kind of account holds none).
|
|
14
|
+
* - 403 `AUTHZ_PLAN_RESTRICTION`: the plan lacks the feature. The same refusal also arrives as a plain 403 whose only
|
|
15
|
+
* mark is its sentence ("…free trial has ended, so widget generation is not available in your plan…"), so the
|
|
16
|
+
* sentence is read for those.
|
|
17
|
+
* - An editor session (a partner's visitor) is refused with `error.details.limit` set to `credits` or `plan`.
|
|
18
|
+
*
|
|
19
|
+
* A 403 is also what an ordinary refusal looks like (a route a session may not use), so a 403 with none of those marks
|
|
20
|
+
* is not a limit.
|
|
21
|
+
*
|
|
22
|
+
* The widget creator keeps the same rules for its own failures (`host/limitRefusal.ts` and `errors/toUserFriendlyError.ts`
|
|
23
|
+
* there): the two packages are published apart, so each holds its copy, and each is tested against the words above.
|
|
24
|
+
*/
|
|
25
|
+
/** The 402s that are not a shortage of credits (see above). */
|
|
26
|
+
const NOT_A_SHORTAGE_PATTERN = /could not read your credit balance|unable to resolve the account to meter|credits are only supported for user accounts/i;
|
|
27
|
+
/** The gateway's sentences for a plan that lacks what was asked. */
|
|
28
|
+
const PLAN_REFUSAL_PATTERN = /not available (?:in your plan|on the free plan|on this workspace's plan)|free trial has ended|is part of the [^.]{1,40} plan|plan (?:doesn't|does not) include|subscription [^.]{0,80} is not active|limit for this action on your plan/i;
|
|
29
|
+
/** The `limit` an editor session's refusal is marked with, when it is marked. */
|
|
30
|
+
function readLimitMark(details) {
|
|
31
|
+
if (!details || typeof details !== 'object')
|
|
32
|
+
return null;
|
|
33
|
+
const mark = details.limit;
|
|
34
|
+
return typeof mark === 'string' ? mark : null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Which limit refused a request, or `null` when the refusal is not about credits or the plan.
|
|
38
|
+
* Pure: nothing is logged here, so a caller can ask as often as it likes.
|
|
39
|
+
*/
|
|
40
|
+
export function limitFailureKindOfRefusal(refusal) {
|
|
41
|
+
const limitMark = readLimitMark(refusal.details);
|
|
42
|
+
const sentence = refusal.message ?? '';
|
|
43
|
+
if (refusal.status === 402) {
|
|
44
|
+
// A balance that could not be read is a failure to try again, not a shortage
|
|
45
|
+
if (NOT_A_SHORTAGE_PATTERN.test(sentence))
|
|
46
|
+
return null;
|
|
47
|
+
return limitMark === 'plan' ? 'plan' : 'credits';
|
|
48
|
+
}
|
|
49
|
+
if (refusal.status === 403) {
|
|
50
|
+
if (limitMark === 'credits')
|
|
51
|
+
return 'credits';
|
|
52
|
+
if (limitMark === 'plan' || refusal.code === 'AUTHZ_PLAN_RESTRICTION')
|
|
53
|
+
return 'plan';
|
|
54
|
+
return PLAN_REFUSAL_PATTERN.test(sentence) ? 'plan' : null;
|
|
55
|
+
}
|
|
56
|
+
// A proxy can change the status; the code still says the credits are used up
|
|
57
|
+
if (refusal.code === 'BILLING_INSUFFICIENT_CREDITS' && !NOT_A_SHORTAGE_PATTERN.test(sentence))
|
|
58
|
+
return 'credits';
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
@@ -60,15 +60,23 @@ export interface SketchAssistantContext {
|
|
|
60
60
|
}
|
|
61
61
|
/** The status of a request that got no answer at all (offline, the gateway down), which is no HTTP status. */
|
|
62
62
|
export declare const SKETCH_ASSISTANT_NO_ANSWER_STATUS = 0;
|
|
63
|
+
/**
|
|
64
|
+
* The id as the gateway can take it, or null. `POST /agent/sketch` accepts `conversationId` and `canvasId` only as UUIDs and refuses
|
|
65
|
+
* the whole request (a 400, before the model or any canvas tool runs) for anything else. A draft canvas has no widget yet, so its
|
|
66
|
+
* chat's conversation lives only in the browser (an id like `local_draft_convert_canvas_1731…`): such an id says nothing the gateway
|
|
67
|
+
* could use, so it is left out and the drawing goes on without it. Said once in the console for each request that leaves one out.
|
|
68
|
+
*/
|
|
69
|
+
export declare function idForGateway(candidateId: string | null | undefined, fieldName: 'conversationId' | 'canvasId'): string | null;
|
|
63
70
|
/**
|
|
64
71
|
* What the gateway answered when it did not take a request: the HTTP status, the code of its error envelope
|
|
65
|
-
* (for example `BILLING_INSUFFICIENT_CREDITS`)
|
|
66
|
-
* `SKETCH_ASSISTANT_NO_ANSWER_STATUS`.
|
|
72
|
+
* (for example `BILLING_INSUFFICIENT_CREDITS`), its own sentence and the `details` of the envelope (an editor session's
|
|
73
|
+
* refusal marks which `limit` it was). A request that got no answer has the status `SKETCH_ASSISTANT_NO_ANSWER_STATUS`.
|
|
67
74
|
*/
|
|
68
75
|
export declare class SketchAssistantRequestError extends Error {
|
|
69
76
|
readonly status: number;
|
|
70
77
|
readonly code: string | null;
|
|
71
|
-
|
|
78
|
+
readonly details: Record<string, unknown> | null;
|
|
79
|
+
constructor(message: string, status: number, code?: string | null, details?: Record<string, unknown> | null);
|
|
72
80
|
}
|
|
73
81
|
export declare function startSketchAssistantRequest(input: {
|
|
74
82
|
apiBaseUrl: string;
|
|
@@ -3,30 +3,56 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/** The status of a request that got no answer at all (offline, the gateway down), which is no HTTP status. */
|
|
5
5
|
export const SKETCH_ASSISTANT_NO_ANSWER_STATUS = 0;
|
|
6
|
+
/** The shape the gateway's schema takes for the id of a conversation or of a canvas. */
|
|
7
|
+
const GATEWAY_UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
8
|
+
/**
|
|
9
|
+
* The id as the gateway can take it, or null. `POST /agent/sketch` accepts `conversationId` and `canvasId` only as UUIDs and refuses
|
|
10
|
+
* the whole request (a 400, before the model or any canvas tool runs) for anything else. A draft canvas has no widget yet, so its
|
|
11
|
+
* chat's conversation lives only in the browser (an id like `local_draft_convert_canvas_1731…`): such an id says nothing the gateway
|
|
12
|
+
* could use, so it is left out and the drawing goes on without it. Said once in the console for each request that leaves one out.
|
|
13
|
+
*/
|
|
14
|
+
export function idForGateway(candidateId, fieldName) {
|
|
15
|
+
if (typeof candidateId !== 'string')
|
|
16
|
+
return null;
|
|
17
|
+
const trimmedId = candidateId.trim();
|
|
18
|
+
if (trimmedId === '')
|
|
19
|
+
return null;
|
|
20
|
+
if (GATEWAY_UUID_PATTERN.test(trimmedId))
|
|
21
|
+
return trimmedId;
|
|
22
|
+
// console.debug(`[chat] sketch assistant: ${fieldName} is not a UUID, so it is left out of the request`, {
|
|
23
|
+
// 'Left Out': trimmedId.slice(0, 48)
|
|
24
|
+
// });
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
6
27
|
/**
|
|
7
28
|
* What the gateway answered when it did not take a request: the HTTP status, the code of its error envelope
|
|
8
|
-
* (for example `BILLING_INSUFFICIENT_CREDITS`)
|
|
9
|
-
* `SKETCH_ASSISTANT_NO_ANSWER_STATUS`.
|
|
29
|
+
* (for example `BILLING_INSUFFICIENT_CREDITS`), its own sentence and the `details` of the envelope (an editor session's
|
|
30
|
+
* refusal marks which `limit` it was). A request that got no answer has the status `SKETCH_ASSISTANT_NO_ANSWER_STATUS`.
|
|
10
31
|
*/
|
|
11
32
|
export class SketchAssistantRequestError extends Error {
|
|
12
33
|
status;
|
|
13
34
|
code;
|
|
14
|
-
|
|
35
|
+
details;
|
|
36
|
+
constructor(message, status, code = null, details = null) {
|
|
15
37
|
super(message);
|
|
16
38
|
this.name = 'SketchAssistantRequestError';
|
|
17
39
|
this.status = status;
|
|
18
40
|
this.code = code;
|
|
41
|
+
this.details = details;
|
|
19
42
|
}
|
|
20
43
|
}
|
|
21
|
-
/** The sentence and the
|
|
44
|
+
/** The sentence, the code and the details of a refusal. The gateway writes `{ message, error: { code, message, details } }`; some doors write `{ error, code }`. */
|
|
22
45
|
function readRefusal(payload) {
|
|
23
46
|
if (!payload || typeof payload !== 'object')
|
|
24
|
-
return { message: null, code: null };
|
|
47
|
+
return { message: null, code: null, details: null };
|
|
25
48
|
const body = payload;
|
|
26
|
-
const nested = body.error && typeof body.error === 'object'
|
|
49
|
+
const nested = body.error && typeof body.error === 'object'
|
|
50
|
+
? body.error
|
|
51
|
+
: null;
|
|
27
52
|
const message = [body.message, nested?.message, typeof body.error === 'string' ? body.error : null].find((candidate) => typeof candidate === 'string' && candidate.trim().length > 0);
|
|
28
53
|
const code = [nested?.code, body.code].find((candidate) => typeof candidate === 'string' && candidate.length > 0);
|
|
29
|
-
|
|
54
|
+
const details = [nested?.details, body.details].find((candidate) => !!candidate && typeof candidate === 'object' && !Array.isArray(candidate));
|
|
55
|
+
return { message: message ?? null, code: code ?? null, details: details ?? null };
|
|
30
56
|
}
|
|
31
57
|
async function postJson(baseUrl, path, body, token, signal) {
|
|
32
58
|
let response;
|
|
@@ -55,7 +81,7 @@ async function postJson(baseUrl, path, body, token, signal) {
|
|
|
55
81
|
const refusal = readRefusal(payload);
|
|
56
82
|
const technical = refusal.message ?? `request failed with status ${response.status}`;
|
|
57
83
|
console.error('[chat] sketch assistant response', { status: response.status, code: refusal.code, message: technical });
|
|
58
|
-
throw new SketchAssistantRequestError(technical, response.status, refusal.code);
|
|
84
|
+
throw new SketchAssistantRequestError(technical, response.status, refusal.code, refusal.details);
|
|
59
85
|
}
|
|
60
86
|
return (payload?.data ?? payload);
|
|
61
87
|
}
|
|
@@ -64,8 +90,9 @@ export async function startSketchAssistantRequest(input) {
|
|
|
64
90
|
prompt: input.prompt,
|
|
65
91
|
sceneSummary: input.sceneSummary,
|
|
66
92
|
sketchContext: input.sketchContext,
|
|
67
|
-
|
|
68
|
-
|
|
93
|
+
// Only ids the gateway can take (UUIDs): an id of a conversation that lives in the browser would fail the whole request
|
|
94
|
+
conversationId: idForGateway(input.conversationId, 'conversationId'),
|
|
95
|
+
canvasId: idForGateway(input.canvasId, 'canvasId')
|
|
69
96
|
}, input.authToken, input.signal);
|
|
70
97
|
}
|
|
71
98
|
export async function sketchAssistantStepRequest(input) {
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import type { Translate } from '@widgetic/design-system/i18n';
|
|
2
2
|
import type { ChatMessageKey } from '../i18n/messages.js';
|
|
3
|
+
import { type LimitFailureKind } from './limitRefusal.js';
|
|
4
|
+
/** How a failure is worded, for the places that are not the person's own account. */
|
|
5
|
+
export interface SketchFailureWording {
|
|
6
|
+
/**
|
|
7
|
+
* Say a refusal because of a limit without naming the credits or the plan. The visitor of a page that belongs to someone else
|
|
8
|
+
* (a partner's) has neither, and the page decides what a limit means to them. The chat still shows its "Upgrade" button under the
|
|
9
|
+
* sentence, and a press on it goes to the host (`onUpgradePlans`). Defaults to `false`.
|
|
10
|
+
*/
|
|
11
|
+
neutralLimits?: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Which limit refused a sketch request (the credits are used up, or the plan does not include it), or `null` when the failure is
|
|
15
|
+
* anything else (including a credit balance that could not be read, which is a reason to try again).
|
|
16
|
+
*/
|
|
17
|
+
export declare function limitKindOfSketchFailure(error: unknown): LimitFailureKind | null;
|
|
3
18
|
/** Words shown in the chat bubble when a sketch request fails. */
|
|
4
|
-
export declare function describeSketchRequestFailure(error: unknown, translate?: Translate<ChatMessageKey
|
|
19
|
+
export declare function describeSketchRequestFailure(error: unknown, translate?: Translate<ChatMessageKey>, wording?: SketchFailureWording): string;
|
|
@@ -1,15 +1,36 @@
|
|
|
1
1
|
import { translateEnglish } from '../i18n/language.js';
|
|
2
2
|
import { SKETCH_ASSISTANT_NO_ANSWER_STATUS, SketchAssistantRequestError, } from './sketchAssistantClient.js';
|
|
3
|
+
import { limitFailureKindOfRefusal } from './limitRefusal.js';
|
|
3
4
|
import { logTechnicalUserError } from '../errors/logTechnicalUserError.js';
|
|
5
|
+
/**
|
|
6
|
+
* Which limit refused a sketch request (the credits are used up, or the plan does not include it), or `null` when the failure is
|
|
7
|
+
* anything else (including a credit balance that could not be read, which is a reason to try again).
|
|
8
|
+
*/
|
|
9
|
+
export function limitKindOfSketchFailure(error) {
|
|
10
|
+
if (!(error instanceof SketchAssistantRequestError))
|
|
11
|
+
return null;
|
|
12
|
+
return limitFailureKindOfRefusal({
|
|
13
|
+
status: error.status,
|
|
14
|
+
code: error.code,
|
|
15
|
+
message: error.message,
|
|
16
|
+
details: error.details,
|
|
17
|
+
});
|
|
18
|
+
}
|
|
4
19
|
/** Words shown in the chat bubble when a sketch request fails. */
|
|
5
|
-
export function describeSketchRequestFailure(error, translate = translateEnglish) {
|
|
20
|
+
export function describeSketchRequestFailure(error, translate = translateEnglish, wording = {}) {
|
|
6
21
|
if (error instanceof SketchAssistantRequestError) {
|
|
7
22
|
logTechnicalUserError('sketch assistant request', error, error.message);
|
|
8
|
-
|
|
9
|
-
|
|
23
|
+
// A refusal because of money says so, plainly: the chat draws "Upgrade" under these sentences (it knows them by their words)
|
|
24
|
+
const limitKind = limitKindOfSketchFailure(error);
|
|
25
|
+
if (limitKind !== null) {
|
|
26
|
+
if (wording.neutralLimits === true)
|
|
27
|
+
return translate('chat.sketch.limitReached');
|
|
28
|
+
return limitKind === 'credits' ? translate('chat.sketch.noCredits') : translate('chat.sketch.planRequired');
|
|
29
|
+
}
|
|
10
30
|
if (error.status === 429)
|
|
11
31
|
return translate('chat.sketch.busy');
|
|
12
|
-
|
|
32
|
+
// A 402 that is not a shortage is a balance that could not be read: nothing is wrong with the person's account
|
|
33
|
+
if (error.status === SKETCH_ASSISTANT_NO_ANSWER_STATUS || error.status === 402 || error.status === 408 || error.status >= 500) {
|
|
13
34
|
return translate('chat.sketch.unavailable');
|
|
14
35
|
}
|
|
15
36
|
return translate('chat.sketch.failed');
|
|
@@ -2,7 +2,8 @@ import { type SketchAssistantContext, type SketchSceneSummary } from './sketchAs
|
|
|
2
2
|
import { type SketchToolTrace } from './sketchAssistantReply.js';
|
|
3
3
|
import type { Translate } from '@widgetic/design-system/i18n';
|
|
4
4
|
import type { ChatMessageKey } from '../i18n/messages.js';
|
|
5
|
-
export { describeSketchRequestFailure } from './sketchAssistantErrors.js';
|
|
5
|
+
export { describeSketchRequestFailure, limitKindOfSketchFailure } from './sketchAssistantErrors.js';
|
|
6
|
+
export type { SketchFailureWording } from './sketchAssistantErrors.js';
|
|
6
7
|
export interface CanvasSketchExecutor {
|
|
7
8
|
getSceneSummary(): SketchSceneSummary;
|
|
8
9
|
executeTool(name: string, args: Record<string, unknown>): Record<string, unknown>;
|
|
@@ -40,6 +41,11 @@ export declare function runSketchAssistantLoop(input: {
|
|
|
40
41
|
sketchContext?: SketchAssistantContext;
|
|
41
42
|
maxSteps?: number;
|
|
42
43
|
translate?: Translate<ChatMessageKey>;
|
|
44
|
+
/**
|
|
45
|
+
* Say a refusal because of a limit (the credits, the plan) without naming either: for the visitor of a page that is not their own,
|
|
46
|
+
* who has neither. See `SketchFailureWording`.
|
|
47
|
+
*/
|
|
48
|
+
neutralLimits?: boolean;
|
|
43
49
|
/** Stops the run between requests, and the request that is on its way. */
|
|
44
50
|
signal?: AbortSignal;
|
|
45
51
|
}): Promise<SketchAssistantLoopResult>;
|
|
@@ -3,7 +3,7 @@ import { buildSketchAssistantReply } from './sketchAssistantReply.js';
|
|
|
3
3
|
import { translateEnglish } from '../i18n/language.js';
|
|
4
4
|
import { describeSketchRequestFailure } from './sketchAssistantErrors.js';
|
|
5
5
|
import { logTechnicalUserError } from '../errors/logTechnicalUserError.js';
|
|
6
|
-
export { describeSketchRequestFailure } from './sketchAssistantErrors.js';
|
|
6
|
+
export { describeSketchRequestFailure, limitKindOfSketchFailure } from './sketchAssistantErrors.js';
|
|
7
7
|
/**
|
|
8
8
|
* How many times a run answers the gateway with tool results. The gateway stops a run after the same number of steps
|
|
9
9
|
* (its last answer is words only), so a run that is still asking for tools after this many has not understood the
|
|
@@ -106,7 +106,7 @@ export async function runSketchAssistantLoop(input) {
|
|
|
106
106
|
if (!(error instanceof SketchAssistantRequestError) && !input.signal?.aborted) {
|
|
107
107
|
console.warn('[Sketch] The sketch assistant stopped', error);
|
|
108
108
|
}
|
|
109
|
-
return outcome(false, describeSketchRequestFailure(error, translate));
|
|
109
|
+
return outcome(false, describeSketchRequestFailure(error, translate, { neutralLimits: input.neutralLimits === true }));
|
|
110
110
|
}
|
|
111
111
|
finally {
|
|
112
112
|
if (batchOpen)
|
|
@@ -65,6 +65,17 @@ export interface AttachmentInput {
|
|
|
65
65
|
* from the file it is sent with (`referenceLabel`) to tie a `#word` of the text to that file.
|
|
66
66
|
*/
|
|
67
67
|
referenceLabel?: string;
|
|
68
|
+
/**
|
|
69
|
+
* For a long text that was pasted into the message box: the beginning of the text (see `pastedTextExcerpt`). Its presence is
|
|
70
|
+
* what makes the file a pasted text: it lives in the words of the message, as a badge where the caret was, and the tray has no
|
|
71
|
+
* tile for it. The card over its badge shows this; it is for the screen only and is never sent anywhere.
|
|
72
|
+
*/
|
|
73
|
+
excerpt?: string;
|
|
74
|
+
/**
|
|
75
|
+
* What the file's bytes are, as a short text (see `fingerprintFile`): a file that comes again (dragged twice, pasted after it was
|
|
76
|
+
* dropped) is recognised by it and is not attached a second time. For the screen's bookkeeping only; never sent anywhere.
|
|
77
|
+
*/
|
|
78
|
+
fingerprint?: string;
|
|
68
79
|
}
|
|
69
80
|
/**
|
|
70
81
|
* Client-side attachment before upload
|
|
@@ -59,6 +59,14 @@ export interface TurnReplyFacts {
|
|
|
59
59
|
* the turn (or a generation that ran for it) makes an ordinary last reply a success.
|
|
60
60
|
*/
|
|
61
61
|
export declare function turnOutcome(replies: readonly TurnReplyFacts[], generationRanForTurn: boolean): TurnOutcome | null;
|
|
62
|
+
/**
|
|
63
|
+
* The outcome the avatar is DRAWN for. A success is celebrated (the large avatar plays its one-shot) only by a person who just
|
|
64
|
+
* watched the work succeed. A turn that was judged a success but was not watched happen is drawn as a plain answer, at rest:
|
|
65
|
+
* a conversation that was loaded, work that came back from this browser's archive after a reload (or when the conversation was
|
|
66
|
+
* opened again) is the work of an earlier run, and a refresh must leave the avatar as it was and not make it do the task again.
|
|
67
|
+
* Every other outcome (a failure, a stop, a question) is how the turn really ended and is drawn as it is.
|
|
68
|
+
*/
|
|
69
|
+
export declare function outcomeToShow(outcome: TurnOutcome, successWasWatched: boolean): TurnOutcome;
|
|
62
70
|
/**
|
|
63
71
|
* The look of a turn that is not running. Only the newest turn moves, and only its conclusion is large (the success avatar,
|
|
64
72
|
* or a question to answer): older turns are small still pictures, so a long chat keeps one mascot alive instead of one per
|
|
@@ -169,12 +177,26 @@ export interface FinishedGeneration {
|
|
|
169
177
|
* on the diff. Null when the run has none: the first message of a conversation, a page that does not give changes.
|
|
170
178
|
*/
|
|
171
179
|
changes?: CodeChanges | null;
|
|
180
|
+
/**
|
|
181
|
+
* The agent's own words about what the run changed, when the page gave them (the gateway sends them with the completed
|
|
182
|
+
* operation). The conclusion says them in place of the catalog's "Done" sentence. Null when the run has none: a gateway that
|
|
183
|
+
* sends no summary, a build that was not kept.
|
|
184
|
+
*/
|
|
185
|
+
summary?: string | null;
|
|
172
186
|
}
|
|
173
187
|
/**
|
|
174
188
|
* The most text kept of either part. A generation streams tails; the chat stitches them, and a runaway stream
|
|
175
189
|
* must not grow memory without end.
|
|
176
190
|
*/
|
|
177
191
|
export declare const MAX_KEPT_GENERATION_CHARS = 120000;
|
|
192
|
+
/** The most characters kept of the agent's summary of a run: a sentence or two, never an essay. A longer one is cut and ends in "…". */
|
|
193
|
+
export declare const MAX_KEPT_SUMMARY_CHARS = 600;
|
|
194
|
+
/**
|
|
195
|
+
* The agent's summary of a run, read from whatever the page gave: the words as one paragraph (line breaks and runs of spaces become
|
|
196
|
+
* one space), within `MAX_KEPT_SUMMARY_CHARS`. Anything that is not text, or is only spaces, reads as no summary, and the conclusion
|
|
197
|
+
* keeps the catalog's sentence. It never throws.
|
|
198
|
+
*/
|
|
199
|
+
export declare function readGenerationSummary(raw: unknown): string | null;
|
|
178
200
|
/**
|
|
179
201
|
* A prompt as a way to recognise its turn. A message id is no use: the host swaps a made-up id for the saved one, and
|
|
180
202
|
* may reload the whole conversation after a generation. The words the person wrote survive both.
|
|
@@ -182,7 +204,8 @@ export declare const MAX_KEPT_GENERATION_CHARS = 120000;
|
|
|
182
204
|
export declare function normalizePromptText(content: string | null | undefined): string;
|
|
183
205
|
/**
|
|
184
206
|
* What to keep of a generation that ended, or null when it left nothing to show. `changes` is whatever the page gave as the
|
|
185
|
-
* changes of the run:
|
|
207
|
+
* changes of the run, and `summary` the agent's words about them: both are read here (a part that is not usable is dropped), so
|
|
208
|
+
* what is kept is always plain, bounded data. A run that left only a summary is kept: its conclusion says it.
|
|
186
209
|
*/
|
|
187
210
|
export declare function keepFinishedGeneration(input: {
|
|
188
211
|
promptText: string | null | undefined;
|
|
@@ -190,7 +213,15 @@ export declare function keepFinishedGeneration(input: {
|
|
|
190
213
|
code: string;
|
|
191
214
|
thoughtSeconds: number | null;
|
|
192
215
|
changes?: unknown;
|
|
216
|
+
summary?: unknown;
|
|
193
217
|
}): FinishedGeneration | null;
|
|
218
|
+
/**
|
|
219
|
+
* The kept work of a run with the agent's summary of that run put into it, for a page that gives the summary AFTER the run ended
|
|
220
|
+
* (it comes with the completed operation, like the changes: see `withChangesOfTheRun`). It gives back the very same object when
|
|
221
|
+
* there is nothing to put in (the work has a summary already, or what was given is not usable), so the caller can tell by identity
|
|
222
|
+
* that nothing changed.
|
|
223
|
+
*/
|
|
224
|
+
export declare function withSummaryOfTheRun(finished: FinishedGeneration, summary: unknown): FinishedGeneration;
|
|
194
225
|
/**
|
|
195
226
|
* The kept work of a run with the changes of that run put into it, for a page that gives the changes AFTER the run ended. The
|
|
196
227
|
* gateway sends them with the completed operation, and a page that lets the chat take the next message as soon as the preview is
|