@ai-matrx/messaging 0.3.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -16,10 +16,22 @@ import { RealtimeManager } from '@ai-matrx/realtime';
16
16
  * is the JSON boundary — `metadata` and `action_data` are host/DB-generated
17
17
  * shapes this package does not own (the data 0.2.1 `Json = unknown` lesson).
18
18
  */
19
- /** Nominal id types. A conversation id can never be passed where a user id goes. */
20
- declare const brand: unique symbol;
19
+ /**
20
+ * Nominal id types. A conversation id can never be passed where a user id goes.
21
+ *
22
+ * 🚨 THE MARKER IS A NAMED PROPERTY, NOT A `unique symbol`. This package ships
23
+ * two entries built as two separate bundles, so a `declare const brand: unique
24
+ * symbol` is DECLARED TWICE — and two unique symbols are two different types.
25
+ * `ConversationId` from `@ai-matrx/messaging` then does not match
26
+ * `ConversationId` from `@ai-matrx/messaging/react`, which makes the two
27
+ * entries unusable together: the first consumer hit exactly that, calling
28
+ * `asConversationId` from the core and passing it to a hook. A structural
29
+ * marker is identical in both declarations, so the brands unify — and it still
30
+ * cannot be produced by accident, which is all nominal typing needs to do.
31
+ * (The marker is types-only; nothing writes it at runtime.)
32
+ */
21
33
  type Brand<T, B extends string> = T & {
22
- readonly [brand]: B;
34
+ readonly __mxBrand: B;
23
35
  };
24
36
  type ConversationId = Brand<string, "ConversationId">;
25
37
  type MessageId = Brand<string, "MessageId">;
@@ -910,13 +922,6 @@ declare function formatConversationTime(isoString: string | null, now?: number,
910
922
  declare function formatMessageTime(isoString: string, locale?: string): string;
911
923
  /** The separator between day groups in a thread. */
912
924
  declare function formatDateSeparator(isoString: string, now?: number, locale?: string): string;
913
- declare function getInitials(name: string): string;
914
- /**
915
- * A stable palette index for an avatar with no image. Deterministic on the id,
916
- * so the same person is the same color on every device and every reload — a
917
- * random color per render is a surprisingly loud bug.
918
- */
919
- declare function avatarPaletteIndex(seed: string, buckets?: number): number;
920
925
  /**
921
926
  * Group consecutive messages by the same sender within a window, the way every
922
927
  * good chat UI does — one avatar and one name per burst.
@@ -984,6 +989,20 @@ type TextSegment = {
984
989
  } | {
985
990
  readonly type: "reference";
986
991
  readonly reference: MatrxReference;
992
+ }
993
+ /**
994
+ * A ```matrx fence this package could not resolve into references.
995
+ *
996
+ * It is NOT dropped. Platforms carry richer fence dialects than this
997
+ * package's own array shape — Matrx's is a `__kind` directive shell whose
998
+ * items are typed per noun, resolvable only by the app's kind registry — and
999
+ * a fence silently deleted on render is a message that lost a paragraph
1000
+ * between the sender and the reader. The host draws it (`renderFence`), or
1001
+ * the package draws an honest inert card. Never a code block of JSON.
1002
+ */
1003
+ | {
1004
+ readonly type: "fence";
1005
+ readonly body: string;
987
1006
  };
988
1007
  /** Every reference a message carries, from both transports, de-duplicated. */
989
1008
  declare function extractReferences(content: string, structured?: readonly MatrxReference[]): readonly MatrxReference[];
@@ -1001,4 +1020,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1001
1020
  /** Serialize picked references into a fence the platform's other readers accept. */
1002
1021
  declare function composeFence(references: readonly MatrxReference[]): string;
1003
1022
 
1004
- export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationCursor, type ConversationId, type ConversationSummary, type ConversationThread, type ConversationType, type DeliveryState, type DraftMessage, type EngineDiagnostic, type JsonObject, type JsonValue, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingIdentity, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, type Participant, type ParticipantRole, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, avatarPaletteIndex, composeFence, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createWebOutboxStorage, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, getInitials, groupMessages, inboxTopic, invalidResponse, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, splitText, summarizeText };
1023
+ export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationCursor, type ConversationId, type ConversationSummary, type ConversationThread, type ConversationType, type DeliveryState, type DraftMessage, type EngineDiagnostic, type JsonObject, type JsonValue, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingIdentity, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, type Participant, type ParticipantRole, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, composeFence, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createWebOutboxStorage, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, groupMessages, inboxTopic, invalidResponse, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, splitText, summarizeText };
package/dist/index.d.ts CHANGED
@@ -16,10 +16,22 @@ import { RealtimeManager } from '@ai-matrx/realtime';
16
16
  * is the JSON boundary — `metadata` and `action_data` are host/DB-generated
