@ai-matrx/messaging 0.15.1 → 0.15.3

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.js CHANGED
@@ -1908,10 +1908,23 @@ function createMessagingRepository(options) {
1908
1908
  });
1909
1909
  return found;
1910
1910
  }
1911
+ const conversationOrganizations = /* @__PURE__ */ new Map();
1911
1912
  async function organizationOfExisting(conversationId) {
1912
- if (org !== null) return org;
1913
- const conversation = await repository.getConversation(conversationId);
1914
- return conversation.organizationId;
1913
+ const known = conversationOrganizations.get(conversationId);
1914
+ if (known !== void 0) return known;
1915
+ const operation = "organizationOfExisting";
1916
+ const { data, error } = await withSessionRetry(
1917
+ operation,
1918
+ async () => db().from(TABLES.conversations).select("organization_id").eq("id", conversationId).single()
1919
+ );
1920
+ if (error !== null) throw normalizeMessagingError(error, operation);
1921
+ const own = data?.["organization_id"];
1922
+ if (typeof own !== "string" || own.length === 0) {
1923
+ throw invalidResponse(operation, `conversation ${conversationId} has no organization`);
1924
+ }
1925
+ const organization = own;
1926
+ conversationOrganizations.set(conversationId, organization);
1927
+ return organization;
1915
1928
  }
1916
1929
  const repository = {
1917
1930
  organizationId: org,