@sonordev/contracts 2.3.0 → 2.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.5.0
4
+
5
+ A minor release: one new entry, `@sonordev/contracts/sentences`, and a cache tag for commerce. Every other entry is unchanged.
6
+
7
+ - **New entry `@sonordev/contracts/sentences`**: where prose splits into sentences, so every app that cuts an excerpt, a social slide or a summary out of an article ends sentences in the same places.
8
+ - `splitSentences(text)` returns the trimmed sentences of `text`. It's lossless: joining the result with spaces gives back every word of the input, in order. The usual one-liners aren't: `text.match(/[^.!?]+[.!?]+(?=\s|$)/g)` skips ahead at a period it can't use (the first one in "9 p.m.") and drops every word before its next match, and `text.match(/[^.!?]+[.!?]+/g)` cuts "9 p.m." into "9 p." and "m.".
9
+ - It doesn't end a sentence at a dotted abbreviation of letters ("p.m.", "U.S.", "e.g."), a single letter ("J."), a common short form (titles, company and street suffixes, months, and days of the week when capitalized: "Dr.", "Inc.", "Ave.", "Sept.", "Mon."), a label before a number ("No. 5", "Fig. 2") or a list number ("1.", "Step 2."), and never before a lowercase word. A piece with no letter in it ("...", "1.") joins the next sentence. A `!` or `?` right after an abbreviation still ends one.
10
+ - Prices, versions, domains and email addresses ("$4.50", "v2.1", "example.com") aren't abbreviations: a sentence can end after them.
11
+ - It runs in linear time: a megabyte of text takes milliseconds, however many abbreviations it holds.
12
+ - A newline or a list marker isn't a boundary by itself, so split on lines or paragraphs first when those matter.
13
+ - Empty, whitespace-only, `null` and `undefined` input give `[]`.
14
+ - **`site-cache`**: `SITE_CACHE_TAGS.commerce` (`commerce`) is the tag for products, services, events and membership plans. commerce-kit tags its server fetches with it, and the Sonor API expires it when an offering changes. The other tags are unchanged.
15
+
16
+ ## 2.4.0
17
+
18
+ A minor release: one new entry, `@sonordev/contracts/schema-placeholders`, and the llms.txt sanitizers stop cutting mid-word. Every other entry is unchanged.
19
+
20
+ - **New entry `@sonordev/contracts/schema-placeholders`**: whether stored JSON-LD carries a template's unfilled slots, so the API that serves it and the site that renders it drop the same nodes.
21
+ - `withoutSchemaPlaceholders(value)` returns `{ value, dropped, notes }`: the JSON-LD without its placeholder nodes (the same reference when nothing was found, `null` when nothing real is left), every node it removed with the reason and the evidence, and the AI note keys it stripped from nodes it kept.
22
+ - `findSchemaPlaceholders(value)` returns just the nodes, and `describeSchemaPlaceholder(node)` turns one into a line a person can act on.
23
+ - It finds reserved example domains (`example.com`, `example.net`, `example.org`, `.example`) in URLs, hosts and emails, whole-value template names ("Example", "Your Business Name"), placeholder phones, bracketed and JSX slots (`[Resident Name]`, `{plan.name}`, `{{business_name}}`), `REPLACE_WITH_` markers, and objects that are only a note. A URI template's `{search_term_string}`, a real name that contains "Example" and a 555 number outside the fiction range are left alone.
24
+ - **`llms`**: `clipAtWordBoundary(text, max)` cuts prose to a length without splitting a word. It ends at a sentence when one closes in the last 40% of the window, otherwise at the last whole word with an ellipsis, and never returns more than `max` characters. `sanitizeLlmsPublicSummary` and `sanitizeLlmsDisclaimerLine` now cut with it, so a long summary ends at a sentence or a whole word instead of mid-word. The limits are unchanged (400 and 280).
25
+
3
26
  ## 2.3.0
4
27
 
5
28
  A minor release: one new entry, `@sonordev/contracts/error-page`. Every other entry is unchanged.
