@rudra-js/core 0.9.0 → 0.10.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 (63) hide show
  1. package/README.md +425 -375
  2. package/dist/claim-screening.d.ts.map +1 -1
  3. package/dist/claim-screening.js +3 -9
  4. package/dist/claim-screening.js.map +1 -1
  5. package/dist/component-generator.d.ts +1 -1
  6. package/dist/component-generator.d.ts.map +1 -1
  7. package/dist/component-generator.js +28 -61
  8. package/dist/component-generator.js.map +1 -1
  9. package/dist/component-spec.d.ts +100 -11
  10. package/dist/component-spec.d.ts.map +1 -1
  11. package/dist/component-spec.js +3 -6
  12. package/dist/component-spec.js.map +1 -1
  13. package/dist/fallback-component.d.ts.map +1 -1
  14. package/dist/fallback-component.js +3 -3
  15. package/dist/fallback-component.js.map +1 -1
  16. package/dist/fit-to-shopper.d.ts +4 -1
  17. package/dist/fit-to-shopper.d.ts.map +1 -1
  18. package/dist/fit-to-shopper.js +8 -0
  19. package/dist/fit-to-shopper.js.map +1 -1
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +1 -1
  23. package/dist/index.js.map +1 -1
  24. package/dist/model-prompt.d.ts.map +1 -1
  25. package/dist/model-prompt.js +16 -3
  26. package/dist/model-prompt.js.map +1 -1
  27. package/dist/product-display.d.ts +6 -0
  28. package/dist/product-display.d.ts.map +1 -0
  29. package/dist/product-display.js +32 -0
  30. package/dist/product-display.js.map +1 -0
  31. package/dist/reconciliation.d.ts +2 -4
  32. package/dist/reconciliation.d.ts.map +1 -1
  33. package/dist/reconciliation.js +15 -21
  34. package/dist/reconciliation.js.map +1 -1
  35. package/dist/schemas.d.ts +1 -0
  36. package/dist/schemas.d.ts.map +1 -1
  37. package/dist/schemas.js +1 -0
  38. package/dist/schemas.js.map +1 -1
  39. package/dist/signal-digest.d.ts.map +1 -1
  40. package/dist/signal-digest.js +2 -10
  41. package/dist/signal-digest.js.map +1 -1
  42. package/dist/spec-cache.d.ts +86 -7
  43. package/dist/spec-cache.d.ts.map +1 -1
  44. package/dist/spec-cache.js +14 -32
  45. package/dist/spec-cache.js.map +1 -1
  46. package/dist/tracking-input.d.ts.map +1 -1
  47. package/dist/tracking-input.js +8 -2
  48. package/dist/tracking-input.js.map +1 -1
  49. package/package.json +5 -4
  50. package/schemas/package.json +4 -0
  51. package/src/claim-screening.ts +3 -9
  52. package/src/component-generator.ts +33 -82
  53. package/src/component-spec.ts +5 -18
  54. package/src/fallback-component.ts +4 -3
  55. package/src/fit-to-shopper.ts +16 -1
  56. package/src/index.ts +1 -2
  57. package/src/model-prompt.ts +24 -3
  58. package/src/product-display.ts +43 -0
  59. package/src/reconciliation.ts +16 -23
  60. package/src/schemas.ts +6 -0
  61. package/src/signal-digest.ts +2 -8
  62. package/src/spec-cache.ts +17 -41
  63. package/src/tracking-input.ts +11 -2
