@assistant-ui/react 0.5.99 → 0.5.100

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"ExternalStoreThreadListRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,8BAA8B,EAAE,MAAM,kCAAkC,CAAC;AAClF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,8BAA8B,EAAE,MAAM,wBAAwB,CAAC;AAExE,MAAM,MAAM,0BAA0B,GAAG,CACvC,QAAQ,EAAE,MAAM,KACb,8BAA8B,CAAC;AAKpC,qBAAa,kCACX,YAAW,qBAAqB;IAiB9B,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,aAAa;IAhBvB,IAAW,OAAO;;;SAEjB;IAED,IAAW,eAAe;;;SAEzB;IAED,OAAO,CAAC,WAAW,CAAiC;IAEpD,IAAW,UAAU,mCAEpB;gBAGS,OAAO,EAAE,8BAA8B,YAAK,EAC5C,aAAa,EAAE,0BAA0B;IAK5C,qBAAqB,CAAC,QAAQ,EAAE,MAAM;;;;IAUtC,UAAU,CAAC,OAAO,EAAE,8BAA8B;IAyBlD,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAUtC,iBAAiB,IAAI,IAAI;IAUnB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQzD,OAAO,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQxC,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ1C,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpD,OAAO,CAAC,cAAc,C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C;IAQpD,OAAO,CAAC,cAAc,CAAyB;IAExC,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,WAAW;IAKnD,OAAO,CAAC,kBAAkB;CAG3B"}
@@ -56,7 +56,10 @@ var ExternalStoreThreadListRuntimeCore = class {
56
56
  const newThreadId = adapter.threadId ?? DEFAULT_THREAD_ID;
57
57
  const newThreads = adapter.threads ?? EMPTY_ARRAY;
58
58
  const newArchivedThreads = adapter.archivedThreads ?? EMPTY_ARRAY;
59
- if (previousAdapter.threadId === newThreadId && previousAdapter.threads === newThreads && previousAdapter.archivedThreads === newArchivedThreads) {
59
+ const previousThreadId = previousAdapter.threadId ?? DEFAULT_THREAD_ID;
60
+ const previousThreads = previousAdapter.threads ?? EMPTY_ARRAY;
61
+ const previousArchivedThreads = previousAdapter.archivedThreads ?? EMPTY_ARRAY;
62
+ if (previousThreadId === newThreadId && previousThreads === newThreads && previousArchivedThreads === newArchivedThreads) {
60
63
  return;
61
64
  }
62
65
  if (previousAdapter.threadId !== newThreadId) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ExternalStoreThreadRuntimeCore } from \"./ExternalStoreThreadRuntimeCore\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { ExternalStoreThreadListAdapter } from \"./ExternalStoreAdapter\";\n\nexport type ExternalStoreThreadFactory = (\n threadId: string,\n) => ExternalStoreThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst DEFAULT_THREAD_ID = \"DEFAULT_THREAD_ID\";\n\nexport class ExternalStoreThreadListRuntimeCore\n implements ThreadListRuntimeCore\n{\n public get threads() {\n return this.adapter.threads ?? EMPTY_ARRAY;\n }\n\n public get archivedThreads() {\n return this.adapter.archivedThreads ?? EMPTY_ARRAY;\n }\n\n private _mainThread: ExternalStoreThreadRuntimeCore;\n\n public get mainThread() {\n return this._mainThread;\n }\n\n constructor(\n private adapter: ExternalStoreThreadListAdapter = {},\n private threadFactory: ExternalStoreThreadFactory,\n ) {\n this._mainThread = this.threadFactory(DEFAULT_THREAD_ID);\n }\n\n public getThreadMetadataById(threadId: string) {\n for (const thread of this.threads) {\n if (thread.threadId === threadId) return thread;\n }\n for (const thread of this.archivedThreads) {\n if (thread.threadId === threadId) return thread;\n }\n return undefined;\n }\n\n public setAdapter(adapter: ExternalStoreThreadListAdapter) {\n const previousAdapter = this.adapter;\n this.adapter = adapter;\n\n const newThreadId = adapter.threadId ?? DEFAULT_THREAD_ID;\n const newThreads = adapter.threads ?? EMPTY_ARRAY;\n const newArchivedThreads = adapter.archivedThreads ?? EMPTY_ARRAY;\n\n if (\n previousAdapter.threadId === newThreadId &&\n previousAdapter.threads === newThreads &&\n previousAdapter.archivedThreads === newArchivedThreads\n ) {\n return;\n }\n\n if (previousAdapter.threadId !== newThreadId) {\n this._mainThread._notifyEventSubscribers(\"switched-away\");\n this._mainThread = this.threadFactory(newThreadId);\n this._mainThread._notifyEventSubscribers(\"switched-to\");\n }\n\n this._notifySubscribers();\n }\n\n public switchToThread(threadId: string): void {\n if (this._mainThread?.threadId === threadId) return;\n const onSwitchToThread = this.adapter.onSwitchToThread;\n if (!onSwitchToThread)\n throw new Error(\n \"External store adapter does not support switching to thread\",\n );\n onSwitchToThread(threadId);\n }\n\n public switchToNewThread(): void {\n const onSwitchToNewThread = this.adapter.onSwitchToNewThread;\n if (!onSwitchToNewThread)\n throw new Error(\n \"External store adapter does not support switching to new thread\",\n );\n\n onSwitchToNewThread();\n }\n\n public async rename(threadId: string, newTitle: string): Promise<void> {\n const onRename = this.adapter.onRename;\n if (!onRename)\n throw new Error(\"External store adapter does not support renaming\");\n\n onRename(threadId, newTitle);\n }\n\n public async archive(threadId: string): Promise<void> {\n const onArchive = this.adapter.onArchive;\n if (!onArchive)\n throw new Error(\"External store adapter does not support archiving\");\n\n onArchive(threadId);\n }\n\n public async unarchive(threadId: string): Promise<void> {\n const onUnarchive = this.adapter.onUnarchive;\n if (!onUnarchive)\n throw new Error(\"External store adapter does not support unarchiving\");\n\n onUnarchive(threadId);\n }\n\n public async delete(threadId: string): Promise<void> {\n const onDelete = this.adapter.onDelete;\n if (!onDelete)\n throw new Error(\"External store adapter does not support deleting\");\n\n onDelete(threadId);\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AACpC,IAAM,oBAAoB;AAEnB,IAAM,qCAAN,MAEP;AAAA,EAeE,YACU,UAA0C,CAAC,GAC3C,eACR;AAFQ;AACA;AAER,SAAK,cAAc,KAAK,cAAc,iBAAiB;AAAA,EACzD;AAAA,EAnBA,IAAW,UAAU;AACnB,WAAO,KAAK,QAAQ,WAAW;AAAA,EACjC;AAAA,EAEA,IAAW,kBAAkB;AAC3B,WAAO,KAAK,QAAQ,mBAAmB;AAAA,EACzC;AAAA,EAEQ;AAAA,EAER,IAAW,aAAa;AACtB,WAAO,KAAK;AAAA,EACd;AAAA,EASO,sBAAsB,UAAkB;AAC7C,eAAW,UAAU,KAAK,SAAS;AACjC,UAAI,OAAO,aAAa,SAAU,QAAO;AAAA,IAC3C;AACA,eAAW,UAAU,KAAK,iBAAiB;AACzC,UAAI,OAAO,aAAa,SAAU,QAAO;AAAA,IAC3C;AACA,WAAO;AAAA,EACT;AAAA,EAEO,WAAW,SAAyC;AACzD,UAAM,kBAAkB,KAAK;AAC7B,SAAK,UAAU;AAEf,UAAM,cAAc,QAAQ,YAAY;AACxC,UAAM,aAAa,QAAQ,WAAW;AACtC,UAAM,qBAAqB,QAAQ,mBAAmB;AAEtD,QACE,gB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,UAAU,UAAmC;AAClD,SAAK,eAAe,IAAI,QAAQ;AAChC,WAAO,MAAM,KAAK,eAAe,OAAO,QAAQ;AAAA,EAClD;AAAA,EAEQ,qBAAqB;AAC3B,eAAW,YAAY,KAAK,eAAgB,UAAS;AAAA,EACvD;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ExternalStoreThreadRuntimeCore } from \"./ExternalStoreThreadRuntimeCore\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { ExternalStoreThreadListAdapter } from \"./ExternalStoreAdapter\";\n\nexport type ExternalStoreThreadFactory = (\n threadId: string,\n) => ExternalStoreThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst DEFAULT_THREAD_ID = \"DEFAULT_THREAD_ID\";\n\nexport class ExternalStoreThreadListRuntimeCore\n implements ThreadListRuntimeCore\n{\n public get threads() {\n return this.adapter.threads ?? EMPTY_ARRAY;\n }\n\n public get archivedThreads() {\n return this.adapter.archivedThreads ?? EMPTY_ARRAY;\n }\n\n private _mainThread: ExternalStoreThreadRuntimeCore;\n\n public get mainThread() {\n return this._mainThread;\n }\n\n constructor(\n private adapter: ExternalStoreThreadListAdapter = {},\n private threadFactory: ExternalStoreThreadFactory,\n ) {\n this._mainThread = this.threadFactory(DEFAULT_THREAD_ID);\n }\n\n public getThreadMetadataById(threadId: string) {\n for (const thread of this.threads) {\n if (thread.threadId === threadId) return thread;\n }\n for (const thread of this.archivedThreads) {\n if (thread.threadId === threadId) return thread;\n }\n return undefined;\n }\n\n public setAdapter(adapter: ExternalStoreThreadListAdapter) {\n const previousAdapter = this.adapter;\n this.adapter = adapter;\n\n const newThreadId = adapter.threadId ?? DEFAULT_THREAD_ID;\n const newThreads = adapter.threads ?? EMPTY_ARRAY;\n const newArchivedThreads = adapter.archivedThreads ?? EMPTY_ARRAY;\n\n const previousThreadId = previousAdapter.threadId ?? DEFAULT_THREAD_ID;\n const previousThreads = previousAdapter.threads ?? EMPTY_ARRAY;\n const previousArchivedThreads =\n previousAdapter.archivedThreads ?? EMPTY_ARRAY;\n\n if (\n previousThreadId === newThreadId &&\n previousThreads === newThreads &&\n previousArchivedThreads === newArchivedThreads\n ) {\n return;\n }\n\n if (previousAdapter.threadId !== newThreadId) {\n this._mainThread._notifyEventSubscribers(\"switched-away\");\n this._mainThread = this.threadFactory(newThreadId);\n this._mainThread._notifyEventSubscribers(\"switched-to\");\n }\n\n this._notifySubscribers();\n }\n\n public switchToThread(threadId: string): void {\n if (this._mainThread?.threadId === threadId) return;\n const onSwitchToThread = this.adapter.onSwitchToThread;\n if (!onSwitchToThread)\n throw new Error(\n \"External store adapter does not support switching to thread\",\n );\n onSwitchToThread(threadId);\n }\n\n public switchToNewThread(): void {\n const onSwitchToNewThread = this.adapter.onSwitchToNewThread;\n if (!onSwitchToNewThread)\n throw new Error(\n \"External store adapter does not support switching to new thread\",\n );\n\n onSwitchToNewThread();\n }\n\n public async rename(threadId: string, newTitle: string): Promise<void> {\n const onRename = this.adapter.onRename;\n if (!onRename)\n throw new Error(\"External store adapter does not support renaming\");\n\n onRename(threadId, newTitle);\n }\n\n public async archive(threadId: string): Promise<void> {\n const onArchive = this.adapter.onArchive;\n if (!onArchive)\n throw new Error(\"External store adapter does not support archiving\");\n\n onArchive(threadId);\n }\n\n public async unarchive(threadId: string): Promise<void> {\n const onUnarchive = this.adapter.onUnarchive;\n if (!onUnarchive)\n throw new Error(\"External store adapter does not support unarchiving\");\n\n onUnarchive(threadId);\n }\n\n public async delete(threadId: string): Promise<void> {\n const onDelete = this.adapter.onDelete;\n if (!onDelete)\n throw new Error(\"External store adapter does not support deleting\");\n\n onDelete(threadId);\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers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? DEFAULT_THREAD_ID;
33
33
  const newThreads = adapter.threads ?? EMPTY_ARRAY;
34
34
  const newArchivedThreads = adapter.archivedThreads ?? EMPTY_ARRAY;
35
- if (previousAdapter.threadId === newThreadId && previousAdapter.threads === newThreads && previousAdapter.archivedThreads === newArchivedThreads) {
35
+ const previousThreadId = previousAdapter.threadId ?? DEFAULT_THREAD_ID;
36
+ const previousThreads = previousAdapter.threads ?? EMPTY_ARRAY;
37
+ const previousArchivedThreads = previousAdapter.archivedThreads ?? EMPTY_ARRAY;
38
+ if (previousThreadId === newThreadId && previousThreads === newThreads && previousArchivedThreads === newArchivedThreads) {
36
39
  return;
37
40
  }
38
41
  if (previousAdapter.threadId !== newThreadId) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/external-store/ExternalStoreThreadListRuntimeCore.tsx"],"sourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ExternalStoreThreadRuntimeCore } from \"./ExternalStoreThreadRuntimeCore\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { ExternalStoreThreadListAdapter } from \"./ExternalStoreAdapter\";\n\nexport type ExternalStoreThreadFactory = (\n threadId: string,\n) => ExternalStoreThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst DEFAULT_THREAD_ID = \"DEFAULT_THREAD_ID\";\n\nexport class ExternalStoreThreadListRuntimeCore\n implements ThreadListRuntimeCore\n{\n public get threads() {\n return this.adapter.threads ?? EMPTY_ARRAY;\n }\n\n public get archivedThreads() {\n return this.adapter.archivedThreads ?? EMPTY_ARRAY;\n }\n\n private _mainThread: ExternalStoreThreadRuntimeCore;\n\n public get mainThread() {\n return this._mainThread;\n }\n\n constructor(\n private adapter: ExternalStoreThreadListAdapter = {},\n private threadFactory: ExternalStoreThreadFactory,\n ) {\n this._mainThread = this.threadFactory(DEFAULT_THREAD_ID);\n }\n\n public getThreadMetadataById(threadId: string) {\n for (const thread of this.threads) {\n if (thread.threadId === threadId) return thread;\n }\n for (const thread of this.archivedThreads) {\n if (thread.threadId === threadId) return thread;\n }\n return undefined;\n }\n\n public setAdapter(adapter: ExternalStoreThreadListAdapter) {\n const previousAdapter = this.adapter;\n this.adapter = adapter;\n\n const newThreadId = adapter.threadId ?? DEFAULT_THREAD_ID;\n const newThreads = adapter.threads ?? EMPTY_ARRAY;\n const newArchivedThreads = adapter.archivedThreads ?? EMPTY_ARRAY;\n\n if (\n previousAdapter.threadId === newThreadId &&\n previousAdapter.threads === newThreads &&\n previousAdapter.archivedThreads === newArchivedThreads\n ) {\n return;\n }\n\n if (previousAdapter.threadId !== newThreadId) {\n this._mainThread._notifyEventSubscribers(\"switched-away\");\n this._mainThread = this.threadFactory(newThreadId);\n this._mainThread._notifyEventSubscribers(\"switched-to\");\n }\n\n this._notifySubscribers();\n }\n\n public switchToThread(threadId: string): void {\n if (this._mainThread?.threadId === threadId) return;\n const onSwitchToThread = this.adapter.onSwitchToThread;\n if (!onSwitchToThread)\n throw new Error(\n \"External store adapter does not support switching to thread\",\n );\n onSwitchToThread(threadId);\n }\n\n public switchToNewThread(): void {\n const onSwitchToNewThread = this.adapter.onSwitchToNewThread;\n if (!onSwitchToNewThread)\n throw new Error(\n \"External store adapter does not support switching to new thread\",\n );\n\n onSwitchToNewThread();\n }\n\n public async rename(threadId: string, newTitle: string): Promise<void> {\n const onRename = this.adapter.onRename;\n if (!onRename)\n throw new Error(\"External store adapter does not support renaming\");\n\n onRename(threadId, newTitle);\n }\n\n public async archive(threadId: string): Promise<void> {\n const onArchive = this.adapter.onArchive;\n if (!onArchive)\n throw new Error(\"External store adapter does not support archiving\");\n\n onArchive(threadId);\n }\n\n public async unarchive(threadId: string): Promise<void> {\n const onUnarchive = this.adapter.onUnarchive;\n if (!onUnarchive)\n throw new Error(\"External store adapter does not support unarchiving\");\n\n onUnarchive(threadId);\n }\n\n public async delete(threadId: string): Promise<void> {\n const onDelete = this.adapter.onDelete;\n if (!onDelete)\n throw new Error(\"External store adapter does not support deleting\");\n\n onDelete(threadId);\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n}\n"],"mappings":";AASA,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AACpC,IAAM,oBAAoB;AAEnB,IAAM,qCAAN,MAEP;AAAA,EAeE,YACU,UAA0C,CAAC,GAC3C,eACR;AAFQ;AACA;AAER,SAAK,cAAc,KAAK,cAAc,iBAAiB;AAAA,EACzD;AAAA,EAnBA,IAAW,UAAU;AACnB,WAAO,KAAK,QAAQ,WAAW;AAAA,EACjC;AAAA,EAEA,IAAW,kBAAkB;AAC3B,WAAO,KAAK,QAAQ,mBAAmB;AAAA,EACzC;AAAA,EAEQ;AAAA,EAER,IAAW,aAAa;AACtB,WAAO,KAAK;AAAA,EACd;AAAA,EASO,sBAAsB,UAAkB;AAC7C,eAAW,UAAU,KAAK,SAAS;AACjC,UAAI,OAAO,aAAa,SAAU,QAAO;AAAA,IAC3C;AACA,eAAW,UAAU,KAAK,iBAAiB;AACzC,UAAI,OAAO,aAAa,SAAU,QAAO;AAAA,IAC3C;AACA,WAAO;AAAA,EACT;AAAA,EAEO,WAAW,SAAyC;AACzD,UAAM,kBAAkB,KAAK;AAC7B,SAAK,UAAU;AAEf,UAAM,cAAc,QAAQ,YAAY;AACxC,UAAM,aAAa,QAAQ,WAAW;AACtC,UAAM,qBAAqB,QAAQ,mBAAmB;AAEtD,QACE,gBAAgB,aAAa,eAC7B,gBAAgB,YAAY,cAC5B,gBAAgB,oBAAoB,oBACpC;AACA;AAAA,IACF;AAEA,QAAI,gBAAgB,aAAa,aAAa;AAC5C,WAAK,YAAY,wBAAwB,eAAe;AACxD,WAAK,cAAc,KAAK,cAAc,WAAW;AACjD,WAAK,YAAY,wBAAwB,aAAa;AAAA,IACxD;AAEA,SAAK,mBAAmB;AAAA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ourcesContent":["import type { Unsubscribe } from \"../../types\";\nimport { ExternalStoreThreadRuntimeCore } from \"./ExternalStoreThreadRuntimeCore\";\nimport { ThreadListRuntimeCore } from \"../core/ThreadListRuntimeCore\";\nimport { ExternalStoreThreadListAdapter } from \"./ExternalStoreAdapter\";\n\nexport type ExternalStoreThreadFactory = (\n threadId: string,\n) => ExternalStoreThreadRuntimeCore;\n\nconst EMPTY_ARRAY = Object.freeze([]);\nconst DEFAULT_THREAD_ID = \"DEFAULT_THREAD_ID\";\n\nexport class ExternalStoreThreadListRuntimeCore\n implements ThreadListRuntimeCore\n{\n public get threads() {\n return this.adapter.threads ?? EMPTY_ARRAY;\n }\n\n public get archivedThreads() {\n return this.adapter.archivedThreads ?? EMPTY_ARRAY;\n }\n\n private _mainThread: ExternalStoreThreadRuntimeCore;\n\n public get mainThread() {\n return this._mainThread;\n }\n\n constructor(\n private adapter: ExternalStoreThreadListAdapter = {},\n private threadFactory: ExternalStoreThreadFactory,\n ) {\n this._mainThread = this.threadFactory(DEFAULT_THREAD_ID);\n }\n\n public getThreadMetadataById(threadId: string) {\n for (const thread of this.threads) {\n if (thread.threadId === threadId) return thread;\n }\n for (const thread of this.archivedThreads) {\n if (thread.threadId === threadId) return thread;\n }\n return undefined;\n }\n\n public setAdapter(adapter: ExternalStoreThreadListAdapter) {\n const previousAdapter = this.adapter;\n this.adapter = adapter;\n\n const newThreadId = adapter.threadId ?? DEFAULT_THREAD_ID;\n const newThreads = adapter.threads ?? EMPTY_ARRAY;\n const newArchivedThreads = adapter.archivedThreads ?? EMPTY_ARRAY;\n\n const previousThreadId = previousAdapter.threadId ?? DEFAULT_THREAD_ID;\n const previousThreads = previousAdapter.threads ?? EMPTY_ARRAY;\n const previousArchivedThreads =\n previousAdapter.archivedThreads ?? EMPTY_ARRAY;\n\n if (\n previousThreadId === newThreadId &&\n previousThreads === newThreads &&\n previousArchivedThreads === newArchivedThreads\n ) {\n return;\n }\n\n if (previousAdapter.threadId !== newThreadId) {\n this._mainThread._notifyEventSubscribers(\"switched-away\");\n this._mainThread = this.threadFactory(newThreadId);\n this._mainThread._notifyEventSubscribers(\"switched-to\");\n }\n\n this._notifySubscribers();\n }\n\n public switchToThread(threadId: string): void {\n if (this._mainThread?.threadId === threadId) return;\n const onSwitchToThread = this.adapter.onSwitchToThread;\n if (!onSwitchToThread)\n throw new Error(\n \"External store adapter does not support switching to thread\",\n );\n onSwitchToThread(threadId);\n }\n\n public switchToNewThread(): void {\n const onSwitchToNewThread = this.adapter.onSwitchToNewThread;\n if (!onSwitchToNewThread)\n throw new Error(\n \"External store adapter does not support switching to new thread\",\n );\n\n onSwitchToNewThread();\n }\n\n public async rename(threadId: string, newTitle: string): Promise<void> {\n const onRename = this.adapter.onRename;\n if (!onRename)\n throw new Error(\"External store adapter does not support renaming\");\n\n onRename(threadId, newTitle);\n }\n\n public async archive(threadId: string): Promise<void> {\n const onArchive = this.adapter.onArchive;\n if (!onArchive)\n throw new Error(\"External store adapter does not support archiving\");\n\n onArchive(threadId);\n }\n\n public async unarchive(threadId: string): Promise<void> {\n const onUnarchive = this.adapter.onUnarchive;\n if (!onUnarchive)\n throw new Error(\"External store adapter does not support unarchiving\");\n\n onUnarchive(threadId);\n }\n\n public async delete(threadId: string): Promise<void> {\n const onDelete = this.adapter.onDelete;\n if (!onDelete)\n throw new Error(\"External store adapter does not support deleting\");\n\n onDelete(threadId);\n }\n\n private _subscriptions = new Set<() => void>();\n\n public subscribe(callback: () => void): Unsubscribe {\n this._subscriptions.add(callback);\n return () => this._subscriptions.delete(callback);\n }\n\n private _notifySubscribers() {\n for (const callback of this._subscriptions) callback();\n }\n}\n"],"mappings":";AASA,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AACpC,IAAM,oBAAoB;AAEnB,IAAM,qCAAN,MAEP;AAAA,EAeE,YACU,UAA0C,CAAC,GAC3C,eACR;AAFQ;AACA;AAER,SAAK,cAAc,KAAK,cAAc,iBAAiB;AAAA,EACzD;AAAA,EAnBA,IAA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F,wBAAoB;AAAA,EACtB;AAAA,EAEA,MAAa,OAAO,UAAkB,UAAiC;AACrE,UAAM,WAAW,KAAK,QAAQ;AAC9B,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,kDAAkD;AAEpE,aAAS,UAAU,QAAQ;AAAA,EAC7B;AAAA,EAEA,MAAa,QAAQ,UAAiC;AACpD,UAAM,YAAY,KAAK,QAAQ;AAC/B,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,mDAAmD;AAErE,cAAU,QAAQ;AAAA,EACpB;AAAA,EAEA,MAAa,UAAU,UAAiC;AACtD,UAAM,cAAc,KAAK,QAAQ;AACjC,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,qDAAqD;AAEvE,gBAAY,QAAQ;AAAA,EACtB;AAAA,EAEA,MAAa,OAAO,UAAiC;AACnD,UAAM,WAAW,KAAK,QAAQ;AAC9B,QAAI,CAAC;AACH,YAAM,IAAI,MAAM,kDAAkD;AAEpE,aAAS,QAAQ;AAAA,EACnB;AAAA,EAEQ,iBAAiB,oBAAI,IAAgB;AAAA,EAEtC,UAAU,UAAmC;AAClD,SAAK,eAAe,IAAI,QAAQ;AAChC,WAAO,MAAM,KAAK,eAAe,OAAO,QAAQ;AAAA,EAClD;AAAA,EAEQ,qBAAqB;AAC3B,eAAW,YAAY,KAAK,eAAgB,UAAS;AAAA,EACvD;AACF;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"ExternalStoreThreadRuntimeCore.d.ts","sourceRoot":"","sources":["../../../src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAS9D,OAAO,EAEL,iBAAiB,EAClB,MAAM,2BAA2B,CAA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D,OAAO,CAAC,cAAc,CASpB;CACH"}
