@ai-matrx/messaging 0.1.3 → 0.2.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 { ReactNode, SVGProps } from 'react';
1
+ import { ComponentType, ReactNode, SVGProps } from 'react';
2
2
  import { MatrxTransport } from '@ai-matrx/agents/matrx';
3
3
  import { RealtimeClientLike, RealtimeManager } from '@ai-matrx/realtime';
4
4
 
@@ -781,12 +781,39 @@ declare function messagingClientId(): string;
781
781
  * resubscribe loop that looks exactly like "realtime is broken".
782
782
  */
783
783
 
784
+ /**
785
+ * A host-supplied surface for ONE action kind.
786
+ *
787
+ * Chips answer a QUESTION ("Approve" / "Decline"); some actions are not
788
+ * questions. A shared-resource card, a link out to a report, a reminder with an
789
+ * app icon — those are app-shaped surfaces that only the host can draw, and a
790
+ * host that cannot draw them in the bubble ends up keeping its own message
791
+ * renderer beside this package's, which is the failure this package exists to
792
+ * prevent.
793
+ *
794
+ * The forward-compatibility rule is unchanged and enforced here, not by the
795
+ * host: a kind at a version this build does not list renders NOTHING.
796
+ */
797
+ interface MessageActionRenderProps<TPayload = unknown> {
798
+ readonly message: Message;
799
+ readonly payload: TPayload;
800
+ /** The signed-in user wrote this message — bubble-side styling depends on it. */
801
+ readonly isOwn: boolean;
802
+ }
803
+ interface MessageActionRenderer<TPayload = unknown> {
804
+ readonly kind: string;
805
+ /** Versions this build understands. An unlisted version renders nothing. */
806
+ readonly versions: readonly number[];
807
+ readonly render: ComponentType<MessageActionRenderProps<TPayload>>;
808
+ }
784
809
  interface MessagingHost {
785
810
  readonly engine: MessagingEngine;
786
811
  readonly actions: ActionRegistry;
787
812
  readonly ai: MessagingAi | null;
788
813
  readonly identity: MessagingIdentity;
789
814
  readonly openReference: ((reference: MatrxReference) => void) | null;
815
+ /** Host surfaces for action kinds whose answer is a card, not a chip. */
816
+ readonly actionRenderers: ReadonlyMap<string, MessageActionRenderer>;
790
817
  }
791
818
  interface MessagingProviderProps {
792
819
  /** Any Supabase client. `null` while the host is still resolving one. */
@@ -804,6 +831,14 @@ interface MessagingProviderProps {
804
831
  agents?: MessagingAgents | undefined;
805
832
  /** Handlers for actionable messages. Registered once per handler identity. */
806
833
  actions?: readonly ActionHandler<never>[] | undefined;
834
+ /**
835
+ * Host surfaces for action kinds whose answer is a CARD, not a chip — a
836
+ * shared-resource card, a link out, an app-shaped reminder. A kind with a
837
+ * renderer draws that instead of chips; every other rule is unchanged,
838
+ * including the one that matters: an unknown kind, or a known kind at an
839
+ * unlisted version, renders NOTHING.
840
+ */
841
+ actionRenderers?: readonly MessageActionRenderer<never>[] | undefined;
807
842
  /** Called when a reference card is clicked. Omit and cards render inert-but-labeled. */
808
843
  onOpenReference?: ((reference: MatrxReference) => void) | undefined;
809
844
  /** A message arrived from someone else — for a toast, sound, or badge. */
@@ -1286,4 +1321,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1286
1321
  /** Serialize picked references into a fence the platform's other readers accept. */
1287
1322
  declare function composeFence(references: readonly MatrxReference[]): string;
1288
1323
 
1289
- 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, 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 };
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 };
package/dist/react.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ReactNode, SVGProps } from 'react';
1
+ import { ComponentType, ReactNode, SVGProps } from 'react';
2
2
  import { MatrxTransport } from '@ai-matrx/agents/matrx';
3
3
  import { RealtimeClientLike, RealtimeManager } from '@ai-matrx/realtime';
4
4
 
