@widgetic/chat 0.1.21 → 0.1.23

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.
@@ -694,7 +694,6 @@
694
694
  * available in Debug ON too — the assistant summary and the user-side chrome coexist. */
695
695
  function showCommitMetaOnUserTurn(turn: ChatTurn): boolean {
696
696
  return !!getTurnHeadOrCommitReply(turn)
697
- || canRestoreLegacyUserTurn(turn)
698
697
  || canRestoreFailedLastTurn(turn)
699
698
  || !!versionLabelFromPrompt(turn);
700
699
  }
@@ -813,11 +812,19 @@
813
812
  window.location.assign('/workspaces/personal/settings/billing');
814
813
  }
815
814
 
815
+ function turnIsDesignCardOnly(turn: ChatTurn): boolean {
816
+ const hasCard = turn.replies.some((reply) => !!reply.designControls);
817
+ return hasCard && !getTurnCommitReply(turn);
818
+ }
819
+
816
820
  function turnNeedsRetry(turn: ChatTurn, turnIndex: number): boolean {
817
821
  // Never show Retry while a send/codegen is still running.
818
822
  if (isLoading || isGenerating) return false;
819
823
  const userMsg = turn.user;
820
824
  if (!userMsg?.messageContent?.trim()) return false;
825
+ // A design card already applied the change. Retry would send it to the model,
826
+ // add another bubble, and leave the card on the old one.
827
+ if (turnIsDesignCardOnly(turn)) return false;
821
828
  // The earlier copy of a prompt that was already run again stays without Retry.
822
829
  if (promptWasRetriedLater(turn, turnIndex)) return false;
823
830
  return true;
@@ -833,6 +840,10 @@
833
840
  let messagesContainer: HTMLElement;
834
841
  let showSuggestionsInline = $state(false);
835
842
  let autoScroll = $state(true);
843
+ // The first paint is shorter than the loaded page. Scrolling then, or treating
844
+ // that short box as "the user is at the top", loads older pages and never
845
+ // lands on the newest message. Pin once, after this load has finished.
846
+ let initialBottomPinned = $state(false);
836
847
 
837
848
  // Collapse an expanded suggestions panel as soon as a generation starts, so it
838
849
  // does not reappear under the new turn when generation ends.
@@ -847,24 +858,47 @@
847
858
  * up). Disconnected on destroy.
848
859
  */
849
860
  let containerResizeObserver: ResizeObserver | null = null;
861
+ let contentGrowthObserver: MutationObserver | null = null;
850
862
 
