@ai-matrx/messaging 0.4.0 → 0.7.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/index.d.cts CHANGED
@@ -16,10 +16,22 @@ import { RealtimeManager } from '@ai-matrx/realtime';
16
16
  * is the JSON boundary — `metadata` and `action_data` are host/DB-generated
17
17
  * shapes this package does not own (the data 0.2.1 `Json = unknown` lesson).
18
18
  */
19
- /** Nominal id types. A conversation id can never be passed where a user id goes. */
20
- declare const brand: unique symbol;
19
+ /**
20
+ * Nominal id types. A conversation id can never be passed where a user id goes.
21
+ *
22
+ * 🚨 THE MARKER IS A NAMED PROPERTY, NOT A `unique symbol`. This package ships
23
+ * two entries built as two separate bundles, so a `declare const brand: unique
24
+ * symbol` is DECLARED TWICE — and two unique symbols are two different types.
25
+ * `ConversationId` from `@ai-matrx/messaging` then does not match
26
+ * `ConversationId` from `@ai-matrx/messaging/react`, which makes the two
27
+ * entries unusable together: the first consumer hit exactly that, calling
28
+ * `asConversationId` from the core and passing it to a hook. A structural
29
+ * marker is identical in both declarations, so the brands unify — and it still
30
+ * cannot be produced by accident, which is all nominal typing needs to do.
31
+ * (The marker is types-only; nothing writes it at runtime.)
32
+ */
21
33
  type Brand<T, B extends string> = T & {
22
- readonly [brand]: B;
34
+ readonly __mxBrand: B;
23
35
  };
24
36
  type ConversationId = Brand<string, "ConversationId">;
25
37
  type MessageId = Brand<string, "MessageId">;
