@widgetic/chat 0.1.36 → 0.1.38

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.
@@ -31,7 +31,7 @@ export declare const CHAT_MESSAGES: {
31
31
  readonly 'chat.header.new': "New";
32
32
  /** The name of a conversation that has none. */
33
33
  readonly 'chat.header.untitled': "Untitled";
34
- readonly 'chat.header.newConversationTitle': "New conversation";
34
+ readonly 'chat.header.newConversationTitle': "New chat";
35
35
  readonly 'chat.header.newConversation': "Start new conversation";
36
36
  /** Label for the debug console icon in the panel chat header. */
37
37
  readonly 'chat.header.console': "Console";
@@ -68,6 +68,12 @@ export declare const CHAT_MESSAGES: {
68
68
  readonly 'chat.messages.attachmentMissingTitle': "Attachment not available";
69
69
  readonly 'chat.messages.attachmentMissingLabel': "Missing file attachment";
70
70
  readonly 'chat.messages.attachmentMissingCaption': "Attachment not saved. Re-attach with Upload, then send it again.";
71
+ /** The alert card a failed reply is shown in (docked panel): its title, its line, and the button that runs the prompt again. */
72
+ readonly 'chat.messages.failedTitle': "Could not build the widget";
73
+ readonly 'chat.messages.failedHint': "The build did not finish. Your sketch is safe, so you can try again.";
74
+ readonly 'chat.messages.failedRetry': "Try again";
75
+ /** The line a build the person stopped leaves in the conversation (docked panel): it is their own command, not a failure. */
76
+ readonly 'chat.messages.stoppedByYou': "You stopped the build.";
71
77
  readonly 'chat.messages.upgrade': "Upgrade";
72
78
  readonly 'chat.messages.upgradeTitle': "Open plans and billing";
73
79
  /** Under a prompt: the short id of the commit it made. */
@@ -92,12 +98,19 @@ export declare const CHAT_MESSAGES: {
92
98
  readonly 'chat.messages.restoredFrom': "Restored from {label}";
93
99
  readonly 'chat.messages.previousVersion': "a previous version";
94
100
  readonly 'chat.suggestions.title.frame': "Suggested actions for this widget";
101
+ readonly 'chat.suggestions.title.panelEmpty': "Suggestions";
102
+ readonly 'chat.suggestions.title.tryNext': "Try next";
95
103
  readonly 'chat.suggestions.title.text': "Suggested text improvements";
96
104
  readonly 'chat.suggestions.title.image': "Suggested image analysis";
97
105
  readonly 'chat.suggestions.title.document': "Suggested document actions";
98
106
  readonly 'chat.suggestions.title.other': "Suggested questions";
99
107
  readonly 'chat.suggestions.hide': "Hide suggestions";
100
108
  /** The ideas for a widget: tapping one sends it as the person's own message. */
109
+ readonly 'chat.suggestions.panel.countdown': "A countdown to a sale";
110
+ readonly 'chat.suggestions.panel.testimonials': "Customer testimonials";
111
+ readonly 'chat.suggestions.panel.gallery': "A before and after gallery";
112
+ readonly 'chat.suggestions.panel.changeEndDate': "Change the end date";
113
+ readonly 'chat.suggestions.panel.biggerButton': "Make the button bigger";
101
114
  readonly 'chat.suggestions.frame.generateCode': "Generate code from this design";
102
115
  readonly 'chat.suggestions.frame.improveLayout': "Improve this layout";
103
116
  readonly 'chat.suggestions.frame.addInteractivity': "Add interactive functionality";
@@ -124,10 +137,13 @@ export declare const CHAT_MESSAGES: {
124
137
  readonly 'chat.suggestions.other.understand': "Help me understand this better";
125
138
  readonly 'chat.suggestions.other.options': "What can I do with this?";
126
139
  readonly 'chat.input.placeholder': "Type your message...";
140
+ readonly 'chat.input.placeholderCreate': "Describe your widget…";
141
+ readonly 'chat.input.placeholderFollowUp': "Ask for a change…";
127
142
  readonly 'chat.input.stop': "Stop generation";
128
143
  readonly 'chat.input.sending': "Sending message...";
129
144
  readonly 'chat.input.send': "Send message";
130
145
  readonly 'chat.input.tooLong': "Message is too long";
146
+ readonly 'chat.input.publishNudge': "First generate your widget, then you can publish it.";
131
147
  readonly 'chat.composer.assistant': "Assistant";
132
148
  readonly 'chat.messages.scrollToBottom': "Scroll to latest messages";
133
149
  readonly 'chat.messages.clarificationPrompt': "Which option fits best?";
@@ -33,7 +33,7 @@ export const CHAT_MESSAGES = {
33
33
  'chat.header.new': 'New',
34
34
  /** The name of a conversation that has none. */
35
35
  'chat.header.untitled': 'Untitled',
36
- 'chat.header.newConversationTitle': 'New conversation',
36
+ 'chat.header.newConversationTitle': 'New chat',
37
37
  'chat.header.newConversation': 'Start new conversation',
38
38
  /** Label for the debug console icon in the panel chat header. */
39
39
  'chat.header.console': 'Console',
@@ -72,6 +72,12 @@ export const CHAT_MESSAGES = {
72
72
  'chat.messages.attachmentMissingTitle': 'Attachment not available',
73
73
  'chat.messages.attachmentMissingLabel': 'Missing file attachment',
74
74
  'chat.messages.attachmentMissingCaption': 'Attachment not saved. Re-attach with Upload, then send it again.',
75
+ /** The alert card a failed reply is shown in (docked panel): its title, its line, and the button that runs the prompt again. */
76
+ 'chat.messages.failedTitle': 'Could not build the widget',
77
+ 'chat.messages.failedHint': 'The build did not finish. Your sketch is safe, so you can try again.',
78
+ 'chat.messages.failedRetry': 'Try again',
79
+ /** The line a build the person stopped leaves in the conversation (docked panel): it is their own command, not a failure. */
80
+ 'chat.messages.stoppedByYou': 'You stopped the build.',
75
81
  'chat.messages.upgrade': 'Upgrade',
76
82
  'chat.messages.upgradeTitle': 'Open plans and billing',
77
83
  /** Under a prompt: the short id of the commit it made. */
@@ -97,12 +103,19 @@ export const CHAT_MESSAGES = {
97
103
  'chat.messages.previousVersion': 'a previous version',
98
104
  // ===== Ideas the chat offers to start with =====
99
105
  'chat.suggestions.title.frame': 'Suggested actions for this widget',
106
+ 'chat.suggestions.title.panelEmpty': 'Suggestions',
107
+ 'chat.suggestions.title.tryNext': 'Try next',
100
108
  'chat.suggestions.title.text': 'Suggested text improvements',
101
109
  'chat.suggestions.title.image': 'Suggested image analysis',
102
110
  'chat.suggestions.title.document': 'Suggested document actions',
103
111
  'chat.suggestions.title.other': 'Suggested questions',
104
112
  'chat.suggestions.hide': 'Hide suggestions',
105
113
  /** The ideas for a widget: tapping one sends it as the person's own message. */
114
+ 'chat.suggestions.panel.countdown': 'A countdown to a sale',
115
+ 'chat.suggestions.panel.testimonials': 'Customer testimonials',
116
+ 'chat.suggestions.panel.gallery': 'A before and after gallery',
117
+ 'chat.suggestions.panel.changeEndDate': 'Change the end date',
118
+ 'chat.suggestions.panel.biggerButton': 'Make the button bigger',
106
119
  'chat.suggestions.frame.generateCode': 'Generate code from this design',
107
120
  'chat.suggestions.frame.improveLayout': 'Improve this layout',
108
121
  'chat.suggestions.frame.addInteractivity': 'Add interactive functionality',
@@ -130,10 +143,13 @@ export const CHAT_MESSAGES = {
130
143
  'chat.suggestions.other.options': 'What can I do with this?',
131
144
  // ===== The box a message is typed in =====
132
145
  'chat.input.placeholder': 'Type your message...',
146
+ 'chat.input.placeholderCreate': 'Describe your widget…',
147
+ 'chat.input.placeholderFollowUp': 'Ask for a change…',
133
148
  'chat.input.stop': 'Stop generation',
134
149
  'chat.input.sending': 'Sending message...',
135
150
  'chat.input.send': 'Send message',
136
151
  'chat.input.tooLong': 'Message is too long',
152
+ 'chat.input.publishNudge': 'First generate your widget, then you can publish it.',
137
153
  'chat.composer.assistant': 'Assistant',
138
154
  'chat.messages.scrollToBottom': 'Scroll to latest messages',
139
155
  'chat.messages.clarificationPrompt': 'Which option fits best?',
@@ -0,0 +1,18 @@
1
+ /** Host-facing translations for `chat.input.publishNudge` (one row per ui-sdk module locale). */
2
+ export declare const PUBLISH_NUDGE_ENGLISH: "First generate your widget, then you can publish it.";
3
+ export declare const PUBLISH_NUDGE_BY_LOCALE: {
4
+ readonly en: "First generate your widget, then you can publish it.";
5
+ readonly ar: "أنشئ الويدجت أولاً، ثم يمكنك نشره.";
6
+ readonly da: "Generér din widget først, og udgiv den derefter.";
7
+ readonly de: "Erzeuge zuerst dein Widget, danach kannst du es veröffentlichen.";
8
+ readonly es: "Primero genera tu widget y luego podrás publicarlo.";
9
+ readonly fa: "اول ویجت را تولید کنید، بعد می‌توانید آن را منتشر کنید.";
10
+ readonly fr: "Générez d'abord votre widget, puis vous pourrez le publier.";
11
+ readonly he: "תחילה צור את הווידג׳ט, ואז תוכל לפרסם אותו.";
12
+ readonly nl: "Genereer eerst je widget; daarna kun je publiceren.";
13
+ readonly 'pt-BR': "Primeiro gere o seu widget; depois você poderá publicá-lo.";
14
+ readonly sv: "Generera widgeten först, sedan kan du publicera den.";
15
+ readonly ur: "پہلے اپنا ویجٹ بنائیں، پھر آپ اسے شائع کر سکتے ہیں۔";
16
+ readonly 'zh-CN': "请先生成小组件,然后再发布。";
17
+ };
18
+ export type PublishNudgeLocale = keyof typeof PUBLISH_NUDGE_BY_LOCALE;
@@ -0,0 +1,17 @@
1
+ /** Host-facing translations for `chat.input.publishNudge` (one row per ui-sdk module locale). */
2
+ export const PUBLISH_NUDGE_ENGLISH = 'First generate your widget, then you can publish it.';
3
+ export const PUBLISH_NUDGE_BY_LOCALE = {
4
+ en: PUBLISH_NUDGE_ENGLISH,
5
+ ar: 'أنشئ الويدجت أولاً، ثم يمكنك نشره.',
6
+ da: 'Generér din widget først, og udgiv den derefter.',
7
+ de: 'Erzeuge zuerst dein Widget, danach kannst du es veröffentlichen.',
8
+ es: 'Primero genera tu widget y luego podrás publicarlo.',
9
+ fa: 'اول ویجت را تولید کنید، بعد می‌توانید آن را منتشر کنید.',
10
+ fr: "Générez d'abord votre widget, puis vous pourrez le publier.",
11
+ he: 'תחילה צור את הווידג׳ט, ואז תוכל לפרסם אותו.',
12
+ nl: 'Genereer eerst je widget; daarna kun je publiceren.',
13
+ 'pt-BR': 'Primeiro gere o seu widget; depois você poderá publicá-lo.',
14
+ sv: 'Generera widgeten först, sedan kan du publicera den.',
15
+ ur: 'پہلے اپنا ویجٹ بنائیں، پھر آپ اسے شائع کر سکتے ہیں۔',
16
+ 'zh-CN': '请先生成小组件,然后再发布。',
17
+ };
@@ -3,3 +3,9 @@ import type { ChatMessageKey } from './messages.js';
3
3
  export declare function suggestionKeysFor(type: string): readonly ChatMessageKey[];
4
4
  /** The message of the heading over the ideas offered for a kind of thing. */
5
5
  export declare function suggestionTitleKeyFor(type: string): ChatMessageKey;
6
+ /** Empty side-panel suggestions (creator dock), in display order. */
7
+ export declare function panelEmptySuggestionKeys(): readonly ChatMessageKey[];
8
+ /** Heading over the empty side-panel suggestions. */
9
+ export declare function panelEmptySuggestionTitleKey(): ChatMessageKey;
10
+ export declare function panelFollowUpSuggestionKeys(): readonly ChatMessageKey[];
11
+ export declare function panelFollowUpSuggestionTitleKey(): ChatMessageKey;
@@ -3,6 +3,16 @@
3
3
  * are message keys, so the words follow the language of the page, and a key (not the text) is what tells two ideas apart
4
4
  * in a list: two ideas that a language happens to say with the same words are still two.
5
5
  */
6
+ /** Figma side-panel empty state (widget creator): three starter ideas with icons. */
7
+ const PANEL_EMPTY_SUGGESTION_KEYS = [
8
+ 'chat.suggestions.panel.countdown',
9
+ 'chat.suggestions.panel.testimonials',
10
+ 'chat.suggestions.panel.gallery',
11
+ ];
12
+ const PANEL_FOLLOW_UP_SUGGESTION_KEYS = [
13
+ 'chat.suggestions.panel.changeEndDate',
14
+ 'chat.suggestions.panel.biggerButton',
15
+ ];
6
16
  const SUGGESTION_KEYS = {
7
17
  frame: [
8
18
  'chat.suggestions.frame.generateCode',
@@ -64,3 +74,17 @@ export function suggestionKeysFor(type) {
64
74
  export function suggestionTitleKeyFor(type) {
65
75
  return TITLE_KEYS[groupOf(type)];
66
76
  }
77
+ /** Empty side-panel suggestions (creator dock), in display order. */
78
+ export function panelEmptySuggestionKeys() {
79
+ return PANEL_EMPTY_SUGGESTION_KEYS;
80
+ }
81
+ /** Heading over the empty side-panel suggestions. */
82
+ export function panelEmptySuggestionTitleKey() {
83
+ return 'chat.suggestions.title.panelEmpty';
84
+ }
85
+ export function panelFollowUpSuggestionKeys() {
86
+ return PANEL_FOLLOW_UP_SUGGESTION_KEYS;
87
+ }
88
+ export function panelFollowUpSuggestionTitleKey() {
89
+ return 'chat.suggestions.title.tryNext';
90
+ }
@@ -0,0 +1,5 @@
1
+ export type SendNudgePhase = 'idle' | 'active' | 'cleared';
2
+ export type SendNudgeEvent = 'trigger' | 'autoHide' | 'userInteract' | 'reset';
3
+ /** Small state machine for the Send-button publish nudge (bounce + tooltip). */
4
+ export declare function reduceSendNudge(phase: SendNudgePhase, event: SendNudgeEvent): SendNudgePhase;
5
+ export declare const SEND_NUDGE_VISIBLE_MS = 4000;
@@ -0,0 +1,18 @@
1
+ /** Small state machine for the Send-button publish nudge (bounce + tooltip). */
2
+ export function reduceSendNudge(phase, event) {
3
+ switch (phase) {
4
+ case 'idle':
5
+ return event === 'trigger' ? 'active' : 'idle';
6
+ case 'active':
7
+ if (event === 'autoHide' || event === 'userInteract')
8
+ return 'cleared';
9
+ if (event === 'trigger')
10
+ return 'active';
11
+ return phase;
12
+ case 'cleared':
13
+ return event === 'reset' ? 'idle' : event === 'trigger' ? 'active' : 'cleared';
14
+ default:
15
+ return 'idle';
16
+ }
17
+ }
18
+ export const SEND_NUDGE_VISIBLE_MS = 4000;
@@ -43,6 +43,11 @@ export interface AttachmentInput {
43
43
  uploadedUrl?: string;
44
44
  /** Widgetic uploads row id (for codegen attachmentIds) */
45
45
  uploadId?: string;
46
+ /**
47
+ * An image as a `data:` URL, read when it is attached. A `blob:` preview and a CDN address do not come back after a
48
+ * refresh (the first dies with the page, the second is not an image the draft can rebuild a File from), so the draft keeps this.
49
+ */
50
+ persistedDataUrl?: string;
46
51
  uploadProgress?: number;
47
52
  }
48
53
  /**
@@ -52,6 +52,13 @@ export interface ChatMessage {
52
52
  * reply (beside `suggestions`), so a reload re-renders the card and re-fetches
53
53
  * its current values from the composition it names. */
54
54
  designControls?: DesignControlRequest;
55
+ /** Host-owned flags about how this reply is shown. `panelFollowUp: false`
56
+ * keeps this reply's suggestion chips out of the docked creator panel's
57
+ * follow-up list (the panel shows the chips of the last reply that has any,
58
+ * unless the host says otherwise). Absent for every reply that sets nothing. */
59
+ metadata?: {
60
+ panelFollowUp?: boolean;
61
+ } | null;
55
62
  }
56
63
  /** One design property the host wants rendered as an inline controller. */
57
64
  export interface DesignControlProperty {
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Splits a line of chat text into plain text and web links, so a message can show an address as a link a person can
3
+ * click, and let the long address wrap inside the message instead of running out of the panel.
4
+ *
5
+ * Only `http://` and `https://` addresses become links: a `javascript:` or `data:` address in a message is plain text.
6
+ */
7
+ export type LinkifiedSegment = {
8
+ type: 'text';
9
+ text: string;
10
+ } | {
11
+ type: 'link';
12
+ text: string;
13
+ href: string;
14
+ };
15
+ /** The segments of `text` in order; joining their `text` gives `text` back. */
16
+ export declare function splitTextIntoLinks(text: string): LinkifiedSegment[];
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Splits a line of chat text into plain text and web links, so a message can show an address as a link a person can
3
+ * click, and let the long address wrap inside the message instead of running out of the panel.
4
+ *
5
+ * Only `http://` and `https://` addresses become links: a `javascript:` or `data:` address in a message is plain text.
6
+ */
7
+ /** An address runs until a space or a character that cannot be part of one in running text. */
8
+ const ADDRESS_PATTERN = /https?:\/\/[^\s<>"'`]+/gi;
9
+ /** Punctuation that ends a sentence rather than an address ("see https://a.com/x."). */
10
+ const SENTENCE_END = /[.,;:!?]+$/;
11
+ /**
12
+ * Where the address in `candidate` really ends: trailing sentence punctuation is not part of it, and neither is a closing
13
+ * bracket without an opening one inside the address ("(see https://a.com/x)").
14
+ */
15
+ function trimAddressEnd(candidate) {
16
+ let address = candidate;
17
+ let changed = true;
18
+ while (changed && address.length > 0) {
19
+ changed = false;
20
+ const withoutPunctuation = address.replace(SENTENCE_END, '');
21
+ if (withoutPunctuation !== address) {
22
+ address = withoutPunctuation;
23
+ changed = true;
24
+ }
25
+ const last = address.at(-1);
26
+ const opener = last === ')' ? '(' : last === ']' ? '[' : last === '}' ? '{' : null;
27
+ if (opener && last) {
28
+ const opens = address.split(opener).length - 1;
29
+ const closes = address.split(last).length - 1;
30
+ if (closes > opens) {
31
+ address = address.slice(0, -1);
32
+ changed = true;
33
+ }
34
+ }
35
+ }
36
+ return address;
37
+ }
38
+ /** The segments of `text` in order; joining their `text` gives `text` back. */
39
+ export function splitTextIntoLinks(text) {
40
+ const source = String(text ?? '');
41
+ const segments = [];
42
+ let cursor = 0;
43
+ for (const match of source.matchAll(ADDRESS_PATTERN)) {
44
+ const start = match.index ?? 0;
45
+ const address = trimAddressEnd(match[0]);
46
+ // "https://" alone is not an address
47
+ if (!/^https?:\/\/[^\s/?#]+/i.test(address))
48
+ continue;
49
+ if (start > cursor)
50
+ segments.push({ type: 'text', text: source.slice(cursor, start) });
51
+ segments.push({ type: 'link', text: address, href: address });
52
+ cursor = start + address.length;
53
+ }
54
+ if (cursor < source.length)
55
+ segments.push({ type: 'text', text: source.slice(cursor) });
56
+ return segments;
57
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.36",
3
+ "version": "0.1.38",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",