17
17
  * shapes this package does not own (the data 0.2.1 `Json = unknown` lesson).
18
18
  */
19
- /** Nominal id types. A conversation id can never be passed where a user id goes. */
20
- declare const brand: unique symbol;
19
+ /**
20
+ * Nominal id types. A conversation id can never be passed where a user id goes.
21
+ *
22
+ * 🚨 THE MARKER IS A NAMED PROPERTY, NOT A `unique symbol`. This package ships
23
+ * two entries built as two separate bundles, so a `declare const brand: unique
24
+ * symbol` is DECLARED TWICE — and two unique symbols are two different types.
25
+ * `ConversationId` from `@ai-matrx/messaging` then does not match
26
+ * `ConversationId` from `@ai-matrx/messaging/react`, which makes the two
27
+ * entries unusable together: the first consumer hit exactly that, calling
28
+ * `asConversationId` from the core and passing it to a hook. A structural
29
+ * marker is identical in both declarations, so the brands unify — and it still
30
+ * cannot be produced by accident, which is all nominal typing needs to do.
31
+ * (The marker is types-only; nothing writes it at runtime.)
32
+ */
21
33
  type Brand<T, B extends string> = T & {
22
- readonly [brand]: B;
34
+ readonly __mxBrand: B;
23
35
  };
24
36
  type ConversationId = Brand<string, "ConversationId">;
25
37
  type MessageId = Brand<string, "MessageId">;
@@ -910,13 +922,6 @@ declare function formatConversationTime(isoString: string | null, now?: number,
910
922
  declare function formatMessageTime(isoString: string, locale?: string): string;
911
923
  /** The separator between day groups in a thread. */
912
924
  declare function formatDateSeparator(isoString: string, now?: number, locale?: string): string;
913
- declare function getInitials(name: string): string;
914
- /**
915
- * A stable palette index for an avatar with no image. Deterministic on the id,
916
- * so the same person is the same color on every device and every reload — a
917
- * random color per render is a surprisingly loud bug.
918
- */
919
- declare function avatarPaletteIndex(seed: string, buckets?: number): number;
920
925
  /**
921
926
  * Group consecutive messages by the same sender within a window, the way every
922
927
  * good chat UI does — one avatar and one name per burst.
@@ -984,6 +989,20 @@ type TextSegment = {
984
989
  } | {
985
990
  readonly type: "reference";
986
991
  readonly reference: MatrxReference;
992
+ }
993
+ /**
994
+ * A ```matrx fence this package could not resolve into references.
995
+ *
996
+ * It is NOT dropped. Platforms carry richer fence dialects than this
997
+ * package's own array shape — Matrx's is a `__kind` directive shell whose
998
+ * items are typed per noun, resolvable only by the app's kind registry — and
999
+ * a fence silently deleted on render is a message that lost a paragraph
1000
+ * between the sender and the reader. The host draws it (`renderFence`), or
1001
+ * the package draws an honest inert card. Never a code block of JSON.
1002
+ */
1003
+ | {
1004
+ readonly type: "fence";
1005
+ readonly body: string;
987
1006
  };
988
1007
  /** Every reference a message carries, from both transports, de-duplicated. */
989
1008
  declare function extractReferences(content: string, structured?: readonly MatrxReference[]): readonly MatrxReference[];
@@ -1001,4 +1020,4 @@ declare function summarizeText(content: string, maxLength?: number): string;
1001
1020
  /** Serialize picked references into a fence the platform's other readers accept. */
1002
1021
  declare function composeFence(references: readonly MatrxReference[]): string;
1003
1022
 
1004
- export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationCursor, type ConversationId, type ConversationSummary, type ConversationThread, type ConversationType, type DeliveryState, type DraftMessage, type EngineDiagnostic, type JsonObject, type JsonValue, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingIdentity, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, type Participant, type ParticipantRole, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, avatarPaletteIndex, composeFence, conversationTopic, createActionRegistry, createMemoryOutboxStorage, createMessagingAi, createMessagingEngine, createMessagingRepository, createMessagingStore, createOutbox, createReadCache, createWebOutboxStorage, extractReferences, formatConversationTime, formatDateSeparator, formatLastSeen, formatMessageTime, formatTypists, getInitials, groupMessages, inboxTopic, invalidResponse, isSameDay, messagingClientId, normalizeMessagingError, optimisticMessage, participantNames, projectConversationSummary, projectMessage, projectMessageAction, projectParticipantRole, projectUserSummary, resolveActor, splitText, summarizeText };
1023
+ export { type ActionChoice, type ActionContext, type ActionHandler, type ActionOutcome, type ActionReceipt, type ActionRegistry, type ActorPresentation, type AiCapability, type AiResult, type Attachment, type ClientMessageId, type Conversation, type ConversationCursor, type ConversationId, type ConversationSummary, type ConversationThread, type ConversationType, type DeliveryState, type DraftMessage, type EngineDiagnostic, type JsonObject, type JsonValue, MESSAGING_EVENTS, MESSAGING_SCHEMA, type MatrxReference, type Message, type MessageAction, type MessageCursor, type MessageGroup, type MessageId, type MessageKind, type MessagingAgents, type MessagingAi, type MessagingAiOptions, type MessagingEngine, type MessagingEngineOptions, MessagingError, type MessagingErrorCode, type MessagingIdentity, type MessagingRepository, type MessagingSnapshot, type MessagingStore, type OrganizationId, type Outbox, type OutboxEntry, type OutboxOptions, type OutboxStorage, type Page, type Participant, type ParticipantRole, type PostgrestFilterLike, type PostgrestLikeResponse, type PostgrestTableLike, RPCS, type ReadCache, type ReadCacheOptions, type RepositoryOptions, type SchemaLike, type SessionResolver, type SupabaseLike, TABLES, type TextSegment, type UserId, type UserSummary, asClientMessageId, asConversationId, asMessageId, asOrganizationId, asUserId, 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
@@ -252,21 +252,32 @@ function splitText(content) {
252
252
  if (start > cursor) {
253
253
  segments.push({ type: "text", value: content.slice(cursor, start) });
254
254
  }
255
- parseFenceBody(match[1] ?? "").forEach((reference) => {
256
- segments.push({ type: "reference", reference });
257
- });
255
+ const body = match[1] ?? "";
256
+ const references = parseFenceBody(body);
257
+ if (references.length === 0) {
258
+ segments.push({ type: "fence", body });
259
+ } else {
260
+ references.forEach((reference) => {
261
+ segments.push({ type: "reference", reference });
262
+ });
263
+ }
258
264
  cursor = start + match[0].length;
259
265
  }
260
266
  if (cursor < content.length) {
261
267
  segments.push({ type: "text", value: content.slice(cursor) });
262
268
  }
263
269
  return segments.filter(
264
- (segment) => segment.type === "reference" || segment.value.trim().length > 0
270
+ (segment) => segment.type !== "text" || segment.value.trim().length > 0
265
271
  );
266
272
  }