@@ -625,8 +637,25 @@ interface SupabaseLike extends SchemaLike {
625
637
  * — which in a large org is every page.
626
638
  */
627
639
 
628
- /** The schema. Messaging is never in `public`. */
640
+ /** The TABLES' schema. Messaging tables are never in `public`. */
629
641
  declare const MESSAGING_SCHEMA = "communication";
642
+ /**
643
+ * 🚨 THE RPCS LIVE IN `public`, AND THE TABLES DO NOT. THIS IS NOT A TYPO.
644
+ *
645
+ * Matrx Main's messaging tables moved into `communication` during the schema
646
+ * reorg; the five auth-checked SECURITY DEFINER functions stayed in `public`,
647
+ * where PostgREST exposes them by default and where every existing caller and
648
+ * GRANT already pointed. Calling them on `communication` fails with PGRST202
649
+ * ("no matches were found in the schema cache") on EVERY read — which is what
650
+ * happened the first time this package touched the live database, and what no
651
+ * amount of checking the SQL by inspection had caught.
652
+ *
653
+ * Verify before changing either constant:
654
+ * select n.nspname, p.proname from pg_proc p
655
+ * join pg_namespace n on n.oid = p.pronamespace
656
+ * where p.proname like '%_dm_%';
657
+ */
658
+ declare const MESSAGING_RPC_SCHEMA = "public";
630
659
  declare const TABLES: {
631
660
  readonly conversations: "dm_conversations";
632
661
  readonly participants: "dm_conversation_participants";
@@ -910,13 +939,6 @@ declare function formatConversationTime(isoString: string | null, now?: number,
910
939
  declare function formatMessageTime(isoString: string, locale?: string): string;
911
940
  /** The separator between day groups in a thread. */
912
941
  declare function formatDateSeparator(isoString: string, now?: number, locale?: string): string;
913
- declare function getInitials(name: string): string;
914
- /**
915
- * A stable palette index for an avatar with no image. Deterministic on the id,
916
- * so the same person is the same color on every device and every reload — a
917
- * random color per render is a surprisingly loud bug.
918
- */
919
- declare function avatarPaletteIndex(seed: string, buckets?: number): number;
920
942
  /**
921
943
  * Group consecutive messages by the same sender within a window, the way every
922
944
  * good chat UI does — one avatar and one name per burst.
@@ -1015,4 +1037,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1015
1037
  /** Serialize picked references into a fence the platform's other readers accept. */
1016
1038
  declare function composeFence(references: readonly MatrxReference[]): string;
1017
1039
 
1018
- export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationCursor, type ConversationId, type ConversationSummary, type ConversationThread, type ConversationType, type DeliveryState, type DraftMessage, type EngineDiagnostic, type JsonObject, type JsonValue, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingIdentity, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, type Participant, type ParticipantRole, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, avatarPaletteIndex, composeFence, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createWebOutboxStorage, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, getInitials, groupMessages, inboxTopic, invalidResponse, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, splitText, summarizeText };
1040
+ export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationCursor, type ConversationId, type ConversationSummary, type ConversationThread, type ConversationType, type DeliveryState, type DraftMessage, type EngineDiagnostic, type JsonObject, type JsonValue, MESSAGING_EVENTS, MESSAGING_RPC_SCHEMA, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingIdentity, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, type Participant, type ParticipantRole, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, composeFence, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createWebOutboxStorage, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, groupMessages, inboxTopic, invalidResponse, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, splitText, summarizeText };
package/dist/index.d.ts CHANGED
@@ -16,10 +16,22 @@ import { RealtimeManager } from '@ai-matrx/realtime';
16
16
  * is the JSON boundary — `metadata` and `action_data` are host/DB-generated
17
17
  * shapes this package does not own (the data 0.2.1 `Json = unknown` lesson).
18
18
  */
19
- /** Nominal id types. A conversation id can never be passed where a user id goes. */
20
- declare const brand: unique symbol;
19
+ /**
20
+ * Nominal id types. A conversation id can never be passed where a user id goes.
21
+ *
22
+ * 🚨 THE MARKER IS A NAMED PROPERTY, NOT A `unique symbol`. This package ships
23
+ * two entries built as two separate bundles, so a `declare const brand: unique
24
+ * symbol` is DECLARED TWICE — and two unique symbols are two different types.
25
+ * `ConversationId` from `@ai-matrx/messaging` then does not match
26
+ * `ConversationId` from `@ai-matrx/messaging/react`, which makes the two
27
+ * entries unusable together: the first consumer hit exactly that, calling
28
+ * `asConversationId` from the core and passing it to a hook. A structural
29
+ * marker is identical in both declarations, so the brands unify — and it still
30
+ * cannot be produced by accident, which is all nominal typing needs to do.
31
+ * (The marker is types-only; nothing writes it at runtime.)
32
+ */
21
33
  type Brand<T, B extends string> = T & {
22
- readonly [brand]: B;
34
+ readonly __mxBrand: B;
23
35
  };
24
36
  type ConversationId = Brand<string, "ConversationId">;
25
37
  type MessageId = Brand<string, "MessageId">;
@@ -625,8 +637,25 @@ interface SupabaseLike extends SchemaLike {
625
637
  * — which in a large org is every page.
626
638
  */
627
639
 
628
- /** The schema. Messaging is never in `public`. */
640
+ /** The TABLES' schema. Messaging tables are never in `public`. */
629
641
  declare const MESSAGING_SCHEMA = "communication";
642
+ /**
643
+ * 🚨 THE RPCS LIVE IN `public`, AND THE TABLES DO NOT. THIS IS NOT A TYPO.
644
+ *
645
+ * Matrx Main's messaging tables moved into `communication` during the schema
646
+ * reorg; the five auth-checked SECURITY DEFINER functions stayed in `public`,
647
+ * where PostgREST exposes them by default and where every existing caller and
648
+ * GRANT already pointed. Calling them on `communication` fails with PGRST202
649
+ * ("no matches were found in the schema cache") on EVERY read — which is what
650
+ * happened the first time this package touched the live database, and what no
651
+ * amount of checking the SQL by inspection had caught.
652
+ *
653
+ * Verify before changing either constant:
654
+ * select n.nspname, p.proname from pg_proc p
655
+ * join pg_namespace n on n.oid = p.pronamespace
656
+ * where p.proname like '%_dm_%';
657
+ */
658
+ declare const MESSAGING_RPC_SCHEMA = "public";
630
659
  declare const TABLES: {
631
660
  readonly conversations: "dm_conversations";
632
661
  readonly participants: "dm_conversation_participants";
@@ -910,13 +939,6 @@ declare function formatConversationTime(isoString: string | null, now?: number,
910
939
  declare function formatMessageTime(isoString: string, locale?: string): string;
911
940
  /** The separator between day groups in a thread. */
912
941
  declare function formatDateSeparator(isoString: string, now?: number, locale?: string): string;
913
- declare function getInitials(name: string): string;
914
- /**
915
- * A stable palette index for an avatar with no image. Deterministic on the id,
916
- * so the same person is the same color on every device and every reload — a
917
- * random color per render is a surprisingly loud bug.
918
- */
919
- declare function avatarPaletteIndex(seed: string, buckets?: number): number;
920
942
  /**
921
943
  * Group consecutive messages by the same sender within a window, the way every
922
944
  * good chat UI does — one avatar and one name per burst.
@@ -1015,4 +1037,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1015
1037
  /** Serialize picked references into a fence the platform's other readers accept. */
1016
1038
  declare function composeFence(references: readonly MatrxReference[]): string;
1017
1039
 
1018
- export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationCursor, type ConversationId, type ConversationSummary, type ConversationThread, type ConversationType, type DeliveryState, type DraftMessage, type EngineDiagnostic, type JsonObject, type JsonValue, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingIdentity, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, type Participant, type ParticipantRole, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, avatarPaletteIndex, composeFence, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createWebOutboxStorage, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, getInitials, groupMessages, inboxTopic, invalidResponse, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, splitText, summarizeText };
1040
+ export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationCursor, type ConversationId, type ConversationSummary, type ConversationThread, type ConversationType, type DeliveryState, type DraftMessage, type EngineDiagnostic, type JsonObject, type JsonValue, MESSAGING_EVENTS, MESSAGING_RPC_SCHEMA, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingIdentity, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, type Participant, type ParticipantRole, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, composeFence, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createWebOutboxStorage, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, groupMessages, inboxTopic, invalidResponse, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, splitText, summarizeText };
package/dist/index.js CHANGED
@@ -1431,20 +1431,6 @@ function formatDateSeparator(isoString, now = Date.now(), locale) {
1431
1431
  day: "numeric"
1432
1432
  });
1433
1433
  }