@@ -186,9 +186,14 @@ var ExternalStoreThreadRuntimeCore = class extends import_BaseThreadRuntimeCore.
186
186
  this._store.onAddToolResult(options);
187
187
  }
188
188
  updateMessages = (messages) => {
189
- this._store.setMessages?.(
190
- messages.flatMap(import_getExternalStoreMessage.getExternalStoreMessage).filter((m) => m != null)
191
- );
189
+ const hasConverter = this._store.convertMessage !== void 0;
190
+ if (hasConverter) {
191
+ this._store.setMessages?.(
192
+ messages.flatMap(import_getExternalStoreMessage.getExternalStoreMessage).filter((m) => m != null)
193
+ );
194
+ } else {
195
+ this._store.setMessages?.(messages);
196
+ }
192
197
  };
193
198
  };
194
199
  // Annotate the CommonJS export names for ESM import in node:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n} from \"../core/ThreadRuntimeCore\";\n\nimport { AppendMessage, ModelConfigProvider, ThreadMessage } from \"../../types\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport {\n getExternalStoreMessage,\n symbolInnerMessage,\n} from \"./getExternalStoreMessage\";\nimport { ThreadMessageConverter } from \"./ThreadMessageConverter\";\nimport { getAutoStatus, isAutoStatus } from \"./auto-status\";\nimport { fromThreadMessageLike } from \"./ThreadMessageLike\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport {\n RuntimeCapabilities,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\n\nconst EMPTY_ARRAY = Object.freeze([]);\n\nexport const hasUpcomingMessage = (\n isRunning: boolean,\n messages: ThreadMessage[],\n) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class ExternalStoreThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n private assistantOptimisticId: string | null = null;\n\n private _capabilities: RuntimeCapabilities = {\n switchToBranch: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n public get capabilities() {\n return this._capabilities;\n }\n\n public threadId!: string;\n private _messages!: ThreadMessage[];\n public isDisabled!: boolean;\n\n public override get messages() {\n return this._messages;\n }\n\n public get adapters() {\n return this._store.adapters;\n }\n\n public suggestions: readonly ThreadSuggestion[] = [];\n public extras: unknown = undefined;\n\n private _converter = new ThreadMessageConverter();\n\n private _store!: ExternalStoreAdapter<any>;\n\n public override beginEdit(messageId: string) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing.\");\n\n super.beginEdit(messageId);\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n threadId: string,\n store: ExternalStoreAdapter<any>,\n ) {\n super(configProvider);\n this.threadId = threadId;\n this.setStore(store);\n }\n\n public setStore(store: ExternalStoreAdapter<any>) {\n if (this._store === store) return;\n\n const isRunning = store.isRunning ?? false;\n this.isDisabled = store.isDisabled ?? false;\n\n const oldStore = this._store as ExternalStoreAdapter<any> | undefined;\n this._store = store;\n this.extras = store.extras;\n this.suggestions = store.suggestions ?? EMPTY_ARRAY;\n this._capabilities = {\n switchToBranch: this._store.setMessages !== undefined,\n edit: this._store.onEdit !== undefined,\n reload: this._store.onReload !== undefined,\n cancel: this._store.onCancel !== undefined,\n speech: this._store.adapters?.speech !== undefined,\n unstable_copy: this._store.unstable_capabilities?.copy !== false, // default true\n attachments: !!this._store.adapters?.attachments,\n feedback: !!this._store.adapters?.feedback,\n };\n\n if (oldStore) {\n // flush the converter cache when the convertMessage prop changes\n if (oldStore.convertMessage !== store.convertMessage) {\n this._converter = new ThreadMessageConverter();\n } else if (\n oldStore.isRunning === store.isRunning &&\n oldStore.messages === store.messages\n ) {\n this._notifySubscribers();\n // no conversion update\n return;\n }\n }\n\n const messages = !store.convertMessage\n ? store.messages\n : this._converter.convertMessages(store.messages, (cache, m, idx) => {\n if (!store.convertMessage) return m;\n\n const isLast = idx === store.messages.length - 1;\n const autoStatus = getAutoStatus(isLast, isRunning);\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n )\n return cache;\n\n const newMessage = fromThreadMessageLike(\n store.convertMessage(m, idx),\n idx.toString(),\n autoStatus,\n );\n (newMessage as any)[symbolInnerMessage] = m;\n return newMessage;\n });\n\n for (let i = 0; i < messages.length; i++) {\n const message = messages[i]!;\n const parent = messages[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n if (hasUpcomingMessage(isRunning, messages)) {\n this.assistantOptimisticId = this.repository.appendOptimisticMessage(\n messages.at(-1)?.id ?? null,\n {\n role: \"assistant\",\n content: [],\n },\n );\n }\n\n this.repository.resetHead(\n this.assistantOptimisticId ?? messages.at(-1)?.id ?? null,\n );\n\n this._messages = this.repository.getMessages();\n this._notifySubscribers();\n }\n\n public override switchToBranch(branchId: string): void {\n if (!this._store.setMessages)\n throw new Error(\"Runtime does not support switching branches.\");\n\n this.repository.switchToBranch(branchId);\n this.updateMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n if (message.parentId !== (this.messages.at(-1)?.id ?? null)) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing messages.\");\n await this._store.onEdit(message);\n } else {\n await this._store.onNew(message);\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n if (!this._store.onReload)\n throw new Error(\"Runtime does not support reloading messages.\");\n\n await this._store.onReload(parentId);\n }\n\n public cancelRun(): void {\n if (!this._store.onCancel)\n throw new Error(\"Runtime does not support cancelling runs.\");\n\n this._store.onCancel();\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n let messages = this.repository.getMessages();\n const previousMessage = messages[messages.length - 1];\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.repository.deleteMessage(previousMessage.id);\n if (!this.composer.text.trim()) {\n this.composer.setText(getThreadMessageText(previousMessage));\n }\n\n messages = this.repository.getMessages();\n } else {\n this._notifySubscribers();\n }\n\n // resync messages (for reloading, to restore the previous branch)\n setTimeout(() => {\n this.updateMessages(messages);\n }, 0);\n }\n\n public addToolResult(options: AddToolResultOptions) {\n if (!this._store.onAddToolResult)\n throw new Error(\"Runtime does not support tool results.\");\n this._store.onAddToolResult(options);\n }\n\n private updateMessages = (messages: ThreadMessage[]) => {\n this._store.setMessages?.(\n messages.flatMap(getExternalStoreMessage).filter((m) => m != null),\n );\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,qCAGO;AACP,oCAAuC;AACvC,yBAA4C;AAC5C,+BAAsC;AACtC,kCAAqC;AAKrC,mCAAsC;AAEtC,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AAE7B,IAAM,qBAAqB,CAChC,WACA,aACG;AACH,SAAO,aAAa,SAAS,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D;AAEO,IAAM,iCAAN,cACG,mDAEV;AAAA,EACU,wBAAuC;AAAA,EAEvC,gBAAqC;AAAA,IAC3C,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEA,IAAW,eAAe;AACxB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO;AAAA,EACC;AAAA,EACD;AAAA,EAEP,IAAoB,WAAW;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,WAAW;AACpB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEO,c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AQ,sDAAuB,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI;AAAA,IACnE;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n} from \"../core/ThreadRuntimeCore\";\n\nimport { AppendMessage, ModelConfigProvider, ThreadMessage } from \"../../types\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport {\n getExternalStoreMessage,\n symbolInnerMessage,\n} from \"./getExternalStoreMessage\";\nimport { ThreadMessageConverter } from \"./ThreadMessageConverter\";\nimport { getAutoStatus, isAutoStatus } from \"./auto-status\";\nimport { fromThreadMessageLike } from \"./ThreadMessageLike\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport {\n RuntimeCapabilities,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\n\nconst EMPTY_ARRAY = Object.freeze([]);\n\nexport const hasUpcomingMessage = (\n isRunning: boolean,\n messages: ThreadMessage[],\n) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class ExternalStoreThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n private assistantOptimisticId: string | null = null;\n\n private _capabilities: RuntimeCapabilities = {\n switchToBranch: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n public get capabilities() {\n return this._capabilities;\n }\n\n public threadId!: string;\n private _messages!: ThreadMessage[];\n public isDisabled!: boolean;\n\n public override get messages() {\n return this._messages;\n }\n\n public get adapters() {\n return this._store.adapters;\n }\n\n public suggestions: readonly ThreadSuggestion[] = [];\n public extras: unknown = undefined;\n\n private _converter = new ThreadMessageConverter();\n\n private _store!: ExternalStoreAdapter<any>;\n\n public override beginEdit(messageId: string) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing.\");\n\n super.beginEdit(messageId);\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n threadId: string,\n store: ExternalStoreAdapter<any>,\n ) {\n super(configProvider);\n this.threadId = threadId;\n this.setStore(store);\n }\n\n public setStore(store: ExternalStoreAdapter<any>) {\n if (this._store === store) return;\n\n const isRunning = store.isRunning ?? false;\n this.isDisabled = store.isDisabled ?? false;\n\n const oldStore = this._store as ExternalStoreAdapter<any> | undefined;\n this._store = store;\n this.extras = store.extras;\n this.suggestions = store.suggestions ?? EMPTY_ARRAY;\n this._capabilities = {\n switchToBranch: this._store.setMessages !== undefined,\n edit: this._store.onEdit !== undefined,\n reload: this._store.onReload !== undefined,\n cancel: this._store.onCancel !== undefined,\n speech: this._store.adapters?.speech !== undefined,\n unstable_copy: this._store.unstable_capabilities?.copy !== false, // default true\n attachments: !!this._store.adapters?.attachments,\n feedback: !!this._store.adapters?.feedback,\n };\n\n if (oldStore) {\n // flush the converter cache when the convertMessage prop changes\n if (oldStore.convertMessage !== store.convertMessage) {\n this._converter = new ThreadMessageConverter();\n } else if (\n oldStore.isRunning === store.isRunning &&\n oldStore.messages === store.messages\n ) {\n this._notifySubscribers();\n // no conversion update\n return;\n }\n }\n\n const messages = !store.convertMessage\n ? store.messages\n : this._converter.convertMessages(store.messages, (cache, m, idx) => {\n if (!store.convertMessage) return m;\n\n const isLast = idx === store.messages.length - 1;\n const autoStatus = getAutoStatus(isLast, isRunning);\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n )\n return cache;\n\n const newMessage = fromThreadMessageLike(\n store.convertMessage(m, idx),\n idx.toString(),\n autoStatus,\n );\n (newMessage as any)[symbolInnerMessage] = m;\n return newMessage;\n });\n\n for (let i = 0; i < messages.length; i++) {\n const message = messages[i]!;\n const parent = messages[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n if (hasUpcomingMessage(isRunning, messages)) {\n this.assistantOptimisticId = this.repository.appendOptimisticMessage(\n messages.at(-1)?.id ?? null,\n {\n role: \"assistant\",\n content: [],\n },\n );\n }\n\n this.repository.resetHead(\n this.assistantOptimisticId ?? messages.at(-1)?.id ?? null,\n );\n\n this._messages = this.repository.getMessages();\n this._notifySubscribers();\n }\n\n public override switchToBranch(branchId: string): void {\n if (!this._store.setMessages)\n throw new Error(\"Runtime does not support switching branches.\");\n\n this.repository.switchToBranch(branchId);\n this.updateMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n if (message.parentId !== (this.messages.at(-1)?.id ?? null)) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing messages.\");\n await this._store.onEdit(message);\n } else {\n await this._store.onNew(message);\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n if (!this._store.onReload)\n throw new Error(\"Runtime does not support reloading messages.\");\n\n await this._store.onReload(parentId);\n }\n\n public cancelRun(): void {\n if (!this._store.onCancel)\n throw new Error(\"Runtime does not support cancelling runs.\");\n\n this._store.onCancel();\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n let messages = this.repository.getMessages();\n const previousMessage = messages[messages.length - 1];\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.repository.deleteMessage(previousMessage.id);\n if (!this.composer.text.trim()) {\n this.composer.setText(getThreadMessageText(previousMessage));\n }\n\n messages = this.repository.getMessages();\n } else {\n this._notifySubscribers();\n }\n\n // resync messages (for reloading, to restore the previous branch)\n setTimeout(() => {\n this.updateMessages(messages);\n }, 0);\n }\n\n public addToolResult(options: AddToolResultOptions) {\n if (!this._store.onAddToolResult)\n throw new Error(\"Runtime does not support tool results.\");\n this._store.onAddToolResult(options);\n }\n\n private updateMessages = (messages: ThreadMessage[]) => {\n const hasConverter = this._store.convertMessage !== undefined;\n if (hasConverter) {\n this._store.setMessages?.(\n messages.flatMap(getExternalStoreMessage).filter((m) => m != null),\n );\n } else {\n this._store.setMessages?.(messages);\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOA,qCAGO;AACP,oCAAuC;AACvC,yBAA4C;AAC5C,+BAAsC;AACtC,kCAAqC;AAKrC,mCAAsC;AAEtC,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AAE7B,IAAM,qBAAqB,CAChC,WACA,aACG;AACH,SAAO,aAAa,SAAS,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D;AAEO,IAAM,iCAAN,cACG,mDAEV;AAAA,EACU,wBAAuC;AAAA,EAEvC,gBAAqC;AAAA,IAC3C,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEA,IAAW,eAAe;AACxB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO;AAAA,EACC;AAAA,EACD;AAAA,EAEP,IAAoB,WAAW;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,WAAW;AACpB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEO,cAA2C,CAAC;AAAA,EAC5C,SAAkB;AAAA,EAEjB,aAAa,IAAI,qDAAuB;AAAA,EAExC;AAAA,EAEQ,UAAU,WAAmB;AAC3C,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI,MAAM,mCAAmC;AAErD,UAAM,UAAU,SAAS;AAAA,EAC3B;AAAA,EAEA,YACE,gBACA,UACA,OACA;AACA,UAAM,cAAc;AACpB,SAAK,WAAW;AAChB,SAAK,SAAS,KAAK;AAAA,EACrB;AAA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E,UAAM,KAAK,OAAO,SAAS,QAAQ;AAAA,EACrC;AAAA,EAEO,YAAkB;AACvB,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI,MAAM,2CAA2C;AAE7D,SAAK,OAAO,SAAS;AAErB,QAAI,KAAK,uBAAuB;AAC9B,WAAK,WAAW,cAAc,KAAK,qBAAqB;AACxD,WAAK,wBAAwB;AAAA,IAC/B;AAEA,QAAI,WAAW,KAAK,WAAW,YAAY;AAC3C,UAAM,kBAAkB,SAAS,SAAS,SAAS,CAAC;AACpD,QACE,iBAAiB,SAAS,UAC1B,gBAAgB,OAAO,SAAS,GAAG,EAAE,GAAG,IACxC;AACA,WAAK,WAAW,cAAc,gBAAgB,EAAE;AAChD,UAAI,CAAC,KAAK,SAAS,KAAK,KAAK,GAAG;AAC9B,aAAK,SAAS,YAAQ,kDAAqB,eAAe,CAAC;AAAA,MAC7D;AAEA,iBAAW,KAAK,WAAW,YAAY;AAAA,IACzC,OAAO;AACL,WAAK,mBAAmB;AAAA,IAC1B;AAGA,eAAW,MAAM;AACf,WAAK,eAAe,QAAQ;AAAA,IAC9B,GAAG,CAAC;AAAA,EACN;AAAA,EAEO,cAAc,SAA+B;AAClD,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI,MAAM,wCAAwC;AAC1D,SAAK,OAAO,gBAAgB,OAAO;AAAA,EACrC;AAAA,EAEQ,iBAAiB,CAAC,aAA8B;AACtD,UAAM,eAAe,KAAK,OAAO,mBAAmB;AACpD,QAAI,cAAc;AAChB,WAAK,OAAO;AAAA,QACV,SAAS,QAAQ,sDAAuB,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI;AAAA,MACnE;AAAA,IACF,OAAO;AACL,WAAK,OAAO,cAAc,QAAQ;AAAA,IACpC;AAAA,EACF;AACF;","names":[]}
