@widgetic/chat 0.1.16 → 0.1.18

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.
@@ -0,0 +1,182 @@
1
+ /**
2
+ * Every word the chat shows to the person using it, in English: the one place to read them, and the keys a page can
3
+ * replace with the `messages` of the chat.
4
+ *
5
+ * A message is plain text. `{name}` is a value the chat puts in; `{count, plural, one {# file} other {# files}}` picks
6
+ * the form that fits a number in the page's language. `\{`, `\}`, `\#` and `\\` write those characters themselves. See
7
+ * `@widgetic/design-system/i18n` for the whole format.
8
+ *
9
+ * Keys are grouped by where the words appear. A key that is left out of a page's `messages` keeps the English text below,
10
+ * so a language can be added a screen at a time.
11
+ *
12
+ * Words that are NOT here, on purpose:
13
+ * - what the assistant says: its replies, the failures the generation service reports and the names of files are shown as
14
+ * they arrive, in the language they were written in;
15
+ * - the lines the host saves into a conversation in English ("Restored from Version 3", "Code generation failed"):
16
+ * the API keeps them in English; the host's `storedLineLabel` (the widget creator's `conversationLineLabel`) says them
17
+ * in the page's language when they are drawn. The chat still matches commits on the English stored text.
18
+ * - the labels of the host: the version labels ("Version 4") are made by the page that gives them to the chat.
19
+ */
20
+ export const CHAT_MESSAGES = {
21
+ // ===== What kind of thing a chat is about =====
22
+ /** What the chat is attached to, in a sentence ("Ask a question about your frame"). */
23
+ 'chat.contextType.frame': 'frame',
24
+ 'chat.contextType.text': 'text',
25
+ 'chat.contextType.image': 'image',
26
+ 'chat.contextType.document': 'document',
27
+ 'chat.contextType.canvas': 'canvas',
28
+ // ===== The header of a chat =====
29
+ /** The line under a chat's title: "frame chat". The kind of thing comes from the messages above. */
30
+ 'chat.header.typeChat': '{type} chat',
31
+ 'chat.header.switchConversation': 'Switch conversation',
32
+ 'chat.header.conversations': 'Conversations',
33
+ 'chat.header.new': 'New',
34
+ /** The name of a conversation that has none. */
35
+ 'chat.header.untitled': 'Untitled',
36
+ 'chat.header.newConversationTitle': 'New conversation',
37
+ 'chat.header.newConversation': 'Start new conversation',
38
+ 'chat.header.close': 'Close chat',
39
+ /** The name of the button that expands a chat that is shown as a small card. */
40
+ 'chat.contextPreview.expand': 'Expand {name} chat context',
41
+ // ===== The name of a conversation the chat starts by itself =====
42
+ 'chat.conversation.defaultTitle': 'Chat about {name}',
43
+ // ===== The messages area =====
44
+ 'chat.messages.startTitle': 'Start a conversation',
45
+ 'chat.messages.startHint': 'Ask a question about your {type} to get started.',
46
+ 'chat.messages.loadingHistory': 'Loading chat history...',
47
+ /** Said while the assistant works on an answer. */
48
+ 'chat.messages.thinking': 'Assistant is thinking...',
49
+ /** The mark on the turn of the version that is open now, and the line that explains it. */
50
+ 'chat.messages.viewing': 'You are here',
51
+ 'chat.messages.viewingTitle': 'This is the version you are looking at',
52
+ 'chat.messages.attachmentMissingTitle': 'Attachment not available',
53
+ 'chat.messages.attachmentMissingLabel': 'Missing file attachment',
54
+ 'chat.messages.attachmentMissingCaption': 'Attachment not saved. Re-attach with Upload, then Retry.',
55
+ 'chat.messages.retry': 'Retry',
56
+ 'chat.messages.retryPromptTitle': 'Run this prompt again as its own message. The sketch stays with the model, not on the bubble.',
57
+ 'chat.messages.retryLastTitle': 'Retry the last user prompt (same generation request)',
58
+ 'chat.messages.upgrade': 'Upgrade',
59
+ 'chat.messages.upgradeTitle': 'Open plans and billing',
60
+ /** Under a prompt: the short id of the commit it made. */
61
+ 'chat.messages.commitId': '(commit id: {id})',
62
+ 'chat.messages.restore': 'Restore Checkpoint',
63
+ 'chat.messages.restoreTitle': 'Restore widget code to this prompt\'s commit',
64
+ 'chat.messages.alreadyHead': 'This checkpoint is already HEAD',
65
+ 'chat.messages.showSuggestions': 'Show suggestions',
66
+ /**
67
+ * Versions are named "Version 4" between the page and the chat, and in the lines the chat saves ("Restored from Version
68
+ * 4"): the chat reads the number out of those words. It says them again in the page's language with these three.
69
+ * `{number}` is the number of the version, `{label}` the name of the version the restore came from.
70
+ */
71
+ 'chat.messages.version': 'Version {number}',
72
+ 'chat.messages.restoredFrom': 'Restored from {label}',
73
+ 'chat.messages.previousVersion': 'a previous version',
74
+ // ===== Ideas the chat offers to start with =====
75
+ 'chat.suggestions.title.frame': 'Suggested actions for this widget',
76
+ 'chat.suggestions.title.text': 'Suggested text improvements',
77
+ 'chat.suggestions.title.image': 'Suggested image analysis',
78
+ 'chat.suggestions.title.document': 'Suggested document actions',
79
+ 'chat.suggestions.title.other': 'Suggested questions',
80
+ 'chat.suggestions.hide': 'Hide suggestions',
81
+ /** The ideas for a widget: tapping one sends it as the person's own message. */
82
+ 'chat.suggestions.frame.generateCode': 'Generate code from this design',
83
+ 'chat.suggestions.frame.improveLayout': 'Suggest improvements for this layout',
84
+ 'chat.suggestions.frame.addInteractivity': 'Add interactive functionality',
85
+ 'chat.suggestions.frame.makeResponsive': 'Make this responsive for mobile',
86
+ 'chat.suggestions.frame.addAnimations': 'Add animations and transitions',
87
+ 'chat.suggestions.text.improveWriting': 'Help improve this writing',
88
+ 'chat.suggestions.text.checkGrammar': 'Check grammar and style',
89
+ 'chat.suggestions.text.alternativePhrasing': 'Suggest alternative phrasing',
90
+ 'chat.suggestions.text.summarize': 'Summarize this content',
91
+ 'chat.suggestions.text.expand': 'Expand on this topic',
92
+ 'chat.suggestions.image.describe': 'Describe what you see in this image',
93
+ 'chat.suggestions.image.altText': 'Generate alt text for accessibility',
94
+ 'chat.suggestions.image.improveDesign': 'Suggest design improvements',
95
+ 'chat.suggestions.image.toCode': 'Convert image to code',
96
+ 'chat.suggestions.image.extractText': 'Extract text from this image',
97
+ 'chat.suggestions.document.summarize': 'Summarize this document',
98
+ 'chat.suggestions.document.keyPoints': 'Extract key points',
99
+ 'chat.suggestions.document.checkErrors': 'Check for errors or inconsistencies',
100
+ 'chat.suggestions.document.improve': 'Suggest improvements',
101
+ 'chat.suggestions.document.outline': 'Create an outline',
102
+ 'chat.suggestions.other.ask': 'Ask a question about this content',
103
+ 'chat.suggestions.other.improve': 'Get suggestions for improvement',
104
+ 'chat.suggestions.other.explain': 'Explain what you see here',
105
+ 'chat.suggestions.other.understand': 'Help me understand this better',
106
+ 'chat.suggestions.other.options': 'What can I do with this?',
107
+ // ===== The box a message is typed in =====
108
+ 'chat.input.placeholder': 'Type your message...',
109
+ 'chat.input.stop': 'Stop generation',
110
+ 'chat.input.sending': 'Sending message...',
111
+ 'chat.input.send': 'Send message',
112
+ // ===== The buttons under the messages =====
113
+ 'chat.actions.screenshot': 'Screenshot',
114
+ 'chat.actions.screenshotTitle': 'Take Screenshot',
115
+ 'chat.actions.screenshotLabel': 'Take screenshot of current content',
116
+ 'chat.actions.record': 'Record',
117
+ 'chat.actions.stop': 'Stop',
118
+ 'chat.actions.startRecordingTitle': 'Start Recording',
119
+ 'chat.actions.stopRecordingTitle': 'Stop Recording',
120
+ 'chat.actions.startRecordingLabel': 'Start recording',
121
+ 'chat.actions.stopRecordingLabel': 'Stop recording',
122
+ 'chat.actions.upload': 'Upload',
123
+ 'chat.actions.uploadTitle': 'Upload File',
124
+ 'chat.actions.uploadLabel': 'Upload file',
125
+ 'chat.actions.complete': 'Complete',
126
+ 'chat.actions.completed': 'Completed',
127
+ 'chat.actions.markCompleteTitle': 'Mark this chat as done. You can still send messages and iterate on the widget.',
128
+ 'chat.actions.markActiveTitle': 'Mark as Active — you can keep iterating either way',
129
+ 'chat.actions.markCompleteLabel': 'Mark conversation as complete',
130
+ 'chat.actions.markActiveLabel': 'Mark conversation as active',
131
+ 'chat.resize.label': 'Resize messages area',
132
+ 'chat.resize.title': 'Drag to resize messages area',
133
+ // ===== Files attached to a message =====
134
+ 'chat.attachment.alt': 'Attachment',
135
+ /** The name of a file when it has none. */
136
+ 'chat.attachment.untitled': 'Untitled',
137
+ /** The name a file is given in the small list of attachments when it has none. */
138
+ 'chat.attachment.fileFallback': 'File',
139
+ /** What a picture of a typed message is called when its file has no name. */
140
+ 'chat.attachment.namelessAlt': 'attachment',
141
+ 'chat.attachment.previewAlt': 'Attachment preview',
142
+ 'chat.attachment.pdfTitle': 'PDF Document',
143
+ 'chat.attachment.noVideo': 'Your browser does not support video playback.',
144
+ 'chat.attachment.view': 'Click to view {name}',
145
+ 'chat.attachment.viewFile': 'Click to view file',
146
+ 'chat.attachment.more': '{count, plural, one {+# more file} other {+# more files}}',
147
+ 'chat.attachment.remove': 'Remove attachment',
148
+ 'chat.attachment.close': 'Close',
149
+ /** The size of a file, from bytes to gigabytes: `{size}` is the number, written the way the language writes numbers ("1.5", "1,5"). */
150
+ 'chat.size.bytes': '{size} B',
151
+ 'chat.size.kb': '{size} KB',
152
+ 'chat.size.mb': '{size} MB',
153
+ 'chat.size.gb': '{size} GB',
154
+ // ===== Code in a message =====
155
+ 'chat.code.copy': 'Copy',
156
+ 'chat.code.copyTitle': 'Copy code',
157
+ 'chat.code.copied': 'Copied!',
158
+ // ===== The state of a conversation =====
159
+ 'chat.status.active': 'Active',
160
+ 'chat.status.completed': 'Completed',
161
+ 'chat.status.processing': 'Processing...',
162
+ 'chat.status.error': 'Error',
163
+ 'chat.status.messageCount': '{count, plural, one {(# message)} other {(# messages)}}',
164
+ // ===== When something goes wrong =====
165
+ 'chat.error.dismiss': 'Dismiss',
166
+ 'chat.error.retryLoad': 'Retry load history',
167
+ 'chat.error.loadHistory': 'Could not load chat history.',
168
+ 'chat.error.initialize': 'Failed to initialize chat. Please try again.',
169
+ 'chat.error.loadConversations': 'Failed to load conversations.',
170
+ 'chat.error.loadConversation': 'Failed to load conversation.',
171
+ 'chat.error.sendMessage': 'Failed to send message. Please try again.',
172
+ 'chat.error.sendSuggestion': 'Failed to send the selected suggestion. Please try again.',
173
+ 'chat.error.screenshotUnavailable': 'Screenshot capture failed — no preview available.',
174
+ 'chat.error.screenshotFailed': 'Failed to capture screenshot',
175
+ 'chat.error.screenshotActionFailed': 'Screenshot action failed. Please try again.',
176
+ 'chat.error.recordingStartFailed': 'Failed to start recording',
177
+ 'chat.error.recordingStopFailed': 'Failed to stop recording',
178
+ 'chat.error.recordingActionFailed': 'Recording action failed. Please try again.',
179
+ 'chat.error.actionFailed': 'The action failed. Please try again.',
180
+ 'chat.error.statusUpdateFailed': 'Failed to update conversation status',
181
+ 'chat.error.restoreFailed': 'Failed to restore checkpoint. Please try again.'
182
+ };
@@ -0,0 +1,5 @@
1
+ import type { ChatMessageKey } from './messages.js';
2
+ /** The messages of the ideas offered for a kind of thing, in the order they are shown. */
3
+ export declare function suggestionKeysFor(type: string): readonly ChatMessageKey[];
4
+ /** The message of the heading over the ideas offered for a kind of thing. */
5
+ export declare function suggestionTitleKeyFor(type: string): ChatMessageKey;
@@ -0,0 +1,66 @@
1
+ /**
2
+ * The ideas the chat offers to start with, and the heading over them, for each kind of thing a chat can be about. They
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
+ * in a list: two ideas that a language happens to say with the same words are still two.
5
+ */
6
+ const SUGGESTION_KEYS = {
7
+ frame: [
8
+ 'chat.suggestions.frame.generateCode',
9
+ 'chat.suggestions.frame.improveLayout',
10
+ 'chat.suggestions.frame.addInteractivity',
11
+ 'chat.suggestions.frame.makeResponsive',
12
+ 'chat.suggestions.frame.addAnimations'
13
+ ],
14
+ text: [
15
+ 'chat.suggestions.text.improveWriting',
16
+ 'chat.suggestions.text.checkGrammar',
17
+ 'chat.suggestions.text.alternativePhrasing',
18
+ 'chat.suggestions.text.summarize',
19
+ 'chat.suggestions.text.expand'
20
+ ],
21
+ image: [
22
+ 'chat.suggestions.image.describe',
23
+ 'chat.suggestions.image.altText',
24
+ 'chat.suggestions.image.improveDesign',
25
+ 'chat.suggestions.image.toCode',
26
+ 'chat.suggestions.image.extractText'
27
+ ],
28
+ document: [
29
+ 'chat.suggestions.document.summarize',
30
+ 'chat.suggestions.document.keyPoints',
31
+ 'chat.suggestions.document.checkErrors',
32
+ 'chat.suggestions.document.improve',
33
+ 'chat.suggestions.document.outline'
34
+ ],
35
+ other: [
36
+ 'chat.suggestions.other.ask',
37
+ 'chat.suggestions.other.improve',
38
+ 'chat.suggestions.other.explain',
39
+ 'chat.suggestions.other.understand',
40
+ 'chat.suggestions.other.options'
41
+ ]
42
+ };
43
+ /** The heading over the ideas, for each kind of thing a chat can be about. */
44
+ const TITLE_KEYS = {
45
+ frame: 'chat.suggestions.title.frame',
46
+ text: 'chat.suggestions.title.text',
47
+ image: 'chat.suggestions.title.image',
48
+ document: 'chat.suggestions.title.document',
49
+ other: 'chat.suggestions.title.other'
50
+ };
51
+ /**
52
+ * A kind of thing the chat has no ideas of its own for (a canvas, or one a host made up) gets the general ones. Only the
53
+ * tables' own entries count, so a kind named like a built-in property of an object ("constructor") cannot pick something
54
+ * else.
55
+ */
56
+ function groupOf(type) {
57
+ return Object.prototype.hasOwnProperty.call(SUGGESTION_KEYS, type) ? type : 'other';
58
+ }
59
+ /** The messages of the ideas offered for a kind of thing, in the order they are shown. */
60
+ export function suggestionKeysFor(type) {
61
+ return SUGGESTION_KEYS[groupOf(type)];
62
+ }
63
+ /** The message of the heading over the ideas offered for a kind of thing. */
64
+ export function suggestionTitleKeyFor(type) {
65
+ return TITLE_KEYS[groupOf(type)];
66
+ }
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ export * from './services/index.js';
4
4
  export * from './adapters/index.js';
