@rudra-js/core 0.1.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/LICENSE +21 -0
- package/README.md +189 -0
- package/dist/component-generator.d.ts +84 -0
- package/dist/component-generator.d.ts.map +1 -0
- package/dist/component-generator.js +331 -0
- package/dist/component-generator.js.map +1 -0
- package/dist/component-spec.d.ts +426 -0
- package/dist/component-spec.d.ts.map +1 -0
- package/dist/component-spec.js +170 -0
- package/dist/component-spec.js.map +1 -0
- package/dist/fallback-component.d.ts +11 -0
- package/dist/fallback-component.d.ts.map +1 -0
- package/dist/fallback-component.js +69 -0
- package/dist/fallback-component.js.map +1 -0
- package/dist/fit-to-shopper.d.ts +4 -0
- package/dist/fit-to-shopper.d.ts.map +1 -0
- package/dist/fit-to-shopper.js +36 -0
- package/dist/fit-to-shopper.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/model-prompt.d.ts +29 -0
- package/dist/model-prompt.d.ts.map +1 -0
- package/dist/model-prompt.js +227 -0
- package/dist/model-prompt.js.map +1 -0
- package/dist/product-selection.d.ts +33 -0
- package/dist/product-selection.d.ts.map +1 -0
- package/dist/product-selection.js +102 -0
- package/dist/product-selection.js.map +1 -0
- package/dist/provider.d.ts +80 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +23 -0
- package/dist/provider.js.map +1 -0
- package/dist/reconciliation.d.ts +49 -0
- package/dist/reconciliation.d.ts.map +1 -0
- package/dist/reconciliation.js +564 -0
- package/dist/reconciliation.js.map +1 -0
- package/dist/signal-digest.d.ts +66 -0
- package/dist/signal-digest.d.ts.map +1 -0
- package/dist/signal-digest.js +224 -0
- package/dist/signal-digest.js.map +1 -0
- package/dist/spec-cache.d.ts +88 -0
- package/dist/spec-cache.d.ts.map +1 -0
- package/dist/spec-cache.js +152 -0
- package/dist/spec-cache.js.map +1 -0
- package/dist/tracking-input.d.ts +258 -0
- package/dist/tracking-input.d.ts.map +1 -0
- package/dist/tracking-input.js +241 -0
- package/dist/tracking-input.js.map +1 -0
- package/package.json +60 -0
- package/src/component-generator.ts +521 -0
- package/src/component-spec.ts +243 -0
- package/src/fallback-component.ts +77 -0
- package/src/fit-to-shopper.ts +45 -0
- package/src/index.ts +102 -0
- package/src/model-prompt.ts +258 -0
- package/src/product-selection.ts +153 -0
- package/src/provider.ts +98 -0
- package/src/reconciliation.ts +675 -0
- package/src/signal-digest.ts +335 -0
- package/src/spec-cache.ts +223 -0
- package/src/tracking-input.ts +300 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The component specification — the only thing a language model is ever allowed
|
|
5
|
+
* to return.
|
|
6
|
+
*
|
|
7
|
+
* The model chooses layout, ordering, emphasis, copy, the recommendation
|
|
8
|
+
* strategy behind each pick, and which of the host's candidate products to
|
|
9
|
+
* surface. It never returns markup, code, URLs, prices,
|
|
10
|
+
* product titles, or images. Every field is an enum, a bounded number, a SKU
|
|
11
|
+
* reference resolved against the candidate set, or free text that is clamped
|
|
12
|
+
* and escaped before it renders. That is what makes generated output safe to
|
|
13
|
+
* put in a server-rendered response.
|
|
14
|
+
*
|
|
15
|
+
* Two constraints shape this file, and both are easy to undo by accident:
|
|
16
|
+
*
|
|
17
|
+
* 1. It doubles as a provider structured-output schema, so it avoids
|
|
18
|
+
* recursion, string length bounds, and numeric ranges. Providers reject
|
|
19
|
+
* schemas that use them in strict mode. Bounds are enforced afterwards, in
|
|
20
|
+
* reconciliation, where a violation can be repaired rather than fatal.
|
|
21
|
+
* 2. Optionality is `.nullable()` rather than `.optional()`, because strict
|
|
22
|
+
* structured outputs require every declared property to be present. "No
|
|
23
|
+
* badge" has to be expressible as `null`, not as a missing key.
|
|
24
|
+
*
|
|
25
|
+
* A test asserts both by converting this schema to JSON Schema, so neither is
|
|
26
|
+
* left to a comment nobody reads.
|
|
27
|
+
*
|
|
28
|
+
* Note the asymmetry with `tracking-input`, which rejects unknown fields: these
|
|
29
|
+
* schemas strip them. The inputs differ in kind. An unrecognised key in a host
|
|
30
|
+
* payload is a typo, and silently dropping it costs the shopper their history,
|
|
31
|
+
* so it must be loud. An unrecognised key from a model is drift, and discarding
|
|
32
|
+
* it is exactly right — rejecting the whole spec over one stray key would cost
|
|
33
|
+
* the shopper the component. Either way the renderer only ever sees the fields
|
|
34
|
+
* declared here, which is the property that matters.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
/** Overall voice of the component. */
|
|
38
|
+
export const TONES = ['neutral', 'enthusiastic', 'urgent', 'editorial'] as const;
|
|
39
|
+
|
|
40
|
+
/** What a banner is claiming. */
|
|
41
|
+
export const BANNER_TONES = ['info', 'promo', 'urgency', 'restock'] as const;
|
|
42
|
+
|
|
43
|
+
/** How prominently a single product is placed. */
|
|
44
|
+
export const EMPHASIS = ['normal', 'featured'] as const;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Why a product was chosen — the recommendation strategy behind the pick.
|
|
48
|
+
*
|
|
49
|
+
* This is a closed set rather than free text because every value here is a
|
|
50
|
+
* factual claim about the shopper, and a claim the server can check. "Because
|
|
51
|
+
* you viewed this" written as prose is unverifiable: nothing downstream can
|
|
52
|
+
* tell whether the shopper viewed anything. Declared as `most_viewed`,
|
|
53
|
+
* reconciliation can look it up in the digest and drop the claim if it is
|
|
54
|
+
* false.
|
|
55
|
+
*
|
|
56
|
+
* Every value is deliberately checkable against data already in hand — the
|
|
57
|
+
* signal digest or the host's own catalog. A basis that needs data the
|
|
58
|
+
* framework never receives (`new_arrival`, `back_in_stock`, `trending_today`)
|
|
59
|
+
* is not in this list, because it could only ever be taken on trust.
|
|
60
|
+
*/
|
|
61
|
+
export const RECOMMENDATION_BASES = [
|
|
62
|
+
/** Same category as the product being viewed. */
|
|
63
|
+
'similar_to_current',
|
|
64
|
+
/** The shopper has viewed this product. */
|
|
65
|
+
'most_viewed',
|
|
66
|
+
/** Goes with something already in the cart. */
|
|
67
|
+
'complements_cart',
|
|
68
|
+
/** Goes with something the shopper has bought. */
|
|
69
|
+
'complements_purchase',
|
|
70
|
+
/** In a category the shopper's signals favour. */
|
|
71
|
+
'liked_category',
|
|
72
|
+
/** No claim about this shopper at all — the safe default. */
|
|
73
|
+
'popular',
|
|
74
|
+
] as const;
|
|
75
|
+
|
|
76
|
+
/** A reference to one product from the candidate set, and why it was chosen. */
|
|
77
|
+
export const productReferenceSchema = z.object({
|
|
78
|
+
/** Must be a SKU the host supplied in `TrackingInput.candidates`. */
|
|
79
|
+
sku: z.string(),
|
|
80
|
+
/**
|
|
81
|
+
* The strategy behind this pick. Reconciliation checks it against the
|
|
82
|
+
* shopper's signals, so the model cannot assert a relationship that is not
|
|
83
|
+
* there.
|
|
84
|
+
*/
|
|
85
|
+
basis: z.enum(RECOMMENDATION_BASES),
|
|
86
|
+
/**
|
|
87
|
+
* How the basis is phrased for the shopper, e.g. "Pairs with the boots you
|
|
88
|
+
* bought". Free text, but it has to be consistent with `basis`, which is not.
|
|
89
|
+
*
|
|
90
|
+
* Nullable because reconciliation clears it when it cannot verify the basis:
|
|
91
|
+
* a pick may still be worth showing when the stated reason for it is not
|
|
92
|
+
* true, but the prose asserting that reason must not render.
|
|
93
|
+
*/
|
|
94
|
+
reason: z.string().nullable(),
|
|
95
|
+
/** Short accent label, e.g. "Back in stock". Null when nothing warrants one. */
|
|
96
|
+
badge: z.string().nullable(),
|
|
97
|
+
emphasis: z.enum(EMPHASIS),
|
|
98
|
+
});
|
|
99
|
+
export type ProductReference = z.infer<typeof productReferenceSchema>;
|
|
100
|
+
export type RecommendationBasis = (typeof RECOMMENDATION_BASES)[number];
|
|
101
|
+
|
|
102
|
+
/** One large featured statement, optionally anchored to a single product. */
|
|
103
|
+
const heroBlockSchema = z.object({
|
|
104
|
+
kind: z.literal('hero'),
|
|
105
|
+
headline: z.string(),
|
|
106
|
+
body: z.string().nullable(),
|
|
107
|
+
sku: z.string().nullable(),
|
|
108
|
+
ctaLabel: z.string().nullable(),
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
/** The general-purpose choice when several products are comparably relevant. */
|
|
112
|
+
const gridBlockSchema = z.object({
|
|
113
|
+
kind: z.literal('grid'),
|
|
114
|
+
title: z.string().nullable(),
|
|
115
|
+
columns: z.union([z.literal(2), z.literal(3), z.literal(4)]),
|
|
116
|
+
items: z.array(productReferenceSchema),
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
/** A horizontally scanned row, for when order implies a ranking. */
|
|
120
|
+
const carouselBlockSchema = z.object({
|
|
121
|
+
kind: z.literal('carousel'),
|
|
122
|
+
title: z.string().nullable(),
|
|
123
|
+
items: z.array(productReferenceSchema),
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/** A single line of merchandising copy. */
|
|
127
|
+
const bannerBlockSchema = z.object({
|
|
128
|
+
kind: z.literal('banner'),
|
|
129
|
+
tone: z.enum(BANNER_TONES),
|
|
130
|
+
text: z.string(),
|
|
131
|
+
ctaLabel: z.string().nullable(),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
/** Short editorial prose, for explaining the theme of a selection. */
|
|
135
|
+
const copyBlockSchema = z.object({
|
|
136
|
+
kind: z.literal('copy'),
|
|
137
|
+
title: z.string().nullable(),
|
|
138
|
+
body: z.string(),
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
/** A set the shop sells together. The shop picks which one; this only asks for it. */
|
|
142
|
+
const bundleBlockSchema = z.object({
|
|
143
|
+
kind: z.literal('bundle'),
|
|
144
|
+
title: z.string().nullable(),
|
|
145
|
+
body: z.string().nullable(),
|
|
146
|
+
ctaLabel: z.string().nullable(),
|
|
147
|
+
// Filled in per request. Whatever the model puts here is thrown away.
|
|
148
|
+
bundleId: z.string().nullable(),
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
/** Blocks do not nest. The vocabulary is closed on purpose. */
|
|
152
|
+
export const blockSchema = z.discriminatedUnion('kind', [
|
|
153
|
+
heroBlockSchema,
|
|
154
|
+
gridBlockSchema,
|
|
155
|
+
carouselBlockSchema,
|
|
156
|
+
bannerBlockSchema,
|
|
157
|
+
copyBlockSchema,
|
|
158
|
+
bundleBlockSchema,
|
|
159
|
+
]);
|
|
160
|
+
export type Block = z.infer<typeof blockSchema>;
|
|
161
|
+
export type BlockKind = Block['kind'];
|
|
162
|
+
|
|
163
|
+
export type HeroBlock = z.infer<typeof heroBlockSchema>;
|
|
164
|
+
export type GridBlock = z.infer<typeof gridBlockSchema>;
|
|
165
|
+
export type CarouselBlock = z.infer<typeof carouselBlockSchema>;
|
|
166
|
+
export type BannerBlock = z.infer<typeof bannerBlockSchema>;
|
|
167
|
+
export type CopyBlock = z.infer<typeof copyBlockSchema>;
|
|
168
|
+
export type BundleBlock = z.infer<typeof bundleBlockSchema>;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Exactly what the model must return. Provenance — version, slot, latency, which
|
|
172
|
+
* provider answered — is added by the server afterwards, and is deliberately not
|
|
173
|
+
* part of the model's burden.
|
|
174
|
+
*/
|
|
175
|
+
export const generatedSpecSchema = z.object({
|
|
176
|
+
tone: z.enum(TONES),
|
|
177
|
+
headline: z.string(),
|
|
178
|
+
subheadline: z.string().nullable(),
|
|
179
|
+
blocks: z.array(blockSchema),
|
|
180
|
+
/**
|
|
181
|
+
* One sentence on why this arrangement was chosen. For engineers reading
|
|
182
|
+
* generation logs, not for shoppers; it is not rendered by default.
|
|
183
|
+
*/
|
|
184
|
+
rationale: z.string(),
|
|
185
|
+
});
|
|
186
|
+
export type GeneratedSpec = z.infer<typeof generatedSpecSchema>;
|
|
187
|
+
|
|
188
|
+
/** How a spec came to exist. Surfaced for benchmarking and observability. */
|
|
189
|
+
export type SpecSource = 'llm' | 'cache' | 'fallback';
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Why a component is not what the model would have produced.
|
|
193
|
+
*
|
|
194
|
+
* A closed set, like `SpecSource`: it is rendered into pages as
|
|
195
|
+
* `data-rudra-degraded` and counted in dashboards, so a host needs to know what
|
|
196
|
+
* it can receive without reading the generator.
|
|
197
|
+
*/
|
|
198
|
+
export type DegradedReason =
|
|
199
|
+
/** No provider was configured, so nothing was ever asked. */
|
|
200
|
+
| 'no-provider'
|
|
201
|
+
/** The provider errored, or threw before it reached the vendor. */
|
|
202
|
+
| 'provider-error'
|
|
203
|
+
/** The deadline fired before an answer arrived. */
|
|
204
|
+
| 'timeout'
|
|
205
|
+
/** An answer came back that did not satisfy the schema. */
|
|
206
|
+
| 'invalid-generation'
|
|
207
|
+
/** A usable answer reconciled down to nothing for this shopper. */
|
|
208
|
+
| 'unusable-on-serve'
|
|
209
|
+
/** The caller asked for the deterministic component on purpose. */
|
|
210
|
+
| 'requested';
|
|
211
|
+
|
|
212
|
+
export const SPEC_VERSION = '1' as const;
|
|
213
|
+
|
|
214
|
+
/** A generated spec plus the provenance the server owns. This is what renders. */
|
|
215
|
+
export interface ComponentSpec extends GeneratedSpec {
|
|
216
|
+
specVersion: typeof SPEC_VERSION;
|
|
217
|
+
slot: string;
|
|
218
|
+
source: SpecSource;
|
|
219
|
+
/** Epoch milliseconds at which the underlying generation completed. */
|
|
220
|
+
generatedAt: number;
|
|
221
|
+
/** Wall-clock milliseconds spent producing it, including any cache lookup. */
|
|
222
|
+
latencyMs: number;
|
|
223
|
+
/** Provider name, or null when no model was involved. */
|
|
224
|
+
provider: string | null;
|
|
225
|
+
/** Model identifier, or null when no model was involved. */
|
|
226
|
+
model: string | null;
|
|
227
|
+
/**
|
|
228
|
+
* Why the deterministic component is showing instead of a generated one.
|
|
229
|
+
* Present on every fallback, including the ones where no model was involved
|
|
230
|
+
* at all — no provider configured, or the caller asked for it directly.
|
|
231
|
+
*/
|
|
232
|
+
degradedReason?: DegradedReason;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Throws a `ZodError` if the value is not a well-formed generated spec. */
|
|
236
|
+
export function parseGeneratedSpec(value: unknown): GeneratedSpec {
|
|
237
|
+
return generatedSpecSchema.parse(value);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** Non-throwing variant, for validating untrusted model output. */
|
|
241
|
+
export function safeParseGeneratedSpec(value: unknown) {
|
|
242
|
+
return generatedSpecSchema.safeParse(value);
|
|
243
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import type { GeneratedSpec, ProductReference } from './component-spec.js';
|
|
2
|
+
import type { SignalDigest } from './signal-digest.js';
|
|
3
|
+
import { selectProducts, type ProductPick } from './product-selection.js';
|
|
4
|
+
import type { TrackingInput } from './tracking-input.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The deterministic component — what renders when no model does.
|
|
8
|
+
*
|
|
9
|
+
* The manuscript names data latency as the central risk of moving
|
|
10
|
+
* personalisation onto the server path: any delay in the recommendation engine
|
|
11
|
+
* blocks the page. This module is the answer. It is pure, synchronous, and
|
|
12
|
+
* cannot fail, so the server always has something correct to render — whether
|
|
13
|
+
* the model is slow, erroring, rate-limited, or simply not configured.
|
|
14
|
+
*
|
|
15
|
+
* It reads the same digest and uses the same selector the model path does, so a
|
|
16
|
+
* degraded render is a weaker version of the same decision rather than an
|
|
17
|
+
* unrelated one. Only the presentation is fixed.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** A featured lead only reads as deliberate when something follows it. */
|
|
21
|
+
const MIN_PICKS_FOR_A_FEATURED_LEAD = 3;
|
|
22
|
+
|
|
23
|
+
function headlineFor(digest: SignalDigest): { headline: string; subheadline: string | null } {
|
|
24
|
+
if (digest.isColdStart) {
|
|
25
|
+
return { headline: 'Popular right now', subheadline: null };
|
|
26
|
+
}
|
|
27
|
+
if (digest.cartSkus.length > 0) {
|
|
28
|
+
return { headline: 'Goes with your cart', subheadline: null };
|
|
29
|
+
}
|
|
30
|
+
const topCategory = digest.categoryAffinity[0]?.category;
|
|
31
|
+
if (topCategory) {
|
|
32
|
+
return { headline: 'Picked for you', subheadline: `More from ${topCategory}` };
|
|
33
|
+
}
|
|
34
|
+
return { headline: 'You might also like', subheadline: null };
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Wide enough to fill, never wider. */
|
|
38
|
+
function columnsFor(itemCount: number): 2 | 3 | 4 {
|
|
39
|
+
if (itemCount >= 4) return 4;
|
|
40
|
+
if (itemCount === 3) return 3;
|
|
41
|
+
return 2;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function toProductReference(pick: ProductPick, index: number, total: number): ProductReference {
|
|
45
|
+
return {
|
|
46
|
+
sku: pick.product.sku,
|
|
47
|
+
basis: pick.basis,
|
|
48
|
+
reason: pick.reason,
|
|
49
|
+
badge: null,
|
|
50
|
+
emphasis: index === 0 && total >= MIN_PICKS_FOR_A_FEATURED_LEAD ? 'featured' : 'normal',
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Builds a renderable spec from signals alone. Never throws. Returns a spec with
|
|
56
|
+
* no blocks only when there is genuinely nothing in stock left to show, which
|
|
57
|
+
* the renderer treats as "render nothing" — an empty recommendation region is
|
|
58
|
+
* worse than none.
|
|
59
|
+
*/
|
|
60
|
+
export function buildFallbackSpec(input: TrackingInput, digest: SignalDigest): GeneratedSpec {
|
|
61
|
+
const picks = selectProducts(input, digest).slice(0, digest.maxItems);
|
|
62
|
+
const { headline, subheadline } = headlineFor(digest);
|
|
63
|
+
const items = picks.map((pick, index) => toProductReference(pick, index, picks.length));
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
tone: 'neutral',
|
|
67
|
+
headline,
|
|
68
|
+
subheadline,
|
|
69
|
+
blocks:
|
|
70
|
+
items.length === 0
|
|
71
|
+
? []
|
|
72
|
+
: [{ kind: 'grid', title: null, columns: columnsFor(items.length), items }],
|
|
73
|
+
rationale: digest.isColdStart
|
|
74
|
+
? 'Deterministic: no behavioural signals, ranked by rating and stock.'
|
|
75
|
+
: 'Deterministic: ranked by category affinity, revisit, rating and tag overlap.',
|
|
76
|
+
};
|
|
77
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Block, GeneratedSpec, ProductReference } from './component-spec.js';
|
|
2
|
+
import type { ProductPick } from './product-selection.js';
|
|
3
|
+
|
|
4
|
+
// The model picks the shape of the component. Selection picks the products and
|
|
5
|
+
// what may be said about them, so a shared component still fits one shopper.
|
|
6
|
+
export function fitToShopper(
|
|
7
|
+
spec: GeneratedSpec,
|
|
8
|
+
picks: readonly ProductPick[],
|
|
9
|
+
maxItems: number,
|
|
10
|
+
): GeneratedSpec {
|
|
11
|
+
// Picks are ordered best first. Every slot takes the next one.
|
|
12
|
+
let next = 0;
|
|
13
|
+
const limit = Math.min(picks.length, maxItems);
|
|
14
|
+
|
|
15
|
+
const blocks: Block[] = [];
|
|
16
|
+
for (const block of spec.blocks) {
|
|
17
|
+
// A hero is left alone. Its headline and body were written about the
|
|
18
|
+
// product it names, so swapping the product would leave copy that describes
|
|
19
|
+
// something else. Reconciliation drops the link if this shopper cannot see
|
|
20
|
+
// that product, and the words stay.
|
|
21
|
+
|
|
22
|
+
if (block.kind === 'grid' || block.kind === 'carousel') {
|
|
23
|
+
const items: ProductReference[] = [];
|
|
24
|
+
for (const item of block.items) {
|
|
25
|
+
if (next >= limit) break; // shrink, never pad
|
|
26
|
+
const chosen = picks[next]!;
|
|
27
|
+
items.push({
|
|
28
|
+
sku: chosen.product.sku,
|
|
29
|
+
basis: chosen.basis,
|
|
30
|
+
reason: chosen.reason,
|
|
31
|
+
// The badge was written about a different product.
|
|
32
|
+
badge: null,
|
|
33
|
+
emphasis: item.emphasis,
|
|
34
|
+
});
|
|
35
|
+
next += 1;
|
|
36
|
+
}
|
|
37
|
+
blocks.push({ ...block, items });
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
blocks.push(block);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return { ...spec, blocks };
|
|
45
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @rudra-js/core — the contracts and logic that turn one tracking payload into one
|
|
3
|
+
* renderable component specification.
|
|
4
|
+
*
|
|
5
|
+
* Carries no React and no model-vendor SDK, so it can be unit tested in
|
|
6
|
+
* isolation and imported from any server runtime.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
FIELD_LIMITS,
|
|
11
|
+
productSchema,
|
|
12
|
+
skuSignalSchema,
|
|
13
|
+
viewSignalSchema,
|
|
14
|
+
purchaseSignalSchema,
|
|
15
|
+
interactionSchema,
|
|
16
|
+
renderContextSchema,
|
|
17
|
+
trackingSignalsSchema,
|
|
18
|
+
bundleSchema,
|
|
19
|
+
trackingInputSchema,
|
|
20
|
+
parseTrackingInput,
|
|
21
|
+
safeParseTrackingInput,
|
|
22
|
+
type Product,
|
|
23
|
+
type SkuSignal,
|
|
24
|
+
type ViewSignal,
|
|
25
|
+
type PurchaseSignal,
|
|
26
|
+
type Interaction,
|
|
27
|
+
type RenderContext,
|
|
28
|
+
type TrackingSignals,
|
|
29
|
+
type Bundle,
|
|
30
|
+
type TrackingInput,
|
|
31
|
+
type TrackingInputDraft,
|
|
32
|
+
type TrackingInputResult,
|
|
33
|
+
} from './tracking-input.js';
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
DIGEST_LIMITS,
|
|
37
|
+
buildDigest,
|
|
38
|
+
toCohortDigest,
|
|
39
|
+
type CategoryAffinity,
|
|
40
|
+
type InteractionCount,
|
|
41
|
+
type SignalDigest,
|
|
42
|
+
type ViewedProduct,
|
|
43
|
+
} from './signal-digest.js';
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
BANNER_TONES,
|
|
47
|
+
EMPHASIS,
|
|
48
|
+
RECOMMENDATION_BASES,
|
|
49
|
+
SPEC_VERSION,
|
|
50
|
+
TONES,
|
|
51
|
+
blockSchema,
|
|
52
|
+
generatedSpecSchema,
|
|
53
|
+
parseGeneratedSpec,
|
|
54
|
+
productReferenceSchema,
|
|
55
|
+
safeParseGeneratedSpec,
|
|
56
|
+
type BannerBlock,
|
|
57
|
+
type Block,
|
|
58
|
+
type BlockKind,
|
|
59
|
+
type BundleBlock,
|
|
60
|
+
type CarouselBlock,
|
|
61
|
+
type ComponentSpec,
|
|
62
|
+
type CopyBlock,
|
|
63
|
+
type GeneratedSpec,
|
|
64
|
+
type GridBlock,
|
|
65
|
+
type HeroBlock,
|
|
66
|
+
type ProductReference,
|
|
67
|
+
type RecommendationBasis,
|
|
68
|
+
type DegradedReason,
|
|
69
|
+
type SpecSource,
|
|
70
|
+
} from './component-spec.js';
|
|
71
|
+
|
|
72
|
+
export { neverRecommend, reconcileSpec, type ReconcileResult } from './reconciliation.js';
|
|
73
|
+
export { selectProducts, type ProductPick } from './product-selection.js';
|
|
74
|
+
export { fitToShopper } from './fit-to-shopper.js';
|
|
75
|
+
export { buildFallbackSpec } from './fallback-component.js';
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
createFixedSpecProvider,
|
|
79
|
+
type ComponentProvider,
|
|
80
|
+
type ProviderRequest,
|
|
81
|
+
type ProviderResult,
|
|
82
|
+
type TokenUsage,
|
|
83
|
+
} from './provider.js';
|
|
84
|
+
|
|
85
|
+
export {
|
|
86
|
+
createMemorySpecCache,
|
|
87
|
+
createNullSpecCache,
|
|
88
|
+
cohortCacheKey,
|
|
89
|
+
specCacheKey,
|
|
90
|
+
type CachedSpec,
|
|
91
|
+
type MemorySpecCacheOptions,
|
|
92
|
+
type SpecCache,
|
|
93
|
+
} from './spec-cache.js';
|
|
94
|
+
|
|
95
|
+
export { SYSTEM_PROMPT, buildPrompt, type PromptPair } from './model-prompt.js';
|
|
96
|
+
|
|
97
|
+
export {
|
|
98
|
+
createComponentGenerator,
|
|
99
|
+
type ComponentGenerator,
|
|
100
|
+
type ComponentGeneratorOptions,
|
|
101
|
+
type GenerationEvent,
|
|
102
|
+
} from './component-generator.js';
|