@widgetic/chat 0.1.47 → 0.1.49

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.
@@ -439,6 +439,10 @@
439
439
  composerModels?: ComposerModelOption[];
440
440
  selectedComposerModelId?: string | null;
441
441
  onSelectComposerModel?: (modelId: string) => void;
442
+ /**
443
+ * Rewrites the text in the composer (Magic Enhance). Left out, the sparkle control is not drawn.
444
+ */
445
+ onEnhancePrompt?: (prompt: string) => Promise<string>;
442
446
  }
443
447
 
444
448
  // Expose methods to parent component
@@ -489,7 +493,7 @@
489
493
  updateLastUserMessageAttachments: (attachments: Array<{ id?: string; url: string; file_type?: string; file_name?: string | null }>) => void;
490
494
  }
491
495
 
492
- let { context, config = {}, class: className = '', locale = null, messages: languageMessages = null, dir = undefined, style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onQuestionsAnswered, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onRateVersion, versionRatings: ratingsFromHost = {}, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onSketchUndo, onUpgradePlans, onUploadChatFile, showHeader = true, showPanelHeader = false, showConsoleControl = false, sendNudgeToken = 0, completion, isReferenceableAttachment = isReferenceablePicture, maxReferences, consoleOpen = false, onToggleConsole, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, onMessagesDrag, onMessagesDragEnd, onLoadOlderMessages, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], isGenerating = false, generationStream = '', generationThinking = '', generationPlan = null, generationPlanPending = false, generationChanges = null, generationSummary = null, onStopGeneration, members = [], currentUser = null, renderAgentAvatar, agentSound, tightBubbles = true, referenceBadges = true, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, showSelector = false, isSelectorActive = false, selectedElements = [], onToggleSelector, onRemoveSelectedElement, onClearSelectedElements, activeSelectedElementId = null, onSelectedElementClick, mentionSources = [], mentionLimit = DEFAULT_MENTION_LIMIT, composerExtras, storedLineLabel, composerModels = [], selectedComposerModelId = null, onSelectComposerModel }: Props = $props();
496
+ let { context, config = {}, class: className = '', locale = null, messages: languageMessages = null, dir = undefined, style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onQuestionsAnswered, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onRateVersion, versionRatings: ratingsFromHost = {}, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onSketchUndo, onUpgradePlans, onUploadChatFile, showHeader = true, showPanelHeader = false, showConsoleControl = false, sendNudgeToken = 0, completion, isReferenceableAttachment = isReferenceablePicture, maxReferences, consoleOpen = false, onToggleConsole, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, onMessagesDrag, onMessagesDragEnd, onLoadOlderMessages, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], isGenerating = false, generationStream = '', generationThinking = '', generationPlan = null, generationPlanPending = false, generationChanges = null, generationSummary = null, onStopGeneration, members = [], currentUser = null, renderAgentAvatar, agentSound, tightBubbles = true, referenceBadges = true, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, showSelector = false, isSelectorActive = false, selectedElements = [], onToggleSelector, onRemoveSelectedElement, onClearSelectedElements, activeSelectedElementId = null, onSelectedElementClick, mentionSources = [], mentionLimit = DEFAULT_MENTION_LIMIT, composerExtras, storedLineLabel, composerModels = [], selectedComposerModelId = null, onSelectComposerModel, onEnhancePrompt }: Props = $props();
493
497
 
494
498
  // The words of everything inside the chat, in the language the page chose. The page can change the language while the
495
499
  // chat is open: the settings are read again whenever they change (and setting the same language again does nothing).
@@ -3720,6 +3724,7 @@
3720
3724
  ? (pastedAttachments, selection) => void addPastedAttachments(pastedAttachments, selection)
3721
3725
  : undefined}
3722
3726
  onAttach={config?.features?.fileUpload !== false ? () => void handleUpload() : undefined}
3727
+ onEnhancePrompt={onEnhancePrompt}
3723
3728
  canSendWithoutText={(selectedElements ?? []).some((element) => !!element.note?.trim())}
3724
3729
  />
3725
3730
  </div>
@@ -410,6 +410,10 @@ interface Props {
410
410
  composerModels?: ComposerModelOption[];
411
411
  selectedComposerModelId?: string | null;
412
412
  onSelectComposerModel?: (modelId: string) => void;
413
+ /**
414
+ * Rewrites the text in the composer (Magic Enhance). Left out, the sparkle control is not drawn.
415
+ */
416
+ onEnhancePrompt?: (prompt: string) => Promise<string>;
413
417
  }
