@assistant-ui/react 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +8 -7
- package/dist/index.d.ts +8 -7
- package/dist/index.js +94 -51
- package/dist/index.mjs +94 -51
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
@@ -35,8 +35,13 @@ declare const ThreadViewport: react.ForwardRefExoticComponent<Pick<Omit<react.De
|
|
35
35
|
type ThreadMessagesProps = {
|
36
36
|
components: {
|
37
37
|
Message: React.ComponentType;
|
38
|
+
UserMessage?: React.ComponentType;
|
39
|
+
EditingUserMessage?: React.ComponentType;
|
40
|
+
AssistantMessage?: React.ComponentType;
|
38
41
|
} | {
|
42
|
+
Message?: React.ComponentType;
|
39
43
|
UserMessage: React.ComponentType;
|
44
|
+
EditingUserMessage?: React.ComponentType;
|
40
45
|
AssistantMessage: React.ComponentType;
|
41
46
|
};
|
42
47
|
};
|
@@ -137,9 +142,7 @@ declare const ActionBarRoot: react.ForwardRefExoticComponent<Pick<Omit<react.Det
|
|
137
142
|
ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
|
138
143
|
} & {
|
139
144
|
asChild?: boolean;
|
140
|
-
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> &
|
141
|
-
hideWhenEditing?: boolean;
|
142
|
-
} & react.RefAttributes<HTMLDivElement>>;
|
145
|
+
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
|
143
146
|
|
144
147
|
type ActionBarCopyProps = {
|
145
148
|
copiedDuration?: number;
|
@@ -170,9 +173,7 @@ declare const EditBarRoot: react.ForwardRefExoticComponent<Pick<Omit<react.Detai
|
|
170
173
|
ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
|
171
174
|
} & {
|
172
175
|
asChild?: boolean;
|
173
|
-
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> &
|
174
|
-
hideWhenNotEditing?: boolean;
|
175
|
-
} & react.RefAttributes<HTMLDivElement>>;
|
176
|
+
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
|
176
177
|
|
177
178
|
declare const EditBarSave: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
178
179
|
ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
|
@@ -221,7 +222,7 @@ declare const useMessageContext: <Selection>(consumerName: string, selector: (s:
|
|
221
222
|
|
222
223
|
declare const useCopyMessage: ({ copiedDuration }: {
|
223
224
|
copiedDuration?: number | undefined;
|
224
|
-
}) => () => void;
|
225
|
+
}) => (() => void) | null;
|
225
226
|
|
226
227
|
declare const useReloadMessage: () => (() => Promise<void>) | null;
|
227
228
|
|
package/dist/index.d.ts
CHANGED
@@ -35,8 +35,13 @@ declare const ThreadViewport: react.ForwardRefExoticComponent<Pick<Omit<react.De
|
|
35
35
|
type ThreadMessagesProps = {
|
36
36
|
components: {
|
37
37
|
Message: React.ComponentType;
|
38
|
+
UserMessage?: React.ComponentType;
|
39
|
+
EditingUserMessage?: React.ComponentType;
|
40
|
+
AssistantMessage?: React.ComponentType;
|
38
41
|
} | {
|
42
|
+
Message?: React.ComponentType;
|
39
43
|
UserMessage: React.ComponentType;
|
44
|
+
EditingUserMessage?: React.ComponentType;
|
40
45
|
AssistantMessage: React.ComponentType;
|
41
46
|
};
|
42
47
|
};
|
@@ -137,9 +142,7 @@ declare const ActionBarRoot: react.ForwardRefExoticComponent<Pick<Omit<react.Det
|
|
137
142
|
ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
|
138
143
|
} & {
|
139
144
|
asChild?: boolean;
|
140
|
-
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> &
|
141
|
-
hideWhenEditing?: boolean;
|
142
|
-
} & react.RefAttributes<HTMLDivElement>>;
|
145
|
+
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
|
143
146
|
|
144
147
|
type ActionBarCopyProps = {
|
145
148
|
copiedDuration?: number;
|
@@ -170,9 +173,7 @@ declare const EditBarRoot: react.ForwardRefExoticComponent<Pick<Omit<react.Detai
|
|
170
173
|
ref?: ((instance: HTMLDivElement | null) => void) | react.RefObject<HTMLDivElement> | null | undefined;
|
171
174
|
} & {
|
172
175
|
asChild?: boolean;
|
173
|
-
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> &
|
174
|
-
hideWhenNotEditing?: boolean;
|
175
|
-
} & react.RefAttributes<HTMLDivElement>>;
|
176
|
+
}, "key" | keyof react.HTMLAttributes<HTMLDivElement> | "asChild"> & react.RefAttributes<HTMLDivElement>>;
|
176
177
|
|
177
178
|
declare const EditBarSave: react.ForwardRefExoticComponent<Pick<Omit<react.DetailedHTMLProps<react.ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
|
178
179
|
ref?: ((instance: HTMLButtonElement | null) => void) | react.RefObject<HTMLButtonElement> | null | undefined;
|
@@ -221,7 +222,7 @@ declare const useMessageContext: <Selection>(consumerName: string, selector: (s:
|
|
221
222
|
|
222
223
|
declare const useCopyMessage: ({ copiedDuration }: {
|
223
224
|
copiedDuration?: number | undefined;
|
224
|
-
}) => () => void;
|
225
|
+
}) => (() => void) | null;
|
225
226
|
|
226
227
|
declare const useReloadMessage: () => (() => Promise<void>) | null;
|
227
228
|
|
package/dist/index.js
CHANGED
@@ -186,7 +186,6 @@ var useOnResizeContent = (ref, callback) => {
|
|
186
186
|
return;
|
187
187
|
const resizeObserver = new ResizeObserver(() => {
|
188
188
|
callbackRef.current();
|
189
|
-
console.log("resize observed");
|
190
189
|
});
|
191
190
|
const mutationObserver = new MutationObserver((mutations) => {
|
192
191
|
for (const mutation of mutations) {
|
@@ -203,6 +202,7 @@ var useOnResizeContent = (ref, callback) => {
|
|
203
202
|
}
|
204
203
|
callbackRef.current();
|
205
204
|
});
|
205
|
+
resizeObserver.observe(el);
|
206
206
|
mutationObserver.observe(el, { childList: true });
|
207
207
|
for (const child of el.children) {
|
208
208
|
resizeObserver.observe(child);
|
@@ -514,22 +514,23 @@ var MessageEditableContent = (0, import_react8.forwardRef)(({ onChange, value, .
|
|
514
514
|
|
515
515
|
// src/primitives/thread/ThreadMessages.tsx
|
516
516
|
var getComponents = (components) => {
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
}
|
523
|
-
return components;
|
517
|
+
return {
|
518
|
+
EditingUserMessage: components.EditingUserMessage ?? components.UserMessage ?? components.Message,
|
519
|
+
UserMessage: components.UserMessage ?? components.Message,
|
520
|
+
AssistantMessage: components.AssistantMessage ?? components.Message
|
521
|
+
};
|
524
522
|
};
|
525
523
|
var ThreadMessages = ({ components }) => {
|
526
524
|
const chat = useThreadContext("Thread.Messages", (s) => s.chat);
|
527
525
|
const messages = chat.messages;
|
528
|
-
const { UserMessage, AssistantMessage } = getComponents(components);
|
526
|
+
const { UserMessage, EditingUserMessage, AssistantMessage } = getComponents(components);
|
529
527
|
if (messages.length === 0)
|
530
528
|
return null;
|
531
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, messages.map((message) => {
|
532
|
-
return
|
529
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, messages.map((message, idx) => {
|
530
|
+
return (
|
531
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: fixes a11y issues with branch navigation
|
532
|
+
/* @__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
|
+
);
|
533
534
|
}), chat.isLoading && chat.messages[chat.messages.length - 1]?.role !== "assistant" && /* @__PURE__ */ React.createElement(
|
534
535
|
MessageProvider,
|
535
536
|
{
|
@@ -698,12 +699,19 @@ var useGoToNextBranch = () => {
|
|
698
699
|
"BranchPicker.Next",
|
699
700
|
(s) => s.chat.switchToBranch
|
700
701
|
);
|
701
|
-
const
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
702
|
+
const context = useMessageContext("BranchPicker.Next", (s) => {
|
703
|
+
const {
|
704
|
+
message: message2,
|
705
|
+
editState: { isEditing },
|
706
|
+
branchState: { branchId: branchId2, branchCount }
|
707
|
+
} = s;
|
708
|
+
if (isEditing || branchCount <= 1 || branchId2 + 1 >= branchCount)
|
709
|
+
return null;
|
710
|
+
return { message: message2, branchId: branchId2 };
|
711
|
+
});
|
712
|
+
if (!context)
|
706
713
|
return null;
|
714
|
+
const { message, branchId } = context;
|
707
715
|
return () => {
|
708
716
|
switchToBranch(message, branchId + 1);
|
709
717
|
};
|
@@ -718,12 +726,19 @@ var useGoToPreviousBranch = () => {
|
|
718
726
|
"BranchPicker.Previous",
|
719
727
|
(s) => s.chat.switchToBranch
|
720
728
|
);
|
721
|
-
const
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
729
|
+
const context = useMessageContext("BranchPicker.Previous", (s) => {
|
730
|
+
const {
|
731
|
+
message: message2,
|
732
|
+
editState: { isEditing },
|
733
|
+
branchState: { branchId: branchId2, branchCount }
|
734
|
+
} = s;
|
735
|
+
if (isEditing || branchCount <= 1 || branchId2 <= 0)
|
736
|
+
return null;
|
737
|
+
return { message: message2, branchId: branchId2 };
|
738
|
+
});
|
739
|
+
if (!context)
|
726
740
|
return null;
|
741
|
+
const { message, branchId } = context;
|
727
742
|
return () => {
|
728
743
|
switchToBranch(message, branchId - 1);
|
729
744
|
};
|
@@ -769,18 +784,27 @@ __export(actionBar_exports, {
|
|
769
784
|
// src/primitives/actionBar/ActionBarRoot.tsx
|
770
785
|
var import_react_primitive8 = require("@radix-ui/react-primitive");
|
771
786
|
var import_react14 = require("react");
|
772
|
-
var ActionBarRoot = (0, import_react14.forwardRef)(({
|
773
|
-
return /* @__PURE__ */ React.createElement(
|
787
|
+
var ActionBarRoot = (0, import_react14.forwardRef)(({ ...rest }, ref) => {
|
788
|
+
return /* @__PURE__ */ React.createElement(import_react_primitive8.Primitive.div, { ...rest, ref });
|
774
789
|
});
|
775
790
|
|
776
791
|
// src/actions/useCopyMessage.tsx
|
777
792
|
var useCopyMessage = ({ copiedDuration = 3e3 }) => {
|
778
|
-
const
|
779
|
-
|
780
|
-
|
781
|
-
|
793
|
+
const context = useMessageContext("ActionBar.Copy", (s) => {
|
794
|
+
const {
|
795
|
+
editState: { isEditing },
|
796
|
+
message: { content: content2 },
|
797
|
+
setIsCopied: setIsCopied2
|
798
|
+
} = s;
|
799
|
+
if (isEditing)
|
800
|
+
return null;
|
801
|
+
return { content: content2, setIsCopied: setIsCopied2 };
|
802
|
+
});
|
803
|
+
if (!context)
|
804
|
+
return null;
|
805
|
+
const { content, setIsCopied } = context;
|
782
806
|
return () => {
|
783
|
-
navigator.clipboard.writeText(
|
807
|
+
navigator.clipboard.writeText(content);
|
784
808
|
setIsCopied(true);
|
785
809
|
setTimeout(() => setIsCopied(false), copiedDuration);
|
786
810
|
};
|
@@ -795,8 +819,13 @@ var useReloadMessage = () => {
|
|
795
819
|
s.chat.isLoading,
|
796
820
|
s.chat.reloadAt
|
797
821
|
]);
|
798
|
-
const message = useMessageContext("ActionBar.Reload", (s) =>
|
799
|
-
|
822
|
+
const message = useMessageContext("ActionBar.Reload", (s) => {
|
823
|
+
const message2 = s.message;
|
824
|
+
if (message2.role !== "assistant" || isLoading)
|
825
|
+
return null;
|
826
|
+
return message2;
|
827
|
+
});
|
828
|
+
if (!message)
|
800
829
|
return null;
|
801
830
|
return () => reloadAt(message);
|
802
831
|
};
|
@@ -806,14 +835,21 @@ var ActionBarReload = createActionButton(useReloadMessage);
|
|
806
835
|
|
807
836
|
// src/actions/useBeginMessageEdit.tsx
|
808
837
|
var useBeginMessageEdit = () => {
|
809
|
-
const
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
838
|
+
const context = useMessageContext("ActionBar.Edit", (s) => {
|
839
|
+
const {
|
840
|
+
message: { content: content2 },
|
841
|
+
editState: { isEditing },
|
842
|
+
setEditState: setEditState2
|
843
|
+
} = s;
|
844
|
+
if (isEditing)
|
845
|
+
return null;
|
846
|
+
return { content: content2, setEditState: setEditState2 };
|
847
|
+
});
|
848
|
+
if (!context)
|
814
849
|
return null;
|
850
|
+
const { content, setEditState } = context;
|
815
851
|
return () => {
|
816
|
-
setEditState({ isEditing: true, value:
|
852
|
+
setEditState({ isEditing: true, value: content });
|
817
853
|
};
|
818
854
|
};
|
819
855
|
|
@@ -832,28 +868,29 @@ __export(editBar_exports, {
|
|
832
868
|
var import_react_primitive9 = require("@radix-ui/react-primitive");
|
833
869
|
var import_react15 = require("react");
|
834
870
|
var EditBarRoot = (0, import_react15.forwardRef)(
|
835
|
-
({
|
836
|
-
return /* @__PURE__ */ React.createElement(
|
871
|
+
({ ...rest }, ref) => {
|
872
|
+
return /* @__PURE__ */ React.createElement(import_react_primitive9.Primitive.div, { ...rest, ref });
|
837
873
|
}
|
838
874
|
);
|
839
875
|
|
840
876
|
// src/actions/useSaveMessageEdit.tsx
|
841
877
|
var useSaveMessageEdit = () => {
|
842
878
|
const chat = useThreadContext("EditBar.Save", (s) => s.chat);
|
843
|
-
const
|
844
|
-
|
845
|
-
(
|
846
|
-
|
847
|
-
|
879
|
+
const context = useMessageContext("EditBar.Save", (s) => {
|
880
|
+
const { message: message2, editState, setEditState: setEditState2 } = s;
|
881
|
+
if (!editState.isEditing)
|
882
|
+
return null;
|
883
|
+
return { message: message2, content: editState.value, setEditState: setEditState2 };
|
884
|
+
});
|
885
|
+
if (!context)
|
848
886
|
return null;
|
887
|
+
const { message, content, setEditState } = context;
|
849
888
|
return () => {
|
850
|
-
if (!editState.isEditing)
|
851
|
-
return;
|
852
889
|
chat.editAt(message, {
|
853
890
|
...message,
|
854
891
|
id: void 0,
|
855
892
|
// remove id to create a new message
|
856
|
-
content
|
893
|
+
content
|
857
894
|
});
|
858
895
|
setEditState({ isEditing: false });
|
859
896
|
};
|
@@ -864,12 +901,18 @@ var EditBarSave = createActionButton(useSaveMessageEdit);
|
|
864
901
|
|
865
902
|
// src/actions/useCancelMessageEdit.tsx
|
866
903
|
var useCancelMessageEdit = () => {
|
867
|
-
const
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
904
|
+
const context = useMessageContext("EditBar.Cancel", (s) => {
|
905
|
+
const {
|
906
|
+
editState: { isEditing },
|
907
|
+
setEditState: setEditState2
|
908
|
+
} = s;
|
909
|
+
if (!isEditing)
|
910
|
+
return null;
|
911
|
+
return { setEditState: setEditState2 };
|
912
|
+
});
|
913
|
+
if (!context)
|
872
914
|
return null;
|
915
|
+
const { setEditState } = context;
|
873
916
|
return () => {
|
874
917
|
setEditState({ isEditing: false });
|
875
918
|
};
|
package/dist/index.mjs
CHANGED
@@ -151,7 +151,6 @@ var useOnResizeContent = (ref, callback) => {
|
|
151
151
|
return;
|
152
152
|
const resizeObserver = new ResizeObserver(() => {
|
153
153
|
callbackRef.current();
|
154
|
-
console.log("resize observed");
|
155
154
|
});
|
156
155
|
const mutationObserver = new MutationObserver((mutations) => {
|
157
156
|
for (const mutation of mutations) {
|
@@ -168,6 +167,7 @@ var useOnResizeContent = (ref, callback) => {
|
|
168
167
|
}
|
169
168
|
callbackRef.current();
|
170
169
|
});
|
170
|
+
resizeObserver.observe(el);
|
171
171
|
mutationObserver.observe(el, { childList: true });
|
172
172
|
for (const child of el.children) {
|
173
173
|
resizeObserver.observe(child);
|
@@ -481,22 +481,23 @@ var MessageEditableContent = forwardRef4(({ onChange, value, ...rest }, forwarde
|
|
481
481
|
|
482
482
|
// src/primitives/thread/ThreadMessages.tsx
|
483
483
|
var getComponents = (components) => {
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
}
|
490
|
-
return components;
|
484
|
+
return {
|
485
|
+
EditingUserMessage: components.EditingUserMessage ?? components.UserMessage ?? components.Message,
|
486
|
+
UserMessage: components.UserMessage ?? components.Message,
|
487
|
+
AssistantMessage: components.AssistantMessage ?? components.Message
|
488
|
+
};
|
491
489
|
};
|
492
490
|
var ThreadMessages = ({ components }) => {
|
493
491
|
const chat = useThreadContext("Thread.Messages", (s) => s.chat);
|
494
492
|
const messages = chat.messages;
|
495
|
-
const { UserMessage, AssistantMessage } = getComponents(components);
|
493
|
+
const { UserMessage, EditingUserMessage, AssistantMessage } = getComponents(components);
|
496
494
|
if (messages.length === 0)
|
497
495
|
return null;
|
498
|
-
return /* @__PURE__ */ React.createElement(React.Fragment, null, messages.map((message) => {
|
499
|
-
return
|
496
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, messages.map((message, idx) => {
|
497
|
+
return (
|
498
|
+
// biome-ignore lint/suspicious/noArrayIndexKey: fixes a11y issues with branch navigation
|
499
|
+
/* @__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
|
+
);
|
500
501
|
}), chat.isLoading && chat.messages[chat.messages.length - 1]?.role !== "assistant" && /* @__PURE__ */ React.createElement(
|
501
502
|
MessageProvider,
|
502
503
|
{
|
@@ -671,12 +672,19 @@ var useGoToNextBranch = () => {
|
|
671
672
|
"BranchPicker.Next",
|
672
673
|
(s) => s.chat.switchToBranch
|
673
674
|
);
|
674
|
-
const
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
675
|
+
const context = useMessageContext("BranchPicker.Next", (s) => {
|
676
|
+
const {
|
677
|
+
message: message2,
|
678
|
+
editState: { isEditing },
|
679
|
+
branchState: { branchId: branchId2, branchCount }
|
680
|
+
} = s;
|
681
|
+
if (isEditing || branchCount <= 1 || branchId2 + 1 >= branchCount)
|
682
|
+
return null;
|
683
|
+
return { message: message2, branchId: branchId2 };
|
684
|
+
});
|
685
|
+
if (!context)
|
679
686
|
return null;
|
687
|
+
const { message, branchId } = context;
|
680
688
|
return () => {
|
681
689
|
switchToBranch(message, branchId + 1);
|
682
690
|
};
|
@@ -691,12 +699,19 @@ var useGoToPreviousBranch = () => {
|
|
691
699
|
"BranchPicker.Previous",
|
692
700
|
(s) => s.chat.switchToBranch
|
693
701
|
);
|
694
|
-
const
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
702
|
+
const context = useMessageContext("BranchPicker.Previous", (s) => {
|
703
|
+
const {
|
704
|
+
message: message2,
|
705
|
+
editState: { isEditing },
|
706
|
+
branchState: { branchId: branchId2, branchCount }
|
707
|
+
} = s;
|
708
|
+
if (isEditing || branchCount <= 1 || branchId2 <= 0)
|
709
|
+
return null;
|
710
|
+
return { message: message2, branchId: branchId2 };
|
711
|
+
});
|
712
|
+
if (!context)
|
699
713
|
return null;
|
714
|
+
const { message, branchId } = context;
|
700
715
|
return () => {
|
701
716
|
switchToBranch(message, branchId - 1);
|
702
717
|
};
|
@@ -746,18 +761,27 @@ import {
|
|
746
761
|
Primitive as Primitive8
|
747
762
|
} from "@radix-ui/react-primitive";
|
748
763
|
import { forwardRef as forwardRef10 } from "react";
|
749
|
-
var ActionBarRoot = forwardRef10(({
|
750
|
-
return /* @__PURE__ */ React.createElement(
|
764
|
+
var ActionBarRoot = forwardRef10(({ ...rest }, ref) => {
|
765
|
+
return /* @__PURE__ */ React.createElement(Primitive8.div, { ...rest, ref });
|
751
766
|
});
|
752
767
|
|
753
768
|
// src/actions/useCopyMessage.tsx
|
754
769
|
var useCopyMessage = ({ copiedDuration = 3e3 }) => {
|
755
|
-
const
|
756
|
-
|
757
|
-
|
758
|
-
|
770
|
+
const context = useMessageContext("ActionBar.Copy", (s) => {
|
771
|
+
const {
|
772
|
+
editState: { isEditing },
|
773
|
+
message: { content: content2 },
|
774
|
+
setIsCopied: setIsCopied2
|
775
|
+
} = s;
|
776
|
+
if (isEditing)
|
777
|
+
return null;
|
778
|
+
return { content: content2, setIsCopied: setIsCopied2 };
|
779
|
+
});
|
780
|
+
if (!context)
|
781
|
+
return null;
|
782
|
+
const { content, setIsCopied } = context;
|
759
783
|
return () => {
|
760
|
-
navigator.clipboard.writeText(
|
784
|
+
navigator.clipboard.writeText(content);
|
761
785
|
setIsCopied(true);
|
762
786
|
setTimeout(() => setIsCopied(false), copiedDuration);
|
763
787
|
};
|
@@ -772,8 +796,13 @@ var useReloadMessage = () => {
|
|
772
796
|
s.chat.isLoading,
|
773
797
|
s.chat.reloadAt
|
774
798
|
]);
|
775
|
-
const message = useMessageContext("ActionBar.Reload", (s) =>
|
776
|
-
|
799
|
+
const message = useMessageContext("ActionBar.Reload", (s) => {
|
800
|
+
const message2 = s.message;
|
801
|
+
if (message2.role !== "assistant" || isLoading)
|
802
|
+
return null;
|
803
|
+
return message2;
|
804
|
+
});
|
805
|
+
if (!message)
|
777
806
|
return null;
|
778
807
|
return () => reloadAt(message);
|
779
808
|
};
|
@@ -783,14 +812,21 @@ var ActionBarReload = createActionButton(useReloadMessage);
|
|
783
812
|
|
784
813
|
// src/actions/useBeginMessageEdit.tsx
|
785
814
|
var useBeginMessageEdit = () => {
|
786
|
-
const
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
815
|
+
const context = useMessageContext("ActionBar.Edit", (s) => {
|
816
|
+
const {
|
817
|
+
message: { content: content2 },
|
818
|
+
editState: { isEditing },
|
819
|
+
setEditState: setEditState2
|
820
|
+
} = s;
|
821
|
+
if (isEditing)
|
822
|
+
return null;
|
823
|
+
return { content: content2, setEditState: setEditState2 };
|
824
|
+
});
|
825
|
+
if (!context)
|
791
826
|
return null;
|
827
|
+
const { content, setEditState } = context;
|
792
828
|
return () => {
|
793
|
-
setEditState({ isEditing: true, value:
|
829
|
+
setEditState({ isEditing: true, value: content });
|
794
830
|
};
|
795
831
|
};
|
796
832
|
|
@@ -811,28 +847,29 @@ import {
|
|
811
847
|
} from "@radix-ui/react-primitive";
|
812
848
|
import { forwardRef as forwardRef11 } from "react";
|
813
849
|
var EditBarRoot = forwardRef11(
|
814
|
-
({
|
815
|
-
return /* @__PURE__ */ React.createElement(
|
850
|
+
({ ...rest }, ref) => {
|
851
|
+
return /* @__PURE__ */ React.createElement(Primitive9.div, { ...rest, ref });
|
816
852
|
}
|
817
853
|
);
|
818
854
|
|
819
855
|
// src/actions/useSaveMessageEdit.tsx
|
820
856
|
var useSaveMessageEdit = () => {
|
821
857
|
const chat = useThreadContext("EditBar.Save", (s) => s.chat);
|
822
|
-
const
|
823
|
-
|
824
|
-
(
|
825
|
-
|
826
|
-
|
858
|
+
const context = useMessageContext("EditBar.Save", (s) => {
|
859
|
+
const { message: message2, editState, setEditState: setEditState2 } = s;
|
860
|
+
if (!editState.isEditing)
|
861
|
+
return null;
|
862
|
+
return { message: message2, content: editState.value, setEditState: setEditState2 };
|
863
|
+
});
|
864
|
+
if (!context)
|
827
865
|
return null;
|
866
|
+
const { message, content, setEditState } = context;
|
828
867
|
return () => {
|
829
|
-
if (!editState.isEditing)
|
830
|
-
return;
|
831
868
|
chat.editAt(message, {
|
832
869
|
...message,
|
833
870
|
id: void 0,
|
834
871
|
// remove id to create a new message
|
835
|
-
content
|
872
|
+
content
|
836
873
|
});
|
837
874
|
setEditState({ isEditing: false });
|
838
875
|
};
|
@@ -843,12 +880,18 @@ var EditBarSave = createActionButton(useSaveMessageEdit);
|
|
843
880
|
|
844
881
|
// src/actions/useCancelMessageEdit.tsx
|
845
882
|
var useCancelMessageEdit = () => {
|
846
|
-
const
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
883
|
+
const context = useMessageContext("EditBar.Cancel", (s) => {
|
884
|
+
const {
|
885
|
+
editState: { isEditing },
|
886
|
+
setEditState: setEditState2
|
887
|
+
} = s;
|
888
|
+
if (!isEditing)
|
889
|
+
return null;
|
890
|
+
return { setEditState: setEditState2 };
|
891
|
+
});
|
892
|
+
if (!context)
|
851
893
|
return null;
|
894
|
+
const { setEditState } = context;
|
852
895
|
return () => {
|
853
896
|
setEditState({ isEditing: false });
|
854
897
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@assistant-ui/react",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.3",
|
4
4
|
"license": "MIT",
|
5
5
|
"exports": {
|
6
6
|
".": {
|
@@ -31,7 +31,7 @@
|
|
31
31
|
"@radix-ui/react-compose-refs": "^1.0.1",
|
32
32
|
"@radix-ui/react-primitive": "^1.0.3",
|
33
33
|
"@radix-ui/react-slot": "^1.0.2",
|
34
|
-
"ai": "^3.1.
|
34
|
+
"ai": "^3.1.8",
|
35
35
|
"react-textarea-autosize": "^8.5.3",
|
36
36
|
"use-sync-external-store": "^1.2.2"
|
37
37
|
},
|