@widgetic/chat 0.1.42 → 0.1.44
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 +461 -6
- package/dist/components/Chat.svelte +1078 -87
- package/dist/components/Chat.svelte.d.ts +102 -2
- package/dist/components/ChatComposer.svelte +382 -9
- package/dist/components/ChatComposer.svelte.d.ts +66 -3
- package/dist/components/ChatMessageQueue.svelte +56 -0
- package/dist/components/ChatMessageQueue.svelte.d.ts +20 -0
- package/dist/components/ChatMessages.svelte +485 -50
- package/dist/components/ChatMessages.svelte.d.ts +45 -2
- package/dist/components/ComposerAttachmentsTray.svelte +42 -10
- package/dist/components/ComposerAttachmentsTray.svelte.d.ts +5 -0
- package/dist/components/ComposerMentionChips.svelte +53 -0
- package/dist/components/ComposerMentionChips.svelte.d.ts +15 -0
- package/dist/components/FollowUpCard.svelte +134 -0
- package/dist/components/FollowUpCard.svelte.d.ts +17 -0
- package/dist/components/MentionChip.svelte +41 -0
- package/dist/components/MentionChip.svelte.d.ts +12 -0
- package/dist/components/MentionMenu.svelte +114 -0
- package/dist/components/MentionMenu.svelte.d.ts +19 -0
- package/dist/components/agent/AgentAvatar.svelte +6 -4
- package/dist/components/agent/AgentAvatar.svelte.d.ts +1 -1
- package/dist/components/agent/CodeCard.svelte +122 -27
- package/dist/components/agent/CodeCard.svelte.d.ts +3 -0
- package/dist/components/agent/CodeDiff.svelte +180 -0
- package/dist/components/agent/CodeDiff.svelte.d.ts +10 -0
- package/dist/components/agent/GenerationModule.svelte +13 -2
- package/dist/components/agent/GenerationModule.svelte.d.ts +3 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.js +9 -0
- package/dist/errors/logTechnicalUserError.d.ts +1 -0
- package/dist/errors/logTechnicalUserError.js +37 -0
- package/dist/i18n/messages.d.ts +106 -1
- package/dist/i18n/messages.js +112 -1
- package/dist/i18n/sketchLocales.js +8 -8
- package/dist/messageQueue.d.ts +83 -0
- package/dist/messageQueue.js +84 -0
- package/dist/services/index.d.ts +1 -1
- package/dist/services/sketchAssistantClient.d.ts +27 -0
- package/dist/services/sketchAssistantClient.js +7 -2
- package/dist/services/sketchAssistantErrors.d.ts +4 -0
- package/dist/services/sketchAssistantErrors.js +22 -0
- package/dist/services/sketchAssistantOrchestrator.d.ts +7 -7
- package/dist/services/sketchAssistantOrchestrator.js +11 -24
- package/dist/services/sketchAssistantReply.js +3 -1
- package/dist/stores/chatStore.d.ts +5 -0
- package/dist/stores/chatStore.js +21 -0
- package/dist/types/agent.d.ts +4 -3
- package/dist/types/attachment.d.ts +16 -0
- package/dist/types/config.d.ts +6 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/mention.d.ts +40 -0
- package/dist/types/mention.js +8 -0
- package/dist/types/message.d.ts +60 -1
- package/dist/utils/agentTurn.d.ts +40 -9
- package/dist/utils/agentTurn.js +43 -11
- package/dist/utils/attachmentProgress.d.ts +12 -0
- package/dist/utils/attachmentProgress.js +18 -0
- package/dist/utils/bubbleRichFit.d.ts +68 -0
- package/dist/utils/bubbleRichFit.js +45 -0
- package/dist/utils/bubbleShrinkWrap.d.ts +8 -1
- package/dist/utils/bubbleShrinkWrap.js +113 -17
- package/dist/utils/codeChanges.d.ts +103 -0
- package/dist/utils/codeChanges.js +226 -0
- package/dist/utils/codeHighlight.js +1 -0
- package/dist/utils/codeStreamFormat.d.ts +5 -2
- package/dist/utils/composerMentions.d.ts +96 -0
- package/dist/utils/composerMentions.js +217 -0
- package/dist/utils/followUps.d.ts +74 -0
- package/dist/utils/followUps.js +116 -0
- package/dist/utils/generationArchiveStore.d.ts +6 -0
- package/dist/utils/generationArchiveStore.js +11 -3
- package/dist/utils/index.d.ts +12 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/orderedLine.d.ts +29 -0
- package/dist/utils/orderedLine.js +17 -0
- package/dist/utils/pastedContent.d.ts +99 -0
- package/dist/utils/pastedContent.js +258 -0
- package/dist/utils/questionCards.d.ts +131 -0
- package/dist/utils/questionCards.js +287 -0
- package/dist/utils/referenceItems.d.ts +36 -0
- package/dist/utils/referenceItems.js +56 -0
- package/dist/utils/sentReferenceBadges.d.ts +26 -0
- package/dist/utils/sentReferenceBadges.js +32 -0
- package/package.json +1 -1
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { chatWarn } from './logger.js';
|
|
2
|
+
// --- bounds: the chat reads what a server sent, so it caps every part -----------------------------------------------
|
|
3
|
+
/** The most files read from one round (the gateway sends at most 8; this is only a guard against a runaway). */
|
|
4
|
+
export const MAX_CHANGED_FILES_READ = 50;
|
|
5
|
+
/** The most characters read from one file's patch. A longer patch is cut there and marked as cut. */
|
|
6
|
+
export const MAX_PATCH_CHARACTERS_READ = 200_000;
|
|
7
|
+
/**
|
|
8
|
+
* The most characters read from all the patches of a round together (the gateway sends at most 60,000). What comes after is cut,
|
|
9
|
+
* the files that come after it are listed with no patch, and the changes that are kept (in memory and in the archive of this
|
|
10
|
+
* browser) never grow past it.
|
|
11
|
+
*/
|
|
12
|
+
export const MAX_TOTAL_PATCH_CHARACTERS_READ = 400_000;
|
|
13
|
+
/** The most characters of a path. A longer path is not a path of a widget: the file is dropped. */
|
|
14
|
+
export const MAX_PATH_CHARACTERS_READ = 1_000;
|
|
15
|
+
/** The largest count read for lines and files (a guard against a number that is not a count). */
|
|
16
|
+
const MAX_COUNT_READ = 1_000_000_000;
|
|
17
|
+
const KNOWN_STATUSES = ['added', 'modified', 'deleted', 'renamed'];
|
|
18
|
+
// --- reading what the gateway sent --------------------------------------------------------------------------------
|
|
19
|
+
function isRecord(value) {
|
|
20
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
21
|
+
}
|
|
22
|
+
/** A count: a whole number from 0 up. Anything else (text, a negative, NaN, a float) reads as the whole part or 0. */
|
|
23
|
+
function readCount(value) {
|
|
24
|
+
if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0)
|
|
25
|
+
return 0;
|
|
26
|
+
return Math.min(MAX_COUNT_READ, Math.floor(value));
|
|
27
|
+
}
|
|
28
|
+
function readStatus(value) {
|
|
29
|
+
return KNOWN_STATUSES.find((status) => status === value) ?? 'modified';
|
|
30
|
+
}
|
|
31
|
+
/** One file of the changes, or null when it has no usable path. */
|
|
32
|
+
function readCodeChangeFile(candidate) {
|
|
33
|
+
if (!isRecord(candidate))
|
|
34
|
+
return null;
|
|
35
|
+
const path = typeof candidate.path === 'string' ? candidate.path.trim() : '';
|
|
36
|
+
if (path === '' || path.length > MAX_PATH_CHARACTERS_READ)
|
|
37
|
+
return null;
|
|
38
|
+
const sentPatch = typeof candidate.patch === 'string' ? candidate.patch : '';
|
|
39
|
+
const isPatchTooLong = sentPatch.length > MAX_PATCH_CHARACTERS_READ;
|
|
40
|
+
return {
|
|
41
|
+
path,
|
|
42
|
+
status: readStatus(candidate.status),
|
|
43
|
+
additions: readCount(candidate.additions),
|
|
44
|
+
deletions: readCount(candidate.deletions),
|
|
45
|
+
patch: isPatchTooLong ? sentPatch.slice(0, MAX_PATCH_CHARACTERS_READ) : sentPatch,
|
|
46
|
+
truncated: candidate.truncated === true || isPatchTooLong
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* The changes of a round from what a server sent, or null when there is nothing to show. It never throws: a value that is not
|
|
51
|
+
* the expected shape reads as "no changes", and a file that is not usable is left out of the others.
|
|
52
|
+
*/
|
|
53
|
+
export function readCodeChanges(raw) {
|
|
54
|
+
try {
|
|
55
|
+
if (!isRecord(raw) || !Array.isArray(raw.files))
|
|
56
|
+
return null;
|
|
57
|
+
const files = [];
|
|
58
|
+
for (const candidate of raw.files.slice(0, MAX_CHANGED_FILES_READ)) {
|
|
59
|
+
const file = readCodeChangeFile(candidate);
|
|
60
|
+
if (file)
|
|
61
|
+
files.push(file);
|
|
62
|
+
}
|
|
63
|
+
if (files.length === 0)
|
|
64
|
+
return null;
|
|
65
|
+
// The patches share one bound: the first files keep theirs whole, the one that crosses it is cut, the rest have none
|
|
66
|
+
let remainingPatchCharacters = MAX_TOTAL_PATCH_CHARACTERS_READ;
|
|
67
|
+
for (const file of files) {
|
|
68
|
+
if (file.patch.length > remainingPatchCharacters) {
|
|
69
|
+
file.patch = file.patch.slice(0, remainingPatchCharacters);
|
|
70
|
+
file.truncated = true;
|
|
71
|
+
}
|
|
72
|
+
remainingPatchCharacters -= file.patch.length;
|
|
73
|
+
}
|
|
74
|
+
const filesBeyondTheGuard = Math.max(0, raw.files.length - MAX_CHANGED_FILES_READ);
|
|
75
|
+
return { files, omittedFiles: Math.min(MAX_COUNT_READ, readCount(raw.omittedFiles) + filesBeyondTheGuard) };
|
|
76
|
+
}
|
|
77
|
+
catch (error) {
|
|
78
|
+
chatWarn('[Chat] code changes: what was sent could not be read, no changes are shown:', error);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The changes of a round from the metadata of a completed operation (`metadata.codeChanges`), or null when the operation has none:
|
|
84
|
+
* an old gateway, a client that did not ask, a first build, a build that was not kept, or a round that changed nothing.
|
|
85
|
+
*/
|
|
86
|
+
export function readCodeChangesFromMetadata(metadata) {
|
|
87
|
+
if (!metadata || !Object.prototype.hasOwnProperty.call(metadata, 'codeChanges'))
|
|
88
|
+
return null;
|
|
89
|
+
return readCodeChanges(metadata.codeChanges);
|
|
90
|
+
}
|
|
91
|
+
/** The totals of the changes, for the header of the card. */
|
|
92
|
+
export function summarizeCodeChanges(changes) {
|
|
93
|
+
let additions = 0;
|
|
94
|
+
let deletions = 0;
|
|
95
|
+
for (const file of changes.files) {
|
|
96
|
+
additions += file.additions;
|
|
97
|
+
deletions += file.deletions;
|
|
98
|
+
}
|
|
99
|
+
return {
|
|
100
|
+
shownFiles: changes.files.length,
|
|
101
|
+
totalFiles: changes.files.length + changes.omittedFiles,
|
|
102
|
+
additions,
|
|
103
|
+
deletions
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
// --- turning a patch into rows -----------------------------------------------------------------------------------
|
|
107
|
+
/** `@@ -12,6 +12,7 @@`: the start of each range, and the count when it is not 1. */
|
|
108
|
+
const HUNK_HEADER = /^@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/;
|
|
109
|
+
/**
|
|
110
|
+
* The hunks of a patch, with the line numbers of both sides. Lines before the first header are ignored (a file header that a
|
|
111
|
+
* host left in, for example). A line that belongs to no kind is skipped. The counts in a header are only read to tell a range
|
|
112
|
+
* that has lines from one that names the line before it; the rows come from what the hunk really holds, so a patch that was cut
|
|
113
|
+
* in the middle of a hunk shows the lines it has and nothing more.
|
|
114
|
+
*/
|
|
115
|
+
export function parseUnifiedPatch(patch) {
|
|
116
|
+
const hunks = [];
|
|
117
|
+
if (patch === '')
|
|
118
|
+
return hunks;
|
|
119
|
+
const patchLines = patch.split('\n');
|
|
120
|
+
let currentHunk = null;
|
|
121
|
+
let nextOldNumber = 0;
|
|
122
|
+
let nextNewNumber = 0;
|
|
123
|
+
/** The last line of the new file that the hunks so far have reached. */
|
|
124
|
+
let previousHunkNewEnd = 0;
|
|
125
|
+
let skippedLineCount = 0;
|
|
126
|
+
/** Closes the hunk being read: the new file has been read up to the line before the next number. */
|
|
127
|
+
const closeCurrentHunk = () => {
|
|
128
|
+
if (currentHunk)
|
|
129
|
+
previousHunkNewEnd = nextNewNumber - 1;
|
|
130
|
+
};
|
|
131
|
+
for (let lineIndex = 0; lineIndex < patchLines.length; lineIndex++) {
|
|
132
|
+
const patchLine = patchLines[lineIndex];
|
|
133
|
+
const header = HUNK_HEADER.exec(patchLine);
|
|
134
|
+
if (header) {
|
|
135
|
+
closeCurrentHunk();
|
|
136
|
+
const oldStart = Number(header[1]);
|
|
137
|
+
const oldCount = header[2] === undefined ? 1 : Number(header[2]);
|
|
138
|
+
const newStart = Number(header[3]);
|
|
139
|
+
const newCount = header[4] === undefined ? 1 : Number(header[4]);
|
|
140
|
+
// A range of zero lines names the line before it, so its first line is the next one
|
|
141
|
+
nextOldNumber = oldCount === 0 ? oldStart + 1 : oldStart;
|
|
142
|
+
nextNewNumber = newCount === 0 ? newStart + 1 : newStart;
|
|
143
|
+
currentHunk = { unchangedLinesBefore: Math.max(0, nextNewNumber - previousHunkNewEnd - 1), lines: [] };
|
|
144
|
+
hunks.push(currentHunk);
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
// Before the first header there is no hunk to put a line in
|
|
148
|
+
if (!currentHunk)
|
|
149
|
+
continue;
|
|
150
|
+
const marker = patchLine[0];
|
|
151
|
+
if (marker === '+') {
|
|
152
|
+
currentHunk.lines.push({ kind: 'insert', oldNumber: null, newNumber: nextNewNumber, text: patchLine.slice(1) });
|
|
153
|
+
nextNewNumber += 1;
|
|
154
|
+
}
|
|
155
|
+
else if (marker === '-') {
|
|
156
|
+
currentHunk.lines.push({ kind: 'delete', oldNumber: nextOldNumber, newNumber: null, text: patchLine.slice(1) });
|
|
157
|
+
nextOldNumber += 1;
|
|
158
|
+
}
|
|
159
|
+
else if (marker === ' ' || (patchLine === '' && lineIndex < patchLines.length - 1)) {
|
|
160
|
+
// An empty line inside the patch is an empty line of the file whose leading space a transport trimmed
|
|
161
|
+
currentHunk.lines.push({
|
|
162
|
+
kind: 'context',
|
|
163
|
+
oldNumber: nextOldNumber,
|
|
164
|
+
newNumber: nextNewNumber,
|
|
165
|
+
text: patchLine.slice(1)
|
|
166
|
+
});
|
|
167
|
+
nextOldNumber += 1;
|
|
168
|
+
nextNewNumber += 1;
|
|
169
|
+
}
|
|
170
|
+
else if (marker !== '\\' && patchLine !== '') {
|
|
171
|
+
// `` and the empty end of the text are not lines; anything else is not a diff line
|
|
172
|
+
skippedLineCount += 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (skippedLineCount > 0) {
|
|
176
|
+
chatWarn(`[Chat] code changes: ${skippedLineCount} line(s) of a patch were not diff lines and were skipped.`);
|
|
177
|
+
}
|
|
178
|
+
return hunks;
|
|
179
|
+
}
|
|
180
|
+
// --- what kind of code a path is --------------------------------------------------------------------------------
|
|
181
|
+
/** The kind of code of a file, from its extension, for the words that colour it. A file of no known kind is plain text. */
|
|
182
|
+
export function codeKindOfPath(path) {
|
|
183
|
+
const fileName = path.slice(path.lastIndexOf('/') + 1).toLowerCase();
|
|
184
|
+
const extension = fileName.includes('.') ? fileName.slice(fileName.lastIndexOf('.') + 1) : '';
|
|
185
|
+
switch (extension) {
|
|
186
|
+
case 'js':
|
|
187
|
+
case 'jsx':
|
|
188
|
+
case 'mjs':
|
|
189
|
+
case 'cjs':
|
|
190
|
+
case 'ts':
|
|
191
|
+
case 'tsx':
|
|
192
|
+
case 'mts':
|
|
193
|
+
case 'cts':
|
|
194
|
+
return 'script';
|
|
195
|
+
case 'html':
|
|
196
|
+
case 'htm':
|
|
197
|
+
case 'svelte':
|
|
198
|
+
case 'vue':
|
|
199
|
+
case 'xml':
|
|
200
|
+
case 'svg':
|
|
201
|
+
return 'markup';
|
|
202
|
+
case 'json':
|
|
203
|
+
return 'json';
|
|
204
|
+
case 'css':
|
|
205
|
+
return 'css';
|
|
206
|
+
default:
|
|
207
|
+
return 'plain';
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
// --- the changes as text, to copy ---------------------------------------------------------------------------------
|
|
211
|
+
/** The old and new name of a file in the header of a unified diff: `/dev/null` stands where a file did not exist. */
|
|
212
|
+
function patchHeaderOf(file) {
|
|
213
|
+
const oldName = file.status === 'added' ? '/dev/null' : `a/${file.path}`;
|
|
214
|
+
const newName = file.status === 'deleted' ? '/dev/null' : `b/${file.path}`;
|
|
215
|
+
return `--- ${oldName}\n+++ ${newName}`;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* The changes as one unified diff, for the Copy button: each file with its header, then its hunks. A patch that was cut ends
|
|
219
|
+
* where it was cut, which is what the card shows. Files that were not sent are not in it.
|
|
220
|
+
*/
|
|
221
|
+
export function patchTextOfChanges(changes) {
|
|
222
|
+
const filesWithAPatch = changes.files.filter((file) => file.patch !== '');
|
|
223
|
+
if (filesWithAPatch.length === 0)
|
|
224
|
+
return '';
|
|
225
|
+
return filesWithAPatch.map((file) => `${patchHeaderOf(file)}\n${file.patch}`).join('\n') + '\n';
|
|
226
|
+
}
|
|
@@ -30,8 +30,11 @@ export interface LineEndSnapshot {
|
|
|
30
30
|
* @param keepLast How many of the last line breaks to keep (the cuts worth trying are the newest ones).
|
|
31
31
|
*/
|
|
32
32
|
export declare function scanLineEnds(source: string, keepLast?: number): LineEndSnapshot[];
|
|
33
|
-
/**
|
|
34
|
-
|
|
33
|
+
/**
|
|
34
|
+
* What the code is, for the words that colour it and for whether Prettier can format it. `css` is only ever the kind of a changed
|
|
35
|
+
* file, told by its path (see `codeKindOfPath`): `detectCodeKind` reads the start of streamed code and never guesses it.
|
|
36
|
+
*/
|
|
37
|
+
export type CodeKind = 'script' | 'markup' | 'json' | 'css' | 'plain';
|
|
35
38
|
/** Reads the start of the code to tell what it is. Code that starts in the middle of a file is plain: nothing is guessed. */
|
|
36
39
|
export declare function detectCodeKind(source: string): CodeKind;
|
|
37
40
|
/** The number of lines of the code, the way an editor counts them (a last line break does not start a line). */
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules of the `@` menu in the message box: when the caret is inside a mention, which rows the menu shows, how the arrow keys
|
|
3
|
+
* move through them, what a pick writes into the text, and which links are offered as a one-tap pick.
|
|
4
|
+
*
|
|
5
|
+
* The chat knows nothing of what a row is: the page hands it lists of `{ id, name }` (see `MentionSource`) and gets the picks back.
|
|
6
|
+
* Only a picked row is a mention. A word that starts with `@` and was typed by hand is text, and goes to the assistant as text.
|
|
7
|
+
*
|
|
8
|
+
* Plain TypeScript with no Svelte in it, so the tests run it in Node as it is.
|
|
9
|
+
*/
|
|
10
|
+
import type { ComposerMention, MentionSource, MentionSourceItem } from '../types/mention.js';
|
|
11
|
+
/** The most picks one message holds when the page does not say (`mentionLimit` of `Chat`). */
|
|
12
|
+
export declare const DEFAULT_MENTION_LIMIT = 5;
|
|
13
|
+
/** The most one-tap link offers the box shows at once, so a message full of links does not fill the tray. */
|
|
14
|
+
export declare const MAX_MENTION_LINK_HINTS = 3;
|
|
15
|
+
export interface ActiveMentionTrigger {
|
|
16
|
+
/** Where the `@` is in the text. */
|
|
17
|
+
start: number;
|
|
18
|
+
/** What was typed after it, up to the caret (no whitespace in it). */
|
|
19
|
+
query: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Whether the caret sits inside a mention being typed: an `@` at the start of the text or right after whitespace, and no
|
|
23
|
+
* whitespace between it and the caret. An `@` inside a word (`name@example.com`) is not one.
|
|
24
|
+
*/
|
|
25
|
+
export declare function findActiveMentionTrigger(text: string, caret: number): ActiveMentionTrigger | null;
|
|
26
|
+
/** Why a row cannot be picked: the page said so (`selectable: false`), or the message already holds as many picks as it may. */
|
|
27
|
+
export type MentionRowUnavailable = 'source' | 'limit';
|
|
28
|
+
export interface MentionRow {
|
|
29
|
+
/** Different for every row, whatever its kind. */
|
|
30
|
+
key: string;
|
|
31
|
+
kind: string;
|
|
32
|
+
/** The heading of the row's group (the page's own words). */
|
|
33
|
+
groupLabel: string;
|
|
34
|
+
item: MentionSourceItem;
|
|
35
|
+
/** Whether a pick is taken. A row that is not selectable is shown dimmed, with the reason, and is passed over by the arrow keys. */
|
|
36
|
+
selectable: boolean;
|
|
37
|
+
/** Why it cannot be picked, or `null`. */
|
|
38
|
+
unavailable: MentionRowUnavailable | null;
|
|
39
|
+
}
|
|
40
|
+
/** A key that is different for every kind and id, even for kinds and ids that run together (`a:b` + `c` and `a` + `b:c`). */
|
|
41
|
+
export declare function mentionKey(kind: string, id: string): string;
|
|
42
|
+
/** The id of the option at a place in the menu: the id of the list and the place, so the text box can say which one is highlighted. */
|
|
43
|
+
export declare function mentionOptionId(listId: string, index: number): string;
|
|
44
|
+
/** Whether what the person typed after `@` is in a row's name or in its caption, in any case. Nothing typed matches every row. */
|
|
45
|
+
export declare function mentionItemMatches(item: MentionSourceItem, query: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* The rows for what was typed after `@`, in the order the page gave its lists. A row that is already picked can be picked again
|
|
48
|
+
* (it writes its name once more and the chip stays one); once the message holds as many picks as it may, the others stay in the
|
|
49
|
+
* menu, dimmed, saying so. A row the page gave twice (the same kind and id) is shown once, and one with no id or no name is left out.
|
|
50
|
+
*/
|
|
51
|
+
export declare function buildMentionRows(sources: readonly MentionSource[] | null | undefined, query: string, picked?: readonly ComposerMention[], limit?: number): MentionRow[];
|
|
52
|
+
/** Whether the rows are of more than one kind, which is when the menu labels its groups (one group needs no heading). */
|
|
53
|
+
export declare function mentionRowsHaveSeveralKinds(rows: readonly MentionRow[]): boolean;
|
|
54
|
+
/** The row to highlight when the menu opens or its rows change: the first one that can be picked (the first row when none can). */
|
|
55
|
+
export declare function firstSelectableRowIndex(rows: readonly MentionRow[]): number;
|
|
56
|
+
/**
|
|
57
|
+
* The row an arrow key moves the highlight to: the next one that can be picked in that direction, going round at the ends. A row
|
|
58
|
+
* that cannot be picked is passed over, so Enter never lands on one. When none can be picked the highlight stays where it is.
|
|
59
|
+
*/
|
|
60
|
+
export declare function nextSelectableRowIndex(rows: readonly MentionRow[], from: number, direction: 1 | -1): number;
|
|
61
|
+
/**
|
|
62
|
+
* The text with `@{name} ` where the person was typing the mention: from the `@` to the caret is replaced. A space that already
|
|
63
|
+
* follows the caret is the one that ends the mention, so none is added to it.
|
|
64
|
+
*/
|
|
65
|
+
export declare function insertMentionText(text: string, triggerStart: number, caret: number, name: string): string;
|
|
66
|
+
/** Where the caret goes after `insertMentionText`: just after the space that ends the mention, ready to go on writing. */
|
|
67
|
+
export declare function caretAfterMentionInsert(triggerStart: number, name: string): number;
|
|
68
|
+
/** Whether a pick of this kind and id is in the list. */
|
|
69
|
+
export declare function hasMention(mentions: readonly ComposerMention[], kind: string, id: string): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* The picks with one more, unless it is there already (the same kind and id: ids of two kinds may be alike, and are two picks)
|
|
72
|
+
* or the message already holds as many as it may.
|
|
73
|
+
*/
|
|
74
|
+
export declare function addMention(existing: readonly ComposerMention[], mention: ComposerMention, limit?: number): readonly ComposerMention[];
|
|
75
|
+
export declare function removeMention(existing: readonly ComposerMention[], kind: string, id: string): readonly ComposerMention[];
|
|
76
|
+
/**
|
|
77
|
+
* The part of a site's name that belongs to whoever owns it: `mcp.figma.com` and `www.figma.com` both give `figma.com`. This is
|
|
78
|
+
* not the public suffix list: it takes the last two names, or the last three when the end is a country code behind a common second
|
|
79
|
+
* level (`bbc.co.uk`). A wrong match only offers a pick that the person can ignore, and nothing is read until they send.
|
|
80
|
+
*/
|
|
81
|
+
export declare function registrableDomain(host: string): string;
|
|
82
|
+
/** The sites of the `http` and `https` links in a text, each once, in the order they appear. */
|
|
83
|
+
export declare function linkHostsOfText(text: string): string[];
|
|
84
|
+
export interface MentionLinkHint {
|
|
85
|
+
key: string;
|
|
86
|
+
kind: string;
|
|
87
|
+
id: string;
|
|
88
|
+
name: string;
|
|
89
|
+
/** The site of the link in the message that matched. */
|
|
90
|
+
host: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The picks to offer for the links in a text: a row whose `linkHosts` hold the domain of a link in the text, that can be picked,
|
|
94
|
+
* and that is not picked yet. At most `MAX_MENTION_LINK_HINTS`, and none once the message holds as many picks as it may.
|
|
95
|
+
*/
|
|
96
|
+
export declare function findMentionLinkHints(text: string, sources: readonly MentionSource[] | null | undefined, picked?: readonly ComposerMention[], limit?: number): MentionLinkHint[];
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules of the `@` menu in the message box: when the caret is inside a mention, which rows the menu shows, how the arrow keys
|
|
3
|
+
* move through them, what a pick writes into the text, and which links are offered as a one-tap pick.
|
|
4
|
+
*
|
|
5
|
+
* The chat knows nothing of what a row is: the page hands it lists of `{ id, name }` (see `MentionSource`) and gets the picks back.
|
|
6
|
+
* Only a picked row is a mention. A word that starts with `@` and was typed by hand is text, and goes to the assistant as text.
|
|
7
|
+
*
|
|
8
|
+
* Plain TypeScript with no Svelte in it, so the tests run it in Node as it is.
|
|
9
|
+
*/
|
|
10
|
+
import { splitTextIntoLinks } from './linkifyText.js';
|
|
11
|
+
/** The most picks one message holds when the page does not say (`mentionLimit` of `Chat`). */
|
|
12
|
+
export const DEFAULT_MENTION_LIMIT = 5;
|
|
13
|
+
/** The most one-tap link offers the box shows at once, so a message full of links does not fill the tray. */
|
|
14
|
+
export const MAX_MENTION_LINK_HINTS = 3;
|
|
15
|
+
/**
|
|
16
|
+
* Whether the caret sits inside a mention being typed: an `@` at the start of the text or right after whitespace, and no
|
|
17
|
+
* whitespace between it and the caret. An `@` inside a word (`name@example.com`) is not one.
|
|
18
|
+
*/
|
|
19
|
+
export function findActiveMentionTrigger(text, caret) {
|
|
20
|
+
const source = String(text ?? '');
|
|
21
|
+
const end = Number.isFinite(caret) ? Math.min(Math.max(0, Math.trunc(caret)), source.length) : source.length;
|
|
22
|
+
const upToCaret = source.slice(0, end);
|
|
23
|
+
const start = upToCaret.lastIndexOf('@');
|
|
24
|
+
if (start === -1)
|
|
25
|
+
return null;
|
|
26
|
+
if (start > 0 && !/\s/.test(upToCaret[start - 1] ?? ''))
|
|
27
|
+
return null;
|
|
28
|
+
const query = upToCaret.slice(start + 1);
|
|
29
|
+
if (/\s/.test(query))
|
|
30
|
+
return null;
|
|
31
|
+
return { start, query };
|
|
32
|
+
}
|
|
33
|
+
/** A key that is different for every kind and id, even for kinds and ids that run together (`a:b` + `c` and `a` + `b:c`). */
|
|
34
|
+
export function mentionKey(kind, id) {
|
|
35
|
+
return `${kind.length}.${kind}.${id}`;
|
|
36
|
+
}
|
|
37
|
+
/** The id of the option at a place in the menu: the id of the list and the place, so the text box can say which one is highlighted. */
|
|
38
|
+
export function mentionOptionId(listId, index) {
|
|
39
|
+
return `${listId}-option-${index}`;
|
|
40
|
+
}
|
|
41
|
+
function isUsableItem(item) {
|
|
42
|
+
return !!item && typeof item.id === 'string' && item.id !== '' && typeof item.name === 'string' && item.name.trim() !== '';
|
|
43
|
+
}
|
|
44
|
+
function usableLimit(limit) {
|
|
45
|
+
return typeof limit === 'number' && Number.isFinite(limit) && limit >= 1 ? Math.floor(limit) : DEFAULT_MENTION_LIMIT;
|
|
46
|
+
}
|
|
47
|
+
/** Whether what the person typed after `@` is in a row's name or in its caption, in any case. Nothing typed matches every row. */
|
|
48
|
+
export function mentionItemMatches(item, query) {
|
|
49
|
+
const wanted = String(query ?? '').trim().toLowerCase();
|
|
50
|
+
if (wanted === '')
|
|
51
|
+
return true;
|
|
52
|
+
return item.name.toLowerCase().includes(wanted) || (item.caption ?? '').toLowerCase().includes(wanted);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The rows for what was typed after `@`, in the order the page gave its lists. A row that is already picked can be picked again
|
|
56
|
+
* (it writes its name once more and the chip stays one); once the message holds as many picks as it may, the others stay in the
|
|
57
|
+
* menu, dimmed, saying so. A row the page gave twice (the same kind and id) is shown once, and one with no id or no name is left out.
|
|
58
|
+
*/
|
|
59
|
+
export function buildMentionRows(sources, query, picked = [], limit = DEFAULT_MENTION_LIMIT) {
|
|
60
|
+
const rows = [];
|
|
61
|
+
const seen = new Set();
|
|
62
|
+
const roomLeft = picked.length < usableLimit(limit);
|
|
63
|
+
for (const source of sources ?? []) {
|
|
64
|
+
if (typeof source?.kind !== 'string' || source.kind === '')
|
|
65
|
+
continue;
|
|
66
|
+
for (const item of source.items ?? []) {
|
|
67
|
+
if (!isUsableItem(item) || !mentionItemMatches(item, query))
|
|
68
|
+
continue;
|
|
69
|
+
const key = mentionKey(source.kind, item.id);
|
|
70
|
+
if (seen.has(key))
|
|
71
|
+
continue;
|
|
72
|
+
seen.add(key);
|
|
73
|
+
const alreadyPicked = picked.some((mention) => mention.kind === source.kind && mention.id === item.id);
|
|
74
|
+
const unavailable = item.selectable === false ? 'source' : !alreadyPicked && !roomLeft ? 'limit' : null;
|
|
75
|
+
rows.push({
|
|
76
|
+
key,
|
|
77
|
+
kind: source.kind,
|
|
78
|
+
groupLabel: typeof source.label === 'string' ? source.label : '',
|
|
79
|
+
item,
|
|
80
|
+
selectable: unavailable === null,
|
|
81
|
+
unavailable,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return rows;
|
|
86
|
+
}
|
|
87
|
+
/** Whether the rows are of more than one kind, which is when the menu labels its groups (one group needs no heading). */
|
|
88
|
+
export function mentionRowsHaveSeveralKinds(rows) {
|
|
89
|
+
return new Set(rows.map((row) => row.kind)).size > 1;
|
|
90
|
+
}
|
|
91
|
+
/** The row to highlight when the menu opens or its rows change: the first one that can be picked (the first row when none can). */
|
|
92
|
+
export function firstSelectableRowIndex(rows) {
|
|
93
|
+
const index = rows.findIndex((row) => row.selectable);
|
|
94
|
+
return index === -1 ? 0 : index;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* The row an arrow key moves the highlight to: the next one that can be picked in that direction, going round at the ends. A row
|
|
98
|
+
* that cannot be picked is passed over, so Enter never lands on one. When none can be picked the highlight stays where it is.
|
|
99
|
+
*/
|
|
100
|
+
export function nextSelectableRowIndex(rows, from, direction) {
|
|
101
|
+
const count = rows.length;
|
|
102
|
+
for (let step = 1; step <= count; step += 1) {
|
|
103
|
+
const index = (((from + direction * step) % count) + count) % count;
|
|
104
|
+
if (rows[index]?.selectable)
|
|
105
|
+
return index;
|
|
106
|
+
}
|
|
107
|
+
return from;
|
|
108
|
+
}
|
|
109
|
+
// --- what a pick writes into the text ----------------------------------------------------------------------------------
|
|
110
|
+
/**
|
|
111
|
+
* The text with `@{name} ` where the person was typing the mention: from the `@` to the caret is replaced. A space that already
|
|
112
|
+
* follows the caret is the one that ends the mention, so none is added to it.
|
|
113
|
+
*/
|
|
114
|
+
export function insertMentionText(text, triggerStart, caret, name) {
|
|
115
|
+
const before = text.slice(0, triggerStart);
|
|
116
|
+
const after = text.slice(caret);
|
|
117
|
+
return `${before}@${name}${after.startsWith(' ') ? '' : ' '}${after}`;
|
|
118
|
+
}
|
|
119
|
+
/** Where the caret goes after `insertMentionText`: just after the space that ends the mention, ready to go on writing. */
|
|
120
|
+
export function caretAfterMentionInsert(triggerStart, name) {
|
|
121
|
+
return triggerStart + name.length + 2;
|
|
122
|
+
}
|
|
123
|
+
// --- the picks of a message --------------------------------------------------------------------------------------------
|
|
124
|
+
/** Whether a pick of this kind and id is in the list. */
|
|
125
|
+
export function hasMention(mentions, kind, id) {
|
|
126
|
+
return mentions.some((mention) => mention.kind === kind && mention.id === id);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The picks with one more, unless it is there already (the same kind and id: ids of two kinds may be alike, and are two picks)
|
|
130
|
+
* or the message already holds as many as it may.
|
|
131
|
+
*/
|
|
132
|
+
export function addMention(existing, mention, limit = DEFAULT_MENTION_LIMIT) {
|
|
133
|
+
if (hasMention(existing, mention.kind, mention.id))
|
|
134
|
+
return existing;
|
|
135
|
+
if (existing.length >= usableLimit(limit))
|
|
136
|
+
return existing;
|
|
137
|
+
return [...existing, { kind: mention.kind, id: mention.id, name: mention.name }];
|
|
138
|
+
}
|
|
139
|
+
export function removeMention(existing, kind, id) {
|
|
140
|
+
return existing.filter((mention) => !(mention.kind === kind && mention.id === id));
|
|
141
|
+
}
|
|
142
|
+
// --- links that are offered as a pick ------------------------------------------------------------------------------------
|
|
143
|
+
/**
|
|
144
|
+
* The part of a site's name that belongs to whoever owns it: `mcp.figma.com` and `www.figma.com` both give `figma.com`. This is
|
|
145
|
+
* not the public suffix list: it takes the last two names, or the last three when the end is a country code behind a common second
|
|
146
|
+
* level (`bbc.co.uk`). A wrong match only offers a pick that the person can ignore, and nothing is read until they send.
|
|
147
|
+
*/
|
|
148
|
+
export function registrableDomain(host) {
|
|
149
|
+
const cleaned = String(host ?? '')
|
|
150
|
+
.trim()
|
|
151
|
+
.toLowerCase()
|
|
152
|
+
.replace(/^\[|\]$/g, '')
|
|
153
|
+
.replace(/\.$/, '');
|
|
154
|
+
if (cleaned === '')
|
|
155
|
+
return '';
|
|
156
|
+
// A number or an IPv6 address names one machine, not a domain
|
|
157
|
+
if (/^\d{1,3}(\.\d{1,3}){3}$/.test(cleaned) || cleaned.includes(':'))
|
|
158
|
+
return cleaned;
|
|
159
|
+
const labels = cleaned.split('.');
|
|
160
|
+
if (labels.length <= 2)
|
|
161
|
+
return cleaned;
|
|
162
|
+
const last = labels[labels.length - 1] ?? '';
|
|
163
|
+
const secondLast = labels[labels.length - 2] ?? '';
|
|
164
|
+
const keep = last.length === 2 && ['ac', 'co', 'com', 'edu', 'gov', 'net', 'org'].includes(secondLast) ? 3 : 2;
|
|
165
|
+
return labels.slice(-keep).join('.');
|
|
166
|
+
}
|
|
167
|
+
/** The sites of the `http` and `https` links in a text, each once, in the order they appear. */
|
|
168
|
+
export function linkHostsOfText(text) {
|
|
169
|
+
const hosts = [];
|
|
170
|
+
for (const segment of splitTextIntoLinks(String(text ?? ''))) {
|
|
171
|
+
if (segment.type !== 'link')
|
|
172
|
+
continue;
|
|
173
|
+
try {
|
|
174
|
+
const host = new URL(segment.href).hostname.toLowerCase();
|
|
175
|
+
if (host !== '' && !hosts.includes(host))
|
|
176
|
+
hosts.push(host);
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
/* not an address after all: nothing to offer for it */
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return hosts;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* The picks to offer for the links in a text: a row whose `linkHosts` hold the domain of a link in the text, that can be picked,
|
|
186
|
+
* and that is not picked yet. At most `MAX_MENTION_LINK_HINTS`, and none once the message holds as many picks as it may.
|
|
187
|
+
*/
|
|
188
|
+
export function findMentionLinkHints(text, sources, picked = [], limit = DEFAULT_MENTION_LIMIT) {
|
|
189
|
+
// The box asks on every key: with no list, or a message that is full, there is nothing to look for, so the text is not read
|
|
190
|
+
if (!sources || sources.length === 0 || picked.length >= usableLimit(limit))
|
|
191
|
+
return [];
|
|
192
|
+
const textHosts = linkHostsOfText(text).map((host) => ({ host, domain: registrableDomain(host) }));
|
|
193
|
+
if (textHosts.length === 0)
|
|
194
|
+
return [];
|
|
195
|
+
const hints = [];
|
|
196
|
+
const seen = new Set();
|
|
197
|
+
for (const source of sources ?? []) {
|
|
198
|
+
if (typeof source?.kind !== 'string' || source.kind === '')
|
|
199
|
+
continue;
|
|
200
|
+
for (const item of source.items ?? []) {
|
|
201
|
+
if (!isUsableItem(item) || item.selectable === false || !item.linkHosts || item.linkHosts.length === 0)
|
|
202
|
+
continue;
|
|
203
|
+
const key = mentionKey(source.kind, item.id);
|
|
204
|
+
if (seen.has(key) || hasMention(picked, source.kind, item.id))
|
|
205
|
+
continue;
|
|
206
|
+
const domains = new Set(item.linkHosts.map(registrableDomain).filter((domain) => domain !== ''));
|
|
207
|
+
const match = textHosts.find((candidate) => domains.has(candidate.domain));
|
|
208
|
+
if (!match)
|
|
209
|
+
continue;
|
|
210
|
+
seen.add(key);
|
|
211
|
+
hints.push({ key, kind: source.kind, id: item.id, name: item.name, host: match.host });
|
|
212
|
+
if (hints.length >= MAX_MENTION_LINK_HINTS)
|
|
213
|
+
return hints;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return hints;
|
|
217
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Follow-up pills: the ideas the assistant offers, after a build the person kept, for what to improve next on the widget.
|
|
3
|
+
*
|
|
4
|
+
* A reply's `suggestions` carry two different things, and the title is the whole difference:
|
|
5
|
+
* - an option of a question the assistant asked ("Monthly only", "Monthly and yearly"): no title, drawn as a question card;
|
|
6
|
+
* - a follow-up ("Add a sale banner"): it has a short `title` (a few words, for a small pill) next to its `label` (the whole
|
|
7
|
+
* request, shown in the tooltip, and what a pick puts in the message box).
|
|
8
|
+
*
|
|
9
|
+
* Everything here is plain functions on plain data: which chips are follow-ups, the card the newest reply makes, and whether a
|
|
10
|
+
* pill's request is already in the message box (that is what "checked" means: it is never remembered, it is read from the box,
|
|
11
|
+
* so deleting the words is all it takes to make the pill pickable again).
|
|
12
|
+
*
|
|
13
|
+
* No other file is imported (only types), so Node can run the tests on this file as it is.
|
|
14
|
+
*/
|
|
15
|
+
import type { ChatMessage, ClarificationSuggestion } from '../types/message.js';
|
|
16
|
+
/** The most words a pill shows. The gateway writes titles of at most this; a longer one is cut when read. */
|
|
17
|
+
export declare const FOLLOW_UP_TITLE_WORDS = 5;
|
|
18
|
+
/** The most characters a pill shows (a language with no spaces has no words to count, so this is what holds it). */
|
|
19
|
+
export declare const FOLLOW_UP_TITLE_CHARS = 40;
|
|
20
|
+
/** The most pills one card draws, whatever the reply carries. */
|
|
21
|
+
export declare const FOLLOW_UP_MAX_PILLS = 5;
|
|
22
|
+
/** One pill of the follow-up card. */
|
|
23
|
+
export interface FollowUpPill {
|
|
24
|
+
/** Stable for a request, whatever its place: the request without its case and spacing. A dismissed pill is remembered by it. */
|
|
25
|
+
id: string;
|
|
26
|
+
/** The few words the pill shows. */
|
|
27
|
+
title: string;
|
|
28
|
+
/** The whole request: what the tooltip shows and what a pick puts in the message box. */
|
|
29
|
+
request: string;
|
|
30
|
+
}
|
|
31
|
+
/** The card the newest reply makes. */
|
|
32
|
+
export interface FollowUpCardModel {
|
|
33
|
+
/** The reply whose chips these are: a dismissed pill is remembered against it. */
|
|
34
|
+
replyId: string;
|
|
35
|
+
pills: FollowUpPill[];
|
|
36
|
+
}
|
|
37
|
+
/** A text as one line, compared without regard to case or spacing: the key of a request. */
|
|
38
|
+
export declare function normalizeRequest(text: string): string;
|
|
39
|
+
/** The title of a chip as a pill shows it, or '' when the chip has none (it is then an option of a question). */
|
|
40
|
+
export declare function followUpTitleOf(suggestion: ClarificationSuggestion | null | undefined): string;
|
|
41
|
+
/**
|
|
42
|
+
* Whether a chip is a follow-up pill: a plain `refine` chip with words to ask and a title. The sketch's undo chip and the
|
|
43
|
+
* "generate anyway" chip of a question are never pills, and a chip with no title is an option of a question.
|
|
44
|
+
*/
|
|
45
|
+
export declare function isFollowUpSuggestion(suggestion: ClarificationSuggestion | null | undefined): boolean;
|
|
46
|
+
/** The chips of a reply that are options of a question: everything that is not a follow-up pill. */
|
|
47
|
+
export declare function questionOptionsOf(suggestions: readonly ClarificationSuggestion[] | null | undefined): ClarificationSuggestion[];
|
|
48
|
+
/**
|
|
49
|
+
* The options of the question card a reply shows now: those of `questionOptionsOf`, or none once the person pressed Skip on
|
|
50
|
+
* that reply's card (`skippedReplyIds`, kept with `withQuestionSkipped`). Without options there is no card: the words of the
|
|
51
|
+
* question are then drawn as a plain message, and the turn no longer waits for an answer.
|
|
52
|
+
*/
|
|
53
|
+
export declare function openQuestionOptionsOf(suggestions: readonly ClarificationSuggestion[] | null | undefined, replyId: string, skippedReplyIds: readonly string[]): ClarificationSuggestion[];
|
|
54
|
+
/**
|
|
55
|
+
* The replies whose question card was skipped, with one more: each reply is named once, in the order the cards were skipped.
|
|
56
|
+
* A new list every time (nothing is changed in place), so a `$state` that holds it notices the change. An empty id is not a reply.
|
|
57
|
+
*/
|
|
58
|
+
export declare function withQuestionSkipped(skippedReplyIds: readonly string[], replyId: string): string[];
|
|
59
|
+
/** The pills a reply makes: its follow-up chips, one for each request (a repeat is left out), at most `FOLLOW_UP_MAX_PILLS`. */
|
|
60
|
+
export declare function followUpPillsOf(suggestions: readonly ClarificationSuggestion[] | null | undefined): FollowUpPill[];
|
|
61
|
+
/**
|
|
62
|
+
* The card the conversation shows now, or null. It is made from the newest reply that has follow-ups, looking back from the end
|
|
63
|
+
* of the conversation and stopping at the first message of the person: a message sent takes the card away, and an older turn's
|
|
64
|
+
* ideas never come back. The reply need not be one the chat shows: the chips of a build ride on the saved summary of it ("Updated
|
|
65
|
+
* 2 files"), which the chat keeps out of sight. A reply that was rolled back by a restore, and one the host marked with
|
|
66
|
+
* `metadata.panelFollowUp === false`, are skipped.
|
|
67
|
+
*/
|
|
68
|
+
export declare function findFollowUpCard(messages: readonly ChatMessage[]): FollowUpCardModel | null;
|
|
69
|
+
/** Whether a pill's request is in the message box: what makes the pill show as checked (and refuse a second pick). */
|
|
70
|
+
export declare function isRequestInDraft(draftText: string | null | undefined, request: string): boolean;
|
|
71
|
+
/** What a dismissed pill is remembered by: the reply it was offered under and its request. */
|
|
72
|
+
export declare function followUpDismissKey(replyId: string, pill: Pick<FollowUpPill, 'id'>): string;
|
|
73
|
+
/** The card with the pills the person took out left out; null when none is left (the card goes with its last pill). */
|
|
74
|
+
export declare function withoutDismissedPills(card: FollowUpCardModel | null, dismissedKeys: readonly string[]): FollowUpCardModel | null;
|