@liveblocks/react 3.2.1 → 3.3.1

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/_private.cjs CHANGED
@@ -25,7 +25,7 @@
25
25
 
26
26
 
27
27
 
28
- var _chunkLJQILG65cjs = require('./chunk-LJQILG65.cjs');
28
+ var _chunkV36VCKRBcjs = require('./chunk-V36VCKRB.cjs');
29
29
 
30
30
  // src/lib/use-layout-effect.ts
31
31
  var _react = require('react');
@@ -43,8 +43,8 @@ function normalizeMentionSuggestions(suggestions) {
43
43
  function useMentionSuggestions(roomId, search) {
44
44
  const [mentionSuggestions, setMentionSuggestions] = _react.useState.call(void 0, );
45
45
  const lastInvokedAt = _react.useRef.call(void 0, );
46
- const resolveMentionSuggestions = _chunkLJQILG65cjs.useResolveMentionSuggestions.call(void 0, );
47
- const mentionSuggestionsCache = _chunkLJQILG65cjs.useMentionSuggestionsCache.call(void 0, );
46
+ const resolveMentionSuggestions = _chunkV36VCKRBcjs.useResolveMentionSuggestions.call(void 0, );
47
+ const mentionSuggestionsCache = _chunkV36VCKRBcjs.useMentionSuggestionsCache.call(void 0, );
48
48
  _react.useEffect.call(void 0, () => {
49
49
  if (search === void 0 || !resolveMentionSuggestions) {
50
50
  return;
@@ -99,7 +99,7 @@ function useMentionSuggestions(roomId, search) {
99
99
 
100
100
 
101
101
  function useSyncSource() {
102
- const client = _chunkLJQILG65cjs.useClient.call(void 0, );
102
+ const client = _chunkV36VCKRBcjs.useClient.call(void 0, );
103
103
  const createSyncSource = client[_core.kInternal].createSyncSource;
104
104
  const [syncSource, setSyncSource] = _react.useState.call(void 0, );
105
105
  _react.useEffect.call(void 0, () => {
@@ -138,5 +138,5 @@ function useSyncSource() {
138
138
 
139
139
 
140
140
 
141
- exports.getUmbrellaStoreForClient = _chunkLJQILG65cjs.getUmbrellaStoreForClient; exports.useAddRoomCommentReaction = _chunkLJQILG65cjs.useAddRoomCommentReaction; exports.useClientOrNull = _chunkLJQILG65cjs.useClientOrNull; exports.useCreateRoomComment = _chunkLJQILG65cjs.useCreateRoomComment; exports.useCreateRoomThread = _chunkLJQILG65cjs.useCreateRoomThread; exports.useCreateTextMention = _chunkLJQILG65cjs.useCreateTextMention; exports.useDeleteRoomComment = _chunkLJQILG65cjs.useDeleteRoomComment; exports.useDeleteRoomThread = _chunkLJQILG65cjs.useDeleteRoomThread; exports.useDeleteTextMention = _chunkLJQILG65cjs.useDeleteTextMention; exports.useEditRoomComment = _chunkLJQILG65cjs.useEditRoomComment; exports.useEditRoomThreadMetadata = _chunkLJQILG65cjs.useEditRoomThreadMetadata; exports.useLatest = _chunkLJQILG65cjs.useLatest; exports.useLayoutEffect = useLayoutEffect; exports.useMarkRoomThreadAsRead = _chunkLJQILG65cjs.useMarkRoomThreadAsRead; exports.useMarkRoomThreadAsResolved = _chunkLJQILG65cjs.useMarkRoomThreadAsResolved; exports.useMarkRoomThreadAsUnresolved = _chunkLJQILG65cjs.useMarkRoomThreadAsUnresolved; exports.useMentionSuggestions = useMentionSuggestions; exports.useMentionSuggestionsCache = _chunkLJQILG65cjs.useMentionSuggestionsCache; exports.useRemoveRoomCommentReaction = _chunkLJQILG65cjs.useRemoveRoomCommentReaction; exports.useReportTextEditor = _chunkLJQILG65cjs.useReportTextEditor; exports.useResolveMentionSuggestions = _chunkLJQILG65cjs.useResolveMentionSuggestions; exports.useRoomAttachmentUrl = _chunkLJQILG65cjs.useRoomAttachmentUrl; exports.useRoomPermissions = _chunkLJQILG65cjs.useRoomPermissions; exports.useRoomThreadSubscription = _chunkLJQILG65cjs.useRoomThreadSubscription; exports.useSignal = _chunkLJQILG65cjs.useSignal; exports.useSyncExternalStoreWithSelector = _chunkLJQILG65cjs.useSyncExternalStoreWithSelector; exports.useSyncSource = useSyncSource; exports.useYjsProvider = _chunkLJQILG65cjs.useYjsProvider;
141
+ exports.getUmbrellaStoreForClient = _chunkV36VCKRBcjs.getUmbrellaStoreForClient; exports.useAddRoomCommentReaction = _chunkV36VCKRBcjs.useAddRoomCommentReaction; exports.useClientOrNull = _chunkV36VCKRBcjs.useClientOrNull; exports.useCreateRoomComment = _chunkV36VCKRBcjs.useCreateRoomComment; exports.useCreateRoomThread = _chunkV36VCKRBcjs.useCreateRoomThread; exports.useCreateTextMention = _chunkV36VCKRBcjs.useCreateTextMention; exports.useDeleteRoomComment = _chunkV36VCKRBcjs.useDeleteRoomComment; exports.useDeleteRoomThread = _chunkV36VCKRBcjs.useDeleteRoomThread; exports.useDeleteTextMention = _chunkV36VCKRBcjs.useDeleteTextMention; exports.useEditRoomComment = _chunkV36VCKRBcjs.useEditRoomComment; exports.useEditRoomThreadMetadata = _chunkV36VCKRBcjs.useEditRoomThreadMetadata; exports.useLatest = _chunkV36VCKRBcjs.useLatest; exports.useLayoutEffect = useLayoutEffect; exports.useMarkRoomThreadAsRead = _chunkV36VCKRBcjs.useMarkRoomThreadAsRead; exports.useMarkRoomThreadAsResolved = _chunkV36VCKRBcjs.useMarkRoomThreadAsResolved; exports.useMarkRoomThreadAsUnresolved = _chunkV36VCKRBcjs.useMarkRoomThreadAsUnresolved; exports.useMentionSuggestions = useMentionSuggestions; exports.useMentionSuggestionsCache = _chunkV36VCKRBcjs.useMentionSuggestionsCache; exports.useRemoveRoomCommentReaction = _chunkV36VCKRBcjs.useRemoveRoomCommentReaction; exports.useReportTextEditor = _chunkV36VCKRBcjs.useReportTextEditor; exports.useResolveMentionSuggestions = _chunkV36VCKRBcjs.useResolveMentionSuggestions; exports.useRoomAttachmentUrl = _chunkV36VCKRBcjs.useRoomAttachmentUrl; exports.useRoomPermissions = _chunkV36VCKRBcjs.useRoomPermissions; exports.useRoomThreadSubscription = _chunkV36VCKRBcjs.useRoomThreadSubscription; exports.useSignal = _chunkV36VCKRBcjs.useSignal; exports.useSyncExternalStoreWithSelector = _chunkV36VCKRBcjs.useSyncExternalStoreWithSelector; exports.useSyncSource = useSyncSource; exports.useYjsProvider = _chunkV36VCKRBcjs.useYjsProvider;
142
142
  //# sourceMappingURL=_private.cjs.map
@@ -1,4 +1,4 @@
1
- export { g as getUmbrellaStoreForClient, a as useAddRoomCommentReaction, u as useClientOrNull, b as useCreateRoomComment, c as useCreateRoomThread, d as useCreateTextMention, e as useDeleteRoomComment, f as useDeleteRoomThread, h as useDeleteTextMention, i as useEditRoomComment, j as useEditRoomThreadMetadata, k as useMarkRoomThreadAsRead, l as useMarkRoomThreadAsResolved, m as useMarkRoomThreadAsUnresolved, n as useMentionSuggestionsCache, o as useRemoveRoomCommentReaction, p as useReportTextEditor, q as useResolveMentionSuggestions, r as useRoomAttachmentUrl, s as useRoomPermissions, t as useRoomThreadSubscription, v as useYjsProvider } from './room-DRYXmQT5.cjs';
1
+ export { g as getUmbrellaStoreForClient, a as useAddRoomCommentReaction, u as useClientOrNull, b as useCreateRoomComment, c as useCreateRoomThread, d as useCreateTextMention, e as useDeleteRoomComment, f as useDeleteRoomThread, h as useDeleteTextMention, i as useEditRoomComment, j as useEditRoomThreadMetadata, k as useMarkRoomThreadAsRead, l as useMarkRoomThreadAsResolved, m as useMarkRoomThreadAsUnresolved, n as useMentionSuggestionsCache, o as useRemoveRoomCommentReaction, p as useReportTextEditor, q as useResolveMentionSuggestions, r as useRoomAttachmentUrl, s as useRoomPermissions, t as useRoomThreadSubscription, v as useYjsProvider } from './room-BE4TZf40.cjs';
2
2
  import { MutableRefObject, useEffect } from 'react';
3
3
  import { ISignal, SyncSource } from '@liveblocks/core';
4
4
  import '@liveblocks/client';
@@ -1,4 +1,4 @@
1
- export { g as getUmbrellaStoreForClient, a as useAddRoomCommentReaction, u as useClientOrNull, b as useCreateRoomComment, c as useCreateRoomThread, d as useCreateTextMention, e as useDeleteRoomComment, f as useDeleteRoomThread, h as useDeleteTextMention, i as useEditRoomComment, j as useEditRoomThreadMetadata, k as useMarkRoomThreadAsRead, l as useMarkRoomThreadAsResolved, m as useMarkRoomThreadAsUnresolved, n as useMentionSuggestionsCache, o as useRemoveRoomCommentReaction, p as useReportTextEditor, q as useResolveMentionSuggestions, r as useRoomAttachmentUrl, s as useRoomPermissions, t as useRoomThreadSubscription, v as useYjsProvider } from './room-DRYXmQT5.js';
1
+ export { g as getUmbrellaStoreForClient, a as useAddRoomCommentReaction, u as useClientOrNull, b as useCreateRoomComment, c as useCreateRoomThread, d as useCreateTextMention, e as useDeleteRoomComment, f as useDeleteRoomThread, h as useDeleteTextMention, i as useEditRoomComment, j as useEditRoomThreadMetadata, k as useMarkRoomThreadAsRead, l as useMarkRoomThreadAsResolved, m as useMarkRoomThreadAsUnresolved, n as useMentionSuggestionsCache, o as useRemoveRoomCommentReaction, p as useReportTextEditor, q as useResolveMentionSuggestions, r as useRoomAttachmentUrl, s as useRoomPermissions, t as useRoomThreadSubscription, v as useYjsProvider } from './room-BE4TZf40.js';
2
2
  import { MutableRefObject, useEffect } from 'react';
3
3
  import { ISignal, SyncSource } from '@liveblocks/core';
4
4
  import '@liveblocks/client';
package/dist/_private.js CHANGED
@@ -25,7 +25,7 @@ import {
25
25
  useSignal,
26
26
  useSyncExternalStoreWithSelector,
27
27
  useYjsProvider
28
- } from "./chunk-YZRXMG3Z.js";
28
+ } from "./chunk-UHR5FZDL.js";
29
29
 
30
30
  // src/lib/use-layout-effect.ts
31
31
  import { useEffect, useLayoutEffect as useOriginalLayoutEffect } from "react";
@@ -1,6 +1,6 @@
1
1
  // src/version.ts
2
2
  var PKG_NAME = "@liveblocks/react";
3
- var PKG_VERSION = "3.2.1";
3
+ var PKG_VERSION = "3.3.1";
4
4
  var PKG_FORMAT = "esm";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -20,4 +20,4 @@ export {
20
20
  PKG_FORMAT,
21
21
  ClientSideSuspense
22
22
  };
23
- //# sourceMappingURL=chunk-G4GBR6VV.js.map
23
+ //# sourceMappingURL=chunk-45ZT2X3R.js.map
@@ -1,6 +1,6 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/version.ts
2
2
  var PKG_NAME = "@liveblocks/react";
3
- var PKG_VERSION = "3.2.1";
3
+ var PKG_VERSION = "3.3.1";
4
4
  var PKG_FORMAT = "cjs";
5
5
 
6
6
  // src/ClientSideSuspense.tsx
@@ -20,4 +20,4 @@ function ClientSideSuspense(props) {
20
20
 
21
21
 
22
22
  exports.PKG_NAME = PKG_NAME; exports.PKG_VERSION = PKG_VERSION; exports.PKG_FORMAT = PKG_FORMAT; exports.ClientSideSuspense = ClientSideSuspense;
23
- //# sourceMappingURL=chunk-VARKVHO4.cjs.map
23
+ //# sourceMappingURL=chunk-S7XMPZC4.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-VARKVHO4.cjs","../src/version.ts","../src/ClientSideSuspense.tsx"],"names":[],"mappings":"AAAA;ACGO,IAAM,SAAA,EAAW,mBAAA;AACjB,IAAM,YAAA,EAAiD,OAAA;AACvD,IAAM,WAAA,EAAgD,KAAA;ADD7D;AACA;AEJA,8BAA8C;AAkC1C,+CAAA;AAVG,SAAS,kBAAA,CAAmB,KAAA,EAAc;AAC/C,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,EAAA,EAAI,6BAAA,KAAc,CAAA;AAE5C,EAAA,8BAAA,CAAU,EAAA,GAAM;AAGd,IAAA,UAAA,CAAW,IAAI,CAAA;AAAA,EACjB,CAAA,EAAG,CAAC,CAAC,CAAA;AAEL,EAAA,uBACE,6BAAA,eAAC,EAAA,EAAS,QAAA,EAAU,KAAA,CAAM,QAAA,EACvB,QAAA,EAAA,QAAA,EACG,OAAO,KAAA,CAAM,SAAA,IAAa,WAAA,EACxB,KAAA,CAAM,QAAA,CAAS,EAAA,EACf,KAAA,CAAM,SAAA,EACR,KAAA,CAAM,SAAA,CACZ,CAAA;AAEJ;AF5BA;AACA;AACE;AACA;AACA;AACA;AACF,iJAAC","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-VARKVHO4.cjs","sourcesContent":[null,"declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n","import type { ReactNode } from \"react\";\nimport { Suspense, useEffect, useState } from \"react\";\n\ntype Props = {\n fallback: ReactNode;\n children: (() => ReactNode | undefined) | ReactNode | undefined;\n};\n\n/**\n * Almost like a normal <Suspense> component, except that for server-side\n * renders, the fallback will be used.\n *\n * The child props will have to be provided in a function, i.e. change:\n *\n * <Suspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </Suspense>\n *\n * To:\n *\n * <ClientSideSuspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </ClientSideSuspense>\n *\n */\nexport function ClientSideSuspense(props: Props) {\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n // Effects are never executed on the server side. The point of this is to\n // delay the flipping of this boolean until after hydration has happened.\n setMounted(true);\n }, []);\n\n return (\n <Suspense fallback={props.fallback}>\n {mounted\n ? typeof props.children === \"function\"\n ? props.children()\n : props.children\n : props.fallback}\n </Suspense>\n );\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-S7XMPZC4.cjs","../src/version.ts","../src/ClientSideSuspense.tsx"],"names":[],"mappings":"AAAA;ACGO,IAAM,SAAA,EAAW,mBAAA;AACjB,IAAM,YAAA,EAAiD,OAAA;AACvD,IAAM,WAAA,EAAgD,KAAA;ADD7D;AACA;AEJA,8BAA8C;AAkC1C,+CAAA;AAVG,SAAS,kBAAA,CAAmB,KAAA,EAAc;AAC/C,EAAA,MAAM,CAAC,OAAA,EAAS,UAAU,EAAA,EAAI,6BAAA,KAAc,CAAA;AAE5C,EAAA,8BAAA,CAAU,EAAA,GAAM;AAGd,IAAA,UAAA,CAAW,IAAI,CAAA;AAAA,EACjB,CAAA,EAAG,CAAC,CAAC,CAAA;AAEL,EAAA,uBACE,6BAAA,eAAC,EAAA,EAAS,QAAA,EAAU,KAAA,CAAM,QAAA,EACvB,QAAA,EAAA,QAAA,EACG,OAAO,KAAA,CAAM,SAAA,IAAa,WAAA,EACxB,KAAA,CAAM,QAAA,CAAS,EAAA,EACf,KAAA,CAAM,SAAA,EACR,KAAA,CAAM,SAAA,CACZ,CAAA;AAEJ;AF5BA;AACA;AACE;AACA;AACA;AACA;AACF,iJAAC","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-react/dist/chunk-S7XMPZC4.cjs","sourcesContent":[null,"declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/react\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n","import type { ReactNode } from \"react\";\nimport { Suspense, useEffect, useState } from \"react\";\n\ntype Props = {\n fallback: ReactNode;\n children: (() => ReactNode | undefined) | ReactNode | undefined;\n};\n\n/**\n * Almost like a normal <Suspense> component, except that for server-side\n * renders, the fallback will be used.\n *\n * The child props will have to be provided in a function, i.e. change:\n *\n * <Suspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </Suspense>\n *\n * To:\n *\n * <ClientSideSuspense fallback={<Loading />}>\n * <MyRealComponent a={1} />\n * </ClientSideSuspense>\n *\n */\nexport function ClientSideSuspense(props: Props) {\n const [mounted, setMounted] = useState(false);\n\n useEffect(() => {\n // Effects are never executed on the server side. The point of this is to\n // delay the flipping of this boolean until after hydration has happened.\n setMounted(true);\n }, []);\n\n return (\n <Suspense fallback={props.fallback}>\n {mounted\n ? typeof props.children === \"function\"\n ? props.children()\n : props.children\n : props.fallback}\n </Suspense>\n );\n}\n"]}
@@ -258,31 +258,30 @@ function useInitialUnlessFunction(latestValue) {
258
258
  }
259
259
 
260
260
  // src/lib/use-polyfill.ts
261
- var use = (
262
- // React.use ||
263
- (promise) => {
264
- if (promise.status === "pending") {
265
- throw promise;
266
- } else if (promise.status === "fulfilled") {
267
- return promise.value;
268
- } else if (promise.status === "rejected") {
269
- throw promise.reason;
270
- } else {
271
- promise.status = "pending";
272
- promise.then(
273
- (v) => {
274
- promise.status = "fulfilled";
275
- promise.value = v;
276
- },
277
- (e) => {
278
- promise.status = "rejected";
279
- promise.reason = e;
280
- }
281
- );
282
- throw promise;
283
- }
261
+ import * as React from "react";
262
+ var reactUse = React[" use ".trim().toString()];
263
+ var use = reactUse ?? ((promise) => {
264
+ if (promise.status === "pending") {
265
+ throw promise;
266
+ } else if (promise.status === "fulfilled") {
267
+ return promise.value;
268
+ } else if (promise.status === "rejected") {
269
+ throw promise.reason;
270
+ } else {
271
+ promise.status = "pending";
272
+ promise.then(
273
+ (v) => {
274
+ promise.status = "fulfilled";
275
+ promise.value = v;
276
+ },
277
+ (e) => {
278
+ promise.status = "rejected";
279
+ promise.reason = e;
280
+ }
281
+ );
282
+ throw promise;
284
283
  }
285
- );
284
+ });
286
285
 
287
286
  // src/umbrella-store.ts
288
287
  import {
@@ -488,6 +487,9 @@ function makeRoomThreadsQueryKey(roomId, query) {
488
487
  function makeUserThreadsQueryKey(query) {
489
488
  return stableStringify(query ?? {});
490
489
  }
490
+ function makeAiChatsQueryKey(query) {
491
+ return stableStringify(query ?? {});
492
+ }
491
493
  function usify(promise) {
492
494
  if ("status" in promise) {
493
495
  return promise;
@@ -925,8 +927,6 @@ var UmbrellaStore = class {
925
927
  #roomVersionsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
926
928
  // Notification Settings
927
929
  #notificationSettings;
928
- // Copilot chats
929
- #aiChats;
930
930
  constructor(client) {
931
931
  this.#client = client[kInternal2].as();
932
932
  this.optimisticUpdates = createStore_forOptimistic(this.#client);
@@ -956,12 +956,6 @@ var UmbrellaStore = class {
956
956
  this.#notificationSettings = new SinglePageResource(
957
957
  notificationSettingsFetcher
958
958
  );
959
- this.#aiChats = new PaginatedResource(async (cursor) => {
960
- const result = await this.#client[kInternal2].ai.getChats({
961
- cursor
962
- });
963
- return result.nextCursor;
964
- });
965
959
  this.threads = new ThreadDB();
966
960
  this.subscriptions = createStore_forSubscriptions(
967
961
  this.optimisticUpdates.signal,
@@ -1168,23 +1162,34 @@ var UmbrellaStore = class {
1168
1162
  }, shallow),
1169
1163
  waitUntilLoaded: this.#notificationSettings.waitUntilLoaded
1170
1164
  };
1171
- const aiChats = {
1172
- signal: DerivedSignal.from(() => {
1173
- const result = this.#aiChats.get();
1174
- if (result.isLoading || result.error) {
1175
- return result;
1176
- }
1177
- return {
1178
- isLoading: false,
1179
- chats: this.#client[kInternal2].ai.signals.chats\u03A3.get(),
1180
- hasFetchedAll: result.data.hasFetchedAll,
1181
- isFetchingMore: result.data.isFetchingMore,
1182
- fetchMore: result.data.fetchMore,
1183
- fetchMoreError: result.data.fetchMoreError
1184
- };
1185
- }, shallow),
1186
- waitUntilLoaded: this.#aiChats.waitUntilLoaded
1187
- };
1165
+ const aiChats = new DefaultMap(
1166
+ (queryKey) => {
1167
+ const query = JSON.parse(queryKey);
1168
+ const resource = new PaginatedResource(async (cursor) => {
1169
+ const result = await this.#client[kInternal2].ai.getChats({
1170
+ cursor,
1171
+ query
1172
+ });
1173
+ return result.nextCursor;
1174
+ });
1175
+ const signal = DerivedSignal.from(() => {
1176
+ const result = resource.get();
1177
+ if (result.isLoading || result.error) {
1178
+ return result;
1179
+ }
1180
+ const chats = this.#client[kInternal2].ai.queryChats(query);
1181
+ return {
1182
+ isLoading: false,
1183
+ chats,
1184
+ hasFetchedAll: result.data.hasFetchedAll,
1185
+ isFetchingMore: result.data.isFetchingMore,
1186
+ fetchMore: result.data.fetchMore,
1187
+ fetchMoreError: result.data.fetchMoreError
1188
+ };
1189
+ }, shallow);
1190
+ return { signal, waitUntilLoaded: resource.waitUntilLoaded };
1191
+ }
1192
+ );
1188
1193
  const messagesByChatId = new DefaultMap((chatId) => {
1189
1194
  const resource\u03A3 = new SinglePageResource(async () => {
1190
1195
  await this.#client[kInternal2].ai.getMessageTree(chatId);
@@ -2526,12 +2531,13 @@ function useRoomInfoSuspense_withClient(client, roomId) {
2526
2531
  error: void 0
2527
2532
  };
2528
2533
  }
2529
- function useAiChats() {
2534
+ function useAiChats(options) {
2530
2535
  const client = useClient();
2531
2536
  const store = getUmbrellaStoreForClient(client);
2537
+ const queryKey = makeAiChatsQueryKey(options?.query);
2532
2538
  useEnsureAiConnection(client);
2533
2539
  useEffect4(
2534
- () => void store.outputs.aiChats.waitUntilLoaded()
2540
+ () => void store.outputs.aiChats.getOrCreate(queryKey).waitUntilLoaded()
2535
2541
  // NOTE: Deliberately *not* using a dependency array here!
2536
2542
  //
2537
2543
  // It is important to call waitUntil on *every* render.
@@ -2541,15 +2547,16 @@ function useAiChats() {
2541
2547
  // 3. If ever the promise would fail, then after 5 seconds it would reset, and on the very
2542
2548
  // *next* render after that, a *new* fetch/promise will get created.
2543
2549
  );
2544
- return useSignal(store.outputs.aiChats.signal, identity2, shallow3);
2550
+ return useSignal(store.outputs.aiChats.getOrCreate(queryKey).signal, identity2, shallow3);
2545
2551
  }
2546
- function useAiChatsSuspense() {
2552
+ function useAiChatsSuspense(options) {
2547
2553
  ensureNotServerSide();
2548
2554
  const client = useClient();
2549
2555
  const store = getUmbrellaStoreForClient(client);
2550
2556
  useEnsureAiConnection(client);
2551
- use(store.outputs.aiChats.waitUntilLoaded());
2552
- const result = useAiChats();
2557
+ const queryKey = makeAiChatsQueryKey(options?.query);
2558
+ use(store.outputs.aiChats.getOrCreate(queryKey).waitUntilLoaded());
2559
+ const result = useAiChats(options);
2553
2560
  assert(!result.error, "Did not expect error");
2554
2561
  assert(!result.isLoading, "Did not expect loading");
2555
2562
  return result;
@@ -2618,6 +2625,9 @@ function useCreateAiChat() {
2618
2625
  const client = useClient();
2619
2626
  return useCallback2(
2620
2627
  (options) => {
2628
+ if (typeof options === "string") {
2629
+ options = { id: options };
2630
+ }
2621
2631
  client[kInternal3].ai.getOrCreateChat(options.id, {
2622
2632
  title: options.title,
2623
2633
  metadata: options.metadata
@@ -2645,35 +2655,54 @@ function useDeleteAiChat() {
2645
2655
  }
2646
2656
  function useSendAiMessage(chatId, options) {
2647
2657
  const client = useClient();
2648
- const copilotId = options?.copilotId;
2649
2658
  return useCallback2(
2650
2659
  (message) => {
2651
- const messages = client[kInternal3].ai.signals.getChatMessagesForBranch\u03A3(chatId).get();
2660
+ const {
2661
+ text: messageText,
2662
+ chatId: messageOptionsChatId,
2663
+ ...messageOptions
2664
+ } = typeof message === "string" ? { text: message } : message;
2665
+ const resolvedChatId = messageOptionsChatId ?? chatId ?? // The `useSendAiMessage` overloads prevent this scenario from happening
2666
+ // at the type level, and this error prevents it from happening at runtime.
2667
+ raise2(
2668
+ "chatId must be provided to either `useSendAiMessage` or its returned function."
2669
+ );
2670
+ const messages = client[kInternal3].ai.signals.getChatMessagesForBranch\u03A3(resolvedChatId).get();
2652
2671
  const lastMessageId = messages[messages.length - 1]?.id ?? null;
2653
- const content = [{ type: "text", text: message }];
2672
+ const content = [{ type: "text", text: messageText }];
2654
2673
  const newMessageId = client[kInternal3].ai[kInternal3].context.messagesStore.createOptimistically(
2655
- chatId,
2674
+ resolvedChatId,
2656
2675
  "user",
2657
2676
  lastMessageId,
2658
2677
  content
2659
2678
  );
2679
+ const newMessage = client[kInternal3].ai[kInternal3].context.messagesStore.getMessageById(newMessageId);
2660
2680
  const targetMessageId = client[kInternal3].ai[kInternal3].context.messagesStore.createOptimistically(
2661
- chatId,
2681
+ resolvedChatId,
2662
2682
  "assistant",
2663
2683
  newMessageId
2664
2684
  );
2665
2685
  void client[kInternal3].ai.askUserMessageInChat(
2666
- chatId,
2686
+ resolvedChatId,
2667
2687
  { id: newMessageId, parentMessageId: lastMessageId, content },
2668
2688
  targetMessageId,
2669
2689
  {
2670
- stream: options?.stream,
2671
- copilotId,
2672
- timeout: options?.timeout
2690
+ stream: messageOptions.stream ?? options?.stream,
2691
+ copilotId: messageOptions.copilotId ?? options?.copilotId,
2692
+ timeout: messageOptions.timeout ?? options?.timeout,
2693
+ knowledge: messageOptions.knowledge ?? options?.knowledge
2673
2694
  }
2674
2695
  );
2696
+ return newMessage;
2675
2697
  },
2676
- [client, chatId, copilotId, options?.stream, options?.timeout]
2698
+ [
2699
+ client,
2700
+ chatId,
2701
+ options?.copilotId,
2702
+ options?.stream,
2703
+ options?.timeout,
2704
+ options?.knowledge
2705
+ ]
2677
2706
  );
2678
2707
  }
2679
2708
  function createSharedContext(client) {
@@ -4639,4 +4668,4 @@ export {
4639
4668
  _useStorageRoot,
4640
4669
  _useUpdateMyPresence
4641
4670
  };
4642
- //# sourceMappingURL=chunk-YZRXMG3Z.js.map
4671
+ //# sourceMappingURL=chunk-UHR5FZDL.js.map