414
418
  declare const Chat: import("svelte").Component<Props, {}, "">;
415
419
  type Chat = ReturnType<typeof Chat>;
@@ -5,6 +5,7 @@
5
5
  import { useChatLanguage } from '../i18n/language.js';
6
6
  import { dirForUserText, useTextDirection } from '@widgetic/design-system/components/textDirection';
7
7
  import { HintTooltip } from '@widgetic/design-system/components';
8
+ import IconSparkles from '@tabler/icons-svelte/icons/sparkles';
8
9
  import {
9
10
  Composer,
10
11
  IconButton,
@@ -127,6 +128,11 @@
127
128
  * chip and sends it with the message.
128
129
  */
129
130
  onMentionPick?: (mention: ComposerMention) => void;
131
+ /**
132
+ * Rewrites the text in the box (Magic Enhance). Given, a sparkle control sits next to attach.
133
+ * The host calls the planner and returns the new text; this component puts it in the box.
134
+ */
135
+ onEnhancePrompt?: (prompt: string) => Promise<string>;
130
136
  }
131
137
 
132
138
  let {
@@ -163,8 +169,11 @@
163
169
  mentions = [],
164
170
  mentionLimit = DEFAULT_MENTION_LIMIT,
165
171
  onMentionPick,
172
+ onEnhancePrompt,
166
173
  }: Props = $props();
167
174
 
175
+ let isEnhancing = $state(false);
176
+
168
177
  const composerSendIcon = $derived(panelLayout ? 'arrow-up' : sendIcon);
169
178
 
170
179
  // The shell, to reach the message box in it. The design system's Composer draws the box (a textarea) and does not hand it out,
@@ -506,6 +515,25 @@
506
515
  onQueue?.(trimmed);
507
516
  }
508
517
 
518
+ async function handleEnhancePromptClick() {
519
+ const trimmed = (value ?? '').trim();
520
+ if (!trimmed || !onEnhancePrompt || isEnhancing) return;
521
+ if (isSending || isGenerating) return;
522
+ isEnhancing = true;
523
+ try {
524
+ const next = await onEnhancePrompt(trimmed);
525
+ if (typeof next === 'string' && next.trim()) {
526
+ value = next.trim();
527
+ onInputChange?.(value);
528
+ chatLog('[ChatComposer] Prompt enhanced', { length: value.length });
529
+ }
530
+ } catch (error) {
531
+ chatError('[ChatComposer] Prompt enhance failed:', error);
532
+ } finally {
533
+ isEnhancing = false;
534
+ }
535
+ }
536
+
509
537
  function handleComposerSend(text: string, options?: ComposerSendOptions) {
510
538
  const trimmed = text.trim();
511
539
  if (!trimmed && !allowEmptySend) return;
@@ -519,8 +547,8 @@
519
547
  }
520
548
  </script>
521
549
 
