greatstore 0.0.0-stage → 0.2.3

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.
@@ -0,0 +1,35 @@
1
+ # AI agents and the store's MCP endpoint
2
+
3
+ Every GreatStore store publishes a standard MCP server card, and the
4
+ platform runs one MCP endpoint for coding agents — no authentication
5
+ required for either:
6
+
7
+ | URL | What it is |
8
+ |---|---|
9
+ | `https://<slug>.greatstore.ai/.well-known/mcp/server-card.json` | Standard MCP server card — machine-readable discovery document for the store. |
10
+ | `https://admin.greatstore.ai/mcp` | A **documentation server for coding agents**: its tools return usage docs for the `gs` CLI. Same URL for every store. |
11
+
12
+ ## CLI docs for coding agents — `/mcp`
13
+
14
+ A stateless HTTP MCP whose tools hand back markdown documentation for `gs`
15
+ CLI commands.
16
+
17
+ ```
18
+ claude mcp add --transport http greatstore-admin https://admin.greatstore.ai/mcp
19
+ ```
20
+
21
+ Useful when a coding agent is shipping apps
22
+ ([apps.md](apps.md)) and needs the exact command for
23
+ the next step. If this skill is installed, the agent already has the
24
+ workflow — the MCP is the self-serve alternative for agents that don't.
25
+
26
+ ## What to use when
27
+
28
+ - **Building the merchant's site** → this skill's other references (the SDK,
29
+ structured content, page tools).
30
+ - **A coding agent shipping apps** → the `gs` CLI, with `/mcp`
31
+ as its built-in documentation.
32
+ - **Reading or changing store settings** (origin allowlists, CSP hosts, MCP
33
+ connectors, brand config) → the `gs` CLI's admin commands —
34
+ [store-admin.md](store-admin.md), including which changes are safe to make
35
+ without asking the merchant.
@@ -0,0 +1,339 @@
1
+ # Apps — authoring custom in-chat UI with the `gs` CLI
2
+
3
+ An app is interactive UI the assistant renders **inside the conversation** —
4
+ product configurators, quizzes, size guides, booking forms, anything richer
5
+ than text. You write it in React; GreatStore bundles it and serves it to
6
+ every surface the store's assistant runs on.
7
+
8
+ Each app is an AI-callable tool: the manifest's `description` tells the
9
+ assistant *when* to reach for it, its `inputSchema` declares the props the
10
+ assistant fills in, and a `displayMode` picks where it appears.
11
+
12
+ Authoring requires store-owner access (`npx greatstore login` signs in with the store
13
+ owner's account).
14
+
15
+ ## How an app actually runs
16
+
17
+ An app is not a page the shopper navigates to. It is a tool the assistant
18
+ calls mid-conversation, and once it is on screen it can talk back — which is
19
+ the part that makes apps worth building.
20
+
21
+ ```
22
+ Shopper Assistant Your app
23
+ │ │ │
24
+ │ "what size am I?" │ │
25
+ ├────────────────────>│ │
26
+ │ │ picks the app by its │
27
+ │ │ name + description │
28
+ │ │ │
29
+ │ │ calls it with props │
30
+ │ │ your inputSchema asked │
31
+ │ │ for (productName, …) │
32
+ │ ├────────────────────────>│
33
+ │ │ ├──┐ onGenerateStructured-
34
+ │ │ │ │ Content(): its own
35
+ │ │ │ │ catalog-grounded
36
+ │ │ │<─┘ generation, if wanted
37
+ │ │ │
38
+ │ │ │ renders the moment your
39
+ │ │ │ happy path has what it
40
+ │ │ │ needs (async: after your
41
+ │<────────────────────┼─────────────────────────┤ promise resolves)
42
+ │ sees the app │ │
43
+ │ │ │
44
+ │ picks size M │ │
45
+ ├─────────────────────┼────────────────────────>│
46
+ │ │ │
47
+ │ │ onUpdateModelContext() │ silent: the assistant
48
+ │ │<────────────────────────┤ now knows the pick
49
+ │ │ │
50
+ │ │ onSendMessage() │ visible: a shopper turn
51
+ │ │<────────────────────────┤ happens right now
52
+ │ │ │
53
+ │ │ calls the app again │ same app, new props —
54
+ │ ├────────────────────────>│ re-rendered in place
55
+ │ │ │
56
+ ```
57
+
58
+ Four consequences worth designing around:
59
+
60
+ 1. **The assistant chooses the app, so the manifest is the interface it
61
+ sees.** Everything under [Writing a `name` and `description` the assistant
62
+ will actually pick](#writing-a-name-and-description-the-assistant-will-actually-pick)
63
+ is about that choice.
64
+ 2. **Control is bidirectional once the app is up.** The app reports what the
65
+ shopper is doing (`onUpdateModelContext`), can speak for the shopper
66
+ (`onSendMessage`), and the assistant can call the app again with revised
67
+ props. Keep the render a function of the props it was given, so a re-call
68
+ is a re-render rather than a reset.
69
+ 3. **The app can run its own generation, not just receive props.**
70
+ `onGenerateStructuredContent(schema, prompt, fallback)` gives it a
71
+ catalog-grounded, shopper-personalized generation of its own, returned as
72
+ an object matching your schema — recommended picks, a personalized
73
+ summary, a reason per option — rendered in the merchant's own markup. Use
74
+ it when the app needs content the assistant didn't (and shouldn't have to)
75
+ pass as props.
76
+ 4. **Render on the happy path, not on a shell.** Whatever the app needs to be
77
+ correct — props, or awaited data in an async app, including a generation
78
+ of its own — should be there before anything paints; GreatStore owns the
79
+ loading state.
80
+
81
+ ## Workflow
82
+
83
+ ```
84
+ npx greatstore login # browser sign-in
85
+ npx greatstore apps init --store my-store # scaffold a project root
86
+ cd <project> && npm install
87
+ npx greatstore apps init size_guide # scaffold components/size_guide/
88
+ # … edit components/size_guide/{component.tsx,manifest.json} …
89
+ npx greatstore apps build # bundle every app
90
+ npx greatstore apps push # upload changed apps as drafts
91
+ npx greatstore apps publish size_guide # promote to live
92
+ ```
93
+
94
+ `npx greatstore apps list` shows what's deployed (with dashboard links); `npx greatstore apps pull`
95
+ round-trips live apps back to disk. `npx greatstore apps push` hashes apps and only
96
+ uploads what changed. (The subcommands also work at the top level —
97
+ `npx greatstore push` == `npx greatstore apps push`.) On disk each app is a folder under
98
+ `components/`, holding `manifest.json` and `component.tsx`.
99
+
100
+ The scaffold writes an `AGENTS.md` into the project (with `CLAUDE.md` /
101
+ `GEMINI.md` symlinked) containing the complete design rules and brand
102
+ variable table — your coding agent picks it up automatically when working in
103
+ the project. `https://admin.greatstore.ai/mcp` serves the same CLI docs to
104
+ agents over MCP (see [agents-and-mcp.md](agents-and-mcp.md)).
105
+
106
+ ## `manifest.json`
107
+
108
+ ```json
109
+ {
110
+ "name": "size_guide",
111
+ "displayName": "Size guide",
112
+ "description": "Use when a shopper is unsure which size to buy, asks how an item fits, or compares their usual size across brands. Turns fit questions into a confident size choice, and reports the size they settle on back to you.",
113
+ "displayMode": "inline",
114
+ "inputSchema": {
115
+ "type": "object",
116
+ "properties": {
117
+ "productName": { "type": "string" },
118
+ "category": { "type": "string" }
119
+ },
120
+ "required": ["productName"]
121
+ }
122
+ }
123
+ ```
124
+
125
+ | Field | Meaning |
126
+ |---|---|
127
+ | `name` | Tool name, snake_case (`^[a-z][a-z0-9_]*$`), matches the folder under `components/`. |
128
+ | `displayName` | Friendly label shown in chat UI — the only field written for the shopper. |
129
+ | `description` | **Load-bearing** — the assistant's sole basis for choosing this app. See below. |
130
+ | `displayMode` | Where it renders — see below. |
131
+ | `inputSchema` | JSON Schema for the props the assistant fills. Keep it tight; required fields the AI can't infer cause bad calls. |
132
+ | `async` | Set `true` for backend-backed apps (see Async below). |
133
+
134
+ ### Writing a `name` and `description` the assistant will actually pick
135
+
136
+ The assistant never sees your app. It sees a name and a sentence, next to
137
+ every other tool it has, and picks one. So write the description for the
138
+ *caller*, answering one question: **when should I reach for this, and what do
139
+ I get back?**
140
+
141
+ **Describing the UI is the most common mistake.** Layout, sliders, tabs,
142
+ carousels and colors are the shopper's concern. To the assistant they are
143
+ noise — they say nothing about when to call the tool, and a description made
144
+ of them leaves it guessing.
145
+
146
+ | Don't | Do |
147
+ |---|---|
148
+ | "Renders a two-column table of measurements with a unit toggle." | "Use when a shopper is unsure which size to buy or asks how an item fits." |
149
+ | "A carousel of product cards with images and prices." | "Use to show 2–8 specific products you have already chosen, when the shopper wants to see them side by side before deciding." |
150
+ | "Modal with a multi-step form and a progress bar." | "Use when the shopper wants a gift but can't say what — collects budget, recipient and occasion, then reports them back so you can recommend." |
151
+ | "Beautiful, responsive, mobile-friendly booking widget." | "Use when the shopper asks to book, reschedule or check availability for an in-store appointment." |
152
+
153
+ What belongs in a description, in this order:
154
+
155
+ 1. **The trigger** — the shopper situation or intent, in the words a shopper
156
+ would actually use ("unsure which size", "wants to compare", "asks to
157
+ book"). Start with `Use when …`.
158
+ 2. **The boundary** — when *not* to, if a sibling tool overlaps. One clause
159
+ is enough: "Use for in-store appointments; not for delivery scheduling."
160
+ 3. **What the assistant gets back** — if the app reports state or sends
161
+ messages, say so, because that changes whether calling it is useful:
162
+ "reports the size the shopper settles on back to you."
163
+
164
+ Keep it to one or two sentences. If a required prop is subtle, say what it
165
+ means here rather than trusting the schema alone ("`category` is the apparel
166
+ category, e.g. `outerwear`").
167
+
168
+ The same rule governs the **name**: name it after the job, not the widget.
169
+ `size_guide`, `gift_finder`, `book_appointment` read as intents; `size_modal`,
170
+ `quiz_ui`, `product_grid_v2` read as implementation details and get skipped.
171
+ Names also compete — if an upstream tool already does the shopper-facing job,
172
+ name yours for the distinct thing it does (`show_catalog_inline` alongside
173
+ `show_catalog`) so the assistant has a real choice rather than a coin flip.
174
+
175
+ ### Display modes
176
+
177
+ - `inline` — a bubble inside the chat transcript; persists with the message
178
+ log.
179
+ - `over-input` — floats above the chat input (like a question overlay);
180
+ cleared by the next user turn or an explicit close.
181
+ - `fullscreen` — takes over the full preview surface; persists until the
182
+ next widget-emitting tool call or an explicit close.
183
+
184
+ **Safe-zone for `fullscreen` apps.** The floating chat widget sits over the
185
+ bottom of a fullscreen app, covering whatever is rendered there. Leave
186
+ `6.25em` (100px at the default font size) of bottom padding on the app's
187
+ scrolling content so everything can be scrolled clear of it.
188
+
189
+ ## The app contract
190
+
191
+ `component.tsx` default-exports a React component. Its props are the
192
+ `inputSchema` fields the assistant filled, plus six GreatStore-injected
193
+ lifecycle props (always present):
194
+
195
+ | Prop | What it does |
196
+ |---|---|
197
+ | `onSendMessage(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?"). |
198
+ | `onUpdateModelContext(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 `onSendMessage` when the assistant should *know* state without a message appearing in the transcript. |
199
+ | `onShowLightbox({ 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). |
200
+ | `onGenerateStructuredContent(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 — no `window.GreatStore` needed. 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. |
201
+ | `onClose()` | Dismiss the host slot. `over-input` clears the overlay, `fullscreen` reverts the pane, `inline` is a no-op. |
202
+ | `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>`. |
203
+
204
+ Reach for `onUpdateModelContext` when the shopper changes something inside
205
+ the app (picks a size, configures a build, advances a quiz) and you want the
206
+ assistant to factor it into the *next* thing they ask — without spamming the
207
+ chat with a visible "I selected M" message. Use `onSendMessage` when you
208
+ actually want a turn to happen now.
209
+
210
+ Reach for `onShowLightbox` whenever your app shows imagery the shopper might
211
+ want to inspect closely — product photos, swatches, a size chart. A
212
+ thumbnail's `onClick` handler is the natural place to call it. Don't build
213
+ your own full-screen modal: an app is sandboxed inside its own bounds and
214
+ shadow root, so a self-rendered overlay can't cover the chat. The shared
215
+ lightbox escapes those bounds and themes itself from the store's CSS
216
+ variables.
217
+
218
+ ```tsx
219
+ import React from "react";
220
+
221
+ interface Props {
222
+ productName: string;
223
+ category?: string;
224
+ onSendMessage: (text: string) => void;
225
+ onUpdateModelContext: (context: string) => void;
226
+ onShowLightbox: (options: { src: string; originRect?: DOMRect }) => void;
227
+ onGenerateStructuredContent: <T = unknown>(
228
+ schema: object,
229
+ prompt: string,
230
+ fallback: T,
231
+ ) => Promise<T>;
232
+ onClose: () => void;
233
+ Image: React.ElementType<React.ComponentProps<"img">>;
234
+ }
235
+
236
+ export default function SizeGuide({
237
+ productName,
238
+ onSendMessage,
239
+ onUpdateModelContext,
240
+ onShowLightbox,
241
+ Image,
242
+ }: Props) {
243
+ return (
244
+ <div
245
+ style={{
246
+ padding: "1em",
247
+ border: "1px solid var(--color-border-default)",
248
+ borderRadius: "var(--radius-lg)",
249
+ background: "var(--color-surface)",
250
+ color: "var(--color-foreground)",
251
+ fontFamily: "var(--font-primary)",
252
+ }}
253
+ >
254
+ {/* … sizes for {productName} … */}
255
+ <Image
256
+ src={`/size-charts/${productName}.png`}
257
+ alt={`${productName} size chart`}
258
+ style={{ cursor: "zoom-in", width: "100%" }}
259
+ onClick={(e) =>
260
+ onShowLightbox({
261
+ src: `/size-charts/${productName}.png`,
262
+ originRect: e.currentTarget.getBoundingClientRect(),
263
+ })
264
+ }
265
+ />
266
+ <button
267
+ onClick={() =>
268
+ // Silent: the assistant now knows the pick for the shopper's
269
+ // next question, with nothing added to the transcript.
270
+ onUpdateModelContext(`Shopper selected size M of "${productName}".`)
271
+ }
272
+ >
273
+ Select size M
274
+ </button>
275
+ <button onClick={() => onSendMessage(`Size M of "${productName}" — is it in stock?`)}>
276
+ Ask about size M
277
+ </button>
278
+ </div>
279
+ );
280
+ }
281
+ ```
282
+
283
+ ## Design rules (non-negotiable)
284
+
285
+ Apps render inside arbitrary publisher pages *and* the GreatStore
286
+ storefront; you control neither the host's root font size nor its colors.
287
+
288
+ 1. **Size in `em`, never `rem`** — `rem` resolves against the host page's
289
+ root font size, which is arbitrary (`html { font-size: 8px }` breaks every
290
+ `rem` dimension). `em` stays self-consistent anywhere. Borders may stay
291
+ `px`.
292
+ 2. **Never hardcode colors, fonts, or radii** — read the brand CSS variables
293
+ GreatStore injects (`--color-primary`, `--color-surface`,
294
+ `--color-foreground`, `--color-border-default`, `--font-primary`,
295
+ `--radius-lg`, …) so the app restyles itself with the store's theme. The
296
+ scaffolded `AGENTS.md` has the full variable table.
297
+
298
+ ## Async apps (backend-backed data)
299
+
300
+ If an app must load data before it can render correctly, don't render a shell
301
+ and fetch in `useEffect` — set `"async": true` in the manifest and export an
302
+ **async** default. GreatStore shows its own loading state, awaits your
303
+ promise, and renders what it resolves to.
304
+
305
+ A thrown error is a **retry signal**: the assistant sees it and usually
306
+ re-calls the tool. So only throw when a *different* call could help:
307
+
308
+ 1. Validate the AI-passed props first and throw on bad input — the AI can
309
+ fix the args and retry. (Don't validate the API's *output* and throw: the
310
+ AI can't fix your backend, it'll just loop.)
311
+ 2. Throw on failures where retrying differently could succeed, and say what
312
+ to change (e.g. empty search → `"no results for X — try a broader keyword"`).
313
+ 3. For idempotent failures (500, timeout, missing record) render a graceful
314
+ fallback instead of throwing — re-running the same call changes nothing.
315
+
316
+ ```tsx
317
+ export default async function Results(props: Props) {
318
+ if (!props.query?.trim()) throw new Error("missing required prop: query");
319
+ const res = await fetch(`/api/search?q=${encodeURIComponent(props.query)}`);
320
+ if (res.ok) {
321
+ const { results } = await res.json();
322
+ if (results.length === 0)
323
+ throw new Error(`no results for "${props.query}" — try a broader keyword`);
324
+ return <ul>{/* render results */}</ul>;
325
+ }
326
+ return <p>Couldn't load results right now.</p>; // idempotent: don't throw
327
+ }
328
+ ```
329
+
330
+ ## When to build an app vs. the other facets
331
+
332
+ - Content for the **merchant's page** → `window.GreatStore.generateStructuredContent`
333
+ ([structured-content.md](structured-content.md)). Inside an app, use the
334
+ injected `onGenerateStructuredContent` prop instead — same idea, but
335
+ personalized to the shopper and available on every surface without the global.
336
+ - Letting the assistant **act on the page** → WebMCP page tools
337
+ ([embed-api.md](embed-api.md)).
338
+ - Rich, interactive UI **inside the conversation itself**, available on the
339
+ storefront and every embed without page changes → an app.