@@ -164,9 +164,14 @@ var ExternalStoreThreadRuntimeCore = class extends BaseThreadRuntimeCore {
164
164
  this._store.onAddToolResult(options);
165
165
  }
166
166
  updateMessages = (messages) => {
167
- this._store.setMessages?.(
168
- messages.flatMap(getExternalStoreMessage).filter((m) => m != null)
169
- );
167
+ const hasConverter = this._store.convertMessage !== void 0;
168
+ if (hasConverter) {
169
+ this._store.setMessages?.(
170
+ messages.flatMap(getExternalStoreMessage).filter((m) => m != null)
171
+ );
172
+ } else {
173
+ this._store.setMessages?.(messages);
174
+ }
170
175
  };
171
176
  };
172
177
  export {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n} from \"../core/ThreadRuntimeCore\";\n\nimport { AppendMessage, ModelConfigProvider, ThreadMessage } from \"../../types\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport {\n getExternalStoreMessage,\n symbolInnerMessage,\n} from \"./getExternalStoreMessage\";\nimport { ThreadMessageConverter } from \"./ThreadMessageConverter\";\nimport { getAutoStatus, isAutoStatus } from \"./auto-status\";\nimport { fromThreadMessageLike } from \"./ThreadMessageLike\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport {\n RuntimeCapabilities,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\n\nconst EMPTY_ARRAY = Object.freeze([]);\n\nexport const hasUpcomingMessage = (\n isRunning: boolean,\n messages: ThreadMessage[],\n) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class ExternalStoreThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n private assistantOptimisticId: string | null = null;\n\n private _capabilities: RuntimeCapabilities = {\n switchToBranch: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n public get capabilities() {\n return this._capabilities;\n }\n\n public threadId!: string;\n private _messages!: ThreadMessage[];\n public isDisabled!: boolean;\n\n public override get messages() {\n return this._messages;\n }\n\n public get adapters() {\n return this._store.adapters;\n }\n\n public suggestions: readonly ThreadSuggestion[] = [];\n public extras: unknown = undefined;\n\n private _converter = new ThreadMessageConverter();\n\n private _store!: ExternalStoreAdapter<any>;\n\n public override beginEdit(messageId: string) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing.\");\n\n super.beginEdit(messageId);\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n threadId: string,\n store: ExternalStoreAdapter<any>,\n ) {\n super(configProvider);\n this.threadId = threadId;\n this.setStore(store);\n }\n\n public setStore(store: ExternalStoreAdapter<any>) {\n if (this._store === store) return;\n\n const isRunning = store.isRunning ?? false;\n this.isDisabled = store.isDisabled ?? false;\n\n const oldStore = this._store as ExternalStoreAdapter<any> | undefined;\n this._store = store;\n this.extras = store.extras;\n this.suggestions = store.suggestions ?? EMPTY_ARRAY;\n this._capabilities = {\n switchToBranch: this._store.setMessages !== undefined,\n edit: this._store.onEdit !== undefined,\n reload: this._store.onReload !== undefined,\n cancel: this._store.onCancel !== undefined,\n speech: this._store.adapters?.speech !== undefined,\n unstable_copy: this._store.unstable_capabilities?.copy !== false, // default true\n attachments: !!this._store.adapters?.attachments,\n feedback: !!this._store.adapters?.feedback,\n };\n\n if (oldStore) {\n // flush the converter cache when the convertMessage prop changes\n if (oldStore.convertMessage !== store.convertMessage) {\n this._converter = new ThreadMessageConverter();\n } else if (\n oldStore.isRunning === store.isRunning &&\n oldStore.messages === store.messages\n ) {\n this._notifySubscribers();\n // no conversion update\n return;\n }\n }\n\n const messages = !store.convertMessage\n ? store.messages\n : this._converter.convertMessages(store.messages, (cache, m, idx) => {\n if (!store.convertMessage) return m;\n\n const isLast = idx === store.messages.length - 1;\n const autoStatus = getAutoStatus(isLast, isRunning);\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n )\n return cache;\n\n const newMessage = fromThreadMessageLike(\n store.convertMessage(m, idx),\n idx.toString(),\n autoStatus,\n );\n (newMessage as any)[symbolInnerMessage] = m;\n return newMessage;\n });\n\n for (let i = 0; i < messages.length; i++) {\n const message = messages[i]!;\n const parent = messages[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n if (hasUpcomingMessage(isRunning, messages)) {\n this.assistantOptimisticId = this.repository.appendOptimisticMessage(\n messages.at(-1)?.id ?? null,\n {\n role: \"assistant\",\n content: [],\n },\n );\n }\n\n this.repository.resetHead(\n this.assistantOptimisticId ?? messages.at(-1)?.id ?? null,\n );\n\n this._messages = this.repository.getMessages();\n this._notifySubscribers();\n }\n\n public override switchToBranch(branchId: string): void {\n if (!this._store.setMessages)\n throw new Error(\"Runtime does not support switching branches.\");\n\n this.repository.switchToBranch(branchId);\n this.updateMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n if (message.parentId !== (this.messages.at(-1)?.id ?? null)) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing messages.\");\n await this._store.onEdit(message);\n } else {\n await this._store.onNew(message);\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n if (!this._store.onReload)\n throw new Error(\"Runtime does not support reloading messages.\");\n\n await this._store.onReload(parentId);\n }\n\n public cancelRun(): void {\n if (!this._store.onCancel)\n throw new Error(\"Runtime does not support cancelling runs.\");\n\n this._store.onCancel();\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n let messages = this.repository.getMessages();\n const previousMessage = messages[messages.length - 1];\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.repository.deleteMessage(previousMessage.id);\n if (!this.composer.text.trim()) {\n this.composer.setText(getThreadMessageText(previousMessage));\n }\n\n messages = this.repository.getMessages();\n } else {\n this._notifySubscribers();\n }\n\n // resync messages (for reloading, to restore the previous branch)\n setTimeout(() => {\n this.updateMessages(messages);\n }, 0);\n }\n\n public addToolResult(options: AddToolResultOptions) {\n if (!this._store.onAddToolResult)\n throw new Error(\"Runtime does not support tool results.\");\n this._store.onAddToolResult(options);\n }\n\n private updateMessages = (messages: ThreadMessage[]) => {\n this._store.setMessages?.(\n messages.flatMap(getExternalStoreMessage).filter((m) => m != null),\n );\n };\n}\n"],"mappings":";AAOA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AACvC,SAAS,eAAe,oBAAoB;AAC5C,SAAS,6BAA6B;AACtC,SAAS,4BAA4B;AAKrC,SAAS,6BAA6B;AAEtC,IAAM,cAAc,OAAO,OAAO,CAAC,CAAC;AAE7B,IAAM,qBAAqB,CAChC,WACA,aACG;AACH,SAAO,aAAa,SAAS,SAAS,SAAS,CAAC,GAAG,SAAS;AAC9D;AAEO,IAAM,iCAAN,cACG,sBAEV;AAAA,EACU,wBAAuC;AAAA,EAEvC,gBAAqC;AAAA,IAC3C,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR,eAAe;AAAA,IACf,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,UAAU;AAAA,EACZ;AAAA,EAEA,IAAW,eAAe;AACxB,WAAO,KAAK;AAAA,EACd;AAAA,EAEO;AAAA,EACC;AAAA,EACD;AAAA,EAEP,IAAoB,WAAW;AAC7B,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAW,WAAW;AACpB,WAAO,KAAK,OAAO;AAAA,EACrB;AAAA,EAEO,cAA2C,CAAC;AAAA,EAC5C,SAAkB;AAAA,EAEjB,aAAa,IAAI,uBAAuB;AAAA,EAExC;AAAA,EAEQ,UAAU,WAAmB;AAC3C,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI,MAAM,mCAAmC;AAErD,UAAM,UAAU,SAAS;AAAA,E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AAA,EACF;AAAA,EAEA,MAAa,SAAS,UAAwC;AAC5D,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI,MAAM,8CAA8C;AAEhE,UAAM,KAAK,OAAO,SAAS,QAAQ;AAAA,EACrC;AAAA,EAEO,YAAkB;AACvB,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI,MAAM,2CAA2C;AAE7D,SAAK,OAAO,SAAS;AAErB,QAAI,KAAK,uBAAuB;AAC9B,WAAK,WAAW,cAAc,KAAK,qBAAqB;AACxD,WAAK,wBAAwB;AAAA,IAC/B;AAEA,QAAI,WAAW,KAAK,WAAW,YAAY;AAC3C,UAAM,kBAAkB,SAAS,SAAS,SAAS,CAAC;AACpD,QACE,iBAAiB,SAAS,UAC1B,gBAAgB,OAAO,SAAS,GAAG,EAAE,GAAG,IACxC;AACA,WAAK,WAAW,cAAc,gBAAgB,EAAE;AAChD,UAAI,CAAC,KAAK,SAAS,KAAK,KAAK,GAAG;AAC9B,aAAK,SAAS,QAAQ,qBAAqB,eAAe,CAAC;AAAA,MAC7D;AAEA,iBAAW,KAAK,WAAW,YAAY;AAAA,IACzC,OAAO;AACL,WAAK,mBAAmB;AAAA,IAC1B;AAGA,eAAW,MAAM;AACf,WAAK,eAAe,QAAQ;AAAA,IAC9B,GAAG,CAAC;AAAA,EACN;AAAA,EAEO,cAAc,SAA+B;AAClD,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI,MAAM,wCAAwC;AAC1D,SAAK,OAAO,gBAAgB,OAAO;AAAA,EACrC;AAAA,EAEQ,iBAAiB,CAAC,aAA8B;AACtD,SAAK,OAAO;AAAA,MACV,SAAS,QAAQ,uBAAuB,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI;AAAA,IACnE;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../src/runtimes/external-store/ExternalStoreThreadRuntimeCore.tsx"],"sourcesContent":["import {\n AddToolResultOptions,\n ThreadSuggestion,\n} from \"../core/ThreadRuntimeCore\";\n\nimport { AppendMessage, ModelConfigProvider, ThreadMessage } from \"../../types\";\nimport { ExternalStoreAdapter } from \"./ExternalStoreAdapter\";\nimport {\n getExternalStoreMessage,\n symbolInnerMessage,\n} from \"./getExternalStoreMessage\";\nimport { ThreadMessageConverter } from \"./ThreadMessageConverter\";\nimport { getAutoStatus, isAutoStatus } from \"./auto-status\";\nimport { fromThreadMessageLike } from \"./ThreadMessageLike\";\nimport { getThreadMessageText } from \"../../utils/getThreadMessageText\";\nimport {\n RuntimeCapabilities,\n ThreadRuntimeCore,\n} from \"../core/ThreadRuntimeCore\";\nimport { BaseThreadRuntimeCore } from \"../core/BaseThreadRuntimeCore\";\n\nconst EMPTY_ARRAY = Object.freeze([]);\n\nexport const hasUpcomingMessage = (\n isRunning: boolean,\n messages: ThreadMessage[],\n) => {\n return isRunning && messages[messages.length - 1]?.role !== \"assistant\";\n};\n\nexport class ExternalStoreThreadRuntimeCore\n extends BaseThreadRuntimeCore\n implements ThreadRuntimeCore\n{\n private assistantOptimisticId: string | null = null;\n\n private _capabilities: RuntimeCapabilities = {\n switchToBranch: false,\n edit: false,\n reload: false,\n cancel: false,\n unstable_copy: false,\n speech: false,\n attachments: false,\n feedback: false,\n };\n\n public get capabilities() {\n return this._capabilities;\n }\n\n public threadId!: string;\n private _messages!: ThreadMessage[];\n public isDisabled!: boolean;\n\n public override get messages() {\n return this._messages;\n }\n\n public get adapters() {\n return this._store.adapters;\n }\n\n public suggestions: readonly ThreadSuggestion[] = [];\n public extras: unknown = undefined;\n\n private _converter = new ThreadMessageConverter();\n\n private _store!: ExternalStoreAdapter<any>;\n\n public override beginEdit(messageId: string) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing.\");\n\n super.beginEdit(messageId);\n }\n\n constructor(\n configProvider: ModelConfigProvider,\n threadId: string,\n store: ExternalStoreAdapter<any>,\n ) {\n super(configProvider);\n this.threadId = threadId;\n this.setStore(store);\n }\n\n public setStore(store: ExternalStoreAdapter<any>) {\n if (this._store === store) return;\n\n const isRunning = store.isRunning ?? false;\n this.isDisabled = store.isDisabled ?? false;\n\n const oldStore = this._store as ExternalStoreAdapter<any> | undefined;\n this._store = store;\n this.extras = store.extras;\n this.suggestions = store.suggestions ?? EMPTY_ARRAY;\n this._capabilities = {\n switchToBranch: this._store.setMessages !== undefined,\n edit: this._store.onEdit !== undefined,\n reload: this._store.onReload !== undefined,\n cancel: this._store.onCancel !== undefined,\n speech: this._store.adapters?.speech !== undefined,\n unstable_copy: this._store.unstable_capabilities?.copy !== false, // default true\n attachments: !!this._store.adapters?.attachments,\n feedback: !!this._store.adapters?.feedback,\n };\n\n if (oldStore) {\n // flush the converter cache when the convertMessage prop changes\n if (oldStore.convertMessage !== store.convertMessage) {\n this._converter = new ThreadMessageConverter();\n } else if (\n oldStore.isRunning === store.isRunning &&\n oldStore.messages === store.messages\n ) {\n this._notifySubscribers();\n // no conversion update\n return;\n }\n }\n\n const messages = !store.convertMessage\n ? store.messages\n : this._converter.convertMessages(store.messages, (cache, m, idx) => {\n if (!store.convertMessage) return m;\n\n const isLast = idx === store.messages.length - 1;\n const autoStatus = getAutoStatus(isLast, isRunning);\n\n if (\n cache &&\n (cache.role !== \"assistant\" ||\n !isAutoStatus(cache.status) ||\n cache.status === autoStatus)\n )\n return cache;\n\n const newMessage = fromThreadMessageLike(\n store.convertMessage(m, idx),\n idx.toString(),\n autoStatus,\n );\n (newMessage as any)[symbolInnerMessage] = m;\n return newMessage;\n });\n\n for (let i = 0; i < messages.length; i++) {\n const message = messages[i]!;\n const parent = messages[i - 1];\n this.repository.addOrUpdateMessage(parent?.id ?? null, message);\n }\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n if (hasUpcomingMessage(isRunning, messages)) {\n this.assistantOptimisticId = this.repository.appendOptimisticMessage(\n messages.at(-1)?.id ?? null,\n {\n role: \"assistant\",\n content: [],\n },\n );\n }\n\n this.repository.resetHead(\n this.assistantOptimisticId ?? messages.at(-1)?.id ?? null,\n );\n\n this._messages = this.repository.getMessages();\n this._notifySubscribers();\n }\n\n public override switchToBranch(branchId: string): void {\n if (!this._store.setMessages)\n throw new Error(\"Runtime does not support switching branches.\");\n\n this.repository.switchToBranch(branchId);\n this.updateMessages(this.repository.getMessages());\n }\n\n public async append(message: AppendMessage): Promise<void> {\n if (message.parentId !== (this.messages.at(-1)?.id ?? null)) {\n if (!this._store.onEdit)\n throw new Error(\"Runtime does not support editing messages.\");\n await this._store.onEdit(message);\n } else {\n await this._store.onNew(message);\n }\n }\n\n public async startRun(parentId: string | null): Promise<void> {\n if (!this._store.onReload)\n throw new Error(\"Runtime does not support reloading messages.\");\n\n await this._store.onReload(parentId);\n }\n\n public cancelRun(): void {\n if (!this._store.onCancel)\n throw new Error(\"Runtime does not support cancelling runs.\");\n\n this._store.onCancel();\n\n if (this.assistantOptimisticId) {\n this.repository.deleteMessage(this.assistantOptimisticId);\n this.assistantOptimisticId = null;\n }\n\n let messages = this.repository.getMessages();\n const previousMessage = messages[messages.length - 1];\n if (\n previousMessage?.role === \"user\" &&\n previousMessage.id === messages.at(-1)?.id // ensure the previous message is a leaf node\n ) {\n this.repository.deleteMessage(previousMessage.id);\n if (!this.composer.text.trim()) {\n this.composer.setText(getThreadMessageText(previousMessage));\n }\n\n messages = this.repository.getMessages();\n } else {\n this._notifySubscribers();\n }\n\n // resync messages (for reloading, to restore the previous branch)\n setTimeout(() => {\n this.updateMessages(messages);\n }, 0);\n }\n\n public addToolResult(options: AddToolResultOptions) {\n if (!this._store.onAddToolResult)\n throw new Error(\"Runtime does not support tool results.\");\n this._store.onAddToolResult(options);\n }\n\n private updateMessages = (messages: ThreadMessage[]) => {\n const hasConverter = this._store.convertMessage !== undefined;\n if (hasConverter) {\n this._store.setMessages?.(\n messages.flatMap(getExternalStoreMessage).filter((m) => m != null),\n );\n } else {\n this._store.setMessages?.(messages);\n }\n };\n}\n"],"mappings":";AAOA;AAAA,E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AK,qBAAqB;AACxD,WAAK,wBAAwB;AAAA,IAC/B;AAEA,QAAI,WAAW,KAAK,WAAW,YAAY;AAC3C,UAAM,kBAAkB,SAAS,SAAS,SAAS,CAAC;AACpD,QACE,iBAAiB,SAAS,UAC1B,gBAAgB,OAAO,SAAS,GAAG,EAAE,GAAG,IACxC;AACA,WAAK,WAAW,cAAc,gBAAgB,EAAE;AAChD,UAAI,CAAC,KAAK,SAAS,KAAK,KAAK,GAAG;AAC9B,aAAK,SAAS,QAAQ,qBAAqB,eAAe,CAAC;AAAA,MAC7D;AAEA,iBAAW,KAAK,WAAW,YAAY;AAAA,IACzC,OAAO;AACL,WAAK,mBAAmB;AAAA,IAC1B;AAGA,eAAW,MAAM;AACf,WAAK,eAAe,QAAQ;AAAA,IAC9B,GAAG,CAAC;AAAA,EACN;AAAA,EAEO,cAAc,SAA+B;AAClD,QAAI,CAAC,KAAK,OAAO;AACf,YAAM,IAAI,MAAM,wCAAwC;AAC1D,SAAK,OAAO,gBAAgB,OAAO;AAAA,EACrC;AAAA,EAEQ,iBAAiB,CAAC,aAA8B;AACtD,UAAM,eAAe,KAAK,OAAO,mBAAmB;AACpD,QAAI,cAAc;AAChB,WAAK,OAAO;AAAA,QACV,SAAS,QAAQ,uBAAuB,EAAE,OAAO,CAAC,MAAM,KAAK,IAAI;AAAA,MACnE;AAAA,IACF,OAAO;AACL,WAAK,OAAO,cAAc,QAAQ;AAAA,IACpC;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -29,7 +29,7 @@