5
5
  export * from './utils/index.js';
6
6
  export * from './types/index.js';
7
+ export * from './i18n/index.js';
7
8
  export { default as Chat } from './components/Chat.svelte';
8
9
  export { default as ContextPreview } from './components/ContextPreview.svelte';
9
10
  export { createChatService } from './services/chatService.js';
package/dist/index.js CHANGED
@@ -11,6 +11,8 @@ export * from './adapters/index.js';
11
11
  export * from './utils/index.js';
12
12
  // Types
13
13
  export * from './types/index.js';
14
+ // Languages: the chat's words as messages, and the check of a page's own
15
+ export * from './i18n/index.js';
14
16
  // Re-export main components as named exports for convenience
15
17
  export { default as Chat } from './components/Chat.svelte';
16
18
  export { default as ContextPreview } from './components/ContextPreview.svelte';
@@ -46,6 +46,45 @@ export interface ChatMessage {
46
46
  * generate request (`chipIntent`). Bare-string rows from before the
47
47
  * contract are normalized to refine suggestions by the server on read. */
48
48
  suggestions?: ClarificationSuggestion[];
49
+ /** Design-property controls to render inline under this assistant reply.
50
+ * Set by the host when a deterministic (model-free) design tweak is applied,
51
+ * so the user can keep adjusting the property by hand. Persisted with the
52
+ * reply (beside `suggestions`), so a reload re-renders the card and re-fetches
53
+ * its current values from the composition it names. */
54
+ designControls?: DesignControlRequest;
55
+ }
56
+ /** One design property the host wants rendered as an inline controller. */
57
+ export interface DesignControlProperty {
58
+ id: string;
59
+ label: string;
60
+ /** Lowercased `inputController.type` (colorpicker, slider, dropdown, ...). */
61
+ controllerType: string;
62
+ value: unknown;
63
+ options?: Array<{
64
+ label: string;
65
+ value: string;
66
+ }>;
67
+ min?: number;
68
+ max?: number;
69
+ step?: number;
70
+ helpText?: string;
71
+ }
72
+ /** Payload for the inline design-control card (see `ChatMessage.designControls`). */
73
+ export interface DesignControlRequest {
74
+ summary: string;
75
+ properties: DesignControlProperty[];
76
+ /**
77
+ * The composition the change was authored against, when the host knows it.
78
+ *
79
+ * This is what makes the card re-attach after a reload: the host feeds the
80
+ * controls the live design values of *this* composition only, and renders
81
+ * them read-only while another composition is loaded — otherwise a stale
82
+ * card would write its property into whatever composition happens to be
83
+ * selected. Undefined on cards created before this was recorded, and on
84
+ * hosts that edit design values without a saved composition; both are
85
+ * treated as "attached", which is the behaviour that existed before.
86
+ */
87
+ compositionId?: string | null;
49
88
  }
50
89
  /** One suggestion chip on a clarification card — display copy plus the
51
90
  * machine-readable behavior of tapping it. The client keys off `intent`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.16",
3
+ "version": "0.1.18",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -44,11 +44,12 @@
44
44
  "dev": "npm run dev-sv -- --open",
45
45
  "dev-sv": "NODE_ENV=development vite dev",
46
46
  "build": "vite build",
47
- "package": "svelte-package",
48
- "package:watch": "svelte-package --watch",
47
+ "package": "svelte-kit sync && svelte-package",
48
+ "package:watch": "svelte-kit sync && svelte-package --watch",
49
49
  "prepackage:watch": "npm run lps",
50
50
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --diagnostic-sources \"js,svelte\"",
51
51
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
52
+ "test": "node --test \"tests/**/*.test.mjs\"",
52
53
  "lint": "prettier --check . && eslint .",
53
54
  "format": "prettier --write ."
54
55
  },
@@ -89,6 +90,7 @@
89
90
  "vite": "^6.2.6"
90
91
  },
91
92
  "overrides": {
93
+ "tar": "^7.5.22",
92
94
  "bits-ui": {
93
95
  "@melt-ui/svelte": "^0.86.3"
94
96
  },