greatstore 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.
- package/CHANGELOG.md +16 -0
- package/README.md +7 -6
- package/dist/cli.js +97 -78
- package/dist/gs-skill/SKILL.md +4 -4
- package/dist/gs-skill/references/agents-and-mcp.md +7 -5
- package/dist/gs-skill/references/apps.md +38 -44
- package/dist/gs-skill/references/embed-api/call-tool.md +19 -6
- package/dist/gs-skill/references/embed-api/generate-structured-content.md +282 -12
- package/dist/gs-skill/references/embed-api/voice-call.md +19 -2
- package/dist/gs-skill/references/embed-api.md +1 -1
- package/dist/gs-skill/references/store-admin.md +8 -2
- package/package.json +1 -1
- package/dist/gs-skill/references/structured-content.md +0 -317
package/dist/gs-skill/SKILL.md
CHANGED
|
@@ -23,14 +23,14 @@ constraints) that the references spell out.
|
|
|
23
23
|
| Goal | Use | Read |
|
|
24
24
|
|---|---|---|
|
|
25
25
|
| Install the widget; control the panel; readiness, events, troubleshooting | `window.GreatStore` SDK | [references/embed-api.md](references/embed-api.md) |
|
|
26
|
-
| AI-generated, catalog-grounded content rendered in **your own HTML/CSS** (highlights, comparisons, FAQs, gift guides) | `generateStructuredContent(schema, prompt)` | [references/structured-content.md](references/structured-content.md) |
|
|
26
|
+
| AI-generated, catalog-grounded content rendered in **your own HTML/CSS** (highlights, comparisons, FAQs, gift guides) | `generateStructuredContent(schema, prompt)` | [references/embed-api/generate-structured-content.md](references/embed-api/generate-structured-content.md) |
|
|
27
27
|
| Contextual **conversation entry points** anywhere on the page | `sendMessage(text)`, `open()`, `?gs_chat=open` | [references/embed-api/send-message.md](references/embed-api/send-message.md) |
|
|
28
|
-
| Feed the assistant **invisible page/app state** (current product, cart, selected variant) | `updateModelContext(text)`; an app's `
|
|
29
|
-
| **Fetch store data into your own UI** from a connector's read-only tool,
|
|
28
|
+
| Feed the assistant **invisible page/app state** (current product, cart, selected variant) | `updateModelContext(text)`; an app's `$.updateModelContext` | [references/embed-api/update-model-context.md](references/embed-api/update-model-context.md), [references/apps.md](references/apps.md) |
|
|
29
|
+
| **Fetch store data into your own UI** from a connector's read-only tool, open a full-screen app from a button, or run a page tool || `callTool(name, args)`; an app's `$.callTool` | [references/embed-api/call-tool.md](references/embed-api/call-tool.md) |
|
|
30
30
|
| Let the assistant **act on the page** (cart, navigation, filters) | WebMCP: `document.modelContext.registerTool(...)` | [references/embed-api/webmcp.md](references/embed-api/webmcp.md) |
|
|
31
31
|
| Custom **interactive UI inside the chat** (configurators, quizzes, size guides, booking forms) | apps shipped with the `gs` CLI | [references/apps.md](references/apps.md) |
|
|
32
32
|
| Run one of those apps **on your own page**, outside the conversation | `surfaces: ["embed"]` + the container snippet | [references/apps.md](references/apps.md) |
|
|
33
|
-
| Expand an app's image in an **on-brand full-screen lightbox** | an app's
|
|
33
|
+
| Expand an app's image in an **on-brand full-screen lightbox** | an app's `$.showLightbox({ src, originRect })` | [references/apps.md](references/apps.md) |
|
|
34
34
|
| **Re-engage shoppers** with browser notifications | merchant-hosted `gs.js` + `enableNotifications()` | [references/push-notifications.md](references/push-notifications.md) |
|
|
35
35
|
| Connect **AI agents** to the store (shopping tools over MCP, CLI docs for coding agents) | the store's MCP endpoints | [references/agents-and-mcp.md](references/agents-and-mcp.md) |
|
|
36
36
|
| **Administer the store** — read config/connectors to ground decisions; self-serve origin allowlists and CSP hosts | `npx greatstore configure`, `npx greatstore connectors` | [references/store-admin.md](references/store-admin.md) |
|
|
@@ -22,14 +22,16 @@ works there too, with these differences:
|
|
|
22
22
|
theme: the same CSS variables (`--color-surface`, `--color-primary`,
|
|
23
23
|
`--font-primary`, …) are set from the host's look, so an app that reads
|
|
24
24
|
them instead of hardcoding colors fits in unchanged.
|
|
25
|
-
- `
|
|
26
|
-
`
|
|
25
|
+
- `$.sendMessage` posts a message as the shopper in the host's chat, and
|
|
26
|
+
`$.updateModelContext` updates what the host's assistant knows.
|
|
27
27
|
- `over-input` apps render in the conversation like `inline` ones;
|
|
28
|
-
`
|
|
28
|
+
`$.close` hides them.
|
|
29
29
|
- `fullscreen` apps show as a card the shopper can expand to the host's
|
|
30
|
-
full screen; `
|
|
30
|
+
full screen; `$.close` brings them back to the card.
|
|
31
31
|
- Links and `window.open` open through the host.
|
|
32
|
-
- `
|
|
32
|
+
- `$.callTool` always rejects there: an app can't fetch tool data or open
|
|
33
|
+
another app inside another assistant, so give it a path that works without.
|
|
34
|
+
- `$.generateStructuredContent` works there too, on the store's credits.
|
|
33
35
|
It isn't personalized: the store doesn't know who the shopper is inside
|
|
34
36
|
another assistant.
|
|
35
37
|
- An async app runs after the assistant's tool call has returned, so a thrown
|
|
@@ -30,7 +30,7 @@ Shopper Assistant Your app
|
|
|
30
30
|
│ │ your inputSchema asked │
|
|
31
31
|
│ │ for (productName, …) │
|
|
32
32
|
│ ├────────────────────────>│
|
|
33
|
-
│ │ ├──┐
|
|
33
|
+
│ │ ├──┐ $.generateStructured-
|
|
34
34
|
│ │ │ │ Content(): its own
|
|
35
35
|
│ │ │ │ catalog-grounded
|
|
36
36
|
│ │ │<─┘ generation, if wanted
|
|
@@ -44,10 +44,10 @@ Shopper Assistant Your app
|
|
|
44
44
|
│ picks size M │ │
|
|
45
45
|
├─────────────────────┼────────────────────────>│
|
|
46
46
|
│ │ │
|
|
47
|
-
│ │
|
|
47
|
+
│ │ $.updateModelContext() │ silent: the assistant
|
|
48
48
|
│ │<────────────────────────┤ now knows the pick
|
|
49
49
|
│ │ │
|
|
50
|
-
│ │
|
|
50
|
+
│ │ $.sendMessage() │ visible: a shopper turn
|
|
51
51
|
│ │<────────────────────────┤ happens right now
|
|
52
52
|
│ │ │
|
|
53
53
|
│ │ calls the app again │ same app, new props —
|
|
@@ -62,12 +62,12 @@ Four consequences worth designing around:
|
|
|
62
62
|
will actually pick](#writing-a-name-and-description-the-assistant-will-actually-pick)
|
|
63
63
|
is about that choice.
|
|
64
64
|
2. **Control is bidirectional once the app is up.** The app reports what the
|
|
65
|
-
shopper is doing (`
|
|
66
|
-
(`
|
|
65
|
+
shopper is doing (`$.updateModelContext`), can speak for the shopper
|
|
66
|
+
(`$.sendMessage`), and the assistant can call the app again with revised
|
|
67
67
|
props. Keep the render a function of the props it was given, so a re-call
|
|
68
68
|
is a re-render rather than a reset.
|
|
69
69
|
3. **The app can run its own generation, not just receive props.**
|
|
70
|
-
|
|
70
|
+
`$.generateStructuredContent(schema, prompt, fallback)` gives it a
|
|
71
71
|
catalog-grounded, shopper-personalized generation of its own, returned as
|
|
72
72
|
an object matching your schema — recommended picks, a personalized
|
|
73
73
|
summary, a reason per option — rendered in the merchant's own markup. Use
|
|
@@ -241,33 +241,36 @@ What to expect:
|
|
|
241
241
|
- If the app can't run — not published, not embeddable, or the store is
|
|
242
242
|
unavailable — the container is emptied and takes no space. The page looks as
|
|
243
243
|
though it was never there.
|
|
244
|
-
-
|
|
244
|
+
- `$.close()` takes the app off the page.
|
|
245
245
|
- The page's domain must be in the store's allowed domains, exactly as for
|
|
246
246
|
chat.
|
|
247
247
|
|
|
248
248
|
## The app contract
|
|
249
249
|
|
|
250
250
|
`component.tsx` default-exports a React component. Its props are the
|
|
251
|
-
`inputSchema` fields the assistant filled, plus
|
|
252
|
-
|
|
251
|
+
`inputSchema` fields the assistant filled, plus one GreatStore prop, `$`
|
|
252
|
+
(always present). Destructure what you need from `$` at the top of the
|
|
253
|
+
component. Never declare a `$` field in `inputSchema` — the build refuses it.
|
|
253
254
|
|
|
254
|
-
|
|
|
255
|
+
| `$` member | What it does |
|
|
255
256
|
|---|---|
|
|
256
|
-
|
|
|
257
|
-
|
|
|
258
|
-
|
|
|
259
|
-
|
|
|
260
|
-
|
|
|
261
|
-
|
|
|
262
|
-
| `
|
|
263
|
-
|
|
264
|
-
|
|
257
|
+
| `$.sendMessage(text)` | Send text into the chat as if the shopper typed it — lets the app drive the conversation ("Selected size M, what's the return policy?"). |
|
|
258
|
+
| `$.updateModelContext(context)` | Inject **invisible** background context for the model — the variant the shopper selected, the options they configured, the step they're on. Replaces the prior value (never appends); pass `""` to clear. Read on the next chat turn. Use this instead of `$.sendMessage` when the assistant should *know* state without a message appearing in the transcript. |
|
|
259
|
+
| `$.callTool(name, args?)` | The page's `window.GreatStore.callTool`, for the app: run one of the page's own WebMCP tools or a read-only connector tool and get its result, or open a full-screen app by name — see [embed-api/call-tool.md](embed-api/call-tool.md) for what it reaches, what comes back, and how to look up tools. Never touches the conversation. In the app preview, tools run for real and naming a full-screen app only logs what would open. Inside other AI assistants (ChatGPT, …) it always rejects — handle the rejection. |
|
|
260
|
+
| `$.showLightbox({ src, originRect? })` | Expand an image in the chat's shared full-screen lightbox — an on-brand zoom overlay you can't render yourself (your app is boxed inside its own bounds and shadow root). Pass the image `src`; for a smooth zoom, also pass the clicked element's `getBoundingClientRect()` as `originRect` (omit it and the image grows from the viewport centre). |
|
|
261
|
+
| `$.generateStructuredContent(schema, prompt, fallback)` | Ask the store's assistant for content matching a JSON Schema (or Zod schema) and get back the generated object. Personalized to the shopper. Works the same in the conversation on the storefront and every embed. Best for async apps that build their render from a generated payload. `fallback` is **required**: a schema-shaped object you provide that the app preview renders (no live store there), validated against the schema — a mismatch throws. |
|
|
262
|
+
| `$.close()` | Dismiss the host slot. `over-input` clears the overlay, `fullscreen` reverts the pane, `inline` is a no-op. |
|
|
263
|
+
| `$.useVoiceCall()` | A hook — call it at the top of your component like any other — returning `{ status, available, start, end }` for a voice call with the store's assistant. `start()` starts the call without opening the chat — it runs in the collapsed chat bar (which stays hidden if the store hides the chat until opened), and the chat opens only when the assistant shows an inline app (call it from a click; it rejects when the store has no voice), `end()` hangs up. `available` says whether the store has voice. `status` is `null` until a call starts, then `started`, `connecting`, `connected`, `listening` / `speaking` / `working` as the conversation goes, `disconnected` while the network drops (the call recovers on its own), and `ended` — or `rejected` instead of `ended` when the shopper refuses the microphone (calling `start()` again asks again, though a browser where they blocked it refuses without asking). Your app re-renders on every change. |
|
|
264
|
+
| `$.Image` | A drop-in for `<img>` — render `<Image src=… alt=… />` and the image is served at the right size for the store. Takes the same props as `<img>`. |
|
|
265
|
+
| `$.store` | `{ slug }` — the store the app is running in. |
|
|
266
|
+
|
|
267
|
+
Reach for `$.updateModelContext` when the shopper changes something inside
|
|
265
268
|
the app (picks a size, configures a build, advances a quiz) and you want the
|
|
266
269
|
assistant to factor it into the *next* thing they ask — without spamming the
|
|
267
|
-
chat with a visible "I selected M" message. Use `
|
|
270
|
+
chat with a visible "I selected M" message. Use `$.sendMessage` when you
|
|
268
271
|
actually want a turn to happen now.
|
|
269
272
|
|
|
270
|
-
Reach for `
|
|
273
|
+
Reach for `$.showLightbox` whenever your app shows imagery the shopper might
|
|
271
274
|
want to inspect closely — product photos, swatches, a size chart. A
|
|
272
275
|
thumbnail's `onClick` handler is the natural place to call it. Don't build
|
|
273
276
|
your own full-screen modal: an app is sandboxed inside its own bounds and
|
|
@@ -281,25 +284,16 @@ import React from "react";
|
|
|
281
284
|
interface Props {
|
|
282
285
|
productName: string;
|
|
283
286
|
category?: string;
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
fallback: T,
|
|
291
|
-
) => Promise<T>;
|
|
292
|
-
onClose: () => void;
|
|
293
|
-
Image: React.ElementType<React.ComponentProps<"img">>;
|
|
287
|
+
$: {
|
|
288
|
+
sendMessage: (text: string) => void;
|
|
289
|
+
updateModelContext: (context: string) => void;
|
|
290
|
+
showLightbox: (options: { src: string; originRect?: DOMRect }) => void;
|
|
291
|
+
Image: React.ElementType<React.ComponentProps<"img">>;
|
|
292
|
+
};
|
|
294
293
|
}
|
|
295
294
|
|
|
296
|
-
export default function SizeGuide({
|
|
297
|
-
|
|
298
|
-
onSendMessage,
|
|
299
|
-
onUpdateModelContext,
|
|
300
|
-
onShowLightbox,
|
|
301
|
-
Image,
|
|
302
|
-
}: Props) {
|
|
295
|
+
export default function SizeGuide({ productName, $ }: Props) {
|
|
296
|
+
const { sendMessage, updateModelContext, showLightbox, Image } = $;
|
|
303
297
|
return (
|
|
304
298
|
<div
|
|
305
299
|
style={{
|
|
@@ -317,7 +311,7 @@ export default function SizeGuide({
|
|
|
317
311
|
alt={`${productName} size chart`}
|
|
318
312
|
style={{ cursor: "zoom-in", width: "100%" }}
|
|
319
313
|
onClick={(e) =>
|
|
320
|
-
|
|
314
|
+
showLightbox({
|
|
321
315
|
src: `/size-charts/${productName}.png`,
|
|
322
316
|
originRect: e.currentTarget.getBoundingClientRect(),
|
|
323
317
|
})
|
|
@@ -327,12 +321,12 @@ export default function SizeGuide({
|
|
|
327
321
|
onClick={() =>
|
|
328
322
|
// Silent: the assistant now knows the pick for the shopper's
|
|
329
323
|
// next question, with nothing added to the transcript.
|
|
330
|
-
|
|
324
|
+
updateModelContext(`Shopper selected size M of "${productName}".`)
|
|
331
325
|
}
|
|
332
326
|
>
|
|
333
327
|
Select size M
|
|
334
328
|
</button>
|
|
335
|
-
<button onClick={() =>
|
|
329
|
+
<button onClick={() => sendMessage(`Size M of "${productName}" — is it in stock?`)}>
|
|
336
330
|
Ask about size M
|
|
337
331
|
</button>
|
|
338
332
|
</div>
|
|
@@ -390,9 +384,9 @@ export default async function Results(props: Props) {
|
|
|
390
384
|
## When to build an app vs. the other facets
|
|
391
385
|
|
|
392
386
|
- Content for the **merchant's page** → `window.GreatStore.generateStructuredContent`
|
|
393
|
-
([structured-content.md](structured-content.md)). Inside an app, use
|
|
394
|
-
|
|
395
|
-
|
|
387
|
+
([embed-api/generate-structured-content.md](embed-api/generate-structured-content.md)). Inside an app, use
|
|
388
|
+
`$.generateStructuredContent` instead — same idea, but personalized to the
|
|
389
|
+
shopper and available on every surface without the global.
|
|
396
390
|
- Letting the assistant **act on the page** → WebMCP page tools
|
|
397
391
|
([embed-api/webmcp.md](embed-api/webmcp.md)).
|
|
398
392
|
- Rich, interactive UI **inside the conversation itself**, available on the
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `callTool(name: string, args?: object): Promise<object | undefined>`
|
|
2
2
|
|
|
3
|
-
The page's own way to reach
|
|
3
|
+
The page's own way to reach three things by name, without the shopper asking
|
|
4
4
|
and without touching the conversation (nothing is added to the chat and the
|
|
5
5
|
assistant never learns the call happened).
|
|
6
6
|
|
|
@@ -16,6 +16,20 @@ page's, not the conversation's — a reload drops it. `inline` and
|
|
|
16
16
|
window.GreatStore.callTool("show_size_guide", { category: "boots" });
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
+
**A page tool.** Name a WebMCP tool the page registered once GreatStore was
|
|
20
|
+
ready (anything listed in `window.GreatStore.tools`) and it runs right there
|
|
21
|
+
on the page, resolving with the tool's result: `content`, plus
|
|
22
|
+
`structuredContent` when `execute` returned an object. Unlike a connector tool it may change state —
|
|
23
|
+
it is the page's own code. A page tool wins over an app or connector tool of
|
|
24
|
+
the same name, which is how a page overrides one for GreatStore alone.
|
|
25
|
+
|
|
26
|
+
```js
|
|
27
|
+
await window.GreatStore.callTool("add_to_cart", { variant_id: 123, quantity: 1 });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
`npx greatstore connectors tools webmcp --store my-store` lists the page
|
|
31
|
+
tools the store's pages have registered in recent chats.
|
|
32
|
+
|
|
19
33
|
**A read-only connector tool.** Name any read-only tool from the store's
|
|
20
34
|
connectors (Maker MCP or the merchant's own MCP servers) and it resolves
|
|
21
35
|
with the tool's MCP `tools/call` result exactly as the server returned it:
|
|
@@ -43,15 +57,14 @@ not when it doesn't. Trust that line over your own reading of the tool. It
|
|
|
43
57
|
also spells out every input: type, whether it's required, allowed values,
|
|
44
58
|
limits and description, nested fields included. Add `--json` for the raw input
|
|
45
59
|
schema. In short, only read-only tools the assistant itself can call are
|
|
46
|
-
reachable. A tool that changes state (cart, checkout) is refused
|
|
47
|
-
|
|
48
|
-
a name, the app wins. Before writing code against the
|
|
60
|
+
reachable. A connector tool that changes state (cart, checkout) is refused.
|
|
61
|
+
When an app and a connector tool share a name, the app wins. Before writing code against the
|
|
49
62
|
result, call the tool once from the browser console and read what comes back:
|
|
50
63
|
the result's shape is the connector's too, and the listing doesn't describe
|
|
51
64
|
it.
|
|
52
65
|
|
|
53
|
-
It rejects with an `Error` when the name is
|
|
54
|
-
full-screen or the args don't match its schema, when
|
|
66
|
+
It rejects with an `Error` when the name is none of these, when an app isn't
|
|
67
|
+
full-screen or the args don't match its schema, when a connector tool is not
|
|
55
68
|
read-only, when the tool answers with an error (the message is the tool's
|
|
56
69
|
own text), or when the server can't be reached. Loads the chat first if it
|
|
57
70
|
isn't up yet.
|
|
@@ -1,15 +1,285 @@
|
|
|
1
1
|
# `generateStructuredContent(schema: object, prompt: string): Promise<unknown>`
|
|
2
2
|
|
|
3
3
|
Generates JSON matching `schema` from `prompt`, grounded in the store's live
|
|
4
|
-
catalog
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
[
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
`
|
|
4
|
+
catalog, for UI the page renders itself — the chat panel is not involved.
|
|
5
|
+
Resolves to **the generated data object itself**. Rejects with an `Error` on
|
|
6
|
+
any failure (invalid input, decline, validation failure, rate limit,
|
|
7
|
+
network); see [Errors](#errors).
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const data = await window.GreatStore.generateStructuredContent(schema, prompt);
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
- `schema` — a JSON Schema object describing the output, or any object
|
|
14
|
+
exposing `.toJSONSchema()` (e.g. a Zod schema); the conversion is called
|
|
15
|
+
for you, and `.describe("…")` becomes the field's `description`.
|
|
16
|
+
- `prompt` — what to generate.
|
|
17
|
+
|
|
18
|
+
Rejects immediately if `prompt` is not a non-empty string or `schema` is not
|
|
19
|
+
an object.
|
|
20
|
+
|
|
21
|
+
## The rules that make it work well
|
|
22
|
+
|
|
23
|
+
Each is unpacked in the sections below; this is the checklist.
|
|
24
|
+
|
|
25
|
+
1. **Top level must be an object.** Want a list? Wrap it:
|
|
26
|
+
`{ type: "object", properties: { items: { type: "array", … } }, required: ["items"] }`.
|
|
27
|
+
2. **Steer the whole output with the prompt, single fields with
|
|
28
|
+
`description`.** Use self-explanatory property names (`benefitHeadline`,
|
|
29
|
+
not `text1`) and describe only where the name isn't enough.
|
|
30
|
+
3. **Only `require` what's guaranteed.** `required` is strictly enforced; if
|
|
31
|
+
the catalog can't ground a required field the whole call can fail. Require
|
|
32
|
+
structural fields, keep per-product details (image URLs, prices) optional,
|
|
33
|
+
and make rendering tolerate missing values.
|
|
34
|
+
4. **Point, don't paste.** GreatStore researches the store's live catalog on
|
|
35
|
+
its own — name the entity (`` `…the product "${productName}" (SKU ${sku})` ``)
|
|
36
|
+
and let it look the facts up. The one thing it *can't* see is your page,
|
|
37
|
+
so page-only context (which page the shopper is on, what the section is
|
|
38
|
+
for) does belong in the prompt.
|
|
39
|
+
5. **Research is bounded by the store's connectors — validate before you
|
|
40
|
+
build.** Ask for something no connector provides — currency conversion,
|
|
41
|
+
live shipping rates, review data the store never wired up — and it has
|
|
42
|
+
nothing to ground on, so it will decline, omit… or hallucinate. Run
|
|
43
|
+
`npx greatstore connectors` (and `npx greatstore connectors health`,
|
|
44
|
+
[store-admin.md](../store-admin.md)) first; if there's no connector for
|
|
45
|
+
it, don't ask for it.
|
|
46
|
+
6. **Responses are cached** for up to ~24h per page + prompt + schema. Keep
|
|
47
|
+
prompts deterministic per page — no timestamps, random values, or
|
|
48
|
+
per-visitor data.
|
|
49
|
+
7. **Progressive enhancement, always.** Generate after the page renders into
|
|
50
|
+
a hidden container, reveal on success, leave the fallback on error. Render
|
|
51
|
+
generated strings via `textContent`, never `innerHTML`.
|
|
52
|
+
8. **One rich call beats many small ones** — there's a per-IP rate limit
|
|
53
|
+
(~20 requests/minute); fetch multiple surfaces with one combined schema.
|
|
54
|
+
|
|
55
|
+
## What happens on a call
|
|
56
|
+
|
|
57
|
+
1. The SDK posts your schema + prompt to the store, along with the current
|
|
58
|
+
**page context**, sent automatically — you don't pass it, and you can't
|
|
59
|
+
override it:
|
|
60
|
+
- the page URL, **without its query string or fragment**;
|
|
61
|
+
- the page title;
|
|
62
|
+
- a small, length-capped subset of the page's schema.org JSON-LD
|
|
63
|
+
(`Product`, `ProductGroup`, `Offer`, `Article`, `WebPage`, `FAQPage`,
|
|
64
|
+
`AggregateRating`). For products that's identifiers only — name,
|
|
65
|
+
brand, SKU, GTIN, URL — so emitting product JSON-LD is the most
|
|
66
|
+
reliable way to tell GreatStore exactly which product the page is
|
|
67
|
+
about.
|
|
68
|
+
2. GreatStore **researches** the store's live catalog (products, prices,
|
|
69
|
+
availability, store info) using read-only lookups. The page context only
|
|
70
|
+
hints at which product or category to look up — it is *not* a source of
|
|
71
|
+
product data, and nothing else on the page (visible text, reviews, your
|
|
72
|
+
markup) is read. Its reach is exactly the store's MCP connectors.
|
|
73
|
+
3. The AI fills your schema from the researched data under a strict
|
|
74
|
+
grounding contract: it must not invent product names, prices, images, IDs,
|
|
75
|
+
or descriptions. Fields it can't ground are omitted or `null`. For an
|
|
76
|
+
identified shopper it also sees their shopper profile — the same identity
|
|
77
|
+
the chat assistant has — so the output can be subtly personalized without
|
|
78
|
+
you passing anything about the visitor.
|
|
79
|
+
4. The output is validated against your schema (with internal retries)
|
|
80
|
+
before being returned and cached.
|
|
81
|
+
|
|
82
|
+
Because GreatStore already knows who's reading, never put shopper data in
|
|
83
|
+
the prompt — it's redundant, and it poisons the cache key.
|
|
84
|
+
|
|
85
|
+
## Schema support
|
|
86
|
+
|
|
87
|
+
Top level **must describe an object**: `type: "object"` (or a bare
|
|
88
|
+
`properties` / `anyOf`).
|
|
89
|
+
|
|
90
|
+
Supported keywords (anything else is tolerated but ignored):
|
|
91
|
+
|
|
92
|
+
- Types: `object`, `array`, `string`, `number`, `integer`, `boolean`, `null`
|
|
93
|
+
- Structure: `properties`, `required`, `items`, `additionalProperties`
|
|
94
|
+
- Choice: `enum`, `const`, `anyOf`, `nullable`
|
|
95
|
+
- Constraints: `minimum`, `maximum`, `minLength`, `maxLength`, `minItems`,
|
|
96
|
+
`maxItems`, `pattern`, `format`, `default`
|
|
97
|
+
- Guidance: `description`, `example`, `title` (on any property)
|
|
98
|
+
|
|
99
|
+
Validation of the output is real: `required` is enforced, `enum`/`const`
|
|
100
|
+
must match, numeric and length bounds are checked, and
|
|
101
|
+
`additionalProperties: false` rejects extra keys. Constraints are therefore a
|
|
102
|
+
*tool* — `enum` reliably restricts a field — but every constraint is also a
|
|
103
|
+
way for generation to fail, so apply them only where you'd rather have no
|
|
104
|
+
content than non-conforming content.
|
|
105
|
+
|
|
106
|
+
Item counts are the exception. `minItems` is honored as the content is
|
|
107
|
+
written, so a list comes back with at least that many entries, and a list
|
|
108
|
+
longer than `maxItems` is cut to its first `maxItems` entries rather than
|
|
109
|
+
failing. The same applies to an app's `inputSchema`.
|
|
110
|
+
|
|
111
|
+
### Field descriptions
|
|
112
|
+
|
|
113
|
+
A property's `description` is shown to the AI as guidance for that one
|
|
114
|
+
field, and an `example` shows the exact shape you want (`"4.5 out of 5"`,
|
|
115
|
+
`"SKU-1234"`). Both are optional: a field without them is filled from its
|
|
116
|
+
name, the prompt, and its constraints.
|
|
117
|
+
|
|
118
|
+
```js
|
|
119
|
+
{
|
|
120
|
+
type: "object",
|
|
121
|
+
properties: {
|
|
122
|
+
headline: { type: "string", maxLength: 60 },
|
|
123
|
+
priceJustification: {
|
|
124
|
+
type: "string",
|
|
125
|
+
description: "One sentence on why the price is fair, citing a real material or feature",
|
|
126
|
+
},
|
|
127
|
+
rating: { type: "string", example: "4.5 out of 5" },
|
|
128
|
+
},
|
|
129
|
+
required: ["headline"],
|
|
130
|
+
}
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
Split the work between the two channels:
|
|
134
|
+
|
|
135
|
+
- **Prompt** — the situation, the task as a whole, grounding, and voice.
|
|
136
|
+
- **`description` / `example`** — what one specific field holds: its unit,
|
|
137
|
+
length in words, perspective ("first-person, as the shopper"), or how it
|
|
138
|
+
relates to a sibling.
|
|
139
|
+
- Property *names* still carry most of the intent — make them
|
|
140
|
+
self-documenting (`ctaLabel`, `warmthRating`, `priceJustification`) and
|
|
141
|
+
reach for a description when the name can't say it.
|
|
142
|
+
|
|
143
|
+
## Prompting
|
|
144
|
+
|
|
145
|
+
A good prompt states, in order:
|
|
146
|
+
|
|
147
|
+
1. **Context** — what page/situation the shopper is in, naming the entity so
|
|
148
|
+
research targets the right thing (the AI can't see your DOM):
|
|
149
|
+
`The shopper is viewing the product "Aurora Down Parka" (SKU AUR-021) on its product page.`
|
|
150
|
+
2. **Task** — what to generate, mapped loosely onto your schema's fields:
|
|
151
|
+
`Write a heading and 3 reasons to love it; each reason has a short title and one supporting sentence.`
|
|
152
|
+
3. **Grounding expectations** — what store data to draw on:
|
|
153
|
+
`Base every claim on the product's real materials, features, and price.`
|
|
154
|
+
4. **Voice** — tone and constraints:
|
|
155
|
+
`Warm and concrete. No exclamation marks, no generic marketing filler.`
|
|
156
|
+
|
|
157
|
+
Note what's *not* in that prompt: no pasted specs, prices, or descriptions.
|
|
158
|
+
Pointing at the SKU is enough, and the data research finds is live rather
|
|
159
|
+
than whatever was true when you wrote the prompt.
|
|
160
|
+
|
|
161
|
+
Anti-patterns:
|
|
162
|
+
|
|
163
|
+
- **Pasting researched material into the prompt** (specs, prices,
|
|
164
|
+
descriptions fetched from your platform's API). Pasted facts go stale,
|
|
165
|
+
bloat the cache key, and compete with the fresher data research returns.
|
|
166
|
+
- **Per-visitor or per-moment data in the prompt** (names, cart contents,
|
|
167
|
+
timestamps, `Math.random()`): destroys caching, so every visitor pays full
|
|
168
|
+
generation latency and the store pays for every call — and it's redundant,
|
|
169
|
+
because identified shoppers are personalized for server-side. For
|
|
170
|
+
per-shopper *interaction*, use [`sendMessage`](send-message.md) and the
|
|
171
|
+
chat panel.
|
|
172
|
+
- **Asking for data no connector provides** ("convert the price to EUR",
|
|
173
|
+
"estimate delivery to the shopper's city"): the AI may hallucinate
|
|
174
|
+
plausible-looking values rather than leave the field empty.
|
|
175
|
+
- **Asking it to read the page** ("summarize the reviews shown below") — it
|
|
176
|
+
can't. Page-only data (review snippets, UGC, things that exist nowhere but
|
|
177
|
+
the DOM) is the one kind worth inlining — keep it stable per page so
|
|
178
|
+
caching still works.
|
|
179
|
+
- **Asking for minute-fresh operational data** (exact live stock counts,
|
|
180
|
+
delivery countdowns). Even when a connector could answer, responses cache
|
|
181
|
+
for up to ~24h — display operational data from your own platform APIs and
|
|
182
|
+
use GreatStore for *editorial intelligence over the catalog*.
|
|
183
|
+
- **Putting whole-output instructions in a field's `description`** (voice,
|
|
184
|
+
grounding, what the page is) — they belong in the prompt, where they apply
|
|
185
|
+
to every field.
|
|
186
|
+
|
|
187
|
+
## Caching
|
|
188
|
+
|
|
189
|
+
Responses are cached server-side for up to **24 hours**, keyed by page
|
|
190
|
+
context (URL path, title, JSON-LD identifiers) + prompt + schema. Anonymous
|
|
191
|
+
visitors share one entry per key; identified shoppers each get their own
|
|
192
|
+
(their output may be personalized, so it's only ever served back to them).
|
|
193
|
+
|
|
194
|
+
**The query string and fragment never reach GreatStore.** `/product?id=123`
|
|
195
|
+
and `/product?id=456` are the same page to it — same hints, same cache entry.
|
|
196
|
+
If your page picks its product from a query param, name that product in the
|
|
197
|
+
prompt (`` `…the product "${name}" (SKU ${sku})` ``), or emit JSON-LD for it;
|
|
198
|
+
either one differentiates the content and the cache.
|
|
199
|
+
|
|
200
|
+
The one exception is `intent_id`, the ad reference some ad landing URLs
|
|
201
|
+
carry: when it's present, content is steered toward what that ad showed and
|
|
202
|
+
cached for that ad alone. You don't need to do anything for this, and the
|
|
203
|
+
call behaves the same either way.
|
|
204
|
+
|
|
205
|
+
Practical consequences:
|
|
206
|
+
|
|
207
|
+
- **The first render pays, repeats fly.** Expect a few seconds on a cache
|
|
208
|
+
miss and near-instant responses after. The catalog research underneath is
|
|
209
|
+
also cached briefly and shared, so even misses — and several distinct
|
|
210
|
+
surfaces on one page — are cheaper than cold. Design loading states for
|
|
211
|
+
the miss case.
|
|
212
|
+
- **Same call on different pages = different content**, automatically — the
|
|
213
|
+
page path is in the key and in the AI's hints. A single site-wide snippet
|
|
214
|
+
with a constant prompt yields per-page content for free.
|
|
215
|
+
- **Content refreshes roughly daily.** Don't build experiences that assume
|
|
216
|
+
minute-level freshness.
|
|
217
|
+
- **To force different content, change the prompt or schema** (e.g. a
|
|
218
|
+
campaign variant string that changes weekly — deliberate, low-cardinality
|
|
219
|
+
variation is fine; per-visitor cardinality is not).
|
|
220
|
+
|
|
221
|
+
## Errors
|
|
222
|
+
|
|
223
|
+
The promise rejects with `new Error(message)`. The message is
|
|
224
|
+
developer-facing — never render it to shoppers. Server-side failures also
|
|
225
|
+
carry `error.code`, and a decline carries `error.reason`.
|
|
226
|
+
|
|
227
|
+
| Case | Message you'll see | Retry? |
|
|
228
|
+
|---|---|---|
|
|
229
|
+
| Bad input (empty prompt, non-object schema) | rejected immediately by the SDK | Fix the call |
|
|
230
|
+
| Invalid schema shape, or constraints no output could satisfy | `Invalid schema: …` | Fix the schema |
|
|
231
|
+
| 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. |
|
|
232
|
+
| Output couldn't satisfy the schema | `Failed to produce valid structured content` | No — usually `required`/constraints demand data the catalog lacks. Loosen the schema. |
|
|
233
|
+
| Rate limit (~20/min per IP address) | rate-limit message | Later — and consolidate calls |
|
|
234
|
+
| Network / server | varies | Next page load |
|
|
235
|
+
|
|
236
|
+
A decline is only ever one of these `error.reason` values — anything else
|
|
237
|
+
(vague wording, missing data for optional fields, marketing copy) is served:
|
|
238
|
+
|
|
239
|
+
| `reason` | Declined because the request… |
|
|
240
|
+
|---|---|
|
|
241
|
+
| `off_topic` | has nothing to do with the store or shopping there (homework, code, news, another business's products) |
|
|
242
|
+
| `harmful` | asks for unsafe, hateful, sexual, or illegal content, or advice that could hurt someone |
|
|
243
|
+
| `deceptive` | asks for fake reviews, invented discounts or scarcity, claims the catalog contradicts, or impersonating/disparaging a named brand or person |
|
|
244
|
+
| `system_probe` | asks about or tries to override the assistant's own instructions or tools |
|
|
245
|
+
| `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 |
|
|
246
|
+
|
|
247
|
+
The uniform shopper-facing strategy: render into a hidden-by-default
|
|
248
|
+
container, reveal on success, leave hidden (or show your static fallback) on
|
|
249
|
+
any rejection. One `try/catch`, no case analysis needed unless you're
|
|
250
|
+
logging.
|
|
251
|
+
|
|
252
|
+
## Performance pattern
|
|
253
|
+
|
|
254
|
+
Fire generation as early as possible without blocking render — top of your
|
|
255
|
+
deferred script, before other work:
|
|
256
|
+
|
|
257
|
+
```js
|
|
258
|
+
const highlightsPromise = window.GreatStore?.generateStructuredContent
|
|
259
|
+
? window.GreatStore.generateStructuredContent(schema, prompt).catch(() => null)
|
|
260
|
+
: Promise.resolve(null);
|
|
261
|
+
|
|
262
|
+
// …rest of page setup…
|
|
263
|
+
|
|
264
|
+
const data = await highlightsPromise;
|
|
265
|
+
if (data) renderHighlights(data);
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
The `.catch(() => null)` attached immediately avoids unhandled-rejection
|
|
269
|
+
noise while keeping a single render path.
|
|
270
|
+
|
|
271
|
+
For multiple surfaces on one page, prefer **one call with a combined
|
|
272
|
+
schema** over parallel calls — it's one research pass, one cache entry, and
|
|
273
|
+
no rate-limit pressure:
|
|
274
|
+
|
|
275
|
+
```js
|
|
276
|
+
const schema = {
|
|
277
|
+
type: "object",
|
|
278
|
+
properties: {
|
|
279
|
+
highlights: { /* … */ },
|
|
280
|
+
faq: { /* … */ },
|
|
281
|
+
crossSell: { /* … */ },
|
|
282
|
+
},
|
|
283
|
+
required: ["highlights"],
|
|
284
|
+
};
|
|
285
|
+
```
|
|
@@ -24,16 +24,33 @@ receives the status) and as a `greatstore:voicestatus` event on `window`
|
|
|
24
24
|
| `speaking` | The assistant is talking. |
|
|
25
25
|
| `working` | The assistant is thinking or looking something up. |
|
|
26
26
|
| `disconnected` | The shopper's network dropped mid-call. The call recovers on its own, back to `listening`. |
|
|
27
|
-
| `ended` | The call is over — hung up, ended by the assistant,
|
|
27
|
+
| `ended` | The call is over — hung up, ended by the assistant, or failed. |
|
|
28
|
+
| `rejected` | The shopper refused the microphone, so the call never connected. Comes in place of `ended`. |
|
|
29
|
+
|
|
30
|
+
Every call finishes on exactly one of `ended` or `rejected`.
|
|
31
|
+
|
|
32
|
+
Use `rejected` to tell the shopper why nothing happened. Calling
|
|
33
|
+
`startVoiceCall()` again asks for the microphone again, but whether the shopper
|
|
34
|
+
sees the prompt is up to the browser: once they've blocked the microphone for
|
|
35
|
+
the site, the browser refuses without asking (and `rejected` fires again) until
|
|
36
|
+
they allow it in the browser's site settings. A prompt the shopper only closed
|
|
37
|
+
usually comes back.
|
|
28
38
|
|
|
29
39
|
```js
|
|
30
40
|
const callButton = document.querySelector("#talk");
|
|
41
|
+
const micNote = document.querySelector("#mic-note");
|
|
31
42
|
callButton.addEventListener("click", () => {
|
|
32
43
|
if (callButton.dataset.live) window.GreatStore.endVoiceCall();
|
|
33
44
|
else window.GreatStore.startVoiceCall().catch(() => (callButton.hidden = true));
|
|
34
45
|
});
|
|
35
46
|
window.addEventListener("greatstore:voicestatus", (event) => {
|
|
36
|
-
const
|
|
47
|
+
const { status } = event.detail;
|
|
48
|
+
if (status === "rejected") {
|
|
49
|
+
micNote.textContent = "Allow microphone access in your browser to talk to us.";
|
|
50
|
+
} else if (status === "started") {
|
|
51
|
+
micNote.textContent = "";
|
|
52
|
+
}
|
|
53
|
+
const live = status !== "ended" && status !== "rejected";
|
|
37
54
|
callButton.dataset.live = live ? "1" : "";
|
|
38
55
|
callButton.textContent = live ? "Hang up" : "Talk to us";
|
|
39
56
|
});
|
|
@@ -112,7 +112,7 @@ and replay in order.
|
|
|
112
112
|
| `load()`, `open()`, `close()`, `toggle()`, `destroy()` | Pre-warm, show, hide, or tear down the chat panel. | [embed-api/panel.md](embed-api/panel.md) |
|
|
113
113
|
| `sendMessage(text)` | Send a visible message as the shopper and open the panel — a conversation entry point from any element. | [embed-api/send-message.md](embed-api/send-message.md) |
|
|
114
114
|
| `updateModelContext(text)` | Give the assistant invisible background context about the page (product, cart, account). | [embed-api/update-model-context.md](embed-api/update-model-context.md) |
|
|
115
|
-
| `callTool(name, args)` |
|
|
115
|
+
| `callTool(name, args)` | Run one of the page's own WebMCP tools, open a full-screen app from the page, or fetch data from a connector's read-only tool. | [embed-api/call-tool.md](embed-api/call-tool.md) |
|
|
116
116
|
| `on(event, handler)` | Subscribe to panel and voice events. | [embed-api/events.md](embed-api/events.md) |
|
|
117
117
|
| `startVoiceCall()`, `endVoiceCall()` | Start or hang up a voice call without opening the chat. | [embed-api/voice-call.md](embed-api/voice-call.md) |
|
|
118
118
|
| `generateStructuredContent(schema, prompt)` | Generate catalog-grounded JSON for the page's own UI. | [embed-api/generate-structured-content.md](embed-api/generate-structured-content.md) |
|