@assistant-ui/react 0.5.15 → 0.5.16
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/index.d.mts +6 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.js +43 -15
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -15
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
@@ -245,6 +245,7 @@ declare class LocalThreadRuntime implements ThreadRuntime {
|
|
245
245
|
cancel: true;
|
246
246
|
copy: true;
|
247
247
|
}>;
|
248
|
+
readonly isDisabled = false;
|
248
249
|
get messages(): ThreadMessage[];
|
249
250
|
get isRunning(): boolean;
|
250
251
|
constructor(configProvider: ModelConfigProvider, adapter: ChatModelAdapter, options?: LocalRuntimeOptions | undefined);
|
@@ -565,6 +566,7 @@ type ExternalStoreMessageConverterAdapter<T> = {
|
|
565
566
|
};
|
566
567
|
type ExternalStoreAdapterBase<T> = {
|
567
568
|
threadId?: string | undefined;
|
569
|
+
isDisabled?: boolean | undefined;
|
568
570
|
isRunning?: boolean | undefined;
|
569
571
|
messages: T[];
|
570
572
|
setMessages?: ((messages: T[]) => void) | undefined;
|
@@ -656,7 +658,8 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
|
|
656
658
|
cancel: boolean;
|
657
659
|
copy: boolean;
|
658
660
|
};
|
659
|
-
messages:
|
661
|
+
messages: any[];
|
662
|
+
isDisabled: boolean;
|
660
663
|
isRunning: boolean;
|
661
664
|
constructor(store: ExternalStoreAdapter<any>);
|
662
665
|
getBranches(messageId: string): string[];
|
@@ -760,6 +763,7 @@ declare function useAssistantContext(options: {
|
|
760
763
|
|
761
764
|
type ThreadState = Readonly<{
|
762
765
|
isRunning: boolean;
|
766
|
+
isDisabled: boolean;
|
763
767
|
}>;
|
764
768
|
|
765
769
|
type ThreadViewportState = Readonly<{
|
@@ -932,6 +936,7 @@ declare const useThreadEmpty: () => boolean;
|
|
932
936
|
type ThreadIfFilters = {
|
933
937
|
empty: boolean | undefined;
|
934
938
|
running: boolean | undefined;
|
939
|
+
disabled: boolean | undefined;
|
935
940
|
};
|
936
941
|
type UseThreadIfProps = RequireAtLeastOne<ThreadIfFilters>;
|
937
942
|
declare const useThreadIf: (props: UseThreadIfProps) => boolean;
|
package/dist/index.d.ts
CHANGED
@@ -245,6 +245,7 @@ declare class LocalThreadRuntime implements ThreadRuntime {
|
|
245
245
|
cancel: true;
|
246
246
|
copy: true;
|
247
247
|
}>;
|
248
|
+
readonly isDisabled = false;
|
248
249
|
get messages(): ThreadMessage[];
|
249
250
|
get isRunning(): boolean;
|
250
251
|
constructor(configProvider: ModelConfigProvider, adapter: ChatModelAdapter, options?: LocalRuntimeOptions | undefined);
|
@@ -565,6 +566,7 @@ type ExternalStoreMessageConverterAdapter<T> = {
|
|
565
566
|
};
|
566
567
|
type ExternalStoreAdapterBase<T> = {
|
567
568
|
threadId?: string | undefined;
|
569
|
+
isDisabled?: boolean | undefined;
|
568
570
|
isRunning?: boolean | undefined;
|
569
571
|
messages: T[];
|
570
572
|
setMessages?: ((messages: T[]) => void) | undefined;
|
@@ -656,7 +658,8 @@ declare class ExternalStoreThreadRuntime implements ReactThreadRuntime {
|
|
656
658
|
cancel: boolean;
|
657
659
|
copy: boolean;
|
658
660
|
};
|
659
|
-
messages:
|
661
|
+
messages: any[];
|
662
|
+
isDisabled: boolean;
|
660
663
|
isRunning: boolean;
|
661
664
|
constructor(store: ExternalStoreAdapter<any>);
|
662
665
|
getBranches(messageId: string): string[];
|
@@ -760,6 +763,7 @@ declare function useAssistantContext(options: {
|
|
760
763
|
|
761
764
|
type ThreadState = Readonly<{
|
762
765
|
isRunning: boolean;
|
766
|
+
isDisabled: boolean;
|
763
767
|
}>;
|
764
768
|
|
765
769
|
type ThreadViewportState = Readonly<{
|
@@ -932,6 +936,7 @@ declare const useThreadEmpty: () => boolean;
|
|
932
936
|
type ThreadIfFilters = {
|
933
937
|
empty: boolean | undefined;
|
934
938
|
running: boolean | undefined;
|
939
|
+
disabled: boolean | undefined;
|
935
940
|
};
|
936
941
|
type UseThreadIfProps = RequireAtLeastOne<ThreadIfFilters>;
|
937
942
|
declare const useThreadIf: (props: UseThreadIfProps) => boolean;
|
package/dist/index.js
CHANGED
@@ -304,6 +304,7 @@ var makeComposerStore = (useThreadMessages, useThreadActions) => {
|
|
304
304
|
var import_zustand4 = require("zustand");
|
305
305
|
var makeThreadStore = (runtimeRef) => {
|
306
306
|
return (0, import_zustand4.create)(() => ({
|
307
|
+
isDisabled: runtimeRef.getState().isDisabled,
|
307
308
|
isRunning: runtimeRef.getState().isRunning
|
308
309
|
}));
|
309
310
|
};
|
@@ -402,10 +403,12 @@ var ThreadProvider = ({
|
|
402
403
|
(0, import_react4.useCallback)(
|
403
404
|
(thread) => {
|
404
405
|
const onThreadUpdate = () => {
|
405
|
-
|
406
|
+
const threadState = context.useThread.getState();
|
407
|
+
if (thread.isRunning !== threadState.isRunning || thread.isDisabled !== threadState.isDisabled) {
|
406
408
|
context.useThread.setState(
|
407
409
|
Object.freeze({
|
408
|
-
isRunning: thread.isRunning
|
410
|
+
isRunning: thread.isRunning,
|
411
|
+
isDisabled: thread.isDisabled
|
409
412
|
}),
|
410
413
|
true
|
411
414
|
);
|
@@ -716,7 +719,7 @@ var useActionBarReload = () => {
|
|
716
719
|
const { useMessage } = useMessageContext();
|
717
720
|
const disabled = useCombinedStore(
|
718
721
|
[useThread, useMessage],
|
719
|
-
(t, m) => t.isRunning || m.message.role !== "assistant"
|
722
|
+
(t, m) => t.isRunning || t.isDisabled || m.message.role !== "assistant"
|
720
723
|
);
|
721
724
|
const callback = (0, import_react19.useCallback)(() => {
|
722
725
|
const { parentId } = useMessage.getState();
|
@@ -802,9 +805,16 @@ var useComposerIf = (props) => {
|
|
802
805
|
// src/primitive-hooks/composer/useComposerSend.tsx
|
803
806
|
var import_react23 = require("react");
|
804
807
|
var useComposerSend = () => {
|
805
|
-
const {
|
808
|
+
const {
|
809
|
+
useThread,
|
810
|
+
useViewport,
|
811
|
+
useComposer: useNewComposer
|
812
|
+
} = useThreadContext();
|
806
813
|
const { useComposer } = useComposerContext();
|
807
|
-
const disabled =
|
814
|
+
const disabled = useCombinedStore(
|
815
|
+
[useThread, useComposer],
|
816
|
+
(t, c) => t.isDisabled || t.isRunning || !c.isEditing || c.value.length === 0
|
817
|
+
);
|
808
818
|
const callback = (0, import_react23.useCallback)(() => {
|
809
819
|
const composerState = useComposer.getState();
|
810
820
|
if (!composerState.isEditing) return;
|
@@ -883,6 +893,8 @@ var useThreadIf = (props) => {
|
|
883
893
|
if (props.empty === false && messages.length === 0) return false;
|
884
894
|
if (props.running === true && !thread.isRunning) return false;
|
885
895
|
if (props.running === false && thread.isRunning) return false;
|
896
|
+
if (props.disabled === true && thread.isDisabled) return false;
|
897
|
+
if (props.disabled === false && thread.isDisabled) return false;
|
886
898
|
return true;
|
887
899
|
}
|
888
900
|
);
|
@@ -914,7 +926,7 @@ var useThreadSuggestion = ({
|
|
914
926
|
}) => {
|
915
927
|
const { useThread, useComposer } = useThreadContext();
|
916
928
|
const append = useAppendMessage();
|
917
|
-
const disabled = useThread((t) => t.
|
929
|
+
const disabled = useThread((t) => t.isDisabled);
|
918
930
|
const callback = (0, import_react25.useCallback)(() => {
|
919
931
|
const thread = useThread.getState();
|
920
932
|
const composer = useComposer.getState();
|
@@ -1597,7 +1609,14 @@ var import_react_textarea_autosize = __toESM(require("react-textarea-autosize"))
|
|
1597
1609
|
var import_react_use_escape_keydown = require("@radix-ui/react-use-escape-keydown");
|
1598
1610
|
var import_jsx_runtime19 = require("react/jsx-runtime");
|
1599
1611
|
var ComposerPrimitiveInput = (0, import_react41.forwardRef)(
|
1600
|
-
({
|
1612
|
+
({
|
1613
|
+
autoFocus = false,
|
1614
|
+
asChild,
|
1615
|
+
disabled: disabledProp,
|
1616
|
+
onChange,
|
1617
|
+
onKeyDown,
|
1618
|
+
...rest
|
1619
|
+
}, forwardedRef) => {
|
1601
1620
|
const { useThread } = useThreadContext();
|
1602
1621
|
const { useComposer, type } = useComposerContext();
|
1603
1622
|
const value = useComposer((c) => {
|
@@ -1605,6 +1624,7 @@ var ComposerPrimitiveInput = (0, import_react41.forwardRef)(
|
|
1605
1624
|
return c.value;
|
1606
1625
|
});
|
1607
1626
|
const Component = asChild ? import_react_slot.Slot : import_react_textarea_autosize.default;
|
1627
|
+
const isDisabled = useThread((t) => t.isDisabled) ?? disabledProp ?? false;
|
1608
1628
|
const textareaRef = (0, import_react41.useRef)(null);
|
1609
1629
|
const ref = (0, import_react_compose_refs2.useComposedRefs)(forwardedRef, textareaRef);
|
1610
1630
|
(0, import_react_use_escape_keydown.useEscapeKeydown)((e) => {
|
@@ -1615,7 +1635,7 @@ var ComposerPrimitiveInput = (0, import_react41.forwardRef)(
|
|
1615
1635
|
}
|
1616
1636
|
});
|
1617
1637
|
const handleKeyPress = (e) => {
|
1618
|
-
if (
|
1638
|
+
if (isDisabled) return;
|
1619
1639
|
if (e.key === "Enter" && e.shiftKey === false) {
|
1620
1640
|
const isRunning = useThread.getState().isRunning;
|
1621
1641
|
if (!isRunning) {
|
@@ -1624,7 +1644,7 @@ var ComposerPrimitiveInput = (0, import_react41.forwardRef)(
|
|
1624
1644
|
}
|
1625
1645
|
}
|
1626
1646
|
};
|
1627
|
-
const autoFocusEnabled = autoFocus && !
|
1647
|
+
const autoFocusEnabled = autoFocus && !isDisabled;
|
1628
1648
|
const focus = (0, import_react41.useCallback)(() => {
|
1629
1649
|
const textarea = textareaRef.current;
|
1630
1650
|
if (!textarea || !autoFocusEnabled) return;
|
@@ -1647,7 +1667,7 @@ var ComposerPrimitiveInput = (0, import_react41.forwardRef)(
|
|
1647
1667
|
value,
|
1648
1668
|
...rest,
|
1649
1669
|
ref,
|
1650
|
-
disabled,
|
1670
|
+
disabled: isDisabled,
|
1651
1671
|
onChange: (0, import_primitive5.composeEventHandlers)(onChange, (e) => {
|
1652
1672
|
const composerState = useComposer.getState();
|
1653
1673
|
if (!composerState.isEditing) return;
|
@@ -3475,6 +3495,7 @@ var LocalThreadRuntime = class {
|
|
3475
3495
|
abortController = null;
|
3476
3496
|
repository = new MessageRepository();
|
3477
3497
|
capabilities = CAPABILITIES;
|
3498
|
+
isDisabled = false;
|
3478
3499
|
get messages() {
|
3479
3500
|
return this.repository.getMessages();
|
3480
3501
|
}
|
@@ -3785,6 +3806,7 @@ var useExternalStoreSync = (adapter, updateData) => {
|
|
3785
3806
|
}, [adapter.convertMessage]);
|
3786
3807
|
(0, import_react55.useEffect)(() => {
|
3787
3808
|
updateData(
|
3809
|
+
adapter.isDisabled ?? false,
|
3788
3810
|
adapter.isRunning ?? false,
|
3789
3811
|
converter.convertMessages(adapter.messages, convertCallback)
|
3790
3812
|
);
|
@@ -3792,8 +3814,9 @@ var useExternalStoreSync = (adapter, updateData) => {
|
|
3792
3814
|
updateData,
|
3793
3815
|
converter,
|
3794
3816
|
convertCallback,
|
3795
|
-
adapter.
|
3796
|
-
adapter.isRunning
|
3817
|
+
adapter.isDisabled,
|
3818
|
+
adapter.isRunning,
|
3819
|
+
adapter.messages
|
3797
3820
|
]);
|
3798
3821
|
};
|
3799
3822
|
|
@@ -3804,6 +3827,9 @@ var hasUpcomingMessage = (isRunning, messages) => {
|
|
3804
3827
|
var ExternalStoreThreadRuntime = class {
|
3805
3828
|
constructor(store) {
|
3806
3829
|
this.store = store;
|
3830
|
+
this.isDisabled = store.isDisabled ?? false;
|
3831
|
+
this.isRunning = store.isRunning ?? false;
|
3832
|
+
this.messages = store.messages;
|
3807
3833
|
this.useStore = (0, import_zustand14.create)(() => ({
|
3808
3834
|
store
|
3809
3835
|
}));
|
@@ -3821,8 +3847,9 @@ var ExternalStoreThreadRuntime = class {
|
|
3821
3847
|
copy: this.store.onCopy !== null
|
3822
3848
|
};
|
3823
3849
|
}
|
3824
|
-
messages
|
3825
|
-
|
3850
|
+
messages;
|
3851
|
+
isDisabled;
|
3852
|
+
isRunning;
|
3826
3853
|
getBranches(messageId) {
|
3827
3854
|
return this.repository.getBranches(messageId);
|
3828
3855
|
}
|
@@ -3873,7 +3900,7 @@ var ExternalStoreThreadRuntime = class {
|
|
3873
3900
|
this.useStore.setState({ store: this.store });
|
3874
3901
|
}
|
3875
3902
|
}
|
3876
|
-
updateData = (isRunning, vm) => {
|
3903
|
+
updateData = (isDisabled, isRunning, vm) => {
|
3877
3904
|
for (let i = 0; i < vm.length; i++) {
|
3878
3905
|
const message = vm[i];
|
3879
3906
|
const parent = vm[i - 1];
|
@@ -3896,6 +3923,7 @@ var ExternalStoreThreadRuntime = class {
|
|
3896
3923
|
this.assistantOptimisticId ?? vm.at(-1)?.id ?? null
|
3897
3924
|
);
|
3898
3925
|
this.messages = this.repository.getMessages();
|
3926
|
+
this.isDisabled = isDisabled;
|
3899
3927
|
this.isRunning = isRunning;
|
3900
3928
|
for (const callback of this._subscriptions) callback();
|
3901
3929
|
};
|