@assistant-ui/react 0.7.46 → 0.7.47
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/api/AssistantRuntime.d.ts +1 -0
- package/dist/api/AssistantRuntime.d.ts.map +1 -1
- package/dist/api/AssistantRuntime.js +5 -0
- package/dist/api/AssistantRuntime.js.map +1 -1
- package/dist/api/AssistantRuntime.mjs +5 -0
- package/dist/api/AssistantRuntime.mjs.map +1 -1
- package/dist/api/AttachmentRuntime.d.ts +1 -0
- package/dist/api/AttachmentRuntime.d.ts.map +1 -1
- package/dist/api/AttachmentRuntime.js +5 -0
- package/dist/api/AttachmentRuntime.js.map +1 -1
- package/dist/api/AttachmentRuntime.mjs +5 -0
- package/dist/api/AttachmentRuntime.mjs.map +1 -1
- package/dist/api/ComposerRuntime.d.ts +2 -0
- package/dist/api/ComposerRuntime.d.ts.map +1 -1
- package/dist/api/ComposerRuntime.js +19 -0
- package/dist/api/ComposerRuntime.js.map +1 -1
- package/dist/api/ComposerRuntime.mjs +19 -0
- package/dist/api/ComposerRuntime.mjs.map +1 -1
- package/dist/api/ContentPartRuntime.d.ts +1 -0
- package/dist/api/ContentPartRuntime.d.ts.map +1 -1
- package/dist/api/ContentPartRuntime.js +5 -0
- package/dist/api/ContentPartRuntime.js.map +1 -1
- package/dist/api/ContentPartRuntime.mjs +5 -0
- package/dist/api/ContentPartRuntime.mjs.map +1 -1
- package/dist/api/MessageRuntime.d.ts +1 -0
- package/dist/api/MessageRuntime.d.ts.map +1 -1
- package/dist/api/MessageRuntime.js +13 -0
- package/dist/api/MessageRuntime.js.map +1 -1
- package/dist/api/MessageRuntime.mjs +13 -0
- package/dist/api/MessageRuntime.mjs.map +1 -1
- package/dist/api/ThreadListItemRuntime.d.ts +1 -0
- package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListItemRuntime.js +11 -0
- package/dist/api/ThreadListItemRuntime.js.map +1 -1
- package/dist/api/ThreadListItemRuntime.mjs +11 -0
- package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
- package/dist/api/ThreadListRuntime.d.ts +1 -0
- package/dist/api/ThreadListRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListRuntime.js +10 -0
- package/dist/api/ThreadListRuntime.js.map +1 -1
- package/dist/api/ThreadListRuntime.mjs +10 -0
- package/dist/api/ThreadListRuntime.mjs.map +1 -1
- package/dist/api/ThreadRuntime.d.ts +1 -1
- package/dist/api/ThreadRuntime.d.ts.map +1 -1
- package/dist/api/ThreadRuntime.js +14 -3
- package/dist/api/ThreadRuntime.js.map +1 -1
- package/dist/api/ThreadRuntime.mjs +14 -3
- package/dist/api/ThreadRuntime.mjs.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.js +5 -14
- package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.mjs +5 -14
- package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
- package/dist/context/providers/AttachmentRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/AttachmentRuntimeProvider.js +5 -16
- package/dist/context/providers/AttachmentRuntimeProvider.js.map +1 -1
- package/dist/context/providers/AttachmentRuntimeProvider.mjs +6 -21
- package/dist/context/providers/AttachmentRuntimeProvider.mjs.map +1 -1
- package/dist/context/providers/ContentPartRuntimeProvider.d.ts +0 -1
- package/dist/context/providers/ContentPartRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/ContentPartRuntimeProvider.js +5 -15
- package/dist/context/providers/ContentPartRuntimeProvider.js.map +1 -1
- package/dist/context/providers/ContentPartRuntimeProvider.mjs +4 -13
- package/dist/context/providers/ContentPartRuntimeProvider.mjs.map +1 -1
- package/dist/context/providers/MessageRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/MessageRuntimeProvider.js +3 -22
- package/dist/context/providers/MessageRuntimeProvider.js.map +1 -1
- package/dist/context/providers/MessageRuntimeProvider.mjs +3 -22
- package/dist/context/providers/MessageRuntimeProvider.mjs.map +1 -1
- package/dist/context/providers/TextContentPartProvider.d.ts.map +1 -1
- package/dist/context/providers/TextContentPartProvider.js +13 -12
- package/dist/context/providers/TextContentPartProvider.js.map +1 -1
- package/dist/context/providers/TextContentPartProvider.mjs +13 -12
- package/dist/context/providers/TextContentPartProvider.mjs.map +1 -1
- package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts +0 -1
- package/dist/context/providers/ThreadListItemRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/ThreadListItemRuntimeProvider.js +5 -15
- package/dist/context/providers/ThreadListItemRuntimeProvider.js.map +1 -1
- package/dist/context/providers/ThreadListItemRuntimeProvider.mjs +4 -13
- package/dist/context/providers/ThreadListItemRuntimeProvider.mjs.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.js +5 -24
- package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.mjs +6 -25
- package/dist/context/providers/ThreadRuntimeProvider.mjs.map +1 -1
- package/dist/context/react/AssistantContext.d.ts +26 -17
- package/dist/context/react/AssistantContext.d.ts.map +1 -1
- package/dist/context/react/AssistantContext.js +3 -4
- package/dist/context/react/AssistantContext.js.map +1 -1
- package/dist/context/react/AssistantContext.mjs +3 -4
- package/dist/context/react/AssistantContext.mjs.map +1 -1
- package/dist/context/react/AttachmentContext.d.ts +558 -30
- package/dist/context/react/AttachmentContext.d.ts.map +1 -1
- package/dist/context/react/AttachmentContext.js +32 -52
- package/dist/context/react/AttachmentContext.js.map +1 -1
- package/dist/context/react/AttachmentContext.mjs +33 -52
- package/dist/context/react/AttachmentContext.mjs.map +1 -1
- package/dist/context/react/ComposerContext.d.ts +28 -19
- package/dist/context/react/ComposerContext.d.ts.map +1 -1
- package/dist/context/react/ComposerContext.js +2 -19
- package/dist/context/react/ComposerContext.js.map +1 -1
- package/dist/context/react/ComposerContext.mjs +4 -20
- package/dist/context/react/ComposerContext.mjs.map +1 -1
- package/dist/context/react/ContentPartContext.d.ts +22 -16
- package/dist/context/react/ContentPartContext.d.ts.map +1 -1
- package/dist/context/react/ContentPartContext.js +2 -7
- package/dist/context/react/ContentPartContext.js.map +1 -1
- package/dist/context/react/ContentPartContext.mjs +2 -6
- package/dist/context/react/ContentPartContext.mjs.map +1 -1
- package/dist/context/react/MessageContext.d.ts +49 -29
- package/dist/context/react/MessageContext.d.ts.map +1 -1
- package/dist/context/react/MessageContext.js +5 -9
- package/dist/context/react/MessageContext.js.map +1 -1
- package/dist/context/react/MessageContext.mjs +5 -8
- package/dist/context/react/MessageContext.mjs.map +1 -1
- package/dist/context/react/ThreadContext.d.ts +44 -24
- package/dist/context/react/ThreadContext.d.ts.map +1 -1
- package/dist/context/react/ThreadContext.js +5 -9
- package/dist/context/react/ThreadContext.js.map +1 -1
- package/dist/context/react/ThreadContext.mjs +5 -8
- package/dist/context/react/ThreadContext.mjs.map +1 -1
- package/dist/context/react/ThreadListItemContext.d.ts +22 -16
- package/dist/context/react/ThreadListItemContext.d.ts.map +1 -1
- package/dist/context/react/ThreadListItemContext.js +3 -6
- package/dist/context/react/ThreadListItemContext.js.map +1 -1
- package/dist/context/react/ThreadListItemContext.mjs +3 -5
- package/dist/context/react/ThreadListItemContext.mjs.map +1 -1
- package/dist/context/react/index.d.ts +1 -0
- package/dist/context/react/index.d.ts.map +1 -1
- package/dist/context/react/index.js +3 -0
- package/dist/context/react/index.js.map +1 -1
- package/dist/context/react/index.mjs +2 -0
- package/dist/context/react/index.mjs.map +1 -1
- package/dist/context/react/utils/createContextHook.d.ts +3 -8
- package/dist/context/react/utils/createContextHook.d.ts.map +1 -1
- package/dist/context/react/utils/createContextHook.js.map +1 -1
- package/dist/context/react/utils/createContextHook.mjs.map +1 -1
- package/dist/context/react/utils/createStateHookForRuntime.d.ts +31 -0
- package/dist/context/react/utils/createStateHookForRuntime.d.ts.map +1 -0
- package/dist/context/react/utils/createStateHookForRuntime.js +47 -0
- package/dist/context/react/utils/createStateHookForRuntime.js.map +1 -0
- package/dist/context/react/utils/createStateHookForRuntime.mjs +24 -0
- package/dist/context/react/utils/createStateHookForRuntime.mjs.map +1 -0
- package/dist/context/react/utils/ensureBinding.d.ts +2 -0
- package/dist/context/react/utils/ensureBinding.d.ts.map +1 -0
- package/dist/context/react/utils/ensureBinding.js +36 -0
- package/dist/context/react/utils/ensureBinding.js.map +1 -0
- package/dist/context/react/utils/ensureBinding.mjs +11 -0
- package/dist/context/react/utils/ensureBinding.mjs.map +1 -0
- package/dist/context/react/utils/useRuntimeState.d.ts +10 -0
- package/dist/context/react/utils/useRuntimeState.d.ts.map +1 -0
- package/dist/context/react/utils/useRuntimeState.js +48 -0
- package/dist/context/react/utils/useRuntimeState.js.map +1 -0
- package/dist/context/react/utils/useRuntimeState.mjs +22 -0
- package/dist/context/react/utils/useRuntimeState.mjs.map +1 -0
- package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts +1 -1
- package/dist/runtimes/adapters/attachment/AttachmentAdapter.d.ts.map +1 -1
- package/dist/runtimes/adapters/attachment/AttachmentAdapter.js.map +1 -1
- package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.d.ts +1 -1
- package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.d.ts.map +1 -1
- package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.js +1 -1
- package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.js.map +1 -1
- package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.mjs +1 -1
- package/dist/runtimes/adapters/attachment/CompositeAttachmentAdapter.mjs.map +1 -1
- package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.d.ts.map +1 -1
- package/dist/runtimes/adapters/thread-history/ThreadHistoryAdapter.js.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js +22 -2
- package/dist/runtimes/composer/BaseComposerRuntimeCore.js.map +1 -1
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs +22 -2
- package/dist/runtimes/composer/BaseComposerRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.js +4 -0
- package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs +4 -0
- package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
- package/package.json +3 -3
- package/src/api/AssistantRuntime.ts +7 -0
- package/src/api/AttachmentRuntime.ts +6 -0
- package/src/api/ComposerRuntime.ts +21 -0
- package/src/api/ContentPartRuntime.ts +6 -0
- package/src/api/MessageRuntime.ts +15 -0
- package/src/api/ThreadListItemRuntime.ts +12 -0
- package/src/api/ThreadListRuntime.ts +11 -0
- package/src/api/ThreadRuntime.ts +15 -4
- package/src/context/providers/AssistantRuntimeProvider.tsx +5 -17
- package/src/context/providers/AttachmentRuntimeProvider.tsx +6 -24
- package/src/context/providers/ContentPartRuntimeProvider.tsx +4 -14
- package/src/context/providers/MessageRuntimeProvider.tsx +5 -31
- package/src/context/providers/TextContentPartProvider.tsx +26 -22
- package/src/context/providers/ThreadListItemRuntimeProvider.tsx +3 -14
- package/src/context/providers/ThreadRuntimeProvider.tsx +7 -33
- package/src/context/react/AssistantContext.ts +7 -7
- package/src/context/react/AttachmentContext.ts +45 -136
- package/src/context/react/ComposerContext.ts +6 -29
- package/src/context/react/ContentPartContext.ts +3 -8
- package/src/context/react/MessageContext.ts +10 -13
- package/src/context/react/ThreadContext.ts +9 -12
- package/src/context/react/ThreadListItemContext.ts +4 -7
- package/src/context/react/index.ts +2 -0
- package/src/context/react/utils/createContextHook.ts +1 -3
- package/src/context/react/utils/createStateHookForRuntime.ts +80 -0
- package/src/context/react/utils/ensureBinding.ts +45 -0
- package/src/context/react/utils/useRuntimeState.ts +43 -0
- package/src/runtimes/adapters/attachment/AttachmentAdapter.ts +3 -1
- package/src/runtimes/adapters/attachment/CompositeAttachmentAdapter.ts +1 -1
- package/src/runtimes/adapters/thread-history/ThreadHistoryAdapter.ts +1 -0
- package/src/runtimes/composer/BaseComposerRuntimeCore.tsx +24 -2
- package/src/runtimes/local/useLocalRuntime.tsx +5 -0
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { FC, PropsWithChildren, useEffect, useState } from "react";
|
|
4
|
-
import { create } from "zustand";
|
|
4
|
+
import { create, StoreApi, UseBoundStore } from "zustand";
|
|
5
5
|
import {
|
|
6
6
|
ContentPartContext,
|
|
7
7
|
ContentPartContextValue,
|
|
8
8
|
} from "../react/ContentPartContext";
|
|
9
|
-
import { ContentPartStatus
|
|
9
|
+
import { ContentPartStatus } from "../../types/AssistantTypes";
|
|
10
10
|
import { writableStore } from "../ReadonlyStore";
|
|
11
11
|
import {
|
|
12
12
|
ContentPartRuntimeImpl,
|
|
13
13
|
ContentPartState,
|
|
14
14
|
} from "../../api/ContentPartRuntime";
|
|
15
|
+
import { ensureBinding } from "../react/utils/ensureBinding";
|
|
15
16
|
|
|
16
17
|
export namespace TextContentPartProvider {
|
|
17
18
|
export type Props = PropsWithChildren<{
|
|
@@ -33,36 +34,39 @@ export const TextContentPartProvider: FC<TextContentPartProvider.Props> = ({
|
|
|
33
34
|
text,
|
|
34
35
|
isRunning,
|
|
35
36
|
}) => {
|
|
36
|
-
const [context] = useState<
|
|
37
|
-
|
|
37
|
+
const [context] = useState<
|
|
38
|
+
ContentPartContextValue & {
|
|
39
|
+
useContentPart: UseBoundStore<
|
|
40
|
+
StoreApi<ContentPartState & { type: "text" }>
|
|
41
|
+
>;
|
|
42
|
+
}
|
|
43
|
+
>(() => {
|
|
44
|
+
const useContentPart = create<ContentPartState & { type: "text" }>(() => ({
|
|
38
45
|
status: isRunning ? RUNNING_STATUS : COMPLETE_STATUS,
|
|
39
46
|
type: "text",
|
|
40
47
|
text,
|
|
41
48
|
}));
|
|
42
49
|
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
50
|
+
const contentPartRuntime = new ContentPartRuntimeImpl({
|
|
51
|
+
path: {
|
|
52
|
+
ref: "text",
|
|
53
|
+
threadSelector: { type: "main" },
|
|
54
|
+
messageSelector: { type: "messageId", messageId: "" },
|
|
55
|
+
contentPartSelector: { type: "index", index: 0 },
|
|
56
|
+
},
|
|
57
|
+
getState: useContentPart.getState,
|
|
58
|
+
subscribe: useContentPart.subscribe,
|
|
59
|
+
});
|
|
60
|
+
ensureBinding(contentPartRuntime);
|
|
61
|
+
|
|
62
|
+
const useContentPartRuntime = create(() => contentPartRuntime);
|
|
56
63
|
|
|
57
64
|
return { useContentPartRuntime, useContentPart };
|
|
58
65
|
});
|
|
59
66
|
|
|
60
67
|
useEffect(() => {
|
|
61
|
-
const state = context.useContentPart.getState()
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const textUpdated = (state as TextContentPart).text !== text;
|
|
68
|
+
const state = context.useContentPart.getState();
|
|
69
|
+
const textUpdated = state.text !== text;
|
|
66
70
|
const targetStatus = isRunning ? RUNNING_STATUS : COMPLETE_STATUS;
|
|
67
71
|
const statusUpdated = state.status !== targetStatus;
|
|
68
72
|
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
} from "../react/ThreadListItemContext";
|
|
9
9
|
import { writableStore } from "../ReadonlyStore";
|
|
10
10
|
import { ThreadListItemRuntime } from "../../api/ThreadListItemRuntime";
|
|
11
|
+
import { ensureBinding } from "../react/utils/ensureBinding";
|
|
11
12
|
|
|
12
13
|
export namespace ThreadListItemRuntimeProvider {
|
|
13
14
|
export type Props = PropsWithChildren<{
|
|
@@ -19,31 +20,19 @@ const useThreadListItemRuntimeStore = (runtime: ThreadListItemRuntime) => {
|
|
|
19
20
|
const [store] = useState(() => create(() => runtime));
|
|
20
21
|
|
|
21
22
|
useEffect(() => {
|
|
23
|
+
ensureBinding(runtime);
|
|
22
24
|
writableStore(store).setState(runtime, true);
|
|
23
25
|
}, [runtime, store]);
|
|
24
26
|
|
|
25
27
|
return store;
|
|
26
28
|
};
|
|
27
29
|
|
|
28
|
-
export const useThreadListItemStore = (runtime: ThreadListItemRuntime) => {
|
|
29
|
-
const [store] = useState(() => create(() => runtime.getState()));
|
|
30
|
-
useEffect(() => {
|
|
31
|
-
const updateState = () =>
|
|
32
|
-
writableStore(store).setState(runtime.getState(), true);
|
|
33
|
-
updateState();
|
|
34
|
-
return runtime.subscribe(updateState);
|
|
35
|
-
}, [runtime, store]);
|
|
36
|
-
|
|
37
|
-
return store;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
30
|
export const ThreadListItemRuntimeProvider: FC<
|
|
41
31
|
ThreadListItemRuntimeProvider.Props
|
|
42
32
|
> = ({ runtime, children }) => {
|
|
43
33
|
const useThreadListItemRuntime = useThreadListItemRuntimeStore(runtime);
|
|
44
|
-
const useThreadListItem = useThreadListItemStore(runtime);
|
|
45
34
|
const [context] = useState<ThreadListItemContextValue>(() => {
|
|
46
|
-
return { useThreadListItemRuntime
|
|
35
|
+
return { useThreadListItemRuntime };
|
|
47
36
|
});
|
|
48
37
|
|
|
49
38
|
return (
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import type { FC, PropsWithChildren } from "react";
|
|
4
|
-
import { useEffect,
|
|
4
|
+
import { useEffect, useState } from "react";
|
|
5
5
|
import type { ThreadContextValue } from "../react/ThreadContext";
|
|
6
6
|
import { ThreadContext } from "../react/ThreadContext";
|
|
7
7
|
import { makeThreadViewportStore } from "../stores/ThreadViewport";
|
|
8
8
|
import { writableStore } from "../ReadonlyStore";
|
|
9
9
|
import { ThreadRuntime } from "../../api/ThreadRuntime";
|
|
10
10
|
import { create } from "zustand";
|
|
11
|
-
import { ThreadComposerRuntime } from "../../api/ComposerRuntime";
|
|
12
11
|
import { ThreadListItemRuntime } from "../../api/ThreadListItemRuntime";
|
|
13
12
|
import { ThreadListItemRuntimeProvider } from "./ThreadListItemRuntimeProvider";
|
|
13
|
+
import { ensureBinding } from "../react/utils/ensureBinding";
|
|
14
14
|
|
|
15
15
|
type ThreadProviderProps = {
|
|
16
16
|
listItemRuntime: ThreadListItemRuntime;
|
|
@@ -21,32 +21,10 @@ const useThreadRuntimeStore = (runtime: ThreadRuntime) => {
|
|
|
21
21
|
const [store] = useState(() => create(() => runtime));
|
|
22
22
|
|
|
23
23
|
useEffect(() => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return store;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
const useThreadStore = (runtime: ThreadRuntime) => {
|
|
31
|
-
const [store] = useState(() => create(() => runtime.getState()));
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
const updateState = () =>
|
|
34
|
-
writableStore(store).setState(runtime.getState(), true);
|
|
35
|
-
updateState();
|
|
36
|
-
return runtime.subscribe(updateState);
|
|
37
|
-
}, [runtime, store]);
|
|
38
|
-
|
|
39
|
-
return store;
|
|
40
|
-
};
|
|
24
|
+
ensureBinding(runtime);
|
|
25
|
+
ensureBinding(runtime.composer);
|
|
41
26
|
|
|
42
|
-
|
|
43
|
-
const [store] = useState(() => create(() => runtime.getState()));
|
|
44
|
-
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
const updateState = () =>
|
|
47
|
-
writableStore(store).setState(runtime.getState(), true);
|
|
48
|
-
updateState();
|
|
49
|
-
return runtime.subscribe(updateState);
|
|
27
|
+
writableStore(store).setState(runtime, true);
|
|
50
28
|
}, [runtime, store]);
|
|
51
29
|
|
|
52
30
|
return store;
|
|
@@ -56,19 +34,15 @@ export const ThreadRuntimeProvider: FC<
|
|
|
56
34
|
PropsWithChildren<ThreadProviderProps>
|
|
57
35
|
> = ({ children, listItemRuntime: threadListItemRuntime, runtime }) => {
|
|
58
36
|
const useThreadRuntime = useThreadRuntimeStore(runtime);
|
|
59
|
-
const useThread = useThreadStore(runtime);
|
|
60
|
-
const useThreadComposer = useThreadComposerStore(runtime.composer);
|
|
61
37
|
|
|
62
|
-
const context =
|
|
38
|
+
const [context] = useState<ThreadContextValue>(() => {
|
|
63
39
|
const useViewport = makeThreadViewportStore();
|
|
64
40
|
|
|
65
41
|
return {
|
|
66
|
-
useThread,
|
|
67
42
|
useThreadRuntime,
|
|
68
|
-
useComposer: useThreadComposer,
|
|
69
43
|
useViewport,
|
|
70
44
|
};
|
|
71
|
-
}
|
|
45
|
+
});
|
|
72
46
|
|
|
73
47
|
return (
|
|
74
48
|
<ThreadListItemRuntimeProvider runtime={threadListItemRuntime}>
|
|
@@ -7,12 +7,12 @@ import { createContextHook } from "./utils/createContextHook";
|
|
|
7
7
|
import { createContextStoreHook } from "./utils/createContextStoreHook";
|
|
8
8
|
import { UseBoundStore } from "zustand";
|
|
9
9
|
import { AssistantRuntime } from "../../api/AssistantRuntime";
|
|
10
|
-
import {
|
|
10
|
+
import { ThreadListRuntime } from "../../api/ThreadListRuntime";
|
|
11
|
+
import { createStateHookForRuntime } from "./utils/createStateHookForRuntime";
|
|
11
12
|
|
|
12
13
|
export type AssistantContextValue = {
|
|
13
|
-
useToolUIs: UseBoundStore<ReadonlyStore<AssistantToolUIsState>>;
|
|
14
14
|
useAssistantRuntime: UseBoundStore<ReadonlyStore<AssistantRuntime>>;
|
|
15
|
-
|
|
15
|
+
useToolUIs: UseBoundStore<ReadonlyStore<AssistantToolUIsState>>;
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
export const AssistantContext = createContext<AssistantContextValue | null>(
|
|
@@ -43,7 +43,7 @@ export const { useToolUIs, useToolUIsStore } = createContextStoreHook(
|
|
|
43
43
|
"useToolUIs",
|
|
44
44
|
);
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
);
|
|
46
|
+
const useThreadListRuntime = (opt: {
|
|
47
|
+
optional: boolean | undefined;
|
|
48
|
+
}): ThreadListRuntime | null => useAssistantRuntime(opt)?.threads ?? null;
|
|
49
|
+
export const useThreadList = createStateHookForRuntime(useThreadListRuntime);
|
|
@@ -1,124 +1,24 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { createContext
|
|
3
|
+
import { createContext } from "react";
|
|
4
4
|
import { ReadonlyStore } from "../ReadonlyStore";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
AttachmentRuntime,
|
|
8
|
-
AttachmentState,
|
|
9
|
-
} from "../../api/AttachmentRuntime";
|
|
5
|
+
import { AttachmentRuntime } from "../../api/AttachmentRuntime";
|
|
10
6
|
import { UseBoundStore } from "zustand";
|
|
7
|
+
import { createContextHook } from "./utils/createContextHook";
|
|
8
|
+
import { createStateHookForRuntime } from "./utils/createStateHookForRuntime";
|
|
11
9
|
|
|
12
10
|
export type AttachmentContextValue = {
|
|
13
|
-
source: "thread-composer" | "edit-composer" | "message";
|
|
14
|
-
useAttachment: UseBoundStore<ReadonlyStore<AttachmentState>>;
|
|
15
11
|
useAttachmentRuntime: UseBoundStore<ReadonlyStore<AttachmentRuntime>>;
|
|
16
12
|
};
|
|
17
13
|
|
|
18
|
-
type ThreadComposerAttachmentContextValue = {
|
|
19
|
-
source: "thread-composer";
|
|
20
|
-
useAttachment: UseBoundStore<
|
|
21
|
-
ReadonlyStore<AttachmentState & { source: "thread-composer" }>
|
|
22
|
-
>;
|
|
23
|
-
useAttachmentRuntime: UseBoundStore<
|
|
24
|
-
ReadonlyStore<AttachmentRuntime & { type: "thread-composer" }>
|
|
25
|
-
>;
|
|
26
|
-
};
|
|
27
|
-
type EditComposerAttachmentContextValue = {
|
|
28
|
-
source: "edit-composer";
|
|
29
|
-
useAttachment: UseBoundStore<
|
|
30
|
-
ReadonlyStore<AttachmentState & { source: "edit-composer" }>
|
|
31
|
-
>;
|
|
32
|
-
useAttachmentRuntime: UseBoundStore<
|
|
33
|
-
ReadonlyStore<AttachmentRuntime & { type: "edit-composer" }>
|
|
34
|
-
>;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
type MessageAttachmentContextValue = {
|
|
38
|
-
source: "message";
|
|
39
|
-
useAttachment: UseBoundStore<
|
|
40
|
-
ReadonlyStore<AttachmentState & { source: "message" }>
|
|
41
|
-
>;
|
|
42
|
-
useAttachmentRuntime: UseBoundStore<
|
|
43
|
-
ReadonlyStore<AttachmentRuntime & { type: "message" }>
|
|
44
|
-
>;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
14
|
export const AttachmentContext = createContext<AttachmentContextValue | null>(
|
|
48
15
|
null,
|
|
49
16
|
);
|
|
50
17
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
optional?: boolean | undefined;
|
|
56
|
-
}): AttachmentContextValue | null;
|
|
57
|
-
export function useAttachmentContext(options?: {
|
|
58
|
-
optional?: boolean | undefined;
|
|
59
|
-
}) {
|
|
60
|
-
const context = useContext(AttachmentContext);
|
|
61
|
-
if (!options?.optional && !context)
|
|
62
|
-
throw new Error(
|
|
63
|
-
"This component must be used within a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component.",
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return context;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function useThreadComposerAttachmentContext(options?: {
|
|
70
|
-
optional?: false | undefined;
|
|
71
|
-
}): ThreadComposerAttachmentContextValue;
|
|
72
|
-
function useThreadComposerAttachmentContext(options?: {
|
|
73
|
-
optional?: boolean | undefined;
|
|
74
|
-
}): ThreadComposerAttachmentContextValue | null;
|
|
75
|
-
function useThreadComposerAttachmentContext(options?: {
|
|
76
|
-
optional?: boolean | undefined;
|
|
77
|
-
}): ThreadComposerAttachmentContextValue | null {
|
|
78
|
-
const context = useAttachmentContext(options);
|
|
79
|
-
if (!context) return null;
|
|
80
|
-
if (context.source !== "thread-composer")
|
|
81
|
-
throw new Error(
|
|
82
|
-
"This component must be used within a thread's ComposerPrimitive.Attachments component.",
|
|
83
|
-
);
|
|
84
|
-
return context as ThreadComposerAttachmentContextValue;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function useEditComposerAttachmentContext(options?: {
|
|
88
|
-
optional?: false | undefined;
|
|
89
|
-
}): EditComposerAttachmentContextValue;
|
|
90
|
-
function useEditComposerAttachmentContext(options?: {
|
|
91
|
-
optional?: boolean | undefined;
|
|
92
|
-
}): EditComposerAttachmentContextValue | null;
|
|
93
|
-
function useEditComposerAttachmentContext(options?: {
|
|
94
|
-
optional?: boolean | undefined;
|
|
95
|
-
}): EditComposerAttachmentContextValue | null {
|
|
96
|
-
const context = useAttachmentContext(options);
|
|
97
|
-
if (!context) return null;
|
|
98
|
-
if (context.source !== "edit-composer")
|
|
99
|
-
throw new Error(
|
|
100
|
-
"This component must be used within a messages's ComposerPrimitive.Attachments component.",
|
|
101
|
-
);
|
|
102
|
-
return context as EditComposerAttachmentContextValue;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function useMessageAttachmentContext(options?: {
|
|
106
|
-
optional?: false | undefined;
|
|
107
|
-
}): MessageAttachmentContextValue;
|
|
108
|
-
function useMessageAttachmentContext(options?: {
|
|
109
|
-
optional?: boolean | undefined;
|
|
110
|
-
}): MessageAttachmentContextValue | null;
|
|
111
|
-
function useMessageAttachmentContext(options?: {
|
|
112
|
-
optional?: boolean | undefined;
|
|
113
|
-
}): MessageAttachmentContextValue | null {
|
|
114
|
-
const context = useAttachmentContext(options);
|
|
115
|
-
if (!context) return null;
|
|
116
|
-
if (context.source !== "message")
|
|
117
|
-
throw new Error(
|
|
118
|
-
"This component must be used within a MessagePrimitive.Attachments component.",
|
|
119
|
-
);
|
|
120
|
-
return context as MessageAttachmentContextValue;
|
|
121
|
-
}
|
|
18
|
+
const useAttachmentContext = createContextHook(
|
|
19
|
+
AttachmentContext,
|
|
20
|
+
"a ComposerPrimitive.Attachments or MessagePrimitive.Attachments component",
|
|
21
|
+
);
|
|
122
22
|
|
|
123
23
|
export function useAttachmentRuntime(options?: {
|
|
124
24
|
optional?: false | undefined;
|
|
@@ -136,58 +36,67 @@ export function useAttachmentRuntime(options?: {
|
|
|
136
36
|
|
|
137
37
|
export function useThreadComposerAttachmentRuntime(options?: {
|
|
138
38
|
optional?: false | undefined;
|
|
139
|
-
}): AttachmentRuntime
|
|
39
|
+
}): AttachmentRuntime<"thread-composer">;
|
|
140
40
|
export function useThreadComposerAttachmentRuntime(options?: {
|
|
141
41
|
optional?: boolean | undefined;
|
|
142
|
-
}): AttachmentRuntime | null;
|
|
42
|
+
}): AttachmentRuntime<"thread-composer"> | null;
|
|
143
43
|
export function useThreadComposerAttachmentRuntime(options?: {
|
|
144
44
|
optional?: boolean | undefined;
|
|
145
|
-
}): AttachmentRuntime | null {
|
|
146
|
-
const attachmentRuntime =
|
|
45
|
+
}): AttachmentRuntime<"thread-composer"> | null {
|
|
46
|
+
const attachmentRuntime = useAttachmentRuntime(options);
|
|
147
47
|
if (!attachmentRuntime) return null;
|
|
148
|
-
|
|
48
|
+
if (attachmentRuntime.source !== "thread-composer")
|
|
49
|
+
throw new Error(
|
|
50
|
+
"This component must be used within a thread's ComposerPrimitive.Attachments component.",
|
|
51
|
+
);
|
|
52
|
+
return attachmentRuntime as AttachmentRuntime<"thread-composer">;
|
|
149
53
|
}
|
|
150
54
|
|
|
151
55
|
export function useEditComposerAttachmentRuntime(options?: {
|
|
152
56
|
optional?: false | undefined;
|
|
153
|
-
}): AttachmentRuntime
|
|
57
|
+
}): AttachmentRuntime<"edit-composer">;
|
|
154
58
|
export function useEditComposerAttachmentRuntime(options?: {
|
|
155
59
|
optional?: boolean | undefined;
|
|
156
|
-
}): AttachmentRuntime | null;
|
|
60
|
+
}): AttachmentRuntime<"edit-composer"> | null;
|
|
157
61
|
export function useEditComposerAttachmentRuntime(options?: {
|
|
158
62
|
optional?: boolean | undefined;
|
|
159
|
-
}): AttachmentRuntime | null {
|
|
160
|
-
const attachmentRuntime =
|
|
63
|
+
}): AttachmentRuntime<"edit-composer"> | null {
|
|
64
|
+
const attachmentRuntime = useAttachmentRuntime(options);
|
|
161
65
|
if (!attachmentRuntime) return null;
|
|
162
|
-
|
|
66
|
+
if (attachmentRuntime.source !== "edit-composer")
|
|
67
|
+
throw new Error(
|
|
68
|
+
"This component must be used within a message's ComposerPrimitive.Attachments component.",
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return attachmentRuntime as AttachmentRuntime<"edit-composer">;
|
|
163
72
|
}
|
|
164
73
|
|
|
165
74
|
export function useMessageAttachmentRuntime(options?: {
|
|
166
75
|
optional?: false | undefined;
|
|
167
|
-
}): AttachmentRuntime
|
|
76
|
+
}): AttachmentRuntime<"message">;
|
|
168
77
|
export function useMessageAttachmentRuntime(options?: {
|
|
169
78
|
optional?: boolean | undefined;
|
|
170
|
-
}): AttachmentRuntime | null;
|
|
79
|
+
}): AttachmentRuntime<"message"> | null;
|
|
171
80
|
export function useMessageAttachmentRuntime(options?: {
|
|
172
81
|
optional?: boolean | undefined;
|
|
173
|
-
}): AttachmentRuntime | null {
|
|
174
|
-
const attachmentRuntime =
|
|
82
|
+
}): AttachmentRuntime<"message"> | null {
|
|
83
|
+
const attachmentRuntime = useAttachmentRuntime(options);
|
|
175
84
|
if (!attachmentRuntime) return null;
|
|
176
|
-
|
|
85
|
+
if (attachmentRuntime.source !== "message")
|
|
86
|
+
throw new Error(
|
|
87
|
+
"This component must be used within a MessagePrimitive.Attachments component.",
|
|
88
|
+
);
|
|
89
|
+
return attachmentRuntime as AttachmentRuntime<"message">;
|
|
177
90
|
}
|
|
178
91
|
|
|
179
|
-
export const
|
|
180
|
-
useAttachmentContext,
|
|
181
|
-
"useAttachment",
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
export const { useAttachment: useThreadComposerAttachment } =
|
|
185
|
-
createContextStoreHook(useThreadComposerAttachmentContext, "useAttachment");
|
|
92
|
+
export const useAttachment = createStateHookForRuntime(useAttachmentRuntime);
|
|
186
93
|
|
|
187
|
-
export const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
export const
|
|
191
|
-
|
|
192
|
-
|
|
94
|
+
export const useThreadComposerAttachment = createStateHookForRuntime(
|
|
95
|
+
useThreadComposerAttachmentRuntime,
|
|
96
|
+
);
|
|
97
|
+
export const useEditComposerAttachment = createStateHookForRuntime(
|
|
98
|
+
useEditComposerAttachmentRuntime,
|
|
99
|
+
);
|
|
100
|
+
export const useMessageAttachment = createStateHookForRuntime(
|
|
101
|
+
useMessageAttachmentRuntime,
|
|
193
102
|
);
|
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { createContextStoreHook } from "./utils/createContextStoreHook";
|
|
8
|
-
import { ComposerRuntime, ComposerState } from "../../api/ComposerRuntime";
|
|
9
|
-
import { UseBoundStore } from "zustand";
|
|
10
|
-
|
|
11
|
-
export type ComposerContextValue = {
|
|
12
|
-
useComposer: UseBoundStore<ReadonlyStore<ComposerState>>;
|
|
13
|
-
type: "edit" | "new";
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const useComposerContext = (): ComposerContextValue => {
|
|
17
|
-
const { useComposer: useThreadComposer } = useThreadContext();
|
|
18
|
-
const { useEditComposer } = useMessageContext({ optional: true }) ?? {};
|
|
19
|
-
return useMemo(
|
|
20
|
-
() => ({
|
|
21
|
-
useComposer: useEditComposer ?? useThreadComposer,
|
|
22
|
-
type: useEditComposer ? ("edit" as const) : ("new" as const),
|
|
23
|
-
}),
|
|
24
|
-
[useEditComposer, useThreadComposer],
|
|
25
|
-
);
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const { useComposer } = createContextStoreHook(
|
|
29
|
-
useComposerContext,
|
|
30
|
-
"useComposer",
|
|
31
|
-
);
|
|
3
|
+
import { useMessageRuntime } from "./MessageContext";
|
|
4
|
+
import { useThreadRuntime } from "./ThreadContext";
|
|
5
|
+
import { ComposerRuntime } from "../../api/ComposerRuntime";
|
|
6
|
+
import { createStateHookForRuntime } from "./utils/createStateHookForRuntime";
|
|
32
7
|
|
|
33
8
|
export function useComposerRuntime(options?: {
|
|
34
9
|
optional?: false | undefined;
|
|
@@ -45,3 +20,5 @@ export function useComposerRuntime(options?: {
|
|
|
45
20
|
? messageRuntime.composer
|
|
46
21
|
: (threadRuntime?.composer ?? null);
|
|
47
22
|
}
|
|
23
|
+
|
|
24
|
+
export const useComposer = createStateHookForRuntime(useComposerRuntime);
|
|
@@ -2,22 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import { createContext } from "react";
|
|
4
4
|
import { ReadonlyStore } from "../ReadonlyStore";
|
|
5
|
-
import { createContextStoreHook } from "./utils/createContextStoreHook";
|
|
6
5
|
import { createContextHook } from "./utils/createContextHook";
|
|
7
6
|
import { UseBoundStore } from "zustand";
|
|
8
7
|
import { ContentPartRuntime } from "../../api/ContentPartRuntime";
|
|
9
|
-
import {
|
|
8
|
+
import { createStateHookForRuntime } from "./utils/createStateHookForRuntime";
|
|
10
9
|
|
|
11
10
|
export type ContentPartContextValue = {
|
|
12
11
|
useContentPartRuntime: UseBoundStore<ReadonlyStore<ContentPartRuntime>>;
|
|
13
|
-
useContentPart: UseBoundStore<ReadonlyStore<ContentPartState>>;
|
|
14
12
|
};
|
|
15
13
|
|
|
16
14
|
export const ContentPartContext = createContext<ContentPartContextValue | null>(
|
|
17
15
|
null,
|
|
18
16
|
);
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
const useContentPartContext = createContextHook(
|
|
21
19
|
ContentPartContext,
|
|
22
20
|
"a component passed to <MessagePrimitive.Content components={...}>",
|
|
23
21
|
);
|
|
@@ -36,7 +34,4 @@ export function useContentPartRuntime(options?: {
|
|
|
36
34
|
return context.useContentPartRuntime();
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
export const
|
|
40
|
-
useContentPartContext,
|
|
41
|
-
"useContentPart",
|
|
42
|
-
);
|
|
37
|
+
export const useContentPart = createStateHookForRuntime(useContentPartRuntime);
|
|
@@ -7,19 +7,17 @@ import { createContextHook } from "./utils/createContextHook";
|
|
|
7
7
|
import { createContextStoreHook } from "./utils/createContextStoreHook";
|
|
8
8
|
import { UseBoundStore } from "zustand";
|
|
9
9
|
import { MessageRuntime } from "../../api/MessageRuntime";
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { createStateHookForRuntime } from "./utils/createStateHookForRuntime";
|
|
11
|
+
import { EditComposerRuntime } from "../../api";
|
|
12
12
|
|
|
13
13
|
export type MessageContextValue = {
|
|
14
14
|
useMessageRuntime: UseBoundStore<ReadonlyStore<MessageRuntime>>;
|
|
15
|
-
useMessage: UseBoundStore<ReadonlyStore<MessageState>>;
|
|
16
15
|
useMessageUtils: UseBoundStore<ReadonlyStore<MessageUtilsState>>;
|
|
17
|
-
useEditComposer: UseBoundStore<ReadonlyStore<EditComposerState>>;
|
|
18
16
|
};
|
|
19
17
|
|
|
20
18
|
export const MessageContext = createContext<MessageContextValue | null>(null);
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
const useMessageContext = createContextHook(
|
|
23
21
|
MessageContext,
|
|
24
22
|
"a component passed to <ThreadPrimitive.Messages components={...} />",
|
|
25
23
|
);
|
|
@@ -38,17 +36,16 @@ export function useMessageRuntime(options?: {
|
|
|
38
36
|
return context.useMessageRuntime();
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
export const
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
export const useMessage = createStateHookForRuntime(useMessageRuntime);
|
|
40
|
+
|
|
41
|
+
const useEditComposerRuntime = (opt: {
|
|
42
|
+
optional: boolean | undefined;
|
|
43
|
+
}): EditComposerRuntime | null => useMessageRuntime(opt)?.composer ?? null;
|
|
44
|
+
export const useEditComposer = createStateHookForRuntime(
|
|
45
|
+
useEditComposerRuntime,
|
|
44
46
|
);
|
|
45
47
|
|
|
46
48
|
export const { useMessageUtils, useMessageUtilsStore } = createContextStoreHook(
|
|
47
49
|
useMessageContext,
|
|
48
50
|
"useMessageUtils",
|
|
49
51
|
);
|
|
50
|
-
|
|
51
|
-
export const { useEditComposer } = createContextStoreHook(
|
|
52
|
-
useMessageContext,
|
|
53
|
-
"useEditComposer",
|
|
54
|
-
);
|
|
@@ -7,20 +7,18 @@ import { UseBoundStore } from "zustand";
|
|
|
7
7
|
import { createContextHook } from "./utils/createContextHook";
|
|
8
8
|
import { createContextStoreHook } from "./utils/createContextStoreHook";
|
|
9
9
|
import { ThreadRuntime } from "../../api/ThreadRuntime";
|
|
10
|
-
import { ThreadState } from "../../api/ThreadRuntime";
|
|
11
10
|
import { ModelConfig } from "../../types";
|
|
12
|
-
import {
|
|
11
|
+
import { createStateHookForRuntime } from "./utils/createStateHookForRuntime";
|
|
12
|
+
import { ThreadComposerRuntime } from "../../api";
|
|
13
13
|
|
|
14
14
|
export type ThreadContextValue = {
|
|
15
|
-
useThread: UseBoundStore<ReadonlyStore<ThreadState>>;
|
|
16
15
|
useThreadRuntime: UseBoundStore<ReadonlyStore<ThreadRuntime>>;
|
|
17
|
-
useComposer: UseBoundStore<ReadonlyStore<ThreadComposerState>>;
|
|
18
16
|
useViewport: UseBoundStore<ReadonlyStore<ThreadViewportState>>;
|
|
19
17
|
};
|
|
20
18
|
|
|
21
19
|
export const ThreadContext = createContext<ThreadContextValue | null>(null);
|
|
22
20
|
|
|
23
|
-
|
|
21
|
+
const useThreadContext = createContextHook(
|
|
24
22
|
ThreadContext,
|
|
25
23
|
"AssistantRuntimeProvider",
|
|
26
24
|
);
|
|
@@ -37,14 +35,13 @@ export function useThreadRuntime(options?: { optional?: boolean | undefined }) {
|
|
|
37
35
|
return context.useThreadRuntime();
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
export const
|
|
41
|
-
useThreadContext,
|
|
42
|
-
"useThread",
|
|
43
|
-
);
|
|
38
|
+
export const useThread = createStateHookForRuntime(useThreadRuntime);
|
|
44
39
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
const useThreadComposerRuntime = (opt: {
|
|
41
|
+
optional: boolean | undefined;
|
|
42
|
+
}): ThreadComposerRuntime | null => useThreadRuntime(opt)?.composer ?? null;
|
|
43
|
+
export const useThreadComposer = createStateHookForRuntime(
|
|
44
|
+
useThreadComposerRuntime,
|
|
48
45
|
);
|
|
49
46
|
|
|
50
47
|
export const {
|
|
@@ -2,21 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
import { createContext } from "react";
|
|
4
4
|
import { ReadonlyStore } from "../ReadonlyStore";
|
|
5
|
-
import { createContextStoreHook } from "./utils/createContextStoreHook";
|
|
6
5
|
import { createContextHook } from "./utils/createContextHook";
|
|
7
6
|
import { UseBoundStore } from "zustand";
|
|
8
7
|
import { ThreadListItemRuntime } from "../../api/ThreadListItemRuntime";
|
|
9
|
-
import {
|
|
8
|
+
import { createStateHookForRuntime } from "./utils/createStateHookForRuntime";
|
|
10
9
|
|
|
11
10
|
export type ThreadListItemContextValue = {
|
|
12
11
|
useThreadListItemRuntime: UseBoundStore<ReadonlyStore<ThreadListItemRuntime>>;
|
|
13
|
-
useThreadListItem: UseBoundStore<ReadonlyStore<ThreadListItemState>>;
|
|
14
12
|
};
|
|
15
13
|
|
|
16
14
|
export const ThreadListItemContext =
|
|
17
15
|
createContext<ThreadListItemContextValue | null>(null);
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
const useThreadListItemContext = createContextHook(
|
|
20
18
|
ThreadListItemContext,
|
|
21
19
|
"a component passed to <ThreadListPrimitive.Items components={...}>",
|
|
22
20
|
);
|
|
@@ -35,7 +33,6 @@ export function useThreadListItemRuntime(options?: {
|
|
|
35
33
|
return context.useThreadListItemRuntime();
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
export const
|
|
39
|
-
|
|
40
|
-
"useThreadListItem",
|
|
36
|
+
export const useThreadListItem = createStateHookForRuntime(
|
|
37
|
+
useThreadListItemRuntime,
|
|
41
38
|
);
|