@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/index.d.cts CHANGED
@@ -984,6 +984,20 @@ type TextSegment = {
984
984
  } | {
985
985
  readonly type: "reference";
986
986
  readonly reference: MatrxReference;
987
+ }
988
+ /**
989
+ * A ```matrx fence this package could not resolve into references.
990
+ *
991
+ * It is NOT dropped. Platforms carry richer fence dialects than this
992
+ * package's own array shape — Matrx's is a `__kind` directive shell whose
993
+ * items are typed per noun, resolvable only by the app's kind registry — and
994
+ * a fence silently deleted on render is a message that lost a paragraph
995
+ * between the sender and the reader. The host draws it (`renderFence`), or
996
+ * the package draws an honest inert card. Never a code block of JSON.
997
+ */
998
+ | {
999
+ readonly type: "fence";
1000
+ readonly body: string;
987
1001
  };
988
1002
  /** Every reference a message carries, from both transports, de-duplicated. */
989
1003
  declare function extractReferences(content: string, structured?: readonly MatrxReference[]): readonly MatrxReference[];
package/dist/index.d.ts CHANGED
@@ -984,6 +984,20 @@ type TextSegment = {
984
984
  } | {
985
985
  readonly type: "reference";
986
986
  readonly reference: MatrxReference;
987
+ }
988
+ /**
989
+ * A ```matrx fence this package could not resolve into references.
990
+ *
991
+ * It is NOT dropped. Platforms carry richer fence dialects than this
992
+ * package's own array shape — Matrx's is a `__kind` directive shell whose
993
+ * items are typed per noun, resolvable only by the app's kind registry — and
994
+ * a fence silently deleted on render is a message that lost a paragraph
995
+ * between the sender and the reader. The host draws it (`renderFence`), or
996
+ * the package draws an honest inert card. Never a code block of JSON.
997
+ */
998
+ | {
999
+ readonly type: "fence";
1000
+ readonly body: string;
987
1001
  };
988
1002
  /** Every reference a message carries, from both transports, de-duplicated. */
989
1003
  declare function extractReferences(content: string, structured?: readonly MatrxReference[]): readonly MatrxReference[];
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;