@rudra-js/core 0.4.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.
Files changed (64) hide show
  1. package/README.md +139 -15
  2. package/dist/claim-screening.d.ts +33 -0
  3. package/dist/claim-screening.d.ts.map +1 -0
  4. package/dist/claim-screening.js +226 -0
  5. package/dist/claim-screening.js.map +1 -0
  6. package/dist/component-generator.d.ts.map +1 -1
  7. package/dist/component-generator.js +33 -98
  8. package/dist/component-generator.js.map +1 -1
  9. package/dist/component-spec.d.ts +2 -49
  10. package/dist/component-spec.d.ts.map +1 -1
  11. package/dist/component-spec.js +3 -17
  12. package/dist/component-spec.js.map +1 -1
  13. package/dist/fallback-component.d.ts +3 -0
  14. package/dist/fallback-component.d.ts.map +1 -1
  15. package/dist/fallback-component.js +3 -13
  16. package/dist/fallback-component.js.map +1 -1
  17. package/dist/fit-to-shopper.d.ts +5 -1
  18. package/dist/fit-to-shopper.d.ts.map +1 -1
  19. package/dist/fit-to-shopper.js +6 -4
  20. package/dist/fit-to-shopper.js.map +1 -1
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/model-prompt.d.ts +13 -1
  25. package/dist/model-prompt.d.ts.map +1 -1
  26. package/dist/model-prompt.js +53 -21
  27. package/dist/model-prompt.js.map +1 -1
  28. package/dist/product-selection.d.ts +1 -9
  29. package/dist/product-selection.d.ts.map +1 -1
  30. package/dist/product-selection.js +1 -4
  31. package/dist/product-selection.js.map +1 -1
  32. package/dist/provider.d.ts +1 -8
  33. package/dist/provider.d.ts.map +1 -1
  34. package/dist/provider.js +1 -8
  35. package/dist/provider.js.map +1 -1
  36. package/dist/reconciliation.d.ts +15 -12
  37. package/dist/reconciliation.d.ts.map +1 -1
  38. package/dist/reconciliation.js +150 -340
  39. package/dist/reconciliation.js.map +1 -1
  40. package/dist/signal-digest.d.ts +10 -0
  41. package/dist/signal-digest.d.ts.map +1 -1
  42. package/dist/signal-digest.js +38 -28
  43. package/dist/signal-digest.js.map +1 -1
  44. package/dist/spec-cache.d.ts +14 -2
  45. package/dist/spec-cache.d.ts.map +1 -1
  46. package/dist/spec-cache.js +14 -24
  47. package/dist/spec-cache.js.map +1 -1
  48. package/dist/tracking-input.d.ts.map +1 -1
  49. package/dist/tracking-input.js +15 -13
  50. package/dist/tracking-input.js.map +1 -1
  51. package/package.json +4 -2
  52. package/src/claim-screening.ts +242 -0
  53. package/src/component-generator.ts +38 -123
  54. package/src/component-spec.ts +5 -18
  55. package/src/fallback-component.ts +3 -14
  56. package/src/fit-to-shopper.ts +11 -4
  57. package/src/index.ts +1 -0
  58. package/src/model-prompt.ts +58 -23
  59. package/src/product-selection.ts +2 -13
  60. package/src/provider.ts +1 -8
  61. package/src/reconciliation.ts +178 -359
  62. package/src/signal-digest.ts +41 -31
  63. package/src/spec-cache.ts +27 -24
  64. package/src/tracking-input.ts +16 -13
@@ -1,4 +1,5 @@
1
1
  import { BANNER_TONES, EMPHASIS, RECOMMENDATION_BASES, TONES } from './component-spec.js';
