@smartspace/chat-ui 1.13.1-pr.252.acadb9f → 1.13.1-pr.255.41c66f3

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/index.d.ts CHANGED
@@ -1147,7 +1147,11 @@ declare const messagesListOptions: (service: ChatService, threadId: string, opts
1147
1147
  [dataTagErrorSymbol]: Error;
1148
1148
  };
1149
1149
  };
1150
- declare function useMessages(threadId: string): _tanstack_react_query.UseQueryResult<Message[], Error>;
1150
+ declare function useMessages(threadId: string, opts?: {
1151
+ take?: number;
1152
+ skip?: number;
1153
+ skipWhenNewThread?: boolean;
1154
+ }): _tanstack_react_query.UseQueryResult<Message[], Error>;
1151
1155
 
1152
1156
  declare const useFileMutations: (scope: FileScope) => {
1153
1157
  uploadFilesMutation: _tanstack_react_query.UseMutationResult<FileInfo$1[], Error, File[], unknown>;
package/dist/index.js CHANGED
@@ -3815,11 +3815,13 @@ function MessageComposer({
3815
3815
  workspaceId,
3816
3816
  threadId: isDraftThread ? void 0 : threadId
3817
3817
  });
3818
- if (typeof window !== "undefined") {
3819
- window.__ssDownloadFile = async (id) => {
3820
- return await getFileBlobUrl(id);
3818
+ useEffect(() => {
3819
+ if (typeof window === "undefined") return;
3820
+ window.__ssDownloadFile = (id) => getFileBlobUrl(id);
3821
+ return () => {
3822
+ if (window.__ssDownloadFile) delete window.__ssDownloadFile;
3821
3823
  };
3822
- }
3824
+ }, [getFileBlobUrl]);
3823
3825
  const onUploadFiles = async (files) => {
3824
3826
  const res = await uploadFilesMutation.mutateAsync(files);
3825
3827
  return res.map(({ id, name }) => ({ id, name }));
@@ -4242,13 +4244,15 @@ var messagesListOptions = (service, threadId, opts) => queryOptions({
4242
4244
  // Avoid re-fetching the entire thread on every small navigation.
4243
4245
  staleTime: 3e4
4244
4246
  });
4245
- function useMessages(threadId) {
4247
+ function useMessages(threadId, opts) {
4246
4248
  const service = useChatService();
4247
4249
  const isDraft = isDraftThreadId(threadId);
4250
+ const skipFetch = opts?.skipWhenNewThread || !threadId || isDraft;
4251
+ const listOpts = opts?.take != null || opts?.skip != null ? { take: opts.take, skip: opts.skip } : void 0;
4248
4252
  return useQuery({
4249
- ...messagesListOptions(service, threadId),
4250
- enabled: !!threadId && !isDraft,
4251
- initialData: !threadId || isDraft ? [] : void 0
4253
+ ...messagesListOptions(service, threadId, listOpts),
4254
+ enabled: !opts?.skipWhenNewThread && !!threadId && !isDraft,
4255
+ initialData: skipFetch ? [] : void 0
4252
4256
  });
4253
4257
  }
4254
4258