@widgetic/chat 0.1.41 → 0.1.43

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +461 -6
  2. package/dist/components/Chat.svelte +1117 -119
  3. package/dist/components/Chat.svelte.d.ts +112 -2
  4. package/dist/components/ChatComposer.svelte +389 -8
  5. package/dist/components/ChatComposer.svelte.d.ts +71 -2
  6. package/dist/components/ChatMessageQueue.svelte +56 -0
  7. package/dist/components/ChatMessageQueue.svelte.d.ts +20 -0
  8. package/dist/components/ChatMessages.svelte +477 -46
  9. package/dist/components/ChatMessages.svelte.d.ts +45 -2
  10. package/dist/components/ComposerAttachmentsTray.svelte +42 -10
  11. package/dist/components/ComposerAttachmentsTray.svelte.d.ts +5 -0
  12. package/dist/components/ComposerMentionChips.svelte +53 -0
  13. package/dist/components/ComposerMentionChips.svelte.d.ts +15 -0
  14. package/dist/components/FollowUpCard.svelte +134 -0
  15. package/dist/components/FollowUpCard.svelte.d.ts +17 -0
  16. package/dist/components/MentionChip.svelte +41 -0
  17. package/dist/components/MentionChip.svelte.d.ts +12 -0
  18. package/dist/components/MentionMenu.svelte +114 -0
  19. package/dist/components/MentionMenu.svelte.d.ts +19 -0
  20. package/dist/components/SelectedElementChip.svelte +73 -0
  21. package/dist/components/SelectedElementChip.svelte.d.ts +20 -0
  22. package/dist/components/agent/AgentAvatar.svelte +6 -4
  23. package/dist/components/agent/AgentAvatar.svelte.d.ts +1 -1
  24. package/dist/components/agent/CodeCard.svelte +122 -27
  25. package/dist/components/agent/CodeCard.svelte.d.ts +3 -0
  26. package/dist/components/agent/CodeDiff.svelte +180 -0
  27. package/dist/components/agent/CodeDiff.svelte.d.ts +10 -0
  28. package/dist/components/agent/GenerationModule.svelte +13 -2
  29. package/dist/components/agent/GenerationModule.svelte.d.ts +3 -0
  30. package/dist/components/index.d.ts +5 -0
  31. package/dist/components/index.js +12 -0
  32. package/dist/errors/logTechnicalUserError.d.ts +1 -0
  33. package/dist/errors/logTechnicalUserError.js +37 -0
  34. package/dist/i18n/messages.d.ts +106 -1
  35. package/dist/i18n/messages.js +112 -1
  36. package/dist/i18n/sketchLocales.js +8 -8
  37. package/dist/messageQueue.d.ts +83 -0
  38. package/dist/messageQueue.js +84 -0
  39. package/dist/services/sketchAssistantClient.js +6 -2
  40. package/dist/services/sketchAssistantErrors.d.ts +4 -0
  41. package/dist/services/sketchAssistantErrors.js +22 -0
  42. package/dist/services/sketchAssistantOrchestrator.d.ts +1 -6
  43. package/dist/services/sketchAssistantOrchestrator.js +10 -24
  44. package/dist/services/sketchAssistantReply.js +3 -1
  45. package/dist/stores/chatStore.d.ts +5 -0
  46. package/dist/stores/chatStore.js +21 -0
  47. package/dist/types/agent.d.ts +4 -3
  48. package/dist/types/attachment.d.ts +16 -0
  49. package/dist/types/config.d.ts +6 -0
  50. package/dist/types/index.d.ts +1 -0
  51. package/dist/types/index.js +2 -0
  52. package/dist/types/mention.d.ts +40 -0
  53. package/dist/types/mention.js +8 -0
  54. package/dist/types/message.d.ts +60 -1
  55. package/dist/utils/agentTurn.d.ts +40 -9
  56. package/dist/utils/agentTurn.js +43 -11
  57. package/dist/utils/attachmentProgress.d.ts +12 -0
  58. package/dist/utils/attachmentProgress.js +18 -0
  59. package/dist/utils/bubbleRichFit.d.ts +68 -0
  60. package/dist/utils/bubbleRichFit.js +45 -0
  61. package/dist/utils/bubbleShrinkWrap.d.ts +8 -1
  62. package/dist/utils/bubbleShrinkWrap.js +113 -17
  63. package/dist/utils/codeChanges.d.ts +103 -0
  64. package/dist/utils/codeChanges.js +226 -0
  65. package/dist/utils/codeHighlight.js +1 -0
  66. package/dist/utils/codeStreamFormat.d.ts +5 -2
  67. package/dist/utils/composerMentions.d.ts +96 -0
  68. package/dist/utils/composerMentions.js +217 -0
  69. package/dist/utils/followUps.d.ts +74 -0
  70. package/dist/utils/followUps.js +116 -0
  71. package/dist/utils/generationArchiveStore.d.ts +6 -0
  72. package/dist/utils/generationArchiveStore.js +11 -3
  73. package/dist/utils/index.d.ts +14 -0
  74. package/dist/utils/index.js +22 -0
  75. package/dist/utils/orderedLine.d.ts +29 -0
  76. package/dist/utils/orderedLine.js +17 -0
  77. package/dist/utils/pastedContent.d.ts +99 -0
  78. package/dist/utils/pastedContent.js +258 -0
  79. package/dist/utils/questionCards.d.ts +131 -0
  80. package/dist/utils/questionCards.js +287 -0
  81. package/dist/utils/referenceItems.d.ts +36 -0
  82. package/dist/utils/referenceItems.js +56 -0
  83. package/dist/utils/selectedElementChip.d.ts +47 -0
  84. package/dist/utils/selectedElementChip.js +73 -0
  85. package/dist/utils/sentReferenceBadges.d.ts +26 -0
  86. package/dist/utils/sentReferenceBadges.js +32 -0
  87. package/package.json +1 -1
