@ai-matrx/messaging 0.12.5 → 0.13.0

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/react.cjs CHANGED
@@ -982,6 +982,7 @@ function createMessagingStore() {
982
982
  let archivedCount = null;
983
983
  let threads = /* @__PURE__ */ new Map();
984
984
  let activeConversationId = null;
985
+ let conversationReadFailures = /* @__PURE__ */ new Map();
985
986
  const listeners = /* @__PURE__ */ new Set();
986
987
  let cached = null;
987
988
  function snapshot() {
@@ -994,7 +995,8 @@ function createMessagingStore() {
994
995
  activeConversationId,
995
996
  totalUnreadConversations: conversations.filter((item) => item.unreadCount > 0).length,
996
997
  archiveFilter,
997
- archivedCount
998
+ archivedCount,
999
+ conversationReadFailures
998
1000
  };
999
1001
  return cached;
1000
1002
  }
@@ -1078,6 +1080,14 @@ function createMessagingStore() {
1078
1080
  conversations = normalizeConversations(conversations);
1079
1081
  emit();
1080
1082
  },
1083
+ setConversationReadFailure(id, failure) {
1084
+ if (failure === null && !conversationReadFailures.has(id)) return;
1085
+ const next = new Map(conversationReadFailures);
1086
+ if (failure === null) next.delete(id);
1087
+ else next.set(id, failure);
1088
+ conversationReadFailures = next;
1089
+ emit();
1090
+ },
1081
1091
  setThread(id, messages, args = {}) {
1082
1092
  writeThread({
1083
1093
  conversationId: id,
@@ -1383,11 +1393,26 @@ function createMessagingEngine(options) {
1383
1393
  },
1384
1394
  async openConversation(id) {
1385
1395
  store.setActiveConversation(id);
1396
+ store.setConversationReadFailure(id, null);
1386
1397
  try {
1387
1398
  const page = await repository.listMessages(id, { limit: messagePageSize });
1399
+ if (page.items.length === 0) {
1400
+ await repository.getConversation(id);
1401
+ }
1388
1402
  store.setThread(id, page.items, { hasMoreOlder: page.hasMore });
1389
1403
  } catch (error) {
1390
- reportError(error, "openConversation");
1404
+ const normalized = normalizeMessagingError(error, "openConversation");
1405
+ const unavailable = normalized.code === "not-found" || normalized.code === "forbidden";
1406
+ store.setConversationReadFailure(id, { error: normalized, unavailable });
1407
+ if (unavailable) {
1408
+ report({
1409
+ level: "warn",
1410
+ message: normalized.message,
1411
+ remedy: normalized.remedy
1412
+ });
1413
+ return;
1414
+ }
1415
+ reportError(normalized, "openConversation");
1391
1416
  }
1392
1417
  if (openChannels.has(id) || disposed) return;
1393
1418
  const handle = manager.open({
@@ -2500,6 +2525,7 @@ function useConversation(id) {
2500
2525
  }, []);
2501
2526
  const thread = id === null ? null : snapshot?.threads.get(id) ?? null;
2502
2527
  const summary = id === null ? null : snapshot?.conversations.find((item) => item.conversation.id === id) ?? null;
2528
+ const failure = id === null ? null : snapshot?.conversationReadFailures.get(id) ?? null;
2503
2529
  const pending = (0, import_react3.useMemo)(() => {
2504
2530
  void outboxTick;
2505
2531
  return id === null ? [] : host?.engine.outbox.pendingFor(id) ?? [];
@@ -2509,7 +2535,9 @@ function useConversation(id) {
2509
2535
  thread,
2510
2536
  messages: thread?.messages ?? [],
2511
2537
  participants: summary?.participants ?? [],
2512
- isLoading: id !== null && thread === null,
2538
+ isLoading: id !== null && thread === null && failure === null,
2539
+ error: failure?.error ?? null,
2540
+ unavailable: failure?.unavailable ?? false,
2513
2541
  hasMoreOlder: thread?.hasMoreOlder ?? false,
2514
2542
  loadOlder: () => {
2515
2543
  if (id !== null) void host?.engine.loadOlderMessages(id);
@@ -3291,7 +3319,19 @@ function ConversationView(props) {
3291
3319
  }
3292
3320
  )
3293
3321
  ] }) : null,
3294
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "mx-msg__scroll", ref: scrollRef, children: conversation.isLoading ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConversationSkeleton, { rows: 4 }) : messages.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(EmptyState, { title: "No messages yet", body: "Say something to get started." }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "mx-msg__messages", children: [
3322
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "mx-msg__scroll", ref: scrollRef, children: conversation.isLoading ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConversationSkeleton, { rows: 4 }) : conversation.unavailable ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3323
+ EmptyState,
3324
+ {
3325
+ title: "Conversation unavailable",
3326
+ body: "It doesn't exist, or you aren't a member of it."
3327
+ }
3328
+ ) : conversation.error !== null && messages.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3329
+ EmptyState,
3330
+ {
3331
+ title: "Couldn't load this conversation",
3332
+ body: "Check your connection, then open it again."
3333
+ }
3334
+ ) : messages.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(EmptyState, { title: "No messages yet", body: "Say something to get started." }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "mx-msg__messages", children: [
3295
3335
  conversation.hasMoreOlder ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
3296
3336
  "button",
3297
3337
  {