@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,38 @@
|
|
|
1
|
+
import { isPastedTextOfMessage, isPictureOfMessage } from './sentReferenceBadges.js';
|
|
2
|
+
/** The places of the files that a badge of the message's words names (an empty set when the words have no badge). */
|
|
3
|
+
export function attachmentIndexesNamedByBadges(segments) {
|
|
4
|
+
const named = new Set();
|
|
5
|
+
for (const segment of segments ?? []) {
|
|
6
|
+
if (segment.kind === 'badge' && typeof segment.attachmentIndex === 'number')
|
|
7
|
+
named.add(segment.attachmentIndex);
|
|
8
|
+
}
|
|
9
|
+
return named;
|
|
10
|
+
}
|
|
11
|
+
/** Whether a file is drawn as a thumbnail: a picture that has an address to draw it from. */
|
|
12
|
+
export function isSentPicture(attachment) {
|
|
13
|
+
return isPictureOfMessage(attachment) && typeof attachment.url === 'string' && attachment.url !== '';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 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
|
|
17
|
+
* chip or as a thumbnail, and each row keeps the order in which its files were attached.
|
|
18
|
+
*/
|
|
19
|
+
export function arrangeSentAttachments(attachments, namedByBadge = new Set()) {
|
|
20
|
+
const arrangement = { chips: [], pictures: [] };
|
|
21
|
+
attachments.forEach((attachment, index) => {
|
|
22
|
+
if (isPastedTextOfMessage(attachment) && namedByBadge.has(index))
|
|
23
|
+
return;
|
|
24
|
+
if (isSentPicture(attachment))
|
|
25
|
+
arrangement.pictures.push({ attachment, index });
|
|
26
|
+
else
|
|
27
|
+
arrangement.chips.push({ attachment, index });
|
|
28
|
+
});
|
|
29
|
+
return arrangement;
|
|
30
|
+
}
|
|
31
|
+
/** Whether there is anything to draw above the bubble. */
|
|
32
|
+
export function hasSentTiles(arrangement) {
|
|
33
|
+
return arrangement.chips.length + arrangement.pictures.length > 0;
|
|
34
|
+
}
|
|
35
|
+
/** The files in the order the screen draws them (the chips, then the pictures): the order the arrows of the preview step through. */
|
|
36
|
+
export function sentAttachmentsInDrawnOrder(arrangement) {
|
|
37
|
+
return [...arrangement.chips, ...arrangement.pictures].map((entry) => entry.attachment);
|
|
38
|
+
}
|
|
@@ -14,13 +14,23 @@ export declare const SENT_BADGE_PICTURE_PX = 18;
|
|
|
14
14
|
type PictureFacts = Pick<ContentItemOutput, 'file_type' | 'url'>;
|
|
15
15
|
/** Whether a file of a message is a picture (the only files a badge shows, since a badge shows what is in the file). */
|
|
16
16
|
export declare function isPictureOfMessage(attachment: PictureFacts): boolean;
|
|
17
|
+
/** Whether a file of a message is a text that was pasted into the box (it has no thumbnail: its badge shows a file glyph). */
|
|
18
|
+
export declare function isPastedTextOfMessage(attachment: Pick<ContentItemOutput, 'file_name'> | undefined): boolean;
|
|
17
19
|
/**
|
|
18
20
|
* The files of a message as `segmentSentText` takes them, in the order the message holds them. Every file counts for the rule (a
|
|
19
|
-
* name two files share is not trusted, whatever the files are); only a picture that has an address to draw it from
|
|
21
|
+
* name two files share is not trusted, whatever the files are); only a picture that has an address to draw it from, and a text that
|
|
22
|
+
* was pasted (its badge draws a glyph), may have a badge.
|
|
20
23
|
*/
|
|
21
24
|
export declare function sentAttachmentsOf(attachments: readonly ContentItemOutput[]): SentAttachment[];
|
|
22
25
|
/** The address of the picture a badge shows, at the size a badge draws it, or '' when the file has none. */
|
|
23
26
|
export declare function sentBadgePictureOf(attachment: Pick<ContentItemOutput, 'url'> | undefined): string;
|
|
24
27
|
/** What a badge says to a screen reader beyond its words: the name of the file, or nothing when the file has none. */
|
|
25
28
|
export declare function sentBadgeTitleOf(attachment: Pick<ContentItemOutput, 'file_name'> | undefined): string | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* The beginning of a text that was pasted into a sent message, read from the file the message holds (its address). The message
|
|
31
|
+
* keeps the file and not the excerpt, so it is fetched when the pointer rests on the badge. Resolves to '' when the file cannot be
|
|
32
|
+
* read (the page it is on is not allowed to, the address is gone, it takes too long): the badge then says the name of the file.
|
|
33
|
+
* `fetchText` is the browser's `fetch`, given by the caller so Node can test the rest.
|
|
34
|
+
*/
|
|
35
|
+
export declare function fetchPastedTextExcerpt(url: string, fetchText?: typeof fetch, timeLimitMilliseconds?: number): Promise<string>;
|
|
26
36
|
export {};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { buildImageThumbnailUrl } from './imageTransform.js';
|
|
2
|
+
import { pastedTextExcerpt } from './pastedContent.js';
|
|
3
|
+
import { chatWarn } from './logger.js';
|
|
2
4
|
/** The side of the picture inside a badge, in CSS px (the design system's `BADGE_THUMBNAIL_SIZE_PX`). */
|
|
3
5
|
export const SENT_BADGE_PICTURE_PX = 18;
|
|
4
6
|
/** Whether a file of a message is a picture (the only files a badge shows, since a badge shows what is in the file). */
|
|
@@ -8,14 +10,26 @@ export function isPictureOfMessage(attachment) {
|
|
|
8
10
|
const url = attachment.url;
|
|
9
11
|
return typeof url === 'string' && (/^data:image\//i.test(url) || /\.(png|jpe?g|gif|webp|svg)(\?|$)/i.test(url));
|
|
10
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* A text that was pasted into the message box is attached under the name "pasted-text.txt" (then "pasted-text-2.txt", …): that is
|
|
15
|
+
* what a message's file says it is. The words of the message name it with a badge, written where the text was pasted.
|
|
16
|
+
*/
|
|
17
|
+
const PASTED_TEXT_FILE_NAME_PATTERN = /^pasted-text(?:-\d+)?\.txt$/i;
|
|
18
|
+
/** Whether a file of a message is a text that was pasted into the box (it has no thumbnail: its badge shows a file glyph). */
|
|
19
|
+
export function isPastedTextOfMessage(attachment) {
|
|
20
|
+
const name = attachment?.file_name?.trim();
|
|
21
|
+
return !!name && PASTED_TEXT_FILE_NAME_PATTERN.test(name);
|
|
22
|
+
}
|
|
11
23
|
/**
|
|
12
24
|
* The files of a message as `segmentSentText` takes them, in the order the message holds them. Every file counts for the rule (a
|
|
13
|
-
* name two files share is not trusted, whatever the files are); only a picture that has an address to draw it from
|
|
25
|
+
* name two files share is not trusted, whatever the files are); only a picture that has an address to draw it from, and a text that
|
|
26
|
+
* was pasted (its badge draws a glyph), may have a badge.
|
|
14
27
|
*/
|
|
15
28
|
export function sentAttachmentsOf(attachments) {
|
|
16
29
|
return attachments.map((attachment) => ({
|
|
17
30
|
fileName: attachment.file_name ?? null,
|
|
18
|
-
badge: isPictureOfMessage(attachment) && typeof attachment.url === 'string' && attachment.url !== ''
|
|
31
|
+
badge: (isPictureOfMessage(attachment) && typeof attachment.url === 'string' && attachment.url !== '') ||
|
|
32
|
+
isPastedTextOfMessage(attachment)
|
|
19
33
|
}));
|
|
20
34
|
}
|
|
21
35
|
/** The address of the picture a badge shows, at the size a badge draws it, or '' when the file has none. */
|
|
@@ -30,3 +44,34 @@ export function sentBadgeTitleOf(attachment) {
|
|
|
30
44
|
const name = attachment?.file_name?.trim();
|
|
31
45
|
return name ? name : undefined;
|
|
32
46
|
}
|
|
47
|
+
/** The most of a pasted text the card over its badge needs; the rest of a long text is never read for it. */
|
|
48
|
+
const PASTED_TEXT_READ_MAX_CHARACTERS = 4000;
|
|
49
|
+
/** How long the stored text may take to come before the badge is left with the name of the file. */
|
|
50
|
+
const PASTED_TEXT_FETCH_TIME_LIMIT_MS = 6000;
|
|
51
|
+
/**
|
|
52
|
+
* The beginning of a text that was pasted into a sent message, read from the file the message holds (its address). The message
|
|
53
|
+
* keeps the file and not the excerpt, so it is fetched when the pointer rests on the badge. Resolves to '' when the file cannot be
|
|
54
|
+
* read (the page it is on is not allowed to, the address is gone, it takes too long): the badge then says the name of the file.
|
|
55
|
+
* `fetchText` is the browser's `fetch`, given by the caller so Node can test the rest.
|
|
56
|
+
*/
|
|
57
|
+
export async function fetchPastedTextExcerpt(url, fetchText = (input, init) => fetch(input, init), timeLimitMilliseconds = PASTED_TEXT_FETCH_TIME_LIMIT_MS) {
|
|
58
|
+
if (!url)
|
|
59
|
+
return '';
|
|
60
|
+
const controller = typeof AbortController === 'function' ? new AbortController() : null;
|
|
61
|
+
const timer = controller ? setTimeout(() => controller.abort(), timeLimitMilliseconds) : null;
|
|
62
|
+
try {
|
|
63
|
+
const response = await fetchText(url, controller ? { signal: controller.signal } : undefined);
|
|
64
|
+
if (!response.ok)
|
|
65
|
+
return '';
|
|
66
|
+
const wholeText = await response.text();
|
|
67
|
+
return pastedTextExcerpt(wholeText.slice(0, PASTED_TEXT_READ_MAX_CHARACTERS));
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
chatWarn('[sentReferenceBadges] The text of a pasted text could not be read for its badge:', error);
|
|
71
|
+
return '';
|
|
72
|
+
}
|
|
73
|
+
finally {
|
|
74
|
+
if (timer)
|
|
75
|
+
clearTimeout(timer);
|
|
76
|
+
}
|
|
77
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@widgetic/chat",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.47",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
59
|
"@widgetic/api-sdk": "*",
|
|
60
|
-
"@widgetic/design-system": ">=0.5.
|
|
60
|
+
"@widgetic/design-system": ">=0.5.43",
|
|
61
61
|
"svelte": "^5.25.6"
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
"@tailwindcss/postcss": "^4.1.4",
|
|
76
76
|
"@types/node": "^26.4.1",
|
|
77
77
|
"@widgetic/api-sdk": "^1.0.10",
|
|
78
|
-
"@widgetic/design-system": "^0.5.
|
|
78
|
+
"@widgetic/design-system": "^0.5.43",
|
|
79
79
|
"@widgetic/dev-tools": "^0.2.0",
|
|
80
80
|
"autoprefixer": "^10.4.20",
|
|
81
81
|
"eslint": "^9.0.0",
|