package/README.md CHANGED
@@ -14,7 +14,7 @@ pnpm add @sonordev/contracts
14
14
  | `@sonordev/contracts/sites` | The canonical shape of a site host (the multi-site `site` dimension) | every ingest and read that filters by site |
15
15
  | `@sonordev/contracts/seo-pages` | Which `seo_pages` row a path resolves to on a multi-site project | the Sonor API, Signal, site-kit's sitemap sync |
16
16
  | `@sonordev/contracts/seo-meta` | Whether a title or description is fit to ship | site-kit, Signal's SEO gate |
17
- | `@sonordev/contracts/llms` | llms.txt sanitizers and contract version | site-kit, the Sonor API, Signal's schema validation |
17
+ | `@sonordev/contracts/llms` | llms.txt sanitizers, the word-safe cut they use (`clipAtWordBoundary`), and the contract version | site-kit, the Sonor API, Signal's schema validation |
18
18
  | `@sonordev/contracts/forms` | The honeypot policy | site-kit forms, the Sonor API's form intake |
19
19
  | `@sonordev/contracts/fleet` | The fleet heartbeat's wire shape | site-kit, the Sonor API |
20
20
  | `@sonordev/contracts/slots` | Slot payload signing, contract v2 (HMAC; Node only). Signs and verifies v1 for older site-kit releases | the Sonor API, site-kit on the server |
@@ -25,6 +25,42 @@ pnpm add @sonordev/contracts
25
25
  | `@sonordev/contracts/proposal-sitemap` | How a proposal's site plan counts its pages, when its before-and-after comparison may show, and whether the page counts stated elsewhere in the proposal add up | the Sonor API, Signal's proposal writer, the dashboard's proposal pages |
26
26
  | `@sonordev/contracts/voice` | The house voice's contraction rule. `findUncontracted` and `contractText` find and apply full forms that should be contractions; `findContracted` finds the contractions a question-form heading should expand | anything that checks or rewrites copy: Sonor's APIs and dashboard |
27
27
  | `@sonordev/contracts/error-page` | Whether stored text is a rendered error page rather than a page's content, and whether generated copy says the page itself is missing | anything that stores page text or writes page copy from it: the Sonor API's page-view and sitemap writers, Signal's metadata generators |
28
+ | `@sonordev/contracts/schema-placeholders` | Whether stored JSON-LD carries a template's unfilled slots (`example.com` URLs, an `Organization` named "Example", a placeholder phone, `[Resident Name]`, `{plan.name}`), and the value without them | site-kit's schema output, the Sonor API's schema reads and writes |
29
+ | `@sonordev/contracts/sentences` | Where prose splits into sentences, without dropping a word or ending one at "p.m." (`splitSentences`) | anything that cuts an excerpt, a social slide or a summary out of an article: the Sonor API's carousels, Signal's article pipeline |
30
+
31
+ ## Schema placeholders
32
+
33
+ `schema-placeholders` finds the parts of a JSON-LD value that a template left
34
+ unfilled, so a site never publishes them as the business's identity. Schema
35
+ extracted from a site's source, where the base URL was a variable, comes back
36
+ as `https://example.com`; a template filled in by hand or by an AI can leave
37
+ "Example", `+1-000-000-0000`, `[Resident Name]`, `{plan.name}`, or an object
38
+ that's only a note about what goes there.
39
+
40
+ ```ts
41
+ import { withoutSchemaPlaceholders, describeSchemaPlaceholder } from '@sonordev/contracts/schema-placeholders'
42
+
43
+ const { value, dropped } = withoutSchemaPlaceholders(storedJsonLd)
44
+ // value: the JSON-LD without its placeholder nodes (the same reference when
45
+ // nothing was found, null when nothing real is left)
46
+ dropped.map(describeSchemaPlaceholder)
47
+ // ['Organization at $: name "Example" is a placeholder name']
48
+ ```
49
+
50
+ - **The unit is the node.** The innermost object with an `@type` or `@id` (or
51
+ a top-level or `@graph` member) whose own values hold the placeholder is
52
+ dropped whole. Its real siblings, and a real parent it hangs off, stay. A
53
+ node left with nothing but JSON-LD keywords once its placeholder children are
54
+ gone goes too.
55
+ - **Conservative on purpose.** A false positive removes real schema from a live
56
+ site, so names match whole values only ("Example Plumbing Co" is a real
57
+ name), domains are only the reserved example domains, phones are only
58
+ all-zero, sequential, `XXX` and the 555-0100 to 555-0199 fiction range, and a
59
+ URI template's `{search_term_string}` is how schema.org spells a
60
+ `SearchAction`, never a finding.
61
+ - **Notes.** An AI's `note` key on a real node isn't schema.org vocabulary: it's
62
+ stripped and the node stays. An object that's only a note is dropped.
63
+ - **Pure.** The input is never mutated.
28
64
 
