@widgetic/chat 0.1.44 → 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 +162 -20
- package/dist/components/ActionBar.svelte +14 -1
- package/dist/components/ActionBar.svelte.d.ts +6 -0
- 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 +556 -121
- 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/PanelSuggestionButtons.svelte +67 -19
- package/dist/components/PanelSuggestionButtons.svelte.d.ts +3 -1
- 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/index.d.ts +1 -1
- package/dist/i18n/index.js +1 -1
- package/dist/i18n/messages.d.ts +52 -4
- package/dist/i18n/messages.js +58 -6
- package/dist/i18n/suggestions.d.ts +17 -2
- package/dist/i18n/suggestions.js +11 -12
- 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
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules of the screen that covers the chat while files are dragged over it, kept apart from the component so Node can test them.
|
|
3
|
+
*
|
|
4
|
+
* The whole chat takes a drop, not only the message box. The browser sends a `dragenter` and a `dragleave` every time the files
|
|
5
|
+
* cross from a part of the chat to another one (the header, a message, the box), so a `dragleave` alone does not say the files left:
|
|
6
|
+
* `dragLeftTheChat` tells the two apart. And the browser says nothing when the drag ends without a drop on the page (the Escape key,
|
|
7
|
+
* a window that took the files), so the chat takes the drag for over after `FILE_DRAG_IDLE_MS` without a `dragover`.
|
|
8
|
+
*/
|
|
9
|
+
import type { DragVerdict } from './attachmentPolicy.js';
|
|
10
|
+
/** What covers the chat: nothing, the screen that invites the drop, or the one that says the files are not taken. */
|
|
11
|
+
export type FileDragOverlay = 'hidden' | 'accept' | 'refuse';
|
|
12
|
+
/**
|
|
13
|
+
* How long the chat waits for the next `dragover` before it takes the drag for over. The browser sends one every 50 to 350 ms for as
|
|
14
|
+
* long as files are over the page, so a longer silence means they are gone.
|
|
15
|
+
*/
|
|
16
|
+
export declare const FILE_DRAG_IDLE_MS = 1500;
|
|
17
|
+
/** The screen a verdict on the files calls for: a drag with no file in it ('none') covers nothing. */
|
|
18
|
+
export declare function overlayForVerdict(verdict: DragVerdict): FileDragOverlay;
|
|
19
|
+
/** What a `dragleave` tells: where the files went (not every browser says) and where the pointer was. */
|
|
20
|
+
export interface DragLeaveFacts {
|
|
21
|
+
relatedTarget: unknown;
|
|
22
|
+
clientX: number;
|
|
23
|
+
clientY: number;
|
|
24
|
+
}
|
|
25
|
+
/** The chat the files are dragged over: whether an element is part of it, and the box it takes on the screen. */
|
|
26
|
+
export interface ChatBounds {
|
|
27
|
+
contains: (node: unknown) => boolean;
|
|
28
|
+
left: number;
|
|
29
|
+
top: number;
|
|
30
|
+
right: number;
|
|
31
|
+
bottom: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Whether a `dragleave` means the files left the chat (and did not just move from a part of it to another one). When the browser
|
|
35
|
+
* says where they went, that decides. When it does not (Safari gives no `relatedTarget`), the pointer decides: while it is still
|
|
36
|
+
* inside the chat the files are still over it. A pointer on the edge counts as out, as does the position (0, 0) a browser gives
|
|
37
|
+
* when the drag was cancelled with Escape.
|
|
38
|
+
*/
|
|
39
|
+
export declare function dragLeftTheChat(leave: DragLeaveFacts, chat: ChatBounds): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The rules of the screen that covers the chat while files are dragged over it, kept apart from the component so Node can test them.
|
|
3
|
+
*
|
|
4
|
+
* The whole chat takes a drop, not only the message box. The browser sends a `dragenter` and a `dragleave` every time the files
|
|
5
|
+
* cross from a part of the chat to another one (the header, a message, the box), so a `dragleave` alone does not say the files left:
|
|
6
|
+
* `dragLeftTheChat` tells the two apart. And the browser says nothing when the drag ends without a drop on the page (the Escape key,
|
|
7
|
+
* a window that took the files), so the chat takes the drag for over after `FILE_DRAG_IDLE_MS` without a `dragover`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* How long the chat waits for the next `dragover` before it takes the drag for over. The browser sends one every 50 to 350 ms for as
|
|
11
|
+
* long as files are over the page, so a longer silence means they are gone.
|
|
12
|
+
*/
|
|
13
|
+
export const FILE_DRAG_IDLE_MS = 1500;
|
|
14
|
+
/** The screen a verdict on the files calls for: a drag with no file in it ('none') covers nothing. */
|
|
15
|
+
export function overlayForVerdict(verdict) {
|
|
16
|
+
return verdict === 'none' ? 'hidden' : verdict;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Whether a `dragleave` means the files left the chat (and did not just move from a part of it to another one). When the browser
|
|
20
|
+
* says where they went, that decides. When it does not (Safari gives no `relatedTarget`), the pointer decides: while it is still
|
|
21
|
+
* inside the chat the files are still over it. A pointer on the edge counts as out, as does the position (0, 0) a browser gives
|
|
22
|
+
* when the drag was cancelled with Escape.
|
|
23
|
+
*/
|
|
24
|
+
export function dragLeftTheChat(leave, chat) {
|
|
25
|
+
if (leave.relatedTarget && chat.contains(leave.relatedTarget))
|
|
26
|
+
return false;
|
|
27
|
+
const pointerIsInside = leave.clientX > chat.left && leave.clientX < chat.right && leave.clientY > chat.top && leave.clientY < chat.bottom;
|
|
28
|
+
return !pointerIsInside;
|
|
29
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files of the message box as the preview card takes them: which of them can be opened, in what order the arrows step through
|
|
3
|
+
* them, and the address each is read from. Kept apart from the components so Node can test it.
|
|
4
|
+
*
|
|
5
|
+
* The order is the one the tray draws (the chips first, then the pictures), so the right arrow goes to the file drawn after the open one.
|
|
6
|
+
* A picture, a video or a PDF has an address the tray already draws it with (a `blob:` address of the file, or the address of its
|
|
7
|
+
* upload). A text file has none until it is uploaded, and the card reads text from an address, so one is made for it from the file
|
|
8
|
+
* itself; the page gives those addresses back when the card closes (`madeUrls`).
|
|
9
|
+
*/
|
|
10
|
+
import type { AttachmentInput } from '../types/attachment.js';
|
|
11
|
+
import { type PreviewableFile } from './attachmentPreview.js';
|
|
12
|
+
/** What the rules need from the page. */
|
|
13
|
+
export interface ComposerPreviewOptions {
|
|
14
|
+
/** Whether a file of the box is a picture (the tray puts the pictures after the chips). */
|
|
15
|
+
isPicture: (attachment: AttachmentInput) => boolean;
|
|
16
|
+
/** The address the tray draws a file with, or '' when it has none yet. */
|
|
17
|
+
readUrl: (attachment: AttachmentInput) => string;
|
|
18
|
+
/** Makes an address for a file that has none. Left out, a file with no address cannot be opened. */
|
|
19
|
+
makeObjectUrl?: (file: File) => string | null | undefined;
|
|
20
|
+
}
|
|
21
|
+
/** The files of the box the card can step through, and where the one that was pressed stands. */
|
|
22
|
+
export interface ComposerPreview {
|
|
23
|
+
files: PreviewableFile[];
|
|
24
|
+
/** The place in `files` of the file that was pressed. */
|
|
25
|
+
openIndex: number;
|
|
26
|
+
/** The addresses that were made for the card alone (see `makeObjectUrl`): the page gives them back when the card closes. */
|
|
27
|
+
madeUrls: string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The card's files for the message box, with the pressed file's place, or null when the pressed file cannot be opened (its kind has no
|
|
31
|
+
* preview, or it has no address and none could be made).
|
|
32
|
+
*/
|
|
33
|
+
export declare function composerPreviewOf(attachments: readonly AttachmentInput[], pressed: AttachmentInput, options: ComposerPreviewOptions): ComposerPreview | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { arrangeTrayAttachments } from './attachmentTray.js';
|
|
2
|
+
import { previewKindOf } from './attachmentPreview.js';
|
|
3
|
+
/**
|
|
4
|
+
* The card's files for the message box, with the pressed file's place, or null when the pressed file cannot be opened (its kind has no
|
|
5
|
+
* preview, or it has no address and none could be made).
|
|
6
|
+
*/
|
|
7
|
+
export function composerPreviewOf(attachments, pressed, options) {
|
|
8
|
+
const { chips, pictures } = arrangeTrayAttachments(attachments, options.isPicture);
|
|
9
|
+
const files = [];
|
|
10
|
+
const madeUrls = [];
|
|
11
|
+
let openIndex = -1;
|
|
12
|
+
for (const { attachment } of [...chips, ...pictures]) {
|
|
13
|
+
const name = attachment.file?.name ?? '';
|
|
14
|
+
const type = attachment.file?.type ?? '';
|
|
15
|
+
let url = options.readUrl(attachment);
|
|
16
|
+
// What the card cannot show is left out before an address is made for it
|
|
17
|
+
if (previewKindOf({ url, name, type }) === null)
|
|
18
|
+
continue;
|
|
19
|
+
if (!url && attachment.file && options.makeObjectUrl) {
|
|
20
|
+
url = options.makeObjectUrl(attachment.file) ?? '';
|
|
21
|
+
if (url)
|
|
22
|
+
madeUrls.push(url);
|
|
23
|
+
}
|
|
24
|
+
if (!url)
|
|
25
|
+
continue;
|
|
26
|
+
if (attachment === pressed)
|
|
27
|
+
openIndex = files.length;
|
|
28
|
+
files.push({ url, name, type, size: typeof attachment.file?.size === 'number' && attachment.file.size > 0 ? attachment.file.size : null });
|
|
29
|
+
}
|
|
30
|
+
return openIndex >= 0 ? { files, openIndex, madeUrls } : null;
|
|
31
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/** Local persistence for panel generation archive (thinking + code tails), keyed by conversation. */
|
|
2
1
|
import { type CodeChanges } from './codeChanges.js';
|
|
3
2
|
export type GenerationArchiveRecord = {
|
|
4
3
|
thinking: string;
|
|
@@ -14,6 +13,11 @@ export type GenerationArchiveRecord = {
|
|
|
14
13
|
* Records saved before this was kept have none.
|
|
15
14
|
*/
|
|
16
15
|
changes?: CodeChanges | null;
|
|
16
|
+
/**
|
|
17
|
+
* The agent's own words about what the run changed (the conclusion says them), when the host gave them. Records saved before
|
|
18
|
+
* this was kept have none.
|
|
19
|
+
*/
|
|
20
|
+
summary?: string | null;
|
|
17
21
|
updatedAt: number;
|
|
18
22
|
};
|
|
19
23
|
export declare function loadGenerationArchive(conversationId: string | null | undefined): Promise<GenerationArchiveRecord | null>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/** Local persistence for panel generation archive (thinking + code tails), keyed by conversation. */
|
|
2
|
+
import { readGenerationSummary } from './agentTurn.js';
|
|
2
3
|
import { readCodeChanges } from './codeChanges.js';
|
|
3
4
|
const DB_NAME = 'widgetic-chat-generation-archive';
|
|
4
5
|
const STORE = 'byConversation';
|
|
@@ -32,7 +33,8 @@ export async function loadGenerationArchive(conversationId) {
|
|
|
32
33
|
const row = req.result;
|
|
33
34
|
// Read again, not trusted: what is in the browser's storage is data of a past version, or of no version at all
|
|
34
35
|
const savedChanges = readCodeChanges(row?.changes);
|
|
35
|
-
|
|
36
|
+
const savedSummary = readGenerationSummary(row?.summary);
|
|
37
|
+
if (!row || (!row.thinking?.trim() && !row.code?.trim() && savedChanges === null && savedSummary === null)) {
|
|
36
38
|
resolve(null);
|
|
37
39
|
return;
|
|
38
40
|
}
|
|
@@ -42,6 +44,7 @@ export async function loadGenerationArchive(conversationId) {
|
|
|
42
44
|
thoughtSeconds: row.thoughtSeconds ?? null,
|
|
43
45
|
prompt: typeof row.prompt === 'string' ? row.prompt : '',
|
|
44
46
|
changes: savedChanges,
|
|
47
|
+
summary: savedSummary,
|
|
45
48
|
updatedAt: row.updatedAt ?? 0,
|
|
46
49
|
});
|
|
47
50
|
};
|
|
@@ -49,7 +52,7 @@ export async function loadGenerationArchive(conversationId) {
|
|
|
49
52
|
});
|
|
50
53
|
}
|
|
51
54
|
catch (error) {
|
|
52
|
-
console.debug('[generationArchiveStore] load skipped', error);
|
|
55
|
+
// console.debug('[generationArchiveStore] load skipped', error);
|
|
53
56
|
return null;
|
|
54
57
|
}
|
|
55
58
|
}
|
|
@@ -58,9 +61,10 @@ export async function saveGenerationArchive(conversationId, record) {
|
|
|
58
61
|
return;
|
|
59
62
|
try {
|
|
60
63
|
// Read again into plain data: IndexedDB cannot copy a proxy, and a record that fails to copy would lose the thinking and the
|
|
61
|
-
// code with it. The read also keeps what is written inside the bounds of `readCodeChanges`.
|
|
64
|
+
// code with it. The read also keeps what is written inside the bounds of `readCodeChanges` and `readGenerationSummary`.
|
|
62
65
|
const changesToSave = readCodeChanges(record.changes);
|
|
63
|
-
|
|
66
|
+
const summaryToSave = readGenerationSummary(record.summary);
|
|
67
|
+
if (!record.thinking.trim() && !record.code.trim() && changesToSave === null && summaryToSave === null)
|
|
64
68
|
return;
|
|
65
69
|
const db = await openDb();
|
|
66
70
|
await new Promise((resolve, reject) => {
|
|
@@ -69,6 +73,7 @@ export async function saveGenerationArchive(conversationId, record) {
|
|
|
69
73
|
conversationId,
|
|
70
74
|
...record,
|
|
71
75
|
changes: changesToSave,
|
|
76
|
+
summary: summaryToSave,
|
|
72
77
|
updatedAt: Date.now(),
|
|
73
78
|
});
|
|
74
79
|
tx.oncomplete = () => resolve();
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export { readGenerationPlanFromMetadata, mapWidgetPlanToPlanCard, } from './gene
|
|
|
12
12
|
export type { GenerationPlanWire, MappedGenerationPlanCard, WidgetPlanTaskStatusWire, } from './generationPlan.js';
|
|
13
13
|
export { readCodeChanges, readCodeChangesFromMetadata } from './codeChanges.js';
|
|
14
14
|
export type { CodeChangeFile, CodeChangeStatus, CodeChanges } from './codeChanges.js';
|
|
15
|
-
export { AGENT_AVATAR_PIXELS, CURRENT_USER_PLACEHOLDER_ID, LOCAL_SERVICE_USER_ID, MAX_KEPT_GENERATION_CHARS, agentAvatarLabelKey, agentAvatarPixels, agentLookSignature, avatarStartAfter, finishedGenerationBelongsTo, finishedModulesView, keepFinishedGeneration, keptWorkIsOutdated, liveAgentLook, liveModulesView, memberDisplayName, memberMailtoHref, memberTooltipEmail, normalizePromptText, pageNamesPeople, resolveChatMember, settledAgentLook, soundStateOf, turnOutcome } from './agentTurn.js';
|
|
15
|
+
export { AGENT_AVATAR_PIXELS, CURRENT_USER_PLACEHOLDER_ID, LOCAL_SERVICE_USER_ID, MAX_KEPT_GENERATION_CHARS, MAX_KEPT_SUMMARY_CHARS, agentAvatarLabelKey, agentAvatarPixels, agentLookSignature, avatarStartAfter, finishedGenerationBelongsTo, finishedModulesView, keepFinishedGeneration, keptWorkIsOutdated, liveAgentLook, liveModulesView, memberDisplayName, memberMailtoHref, memberTooltipEmail, normalizePromptText, outcomeToShow, pageNamesPeople, readGenerationSummary, resolveChatMember, settledAgentLook, soundStateOf, turnOutcome } from './agentTurn.js';
|
|
16
16
|
export { CHIP_NOTE_MAX_CHARACTERS, CHIP_NOTE_MAX_WORDS, firstWords, selectedElementChipLabel, selectedElementChipTitle, selectedElementName, } from './selectedElementChip.js';
|
|
17
17
|
export type { SelectedElementChipSource } from './selectedElementChip.js';
|
|
18
18
|
export { FOLLOW_UP_MAX_PILLS, FOLLOW_UP_TITLE_CHARS, FOLLOW_UP_TITLE_WORDS, findFollowUpCard, followUpPillsOf, followUpTitleOf, isFollowUpSuggestion, isRequestInDraft, questionOptionsOf } from './followUps.js';
|
package/dist/utils/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export { readGenerationPlanFromMetadata, mapWidgetPlanToPlanCard, } from './gene
|
|
|
18
18
|
export { readCodeChanges, readCodeChangesFromMetadata } from './codeChanges.js';
|
|
19
19
|
// The assistant's turn: its avatar's looks, the judgement of a finished turn, who wrote a message, what is kept of the work.
|
|
20
20
|
// A page that is not the chat (the workflows assistant) follows the same choreography through these.
|
|
21
|
-
export { AGENT_AVATAR_PIXELS, CURRENT_USER_PLACEHOLDER_ID, LOCAL_SERVICE_USER_ID, MAX_KEPT_GENERATION_CHARS, agentAvatarLabelKey, agentAvatarPixels, agentLookSignature, avatarStartAfter, finishedGenerationBelongsTo, finishedModulesView, keepFinishedGeneration, keptWorkIsOutdated, liveAgentLook, liveModulesView, memberDisplayName, memberMailtoHref, memberTooltipEmail, normalizePromptText, pageNamesPeople, resolveChatMember, settledAgentLook, soundStateOf, turnOutcome } from './agentTurn.js';
|
|
21
|
+
export { AGENT_AVATAR_PIXELS, CURRENT_USER_PLACEHOLDER_ID, LOCAL_SERVICE_USER_ID, MAX_KEPT_GENERATION_CHARS, MAX_KEPT_SUMMARY_CHARS, agentAvatarLabelKey, agentAvatarPixels, agentLookSignature, avatarStartAfter, finishedGenerationBelongsTo, finishedModulesView, keepFinishedGeneration, keptWorkIsOutdated, liveAgentLook, liveModulesView, memberDisplayName, memberMailtoHref, memberTooltipEmail, normalizePromptText, outcomeToShow, pageNamesPeople, readGenerationSummary, resolveChatMember, settledAgentLook, soundStateOf, turnOutcome } from './agentTurn.js';
|
|
22
22
|
// What the chip of a picked part says: the first words of its note, or its name while the note is empty.
|
|
23
23
|
export { CHIP_NOTE_MAX_CHARACTERS, CHIP_NOTE_MAX_WORDS, firstWords, selectedElementChipLabel, selectedElementChipTitle, selectedElementName, } from './selectedElementChip.js';
|
|
24
24
|
// The follow-up card (ideas for what to improve next, as pills under the last reply): which chips are pills (the ones with a
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Translate } from '@widgetic/design-system/i18n';
|
|
2
|
+
import { type ChatMessageKey } from '../i18n/messages.js';
|
|
3
|
+
/**
|
|
4
|
+
* Telling the chat's own sentences for a limit among the lines of a conversation.
|
|
5
|
+
*
|
|
6
|
+
* The sketch assistant says a refusal because of money in one of three sentences (`chat.sketch.noCredits`, `.planRequired`,
|
|
7
|
+
* `.limitReached`). A reply is saved as its words only, so after a reload the sentence is all the chat has to tell that the
|
|
8
|
+
* way out is to upgrade (the red failure line, and the "Upgrade" button under it).
|
|
9
|
+
*
|
|
10
|
+
* The words are read whole, and only these: a reply the model writes that happens to mention a free trial must never be
|
|
11
|
+
* taken for a limit (the looser test of `isPlanLimitMessage` would, and it is kept for the lines the widget creator saves
|
|
12
|
+
* for a code generation, which start with "Code generation failed").
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The sentences, each as the English the host saves and as `translate` says it in the page's language (a host that saves the
|
|
16
|
+
* words it showed saved them in that language). Said once for a language, so a screen asks for it once and not for each line.
|
|
17
|
+
*/
|
|
18
|
+
export declare function limitFailureSentencesOf(translate: Translate<ChatMessageKey>): ReadonlySet<string>;
|
|
19
|
+
/** Whether a saved line is, as a whole, one of the sentences for a limit (spaces around it do not matter). */
|
|
20
|
+
export declare function isLimitFailureLine(content: string | null | undefined, sentences: ReadonlySet<string>): boolean;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { CHAT_MESSAGES } from '../i18n/messages.js';
|
|
2
|
+
/**
|
|
3
|
+
* Telling the chat's own sentences for a limit among the lines of a conversation.
|
|
4
|
+
*
|
|
5
|
+
* The sketch assistant says a refusal because of money in one of three sentences (`chat.sketch.noCredits`, `.planRequired`,
|
|
6
|
+
* `.limitReached`). A reply is saved as its words only, so after a reload the sentence is all the chat has to tell that the
|
|
7
|
+
* way out is to upgrade (the red failure line, and the "Upgrade" button under it).
|
|
8
|
+
*
|
|
9
|
+
* The words are read whole, and only these: a reply the model writes that happens to mention a free trial must never be
|
|
10
|
+
* taken for a limit (the looser test of `isPlanLimitMessage` would, and it is kept for the lines the widget creator saves
|
|
11
|
+
* for a code generation, which start with "Code generation failed").
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* The sentences, each as the English the host saves and as `translate` says it in the page's language (a host that saves the
|
|
15
|
+
* words it showed saved them in that language). Said once for a language, so a screen asks for it once and not for each line.
|
|
16
|
+
*/
|
|
17
|
+
export function limitFailureSentencesOf(translate) {
|
|
18
|
+
const sentences = new Set([
|
|
19
|
+
CHAT_MESSAGES['chat.sketch.noCredits'],
|
|
20
|
+
CHAT_MESSAGES['chat.sketch.planRequired'],
|
|
21
|
+
CHAT_MESSAGES['chat.sketch.limitReached'],
|
|
22
|
+
]);
|
|
23
|
+
for (const sentence of [
|
|
24
|
+
translate('chat.sketch.noCredits'),
|
|
25
|
+
translate('chat.sketch.planRequired'),
|
|
26
|
+
translate('chat.sketch.limitReached'),
|
|
27
|
+
]) {
|
|
28
|
+
const trimmedSentence = sentence.trim();
|
|
29
|
+
if (trimmedSentence !== '')
|
|
30
|
+
sentences.add(trimmedSentence);
|
|
31
|
+
}
|
|
32
|
+
return sentences;
|
|
33
|
+
}
|
|
34
|
+
/** Whether a saved line is, as a whole, one of the sentences for a limit (spaces around it do not matter). */
|
|
35
|
+
export function isLimitFailureLine(content, sentences) {
|
|
36
|
+
if (typeof content !== 'string')
|
|
37
|
+
return false;
|
|
38
|
+
const trimmedContent = content.trim();
|
|
39
|
+
return trimmedContent !== '' && sentences.has(trimmedContent);
|
|
40
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The room the docked panel leaves at the sides of its list of messages (Figma: Chat states, "Thread").
|
|
3
|
+
*
|
|
4
|
+
* The list keeps 12 px at each side, exactly what the message box under it keeps, so the face of the assistant starts where the box
|
|
5
|
+
* starts and a bubble (and the face of the person who wrote it) ends where the box ends.
|
|
6
|
+
*
|
|
7
|
+
* A scrollbar that takes room of its own (the classic bars of Windows, or of a Mac with a mouse) sits inside the gap at the end: the
|
|
8
|
+
* padding there gives up as much as the bar takes, so the words still end where the box ends. A bar that floats over the list (the
|
|
9
|
+
* overlay bars of a Mac with a trackpad) takes none, and the padding stays what it is. The start is never touched.
|
|
10
|
+
*
|
|
11
|
+
* Plain TypeScript with no Svelte in it, so a test can hold it. `ChatMessages.svelte` reads the list (its width with and without
|
|
12
|
+
* the bar) and sets what this returns.
|
|
13
|
+
*/
|
|
14
|
+
/** The room the list leaves at each side, in px: the message box under it keeps the same. */
|
|
15
|
+
export declare const PANEL_LIST_INLINE_PADDING_PX = 12;
|
|
16
|
+
/**
|
|
17
|
+
* The padding at the END of the list (in px) while a scrollbar takes room, or `null` when the padding of the list's own style is
|
|
18
|
+
* right (there is no bar, or it floats over the list). Never throws: a width that is not a number counts as no bar.
|
|
19
|
+
*/
|
|
20
|
+
export declare function panelListEndPaddingPx(listHasScrollbar: boolean, scrollbarWidthPx: number): number | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The room the docked panel leaves at the sides of its list of messages (Figma: Chat states, "Thread").
|
|
3
|
+
*
|
|
4
|
+
* The list keeps 12 px at each side, exactly what the message box under it keeps, so the face of the assistant starts where the box
|
|
5
|
+
* starts and a bubble (and the face of the person who wrote it) ends where the box ends.
|
|
6
|
+
*
|
|
7
|
+
* A scrollbar that takes room of its own (the classic bars of Windows, or of a Mac with a mouse) sits inside the gap at the end: the
|
|
8
|
+
* padding there gives up as much as the bar takes, so the words still end where the box ends. A bar that floats over the list (the
|
|
9
|
+
* overlay bars of a Mac with a trackpad) takes none, and the padding stays what it is. The start is never touched.
|
|
10
|
+
*
|
|
11
|
+
* Plain TypeScript with no Svelte in it, so a test can hold it. `ChatMessages.svelte` reads the list (its width with and without
|
|
12
|
+
* the bar) and sets what this returns.
|
|
13
|
+
*/
|
|
14
|
+
/** The room the list leaves at each side, in px: the message box under it keeps the same. */
|
|
15
|
+
export const PANEL_LIST_INLINE_PADDING_PX = 12;
|
|
16
|
+
/**
|
|
17
|
+
* The padding at the END of the list (in px) while a scrollbar takes room, or `null` when the padding of the list's own style is
|
|
18
|
+
* right (there is no bar, or it floats over the list). Never throws: a width that is not a number counts as no bar.
|
|
19
|
+
*/
|
|
20
|
+
export function panelListEndPaddingPx(listHasScrollbar, scrollbarWidthPx) {
|
|
21
|
+
try {
|
|
22
|
+
if (!listHasScrollbar)
|
|
23
|
+
return null;
|
|
24
|
+
if (!Number.isFinite(scrollbarWidthPx) || scrollbarWidthPx <= 0)
|
|
25
|
+
return null;
|
|
26
|
+
return Math.max(0, PANEL_LIST_INLINE_PADDING_PX - scrollbarWidthPx);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AttachmentInput } from '../types/attachment.js';
|
|
2
|
+
/** Where the paste landed in the text of the box: the caret, or the part of the text that the paste replaces. */
|
|
3
|
+
export interface PasteSelection {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
}
|
|
7
|
+
/** Whether a label is one a pasted text is given (for a draft that comes back without its files: see `Chat.svelte`). */
|
|
8
|
+
export declare function isPastedTextLabel(label: string): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Where in the text the badge goes, given where the caret was when the paste arrived (`snapshotText`, with `selection` in it) and
|
|
11
|
+
* what the box holds now (`currentText`). The two are the same unless the person typed in the moments between (a paste waits for
|
|
12
|
+
* the pastes before it, and a picture is made smaller first). Typing after the caret does not move it; typing before it does, and
|
|
13
|
+
* then the place is lost: the badge goes at the end of the text, which is where the person would look for it.
|
|
14
|
+
*/
|
|
15
|
+
export declare function resolvePasteInsertionRange(snapshotText: string, currentText: string, selection: PasteSelection | null | undefined): PasteSelection;
|
|
16
|
+
/** What writing a badge into a text gives: the new text and where the caret goes (after the badge, ready to go on typing). */
|
|
17
|
+
export interface TokenWritten {
|
|
18
|
+
text: string;
|
|
19
|
+
caret: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Writes the badge of `label` into `text` over `range`. A space goes before it when a word stands right in front of it (a badge
|
|
23
|
+
* hugging a word would look like part of it), and the design system's plan adds the space after it (unless one is there).
|
|
24
|
+
*/
|
|
25
|
+
export declare function writeReferenceToken(text: string, range: PasteSelection, label: string): TokenWritten;
|
|
26
|
+
/** The words (labels, lower case) a text names: the badges in it and the `#label` words typed by hand. */
|
|
27
|
+
export declare function labelsNamedByText(text: string): Set<string>;
|
|
28
|
+
/**
|
|
29
|
+
* The files that go with a message: every file, except a pasted text the message no longer names. A pasted text has no tile in
|
|
30
|
+
* the tray, so a badge that was deleted (or cut, to be put somewhere else) leaves a file that nothing on the screen shows: it is
|
|
31
|
+
* kept (undo, or pasting the badge back, brings the badge to life again) but it must not be sent with words that do not name it.
|
|
32
|
+
*/
|
|
33
|
+
export declare function attachmentsNamedByText(attachments: readonly AttachmentInput[], text: string): AttachmentInput[];
|
|
34
|
+
/**
|
|
35
|
+
* A draft that comes back after a refresh has its pictures but not the texts that were pasted (only pictures are kept in a draft).
|
|
36
|
+
* The badge of a text that is not here is taken out of the words, with one space beside it, instead of being left as a plain
|
|
37
|
+
* `#pasted_text` that stands for nothing. Only badges of the labels a pasted text is given are touched; `knownLabels` are the
|
|
38
|
+
* labels of the files that are attached now.
|
|
39
|
+
*/
|
|
40
|
+
export declare function removeBadgesOfMissingPastedTexts(text: string, knownLabels: Iterable<string>): {
|
|
41
|
+
text: string;
|
|
42
|
+
removed: number;
|
|
43
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where a pasted text goes in the message, and how it gets there. Kept apart from the components so Node can test it.
|
|
3
|
+
*
|
|
4
|
+
* A long text pasted into the box is attached as a file (`attachmentsFromPaste`), and the message names it with a badge written
|
|
5
|
+
* where the caret was: so a person who pastes a log after the second paragraph of a brief has the badge after the second paragraph,
|
|
6
|
+
* and can say "…as the error in #pasted_text shows" around it. The badge is the design system's token (its rooms, the `#`, the
|
|
7
|
+
* label), written into the text the box holds; the box paints it.
|
|
8
|
+
*/
|
|
9
|
+
// From the module of the tokens itself and not from the folder's index: the index also brings the menu (a Svelte file), and what is
|
|
10
|
+
// needed here is the text model alone, which Node can load for the tests
|
|
11
|
+
import { FIGURE_SPACE, isRegularWhitespace, parseTokens, planTokenInsertion, referenceOccurrences, removeToken, } from '@widgetic/design-system/prompt-references/referenceTokens';
|
|
12
|
+
import { isPastedTextAttachment } from './attachmentTray.js';
|
|
13
|
+
/** The labels a pasted text is called by: `pasted_text`, then `pasted_text_2`, … (the file is `pasted-text.txt`, then `pasted-text-2.txt`). */
|
|
14
|
+
const PASTED_TEXT_LABEL_PATTERN = /^pasted_text(?:_\d+)?$/i;
|
|
15
|
+
/** Whether a label is one a pasted text is given (for a draft that comes back without its files: see `Chat.svelte`). */
|
|
16
|
+
export function isPastedTextLabel(label) {
|
|
17
|
+
return PASTED_TEXT_LABEL_PATTERN.test(label);
|
|
18
|
+
}
|
|
19
|
+
/** A number kept inside `[low, high]`; a value that is not a number is `low`. */
|
|
20
|
+
function clamp(value, low, high) {
|
|
21
|
+
if (!Number.isFinite(value))
|
|
22
|
+
return low;
|
|
23
|
+
return Math.min(high, Math.max(low, Math.floor(value)));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Where in the text the badge goes, given where the caret was when the paste arrived (`snapshotText`, with `selection` in it) and
|
|
27
|
+
* what the box holds now (`currentText`). The two are the same unless the person typed in the moments between (a paste waits for
|
|
28
|
+
* the pastes before it, and a picture is made smaller first). Typing after the caret does not move it; typing before it does, and
|
|
29
|
+
* then the place is lost: the badge goes at the end of the text, which is where the person would look for it.
|
|
30
|
+
*/
|
|
31
|
+
export function resolvePasteInsertionRange(snapshotText, currentText, selection) {
|
|
32
|
+
if (!selection)
|
|
33
|
+
return { start: currentText.length, end: currentText.length };
|
|
34
|
+
const start = clamp(selection.start, 0, snapshotText.length);
|
|
35
|
+
const end = clamp(selection.end, start, snapshotText.length);
|
|
36
|
+
if (currentText === snapshotText)
|
|
37
|
+
return { start, end };
|
|
38
|
+
const textBeforeCaretIsTheSame = currentText.startsWith(snapshotText.slice(0, start));
|
|
39
|
+
if (!textBeforeCaretIsTheSame)
|
|
40
|
+
return { start: currentText.length, end: currentText.length };
|
|
41
|
+
// A selection the paste replaces is replaced only while it is still there: otherwise the badge is put in front of what stands there now.
|
|
42
|
+
const selectedText = snapshotText.slice(start, end);
|
|
43
|
+
const selectionIsStillThere = currentText.slice(start, start + selectedText.length) === selectedText;
|
|
44
|
+
return selectionIsStillThere ? { start, end: start + selectedText.length } : { start, end: start };
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Writes the badge of `label` into `text` over `range`. A space goes before it when a word stands right in front of it (a badge
|
|
48
|
+
* hugging a word would look like part of it), and the design system's plan adds the space after it (unless one is there).
|
|
49
|
+
*/
|
|
50
|
+
export function writeReferenceToken(text, range, label) {
|
|
51
|
+
const start = clamp(range.start, 0, text.length);
|
|
52
|
+
const end = clamp(range.end, start, text.length);
|
|
53
|
+
const plan = planTokenInsertion(text, { start, end }, label);
|
|
54
|
+
const characterBefore = start > 0 ? text[start - 1] : undefined;
|
|
55
|
+
const needsSpaceBefore = characterBefore !== undefined && characterBefore !== FIGURE_SPACE && !isRegularWhitespace(characterBefore);
|
|
56
|
+
const spaceBefore = needsSpaceBefore ? ' ' : '';
|
|
57
|
+
return {
|
|
58
|
+
text: `${text.slice(0, start)}${spaceBefore}${plan.insertion}${text.slice(end)}`,
|
|
59
|
+
caret: start + spaceBefore.length + plan.insertion.length,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** The words (labels, lower case) a text names: the badges in it and the `#label` words typed by hand. */
|
|
63
|
+
export function labelsNamedByText(text) {
|
|
64
|
+
return new Set(referenceOccurrences(text).map((occurrence) => occurrence.label.toLowerCase()));
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The files that go with a message: every file, except a pasted text the message no longer names. A pasted text has no tile in
|
|
68
|
+
* the tray, so a badge that was deleted (or cut, to be put somewhere else) leaves a file that nothing on the screen shows: it is
|
|
69
|
+
* kept (undo, or pasting the badge back, brings the badge to life again) but it must not be sent with words that do not name it.
|
|
70
|
+
*/
|
|
71
|
+
export function attachmentsNamedByText(attachments, text) {
|
|
72
|
+
const named = labelsNamedByText(text);
|
|
73
|
+
return attachments.filter((attachment) => !isPastedTextAttachment(attachment) ||
|
|
74
|
+
(attachment.referenceLabel !== undefined && named.has(attachment.referenceLabel.toLowerCase())));
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A draft that comes back after a refresh has its pictures but not the texts that were pasted (only pictures are kept in a draft).
|
|
78
|
+
* The badge of a text that is not here is taken out of the words, with one space beside it, instead of being left as a plain
|
|
79
|
+
* `#pasted_text` that stands for nothing. Only badges of the labels a pasted text is given are touched; `knownLabels` are the
|
|
80
|
+
* labels of the files that are attached now.
|
|
81
|
+
*/
|
|
82
|
+
export function removeBadgesOfMissingPastedTexts(text, knownLabels) {
|
|
83
|
+
const known = new Set(Array.from(knownLabels, (label) => label.toLowerCase()));
|
|
84
|
+
let result = text;
|
|
85
|
+
let removed = 0;
|
|
86
|
+
// From the end, so the places of the badges before it stay as they were
|
|
87
|
+
for (const token of parseTokens(text).reverse()) {
|
|
88
|
+
if (!isPastedTextLabel(token.label) || known.has(token.label.toLowerCase()))
|
|
89
|
+
continue;
|
|
90
|
+
result = removeToken(result, token).text;
|
|
91
|
+
removed += 1;
|
|
92
|
+
}
|
|
93
|
+
return { text: result, removed };
|
|
94
|
+
}
|
|
@@ -33,7 +33,20 @@ export interface PastedAttachment {
|
|
|
33
33
|
file: File;
|
|
34
34
|
/** The first words of a pasted text. It is for the screen only: it is never sent anywhere, the name of the file is. */
|
|
35
35
|
label?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The beginning of a pasted text (see `pastedTextExcerpt`): the card over the text's badge shows it. Only a pasted text has one,
|
|
38
|
+
* and it is what tells a pasted text from any other file. For the screen only: it is never sent anywhere.
|
|
39
|
+
*/
|
|
40
|
+
excerpt?: string;
|
|
36
41
|
}
|
|
42
|
+
/** Longest excerpt of a pasted text, in characters: far more than the card over the badge has room for (it cuts it again by lines). */
|
|
43
|
+
export declare const PASTED_TEXT_EXCERPT_MAX_CHARACTERS = 600;
|
|
44
|
+
/**
|
|
45
|
+
* The beginning of a pasted text as the card over its badge shows it: the text as it was written (its line breaks stay, so a list
|
|
46
|
+
* or a piece of code reads as it did), with the blank lines at both ends and runs of more than one blank line in a row taken out,
|
|
47
|
+
* cut at `maxCharacters` with an ellipsis. A text that fits is returned whole, with no ellipsis.
|
|
48
|
+
*/
|
|
49
|
+
export declare function pastedTextExcerpt(text: string, maxCharacters?: number): string;
|
|
37
50
|
/** One entry of `clipboardData.items`, as much as the rules read of it. */
|
|
38
51
|
export interface PasteSourceItem {
|
|
39
52
|
readonly kind: string;
|
|
@@ -27,6 +27,23 @@ export const DEFAULT_PASTED_TEXT_THRESHOLDS = {
|
|
|
27
27
|
minCharacters: PASTED_TEXT_MIN_CHARACTERS,
|
|
28
28
|
minLines: PASTED_TEXT_MIN_LINES
|
|
29
29
|
};
|
|
30
|
+
/** Longest excerpt of a pasted text, in characters: far more than the card over the badge has room for (it cuts it again by lines). */
|
|
31
|
+
export const PASTED_TEXT_EXCERPT_MAX_CHARACTERS = 600;
|
|
32
|
+
/**
|
|
33
|
+
* The beginning of a pasted text as the card over its badge shows it: the text as it was written (its line breaks stay, so a list
|
|
34
|
+
* or a piece of code reads as it did), with the blank lines at both ends and runs of more than one blank line in a row taken out,
|
|
35
|
+
* cut at `maxCharacters` with an ellipsis. A text that fits is returned whole, with no ellipsis.
|
|
36
|
+
*/
|
|
37
|
+
export function pastedTextExcerpt(text, maxCharacters = PASTED_TEXT_EXCERPT_MAX_CHARACTERS) {
|
|
38
|
+
const tidyText = (text ?? '')
|
|
39
|
+
.replace(/\r\n?/g, '\n')
|
|
40
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
41
|
+
.trim();
|
|
42
|
+
const characters = Array.from(tidyText);
|
|
43
|
+
if (characters.length <= maxCharacters)
|
|
44
|
+
return tidyText;
|
|
45
|
+
return `${characters.slice(0, maxCharacters).join('').trimEnd()}…`;
|
|
46
|
+
}
|
|
30
47
|
/** A line break of any system. */
|
|
31
48
|
const LINE_BREAK = /\r\n|\r|\n/;
|
|
32
49
|
/** A text that is nothing but one address: what some browsers write next to a picture copied from a page. */
|
|
@@ -252,7 +269,7 @@ export function attachmentsFromPaste(source, thresholds = {}) {
|
|
|
252
269
|
}
|
|
253
270
|
// 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
271
|
if (isLongPastedText(pastedText, thresholds)) {
|
|
255
|
-
return [{ file: textAsFile(pastedText), label: pastedTextLabel(pastedText) }];
|
|
272
|
+
return [{ file: textAsFile(pastedText), label: pastedTextLabel(pastedText), excerpt: pastedTextExcerpt(pastedText) }];
|
|
256
273
|
}
|
|
257
274
|
return [];
|
|
258
275
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isPastedTextAttachment } from "./attachmentTray.js";
|
|
1
2
|
/**
|
|
2
3
|
* The files of the composer tray as the message box offers them to a `#` (the design system's `references` prop). Kept apart from
|
|
3
4
|
* the components so Node can test it. The label a file is called by is given in `Chat.svelte` when the file joins the tray; the rules
|
|
@@ -27,17 +28,24 @@ export function buildReferenceItems(attachments, sources) {
|
|
|
27
28
|
const items = [];
|
|
28
29
|
for (const attachment of attachments) {
|
|
29
30
|
const label = attachment.referenceLabel;
|
|
30
|
-
|
|
31
|
+
// A text pasted into the box is always referenceable: its badge is how the message holds it (see `isPastedTextAttachment`).
|
|
32
|
+
const pastedText = isPastedTextAttachment(attachment);
|
|
33
|
+
if (!label || !(pastedText || sources.isReferenceable(attachment)))
|
|
31
34
|
continue;
|
|
32
|
-
const previewUrl = sources.previewUrlOf(attachment);
|
|
35
|
+
const previewUrl = pastedText ? "" : sources.previewUrlOf(attachment);
|
|
33
36
|
const sizeLabel = sources.sizeLabelOf(attachment);
|
|
34
37
|
items.push({
|
|
35
38
|
id: referenceIdOf(attachment),
|
|
36
39
|
label,
|
|
37
40
|
number: items.length + 1,
|
|
38
|
-
|
|
41
|
+
// A pasted text is called by its first words (what its tile used to say), not by "pasted-text.txt".
|
|
42
|
+
fileName: pastedText
|
|
43
|
+
? attachment.label || attachment.file?.name || ""
|
|
44
|
+
: (attachment.file?.name ?? ""),
|
|
39
45
|
previewUrl: previewUrl || null,
|
|
40
46
|
sizeLabel: sizeLabel || undefined,
|
|
47
|
+
// The card over its badge shows what the text says, cut short with an ellipsis (the design system draws it).
|
|
48
|
+
...(pastedText ? { excerpt: attachment.excerpt } : {}),
|
|
41
49
|
});
|
|
42
50
|
}
|
|
43
51
|
return items;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which of the files of a sent message are drawn above its bubble, and in what order. Kept apart from the components so Node can test it.
|
|
3
|
+
*
|
|
4
|
+
* A person who sends a message with files sees the same small arrangement they saw in the message box: the files that are not
|
|
5
|
+
* pictures come first, each as a chip with the glyph of its kind, and the pictures follow below them as small thumbnails, one after the
|
|
6
|
+
* other, whatever order the files were attached in. Both rows sit above the bubble (a bubble holds words, not pictures), at its end.
|
|
7
|
+
*
|
|
8
|
+
* A text that was pasted into the box is not drawn here when the words of the message name it with a badge: the badge stands where the
|
|
9
|
+
* text was pasted, so a chip of the same file would show it twice. A pasted text no badge names is drawn as a chip, so no file of a
|
|
10
|
+
* message is ever hidden without a reason.
|
|
11
|
+
*/
|
|
12
|
+
import type { ContentItemOutput } from '../types/message.js';
|
|
13
|
+
/** One file of a sent message, with its place in the list the message holds. */
|
|
14
|
+
export interface SentEntry {
|
|
15
|
+
attachment: ContentItemOutput;
|
|
16
|
+
/** The place of the file among the files of the message (the number a badge of the words carries as `attachmentIndex`). */
|
|
17
|
+
index: number;
|
|
18
|
+
}
|
|
19
|
+
/** The files of a message as they are drawn, top to bottom. */
|
|
20
|
+
export interface SentArrangement {
|
|
21
|
+
/** The files that are not pictures, in the order the message holds them: each is a chip. */
|
|
22
|
+
chips: SentEntry[];
|
|
23
|
+
/** The pictures, in the order the message holds them: each is a small thumbnail below the chips. */
|
|
24
|
+
pictures: SentEntry[];
|
|
25
|
+
}
|
|
26
|
+
/** What of a badge of the words matters here: that it is one, and which file it names (the shape of the design system's `SentSegment`). */
|
|
27
|
+
export interface BadgeSegmentFacts {
|
|
28
|
+
kind: string;
|
|
29
|
+
attachmentIndex?: number;
|
|
30
|
+
}
|
|
31
|
+
/** The places of the files that a badge of the message's words names (an empty set when the words have no badge). */
|
|
32
|
+
export declare function attachmentIndexesNamedByBadges(segments: readonly BadgeSegmentFacts[] | null | undefined): Set<number>;
|
|
33
|
+
/** Whether a file is drawn as a thumbnail: a picture that has an address to draw it from. */
|
|
34
|
+
export declare function isSentPicture(attachment: ContentItemOutput): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* The files of a message in the order they are drawn. A pasted text that a badge names is left out; every other file is drawn, as a
|
|
37
|
+
* chip or as a thumbnail, and each row keeps the order in which its files were attached.
|
|
38
|
+
*/
|
|
39
|
+
export declare function arrangeSentAttachments(attachments: readonly ContentItemOutput[], namedByBadge?: ReadonlySet<number>): SentArrangement;
|
|
40
|
+
/** Whether there is anything to draw above the bubble. */
|
|
41
|
+
export declare function hasSentTiles(arrangement: SentArrangement): boolean;
|
|
42
|
+
/** The files in the order the screen draws them (the chips, then the pictures): the order the arrows of the preview step through. */
|
|
43
|
+
export declare function sentAttachmentsInDrawnOrder(arrangement: SentArrangement): ContentItemOutput[];
|