@ai-matrx/messaging 0.7.0 → 0.9.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
@@ -1,5 +1,5 @@
1
1
  import { MatrxTransport } from '@ai-matrx/agents/matrx';
2
- import { RealtimeManager } from '@ai-matrx/realtime';
2
+ import { RealtimeClientLike, RealtimeManager } from '@ai-matrx/realtime';
3
3
 
4
4
  /**
5
5
  * THE MESSAGING DOMAIN TYPES.
@@ -609,6 +609,38 @@ interface SchemaLike {
609
609
  interface SupabaseLike extends SchemaLike {
610
610
  schema(name: string): SchemaLike;
611
611
  }
612
+ /**
613
+ * 🚨 THE PUBLIC PROP TYPE IS DELIBERATELY SHALLOW.
614
+ *
615
+ * `<MessagingProvider client={supabase}>` must accept the client the host
616
+ * ALREADY HAS — a `SupabaseClient<Database>` built from generated types. It did
617
+ * not: checking a fully-typed client against the rich `SupabaseLike` above
618
+ * makes tsc chase PostgREST's schema machinery until it bails with **TS2589,
619
+ * "Type instantiation is excessively deep"**, followed by a page of "not
620
+ * assignable". The first real consumer hit both on the one line the README
621
+ * tells every consumer to write, and the only escape was the cast this
622
+ * package's own header forbids.
623
+ *
624
+ * So the boundary is shallow — method names and arity, results as `unknown` —
625
+ * which a typed client satisfies without the compiler unrolling anything. The
626
+ * RICH shape (`SupabaseLike`) is still the internal contract, and the provider
627
+ * narrows to it ONCE, inside the package. That is the data 0.2.1 lesson applied
628
+ * to a client instead of a JSON column: type a public boundary over `unknown`,
629
+ * never over a strict recursive type the host's generator also produces.
630
+ *
631
+ * `supabase-shape.test.ts` proves BOTH legs at compile time: every call this
632
+ * package makes works on a real client, AND a fully-typed real client is
633
+ * assignable to this type.
634
+ */
635
+ interface MessagingSupabaseClient {
636
+ schema(name: string): unknown;
637
+ from(table: string): unknown;
638
+ rpc(fn: string, args?: Record<string, unknown>): unknown;
639
+ channel(topic: string, params?: unknown): unknown;
640
+ removeChannel(channel: never): unknown;
641
+ }
642
+ /** The internal client contract — what the repository and the manager see. */
643
+ type MessagingSupabaseInternal = SupabaseLike & RealtimeClientLike;
612
644
 
613
645
  /**
614
646
  * THE DATA CONTRACT — the ONE place a messaging table or RPC name exists.
@@ -677,7 +709,15 @@ declare const RPCS: {
677
709
  */
678
710
  type SessionResolver = () => Promise<unknown>;
679
711
  interface RepositoryOptions {
680
- client: SupabaseLike;
712
+ /**
713
+ * The host's Supabase client. Typed over the SHALLOW public shape for the
714
+ * same reason the provider's prop is (see `supabase-shape.ts`): a fully-typed
715
+ * `SupabaseClient<Database>` checked against the rich contract makes tsc bail
716
+ * with TS2589. A service module builds this repository directly — the
717
+ * framework-free path in the README — so it hits the boundary exactly like
718
+ * the provider does.
719
+ */
720
+ client: MessagingSupabaseClient;
681
721
  identity: MessagingIdentity;
682
722
  /** Called once before a retry when a read fails with a missing session. */
683
723
  resolveSession?: SessionResolver | undefined;
@@ -1037,4 +1077,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1037
1077
  /** Serialize picked references into a fence the platform's other readers accept. */
1038
1078
  declare function composeFence(references: readonly MatrxReference[]): string;
1039
1079
 
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 };
1080
+ 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 MessagingSupabaseClient, type MessagingSupabaseInternal, 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
@@ -1,5 +1,5 @@
1
1
  import { MatrxTransport } from '@ai-matrx/agents/matrx';
2
- import { RealtimeManager } from '@ai-matrx/realtime';
2
+ import { RealtimeClientLike, RealtimeManager } from '@ai-matrx/realtime';
3
3
 
