@assistant-ui/react 0.7.9 → 0.7.10
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/api/AssistantRuntime.d.ts +4 -5
- package/dist/api/AssistantRuntime.d.ts.map +1 -1
- package/dist/api/AssistantRuntime.js +16 -19
- package/dist/api/AssistantRuntime.js.map +1 -1
- package/dist/api/AssistantRuntime.mjs +16 -19
- package/dist/api/AssistantRuntime.mjs.map +1 -1
- package/dist/api/ThreadListItemRuntime.d.ts +11 -2
- package/dist/api/ThreadListItemRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListItemRuntime.js +16 -5
- package/dist/api/ThreadListItemRuntime.js.map +1 -1
- package/dist/api/ThreadListItemRuntime.mjs +16 -5
- package/dist/api/ThreadListItemRuntime.mjs.map +1 -1
- package/dist/api/ThreadListRuntime.d.ts +3 -0
- package/dist/api/ThreadListRuntime.d.ts.map +1 -1
- package/dist/api/ThreadListRuntime.js +27 -8
- package/dist/api/ThreadListRuntime.js.map +1 -1
- package/dist/api/ThreadListRuntime.mjs +27 -8
- package/dist/api/ThreadListRuntime.mjs.map +1 -1
- package/dist/api/ThreadRuntime.d.ts +10 -7
- package/dist/api/ThreadRuntime.d.ts.map +1 -1
- package/dist/api/ThreadRuntime.js +16 -6
- package/dist/api/ThreadRuntime.js.map +1 -1
- package/dist/api/ThreadRuntime.mjs +16 -6
- package/dist/api/ThreadRuntime.mjs.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.js +8 -1
- package/dist/context/providers/AssistantRuntimeProvider.js.map +1 -1
- package/dist/context/providers/AssistantRuntimeProvider.mjs +8 -1
- package/dist/context/providers/AssistantRuntimeProvider.mjs.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.d.ts +2 -0
- package/dist/context/providers/ThreadRuntimeProvider.d.ts.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.js +3 -2
- package/dist/context/providers/ThreadRuntimeProvider.js.map +1 -1
- package/dist/context/providers/ThreadRuntimeProvider.mjs +3 -2
- package/dist/context/providers/ThreadRuntimeProvider.mjs.map +1 -1
- package/dist/internal.d.ts +1 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +0 -3
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +0 -2
- package/dist/internal.mjs.map +1 -1
- package/dist/primitives/composer/ComposerInput.d.ts.map +1 -1
- package/dist/primitives/composer/ComposerInput.js +3 -1
- package/dist/primitives/composer/ComposerInput.js.map +1 -1
- package/dist/primitives/composer/ComposerInput.mjs +3 -1
- package/dist/primitives/composer/ComposerInput.mjs.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts +2 -4
- package/dist/runtimes/core/BaseThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.js +1 -5
- package/dist/runtimes/core/BaseThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/BaseThreadRuntimeCore.mjs +1 -5
- package/dist/runtimes/core/BaseThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts +14 -6
- package/dist/runtimes/core/ThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts +1 -15
- package/dist/runtimes/core/ThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/core/ThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/core/index.d.ts +1 -1
- package/dist/runtimes/core/index.d.ts.map +1 -1
- package/dist/runtimes/core/index.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts +20 -3
- package/dist/runtimes/external-store/ExternalStoreAdapter.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreAdapter.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts +0 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js +3 -10
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs +3 -10
- package/dist/runtimes/external-store/ExternalStoreRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts +9 -11
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js +19 -27
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs +19 -27
- package/dist/runtimes/external-store/ExternalStoreThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts +2 -2
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js +4 -7
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs +4 -7
- package/dist/runtimes/external-store/ExternalStoreThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts +0 -1
- package/dist/runtimes/local/LocalRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.js +3 -12
- package/dist/runtimes/local/LocalRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalRuntimeCore.mjs +3 -12
- package/dist/runtimes/local/LocalRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts +17 -15
- package/dist/runtimes/local/LocalThreadListRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js +94 -92
- package/dist/runtimes/local/LocalThreadListRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs +94 -92
- package/dist/runtimes/local/LocalThreadListRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts +4 -3
- package/dist/runtimes/local/LocalThreadRuntimeCore.d.ts.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.js +11 -10
- package/dist/runtimes/local/LocalThreadRuntimeCore.js.map +1 -1
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs +11 -10
- package/dist/runtimes/local/LocalThreadRuntimeCore.mjs.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.d.ts.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.js +4 -7
- package/dist/runtimes/local/useLocalRuntime.js.map +1 -1
- package/dist/runtimes/local/useLocalRuntime.mjs +4 -7
- package/dist/runtimes/local/useLocalRuntime.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/AssistantRuntime.ts +21 -25
- package/src/api/ThreadListItemRuntime.ts +36 -7
- package/src/api/ThreadListRuntime.ts +31 -9
- package/src/api/ThreadRuntime.ts +38 -10
- package/src/context/providers/AssistantRuntimeProvider.tsx +4 -1
- package/src/context/providers/ThreadRuntimeProvider.tsx +9 -2
- package/src/internal.ts +1 -1
- package/src/primitives/composer/ComposerInput.tsx +3 -1
- package/src/runtimes/core/BaseThreadRuntimeCore.tsx +1 -9
- package/src/runtimes/core/ThreadListRuntimeCore.tsx +16 -7
- package/src/runtimes/core/ThreadRuntimeCore.tsx +1 -19
- package/src/runtimes/core/index.ts +0 -1
- package/src/runtimes/external-store/ExternalStoreAdapter.tsx +20 -3
- package/src/runtimes/external-store/ExternalStoreRuntimeCore.tsx +5 -12
- package/src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx +22 -35
- package/src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx +3 -7
- package/src/runtimes/local/LocalRuntimeCore.tsx +7 -14
- package/src/runtimes/local/LocalThreadListRuntimeCore.tsx +110 -103
- package/src/runtimes/local/LocalThreadRuntimeCore.tsx +11 -10
- package/src/runtimes/local/useLocalRuntime.tsx +5 -12
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.d.ts +0 -19
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.d.ts.map +0 -1
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.js +0 -87
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.js.map +0 -1
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.mjs +0 -62
- package/dist/runtimes/local/LocalThreadMetadataRuntimeCore.mjs.map +0 -1
- package/src/runtimes/local/LocalThreadMetadataRuntimeCore.tsx +0 -79
@@ -21,6 +21,7 @@ export type ThreadListRuntime = {
|
|
21
21
|
|
22
22
|
subscribe(callback: () => void): Unsubscribe;
|
23
23
|
|
24
|
+
readonly mainThreadListItem: ThreadListItemRuntime;
|
24
25
|
getThreadListItemById(threadId: string): ThreadListItemRuntime;
|
25
26
|
getThreadListItemByIndex(idx: number): ThreadListItemRuntime;
|
26
27
|
getThreadListArchivedItemByIndex(idx: number): ThreadListItemRuntime;
|
@@ -30,10 +31,10 @@ const getThreadListState = (
|
|
30
31
|
threadList: ThreadListRuntimeCore,
|
31
32
|
): ThreadListState => {
|
32
33
|
return {
|
33
|
-
mainThreadId: threadList.
|
34
|
-
newThread: threadList.
|
35
|
-
threads: threadList.
|
36
|
-
archivedThreads: threadList.
|
34
|
+
mainThreadId: threadList.mainThreadId,
|
35
|
+
newThread: threadList.newThreadId,
|
36
|
+
threads: threadList.threadIds,
|
37
|
+
archivedThreads: threadList.archivedThreadIds,
|
37
38
|
};
|
38
39
|
};
|
39
40
|
|
@@ -43,13 +44,14 @@ const getThreadListItemState = (
|
|
43
44
|
): ThreadListItemState | SKIP_UPDATE => {
|
44
45
|
if (threadId === undefined) return SKIP_UPDATE;
|
45
46
|
|
46
|
-
const threadData = threadList.
|
47
|
+
const threadData = threadList.getItemById(threadId);
|
47
48
|
if (!threadData) return SKIP_UPDATE;
|
48
49
|
return {
|
49
|
-
|
50
|
+
id: threadData.threadId,
|
51
|
+
threadId: threadData.threadId, // TODO remove in 0.8.0
|
50
52
|
title: threadData.title,
|
51
53
|
state: threadData.state,
|
52
|
-
isMain:
|
54
|
+
isMain: threadData.threadId === threadList.mainThreadId,
|
53
55
|
};
|
54
56
|
};
|
55
57
|
|
@@ -65,6 +67,20 @@ export class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
65
67
|
});
|
66
68
|
|
67
69
|
this._getState = stateBinding.getState.bind(stateBinding);
|
70
|
+
|
71
|
+
this._mainThreadListItemRuntime = new ThreadListItemRuntimeImpl(
|
72
|
+
new ShallowMemoizeSubject({
|
73
|
+
path: {
|
74
|
+
ref: `threadItems[main]`,
|
75
|
+
threadSelector: { type: "main" },
|
76
|
+
},
|
77
|
+
getState: () => {
|
78
|
+
return getThreadListItemState(this._core, this._core.mainThreadId);
|
79
|
+
},
|
80
|
+
subscribe: (callback) => this._core.subscribe(callback),
|
81
|
+
}),
|
82
|
+
this._core,
|
83
|
+
);
|
68
84
|
}
|
69
85
|
|
70
86
|
public getState(): ThreadListState {
|
@@ -75,6 +91,12 @@ export class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
75
91
|
return this._core.subscribe(callback);
|
76
92
|
}
|
77
93
|
|
94
|
+
private _mainThreadListItemRuntime;
|
95
|
+
|
96
|
+
public get mainThreadListItem() {
|
97
|
+
return this._mainThreadListItemRuntime;
|
98
|
+
}
|
99
|
+
|
78
100
|
public getThreadListItemByIndex(idx: number) {
|
79
101
|
return new ThreadListItemRuntimeImpl(
|
80
102
|
new ShallowMemoizeSubject({
|
@@ -83,7 +105,7 @@ export class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
83
105
|
threadSelector: { type: "index", index: idx },
|
84
106
|
},
|
85
107
|
getState: () => {
|
86
|
-
return getThreadListItemState(this._core, this._core.
|
108
|
+
return getThreadListItemState(this._core, this._core.threadIds[idx]);
|
87
109
|
},
|
88
110
|
subscribe: (callback) => this._core.subscribe(callback),
|
89
111
|
}),
|
@@ -101,7 +123,7 @@ export class ThreadListRuntimeImpl implements ThreadListRuntime {
|
|
101
123
|
getState: () => {
|
102
124
|
return getThreadListItemState(
|
103
125
|
this._core,
|
104
|
-
this._core.
|
126
|
+
this._core.archivedThreadIds[idx],
|
105
127
|
);
|
106
128
|
},
|
107
129
|
subscribe: (callback) => this._core.subscribe(callback),
|
package/src/api/ThreadRuntime.ts
CHANGED
@@ -4,7 +4,6 @@ import {
|
|
4
4
|
ThreadRuntimeCore,
|
5
5
|
SpeechState,
|
6
6
|
ThreadRuntimeEventType,
|
7
|
-
ThreadMetadata,
|
8
7
|
} from "../runtimes/core/ThreadRuntimeCore";
|
9
8
|
import { ExportedMessageRepository } from "../runtimes/utils/MessageRepository";
|
10
9
|
import {
|
@@ -30,7 +29,12 @@ import {
|
|
30
29
|
} from "./ComposerRuntime";
|
31
30
|
import { LazyMemoizeSubject } from "./subscribable/LazyMemoizeSubject";
|
32
31
|
import { SKIP_UPDATE } from "./subscribable/SKIP_UPDATE";
|
33
|
-
import {
|
32
|
+
import {
|
33
|
+
MessageRuntimePath,
|
34
|
+
ThreadListItemRuntimePath,
|
35
|
+
ThreadRuntimePath,
|
36
|
+
} from "./RuntimePathTypes";
|
37
|
+
import { ThreadListItemState } from "./ThreadListItemRuntime";
|
34
38
|
|
35
39
|
export type CreateAppendMessage =
|
36
40
|
| string
|
@@ -74,17 +78,24 @@ export type ThreadRuntimeCoreBinding = SubscribableWithState<
|
|
74
78
|
outerSubscribe(callback: () => void): Unsubscribe;
|
75
79
|
};
|
76
80
|
|
81
|
+
export type ThreadListItemRuntimeBinding = SubscribableWithState<
|
82
|
+
ThreadListItemState,
|
83
|
+
ThreadListItemRuntimePath
|
84
|
+
>;
|
85
|
+
|
77
86
|
export type ThreadState = {
|
78
87
|
/**
|
79
88
|
* The thread ID.
|
80
|
-
* @deprecated This field is deprecated and will be removed in 0.8.0. Use `
|
89
|
+
* @deprecated This field is deprecated and will be removed in 0.8.0. Use `useThreadListItem().id` instead.
|
81
90
|
*/
|
82
91
|
readonly threadId: string;
|
83
92
|
|
84
93
|
/**
|
85
94
|
* The thread metadata.
|
95
|
+
*
|
96
|
+
* @deprecated Use `useThreadListItem()` instead. This field is deprecated and will be removed in 0.8.0.
|
86
97
|
*/
|
87
|
-
readonly metadata:
|
98
|
+
readonly metadata: ThreadListItemState;
|
88
99
|
|
89
100
|
/**
|
90
101
|
* Whether the thread is disabled. Disabled threads cannot receive new messages.
|
@@ -122,11 +133,14 @@ export type ThreadState = {
|
|
122
133
|
readonly speech: SpeechState | undefined;
|
123
134
|
};
|
124
135
|
|
125
|
-
export const getThreadState = (
|
136
|
+
export const getThreadState = (
|
137
|
+
runtime: ThreadRuntimeCore,
|
138
|
+
threadListItemState: ThreadListItemState,
|
139
|
+
): ThreadState => {
|
126
140
|
const lastMessage = runtime.messages.at(-1);
|
127
141
|
return Object.freeze({
|
128
|
-
threadId:
|
129
|
-
metadata:
|
142
|
+
threadId: threadListItemState.id,
|
143
|
+
metadata: threadListItemState,
|
130
144
|
capabilities: runtime.capabilities,
|
131
145
|
isDisabled: runtime.isDisabled,
|
132
146
|
isRunning:
|
@@ -208,11 +222,25 @@ export class ThreadRuntimeImpl implements ThreadRuntime {
|
|
208
222
|
getStateState(): ThreadState;
|
209
223
|
};
|
210
224
|
|
211
|
-
constructor(
|
225
|
+
constructor(
|
226
|
+
threadBinding: ThreadRuntimeCoreBinding,
|
227
|
+
threadListItemBinding: ThreadListItemRuntimeBinding,
|
228
|
+
) {
|
212
229
|
const stateBinding = new LazyMemoizeSubject({
|
213
230
|
path: threadBinding.path,
|
214
|
-
getState: () =>
|
215
|
-
|
231
|
+
getState: () =>
|
232
|
+
getThreadState(
|
233
|
+
threadBinding.getState(),
|
234
|
+
threadListItemBinding.getState(),
|
235
|
+
),
|
236
|
+
subscribe: (callback) => {
|
237
|
+
const sub1 = threadBinding.subscribe(callback);
|
238
|
+
const sub2 = threadListItemBinding.subscribe(callback);
|
239
|
+
return () => {
|
240
|
+
sub1();
|
241
|
+
sub2();
|
242
|
+
};
|
243
|
+
},
|
216
244
|
});
|
217
245
|
|
218
246
|
this._threadBinding = {
|
@@ -61,7 +61,10 @@ export const AssistantRuntimeProviderImpl: FC<
|
|
61
61
|
|
62
62
|
return (
|
63
63
|
<AssistantContext.Provider value={context}>
|
64
|
-
<ThreadRuntimeProvider
|
64
|
+
<ThreadRuntimeProvider
|
65
|
+
runtime={runtime.thread}
|
66
|
+
listItemRuntime={runtime.threadList.mainThreadListItem}
|
67
|
+
>
|
65
68
|
{children}
|
66
69
|
</ThreadRuntimeProvider>
|
67
70
|
</AssistantContext.Provider>
|
@@ -7,8 +7,11 @@ import { writableStore } from "../ReadonlyStore";
|
|
7
7
|
import { ThreadRuntime } from "../../api/ThreadRuntime";
|
8
8
|
import { create } from "zustand";
|
9
9
|
import { ThreadComposerRuntime } from "../../api/ComposerRuntime";
|
10
|
+
import { ThreadListItemRuntime } from "../../api/ThreadListItemRuntime";
|
11
|
+
import { ThreadListItemRuntimeProvider } from "./ThreadListItemRuntimeProvider";
|
10
12
|
|
11
13
|
type ThreadProviderProps = {
|
14
|
+
listItemRuntime: ThreadListItemRuntime;
|
12
15
|
runtime: ThreadRuntime;
|
13
16
|
};
|
14
17
|
|
@@ -49,7 +52,7 @@ const useThreadComposerStore = (runtime: ThreadComposerRuntime) => {
|
|
49
52
|
|
50
53
|
export const ThreadRuntimeProvider: FC<
|
51
54
|
PropsWithChildren<ThreadProviderProps>
|
52
|
-
> = ({ children, runtime }) => {
|
55
|
+
> = ({ children, listItemRuntime: threadListItemRuntime, runtime }) => {
|
53
56
|
const useThreadRuntime = useThreadRuntimeStore(runtime);
|
54
57
|
const useThread = useThreadStore(runtime);
|
55
58
|
const useThreadComposer = useThreadComposerStore(runtime.composer);
|
@@ -66,6 +69,10 @@ export const ThreadRuntimeProvider: FC<
|
|
66
69
|
}, [useThread, useThreadRuntime, useThreadComposer]);
|
67
70
|
|
68
71
|
return (
|
69
|
-
<
|
72
|
+
<ThreadListItemRuntimeProvider runtime={threadListItemRuntime}>
|
73
|
+
<ThreadContext.Provider value={context}>
|
74
|
+
{children}
|
75
|
+
</ThreadContext.Provider>
|
76
|
+
</ThreadListItemRuntimeProvider>
|
70
77
|
);
|
71
78
|
};
|
package/src/internal.ts
CHANGED
@@ -10,7 +10,7 @@ export { AssistantRuntimeImpl } from "./api/AssistantRuntime";
|
|
10
10
|
export {
|
11
11
|
ThreadRuntimeImpl,
|
12
12
|
type ThreadRuntimeCoreBinding,
|
13
|
+
type ThreadListItemRuntimeBinding,
|
13
14
|
} from "./api/ThreadRuntime";
|
14
|
-
export { LocalThreadMetadataRuntimeCore } from "./runtimes/local/LocalThreadMetadataRuntimeCore";
|
15
15
|
|
16
16
|
export * from "./utils/smooth";
|
@@ -20,6 +20,7 @@ import {
|
|
20
20
|
import { useThread, useThreadRuntime } from "../../context/react/ThreadContext";
|
21
21
|
import { useEscapeKeydown } from "@radix-ui/react-use-escape-keydown";
|
22
22
|
import { useOnScrollToBottom } from "../../utils/hooks/useOnScrollToBottom";
|
23
|
+
import { useThreadListItemRuntime } from "../../context/react/ThreadListItemContext";
|
23
24
|
|
24
25
|
export namespace ComposerPrimitiveInput {
|
25
26
|
export type Element = HTMLTextAreaElement;
|
@@ -53,6 +54,7 @@ export const ComposerPrimitiveInput = forwardRef<
|
|
53
54
|
},
|
54
55
|
forwardedRef,
|
55
56
|
) => {
|
57
|
+
const threadListItemRuntime = useThreadListItemRuntime();
|
56
58
|
const threadRuntime = useThreadRuntime();
|
57
59
|
const composerRuntime = useComposerRuntime();
|
58
60
|
|
@@ -124,7 +126,7 @@ export const ComposerPrimitiveInput = forwardRef<
|
|
124
126
|
if (composerRuntime.type !== "thread" || !unstable_focusOnThreadSwitched)
|
125
127
|
return undefined;
|
126
128
|
|
127
|
-
return
|
129
|
+
return threadListItemRuntime.unstable_on("switched-to", focus);
|
128
130
|
}, [unstable_focusOnThreadSwitched]);
|
129
131
|
|
130
132
|
return (
|
@@ -17,7 +17,6 @@ import {
|
|
17
17
|
RuntimeCapabilities,
|
18
18
|
SubmittedFeedback,
|
19
19
|
ThreadRuntimeEventType,
|
20
|
-
ThreadMetadataRuntimeCore,
|
21
20
|
} from "../core/ThreadRuntimeCore";
|
22
21
|
import { DefaultEditComposerRuntimeCore } from "../composer/DefaultEditComposerRuntimeCore";
|
23
22
|
import { SpeechSynthesisAdapter } from "../speech/SpeechAdapterTypes";
|
@@ -46,20 +45,13 @@ export abstract class BaseThreadRuntimeCore implements ThreadRuntimeCore {
|
|
46
45
|
public abstract addToolResult(options: AddToolResultOptions): void;
|
47
46
|
public abstract cancelRun(): void;
|
48
47
|
|
49
|
-
public get metadata() {
|
50
|
-
return this._metadata;
|
51
|
-
}
|
52
|
-
|
53
48
|
public get messages() {
|
54
49
|
return this.repository.getMessages();
|
55
50
|
}
|
56
51
|
|
57
52
|
public readonly composer = new DefaultThreadComposerRuntimeCore(this);
|
58
53
|
|
59
|
-
constructor(
|
60
|
-
private readonly _configProvider: ModelConfigProvider,
|
61
|
-
private readonly _metadata: ThreadMetadataRuntimeCore,
|
62
|
-
) {}
|
54
|
+
constructor(private readonly _configProvider: ModelConfigProvider) {}
|
63
55
|
|
64
56
|
public getModelConfig() {
|
65
57
|
return this._configProvider.getModelConfig();
|
@@ -1,21 +1,30 @@
|
|
1
1
|
import { Unsubscribe } from "../../types";
|
2
|
-
import {
|
2
|
+
import { ThreadRuntimeCore } from "./ThreadRuntimeCore";
|
3
|
+
|
4
|
+
type ThreadListItemCoreState = {
|
5
|
+
readonly threadId: string;
|
6
|
+
readonly state: "archived" | "regular" | "new" | "deleted";
|
7
|
+
readonly title?: string | undefined;
|
8
|
+
|
9
|
+
readonly runtime?: ThreadRuntimeCore | undefined;
|
10
|
+
};
|
3
11
|
|
4
12
|
export type ThreadListRuntimeCore = {
|
5
|
-
|
13
|
+
mainThreadId: string;
|
14
|
+
newThreadId: string | undefined;
|
6
15
|
|
7
|
-
|
8
|
-
|
9
|
-
archivedThreads: readonly string[];
|
16
|
+
threadIds: readonly string[];
|
17
|
+
archivedThreadIds: readonly string[];
|
10
18
|
|
11
|
-
|
19
|
+
getMainThreadRuntimeCore(): ThreadRuntimeCore;
|
20
|
+
getItemById(threadId: string): ThreadListItemCoreState | undefined;
|
12
21
|
|
13
22
|
switchToThread(threadId: string): Promise<void>;
|
14
23
|
switchToNewThread(): Promise<void>;
|
15
24
|
|
16
25
|
// getLoadThreadsPromise(): Promise<void>;
|
17
26
|
// getLoadArchivedThreadsPromise(): Promise<void>;
|
18
|
-
|
27
|
+
|
19
28
|
rename(threadId: string, newTitle: string): Promise<void>;
|
20
29
|
archive(threadId: string): Promise<void>;
|
21
30
|
unarchive(threadId: string): Promise<void>;
|
@@ -43,30 +43,12 @@ export type SubmittedFeedback = {
|
|
43
43
|
readonly type: "negative" | "positive";
|
44
44
|
};
|
45
45
|
|
46
|
-
export type ThreadMetadata = Readonly<{
|
47
|
-
readonly threadId: string;
|
48
|
-
readonly state: "archived" | "regular" | "new" | "deleted";
|
49
|
-
readonly title?: string | undefined;
|
50
|
-
}>;
|
51
|
-
|
52
46
|
export type ThreadRuntimeEventType =
|
53
|
-
| "switched-to"
|
54
|
-
| "switched-away"
|
55
47
|
| "run-start"
|
48
|
+
| "initialize"
|
56
49
|
| "model-config-update";
|
57
50
|
|
58
|
-
export type ThreadMetadataRuntimeCore = ThreadMetadata & {
|
59
|
-
create(title?: string): Promise<void>;
|
60
|
-
rename(newTitle: string): Promise<void>;
|
61
|
-
archive(): Promise<void>;
|
62
|
-
unarchive(): Promise<void>;
|
63
|
-
delete(): Promise<void>;
|
64
|
-
subscribe(callback: () => void): Unsubscribe;
|
65
|
-
};
|
66
|
-
|
67
51
|
export type ThreadRuntimeCore = Readonly<{
|
68
|
-
metadata: ThreadMetadataRuntimeCore;
|
69
|
-
|
70
52
|
getMessageById: (messageId: string) =>
|
71
53
|
| {
|
72
54
|
parentId: string | null;
|
@@ -2,18 +2,32 @@ import { AppendMessage, ThreadMessage } from "../../types";
|
|
2
2
|
import { AttachmentAdapter } from "../attachment";
|
3
3
|
import {
|
4
4
|
AddToolResultOptions,
|
5
|
-
ThreadMetadata,
|
6
5
|
ThreadSuggestion,
|
7
6
|
} from "../core/ThreadRuntimeCore";
|
8
7
|
import { FeedbackAdapter } from "../feedback/FeedbackAdapter";
|
9
8
|
import { SpeechSynthesisAdapter } from "../speech/SpeechAdapterTypes";
|
10
9
|
import { ThreadMessageLike } from "./ThreadMessageLike";
|
11
10
|
|
11
|
+
export type ExternalStoreThreadData<TState extends "regular" | "archived"> = {
|
12
|
+
state: TState;
|
13
|
+
threadId: string;
|
14
|
+
title?: string | undefined;
|
15
|
+
};
|
16
|
+
|
12
17
|
export type ExternalStoreThreadListAdapter = {
|
18
|
+
/**
|
19
|
+
* @deprecated This API is still under active development and might change without notice.
|
20
|
+
*/
|
13
21
|
threadId?: string | undefined;
|
14
|
-
threads?: readonly
|
15
|
-
archivedThreads?: readonly
|
22
|
+
threads?: readonly ExternalStoreThreadData<"regular">[] | undefined;
|
23
|
+
archivedThreads?: readonly ExternalStoreThreadData<"archived">[] | undefined;
|
24
|
+
/**
|
25
|
+
* @deprecated This API is still under active development and might change without notice.
|
26
|
+
*/
|
16
27
|
onSwitchToNewThread?: (() => Promise<void> | void) | undefined;
|
28
|
+
/**
|
29
|
+
* @deprecated This API is still under active development and might change without notice.
|
30
|
+
*/
|
17
31
|
onSwitchToThread?: ((threadId: string) => Promise<void> | void) | undefined;
|
18
32
|
onRename?: (
|
19
33
|
threadId: string,
|
@@ -54,6 +68,9 @@ type ExternalStoreAdapterBase<T> = {
|
|
54
68
|
attachments?: AttachmentAdapter | undefined;
|
55
69
|
speech?: SpeechSynthesisAdapter | undefined;
|
56
70
|
feedback?: FeedbackAdapter | undefined;
|
71
|
+
/**
|
72
|
+
* @deprecated This API is still under active development and might change without notice.
|
73
|
+
*/
|
57
74
|
threadList?: ExternalStoreThreadListAdapter | undefined;
|
58
75
|
}
|
59
76
|
| undefined;
|
@@ -12,25 +12,18 @@ const getThreadListAdapter = (store: ExternalStoreAdapter<any>) => {
|
|
12
12
|
export class ExternalStoreRuntimeCore extends BaseAssistantRuntimeCore {
|
13
13
|
public readonly threadList;
|
14
14
|
|
15
|
-
private _store: ExternalStoreAdapter<any>;
|
16
|
-
|
17
15
|
constructor(store: ExternalStoreAdapter<any>) {
|
18
16
|
super();
|
19
|
-
this._store = store;
|
20
17
|
this.threadList = new ExternalStoreThreadListRuntimeCore(
|
21
18
|
getThreadListAdapter(store),
|
22
|
-
(
|
23
|
-
new ExternalStoreThreadRuntimeCore(
|
24
|
-
this._proxyConfigProvider,
|
25
|
-
threadId,
|
26
|
-
this._store,
|
27
|
-
),
|
19
|
+
() =>
|
20
|
+
new ExternalStoreThreadRuntimeCore(this._proxyConfigProvider, store),
|
28
21
|
);
|
29
22
|
}
|
30
23
|
|
31
24
|
public setStore(store: ExternalStoreAdapter<any>) {
|
32
|
-
|
33
|
-
this.threadList.
|
34
|
-
this.threadList.
|
25
|
+
// Update the thread list adapter and propagate store changes to the main thread
|
26
|
+
this.threadList.__internal_setAdapter(getThreadListAdapter(store));
|
27
|
+
this.threadList.getMainThreadRuntimeCore().__internal_setStore(store);
|
35
28
|
}
|
36
29
|
}
|
@@ -3,9 +3,7 @@ import { ExternalStoreThreadRuntimeCore } from "./ExternalStoreThreadRuntimeCore
|
|
3
3
|
import { ThreadListRuntimeCore } from "../core/ThreadListRuntimeCore";
|
4
4
|
import { ExternalStoreThreadListAdapter } from "./ExternalStoreAdapter";
|
5
5
|
|
6
|
-
export type ExternalStoreThreadFactory = (
|
7
|
-
threadId: string,
|
8
|
-
) => ExternalStoreThreadRuntimeCore;
|
6
|
+
export type ExternalStoreThreadFactory = () => ExternalStoreThreadRuntimeCore;
|
9
7
|
|
10
8
|
const EMPTY_ARRAY = Object.freeze([]);
|
11
9
|
const DEFAULT_THREAD_ID = "DEFAULT_THREAD_ID";
|
@@ -13,35 +11,40 @@ const DEFAULT_THREAD_ID = "DEFAULT_THREAD_ID";
|
|
13
11
|
export class ExternalStoreThreadListRuntimeCore
|
14
12
|
implements ThreadListRuntimeCore
|
15
13
|
{
|
16
|
-
private
|
17
|
-
private
|
14
|
+
private _mainThreadId: string = DEFAULT_THREAD_ID;
|
15
|
+
private _threads: readonly string[] = EMPTY_ARRAY;
|
16
|
+
private _archivedThreads: readonly string[] = EMPTY_ARRAY;
|
18
17
|
|
19
|
-
public get
|
18
|
+
public get newThreadId() {
|
20
19
|
return undefined;
|
21
20
|
}
|
22
21
|
|
23
|
-
public get
|
22
|
+
public get threadIds() {
|
24
23
|
return this._threads;
|
25
24
|
}
|
26
25
|
|
27
|
-
public get
|
26
|
+
public get archivedThreadIds() {
|
28
27
|
return this._archivedThreads;
|
29
28
|
}
|
30
29
|
|
31
30
|
private _mainThread: ExternalStoreThreadRuntimeCore;
|
32
31
|
|
33
|
-
public get
|
34
|
-
return this.
|
32
|
+
public get mainThreadId() {
|
33
|
+
return this._mainThreadId;
|
35
34
|
}
|
36
35
|
|
37
36
|
constructor(
|
38
37
|
private adapter: ExternalStoreThreadListAdapter = {},
|
39
38
|
private threadFactory: ExternalStoreThreadFactory,
|
40
39
|
) {
|
41
|
-
this._mainThread = this.threadFactory(
|
40
|
+
this._mainThread = this.threadFactory();
|
41
|
+
}
|
42
|
+
|
43
|
+
public getMainThreadRuntimeCore() {
|
44
|
+
return this._mainThread;
|
42
45
|
}
|
43
46
|
|
44
|
-
public
|
47
|
+
public getItemById(threadId: string) {
|
45
48
|
for (const thread of this.adapter.threads ?? []) {
|
46
49
|
if (thread.threadId === threadId) return thread;
|
47
50
|
}
|
@@ -51,7 +54,7 @@ export class ExternalStoreThreadListRuntimeCore
|
|
51
54
|
return undefined;
|
52
55
|
}
|
53
56
|
|
54
|
-
public
|
57
|
+
public __internal_setAdapter(adapter: ExternalStoreThreadListAdapter) {
|
55
58
|
const previousAdapter = this.adapter;
|
56
59
|
this.adapter = adapter;
|
57
60
|
|
@@ -72,42 +75,26 @@ export class ExternalStoreThreadListRuntimeCore
|
|
72
75
|
return;
|
73
76
|
}
|
74
77
|
|
75
|
-
if (
|
78
|
+
if (previousThreads !== newThreads) {
|
76
79
|
this._threads =
|
77
80
|
this.adapter.threads?.map((t) => t.threadId) ?? EMPTY_ARRAY;
|
78
81
|
}
|
79
82
|
|
80
|
-
if (
|
83
|
+
if (previousArchivedThreads !== newArchivedThreads) {
|
81
84
|
this._archivedThreads =
|
82
85
|
this.adapter.archivedThreads?.map((t) => t.threadId) ?? EMPTY_ARRAY;
|
83
86
|
}
|
84
87
|
|
85
|
-
if (
|
86
|
-
this.
|
87
|
-
this._mainThread = this.threadFactory(
|
88
|
-
this._mainThread._notifyEventSubscribers("switched-to");
|
89
|
-
}
|
90
|
-
|
91
|
-
const previousMainState = this._mainThread.metadata.state;
|
92
|
-
const mainState = this.archivedThreads.includes(
|
93
|
-
this._mainThread.metadata.threadId,
|
94
|
-
)
|
95
|
-
? "archived"
|
96
|
-
: "regular";
|
97
|
-
|
98
|
-
if (previousMainState !== mainState) {
|
99
|
-
if (mainState === "archived") {
|
100
|
-
this._mainThread.metadata.archive();
|
101
|
-
} else {
|
102
|
-
this._mainThread.metadata.unarchive();
|
103
|
-
}
|
88
|
+
if (previousThreadId !== newThreadId) {
|
89
|
+
this._mainThreadId = newThreadId;
|
90
|
+
this._mainThread = this.threadFactory();
|
104
91
|
}
|
105
92
|
|
106
93
|
this._notifySubscribers();
|
107
94
|
}
|
108
95
|
|
109
96
|
public async switchToThread(threadId: string): Promise<void> {
|
110
|
-
if (this.
|
97
|
+
if (this._mainThreadId === threadId) return;
|
111
98
|
const onSwitchToThread = this.adapter.onSwitchToThread;
|
112
99
|
if (!onSwitchToThread)
|
113
100
|
throw new Error(
|
@@ -18,7 +18,6 @@ import {
|
|
18
18
|
ThreadRuntimeCore,
|
19
19
|
} from "../core/ThreadRuntimeCore";
|
20
20
|
import { BaseThreadRuntimeCore } from "../core/BaseThreadRuntimeCore";
|
21
|
-
import { LocalThreadMetadataRuntimeCore } from "../local/LocalThreadMetadataRuntimeCore";
|
22
21
|
|
23
22
|
const EMPTY_ARRAY = Object.freeze([]);
|
24
23
|
|
@@ -77,16 +76,13 @@ export class ExternalStoreThreadRuntimeCore
|
|
77
76
|
|
78
77
|
constructor(
|
79
78
|
configProvider: ModelConfigProvider,
|
80
|
-
threadId: string,
|
81
79
|
store: ExternalStoreAdapter<any>,
|
82
80
|
) {
|
83
|
-
|
84
|
-
|
85
|
-
super(configProvider, metadata);
|
86
|
-
this.setStore(store);
|
81
|
+
super(configProvider);
|
82
|
+
this.__internal_setStore(store);
|
87
83
|
}
|
88
84
|
|
89
|
-
public
|
85
|
+
public __internal_setStore(store: ExternalStoreAdapter<any>) {
|
90
86
|
if (this._store === store) return;
|
91
87
|
|
92
88
|
const isRunning = store.isRunning ?? false;
|
@@ -31,10 +31,9 @@ export class LocalRuntimeCore extends BaseAssistantRuntimeCore {
|
|
31
31
|
|
32
32
|
this._options = options;
|
33
33
|
|
34
|
-
this.threadList = new LocalThreadListRuntimeCore((
|
34
|
+
this.threadList = new LocalThreadListRuntimeCore((data) => {
|
35
35
|
const thread = new LocalThreadRuntimeCore(
|
36
36
|
this._proxyConfigProvider,
|
37
|
-
threadId,
|
38
37
|
this._options,
|
39
38
|
);
|
40
39
|
thread.import(data);
|
@@ -42,18 +41,12 @@ export class LocalRuntimeCore extends BaseAssistantRuntimeCore {
|
|
42
41
|
});
|
43
42
|
|
44
43
|
if (initialMessages) {
|
45
|
-
this.threadList
|
46
|
-
|
47
|
-
|
44
|
+
this.threadList
|
45
|
+
.getMainThreadRuntimeCore()
|
46
|
+
.import(getExportFromInitialMessages(initialMessages));
|
48
47
|
}
|
49
48
|
}
|
50
49
|
|
51
|
-
public setOptions(options: LocalRuntimeOptionsBase) {
|
52
|
-
this._options = options;
|
53
|
-
|
54
|
-
this.threadList.mainThread.setOptions(options);
|
55
|
-
}
|
56
|
-
|
57
50
|
public reset({
|
58
51
|
initialMessages,
|
59
52
|
}: {
|
@@ -62,8 +55,8 @@ export class LocalRuntimeCore extends BaseAssistantRuntimeCore {
|
|
62
55
|
this.threadList.switchToNewThread();
|
63
56
|
if (!initialMessages) return;
|
64
57
|
|
65
|
-
this.threadList
|
66
|
-
|
67
|
-
|
58
|
+
this.threadList
|
59
|
+
.getMainThreadRuntimeCore()
|
60
|
+
.import(getExportFromInitialMessages(initialMessages));
|
68
61
|
}
|
69
62
|
}
|