@assistant-ui/react 0.10.36 → 0.10.37
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/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.d.ts.map +1 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js +6 -5
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/package.json +1 -1
- package/src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +6 -6
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"RemoteThreadListHookInstanceManager.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,EAAE,EAMF,iBAAiB,EACjB,aAAa,EACd,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"RemoteThreadListHookInstanceManager.d.ts","sourceRoot":"","sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx"],"names":[],"mappings":"AAGA,OAAO,EACL,EAAE,EAMF,iBAAiB,EACjB,aAAa,EACd,MAAM,OAAO,CAAC;AASf,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7C,KAAK,oBAAoB,GAAG,MAAM,gBAAgB,CAAC;AAKnD,qBAAa,mCAAoC,SAAQ,gBAAgB;IACvE,OAAO,CAAC,cAAc,CAEpB;IACF,OAAO,CAAC,SAAS,CAAmD;IACpE,OAAO,CAAC,0BAA0B,CAAsB;gBAE5C,WAAW,EAAE,oBAAoB;IAKtC,kBAAkB,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwBnC,oBAAoB,CAAC,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAMrC,iBAAiB,CAAC,QAAQ,EAAE,MAAM;IAKlC,cAAc,CAAC,cAAc,EAAE,oBAAoB;IAO1D,OAAO,CAAC,0BAA0B,CAkDhC;IAEF,OAAO,CAAC,0BAA0B,CAkB/B;IAEI,+BAA+B,EAAE,EAAE,CAAC;QACzC,QAAQ,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;KAC5C,CAAC,CAUA;CACH"}
|
@@ -11,7 +11,10 @@ import {
|
|
11
11
|
import { create } from "zustand";
|
12
12
|
import { useAssistantRuntime } from "../../context/index.js";
|
13
13
|
import { ThreadListItemRuntimeProvider } from "../../context/providers/ThreadListItemRuntimeProvider.js";
|
14
|
-
import {
|
14
|
+
import {
|
15
|
+
useThreadListItem,
|
16
|
+
useThreadListItemRuntime
|
17
|
+
} from "../../context/react/ThreadListItemContext.js";
|
15
18
|
import { BaseSubscribable } from "./BaseSubscribable.js";
|
16
19
|
import { jsx } from "react/jsx-runtime";
|
17
20
|
var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
@@ -82,20 +85,18 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
82
85
|
updateRuntime();
|
83
86
|
return threadBinding.outerSubscribe(updateRuntime);
|
84
87
|
}, [threadBinding, updateRuntime]);
|
88
|
+
const threadListItemRuntime = useThreadListItemRuntime();
|
85
89
|
useEffect(() => {
|
86
90
|
return runtime.threads.main.unstable_on("initialize", () => {
|
87
|
-
const threadListItemRuntime = runtime.threads.mainItem;
|
88
|
-
if (threadListItemRuntime.getState().id !== id) return;
|
89
91
|
if (threadListItemRuntime.getState().status === "new") {
|
90
92
|
threadListItemRuntime.initialize();
|
91
93
|
const dispose = runtime.thread.unstable_on("run-end", () => {
|
92
94
|
dispose();
|
93
|
-
if (threadListItemRuntime.getState().id !== id) return;
|
94
95
|
threadListItemRuntime.generateTitle();
|
95
96
|
});
|
96
97
|
}
|
97
98
|
});
|
98
|
-
}, [runtime,
|
99
|
+
}, [runtime, threadListItemRuntime]);
|
99
100
|
return null;
|
100
101
|
};
|
101
102
|
_OuterActiveThreadProvider = memo(({ threadId, provider: Provider }) => {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx"],"sourcesContent":["/* eslint-disable react-hooks/rules-of-hooks */\n\"use client\";\n\nimport {\n FC,\n useCallback,\n useRef,\n useEffect,\n memo,\n useMemo,\n PropsWithChildren,\n ComponentType,\n} from \"react\";\nimport { UseBoundStore, StoreApi, create } from \"zustand\";\nimport { useAssistantRuntime } from \"../../context\";\nimport { ThreadListItemRuntimeProvider } from \"../../context/providers/ThreadListItemRuntimeProvider\";\nimport {
|
1
|
+
{"version":3,"sources":["../../../src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx"],"sourcesContent":["/* eslint-disable react-hooks/rules-of-hooks */\n\"use client\";\n\nimport {\n FC,\n useCallback,\n useRef,\n useEffect,\n memo,\n useMemo,\n PropsWithChildren,\n ComponentType,\n} from \"react\";\nimport { UseBoundStore, StoreApi, create } from \"zustand\";\nimport { useAssistantRuntime } from \"../../context\";\nimport { ThreadListItemRuntimeProvider } from \"../../context/providers/ThreadListItemRuntimeProvider\";\nimport {\n useThreadListItem,\n useThreadListItemRuntime,\n} from \"../../context/react/ThreadListItemContext\";\nimport { ThreadRuntimeCore, ThreadRuntimeImpl } from \"../../internal\";\nimport { BaseSubscribable } from \"./BaseSubscribable\";\nimport { AssistantRuntime } from \"../../api\";\n\ntype RemoteThreadListHook = () => AssistantRuntime;\n\ntype RemoteThreadListHookInstance = {\n runtime?: ThreadRuntimeCore;\n};\nexport class RemoteThreadListHookInstanceManager extends BaseSubscribable {\n private useRuntimeHook: UseBoundStore<\n StoreApi<{ useRuntime: RemoteThreadListHook }>\n >;\n private instances = new Map<string, RemoteThreadListHookInstance>();\n private useAliveThreadsKeysChanged = create(() => ({}));\n\n constructor(runtimeHook: RemoteThreadListHook) {\n super();\n this.useRuntimeHook = create(() => ({ useRuntime: runtimeHook }));\n }\n\n public startThreadRuntime(threadId: string) {\n if (!this.instances.has(threadId)) {\n this.instances.set(threadId, {});\n this.useAliveThreadsKeysChanged.setState({}, true);\n }\n\n return new Promise<ThreadRuntimeCore>((resolve, reject) => {\n const callback = () => {\n const instance = this.instances.get(threadId);\n if (!instance) {\n dispose();\n reject(new Error(\"Thread was deleted before runtime was started\"));\n } else if (!instance.runtime) {\n return; // misc update\n } else {\n dispose();\n resolve(instance.runtime);\n }\n };\n const dispose = this.subscribe(callback);\n callback();\n });\n }\n\n public getThreadRuntimeCore(threadId: string) {\n const instance = this.instances.get(threadId);\n if (!instance) return undefined;\n return instance.runtime;\n }\n\n public stopThreadRuntime(threadId: string) {\n this.instances.delete(threadId);\n this.useAliveThreadsKeysChanged.setState({}, true);\n }\n\n public setRuntimeHook(newRuntimeHook: RemoteThreadListHook) {\n const prevRuntimeHook = this.useRuntimeHook.getState().useRuntime;\n if (prevRuntimeHook !== newRuntimeHook) {\n this.useRuntimeHook.setState({ useRuntime: newRuntimeHook }, true);\n }\n }\n\n private _InnerActiveThreadProvider: FC = () => {\n const { id } = useThreadListItem();\n\n const { useRuntime } = this.useRuntimeHook();\n const runtime = useRuntime();\n\n const threadBinding = (runtime.thread as ThreadRuntimeImpl)\n .__internal_threadBinding;\n\n const updateRuntime = useCallback(() => {\n const aliveThread = this.instances.get(id);\n if (!aliveThread)\n throw new Error(\"Thread not found. This is a bug in assistant-ui.\");\n\n aliveThread.runtime = threadBinding.getState();\n\n if (isMounted) {\n this._notifySubscribers();\n }\n }, [id, threadBinding]);\n\n const isMounted = useRef(false);\n if (!isMounted.current) {\n updateRuntime();\n }\n\n useEffect(() => {\n isMounted.current = true;\n updateRuntime();\n return threadBinding.outerSubscribe(updateRuntime);\n }, [threadBinding, updateRuntime]);\n\n // auto initialize thread\n const threadListItemRuntime = useThreadListItemRuntime();\n useEffect(() => {\n return runtime.threads.main.unstable_on(\"initialize\", () => {\n if (threadListItemRuntime.getState().status === \"new\") {\n threadListItemRuntime.initialize();\n\n // auto generate a title after first run\n const dispose = runtime.thread.unstable_on(\"run-end\", () => {\n dispose();\n\n threadListItemRuntime.generateTitle();\n });\n }\n });\n }, [runtime, threadListItemRuntime]);\n\n return null;\n };\n\n private _OuterActiveThreadProvider: FC<{\n threadId: string;\n provider: ComponentType<PropsWithChildren>;\n // eslint-disable-next-line react/display-name\n }> = memo(({ threadId, provider: Provider }) => {\n const assistantRuntime = useAssistantRuntime();\n const threadListItemRuntime = useMemo(\n () => assistantRuntime.threads.getItemById(threadId),\n [assistantRuntime, threadId],\n );\n\n return (\n <ThreadListItemRuntimeProvider runtime={threadListItemRuntime}>\n <Provider>\n <this._InnerActiveThreadProvider />\n </Provider>\n </ThreadListItemRuntimeProvider>\n );\n });\n\n public __internal_RenderThreadRuntimes: FC<{\n provider: ComponentType<PropsWithChildren>;\n }> = ({ provider }) => {\n this.useAliveThreadsKeysChanged(); // trigger re-render on alive threads change\n\n return Array.from(this.instances.keys()).map((threadId) => (\n <this._OuterActiveThreadProvider\n key={threadId}\n threadId={threadId}\n provider={provider}\n />\n ));\n };\n}\n"],"mappings":";;;AAGA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAkC,cAAc;AAChD,SAAS,2BAA2B;AACpC,SAAS,qCAAqC;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAEP,SAAS,wBAAwB;AAgIvB;AAxHH,IAAM,sCAAN,cAAkD,iBAAiB;AAAA,EAChE;AAAA,EAGA,YAAY,oBAAI,IAA0C;AAAA,EAC1D,6BAA6B,OAAO,OAAO,CAAC,EAAE;AAAA,EAEtD,YAAY,aAAmC;AAC7C,UAAM;AACN,SAAK,iBAAiB,OAAO,OAAO,EAAE,YAAY,YAAY,EAAE;AAAA,EAClE;AAAA,EAEO,mBAAmB,UAAkB;AAC1C,QAAI,CAAC,KAAK,UAAU,IAAI,QAAQ,GAAG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AACF;","names":[]}
|
package/package.json
CHANGED
@@ -14,7 +14,10 @@ import {
|
|
14
14
|
import { UseBoundStore, StoreApi, create } from "zustand";
|
15
15
|
import { useAssistantRuntime } from "../../context";
|
16
16
|
import { ThreadListItemRuntimeProvider } from "../../context/providers/ThreadListItemRuntimeProvider";
|
17
|
-
import {
|
17
|
+
import {
|
18
|
+
useThreadListItem,
|
19
|
+
useThreadListItemRuntime,
|
20
|
+
} from "../../context/react/ThreadListItemContext";
|
18
21
|
import { ThreadRuntimeCore, ThreadRuntimeImpl } from "../../internal";
|
19
22
|
import { BaseSubscribable } from "./BaseSubscribable";
|
20
23
|
import { AssistantRuntime } from "../../api";
|
@@ -111,11 +114,9 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
111
114
|
}, [threadBinding, updateRuntime]);
|
112
115
|
|
113
116
|
// auto initialize thread
|
117
|
+
const threadListItemRuntime = useThreadListItemRuntime();
|
114
118
|
useEffect(() => {
|
115
119
|
return runtime.threads.main.unstable_on("initialize", () => {
|
116
|
-
const threadListItemRuntime = runtime.threads.mainItem;
|
117
|
-
if (threadListItemRuntime.getState().id !== id) return;
|
118
|
-
|
119
120
|
if (threadListItemRuntime.getState().status === "new") {
|
120
121
|
threadListItemRuntime.initialize();
|
121
122
|
|
@@ -123,12 +124,11 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
123
124
|
const dispose = runtime.thread.unstable_on("run-end", () => {
|
124
125
|
dispose();
|
125
126
|
|
126
|
-
if (threadListItemRuntime.getState().id !== id) return;
|
127
127
|
threadListItemRuntime.generateTitle();
|
128
128
|
});
|
129
129
|
}
|
130
130
|
});
|
131
|
-
}, [runtime,
|
131
|
+
}, [runtime, threadListItemRuntime]);
|
132
132
|
|
133
133
|
return null;
|
134
134
|
};
|