@ai-matrx/messaging 0.15.0 → 0.15.2

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
@@ -75,6 +75,7 @@ __export(react_exports, {
75
75
  asOrganizationId: () => asOrganizationId,
76
76
  asUserId: () => asUserId,
77
77
  composeFence: () => composeFence,
78
+ conversationContextVariables: () => conversationContextVariables,
78
79
  conversationTopic: () => conversationTopic,
79
80
  createActionRegistry: () => createActionRegistry,
80
81
  createMemoryOutboxStorage: () => createMemoryOutboxStorage,
@@ -379,6 +380,20 @@ ${JSON.stringify(references, null, 2)}
379
380
  }
380
381
 
381
382
  // src/core/ai.ts
383
+ function conversationContextVariables(context, loadedMessageCount) {
384
+ const values = {
385
+ total_loaded_message_count: loadedMessageCount
386
+ };
387
+ if (context === void 0) return values;
388
+ if (context.conversationType) values.conversation_type = context.conversationType;
389
+ if (context.conversationName) values.conversation_name = context.conversationName;
390
+ if (context.conversationCreatedAt)
391
+ values.conversation_created_at = context.conversationCreatedAt;
392
+ if (typeof context.unreadCount === "number") values.unread_count = context.unreadCount;
393
+ if (typeof context.isMuted === "boolean") values.is_muted = context.isMuted;
394
+ if (context.readerUserId) values.reader_user_id = context.readerUserId;
395
+ return values;
396
+ }
382
397
  function unreadCutoff(messages, unreadCount) {
383
398
  if (unreadCount <= 0) return null;
384
399
  const index = messages.length - unreadCount - 1;
@@ -468,7 +483,8 @@ function createMessagingAi(options) {
468
483
  transcript_message_count: transcript.length,
469
484
  // Honest about the cut, so an agent can say "showing the last 200".
470
485
  transcript_truncated: args.messages.length > transcript.length,
471
- ...args.since != null ? { unread_since: args.since } : {}
486
+ ...args.since != null ? { unread_since: args.since } : {},
487
+ ...conversationContextVariables(args.context, args.messages.length)
472
488
  };
473
489
  }
474
490
  function configured(capability) {
@@ -1858,10 +1874,23 @@ function createMessagingRepository(options) {
1858
1874
  });
1859
1875
  return found;
1860
1876
  }
1877
+ const conversationOrganizations = /* @__PURE__ */ new Map();
1861
1878
  async function organizationOfExisting(conversationId) {
1862
- if (org !== null) return org;
1863
- const conversation = await repository.getConversation(conversationId);
1864
- return conversation.organizationId;
1879
+ const known = conversationOrganizations.get(conversationId);
1880
+ if (known !== void 0) return known;
1881
+ const operation = "organizationOfExisting";
1882
+ const { data, error } = await withSessionRetry(
1883
+ operation,
1884
+ async () => db().from(TABLES.conversations).select("organization_id").eq("id", conversationId).single()
1885
+ );
1886
+ if (error !== null) throw normalizeMessagingError(error, operation);
1887
+ const own = data?.["organization_id"];
1888
+ if (typeof own !== "string" || own.length === 0) {
1889
+ throw invalidResponse(operation, `conversation ${conversationId} has no organization`);
1890
+ }
1891
+ const organization = own;
1892
+ conversationOrganizations.set(conversationId, organization);
1893
+ return organization;
1865
1894
  }
1866
1895
  const repository = {
1867
1896
  organizationId: org,
@@ -2738,6 +2767,14 @@ function useMessagingAi(conversationId) {
2738
2767
  conversationId,
2739
2768
  messages: conversation.messages,
2740
2769
  participants: conversation.participants,
2770
+ context: {
2771
+ conversationType: conversation.summary?.conversation.type,
2772
+ conversationName: conversation.summary?.displayName,
2773
+ conversationCreatedAt: conversation.summary?.conversation.createdAt,
2774
+ unreadCount: conversation.summary?.unreadCount,
2775
+ isMuted: conversation.summary?.isMuted,
2776
+ readerUserId: host?.identity.userId || void 0
2777
+ },
2741
2778
  signal: controller.signal,
2742
2779
  // Live progress. Aborted runs stop painting immediately — a cancelled
2743
2780
  // answer must not keep growing on screen.