greatstore 0.2.13 → 0.2.14

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.
@@ -1,109 +0,0 @@
1
- # GreatStore launchers — AI question chips
2
-
3
- > **Treat this code as a reference, not a drop-in.** Samples are
4
- > framework-free vanilla JS so they stay portable — re-express the same
5
- > logic in the conventions of the repo you're working in (React, Vue,
6
- > Shopify Liquid sections, Svelte, …) instead of retrofitting the sample
7
- > as-is.
8
-
9
- A horizontally scrollable row of chips, each a highly engaging first-person
10
- question about the current page. Tapping a chip sends that question to the
11
- assistant — `generateStructuredContent` writes the questions, `sendMessage`
12
- fires them. Simple yet effective: it works on every page type, costs one
13
- cached generation per page, and every tap starts a conversation that already
14
- has a great opening line.
15
-
16
- ```html
17
- <div id="gs-launchers" hidden></div>
18
-
19
- <style>
20
- #gs-launchers {
21
- display: flex;
22
- gap: 0.5em;
23
- overflow-x: auto;
24
- -webkit-overflow-scrolling: touch;
25
- scrollbar-width: none;
26
- padding: 0.5em 1em;
27
- }
28
- #gs-launchers::-webkit-scrollbar { display: none; }
29
- #gs-launchers button {
30
- flex: 0 0 auto;
31
- white-space: nowrap;
32
- border: 1px solid #ddd;
33
- border-radius: 999px;
34
- padding: 0.5em 0.9em;
35
- background: #fff;
36
- cursor: pointer;
37
- }
38
- </style>
39
-
40
- <script>
41
- (async () => {
42
- const gs = window.GreatStore;
43
- if (!gs?.generateStructuredContent) return;
44
- try {
45
- const data = await gs.generateStructuredContent(
46
- {
47
- type: "object",
48
- properties: {
49
- launchers: {
50
- type: "array", minItems: 4, maxItems: 6,
51
- items: {
52
- type: "object",
53
- properties: {
54
- chip: { type: "string", maxLength: 32 },
55
- question: { type: "string", maxLength: 140 },
56
- },
57
- required: ["chip", "question"],
58
- },
59
- },
60
- },
61
- required: ["launchers"],
62
- },
63
- `The shopper is on the page "${document.title}". Write 4-6 launcher ` +
64
- `chips for a shopping assistant. For each, "question" is a highly ` +
65
- `engaging first-person question this shopper would genuinely want ` +
66
- `answered on this page — specific to its product, category, or ` +
67
- `content, never generic — and "chip" is a 2-4 word teaser of it. ` +
68
- `Vary the angles: fit and use, comparisons, gifting, care, what's ` +
69
- `popular.`
70
- );
71
-
72
- const row = document.getElementById("gs-launchers");
73
- for (const { chip, question } of data.launchers) {
74
- const btn = document.createElement("button");
75
- btn.type = "button";
76
- btn.textContent = chip;
77
- btn.title = question;
78
- btn.addEventListener("click", () => gs.sendMessage(question));
79
- row.append(btn);
80
- }
81
- row.hidden = false;
82
- } catch {}
83
- })();
84
- </script>
85
- ```
86
-
87
- Why it works:
88
-
89
- - **The chip is the teaser, the question is the payload.** A 2-4 word chip
90
- scans instantly; the full first-person question lands in the transcript
91
- reading like something the shopper typed, and gives the assistant a
92
- well-formed prompt. The `title` attribute previews the full question on
93
- hover.
94
- - **Per-page for free.** The page URL is part of the generation context and
95
- the cache key, so one site-wide snippet yields different chips on every
96
- page — each served from cache on repeat renders.
97
- - **Placement is the lever.** Under the product title, above the grid on
98
- collections, at the end of a blog post — wherever a shopper pauses to
99
- wonder, the chips name the question for them.
100
-
101
- Tips:
102
-
103
- - Inline the product or collection name into the prompt when the platform
104
- exposes it — it beats relying on `document.title`.
105
- - Restyle the chips to the site's design system; the CSS above is just the
106
- scroll mechanics (flex row, `overflow-x: auto`, hidden scrollbars,
107
- `white-space: nowrap`).
108
- - Resist adding more than ~6 chips — a launcher row is an invitation, not a
109
- sitemap.
@@ -1,87 +0,0 @@
1
- # Page-action suite (WebMCP)
2
-
3
- > **Treat this code as a reference, not a drop-in.** Samples are
4
- > framework-free vanilla JS so they stay portable — re-express the same
5
- > logic in the conventions of the repo you're working in (React, Vue,
6
- > Shopify Liquid sections, Svelte, …) instead of retrofitting the sample
7
- > as-is.
8
-
9
- Give every conversation on the site real capabilities. Register once in a
10
- shared snippet, once GreatStore is ready (which guarantees
11
- `document.modelContext` exists). The listener works whether the snippet runs
12
- before or after the embed script:
13
-
14
- ```js
15
- window.addEventListener("greatstore:ready", () => {
16
- const text = (value) => ({
17
- content: [{ type: "text", text: JSON.stringify(value) }],
18
- });
19
-
20
- document.modelContext.registerTool({
21
- name: "get_cart",
22
- description:
23
- "Read the shopper's current cart on this site: items, quantities, " +
24
- "and totals. Use before answering any cart question.",
25
- inputSchema: { type: "object", properties: {} },
26
- async execute() {
27
- return text(await (await fetch("/cart.js")).json());
28
- },
29
- });
30
-
31
- document.modelContext.registerTool({
32
- name: "add_to_cart",
33
- description:
34
- "Add a product variant to the cart on this site. Use when the " +
35
- "shopper asks to add or buy something. Confirm the variant with " +
36
- "the shopper first if ambiguous.",
37
- inputSchema: {
38
- type: "object",
39
- properties: {
40
- variantId: { type: "string" },
41
- quantity: { type: "integer", minimum: 1, maximum: 10 },
42
- },
43
- required: ["variantId"],
44
- },
45
- async execute({ variantId, quantity }) {
46
- if (!variantId) throw new Error("variantId is required");
47
- const res = await fetch("/cart/add.js", {
48
- method: "POST",
49
- headers: { "Content-Type": "application/json" },
50
- body: JSON.stringify({ id: variantId, quantity: quantity ?? 1 }),
51
- });
52
- if (!res.ok) throw new Error(`Could not add to cart (${res.status})`);
53
- document.dispatchEvent(new CustomEvent("cart:refresh"));
54
- return text(await res.json());
55
- },
56
- });
57
-
58
- document.modelContext.registerTool({
59
- name: "get_current_page",
60
- description:
61
- "Read what page the shopper is currently on, including structured " +
62
- "product data when on a product page.",
63
- inputSchema: { type: "object", properties: {} },
64
- execute() {
65
- return text({
66
- url: location.href,
67
- title: document.title,
68
- productJson: document.querySelector("#product-json")?.textContent ?? null,
69
- });
70
- },
71
- });
72
- }, { once: true });
73
- ```
74
-
75
- Principles at work: throw on failure (the assistant explains and recovers),
76
- return fresh state after mutations (the assistant confirms accurately), cap
77
- quantities in the schema, and notify your own UI (`cart:refresh`) so the
78
- page reflects what the AI did.
79
-
80
- For a product-page-only tool, register with an `AbortSignal` and abort on
81
- SPA navigation:
82
-
83
- ```js
84
- const ac = new AbortController();
85
- document.modelContext.registerTool(reviewsTool, { signal: ac.signal });
86
- router.onLeave("/products/:handle", () => ac.abort());
87
- ```
@@ -1,58 +0,0 @@
1
- # Product FAQ accordion
2
-
3
- > **Treat this code as a reference, not a drop-in.** Samples are
4
- > framework-free vanilla JS so they stay portable — re-express the same
5
- > logic in the conventions of the repo you're working in (React, Vue,
6
- > Shopify Liquid sections, Svelte, …) instead of retrofitting the sample
7
- > as-is.
8
-
9
- ```js
10
- const data = await window.GreatStore.generateStructuredContent(
11
- {
12
- type: "object",
13
- properties: {
14
- faqs: {
15
- type: "array", minItems: 3, maxItems: 5,
16
- items: {
17
- type: "object",
18
- properties: {
19
- question: { type: "string", maxLength: 90 },
20
- answer: { type: "string", maxLength: 300 },
21
- },
22
- required: ["question", "answer"],
23
- },
24
- },
25
- },
26
- required: ["faqs"],
27
- },
28
- `Generate the questions shoppers most plausibly have before buying the ` +
29
- `product "${productName}", with accurate answers grounded in the real ` +
30
- `product details and store policies. Skip any question the store data ` +
31
- `can't answer confidently.`
32
- );
33
-
34
- const wrap = document.getElementById("gs-faq");
35
- for (const { question, answer } of data.faqs) {
36
- const details = document.createElement("details");
37
- const summary = document.createElement("summary");
38
- summary.textContent = question;
39
- const p = document.createElement("p");
40
- p.textContent = answer;
41
- details.append(summary, p);
42
- wrap.append(details);
43
- }
44
- wrap.hidden = false;
45
- ```
46
-
47
- Engagement bonus — append a hand-off row so unanswered questions become
48
- conversations:
49
-
50
- ```js
51
- const ask = document.createElement("button");
52
- ask.type = "button";
53
- ask.textContent = "Have a different question? Ask us";
54
- ask.addEventListener("click", () =>
55
- window.GreatStore.sendMessage(`I have a question about "${productName}".`)
56
- );
57
- wrap.append(ask);
58
- ```