4
4
  /**
5
5
  * THE MESSAGING DOMAIN TYPES.
@@ -609,6 +609,38 @@ interface SchemaLike {
609
609
  interface SupabaseLike extends SchemaLike {
610
610
  schema(name: string): SchemaLike;
611
611
  }
612
+ /**
613
+ * 🚨 THE PUBLIC PROP TYPE IS DELIBERATELY SHALLOW.
614
+ *
615
+ * `<MessagingProvider client={supabase}>` must accept the client the host
616
+ * ALREADY HAS — a `SupabaseClient<Database>` built from generated types. It did
617
+ * not: checking a fully-typed client against the rich `SupabaseLike` above
618
+ * makes tsc chase PostgREST's schema machinery until it bails with **TS2589,
619
+ * "Type instantiation is excessively deep"**, followed by a page of "not
620
+ * assignable". The first real consumer hit both on the one line the README
621
+ * tells every consumer to write, and the only escape was the cast this
622
+ * package's own header forbids.
623
+ *
624
+ * So the boundary is shallow — method names and arity, results as `unknown` —
625
+ * which a typed client satisfies without the compiler unrolling anything. The
626
+ * RICH shape (`SupabaseLike`) is still the internal contract, and the provider
627
+ * narrows to it ONCE, inside the package. That is the data 0.2.1 lesson applied
628
+ * to a client instead of a JSON column: type a public boundary over `unknown`,
629
+ * never over a strict recursive type the host's generator also produces.
630
+ *
631
+ * `supabase-shape.test.ts` proves BOTH legs at compile time: every call this
632
+ * package makes works on a real client, AND a fully-typed real client is
633
+ * assignable to this type.
634
+ */
635
+ interface MessagingSupabaseClient {
636
+ schema(name: string): unknown;
637
+ from(table: string): unknown;
638
+ rpc(fn: string, args?: Record<string, unknown>): unknown;
639
+ channel(topic: string, params?: unknown): unknown;
640
+ removeChannel(channel: never): unknown;
641
+ }
642
+ /** The internal client contract — what the repository and the manager see. */
643
+ type MessagingSupabaseInternal = SupabaseLike & RealtimeClientLike;
612
644
 
613
645
  /**
614
646
  * THE DATA CONTRACT — the ONE place a messaging table or RPC name exists.
@@ -677,7 +709,15 @@ declare const RPCS: {
677
709
  */
678
710
  type SessionResolver = () => Promise<unknown>;
679
711
  interface RepositoryOptions {
680
- client: SupabaseLike;
712
+ /**
713
+ * The host's Supabase client. Typed over the SHALLOW public shape for the
714
+ * same reason the provider's prop is (see `supabase-shape.ts`): a fully-typed
715
+ * `SupabaseClient<Database>` checked against the rich contract makes tsc bail
716
+ * with TS2589. A service module builds this repository directly — the
717
+ * framework-free path in the README — so it hits the boundary exactly like
718
+ * the provider does.
719
+ */
720
+ client: MessagingSupabaseClient;
681
721
  identity: MessagingIdentity;
682
722
  /** Called once before a retry when a read fails with a missing session. */
683
723
  resolveSession?: SessionResolver | undefined;
@@ -1037,4 +1077,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1037
1077
  /** Serialize picked references into a fence the platform's other readers accept. */
1038
1078
  declare function composeFence(references: readonly MatrxReference[]): string;
1039
1079
 
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 };
1080
+ 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 MessagingSupabaseClient, type MessagingSupabaseInternal, 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
@@ -734,11 +734,13 @@ function projectParticipants(value, operation) {
734
734
  for (const entry of value) {
735
735
  if (typeof entry !== "object" || entry === null) continue;
736
736
  const record = entry;
737
- const id = str(record, "user_id") ?? str(record, "id");
737
+ const nested = typeof record["user"] === "object" && record["user"] !== null ? record["user"] : {};
738
+ const id = str(record, "user_id") ?? str(nested, "user_id") ?? str(record, "id");
738
739
  if (id === null) continue;
739
740
  summaries.push(
740
741
  projectUserSummary({
741
742
  ...record,
743
+ ...nested,
742
744
  user_id: id
743
745
  })
744
746
  );
@@ -1505,12 +1507,13 @@ function requireOrg(organizationId, operation) {
1505
1507
  return organizationId;
1506
1508
  }
1507
1509
  function createMessagingRepository(options) {
1508
- const { client, identity } = options;
1510
+ const { identity } = options;
1509
1511
  const org = requireOrg(identity.organizationId, "createMessagingRepository");
1510
1512
  const userCache = createReadCache({
1511
1513
  ttlMs: options.userTtlMs ?? 5 * 6e4,
1512
1514
  ...options.now !== void 0 ? { now: options.now } : {}
1513
1515
  });
1516
+ const client = options.client;
1514
1517
  const db = () => client.schema(MESSAGING_SCHEMA);
1515
1518
  const rpcDb = () => client.schema(MESSAGING_RPC_SCHEMA);
1516
1519
  async function withSessionRetry(operation, run) {