522
- <!-- Figma: Composer toolbar, left side: attach ("+"), then the mode. -->
523
- {#snippet attachControl()}
550
+ <!-- Figma: Composer toolbar, left side: attach ("+"), Magic Enhance, then the mode. -->
551
+ {#snippet composerLeading()}
524
552
  {#if onAttach}
525
553
  <!-- Resting the pointer on the "+" (the tooltip's usual delay) says what it adds and which kinds of files go in. -->
526
554
  <HintTooltip content={$t('chat.actions.uploadTooltip')} side="top" align="start">
@@ -550,6 +578,30 @@
550
578
  {/snippet}
551
579
  </HintTooltip>
552
580
  {/if}
581
+ {#if onEnhancePrompt}
582
+ <HintTooltip content={isEnhancing ? $t('chat.input.enhancing') : $t('chat.input.enhance')} side="top" align="start">
583
+ {#snippet trigger({ props })}
584
+ <IconButton
585
+ {...props}
586
+ variant="ghost"
587
+ class="chat-composer-enhance-btn cursor-pointer"
588
+ data-testid="chat-composer-enhance"
589
+ label={isEnhancing ? $t('chat.input.enhancing') : $t('chat.input.enhance')}
590
+ disabled={!(value ?? '').trim() || isEnhancing || (isSending && !isGenerating) || isGenerating}
591
+ onclick={() => void handleEnhancePromptClick()}
592
+ >
593
+ {#if isEnhancing}
594
+ <svg class="size-4 animate-spin" viewBox="0 0 24 24" aria-hidden="true">
595
+ <circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2" opacity="0.3"/>
596
+ <path d="M22 12a10 10 0 0 1-10 10" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
597
+ </svg>
598
+ {:else}
599
+ <IconSparkles class="size-4 stroke-2" aria-hidden="true" />
600
+ {/if}
601
+ </IconButton>
602
+ {/snippet}
603
+ </HintTooltip>
604
+ {/if}
553
605
  {/snippet}
554
606
 
555
607
  <!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -589,7 +641,7 @@
589
641
  onStop={() => onStop?.()}
590
642
  onQueue={onQueue ? handleComposerQueue : undefined}
591
643
  {editing}
592
- leading={attachControl}
644
+ leading={composerLeading}
593
645
  {attachments}
594
646
  {completion}
595
647
  references={composerReferences}
@@ -606,3 +658,11 @@
606
658
  />
607
659
  {/if}
608
660
  </div>
661
+
662
+ <style>
663
+ :global(.chat-composer-enhance-btn:focus),
664
+ :global(.chat-composer-enhance-btn:focus-visible) {
665
+ outline: none;
666
+ box-shadow: none;
667
+ }
668
+ </style>
@@ -98,6 +98,11 @@ interface Props {
98
98
  * chip and sends it with the message.
99
99
  */
100
100
  onMentionPick?: (mention: ComposerMention) => void;
101
+ /**
102
+ * Rewrites the text in the box (Magic Enhance). Given, a sparkle control sits next to attach.
103
+ * The host calls the planner and returns the new text; this component puts it in the box.
104
+ */
105
+ onEnhancePrompt?: (prompt: string) => Promise<string>;
101
106
  }
102
107
  declare const ChatComposer: import("svelte").Component<Props, {
103
108
  placeCaret: (position: number) => Promise<void>;
@@ -24,6 +24,8 @@
24
24
  */
25
25
  showAttachmentsTray?: boolean;
26
26
  onSend: (content: string, attachments?: AttachmentInput[]) => void;
27
+ /** Rewrites the text in the box. Left out, Magic Enhance is not drawn. */
28
+ onEnhancePrompt?: (prompt: string) => Promise<string>;
27
29
  onStop?: () => void;
28
30
  onInputChange: (text: string) => void;
29
31
  onAttachmentsChange: (attachments: AttachmentInput[]) => void;
@@ -46,6 +48,7 @@
46
48
  isGenerating = false,
47
49
  showAttachmentsTray = true,
48
50
  onSend,
51
+ onEnhancePrompt,
49
52
  onStop,
50
53
  onInputChange,
51
54
  onAttachmentsChange,
@@ -57,6 +60,7 @@
57
60
  }: Props = $props();
58
61
 
59
62
  let isFileDragOver = $state(false);
63
+ let isEnhancing = $state(false);
60
64
 
61
65
  // What the send button is called (and says in its tooltip): it turns into Stop while the assistant answers
62
66
  let sendLabel = $derived(
@@ -114,6 +118,20 @@
114
118
  return value.trim().length > 0 || attachments.length > 0 || canSendWithoutText;
115
119
  }
116
120
 
121
+ async function handleEnhancePromptClick() {
122
+ const trimmed = value.trim();
123
+ if (!trimmed || !onEnhancePrompt || isEnhancing || isSending || isGenerating) return;
124
+ isEnhancing = true;
125
+ try {
126
+ const next = await onEnhancePrompt(trimmed);
127
+ if (typeof next === 'string' && next.trim()) {
128
+ onInputChange(next.trim());
129
+ }
130
+ } finally {
131
+ isEnhancing = false;
132
+ }
133
+ }
134
+
117
135
  function handleSubmit() {
118
136
  if (!hasSomethingToSend()) return;
119
137
  if (isSending) return;
@@ -339,6 +357,27 @@
339
357
  ></textarea>
340
358
 
341
359
  <div class="send-button-ct flex items-center gap-2">
360
+ {#if onEnhancePrompt}
361
+ <button
362
+ type="button"
363
+ class="enhance-prompt-btn w-8 h-8 rounded-lg flex items-center justify-center cursor-pointer text-gray-600 hover:bg-gray-200 dark:text-gray-200 dark:hover:bg-gray-600"
364
+ onclick={() => void handleEnhancePromptClick()}
365
+ disabled={!value.trim() || isEnhancing || isSending || isGenerating}
366
+ aria-label={isEnhancing ? $t('chat.input.enhancing') : $t('chat.input.enhance')}
367
+ title={isEnhancing ? $t('chat.input.enhancing') : $t('chat.input.enhance')}
368
+ >
369
+ {#if isEnhancing}
370
+ <svg class="w-4 h-4 animate-spin" viewBox="0 0 24 24" aria-hidden="true">
371
+ <circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2" opacity="0.3"/>
372
+ <path d="M22 12a10 10 0 0 1-10 10" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"/>
373
+ </svg>
374
+ {:else}
375
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" class="w-4 h-4" aria-hidden="true">
376
+ <path d="M16 18a2 2 0 0 1 2 2 2 2 0 0 1 2-2 2 2 0 0 1-2-2 2 2 0 0 1-2 2m0-12a2 2 0 0 1 2 2 2 2 0 0 1 2-2 2 2 0 0 1-2-2 2 2 0 0 1-2 2m-7 12a6 6 0 0 1 6-6 6 6 0 0 1-6-6 6 6 0 0 1-6 6 6 6 0 0 1 6 6" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
377
+ </svg>
378
+ {/if}
379
+ </button>
380
+ {/if}
342
381
  <!-- Send Button -->
343
382
  <button
344
383
  class="send-button-btn w-8 h-8 rounded-lg flex items-center justify-center transition-colors"
@@ -397,7 +436,9 @@
397
436
 
398
437
  <style>
399
438
  .send-button-btn:focus,
400
- .send-button-btn:focus-visible {
439
+ .send-button-btn:focus-visible,
440
+ .enhance-prompt-btn:focus,
441
+ .enhance-prompt-btn:focus-visible {
401
442
  outline: none;
402
443
  box-shadow: none;
403
444
  }
@@ -12,6 +12,8 @@ interface Props {
12
12
  */
13
13
  showAttachmentsTray?: boolean;
14
14
  onSend: (content: string, attachments?: AttachmentInput[]) => void;
15
+ /** Rewrites the text in the box. Left out, Magic Enhance is not drawn. */
16
+ onEnhancePrompt?: (prompt: string) => Promise<string>;
15
17
  onStop?: () => void;
16
18
  onInputChange: (text: string) => void;
17
19
  onAttachmentsChange: (attachments: AttachmentInput[]) => void;
@@ -1403,7 +1403,10 @@
1403
1403
  onUpgradePlans();
1404
1404
  return;
1405
1405
  }
1406
- window.location.assign('/workspaces/personal/settings/billing');
1406
+ // The chat does not know which workspace it is open in, and there is no personal workspace to stand in for it: the person
1407
+ // picks the workspace on the site's chooser and goes on to its billing from there. (The widget creator, which does know,
1408
+ // passes its own `onUpgradePlans`.)
1409
+ window.location.assign('/workspaces');
1407
1410
  }
1408
1411
 
1409
1412
  function turnIsDesignCardOnly(turn: ChatTurn): boolean {
@@ -187,6 +187,8 @@ export declare const CHAT_MESSAGES: {
187
187
  readonly 'chat.input.stop': "Stop generation";
188
188
  readonly 'chat.input.sending': "Sending message...";
189
189
  readonly 'chat.input.send': "Send message";
190
+ readonly 'chat.input.enhance': "Magic Enhance";
191
+ readonly 'chat.input.enhancing': "Enhancing...";
190
192
  readonly 'chat.input.tooLong': "Message is too long";
191
193
  readonly 'chat.input.publishNudge': "First generate your widget, then you can publish it.";
192
194
  /** The name of the send control while an agent works and a message is typed: the message waits its turn. */
@@ -193,6 +193,8 @@ export const CHAT_MESSAGES = {
193
193
  'chat.input.stop': 'Stop generation',
194
194
  'chat.input.sending': 'Sending message...',
195
195
  'chat.input.send': 'Send message',
196
+ 'chat.input.enhance': 'Magic Enhance',
197
+ 'chat.input.enhancing': 'Enhancing...',
196
198
  'chat.input.tooLong': 'Message is too long',
197
199
  'chat.input.publishNudge': 'First generate your widget, then you can publish it.',
198
200
  /** The name of the send control while an agent works and a message is typed: the message waits its turn. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.47",
3
+ "version": "0.1.49",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",