rudra-js

rudraRecommendationsApi

import { rudraRecommendationsApi } from '@rudra-js/a2ui/server';

rudraRecommendationsApi lets you add the block to the catalog your agent is prompted with, next to A2UI's basic components.

rudraRecommendationsApi: { name: string; schema: z.ZodObject<{ currentSku: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{ path: z.ZodString; }, "strict", z.ZodTypeAny, { path: string; }, { path: string; }>, z.ZodType<FunctionCall, z.ZodTypeDef, FunctionCall>]>>; currentCategory: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{ path: z.ZodString; }, "strict", z.ZodTypeAny, { path: string; }, { path: string; }>, z.ZodType<FunctionCall, z.ZodTypeDef, FunctionCall>]>>; searchQuery: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{ path: z.ZodString; }, "strict", z.ZodTypeAny, { path: string; }, { path: string; }>, z.ZodType<FunctionCall, z.ZodTypeDef, FunctionCall>]>>; maxItems: z.ZodOptional<z.ZodUnion<[z.ZodNumber, z.ZodObject<{ path: z.ZodString; }, "strict", z.ZodTypeAny, { path: string; }, { path: string; }>, z.ZodType<FunctionCall, z.ZodTypeDef, FunctionCall>]>>; }, "strip", z.ZodTypeAny, { currentSku?: string | FunctionCall | { path: string; } | undefined; currentCategory?: string | FunctionCall | { path: string; } | undefined; searchQuery?: string | FunctionCall | { path: string; } | undefined; maxItems?: number | FunctionCall | { path: string; } | undefined; }, { currentSku?: string | FunctionCall | { path: string; } | undefined; currentCategory?: string | FunctionCall | { path: string; } | undefined; searchQuery?: string | FunctionCall | { path: string; } | undefined; maxItems?: number | FunctionCall | { path: string; } | undefined; }>; }

Reference

rudraRecommendationsApi

Returns

An object with name and schema. name is 'RudraRecommendations', the component the agent places. schema is a zod 3 schema of the four hints, each with a description the agent reads.

Caveats

  • A literal of the wrong type, such as a numeric SKU, makes A2UI refuse the agent's whole message.
  • Each hint can be a literal or a path into the agent's data model, such as { "path": "/viewing/sku" }.

Usage

Adding the block to the catalog your agent is prompted with

Build the agent catalog from A2UI's basic catalog plus rudraRecommendationsApi.

import { Catalog } from '@a2ui/web_core/v0_9';
import { basicCatalog } from '@a2ui/web_core/v0_9/basic_catalog';
import { RUDRA_RECOMMENDATIONS_INSTRUCTIONS, rudraRecommendationsApi } from '@rudra-js/a2ui/server';

export const agentCatalog = new Catalog(
  'https://shop.example/a2ui/catalog.json',
  'v0.9',
  [...basicCatalog.components.values(), rudraRecommendationsApi],
  [...basicCatalog.functions.values()],
  { instructions: RUDRA_RECOMMENDATIONS_INSTRUCTIONS },
);

Put agentCatalog.toJson() in your agent's prompt. Have the agent create its surfaces with catalogId: agentCatalog.id.

Give the browser catalog the same id.

Troubleshooting

Recursive reference detected at #/properties/currentSku/… Defaulting to any

The first toJson() logs this once for each of the four hints. Later calls log nothing.

It's harmless.