@assistant-ui/react 0.10.34 → 0.10.35
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 +3 -1
- package/dist/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.js.map +1 -1
- package/package.json +1 -1
- package/src/runtimes/remote-thread-list/RemoteThreadListHookInstanceManager.tsx +3 -1
@@ -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;AAMf,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,
|
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;AAMf,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,CAqDhC;IAEF,OAAO,CAAC,0BAA0B,CAkB/B;IAEI,+BAA+B,EAAE,EAAE,CAAC;QACzC,QAAQ,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAAC;KAC5C,CAAC,CAUA;CACH"}
|
@@ -84,11 +84,13 @@ var RemoteThreadListHookInstanceManager = class extends BaseSubscribable {
|
|
84
84
|
}, [threadBinding, updateRuntime]);
|
85
85
|
useEffect(() => {
|
86
86
|
return runtime.threads.main.unstable_on("initialize", () => {
|
87
|
-
const threadListItemRuntime = runtime.threads.
|
87
|
+
const threadListItemRuntime = runtime.threads.mainItem;
|
88
|
+
if (threadListItemRuntime.getState().id !== id) return;
|
88
89
|
if (threadListItemRuntime.getState().status === "new") {
|
89
90
|
threadListItemRuntime.initialize();
|
90
91
|
const dispose = runtime.thread.unstable_on("run-end", () => {
|
91
92
|
dispose();
|
93
|
+
if (threadListItemRuntime.getState().id !== id) return;
|
92
94
|
threadListItemRuntime.generateTitle();
|
93
95
|
});
|
94
96
|
}
|
@@ -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 { useThreadListItem } 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 useEffect(() => {\n return runtime.threads.main.unstable_on(\"initialize\", () => {\n const threadListItemRuntime = runtime.threads.
|
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 { useThreadListItem } 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 useEffect(() => {\n return runtime.threads.main.unstable_on(\"initialize\", () => {\n const threadListItemRuntime = runtime.threads.mainItem;\n if (threadListItemRuntime.getState().id !== id) return;\n\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 if (threadListItemRuntime.getState().id !== id) return;\n threadListItemRuntime.generateTitle();\n });\n }\n });\n }, [runtime, id]);\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,EAC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,CAAC,EAAE,UAAU,UAAU,SAAS,MAAM;AAC9C,UAAM,mBAAmB,oBAAoB;AAC7C,UAAM,wBAAwB;AAAA,MAC5B,MAAM,iBAAiB,QAAQ,YAAY,QAAQ;AAAA,MACnD,CAAC,kBAAkB,QAAQ;AAAA,IAC7B;AAEA,WACE,oBAAC,iCAA8B,SAAS,uBACtC,8BAAC,YACC,8BAAC,KAAK,4BAAL,EAAgC,GACnC,GACF;AAAA,EAEJ,CAAC;AAAA,EAEM,kCAEF,CAAC,EAAE,SAAS,MAAM;AACrB,SAAK,2BAA2B;AAEhC,WAAO,MAAM,KAAK,KAAK,UAAU,KAAK,CAAC,EAAE,IAAI,CAAC,aAC5C;AAAA,MAAC,KAAK;AAAA,MAAL;AAAA,QAEC;AAAA,QACA;AAAA;AAAA,MAFK;AAAA,IAGP,CACD;AAAA,EACH;AACF;","names":[]}
|
package/package.json
CHANGED
@@ -113,7 +113,8 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
113
113
|
// auto initialize thread
|
114
114
|
useEffect(() => {
|
115
115
|
return runtime.threads.main.unstable_on("initialize", () => {
|
116
|
-
const threadListItemRuntime = runtime.threads.
|
116
|
+
const threadListItemRuntime = runtime.threads.mainItem;
|
117
|
+
if (threadListItemRuntime.getState().id !== id) return;
|
117
118
|
|
118
119
|
if (threadListItemRuntime.getState().status === "new") {
|
119
120
|
threadListItemRuntime.initialize();
|
@@ -122,6 +123,7 @@ export class RemoteThreadListHookInstanceManager extends BaseSubscribable {
|
|
122
123
|
const dispose = runtime.thread.unstable_on("run-end", () => {
|
123
124
|
dispose();
|
124
125
|
|
126
|
+
if (threadListItemRuntime.getState().id !== id) return;
|
125
127
|
threadListItemRuntime.generateTitle();
|
126
128
|
});
|
127
129
|
}
|