@@ -1,4 +1,7 @@
1
- import type { AttachmentInput } from '../types/attachment.js';
1
+ import { type Snippet } from 'svelte';
2
+ import type { ComposerMention, MentionSource } from '../types/mention.js';
3
+ import { type ComposerCompletion, type ComposerEditing, type ComposerSendOptions, type ReferenceHoverEvent, type ReferenceItem } from '@widgetic/design-system/components/chat/index';
4
+ import { type PastedAttachment } from '../utils/pastedContent.js';
2
5
  export type ComposerModelOption = {
3
6
  id: string;
4
7
  label: string;
@@ -14,10 +17,30 @@ interface Props {
14
17
  models?: ComposerModelOption[];
15
18
  selectedModelId?: string | null;
16
19
  onSelectModel?: (modelId: string) => void;
17
- onSend: (content: string, attachments?: AttachmentInput[]) => void;
20
+ /**
21
+ * `content` is the text a person reads: a reference is the word `#hero_banner`, whatever room its badge takes in the box. With
22
+ * `referenceItems`, `options.references` lists the attached files the text names (see `ComposerSendOptions`).
23
+ */
24
+ onSend: (content: string, options?: ComposerSendOptions) => void;
18
25
  onStop?: () => void;
26
+ /**
27
+ * What the person typed while an agent works. Given, the send control queues it (the host keeps it until the agent is done) and
28
+ * Enter does not stop the agent; left out, the composer has no queue and the control and Enter stop the agent, as before.
29
+ */
30
+ onQueue?: (text: string) => void;
31
+ /**
32
+ * A queued message is open in the composer: the pill of the edit ("Editing ×") above the text and, in place of Send, the check
33
+ * that saves it. Left out, or null, the composer is not editing.
34
+ */
35
+ editing?: ComposerEditing | null;
19
36
  onInputChange?: (text: string) => void;
20
37
  onFilesDropped?: (files: File[]) => void;
38
+ /**
39
+ * What a paste brings in as files to attach: a screenshot or a file on the clipboard, or a long text (which comes as a text
40
+ * file, with the first words of the text as its label). Without it the composer pastes as the browser does: a page that
41
+ * cannot attach files gets no attachment from a paste, and the text goes into the box.
42
+ */
43
+ onFilesPasted?: (pasted: PastedAttachment[]) => void;
21
44
  /** Opens the file picker. The "+" of the toolbar is drawn only when the page can attach files. */
22
45
  onAttach?: () => void;
23
46
  /** Figma side-panel composer: no top border on the shell; DS Composer keeps its own border. */
@@ -26,6 +49,52 @@ interface Props {
26
49
  sendIcon?: 'send' | 'arrow-up';
27
50
  /** Increment from the host to nudge Send before publish. */
28
51
  sendNudgeToken?: number;
52
+ /**
53
+ * What sits inside the message box above the text (the chips of the parts picked on the preview). The box draws nothing
54
+ * for it while this is not given, so a message with no parts looks as it always did.
55
+ */
56
+ attachments?: Snippet;
57
+ /**
58
+ * For a page that uses the message box on its own, to write one short thing (the note of a part picked on the preview).
59
+ * The chat's own box asks for none of these four and looks and acts as it always did.
60
+ *
61
+ * `autofocus`: the box takes the focus when it is drawn, with the caret after what is already written.
62
+ */
63
+ autofocus?: boolean;
64
+ /** The name a screen reader gives the box. Without it the placeholder is its name. */
65
+ inputLabel?: string;
66
+ /** What the Enter key of a touch keyboard says: "done" for a box that ends a note, "send" for one that sends a message. */
67
+ enterKeyHint?: 'enter' | 'done' | 'go' | 'next' | 'previous' | 'search' | 'send';
68
+ /** The name of the send button, for a box whose Enter is not "Send message" (the note of a part is added to the chat). */
69
+ sendLabel?: string;
70
+ /**
71
+ * Ghost text after the caret: a likely continuation of what is typed, taken with Tab (or a tap). The box draws nothing and
72
+ * asks for nothing while this is not given. Enter still sends, and the suggestion goes with the message.
73
+ */
74
+ completion?: ComposerCompletion;
75
+ /**
76
+ * The attached files the message may refer to with `#` (a menu with their pictures opens, and a choice becomes a badge in the
77
+ * text), in tray order. Left out, the box has no references; an empty list is a box that has none to offer yet.
78
+ */
79
+ referenceItems?: ReferenceItem[];
80
+ /** The most files one message may refer to (the host's request has a cap). Default: no cap. */
81
+ maxReferences?: number;
82
+ /** A badge in the text, or a row of the `#` menu, is on a file (`label: null` when it left): the tray rings the same file. */
83
+ onReferenceHover?: (event: ReferenceHoverEvent) => void;
84
+ /**
85
+ * What the person can pick with `@` in the message box: lists of rows that the page hands over (connected apps, compositions, ...).
86
+ * Left out or empty, `@` is an ordinary character and the box behaves exactly as it always did.
87
+ */
88
+ mentionSources?: readonly MentionSource[];
89
+ /** What the message already holds as picks: the rows picked as many times as `mentionLimit` allows are the last the menu offers. */
90
+ mentions?: readonly ComposerMention[];
91
+ /** The most picks one message holds. */
92
+ mentionLimit?: number;
93
+ /**
94
+ * A row was picked from the menu. Its name was written into the box already (`@Name `); the page keeps the pick, draws its
95
+ * chip and sends it with the message.
96
+ */
97
+ onMentionPick?: (mention: ComposerMention) => void;
29
98
  }
30
99
  declare const ChatComposer: import("svelte").Component<Props, {}, "value">;
31
100
  type ChatComposer = ReturnType<typeof ChatComposer>;
@@ -0,0 +1,56 @@
1
+ <script lang="ts">
2
+ import { QueueCard, type QueueCardItem } from '@widgetic/design-system/components/chat/index';
3
+ import { useChatLanguage } from '../i18n/language.js';
4
+ import type { QueuedMessage } from '../messageQueue.js';
5
+
6
+ const { t } = useChatLanguage();
7
+
8
+ /**
9
+ * The card of the messages that wait for the agent, above the composer: the design system draws it, the chat gives it the
10
+ * words (every one of them, in the language of the page) and what the buttons of a row do.
11
+ */
12
+ interface Props {
13
+ /** The waiting messages, the oldest first: the newest is at the bottom. */
14
+ items: QueuedMessage[];
15
+ /** The message that is open in the composer, if one is. */
16
+ editingId?: string | null;
17
+ /** The person pressed Stop while messages waited: the header says so. */
18
+ paused?: boolean;
19
+ /** Left out when the host cannot stop its agent: a row then has no "Send now". */
20
+ onSendNow?: (id: string) => void;
21
+ onEdit?: (id: string) => void;
22
+ onDelete?: (id: string) => void;
23
+ }
24
+
25
+ let { items, editingId = null, paused = false, onSendNow, onEdit, onDelete }: Props = $props();
26
+
27
+ // One row for each message: what was written, and the count of its files in the words of the page
28
+ const cardItems = $derived<QueueCardItem[]>(
29
+ items.map((item) => {
30
+ const attachmentCount = item.attachments.length;
31
+ return {
32
+ id: item.id,
33
+ text: item.text,
34
+ attachmentCount,
35
+ attachmentLabel: attachmentCount > 0 ? $t('chat.queue.attachments', { count: attachmentCount }) : undefined,
36
+ };
37
+ }),
38
+ );
39
+ </script>
40
+
41
+ <QueueCard
42
+ class="prompt-chat-queue"
43
+ title={$t('chat.queue.title', { count: items.length })}
44
+ status={paused ? $t('chat.queue.paused') : ''}
45
+ items={cardItems}
46
+ {editingId}
47
+ messages={{
48
+ sendNow: $t('chat.queue.sendNow'),
49
+ edit: $t('chat.queue.edit'),
50
+ delete: $t('chat.queue.delete'),
51
+ editing: $t('chat.queue.editing'),
52
+ }}
53
+ {onSendNow}
54
+ {onEdit}
55
+ {onDelete}
56
+ />
@@ -0,0 +1,20 @@
1
+ import type { QueuedMessage } from '../messageQueue.js';
2
+ /**
3
+ * The card of the messages that wait for the agent, above the composer: the design system draws it, the chat gives it the
4
+ * words (every one of them, in the language of the page) and what the buttons of a row do.
5
+ */
6
+ interface Props {
7
+ /** The waiting messages, the oldest first: the newest is at the bottom. */
8
+ items: QueuedMessage[];
9
+ /** The message that is open in the composer, if one is. */
10
+ editingId?: string | null;
11
+ /** The person pressed Stop while messages waited: the header says so. */
12
+ paused?: boolean;
13
+ /** Left out when the host cannot stop its agent: a row then has no "Send now". */
14
+ onSendNow?: (id: string) => void;
15
+ onEdit?: (id: string) => void;
16
+ onDelete?: (id: string) => void;
17
+ }
18
+ declare const ChatMessageQueue: import("svelte").Component<Props, {}, "">;
19
+ type ChatMessageQueue = ReturnType<typeof ChatMessageQueue>;
20
+ export default ChatMessageQueue;