@ai-matrx/messaging 0.16.1 → 0.17.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,7 @@
1
1
  import { MatrxJsonObject, MatrxTransport } from '@ai-matrx/agents/matrx';
2
2
  import { RealtimeClientLike, RealtimeManager } from '@ai-matrx/realtime';
3
+ import { SessionIdentity as SessionIdentity$1, SessionIdentitySnapshot as SessionIdentitySnapshot$1, SessionIdentityDiagnostic } from '@ai-matrx/data/session-identity';
4
+ export { SERVER_SESSION_IDENTITY } from '@ai-matrx/data/session-identity';
3
5
 
4
6
  /**
5
7
  * THE MESSAGING DOMAIN TYPES.
@@ -858,38 +860,14 @@ type MessagingSupabaseInternal = SupabaseLike & RealtimeClientLike;
858
860
  * proven at compile time in `supabase-shape.test.ts`.
859
861
  */
860
862
 
861
- interface SessionIdentitySnapshot {
862
- /**
863
- * `resolving` until the first `getSession()` answers. A user-scoped read or
864
- * write issued in this window would name a guess.
865
- */
866
- readonly state: "resolving" | "resolved";
867
- /** Who the session says is acting, or `null` for nobody. */
868
- readonly userId: UserId | null;
869
- }
870
- interface SessionIdentity {
871
- /**
872
- * False when the client handed to us has no auth source at all — a
873
- * misconfiguration, not "nobody is signed in", and the two get different
874
- * sentences.
875
- */
876
- readonly hasAuthSource: boolean;
877
- /** Stable reference until the acting user actually changes. */
878
- snapshot(): SessionIdentitySnapshot;
879
- subscribe(listener: () => void): () => void;
880
- dispose(): void;
881
- }
863
+ type SessionIdentitySnapshot = SessionIdentitySnapshot$1<UserId>;
864
+ type SessionIdentity = SessionIdentity$1<UserId>;
882
865
  interface SessionIdentityOptions {
883
866
  readonly client: MessagingSupabaseClient;
884
- readonly onDiagnostic?: ((event: {
885
- level: "info" | "warn" | "error";
886
- message: string;
887
- remedy?: string | undefined;
888
- }) => void) | undefined;
867
+ readonly onDiagnostic?: ((event: SessionIdentityDiagnostic) => void) | undefined;
889
868
  }
890
- /** The snapshot every server render sees: nobody is acting on a server. */
891
- declare const SERVER_SESSION_IDENTITY: SessionIdentitySnapshot;
892
- declare function createSessionIdentity(options: SessionIdentityOptions): SessionIdentity;
869
+ /** The acting user of `client`'s session, in messaging's words (public as `createSessionIdentity`). */
870
+ declare function createMessagingSessionIdentity(options: SessionIdentityOptions): SessionIdentity;
893
871
 
894
872
  /**
895
873
  * THE DATA CONTRACT — the ONE place a messaging table or RPC name exists.
@@ -1535,4 +1513,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1535
1513
  /** Serialize picked references into a fence the platform's other readers accept. */
1536
1514
  declare function composeFence(references: readonly MatrxReference[]): string;
1537
1515
 
1538
- export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCallArgs, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationAiContext, type ConversationCursor, type ConversationId, type ConversationReadCutoff, type ConversationReadFailure, type ConversationSummary, type ConversationThread, type ConversationType, DEFAULT_MESSAGING_ARCHIVE_FILTER, 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 MessagingAgentIdentity, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingArchiveFilter, 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 PendingSoftExpiries, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, SERVER_SESSION_IDENTITY, type SchemaLike, type SessionIdentity, type SessionIdentitySnapshot, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, composeFence, conversationContextVariables, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createSessionIdentity, createWebOutboxStorage, effectiveActorKey, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, groupMessages, inboxTopic, invalidResponse, isLapsed, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, softExpiryTime, splitText, summarizeText, toMessagingArchiveFilter, unreadCutoff, writeNotApplied };
1516
+ export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCallArgs, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationAiContext, type ConversationCursor, type ConversationId, type ConversationReadCutoff, type ConversationReadFailure, type ConversationSummary, type ConversationThread, type ConversationType, DEFAULT_MESSAGING_ARCHIVE_FILTER, 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 MessagingAgentIdentity, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingArchiveFilter, 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 PendingSoftExpiries, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionIdentity, type SessionIdentitySnapshot, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, composeFence, conversationContextVariables, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createMessagingSessionIdentity as createSessionIdentity, createWebOutboxStorage, effectiveActorKey, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, groupMessages, inboxTopic, invalidResponse, isLapsed, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, softExpiryTime, splitText, summarizeText, toMessagingArchiveFilter, unreadCutoff, writeNotApplied };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,7 @@
1
1
  import { MatrxJsonObject, MatrxTransport } from '@ai-matrx/agents/matrx';
