rudra-js

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) => ComponentProvider

Reference

createFixedSpecProvider(spec)

Parameters

  • spec: The spec to answer with, in the shape a model answers in. Type it as GeneratedSpec so 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, or null.
    • blocks: The blocks inside it, in order, each with a kind. 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 when RudraComponent has hasDiagnostics on.

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. Pass generation: '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. Its provider is 'fixed', so check that to tell your spec apart.

Fields

NameTypeDefaultConstraints
kind"hero"
headlinestring
bodystringnullable
skustringnullable
ctaLabelstringnullable
NameTypeDefaultConstraints
kind"grid"
titlestringnullable
columns2 | 3 | 4
itemsProductReference[]
items.skustring
items.basis"similar_to_current" | "most_viewed" | "complements_cart" | "complements_purchase" | "liked_category" | "popular"
items.reasonstringnullable
items.badgestringnullable
items.emphasis"normal" | "featured"
NameTypeDefaultConstraints
kind"carousel"
titlestringnullable
itemsProductReference[]
items.skustring
items.basis"similar_to_current" | "most_viewed" | "complements_cart" | "complements_purchase" | "liked_category" | "popular"
items.reasonstringnullable
items.badgestringnullable
items.emphasis"normal" | "featured"
NameTypeDefaultConstraints
kind"banner"
tone"info" | "promo" | "urgency" | "restock"
textstring
ctaLabelstringnullable
NameTypeDefaultConstraints
kind"copy"
titlestringnullable
bodystring
NameTypeDefaultConstraints
kind"bundle"
titlestringnullable
bodystringnullable
ctaLabelstringnullable
bundleIdstringnullable

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.