@@ -781,12 +781,39 @@ declare function messagingClientId(): string;
781
781
  * resubscribe loop that looks exactly like "realtime is broken".
782
782
  */
783
783
 
784
+ /**
785
+ * A host-supplied surface for ONE action kind.
786
+ *
787
+ * Chips answer a QUESTION ("Approve" / "Decline"); some actions are not
788
+ * questions. A shared-resource card, a link out to a report, a reminder with an
789
+ * app icon — those are app-shaped surfaces that only the host can draw, and a
790
+ * host that cannot draw them in the bubble ends up keeping its own message
791
+ * renderer beside this package's, which is the failure this package exists to
792
+ * prevent.
793
+ *
794
+ * The forward-compatibility rule is unchanged and enforced here, not by the
795
+ * host: a kind at a version this build does not list renders NOTHING.
796
+ */
797
+ interface MessageActionRenderProps<TPayload = unknown> {
798
+ readonly message: Message;
799
+ readonly payload: TPayload;
800
+ /** The signed-in user wrote this message — bubble-side styling depends on it. */
801
+ readonly isOwn: boolean;
802
+ }
803
+ interface MessageActionRenderer<TPayload = unknown> {
804
+ readonly kind: string;
805
+ /** Versions this build understands. An unlisted version renders nothing. */
806
+ readonly versions: readonly number[];
807
+ readonly render: ComponentType<MessageActionRenderProps<TPayload>>;
808
+ }
784
809
  interface MessagingHost {
785
810
  readonly engine: MessagingEngine;
786
811
  readonly actions: ActionRegistry;
787
812
  readonly ai: MessagingAi | null;
788
813
  readonly identity: MessagingIdentity;
789
814
  readonly openReference: ((reference: MatrxReference) => void) | null;
815
+ /** Host surfaces for action kinds whose answer is a card, not a chip. */
816
+ readonly actionRenderers: ReadonlyMap<string, MessageActionRenderer>;
790
817
  }
791
818
  interface MessagingProviderProps {
792
819
  /** Any Supabase client. `null` while the host is still resolving one. */
@@ -804,6 +831,14 @@ interface MessagingProviderProps {
804
831
  agents?: MessagingAgents | undefined;
805
832
  /** Handlers for actionable messages. Registered once per handler identity. */
806
833
  actions?: readonly ActionHandler<never>[] | undefined;
834
+ /**
835
+ * Host surfaces for action kinds whose answer is a CARD, not a chip — a
836
+ * shared-resource card, a link out, an app-shaped reminder. A kind with a
837
+ * renderer draws that instead of chips; every other rule is unchanged,
838
+ * including the one that matters: an unknown kind, or a known kind at an
839
+ * unlisted version, renders NOTHING.
840
+ */
841
+ actionRenderers?: readonly MessageActionRenderer<never>[] | undefined;
807
842
  /** Called when a reference card is clicked. Omit and cards render inert-but-labeled. */
808
843
  onOpenReference?: ((reference: MatrxReference) => void) | undefined;
809
844
  /** A message arrived from someone else — for a toast, sound, or badge. */
@@ -1286,4 +1321,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1286
1321
  /** Serialize picked references into a fence the platform's other readers accept. */
1287
1322
  declare function composeFence(references: readonly MatrxReference[]): string;
1288
1323
 
1289
- 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, 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 };
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 };
package/dist/react.js CHANGED
@@ -10,7 +10,11 @@ import {
10
10
  useRef,
11
11
  useSyncExternalStore
12
12
  } from "react";
13
- import { RealtimeProvider, useRealtimeManager } from "@ai-matrx/realtime/react";
13
+ import {
14
+ RealtimeProvider,
15
+ useIsRealtimeProviderMounted,
16
+ useRealtimeManager
17
+ } from "@ai-matrx/realtime/react";
14
18
 
15
19
  // src/core/actions.ts