2
2
  import { RealtimeClientLike, RealtimeManager } from '@ai-matrx/realtime';
3
+ import { SessionIdentity as SessionIdentity$1, SessionIdentitySnapshot as SessionIdentitySnapshot$1, SessionIdentityDiagnostic } from '@ai-matrx/data/session-identity';
4
+ export { SERVER_SESSION_IDENTITY } from '@ai-matrx/data/session-identity';
3
5
 
4
6
  /**
5
7
  * THE MESSAGING DOMAIN TYPES.
@@ -858,38 +860,14 @@ type MessagingSupabaseInternal = SupabaseLike & RealtimeClientLike;
858
860
  * proven at compile time in `supabase-shape.test.ts`.
859
861
  */
860
862
 
861
- interface SessionIdentitySnapshot {
862
- /**
863
- * `resolving` until the first `getSession()` answers. A user-scoped read or
864
- * write issued in this window would name a guess.
865
- */
866
- readonly state: "resolving" | "resolved";
867
- /** Who the session says is acting, or `null` for nobody. */
868
- readonly userId: UserId | null;
869
- }
870
- interface SessionIdentity {
871
- /**
872
- * False when the client handed to us has no auth source at all — a
873
- * misconfiguration, not "nobody is signed in", and the two get different
874
- * sentences.
875
- */
876
- readonly hasAuthSource: boolean;
877
- /** Stable reference until the acting user actually changes. */
878
- snapshot(): SessionIdentitySnapshot;
879
- subscribe(listener: () => void): () => void;
880
- dispose(): void;
881
- }
863
+ type SessionIdentitySnapshot = SessionIdentitySnapshot$1<UserId>;
864
+ type SessionIdentity = SessionIdentity$1<UserId>;
882
865
  interface SessionIdentityOptions {
883
866
  readonly client: MessagingSupabaseClient;
884
- readonly onDiagnostic?: ((event: {
885
- level: "info" | "warn" | "error";
886
- message: string;
887
- remedy?: string | undefined;
888
- }) => void) | undefined;
867
+ readonly onDiagnostic?: ((event: SessionIdentityDiagnostic) => void) | undefined;
889
868
  }
890
- /** The snapshot every server render sees: nobody is acting on a server. */
891
- declare const SERVER_SESSION_IDENTITY: SessionIdentitySnapshot;
892
- declare function createSessionIdentity(options: SessionIdentityOptions): SessionIdentity;
869
+ /** The acting user of `client`'s session, in messaging's words (public as `createSessionIdentity`). */
870
+ declare function createMessagingSessionIdentity(options: SessionIdentityOptions): SessionIdentity;
893
871
 
894
872
  /**
895
873
  * THE DATA CONTRACT — the ONE place a messaging table or RPC name exists.
@@ -1535,4 +1513,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1535
1513
  /** Serialize picked references into a fence the platform's other readers accept. */
1536
1514
  declare function composeFence(references: readonly MatrxReference[]): string;
1537
1515
 
