@widgetic/chat 0.1.42 → 0.1.43

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 (83) hide show
  1. package/README.md +461 -6
  2. package/dist/components/Chat.svelte +1078 -87
  3. package/dist/components/Chat.svelte.d.ts +102 -2
  4. package/dist/components/ChatComposer.svelte +382 -9
  5. package/dist/components/ChatComposer.svelte.d.ts +66 -3
  6. package/dist/components/ChatMessageQueue.svelte +56 -0
  7. package/dist/components/ChatMessageQueue.svelte.d.ts +20 -0
  8. package/dist/components/ChatMessages.svelte +477 -46
  9. package/dist/components/ChatMessages.svelte.d.ts +45 -2
  10. package/dist/components/ComposerAttachmentsTray.svelte +42 -10
  11. package/dist/components/ComposerAttachmentsTray.svelte.d.ts +5 -0
  12. package/dist/components/ComposerMentionChips.svelte +53 -0
  13. package/dist/components/ComposerMentionChips.svelte.d.ts +15 -0
  14. package/dist/components/FollowUpCard.svelte +134 -0
  15. package/dist/components/FollowUpCard.svelte.d.ts +17 -0
  16. package/dist/components/MentionChip.svelte +41 -0
  17. package/dist/components/MentionChip.svelte.d.ts +12 -0
  18. package/dist/components/MentionMenu.svelte +114 -0
  19. package/dist/components/MentionMenu.svelte.d.ts +19 -0
  20. package/dist/components/agent/AgentAvatar.svelte +6 -4
  21. package/dist/components/agent/AgentAvatar.svelte.d.ts +1 -1
  22. package/dist/components/agent/CodeCard.svelte +122 -27
  23. package/dist/components/agent/CodeCard.svelte.d.ts +3 -0
  24. package/dist/components/agent/CodeDiff.svelte +180 -0
  25. package/dist/components/agent/CodeDiff.svelte.d.ts +10 -0
  26. package/dist/components/agent/GenerationModule.svelte +13 -2
  27. package/dist/components/agent/GenerationModule.svelte.d.ts +3 -0
  28. package/dist/components/index.d.ts +4 -0
  29. package/dist/components/index.js +9 -0
  30. package/dist/errors/logTechnicalUserError.d.ts +1 -0
  31. package/dist/errors/logTechnicalUserError.js +37 -0
  32. package/dist/i18n/messages.d.ts +106 -1
  33. package/dist/i18n/messages.js +112 -1
  34. package/dist/i18n/sketchLocales.js +8 -8
  35. package/dist/messageQueue.d.ts +83 -0
  36. package/dist/messageQueue.js +84 -0
  37. package/dist/services/sketchAssistantClient.js +6 -2
  38. package/dist/services/sketchAssistantErrors.d.ts +4 -0
  39. package/dist/services/sketchAssistantErrors.js +22 -0
  40. package/dist/services/sketchAssistantOrchestrator.d.ts +1 -6
  41. package/dist/services/sketchAssistantOrchestrator.js +10 -24
  42. package/dist/services/sketchAssistantReply.js +3 -1
  43. package/dist/stores/chatStore.d.ts +5 -0
  44. package/dist/stores/chatStore.js +21 -0
  45. package/dist/types/agent.d.ts +4 -3
  46. package/dist/types/attachment.d.ts +16 -0
  47. package/dist/types/config.d.ts +6 -0
  48. package/dist/types/index.d.ts +1 -0
  49. package/dist/types/index.js +2 -0
  50. package/dist/types/mention.d.ts +40 -0
  51. package/dist/types/mention.js +8 -0
  52. package/dist/types/message.d.ts +60 -1
  53. package/dist/utils/agentTurn.d.ts +40 -9
  54. package/dist/utils/agentTurn.js +43 -11
  55. package/dist/utils/attachmentProgress.d.ts +12 -0
  56. package/dist/utils/attachmentProgress.js +18 -0
  57. package/dist/utils/bubbleRichFit.d.ts +68 -0
  58. package/dist/utils/bubbleRichFit.js +45 -0
  59. package/dist/utils/bubbleShrinkWrap.d.ts +8 -1
  60. package/dist/utils/bubbleShrinkWrap.js +113 -17
  61. package/dist/utils/codeChanges.d.ts +103 -0
  62. package/dist/utils/codeChanges.js +226 -0
  63. package/dist/utils/codeHighlight.js +1 -0
  64. package/dist/utils/codeStreamFormat.d.ts +5 -2
  65. package/dist/utils/composerMentions.d.ts +96 -0
  66. package/dist/utils/composerMentions.js +217 -0
  67. package/dist/utils/followUps.d.ts +74 -0
  68. package/dist/utils/followUps.js +116 -0
  69. package/dist/utils/generationArchiveStore.d.ts +6 -0
  70. package/dist/utils/generationArchiveStore.js +11 -3
  71. package/dist/utils/index.d.ts +12 -0
  72. package/dist/utils/index.js +20 -0
  73. package/dist/utils/orderedLine.d.ts +29 -0
  74. package/dist/utils/orderedLine.js +17 -0
  75. package/dist/utils/pastedContent.d.ts +99 -0
  76. package/dist/utils/pastedContent.js +258 -0
  77. package/dist/utils/questionCards.d.ts +131 -0
  78. package/dist/utils/questionCards.js +287 -0
  79. package/dist/utils/referenceItems.d.ts +36 -0
  80. package/dist/utils/referenceItems.js +56 -0
  81. package/dist/utils/sentReferenceBadges.d.ts +26 -0
  82. package/dist/utils/sentReferenceBadges.js +32 -0
  83. package/package.json +1 -1