@@ -1 +1 @@
1
- {"version":3,"file":"tracking-input.js","sourceRoot":"","sources":["../src/tracking-input.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,UAAU,EAAE,GAAG;IACf,SAAS,EAAE,GAAG;IACd,WAAW,EAAE,GAAG;IAChB,GAAG,EAAE,EAAE;IACP,cAAc,EAAE,EAAE;IAClB,WAAW,EAAE,EAAE;IACf,kBAAkB,EAAE,GAAG;IACvB,UAAU,EAAE,GAAG;IACf,iBAAiB,EAAE,CAAC;IACpB,OAAO,EAAE,EAAE;IACX,SAAS,EAAE,EAAE;IACb,QAAQ,EAAE,EAAE;IACZ,MAAM,EAAE,GAAG;CACH,CAAC;AAEX,MAAM,iBAAiB,GAAG,WAAW,CAAC;AAEtC,MAAM,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAE1C,MAAM,UAAU,GAAG,GAAG,EAAE,CAAC,CAAC,CA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O,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9E,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QACnC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC;gBAAE,OAAO,KAAK,CAAC;QAC5C,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,EACD,EAAE,OAAO,EAAE,oDAAoD,EAAE,CAClE,CAAC;AAQJ,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,mBAAmB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,KAAc;IACnD,OAAO,mBAAmB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AAC9C,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rudra-js/core",
3
- "version": "0.9.0",
4
- "description": "Core of rudra-js, a TypeScript library for LLM-designed product recommendations: turns one page view into a recommendation spec checked against your catalog",
3
+ "version": "0.10.0",
4
+ "description": "The core of rudra-js. Lets a language model design product recommendations for a page and checks them against your own products.",
5
5
  "keywords": [
6
6
  "rudra-js",
7
7
  "product-recommendations",
@@ -43,6 +43,7 @@
43
43
  },
44
44
  "files": [
45
45
  "dist",
46
+ "schemas",
46
47
  "src/**/*.ts",
47
48
  "src/**/*.tsx",
48
49
  "!src/**/*.test.ts",
@@ -60,10 +61,10 @@
60
61
  "zod": "^4.6.7"
61
62
  },
62
63
  "peerDependencies": {
63
- "@rudra-js/attested": "^0.9.0"
64
+ "@rudra-js/attested": "^0.10.0"
64
65
  },
65
66
  "devDependencies": {
66
- "@rudra-js/attested": "0.9.0",
67
+ "@rudra-js/attested": "0.10.0",
67
68
  "@types/node": "^26.4.1"
68
69
  }
69
70
  }
@@ -0,0 +1,4 @@
1
+ {
2
+ "main": "../dist/schemas.js",
3
+ "types": "../dist/schemas.d.ts"
4
+ }
@@ -1,4 +1,4 @@
1
- import { foldLookalikes, verify } from '@rudra-js/attested';
1
+ import { listLookalikeReadings, verify } from '@rudra-js/attested';
2
2
  import { offeredCandidates } from './model-prompt.js';
3
3
  import type { TrackingInput } from './tracking-input.js';
4
4
 
@@ -84,7 +84,6 @@ export const ALLOWED_PHRASES = [
84
84
  ];
85
85
 
86
86
  const FACT_DIGIT = /\p{Nd}/u;
87
- const NUMERAL = /[\p{Nd}\p{No}\p{Nl}]/u;
88
87
 
89
88
  export const NO_FACTS: readonly string[] = [];
90
89
 
@@ -114,11 +113,7 @@ function kindIn(reading: string): string | null {
114
113
  }
115
114
 
116
115
  function claimIn(text: string): string | null {
117
- const readings = new Set([foldLookalikes(text), foldLookalikes(text, true)]);
118
- if (text.includes('\u04C0')) {
119
- readings.add(foldLookalikes(text.replaceAll('\u04C0', '\u04CF'), true));
120
- }
121
- for (const reading of readings) {
116
+ for (const reading of listLookalikeReadings(text)) {
122
117
  const kind = kindIn(reading);
123
118
  if (kind !== null) return kind;
124
119
  }
@@ -133,8 +128,7 @@ export function unbackedClaim(
133
128
  const kind = claimIn(raw) ?? claimIn(clamped);
134
129
  if (kind !== null) return kind;
135
130
 
136
- const values = NUMERAL.test(clamped) ? facts : NO_FACTS;
137
- const result = verify(clamped, { values, allowedPhrases: ALLOWED_PHRASES });
131
+ const result = verify(clamped, { values: facts, allowedPhrases: ALLOWED_PHRASES });
138
132
  if (!result.quantity.supported) return 'quantity';
139
133
  if (!result.wording.supported) return 'wording';
140
134
  return null;
@@ -1,4 +1,3 @@
1
- import { z } from 'zod';
2
1
  import {
3
2
  SPEC_VERSION,
4
3
  generatedSpecSchema,
@@ -8,13 +7,14 @@ import {
8
7
  type SpecSource,
9
8
  } from './component-spec.js';
10
9
  import { buildFallbackSpec } from './fallback-component.js';
11
- import { buildPrompt } from './model-prompt.js';
10
+ import { buildPrompt, type PromptPair } from './model-prompt.js';
12
11
  import type { ComponentProvider, TokenUsage } from './provider.js';
13
- import { bundleForShopper, capBlocks, placeableHeroSkus, reconcileSpec } from './reconciliation.js';
14
- import { selectProducts, type RankOrder } from './product-selection.js';
15
- import { fitToShopper, type FittedSpec } from './fit-to-shopper.js';
12
+ import { reconcileSpec } from './reconciliation.js';
13
+ import type { RankOrder } from './product-selection.js';
14
+ import { fitCohortSpec } from './fit-to-shopper.js';
16
15
  import { buildDigest, toCohortDigest, type SignalDigest } from './signal-digest.js';
17
16
  import {
17
+ cachedSpecSchema,
18
18
  createMemorySpecCache,
19
19
  specCacheKey,
20
20
  type CachedSpec,
@@ -86,11 +86,6 @@ async function withinBudget<T>(
86
86
  }
87
87
  }
88
88
 
89
- const cachedSpecSchema = z.object({
90
- spec: generatedSpecSchema,
91
- generatedAt: z.number(),
92
- });
93
-
94
89
  interface CacheRead {
95
90
  outcome: NonNullable<GenerationEvent['cache']>;
96
91
  entry?: CachedSpec;
@@ -102,13 +97,13 @@ interface ModelCall {
102
97
  }
103
98
 
104
99
  interface Settings {
105
- options: ComponentGeneratorOptions;
106
100
  provider: ComponentProvider | null;
107
101
  cache: SpecCache;
108
- generation: 'cohort' | 'per-shopper';
102
+ generation: NonNullable<ComponentGeneratorOptions['generation']>;
109
103
  rank: RankOrder;
110
104
  modelTimeoutMs: number;
111
105
  cacheTimeoutMs: number;
106
+ onEvent: ComponentGeneratorOptions['onEvent'];
112
107
  inFlight: Map<string, Promise<ModelCall>>;
113
108
  }
114
109
 
@@ -119,59 +114,26 @@ interface Run {
119
114
  startedAt: number;
120
115
  }
121
116
 
122
- interface Trace {
123
- calledModel: boolean;
124
- cache: CacheRead['outcome'];
125
- usage: TokenUsage | undefined;
126
- error?: unknown;
127
- }
128
-
129
117
  type Found =
130
- | { spec: GeneratedSpec; generatedAt: number; source: 'cache' | 'llm'; trace: Trace }
131
- | { failed: DegradedReason; trace: Trace };
118
+ | { spec: GeneratedSpec; generatedAt: number; source: 'cache' | 'llm'; details: EventDetails }
119
+ | { failed: DegradedReason; details: EventDetails };
132
120
 
133
121
  type EventDetails = Pick<
134
122
  GenerationEvent,
135
123
  'calledModel' | 'usage' | 'violations' | 'cache' | 'error'
136
124
  >;
137
125
 
138
- function fitCohortSpec(
139
- spec: GeneratedSpec,
140
- input: TrackingInput,
141
- digest: SignalDigest,
142
- rank: RankOrder,
143
- ): FittedSpec {
144
- const picks = selectProducts(input, digest, { rank });
145
- const blocks = capBlocks(spec.blocks);
146
-
147
- const bundleAt = blocks.findIndex((block) => block.kind === 'bundle');
148
- if (bundleAt === -1) return fitToShopper(spec, picks, digest.maxItems);
149
-
150
- const heroesAbove = placeableHeroSkus(blocks.slice(0, bundleAt), input);
151
- const bundle = bundleForShopper(input, digest, heroesAbove);
152
- if (!bundle) return fitToShopper(spec, picks, digest.maxItems);
153
-
154
- const spokenFor = new Set<string>(bundle.skus);
155
- for (const sku of placeableHeroSkus(blocks, input)) spokenFor.add(sku);
156
-
157
- const roomLeft = digest.maxItems - spokenFor.size;
158
- if (roomLeft <= 0) return fitToShopper(spec, picks, digest.maxItems);
159
-
160
- const forGrid = picks.filter((pick) => !spokenFor.has(pick.product.sku));
161
- return fitToShopper(spec, forGrid, roomLeft);
162
- }
163
-
164
126
  export function createComponentGenerator(
165
127
  options: ComponentGeneratorOptions = {},
166
128
  ): ComponentGenerator {
167
129
  const settings: Settings = {
168
- options,
169
130
  provider: options.provider ?? null,
170
131
  cache: options.cache ?? createMemorySpecCache(),
171
132
  generation: options.generation ?? 'cohort',
172
133
  rank: options.rank ?? 'signals',
173
134
  modelTimeoutMs: options.modelTimeoutMs ?? 1_500,
174
135
  cacheTimeoutMs: options.cacheTimeoutMs ?? 50,
136
+ onEvent: options.onEvent,
175
137
  inFlight: new Map(),
176
138
  };
177
139
 
@@ -186,13 +148,14 @@ async function generate(settings: Settings, draft: TrackingInputDraft): Promise<
186
148
  const provider = settings.provider;
187
149
  if (!provider) return fallback(settings, run, null, 'no-provider');
188
150
 
189
- const key = cacheKeyFor(provider, run);
190
- const found = await findSpec(settings, provider, run, key);
191
- if ('failed' in found)
192
- return fallback(settings, run, key, found.failed, eventDetails(found.trace));
151
+ const prompt = buildPrompt(run.input, run.promptDigest);
152
+ const key = specCacheKey(prompt, provider);
153
+ const found = await findSpec(settings, provider, prompt, key);
154
+ if ('failed' in found) return fallback(settings, run, key, found.failed, found.details);
193
155
 
194
156
  const reconciled = shapeForShopper(settings, run, found.spec);
195
- const details = eventDetails(found.trace, reconciled.violations);
157
+ const { usage, ...seen } = found.details;
158
+ const details = { ...seen, violations: reconciled.violations, ...(usage ? { usage } : {}) };
196
159
  if (!reconciled.isUsable) return fallback(settings, run, key, 'unusable-on-serve', details);
197
160
 
198
161
  const finishedAt = Date.now();
@@ -227,39 +190,34 @@ function startRun(settings: Settings, draft: TrackingInputDraft): Run {
227
190
  return { input, digest, promptDigest, startedAt };
228
191
  }
229
192
 
230
- function cacheKeyFor(provider: ComponentProvider, run: Run): string {
231
- const identity = { name: provider.name, model: provider.model };
232
- const skus = run.input.candidates.map((product) => product.sku);
233
- return specCacheKey(run.promptDigest, skus, identity);
234
- }
235
-
236
193
  async function findSpec(
237
194
  settings: Settings,
238
195
  provider: ComponentProvider,
239
- run: Run,
196
+ prompt: PromptPair,
240
197
  key: string,
241
198
  ): Promise<Found> {
242
199
  const read = await readCache(settings, key);
243
200
  if (read.entry) {
244
- const trace = { calledModel: false, cache: read.outcome, usage: undefined };
245
- return { spec: read.entry.spec, generatedAt: read.entry.generatedAt, source: 'cache', trace };
201
+ const details = { calledModel: false, cache: read.outcome };
202
+ return { spec: read.entry.spec, generatedAt: read.entry.generatedAt, source: 'cache', details };
246
203
  }
247
204
 
248
205
  const calledModel = !settings.inFlight.has(key);
249
206
  let call: ModelCall;
250
207
  try {
251
- call = await sharedCall(settings, key, () => askModel(settings, provider, run));
208
+ call = await sharedCall(settings, key, () => askModel(settings, provider, prompt));
252
209
  } catch (error) {
253
210
  const failed = error instanceof TimeoutError ? 'timeout' : 'provider-error';
254
- return { failed, trace: { calledModel, cache: read.outcome, usage: undefined, error } };
211
+ return { failed, details: { calledModel, cache: read.outcome, error } };
255
212
  }
256
213
 
257
- const trace = { calledModel, cache: read.outcome, usage: call.usage };
258
- if (!call.spec) return { failed: 'invalid-generation', trace };
214
+ const details: EventDetails = { calledModel, cache: read.outcome };
215
+ if (call.usage) details.usage = call.usage;
216
+ if (!call.spec) return { failed: 'invalid-generation', details };
259
217
 
260
218
  const generatedAt = Date.now();
261
219
  if (calledModel) storeInBackground(settings, key, { spec: call.spec, generatedAt });
262
- return { spec: call.spec, generatedAt, source: 'llm', trace };
220
+ return { spec: call.spec, generatedAt, source: 'llm', details };
263
221
  }
264
222
 
265
223
  async function readCache(settings: Settings, key: string): Promise<CacheRead> {
@@ -277,11 +235,15 @@ async function readCache(settings: Settings, key: string): Promise<CacheRead> {
277
235
  async function askModel(
278
236
  settings: Settings,
279
237
  provider: ComponentProvider,
280
- run: Run,
238
+ prompt: PromptPair,
281
239
  ): Promise<ModelCall> {
282
- const { system, user } = buildPrompt(run.input, run.promptDigest);
283
240
  const result = await withinBudget('generation', settings.modelTimeoutMs, (signal) =>
284
- provider.generate({ system, user, schema: generatedSpecSchema, signal }),
241
+ provider.generate({
242
+ system: prompt.system,
243
+ user: prompt.user,
244
+ schema: generatedSpecSchema,
245
+ signal,
246
+ }),
285
247
  );
286
248
  const parsed = generatedSpecSchema.safeParse(result.spec);
287
249
  return {
@@ -345,19 +307,8 @@ function fallback(
345
307
  };
346
308
  }
347
309
 
348
- function eventDetails(trace: Trace, violations?: string[]): EventDetails {
349
- return {
350
- calledModel: trace.calledModel,
351
- cache: trace.cache,
352
- ...(violations ? { violations } : {}),
353
- ...(trace.usage ? { usage: trace.usage } : {}),
354
- ...('error' in trace ? { error: trace.error } : {}),
355
- };
356
- }
357
-
358
310
  function report(settings: Settings, event: GenerationEvent): void {
359
- if (!settings.options.onEvent) return;
360
311
  try {
361
- settings.options.onEvent(event);
312
+ settings.onEvent?.(event);
362
313
  } catch {}
363
314
  }
@@ -40,6 +40,8 @@ const gridBlockSchema = z.object({
40
40
  items: z.array(productReferenceSchema),
41
41
  });
42
42
 
43
+ export const GRID_COLUMNS = gridBlockSchema.shape.columns.options.map((option) => option.value);
44
+
43
45
  export function columnsFor(count: number, widest: 2 | 3 | 4): 2 | 3 | 4 {
44
46
  return Math.min(widest, Math.max(2, count)) as 2 | 3 | 4;
45
47
  }
@@ -114,17 +116,6 @@ export type DegradedReason = (typeof DEGRADED_REASONS)[number];
114
116
 
115
117
  export const SPEC_VERSION = '1' as const;
116
118
 
117
- export interface ComponentSpec extends GeneratedSpec {
118
- specVersion: typeof SPEC_VERSION;
119
- slot: string;
120
- source: SpecSource;
121
- generatedAt: number;
122
- latencyMs: number;
123
- provider: string | null;
124
- model: string | null;
125
- degradedReason?: DegradedReason;
126
- }
127
-
128
119
  const componentSpecSchema = generatedSpecSchema.extend({
129
120
  specVersion: z.literal(SPEC_VERSION),
130
121
  slot: z.string(),
@@ -133,16 +124,12 @@ const componentSpecSchema = generatedSpecSchema.extend({
133
124
  latencyMs: z.number(),
134
125
  provider: z.string().nullable(),
135
126
  model: z.string().nullable(),
136
- degradedReason: z.enum(DEGRADED_REASONS).optional(),
127
+ degradedReason: z.enum(DEGRADED_REASONS).exactOptional(),
137
128
  });
129
+ export type ComponentSpec = z.infer<typeof componentSpecSchema>;
138
130
 
139
131
  export function parseComponentSpec(value: unknown): ComponentSpec {
140
- const { degradedReason, ...spec } = componentSpecSchema.parse(value);
141
- return degradedReason === undefined ? spec : { ...spec, degradedReason };
142
- }
143
-
144
- export function parseGeneratedSpec(value: unknown): GeneratedSpec {
145
- return generatedSpecSchema.parse(value);
132
+ return componentSpecSchema.parse(value);
146
133
  }
147
134
 
148
135
  export function safeParseGeneratedSpec(value: unknown): GeneratedSpecResult {
@@ -43,8 +43,9 @@ export function buildFallbackSpec(
43
43
  items.length === 0
44
44
  ? []
45
45
  : [{ kind: 'grid', title: null, columns: columnsFor(items.length, 4), items }],
46
- rationale: digest.isColdStart
47
- ? 'Deterministic: no behavioural signals, ranked by rating and stock.'
48
- : 'Deterministic: ranked by category affinity, revisit, rating and tag overlap.',
46
+ rationale:
47
+ options.rank === 'given'
48
+ ? 'Deterministic: kept in the order the candidates were sent.'
49
+ : 'Deterministic: ranked by category interest (the browsed category counts too), views, rating and shared tags.',
49
50
  };
50
51
  }
@@ -1,5 +1,8 @@
1
1
  import type { Block, GeneratedSpec, ProductReference } from './component-spec.js';
2
- import type { ProductPick } from './product-selection.js';
2
+ import { selectProducts, type ProductPick, type RankOrder } from './product-selection.js';
3
+ import { heroAndSetSkus } from './reconciliation.js';
4
+ import type { SignalDigest } from './signal-digest.js';
5
+ import type { TrackingInput } from './tracking-input.js';
3
6
 
4
7
  export interface FittedSpec {
5
8
  spec: GeneratedSpec;
@@ -41,3 +44,15 @@ export function fitToShopper(
41
44
 
42
45
  return { spec: { ...spec, blocks }, ourReasons };
43
46
  }
47
+
48
+ export function fitCohortSpec(
49
+ spec: GeneratedSpec,
50
+ input: TrackingInput,
51
+ digest: SignalDigest,
52
+ rank: RankOrder,
53
+ ): FittedSpec {
54
+ const spokenFor = heroAndSetSkus(spec.blocks, input, digest);
55
+ const picks = selectProducts(input, digest, { rank });
56
+ const forGrid = picks.filter((pick) => !spokenFor.has(pick.product.sku));
57
+ return fitToShopper(spec, forGrid, digest.maxItems - spokenFor.size);
58
+ }
package/src/index.ts CHANGED
@@ -43,7 +43,6 @@ export {
43
43
  blockSchema,
44
44
  generatedSpecSchema,
45
45
  parseComponentSpec,
46
- parseGeneratedSpec,
47
46
  productReferenceSchema,
48
47
  safeParseGeneratedSpec,
49
48
  type BannerBlock,
@@ -64,7 +63,7 @@ export {
64
63
  } from './component-spec.js';
65
64
 
66
65
  export { reconcileSpec, type ReconcileResult } from './reconciliation.js';
67
- export { selectProducts, type ProductPick } from './product-selection.js';
66
+ export { selectProducts, type ProductPick, type RankOrder } from './product-selection.js';
68
67
 
69
68
  export {
70
69
  createFixedSpecProvider,
@@ -1,4 +1,10 @@
1
- import { BANNER_TONES, EMPHASIS, RECOMMENDATION_BASES, TONES } from './component-spec.js';
1
+ import {
2
+ BANNER_TONES,
3
+ EMPHASIS,
4
+ GRID_COLUMNS,
5
+ RECOMMENDATION_BASES,
6
+ TONES,
7
+ } from './component-spec.js';
2
8
  import type { SignalDigest } from './signal-digest.js';
3
9
  import { FIELD_LIMITS, type Product, type TrackingInput } from './tracking-input.js';
4
10
 
@@ -12,6 +18,21 @@ export interface PromptPair {
12
18
 
13
19
  const quotedList = (values: readonly string[]) => values.map((value) => `"${value}"`).join(', ');
14
20
 
21
+ const NUMBER_WORDS = [
22
+ 'zero',
23
+ 'one',
24
+ 'two',
25
+ 'three',
26
+ 'four',
27
+ 'five',
28
+ 'six',
29
+ 'seven',
30
+ 'eight',
31
+ 'nine',
32
+ ];
33
+
34
+ const inWords = (count: number) => NUMBER_WORDS[count] ?? String(count);
35
+
15
36
  export const SYSTEM_PROMPT = `You design one recommendation component for one shopper on an
16
37
  e-commerce page. You return JSON matching the schema you were given, and nothing else.
17
38
 
@@ -46,7 +67,7 @@ Blocks never nest.
46
67
 
47
68
  - "hero" — one large statement, optionally anchored to a single product. Use
48
69
  when one product clearly dominates what the shopper seems to want.
49
- - "grid" — a titled grid of 2, 3 or 4 columns. The general choice when several
70
+ - "grid" — a titled grid of ${GRID_COLUMNS.slice(0, -1).join(', ')} or ${GRID_COLUMNS.at(-1)} columns. The general choice when several
50
71
  products are comparably relevant.
51
72
  - "carousel" — a row read left to right. Use when the order means something.
52
73
  - "banner" — a single line of merchandising copy, with a tone of ${quotedList(BANNER_TONES)}.
@@ -59,7 +80,7 @@ Blocks never nest.
59
80
  products: you are never shown which set the shop will pick, so words about
60
81
  the things in it end up beside a different set. Never say a set saves money,
61
82
  and never say by how much — you are not told any of the prices. Every product
62
- in a set spends one of your product slots, and a set holds two to five of
83
+ in a set spends one of your product slots, and a set holds two to ${inWords(FIELD_LIMITS.productsPerBundle)} of
63
84
  them.
64
85
 
65
86
  Each product you place carries an "emphasis" of ${quotedList(EMPHASIS)}.
@@ -0,0 +1,43 @@
1
+ import type { Bundle, Product } from './tracking-input.js';
2
+
3
+ export function defaultHrefForSku(sku: string): string {
4
+ return `/product/${encodeURIComponent(sku)}`;
5
+ }
6
+
7
+ export function findSellableProduct(
8
+ products: ReadonlyMap<string, Product>,
9
+ sku: string,
10
+ ): Product | undefined {
11
+ const product = products.get(sku);
12
+ return product?.isInStock === false ? undefined : product;
13
+ }
14
+
15
+ function formatMoney(price: number, currency: string, locale?: string): string {
16
+ let formatter: Intl.NumberFormat;
17
+ try {
18
+ formatter = new Intl.NumberFormat(locale, { style: 'currency', currency });
19
+ } catch {
20
+ return `${currency} ${price}`;
21
+ }
22
+ return formatter.format(price);
23
+ }
24
+
25
+ export function defaultFormatPrice(product: Product, locale?: string): string {
26
+ if (!Number.isFinite(product.price)) {
27
+ throw new TypeError(
28
+ `price for SKU ${product.sku} is ${String(product.price)}, not a finite number. ` +
29
+ 'Catalog objects must satisfy productSchema from @rudra-js/core',
30
+ );
31
+ }
32
+ return formatMoney(product.price, product.currency, locale);
33
+ }
34
+
35
+ export function defaultFormatBundlePrice(bundle: Bundle, locale?: string): string {
36
+ if (!Number.isFinite(bundle.price)) {
37
+ throw new TypeError(
38
+ `price for bundle ${bundle.id} is ${String(bundle.price)}, not a finite number. ` +
39
+ 'Bundle objects must satisfy bundleSchema from @rudra-js/core',
40
+ );
41
+ }
42
+ return formatMoney(bundle.price, bundle.currency, locale);
43
+ }
@@ -24,10 +24,6 @@ const CLAMP = {
24
24
 
25
25
  export const MAX_BLOCKS = 4;
26
26
 
27
- export function capBlocks(blocks: Block[]): Block[] {
28
- return blocks.slice(0, MAX_BLOCKS);
29
- }
30
-
31
27
  export interface ReconcileResult {
32
28
  spec: GeneratedSpec;
33
29
  isUsable: boolean;
@@ -253,27 +249,24 @@ function chooseBundle(run: Run): Bundle | undefined {
253
249
  return best;
254
250
  }
255
251
 
256
- export function bundleForShopper(
252
+ export function heroAndSetSkus(
253
+ blocks: Block[],
257
254
  input: TrackingInput,
258
255
  digest: SignalDigest,
259
- spokenFor: readonly string[],
260
- ): Bundle | undefined {
261
- const run = startRun(input, digest, new Map());
262
- for (const sku of spokenFor) place(run, sku);
263
-
264
- return chooseBundle(run);
265
- }
266
-
267
- export function placeableHeroSkus(blocks: readonly Block[], input: TrackingInput): string[] {
268
- const allowed = inStockSkus(input);
269
- const blocked = blockedForPicks(input);
270
- const skus: string[] = [];
271
- for (const block of blocks) {
272
- if (block.kind !== 'hero' || block.sku === null) continue;
273
- if (!allowed.has(block.sku) || blocked.has(block.sku)) continue;
274
- if (!skus.includes(block.sku)) skus.push(block.sku);
256
+ ): ReadonlySet<string> {
257
+ const heroes = startRun(input, digest, new Map());
258
+ let setSkus: readonly string[] | undefined;
259
+ let listAbove = false;
260
+
261
+ for (const block of blocks.slice(0, MAX_BLOCKS)) {
262
+ if (block.kind === 'hero' && block.sku !== null) takeSlot(block.sku, heroes);
263
+ if (setSkus !== undefined) continue;
264
+ if (block.kind === 'bundle') setSkus = chooseBundle(heroes)?.skus ?? [];
265
+ if (block.kind === 'grid' || block.kind === 'carousel') listAbove ||= block.items.length > 0;
275
266
  }
276
- return skus;
267
+
268
+ const withSet = new Set([...heroes.placed, ...(setSkus ?? [])]);
269
+ return listAbove && withSet.size >= digest.maxItems ? heroes.placed : withSet;
277
270
  }
278
271
 
279
272
  function reconcileBlock(block: Block, run: Run): Block | null {
@@ -390,7 +383,7 @@ export function reconcileSpec(
390
383
  }
391
384
 
392
385
  const blocks: Block[] = [];
393
- for (const block of capBlocks(generated.blocks)) {
386
+ for (const block of generated.blocks.slice(0, MAX_BLOCKS)) {
394
387
  const reconciled = reconcileBlock(block, run);
395
388
  if (reconciled !== null) blocks.push(reconciled);
396
389
  }
package/src/schemas.ts CHANGED
@@ -5,3 +5,9 @@ export {
5
5
  renderContextSchema,
6
6
  } from './tracking-input.js';
7
7
  export { parseComponentSpec } from './component-spec.js';
8
+ export {
9
+ defaultFormatBundlePrice,
10
+ defaultFormatPrice,
11
+ defaultHrefForSku,
12
+ findSellableProduct,
13
+ } from './product-display.js';
@@ -150,14 +150,8 @@ function mergeViewsBySku(views: ViewSignal[]): MergedView[] {
150
150
  const totals = new Map<string, MergedView>();
151
151
 
152
152
  for (const view of views) {
153
- const total = totals.get(view.sku);
154
- if (!total) {
155
- const first: MergedView = { sku: view.sku, views: view.views, weight: weightOf(view) };
156
- if (view.dwellMs !== undefined) first.dwellMs = view.dwellMs;
157
- if (view.category !== undefined) first.category = view.category;
158
- totals.set(view.sku, first);
159
- continue;
160
- }
153
+ const total = totals.get(view.sku) ?? { sku: view.sku, views: 0, weight: -Infinity };
154
+ totals.set(view.sku, total);
161
155
 
162
156
  total.views += view.views;
163
157
  if (view.dwellMs !== undefined) total.dwellMs = (total.dwellMs ?? 0) + view.dwellMs;