@assistant-ui/react 0.7.45 → 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/dist/ui/thread-config.d.ts +1 -0
- package/dist/ui/thread-config.d.ts.map +1 -1
- package/dist/ui/thread-config.js.map +1 -1
- package/dist/ui/thread-config.mjs.map +1 -1
- package/dist/ui/thread.d.ts +2 -1
- package/dist/ui/thread.d.ts.map +1 -1
- package/dist/ui/thread.js +15 -2
- package/dist/ui/thread.js.map +1 -1
- package/dist/ui/thread.mjs +15 -2
- package/dist/ui/thread.mjs.map +1 -1
- package/package.json +2 -2
- 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
- package/src/ui/thread-config.tsx +1 -0
- package/src/ui/thread.tsx +14 -3
|
@@ -55,6 +55,18 @@ export class ThreadListItemRuntimeImpl implements ThreadListItemRuntime {
|
|
|
55
55
|
private _threadListBinding: ThreadListRuntimeCoreBinding,
|
|
56
56
|
) {}
|
|
57
57
|
|
|
58
|
+
protected __internal_bindMethods() {
|
|
59
|
+
this.switchTo = this.switchTo.bind(this);
|
|
60
|
+
this.rename = this.rename.bind(this);
|
|
61
|
+
this.archive = this.archive.bind(this);
|
|
62
|
+
this.unarchive = this.unarchive.bind(this);
|
|
63
|
+
this.delete = this.delete.bind(this);
|
|
64
|
+
this.initialize = this.initialize.bind(this);
|
|
65
|
+
this.subscribe = this.subscribe.bind(this);
|
|
66
|
+
this.unstable_on = this.unstable_on.bind(this);
|
|
67
|
+
this.getState = this.getState.bind(this);
|
|
68
|
+
}
|
|
69
|
+
|
|
58
70
|
public getState(): ThreadListItemState {
|
|
59
71
|
return this._core.getState();
|
|
60
72
|
}
|
|
@@ -116,6 +116,17 @@ export class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
|
116
116
|
);
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
protected __internal_bindMethods() {
|
|
120
|
+
this.switchToThread = this.switchToThread.bind(this);
|
|
121
|
+
this.switchToNewThread = this.switchToNewThread.bind(this);
|
|
122
|
+
this.getState = this.getState.bind(this);
|
|
123
|
+
this.subscribe = this.subscribe.bind(this);
|
|
124
|
+
this.getById = this.getById.bind(this);
|
|
125
|
+
this.getItemById = this.getItemById.bind(this);
|
|
126
|
+
this.getItemByIndex = this.getItemByIndex.bind(this);
|
|
127
|
+
this.getArchivedItemByIndex = this.getArchivedItemByIndex.bind(this);
|
|
128
|
+
}
|
|
129
|
+
|
|
119
130
|
public switchToThread(threadId: string): Promise<void> {
|
|
120
131
|
return this._core.switchToThread(threadId);
|
|
121
132
|
}
|
package/src/api/ThreadRuntime.ts
CHANGED
|
@@ -286,6 +286,21 @@ export class ThreadRuntimeImpl implements ThreadRuntime {
|
|
|
286
286
|
);
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
protected __internal_bindMethods() {
|
|
290
|
+
this.append = this.append.bind(this);
|
|
291
|
+
this.startRun = this.startRun.bind(this);
|
|
292
|
+
this.cancelRun = this.cancelRun.bind(this);
|
|
293
|
+
this.stopSpeaking = this.stopSpeaking.bind(this);
|
|
294
|
+
this.export = this.export.bind(this);
|
|
295
|
+
this.import = this.import.bind(this);
|
|
296
|
+
this.getMesssageByIndex = this.getMesssageByIndex.bind(this);
|
|
297
|
+
this.getMesssageById = this.getMesssageById.bind(this);
|
|
298
|
+
this.subscribe = this.subscribe.bind(this);
|
|
299
|
+
this.unstable_on = this.unstable_on.bind(this);
|
|
300
|
+
this.getModelConfig = this.getModelConfig.bind(this);
|
|
301
|
+
this.getState = this.getState.bind(this);
|
|
302
|
+
}
|
|
303
|
+
|
|
289
304
|
public readonly composer;
|
|
290
305
|
|
|
291
306
|
public getState() {
|
|
@@ -324,10 +339,6 @@ export class ThreadRuntimeImpl implements ThreadRuntime {
|
|
|
324
339
|
return this._threadBinding.getState().stopSpeaking();
|
|
325
340
|
}
|
|
326
341
|
|
|
327
|
-
public getSubmittedFeedback(messageId: string) {
|
|
328
|
-
return this._threadBinding.getState().getSubmittedFeedback(messageId);
|
|
329
|
-
}
|
|
330
|
-
|
|
331
342
|
public export() {
|
|
332
343
|
return this._threadBinding.getState().export();
|
|
333
344
|
}
|
|
@@ -15,6 +15,7 @@ import { AssistantRuntime } from "../../api/AssistantRuntime";
|
|
|
15
15
|
import { create } from "zustand";
|
|
16
16
|
import { writableStore } from "../ReadonlyStore";
|
|
17
17
|
import { AssistantRuntimeCore } from "../../runtimes/core/AssistantRuntimeCore";
|
|
18
|
+
import { ensureBinding } from "../react/utils/ensureBinding";
|
|
18
19
|
|
|
19
20
|
export namespace AssistantRuntimeProvider {
|
|
20
21
|
export type Props = PropsWithChildren<{
|
|
@@ -29,6 +30,8 @@ const useAssistantRuntimeStore = (runtime: AssistantRuntime) => {
|
|
|
29
30
|
const [store] = useState(() => create(() => runtime));
|
|
30
31
|
|
|
31
32
|
useEffect(() => {
|
|
33
|
+
ensureBinding(runtime);
|
|
34
|
+
|
|
32
35
|
writableStore(store).setState(runtime, true);
|
|
33
36
|
}, [runtime, store]);
|
|
34
37
|
|
|
@@ -39,19 +42,6 @@ const useAssistantToolUIsStore = () => {
|
|
|
39
42
|
return useMemo(() => makeAssistantToolUIsStore(), []);
|
|
40
43
|
};
|
|
41
44
|
|
|
42
|
-
const useThreadListStore = (runtime: AssistantRuntime) => {
|
|
43
|
-
const [store] = useState(() => create(() => runtime.threadList.getState()));
|
|
44
|
-
|
|
45
|
-
useEffect(() => {
|
|
46
|
-
const updateState = () =>
|
|
47
|
-
writableStore(store).setState(runtime.threadList.getState(), true);
|
|
48
|
-
updateState();
|
|
49
|
-
return runtime.threadList.subscribe(updateState);
|
|
50
|
-
}, [runtime, store]);
|
|
51
|
-
|
|
52
|
-
return store;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
45
|
const getRenderComponent = (runtime: AssistantRuntime) => {
|
|
56
46
|
return (runtime as { _core?: AssistantRuntimeCore })._core?.RenderComponent;
|
|
57
47
|
};
|
|
@@ -61,14 +51,12 @@ export const AssistantRuntimeProviderImpl: FC<
|
|
|
61
51
|
> = ({ children, runtime }) => {
|
|
62
52
|
const useAssistantRuntime = useAssistantRuntimeStore(runtime);
|
|
63
53
|
const useToolUIs = useAssistantToolUIsStore();
|
|
64
|
-
const
|
|
65
|
-
const context = useMemo(() => {
|
|
54
|
+
const [context] = useState(() => {
|
|
66
55
|
return {
|
|
67
56
|
useToolUIs,
|
|
68
57
|
useAssistantRuntime,
|
|
69
|
-
useThreadList,
|
|
70
58
|
};
|
|
71
|
-
}
|
|
59
|
+
});
|
|
72
60
|
|
|
73
61
|
const RenderComponent = getRenderComponent(runtime);
|
|
74
62
|
|
|
@@ -1,16 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
type FC,
|
|
5
|
-
type PropsWithChildren,
|
|
6
|
-
useEffect,
|
|
7
|
-
useMemo,
|
|
8
|
-
useState,
|
|
9
|
-
} from "react";
|
|
3
|
+
import { type FC, type PropsWithChildren, useEffect, useState } from "react";
|
|
10
4
|
import { create } from "zustand";
|
|
11
5
|
import { AttachmentContext } from "../react/AttachmentContext";
|
|
12
6
|
import { writableStore } from "../ReadonlyStore";
|
|
13
7
|
import { AttachmentRuntime } from "../../api/AttachmentRuntime";
|
|
8
|
+
import { ensureBinding } from "../react/utils/ensureBinding";
|
|
14
9
|
|
|
15
10
|
export namespace AttachmentRuntimeProvider {
|
|
16
11
|
export type Props = PropsWithChildren<{
|
|
@@ -22,18 +17,9 @@ const useAttachmentRuntimeStore = (runtime: AttachmentRuntime) => {
|
|
|
22
17
|
const [store] = useState(() => create(() => runtime));
|
|
23
18
|
|
|
24
19
|
useEffect(() => {
|
|
25
|
-
|
|
26
|
-
}, [runtime, store]);
|
|
20
|
+
ensureBinding(runtime);
|
|
27
21
|
|
|
28
|
-
|
|
29
|
-
};
|
|
30
|
-
const useAttachmentStore = (runtime: AttachmentRuntime) => {
|
|
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);
|
|
22
|
+
writableStore(store).setState(runtime, true);
|
|
37
23
|
}, [runtime, store]);
|
|
38
24
|
|
|
39
25
|
return store;
|
|
@@ -44,15 +30,11 @@ export const AttachmentRuntimeProvider: FC<AttachmentRuntimeProvider.Props> = ({
|
|
|
44
30
|
children,
|
|
45
31
|
}) => {
|
|
46
32
|
const useAttachmentRuntime = useAttachmentRuntimeStore(runtime);
|
|
47
|
-
const
|
|
48
|
-
const source = useAttachment((s) => s.source);
|
|
49
|
-
const context = useMemo(() => {
|
|
33
|
+
const [context] = useState(() => {
|
|
50
34
|
return {
|
|
51
|
-
source,
|
|
52
35
|
useAttachmentRuntime,
|
|
53
|
-
useAttachment,
|
|
54
36
|
};
|
|
55
|
-
}
|
|
37
|
+
});
|
|
56
38
|
|
|
57
39
|
return (
|
|
58
40
|
<AttachmentContext.Provider value={context}>
|
|
@@ -6,6 +6,7 @@ import { ContentPartContext } from "../react/ContentPartContext";
|
|
|
6
6
|
import type { ContentPartContextValue } from "../react/ContentPartContext";
|
|
7
7
|
import { writableStore } from "../ReadonlyStore";
|
|
8
8
|
import { ContentPartRuntime } from "../../api/ContentPartRuntime";
|
|
9
|
+
import { ensureBinding } from "../react/utils/ensureBinding";
|
|
9
10
|
|
|
10
11
|
export namespace ContentPartRuntimeProvider {
|
|
11
12
|
export type Props = PropsWithChildren<{
|
|
@@ -17,19 +18,9 @@ const useContentPartRuntimeStore = (runtime: ContentPartRuntime) => {
|
|
|
17
18
|
const [store] = useState(() => create(() => runtime));
|
|
18
19
|
|
|
19
20
|
useEffect(() => {
|
|
20
|
-
|
|
21
|
-
}, [runtime, store]);
|
|
21
|
+
ensureBinding(runtime);
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export const useContentPartStore = (runtime: ContentPartRuntime) => {
|
|
27
|
-
const [store] = useState(() => create(() => runtime.getState()));
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
const updateState = () =>
|
|
30
|
-
writableStore(store).setState(runtime.getState(), true);
|
|
31
|
-
updateState();
|
|
32
|
-
return runtime.subscribe(updateState);
|
|
23
|
+
writableStore(store).setState(runtime, true);
|
|
33
24
|
}, [runtime, store]);
|
|
34
25
|
|
|
35
26
|
return store;
|
|
@@ -39,9 +30,8 @@ export const ContentPartRuntimeProvider: FC<
|
|
|
39
30
|
ContentPartRuntimeProvider.Props
|
|
40
31
|
> = ({ runtime, children }) => {
|
|
41
32
|
const useContentPartRuntime = useContentPartRuntimeStore(runtime);
|
|
42
|
-
const useContentPart = useContentPartStore(runtime);
|
|
43
33
|
const [context] = useState<ContentPartContextValue>(() => {
|
|
44
|
-
return { useContentPartRuntime
|
|
34
|
+
return { useContentPartRuntime };
|
|
45
35
|
});
|
|
46
36
|
|
|
47
37
|
return (
|
|
@@ -5,8 +5,9 @@ import { create } from "zustand";
|
|
|
5
5
|
import { MessageContext } from "../react/MessageContext";
|
|
6
6
|
import type { MessageContextValue } from "../react/MessageContext";
|
|
7
7
|
import { makeMessageUtilsStore } from "../stores/MessageUtils";
|
|
8
|
-
import {
|
|
8
|
+
import { writableStore } from "../ReadonlyStore";
|
|
9
9
|
import { MessageRuntime } from "../../api/MessageRuntime";
|
|
10
|
+
import { ensureBinding } from "../react/utils/ensureBinding";
|
|
10
11
|
|
|
11
12
|
export namespace MessageRuntimeProvider {
|
|
12
13
|
export type Props = PropsWithChildren<{
|
|
@@ -18,19 +19,9 @@ const useMessageRuntimeStore = (runtime: MessageRuntime) => {
|
|
|
18
19
|
const [store] = useState(() => create(() => runtime));
|
|
19
20
|
|
|
20
21
|
useEffect(() => {
|
|
21
|
-
|
|
22
|
-
}, [runtime, store]);
|
|
22
|
+
ensureBinding(runtime);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const useMessageStore = (runtime: MessageRuntime) => {
|
|
28
|
-
const [store] = useState(() => create(() => runtime.getState()));
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const updateState = () =>
|
|
31
|
-
writableStore(store).setState(runtime.getState(), true);
|
|
32
|
-
updateState();
|
|
33
|
-
return runtime.subscribe(updateState);
|
|
24
|
+
writableStore(store).setState(runtime, true);
|
|
34
25
|
}, [runtime, store]);
|
|
35
26
|
|
|
36
27
|
return store;
|
|
@@ -41,31 +32,14 @@ const useMessageUtilsStore = () => {
|
|
|
41
32
|
return store;
|
|
42
33
|
};
|
|
43
34
|
|
|
44
|
-
const useEditComposerStore = (
|
|
45
|
-
useMessageRuntime: ReadonlyStore<MessageRuntime>,
|
|
46
|
-
) => {
|
|
47
|
-
const runtime = useMessageRuntime.getState().composer;
|
|
48
|
-
const [store] = useState(() => create(() => runtime.getState()));
|
|
49
|
-
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
const updateState = () => writableStore(store).setState(runtime.getState());
|
|
52
|
-
updateState();
|
|
53
|
-
return runtime.subscribe(updateState);
|
|
54
|
-
}, [runtime, store]);
|
|
55
|
-
|
|
56
|
-
return store;
|
|
57
|
-
};
|
|
58
|
-
|
|
59
35
|
export const MessageRuntimeProvider: FC<MessageRuntimeProvider.Props> = ({
|
|
60
36
|
runtime,
|
|
61
37
|
children,
|
|
62
38
|
}) => {
|
|
63
39
|
const useMessageRuntime = useMessageRuntimeStore(runtime);
|
|
64
|
-
const useMessage = useMessageStore(runtime);
|
|
65
40
|
const useMessageUtils = useMessageUtilsStore();
|
|
66
|
-
const useEditComposer = useEditComposerStore(useMessageRuntime);
|
|
67
41
|
const [context] = useState<MessageContextValue>(() => {
|
|
68
|
-
return { useMessageRuntime,
|
|
42
|
+
return { useMessageRuntime, useMessageUtils };
|
|
69
43
|
});
|
|
70
44
|
|
|
71
45
|
return (
|
|
@@ -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);
|