1538
- export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCallArgs, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationAiContext, type ConversationCursor, type ConversationId, type ConversationReadCutoff, type ConversationReadFailure, type ConversationSummary, type ConversationThread, type ConversationType, DEFAULT_MESSAGING_ARCHIVE_FILTER, 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 MessagingAgentIdentity, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingArchiveFilter, 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 PendingSoftExpiries, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, SERVER_SESSION_IDENTITY, type SchemaLike, type SessionIdentity, type SessionIdentitySnapshot, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, composeFence, conversationContextVariables, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createSessionIdentity, createWebOutboxStorage, effectiveActorKey, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, groupMessages, inboxTopic, invalidResponse, isLapsed, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, softExpiryTime, splitText, summarizeText, toMessagingArchiveFilter, unreadCutoff, writeNotApplied };
1516
+ export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCallArgs, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationAiContext, type ConversationCursor, type ConversationId, type ConversationReadCutoff, type ConversationReadFailure, type ConversationSummary, type ConversationThread, type ConversationType, DEFAULT_MESSAGING_ARCHIVE_FILTER, 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 MessagingAgentIdentity, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingArchiveFilter, 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 PendingSoftExpiries, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionIdentity, type SessionIdentitySnapshot, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, composeFence, conversationContextVariables, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createMessagingSessionIdentity as createSessionIdentity, createWebOutboxStorage, effectiveActorKey, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, groupMessages, inboxTopic, invalidResponse, isLapsed, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, softExpiryTime, splitText, summarizeText, toMessagingArchiveFilter, unreadCutoff, writeNotApplied };
package/dist/index.js CHANGED
@@ -509,22 +509,9 @@ function createReadCache(options) {
509
509
 
510
510
  // src/core/channels.ts
511
511
  import { defineChannelNamespace } from "@ai-matrx/realtime";
512
-
513
- // src/core/slot.ts
514
- var NAMESPACE = "ai-matrx.messaging";
515
- function globalSlot(name, create) {
516
- const key = /* @__PURE__ */ Symbol.for(`${NAMESPACE}.${name}`);
517
- const host = globalThis;
518
- const existing = host[key];
519
- if (existing !== void 0) return existing;
520
- const created = create();
521
- host[key] = created;
522
- return created;
523
- }
524
-
525
- // src/core/channels.ts
512
+ import { globalSlot } from "@ai-matrx/kit/global-slot";
526
513
  function namespaces() {
527
- return globalSlot("channel-namespaces", () => ({
514
+ return globalSlot("ai-matrx.messaging.channel-namespaces", () => ({
528
515
  inbox: defineChannelNamespace({
529
516
  namespace: "messaging-inbox",
530
517
  parts: ["userId"],
@@ -2021,89 +2008,30 @@ function formatLastSeen(lastSeenMs, now = Date.now()) {
2021
2008
  }
2022
2009
 
2023
2010
  // src/core/session-identity.ts
2024
- var RESOLVING = Object.freeze({
2025
- state: "resolving",
2026
- userId: null
2027
- });
2028
- var SERVER_SESSION_IDENTITY = RESOLVING;
2029
- function authOf(client) {
2030
- const candidate = client.auth;
2031
- if (candidate === null || typeof candidate !== "object") return null;
2032
- const auth = candidate;
2033
- if (typeof auth.getSession !== "function") return null;
2034
- if (typeof auth.onAuthStateChange !== "function") return null;
2035
- return auth;
2036
- }
2037
- function userIdOf(session) {
2038
- const id = session?.user?.id;
2039
- return typeof id === "string" && id.length > 0 ? asUserId(id) : null;
2040
- }
2041
- var NO_AUTH_SOURCE = {
2042
- message: "Messaging cannot tell who is signed in: the Supabase client it was given has no auth session source.",
2043
- remedy: "Pass your app's browser Supabase client \u2014 the same client it signs in with \u2014 to <MessagingProvider client={...}> or createMessagingRepository({ client }). Messaging reads the acting user from that client's session; there is no prop or option for a user id, on purpose (DD-241)."
2011
+ import {
2012
+ authOf,
2013
+ createSessionIdentity as createDataSessionIdentity,
2014
+ noAuthSourceMessage,
2015
+ sessionUserId,
2016
+ unreadableSessionMessage
2017
+ } from "@ai-matrx/data/session-identity";
2018
+ import { authOf as authOf2, SERVER_SESSION_IDENTITY } from "@ai-matrx/data/session-identity";
2019
+ var MESSAGING_SESSION_WORDS = {
2020
+ product: "Messaging",
2021
+ noAuthSourceRemedy: "Pass your app's browser Supabase client \u2014 the same client it signs in with \u2014 to <MessagingProvider client={...}> or createMessagingRepository({ client }). Messaging reads the acting user from that client's session; there is no prop or option for a user id, on purpose (DD-241).",
2022
+ unreadableRemedy: "Messages stay unavailable on this device until the session can be read. Reload the page; if it persists, sign in again."
2044
2023
  };
2045
- function createSessionIdentity(options) {
2046
- const { client, onDiagnostic } = options;
2047
- const listeners = /* @__PURE__ */ new Set();
2048
- let current = RESOLVING;
2049
- let disposed = false;
2050
- const publish = (state, userId) => {
2051
- if (disposed) return;
2052
- if (current.state === state && current.userId === userId) return;
2053
- current = Object.freeze({ state, userId });
2054
- for (const listener of [...listeners]) listener();
2055
- };
2056
- const subscribeOnly = (hasAuthSource) => ({
2057
- hasAuthSource,
2058
- snapshot: () => current,
2059
- subscribe: (listener) => {
2060
- listeners.add(listener);
2061
- return () => {
2062
- listeners.delete(listener);
2063
- };
2064
- },
2065
- dispose: () => {
2066
- disposed = true;
2067
- listeners.clear();
2068
- }
2024
+ function createMessagingSessionIdentity(options) {
2025
+ return createDataSessionIdentity({
2026
+ client: options.client,
2027
+ words: MESSAGING_SESSION_WORDS,
2028
+ toUserId: asUserId,
2029
+ onDiagnostic: options.onDiagnostic
2069
2030
  });
2070
- const auth = authOf(client);
2071
- if (auth === null) {
2072
- onDiagnostic?.({ level: "error", ...NO_AUTH_SOURCE });
2073
- current = Object.freeze({ state: "resolved", userId: null });
2074
- return subscribeOnly(false);
2075
- }
2076
- void (async () => {
2077
- try {
2078
- const result = await auth.getSession();
2079
- publish("resolved", userIdOf(result?.data?.session));
2080
- } catch (error) {
2081
- onDiagnostic?.({
2082
- level: "warn",
2083
- message: `Messaging could not read the signed-in session: ${String(
2084
- error?.message ?? error
2085
- )}`,
2086
- remedy: "Messages stay unavailable on this device until the session can be read. Reload the page; if it persists, sign in again."
2087
- });
2088
- publish("resolved", null);
2089
- }
2090
- })();
2091
- const subscription = auth.onAuthStateChange((_event, session) => {
2092
- publish("resolved", userIdOf(session));
2093
- });
2094
- const base = subscribeOnly(true);
2095
- return {
2096
- hasAuthSource: true,
2097
- snapshot: base.snapshot,
2098
- subscribe: base.subscribe,
2099
- dispose: () => {
2100
- base.dispose();
2101
- try {
2102
- subscription.data.subscription.unsubscribe();
2103
- } catch {
2104
- }
2105
- }
2106
- };
2031
+ }
2032
+ function userIdOf(session) {
2033
+ const id = sessionUserId(session);
2034
+ return id === null ? null : asUserId(id);
2107
2035
  }
2108
2036
  function actingUserIdOf(identity) {
2109
2037
  return new Promise((resolve, reject) => {
@@ -2131,11 +2059,8 @@ function noSignedInUserError() {
2131
2059
  );
2132
2060
  }
2133
2061
  function noAuthSourceError() {
2134
- return new MessagingError(
2135
- "misconfigured",
2136
- NO_AUTH_SOURCE.message,
2137
- NO_AUTH_SOURCE.remedy
2138
- );
2062
+ const { message, remedy } = noAuthSourceMessage(MESSAGING_SESSION_WORDS);
2063
+ return new MessagingError("misconfigured", message, remedy);
2139
2064
  }
2140
2065
  async function readActingUserId(client) {
2141
2066
  const auth = authOf(client);
@@ -2147,9 +2072,7 @@ async function readActingUserId(client) {
2147
2072
  } catch (error) {
2148
2073
  throw new MessagingError(
2149
2074
  "session-unavailable",
2150
- `Messaging could not read the signed-in session: ${String(
2151
- error?.message ?? error
2152
- )}`,
2075
+ unreadableSessionMessage(MESSAGING_SESSION_WORDS, error),
2153
2076
  "Reload the page and try again; if it persists, sign in again.",
2154
2077
  error
2155
2078
  );
@@ -2805,7 +2728,7 @@ export {
2805
2728
  createMessagingStore,
2806
2729
  createOutbox,
2807
2730
  createReadCache,
2808
- createSessionIdentity,
2731
+ createMessagingSessionIdentity as createSessionIdentity,
2809
2732
  createWebOutboxStorage,
2810
2733
  effectiveActorKey,
2811
2734
  extractReferences,