2
+ import { FIELD_LIMITS } from './tracking-input.js';
2
3
  /**
3
4
  * What actually reaches the model.
4
5
  *
@@ -126,31 +127,51 @@ on.`;
126
127
  * text exactly the same way, and it missed U+0085, U+061C and U+00AD as well.
127
128
  * Properties cover the ones nobody has thought of yet.
128
129
  *
129
- * - Cc, control. Includes U+0085, a mandatory line break that is not U+000A.
130
- * - Cf, format. Zero-width characters, the bidirectional overrides and
131
- * isolates, and the tag block, which mirrors all of ASCII invisibly.
132
- * - Zl and Zp, the line and paragraph separators.
133
- * - Cn and Co, unassigned and private use — undefined rendering by definition.
134
- * - The variation selectors supplement, which is assigned and therefore not
135
- * caught by Cn, and is invisible.
130
+ * The general categories alone do not, though. Half of what renders as nothing
131
+ * is a mark or a letter rather than a format character \u2014 the Mongolian free
132
+ * variation selectors, U+034F, the Hangul fillers, and the sixteen variation
133
+ * selectors at U+FE00 \u2014 so `Default_Ignorable_Code_Point` is in the class too.
134
+ * It is the property that means "takes up no room", which is the thing that
135
+ * makes a character able to carry text nobody sees.
136
136
  *
137
- * The zero-width joiner is the one exception. It is a format character, but it
138
- * is also how a family emoji is spelled, so escaping it mangles ordinary
139
- * product titles. Emoji presentation selectors (U+FE00-U+FE0F) are excluded for
140
- * the same reason.
137
+ * Three are left out. The zero-width joiner is a format character, but it is
138
+ * also how a family emoji is spelled, and U+FE0E and U+FE0F are what make a
139
+ * character render as an emoji rather than as text. Escaping those mangles
140
+ * ordinary product titles. The other thirteen selectors at U+FE00 spell
141
+ * nothing and are escaped like the rest.
141
142
  */
142
- const UNPRINTABLE = /(?!\u200D)[\p{Cc}\p{Cf}\p{Cn}\p{Co}\p{Zl}\p{Zp}\u{E0100}-\u{E01EF}]/gu;
143
+ const UNPRINTABLE = /(?!\u{200D}|\u{FE0E}|\u{FE0F})[\p{Cc}\p{Cf}\p{Cn}\p{Co}\p{Zl}\p{Zp}\p{Default_Ignorable_Code_Point}]/gu;
143
144
  /**
144
- * Host-supplied text, written so it cannot introduce structure of its own.
145
+ * How long one quoted value may be once escaped.
145
146
  *
146
- * Quoting handles the obvious half. Escaping the characters above handles the
147
- * half that looks identical to a reader: after this, a value occupies exactly
148
- * one line, reads in one direction, and contains nothing a log cannot show.
147
+ * The contract caps the string a host may send, and this caps what that string
148
+ * turns into. They are not the same number: an escape writes up to eight
149
+ * characters for one, so a field on its cap can still buy eight times the
150
+ * prompt \u2014 and the bill \u2014 that the cap implies. Ordinary text escapes nothing
151
+ * and never comes near this.
149
152
  */
