@rudra-js/a2ui 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.
package/README.md CHANGED
@@ -1,19 +1,22 @@
1
1
  # @rudra-js/a2ui
2
2
 
3
- This package is part of [rudra-js](https://rudrajs.com).
4
-
5
- rudra-js is an open-source TypeScript library (MIT) you install from npm. A language model designs one product-recommendation block for a page in your shop, rudra-js checks it against your catalog, and React renders it.
6
-
7
- It is not a hosted platform, a visual or low-code app builder, or a workspace you sign up for.
8
-
9
- This package puts that block inside the interfaces an [A2UI](https://a2ui.org) agent builds. It
10
- adds one component, `RudraRecommendations`, to the catalog your A2UI renderer draws from. The agent
11
- places it and passes hints about what the shopper is looking at. Your server still picks the
12
- products and builds the block with `@rudra-js/core`. The browser renders it with `@rudra-js/react`.
13
- For Flutter, Angular or any other renderer, your server can send the block as A2UI messages
14
- instead. See [Flutter, Angular and other renderers](#flutter-angular-and-other-renderers).
15
-
16
- It works with version 0.9 of the A2UI protocol, using `@a2ui/react` and `@a2ui/web_core` 0.14.
3
+ This package is part of [rudra-js](https://rudrajs.com), an open-source TypeScript library (MIT)
4
+ that you can install from npm. rudra-js uses a language model to design one product-recommendation
5
+ block for a page of your shop. The model picks the layout and writes the words. After rudra-js
6
+ checks the model's answer against your products, React renders the block with your own titles and
7
+ prices. rudra-js is not a hosted platform, a visual or low-code app builder, or a workspace you sign
8
+ up for.
9
+
10
+ You can use this package to let an [A2UI](https://a2ui.org) agent put the block into the interfaces
11
+ that it builds. This package adds a single component, `RudraRecommendations`, to the catalog your
12
+ A2UI renderer draws from. Your agent places the component and passes hints about what the shopper is
13
+ looking at. It's still up to your server to pick the products and build the block with
14
+ `@rudra-js/core`. To render the block in the browser, this package uses `@rudra-js/react`. For
15
+ Flutter, Angular or any other renderer, your server can send the block as A2UI messages instead (see
16
+ [Flutter, Angular and other renderers](#flutter-angular-and-other-renderers)).
17
+
18
+ This package works with version 0.9 of the A2UI protocol and uses `@a2ui/react` and `@a2ui/web_core`
19
+ 0.14.
17
20
 
18
21
  ## Install
19
22
 
@@ -21,33 +24,37 @@ It works with version 0.9 of the A2UI protocol, using `@a2ui/react` and `@a2ui/w
21
24
  npm install @rudra-js/a2ui@latest @rudra-js/core@latest @rudra-js/react@latest @rudra-js/attested@latest @a2ui/react@0.14 @a2ui/web_core@0.14 react react-dom
22
25
  ```
23
26
 
24
- Use the same command to install and to upgrade, whether or not your app already uses rudra-js or A2UI.
25
- If your app has `@rudra-js/anthropic`, add `@rudra-js/anthropic@latest` to that command.
26
-
27
- The `@rudra-js` packages are released together. Each one's peer range for the others starts at its
28
- own version. For a package name with no version, npm stays inside the range your `package.json`
29
- already has. Without `@latest`, an app on an older core can get an `ERESOLVE` error. `react`
30
- and `react-dom` have no version, so npm and pnpm keep a React 18 app on 18.
31
-
32
- Everything except zod is a peer dependency, so your app holds one copy of each. npm and pnpm
33
- install `@rudra-js/core`, `@rudra-js/attested` and `@a2ui/web_core` for you, but not `@a2ui/react`,
34
- `@rudra-js/react` or `react`. Those three are optional, so a server that only builds
35
- [messages for other renderers](#flutter-angular-and-other-renderers) can leave React out. The
36
- browser component can't load without them, so keep them in the command. List the rest anyway,
37
- because your code imports most of them itself.
38
- pnpm only lets your code import what your `package.json` names. Yarn doesn't install peers, so on Yarn you
39
- need the whole list. Yarn also moves a name with no version to its latest release. So on Yarn, if your app
40
- already has React, leave out `react` and `react-dom`. On pnpm, read [zod](#zod) first.
41
-
42
- Keep `skipLibCheck: true` in your `tsconfig.json`. Without it, A2UI's own type declarations fail
43
- to typecheck. They need `"dom"` in `lib`. Two of their imports also have no file extension, which
44
- `nodenext` refuses.
27
+ To install and also to upgrade, you will need to use this same command. It doesn't matter if your
28
+ app already uses rudra-js or A2UI.
29
+ Any app that has `@rudra-js/anthropic` will also need to add `@rudra-js/anthropic@latest` to this
30
+ command.
31
+
32
+ All the `@rudra-js` packages are released together. For each package, the peer range for the others
33
+ starts at the version of that package. For a package name with no version, npm will stay inside the
34
+ range your `package.json` already has. If `@latest` is left out, an app on an older core can get an
35
+ `ERESOLVE` error. With no version on `react` and `react-dom`, npm and pnpm will keep a React 18 app
36
+ on 18.
37
+
38
+ Because everything except zod is a peer dependency, your app holds a single copy of each. On npm and
39
+ pnpm, `@rudra-js/core`, `@rudra-js/attested` and `@a2ui/web_core` will be installed for you, but not
40
+ `@a2ui/react`, `@rudra-js/react` or `react`. React can be left out on a server that only builds
41
+ [messages for other renderers](#flutter-angular-and-other-renderers), since those three are
42
+ optional. But those three have to stay in the command for the browser component to load. List the
43
+ rest anyway, because your code imports most of these itself.
44
+ With pnpm your code can only import the packages your `package.json` names. You will need the whole
45
+ list on Yarn because it doesn't install peers. It will also move a name with no version to its
46
+ latest release. So if your app already has React, leave out `react` and `react-dom` on Yarn. On
47
+ pnpm, read [zod](#zod) first.
48
+
49
+ A2UI's type declarations will fail to typecheck if you don't keep `skipLibCheck: true` in your
50
+ `tsconfig.json`. They need `"dom"` in `lib`. Two of their imports will also be refused by `nodenext`
51
+ because these have no file extension.
45
52
 
46
53
  ## Three pieces
47
54
 
48
55
  ### The catalog your agent is prompted with
49
56
 
50
- Put `agentCatalog.toJson()` in your agent's prompt. Have the agent create surfaces with
57
+ Put `agentCatalog.toJson()` in your agent's prompt and have the agent create surfaces with
51
58
  `catalogId: agentCatalog.id`. If you have catalog instructions of your own, join them to
52
59
  `RUDRA_RECOMMENDATIONS_INSTRUCTIONS`.
53
60
 
@@ -65,15 +72,16 @@ export const agentCatalog = new Catalog(
65
72
  );
66
73
  ```
67
74
 
68
- The first `toJson()` call logs one "Recursive reference detected" warning per hint. It's harmless.
75
+ You will see a "Recursive reference detected" warning per hint from the first `toJson()` call. It's
76
+ harmless.
69
77
 
70
78
  ### Your endpoint
71
79
 
72
- `shopperFor` and `candidatesFor` stand in for the session and catalog code you already have.
73
- `provider: null` calls no model, so pass your own provider.
80
+ `shopperFor` and `candidatesFor` stand in for the session and catalog code you already have. You
81
+ will need to pass your own provider, because `provider: null` calls no model.
74
82
 
75
- `generation` defaults to `'cohort'`, which shares one block design between shoppers who look alike. In
76
- that mode the model never sees `searchQuery`. The agent's search only matters with
83
+ By default `generation` is `'cohort'`. This shares a single block design between shoppers who look
84
+ alike. In that mode the model never sees `searchQuery`. For the agent's search to matter, you need
77
85
  `generation: 'per-shopper'`.
78
86
 
79
87
  ```ts
@@ -113,13 +121,13 @@ export async function POST(request: Request): Promise<Response> {
113
121
  ```
114
122
 
115
123
  - `parseRecommendationRequest` accepts only `currentSku`, `currentCategory`, `searchQuery` and
116
- `maxItems`. Anything else gets a 400.
117
- - `fitRecommendationRequest` drops a SKU or category that none of your candidates has.
118
- - Pick candidates on your side, not from the hints.
119
- - Each new category, `maxItems` or candidate set means a new model call. With `per-shopper`, so
120
- does each shopper and each new SKU or search. Rate-limit the endpoint (see
121
- [SECURITY.md](https://github.com/clivedsouza1010/rudra-js/blob/main/SECURITY.md)).
122
- - Send back `input.candidates` and `input.bundles`, not your raw catalog.
124
+ `maxItems`. Anything else will get a 400.
125
+ - `fitRecommendationRequest` will drop a SKU or category if it's not in any of your candidates.
126
+ - Pick candidates on your side instead of from the hints.
127
+ - There will be a new model call for each new category, `maxItems` or candidate set. With
128
+ `per-shopper` this also goes for each shopper and each new SKU or search. Rate-limit the endpoint
129
+ (see [SECURITY.md](https://github.com/clivedsouza1010/rudra-js/blob/main/SECURITY.md)).
130
+ - Send back `input.candidates` and `input.bundles` instead of your raw catalog.
123
131
 
124
132
  ### The browser
125
133
 
@@ -153,47 +161,48 @@ const shopCatalog = new Catalog<ReactCatalogComponent>(
153
161
  export const processor = new MessageProcessor<ReactCatalogComponent>([shopCatalog]);
154
162
  ```
155
163
 
156
- Give the browser catalog the same id as the agent catalog. A2UI looks it up by the `catalogId` the
157
- agent sends. Render the processor's surfaces with `A2uiSurface`.
164
+ Give the browser catalog the id of the agent catalog, because A2UI will look it up by the
165
+ `catalogId` the agent sends. Use `A2uiSurface` to render the surfaces of the processor.
158
166
 
159
167
  `createRudraRecommendationsComponent` takes `loadRecommendations`, `placeholder` and `onError`. It
160
- also takes every `RudraComponent` prop except `spec`, `products` and `bundles`.
168
+ also takes all of the `RudraComponent` props except `spec`, `products` and `bundles`.
161
169
 
162
170
  ## What the component does
163
171
 
164
- - It reads each hint either as a literal value or from the agent's data model, like
165
- `{ "path": "/viewing/sku" }`. It sends only the four hints the endpoint accepts.
166
- - It leaves out a hint that is blank, or one the server would turn away, like a `maxItems` of 40.
167
- - A literal of the wrong type, like a numeric SKU, makes A2UI refuse the agent's whole message.
168
- - It waits until the hints stop changing for 300 ms, then calls `loadRecommendations`.
172
+ - It will read each hint either as a literal value or from the agent's data model, like
173
+ `{ "path": "/viewing/sku" }`. It will only send the four hints the endpoint accepts.
174
+ - It leaves out any hint that is blank. It also leaves out a hint the server would turn away, like a
175
+ `maxItems` of 40.
176
+ - With a literal of the wrong type, like a numeric SKU, A2UI will refuse the agent's whole message.
177
+ - It waits for the hints to stop changing for 300 ms and then calls `loadRecommendations`.
169
178
  - It keeps showing the last block until the next one arrives.
170
179
  - `signal` aborts when the hints change or the component unmounts.
171
- - It checks the result against core's schemas before it renders any of it.
180
+ - It will check the result against core's schemas before it renders any of it.
172
181
  - It shows `placeholder` until the first load finishes.
173
- - If a load fails or the result fails the schema check, it shows nothing and calls `onError`. It
174
- does the same if the block throws while rendering.
182
+ - If a load fails or the result fails the schema check, it will show nothing and call `onError`.
183
+ This is also what happens if the block throws while rendering.
175
184
  - Each component on a surface sends its own request.
176
185
 
177
186
  ## Where it runs
178
187
 
179
- `@rudra-js/a2ui` holds `createRudraRecommendationsComponent` and its types. It loads only in the
180
- browser, because `@a2ui/react` needs a DOM. The agent catalog and your endpoint import from
181
- `@rudra-js/a2ui/server`, which runs anywhere.
188
+ `@rudra-js/a2ui` holds `createRudraRecommendationsComponent` and its types. It can only be loaded in
189
+ the browser, because `@a2ui/react` needs a DOM. For the agent catalog and your endpoint, import from
190
+ `@rudra-js/a2ui/server`. This entry point can run anywhere.
182
191
 
183
- In Next.js, a `'use client'` file still runs on the server for the first render. Load the file
184
- that imports `@rudra-js/a2ui` through `next/dynamic` with `ssr: false`, and make that call from a
185
- client component.
192
+ In Next.js, a `'use client'` file will also run on the server for the first render. To load the file
193
+ that imports `@rudra-js/a2ui`, you will need `next/dynamic` with `ssr: false`. This call has to be
194
+ made from a client component.
186
195
 
187
- A2UI renders in the browser, so a crawler won't see a block an agent places. For a product page,
188
- render `RudraComponent` on the server, as the
196
+ Any block an agent places won't be seen by a crawler, because A2UI renders in the browser. For a
197
+ product page, render `RudraComponent` on the server as the
189
198
  [`@rudra-js/react` README](https://github.com/clivedsouza1010/rudra-js/tree/main/packages/react)
190
199
  describes.
191
200
 
192
201
  ## Flutter, Angular and other renderers
193
202
 
194
203
  `RudraRecommendations` needs a React renderer. For any other A2UI renderer, build the block on your
195
- server as A2UI messages that use only the basic catalog, which every renderer ships. A server with
196
- no React needs only these:
204
+ server as A2UI messages that use just the basic catalog. All renderers ship with this catalog. If
205
+ your server has no React, it only needs these:
197
206
 
198
207
  ```sh
199
208
  npm install @rudra-js/a2ui@latest @rudra-js/core@latest @rudra-js/attested@latest @a2ui/web_core@0.14
@@ -215,63 +224,66 @@ export function messagesFor(result: RecommendationResult, locale: string) {
215
224
 
216
225
  In [your endpoint](#your-endpoint), return `Response.json(messagesFor(result, shopper.locale))`
217
226
  instead of `result`. Skip the [agent catalog](#the-catalog-your-agent-is-prompted-with) and
218
- [browser](#the-browser) pieces, and keep `rudraRecommendationsApi` out of your agent's catalog.
219
- Those are for `RudraRecommendations`, which needs React. Use your own `surfaceId` in place of
220
- `'rudra_recommendations'`, and never name it in your agent's prompt.
227
+ [browser](#the-browser) pieces and keep `rudraRecommendationsApi` out of your agent's catalog,
228
+ because they are all for `RudraRecommendations`, which needs React. Use your own `surfaceId` in
229
+ place of `'rudra_recommendations'`. It must never be named in your agent's prompt.
221
230
 
222
231
  Your app can call the endpoint with the four hints and give the messages it gets back to its A2UI
223
- renderer. Or your agent's code can call it and pass the messages on to the client unchanged. Then
224
- the call has to carry the shopper's session, because `shopperFor` reads the shopper from the
225
- request. The first way is the safer one. Either way, keep the model away from the messages and
226
- from the block's surface, as
227
- [SECURITY.md](https://github.com/clivedsouza1010/rudra-js/blob/main/SECURITY.md) explains.
228
-
229
- - The messages create the surface named `surfaceId` and fill it. To show a new block there, send
230
- `deleteSurface` for it first. When nothing in the block can be shown, you get no messages.
231
- - Grids and carousels show two cards to a row. The basic catalog can't fit cards to the screen, and
232
- its `List` doesn't scroll on every renderer.
233
- - Each product card is a button that opens the product's page. `hrefForSku` builds the link,
234
- `/product/<sku>` by default. `shopUrl` resolves that link and any relative image URL, because a
235
- native app has no page to resolve them against. A product whose image URL is empty or only
236
- spaces shows no image. A link that is empty, or a link or an image that doesn't end up `http` or
237
- `https`, throws.
238
- - A featured card looks like any other, and a banner looks the same whatever its tone, because the
239
- basic catalog has no styles for them. Nothing carries the `data-rudra-*` attributes the React
240
- block uses for click tracking, so to count clicks, add a query parameter in `hrefForSku`.
241
- - Prices are formatted on your server, for `locale`. Without it, they use the server's default
242
- locale, not the shopper's. Pass `formatPrice` and `formatBundlePrice` to format them yourself.
243
- - All text uses a heading or caption style, never body, because the web renderers read only body
244
- text as Markdown. Flutter's `genui` and the A2UI SwiftUI renderer read every style as Markdown, as
232
+ renderer. This is the safer way. Your agent's code can also call it and pass the messages on to the
233
+ client unchanged, but then the call has to carry the shopper's session because `shopperFor` reads
234
+ the shopper from the request. Either way, keep the model away from the messages and from the surface
235
+ of the block, as [SECURITY.md](https://github.com/clivedsouza1010/rudra-js/blob/main/SECURITY.md)
236
+ explains.
237
+
238
+ - These messages will create the surface named `surfaceId` and then fill it. To show a new block
239
+ there, first send `deleteSurface` for this surface. You will get no messages if nothing in the
240
+ block can be shown.
241
+ - Grids and carousels show two cards to a row, because the basic catalog can't fit cards to the
242
+ screen and its `List` doesn't scroll on all renderers.
243
+ - Each product card is a button to open the product's page. By default `hrefForSku` builds the link
244
+ as `/product/<sku>`. `shopUrl` will resolve this link and any relative image URL, because a native
245
+ app has no page to resolve them against. If the image URL of a product is empty or only spaces, no
246
+ image will be shown. An empty link will throw. A link or an image that doesn't end up `http` or
247
+ `https` will also throw.
248
+ - Featured cards look like any other card and banners look the same in all tones, because the basic
249
+ catalog has no styles for them. As nothing carries the `data-rudra-*` attributes the React block
250
+ uses for click tracking, you will need to add a query parameter in `hrefForSku` to count clicks.
251
+ - Prices are formatted on your server for `locale`. If you leave it out, they will use the default
252
+ locale of the server and not the shopper's. You can also pass `formatPrice` and
253
+ `formatBundlePrice` to format prices yourself.
254
+ - All text uses a heading or caption style and never body, because the web renderers only read body
255
+ text as Markdown. Flutter's `genui` and the A2UI SwiftUI renderer read all styles as Markdown, as
245
256
  the
246
257
  [A2UI guide](https://github.com/a2ui-project/a2ui/blob/main/specification/v0_9_1/docs/basic_catalog_implementation_guide.md)
247
- asks. So square brackets become parentheses, `<` and `>` become `‹` and `›`, and line breaks
248
- become spaces. No text can load an image, and only a bare web address or email address can show
249
- as a link. On SwiftUI a tap opens it. On `genui` it does nothing, and text that starts with `# `
250
- or `- ` shows as Markdown.
251
- - The rationale and how the block was generated are never sent.
258
+ asks. So square brackets become parentheses, while `<` and `>` become `‹` and `›`. Line breaks
259
+ also become spaces. No text can load an image. Only a bare web address or email address can show
260
+ as a link. On SwiftUI a tap will open the link, but on `genui` it does nothing and text that
261
+ starts with `#` or `-` followed by a space shows as Markdown.
262
+ - Neither the rationale nor how the block was generated is ever sent.
252
263
  - Flutter's `genui` knows the basic catalog by its id from 0.10.3. For 0.8 to 0.10.2, pass
253
- `catalogId: 'https://a2ui.org/specification/v0_9/basic_catalog.json'`. On Android 11 and later,
254
- the app has to declare `https` links under `<queries>` in its manifest, or a tap on a card does
255
- nothing.
256
- - On `@a2ui/angular` 0.13, register the `BasicCatalog` from `@a2ui/angular/v0_9`, because the one
257
- from `@a2ui/angular` has the v1.0 id. Pass `useUniversalComponents: true` to `provideA2Ui` too,
258
- next to `catalogs`. Without it, a click on a card does nothing, and each card tries to open its
259
- link in a new tab as soon as it renders.
264
+ `catalogId: 'https://a2ui.org/specification/v0_9/basic_catalog.json'`. On Android 11 and later, a
265
+ tap on a card will do nothing if the app doesn't declare `https` links under `<queries>` in its
266
+ manifest.
267
+ - On `@a2ui/angular` 0.13, register the `BasicCatalog` from `@a2ui/angular/v0_9` because the catalog
268
+ from `@a2ui/angular` has the v1.0 id. You also have to pass `useUniversalComponents: true` to
269
+ `provideA2Ui` next to `catalogs`. If you don't, a click on a card will do nothing and all cards
270
+ will try to open their links in a new tab as soon as they render.
260
271
 
261
272
  ## zod
262
273
 
263
- A2UI's schemas use zod 3, so this package depends on zod 3. The rest of rudra-js uses zod 4. npm
264
- installs both, each where its own package finds it. With npm, you don't need either one yourself.
274
+ This package depends on zod 3 because A2UI's schemas use zod 3, but the rest of rudra-js uses zod 4.
275
+ npm will install both, each where its own package can find it. With npm you don't need to add either
276
+ version yourself.
265
277
 
266
- On pnpm, `@a2ui/react` gets core's zod 4 as its zod peer. Then the browser example fails to
267
- typecheck with TS2344. If your app has no zod of its own, add zod 3:
278
+ On pnpm, `@a2ui/react` gets core's zod 4 as its zod peer. This makes the browser example fail to
279
+ typecheck with TS2344. If your app has no zod of its own, you will need to add zod 3:
268
280
 
269
281
  ```sh
270
282
  pnpm add zod@^3.25.76
271
283
  ```
272
284
 
273
- If your app uses zod 4, remove the zod peer from `@a2ui/react` in `.pnpmfile.cjs`. pnpm then gives
274
- it the zod 3 it depends on:
285
+ If your app uses zod 4, you will need to remove the zod peer from `@a2ui/react` in `.pnpmfile.cjs`.
286
+ Then pnpm will give it the zod 3 it depends on:
275
287
 
276
288
  ```js
277
289
  module.exports = {
@@ -1 +1 @@
1
- {"version":3,"file":"recommendation-messages.d.ts","sourceRoot":"","sources":["../src/recommendation-messages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,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O,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;IACzD,iBAAiB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;IAC7D,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CAC7B;AAgRD,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,6BAA6B,GACrC,WAAW,EAAE,CAoCf"}
@@ -1,32 +1,6 @@
1
+ import { defaultFormatBundlePrice, defaultFormatPrice, defaultHrefForSku, findSellableProduct, } from '@rudra-js/core/schemas';
1
2
  const BASIC_CATALOG_ID = 'https://a2ui.org/specification/v0_9/catalogs/basic/catalog.json';
2
3
  const CARDS_PER_ROW = 2;
3
- function defaultHrefForSku(sku) {
4
- return `/product/${encodeURIComponent(sku)}`;
5
- }
6
- function formatMoney(price, currency, locale) {
7
- let formatter;
8
- try {
9
- formatter = new Intl.NumberFormat(locale, { style: 'currency', currency });
10
- }
11
- catch {
12
- return `${currency} ${price}`;
13
- }
14
- return formatter.format(price);
15
- }
16
- function defaultFormatPrice(product, locale) {
17
- if (!Number.isFinite(product.price)) {
18
- throw new TypeError(`price for SKU ${product.sku} is ${String(product.price)}, not a finite number. ` +
19
- 'Catalog objects must satisfy productSchema from @rudra-js/core');
20
- }
21
- return formatMoney(product.price, product.currency, locale);
22
- }
23
- function defaultFormatBundlePrice(bundle, locale) {
24
- if (!Number.isFinite(bundle.price)) {
25
- throw new TypeError(`price for bundle ${bundle.id} is ${String(bundle.price)}, not a finite number. ` +
26
- 'Bundle objects must satisfy bundleSchema from @rudra-js/core');
27
- }
28
- return formatMoney(bundle.price, bundle.currency, locale);
29
- }
30
4
  function toWebUrl(value, base, name) {
31
5
  if (typeof value !== 'string')
32
6
  throw new TypeError(`${name} is not a string`);
@@ -56,10 +30,6 @@ function plainText(value) {
56
30
  function defined(ids) {
57
31
  return ids.filter((id) => id !== undefined);
58
32
  }
59
- function sellableProduct(context, sku) {
60
- const product = context.products.get(sku);
61
- return product?.isInStock === false ? undefined : product;
62
- }
63
33
  function addText(context, id, value, variant) {
64
34
  const text = value === null ? '' : plainText(value);
65
35
  return text ? context.add({ id, component: 'Text', text, variant }) : undefined;
@@ -110,7 +80,7 @@ function addProductCard(context, id, reference, product) {
110
80
  function addCardRows(context, id, title, items) {
111
81
  const cards = [];
112
82
  for (const reference of items) {
113
- const product = sellableProduct(context, reference.sku);
83
+ const product = findSellableProduct(context.products, reference.sku);
114
84
  if (product) {
115
85
  cards.push(addProductCard(context, `${id}_item${cards.length}`, reference, product));
116
86
  }
@@ -134,7 +104,7 @@ function addCardRows(context, id, title, items) {
134
104
  return addColumn(context, id, [addText(context, `${id}_title`, title, 'h3'), ...rows]);
135
105
  }
136
106
  function addHero(context, id, block) {
137
- const product = block.sku === null ? undefined : sellableProduct(context, block.sku);
107
+ const product = block.sku === null ? undefined : findSellableProduct(context.products, block.sku);
138
108
  const headline = addText(context, `${id}_headline`, block.headline, 'h3');
139
109
  const body = addText(context, `${id}_body`, block.body, 'caption');
140
110
  if (!headline && !body && !product)
@@ -167,7 +137,7 @@ function addBundle(context, id, block) {
167
137
  return undefined;
168
138
  const products = [];
169
139
  for (const sku of bundle.skus) {
170
- const product = sellableProduct(context, sku);
140
+ const product = findSellableProduct(context.products, sku);
171
141
  if (!product)
172
142
  return undefined;
173
143
  products.push(product);
@@ -1 +1 @@
1
- {"version":3,"file":"recommendation-messages.js","sourceRoot":"","sources":["../src/recommendation-messages.ts"],"names":[],"mappings":"AAuBA,MAAM,gBAAgB,GAAG,iEAAiE,CAAC;AAC3F,MAAM,aAAa,GAAG,CAAC,CAAC;AAgCxB,SAAS,iBAAiB,CAAC,GAAW;IACpC,OAAO,YAAY,kBAAkB,CAAC,GAAG,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,WAAW,CAAC,KAAa,EAAE,QAAgB,EAAE,MAA0B;IAC9E,IAAI,SAA4B,CAAC;IACjC,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CAAC,MAAM,EAAE,EAAE,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC;QAC7F,GAAG,EAAE,CAAC,SAAS,EAAE,EAAE;YACjB,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC3B,OAAO,SAAS,CAAC,EAAE,CAAC;QACtB,CAAC;KACF,CAAC;IAEF,MAAM,MAAM,GAAG,OAAO,CACpB,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC,CACpF,CAAC;IACF,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,EAAE,CAAC;IAEnC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE;QACzB,OAAO,CAAC,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC;QACxD,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC;QACnE,GAAG,MAAM;KACV,CAAC,CAAC;IACH,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IAC9B,OAAO;QACL;YACE,OAAO,EAAE,MAAM;YACf,aAAa,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,gBAAgB,EAAE;SAC/E;QACD,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE;KACjE,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@rudra-js/a2ui",
3
- "version": "0.9.0",
4
- "description": "A2UI component for rudra-js: lets an A2UI agent place a product-recommendation block whose products, prices and wording come from your shop, not from the agent",
3
+ "version": "0.10.0",
4
+ "description": "Lets an A2UI agent place rudra-js product recommendations. Your server still picks the products and builds the block.",
5
5
  "keywords": [
6
6
  "rudra-js",
7
7
  "a2ui",
@@ -62,8 +62,8 @@
62
62
  "peerDependencies": {
63
63
  "@a2ui/react": "^0.14.0",
64
64
  "@a2ui/web_core": "^0.14.0",
65
- "@rudra-js/core": "^0.9.0",
66
- "@rudra-js/react": "^0.9.0",
65
+ "@rudra-js/core": "^0.10.0",
66
+ "@rudra-js/react": "^0.10.0",
67
67
  "react": "^18.2.0 || ^19.0.0"
68
68
  },
69
69
  "peerDependenciesMeta": {
@@ -80,8 +80,8 @@
80
80
  "devDependencies": {
81
81
  "@a2ui/react": "0.14.0",
82
82
  "@a2ui/web_core": "0.14.0",
83
- "@rudra-js/core": "0.9.0",
84
- "@rudra-js/react": "0.9.0",
83
+ "@rudra-js/core": "0.10.0",
84
+ "@rudra-js/react": "0.10.0",
85
85
  "@types/react": "^19.3.0",
86
86
  "@types/react-dom": "^19.3.0",
87
87
  "jsdom": "^27.4.0",
@@ -9,6 +9,12 @@ import type {
9
9
  Product,
10
10
  ProductReference,
11
11
  } from '@rudra-js/core';
12
+ import {
13
+ defaultFormatBundlePrice,
14
+ defaultFormatPrice,
15
+ defaultHrefForSku,
16
+ findSellableProduct,
17
+ } from '@rudra-js/core/schemas';
12
18
  import type { RecommendationResult } from './recommendation-result.js';
13
19
 
14
20
  export interface RecommendationMessagesOptions {
@@ -54,40 +60,6 @@ interface BuildContext {
54
60
  readonly add: (component: BasicComponent) => string;
55
61
  }
56
62
 
57
- function defaultHrefForSku(sku: string): string {
58
- return `/product/${encodeURIComponent(sku)}`;
59
- }
60
-
61
- function formatMoney(price: number, currency: string, locale: string | undefined): string {
62
- let formatter: Intl.NumberFormat;
63
- try {
64
- formatter = new Intl.NumberFormat(locale, { style: 'currency', currency });
65
- } catch {
66
- return `${currency} ${price}`;
67
- }
68
- return formatter.format(price);
69
- }
70
-
71
- function defaultFormatPrice(product: Product, locale: string | undefined): string {
72
- if (!Number.isFinite(product.price)) {
73
- throw new TypeError(
74
- `price for SKU ${product.sku} is ${String(product.price)}, not a finite number. ` +
75
- 'Catalog objects must satisfy productSchema from @rudra-js/core',
76
- );
77
- }
78
- return formatMoney(product.price, product.currency, locale);
79
- }
80
-
81
- function defaultFormatBundlePrice(bundle: Bundle, locale: string | undefined): string {
82
- if (!Number.isFinite(bundle.price)) {
83
- throw new TypeError(
84
- `price for bundle ${bundle.id} is ${String(bundle.price)}, not a finite number. ` +
85
- 'Bundle objects must satisfy bundleSchema from @rudra-js/core',
86
- );
87
- }
88
- return formatMoney(bundle.price, bundle.currency, locale);
89
- }
90
-
91
63
  function toWebUrl(value: unknown, base: string | undefined, name: string): string {
92
64
  if (typeof value !== 'string') throw new TypeError(`${name} is not a string`);
93
65
  if (value.trim() === '') throw new TypeError(`${name} is empty`);
@@ -117,11 +89,6 @@ function defined(ids: readonly (string | undefined)[]): string[] {
117
89
  return ids.filter((id): id is string => id !== undefined);
118
90
  }
119
91
 
120
- function sellableProduct(context: BuildContext, sku: string): Product | undefined {
121
- const product = context.products.get(sku);
122
- return product?.isInStock === false ? undefined : product;
123
- }
124
-
125
92
  function addText(
126
93
  context: BuildContext,
127
94
  id: string,
@@ -209,7 +176,7 @@ function addCardRows(
209
176
  ): string | undefined {
210
177
  const cards: string[] = [];
211
178
  for (const reference of items) {
212
- const product = sellableProduct(context, reference.sku);
179
+ const product = findSellableProduct(context.products, reference.sku);
213
180
  if (product) {
214
181
  cards.push(addProductCard(context, `${id}_item${cards.length}`, reference, product));
215
182
  }
@@ -236,7 +203,7 @@ function addCardRows(
236
203
  }
237
204
 
238
205
  function addHero(context: BuildContext, id: string, block: HeroBlock): string | undefined {
239
- const product = block.sku === null ? undefined : sellableProduct(context, block.sku);
206
+ const product = block.sku === null ? undefined : findSellableProduct(context.products, block.sku);
240
207
  const headline = addText(context, `${id}_headline`, block.headline, 'h3');
241
208
  const body = addText(context, `${id}_body`, block.body, 'caption');
242
209
  if (!headline && !body && !product) return undefined;
@@ -278,7 +245,7 @@ function addBundle(context: BuildContext, id: string, block: BundleBlock): strin
278
245
 
279
246
  const products: Product[] = [];
280
247
  for (const sku of bundle.skus) {
281
- const product = sellableProduct(context, sku);
248
+ const product = findSellableProduct(context.products, sku);
282
249
  if (!product) return undefined;
283
250
  products.push(product);
284
251
  }