@smooai/chat-widget 0.5.2 → 0.6.0
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/chat-widget.global.js +473 -40
- package/dist/chat-widget.global.js.map +1 -1
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +473 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/element.ts +208 -47
- package/src/markdown.ts +368 -0
- package/src/styles.ts +44 -0
package/dist/index.d.ts
CHANGED
|
@@ -113,6 +113,8 @@ declare class SmoothAgentChatElement extends HTMLElement {
|
|
|
113
113
|
private hasSent;
|
|
114
114
|
/** Starter prompts shown as chips in the empty state. */
|
|
115
115
|
private examplePrompts;
|
|
116
|
+
/** Resolved greeting text, cached so async (rAF) renders can reuse it. */
|
|
117
|
+
private greeting;
|
|
116
118
|
/** Current mid-turn interrupt (OTP / tool-confirmation), or null. */
|
|
117
119
|
private interrupt;
|
|
118
120
|
private interruptEl;
|
|
@@ -123,6 +125,15 @@ declare class SmoothAgentChatElement extends HTMLElement {
|
|
|
123
125
|
private dotEl;
|
|
124
126
|
private inputEl;
|
|
125
127
|
private sendBtn;
|
|
128
|
+
/** The live streaming assistant bubble whose textContent the rAF loop drives. */
|
|
129
|
+
private streamBubbleEl;
|
|
130
|
+
/** Message id the reveal is bound to (guards against stale frames after rebuilds). */
|
|
131
|
+
private streamMsgId;
|
|
132
|
+
/** Full buffered target text for the streaming message (grows as tokens arrive). */
|
|
133
|
+
private streamTarget;
|
|
134
|
+
/** How many chars of {@link streamTarget} are currently shown. */
|
|
135
|
+
private displayedLength;
|
|
136
|
+
private rafId;
|
|
126
137
|
constructor();
|
|
127
138
|
connectedCallback(): void;
|
|
128
139
|
disconnectedCallback(): void;
|
|
@@ -151,7 +162,46 @@ declare class SmoothAgentChatElement extends HTMLElement {
|
|
|
151
162
|
private syncOpenState;
|
|
152
163
|
/** Grow the textarea with its content, up to the CSS max-height. */
|
|
153
164
|
private autosize;
|
|
165
|
+
/**
|
|
166
|
+
* Receive a new message snapshot from the controller and update the view.
|
|
167
|
+
*
|
|
168
|
+
* `onMessages` fires on *every* `stream_token` delta. Rebuilding the whole
|
|
169
|
+
* list each frame is wasteful and fights the smooth reveal, so we take the
|
|
170
|
+
* cheap path when the only change is the trailing streaming assistant message
|
|
171
|
+
* growing: just bump the reveal *target* (the rAF loop drains it). Any
|
|
172
|
+
* structural change (new message, finalize, citations) triggers a full
|
|
173
|
+
* rebuild via {@link renderMessages}.
|
|
174
|
+
*/
|
|
175
|
+
private handleMessages;
|
|
154
176
|
private renderMessages;
|
|
177
|
+
/** True when the host/user prefers reduced motion (snap, no typewriter). */
|
|
178
|
+
private prefersReducedMotion;
|
|
179
|
+
/**
|
|
180
|
+
* Bind the rAF typewriter to a freshly built streaming bubble. Preserves the
|
|
181
|
+
* already-revealed prefix across rebuilds (so a structural rebuild mid-stream
|
|
182
|
+
* doesn't restart the reveal from zero), then resumes the loop.
|
|
183
|
+
*/
|
|
184
|
+
private bindReveal;
|
|
185
|
+
/** Start the rAF loop if it isn't already running. */
|
|
186
|
+
private ensureRevealLoop;
|
|
187
|
+
/**
|
|
188
|
+
* One animation frame of the reveal. Advances `displayedLength` toward the
|
|
189
|
+
* buffered target at an ADAPTIVE rate — the deeper the backlog, the more
|
|
190
|
+
* chars per frame — so the reveal stays smooth yet never falls behind the
|
|
191
|
+
* network. Updates ONLY the bound bubble's textContent (no list rebuild).
|
|
192
|
+
*/
|
|
193
|
+
private tickReveal;
|
|
194
|
+
/** Snap the bound bubble to the full buffered text immediately (reduced-motion / no-rAF). */
|
|
195
|
+
private snapReveal;
|
|
196
|
+
/** Cancel any in-flight reveal loop and clear its state (called on full rebuild). */
|
|
197
|
+
private resetReveal;
|
|
198
|
+
/**
|
|
199
|
+
* Auto-scroll the message list to the bottom — but don't fight a visitor who
|
|
200
|
+
* has scrolled up to read history. When `force` (a structural rebuild) we
|
|
201
|
+
* always pin to bottom; during the streaming reveal we only follow if the
|
|
202
|
+
* viewport is already near the bottom.
|
|
203
|
+
*/
|
|
204
|
+
private scrollToBottom;
|
|
155
205
|
/** Wrap a bubble in a `.row`, prefixing assistant rows with a mini avatar. */
|
|
156
206
|
private buildRow;
|
|
157
207
|
private greetingBubble;
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/config.ts","../src/element.ts","../src/loader-core.ts","../src/conversation.ts"],"mappings":";;;;;;AAOA;;;;UAAiB,eAAA;EAIb;EAFA,IAAA;EAMA;EAJA,UAAA;EAQA;EANA,OAAA;EAUA;EARA,WAAA;EAYA;EAVA,SAAA;EAkBA;EAhBA,eAAA;EAoBA;EAlBA,mBAAA;EAkBsB;EAhBtB,UAAA;EA2BsB;EAzBtB,cAAA;EAyBsB;EAvBtB,MAAA;EAyBa;EAnBb,iBAAA;;EAEA,qBAAA;EAsBA;EApBA,kBAAA;EAyBO;EAvBP,sBAAA;AAAA;;;;;;;;;KAWQ,cAAA;AAAA,UAEK,gBAAA;EAuCb;;;;EAlCA,QAAA;EAyCuB;;;;EApCvB,IAAA,GAAO,cAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/config.ts","../src/element.ts","../src/loader-core.ts","../src/conversation.ts"],"mappings":";;;;;;AAOA;;;;UAAiB,eAAA;EAIb;EAFA,IAAA;EAMA;EAJA,UAAA;EAQA;EANA,OAAA;EAUA;EARA,WAAA;EAYA;EAVA,SAAA;EAkBA;EAhBA,eAAA;EAoBA;EAlBA,mBAAA;EAkBsB;EAhBtB,UAAA;EA2BsB;EAzBtB,cAAA;EAyBsB;EAvBtB,MAAA;EAyBa;EAnBb,iBAAA;;EAEA,qBAAA;EAsBA;EApBA,kBAAA;EAyBO;EAvBP,sBAAA;AAAA;;;;;;;;;KAWQ,cAAA;AAAA,UAEK,gBAAA;EAuCb;;;;EAlCA,QAAA;EAyCuB;;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