150
- const quote = (value) => JSON.stringify(value).replace(UNPRINTABLE, (character) => {
153
+ const MAX_QUOTED = FIELD_LIMITS.shortText * 2;
154
+ const escapeUnprintable = (text) => text.replace(UNPRINTABLE, (character) => {
151
155
  const codePoint = character.codePointAt(0);
152
156
  return `\\u{${codePoint.toString(16).toUpperCase()}}`;
153
157
  });
158
+ /** Host-supplied text, written so it cannot introduce structure of its own. */
159
+ const quote = (value) => {
160
+ const escaped = escapeUnprintable(JSON.stringify(value));
161
+ if (escaped.length <= MAX_QUOTED)
162
+ return escaped;
163
+ // Cut whole characters, so the result cannot end inside an escape sequence.
164
+ let length = 2;
165
+ let kept = '';
166
+ for (const character of value) {
167
+ const cost = escapeUnprintable(JSON.stringify(character)).length - 2;
168
+ if (length + cost > MAX_QUOTED)
169
+ break;
170
+ length += cost;
171
+ kept += character;
172
+ }
173
+ return escapeUnprintable(JSON.stringify(kept));
174
+ };
154
175
  function section(heading, body) {
155
176
  if (!body || body.length === 0)
156
177
  return null;
@@ -179,7 +200,6 @@ function describeShopper(digest) {
179
200
  ];
180
201
  return lines.filter((line) => line !== null).join('\n');
181
202
  }
182
- /** One candidate per line. Facts the model must not restate are left out. */
183
203
  function describeCandidate(product) {
184
204
  const parts = [quote(product.sku), quote(product.title), quote(product.category)];
185
205
  if (product.rating !== undefined)
@@ -199,10 +219,22 @@ function describeCandidate(product) {
199
219
  * first ones through are the ones it put first.
200
220
  */
201
221
  const MAX_CANDIDATES = 60;
222
+ /**
223
+ * The candidates the model is actually shown.
224
+ *
225
+ * An out-of-stock product is dropped during reconciliation whatever the model
226
+ * does with it, so offering one only costs the shopper a slot.
227
+ *
228
+ * Exported because reconciliation checks the numerals the model writes against
229
+ * the strings on this list, and a candidate it was never shown cannot be where
230
+ * one came from. Two copies of "what the model saw" would drift, and the pair
231
+ * that drifted would be the prompt and the screen reading it back.
232
+ */
233
+ export function offeredCandidates(input) {
234
+ return input.candidates.filter((product) => product.isInStock).slice(0, MAX_CANDIDATES);
235
+ }
202
236
  export function buildPrompt(input, digest) {
203
- // An out-of-stock product is dropped during reconciliation whatever the model
204
- // does with it, so offering one only costs the shopper a slot.
205
- const offered = input.candidates.filter((product) => product.isInStock).slice(0, MAX_CANDIDATES);
237
+ const offered = offeredCandidates(input);
206
238
  // The markers are OWASP's labelled-block recommendation. They are safe as
207
239
  // boundaries because every value between them is quoted and stripped of
208
240
  // anything that could end a line, so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18
  product: Product;
19
19
  /** Why this product, stated so reconciliation can check it. */
20
20
  basis: RecommendationBasis;
21
- /** How the basis reads to a shopper. */
21
+ /** How the basis reads to a shopper. The host's own sentence when it wrote one. */
22
22
  reason: string;
23
- /** True when `reason` is the host's own sentence from the candidate. */
24
- reasonFromHost: boolean;
25
23
  /** Unnormalised. Only the ordering is meaningful. */
26
24
  score: number;
27
25
  }
28
- /**
29
- * Scores every eligible candidate and returns them best first.
30
- *
31
- * Ties break on SKU so the order is total: two runs over the same payload
32
- * produce the same list, which is what makes the control arm reproducible.
33
- */
34
26
  /** How the picks are ordered once the unplaceable ones are gone. */
35
27
  export type RankOrder = 'signals' | 'given';
36
28
  export interface SelectOptions {
@@ -1 +1 @@
1
- {"version":3,"file":"product-selection.d.ts","sourceRoot":"","sources":["../src/product-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAElE;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,+DAA+D;IAC/D,KAAK,EAAE,mBAAmB,CAAC;IAC3B,wCAAwC;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,wEAAwE;IACxE,cAAc,EAAE,OAAO,CAAC;IACxB,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;CACf;AAyED;;;;;GAKG;AACH,oEAAoE;AACpE,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,aAAkB,GAC1B,WAAW,EAAE,CAmDf"}
1
+ {"version":3,"file":"product-selection.d.ts","sourceRoot":"","sources":["../src/product-selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAElE;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,OAAO,CAAC;IACjB,+DAA+D;IAC/D,KAAK,EAAE,mBAAmB,CAAC;IAC3B,mFAAmF;IACnF,MAAM,EAAE,MAAM,CAAC;IACf,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;CACf;AAuED,oEAAoE;AACpE,MAAM,MAAM,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,YAAY,EACpB,OAAO,GAAE,aAAkB,GAC1B,WAAW,EAAE,CAkDf"}
@@ -12,9 +12,7 @@ const SCORE_WEIGHTS = {
12
12
  };
13
13
  /** Beyond this many shared tags, more overlap says nothing new. */
14
14
  const MAX_TAG_OVERLAP = 3;
15
- /** Assumed rating for a product the catalog does not rate. */
16
15
  const UNRATED = 3.5;
17
- /** Tags on the products this shopper has actually engaged with. */
18
16
  function engagedTags(input, digest) {
19
17
  const engagedSkus = new Set([
20
18
  ...digest.likedSkus,
@@ -61,7 +59,7 @@ export function selectProducts(input, digest, options = {}) {
61
59
  // same thing whether a shopper has two signals or two hundred.
62
60
  const strongestAffinity = Math.max(1, ...affinityByCategory.values());
63
61
  const tags = engagedTags(input, digest);
64
- const excluded = neverRecommend(digest);
62
+ const excluded = neverRecommend(input);
65
63
  const viewsBySku = new Map(digest.topViewed.map((viewed) => [viewed.sku, viewed.views]));
66
64
  const picks = [];
67
65
  for (const product of input.candidates) {
@@ -90,7 +88,6 @@ export function selectProducts(input, digest, options = {}) {
90
88
  product,
91
89
  basis,
92
90
  reason: product.reason ?? reason,
93
- reasonFromHost: product.reason !== undefined,
94
91
  score,
95
92
  });
96
93
  }
@@ -1 +1 @@
1
- {"version":3,"file":"product-selection.js","sourceRoot":"","sources":["../src/product-selection.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AA6BrD;;;;GAIG;AACH,MAAM,aAAa,GAAG;IACpB,QAAQ,EAAE,CAAC;IACX,OAAO,EAAE,GAAG;IACZ,MAAM,EAAE,GAAG;IACX,UAAU,EAAE,GAAG;CACP,CAAC;AAEX,mEAAmE;AACnE,MAAM,eAAe,GAAG,CAAC,CAAC;AAE1B,8DAA8D;AAC9D,MAAM,OAAO,GAAG,GAAG,CAAC;AAEpB,mEAAmE;AACnE,SAAS,WAAW,CAAC,KAAoB,EAAE,MAAoB;IAC7D,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;QAC1B,GAAG,MAAM,CAAC,SAAS;QACnB,GAAG,MAAM,CAAC,aAAa;QACvB,GAAG,MAAM,CAAC,QAAQ;QAClB,GAAG,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC;KAChD,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QACvC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,SAAS;QAC5C,KAAK,MAAM,GAAG,IAAI,OAAO,CAAC,IAAI;YAAE,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChD,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C,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,CAC/F,CAAC;AACJ,CAAC"}
@@ -68,13 +68,6 @@ export interface ComponentProvider {
68
68
  readonly model: string;
69
69
  generate(request: ProviderRequest): Promise<ProviderResult>;
70
70
  }
71
- /**
72
- * A provider that returns a fixed spec and never touches the network.
73
- *
74
- * This is the benchmark's control: it isolates the cost of the framework from
75
- * the latency of a model, which is the only way to report what server-side
76
- * rendering itself costs. It is also what the generator's tests run against,
77
- * since a test that needs an API key is a test nobody runs.
78
- */
71
+ /** A provider that returns a fixed spec and never touches the network. */
79
72
  export declare function createFixedSpecProvider(spec: GeneratedSpec): ComponentProvider;
80
73
  //# sourceMappingURL=provider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEzD;;;;;;;GAOG;AAEH,+EAA+E;AAC/E,MAAM,WAAW,UAAU;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IACjC,yEAAyE;IACzE,MAAM,EAAE,WAAW,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,aAAa,CAAC;IACpB,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;A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C,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;CAC7D;AAED,0EAA0E;AAC1E,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,aAAa,GAAG,iBAAiB,CAa9E"}
package/dist/provider.js CHANGED
@@ -1,11 +1,4 @@
1
- /**
2
- * A provider that returns a fixed spec and never touches the network.
3
- *
4
- * This is the benchmark's control: it isolates the cost of the framework from
5
- * the latency of a model, which is the only way to report what server-side
6
- * rendering itself costs. It is also what the generator's tests run against,
7
- * since a test that needs an API key is a test nobody runs.
8
- */
1
+ /** A provider that returns a fixed spec and never touches the network. */
9
2
  export function createFixedSpecProvider(spec) {
10
3
  return {
11
4
  name: 'fixed',
@@ -1 +1 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AA4EA;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAmB;IACzD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YAC7B,0EAA0E;YAC1E,yEAAyE;YACzE,8DAA8D;YAC9D,qEAAqE;YACrE,MAAM,CAAC,cAAc,EAAE,CAAC;YACxB,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AA4EA,0EAA0E;AAC1E,MAAM,UAAU,uBAAuB,CAAC,IAAmB;IACzD,OAAO;QACL,IAAI,EAAE,OAAO;QACb,KAAK,EAAE,MAAM;QACb,QAAQ,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YAC7B,0EAA0E;YAC1E,yEAAyE;YACzE,8DAA8D;YAC9D,qEAAqE;YACrE,MAAM,CAAC,cAAc,EAAE,CAAC;YACxB,OAAO,EAAE,IAAI,EAAE,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,13 +1,10 @@
1
1
  import type { Block, GeneratedSpec } from './component-spec.js';
2
- import type { SignalDigest } from './signal-digest.js';
2
+ import { type SignalDigest } from './signal-digest.js';
3
3
  import type { Bundle, TrackingInput } from './tracking-input.js';
4
- /**
5
- * More than this and the component stops being a component.
6
- *
7
- * Exported because the fill pass has to read the same blocks this module will:
8
- * one past the cap never renders, so nothing is worth reserving for it.
9
- */
4
+ /** More than this and the component stops being a component. */
10
5
  export declare const MAX_BLOCKS = 4;
6
+ /** The fill pass calls this too: one past the cap never renders, so nothing is worth reserving for it. */
7
+ export declare function capBlocks(blocks: Block[]): Block[];
11
8
  export interface ReconcileResult {
12
9
  spec: GeneratedSpec;
13
10
  /** True when something survived that is worth rendering. */
@@ -18,12 +15,15 @@ export interface ReconcileResult {
18
15
  /**
19
16
  * SKUs that must never be recommended, whatever chose them.
20
17
  *
18
+ * Everything above plus what the shopper already has, read from the payload for
19
+ * the same reason: a shopper with nine purchases must not be sold the ninth back.
20
+ *
21
21
  * Exported because the deterministic selector applies the same rule when it
22
22
  * picks. Two copies of "never recommend these" would drift, and the pair that
23
23
  * drifted would be the model path and the fallback path — the two whose
24
24
  * comparability the whole evaluation depends on.
25
25
  */
26
- export declare function neverRecommend(digest: SignalDigest): Set<string>;
26
+ export declare function neverRecommend(input: TrackingInput): Set<string>;
27
27
  /**
28
28
  * The set this shopper should get, decided before anything is placed.
29
29
  *
@@ -44,12 +44,15 @@ export declare function bundleForShopper(input: TrackingInput, digest: SignalDig
44
44
  * One this shopper cannot see is dropped below and spends nothing, so it is not
45
45
  * counted here either.
46
46
  */
47
- export declare function placeableHeroSkus(blocks: readonly Block[], input: TrackingInput, digest: SignalDigest): string[];
47
+ export declare function placeableHeroSkus(blocks: readonly Block[], input: TrackingInput): string[];
48
48
  export declare function reconcileSpec(generated: GeneratedSpec, input: TrackingInput, digest: SignalDigest,
49
49
  /**
50
- * SKUs whose reason this request wrote from the host's own candidate. Only
51
- * `fitToShopper` fills it, so in `per-shopper` mode it is empty and every
50
+ * The reason this request wrote itself, by SKU: the host's own `reason` on a
51
+ * candidate, or the sentence the selector wrote when there was none. Neither is the
52
+ * model's words, and the deterministic component renders the same sentence unscreened.
53
+ *
54
+ * Only `fitToShopper` fills it, so in `per-shopper` mode it is empty and every
52
55
  * reason is the model's, including one that happens to read the same.
53
56
  */
54
- hostReasonSkus?: ReadonlySet<string>): ReconcileResult;
57
+ ourReasons?: ReadonlyMap<string, string>): ReconcileResult;
55
58
  //# sourceMappingURL=reconciliation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reconciliation.d.ts","sourceRoot":"","sources":["../src/reconciliation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,KAAK,EACL,aAAa,EAGd,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAW,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAuC1E;;;;;GAKG;AACH,eAAO,MAAM,UAAU,IAAI,CAAC;AAE5B,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,aAAa,CAAC;IACpB,4DAA4D;IAC5D,QAAQ,EAAE,OAAO,CAAC;IAClB,6EAA6E;IAC7E,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AA2BD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,CAQhE;AA+bD;;;;;;;;;;GAUG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,YAAY,EACpB,SAAS,EAAE,SAAS,MAAM,EAAE,GAC3B,MAAM,GAAG,SAAS,CAQpB;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,SAAS,KAAK,EAAE,EACxB,KAAK,EAAE,aAA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