@assistant-ui/react 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +22 -5
- package/dist/index.d.ts +22 -5
- package/dist/index.js +124 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +96 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -356,9 +356,15 @@ declare const useComposerIf: (props: UseComposerIfProps) => boolean;
|
|
356
356
|
|
357
357
|
declare const useComposerSend: () => (() => void) | null;
|
358
358
|
|
359
|
-
declare const useContentPartDisplay: () =>
|
359
|
+
declare const useContentPartDisplay: () => Readonly<{
|
360
|
+
status: "in_progress" | "done" | "error";
|
361
|
+
part: UIContentPart;
|
362
|
+
}>;
|
360
363
|
|
361
|
-
declare const useContentPartImage: () =>
|
364
|
+
declare const useContentPartImage: () => Readonly<{
|
365
|
+
status: "in_progress" | "done" | "error";
|
366
|
+
part: ImageContentPart;
|
367
|
+
}>;
|
362
368
|
|
363
369
|
declare const useContentPartText: () => Readonly<{
|
364
370
|
status: "in_progress" | "done" | "error";
|
@@ -528,8 +534,16 @@ declare namespace index$3 {
|
|
528
534
|
}
|
529
535
|
|
530
536
|
type PrimitiveSpanProps$1 = ComponentPropsWithoutRef<typeof Primitive.span>;
|
531
|
-
type ContentPartPrimitiveTextProps = Omit<PrimitiveSpanProps$1, "children"
|
532
|
-
|
537
|
+
type ContentPartPrimitiveTextProps = Omit<PrimitiveSpanProps$1, "children"> & {
|
538
|
+
smooth?: boolean;
|
539
|
+
};
|
540
|
+
declare const ContentPartPrimitiveText: react.ForwardRefExoticComponent<Omit<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
541
|
+
ref?: ((instance: HTMLSpanElement | null) => void | react.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof react.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | react.RefObject<HTMLSpanElement> | null | undefined;
|
542
|
+
} & {
|
543
|
+
asChild?: boolean;
|
544
|
+
}, "ref">, "children"> & {
|
545
|
+
smooth?: boolean;
|
546
|
+
} & react.RefAttributes<HTMLSpanElement>>;
|
533
547
|
|
534
548
|
type PrimitiveImageProps = ComponentPropsWithoutRef<typeof Primitive.img>;
|
535
549
|
type ContentPartPrimitiveImageProps = PrimitiveImageProps;
|
@@ -665,14 +679,17 @@ declare class MessageRepository {
|
|
665
679
|
resetHead(messageId: string | null): void;
|
666
680
|
}
|
667
681
|
|
682
|
+
declare const useSmooth: (text: string, smooth?: boolean) => string;
|
683
|
+
|
668
684
|
type internal_BaseAssistantRuntime<TThreadRuntime extends ReactThreadRuntime> = BaseAssistantRuntime<TThreadRuntime>;
|
669
685
|
declare const internal_BaseAssistantRuntime: typeof BaseAssistantRuntime;
|
670
686
|
type internal_MessageRepository = MessageRepository;
|
671
687
|
declare const internal_MessageRepository: typeof MessageRepository;
|
672
688
|
type internal_ProxyConfigProvider = ProxyConfigProvider;
|
673
689
|
declare const internal_ProxyConfigProvider: typeof ProxyConfigProvider;
|
690
|
+
declare const internal_useSmooth: typeof useSmooth;
|
674
691
|
declare namespace internal {
|
675
|
-
export { internal_BaseAssistantRuntime as BaseAssistantRuntime, internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider };
|
692
|
+
export { internal_BaseAssistantRuntime as BaseAssistantRuntime, internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider, internal_useSmooth as useSmooth };
|
676
693
|
}
|
677
694
|
|
678
695
|
export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AppendContentPart, type AppendMessage, type AssistantContentPart, type AssistantContextValue, type AssistantMessage, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ComposerContextValue, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type EditComposerState, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, type ThreadContextValue, type ThreadMessage, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRuntime, type ThreadState, type ThreadViewportState, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UserContentPart, type UserMessage, makeAssistantTool, makeAssistantToolUI, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };
|
package/dist/index.d.ts
CHANGED
@@ -356,9 +356,15 @@ declare const useComposerIf: (props: UseComposerIfProps) => boolean;
|
|
356
356
|
|
357
357
|
declare const useComposerSend: () => (() => void) | null;
|
358
358
|
|
359
|
-
declare const useContentPartDisplay: () =>
|
359
|
+
declare const useContentPartDisplay: () => Readonly<{
|
360
|
+
status: "in_progress" | "done" | "error";
|
361
|
+
part: UIContentPart;
|
362
|
+
}>;
|
360
363
|
|
361
|
-
declare const useContentPartImage: () =>
|
364
|
+
declare const useContentPartImage: () => Readonly<{
|
365
|
+
status: "in_progress" | "done" | "error";
|
366
|
+
part: ImageContentPart;
|
367
|
+
}>;
|
362
368
|
|
363
369
|
declare const useContentPartText: () => Readonly<{
|
364
370
|
status: "in_progress" | "done" | "error";
|
@@ -528,8 +534,16 @@ declare namespace index$3 {
|
|
528
534
|
}
|
529
535
|
|
530
536
|
type PrimitiveSpanProps$1 = ComponentPropsWithoutRef<typeof Primitive.span>;
|
531
|
-
type ContentPartPrimitiveTextProps = Omit<PrimitiveSpanProps$1, "children"
|
532
|
-
|
537
|
+
type ContentPartPrimitiveTextProps = Omit<PrimitiveSpanProps$1, "children"> & {
|
538
|
+
smooth?: boolean;
|
539
|
+
};
|
540
|
+
declare const ContentPartPrimitiveText: react.ForwardRefExoticComponent<Omit<Omit<Omit<react.DetailedHTMLProps<react.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
541
|
+
ref?: ((instance: HTMLSpanElement | null) => void | react.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES[keyof react.DO_NOT_USE_OR_YOU_WILL_BE_FIRED_CALLBACK_REF_RETURN_VALUES]) | react.RefObject<HTMLSpanElement> | null | undefined;
|
542
|
+
} & {
|
543
|
+
asChild?: boolean;
|
544
|
+
}, "ref">, "children"> & {
|
545
|
+
smooth?: boolean;
|
546
|
+
} & react.RefAttributes<HTMLSpanElement>>;
|
533
547
|
|
534
548
|
type PrimitiveImageProps = ComponentPropsWithoutRef<typeof Primitive.img>;
|
535
549
|
type ContentPartPrimitiveImageProps = PrimitiveImageProps;
|
@@ -665,14 +679,17 @@ declare class MessageRepository {
|
|
665
679
|
resetHead(messageId: string | null): void;
|
666
680
|
}
|
667
681
|
|
682
|
+
declare const useSmooth: (text: string, smooth?: boolean) => string;
|
683
|
+
|
668
684
|
type internal_BaseAssistantRuntime<TThreadRuntime extends ReactThreadRuntime> = BaseAssistantRuntime<TThreadRuntime>;
|
669
685
|
declare const internal_BaseAssistantRuntime: typeof BaseAssistantRuntime;
|
670
686
|
type internal_MessageRepository = MessageRepository;
|
671
687
|
declare const internal_MessageRepository: typeof MessageRepository;
|
672
688
|
type internal_ProxyConfigProvider = ProxyConfigProvider;
|
673
689
|
declare const internal_ProxyConfigProvider: typeof ProxyConfigProvider;
|
690
|
+
declare const internal_useSmooth: typeof useSmooth;
|
674
691
|
declare namespace internal {
|
675
|
-
export { internal_BaseAssistantRuntime as BaseAssistantRuntime, internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider };
|
692
|
+
export { internal_BaseAssistantRuntime as BaseAssistantRuntime, internal_MessageRepository as MessageRepository, internal_ProxyConfigProvider as ProxyConfigProvider, internal_useSmooth as useSmooth };
|
676
693
|
}
|
677
694
|
|
678
695
|
export { index$6 as ActionBarPrimitive, type ActionBarPrimitiveCopyProps, type ActionBarPrimitiveEditProps, type ActionBarPrimitiveReloadProps, type ActionBarPrimitiveRootProps, type AppendContentPart, type AppendMessage, type AssistantContentPart, type AssistantContextValue, type AssistantMessage, index$5 as AssistantModalPrimitive, type AssistantModalPrimitiveContentProps, type AssistantModalPrimitiveRootProps, type AssistantModalPrimitiveTriggerProps, type AssistantModelConfigState, type AssistantRuntime, AssistantRuntimeProvider, type AssistantToolProps, type AssistantToolUIProps, index$4 as BranchPickerPrimitive, type BranchPickerPrimitiveCountProps, type BranchPickerPrimitiveNextProps, type BranchPickerPrimitiveNumberProps, type BranchPickerPrimitivePreviousProps, type BranchPickerPrimitiveRootProps, type ChatModelAdapter, type ChatModelRunOptions, type ComposerContextValue, index$3 as ComposerPrimitive, type ComposerPrimitiveCancelProps, type ComposerPrimitiveIfProps, type ComposerPrimitiveInputProps, type ComposerPrimitiveRootProps, type ComposerPrimitiveSendProps, type ComposerState, type ContentPartContextValue, index$2 as ContentPartPrimitive, type ContentPartPrimitiveDisplayProps, type ContentPartPrimitiveImageProps, type ContentPartPrimitiveInProgressProps, type ContentPartPrimitiveTextProps, type ContentPartState, type EditComposerState, internal as INTERNAL, type ImageContentPart, type ImageContentPartComponent, type ImageContentPartProps, type MessageContextValue, index$1 as MessagePrimitive, type MessagePrimitiveContentProps, type MessagePrimitiveIfProps, type MessagePrimitiveInProgressProps, type MessagePrimitiveRootProps, type MessageState, type ModelConfig, type ModelConfigProvider, type ReactThreadRuntime, type TextContentPart, type TextContentPartComponent, type TextContentPartProps, type ThreadContextValue, type ThreadMessage, index as ThreadPrimitive, type ThreadPrimitiveEmptyProps, type ThreadPrimitiveIfProps, type ThreadPrimitiveMessagesProps, type ThreadPrimitiveRootProps, type ThreadPrimitiveScrollToBottomProps, type ThreadPrimitiveSuggestionProps, type ThreadPrimitiveViewportProps, type ThreadRuntime, type ThreadState, type ThreadViewportState, type ToolCallContentPart, type ToolCallContentPartComponent, type ToolCallContentPartProps, type UIContentPart, type UIContentPartComponent, type UIContentPartProps, type Unsubscribe, type UserContentPart, type UserMessage, makeAssistantTool, makeAssistantToolUI, useActionBarCopy, useActionBarEdit, useActionBarReload, useAppendMessage, useAssistantContext, useAssistantInstructions, useAssistantTool, useAssistantToolUI, useBranchPickerCount, useBranchPickerNext, useBranchPickerNumber, useBranchPickerPrevious, useComposerCancel, useComposerContext, useComposerIf, useComposerSend, useContentPartContext, useContentPartDisplay, useContentPartImage, useContentPartText, useLocalRuntime, useMessageContext, useMessageIf, useSwitchToNewThread, useThreadContext, useThreadEmpty, useThreadIf, useThreadScrollToBottom, useThreadSuggestion };
|
package/dist/index.js
CHANGED
@@ -730,7 +730,7 @@ var useContentPartDisplay = () => {
|
|
730
730
|
throw new Error(
|
731
731
|
"This component can only be used inside ui content parts."
|
732
732
|
);
|
733
|
-
return c
|
733
|
+
return c;
|
734
734
|
});
|
735
735
|
return display;
|
736
736
|
};
|
@@ -743,7 +743,7 @@ var useContentPartImage = () => {
|
|
743
743
|
throw new Error(
|
744
744
|
"ContentPartImage can only be used inside image content parts."
|
745
745
|
);
|
746
|
-
return c
|
746
|
+
return c;
|
747
747
|
});
|
748
748
|
return image;
|
749
749
|
};
|
@@ -1097,7 +1097,7 @@ BranchPickerPrimitiveNumber.displayName = "BranchPickerPrimitive.Number";
|
|
1097
1097
|
|
1098
1098
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
1099
1099
|
var import_react_primitive6 = require("@radix-ui/react-primitive");
|
1100
|
-
var
|
1100
|
+
var import_react39 = require("react");
|
1101
1101
|
|
1102
1102
|
// src/primitives/message/index.ts
|
1103
1103
|
var message_exports = {};
|
@@ -1174,7 +1174,7 @@ var MessagePrimitiveIf = ({
|
|
1174
1174
|
MessagePrimitiveIf.displayName = "MessagePrimitive.If";
|
1175
1175
|
|
1176
1176
|
// src/primitives/message/MessageContent.tsx
|
1177
|
-
var
|
1177
|
+
var import_react38 = require("react");
|
1178
1178
|
|
1179
1179
|
// src/context/providers/ContentPartProvider.tsx
|
1180
1180
|
var import_react34 = require("react");
|
@@ -1221,30 +1221,107 @@ var ContentPartProvider = ({
|
|
1221
1221
|
|
1222
1222
|
// src/primitives/contentPart/ContentPartText.tsx
|
1223
1223
|
var import_react_primitive4 = require("@radix-ui/react-primitive");
|
1224
|
+
var import_react36 = require("react");
|
1225
|
+
|
1226
|
+
// src/utils/hooks/useSmooth.tsx
|
1224
1227
|
var import_react35 = require("react");
|
1228
|
+
var TextStreamAnimator = class {
|
1229
|
+
constructor(setText) {
|
1230
|
+
this.setText = setText;
|
1231
|
+
}
|
1232
|
+
animationFrameId = null;
|
1233
|
+
lastUpdateTime = Date.now();
|
1234
|
+
decayFactor = 0.99;
|
1235
|
+
targetText = "";
|
1236
|
+
start() {
|
1237
|
+
if (this.animationFrameId !== null) return;
|
1238
|
+
this.animate();
|
1239
|
+
}
|
1240
|
+
stop() {
|
1241
|
+
if (this.animationFrameId !== null) {
|
1242
|
+
cancelAnimationFrame(this.animationFrameId);
|
1243
|
+
this.animationFrameId = null;
|
1244
|
+
}
|
1245
|
+
}
|
1246
|
+
animate = () => {
|
1247
|
+
const currentTime = Date.now();
|
1248
|
+
const deltaTime = currentTime - this.lastUpdateTime;
|
1249
|
+
this.lastUpdateTime = currentTime;
|
1250
|
+
this.setText((currentText) => {
|
1251
|
+
const targetText = this.targetText;
|
1252
|
+
if (currentText === targetText) {
|
1253
|
+
this.animationFrameId = null;
|
1254
|
+
return currentText;
|
1255
|
+
}
|
1256
|
+
const remainingChars = targetText.length - currentText.length;
|
1257
|
+
const charsToAdd = Math.max(
|
1258
|
+
1,
|
1259
|
+
Math.floor(
|
1260
|
+
remainingChars * (1 - Math.pow(this.decayFactor, deltaTime))
|
1261
|
+
)
|
1262
|
+
);
|
1263
|
+
const newText = targetText.slice(0, currentText.length + charsToAdd);
|
1264
|
+
this.animationFrameId = requestAnimationFrame(this.animate);
|
1265
|
+
return newText;
|
1266
|
+
});
|
1267
|
+
};
|
1268
|
+
};
|
1269
|
+
var useSmooth = (text, smooth = false) => {
|
1270
|
+
const [displayedText, setDisplayedText] = (0, import_react35.useState)(text);
|
1271
|
+
const [animatorRef] = (0, import_react35.useState)(
|
1272
|
+
new TextStreamAnimator(setDisplayedText)
|
1273
|
+
);
|
1274
|
+
(0, import_react35.useEffect)(() => {
|
1275
|
+
if (!smooth) {
|
1276
|
+
animatorRef.stop();
|
1277
|
+
return;
|
1278
|
+
}
|
1279
|
+
if (!text.startsWith(animatorRef.targetText)) {
|
1280
|
+
setDisplayedText(text);
|
1281
|
+
animatorRef.targetText = text;
|
1282
|
+
animatorRef.stop();
|
1283
|
+
return;
|
1284
|
+
}
|
1285
|
+
animatorRef.targetText = text;
|
1286
|
+
animatorRef.start();
|
1287
|
+
}, [animatorRef, smooth, text]);
|
1288
|
+
(0, import_react35.useEffect)(() => {
|
1289
|
+
return () => {
|
1290
|
+
animatorRef.stop();
|
1291
|
+
};
|
1292
|
+
}, [animatorRef]);
|
1293
|
+
return smooth ? displayedText : text;
|
1294
|
+
};
|
1295
|
+
|
1296
|
+
// src/primitives/contentPart/ContentPartText.tsx
|
1225
1297
|
var import_jsx_runtime14 = require("react/jsx-runtime");
|
1226
|
-
var ContentPartPrimitiveText = (0,
|
1298
|
+
var ContentPartPrimitiveText = (0, import_react36.forwardRef)(({ smooth, ...rest }, forwardedRef) => {
|
1227
1299
|
const {
|
1228
|
-
|
1229
|
-
|
1300
|
+
status,
|
1301
|
+
part: { text }
|
1230
1302
|
} = useContentPartText();
|
1231
|
-
|
1303
|
+
const smoothText = useSmooth(text, smooth);
|
1304
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_react_primitive4.Primitive.span, { "data-status": status, ...rest, ref: forwardedRef, children: smoothText });
|
1232
1305
|
});
|
1233
1306
|
ContentPartPrimitiveText.displayName = "ContentPartPrimitive.Text";
|
1234
1307
|
|
1235
1308
|
// src/primitives/contentPart/ContentPartImage.tsx
|
1236
1309
|
var import_react_primitive5 = require("@radix-ui/react-primitive");
|
1237
|
-
var
|
1310
|
+
var import_react37 = require("react");
|
1238
1311
|
var import_jsx_runtime15 = require("react/jsx-runtime");
|
1239
|
-
var ContentPartPrimitiveImage = (0,
|
1240
|
-
const
|
1312
|
+
var ContentPartPrimitiveImage = (0, import_react37.forwardRef)((props, forwardedRef) => {
|
1313
|
+
const {
|
1314
|
+
part: { image }
|
1315
|
+
} = useContentPartImage();
|
1241
1316
|
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_react_primitive5.Primitive.img, { src: image, ...props, ref: forwardedRef });
|
1242
1317
|
});
|
1243
1318
|
ContentPartPrimitiveImage.displayName = "ContentPartPrimitive.Image";
|
1244
1319
|
|
1245
1320
|
// src/primitives/contentPart/ContentPartDisplay.tsx
|
1246
1321
|
var ContentPartPrimitiveDisplay = () => {
|
1247
|
-
const
|
1322
|
+
const {
|
1323
|
+
part: { display }
|
1324
|
+
} = useContentPartDisplay();
|
1248
1325
|
return display ?? null;
|
1249
1326
|
};
|
1250
1327
|
ContentPartPrimitiveDisplay.displayName = "ContentPartPrimitive.Display";
|
@@ -1312,7 +1389,7 @@ var MessageContentPartImpl = ({
|
|
1312
1389
|
}) => {
|
1313
1390
|
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(ContentPartProvider, { partIndex, children: /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(MessageContentPartComponent, { components }) });
|
1314
1391
|
};
|
1315
|
-
var MessageContentPart = (0,
|
1392
|
+
var MessageContentPart = (0, import_react38.memo)(
|
1316
1393
|
MessageContentPartImpl,
|
1317
1394
|
(prev, next) => prev.partIndex === next.partIndex && prev.components?.Text === next.components?.Text && prev.components?.Image === next.components?.Image && prev.components?.UI === next.components?.UI && prev.components?.tools === next.components?.tools
|
1318
1395
|
);
|
@@ -1343,7 +1420,7 @@ MessagePrimitiveInProgress.displayName = "MessagePrimitive.InProgress";
|
|
1343
1420
|
|
1344
1421
|
// src/primitives/branchPicker/BranchPickerRoot.tsx
|
1345
1422
|
var import_jsx_runtime17 = require("react/jsx-runtime");
|
1346
|
-
var BranchPickerPrimitiveRoot = (0,
|
1423
|
+
var BranchPickerPrimitiveRoot = (0, import_react39.forwardRef)(({ hideWhenSingleBranch, ...rest }, ref) => {
|
1347
1424
|
return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(MessagePrimitiveIf, { hasBranches: hideWhenSingleBranch ? true : void 0, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(import_react_primitive6.Primitive.div, { ...rest, ref }) });
|
1348
1425
|
});
|
1349
1426
|
BranchPickerPrimitiveRoot.displayName = "BranchPickerPrimitive.Root";
|
@@ -1361,9 +1438,9 @@ __export(composer_exports, {
|
|
1361
1438
|
// src/primitives/composer/ComposerRoot.tsx
|
1362
1439
|
var import_primitive4 = require("@radix-ui/primitive");
|
1363
1440
|
var import_react_primitive7 = require("@radix-ui/react-primitive");
|
1364
|
-
var
|
1441
|
+
var import_react40 = require("react");
|
1365
1442
|
var import_jsx_runtime18 = require("react/jsx-runtime");
|
1366
|
-
var ComposerPrimitiveRoot = (0,
|
1443
|
+
var ComposerPrimitiveRoot = (0, import_react40.forwardRef)(({ onSubmit, ...rest }, forwardedRef) => {
|
1367
1444
|
const send = useComposerSend();
|
1368
1445
|
const handleSubmit = (e) => {
|
1369
1446
|
e.preventDefault();
|
@@ -1385,11 +1462,11 @@ ComposerPrimitiveRoot.displayName = "ComposerPrimitive.Root";
|
|
1385
1462
|
var import_primitive5 = require("@radix-ui/primitive");
|
1386
1463
|
var import_react_compose_refs2 = require("@radix-ui/react-compose-refs");
|
1387
1464
|
var import_react_slot = require("@radix-ui/react-slot");
|
1388
|
-
var
|
1465
|
+
var import_react41 = require("react");
|
1389
1466
|
var import_react_textarea_autosize = __toESM(require("react-textarea-autosize"));
|
1390
1467
|
var import_react_use_escape_keydown = require("@radix-ui/react-use-escape-keydown");
|
1391
1468
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
1392
|
-
var ComposerPrimitiveInput = (0,
|
1469
|
+
var ComposerPrimitiveInput = (0, import_react41.forwardRef)(
|
1393
1470
|
({ autoFocus = false, asChild, disabled, onChange, onKeyDown, ...rest }, forwardedRef) => {
|
1394
1471
|
const { useThread } = useThreadContext();
|
1395
1472
|
const { useComposer, type } = useComposerContext();
|
@@ -1398,7 +1475,7 @@ var ComposerPrimitiveInput = (0, import_react40.forwardRef)(
|
|
1398
1475
|
return c.value;
|
1399
1476
|
});
|
1400
1477
|
const Component = asChild ? import_react_slot.Slot : import_react_textarea_autosize.default;
|
1401
|
-
const textareaRef = (0,
|
1478
|
+
const textareaRef = (0, import_react41.useRef)(null);
|
1402
1479
|
const ref = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, textareaRef);
|
1403
1480
|
(0, import_react_use_escape_keydown.useEscapeKeydown)((e) => {
|
1404
1481
|
const composer = useComposer.getState();
|
@@ -1418,7 +1495,7 @@ var ComposerPrimitiveInput = (0, import_react40.forwardRef)(
|
|
1418
1495
|
}
|
1419
1496
|
};
|
1420
1497
|
const autoFocusEnabled = autoFocus && !disabled;
|
1421
|
-
const focus = (0,
|
1498
|
+
const focus = (0, import_react41.useCallback)(() => {
|
1422
1499
|
const textarea = textareaRef.current;
|
1423
1500
|
if (!textarea || !autoFocusEnabled) return;
|
1424
1501
|
textarea.focus({ preventScroll: true });
|
@@ -1427,7 +1504,7 @@ var ComposerPrimitiveInput = (0, import_react40.forwardRef)(
|
|
1427
1504
|
textareaRef.current.value.length
|
1428
1505
|
);
|
1429
1506
|
}, [autoFocusEnabled]);
|
1430
|
-
(0,
|
1507
|
+
(0, import_react41.useEffect)(() => focus(), [focus]);
|
1431
1508
|
useOnComposerFocus(() => {
|
1432
1509
|
if (type === "new") {
|
1433
1510
|
focus();
|
@@ -1454,10 +1531,10 @@ var ComposerPrimitiveInput = (0, import_react40.forwardRef)(
|
|
1454
1531
|
ComposerPrimitiveInput.displayName = "ComposerPrimitive.Input";
|
1455
1532
|
|
1456
1533
|
// src/primitives/composer/ComposerSend.tsx
|
1457
|
-
var
|
1534
|
+
var import_react42 = require("react");
|
1458
1535
|
var import_react_primitive8 = require("@radix-ui/react-primitive");
|
1459
1536
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
1460
|
-
var ComposerPrimitiveSend = (0,
|
1537
|
+
var ComposerPrimitiveSend = (0, import_react42.forwardRef)(({ disabled, ...rest }, ref) => {
|
1461
1538
|
const { useComposer } = useComposerContext();
|
1462
1539
|
const hasValue = useComposer((c) => c.isEditing && c.value.length > 0);
|
1463
1540
|
return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(
|
@@ -1511,9 +1588,9 @@ __export(thread_exports, {
|
|
1511
1588
|
|
1512
1589
|
// src/primitives/thread/ThreadRoot.tsx
|
1513
1590
|
var import_react_primitive9 = require("@radix-ui/react-primitive");
|
1514
|
-
var
|
1591
|
+
var import_react43 = require("react");
|
1515
1592
|
var import_jsx_runtime21 = require("react/jsx-runtime");
|
1516
|
-
var ThreadPrimitiveRoot = (0,
|
1593
|
+
var ThreadPrimitiveRoot = (0, import_react43.forwardRef)((props, ref) => {
|
1517
1594
|
return /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(import_react_primitive9.Primitive.div, { ...props, ref });
|
1518
1595
|
});
|
1519
1596
|
ThreadPrimitiveRoot.displayName = "ThreadPrimitive.Root";
|
@@ -1540,18 +1617,18 @@ ThreadPrimitiveIf.displayName = "ThreadPrimitive.If";
|
|
1540
1617
|
// src/primitives/thread/ThreadViewport.tsx
|
1541
1618
|
var import_react_compose_refs4 = require("@radix-ui/react-compose-refs");
|
1542
1619
|
var import_react_primitive10 = require("@radix-ui/react-primitive");
|
1543
|
-
var
|
1620
|
+
var import_react47 = require("react");
|
1544
1621
|
|
1545
1622
|
// src/primitive-hooks/thread/useThreadViewportAutoScroll.tsx
|
1546
1623
|
var import_react_compose_refs3 = require("@radix-ui/react-compose-refs");
|
1547
|
-
var
|
1624
|
+
var import_react46 = require("react");
|
1548
1625
|
|
1549
1626
|
// src/utils/hooks/useOnResizeContent.tsx
|
1550
1627
|
var import_react_use_callback_ref2 = require("@radix-ui/react-use-callback-ref");
|
1551
|
-
var
|
1628
|
+
var import_react44 = require("react");
|
1552
1629
|
var useOnResizeContent = (callback) => {
|
1553
1630
|
const callbackRef = (0, import_react_use_callback_ref2.useCallbackRef)(callback);
|
1554
|
-
const refCallback = (0,
|
1631
|
+
const refCallback = (0, import_react44.useCallback)(
|
1555
1632
|
(el) => {
|
1556
1633
|
const resizeObserver = new ResizeObserver(() => {
|
1557
1634
|
callbackRef();
|
@@ -1588,11 +1665,11 @@ var useOnResizeContent = (callback) => {
|
|
1588
1665
|
|
1589
1666
|
// src/utils/hooks/useOnScrollToBottom.tsx
|
1590
1667
|
var import_react_use_callback_ref3 = require("@radix-ui/react-use-callback-ref");
|
1591
|
-
var
|
1668
|
+
var import_react45 = require("react");
|
1592
1669
|
var useOnScrollToBottom = (callback) => {
|
1593
1670
|
const callbackRef = (0, import_react_use_callback_ref3.useCallbackRef)(callback);
|
1594
1671
|
const { useViewport } = useThreadContext();
|
1595
|
-
(0,
|
1672
|
+
(0, import_react45.useEffect)(() => {
|
1596
1673
|
return useViewport.getState().onScrollToBottom(() => {
|
1597
1674
|
callbackRef();
|
1598
1675
|
});
|
@@ -1603,11 +1680,11 @@ var useOnScrollToBottom = (callback) => {
|
|
1603
1680
|
var useThreadViewportAutoScroll = ({
|
1604
1681
|
autoScroll = true
|
1605
1682
|
}) => {
|
1606
|
-
const divRef = (0,
|
1683
|
+
const divRef = (0, import_react46.useRef)(null);
|
1607
1684
|
const { useViewport } = useThreadContext();
|
1608
|
-
const firstRenderRef = (0,
|
1609
|
-
const lastScrollTop = (0,
|
1610
|
-
const isScrollingToBottomRef = (0,
|
1685
|
+
const firstRenderRef = (0, import_react46.useRef)(true);
|
1686
|
+
const lastScrollTop = (0, import_react46.useRef)(0);
|
1687
|
+
const isScrollingToBottomRef = (0, import_react46.useRef)(false);
|
1611
1688
|
const scrollToBottom = () => {
|
1612
1689
|
const div = divRef.current;
|
1613
1690
|
if (!div || !autoScroll) return;
|
@@ -1654,7 +1731,7 @@ var useThreadViewportAutoScroll = ({
|
|
1654
1731
|
|
1655
1732
|
// src/primitives/thread/ThreadViewport.tsx
|
1656
1733
|
var import_jsx_runtime22 = require("react/jsx-runtime");
|
1657
|
-
var ThreadPrimitiveViewport = (0,
|
1734
|
+
var ThreadPrimitiveViewport = (0, import_react47.forwardRef)(({ autoScroll, onScroll, children, ...rest }, forwardedRef) => {
|
1658
1735
|
const autoScrollRef = useThreadViewportAutoScroll({
|
1659
1736
|
autoScroll
|
1660
1737
|
});
|
@@ -1664,10 +1741,10 @@ var ThreadPrimitiveViewport = (0, import_react46.forwardRef)(({ autoScroll, onSc
|
|
1664
1741
|
ThreadPrimitiveViewport.displayName = "ThreadPrimitive.Viewport";
|
1665
1742
|
|
1666
1743
|
// src/primitives/thread/ThreadMessages.tsx
|
1667
|
-
var
|
1744
|
+
var import_react49 = require("react");
|
1668
1745
|
|
1669
1746
|
// src/context/providers/MessageProvider.tsx
|
1670
|
-
var
|
1747
|
+
var import_react48 = require("react");
|
1671
1748
|
var import_zustand12 = require("zustand");
|
1672
1749
|
|
1673
1750
|
// src/context/stores/EditComposer.ts
|
@@ -1729,7 +1806,7 @@ var syncMessage = (messages, getBranches, useMessage, messageIndex) => {
|
|
1729
1806
|
};
|
1730
1807
|
var useMessageContext2 = (messageIndex) => {
|
1731
1808
|
const { useThreadMessages, useThreadActions } = useThreadContext();
|
1732
|
-
const [context] = (0,
|
1809
|
+
const [context] = (0, import_react48.useState)(() => {
|
1733
1810
|
const useMessage = (0, import_zustand12.create)(() => ({}));
|
1734
1811
|
const useMessageUtils = makeMessageUtilsStore();
|
1735
1812
|
const useEditComposer = makeEditComposerStore({
|
@@ -1766,7 +1843,7 @@ var useMessageContext2 = (messageIndex) => {
|
|
1766
1843
|
);
|
1767
1844
|
return { useMessage, useMessageUtils, useEditComposer };
|
1768
1845
|
});
|
1769
|
-
(0,
|
1846
|
+
(0, import_react48.useEffect)(() => {
|
1770
1847
|
return useThreadMessages.subscribe((thread) => {
|
1771
1848
|
syncMessage(
|
1772
1849
|
thread,
|
@@ -1808,7 +1885,7 @@ var ThreadMessageImpl = ({
|
|
1808
1885
|
/* @__PURE__ */ (0, import_jsx_runtime24.jsx)(MessagePrimitiveIf, { assistant: true, children: /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(AssistantMessage, {}) })
|
1809
1886
|
] });
|
1810
1887
|
};
|
1811
|
-
var ThreadMessage = (0,
|
1888
|
+
var ThreadMessage = (0, import_react49.memo)(
|
1812
1889
|
ThreadMessageImpl,
|
1813
1890
|
(prev, next) => prev.messageIndex === next.messageIndex && prev.components.Message === next.components.Message && prev.components.UserMessage === next.components.UserMessage && prev.components.EditComposer === next.components.EditComposer && prev.components.AssistantMessage === next.components.AssistantMessage
|
1814
1891
|
);
|
@@ -1831,7 +1908,7 @@ var ThreadPrimitiveMessagesImpl = ({
|
|
1831
1908
|
});
|
1832
1909
|
};
|
1833
1910
|
ThreadPrimitiveMessagesImpl.displayName = "ThreadPrimitive.Messages";
|
1834
|
-
var ThreadPrimitiveMessages = (0,
|
1911
|
+
var ThreadPrimitiveMessages = (0, import_react49.memo)(
|
1835
1912
|
ThreadPrimitiveMessagesImpl,
|
1836
1913
|
(prev, next) => prev.components?.Message === next.components?.Message && prev.components?.UserMessage === next.components?.UserMessage && prev.components?.EditComposer === next.components?.EditComposer && prev.components?.AssistantMessage === next.components?.AssistantMessage
|
1837
1914
|
);
|
@@ -1849,7 +1926,7 @@ var ThreadPrimitiveSuggestion = createActionButton(
|
|
1849
1926
|
);
|
1850
1927
|
|
1851
1928
|
// src/runtime/local/useLocalRuntime.tsx
|
1852
|
-
var
|
1929
|
+
var import_react50 = require("react");
|
1853
1930
|
|
1854
1931
|
// src/runtime/utils/idUtils.tsx
|
1855
1932
|
var import_non_secure = require("nanoid/non-secure");
|
@@ -2191,8 +2268,8 @@ var LocalThreadRuntime = class {
|
|
2191
2268
|
|
2192
2269
|
// src/runtime/local/useLocalRuntime.tsx
|
2193
2270
|
var useLocalRuntime = (adapter) => {
|
2194
|
-
const [runtime] = (0,
|
2195
|
-
(0,
|
2271
|
+
const [runtime] = (0, import_react50.useState)(() => new LocalRuntime(adapter));
|
2272
|
+
(0, import_react50.useInsertionEffect)(() => {
|
2196
2273
|
runtime.adapter = adapter;
|
2197
2274
|
});
|
2198
2275
|
return runtime;
|
@@ -2203,7 +2280,8 @@ var internal_exports = {};
|
|
2203
2280
|
__export(internal_exports, {
|
2204
2281
|
BaseAssistantRuntime: () => BaseAssistantRuntime,
|
2205
2282
|
MessageRepository: () => MessageRepository,
|
2206
|
-
ProxyConfigProvider: () => ProxyConfigProvider
|
2283
|
+
ProxyConfigProvider: () => ProxyConfigProvider,
|
2284
|
+
useSmooth: () => useSmooth
|
2207
2285
|
});
|
2208
2286
|
// Annotate the CommonJS export names for ESM import in node:
|
2209
2287
|
0 && (module.exports = {
|