@ai-matrx/messaging 0.15.9 → 0.15.11

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog — `@ai-matrx/messaging`
2
2
 
3
+ ## 0.15.11
4
+
5
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
6
+ `git diff npm/messaging/v0.15.10..npm/messaging/v0.15.11 -- apps/shared/messaging`).
7
+ No source changes intended and no consumer action required.
8
+
9
+ ## 0.15.10
10
+
11
+ Automatic changed-only republish (docs/metadata drift since the last tag — see
12
+ `git diff npm/messaging/v0.15.9..npm/messaging/v0.15.10 -- apps/shared/messaging`).
13
+ No source changes intended and no consumer action required.
14
+
3
15
  ## 0.15.9
4
16
 
5
17
  Automatic changed-only republish (docs/metadata drift since the last tag — see
package/dist/index.cjs CHANGED
@@ -377,7 +377,7 @@ function splitText(content) {
377
377
  }
378
378
  function summarizeText(content, maxLength = 140) {
379
379
  const parts = splitText(content).map(
380
- (segment) => segment.type === "text" ? segment.value : segment.type === "reference" ? segment.reference.label : (
380
+ (segment) => segment.type === "text" ? segment.value.replace(/```[^\n]*\n([\s\S]*?)```/g, "$1").replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1").replace(/\[([^\]]+)\]\([^)]*\)/g, "$1").replace(/^\s{0,3}(?:#{1,6}\s+|>\s*|[-*+]\s+|\d+\.\s+)/gm, "").replace(/([*_`~])\1*(.*?)\1+/g, "$2") : segment.type === "reference" ? segment.reference.label : (
381
381
  // A fence we cannot read still SAYS something. Collapsing it to
382
382
  // nothing is how a reference-only message becomes an inbox row that
383
383
  // reads "No messages yet" — a screen telling a lie.
@@ -892,8 +892,7 @@ function projectMessageAction(value) {
892
892
  payload: jsonObject(record["payload"])
893
893
  };
894
894
  }
895
- function projectAttachments(metadata) {
896
- const raw = metadata["attachments"];
895
+ function projectAttachmentList(raw) {
897
896
  if (!Array.isArray(raw)) return [];
898
897
  const attachments = [];
899
898
  for (const entry of raw) {
@@ -915,8 +914,13 @@ function projectAttachments(metadata) {
915
914
  }
916
915
  return attachments;
917
916
  }
917
+ function projectAttachments(metadata) {
918
+ return projectAttachmentList(metadata["attachments"]);
919
+ }
918
920
  function projectReferences(metadata) {
919
- const raw = metadata["references"];
921
+ return projectReferenceList(metadata["references"]);
922
+ }
923
+ function projectReferenceList(raw) {
920
924
  if (!Array.isArray(raw)) return [];
921
925
  const references = [];
922
926
  for (const entry of raw) {
@@ -935,6 +939,35 @@ function projectReferences(metadata) {
935
939
  }
936
940
  return references;
937
941
  }
942
+ function projectBroadcastMessage(value) {
943
+ const operation = "projectBroadcastMessage";
944
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
945
+ throw invalidResponse(operation, "broadcast payload was not an object");
946
+ }
947
+ const record = value;
948
+ const kindRaw = str(record, "kind") ?? str(record, "messageType") ?? "text";
949
+ const stateRaw = str(record, "deliveryState") ?? str(record, "status") ?? "sent";
950
+ const metadata = jsonObject(record["metadata"]);
951
+ return {
952
+ id: requiredStr(record, "id", operation),
953
+ conversationId: requiredStr(record, "conversationId", operation),
954
+ senderId: requiredStr(record, "senderId", operation),
955
+ organizationId: requiredStr(record, "organizationId", operation),
956
+ content: typeof record["content"] === "string" ? record["content"] : "",
957
+ kind: MESSAGE_KINDS.has(kindRaw) ? kindRaw : "text",
958
+ deliveryState: DELIVERY_STATES.has(stateRaw) ? stateRaw : "sent",
959
+ replyToId: str(record, "replyToId"),
960
+ clientMessageId: str(record, "clientMessageId"),
961
+ createdAt: requiredStr(record, "createdAt", operation),
962
+ editedAt: str(record, "editedAt"),
963
+ deletedAt: str(record, "deletedAt"),
964
+ deletedForEveryone: bool(record, "deletedForEveryone", false),
965
+ action: projectMessageAction(record["action"]),
966
+ attachments: projectAttachmentList(record["attachments"]),
967
+ references: projectReferenceList(record["references"]),
968
+ metadata
969
+ };
970
+ }
938
971
  function projectMessage(row, fallbackOrganizationId) {
939
972
  const operation = "projectMessage";
940
973
  const metadata = jsonObject(row["metadata"]);
@@ -1408,6 +1441,7 @@ function createMessagingEngine(options) {
1408
1441
  store,
1409
1442
  outbox,
1410
1443
  identity,
1444
+ reportDiagnostic: report,
1411
1445
  async start() {
1412
1446
  if (options.archiveFilter !== void 0) {
1413
1447
  store.setArchiveFilter(options.archiveFilter);
@@ -1549,8 +1583,11 @@ function createMessagingEngine(options) {
1549
1583
  {
1550
1584
  event: MESSAGING_EVENTS.message,
1551
1585
  onMessage: ({ data }) => {
1552
- if (typeof data !== "object" || data === null) return;
1553
- store.ingest(data);
1586
+ try {
1587
+ store.ingest(projectBroadcastMessage(data));
1588
+ } catch (error) {
1589
+ reportError(error, "broadcastMessage");
1590
+ }
1554
1591
  }
1555
1592
  }
1556
1593
  ],