@greatstore/cli 0.2.14 → 0.2.16

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.
@@ -32,6 +32,7 @@ npx greatstore configure --store my-store --json # brand config
32
32
  npx greatstore connectors --store my-store --json # MCP connectors feeding the assistant
33
33
  npx greatstore connectors health --store my-store # live-probe them (reports tool counts)
34
34
  npx greatstore connectors tools maker --store my-store # a connector's tools, inputs in full
35
+ npx greatstore connectors tools webmcp --store my-store # the page tools the store's pages register
35
36
  npx greatstore connectors errors --store my-store --json # tools' most frequent errors, last 7 days
36
37
  npx greatstore apps list --store my-store --json # deployed custom in-chat apps
37
38
  ```
@@ -45,17 +46,22 @@ What each read is good for:
45
46
  - **`npx greatstore connectors`** — which MCP connectors the assistant has, and whether
46
47
  the Maker MCP is on. This tells you what the assistant can actually *do*:
47
48
  check it before building features that lean on catalog data (e.g.
48
- [structured content](structured-content.md) grounding), and before
49
+ [structured content](embed-api/generate-structured-content.md) grounding), and before
49
50
  registering WebMCP page tools that would duplicate a capability a
50
51
  server-side connector already provides.
51
52
  - **`npx greatstore connectors health`** — a connector being listed doesn't mean it's
52
53
  reachable; this probes each one live. Run it when assistant behaviour
53
54
  suggests a tool isn't responding.
54
- - **`npx greatstore connectors tools <name|maker> [<tool>]`** — what a
55
+ - **`npx greatstore connectors tools <name|maker|webmcp> [<tool>]`** — what a
55
56
  connector offers, live: each tool's group, whether the assistant may call it,
56
57
  whether a page can call it with `GreatStore.callTool`, its description and
57
58
  every input with its type, constraints and description. Read it before
58
59
  writing a `callTool` call (see [embed-api/call-tool.md](embed-api/call-tool.md)).
60
+ `webmcp` lists the WebMCP page tools the store's pages have registered in
61
+ recent chats, with their names and descriptions; their inputs are whatever
62
+ the page's own `registerTool` call declares. Check it before registering a
63
+ page tool, so you extend or override what the site already has instead of
64
+ duplicating it. A tool only appears after a chat on a page that registers it.
59
65
  - **`npx greatstore connectors errors`** — what actually went wrong when the assistant
60
66
  called a tool on shoppers' behalf: each connector, custom-app or page tool's
61
67
  distinct errors, how often each happened and when last. Health only says a
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatstore/cli",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "CLI for administering GreatStore stores and authoring custom components.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -1,317 +0,0 @@
1
- # `generateStructuredContent` deep dive
2
-
3
- AI-generated, catalog-grounded JSON for UI you render yourself — the chat
4
- panel is not involved.
5
-
6
- ```js
7
- const data = await window.GreatStore.generateStructuredContent(schema, prompt);
8
- ```
9
-
10
- - `schema` — a JSON Schema describing the output (or a Zod schema exposing
11
- `.toJSONSchema()`).
12
- - `prompt` — what to generate.
13
- - Resolves to **the generated JSON object itself**, matching the schema.
14
- Rejects with an `Error` on any failure.
15
-
16
- Code samples here are framework-free reference implementations — re-express
17
- them in the host repo's framework (React, Vue, Shopify Liquid, …) rather
18
- than retrofitting them as-is.
19
-
20
- ## The rules that make it work well
21
-
22
- Each is unpacked in the sections below; this is the checklist.
23
-
24
- 1. **Top level must be an object.** Want a list? Wrap it:
25
- `{ type: "object", properties: { items: { type: "array", … } }, required: ["items"] }`.
26
- 2. **Steer the whole output with the prompt, single fields with
27
- `description`.** A property's `description` reaches the AI as guidance for
28
- that field; it's optional, so use self-explanatory property names
29
- (`benefitHeadline`, not `text1`) and describe only where the name isn't
30
- enough.
31
- 3. **Only `require` what's guaranteed.** `required` is strictly enforced; if
32
- the catalog can't ground a required field the whole call can fail. Require
33
- structural fields, keep per-product details (image URLs, prices) optional,
34
- and make rendering tolerate missing values.
35
- 4. **Point, don't paste.** GreatStore researches the store's live catalog on
36
- its own — name the entity (`` `…the product "${productName}" (SKU ${sku})` ``)
37
- and let it look the facts up. Don't fetch specs/prices/descriptions
38
- yourself and paste them into the prompt. The one thing it *can't* see is
39
- your page, so page-only context (which page the shopper is on, what the
40
- section is for) does belong in the prompt.
41
- 5. **Research is bounded by the store's connectors — validate before you
42
- build.** The AI can only look up what the store's MCP connectors actually
43
- provide. Ask for something outside them — currency conversion, live
44
- shipping rates, review data the store never wired up — and it has nothing
45
- to ground on, so it will decline, omit… or hallucinate. Before writing a
46
- prompt or schema that depends on a data capability, run `npx greatstore connectors`
47
- (and `npx greatstore connectors health`, [store-admin.md](store-admin.md)) and confirm
48
- a connector for it exists; if it doesn't, don't ask for it.
49
- 6. **Responses are cached** for up to ~24h per page + prompt + schema —
50
- shared across anonymous visitors, per-shopper for identified ones. "Page"
51
- means the URL path: query strings are dropped, so a page that varies by
52
- `?param` must name its product in the prompt. Keep
53
- prompts deterministic per page — no timestamps, random values, or
54
- per-visitor data (GreatStore already knows who the shopper is; see below).
55
- 7. **Progressive enhancement, always.** Generate after the page renders into
56
- a hidden container, reveal on success, leave the fallback on error. Render
57
- generated strings via `textContent`, never `innerHTML`.
58
- 8. **One rich call beats many small ones** — there's a per-IP rate limit
59
- (~20 requests/minute); fetch multiple surfaces with one combined schema.
60
-
61
- ## What actually happens
62
-
63
- 1. The SDK posts your schema + prompt to the store's GreatStore endpoint,
64
- along with the current **page context**, sent automatically — you don't
65
- pass it, and you can't override it:
66
- - the page URL, **without its query string or fragment**;
67
- - the page title;
68
- - a small, length-capped subset of the page's schema.org JSON-LD
69
- (`Product`, `ProductGroup`, `Offer`, `Article`, `WebPage`, `FAQPage`,
70
- `AggregateRating`). For products that's identifiers only — name,
71
- brand, SKU, GTIN, URL — so emitting product JSON-LD is the most
72
- reliable way to tell GreatStore exactly which product the page is
73
- about.
74
- 2. GreatStore first **researches**: it looks up real data from the store's
75
- live catalog (products, prices, availability, store info) using read-only
76
- lookups. The page context serves as hints about which product or category
77
- to look up — it is *not* treated as a source of product data, and nothing
78
- else on the page (visible text, reviews, your markup) is read. Research
79
- happens on GreatStore's side — your
80
- prompt only needs to *point* it at the right SKU, product, or collection,
81
- not carry the material. Its reach is exactly the store's MCP connectors:
82
- validate with `npx greatstore connectors` ([store-admin.md](store-admin.md)) that a
83
- connector for the data you want actually exists before you build on it —
84
- research can't exceed the wired-up connectors, and prompts that assume
85
- otherwise invite hallucinated filler.
86
- 3. The AI then fills your schema from the researched data, under a strict
87
- grounding contract: it must not invent product names, prices, images, IDs,
88
- or descriptions. Fields it can't ground are omitted or `null`. For an
89
- identified shopper this step also sees their shopper profile — the same
90
- identity the chat assistant has — so the output can be subtly personalized
91
- without you passing anything about the visitor.
92
- 4. The output is validated against your schema (with internal retries) before
93
- being returned and cached.
94
-
95
- GreatStore already knows who's reading: identity rides the request the same
96
- way it does for chat, and responses for identified shoppers are cached just
97
- for them (anonymous visitors share one entry). The practical consequence:
98
- never put shopper data in the prompt — it's redundant, and it poisons the
99
- cache key.
100
-
101
- ## Schema support
102
-
103
- Top level **must describe an object**: `type: "object"` (or a bare
104
- `properties` / `anyOf`). To get a list, wrap it in an object property.
105
-
106
- Supported keywords (anything else is tolerated but ignored):
107
-
108
- - Types: `object`, `array`, `string`, `number`, `integer`, `boolean`, `null`
109
- - Structure: `properties`, `required`, `items`, `additionalProperties`
110
- - Choice: `enum`, `const`, `anyOf`, `nullable`
111
- - Constraints: `minimum`, `maximum`, `minLength`, `maxLength`, `minItems`,
112
- `maxItems`, `pattern`, `format`, `default`
113
- - Guidance: `description`, `example`, `title` (on any property)
114
-
115
- Validation of the output is real: `required` is enforced, `enum`/`const`
116
- must match, numeric and length bounds are checked, and
117
- `additionalProperties: false` rejects extra keys. Constraints are therefore a
118
- *tool* — `enum` reliably restricts a field — but every constraint is also a
119
- way for generation to fail, so apply them only where you'd rather have no
120
- content than non-conforming content.
121
-
122
- Item counts are the exception. `minItems` is honored as the content is
123
- written, so a list comes back with at least that many entries, and a list
124
- longer than `maxItems` is cut to its first `maxItems` entries rather than
125
- failing. The same applies to an app's `inputSchema`.
126
-
127
- Zod schemas (or anything with a `.toJSONSchema()` method) are accepted and
128
- converted automatically — `.describe("…")` becomes the field's `description`.
129
-
130
- ### Field descriptions
131
-
132
- A property's `description` is shown to the AI as guidance for that one
133
- field, and an `example` shows the exact shape you want (`"4.5 out of 5"`,
134
- `"SKU-1234"`). Both are optional: a field without them is filled from its
135
- name, the prompt, and its constraints.
136
-
137
- ```js
138
- {
139
- type: "object",
140
- properties: {
141
- headline: { type: "string", maxLength: 60 },
142
- priceJustification: {
143
- type: "string",
144
- description: "One sentence on why the price is fair, citing a real material or feature",
145
- },
146
- rating: { type: "string", example: "4.5 out of 5" },
147
- },
148
- required: ["headline"],
149
- }
150
- ```
151
-
152
- Split the work between the two channels:
153
-
154
- - **Prompt** — the situation, the task as a whole, grounding, and voice.
155
- - **`description` / `example`** — what one specific field holds: its unit, length in
156
- words, perspective ("first-person, as the shopper"), or how it relates to
157
- a sibling. Instructions that apply to the whole output don't belong here.
158
- - Property *names* still carry most of the intent — make them
159
- self-documenting (`ctaLabel`, `warmthRating`, `priceJustification`) and
160
- reach for a description when the name can't say it.
161
-
162
- ## Prompting guide
163
-
164
- The prompt carries the instructions for the output as a whole (per-field
165
- guidance can sit in each field's `description` or `example`). A good prompt states, in
166
- order:
167
-
168
- 1. **Context** — what page/situation the shopper is in, naming the entity so
169
- research targets the right thing (the AI can't see your DOM, so identify
170
- it explicitly):
171
- `The shopper is viewing the product "Aurora Down Parka" (SKU AUR-021) on its product page.`
172
- 2. **Task** — what to generate, mapped loosely onto your schema's fields:
173
- `Write a heading and 3 reasons to love it; each reason has a short title and one supporting sentence.`
174
- 3. **Grounding expectations** — what store data to draw on:
175
- `Base every claim on the product's real materials, features, and price.`
176
- 4. **Voice** — tone and constraints:
177
- `Warm and concrete. No exclamation marks, no generic marketing filler.`
178
-
179
- Note what's *not* in that prompt: no pasted specs, prices, or descriptions.
180
- Pointing at the SKU is enough — GreatStore researches the rest itself, from
181
- data that's live rather than whatever was true when you wrote the prompt.
182
-
183
- Anti-patterns:
184
-
185
- - **Pasting researched material into the prompt** (specs, prices,
186
- descriptions you fetched from your platform's API). GreatStore researches
187
- the live catalog itself — point it at the SKU/product/collection and let
188
- it look things up. Pasted facts go stale, bloat the cache key, and compete
189
- with the fresher data research returns.
190
- - **Per-visitor or per-moment data in the prompt** (names, cart contents,
191
- timestamps, `Math.random()`): destroys caching, so every visitor pays full
192
- generation latency and the store pays for every call — and it's redundant,
193
- because GreatStore already knows the shopper and personalizes for
194
- identified ones server-side. If you need per-shopper *interaction*, that's
195
- what `sendMessage` and the chat panel are for.
196
- - **Asking for data no connector provides** ("convert the price to EUR",
197
- "estimate delivery to the shopper's city"): research can't exceed the
198
- store's MCP connectors, and the AI may hallucinate plausible-looking
199
- values rather than leave the field empty. Validate first — `npx greatstore connectors`
200
- shows what's wired up ([store-admin.md](store-admin.md)); if there's no
201
- connector for it, don't ask for it.
202
- - **Asking it to read the page** ("summarize the reviews shown below") — it
203
- can't. Page-only data (review snippets, UGC, things that exist nowhere but
204
- the DOM) is the one kind worth inlining — keep it stable per page so
205
- caching still works.
206
- - **Asking for minute-fresh operational data** (exact live stock counts,
207
- delivery countdowns). Even when a connector could answer, responses cache
208
- for up to ~24h — display operational data from your own platform APIs and
209
- use GreatStore for *editorial intelligence over the catalog*.
210
- - **Putting whole-output instructions in a field's `description`** (voice,
211
- grounding, what the page is) — they belong in the prompt, where they apply
212
- to every field.
213
-
214
- ## Caching: design for it
215
-
216
- Responses are cached server-side for up to **24 hours**, keyed by the
217
- combination of page context (URL path, title, JSON-LD identifiers) + prompt +
218
- schema. Anonymous visitors share one entry per key; identified shoppers each
219
- get their own (their output may be personalized, so it's only ever served
220
- back to them).
221
-
222
- **The query string and fragment never reach GreatStore.** `/product?id=123`
223
- and `/product?id=456` are the same page to it — same hints, same cache entry.
224
- If your page picks its product from a query param, name that product in the
225
- prompt (`` `…the product "${name}" (SKU ${sku})` ``), or emit JSON-LD for it;
226
- either one differentiates the content and the cache.
227
-
228
- The one exception is `intent_id`, the ad reference some ad landing URLs
229
- carry: when it's present, content is steered toward what that ad showed and
230
- cached for that ad alone. You don't need to do anything for this, and the
231
- call behaves the same either way.
232
-
233
- Practical consequences:
234
-
235
- - **The first render pays, repeats fly.** Expect a few seconds on a cache
236
- miss and near-instant responses after — shared across all anonymous
237
- traffic, per-shopper for identified traffic (the research underneath is
238
- cached briefly and shared, so even those misses are cheaper than cold).
239
- Design loading states for the miss case.
240
- - **Same call on different pages = different content**, automatically — the
241
- page path is in the key and in the AI's hints. A single site-wide snippet
242
- with a constant prompt yields per-page content for free.
243
- - **Content refreshes roughly daily.** Don't build experiences that assume
244
- minute-level freshness.
245
- - **To force different content, change the prompt or schema** (e.g. a
246
- campaign variant string that changes weekly — deliberate, low-cardinality
247
- variation is fine; per-visitor cardinality is not).
248
-
249
- The catalog research underneath is also cached briefly, so several distinct
250
- surfaces on the same page (different prompts/schemas) stay cheap even on
251
- cold cache.
252
-
253
- ## Errors and how to handle them
254
-
255
- The promise rejects with `new Error(message)`. The message is
256
- developer-facing — never render it to shoppers. Server-side failures also
257
- carry `error.code`, and a decline carries `error.reason`. Cases:
258
-
259
- | Case | Message you'll see | Retry? |
260
- |---|---|---|
261
- | Bad input (empty prompt, non-object schema) | thrown immediately by the SDK | Fix the call |
262
- | Invalid schema shape, or constraints no output could satisfy | `Invalid schema: …` | Fix the schema |
263
- | AI declined the request | `The assistant declined to generate content for this request.` with `error.reason` (below) | No — rework the prompt. `insufficient_data` alone can change as the catalog does. |
264
- | Output couldn't satisfy the schema | `Failed to produce valid structured content` | No — usually `required`/constraints demand data the catalog lacks. Loosen the schema. |
265
- | Rate limit (~20/min per IP address) | rate-limit message | Later — and consolidate calls |
266
- | Network / server | varies | Next page load |
267
-
268
- A decline is only ever one of these `error.reason` values — anything else
269
- (vague wording, missing data for optional fields, marketing copy) is served:
270
-
271
- | `reason` | Declined because the request… |
272
- |---|---|
273
- | `off_topic` | has nothing to do with the store or shopping there (homework, code, news, another business's products) |
274
- | `harmful` | asks for unsafe, hateful, sexual, or illegal content, or advice that could hurt someone |
275
- | `deceptive` | asks for fake reviews, invented discounts or scarcity, claims the catalog contradicts, or impersonating/disparaging a named brand or person |
276
- | `system_probe` | asks about or tries to override the assistant's own instructions or tools |
277
- | `insufficient_data` | needs store data that isn't there — the catalog doesn't carry what it's about, or nothing it needs could be found |
278
-
279
- The uniform shopper-facing strategy: render into a hidden-by-default
280
- container, reveal on success, leave hidden (or show your static fallback) on
281
- any rejection. One `try/catch`, no case analysis needed unless you're
282
- logging.
283
-
284
- ## Performance pattern
285
-
286
- Fire generation as early as possible without blocking render — top of your
287
- deferred script, before other work:
288
-
289
- ```js
290
- const highlightsPromise = window.GreatStore?.generateStructuredContent
291
- ? window.GreatStore.generateStructuredContent(schema, prompt).catch(() => null)
292
- : Promise.resolve(null);
293
-
294
- // …rest of page setup…
295
-
296
- const data = await highlightsPromise;
297
- if (data) renderHighlights(data);
298
- ```
299
-
300
- The `.catch(() => null)` attached immediately avoids unhandled-rejection
301
- noise while keeping a single render path.
302
-
303
- For multiple surfaces on one page, prefer **one call with a combined
304
- schema** over parallel calls — it's one research pass, one cache entry, and
305
- no rate-limit pressure:
306
-
307
- ```js
308
- const schema = {
309
- type: "object",
310
- properties: {
311
- highlights: { /* … */ },
312
- faq: { /* … */ },
313
- crossSell: { /* … */ },
314
- },
315
- required: ["highlights"],
316
- };
317
- ```