@assistant-ui/react 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.mts CHANGED
@@ -95,7 +95,7 @@ type MessageIfFilters = {
95
95
  editing: boolean | undefined;
96
96
  hasBranches: boolean | undefined;
97
97
  copied: boolean | undefined;
98
- unstable_hoveringOrLast: boolean | undefined;
98
+ lastOrHover: boolean | undefined;
99
99
  };
100
100
  type MessageIfProps = RequireAtLeastOne<MessageIfFilters> & {
101
101
  children: React.ReactNode;
@@ -142,7 +142,10 @@ declare const ActionBarRoot: react.ForwardRefExoticComponent<Pick<Omit<react.Det
142
142
  ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
143
143
  } & {
144
144
  asChild?: boolean;
145
- }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
145
+ }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & {
146
+ hideWhenBusy?: boolean;
147
+ hideWhenNotLastOrHover?: boolean;
148
+ } & react.RefAttributes<HTMLDivElement>>;
146
149
 
147
150
  type ActionBarCopyProps = {
148
151
  copiedDuration?: number;
package/dist/index.d.ts CHANGED
@@ -95,7 +95,7 @@ type MessageIfFilters = {
95
95
  editing: boolean | undefined;
96
96
  hasBranches: boolean | undefined;
97
97
  copied: boolean | undefined;
98
- unstable_hoveringOrLast: boolean | undefined;
98
+ lastOrHover: boolean | undefined;
99
99
  };
100
100
  type MessageIfProps = RequireAtLeastOne<MessageIfFilters> & {
101
101
  children: React.ReactNode;
@@ -142,7 +142,10 @@ declare const ActionBarRoot: react.ForwardRefExoticComponent<Pick<Omit<react.Det
142
142
  ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
143
143
  } & {
144
144
  asChild?: boolean;
145
- }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
145
+ }, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & {
146
+ hideWhenBusy?: boolean;
147
+ hideWhenNotLastOrHover?: boolean;
148
+ } & react.RefAttributes<HTMLDivElement>>;
146
149
 
147
150
  type ActionBarCopyProps = {
148
151
  copiedDuration?: number;
package/dist/index.js CHANGED
@@ -365,6 +365,9 @@ var useChatWithBranches = (chat) => {
365
365
  [chat, getBranchState, switchToBranch, editAt, reloadAt]
366
366
  );
367
367
  };
368
+ var hasUpcomingMessage = (thread) => {
369
+ return thread.isLoading && thread.messages[thread.messages.length - 1]?.role !== "assistant";
370
+ };
368
371
 
369
372
  // src/primitives/message/index.ts
370
373
  var message_exports = {};
@@ -445,6 +448,10 @@ var MessageRoot = (0, import_react7.forwardRef)(
445
448
  );
446
449
 
447
450
  // src/primitives/message/MessageIf.tsx