267
273
  function summarizeText(content, maxLength = 140) {
268
274
  const parts = splitText(content).map(
269
- (segment) => segment.type === "text" ? segment.value : segment.reference.label
275
+ (segment) => segment.type === "text" ? segment.value : segment.type === "reference" ? segment.reference.label : (
276
+ // A fence we cannot read still SAYS something. Collapsing it to
277
+ // nothing is how a reference-only message becomes an inbox row that
278
+ // reads "No messages yet" — a screen telling a lie.
279
+ "Reference"
280
+ )
270
281
  );
271
282
  const flattened = parts.join(" ").replace(/\s+/g, " ").trim();
272
283
  if (flattened.length <= maxLength) return flattened;
@@ -1420,20 +1431,6 @@ function formatDateSeparator(isoString, now = Date.now(), locale) {
1420
1431
  day: "numeric"
1421
1432
  });
1422
1433
  }
1423
- function getInitials(name) {
1424
- const parts = name.trim().split(/\s+/).filter(Boolean);
1425
- if (parts.length === 0) return "?";
1426
- const first = parts[0]?.[0] ?? "";
1427
- const last = parts.length > 1 ? parts.at(-1)?.[0] ?? "" : "";
1428
- return `${first}${last}`.toUpperCase() || "?";
1429
- }
1430
- function avatarPaletteIndex(seed, buckets = 8) {
1431
- let hash = 0;
1432
- for (let index = 0; index < seed.length; index += 1) {
1433
- hash = hash * 31 + seed.charCodeAt(index) | 0;
1434
- }
1435
- return Math.abs(hash) % buckets;
1436
- }
1437
1434
  function groupMessages(messages, args = {}) {
1438
1435
  const windowMs = args.windowMs ?? 5 * MINUTE;
1439
1436
  const now = args.now ?? Date.now();
@@ -1836,7 +1833,6 @@ export {
1836
1833
  asMessageId,
1837
1834
  asOrganizationId,
1838
1835
  asUserId,
1839
- avatarPaletteIndex,
1840
1836
  composeFence,
1841
1837
  conversationTopic,
1842
1838
  createActionRegistry,
@@ -1854,7 +1850,6 @@ export {
1854
1850
  formatLastSeen,
1855
1851
  formatMessageTime,
1856
1852
  formatTypists,
1857
- getInitials,
1858
1853
  groupMessages,
1859
1854
  inboxTopic,
1860
1855
  invalidResponse,