29
65
  ## The voice contract
30
66
 
@@ -252,6 +288,68 @@ A text-only check can't prove a page failed. Where you observed the HTTP
252
288
  status, require 400 or more as well and use this as the fallback; the header of
253
289
  `src/contracts/error-page.ts` lists the other known limits.
254
290
 
291
+ ## The sentences contract
292
+
293
+ Cutting an excerpt, a slide or a summary out of an article starts with
294
+ finding where its sentences end, and the usual one-liners for that get it
295
+ wrong. `text.match(/[^.!?]+[.!?]+(?=\s|$)/g)` can't end a match at the first
296
+ period of "9 p.m.", so it skips ahead and drops every word before the next
297
+ match: "We open at 9 p.m. daily." comes back as "m." and " daily.". Without
298
+ the lookahead, `text.match(/[^.!?]+[.!?]+/g)` cuts "9 p.m." into "9 p." and
299
+ "m.". Both also drop any text after the last full stop. `splitSentences` is
300
+ the one splitter to use instead.
301
+
302
+ - **Lossless.** Joining the result with spaces gives back every word of the
303
+ input, in order. Nothing is dropped, added or reordered, and each sentence
304
+ comes back trimmed and non-empty.
305
+ - **Where a sentence ends.** At `.`, `!` or `?` (and any closing `"`, `'`, `”`,
306
+ `’`, `)` or `]` after it) followed by whitespace and then `A` to `Z` or `0`
307
+ to `9`, optionally after one opening `"`, `'`, `“`, `‘`, `(` or `[`. Never
308
+ before a lowercase word or a symbol. Only ASCII capitals count: a sentence
309
+ that opens with an accented, Greek or Cyrillic capital, a currency sign, `#`,
310
+ `@` or an emoji stays joined to the one before it.
311
+ - **Where it doesn't.** After a dotted abbreviation made of letters ("p.m.",
312
+ "U.S.", "e.g.", "Ph.D."), a single letter of either case (an initial like
313
+ "J.", but also "Plan A."), or a short form on its list: titles, company
314
+ suffixes, months, street suffixes and days of the week ("Dr.", "Inc.",
315
+ "Sept.", "Ave.", "Mon."). A few of those only count when capitalized, because
316
+ the lowercase word ends sentences too ("Mon." is a day, "the sun." isn't).
317
+ A label with a number after it stays together ("No. 5", "Fig. 2",
318
+ "Ste. 200"), while "No." before anything else ends a sentence. A list number
319
+ ("1.", "Step 2.", "Do three things: 1.") stays with its item.
320
+ - **`!` and `?`.** An abbreviation only holds back a period. "Open until 9
321
+ p.m.? Yes!" is two sentences, under the same start-of-sentence rule as above.
322
+ - **Prices, versions and web addresses** ("$4.50", "v2.1", "example.com",
323
+ "info@example.com") aren't abbreviations: a sentence can end after them.
324
+ - **Never a bare mark.** A piece with no letter in it ("...", "?!", "1.")
325
+ isn't a sentence. It joins the next one.
326
+ - **Prose, not layout.** A newline or a list marker doesn't start a new
327
+ sentence by itself. If lines or paragraphs matter, split on those first and
328
+ call `splitSentences` on each one.
329
+ - **Empty is `[]`.** Empty, whitespace-only, `null` and `undefined` input all
330
+ give an empty array, never `null`, so callers can iterate without a guard.
331
+ - **Linear time.** One pass over the text. A megabyte takes milliseconds,
332
+ however many abbreviations, stops or quotes it holds.
333
+
334
+ ```ts
335
+ import { splitSentences } from '@sonordev/contracts/sentences'
336
+
337
+ splitSentences('We open at 9 a.m. daily. Walk-ins are welcome.')
338
+ // ['We open at 9 a.m. daily.', 'Walk-ins are welcome.']
339
+
340
+ splitSentences(excerptSource).slice(0, 2).join(' ')
341
+ // the first two sentences, whole
342
+ ```
343
+
344
+ Known limits. Where it can't be sure it leans toward joining, because a
345
+ sentence that runs long costs less than a lost word, and a caller that caps
346
+ length should cut at a word. It can't tell an abbreviation that ends a
347
+ sentence from one that doesn't ("Contact Acme Inc. Our team ..." and "... in
348
+ Washington, D.C. Residents ..." each stay in one piece), it only knows English
349
+ short forms (a period after one it doesn't know ends a sentence, so "Sra.
350
+ García" splits after "Sra."), and the next sentence has to start with `A` to
351
+ `Z` or a digit.
352
+
255
353
  ## Why it exists
256
354
 
257
355
  A rule that lives in several copies is how two of them end up disagreeing.
package/dist/color.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * Single source of truth for turning a CSS colour string into something the
5
5
  * kit can reason about. Used at build time by the brand-profile extractor
6
6
  * (`src/brand/extract-brand-profile.ts`, theme detection) and in the browser
7
- * by Echo (`src/engage/brand-color.ts`, brand text contrast). Pure, no
7
+ * by Echo (`src/chat/brand-color.ts`, brand text contrast). Pure, no
8
8
  * imports, safe in both.
9
9
  */
10
10
  export type Rgb = {
package/dist/llms.d.ts CHANGED
@@ -28,6 +28,7 @@ export interface LLMsPayloadMeta {
28
28
  /** Optional single-line, public-safe note in the llms.txt blockquote (e.g. scope / not legal advice). */
29
29
  llms_disclaimer?: string | null;
30
30
  }
31
+ export declare function clipAtWordBoundary(text: string, max: number): string;
31
32
  /**
32
33
  * Public-safe summary for llms.txt `[title](url): notes` — never CRM-only or internal copy.
33
34
  */
package/dist/llms.js CHANGED
@@ -18,14 +18,64 @@ var MANAGED_LLM_SCHEMA_KNOWN_KEYS = /* @__PURE__ */ new Set([
18
18
  "speakable",
19
19
  "additionalType"
20
20
  ]);
21
+ var SENTENCE_SHARE = 0.4;
22
+ var ELLIPSIS = "\u2026";
23
+ var CLOSERS = /* @__PURE__ */ new Set(['"', "'", ")", "]", "\u201D", "\u2019", "\xBB"]);
24
+ var ABBREVIATIONS = /* @__PURE__ */ new Set([
25
+ "mr",
26
+ "mrs",
27
+ "ms",
28
+ "dr",
29
+ "prof",
30
+ "st",
31
+ "mt",
32
+ "ft",
33
+ "jr",
34
+ "sr",
35
+ "inc",
36
+ "ltd",
37
+ "co",
38
+ "corp",
39
+ "vs",
40
+ "no"
41
+ ]);
42
+ var TRAILING_SEPARATORS = /[\s.,;:\-\u2013\u2014/&([{]+$/;
43
+ function clipAtWordBoundary(text, max) {
44
+ const flat = text.replace(/\s+/g, " ").trim();
45
+ if (flat.length <= max) return flat;
46
+ if (max < 2) return flat.slice(0, Math.max(0, max));
47
+ const floor = Math.floor(max * (1 - SENTENCE_SHARE));
48
+ for (let end = max; end > floor; end--) {
49
+ if (endsSentence(flat, end)) return flat.slice(0, end);
50
+ }
51
+ const room = max - 1;
52
+ const space = flat.lastIndexOf(" ", room);
53
+ if (space <= 0) return `${flat.slice(0, room)}${ELLIPSIS}`;
54
+ if (endsSentence(flat, space)) return flat.slice(0, space);
55
+ const head = flat.slice(0, space).replace(TRAILING_SEPARATORS, "");
56
+ return `${head || flat.slice(0, room)}${ELLIPSIS}`;
57
+ }
58
+ function endsSentence(flat, end) {
59
+ if (flat[end] !== " ") return false;
60
+ let i = end - 1;
61
+ while (i > 0 && CLOSERS.has(flat[i])) i--;
62
+ const terminator = flat[i];
63
+ if (terminator === "!" || terminator === "?") return true;
64
+ return terminator === "." && !isAbbreviation(flat, i);
65
+ }
66
+ function isAbbreviation(flat, dot) {
67
+ let start = dot;
68
+ while (start > 0 && flat[start - 1] !== " ") start--;
69
+ const token = flat.slice(start, dot).replace(/^[("'[\u201c\u2018]+/, "").toLowerCase();
70
+ if (token.includes(".") || /^[a-z]$/.test(token)) return true;
71
+ return ABBREVIATIONS.has(token);
72
+ }
21
73
  function sanitizeLlmsPublicSummary(raw) {
22
74
  if (raw === null || raw === void 0) return null;
23
75
  if (typeof raw !== "string") return null;
24
76
  let s = raw.trim().replace(/\s+/g, " ");
25
77
  s = s.replace(/[\[\]\r\n]/g, " ").replace(/\s+/g, " ").trim();
26
- if (s.length > LLMS_PUBLIC_SUMMARY_MAX_LENGTH) {
27
- s = `${s.slice(0, LLMS_PUBLIC_SUMMARY_MAX_LENGTH - 1).trimEnd()}\u2026`;
28
- }
78
+ s = clipAtWordBoundary(s, LLMS_PUBLIC_SUMMARY_MAX_LENGTH);
29
79
  if (/\b[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}\b/.test(s)) return null;
30
80
  if (/\b\+?\d[\d\s().-]{8,}\b/.test(s)) return null;
31
81
  if (s.length < 8) return null;
@@ -36,9 +86,7 @@ function sanitizeLlmsDisclaimerLine(raw) {
36
86
  if (typeof raw !== "string") return null;
37
87
  let s = raw.trim().replace(/\s+/g, " ");
38
88
  s = s.replace(/[\[\]\r\n]/g, " ").replace(/\s+/g, " ").trim();
39
- if (s.length > LLMS_DISCLAIMER_MAX_LENGTH) {
40
- s = `${s.slice(0, LLMS_DISCLAIMER_MAX_LENGTH - 1).trimEnd()}\u2026`;
41
- }
89
+ s = clipAtWordBoundary(s, LLMS_DISCLAIMER_MAX_LENGTH);
42
90
  if (/\b[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}\b/.test(s)) return null;
43
91
  if (/\b\+?\d[\d\s().-]{8,}\b/.test(s)) return null;
44
92
  if (s.length < 3) return null;
@@ -100,6 +148,7 @@ exports.LLMS_DISCLAIMER_MAX_LENGTH = LLMS_DISCLAIMER_MAX_LENGTH;
100
148
  exports.LLMS_PUBLIC_SUMMARY_MAX_LENGTH = LLMS_PUBLIC_SUMMARY_MAX_LENGTH;
101
149
  exports.LLM_GEO_CONTRACT_VERSION = LLM_GEO_CONTRACT_VERSION;
102
150
  exports.MANAGED_LLM_SCHEMA_KNOWN_KEYS = MANAGED_LLM_SCHEMA_KNOWN_KEYS;
151
+ exports.clipAtWordBoundary = clipAtWordBoundary;
103
152
  exports.isEmittableReviewNode = isEmittableReviewNode;
104
153
  exports.pickManagedLlmSchemaForJsonLd = pickManagedLlmSchemaForJsonLd;
105
154
  exports.sanitizeLlmsDisclaimerLine = sanitizeLlmsDisclaimerLine;
package/dist/llms.mjs CHANGED
@@ -16,14 +16,64 @@ var MANAGED_LLM_SCHEMA_KNOWN_KEYS = /* @__PURE__ */ new Set([
16
16
  "speakable",
17
17
  "additionalType"
18
18
  ]);
19
+ var SENTENCE_SHARE = 0.4;
20
+ var ELLIPSIS = "\u2026";
21
+ var CLOSERS = /* @__PURE__ */ new Set(['"', "'", ")", "]", "\u201D", "\u2019", "\xBB"]);
22
+ var ABBREVIATIONS = /* @__PURE__ */ new Set([
23
+ "mr",
24
+ "mrs",
25
+ "ms",
26
+ "dr",
27
+ "prof",
28
+ "st",
29
+ "mt",
30
+ "ft",
31
+ "jr",
32
+ "sr",
33
+ "inc",
34
+ "ltd",
35
+ "co",
36
+ "corp",
37
+ "vs",
38
+ "no"
39
+ ]);
40
+ var TRAILING_SEPARATORS = /[\s.,;:\-\u2013\u2014/&([{]+$/;
41
+ function clipAtWordBoundary(text, max) {
42
+ const flat = text.replace(/\s+/g, " ").trim();
43
+ if (flat.length <= max) return flat;
44
+ if (max < 2) return flat.slice(0, Math.max(0, max));
45
+ const floor = Math.floor(max * (1 - SENTENCE_SHARE));
46
+ for (let end = max; end > floor; end--) {
47
+ if (endsSentence(flat, end)) return flat.slice(0, end);
48
+ }
49
+ const room = max - 1;
50
+ const space = flat.lastIndexOf(" ", room);
51
+ if (space <= 0) return `${flat.slice(0, room)}${ELLIPSIS}`;
52
+ if (endsSentence(flat, space)) return flat.slice(0, space);
53
+ const head = flat.slice(0, space).replace(TRAILING_SEPARATORS, "");
54
+ return `${head || flat.slice(0, room)}${ELLIPSIS}`;
55
+ }
56
+ function endsSentence(flat, end) {
57
+ if (flat[end] !== " ") return false;
58
+ let i = end - 1;
59
+ while (i > 0 && CLOSERS.has(flat[i])) i--;
60
+ const terminator = flat[i];
61
+ if (terminator === "!" || terminator === "?") return true;
62
+ return terminator === "." && !isAbbreviation(flat, i);
63
+ }
64
+ function isAbbreviation(flat, dot) {
65
+ let start = dot;
66
+ while (start > 0 && flat[start - 1] !== " ") start--;
67
+ const token = flat.slice(start, dot).replace(/^[("'[\u201c\u2018]+/, "").toLowerCase();
68
+ if (token.includes(".") || /^[a-z]$/.test(token)) return true;
69
+ return ABBREVIATIONS.has(token);
70
+ }
19
71
  function sanitizeLlmsPublicSummary(raw) {
20
72
  if (raw === null || raw === void 0) return null;
21
73
  if (typeof raw !== "string") return null;
22
74
  let s = raw.trim().replace(/\s+/g, " ");
23
75
  s = s.replace(/[\[\]\r\n]/g, " ").replace(/\s+/g, " ").trim();
24
- if (s.length > LLMS_PUBLIC_SUMMARY_MAX_LENGTH) {
25
- s = `${s.slice(0, LLMS_PUBLIC_SUMMARY_MAX_LENGTH - 1).trimEnd()}\u2026`;
26
- }
76
+ s = clipAtWordBoundary(s, LLMS_PUBLIC_SUMMARY_MAX_LENGTH);
27
77
  if (/\b[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}\b/.test(s)) return null;
28
78
  if (/\b\+?\d[\d\s().-]{8,}\b/.test(s)) return null;
29
79
  if (s.length < 8) return null;
@@ -34,9 +84,7 @@ function sanitizeLlmsDisclaimerLine(raw) {
34
84
  if (typeof raw !== "string") return null;
35
85
  let s = raw.trim().replace(/\s+/g, " ");
36
86
  s = s.replace(/[\[\]\r\n]/g, " ").replace(/\s+/g, " ").trim();
37
- if (s.length > LLMS_DISCLAIMER_MAX_LENGTH) {
38
- s = `${s.slice(0, LLMS_DISCLAIMER_MAX_LENGTH - 1).trimEnd()}\u2026`;
39
- }
87
+ s = clipAtWordBoundary(s, LLMS_DISCLAIMER_MAX_LENGTH);
40
88
  if (/\b[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}\b/.test(s)) return null;
41
89
  if (/\b\+?\d[\d\s().-]{8,}\b/.test(s)) return null;
42
90
  if (s.length < 3) return null;
@@ -94,4 +142,4 @@ function pickManagedLlmSchemaForJsonLd(schema) {
94
142
  return Object.keys(out).length ? out : null;
95
143
  }
96
144
 
97
- export { LLMS_DISCLAIMER_MAX_LENGTH, LLMS_PUBLIC_SUMMARY_MAX_LENGTH, LLM_GEO_CONTRACT_VERSION, MANAGED_LLM_SCHEMA_KNOWN_KEYS, isEmittableReviewNode, pickManagedLlmSchemaForJsonLd, sanitizeLlmsDisclaimerLine, sanitizeLlmsPublicSummary, sanitizePrimaryLanguageTag };
145
+ export { LLMS_DISCLAIMER_MAX_LENGTH, LLMS_PUBLIC_SUMMARY_MAX_LENGTH, LLM_GEO_CONTRACT_VERSION, MANAGED_LLM_SCHEMA_KNOWN_KEYS, clipAtWordBoundary, isEmittableReviewNode, pickManagedLlmSchemaForJsonLd, sanitizeLlmsDisclaimerLine, sanitizeLlmsPublicSummary, sanitizePrimaryLanguageTag };
@@ -0,0 +1,87 @@
1
+ /**
2
+ * JSON-LD template placeholders: found once, dropped wherever sonor-api serves
3
+ * stored schema to a site, and never stored as implemented by register-schema.
4
+ *
5
+ * Stored JSON-LD (seo_schema_markup.schema_json, seo_pages.managed_schema) can
6
+ * carry a template's unfilled slots. Schema extracted from a site's source,
7
+ * where the base URL was a variable, comes back as https://example.com; an AI
8
+ * filling a template leaves "Example", "+1-000-000-0000", "[Resident Name]",
9
+ * "{plan.name}", or an object that is only a "note" saying what goes there.
10
+ * site-kit renders all of it on the live page, where search engines and AI
11
+ * crawlers take it as the business's identity. Observed 2026-10-01: a live
12
+ * site served an Organization named "Example", phone +1-000-000-0000, on its
13
+ * home page, and dozens more of its implemented rows carried example.com URLs
14
+ * and unfilled template slots.
15
+ *
16
+ * Conservative on purpose, because a false positive removes real schema from a
17
+ * live site:
18
+ * - Domains: only the reserved example domains (example.com, example.net,
19
+ * example.org, their subdomains, and the .example TLD), and only when the
20
+ * whole value is a URL, host or email address. A real domain with
21
+ * "example" in its path, or prose that mentions example.com, is fine.
22
+ * - Names: whole-value matches only (trimmed, case-insensitive) on name-like
23
+ * properties. "Example Plumbing Co" is a real name.
24
+ * - Phones (telephone, faxNumber, tel: links): all zeros, 123-456-7890,
25
+ * XXX-XXX-XXXX, and 555-0100 through 555-0199, the North American range
26
+ * reserved for fiction. 555-0200 and 555-1212 are real numbers.
27
+ * - Template slots: a value that is wholly a bracketed slot ("[YYYY-MM-DD]")
28
+ * or a JSX expression ("{plan.name}"), a {{mustache}} slot, a
29
+ * REPLACE_WITH_ marker, a title-case field name in brackets inside text
30
+ * ("Call [Phone Number]"), or a JSX member expression inside a URL. A URI
31
+ * template's {search_term_string} is how schema.org spells a SearchAction
32
+ * and is never a finding.
33
+ * - Annotations: an object that holds nothing but an AI note. A note key on
34
+ * a real node is stripped (it isn't schema.org vocabulary) and the node
35
+ * stays.
36
+ *
37
+ * The unit is the NODE: the innermost object with @type or @id (or a top-level
38
+ * or @graph member) whose own values hold the placeholder. A placeholder node
39
+ * is dropped whole, since its other values came from the same unfilled
40
+ * template. Its real siblings, and a real parent it hangs off, stay: an
41
+ * FAQPage keeps its questions when only its publisher was a placeholder. A
42
+ * node left with nothing but JSON-LD keywords once its placeholder children
43
+ * are gone (a BreadcrumbList whose every item was a placeholder) goes too, so
44
+ * the site falls back to what it generates itself.
45
+ *
46
+ * Single source of truth for "is this stored schema a placeholder", published
47
+ * as `@sonordev/contracts/schema-placeholders`: sonor-api's public schema reads
48
+ * and register-schema, and site-kit's ManagedSchema and LLMSchema (so a site
49
+ * drops a placeholder whichever Sonor source served it) all call it. Add new
50
+ * shapes here, with a test, never in a caller.
51
+ */
52
+ export type SchemaPlaceholderReason = 'example_domain' | 'placeholder_phone' | 'placeholder_name' | 'template_token' | 'annotation' | 'emptied';
53
+ export interface SchemaPlaceholderEvidence {
54
+ reason: SchemaPlaceholderReason;
55
+ /** The property that held the value. */
56
+ key: string;
57
+ /** The value, cut short for logs. */
58
+ value: string;
59
+ }
60
+ export interface SchemaPlaceholderNode {
61
+ /** Where the node sits: '$' for the root, then .key and [index] steps. */
62
+ path: string;
63
+ /** The node's @type ('A,B' when it has several), or null. */
64
+ type: string | null;
65
+ reasons: SchemaPlaceholderReason[];
66
+ evidence: SchemaPlaceholderEvidence[];
67
+ }
68
+ export interface SchemaPlaceholderScan<T> {
69
+ /** The value without its placeholder nodes: the same reference when nothing was found, null when nothing real is left. */
70
+ value: T | null;
71
+ /** Every node removed, outermost only (a dropped node's children go with it). */
72
+ dropped: SchemaPlaceholderNode[];
73
+ /** AI note keys stripped from nodes that were kept. */
74
+ notes: Array<{
75
+ path: string;
76
+ key: string;
77
+ }>;
78
+ }
79
+ /**
80
+ * The value with its placeholder nodes removed, and what was removed. Pure; the
81
+ * input is never mutated.
82
+ */
83
+ export declare function withoutSchemaPlaceholders<T>(value: T): SchemaPlaceholderScan<T>;
84
+ /** Which nodes of a JSON-LD value are placeholders, and why. */
85
+ export declare function findSchemaPlaceholders(value: unknown): SchemaPlaceholderNode[];
86
+ /** One line a person can act on: 'Organization at $: name "Example" is a placeholder name'. */
87
+ export declare function describeSchemaPlaceholder(node: SchemaPlaceholderNode): string;