createFixedSpecProvider
import { createFixedSpecProvider } from '@rudra-js/core';Call createFixedSpecProvider to get a provider that answers every request with one spec you wrote yourself. No model is called.
createFixedSpecProvider(spec: GeneratedSpec) => ComponentProviderReference
createFixedSpecProvider(spec)
Parameters
spec: The spec to answer with, in the shape a model answers in. Type it asGeneratedSpecso your editor checks every field.tone: The voice of the copy:'neutral','enthusiastic','urgent'or'editorial'.headline: The heading over the whole block.subheadline: A line under the headline, ornull.blocks: The blocks inside it, in order, each with akind. Core shows the first four. The fields of each kind are under Fields.rationale: A note on why the spec looks the way it does. It only shows on the page whenRudraComponenthashasDiagnosticson.
Returns
A ComponentProvider to pass to createComponentGenerator as provider. It bills nothing.
Caveats
- Your spec goes through core's checks like a model's answer. It needs a headline that passes them and at least one product on show. Otherwise you get the block core builds without a model.
- Core reads your words for claims the way it reads the model's. Text with a price, a rating or a delivery date in it gets dropped.
- In the default
'cohort'mode, core fills each grid and carousel with its own picks for the shopper, up to the number of items you wrote. The hero keeps the product you named. Passgeneration: 'per-shopper'to keep your products everywhere. - The spec you get back has
source: 'llm', or'cache'once it's cached, as if a model had answered. Itsprovideris'fixed', so check that to tell your spec apart.
Fields
| Name | Type | Default | Constraints |
|---|---|---|---|
kind | "hero" | ||
headline | string | ||
body | string | nullable | |
sku | string | nullable | |
ctaLabel | string | nullable |
| Name | Type | Default | Constraints |
|---|---|---|---|
kind | "grid" | ||
title | string | nullable | |
columns | 2 | 3 | 4 | ||
items | ProductReference[] | ||
items.sku | string | ||
items.basis | "similar_to_current" | "most_viewed" | "complements_cart" | "complements_purchase" | "liked_category" | "popular" | ||
items.reason | string | nullable | |
items.badge | string | nullable | |
items.emphasis | "normal" | "featured" |
| Name | Type | Default | Constraints |
|---|---|---|---|
kind | "carousel" | ||
title | string | nullable | |
items | ProductReference[] | ||
items.sku | string | ||
items.basis | "similar_to_current" | "most_viewed" | "complements_cart" | "complements_purchase" | "liked_category" | "popular" | ||
items.reason | string | nullable | |
items.badge | string | nullable | |
items.emphasis | "normal" | "featured" |
| Name | Type | Default | Constraints |
|---|---|---|---|
kind | "banner" | ||
tone | "info" | "promo" | "urgency" | "restock" | ||
text | string | ||
ctaLabel | string | nullable |
| Name | Type | Default | Constraints |
|---|---|---|---|
kind | "copy" | ||
title | string | nullable | |
body | string |
| Name | Type | Default | Constraints |
|---|---|---|---|
kind | "bundle" | ||
title | string | nullable | |
body | string | nullable | |
ctaLabel | string | nullable | |
bundleId | string | nullable |
Usage
Rendering a spec you wrote by hand
Write the spec once, at the top of a module, and pass the provider as provider.
import {
createComponentGenerator,
createFixedSpecProvider,
type GeneratedSpec,
} from '@rudra-js/core';
const rainyDayEdit: GeneratedSpec = {
tone: 'editorial',
headline: 'Ready for wet trails',
subheadline: 'Shoes and layers that shrug off the rain',
blocks: [
{
kind: 'hero',
headline: 'Our pick for muddy mornings',
body: 'A grippy outsole and a waterproof lining.',
sku: 'TR-102',
ctaLabel: 'See the shoe',
},
{
kind: 'grid',
title: 'More for the rain',
columns: 3,
items: [
{ sku: 'TR-104', basis: 'popular', reason: null, badge: null, emphasis: 'featured' },
{ sku: 'SK-201', basis: 'popular', reason: null, badge: null, emphasis: 'normal' },
{ sku: 'GT-310', basis: 'popular', reason: null, badge: null, emphasis: 'normal' },
],
},
],
rationale: 'Written by hand for the spring rain campaign',
};
export const generator = createComponentGenerator({
provider: createFixedSpecProvider(rainyDayEdit),
generation: 'per-shopper',
});generation: 'per-shopper' keeps the three products in the grid as written.
The same spec answers every page view, so name products that are in every page's candidates. Core drops one that isn't.
Troubleshooting
Your spec never shows, and degradedReason is 'unusable-on-serve'
Core's checks left your spec with no headline or no product to show, so you got the block core builds without a model. Log event.violations to see what core took out.
Check that the products you named are in the page view's candidates and in stock. Then check the headline for a claim core can't back.