451
+ var isLast = (thread, message) => {
452
+ const hasUpcoming = hasUpcomingMessage(thread);
453
+ return hasUpcoming ? message.id === UPCOMING_MESSAGE_ID : thread.messages[thread.messages.length - 1]?.id === message.id;
454
+ };
448
455
  var useMessageIf = (props) => {
449
456
  const thread = useThreadContext("Message.If", (s) => s.chat);
450
457
  return useMessageContext(
@@ -461,7 +468,7 @@ var useMessageIf = (props) => {
461
468
  return false;
462
469
  if (props.editing === false && isEditing)
463
470
  return false;
464
- if (props.unstable_hoveringOrLast === true && !isHovering && thread.messages[thread.messages.length - 1]?.id !== message.id)
471
+ if (props.lastOrHover === true && !isHovering && !isLast(thread, message))
465
472
  return false;
466
473
  if (props.copied === true && !isCopied)
467
474
  return false;
@@ -531,7 +538,7 @@ var ThreadMessages = ({ components }) => {
531
538
  // biome-ignore lint/suspicious/noArrayIndexKey: fixes a11y issues with branch navigation
532
539
  /* @__PURE__ */ React.createElement(MessageProvider, { key: idx, message }, /* @__PURE__ */ React.createElement(MessageIf, { user: true, editing: false }, /* @__PURE__ */ React.createElement(UserMessage, null)), /* @__PURE__ */ React.createElement(MessageIf, { user: true, editing: true }, /* @__PURE__ */ React.createElement(EditingUserMessage, null)), /* @__PURE__ */ React.createElement(MessageIf, { assistant: true }, /* @__PURE__ */ React.createElement(AssistantMessage, null)))
533
540
  );
534
- }), chat.isLoading && chat.messages[chat.messages.length - 1]?.role !== "assistant" && /* @__PURE__ */ React.createElement(
541
+ }), hasUpcomingMessage(chat) && /* @__PURE__ */ React.createElement(
535
542
  MessageProvider,
536
543
  {
537
544
  message: {
@@ -784,8 +791,8 @@ __export(actionBar_exports, {
784
791
  // src/primitives/actionBar/ActionBarRoot.tsx
785
792
  var import_react_primitive8 = require("@radix-ui/react-primitive");
786
793
  var import_react14 = require("react");
787
- var ActionBarRoot = (0, import_react14.forwardRef)(({ ...rest }, ref) => {
788
- return /* @__PURE__ */ React.createElement(import_react_primitive8.Primitive.div, { ...rest, ref });
794
+ var ActionBarRoot = (0, import_react14.forwardRef)(({ hideWhenBusy, hideWhenNotLastOrHover, ...rest }, ref) => {
795
+ return /* @__PURE__ */ React.createElement(ThreadIf, { busy: hideWhenBusy ? false : void 0 }, /* @__PURE__ */ React.createElement(MessageIf, { lastOrHover: hideWhenNotLastOrHover ? true : void 0 }, /* @__PURE__ */ React.createElement(import_react_primitive8.Primitive.div, { ...rest, ref })));
789
796
  });
790
797
 
791
798
  // src/actions/useCopyMessage.tsx
package/dist/index.mjs CHANGED
@@ -330,6 +330,9 @@ var useChatWithBranches = (chat) => {
330
330
  [chat, getBranchState, switchToBranch, editAt, reloadAt]
331
331
  );
332
332
  };
333
+ var hasUpcomingMessage = (thread) => {
334
+ return thread.isLoading && thread.messages[thread.messages.length - 1]?.role !== "assistant";
335
+ };
333
336
 
334
337
  // src/primitives/message/index.ts
335
338
  var message_exports = {};
@@ -412,6 +415,10 @@ var MessageRoot = forwardRef3(
412
415
  );
413
416
 
414
417
  // src/primitives/message/MessageIf.tsx
418
+ var isLast = (thread, message) => {
419
+ const hasUpcoming = hasUpcomingMessage(thread);
420
+ return hasUpcoming ? message.id === UPCOMING_MESSAGE_ID : thread.messages[thread.messages.length - 1]?.id === message.id;
421
+ };
415
422
  var useMessageIf = (props) => {
416
423
  const thread = useThreadContext("Message.If", (s) => s.chat);
417
424
  return useMessageContext(
@@ -428,7 +435,7 @@ var useMessageIf = (props) => {
428
435
  return false;
429
436
  if (props.editing === false && isEditing)
430
437
  return false;
431
- if (props.unstable_hoveringOrLast === true && !isHovering && thread.messages[thread.messages.length - 1]?.id !== message.id)
438
+ if (props.lastOrHover === true && !isHovering && !isLast(thread, message))
432
439
  return false;
433
440
  if (props.copied === true && !isCopied)
434
441
  return false;
@@ -498,7 +505,7 @@ var ThreadMessages = ({ components }) => {
498
505
  // biome-ignore lint/suspicious/noArrayIndexKey: fixes a11y issues with branch navigation
499
506
  /* @__PURE__ */ React.createElement(MessageProvider, { key: idx, message }, /* @__PURE__ */ React.createElement(MessageIf, { user: true, editing: false }, /* @__PURE__ */ React.createElement(UserMessage, null)), /* @__PURE__ */ React.createElement(MessageIf, { user: true, editing: true }, /* @__PURE__ */ React.createElement(EditingUserMessage, null)), /* @__PURE__ */ React.createElement(MessageIf, { assistant: true }, /* @__PURE__ */ React.createElement(AssistantMessage, null)))
500
507
  );
501
- }), chat.isLoading && chat.messages[chat.messages.length - 1]?.role !== "assistant" && /* @__PURE__ */ React.createElement(
508
+ }), hasUpcomingMessage(chat) && /* @__PURE__ */ React.createElement(
502
509
  MessageProvider,
503
510
  {
504
511
  message: {
@@ -761,8 +768,8 @@ import {
761
768
  Primitive as Primitive8
762
769
  } from "@radix-ui/react-primitive";
763
770
  import { forwardRef as forwardRef10 } from "react";
764
- var ActionBarRoot = forwardRef10(({ ...rest }, ref) => {
765
- return /* @__PURE__ */ React.createElement(Primitive8.div, { ...rest, ref });
771
+ var ActionBarRoot = forwardRef10(({ hideWhenBusy, hideWhenNotLastOrHover, ...rest }, ref) => {
772
+ return /* @__PURE__ */ React.createElement(ThreadIf, { busy: hideWhenBusy ? false : void 0 }, /* @__PURE__ */ React.createElement(MessageIf, { lastOrHover: hideWhenNotLastOrHover ? true : void 0 }, /* @__PURE__ */ React.createElement(Primitive8.div, { ...rest, ref })));
766
773
  });
767
774
 
768
775
  // src/actions/useCopyMessage.tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@assistant-ui/react",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "license": "MIT",
5
5
  "exports": {
6
6
  ".": {