@widgetic/chat 0.1.15 → 0.1.17
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/dist/components/ActionBar.svelte +37 -1
- package/dist/components/ActionBar.svelte.d.ts +7 -0
- package/dist/components/Chat.svelte +79 -7
- package/dist/components/Chat.svelte.d.ts +22 -3
- package/dist/components/ChatMessages.svelte +35 -6
- package/dist/components/ChatMessages.svelte.d.ts +4 -1
- package/dist/types/message.d.ts +39 -0
- package/package.json +3 -3
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
2
3
|
import type { ChatContext } from '../types/context.js';
|
|
3
4
|
|
|
4
5
|
// Props
|
|
@@ -18,6 +19,12 @@
|
|
|
18
19
|
onRecordStop?: () => void;
|
|
19
20
|
onComplete?: (detail: { completed: boolean }) => void;
|
|
20
21
|
onError?: (detail: { type: string; error: unknown }) => void;
|
|
22
|
+
/** Host controls rendered on the right, after Complete. */
|
|
23
|
+
children?: Snippet;
|
|
24
|
+
/** Replaces Complete. The host owns the control. */
|
|
25
|
+
completeReplacement?: Snippet;
|
|
26
|
+
/** When true, render completeReplacement instead of Complete. */
|
|
27
|
+
replaceComplete?: boolean;
|
|
21
28
|
}
|
|
22
29
|
|
|
23
30
|
let {
|
|
@@ -36,6 +43,9 @@
|
|
|
36
43
|
onRecordStop,
|
|
37
44
|
onComplete,
|
|
38
45
|
onError,
|
|
46
|
+
children,
|
|
47
|
+
completeReplacement,
|
|
48
|
+
replaceComplete = false,
|
|
39
49
|
}: Props = $props();
|
|
40
50
|
|
|
41
51
|
// Handle screenshot capture — attachments do not require an existing conversation.
|
|
@@ -141,7 +151,9 @@
|
|
|
141
151
|
</button>
|
|
142
152
|
{/if}
|
|
143
153
|
|
|
144
|
-
{#if
|
|
154
|
+
{#if replaceComplete && completeReplacement}
|
|
155
|
+
{@render completeReplacement()}
|
|
156
|
+
{:else if showComplete}
|
|
145
157
|
<!-- Completion Toggle -->
|
|
146
158
|
<button
|
|
147
159
|
class="action-button completion-button"
|
|
@@ -165,6 +177,12 @@
|
|
|
165
177
|
{/if}
|
|
166
178
|
</button>
|
|
167
179
|
{/if}
|
|
180
|
+
|
|
181
|
+
{#if children}
|
|
182
|
+
<div class="action-bar-extras">
|
|
183
|
+
{@render children()}
|
|
184
|
+
</div>
|
|
185
|
+
{/if}
|
|
168
186
|
</div>
|
|
169
187
|
|
|
170
188
|
<style>
|
|
@@ -183,6 +201,24 @@
|
|
|
183
201
|
pointer-events: none;
|
|
184
202
|
}
|
|
185
203
|
|
|
204
|
+
.action-bar-extras {
|
|
205
|
+
display: contents;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.action-bar select:focus,
|
|
209
|
+
.action-bar select:focus-visible {
|
|
210
|
+
outline: none;
|
|
211
|
+
box-shadow: none;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.action-bar button:focus,
|
|
215
|
+
.action-bar button:focus-visible,
|
|
216
|
+
.action-bar a:focus,
|
|
217
|
+
.action-bar a:focus-visible {
|
|
218
|
+
outline: none;
|
|
219
|
+
box-shadow: none;
|
|
220
|
+
}
|
|
221
|
+
|
|
186
222
|
.action-button {
|
|
187
223
|
display: flex;
|
|
188
224
|
align-items: center;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
1
2
|
import type { ChatContext } from '../types/context.js';
|
|
2
3
|
interface Props {
|
|
3
4
|
context: ChatContext;
|
|
@@ -20,6 +21,12 @@ interface Props {
|
|
|
20
21
|
type: string;
|
|
21
22
|
error: unknown;
|
|
22
23
|
}) => void;
|
|
24
|
+
/** Host controls rendered on the right, after Complete. */
|
|
25
|
+
children?: Snippet;
|
|
26
|
+
/** Replaces Complete. The host owns the control. */
|
|
27
|
+
completeReplacement?: Snippet;
|
|
28
|
+
/** When true, render completeReplacement instead of Complete. */
|
|
29
|
+
replaceComplete?: boolean;
|
|
23
30
|
}
|
|
24
31
|
declare const ActionBar: import("svelte").Component<Props, {}, "">;
|
|
25
32
|
type ActionBar = ReturnType<typeof ActionBar>;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount, onDestroy, untrack } from 'svelte';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
3
4
|
import { chatStore, getCurrentState, getCurrentMessages } from '../stores/chatStore.js';
|
|
4
5
|
import { createChatService } from '../services/chatService.js';
|
|
5
6
|
import { setLogsEnabled, chatLog, chatWarn } from '../utils/logger.js';
|
|
6
7
|
import type { ChatConfig, ChatContext } from '../types/index.js';
|
|
7
|
-
import type { ClarificationSuggestion } from '../types/message.js';
|
|
8
|
+
import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
|
|
8
9
|
import type { AttachmentInput } from '../types/attachment.js';
|
|
9
10
|
import ChatMessages from './ChatMessages.svelte';
|
|
10
11
|
import ChatInput from './ChatInput.svelte';
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
messageType: string,
|
|
50
51
|
attachments?: Array<{ url?: string; file?: File; file_type?: string; file_name?: string | null; file_size?: number | null; display_order?: number }>,
|
|
51
52
|
suggestions?: ClarificationSuggestion[],
|
|
53
|
+
designControls?: DesignControlRequest,
|
|
52
54
|
) => Promise<any>;
|
|
53
55
|
onRestoreCheckpointBackend?: (conversationId: string, checkpointMessageId: string) => Promise<any>;
|
|
54
56
|
onTakeScreenshot?: () => Promise<string | null>;
|
|
@@ -105,12 +107,30 @@
|
|
|
105
107
|
/** Host is running widget codegen — send button becomes stop. */
|
|
106
108
|
isGenerating?: boolean;
|
|
107
109
|
onStopGeneration?: () => void;
|
|
110
|
+
/**
|
|
111
|
+
* Renders the inline design-control card attached to an assistant reply
|
|
112
|
+
* (see `addDesignControlsMessage`). The host owns the controls — the chat
|
|
113
|
+
* package stays free of design-schema/editor dependencies — and receives
|
|
114
|
+
* the resolution payload to render. When omitted, the message text still
|
|
115
|
+
* shows and the card is simply skipped.
|
|
116
|
+
*/
|
|
117
|
+
renderDesignControls?: Snippet<[DesignControlRequest]>;
|
|
118
|
+
/** Extra controls in the action bar, next to Complete. The host owns them. */
|
|
119
|
+
actionBarExtras?: Snippet;
|
|
120
|
+
/** Replaces the Complete button. The host owns it. */
|
|
121
|
+
completeReplacement?: Snippet;
|
|
122
|
+
/** When true, the replacement is shown instead of Complete. */
|
|
123
|
+
replaceComplete?: boolean;
|
|
124
|
+
/** Panel under the action bar, shown when those extras expand. */
|
|
125
|
+
composerExtras?: Snippet;
|
|
108
126
|
}
|
|
109
127
|
|
|
110
128
|
// Expose methods to parent component
|
|
111
129
|
interface ChatMethods {
|
|
112
130
|
sendMessage: (content: string, attachments?: Array<File | AttachmentInput>, options?: { skipIntentGate?: boolean; chipIntent?: ClarificationSuggestion['intent'] }) => Promise<void>;
|
|
113
|
-
addAssistantMessage: (content: string, skipPersist?: boolean, suggestions?: ClarificationSuggestion[]) => void;
|
|
131
|
+
addAssistantMessage: (content: string, skipPersist?: boolean, suggestions?: ClarificationSuggestion[], designControls?: DesignControlRequest) => void;
|
|
132
|
+
/** Add an assistant reply carrying an inline design-control card (no generation). */
|
|
133
|
+
addDesignControlsMessage: (content: string, designControls: DesignControlRequest) => void;
|
|
114
134
|
addUserMessage: (content: string, attachments?: Array<{ id: string; url: string; file_type: string; file_name: string; file_size?: number }>) => void;
|
|
115
135
|
/** Returns the current conversation ID (null if no conversation is active). */
|
|
116
136
|
getConversationId: () => string | null;
|
|
@@ -142,7 +162,7 @@
|
|
|
142
162
|
updateLastUserMessageAttachments: (attachments: Array<{ id?: string; url: string; file_type?: string; file_name?: string | null }>) => void;
|
|
143
163
|
}
|
|
144
164
|
|
|
145
|
-
let { context, config = {}, class: className = '', style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], viewingVersion = null, isGenerating = false, onStopGeneration }: Props = $props();
|
|
165
|
+
let { context, config = {}, class: className = '', style = '', isCompleted = false, onStatsUpdate, onChatReady, onCompletionToggle, onSendMessage, onLoadConversations, onLoadMessages, onCreateConversation, onSaveMessage, onRestoreCheckpointBackend, onTakeScreenshot, onConversationChange, onDraftChange, onRetryMessage, onUploadChatFile, showHeader = true, headerTitle = '', showDescriptionHeader = true, showLogs = true, resizeExpandsContainer = false, onMessagesResize, widgetHeadCommitSha = null, versionLabelByCommitSha = {}, versionLabelByPrompt = {}, versionTimeline = [], viewingVersion = null, isGenerating = false, onStopGeneration, renderDesignControls, actionBarExtras, completeReplacement, replaceComplete = false, composerExtras }: Props = $props();
|
|
146
166
|
|
|
147
167
|
function notifyDraftChange() {
|
|
148
168
|
onDraftChange?.();
|
|
@@ -555,7 +575,7 @@
|
|
|
555
575
|
/** Add an assistant message to the current conversation (called by parent via chatMethods).
|
|
556
576
|
* When skipPersist is true, the message is shown locally but not saved to DB
|
|
557
577
|
* (use when the backend already persists its own version). */
|
|
558
|
-
function addAssistantMessage(content: string, skipPersist = false, suggestions?: ClarificationSuggestion[]) {
|
|
578
|
+
function addAssistantMessage(content: string, skipPersist = false, suggestions?: ClarificationSuggestion[], designControls?: DesignControlRequest) {
|
|
559
579
|
if (!currentConversationId) return;
|
|
560
580
|
const assistantMsg = {
|
|
561
581
|
id: `assistant_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
|
@@ -570,7 +590,8 @@
|
|
|
570
590
|
_optimistic: false,
|
|
571
591
|
_failed: false,
|
|
572
592
|
_retryCount: 0,
|
|
573
|
-
...(suggestions && suggestions.length > 0 ? { suggestions } : {})
|
|
593
|
+
...(suggestions && suggestions.length > 0 ? { suggestions } : {}),
|
|
594
|
+
...(designControls ? { designControls } : {})
|
|
574
595
|
};
|
|
575
596
|
chatStore.actions.addMessage(currentConversationId, assistantMsg);
|
|
576
597
|
|
|
@@ -587,7 +608,11 @@
|
|
|
587
608
|
// persistence (intent gate) already saved this turn when it served the
|
|
588
609
|
// card; this write is the client-driven path (local-only conversations,
|
|
589
610
|
// hosts without the gate) and lands with the same shape either way.
|
|
590
|
-
|
|
611
|
+
// The card rides the same write as the reply text it sits under, so a
|
|
612
|
+
// reload re-renders the reply *and* its inline controls instead of losing
|
|
613
|
+
// half the turn. `compositionId` on the payload is what lets the host
|
|
614
|
+
// re-attach the controls to the composition they were authored against.
|
|
615
|
+
onSaveMessage(convId, content, 'assistant', undefined, suggestions, designControls).then(saved => {
|
|
591
616
|
if (saved?.id && saved.id !== assistantMsg.id) {
|
|
592
617
|
chatStore.actions.updateMessageId(convId, assistantMsg.id, saved.id);
|
|
593
618
|
}
|
|
@@ -600,6 +625,13 @@
|
|
|
600
625
|
}
|
|
601
626
|
}
|
|
602
627
|
|
|
628
|
+
/** Add an assistant reply that carries an inline design-control card. The
|
|
629
|
+
* host applied a deterministic design change and wants the user to keep
|
|
630
|
+
* adjusting the property by hand; nothing is generated. */
|
|
631
|
+
function addDesignControlsMessage(content: string, designControls: DesignControlRequest) {
|
|
632
|
+
addAssistantMessage(content, false, undefined, designControls);
|
|
633
|
+
}
|
|
634
|
+
|
|
603
635
|
/** Add a user message to the UI without triggering generation (called by parent via chatMethods).
|
|
604
636
|
* Also persists to DB via onSaveMessage so multi-turn history is complete. */
|
|
605
637
|
function addUserMessage(content: string, attachments?: Array<{ id: string; url: string; file_type: string; file_name: string; file_size?: number }>) {
|
|
@@ -1463,6 +1495,7 @@
|
|
|
1463
1495
|
const chatMethods: ChatMethods = {
|
|
1464
1496
|
sendMessage,
|
|
1465
1497
|
addAssistantMessage,
|
|
1498
|
+
addDesignControlsMessage,
|
|
1466
1499
|
addUserMessage,
|
|
1467
1500
|
getConversationId: () => currentConversationId,
|
|
1468
1501
|
addImageAttachment,
|
|
@@ -1528,6 +1561,33 @@
|
|
|
1528
1561
|
let messagesAreaHeight: number | null = $state(null);
|
|
1529
1562
|
let isResizingMessages = $state(false);
|
|
1530
1563
|
const MIN_MESSAGES_HEIGHT = 120;
|
|
1564
|
+
let generationOptionsEl: HTMLDivElement | null = $state(null);
|
|
1565
|
+
let lastGenerationOptionsHeight = 0;
|
|
1566
|
+
let generationOptionsHeightReady = false;
|
|
1567
|
+
|
|
1568
|
+
// Brand kit / libraries sit in the footer. Grow the host by that height so
|
|
1569
|
+
// the messages area stays put and the input moves down inside the scroller.
|
|
1570
|
+
$effect(() => {
|
|
1571
|
+
const el = generationOptionsEl;
|
|
1572
|
+
if (!el || !resizeExpandsContainer) return;
|
|
1573
|
+
const observer = new ResizeObserver(() => {
|
|
1574
|
+
const next = Math.round(el.getBoundingClientRect().height);
|
|
1575
|
+
if (!generationOptionsHeightReady) {
|
|
1576
|
+
lastGenerationOptionsHeight = next;
|
|
1577
|
+
generationOptionsHeightReady = true;
|
|
1578
|
+
return;
|
|
1579
|
+
}
|
|
1580
|
+
const delta = next - lastGenerationOptionsHeight;
|
|
1581
|
+
if (Math.abs(delta) < 2) return;
|
|
1582
|
+
lastGenerationOptionsHeight = next;
|
|
1583
|
+
untrack(() => onMessagesResize)?.(delta);
|
|
1584
|
+
});
|
|
1585
|
+
observer.observe(el);
|
|
1586
|
+
return () => {
|
|
1587
|
+
observer.disconnect();
|
|
1588
|
+
generationOptionsHeightReady = false;
|
|
1589
|
+
};
|
|
1590
|
+
});
|
|
1531
1591
|
|
|
1532
1592
|
function handleMessagesResizeStart(e: PointerEvent) {
|
|
1533
1593
|
e.preventDefault();
|
|
@@ -1633,6 +1693,7 @@
|
|
|
1633
1693
|
onRestoreCheckpoint={handleRestoreCheckpoint}
|
|
1634
1694
|
onRetryMessage={handleRetryMessage}
|
|
1635
1695
|
onClarificationSuggestionSelected={handleClarificationSuggestionSelected}
|
|
1696
|
+
{renderDesignControls}
|
|
1636
1697
|
/>
|
|
1637
1698
|
</div>
|
|
1638
1699
|
|
|
@@ -1667,7 +1728,18 @@
|
|
|
1667
1728
|
onRecordStop={() => void handleRecordStop()}
|
|
1668
1729
|
onComplete={(detail) => void handleComplete(detail)}
|
|
1669
1730
|
onError={handleActionError}
|
|
1670
|
-
|
|
1731
|
+
{completeReplacement}
|
|
1732
|
+
{replaceComplete}
|
|
1733
|
+
>
|
|
1734
|
+
{#if actionBarExtras}
|
|
1735
|
+
{@render actionBarExtras()}
|
|
1736
|
+
{/if}
|
|
1737
|
+
</ActionBar>
|
|
1738
|
+
{#if composerExtras}
|
|
1739
|
+
<div class="prompt-chat-generation-options shrink-0 flex flex-col" bind:this={generationOptionsEl}>
|
|
1740
|
+
{@render composerExtras()}
|
|
1741
|
+
</div>
|
|
1742
|
+
{/if}
|
|
1671
1743
|
|
|
1672
1744
|
{#if localAttachments.length > 0}
|
|
1673
1745
|
<div class="prompt-chat-attachments-tray-ct flex flex-wrap gap-2 p-3 border-t border-gray-100 bg-white shrink-0">
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
1
2
|
import type { ChatConfig, ChatContext } from '../types/index.js';
|
|
2
|
-
import type { ClarificationSuggestion } from '../types/message.js';
|
|
3
|
+
import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
|
|
3
4
|
import type { AttachmentInput } from '../types/attachment.js';
|
|
4
5
|
interface ChatMethods {
|
|
5
6
|
sendMessage: (content: string, attachments?: Array<File | AttachmentInput>, options?: {
|
|
6
7
|
skipIntentGate?: boolean;
|
|
7
8
|
chipIntent?: ClarificationSuggestion['intent'];
|
|
8
9
|
}) => Promise<void>;
|
|
9
|
-
addAssistantMessage: (content: string, skipPersist?: boolean, suggestions?: ClarificationSuggestion[]) => void;
|
|
10
|
+
addAssistantMessage: (content: string, skipPersist?: boolean, suggestions?: ClarificationSuggestion[], designControls?: DesignControlRequest) => void;
|
|
11
|
+
/** Add an assistant reply carrying an inline design-control card (no generation). */
|
|
12
|
+
addDesignControlsMessage: (content: string, designControls: DesignControlRequest) => void;
|
|
10
13
|
addUserMessage: (content: string, attachments?: Array<{
|
|
11
14
|
id: string;
|
|
12
15
|
url: string;
|
|
@@ -88,7 +91,7 @@ interface Props {
|
|
|
88
91
|
file_name?: string | null;
|
|
89
92
|
file_size?: number | null;
|
|
90
93
|
display_order?: number;
|
|
91
|
-
}>, suggestions?: ClarificationSuggestion[]) => Promise<any>;
|
|
94
|
+
}>, suggestions?: ClarificationSuggestion[], designControls?: DesignControlRequest) => Promise<any>;
|
|
92
95
|
onRestoreCheckpointBackend?: (conversationId: string, checkpointMessageId: string) => Promise<any>;
|
|
93
96
|
onTakeScreenshot?: () => Promise<string | null>;
|
|
94
97
|
/** Fires whenever the active conversation ID changes (including initial null → uuid). */
|
|
@@ -154,6 +157,22 @@ interface Props {
|
|
|
154
157
|
/** Host is running widget codegen — send button becomes stop. */
|
|
155
158
|
isGenerating?: boolean;
|
|
156
159
|
onStopGeneration?: () => void;
|
|
160
|
+
/**
|
|
161
|
+
* Renders the inline design-control card attached to an assistant reply
|
|
162
|
+
* (see `addDesignControlsMessage`). The host owns the controls — the chat
|
|
163
|
+
* package stays free of design-schema/editor dependencies — and receives
|
|
164
|
+
* the resolution payload to render. When omitted, the message text still
|
|
165
|
+
* shows and the card is simply skipped.
|
|
166
|
+
*/
|
|
167
|
+
renderDesignControls?: Snippet<[DesignControlRequest]>;
|
|
168
|
+
/** Extra controls in the action bar, next to Complete. The host owns them. */
|
|
169
|
+
actionBarExtras?: Snippet;
|
|
170
|
+
/** Replaces the Complete button. The host owns it. */
|
|
171
|
+
completeReplacement?: Snippet;
|
|
172
|
+
/** When true, the replacement is shown instead of Complete. */
|
|
173
|
+
replaceComplete?: boolean;
|
|
174
|
+
/** Panel under the action bar, shown when those extras expand. */
|
|
175
|
+
composerExtras?: Snippet;
|
|
157
176
|
}
|
|
158
177
|
declare const Chat: import("svelte").Component<Props, {}, "">;
|
|
159
178
|
type Chat = ReturnType<typeof Chat>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { ChatMessage, ChatContext } from '../types/index.js';
|
|
3
|
-
import type { ClarificationSuggestion } from '../types/message.js';
|
|
3
|
+
import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
|
|
4
4
|
import { MESSAGE_COLORS } from '../constants/colors.js';
|
|
5
5
|
import { chatLog } from '../utils/logger.js';
|
|
6
6
|
import { AttachmentDisplay, SuggestionButtons } from './index.js';
|
|
7
7
|
import CodeBlock from './CodeBlock.svelte';
|
|
8
8
|
import LoadingIndicator from './LoadingIndicator.svelte';
|
|
9
9
|
import { onDestroy, onMount, tick } from 'svelte';
|
|
10
|
+
import type { Snippet } from 'svelte';
|
|
10
11
|
|
|
11
12
|
// Props
|
|
12
13
|
interface Props {
|
|
@@ -60,6 +61,8 @@
|
|
|
60
61
|
* carrying the chip's structured intent. Chips are disabled while the host
|
|
61
62
|
* runs widget codegen (`isGenerating`). */
|
|
62
63
|
onClarificationSuggestionSelected?: (suggestion: ClarificationSuggestion) => void;
|
|
64
|
+
/** Host-rendered inline design-control card for messages carrying `designControls`. */
|
|
65
|
+
renderDesignControls?: Snippet<[DesignControlRequest]>;
|
|
63
66
|
}
|
|
64
67
|
|
|
65
68
|
let {
|
|
@@ -82,6 +85,7 @@
|
|
|
82
85
|
onRestoreCheckpoint,
|
|
83
86
|
onRetryMessage,
|
|
84
87
|
onClarificationSuggestionSelected,
|
|
88
|
+
renderDesignControls,
|
|
85
89
|
}: Props = $props();
|
|
86
90
|
|
|
87
91
|
let messagesHasScrollbar = $state(false);
|
|
@@ -713,6 +717,15 @@
|
|
|
713
717
|
return false;
|
|
714
718
|
}
|
|
715
719
|
|
|
720
|
+
function isPlanLimitMessage(message: string | null | undefined): boolean {
|
|
721
|
+
if (!message) return false;
|
|
722
|
+
return /credit balance|free trial|not available in your plan|not available on the free plan|upgrade your plan|upgrade to a solo/i.test(message);
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
function openUpgradePlans() {
|
|
726
|
+
window.location.assign('/workspaces/personal/settings/billing');
|
|
727
|
+
}
|
|
728
|
+
|
|
716
729
|
function turnNeedsRetry(turn: ChatTurn, turnIndex: number): boolean {
|
|
717
730
|
// Never show Retry while a send/codegen is still running.
|
|
718
731
|
if (isLoading || isGenerating) return false;
|
|
@@ -1109,7 +1122,7 @@
|
|
|
1109
1122
|
|
|
1110
1123
|
<div
|
|
1111
1124
|
bind:this={messagesContainer}
|
|
1112
|
-
class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto space-y-4"
|
|
1125
|
+
class="{className ? className : 'prompt-chat-messages-ct'} prompt-chat-messages-scroll flex flex-col overflow-y-auto space-y-4 pb-3"
|
|
1113
1126
|
class:loading={isLoading}
|
|
1114
1127
|
style="scroll-behavior: smooth; padding: 12px 0 12px 12px; padding-right: 12px;"
|
|
1115
1128
|
use:detectMessagesScrollbar
|
|
@@ -1161,7 +1174,7 @@
|
|
|
1161
1174
|
</div>
|
|
1162
1175
|
{/if}
|
|
1163
1176
|
<div
|
|
1164
|
-
class="message-bubble relative ml-auto w-fit max-w-[
|
|
1177
|
+
class="message-bubble relative ml-auto w-fit max-w-[94%] rounded-lg shadow-sm text-sm leading-relaxed select-text"
|
|
1165
1178
|
class:p-3={shownAttachments.length === 0}
|
|
1166
1179
|
class:p-0={shownAttachments.length > 0}
|
|
1167
1180
|
class:bubble-fit-content={shownAttachments.length > 0}
|
|
@@ -1238,7 +1251,7 @@
|
|
|
1238
1251
|
</span>
|
|
1239
1252
|
{/if}
|
|
1240
1253
|
{#if showCommitMeta && getTurnCommitShort(turn)}
|
|
1241
|
-
<span class="wc-user-commit-sha font-mono text-xs text-gray-500">
|
|
1254
|
+
<span class="wc-user-commit-sha whitespace-nowrap font-mono text-xs text-gray-500">
|
|
1242
1255
|
(commit id: {getTurnCommitShort(turn)})
|
|
1243
1256
|
</span>
|
|
1244
1257
|
{/if}
|
|
@@ -1270,7 +1283,7 @@
|
|
|
1270
1283
|
|
|
1271
1284
|
{#each turn.replies as reply (reply.id)}
|
|
1272
1285
|
{#if shouldShowAssistantReply(reply)}
|
|
1273
|
-
<div class="message-container wc-chat-turn-reply mr-auto w-fit max-w-[
|
|
1286
|
+
<div class="message-container wc-chat-turn-reply mr-auto w-fit max-w-[94%] flex flex-col items-stretch overflow-visible"
|
|
1274
1287
|
class:opacity-75={reply._optimistic}
|
|
1275
1288
|
class:opacity-50={reply._failed}
|
|
1276
1289
|
class:current-checkpoint={isHeadCommitReply(reply)}
|
|
@@ -1304,6 +1317,12 @@
|
|
|
1304
1317
|
{/if}
|
|
1305
1318
|
</div>
|
|
1306
1319
|
|
|
1320
|
+
{#if reply.designControls && renderDesignControls}
|
|
1321
|
+
<div class="wc-design-controls mt-1.5 w-fit max-w-full overflow-visible">
|
|
1322
|
+
{@render renderDesignControls(reply.designControls)}
|
|
1323
|
+
</div>
|
|
1324
|
+
{/if}
|
|
1325
|
+
|
|
1307
1326
|
{#if reply.suggestions && reply.suggestions.length > 0}
|
|
1308
1327
|
<div class="clarification-suggestions flex flex-wrap gap-1.5 mt-1.5">
|
|
1309
1328
|
{#each reply.suggestions as suggestion, i (i)}
|
|
@@ -1322,6 +1341,15 @@
|
|
|
1322
1341
|
|
|
1323
1342
|
{#if isCodegenFailure(reply) && isLastCodegenFailureInTurn(turn, reply) && turnNeedsRetry(turn, turnIndex)}
|
|
1324
1343
|
<div class="retry-codegen-row flex justify-start mt-1">
|
|
1344
|
+
{#if isPlanLimitMessage(reply.messageContent)}
|
|
1345
|
+
<button
|
|
1346
|
+
class="retry-codegen-btn"
|
|
1347
|
+
onclick={openUpgradePlans}
|
|
1348
|
+
title="Open plans and billing"
|
|
1349
|
+
>
|
|
1350
|
+
Upgrade
|
|
1351
|
+
</button>
|
|
1352
|
+
{:else}
|
|
1325
1353
|
<button
|
|
1326
1354
|
class="retry-codegen-btn"
|
|
1327
1355
|
onclick={() => handleRetryTurn(turn, turnIndex)}
|
|
@@ -1333,6 +1361,7 @@
|
|
|
1333
1361
|
</svg>
|
|
1334
1362
|
Retry
|
|
1335
1363
|
</button>
|
|
1364
|
+
{/if}
|
|
1336
1365
|
</div>
|
|
1337
1366
|
{/if}
|
|
1338
1367
|
</div>
|
|
@@ -1397,7 +1426,7 @@
|
|
|
1397
1426
|
}
|
|
1398
1427
|
|
|
1399
1428
|
.message-container {
|
|
1400
|
-
max-width:
|
|
1429
|
+
max-width: 96%;
|
|
1401
1430
|
}
|
|
1402
1431
|
|
|
1403
1432
|
/* Messages with attachments: text full-width on top, images on a row below */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { ChatMessage, ChatContext } from '../types/index.js';
|
|
2
|
-
import type { ClarificationSuggestion } from '../types/message.js';
|
|
2
|
+
import type { ClarificationSuggestion, DesignControlRequest } from '../types/message.js';
|
|
3
|
+
import type { Snippet } from 'svelte';
|
|
3
4
|
interface Props {
|
|
4
5
|
class?: string;
|
|
5
6
|
messages: ChatMessage[];
|
|
@@ -55,6 +56,8 @@ interface Props {
|
|
|
55
56
|
* carrying the chip's structured intent. Chips are disabled while the host
|
|
56
57
|
* runs widget codegen (`isGenerating`). */
|
|
57
58
|
onClarificationSuggestionSelected?: (suggestion: ClarificationSuggestion) => void;
|
|
59
|
+
/** Host-rendered inline design-control card for messages carrying `designControls`. */
|
|
60
|
+
renderDesignControls?: Snippet<[DesignControlRequest]>;
|
|
58
61
|
}
|
|
59
62
|
declare const ChatMessages: import("svelte").Component<Props, {}, "">;
|
|
60
63
|
type ChatMessages = ReturnType<typeof ChatMessages>;
|
package/dist/types/message.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -44,8 +44,8 @@
|
|
|
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",
|