16
20
  function receiptKey(kind, messageId, actorId) {
@@ -1684,7 +1688,12 @@ function createMessagingRepository(options) {
1684
1688
 
1685
1689
  // src/react/provider.tsx
1686
1690
  import { jsx } from "react/jsx-runtime";
1687
- var MessagingContext = createContext(null);
1691
+ function messagingContext() {
1692
+ return globalSlot(
1693
+ "react-context",
1694
+ () => createContext(null)
1695
+ );
1696
+ }
1688
1697
  function defaultDiagnostics(event) {
1689
1698
  const line = `[@ai-matrx/messaging] ${event.message}${event.remedy !== void 0 ? `
1690
1699
  \u2192 ${event.remedy}` : ""}`;
@@ -1695,6 +1704,8 @@ function defaultDiagnostics(event) {
1695
1704
  function MessagingProvider(props) {
1696
1705
  const { client, userId, organizationId } = props;
1697
1706
  const ready = client != null && typeof userId === "string" && userId.length > 0 && typeof organizationId === "string" && organizationId.length > 0;
1707
+ const hostProvidesRealtime = useIsRealtimeProviderMounted();
1708
+ if (hostProvidesRealtime) return /* @__PURE__ */ jsx(MessagingRuntime, { ...props });
1698
1709
  return /* @__PURE__ */ jsx(RealtimeProvider, { client: ready ? client : null, actorId: userId ?? void 0, children: /* @__PURE__ */ jsx(MessagingRuntime, { ...props }) });
1699
1710
  }
1700
1711
  function MessagingRuntime(props) {
@@ -1763,6 +1774,14 @@ function MessagingRuntime(props) {
1763
1774
  agents
1764
1775
  });
1765
1776
  }, [transport, agents, ready, organizationId]);
1777
+ const renderers = props.actionRenderers;
1778
+ const rendererMap = useMemo(() => {
1779
+ const map = /* @__PURE__ */ new Map();
1780
+ (renderers ?? []).forEach((renderer) => {
1781
+ map.set(renderer.kind, renderer);
1782
+ });
1783
+ return map;
1784
+ }, [renderers]);
1766
1785
  const host = useMemo(() => {
1767
1786
  if (engine === null) return null;
1768
1787
  return {
@@ -1770,13 +1789,15 @@ function MessagingRuntime(props) {
1770
1789
  actions: actionRegistry,
1771
1790
  ai,
1772
1791
  identity: engine.identity,
1773
- openReference: referenceRef.current ?? null
1792
+ openReference: referenceRef.current ?? null,
1793
+ actionRenderers: rendererMap
1774
1794
  };
1775
- }, [engine, actionRegistry, ai]);
1795
+ }, [engine, actionRegistry, ai, rendererMap]);
1796
+ const MessagingContext = messagingContext();
1776
1797
  return /* @__PURE__ */ jsx(MessagingContext.Provider, { value: host, children });
1777
1798
  }
1778
1799
  function useMessagingHost() {
1779
- return useContext(MessagingContext);
1800
+ return useContext(messagingContext());
1780
1801
  }
1781
1802
  function useRequiredMessagingHost() {
1782
1803
  const host = useMessagingHost();
@@ -2788,7 +2809,22 @@ function MessageBubble(props) {
2788
2809
  ] });
2789
2810
  }
2790
2811
  function MessageActionChips(props) {
2812
+ const host = useRequiredMessagingHost();
2791
2813
  const action = useMessageAction(props.message);
2814
+ const declared = props.message.action;
2815
+ const renderer = declared === null ? void 0 : host.actionRenderers.get(declared.kind);
2816
+ if (declared !== null && renderer !== void 0) {
2817
+ if (!renderer.versions.includes(declared.version)) return null;
2818
+ const Render = renderer.render;
2819
+ return /* @__PURE__ */ jsx4(
2820
+ Render,
2821
+ {
2822
+ message: props.message,
2823
+ payload: declared.payload,
2824
+ isOwn: props.message.senderId === host.identity.userId
2825
+ }
2826
+ );
2827
+ }
2792
2828
  if (action.receipt !== null) {
2793
2829
  return /* @__PURE__ */ jsxs2("span", { className: "mx-msg__receipt", children: [
2794
2830
  action.receipt.label,