1434
- function getInitials(name) {
1435
- const parts = name.trim().split(/\s+/).filter(Boolean);
1436
- if (parts.length === 0) return "?";
1437
- const first = parts[0]?.[0] ?? "";
1438
- const last = parts.length > 1 ? parts.at(-1)?.[0] ?? "" : "";
1439
- return `${first}${last}`.toUpperCase() || "?";
1440
- }
1441
- function avatarPaletteIndex(seed, buckets = 8) {
1442
- let hash = 0;
1443
- for (let index = 0; index < seed.length; index += 1) {
1444
- hash = hash * 31 + seed.charCodeAt(index) | 0;
1445
- }
1446
- return Math.abs(hash) % buckets;
1447
- }
1448
1434
  function groupMessages(messages, args = {}) {
1449
1435
  const windowMs = args.windowMs ?? 5 * MINUTE;
1450
1436
  const now = args.now ?? Date.now();
@@ -1491,6 +1477,7 @@ function formatLastSeen(lastSeenMs, now = Date.now()) {
1491
1477
 
1492
1478
  // src/core/repository.ts
1493
1479
  var MESSAGING_SCHEMA = "communication";
1480
+ var MESSAGING_RPC_SCHEMA = "public";
1494
1481
  var TABLES = {
1495
1482
  conversations: "dm_conversations",
1496
1483
  participants: "dm_conversation_participants",
@@ -1525,6 +1512,7 @@ function createMessagingRepository(options) {
1525
1512
  ...options.now !== void 0 ? { now: options.now } : {}
1526
1513
  });
1527
1514
  const db = () => client.schema(MESSAGING_SCHEMA);
1515
+ const rpcDb = () => client.schema(MESSAGING_RPC_SCHEMA);
1528
1516
  async function withSessionRetry(operation, run) {
1529
1517
  try {
1530
1518
  return await run();
@@ -1542,7 +1530,7 @@ function createMessagingRepository(options) {
1542
1530
  }
1543
1531
  }
1544
1532
  async function rpc(fn, args, operation) {
1545
- const { data, error } = await db().rpc(fn, args);
1533
+ const { data, error } = await rpcDb().rpc(fn, args);
1546
1534
  if (error !== null) throw normalizeMessagingError(error, operation);
1547
1535
  return data;
1548
1536
  }
@@ -1838,6 +1826,7 @@ var asOrganizationId = (value) => value;
1838
1826
  var asClientMessageId = (value) => value;
1839
1827
  export {
1840
1828
  MESSAGING_EVENTS,
1829
+ MESSAGING_RPC_SCHEMA,
1841
1830
  MESSAGING_SCHEMA,
1842
1831
  MessagingError,
1843
1832
  RPCS,
@@ -1847,7 +1836,6 @@ export {
1847
1836
  asMessageId,
1848
1837
  asOrganizationId,
1849
1838
  asUserId,
1850
- avatarPaletteIndex,
1851
1839
  composeFence,
1852
1840
  conversationTopic,
1853
1841
  createActionRegistry,
@@ -1865,7 +1853,6 @@ export {
1865
1853
  formatLastSeen,
1866
1854
  formatMessageTime,
1867
1855
  formatTypists,
1868
- getInitials,
1869
1856
  groupMessages,
1870
1857
  inboxTopic,
1871
1858
  invalidResponse,