29
29
  "conversational-ui",
30
30
  "conversational-ai"
31
31
  ],
32
- "version": "0.5.99",
32
+ "version": "0.5.100",
33
33
  "license": "MIT",
34
34
  "exports": {
35
35
  ".": {
@@ -52,10 +52,15 @@ export class ExternalStoreThreadListRuntimeCore
52
52
  const newThreads = adapter.threads ?? EMPTY_ARRAY;
53
53
  const newArchivedThreads = adapter.archivedThreads ?? EMPTY_ARRAY;
54
54
 
55
+ const previousThreadId = previousAdapter.threadId ?? DEFAULT_THREAD_ID;
56
+ const previousThreads = previousAdapter.threads ?? EMPTY_ARRAY;
57
+ const previousArchivedThreads =
58
+ previousAdapter.archivedThreads ?? EMPTY_ARRAY;
59
+
55
60
  if (
56
- previousAdapter.threadId === newThreadId &&
57
- previousAdapter.threads === newThreads &&
58
- previousAdapter.archivedThreads === newArchivedThreads
61
+ previousThreadId === newThreadId &&
62
+ previousThreads === newThreads &&
63
+ previousArchivedThreads === newArchivedThreads
59
64
  ) {
60
65
  return;
61
66
  }
@@ -239,8 +239,13 @@ export class ExternalStoreThreadRuntimeCore
239
239
  }
240
240
 
241
241
  private updateMessages = (messages: ThreadMessage[]) => {
242
- this._store.setMessages?.(
243
- messages.flatMap(getExternalStoreMessage).filter((m) => m != null),
244
- );
242
+ const hasConverter = this._store.convertMessage !== undefined;
243
+ if (hasConverter) {
244
+ this._store.setMessages?.(
245
+ messages.flatMap(getExternalStoreMessage).filter((m) => m != null),
246
+ );
247
+ } else {
248
+ this._store.setMessages?.(messages);
249
+ }
245
250
  };
246
251
  }