@assistant-ui/react 0.10.47 → 0.10.49

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/package.json CHANGED
@@ -28,7 +28,7 @@
28
28
  "conversational-ui",
29
29
  "conversational-ai"
30
30
  ],
31
- "version": "0.10.47",
31
+ "version": "0.10.49",
32
32
  "license": "MIT",
33
33
  "type": "module",
34
34
  "exports": {
@@ -114,11 +114,18 @@ export class ThreadListItemRuntimeImpl implements ThreadListItemRuntime {
114
114
  }
115
115
 
116
116
  public unstable_on(event: ThreadListItemEventType, callback: () => void) {
117
+ // if the runtime is bound to a specific thread, trigger if isMain is toggled
118
+ // if the runtime is bound to the main thread, trigger switched-to if threadId changes
119
+
117
120
  let prevIsMain = this._core.getState().isMain;
121
+ let prevThreadId = this._core.getState().id;
118
122
  return this.subscribe(() => {
119
- const newIsMain = this._core.getState().isMain;
120
- if (prevIsMain === newIsMain) return;
123
+ const currentState = this._core.getState();
124
+ const newIsMain = currentState.isMain;
125
+ const newThreadId = currentState.id;
126
+ if (prevIsMain === newIsMain && prevThreadId === newThreadId) return;
121
127
  prevIsMain = newIsMain;
128
+ prevThreadId = newThreadId;
122
129
 
123
130
  if (event === "switched-to" && !newIsMain) return;
124
131
  if (event === "switched-away" && newIsMain) return;
@@ -14,6 +14,12 @@ import {
14
14
  import { GenericThreadHistoryAdapter } from "../runtimes/adapters/thread-history/ThreadHistoryAdapter";
15
15
  import { ReadonlyJSONObject } from "assistant-stream/utils";
16
16
 
17
+ // Global WeakMap to store message ID mappings across adapter instances
18
+ const globalMessageIdMapping = new WeakMap<
19
+ ThreadListItemRuntime,
20
+ Record<string, string | Promise<string>>
21
+ >();
22
+
17
23
  class FormattedThreadHistoryAdapter<TMessage, TStorageFormat>
18
24
  implements GenericThreadHistoryAdapter<TMessage>
19
25
  {
@@ -52,7 +58,12 @@ class AssistantCloudThreadHistoryAdapter implements ThreadHistoryAdapter {
52
58
  private threadListItemRuntime: ThreadListItemRuntime,
53
59
  ) {}
54
60
 
55
- private _getIdForLocalId: Record<string, string | Promise<string>> = {};
61
+ private get _getIdForLocalId(): Record<string, string | Promise<string>> {
62
+ if (!globalMessageIdMapping.has(this.threadListItemRuntime)) {
63
+ globalMessageIdMapping.set(this.threadListItemRuntime, {});
64
+ }
65
+ return globalMessageIdMapping.get(this.threadListItemRuntime)!;
66
+ }
56
67
 
57
68
  withFormat<TMessage, TStorageFormat>(
58
69
  formatAdapter: MessageFormatAdapter<TMessage, TStorageFormat>,