@assistant-ui/react 0.4.0 → 0.4.2

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/index.mjs CHANGED
@@ -831,21 +831,30 @@ var ActionBarPrimitiveRoot = forwardRef(({ hideWhenRunning, autohide, autohideFl
831
831
  ActionBarPrimitiveRoot.displayName = "ActionBarPrimitive.Root";
832
832
 
833
833
  // src/utils/createActionButton.tsx
834
- import { composeEventHandlers } from "@radix-ui/primitive";
835
- import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
836
834
  import { forwardRef as forwardRef2 } from "react";
835
+ import { Primitive as Primitive2 } from "@radix-ui/react-primitive";
836
+ import { composeEventHandlers } from "@radix-ui/primitive";
837
837
  import { jsx as jsx5 } from "react/jsx-runtime";
838
- var createActionButton = (displayName, useActionButton) => {
838
+ var createActionButton = (displayName, useActionButton, forwardProps = []) => {
839
839
  const ActionButton = forwardRef2((props, forwardedRef) => {
840
- const callback = useActionButton(props);
840
+ const forwardedProps = {};
841
+ const primitiveProps = {};
842
+ Object.keys(props).forEach((key) => {
843
+ if (forwardProps.includes(key)) {
844
+ forwardedProps[key] = props[key];
845
+ } else {
846
+ primitiveProps[key] = props[key];
847
+ }
848
+ });
849
+ const callback = useActionButton(forwardedProps);
841
850
  return /* @__PURE__ */ jsx5(
842
851
  Primitive2.button,
843
852
  {
844
853
  type: "button",
845
854
  disabled: !callback,
846
- ...props,
855
+ ...primitiveProps,
847
856
  ref: forwardedRef,
848
- onClick: composeEventHandlers(props.onClick, () => {
857
+ onClick: composeEventHandlers(primitiveProps.onClick, () => {
849
858
  callback?.();
850
859
  })
851
860
  }
@@ -858,7 +867,8 @@ var createActionButton = (displayName, useActionButton) => {
858
867
  // src/primitives/actionBar/ActionBarCopy.tsx
859
868
  var ActionBarPrimitiveCopy = createActionButton(
860
869
  "ActionBarPrimitive.Copy",
861
- useActionBarCopy
870
+ useActionBarCopy,
871
+ ["copiedDuration"]
862
872
  );
863
873
 
864
874
  // src/primitives/actionBar/ActionBarReload.tsx
@@ -1171,7 +1181,8 @@ import { forwardRef as forwardRef7 } from "react";
1171
1181
  // src/utils/hooks/useSmooth.tsx
1172
1182
  import { useEffect as useEffect8, useState as useState5 } from "react";
1173
1183
  var TextStreamAnimator = class {
1174
- constructor(setText) {
1184
+ constructor(currentText, setText) {
1185
+ this.currentText = currentText;
1175
1186
  this.setText = setText;
1176
1187
  }
1177
1188
  animationFrameId = null;
@@ -1192,33 +1203,31 @@ var TextStreamAnimator = class {
1192
1203
  const currentTime = Date.now();
1193
1204
  const deltaTime = currentTime - this.lastUpdateTime;
1194
1205
  let timeToConsume = deltaTime;
1195
- this.setText((currentText) => {
1196
- const targetText = this.targetText;
1197
- if (currentText === targetText) {
1198
- this.animationFrameId = null;
1199
- return currentText;
1200
- }
1201
- const remainingChars = targetText.length - currentText.length;
1202
- const baseTimePerChar = Math.min(5, 250 / remainingChars);
1203
- let charsToAdd = 0;
1204
- while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {
1205
- charsToAdd++;
1206
- timeToConsume -= baseTimePerChar;
1207
- }
1206
+ const remainingChars = this.targetText.length - this.currentText.length;
1207
+ const baseTimePerChar = Math.min(5, 250 / remainingChars);
1208
+ let charsToAdd = 0;
1209
+ while (timeToConsume >= baseTimePerChar && charsToAdd < remainingChars) {
1210
+ charsToAdd++;
1211
+ timeToConsume -= baseTimePerChar;
1212
+ }
1213
+ if (charsToAdd !== remainingChars) {
1208
1214
  this.animationFrameId = requestAnimationFrame(this.animate);
1209
- if (charsToAdd === 0) {
1210
- return currentText;
1211
- }
1212
- const newText = targetText.slice(0, currentText.length + charsToAdd);
1213
- this.lastUpdateTime = currentTime - timeToConsume;
1214
- return newText;
1215
- });
1215
+ } else {
1216
+ this.animationFrameId = null;
1217
+ }
1218
+ if (charsToAdd === 0) return;
1219
+ this.currentText = this.targetText.slice(
1220
+ 0,
1221
+ this.currentText.length + charsToAdd
1222
+ );
1223
+ this.lastUpdateTime = currentTime - timeToConsume;
1224
+ this.setText(this.currentText);
1216
1225
  };
1217
1226
  };
1218
1227
  var useSmooth = (text, smooth = false) => {
1219
1228
  const [displayedText, setDisplayedText] = useState5(text);
1220
1229
  const [animatorRef] = useState5(
1221
- new TextStreamAnimator(setDisplayedText)
1230
+ new TextStreamAnimator(text, setDisplayedText)
1222
1231
  );
1223
1232
  useEffect8(() => {
1224
1233
  if (!smooth) {
@@ -1227,6 +1236,7 @@ var useSmooth = (text, smooth = false) => {
1227
1236
  }
1228
1237
  if (!text.startsWith(animatorRef.targetText)) {
1229
1238
  setDisplayedText(text);
1239
+ animatorRef.currentText = text;
1230
1240
  animatorRef.targetText = text;
1231
1241
  animatorRef.stop();
1232
1242
  return;
@@ -1885,7 +1895,8 @@ var ThreadPrimitiveScrollToBottom = createActionButton(
1885
1895
  // src/primitives/thread/ThreadSuggestion.tsx
1886
1896
  var ThreadPrimitiveSuggestion = createActionButton(
1887
1897
  "ThreadPrimitive.Suggestion",
1888
- useThreadSuggestion
1898
+ useThreadSuggestion,
1899
+ ["prompt", "autoSend", "method"]
1889
1900
  );
1890
1901
 
1891
1902
  // src/runtimes/local/useLocalRuntime.tsx