@liveblocks/react 3.13.0-vincent3 → 3.13.1-hackathon

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.
@@ -330,7 +330,7 @@ function find(it, predicate) {
330
330
 
331
331
 
332
332
  function makeThreadsFilter(query, subscriptions) {
333
- return (thread) => matchesThreadsQuery(thread, query, subscriptions) && matchesMetadata(thread, query);
333
+ return (thread) => matchesThreadsQuery(thread, query, subscriptions) && matchesThreadMetadata(thread, query);
334
334
  }
335
335
  function matchesThreadsQuery(thread, q, subscriptions) {
336
336
  let subscription = void 0;
@@ -339,7 +339,7 @@ function matchesThreadsQuery(thread, q, subscriptions) {
339
339
  }
340
340
  return (q.resolved === void 0 || thread.resolved === q.resolved) && (q.subscribed === void 0 || q.subscribed === true && subscription !== void 0 || q.subscribed === false && subscription === void 0);
341
341
  }
342
- function matchesMetadata(thread, q) {
342
+ function matchesThreadMetadata(thread, q) {
343
343
  const metadata = thread.metadata;
344
344
  return q.metadata === void 0 || Object.entries(q.metadata).every(
345
345
  ([key, op]) => (
@@ -512,6 +512,12 @@ function makeAiChatsQueryKey(query) {
512
512
  function makeInboxNotificationsQueryKey(query) {
513
513
  return _core.stableStringify.call(void 0, _nullishCoalesce(query, () => ( {})));
514
514
  }
515
+ function makeAgentSessionsQueryKey(roomId, options) {
516
+ return _core.stableStringify.call(void 0, [roomId, _nullishCoalesce(options, () => ( {}))]);
517
+ }
518
+ function makeAgentMessagesQueryKey(roomId, sessionId, options) {
519
+ return _core.stableStringify.call(void 0, [roomId, sessionId, _nullishCoalesce(options, () => ( {}))]);
520
+ }
515
521
  function usify(promise) {
516
522
  if ("status" in promise) {
517
523
  return promise;
@@ -978,6 +984,19 @@ var UmbrellaStore = class {
978
984
  #roomVersionsLastRequestedAtByRoom = /* @__PURE__ */ new Map();
979
985
  // Notification Settings
980
986
  #notificationSettings;
987
+ // Agent Sessions
988
+ #roomsByRoomId = /* @__PURE__ */ new Map();
989
+ // TODO: the need for this seems wrong, i need to explore if maybe this stuff belongs in in RoomContext and not here
990
+ #agentSessionsByRoomId = /* @__PURE__ */ new Map();
991
+ #agentMessagesBySessionId = /* @__PURE__ */ new Map();
992
+ // Signals for agent sessions and messages to trigger reactivity
993
+ // We use a version counter to track changes
994
+ #agentSessionsSignal = new (0, _core.MutableSignal)({
995
+ version: 0
996
+ });
997
+ #agentMessagesSignal = new (0, _core.MutableSignal)({
998
+ version: 0
999
+ });
981
1000
  constructor(client) {
982
1001
  this.#client = client[_core.kInternal].as();
983
1002
  this.optimisticUpdates = createStore_forOptimistic(this.#client);
@@ -1349,6 +1368,94 @@ var UmbrellaStore = class {
1349
1368
  return { signal, waitUntilLoaded: resource.waitUntilLoaded };
1350
1369
  }
1351
1370
  );
1371
+ const loadingAgentSessions = new (0, _core.DefaultMap)(
1372
+ (queryKey) => {
1373
+ const [roomId, options] = JSON.parse(queryKey);
1374
+ const resource = new PaginatedResource(async (cursor) => {
1375
+ const room = this.#roomsByRoomId.get(roomId);
1376
+ if (!room) {
1377
+ throw new Error(
1378
+ `Room ${roomId} not found. Make sure you're calling useAgentSessions inside a RoomProvider.`
1379
+ );
1380
+ }
1381
+ const typedRoom = room;
1382
+ const result = await typedRoom.fetchAgentSessions({
1383
+ cursor,
1384
+ since: _optionalChain([options, 'optionalAccess', _8 => _8.since]),
1385
+ metadata: _optionalChain([options, 'optionalAccess', _9 => _9.metadata])
1386
+ });
1387
+ this.updateAgentSessions(roomId, result.sessions, "list");
1388
+ return _nullishCoalesce(result.nextCursor, () => ( null));
1389
+ });
1390
+ const signal = _core.DerivedSignal.from(
1391
+ resource.signal,
1392
+ this.#agentSessionsSignal,
1393
+ (resourceResult, _signalState) => {
1394
+ if (resourceResult.isLoading || resourceResult.error) {
1395
+ return resourceResult;
1396
+ }
1397
+ const sessionsMap = this.#agentSessionsByRoomId.get(roomId);
1398
+ const sessions = sessionsMap ? Array.from(sessionsMap.values()) : [];
1399
+ const page = resourceResult.data;
1400
+ return {
1401
+ isLoading: false,
1402
+ sessions,
1403
+ hasFetchedAll: page.hasFetchedAll,
1404
+ isFetchingMore: page.isFetchingMore,
1405
+ fetchMoreError: page.fetchMoreError,
1406
+ fetchMore: page.fetchMore
1407
+ };
1408
+ },
1409
+ _core.shallow2
1410
+ );
1411
+ return { signal, waitUntilLoaded: resource.waitUntilLoaded };
1412
+ }
1413
+ );
1414
+ const loadingAgentMessages = new (0, _core.DefaultMap)(
1415
+ (queryKey) => {
1416
+ const [roomId, sessionId, options] = JSON.parse(queryKey);
1417
+ const resource = new PaginatedResource(async (cursor) => {
1418
+ const room = this.#roomsByRoomId.get(roomId);
1419
+ if (!room) {
1420
+ throw new Error(
1421
+ `Room ${roomId} not found. Make sure you're calling useAgentSession inside a RoomProvider.`
1422
+ );
1423
+ }
1424
+ const typedRoom = room;
1425
+ const result = await typedRoom.fetchAgentMessages(sessionId, {
1426
+ cursor,
1427
+ limit: _optionalChain([options, 'optionalAccess', _10 => _10.limit])
1428
+ });
1429
+ this.updateAgentMessages(roomId, sessionId, result.messages, "list");
1430
+ return _nullishCoalesce(result.nextCursor, () => ( null));
1431
+ });
1432
+ const signal = _core.DerivedSignal.from(
1433
+ resource.signal,
1434
+ this.#agentMessagesSignal,
1435
+ (resourceResult, _signalState) => {
1436
+ if (resourceResult.isLoading || resourceResult.error) {
1437
+ return resourceResult;
1438
+ }
1439
+ const messagesMap = this.#agentMessagesBySessionId.get(sessionId);
1440
+ const messages = messagesMap ? Array.from(messagesMap.values()).sort(
1441
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1442
+ (a, b) => a.timestamp - b.timestamp
1443
+ ) : [];
1444
+ const page = resourceResult.data;
1445
+ return {
1446
+ isLoading: false,
1447
+ messages,
1448
+ hasFetchedAll: page.hasFetchedAll,
1449
+ isFetchingMore: page.isFetchingMore,
1450
+ fetchMoreError: page.fetchMoreError,
1451
+ fetchMore: page.fetchMore
1452
+ };
1453
+ },
1454
+ _core.shallow2
1455
+ );
1456
+ return { signal, waitUntilLoaded: resource.waitUntilLoaded };
1457
+ }
1458
+ );
1352
1459
  this.outputs = {
1353
1460
  threadifications,
1354
1461
  threads,
@@ -1364,7 +1471,9 @@ var UmbrellaStore = class {
1364
1471
  aiChats,
1365
1472
  messagesByChatId,
1366
1473
  aiChatById,
1367
- urlMetadataByUrl
1474
+ urlMetadataByUrl,
1475
+ loadingAgentSessions,
1476
+ loadingAgentMessages
1368
1477
  };
1369
1478
  autobind(this);
1370
1479
  }
@@ -1519,6 +1628,26 @@ var UmbrellaStore = class {
1519
1628
  (thread) => applyUpsertComment(thread, editedComment)
1520
1629
  );
1521
1630
  }
1631
+ editCommentMetadata(threadId, commentId, optimisticId, updatedMetadata, updatedAt) {
1632
+ return this.#updateThread(
1633
+ threadId,
1634
+ optimisticId,
1635
+ (thread) => {
1636
+ const comment = thread.comments.find((c) => c.id === commentId);
1637
+ if (comment === void 0) {
1638
+ return thread;
1639
+ }
1640
+ return {
1641
+ ...thread,
1642
+ updatedAt,
1643
+ comments: thread.comments.map(
1644
+ (c) => c.id === commentId ? { ...c, metadata: updatedMetadata } : c
1645
+ )
1646
+ };
1647
+ },
1648
+ updatedAt
1649
+ );
1650
+ }
1522
1651
  deleteComment(threadId, optimisticId, commentId, deletedAt) {
1523
1652
  return this.#updateThread(
1524
1653
  threadId,
@@ -1565,6 +1694,61 @@ var UmbrellaStore = class {
1565
1694
  result.subscriptions.deleted
1566
1695
  );
1567
1696
  }
1697
+ /**
1698
+ * Registers a room instance for agent session fetching.
1699
+ * Called by RoomProvider when it mounts.
1700
+ */
1701
+ registerRoom(roomId, room) {
1702
+ this.#roomsByRoomId.set(roomId, room);
1703
+ }
1704
+ /**
1705
+ * Unregisters a room instance.
1706
+ * Called by RoomProvider when it unmounts.
1707
+ */
1708
+ unregisterRoom(roomId) {
1709
+ this.#roomsByRoomId.delete(roomId);
1710
+ this.#agentSessionsByRoomId.delete(roomId);
1711
+ }
1712
+ /**
1713
+ * Updates the agent sessions cache based on WebSocket events.
1714
+ */
1715
+ updateAgentSessions(roomId, sessions, operation) {
1716
+ let sessionsMap = this.#agentSessionsByRoomId.get(roomId);
1717
+ if (!sessionsMap) {
1718
+ sessionsMap = /* @__PURE__ */ new Map();
1719
+ this.#agentSessionsByRoomId.set(roomId, sessionsMap);
1720
+ }
1721
+ for (const session of sessions) {
1722
+ if (operation === "deleted") {
1723
+ sessionsMap.delete(session.sessionId);
1724
+ } else {
1725
+ sessionsMap.set(session.sessionId, session);
1726
+ }
1727
+ }
1728
+ this.#agentSessionsSignal.mutate((state) => {
1729
+ state.version++;
1730
+ });
1731
+ }
1732
+ /**
1733
+ * Updates the agent messages cache based on WebSocket events.
1734
+ */
1735
+ updateAgentMessages(_roomId, sessionId, messages, operation) {
1736
+ let messagesMap = this.#agentMessagesBySessionId.get(sessionId);
1737
+ if (!messagesMap) {
1738
+ messagesMap = /* @__PURE__ */ new Map();
1739
+ this.#agentMessagesBySessionId.set(sessionId, messagesMap);
1740
+ }
1741
+ for (const message of messages) {
1742
+ if (operation === "deleted") {
1743
+ messagesMap.delete(message.id);
1744
+ } else {
1745
+ messagesMap.set(message.id, message);
1746
+ }
1747
+ }
1748
+ this.#agentMessagesSignal.mutate((state) => {
1749
+ state.version++;
1750
+ });
1751
+ }
1568
1752
  async fetchUnreadNotificationsCount(queryKey, signal) {
1569
1753
  const query = JSON.parse(queryKey);
1570
1754
  const result = await this.#client.getUnreadInboxNotificationsCount({
@@ -1724,6 +1908,27 @@ function applyOptimisticUpdates_forThreadifications(baseThreadsDB, notifications
1724
1908
  threadsDB.upsert(applyUpsertComment(thread, optimisticUpdate.comment));
1725
1909
  break;
1726
1910
  }
1911
+ case "edit-comment-metadata": {
1912
+ const thread = threadsDB.get(optimisticUpdate.threadId);
1913
+ if (thread === void 0) break;
1914
+ if (thread.updatedAt > optimisticUpdate.updatedAt) {
1915
+ break;
1916
+ }
1917
+ const existingComment = thread.comments.find(
1918
+ (c) => c.id === optimisticUpdate.commentId
1919
+ );
1920
+ if (existingComment === void 0) break;
1921
+ threadsDB.upsert(
1922
+ applyUpsertComment(thread, {
1923
+ ...existingComment,
1924
+ metadata: {
1925
+ ...existingComment.metadata,
1926
+ ...optimisticUpdate.metadata
1927
+ }
1928
+ })
1929
+ );
1930
+ break;
1931
+ }
1727
1932
  case "delete-comment": {
1728
1933
  const thread = threadsDB.get(optimisticUpdate.threadId);
1729
1934
  if (thread === void 0) break;
@@ -1930,7 +2135,20 @@ function applyUpsertComment(thread, comment) {
1930
2135
  return updatedThread;
1931
2136
  }
1932
2137
  if (existingComment.deletedAt !== void 0) {
1933
- return thread;
2138
+ const updatedComment = {
2139
+ ...existingComment,
2140
+ metadata: {
2141
+ ...existingComment.metadata,
2142
+ ...comment.metadata
2143
+ }
2144
+ };
2145
+ const updatedComments = thread.comments.map(
2146
+ (c) => c.id === comment.id ? updatedComment : c
2147
+ );
2148
+ return {
2149
+ ...thread,
2150
+ comments: updatedComments
2151
+ };
1934
2152
  }
1935
2153
  if (existingComment.editedAt === void 0 || comment.editedAt === void 0 || existingComment.editedAt <= comment.editedAt) {
1936
2154
  const updatedComments = thread.comments.map(
@@ -1941,7 +2159,7 @@ function applyUpsertComment(thread, comment) {
1941
2159
  updatedAt: new Date(
1942
2160
  Math.max(
1943
2161
  thread.updatedAt.getTime(),
1944
- _optionalChain([comment, 'access', _8 => _8.editedAt, 'optionalAccess', _9 => _9.getTime, 'call', _10 => _10()]) || comment.createdAt.getTime()
2162
+ _optionalChain([comment, 'access', _11 => _11.editedAt, 'optionalAccess', _12 => _12.getTime, 'call', _13 => _13()]) || comment.createdAt.getTime()
1945
2163
  )
1946
2164
  ),
1947
2165
  comments: updatedComments
@@ -2098,7 +2316,7 @@ function selectorFor_useUnreadInboxNotificationsCount(result) {
2098
2316
  return ASYNC_OK("count", result.count);
2099
2317
  }
2100
2318
  function selectorFor_useUser(state, userId) {
2101
- if (state === void 0 || _optionalChain([state, 'optionalAccess', _11 => _11.isLoading])) {
2319
+ if (state === void 0 || _optionalChain([state, 'optionalAccess', _14 => _14.isLoading])) {
2102
2320
  return _nullishCoalesce(state, () => ( { isLoading: true }));
2103
2321
  }
2104
2322
  if (state.error) {
@@ -2116,7 +2334,7 @@ function selectorFor_useUser(state, userId) {
2116
2334
  };
2117
2335
  }
2118
2336
  function selectorFor_useRoomInfo(state, roomId) {
2119
- if (state === void 0 || _optionalChain([state, 'optionalAccess', _12 => _12.isLoading])) {
2337
+ if (state === void 0 || _optionalChain([state, 'optionalAccess', _15 => _15.isLoading])) {
2120
2338
  return _nullishCoalesce(state, () => ( { isLoading: true }));
2121
2339
  }
2122
2340
  if (state.error) {
@@ -2134,7 +2352,7 @@ function selectorFor_useRoomInfo(state, roomId) {
2134
2352
  };
2135
2353
  }
2136
2354
  function selectorFor_useGroupInfo(state, groupId) {
2137
- if (state === void 0 || _optionalChain([state, 'optionalAccess', _13 => _13.isLoading])) {
2355
+ if (state === void 0 || _optionalChain([state, 'optionalAccess', _16 => _16.isLoading])) {
2138
2356
  return _nullishCoalesce(state, () => ( { isLoading: true }));
2139
2357
  }
2140
2358
  if (state.error) {
@@ -2304,7 +2522,7 @@ function makeLiveblocksContextBundle(client) {
2304
2522
  }
2305
2523
  function useInboxNotifications_withClient(client, selector, isEqual, options) {
2306
2524
  const { store, notificationsPoller: poller } = getLiveblocksExtrasForClient(client);
2307
- const queryKey = makeInboxNotificationsQueryKey(_optionalChain([options, 'optionalAccess', _14 => _14.query]));
2525
+ const queryKey = makeInboxNotificationsQueryKey(_optionalChain([options, 'optionalAccess', _17 => _17.query]));
2308
2526
  _react.useEffect.call(void 0,
2309
2527
  () => void store.outputs.loadingNotifications.getOrCreate(queryKey).waitUntilLoaded()
2310
2528
  // NOTE: Deliberately *not* using a dependency array here!
@@ -2332,7 +2550,7 @@ function useInboxNotifications_withClient(client, selector, isEqual, options) {
2332
2550
  function useInboxNotificationsSuspense_withClient(client, options) {
2333
2551
  ensureNotServerSide();
2334
2552
  const store = getLiveblocksExtrasForClient(client).store;
2335
- const queryKey = makeInboxNotificationsQueryKey(_optionalChain([options, 'optionalAccess', _15 => _15.query]));
2553
+ const queryKey = makeInboxNotificationsQueryKey(_optionalChain([options, 'optionalAccess', _18 => _18.query]));
2336
2554
  use(
2337
2555
  store.outputs.loadingNotifications.getOrCreate(queryKey).waitUntilLoaded()
2338
2556
  );
@@ -2348,7 +2566,7 @@ function useInboxNotificationsSuspense_withClient(client, options) {
2348
2566
  }
2349
2567
  function useUnreadInboxNotificationsCount_withClient(client, options) {
2350
2568
  const { store, unreadNotificationsCountPollersByQueryKey: pollers } = getLiveblocksExtrasForClient(client);
2351
- const queryKey = makeInboxNotificationsQueryKey(_optionalChain([options, 'optionalAccess', _16 => _16.query]));
2569
+ const queryKey = makeInboxNotificationsQueryKey(_optionalChain([options, 'optionalAccess', _19 => _19.query]));
2352
2570
  const poller = pollers.getOrCreate(queryKey);
2353
2571
  _react.useEffect.call(void 0,
2354
2572
  () => void store.outputs.unreadNotificationsCount.getOrCreate(queryKey).waitUntilLoaded()
@@ -2377,7 +2595,7 @@ function useUnreadInboxNotificationsCount_withClient(client, options) {
2377
2595
  function useUnreadInboxNotificationsCountSuspense_withClient(client, options) {
2378
2596
  ensureNotServerSide();
2379
2597
  const store = getLiveblocksExtrasForClient(client).store;
2380
- const queryKey = makeInboxNotificationsQueryKey(_optionalChain([options, 'optionalAccess', _17 => _17.query]));
2598
+ const queryKey = makeInboxNotificationsQueryKey(_optionalChain([options, 'optionalAccess', _20 => _20.query]));
2381
2599
  use(
2382
2600
  store.outputs.unreadNotificationsCount.getOrCreate(queryKey).waitUntilLoaded()
2383
2601
  );
@@ -2548,7 +2766,7 @@ function useUpdateNotificationSettings_withClient(client) {
2548
2766
  store.optimisticUpdates.remove(optimisticUpdateId);
2549
2767
  if (err instanceof _core.HttpError) {
2550
2768
  if (err.status === 422) {
2551
- const msg = [_optionalChain([err, 'access', _18 => _18.details, 'optionalAccess', _19 => _19.error]), _optionalChain([err, 'access', _20 => _20.details, 'optionalAccess', _21 => _21.reason])].filter(Boolean).join("\n");
2769
+ const msg = [_optionalChain([err, 'access', _21 => _21.details, 'optionalAccess', _22 => _22.error]), _optionalChain([err, 'access', _23 => _23.details, 'optionalAccess', _24 => _24.reason])].filter(Boolean).join("\n");
2552
2770
  _core.console.error(msg);
2553
2771
  }
2554
2772
  client[_core.kInternal].emitError(
@@ -2783,7 +3001,7 @@ function useGroupInfoSuspense_withClient(client, groupId) {
2783
3001
  function useAiChats(options) {
2784
3002
  const client = useClient();
2785
3003
  const store = getUmbrellaStoreForClient(client);
2786
- const queryKey = makeAiChatsQueryKey(_optionalChain([options, 'optionalAccess', _22 => _22.query]));
3004
+ const queryKey = makeAiChatsQueryKey(_optionalChain([options, 'optionalAccess', _25 => _25.query]));
2787
3005
  useEnsureAiConnection(client);
2788
3006
  _react.useEffect.call(void 0,
2789
3007
  () => void store.outputs.aiChats.getOrCreate(queryKey).waitUntilLoaded()
@@ -2807,7 +3025,7 @@ function useAiChatsSuspense(options) {
2807
3025
  const client = useClient();
2808
3026
  const store = getUmbrellaStoreForClient(client);
2809
3027
  useEnsureAiConnection(client);
2810
- const queryKey = makeAiChatsQueryKey(_optionalChain([options, 'optionalAccess', _23 => _23.query]));
3028
+ const queryKey = makeAiChatsQueryKey(_optionalChain([options, 'optionalAccess', _26 => _26.query]));
2811
3029
  use(store.outputs.aiChats.getOrCreate(queryKey).waitUntilLoaded());
2812
3030
  const result = useAiChats(options);
2813
3031
  _core.assert.call(void 0, !result.error, "Did not expect error");
@@ -2819,7 +3037,7 @@ function useAiChatMessages(chatId, options) {
2819
3037
  const store = getUmbrellaStoreForClient(client);
2820
3038
  useEnsureAiConnection(client);
2821
3039
  _react.useEffect.call(void 0,
2822
- () => void store.outputs.messagesByChatId.getOrCreate(chatId).getOrCreate(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _24 => _24.branchId]), () => ( null))).waitUntilLoaded()
3040
+ () => void store.outputs.messagesByChatId.getOrCreate(chatId).getOrCreate(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _27 => _27.branchId]), () => ( null))).waitUntilLoaded()
2823
3041
  // NOTE: Deliberately *not* using a dependency array here!
2824
3042
  //
2825
3043
  // It is important to call waitUntil on *every* render.
@@ -2830,7 +3048,7 @@ function useAiChatMessages(chatId, options) {
2830
3048
  // *next* render after that, a *new* fetch/promise will get created.
2831
3049
  );
2832
3050
  return useSignal(
2833
- store.outputs.messagesByChatId.getOrCreate(chatId).getOrCreate(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _25 => _25.branchId]), () => ( null))).signal
3051
+ store.outputs.messagesByChatId.getOrCreate(chatId).getOrCreate(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _28 => _28.branchId]), () => ( null))).signal
2834
3052
  );
2835
3053
  }
2836
3054
  function useAiChatMessagesSuspense(chatId, options) {
@@ -2839,7 +3057,7 @@ function useAiChatMessagesSuspense(chatId, options) {
2839
3057
  const store = getUmbrellaStoreForClient(client);
2840
3058
  useEnsureAiConnection(client);
2841
3059
  use(
2842
- store.outputs.messagesByChatId.getOrCreate(chatId).getOrCreate(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _26 => _26.branchId]), () => ( null))).waitUntilLoaded()
3060
+ store.outputs.messagesByChatId.getOrCreate(chatId).getOrCreate(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _29 => _29.branchId]), () => ( null))).waitUntilLoaded()
2843
3061
  );
2844
3062
  const result = useAiChatMessages(chatId, options);
2845
3063
  _core.assert.call(void 0, !result.error, "Did not expect error");
@@ -2958,12 +3176,12 @@ function useAiChatStatus(chatId, branchId) {
2958
3176
  if (result.error) return IDLE;
2959
3177
  const messages = result.messages;
2960
3178
  const lastMessage = messages[messages.length - 1];
2961
- if (_optionalChain([lastMessage, 'optionalAccess', _27 => _27.role]) !== "assistant") return IDLE;
3179
+ if (_optionalChain([lastMessage, 'optionalAccess', _30 => _30.role]) !== "assistant") return IDLE;
2962
3180
  if (lastMessage.status !== "generating" && lastMessage.status !== "awaiting-tool")
2963
3181
  return IDLE;
2964
3182
  const contentSoFar = lastMessage.contentSoFar;
2965
3183
  const lastPart = contentSoFar[contentSoFar.length - 1];
2966
- if (_optionalChain([lastPart, 'optionalAccess', _28 => _28.type]) === "tool-invocation") {
3184
+ if (_optionalChain([lastPart, 'optionalAccess', _31 => _31.type]) === "tool-invocation") {
2967
3185
  return {
2968
3186
  status: "generating",
2969
3187
  partType: "tool-invocation",
@@ -2972,7 +3190,7 @@ function useAiChatStatus(chatId, branchId) {
2972
3190
  } else {
2973
3191
  return {
2974
3192
  status: "generating",
2975
- partType: _optionalChain([lastPart, 'optionalAccess', _29 => _29.type])
3193
+ partType: _optionalChain([lastPart, 'optionalAccess', _32 => _32.type])
2976
3194
  };
2977
3195
  }
2978
3196
  },
@@ -3000,7 +3218,7 @@ function useSendAiMessage(chatId, options) {
3000
3218
  "chatId must be provided to either `useSendAiMessage` or its returned function."
3001
3219
  )));
3002
3220
  const messages = client[_core.kInternal].ai.signals.getChatMessagesForBranch\u03A3(resolvedChatId).get();
3003
- if (process.env.NODE_ENV !== "production" && !messageOptionsCopilotId && !_optionalChain([options, 'optionalAccess', _30 => _30.copilotId])) {
3221
+ if (process.env.NODE_ENV !== "production" && !messageOptionsCopilotId && !_optionalChain([options, 'optionalAccess', _33 => _33.copilotId])) {
3004
3222
  _core.console.warn(
3005
3223
  `No copilot ID was provided to useSendAiMessage when sending the message "${messageText.slice(
3006
3224
  0,
@@ -3012,8 +3230,8 @@ To ensure the correct copilot ID is used, specify it either through the hook as
3012
3230
  )}\u2026", copilotId: "co_xxx" })'`
3013
3231
  );
3014
3232
  }
3015
- const resolvedCopilotId = _nullishCoalesce(_nullishCoalesce(messageOptionsCopilotId, () => ( _optionalChain([options, 'optionalAccess', _31 => _31.copilotId]))), () => ( client[_core.kInternal].ai.getLastUsedCopilotId(resolvedChatId)));
3016
- const lastMessageId = _nullishCoalesce(_optionalChain([messages, 'access', _32 => _32[messages.length - 1], 'optionalAccess', _33 => _33.id]), () => ( null));
3233
+ const resolvedCopilotId = _nullishCoalesce(_nullishCoalesce(messageOptionsCopilotId, () => ( _optionalChain([options, 'optionalAccess', _34 => _34.copilotId]))), () => ( client[_core.kInternal].ai.getLastUsedCopilotId(resolvedChatId)));
3234
+ const lastMessageId = _nullishCoalesce(_optionalChain([messages, 'access', _35 => _35[messages.length - 1], 'optionalAccess', _36 => _36.id]), () => ( null));
3017
3235
  const content = [{ type: "text", text: messageText }];
3018
3236
  const newMessageId = client[_core.kInternal].ai[_core.kInternal].context.messagesStore.createOptimistically(
3019
3237
  resolvedChatId,
@@ -3033,14 +3251,14 @@ To ensure the correct copilot ID is used, specify it either through the hook as
3033
3251
  { id: newMessageId, parentMessageId: lastMessageId, content },
3034
3252
  targetMessageId,
3035
3253
  {
3036
- stream: _nullishCoalesce(messageOptions.stream, () => ( _optionalChain([options, 'optionalAccess', _34 => _34.stream]))),
3254
+ stream: _nullishCoalesce(messageOptions.stream, () => ( _optionalChain([options, 'optionalAccess', _37 => _37.stream]))),
3037
3255
  copilotId: resolvedCopilotId,
3038
- timeout: _nullishCoalesce(messageOptions.timeout, () => ( _optionalChain([options, 'optionalAccess', _35 => _35.timeout])))
3256
+ timeout: _nullishCoalesce(messageOptions.timeout, () => ( _optionalChain([options, 'optionalAccess', _38 => _38.timeout])))
3039
3257
  }
3040
3258
  );
3041
3259
  return newMessage;
3042
3260
  },
3043
- [client, chatId, _optionalChain([options, 'optionalAccess', _36 => _36.copilotId]), _optionalChain([options, 'optionalAccess', _37 => _37.stream]), _optionalChain([options, 'optionalAccess', _38 => _38.timeout])]
3261
+ [client, chatId, _optionalChain([options, 'optionalAccess', _39 => _39.copilotId]), _optionalChain([options, 'optionalAccess', _40 => _40.stream]), _optionalChain([options, 'optionalAccess', _41 => _41.timeout])]
3044
3262
  );
3045
3263
  }
3046
3264
  function createSharedContext(client) {
@@ -3075,7 +3293,7 @@ function createSharedContext(client) {
3075
3293
  }
3076
3294
  function useEnsureNoLiveblocksProvider(options) {
3077
3295
  const existing = useClientOrNull();
3078
- if (!_optionalChain([options, 'optionalAccess', _39 => _39.allowNesting]) && existing !== null) {
3296
+ if (!_optionalChain([options, 'optionalAccess', _42 => _42.allowNesting]) && existing !== null) {
3079
3297
  throw new Error(
3080
3298
  "You cannot nest multiple LiveblocksProvider instances in the same React tree."
3081
3299
  );
@@ -3242,7 +3460,7 @@ var _useAiChatMessagesSuspense = useAiChatMessagesSuspense;
3242
3460
  var _useUrlMetadata = useUrlMetadata;
3243
3461
  var _useUrlMetadataSuspense = useUrlMetadataSuspense;
3244
3462
  function useSyncStatus_withClient(client, options) {
3245
- const smooth = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _40 => _40.smooth]), () => ( false)));
3463
+ const smooth = useInitial(_nullishCoalesce(_optionalChain([options, 'optionalAccess', _43 => _43.smooth]), () => ( false)));
3246
3464
  if (smooth) {
3247
3465
  return useSyncStatusSmooth_withClient(client);
3248
3466
  } else {
@@ -3422,8 +3640,8 @@ function makeRoomExtrasForClient(client) {
3422
3640
  if (innerError.status === 403) {
3423
3641
  const detailedMessage = [
3424
3642
  innerError.message,
3425
- _optionalChain([innerError, 'access', _41 => _41.details, 'optionalAccess', _42 => _42.suggestion]),
3426
- _optionalChain([innerError, 'access', _43 => _43.details, 'optionalAccess', _44 => _44.docs])
3643
+ _optionalChain([innerError, 'access', _44 => _44.details, 'optionalAccess', _45 => _45.suggestion]),
3644
+ _optionalChain([innerError, 'access', _46 => _46.details, 'optionalAccess', _47 => _47.docs])
3427
3645
  ].filter(Boolean).join("\n");
3428
3646
  _core.console.error(detailedMessage);
3429
3647
  }
@@ -3521,9 +3739,13 @@ function makeRoomContextBundle(client) {
3521
3739
  useOthersMapped,
3522
3740
  useOthersConnectionIds,
3523
3741
  useOther,
3742
+ // prettier-ignore
3524
3743
  useMutation,
3525
3744
  useThreads,
3745
+ useAgentSessions,
3746
+ useAgentSession,
3526
3747
  useSearchComments,
3748
+ // prettier-ignore
3527
3749
  useCreateThread,
3528
3750
  useDeleteThread,
3529
3751
  useEditThreadMetadata,
@@ -3533,6 +3755,7 @@ function makeRoomContextBundle(client) {
3533
3755
  useUnsubscribeFromThread,
3534
3756
  useCreateComment,
3535
3757
  useEditComment,
3758
+ useEditCommentMetadata,
3536
3759
  useDeleteComment,
3537
3760
  useAddReaction,
3538
3761
  useRemoveReaction,
@@ -3567,8 +3790,12 @@ function makeRoomContextBundle(client) {
3567
3790
  useOthersMapped: useOthersMappedSuspense,
3568
3791
  useOthersConnectionIds: useOthersConnectionIdsSuspense,
3569
3792
  useOther: useOtherSuspense,
3793
+ // prettier-ignore
3570
3794
  useMutation,
3571
3795
  useThreads: useThreadsSuspense,
3796
+ useAgentSessions: useAgentSessionsSuspense,
3797
+ useAgentSession: useAgentSessionSuspense,
3798
+ // prettier-ignore
3572
3799
  useCreateThread,
3573
3800
  useDeleteThread,
3574
3801
  useEditThreadMetadata,
@@ -3578,6 +3805,7 @@ function makeRoomContextBundle(client) {
3578
3805
  useUnsubscribeFromThread,
3579
3806
  useCreateComment,
3580
3807
  useEditComment,
3808
+ useEditCommentMetadata,
3581
3809
  useDeleteComment,
3582
3810
  useAddReaction,
3583
3811
  useRemoveReaction,
@@ -3683,6 +3911,7 @@ function RoomProviderInner(props) {
3683
3911
  case _core.ServerMsgCode.COMMENT_REACTION_ADDED:
3684
3912
  case _core.ServerMsgCode.COMMENT_REACTION_REMOVED:
3685
3913
  case _core.ServerMsgCode.COMMENT_DELETED:
3914
+ case _core.ServerMsgCode.COMMENT_METADATA_UPDATED:
3686
3915
  if (!existingThread) break;
3687
3916
  store.updateThreadifications(
3688
3917
  [thread],
@@ -3705,6 +3934,41 @@ function RoomProviderInner(props) {
3705
3934
  (message) => void handleCommentEvent(message)
3706
3935
  );
3707
3936
  }, [client, room]);
3937
+ _react.useEffect.call(void 0, () => {
3938
+ const { store } = getRoomExtrasForClient(client);
3939
+ function handleAgentSessionEvent(message) {
3940
+ if (message.type === _core.ServerMsgCode.AGENT_SESSIONS) {
3941
+ const agentSessionsMsg = message;
3942
+ if (agentSessionsMsg.operation !== "list") {
3943
+ store.updateAgentSessions(
3944
+ room.id,
3945
+ agentSessionsMsg.sessions,
3946
+ agentSessionsMsg.operation
3947
+ );
3948
+ }
3949
+ } else if (message.type === _core.ServerMsgCode.AGENT_MESSAGES) {
3950
+ const agentMessagesMsg = message;
3951
+ if (agentMessagesMsg.operation !== "list") {
3952
+ store.updateAgentMessages(
3953
+ room.id,
3954
+ agentMessagesMsg.sessionId,
3955
+ agentMessagesMsg.messages,
3956
+ agentMessagesMsg.operation
3957
+ );
3958
+ }
3959
+ }
3960
+ }
3961
+ return room.events.agentSessions.subscribe(
3962
+ (message) => void handleAgentSessionEvent(message)
3963
+ );
3964
+ }, [client, room]);
3965
+ _react.useEffect.call(void 0, () => {
3966
+ const { store } = getRoomExtrasForClient(client);
3967
+ store.registerRoom(room.id, room);
3968
+ return () => {
3969
+ store.unregisterRoom(room.id);
3970
+ };
3971
+ }, [client, room]);
3708
3972
  _react.useEffect.call(void 0, () => {
3709
3973
  const pair = stableEnterRoom(roomId, frozenProps);
3710
3974
  setRoomLeavePair(pair);
@@ -3720,7 +3984,7 @@ function RoomProviderInner(props) {
3720
3984
  }
3721
3985
  function useRoom(options) {
3722
3986
  const room = useRoomOrNull();
3723
- if (room === null && !_optionalChain([options, 'optionalAccess', _45 => _45.allowOutsideRoom])) {
3987
+ if (room === null && !_optionalChain([options, 'optionalAccess', _48 => _48.allowOutsideRoom])) {
3724
3988
  throw new Error("RoomProvider is missing from the React tree.");
3725
3989
  }
3726
3990
  return room;
@@ -4030,6 +4294,53 @@ function useThreads(options = {}) {
4030
4294
  useScrollToCommentOnLoadEffect(scrollOnLoad, result);
4031
4295
  return result;
4032
4296
  }
4297
+ function useAgentSessions(options) {
4298
+ const room = useRoom();
4299
+ const client = useClient();
4300
+ const { store } = getRoomExtrasForClient(client);
4301
+ const queryKey = makeAgentSessionsQueryKey(room.id, options);
4302
+ const loadableResource = store.outputs.loadingAgentSessions.getOrCreate(queryKey);
4303
+ _react.useEffect.call(void 0, () => {
4304
+ void loadableResource.waitUntilLoaded();
4305
+ });
4306
+ return useSignal(loadableResource.signal);
4307
+ }
4308
+ function useAgentSession(sessionId, options) {
4309
+ const room = useRoom();
4310
+ const client = useClient();
4311
+ const { store } = getRoomExtrasForClient(client);
4312
+ const queryKey = makeAgentMessagesQueryKey(room.id, sessionId, options);
4313
+ _react.useEffect.call(void 0, () => {
4314
+ void store.outputs.loadingAgentMessages.getOrCreate(queryKey).waitUntilLoaded();
4315
+ });
4316
+ return useSignal(
4317
+ store.outputs.loadingAgentMessages.getOrCreate(queryKey).signal
4318
+ );
4319
+ }
4320
+ function useAgentSessionsSuspense(options) {
4321
+ ensureNotServerSide();
4322
+ const client = useClient();
4323
+ const room = useRoom();
4324
+ const { store } = getRoomExtrasForClient(client);
4325
+ const queryKey = makeAgentSessionsQueryKey(room.id, options);
4326
+ use(store.outputs.loadingAgentSessions.getOrCreate(queryKey).waitUntilLoaded());
4327
+ const result = useAgentSessions(options);
4328
+ _core.assert.call(void 0, !result.error, "Did not expect error");
4329
+ _core.assert.call(void 0, !result.isLoading, "Did not expect loading");
4330
+ return result;
4331
+ }
4332
+ function useAgentSessionSuspense(sessionId, options) {
4333
+ ensureNotServerSide();
4334
+ const client = useClient();
4335
+ const room = useRoom();
4336
+ const { store } = getRoomExtrasForClient(client);
4337
+ const queryKey = makeAgentMessagesQueryKey(room.id, sessionId, options);
4338
+ use(store.outputs.loadingAgentMessages.getOrCreate(queryKey).waitUntilLoaded());
4339
+ const result = useAgentSession(sessionId, options);
4340
+ _core.assert.call(void 0, !result.error, "Did not expect error");
4341
+ _core.assert.call(void 0, !result.isLoading, "Did not expect loading");
4342
+ return result;
4343
+ }
4033
4344
  function useSearchComments(options) {
4034
4345
  const [result, setResult] = _react.useState.call(void 0, {
4035
4346
  isLoading: true
@@ -4040,7 +4351,7 @@ function useSearchComments(options) {
4040
4351
  const room = useRoom();
4041
4352
  const queryKey = _core.stableStringify.call(void 0, [room.id, options.query]);
4042
4353
  _react.useEffect.call(void 0, () => {
4043
- const currentRequestId = (_nullishCoalesce(_optionalChain([currentRequestInfo, 'access', _46 => _46.current, 'optionalAccess', _47 => _47.id]), () => ( 0))) + 1;
4354
+ const currentRequestId = (_nullishCoalesce(_optionalChain([currentRequestInfo, 'access', _49 => _49.current, 'optionalAccess', _50 => _50.id]), () => ( 0))) + 1;
4044
4355
  const controller = new AbortController();
4045
4356
  currentRequestInfo.current = { id: currentRequestId, controller };
4046
4357
  setResult((result2) => {
@@ -4057,12 +4368,12 @@ function useSearchComments(options) {
4057
4368
  { signal: controller.signal }
4058
4369
  ).then(({ data }) => {
4059
4370
  if (controller.signal.aborted) return;
4060
- if (_optionalChain([currentRequestInfo, 'access', _48 => _48.current, 'optionalAccess', _49 => _49.id]) !== currentRequestId) return;
4371
+ if (_optionalChain([currentRequestInfo, 'access', _51 => _51.current, 'optionalAccess', _52 => _52.id]) !== currentRequestId) return;
4061
4372
  setResult({ isLoading: false, results: data });
4062
4373
  currentRequestInfo.current = null;
4063
4374
  }).catch((err) => {
4064
4375
  if (controller.signal.aborted) return;
4065
- if (_optionalChain([currentRequestInfo, 'access', _50 => _50.current, 'optionalAccess', _51 => _51.id]) !== currentRequestId) return;
4376
+ if (_optionalChain([currentRequestInfo, 'access', _53 => _53.current, 'optionalAccess', _54 => _54.id]) !== currentRequestId) return;
4066
4377
  setResult({ isLoading: false, error: err });
4067
4378
  currentRequestInfo.current = null;
4068
4379
  });
@@ -4090,6 +4401,7 @@ function useCreateRoomThread(roomId) {
4090
4401
  (options) => {
4091
4402
  const body = options.body;
4092
4403
  const metadata = _nullishCoalesce(options.metadata, () => ( {}));
4404
+ const commentMetadata = _nullishCoalesce(options.commentMetadata, () => ( {}));
4093
4405
  const attachments = options.attachments;
4094
4406
  const threadId = _core.createThreadId.call(void 0, );
4095
4407
  const commentId = _core.createCommentId.call(void 0, );
@@ -4103,7 +4415,8 @@ function useCreateRoomThread(roomId) {
4103
4415
  userId: getCurrentUserId(client),
4104
4416
  body,
4105
4417
  reactions: [],
4106
- attachments: _nullishCoalesce(attachments, () => ( []))
4418
+ attachments: _nullishCoalesce(attachments, () => ( [])),
4419
+ metadata: commentMetadata
4107
4420
  };
4108
4421
  const newThread = {
4109
4422
  id: threadId,
@@ -4121,13 +4434,14 @@ function useCreateRoomThread(roomId) {
4121
4434
  thread: newThread,
4122
4435
  roomId
4123
4436
  });
4124
- const attachmentIds = _optionalChain([attachments, 'optionalAccess', _52 => _52.map, 'call', _53 => _53((attachment) => attachment.id)]);
4437
+ const attachmentIds = _optionalChain([attachments, 'optionalAccess', _55 => _55.map, 'call', _56 => _56((attachment) => attachment.id)]);
4125
4438
  client[_core.kInternal].httpClient.createThread({
4126
4439
  roomId,
4127
4440
  threadId,
4128
4441
  commentId,
4129
4442
  body,
4130
4443
  metadata,
4444
+ commentMetadata,
4131
4445
  attachmentIds
4132
4446
  }).then(
4133
4447
  (thread) => {
@@ -4141,7 +4455,8 @@ function useCreateRoomThread(roomId) {
4141
4455
  threadId,
4142
4456
  commentId,
4143
4457
  body,
4144
- metadata
4458
+ metadata,
4459
+ commentMetadata
4145
4460
  },
4146
4461
  err
4147
4462
  )
@@ -4161,7 +4476,7 @@ function useDeleteRoomThread(roomId) {
4161
4476
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
4162
4477
  const userId = getCurrentUserId(client);
4163
4478
  const existing = store.outputs.threads.get().get(threadId);
4164
- if (_optionalChain([existing, 'optionalAccess', _54 => _54.comments, 'optionalAccess', _55 => _55[0], 'optionalAccess', _56 => _56.userId]) !== userId) {
4479
+ if (_optionalChain([existing, 'optionalAccess', _57 => _57.comments, 'optionalAccess', _58 => _58[0], 'optionalAccess', _59 => _59.userId]) !== userId) {
4165
4480
  throw new Error("Only the thread creator can delete the thread");
4166
4481
  }
4167
4482
  const optimisticId = store.optimisticUpdates.add({
@@ -4224,13 +4539,65 @@ function useEditRoomThreadMetadata(roomId) {
4224
4539
  [client, roomId]
4225
4540
  );
4226
4541
  }
4542
+ function useEditCommentMetadata() {
4543
+ return useEditRoomCommentMetadata(useRoom().id);
4544
+ }
4545
+ function useEditRoomCommentMetadata(roomId) {
4546
+ const client = useClient();
4547
+ return _react.useCallback.call(void 0,
4548
+ (options) => {
4549
+ if (!options.metadata) {
4550
+ return;
4551
+ }
4552
+ const threadId = options.threadId;
4553
+ const commentId = options.commentId;
4554
+ const metadata = options.metadata;
4555
+ const updatedAt = /* @__PURE__ */ new Date();
4556
+ const { store, onMutationFailure } = getRoomExtrasForClient(client);
4557
+ const optimisticId = store.optimisticUpdates.add({
4558
+ type: "edit-comment-metadata",
4559
+ threadId,
4560
+ commentId,
4561
+ metadata,
4562
+ updatedAt
4563
+ });
4564
+ client[_core.kInternal].httpClient.editCommentMetadata({ roomId, threadId, commentId, metadata }).then(
4565
+ (updatedMetadata) => (
4566
+ // Replace the optimistic update by the real thing
4567
+ store.editCommentMetadata(
4568
+ threadId,
4569
+ commentId,
4570
+ optimisticId,
4571
+ updatedMetadata,
4572
+ updatedAt
4573
+ )
4574
+ ),
4575
+ (err) => onMutationFailure(
4576
+ optimisticId,
4577
+ {
4578
+ type: "EDIT_COMMENT_METADATA_ERROR",
4579
+ roomId,
4580
+ threadId,
4581
+ commentId,
4582
+ metadata
4583
+ },
4584
+ err
4585
+ )
4586
+ );
4587
+ },
4588
+ [client, roomId]
4589
+ );
4590
+ }
4227
4591
  function useCreateComment() {
4228
4592
  return useCreateRoomComment(useRoom().id);
4229
4593
  }
4230
4594
  function useCreateRoomComment(roomId) {
4231
4595
  const client = useClient();
4232
4596
  return _react.useCallback.call(void 0,
4233
- ({ threadId, body, attachments }) => {
4597
+ (options) => {
4598
+ const { threadId, body } = options;
4599
+ const metadata = _nullishCoalesce(options.metadata, () => ( {}));
4600
+ const attachments = _nullishCoalesce(options.attachments, () => ( []));
4234
4601
  const commentId = _core.createCommentId.call(void 0, );
4235
4602
  const createdAt = /* @__PURE__ */ new Date();
4236
4603
  const comment = {
@@ -4242,15 +4609,23 @@ function useCreateRoomComment(roomId) {
4242
4609
  userId: getCurrentUserId(client),
4243
4610
  body,
4244
4611
  reactions: [],
4245
- attachments: _nullishCoalesce(attachments, () => ( []))
4612
+ attachments: _nullishCoalesce(attachments, () => ( [])),
4613
+ metadata
4246
4614
  };
4247
4615
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
4248
4616
  const optimisticId = store.optimisticUpdates.add({
4249
4617
  type: "create-comment",
4250
4618
  comment
4251
4619
  });
4252
- const attachmentIds = _optionalChain([attachments, 'optionalAccess', _57 => _57.map, 'call', _58 => _58((attachment) => attachment.id)]);
4253
- client[_core.kInternal].httpClient.createComment({ roomId, threadId, commentId, body, attachmentIds }).then(
4620
+ const attachmentIds = _optionalChain([attachments, 'optionalAccess', _60 => _60.map, 'call', _61 => _61((attachment) => attachment.id)]);
4621
+ client[_core.kInternal].httpClient.createComment({
4622
+ roomId,
4623
+ threadId,
4624
+ commentId,
4625
+ body,
4626
+ metadata,
4627
+ attachmentIds
4628
+ }).then(
4254
4629
  (newComment) => {
4255
4630
  store.createComment(newComment, optimisticId);
4256
4631
  },
@@ -4261,7 +4636,8 @@ function useCreateRoomComment(roomId) {
4261
4636
  roomId,
4262
4637
  threadId,
4263
4638
  commentId,
4264
- body
4639
+ body,
4640
+ metadata
4265
4641
  },
4266
4642
  err
4267
4643
  )
@@ -4277,7 +4653,13 @@ function useEditComment() {
4277
4653
  function useEditRoomComment(roomId) {
4278
4654
  const client = useClient();
4279
4655
  return _react.useCallback.call(void 0,
4280
- ({ threadId, commentId, body, attachments }) => {
4656
+ ({
4657
+ threadId,
4658
+ commentId,
4659
+ body,
4660
+ attachments,
4661
+ metadata
4662
+ }) => {
4281
4663
  const editedAt = /* @__PURE__ */ new Date();
4282
4664
  const { store, onMutationFailure } = getRoomExtrasForClient(client);
4283
4665
  const existing = store.outputs.threads.get().getEvenIfDeleted(threadId);
@@ -4296,23 +4678,42 @@ function useEditRoomComment(roomId) {
4296
4678
  );
4297
4679
  return;
4298
4680
  }
4681
+ const updatedMetadata = metadata !== void 0 ? {
4682
+ ...comment.metadata,
4683
+ ...metadata
4684
+ } : comment.metadata;
4299
4685
  const optimisticId = store.optimisticUpdates.add({
4300
4686
  type: "edit-comment",
4301
4687
  comment: {
4302
4688
  ...comment,
4303
4689
  editedAt,
4304
4690
  body,
4305
- attachments: _nullishCoalesce(attachments, () => ( []))
4691
+ attachments: _nullishCoalesce(attachments, () => ( [])),
4692
+ metadata: updatedMetadata
4306
4693
  }
4307
4694
  });
4308
- const attachmentIds = _optionalChain([attachments, 'optionalAccess', _59 => _59.map, 'call', _60 => _60((attachment) => attachment.id)]);
4309
- client[_core.kInternal].httpClient.editComment({ roomId, threadId, commentId, body, attachmentIds }).then(
4695
+ const attachmentIds = _optionalChain([attachments, 'optionalAccess', _62 => _62.map, 'call', _63 => _63((attachment) => attachment.id)]);
4696
+ client[_core.kInternal].httpClient.editComment({
4697
+ roomId,
4698
+ threadId,
4699
+ commentId,
4700
+ body,
4701
+ attachmentIds,
4702
+ metadata
4703
+ }).then(
4310
4704
  (editedComment) => {
4311
4705
  store.editComment(threadId, optimisticId, editedComment);
4312
4706
  },
4313
4707
  (err) => onMutationFailure(
4314
4708
  optimisticId,
4315
- { type: "EDIT_COMMENT_ERROR", roomId, threadId, commentId, body },
4709
+ {
4710
+ type: "EDIT_COMMENT_ERROR",
4711
+ roomId,
4712
+ threadId,
4713
+ commentId,
4714
+ body,
4715
+ metadata: updatedMetadata
4716
+ },
4316
4717
  err
4317
4718
  )
4318
4719
  );
@@ -4646,7 +5047,7 @@ function useRoomThreadSubscription(roomId, threadId) {
4646
5047
  }
4647
5048
  return {
4648
5049
  status: "subscribed",
4649
- unreadSince: _nullishCoalesce(_optionalChain([notification, 'optionalAccess', _61 => _61.readAt]), () => ( null)),
5050
+ unreadSince: _nullishCoalesce(_optionalChain([notification, 'optionalAccess', _64 => _64.readAt]), () => ( null)),
4650
5051
  subscribe,
4651
5052
  unsubscribe
4652
5053
  };
@@ -4857,7 +5258,7 @@ function useThreadsSuspense(options = {}) {
4857
5258
  return result;
4858
5259
  }
4859
5260
  function selectorFor_useAttachmentUrl(state) {
4860
- if (state === void 0 || _optionalChain([state, 'optionalAccess', _62 => _62.isLoading])) {
5261
+ if (state === void 0 || _optionalChain([state, 'optionalAccess', _65 => _65.isLoading])) {
4861
5262
  return _nullishCoalesce(state, () => ( { isLoading: true }));
4862
5263
  }
4863
5264
  if (state.error) {
@@ -4937,11 +5338,16 @@ var _useMutation = useMutation;
4937
5338
  var _useCreateThread = useCreateThread;
4938
5339
  var _useDeleteThread = useDeleteThread;
4939
5340
  var _useEditThreadMetadata = useEditThreadMetadata;
5341
+ var _useCreateComment = useCreateComment;
5342
+ var _useEditComment = useEditComment;
5343
+ var _useEditCommentMetadata = useEditCommentMetadata;
4940
5344
  var _useEventListener = useEventListener;
4941
5345
  var _useMyPresence = useMyPresence;
4942
5346
  var _useOthersMapped = useOthersMapped;
4943
5347
  var _useOthersMappedSuspense = useOthersMappedSuspense;
4944
5348
  var _useThreads = useThreads;
5349
+ var _useAgentSessions = useAgentSessions;
5350
+ var _useAgentSession = useAgentSession;
4945
5351
  var _useSearchComments = useSearchComments;
4946
5352
  var _useThreadsSuspense = useThreadsSuspense;
4947
5353
  var _useRoomSubscriptionSettings = useRoomSubscriptionSettings;
@@ -5089,5 +5495,8 @@ var _useUpdateMyPresence = useUpdateMyPresence;
5089
5495
 
5090
5496
 
5091
5497
 
5092
- exports.ClientContext = ClientContext; exports.useClientOrNull = useClientOrNull; exports.useClient = useClient; exports.RoomContext = RoomContext; exports.useLatest = useLatest; exports.RegisterAiKnowledge = RegisterAiKnowledge; exports.RegisterAiTool = RegisterAiTool; exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; exports.useSignal = useSignal; exports.getUmbrellaStoreForClient = getUmbrellaStoreForClient; exports.useCreateAiChat = useCreateAiChat; exports.useDeleteAiChat = useDeleteAiChat; exports.useAiChatStatus = useAiChatStatus; exports.useSendAiMessage = useSendAiMessage; exports.LiveblocksProvider = LiveblocksProvider; exports.createLiveblocksContext = createLiveblocksContext; exports.useInboxNotifications = useInboxNotifications; exports.useInboxNotificationsSuspense = useInboxNotificationsSuspense; exports.useMarkAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead; exports.useMarkInboxNotificationAsRead = useMarkInboxNotificationAsRead; exports.useDeleteAllInboxNotifications = useDeleteAllInboxNotifications; exports.useDeleteInboxNotification = useDeleteInboxNotification; exports.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useNotificationSettings = useNotificationSettings; exports.useNotificationSettingsSuspense = useNotificationSettingsSuspense; exports.useUpdateNotificationSettings = useUpdateNotificationSettings; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports.useGroupInfo = useGroupInfo; exports.useGroupInfoSuspense = useGroupInfoSuspense; exports._useInboxNotificationThread = _useInboxNotificationThread; exports._useUser = _useUser; exports._useUserSuspense = _useUserSuspense; exports._useUserThreads_experimental = _useUserThreads_experimental; exports._useUserThreadsSuspense_experimental = _useUserThreadsSuspense_experimental; exports._useAiChats = _useAiChats; exports._useAiChatsSuspense = _useAiChatsSuspense; exports._useAiChat = _useAiChat; exports._useAiChatSuspense = _useAiChatSuspense; exports._useAiChatMessages = _useAiChatMessages; exports._useAiChatMessagesSuspense = _useAiChatMessagesSuspense; exports._useUrlMetadata = _useUrlMetadata; exports._useUrlMetadataSuspense = _useUrlMetadataSuspense; exports.useSyncStatus = useSyncStatus; exports.useErrorListener = useErrorListener; exports.useStatus = useStatus; exports.useReportTextEditor = useReportTextEditor; exports.useYjsProvider = useYjsProvider; exports.useCreateTextMention = useCreateTextMention; exports.useDeleteTextMention = useDeleteTextMention; exports.useResolveMentionSuggestions = useResolveMentionSuggestions; exports.useMentionSuggestionsCache = useMentionSuggestionsCache; exports.useLostConnectionListener = useLostConnectionListener; exports.useHistory = useHistory; exports.useUndo = useUndo; exports.useRedo = useRedo; exports.useCanUndo = useCanUndo; exports.useCanRedo = useCanRedo; exports.useOthersConnectionIds = useOthersConnectionIds; exports.useCreateRoomThread = useCreateRoomThread; exports.useDeleteRoomThread = useDeleteRoomThread; exports.useEditRoomThreadMetadata = useEditRoomThreadMetadata; exports.useCreateComment = useCreateComment; exports.useCreateRoomComment = useCreateRoomComment; exports.useEditComment = useEditComment; exports.useEditRoomComment = useEditRoomComment; exports.useDeleteComment = useDeleteComment; exports.useDeleteRoomComment = useDeleteRoomComment; exports.useAddRoomCommentReaction = useAddRoomCommentReaction; exports.useRemoveReaction = useRemoveReaction; exports.useRemoveRoomCommentReaction = useRemoveRoomCommentReaction; exports.useMarkThreadAsRead = useMarkThreadAsRead; exports.useMarkRoomThreadAsRead = useMarkRoomThreadAsRead; exports.useMarkThreadAsResolved = useMarkThreadAsResolved; exports.useMarkRoomThreadAsResolved = useMarkRoomThreadAsResolved; exports.useMarkThreadAsUnresolved = useMarkThreadAsUnresolved; exports.useMarkRoomThreadAsUnresolved = useMarkRoomThreadAsUnresolved; exports.useSubscribeToThread = useSubscribeToThread; exports.useUnsubscribeFromThread = useUnsubscribeFromThread; exports.useThreadSubscription = useThreadSubscription; exports.useRoomThreadSubscription = useRoomThreadSubscription; exports.useHistoryVersionData = useHistoryVersionData; exports.useUpdateRoomSubscriptionSettings = useUpdateRoomSubscriptionSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.useAttachmentUrl = useAttachmentUrl; exports.useRoomAttachmentUrl = useRoomAttachmentUrl; exports.useAttachmentUrlSuspense = useAttachmentUrlSuspense; exports.useRoomPermissions = useRoomPermissions; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useIsInsideRoom = _useIsInsideRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; exports._useDeleteThread = _useDeleteThread; exports._useEditThreadMetadata = _useEditThreadMetadata; exports._useEventListener = _useEventListener; exports._useMyPresence = _useMyPresence; exports._useOthersMapped = _useOthersMapped; exports._useOthersMappedSuspense = _useOthersMappedSuspense; exports._useThreads = _useThreads; exports._useSearchComments = _useSearchComments; exports._useThreadsSuspense = _useThreadsSuspense; exports._useRoomSubscriptionSettings = _useRoomSubscriptionSettings; exports._useRoomSubscriptionSettingsSuspense = _useRoomSubscriptionSettingsSuspense; exports._useHistoryVersions = _useHistoryVersions; exports._useHistoryVersionsSuspense = _useHistoryVersionsSuspense; exports._useOther = _useOther; exports._useOthers = _useOthers; exports._useOtherSuspense = _useOtherSuspense; exports._useOthersSuspense = _useOthersSuspense; exports._useStorage = _useStorage; exports._useStorageSuspense = _useStorageSuspense; exports._useSelf = _useSelf; exports._useSelfSuspense = _useSelfSuspense; exports._useStorageRoot = _useStorageRoot; exports._useUpdateMyPresence = _useUpdateMyPresence;
5093
- //# sourceMappingURL=chunk-5I7TKGJB.cjs.map
5498
+
5499
+
5500
+
5501
+ exports.ClientContext = ClientContext; exports.useClientOrNull = useClientOrNull; exports.useClient = useClient; exports.RoomContext = RoomContext; exports.useLatest = useLatest; exports.RegisterAiKnowledge = RegisterAiKnowledge; exports.RegisterAiTool = RegisterAiTool; exports.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector; exports.useSignal = useSignal; exports.getUmbrellaStoreForClient = getUmbrellaStoreForClient; exports.useCreateAiChat = useCreateAiChat; exports.useDeleteAiChat = useDeleteAiChat; exports.useAiChatStatus = useAiChatStatus; exports.useSendAiMessage = useSendAiMessage; exports.LiveblocksProvider = LiveblocksProvider; exports.createLiveblocksContext = createLiveblocksContext; exports.useInboxNotifications = useInboxNotifications; exports.useInboxNotificationsSuspense = useInboxNotificationsSuspense; exports.useMarkAllInboxNotificationsAsRead = useMarkAllInboxNotificationsAsRead; exports.useMarkInboxNotificationAsRead = useMarkInboxNotificationAsRead; exports.useDeleteAllInboxNotifications = useDeleteAllInboxNotifications; exports.useDeleteInboxNotification = useDeleteInboxNotification; exports.useUnreadInboxNotificationsCount = useUnreadInboxNotificationsCount; exports.useUnreadInboxNotificationsCountSuspense = useUnreadInboxNotificationsCountSuspense; exports.useNotificationSettings = useNotificationSettings; exports.useNotificationSettingsSuspense = useNotificationSettingsSuspense; exports.useUpdateNotificationSettings = useUpdateNotificationSettings; exports.useRoomInfo = useRoomInfo; exports.useRoomInfoSuspense = useRoomInfoSuspense; exports.useGroupInfo = useGroupInfo; exports.useGroupInfoSuspense = useGroupInfoSuspense; exports._useInboxNotificationThread = _useInboxNotificationThread; exports._useUser = _useUser; exports._useUserSuspense = _useUserSuspense; exports._useUserThreads_experimental = _useUserThreads_experimental; exports._useUserThreadsSuspense_experimental = _useUserThreadsSuspense_experimental; exports._useAiChats = _useAiChats; exports._useAiChatsSuspense = _useAiChatsSuspense; exports._useAiChat = _useAiChat; exports._useAiChatSuspense = _useAiChatSuspense; exports._useAiChatMessages = _useAiChatMessages; exports._useAiChatMessagesSuspense = _useAiChatMessagesSuspense; exports._useUrlMetadata = _useUrlMetadata; exports._useUrlMetadataSuspense = _useUrlMetadataSuspense; exports.useSyncStatus = useSyncStatus; exports.useErrorListener = useErrorListener; exports.useStatus = useStatus; exports.useReportTextEditor = useReportTextEditor; exports.useYjsProvider = useYjsProvider; exports.useCreateTextMention = useCreateTextMention; exports.useDeleteTextMention = useDeleteTextMention; exports.useResolveMentionSuggestions = useResolveMentionSuggestions; exports.useMentionSuggestionsCache = useMentionSuggestionsCache; exports.useLostConnectionListener = useLostConnectionListener; exports.useHistory = useHistory; exports.useUndo = useUndo; exports.useRedo = useRedo; exports.useCanUndo = useCanUndo; exports.useCanRedo = useCanRedo; exports.useOthersConnectionIds = useOthersConnectionIds; exports.useCreateRoomThread = useCreateRoomThread; exports.useDeleteRoomThread = useDeleteRoomThread; exports.useEditRoomThreadMetadata = useEditRoomThreadMetadata; exports.useCreateRoomComment = useCreateRoomComment; exports.useEditRoomComment = useEditRoomComment; exports.useDeleteComment = useDeleteComment; exports.useDeleteRoomComment = useDeleteRoomComment; exports.useAddRoomCommentReaction = useAddRoomCommentReaction; exports.useRemoveReaction = useRemoveReaction; exports.useRemoveRoomCommentReaction = useRemoveRoomCommentReaction; exports.useMarkThreadAsRead = useMarkThreadAsRead; exports.useMarkRoomThreadAsRead = useMarkRoomThreadAsRead; exports.useMarkThreadAsResolved = useMarkThreadAsResolved; exports.useMarkRoomThreadAsResolved = useMarkRoomThreadAsResolved; exports.useMarkThreadAsUnresolved = useMarkThreadAsUnresolved; exports.useMarkRoomThreadAsUnresolved = useMarkRoomThreadAsUnresolved; exports.useSubscribeToThread = useSubscribeToThread; exports.useUnsubscribeFromThread = useUnsubscribeFromThread; exports.useThreadSubscription = useThreadSubscription; exports.useRoomThreadSubscription = useRoomThreadSubscription; exports.useHistoryVersionData = useHistoryVersionData; exports.useUpdateRoomSubscriptionSettings = useUpdateRoomSubscriptionSettings; exports.useOthersConnectionIdsSuspense = useOthersConnectionIdsSuspense; exports.useAttachmentUrl = useAttachmentUrl; exports.useRoomAttachmentUrl = useRoomAttachmentUrl; exports.useAttachmentUrlSuspense = useAttachmentUrlSuspense; exports.useRoomPermissions = useRoomPermissions; exports.createRoomContext = createRoomContext; exports._RoomProvider = _RoomProvider; exports._useBroadcastEvent = _useBroadcastEvent; exports._useOthersListener = _useOthersListener; exports._useRoom = _useRoom; exports._useIsInsideRoom = _useIsInsideRoom; exports._useAddReaction = _useAddReaction; exports._useMutation = _useMutation; exports._useCreateThread = _useCreateThread; exports._useDeleteThread = _useDeleteThread; exports._useEditThreadMetadata = _useEditThreadMetadata; exports._useCreateComment = _useCreateComment; exports._useEditComment = _useEditComment; exports._useEditCommentMetadata = _useEditCommentMetadata; exports._useEventListener = _useEventListener; exports._useMyPresence = _useMyPresence; exports._useOthersMapped = _useOthersMapped; exports._useOthersMappedSuspense = _useOthersMappedSuspense; exports._useThreads = _useThreads; exports._useAgentSessions = _useAgentSessions; exports._useAgentSession = _useAgentSession; exports._useSearchComments = _useSearchComments; exports._useThreadsSuspense = _useThreadsSuspense; exports._useRoomSubscriptionSettings = _useRoomSubscriptionSettings; exports._useRoomSubscriptionSettingsSuspense = _useRoomSubscriptionSettingsSuspense; exports._useHistoryVersions = _useHistoryVersions; exports._useHistoryVersionsSuspense = _useHistoryVersionsSuspense; exports._useOther = _useOther; exports._useOthers = _useOthers; exports._useOtherSuspense = _useOtherSuspense; exports._useOthersSuspense = _useOthersSuspense; exports._useStorage = _useStorage; exports._useStorageSuspense = _useStorageSuspense; exports._useSelf = _useSelf; exports._useSelfSuspense = _useSelfSuspense; exports._useStorageRoot = _useStorageRoot; exports._useUpdateMyPresence = _useUpdateMyPresence;
5502
+ //# sourceMappingURL=chunk-JXNC4PPG.cjs.map