851
- function scrollToBottomInstant(): void {
863
+ function scrollMessagesToEnd(): void {
852
864
  if (!messagesContainer) return;
853
- messagesContainer.scrollTo({
854
- top: messagesContainer.scrollHeight,
855
- behavior: 'instant',
856
- });
865
+ messagesContainer.scrollTop = messagesContainer.scrollHeight;
866
+ }
867
+
868
+ // The last bubble grows after the first scroll (text wrap, the card under it).
869
+ // One assignment lands short of the end, which is the clipped last message.
870
+ function settleMessagesToEnd(): void {
871
+ let frames = 0;
872
+ const step = () => {
873
+ if (!messagesContainer || pendingOlderScroll || isLoading) return;
874
+ const gap = messagesContainer.scrollHeight - messagesContainer.clientHeight - messagesContainer.scrollTop;
875
+ if (shouldPinChatToBottom() || !initialBottomPinned) scrollMessagesToEnd();
876
+ frames += 1;
877
+ if (frames < 12 && gap > 1) {
878
+ requestAnimationFrame(step);
879
+ return;
880
+ }
881
+ initialBottomPinned = true;
882
+ };
883
+ requestAnimationFrame(step);
857
884
  }
858
885
 
859
886
  // Auto-scroll to bottom when new messages arrive or on initial load.
860
887
  // Also scrolls on mount/conversation-switch when messages are already present.
861
888
  $effect(() => {
889
+ if (isLoading) {
890
+ initialBottomPinned = false;
891
+ return;
892
+ }
862
893
  const pinToBottom = shouldPinChatToBottom();
863
894
  const messageCount = visibleMessages.length;
864
- if (messagesContainer && pinToBottom && messageCount > 0 && !pendingOlderScroll) {
895
+ if (!initialBottomPinned && messagesContainer && messageCount > 0 && !pendingOlderScroll) {
896
+ void tick().then(() => settleMessagesToEnd());
897
+ }
898
+ if (messagesContainer && pinToBottom && messageCount > 0 && !pendingOlderScroll && initialBottomPinned) {
865
899
  tick().then(() => {
866
900
  if (!messagesContainer || pendingOlderScroll || !shouldPinChatToBottom()) return;
867
- messagesContainer.scrollTop = messagesContainer.scrollHeight;
901
+ scrollMessagesToEnd();
868
902
  });
869
903
  }
870
904
  });
@@ -872,24 +906,33 @@
872
906
  // Force scroll to bottom on initial mount (messages may already be loaded)
873
907
  onMount(() => {
874
908
  tick().then(() => {
875
- if (messagesContainer && visibleMessages.length > 0 && shouldPinChatToBottom()) {
876
- scrollToBottomInstant();
909
+ if (messagesContainer && visibleMessages.length > 0 && !isLoading && shouldPinChatToBottom()) {
910
+ settleMessagesToEnd();
877
911
  }
878
912
  // Re-pin after late container resizes (panel open animation, parent
879
913
  // layout settling, height restored from prefs).
880
914
  if (messagesContainer && typeof ResizeObserver !== 'undefined') {
881
915
  containerResizeObserver = new ResizeObserver(() => {
882
- if (pendingOlderScroll) return;
883
- if (shouldPinChatToBottom()) scrollToBottomInstant();
916
+ if (pendingOlderScroll || !initialBottomPinned) return;
917
+ if (shouldPinChatToBottom()) scrollMessagesToEnd();
884
918
  });
885
919
  containerResizeObserver.observe(messagesContainer);
886
920
  }
921
+ if (messagesContainer && typeof MutationObserver !== 'undefined') {
922
+ contentGrowthObserver = new MutationObserver(() => {
923
+ if (pendingOlderScroll || !initialBottomPinned) return;
924
+ if (shouldPinChatToBottom()) scrollMessagesToEnd();
925
+ });
926
+ contentGrowthObserver.observe(messagesContainer, { childList: true, subtree: true });
927
+ }
887
928
  });
888
929
  });
889
930
 
890
931
  onDestroy(() => {
891
932
  containerResizeObserver?.disconnect();
892
933
  containerResizeObserver = null;
934
+ contentGrowthObserver?.disconnect();
935
+ contentGrowthObserver = null;
893
936
  });
894
937
 
895
938
  let olderRequestInFlight = false;
@@ -898,7 +941,7 @@
898
941
  function handleScroll() {
899
942
  if (!messagesContainer) return;
900
943
  const { scrollTop, scrollHeight, clientHeight } = messagesContainer;
901
- if (pendingOlderScroll) return;
944
+ if (pendingOlderScroll || !initialBottomPinned) return;
902
945
  autoScroll = scrollTop + clientHeight >= scrollHeight - 10;
903
946
  if (scrollTop > 80 || !hasOlderMessages || olderRequestInFlight || !onRequestOlderMessages) return;
904
947
  autoScroll = false;
@@ -1378,7 +1421,7 @@
1378
1421
  </span>
1379
1422
  {/if}
1380
1423
  </div>
1381
- {#if !turn.user?.id?.startsWith('version-fork-') && !isLoading && ((commitReply && (canRestoreToMessage(commitReply) || isHeadCommitReply(commitReply))) || canRestoreLegacyUserTurn(turn) || canRestoreFailedLastTurn(turn))}
1424
+ {#if !turn.user?.id?.startsWith('version-fork-') && !isLoading && ((commitReply && (canRestoreToMessage(commitReply) || isHeadCommitReply(commitReply))) || canRestoreFailedLastTurn(turn))}
1382
1425
  {@const restoreIsCurrentHead = !!(commitReply && isHeadCommitReply(commitReply))}
1383
1426
  <button
1384
1427
  class="restore-checkpoint-btn shrink-0"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/chat",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -45,7 +45,7 @@
45
45
  "dev-sv": "NODE_ENV=development vite dev",
46
46
  "build": "vite build",
47
47
  "package": "svelte-kit sync && svelte-package",
48
- "publish-to-npm": "npm version patch --no-git-tag-version && npm run package && npm publish --ignore-scripts --access public",
48
+ "publish-to-npm": "node ../dev-tools/bin/publish-package.mjs",
49
49
  "package:watch": "svelte-kit sync && svelte-package --watch",
50
50
  "prepackage:watch": "npm run lps",
51
51
  "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --diagnostic-sources \"js,svelte\"",