@@ -0,0 +1,258 @@
1
+ /**
2
+ * What a paste into the message box brings in. A picture on the clipboard (a screenshot, an image copied from a page), a
3
+ * file copied in the file manager, or a long text becomes an attachment, the way a file dropped on the box would. A short
4
+ * text is no attachment: the browser types it into the box, as it always did.
5
+ *
6
+ * Pure rules, no DOM and no Svelte: `attachmentsFromPaste` reads what `ClipboardEvent.clipboardData` offers (the tests give
7
+ * it a plain object), so a page with a composer of its own (the workflows assistant) can follow the same rules.
8
+ */
9
+ import { chatLog, chatWarn } from './logger.js';
10
+ /** A pasted text of at least this many characters is attached as a text file instead of being typed into the box. */
11
+ export const PASTED_TEXT_MIN_CHARACTERS = 500;
12
+ /** A pasted text of at least this many lines is attached as a text file, even when its lines are short. */
13
+ export const PASTED_TEXT_MIN_LINES = 12;
14
+ /**
15
+ * The name a pasted text is attached under. It is the name the server stores the file under (and puts in the address of the
16
+ * stored file), so it says nothing of the text: the first words of the text are the label of the chip, which stays on screen.
17
+ */
18
+ export const PASTED_TEXT_FILE_NAME = 'pasted-text.txt';
19
+ /** The name given to a pasted picture that came without one (the extension is added from its type). */
20
+ export const PASTED_IMAGE_FILE_NAME = 'pasted-image';
21
+ /** The name given to a pasted file, that is not a picture, that came without one. */
22
+ export const PASTED_FILE_NAME = 'pasted-file';
23
+ /** Longest label of a pasted text, in characters. The chip cuts it again with an ellipsis where it has less room. */
24
+ export const PASTED_TEXT_LABEL_MAX_CHARACTERS = 60;
25
+ /** The thresholds a page gets when it gives none of its own. */
26
+ export const DEFAULT_PASTED_TEXT_THRESHOLDS = {
27
+ minCharacters: PASTED_TEXT_MIN_CHARACTERS,
28
+ minLines: PASTED_TEXT_MIN_LINES
29
+ };
30
+ /** A line break of any system. */
31
+ const LINE_BREAK = /\r\n|\r|\n/;
32
+ /** A text that is nothing but one address: what some browsers write next to a picture copied from a page. */
33
+ const ONLY_A_LINK = /^(?:https?|file|data):\S+$/i;
34
+ /** The extension of a picture type, for the types whose name after the slash is not the extension. */
35
+ const IMAGE_EXTENSION_BY_SUBTYPE = {
36
+ jpeg: 'jpg',
37
+ 'svg+xml': 'svg',
38
+ 'x-icon': 'ico',
39
+ 'vnd.microsoft.icon': 'ico'
40
+ };
41
+ /** Whether a text is long enough to be attached as a file instead of typed into the box. */
42
+ export function isLongPastedText(text, thresholds = {}) {
43
+ const { minCharacters, minLines } = { ...DEFAULT_PASTED_TEXT_THRESHOLDS, ...thresholds };
44
+ const trimmedText = text.trim();
45
+ if (trimmedText.length === 0)
46
+ return false;
47
+ if (trimmedText.length >= minCharacters)
48
+ return true;
49
+ return trimmedText.split(LINE_BREAK).length >= minLines;
50
+ }
51
+ /**
52
+ * The first words of a text, on one line, for the chip of the file made from it: "Great direction — a sketch of ...".
53
+ * Undefined when the text has no word at all. A line that is too long is cut between two words, when there is a space in its
54
+ * second half to cut at, and else where it reaches the limit (a text with no spaces, like Chinese). Cut by characters a
55
+ * person sees: an emoji is never cut in half.
56
+ */
57
+ export function pastedTextLabel(text) {
58
+ const firstLine = text
59
+ .split(LINE_BREAK)
60
+ .map((line) => line.replace(/\s+/g, ' ').trim())
61
+ .find((line) => line.length > 0);
62
+ if (!firstLine)
63
+ return undefined;
64
+ const visibleCharacters = Array.from(firstLine);
65
+ if (visibleCharacters.length <= PASTED_TEXT_LABEL_MAX_CHARACTERS)
66
+ return firstLine;
67
+ const keptCharacters = visibleCharacters.slice(0, PASTED_TEXT_LABEL_MAX_CHARACTERS);
68
+ const limitFallsBetweenWords = visibleCharacters[PASTED_TEXT_LABEL_MAX_CHARACTERS] === ' ';
69
+ const lastSpaceIndex = keptCharacters.lastIndexOf(' ');
70
+ const earliestWordCut = Math.floor(PASTED_TEXT_LABEL_MAX_CHARACTERS / 2);
71
+ const cutIndex = !limitFallsBetweenWords && lastSpaceIndex >= earliestWordCut ? lastSpaceIndex : PASTED_TEXT_LABEL_MAX_CHARACTERS;
72
+ return `${keptCharacters.slice(0, cutIndex).join('').trimEnd()}…`;
73
+ }
74
+ /** A text as the file a person could have dropped on the box. The type is the plain one a text file has, with no charset. */
75
+ export function textAsFile(text) {
76
+ return new File([text], PASTED_TEXT_FILE_NAME, { type: 'text/plain', lastModified: Date.now() });
77
+ }
78
+ /** The extension that goes with a picture type ("image/jpeg" → "jpg"); "png" when the type says nothing usable. */
79
+ function imageExtensionOf(mediaType) {
80
+ const subtype = mediaType.split('/')[1]?.split(';')[0]?.trim().toLowerCase() ?? '';
81
+ const knownExtension = IMAGE_EXTENSION_BY_SUBTYPE[subtype];
82
+ if (knownExtension)
83
+ return knownExtension;
84
+ return /^[a-z0-9]{1,8}$/.test(subtype) ? subtype : 'png';
85
+ }
86
+ /** The same file with a name when the clipboard gave it none. A file that has a name is returned as it is. */
87
+ function withFallbackName(file) {
88
+ if (file.name && file.name.trim().length > 0)
89
+ return file;
90
+ const fallbackName = file.type.startsWith('image/')
91
+ ? `${PASTED_IMAGE_FILE_NAME}.${imageExtensionOf(file.type)}`
92
+ : PASTED_FILE_NAME;
93
+ return new File([file], fallbackName, { type: file.type, lastModified: file.lastModified });
94
+ }
95
+ /** The files a clipboard offers. Some browsers list a pasted picture only among the items, so those are read when `files` is empty. */
96
+ function filesOnClipboard(source) {
97
+ const listedFiles = Array.from(source.files ?? []).filter((file) => !!file && file.size > 0);
98
+ if (listedFiles.length > 0)
99
+ return listedFiles;
100
+ return Array.from(source.items ?? [])
101
+ .filter((item) => item.kind === 'file')
102
+ .map((item) => item.getAsFile())
103
+ .filter((file) => !!file && file.size > 0);
104
+ }
105
+ /** The plain text of a clipboard, or '' when it has none or the browser refuses to say. */
106
+ function plainTextOnClipboard(source) {
107
+ try {
108
+ return source.getData('text/plain') ?? '';
109
+ }
110
+ catch (error) {
111
+ chatWarn('[pastedContent] The clipboard did not give its text:', error);
112
+ return '';
113
+ }
114
+ }
115
+ /**
116
+ * Whether the text that came with some files adds nothing to them: there is none, or it is only the names (or the paths) of the
117
+ * files, which is what a file manager writes next to a file that was copied, or it is only the link of a picture that was
118
+ * copied from a page. Any other text is what the person copied: a spreadsheet writes its cells as text and a picture of them.
119
+ */
120
+ function textOnlyPointsToFiles(text, files) {
121
+ const lines = text
122
+ .split(LINE_BREAK)
123
+ .map((line) => line.trim())
124
+ .filter((line) => line.length > 0);
125
+ if (lines.length === 0)
126
+ return true;
127
+ if (lines.length === 1 && ONLY_A_LINK.test(lines[0]))
128
+ return true;
129
+ return lines.every((line) => files.some((file) => !!file.name && (line === file.name || line.endsWith(`/${file.name}`) || line.endsWith(`\\${file.name}`))));
130
+ }
131
+ /**
132
+ * Where the number of a repeated name goes: before the extension ("image.png" → "image-2.png"). The extension is what follows
133
+ * the last dot. A name with no dot, one that only starts with it (".env") or one that ends with it has no extension, and the
134
+ * number goes at its end.
135
+ */
136
+ function splitFileName(name) {
137
+ const lastDotIndex = name.lastIndexOf('.');
138
+ const hasExtension = lastDotIndex > 0 && lastDotIndex < name.length - 1;
139
+ return hasExtension
140
+ ? { stem: name.slice(0, lastDotIndex), extension: name.slice(lastDotIndex) }
141
+ : { stem: name, extension: '' };
142
+ }
143
+ /**
144
+ * `name`, or when someone has it already (`takenNames`, compared the way a file manager does, without regard to case) the first
145
+ * of "name-2", "name-3", … that nobody has. The number goes before the extension. A name that is free is returned as it is.
146
+ */
147
+ export function uniqueFileName(name, takenNames) {
148
+ const lowerCaseTakenNames = new Set(Array.from(takenNames, (takenName) => takenName.toLowerCase()));
149
+ if (!lowerCaseTakenNames.has(name.toLowerCase()))
150
+ return name;
151
+ const { stem, extension } = splitFileName(name);
152
+ // The names taken are finite, so a free number is always found.
153
+ for (let copyNumber = 2;; copyNumber += 1) {
154
+ const candidateName = `${stem}-${copyNumber}${extension}`;
155
+ if (!lowerCaseTakenNames.has(candidateName.toLowerCase()))
156
+ return candidateName;
157
+ }
158
+ }
159
+ /**
160
+ * What a paste brought in, each file under a name that differs from the others of the paste and from `takenNames` (the files
161
+ * already attached to the message). A browser calls every screenshot "image.png" and a long text is always attached as
162
+ * "pasted-text.txt": the builder is told the text files it reads by name, and the person is told by name which of them it
163
+ * could not read, so two pastes that share a name cannot be told apart. A paste whose name is free is returned as it is; one
164
+ * that is renamed is a new file with the same bytes, type and date. The list given is not changed.
165
+ */
166
+ export function withUniqueFileNames(pastedAttachments, takenNames = []) {
167
+ const namesInUse = new Set(Array.from(takenNames));
168
+ return pastedAttachments.map((pastedAttachment) => {
169
+ const { file } = pastedAttachment;
170
+ const name = uniqueFileName(file.name, namesInUse);
171
+ // The next file of the same paste is compared with this one too.
172
+ namesInUse.add(name);
173
+ if (name === file.name)
174
+ return pastedAttachment;
175
+ chatLog('[pastedContent] A pasted file takes another name, as its own is in use:', file.name, '→', name);
176
+ return {
177
+ ...pastedAttachment,
178
+ file: new File([file], name, { type: file.type, lastModified: file.lastModified })
179
+ };
180
+ });
181
+ }
182
+ /**
183
+ * How long a picture may take to be made ready before it is attached as it came. The pastes of the chat stand in a line (a
184
+ * paste gets its tile after the paste before it), so a picture that is never made ready, because the browser never finishes
185
+ * reading it, would hold up every paste after it. A big picture takes a second or two; this is far beyond that.
186
+ */
187
+ export const PASTED_IMAGE_PREPARATION_TIME_LIMIT_MS = 15000;
188
+ /**
189
+ * One picture made ready by `prepareImage`, or the picture as it came when that fails, hands nothing back, or takes longer
190
+ * than `timeLimitMilliseconds`: a paste is never lost, and never held up for ever, because of how its picture was prepared.
191
+ * What is not ready in time is left to finish on its own; its result is not used.
192
+ */
193
+ export async function prepareImageWithTimeLimit(file, prepareImage, timeLimitMilliseconds = PASTED_IMAGE_PREPARATION_TIME_LIMIT_MS) {
194
+ let timer;
195
+ let tookTooLong = false;
196
+ try {
197
+ const timeLimitReached = new Promise((resolve) => {
198
+ timer = setTimeout(() => {
199
+ tookTooLong = true;
200
+ resolve(undefined);
201
+ }, timeLimitMilliseconds);
202
+ });
203
+ const preparedFile = await Promise.race([prepareImage(file), timeLimitReached]);
204
+ if (tookTooLong) {
205
+ chatWarn('[pastedContent] A picture took more than', timeLimitMilliseconds, 'ms to prepare, it is attached as it came:', file.name);
206
+ return file;
207
+ }
208
+ return preparedFile || file;
209
+ }
210
+ catch (error) {
211
+ chatWarn('[pastedContent] A picture could not be prepared, it is attached as it came:', file.name, error);
212
+ return file;
213
+ }
214
+ finally {
215
+ clearTimeout(timer);
216
+ }
217
+ }
218
+ /**
219
+ * What a paste brought in, with each picture made ready for upload by `prepareImage` (in the chat: made smaller when it is
220
+ * large, see `prepareChatImageFileForUpload`), the way a dropped picture is. The pictures of a paste are prepared all at once,
221
+ * so a paste of several does not take the longer for it. The result keeps the order and the length of the list; a text or any
222
+ * other file is handed back as it is, label and all, and so is a picture that `prepareImage` left as it was. A picture that
223
+ * cannot be prepared (`prepareImage` threw, or took longer than the time limit) stays as it came: a paste is never lost for
224
+ * that, see `prepareImageWithTimeLimit`. The list given is not changed. The function that prepares is given by the caller, so
225
+ * these rules still need no DOM.
226
+ */
227
+ export async function prepareImagesOfPaste(pastedAttachments, prepareImage, timeLimitMilliseconds = PASTED_IMAGE_PREPARATION_TIME_LIMIT_MS) {
228
+ return Promise.all(pastedAttachments.map(async (pastedAttachment) => {
229
+ const { file } = pastedAttachment;
230
+ if (!file.type.startsWith('image/'))
231
+ return pastedAttachment;
232
+ const preparedFile = await prepareImageWithTimeLimit(file, prepareImage, timeLimitMilliseconds);
233
+ if (preparedFile === file)
234
+ return pastedAttachment;
235
+ chatLog('[pastedContent] A pasted picture was prepared for upload:', file.name, file.size, '→', preparedFile.name, preparedFile.size);
236
+ return { ...pastedAttachment, file: preparedFile };
237
+ }));
238
+ }
239
+ /**
240
+ * What a paste brings in as attachments, in the order of the list: the pictures and files that were pasted, or one text file
241
+ * made from a long pasted text. An empty list means "nothing to attach": the paste is an ordinary one and the browser types
242
+ * the text into the box.
243
+ */
244
+ export function attachmentsFromPaste(source, thresholds = {}) {
245
+ if (!source)
246
+ return [];
247
+ const pastedFiles = filesOnClipboard(source);
248
+ const pastedText = plainTextOnClipboard(source);
249
+ // A screenshot, a picture copied from a page, a file copied in the file manager: they are attached as they are.
250
+ if (pastedFiles.length > 0 && textOnlyPointsToFiles(pastedText, pastedFiles)) {
251
+ return pastedFiles.map((file) => ({ file: withFallbackName(file) }));
252
+ }
253
+ // Chat text, a long brief, a log: it is kept out of the box (which shows a few lines) and attached as a text file.
254
+ if (isLongPastedText(pastedText, thresholds)) {
255
+ return [{ file: textAsFile(pastedText), label: pastedTextLabel(pastedText) }];
256
+ }
257
+ return [];
258
+ }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * The card of questions the assistant puts to the person before it builds, as plain functions on plain data.
3
+ *
4
+ * Each question of the card says on its own whether ONE option or SEVERAL can be picked. The person answers in the card (Next
5
+ * works with nothing picked: that question is skipped, and the assistant decides it itself), or leaves the card by writing in the
6
+ * chat: every question is then shown as skipped, and the message that was typed is what the assistant goes on with. This is how
7
+ * Cursor's questions work.
8
+ *
9
+ * What a card is, as the chat draws it:
10
+ * - open: it is the newest message of the conversation, and nothing was done with it;
11
+ * - answered: the person answered it in the card (the picks are kept on the message, so they are shown);
12
+ * - skipped: no question has a pick: the person Skipped the card, pressed Next on every question with nothing picked, or wrote in
13
+ * the chat instead (a message of the person comes right after the card). This is also known after a reload;
14
+ * - closed: it was answered, but what was picked is not known (a reload brought the conversation back from the server, which keeps
15
+ * the card and not the picks). The card is then drawn as the plain words it was saved with.
16
+ *
17
+ * No other file is imported (only types), so Node can run the tests on this file as it is.
18
+ */
19
+ import type { ChatMessage, QuestionCardAnswer, QuestionCardModel } from '../types/message.js';
20
+ /** The most questions a card draws, whatever the server sent (the gateway sends at most four). */
21
+ export declare const QUESTION_CARD_MAX_QUESTIONS = 8;
22
+ /** The most options one question draws (the gateway sends at most five). */
23
+ export declare const QUESTION_CARD_MAX_OPTIONS = 8;
24
+ /** The most characters of a question, of an option, and of the sentence that introduces the card. */
25
+ export declare const QUESTION_CARD_MAX_QUESTION_CHARS = 300;
26
+ export declare const QUESTION_CARD_MAX_OPTION_CHARS = 300;
27
+ export declare const QUESTION_CARD_MAX_MESSAGE_CHARS = 600;
28
+ /** Between the picks of one question, in the one `answer` text that goes to the server. */
29
+ export declare const QUESTION_ANSWER_LINE_SEPARATOR = "\n";
30
+ /** One question of a closed card, as the summary shows it: the question and the words of what was picked (none: skipped). */
31
+ export interface QuestionCardSummaryRow {
32
+ question: string;
33
+ answers: string[];
34
+ }
35
+ /** What a card of a message is at this moment. */
36
+ export type QuestionCardState = {
37
+ kind: 'open';
38
+ } | {
39
+ kind: 'answered';
40
+ rows: QuestionCardSummaryRow[];
41
+ } | {
42
+ kind: 'skipped';
43
+ rows: QuestionCardSummaryRow[];
44
+ } | {
45
+ kind: 'closed';
46
+ };
47
+ /**
48
+ * The card as the chat draws it, made from what the gateway sent (`metadata.clarification` of an operation that ended in
49
+ * `needs_answers`, or `generation_surface.clarification` of the saved message). Nothing is trusted: a question with no words is
50
+ * left out, so is an option with none, "several picks" means something only when there are at least two options, and a card with
51
+ * no question left is no card (null). The picks of an earlier answer (`result`) are not read from the server's card.
52
+ */
53
+ export declare function questionCardFromClarification(raw: unknown): QuestionCardModel | null;
54
+ /** The card of a message, or null when the message carries none (or one that has no usable question). */
55
+ export declare function questionCardOf(message: ChatMessage | null | undefined): QuestionCardModel | null;
56
+ /**
57
+ * The words a card is saved with in the conversation: the sentence that introduces it, then each question numbered with its options
58
+ * under it. The same lines the gateway saves, so a card the chat adds itself reads the same after a reload. It is what is drawn
59
+ * when the card is closed and its picks are not known.
60
+ */
61
+ export declare function questionCardPlainText(card: QuestionCardModel): string;
62
+ /**
63
+ * A recommended option says so in its own label ("Minimal (Recommended)", in the language of the person). That word is for choosing:
64
+ * once it is chosen it is only noise, so the summary shows the label without it.
65
+ */
66
+ export declare function withoutRecommendedWord(label: string, recommendedWord: string | null | undefined): string;
67
+ /** The picks of one answer, one for each line of it. An answer with nothing in it (a skipped question) has none. */
68
+ export declare function picksOfAnswer(answer: string | null | undefined): string[];
69
+ /**
70
+ * The answers of the card for the picks made in it: one for each question, in the order of the card. `pickedOptionIds` is what the
71
+ * design system's card hands over, the ids of the options picked for each question (an empty list for a question that was skipped).
72
+ * The picks of a question are written in the order of its options, one for each line; a question that takes one answer keeps only
73
+ * the first of them; an id that is not an option of the question is left out.
74
+ */
75
+ export declare function answersFromPicks(card: QuestionCardModel, pickedOptionIds: ReadonlyArray<readonly string[]>): QuestionCardAnswer[];
76
+ /** The answers of a card whose every question was left to the assistant: the same questions, each with an empty answer. */
77
+ export declare function skippedAnswersOf(card: QuestionCardModel): QuestionCardAnswer[];
78
+ /** Whether an answer is a question that was skipped. */
79
+ export declare function isSkippedAnswer(answer: QuestionCardAnswer | null | undefined): boolean;
80
+ /** Whether every answer is a skipped question (a list with no answer is not "skipped": nothing was asked of the person). */
81
+ export declare function areAllAnswersSkipped(answers: readonly QuestionCardAnswer[]): boolean;
82
+ /**
83
+ * The rows of the summary of a card: each question with the words of what was picked. An answer belongs to the question at its
84
+ * place, or, when the lists do not line up, to the question with the same words; a question with no answer is skipped.
85
+ */
86
+ export declare function summaryRowsOf(card: QuestionCardModel, answers: readonly QuestionCardAnswer[]): QuestionCardSummaryRow[];
87
+ /** The rows of a card whose every question was skipped. */
88
+ export declare function skippedRowsOf(card: QuestionCardModel): QuestionCardSummaryRow[];
89
+ /**
90
+ * What the card of the message at `index` is. Null when that message carries no card.
91
+ *
92
+ * What the person did in the card wins (`questionCard.result`, kept on the message). Without it, the conversation says: no message
93
+ * after the card, and it is open; a message of the person right after it, and the person wrote in the chat instead (skipped); a
94
+ * message of the assistant after it, and the card was answered at some point whose picks are not known (closed).
95
+ */
96
+ export declare function questionCardStateOf(messages: readonly ChatMessage[], index: number): QuestionCardState | null;
97
+ /**
98
+ * The card that is waiting for an answer, with the id of the message that holds it: the newest message of the conversation, when
99
+ * it carries a card nobody has done anything with. Null otherwise. Ask it BEFORE the message of the person is added to the
100
+ * conversation: once it is added the card is no longer the newest.
101
+ */
102
+ export declare function openQuestionCardOf(messages: readonly ChatMessage[]): {
103
+ messageId: string;
104
+ card: QuestionCardModel;
105
+ } | null;
106
+ /**
107
+ * A reload replaces the thread with the rows the server saved, and the server saves the card but not what the person picked on it:
108
+ * the picks are only in this session. This carries them over, so a card that was answered does not turn into plain words when the
109
+ * conversation is read back (the creator reads it back a moment after every build). For each loaded reply:
110
+ * - with a card, and a local reply that asks the same questions and has picks (`result`): the loaded card gets those picks;
111
+ * - with no card, and a local reply that has one and the same words: the local card stays (the host put it in the chat and the
112
+ * row was saved without it).
113
+ * A local reply is used for one loaded reply only, and the newest ones are paired first, because both lists end at the newest message.
114
+ * Nothing else is touched; with no card in the local messages, the loaded list itself is returned.
115
+ */
116
+ export declare function keepLocalQuestionCards(loaded: readonly ChatMessage[], local: readonly ChatMessage[]): ChatMessage[];
117
+ /** What became of the question of an older card (the chips of a reply), read from the message of the person that comes after it. */
118
+ export type ChipQuestionOutcome = {
119
+ kind: 'open';
120
+ } | {
121
+ kind: 'answered';
122
+ answer: string;
123
+ } | {
124
+ kind: 'skipped';
125
+ };
126
+ /**
127
+ * What became of an older question card, the one drawn from the chips of a reply (`optionLabels` are their words). While no message
128
+ * of the person comes after the reply it is open. Once one does, the person went on in the chat: if that message holds the words of a
129
+ * chip, that chip is what was answered (picking a chip puts its words in the message box), and if not, the question was skipped.
130
+ */
131
+ export declare function chipQuestionOutcomeOf(messages: readonly ChatMessage[], replyIndex: number, optionLabels: readonly string[]): ChipQuestionOutcome;