@ai-matrx/messaging 0.15.8 → 0.15.10

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
@@ -1257,6 +1257,8 @@ interface MessagingEngine {
1257
1257
  readonly store: MessagingStore;
1258
1258
  readonly outbox: Outbox;
1259
1259
  readonly identity: MessagingIdentity;
1260
+ /** Route package-owned recoveries through the host's diagnostic surface. */
1261
+ reportDiagnostic(event: EngineDiagnostic): void;
1260
1262
  /** Load page one of the inbox and start the inbox channel. */
1261
1263
  start(): Promise<void>;
1262
1264
  loadMoreConversations(): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1257,6 +1257,8 @@ interface MessagingEngine {
1257
1257
  readonly store: MessagingStore;
1258
1258
  readonly outbox: Outbox;
1259
1259
  readonly identity: MessagingIdentity;
1260
+ /** Route package-owned recoveries through the host's diagnostic surface. */
1261
+ reportDiagnostic(event: EngineDiagnostic): void;
1260
1262
  /** Load page one of the inbox and start the inbox channel. */
1261
1263
  start(): Promise<void>;
1262
1264
  loadMoreConversations(): Promise<void>;
package/dist/index.js CHANGED
@@ -304,7 +304,7 @@ function splitText(content) {
304
304
  }
305
305
  function summarizeText(content, maxLength = 140) {
306
306
  const parts = splitText(content).map(
307
- (segment) => segment.type === "text" ? segment.value : segment.type === "reference" ? segment.reference.label : (
307
+ (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 : (
308
308
  // A fence we cannot read still SAYS something. Collapsing it to
309
309
  // nothing is how a reference-only message becomes an inbox row that
310
310
  // reads "No messages yet" — a screen telling a lie.
@@ -821,8 +821,7 @@ function projectMessageAction(value) {
821
821
  payload: jsonObject(record["payload"])
822
822
  };
823
823
  }
824
- function projectAttachments(metadata) {
825
- const raw = metadata["attachments"];
824
+ function projectAttachmentList(raw) {
826
825
  if (!Array.isArray(raw)) return [];
827
826
  const attachments = [];
828
827
  for (const entry of raw) {
@@ -844,8 +843,13 @@ function projectAttachments(metadata) {
844
843
  }
845
844
  return attachments;
846
845
  }
846
+ function projectAttachments(metadata) {
847
+ return projectAttachmentList(metadata["attachments"]);
848
+ }
847
849
  function projectReferences(metadata) {
848
- const raw = metadata["references"];
850
+ return projectReferenceList(metadata["references"]);
851
+ }
852
+ function projectReferenceList(raw) {
849
853
  if (!Array.isArray(raw)) return [];
850
854
  const references = [];
851
855
  for (const entry of raw) {
@@ -864,6 +868,35 @@ function projectReferences(metadata) {
864
868
  }
865
869
  return references;
866
870
  }
871
+ function projectBroadcastMessage(value) {
872
+ const operation = "projectBroadcastMessage";
873
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
874
+ throw invalidResponse(operation, "broadcast payload was not an object");
875
+ }
876
+ const record = value;
877
+ const kindRaw = str(record, "kind") ?? str(record, "messageType") ?? "text";
878
+ const stateRaw = str(record, "deliveryState") ?? str(record, "status") ?? "sent";
879
+ const metadata = jsonObject(record["metadata"]);
880
+ return {
881
+ id: requiredStr(record, "id", operation),
882
+ conversationId: requiredStr(record, "conversationId", operation),
883
+ senderId: requiredStr(record, "senderId", operation),
884
+ organizationId: requiredStr(record, "organizationId", operation),
885
+ content: typeof record["content"] === "string" ? record["content"] : "",
886
+ kind: MESSAGE_KINDS.has(kindRaw) ? kindRaw : "text",
887
+ deliveryState: DELIVERY_STATES.has(stateRaw) ? stateRaw : "sent",
888
+ replyToId: str(record, "replyToId"),
889
+ clientMessageId: str(record, "clientMessageId"),
890
+ createdAt: requiredStr(record, "createdAt", operation),
891
+ editedAt: str(record, "editedAt"),
892
+ deletedAt: str(record, "deletedAt"),
893
+ deletedForEveryone: bool(record, "deletedForEveryone", false),
894
+ action: projectMessageAction(record["action"]),
895
+ attachments: projectAttachmentList(record["attachments"]),
896
+ references: projectReferenceList(record["references"]),
897
+ metadata
898
+ };
899
+ }
867
900
  function projectMessage(row, fallbackOrganizationId) {
868
901
  const operation = "projectMessage";
869
902
  const metadata = jsonObject(row["metadata"]);
@@ -1337,6 +1370,7 @@ function createMessagingEngine(options) {
1337
1370
  store,
1338
1371
  outbox,
1339
1372
  identity,
1373
+ reportDiagnostic: report,
1340
1374
  async start() {
1341
1375
  if (options.archiveFilter !== void 0) {
1342
1376
  store.setArchiveFilter(options.archiveFilter);
@@ -1478,8 +1512,11 @@ function createMessagingEngine(options) {
1478
1512
  {
1479
1513
  event: MESSAGING_EVENTS.message,
1480
1514
  onMessage: ({ data }) => {
1481
- if (typeof data !== "object" || data === null) return;
1482
- store.ingest(data);
1515
+ try {
1516
+ store.ingest(projectBroadcastMessage(data));
1517
+ } catch (error) {
1518
+ reportError(error, "broadcastMessage");
1519
+ }
1483
1520
  }
1484
1521
  }
1485
1522
  ],