@ai-matrx/messaging 0.2.0 → 0.4.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/react.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { ComponentType, ReactNode, SVGProps } from 'react';
1
+ import { ReactNode, ComponentType, SVGProps } from 'react';
2
2
  import { MatrxTransport } from '@ai-matrx/agents/matrx';
3
3
  import { RealtimeClientLike, RealtimeManager } from '@ai-matrx/realtime';
4
4
 
@@ -781,6 +781,15 @@ declare function messagingClientId(): string;
781
781
  * resubscribe loop that looks exactly like "realtime is broken".
782
782
  */
783
783
 
784
+ /**
785
+ * What the host needs to decide whether to interrupt someone, and what to say.
786
+ */
787
+ interface IncomingMessageContext {
788
+ /** The message landed in the conversation currently on screen. */
789
+ readonly isActiveConversation: boolean;
790
+ /** The conversation it landed in, when the inbox already holds it. */
791
+ readonly conversation: ConversationSummary | null;
792
+ }
784
793
  /**
785
794
  * A host-supplied surface for ONE action kind.
786
795
  *
@@ -806,6 +815,51 @@ interface MessageActionRenderer<TPayload = unknown> {
806
815
  readonly versions: readonly number[];
807
816
  readonly render: ComponentType<MessageActionRenderProps<TPayload>>;
808
817
  }
818
+ /**
819
+ * A host's own renderer for a Matrx reference.
820
+ *
821
+ * References are the ONE piece of a bubble an app is likely to already render
822
+ * everywhere else — this platform resolves a ```matrx fence through a kind
823
+ * registry and draws a live, openable chip. Two different treatments of the
824
+ * same fence in one app is the second-renderer defect, so a host may hand us
825
+ * theirs. Omit it and the package's own card is used, which is what a
826
+ * greenfield consumer wants.
827
+ */
828
+ type ReferenceRenderer = ComponentType<{
829
+ reference: MatrxReference;
830
+ }>;
831
+ /**
832
+ * A host's renderer for a raw ```matrx fence — the body between the backticks.
833
+ *
834
+ * This package understands one fence dialect: its own. A platform's fences are
835
+ * its platform's business (Matrx's are `__kind` directive shells resolved
836
+ * through a kind registry), and only the app can draw them. Give us this and
837
+ * EVERY fence in a message goes to you, parsed or not.
838
+ */
839
+ type FenceRenderer = ComponentType<{
840
+ body: string;
841
+ }>;
842
+ /**
843
+ * App chrome wrapped around ONE message bubble or ONE conversation row.
844
+ *
845
+ * The reason this exists is the right-click menu. A platform whose every
846
+ * surface answers a right-click with copy / export / attach / hand-to-an-agent
847
+ * cannot have messaging be the one surface that does not — and a menu is
848
+ * per-row app chrome that no package can own (it needs the app's surface name,
849
+ * its entity tokens, its clipboard primitive). Without the seam a host keeps
850
+ * its own message list beside this one, which is the whole failure mode.
851
+ *
852
+ * It wraps; it does not replace. The bubble it receives is the package's.
853
+ */
854
+ interface MessageWrapperProps {
855
+ readonly message: Message;
856
+ readonly isMine: boolean;
857
+ readonly children: ReactNode;
858
+ }
859
+ interface ConversationRowWrapperProps {
860
+ readonly conversation: ConversationSummary;
861
+ readonly children: ReactNode;
862
+ }
809
863
  interface MessagingHost {
810
864
  readonly engine: MessagingEngine;
811
865
  readonly actions: ActionRegistry;
@@ -814,6 +868,10 @@ interface MessagingHost {
814
868
  readonly openReference: ((reference: MatrxReference) => void) | null;
815
869
  /** Host surfaces for action kinds whose answer is a card, not a chip. */
816
870
  readonly actionRenderers: ReadonlyMap<string, MessageActionRenderer>;
871
+ readonly renderReference: ReferenceRenderer | null;
872
+ readonly renderFence: FenceRenderer | null;
873
+ readonly wrapMessage: ComponentType<MessageWrapperProps> | null;
874
+ readonly wrapConversationRow: ComponentType<ConversationRowWrapperProps> | null;
817
875
  }
818
876
  interface MessagingProviderProps {
819
877
  /** Any Supabase client. `null` while the host is still resolving one. */
@@ -841,8 +899,23 @@ interface MessagingProviderProps {
841
899
  actionRenderers?: readonly MessageActionRenderer<never>[] | undefined;
842
900
  /** Called when a reference card is clicked. Omit and cards render inert-but-labeled. */
843
901
  onOpenReference?: ((reference: MatrxReference) => void) | undefined;
844
- /** A message arrived from someone else for a toast, sound, or badge. */
845
- onIncomingMessage?: ((message: Message) => void) | undefined;
902
+ /** Draw references with the app's own renderer instead of the package card. */
903
+ renderReference?: ReferenceRenderer | undefined;
904
+ /** Draw ```matrx fences with the app's own renderer — every fence, parsed or not. */
905
+ renderFence?: FenceRenderer | undefined;
906
+ /** App chrome (a right-click menu, a drop target) around each message bubble. */
907
+ wrapMessage?: ComponentType<MessageWrapperProps> | undefined;
908
+ /** App chrome around each conversation row. */
909
+ wrapConversationRow?: ComponentType<ConversationRowWrapperProps> | undefined;
910
+ /**
911
+ * A message arrived from someone else — for a toast, sound, or badge.
912
+ *
913
+ * The CONTEXT is not a courtesy. "Do not interrupt someone for the
914
+ * conversation they are looking at" is the rule every chat app needs and only
915
+ * this package can answer, and a notification names the SENDER, whose display
916
+ * name lives on the conversation the host cannot see from above the provider.
917
+ */
918
+ onIncomingMessage?: ((message: Message, context: IncomingMessageContext) => void) | undefined;
846
919
  /** Background failures, with a remedy. Defaults to a console sink. */
847
920
  onDiagnostic?: ((event: EngineDiagnostic) => void) | undefined;
848
921
  /** Re-resolve a session after one goes missing. Enables the single retry. */
@@ -1018,11 +1091,6 @@ declare function Avatar(props: {
1018
1091
  declare function DeliveryTick(props: {
1019
1092
  state: DeliveryState;
1020
1093
  }): React.ReactElement | null;
1021
- /**
1022
- * A reference card. NO DEAD ENDS: when the host wired `onOpenReference` it is a
1023
- * button that opens; when it did not, it renders as a labeled, non-interactive
1024
- * card with a title explaining why — never a button that does nothing.
1025
- */
1026
1094
  declare function ReferenceCard(props: {
1027
1095
  reference: MatrxReference;
1028
1096
  onOpen?: ((reference: MatrxReference) => void) | null;
@@ -1304,6 +1372,20 @@ type TextSegment = {
1304
1372
  } | {
1305
1373
  readonly type: "reference";
1306
1374
  readonly reference: MatrxReference;
1375
+ }
1376
+ /**
1377
+ * A ```matrx fence this package could not resolve into references.
1378
+ *
1379
+ * It is NOT dropped. Platforms carry richer fence dialects than this
1380
+ * package's own array shape — Matrx's is a `__kind` directive shell whose
1381
+ * items are typed per noun, resolvable only by the app's kind registry — and
1382
+ * a fence silently deleted on render is a message that lost a paragraph
1383
+ * between the sender and the reader. The host draws it (`renderFence`), or
1384
+ * the package draws an honest inert card. Never a code block of JSON.
1385
+ */
1386
+ | {
1387
+ readonly type: "fence";
1388
+ readonly body: string;
1307
1389
  };
1308
1390
  /** Every reference a message carries, from both transports, de-duplicated. */
1309
1391
  declare function extractReferences(content: string, structured?: readonly MatrxReference[]): readonly MatrxReference[];
@@ -1321,4 +1403,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1321
1403
  /** Serialize picked references into a fence the platform's other readers accept. */
1322
1404
  declare function composeFence(references: readonly MatrxReference[]): string;
1323
1405
 
1324
- export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, AgentTag, type AiCapability, type AiResult, AlertIcon, type Attachment, Avatar, BotIcon, CheckIcon, ChevronLeftIcon, type ClientMessageId, ClockIcon, CloseIcon, Composer, type Conversation, type ConversationCursor, type ConversationId, ConversationList, type ConversationListProps, ConversationSkeleton, type ConversationSummary, type ConversationThread, type ConversationType, ConversationView, type ConversationViewProps, type DeliveryState, DeliveryTick, DoubleCheckIcon, type DraftMessage, EmptyState, type EngineDiagnostic, type JsonObject, type JsonValue, LinkIcon, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, MessageActionChips, type MessageActionRenderProps, type MessageActionRenderer, MessageBubble, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingHost, type MessagingIdentity, MessagingInbox, type MessagingInboxProps, MessagingProvider, type MessagingProviderProps, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, PaperclipIcon, type Participant, type ParticipantRole, PlusIcon, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, ReferenceCard, ReplyIcon, type RepositoryOptions, type SchemaLike, SearchIcon, SendIcon, type SessionResolver, SparklesIcon, type SupabaseLike, TABLES, type TextSegment, TypingDots, type UseComposerResult, type UseConversationResult, type UseConversationsResult, type UseMessageActionResult, type UseMessagingAiResult, type UseTypistsResult, type UserId, type UserSummary, UsersIcon, 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, useComposer, useConversation, useConversations, useMessageAction, useMessagingAi, useMessagingHost, useMessagingSnapshot, useOnlineUserIds, useRequiredMessagingHost, useTypists };
1406
+ export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, AgentTag, type AiCapability, type AiResult, AlertIcon, type Attachment, Avatar, BotIcon, CheckIcon, ChevronLeftIcon, type ClientMessageId, ClockIcon, CloseIcon, Composer, type Conversation, type ConversationCursor, type ConversationId, ConversationList, type ConversationListProps, type ConversationRowWrapperProps, ConversationSkeleton, type ConversationSummary, type ConversationThread, type ConversationType, ConversationView, type ConversationViewProps, type DeliveryState, DeliveryTick, DoubleCheckIcon, type DraftMessage, EmptyState, type EngineDiagnostic, type IncomingMessageContext, type JsonObject, type JsonValue, LinkIcon, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, MessageActionChips, type MessageActionRenderProps, type MessageActionRenderer, MessageBubble, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessageWrapperProps, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingHost, type MessagingIdentity, MessagingInbox, type MessagingInboxProps, MessagingProvider, type MessagingProviderProps, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, PaperclipIcon, type Participant, type ParticipantRole, PlusIcon, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, ReferenceCard, type ReferenceRenderer, ReplyIcon, type RepositoryOptions, type SchemaLike, SearchIcon, SendIcon, type SessionResolver, SparklesIcon, type SupabaseLike, TABLES, type TextSegment, TypingDots, type UseComposerResult, type UseConversationResult, type UseConversationsResult, type UseMessageActionResult, type UseMessagingAiResult, type UseTypistsResult, type UserId, type UserSummary, UsersIcon, 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, useComposer, useConversation, useConversations, useMessageAction, useMessagingAi, useMessagingHost, useMessagingSnapshot, useOnlineUserIds, useRequiredMessagingHost, useTypists };
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ComponentType, ReactNode, SVGProps } from 'react';
1
+ import { ReactNode, ComponentType, SVGProps } from 'react';
2
2
  import { MatrxTransport } from '@ai-matrx/agents/matrx';
3
3
  import { RealtimeClientLike, RealtimeManager } from '@ai-matrx/realtime';
4
4
 
@@ -781,6 +781,15 @@ declare function messagingClientId(): string;
781
781
  * resubscribe loop that looks exactly like "realtime is broken".
782
782
  */
783
783
 
784
+ /**
785
+ * What the host needs to decide whether to interrupt someone, and what to say.
786
+ */
787
+ interface IncomingMessageContext {
788
+ /** The message landed in the conversation currently on screen. */
789
+ readonly isActiveConversation: boolean;
790
+ /** The conversation it landed in, when the inbox already holds it. */
791
+ readonly conversation: ConversationSummary | null;
792
+ }
784
793
  /**
785
794
  * A host-supplied surface for ONE action kind.
786
795
  *
@@ -806,6 +815,51 @@ interface MessageActionRenderer<TPayload = unknown> {
806
815
  readonly versions: readonly number[];
807
816
  readonly render: ComponentType<MessageActionRenderProps<TPayload>>;
808
817
  }
818
+ /**
819
+ * A host's own renderer for a Matrx reference.
820
+ *
821
+ * References are the ONE piece of a bubble an app is likely to already render
822
+ * everywhere else — this platform resolves a ```matrx fence through a kind
823
+ * registry and draws a live, openable chip. Two different treatments of the
824
+ * same fence in one app is the second-renderer defect, so a host may hand us
825
+ * theirs. Omit it and the package's own card is used, which is what a
826
+ * greenfield consumer wants.
827
+ */
828
+ type ReferenceRenderer = ComponentType<{
829
+ reference: MatrxReference;
830
+ }>;
831
+ /**
832
+ * A host's renderer for a raw ```matrx fence — the body between the backticks.
833
+ *
834
+ * This package understands one fence dialect: its own. A platform's fences are
835
+ * its platform's business (Matrx's are `__kind` directive shells resolved
836
+ * through a kind registry), and only the app can draw them. Give us this and
837
+ * EVERY fence in a message goes to you, parsed or not.
838
+ */
839
+ type FenceRenderer = ComponentType<{
840
+ body: string;
841
+ }>;
842
+ /**
843
+ * App chrome wrapped around ONE message bubble or ONE conversation row.
844
+ *
845
+ * The reason this exists is the right-click menu. A platform whose every
846
+ * surface answers a right-click with copy / export / attach / hand-to-an-agent
847
+ * cannot have messaging be the one surface that does not — and a menu is
848
+ * per-row app chrome that no package can own (it needs the app's surface name,
849
+ * its entity tokens, its clipboard primitive). Without the seam a host keeps
850
+ * its own message list beside this one, which is the whole failure mode.
851
+ *
852
+ * It wraps; it does not replace. The bubble it receives is the package's.
853
+ */
854
+ interface MessageWrapperProps {
855
+ readonly message: Message;
856
+ readonly isMine: boolean;
857
+ readonly children: ReactNode;
858
+ }
859
+ interface ConversationRowWrapperProps {
860
+ readonly conversation: ConversationSummary;
861
+ readonly children: ReactNode;
862
+ }
809
863
  interface MessagingHost {
810
864
  readonly engine: MessagingEngine;
811
865
  readonly actions: ActionRegistry;
@@ -814,6 +868,10 @@ interface MessagingHost {
814
868
  readonly openReference: ((reference: MatrxReference) => void) | null;
815
869
  /** Host surfaces for action kinds whose answer is a card, not a chip. */
816
870
  readonly actionRenderers: ReadonlyMap<string, MessageActionRenderer>;
871
+ readonly renderReference: ReferenceRenderer | null;
872
+ readonly renderFence: FenceRenderer | null;
873
+ readonly wrapMessage: ComponentType<MessageWrapperProps> | null;
874
+ readonly wrapConversationRow: ComponentType<ConversationRowWrapperProps> | null;
817
875
  }
818
876
  interface MessagingProviderProps {
819
877
  /** Any Supabase client. `null` while the host is still resolving one. */
@@ -841,8 +899,23 @@ interface MessagingProviderProps {
841
899
  actionRenderers?: readonly MessageActionRenderer<never>[] | undefined;
842
900
  /** Called when a reference card is clicked. Omit and cards render inert-but-labeled. */
843
901
  onOpenReference?: ((reference: MatrxReference) => void) | undefined;
844
- /** A message arrived from someone else for a toast, sound, or badge. */
845
- onIncomingMessage?: ((message: Message) => void) | undefined;
902
+ /** Draw references with the app's own renderer instead of the package card. */
903
+ renderReference?: ReferenceRenderer | undefined;
904
+ /** Draw ```matrx fences with the app's own renderer — every fence, parsed or not. */
905
+ renderFence?: FenceRenderer | undefined;
906
+ /** App chrome (a right-click menu, a drop target) around each message bubble. */
907
+ wrapMessage?: ComponentType<MessageWrapperProps> | undefined;
908
+ /** App chrome around each conversation row. */
909
+ wrapConversationRow?: ComponentType<ConversationRowWrapperProps> | undefined;
910
+ /**
911
+ * A message arrived from someone else — for a toast, sound, or badge.
912
+ *
913
+ * The CONTEXT is not a courtesy. "Do not interrupt someone for the
914
+ * conversation they are looking at" is the rule every chat app needs and only
915
+ * this package can answer, and a notification names the SENDER, whose display
916
+ * name lives on the conversation the host cannot see from above the provider.
917
+ */
918
+ onIncomingMessage?: ((message: Message, context: IncomingMessageContext) => void) | undefined;
846
919
  /** Background failures, with a remedy. Defaults to a console sink. */
847
920
  onDiagnostic?: ((event: EngineDiagnostic) => void) | undefined;
848
921
  /** Re-resolve a session after one goes missing. Enables the single retry. */
@@ -1018,11 +1091,6 @@ declare function Avatar(props: {
1018
1091
  declare function DeliveryTick(props: {
1019
1092
  state: DeliveryState;
1020
1093
  }): React.ReactElement | null;
1021
- /**
1022
- * A reference card. NO DEAD ENDS: when the host wired `onOpenReference` it is a
1023
- * button that opens; when it did not, it renders as a labeled, non-interactive
1024
- * card with a title explaining why — never a button that does nothing.
1025
- */
1026
1094
  declare function ReferenceCard(props: {
1027
1095
  reference: MatrxReference;
1028
1096
  onOpen?: ((reference: MatrxReference) => void) | null;
@@ -1304,6 +1372,20 @@ type TextSegment = {
1304
1372
  } | {
1305
1373
  readonly type: "reference";
1306
1374
  readonly reference: MatrxReference;
1375
+ }
1376
+ /**
1377
+ * A ```matrx fence this package could not resolve into references.
1378
+ *
1379
+ * It is NOT dropped. Platforms carry richer fence dialects than this
1380
+ * package's own array shape — Matrx's is a `__kind` directive shell whose
1381
+ * items are typed per noun, resolvable only by the app's kind registry — and
1382
+ * a fence silently deleted on render is a message that lost a paragraph
1383
+ * between the sender and the reader. The host draws it (`renderFence`), or
1384
+ * the package draws an honest inert card. Never a code block of JSON.
1385
+ */
1386
+ | {
1387
+ readonly type: "fence";
1388
+ readonly body: string;
1307
1389
  };
1308
1390
  /** Every reference a message carries, from both transports, de-duplicated. */
1309
1391
  declare function extractReferences(content: string, structured?: readonly MatrxReference[]): readonly MatrxReference[];
@@ -1321,4 +1403,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1321
1403
  /** Serialize picked references into a fence the platform's other readers accept. */
1322
1404
  declare function composeFence(references: readonly MatrxReference[]): string;
1323
1405
 
1324
- export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, AgentTag, type AiCapability, type AiResult, AlertIcon, type Attachment, Avatar, BotIcon, CheckIcon, ChevronLeftIcon, type ClientMessageId, ClockIcon, CloseIcon, Composer, type Conversation, type ConversationCursor, type ConversationId, ConversationList, type ConversationListProps, ConversationSkeleton, type ConversationSummary, type ConversationThread, type ConversationType, ConversationView, type ConversationViewProps, type DeliveryState, DeliveryTick, DoubleCheckIcon, type DraftMessage, EmptyState, type EngineDiagnostic, type JsonObject, type JsonValue, LinkIcon, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, MessageActionChips, type MessageActionRenderProps, type MessageActionRenderer, MessageBubble, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingHost, type MessagingIdentity, MessagingInbox, type MessagingInboxProps, MessagingProvider, type MessagingProviderProps, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, PaperclipIcon, type Participant, type ParticipantRole, PlusIcon, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, ReferenceCard, ReplyIcon, type RepositoryOptions, type SchemaLike, SearchIcon, SendIcon, type SessionResolver, SparklesIcon, type SupabaseLike, TABLES, type TextSegment, TypingDots, type UseComposerResult, type UseConversationResult, type UseConversationsResult, type UseMessageActionResult, type UseMessagingAiResult, type UseTypistsResult, type UserId, type UserSummary, UsersIcon, 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, useComposer, useConversation, useConversations, useMessageAction, useMessagingAi, useMessagingHost, useMessagingSnapshot, useOnlineUserIds, useRequiredMessagingHost, useTypists };
1406
+ export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, AgentTag, type AiCapability, type AiResult, AlertIcon, type Attachment, Avatar, BotIcon, CheckIcon, ChevronLeftIcon, type ClientMessageId, ClockIcon, CloseIcon, Composer, type Conversation, type ConversationCursor, type ConversationId, ConversationList, type ConversationListProps, type ConversationRowWrapperProps, ConversationSkeleton, type ConversationSummary, type ConversationThread, type ConversationType, ConversationView, type ConversationViewProps, type DeliveryState, DeliveryTick, DoubleCheckIcon, type DraftMessage, EmptyState, type EngineDiagnostic, type IncomingMessageContext, type JsonObject, type JsonValue, LinkIcon, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, MessageActionChips, type MessageActionRenderProps, type MessageActionRenderer, MessageBubble, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessageWrapperProps, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingHost, type MessagingIdentity, MessagingInbox, type MessagingInboxProps, MessagingProvider, type MessagingProviderProps, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, PaperclipIcon, type Participant, type ParticipantRole, PlusIcon, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, ReferenceCard, type ReferenceRenderer, ReplyIcon, type RepositoryOptions, type SchemaLike, SearchIcon, SendIcon, type SessionResolver, SparklesIcon, type SupabaseLike, TABLES, type TextSegment, TypingDots, type UseComposerResult, type UseConversationResult, type UseConversationsResult, type UseMessageActionResult, type UseMessagingAiResult, type UseTypistsResult, type UserId, type UserSummary, UsersIcon, 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, useComposer, useConversation, useConversations, useMessageAction, useMessagingAi, useMessagingHost, useMessagingSnapshot, useOnlineUserIds, useRequiredMessagingHost, useTypists };
package/dist/react.js CHANGED
@@ -222,21 +222,32 @@ function splitText(content) {
222
222
  if (start > cursor) {
223
223
  segments.push({ type: "text", value: content.slice(cursor, start) });
224
224
  }
225
- parseFenceBody(match[1] ?? "").forEach((reference) => {
226
- segments.push({ type: "reference", reference });
227
- });
225
+ const body = match[1] ?? "";
226
+ const references = parseFenceBody(body);
227
+ if (references.length === 0) {
228
+ segments.push({ type: "fence", body });
229
+ } else {
230
+ references.forEach((reference) => {
231
+ segments.push({ type: "reference", reference });
232
+ });
233
+ }
228
234
  cursor = start + match[0].length;
229
235
  }
230
236
  if (cursor < content.length) {
231
237
  segments.push({ type: "text", value: content.slice(cursor) });
232
238
  }
233
239
  return segments.filter(
234
- (segment) => segment.type === "reference" || segment.value.trim().length > 0
240
+ (segment) => segment.type !== "text" || segment.value.trim().length > 0
235
241
  );
236
242
  }
237
243
  function summarizeText(content, maxLength = 140) {
238
244
  const parts = splitText(content).map(
239
- (segment) => segment.type === "text" ? segment.value : segment.reference.label
245
+ (segment) => segment.type === "text" ? segment.value : segment.type === "reference" ? segment.reference.label : (
246
+ // A fence we cannot read still SAYS something. Collapsing it to
247
+ // nothing is how a reference-only message becomes an inbox row that
248
+ // reads "No messages yet" — a screen telling a lie.
249
+ "Reference"
250
+ )
240
251
  );
241
252
  const flattened = parts.join(" ").replace(/\s+/g, " ").trim();
242
253
  if (flattened.length <= maxLength) return flattened;
@@ -1739,7 +1750,8 @@ function MessagingRuntime(props) {
1739
1750
  identity,
1740
1751
  ...props.resolveSession !== void 0 ? { resolveSession: props.resolveSession } : {}
1741
1752
  });
1742
- return createMessagingEngine({
1753
+ let built = null;
1754
+ built = createMessagingEngine({
1743
1755
  repository,
1744
1756
  manager,
1745
1757
  identity,
@@ -1748,8 +1760,18 @@ function MessagingRuntime(props) {
1748
1760
  onFallback: (message) => report({ level: "warn", message })
1749
1761
  }),
1750
1762
  onDiagnostic: report,
1751
- onIncoming: (message) => incomingRef.current?.(message)
1763
+ onIncoming: (message) => {
1764
+ const snapshot = built?.store.snapshot();
1765
+ if (snapshot === void 0) return;
1766
+ incomingRef.current?.(message, {
1767
+ isActiveConversation: snapshot.activeConversationId === message.conversationId,
1768
+ conversation: snapshot.conversations.find(
1769
+ (item) => item.conversation.id === message.conversationId
1770
+ ) ?? null
1771
+ });
1772
+ }
1752
1773
  });
1774
+ return built;
1753
1775
  }, [ready, manager, userId, organizationId]);
1754
1776
  useEffect(() => {
1755
1777
  if (engine === null) return void 0;
@@ -1782,6 +1804,10 @@ function MessagingRuntime(props) {
1782
1804
  });
1783
1805
  return map;
1784
1806
  }, [renderers]);
1807
+ const renderReference = props.renderReference ?? null;
1808
+ const renderFence = props.renderFence ?? null;
1809
+ const wrapMessage = props.wrapMessage ?? null;
1810
+ const wrapConversationRow = props.wrapConversationRow ?? null;
1785
1811
  const host = useMemo(() => {
1786
1812
  if (engine === null) return null;
1787
1813
  return {
@@ -1790,9 +1816,22 @@ function MessagingRuntime(props) {
1790
1816
  ai,
1791
1817
  identity: engine.identity,
1792
1818
  openReference: referenceRef.current ?? null,
1793
- actionRenderers: rendererMap
1819
+ actionRenderers: rendererMap,
1820
+ renderReference,
1821
+ renderFence,
1822
+ wrapMessage,
1823
+ wrapConversationRow
1794
1824
  };
1795
- }, [engine, actionRegistry, ai, rendererMap]);
1825
+ }, [
1826
+ engine,
1827
+ actionRegistry,
1828
+ ai,
1829
+ rendererMap,
1830
+ renderReference,
1831
+ renderFence,
1832
+ wrapMessage,
1833
+ wrapConversationRow
1834
+ ]);
1796
1835
  const MessagingContext = messagingContext();
1797
1836
  return /* @__PURE__ */ jsx(MessagingContext.Provider, { value: host, children });
1798
1837
  }
@@ -2383,6 +2422,20 @@ function DeliveryTick(props) {
2383
2422
  return null;
2384
2423
  }
2385
2424
  }
2425
+ function UnreadableReference() {
2426
+ return /* @__PURE__ */ jsxs(
2427
+ "span",
2428
+ {
2429
+ className: "mx-msg__reference mx-msg__reference--inert",
2430
+ title: "This message names something in a reference format this app has not wired. Pass renderFence to <MessagingProvider> to render it.",
2431
+ children: [
2432
+ /* @__PURE__ */ jsx3(LinkIcon, {}),
2433
+ /* @__PURE__ */ jsx3("span", { className: "mx-msg__reference-type", children: "reference" }),
2434
+ "Reference"
2435
+ ]
2436
+ }
2437
+ );
2438
+ }
2386
2439
  function ReferenceCard(props) {
2387
2440
  const { reference, onOpen } = props;
2388
2441
  const href = reference.href;
@@ -2463,6 +2516,7 @@ var AI_LABELS = {
2463
2516
  };
2464
2517
  function ConversationList(props) {
2465
2518
  const { conversations, hasMore, isInitialLoading, loadMore, select, activeConversationId } = useConversations();
2519
+ const RowChrome = useMessagingHost()?.wrapConversationRow ?? null;
2466
2520
  const [query, setQuery] = useState2("");
2467
2521
  const visible = useMemo3(() => {
2468
2522
  const needle = query.trim().toLowerCase();
@@ -2503,17 +2557,20 @@ function ConversationList(props) {
2503
2557
  title: query.length > 0 ? "No matches" : "No conversations yet",
2504
2558
  body: query.length > 0 ? "Try a different name or word." : "Start one and it will appear here."
2505
2559
  }
2506
- ) : /* @__PURE__ */ jsx4("ul", { className: "mx-msg__rows", children: visible.map((item) => /* @__PURE__ */ jsx4("li", { children: /* @__PURE__ */ jsx4(
2507
- ConversationRow,
2508
- {
2509
- summary: item,
2510
- isActive: item.conversation.id === activeConversationId,
2511
- onSelect: () => {
2512
- select(item.conversation.id);
2513
- props.onSelect?.(item.conversation.id);
2560
+ ) : /* @__PURE__ */ jsx4("ul", { className: "mx-msg__rows", children: visible.map((item) => {
2561
+ const row = /* @__PURE__ */ jsx4(
2562
+ ConversationRow,
2563
+ {
2564
+ summary: item,
2565
+ isActive: item.conversation.id === activeConversationId,
2566
+ onSelect: () => {
2567
+ select(item.conversation.id);
2568
+ props.onSelect?.(item.conversation.id);
2569
+ }
2514
2570
  }
2515
- }
2516
- ) }, item.conversation.id)) }),
2571
+ );
2572
+ return /* @__PURE__ */ jsx4("li", { children: RowChrome !== null ? /* @__PURE__ */ jsx4(RowChrome, { conversation: item, children: row }) : row }, item.conversation.id);
2573
+ }) }),
2517
2574
  hasMore && !isInitialLoading ? /* @__PURE__ */ jsx4(
2518
2575
  "button",
2519
2576
  {
@@ -2742,6 +2799,9 @@ function MessageGroupView(props) {
2742
2799
  function MessageBubble(props) {
2743
2800
  const { message, isMine } = props;
2744
2801
  const host = useMessagingHost();
2802
+ const HostReference = host?.renderReference ?? null;
2803
+ const HostFence = host?.renderFence ?? null;
2804
+ const MessageChrome = host?.wrapMessage ?? null;
2745
2805
  if (message.deletedAt !== null) {
2746
2806
  return /* @__PURE__ */ jsx4("div", { className: "mx-msg__bubble mx-msg__bubble--deleted", children: "Message deleted" });
2747
2807
  }
@@ -2752,10 +2812,16 @@ function MessageBubble(props) {
2752
2812
  message.deliveryState === "sending" ? "mx-msg__bubble--pending" : "",
2753
2813
  message.deliveryState === "failed" ? "mx-msg__bubble--failed" : ""
2754
2814
  ].filter(Boolean).join(" ");
2755
- return /* @__PURE__ */ jsxs2(Fragment, { children: [
2815
+ const bubble = /* @__PURE__ */ jsxs2(Fragment, { children: [
2756
2816
  /* @__PURE__ */ jsxs2("div", { className: classes, children: [
2757
2817
  splitText(message.content).map(
2758
- (segment, index) => segment.type === "text" ? /* @__PURE__ */ jsx4("span", { children: segment.value }, index) : /* @__PURE__ */ jsx4(
2818
+ (segment, index) => segment.type === "text" ? /* @__PURE__ */ jsx4("span", { children: segment.value }, index) : segment.type === "fence" ? HostFence !== null ? /* @__PURE__ */ jsx4(HostFence, { body: segment.body }, `fence:${index}`) : /* @__PURE__ */ jsx4(UnreadableReference, {}, `fence:${index}`) : HostReference !== null ? /* @__PURE__ */ jsx4(
2819
+ HostReference,
2820
+ {
2821
+ reference: segment.reference
2822
+ },
2823
+ `${segment.reference.entityType}:${segment.reference.entityId}`
2824
+ ) : /* @__PURE__ */ jsx4(
2759
2825
  ReferenceCard,
2760
2826
  {
2761
2827
  reference: segment.reference,
@@ -2764,14 +2830,22 @@ function MessageBubble(props) {
2764
2830
  `${segment.reference.entityType}:${segment.reference.entityId}`
2765
2831
  )
2766
2832
  ),
2767
- message.references.map((reference) => /* @__PURE__ */ jsx4(
2768
- ReferenceCard,
2769
- {
2770
- reference,
2771
- onOpen: host?.openReference ?? null
2772
- },
2773
- `structured:${reference.entityType}:${reference.entityId}`
2774
- )),
2833
+ message.references.map(
2834
+ (reference) => HostReference !== null ? /* @__PURE__ */ jsx4(
2835
+ HostReference,
2836
+ {
2837
+ reference
2838
+ },
2839
+ `structured:${reference.entityType}:${reference.entityId}`
2840
+ ) : /* @__PURE__ */ jsx4(
2841
+ ReferenceCard,
2842
+ {
2843
+ reference,
2844
+ onOpen: host?.openReference ?? null
2845
+ },
2846
+ `structured:${reference.entityType}:${reference.entityId}`
2847
+ )
2848
+ ),
2775
2849
  message.action !== null ? /* @__PURE__ */ jsx4(MessageActionChips, { message }) : null
2776
2850
  ] }),
2777
2851
  /* @__PURE__ */ jsxs2(
@@ -2807,6 +2881,7 @@ function MessageBubble(props) {
2807
2881
  }
2808
2882
  )
2809
2883
  ] });
2884
+ return MessageChrome !== null ? /* @__PURE__ */ jsx4(MessageChrome, { message, isMine, children: bubble }) : bubble;
2810
2885
  }
2811
2886
  function MessageActionChips(props) {
2812
2887
  const host = useRequiredMessagingHost();