create-skybridge 0.0.0-dev.0f97936 → 0.0.0-dev.0fa5252

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.
Files changed (83) hide show
  1. package/dist/index.js +52 -26
  2. package/package.json +3 -3
  3. package/templates/blank/Dockerfile +2 -2
  4. package/templates/blank/node_modules/.bin/alpic +2 -2
  5. package/templates/blank/node_modules/.bin/tsx +2 -2
  6. package/templates/blank/node_modules/.bin/vite +2 -2
  7. package/templates/blank/package.json +8 -7
  8. package/templates/blank/vite.config.ts +7 -1
  9. package/templates/demo/Dockerfile +2 -2
  10. package/templates/demo/node_modules/.bin/alpic +2 -2
  11. package/templates/demo/node_modules/.bin/tsx +2 -2
  12. package/templates/demo/node_modules/.bin/vite +2 -2
  13. package/templates/demo/package.json +13 -12
  14. package/templates/demo/vite.config.ts +7 -1
  15. package/templates/ecom/.dockerignore +4 -0
  16. package/templates/ecom/.env.template +7 -0
  17. package/templates/ecom/.ladle/components.tsx +26 -0
  18. package/templates/ecom/.ladle/config.mjs +11 -0
  19. package/templates/ecom/.ladle/vite.config.ts +11 -0
  20. package/templates/ecom/AGENTS.md +2 -0
  21. package/templates/ecom/Dockerfile +53 -0
  22. package/templates/ecom/README.md +92 -0
  23. package/templates/ecom/_gitignore +9 -0
  24. package/templates/ecom/alpic.json +3 -0
  25. package/templates/ecom/node_modules/.bin/alpic +21 -0
  26. package/templates/ecom/node_modules/.bin/ladle +21 -0
  27. package/templates/ecom/node_modules/.bin/sb +21 -0
  28. package/templates/ecom/node_modules/.bin/skybridge +21 -0
  29. package/templates/ecom/node_modules/.bin/tsc +21 -0
  30. package/templates/ecom/node_modules/.bin/tsserver +21 -0
  31. package/templates/ecom/node_modules/.bin/tsx +21 -0
  32. package/templates/ecom/node_modules/.bin/vite +21 -0
  33. package/templates/ecom/package.json +42 -0
  34. package/templates/ecom/src/catalog/index.ts +19 -0
  35. package/templates/ecom/src/catalog/mock.ts +134 -0
  36. package/templates/ecom/src/catalog/shopify.ts +264 -0
  37. package/templates/ecom/src/components/chip.css.ts +63 -0
  38. package/templates/ecom/src/components/chip.stories.tsx +27 -0
  39. package/templates/ecom/src/components/chip.tsx +49 -0
  40. package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
  41. package/templates/ecom/src/components/empty-state.tsx +12 -0
  42. package/templates/ecom/src/components/expandable-text.css.ts +49 -0
  43. package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
  44. package/templates/ecom/src/components/expandable-text.tsx +53 -0
  45. package/templates/ecom/src/components/image-gallery.css.ts +172 -0
  46. package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
  47. package/templates/ecom/src/components/image-gallery.tsx +163 -0
  48. package/templates/ecom/src/components/product-card.css.ts +159 -0
  49. package/templates/ecom/src/components/product-card.stories.tsx +58 -0
  50. package/templates/ecom/src/components/product-card.tsx +102 -0
  51. package/templates/ecom/src/components/product-carousel.css.ts +134 -0
  52. package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
  53. package/templates/ecom/src/components/product-carousel.tsx +202 -0
  54. package/templates/ecom/src/components/variant-picker.css.ts +27 -0
  55. package/templates/ecom/src/components/variant-picker.stories.tsx +67 -0
  56. package/templates/ecom/src/components/variant-picker.tsx +70 -0
  57. package/templates/ecom/src/components/view-frame.css.ts +22 -0
  58. package/templates/ecom/src/components/view-frame.tsx +27 -0
  59. package/templates/ecom/src/config.ts +12 -0
  60. package/templates/ecom/src/design/contract.css.ts +39 -0
  61. package/templates/ecom/src/design/fonts.css +15 -0
  62. package/templates/ecom/src/design/primitives.css.ts +101 -0
  63. package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
  64. package/templates/ecom/src/design/sprinkles.css.ts +128 -0
  65. package/templates/ecom/src/design/themes/dark.css.ts +36 -0
  66. package/templates/ecom/src/design/themes/light.css.ts +36 -0
  67. package/templates/ecom/src/design/tokens.ts +8 -0
  68. package/templates/ecom/src/helpers.ts +4 -0
  69. package/templates/ecom/src/i18n.ts +35 -0
  70. package/templates/ecom/src/index.css +9 -0
  71. package/templates/ecom/src/lib/cx.ts +9 -0
  72. package/templates/ecom/src/lib/format.ts +9 -0
  73. package/templates/ecom/src/lib/variants.ts +150 -0
  74. package/templates/ecom/src/server.ts +43 -0
  75. package/templates/ecom/src/tools/render-carousel.ts +161 -0
  76. package/templates/ecom/src/tools/search-products.ts +196 -0
  77. package/templates/ecom/src/types.ts +87 -0
  78. package/templates/ecom/src/views/carousel/detail/detail.css.ts +115 -0
  79. package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +133 -0
  80. package/templates/ecom/src/views/carousel/detail/index.tsx +254 -0
  81. package/templates/ecom/src/views/carousel/index.tsx +233 -0
  82. package/templates/ecom/tsconfig.json +11 -0
  83. package/templates/ecom/vite.config.ts +8 -0
@@ -0,0 +1,128 @@
1
+ import { createSprinkles, defineProperties } from "@vanilla-extract/sprinkles";
2
+ import { colors } from "./contract.css";
3
+ import { primitives } from "./primitives.css";
4
+
5
+ /**
6
+ * Atomic style props built on the primitives + color contract. Use sprinkles
7
+ * for one-off layout/spacing/color on an element, e.g.
8
+ * sprinkles({ display: "flex", gap: "s", color: "intense" })
9
+ *
10
+ * Structural component styling belongs in a co-located `.css.ts` `style()`
11
+ * block; sprinkles is the thin glue layer on top.
12
+ */
13
+
14
+ const spaceProperties = defineProperties({
15
+ properties: {
16
+ padding: primitives.space,
17
+ paddingTop: primitives.space,
18
+ paddingRight: primitives.space,
19
+ paddingBottom: primitives.space,
20
+ paddingLeft: primitives.space,
21
+ margin: primitives.space,
22
+ marginTop: primitives.space,
23
+ marginRight: primitives.space,
24
+ marginBottom: primitives.space,
25
+ marginLeft: primitives.space,
26
+ gap: primitives.space,
27
+ rowGap: primitives.space,
28
+ columnGap: primitives.space,
29
+ },
30
+ shorthands: {
31
+ p: ["padding"],
32
+ pt: ["paddingTop"],
33
+ pr: ["paddingRight"],
34
+ pb: ["paddingBottom"],
35
+ pl: ["paddingLeft"],
36
+ px: ["paddingLeft", "paddingRight"],
37
+ py: ["paddingTop", "paddingBottom"],
38
+ m: ["margin"],
39
+ mt: ["marginTop"],
40
+ mr: ["marginRight"],
41
+ mb: ["marginBottom"],
42
+ ml: ["marginLeft"],
43
+ mx: ["marginLeft", "marginRight"],
44
+ my: ["marginTop", "marginBottom"],
45
+ },
46
+ });
47
+
48
+ const colorProperties = defineProperties({
49
+ properties: {
50
+ backgroundColor: {
51
+ ...colors.surface,
52
+ accent: colors.common.accent,
53
+ invertAccent: colors.common.invertAccent,
54
+ highlight: colors.common.highlight,
55
+ transparent: "transparent",
56
+ },
57
+ color: {
58
+ ...colors.content,
59
+ accent: colors.common.accent,
60
+ invertAccent: colors.common.invertAccent,
61
+ highlight: colors.common.highlight,
62
+ error: colors.common.error,
63
+ success: colors.common.success,
64
+ },
65
+ borderColor: {
66
+ ...colors.border,
67
+ accent: colors.common.accent,
68
+ invertAccent: colors.common.invertAccent,
69
+ highlight: colors.common.highlight,
70
+ transparent: "transparent",
71
+ },
72
+ },
73
+ });
74
+
75
+ const radiusProperties = defineProperties({
76
+ properties: {
77
+ borderRadius: primitives.radius,
78
+ borderTopLeftRadius: primitives.radius,
79
+ borderTopRightRadius: primitives.radius,
80
+ borderBottomLeftRadius: primitives.radius,
81
+ borderBottomRightRadius: primitives.radius,
82
+ },
83
+ });
84
+
85
+ const typographyProperties = defineProperties({
86
+ properties: {
87
+ fontFamily: primitives.font.family,
88
+ fontWeight: primitives.font.weight,
89
+ fontSize: primitives.font.size,
90
+ lineHeight: primitives.font.lineHeight,
91
+ letterSpacing: primitives.font.letterSpacing,
92
+ },
93
+ });
94
+
95
+ const strokeProperties = defineProperties({
96
+ properties: {
97
+ borderWidth: primitives.stroke,
98
+ },
99
+ });
100
+
101
+ const layoutProperties = defineProperties({
102
+ properties: {
103
+ display: ["none", "flex", "inline-flex", "block", "inline-block", "grid"],
104
+ flexDirection: ["row", "column", "row-reverse", "column-reverse"],
105
+ alignItems: ["flex-start", "center", "flex-end", "stretch", "baseline"],
106
+ justifyContent: [
107
+ "flex-start",
108
+ "center",
109
+ "flex-end",
110
+ "space-between",
111
+ "space-around",
112
+ "space-evenly",
113
+ ],
114
+ flexWrap: ["wrap", "nowrap", "wrap-reverse"],
115
+ textAlign: ["left", "center", "right"],
116
+ },
117
+ });
118
+
119
+ export const sprinkles = createSprinkles(
120
+ spaceProperties,
121
+ colorProperties,
122
+ radiusProperties,
123
+ typographyProperties,
124
+ strokeProperties,
125
+ layoutProperties,
126
+ );
127
+
128
+ export type Sprinkles = Parameters<typeof sprinkles>[0];
@@ -0,0 +1,36 @@
1
+ import { createTheme } from "@vanilla-extract/css";
2
+ import { colors } from "../contract.css";
3
+ import { primitives } from "../primitives.css";
4
+
5
+ /**
6
+ * Dark palette. Fills the same contract slots as light.css.ts (surface and
7
+ * content swap ends of the grey ramp).
8
+ *
9
+ * @todo: tune these mappings to your brand.
10
+ */
11
+ export const darkTheme = createTheme(colors, {
12
+ surface: {
13
+ extraLight: primitives.grey.black,
14
+ light: primitives.grey["900"],
15
+ subtle: primitives.grey["700"],
16
+ intense: primitives.grey["400"],
17
+ },
18
+ content: {
19
+ intense: primitives.grey["50"],
20
+ subtle: primitives.grey["300"],
21
+ invertIntense: primitives.grey["900"],
22
+ invertSubtle: primitives.grey["500"],
23
+ },
24
+ border: {
25
+ thin: primitives.grey["700"],
26
+ subtle: primitives.grey["600"],
27
+ intense: primitives.grey["400"],
28
+ },
29
+ common: {
30
+ accent: primitives.accent["400"],
31
+ invertAccent: primitives.grey.black,
32
+ highlight: primitives.accent["400"],
33
+ error: primitives.status.error,
34
+ success: primitives.status.success,
35
+ },
36
+ });
@@ -0,0 +1,36 @@
1
+ import { createTheme } from "@vanilla-extract/css";
2
+ import { colors } from "../contract.css";
3
+ import { primitives } from "../primitives.css";
4
+
5
+ /**
6
+ * Light palette: maps each semantic slot to a primitive.
7
+ *
8
+ * @todo: tune these mappings to your brand. dark.css.ts must fill the same
9
+ * slots (the contract enforces it).
10
+ */
11
+ export const lightTheme = createTheme(colors, {
12
+ surface: {
13
+ extraLight: primitives.grey.white,
14
+ light: primitives.grey["50"],
15
+ subtle: primitives.grey["200"],
16
+ intense: primitives.grey["400"],
17
+ },
18
+ content: {
19
+ intense: primitives.grey["900"],
20
+ subtle: primitives.grey["500"],
21
+ invertIntense: primitives.grey["50"],
22
+ invertSubtle: primitives.grey["300"],
23
+ },
24
+ border: {
25
+ thin: primitives.grey["200"],
26
+ subtle: primitives.grey["300"],
27
+ intense: primitives.grey["400"],
28
+ },
29
+ common: {
30
+ accent: primitives.accent["600"],
31
+ invertAccent: primitives.grey.white,
32
+ highlight: primitives.accent["600"],
33
+ error: primitives.status.error,
34
+ success: primitives.status.success,
35
+ },
36
+ });
@@ -0,0 +1,8 @@
1
+ // Barrel for the design system. Import tokens from here rather than reaching
2
+ // into individual files.
3
+ export { colors } from "./contract.css";
4
+ export { primitives } from "./primitives.css";
5
+ export { text } from "./recipes/typography.css";
6
+ export { type Sprinkles, sprinkles } from "./sprinkles.css";
7
+ export { darkTheme } from "./themes/dark.css";
8
+ export { lightTheme } from "./themes/light.css";
@@ -0,0 +1,4 @@
1
+ import { generateHelpers } from "skybridge/web";
2
+ import type { AppType } from "./server.js";
3
+
4
+ export const { useToolInfo, useCallTool } = generateHelpers<AppType>();
@@ -0,0 +1,35 @@
1
+ import { useUser } from "skybridge/web";
2
+
3
+ // Centralized UI labels. The active locale comes from the host via useUser();
4
+ // useLabels matches on the language subtag ("en-US" -> "en") and falls back to
5
+ // English for anything unlisted.
6
+ // @todo: adapt the English copy to your brand voice, and add a locale key (e.g.
7
+ // `fr`) with the same shape for each language you want to support.
8
+ const LABELS = {
9
+ en: {
10
+ outOfStock: "Out of stock",
11
+ combinationUnavailable: "Combination unavailable",
12
+ noProducts: "No products to show.",
13
+ carousel: "carousel",
14
+ products: "Products",
15
+ previous: "Previous",
16
+ next: "Next",
17
+ // Detail view.
18
+ reference: "Ref.",
19
+ viewOnSite: "View on site",
20
+ priceOnRequest: "Price on request",
21
+ specifications: "Specifications",
22
+ readMore: "Read more",
23
+ readLess: "Read less",
24
+ },
25
+ } as const;
26
+
27
+ const DEFAULT_LOCALE = "en";
28
+
29
+ export type Labels = (typeof LABELS)[typeof DEFAULT_LOCALE];
30
+
31
+ export function useLabels(): Labels {
32
+ const { locale } = useUser();
33
+ const lang = locale.split("-")[0] ?? DEFAULT_LOCALE;
34
+ return lang in LABELS ? LABELS[lang as keyof typeof LABELS] : LABELS.en;
35
+ }
@@ -0,0 +1,9 @@
1
+ @import "./design/fonts.css";
2
+
3
+ /* The view mounts in a host iframe whose <body> keeps the user-agent default
4
+ margin (~8px). Zero it out so the surface paints edge to edge. */
5
+ html,
6
+ body {
7
+ margin: 0;
8
+ padding: 0;
9
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Zero-dep class-name joiner. vanilla-extract's `recipe`/`style` return plain
3
+ * strings, so merging a recipe class with an optional consumer `className`
4
+ * just needs string concatenation that tolerates `undefined`/`false`/`null`.
5
+ *
6
+ * className={cx(text({ style: "bodyM" }), sprinkles({ color: "accent" }))}
7
+ */
8
+ export const cx = (...classes: (string | false | null | undefined)[]) =>
9
+ classes.filter(Boolean).join(" ");
@@ -0,0 +1,9 @@
1
+ import type { Price } from "../types.js";
2
+
3
+ // Pass useUser().locale from the view; omit for the runtime default.
4
+ export function formatPrice(price: Price, locale?: string): string {
5
+ return new Intl.NumberFormat(locale, {
6
+ style: "currency",
7
+ currency: price.currency,
8
+ }).format(price.amount);
9
+ }
@@ -0,0 +1,150 @@
1
+ import type { Product, Variant } from "../types.js";
2
+
3
+ // Pure helpers that turn the client's option choices into a concrete variant.
4
+ // The `variants` list is SPARSE: only combinations that exist are present, and
5
+ // that is the whole contingency model. These helpers never encode rules; they
6
+ // filter the list. A variant may also skip an axis entirely (a one-size cap in
7
+ // a capacity x size catalog carries no `size`): that axis is simply "not
8
+ // applicable" to it, and the helpers treat the absence as its own value.
9
+ //
10
+ // Availability is computed TOP-DOWN (the Shopify convention): an axis is
11
+ // constrained only by the choices on the axes declared BEFORE it. So the first
12
+ // axis is never disabled by a later choice, and each later axis narrows under
13
+ // the ones above. Order the `options` array accordingly.
14
+
15
+ // A selection is one chosen value per axis, keyed by Option.id -> OptionValue.id.
16
+ export type Selection = Record<string, string>;
17
+
18
+ /**
19
+ * The variant that exactly matches a selection, or undefined if none does.
20
+ * Strict per-axis equality with "missing" normalized to null: a partial
21
+ * selection resolves nothing, and a variant that skips an axis matches only a
22
+ * selection that also leaves it unset. A product with no options resolves to
23
+ * its single variant on an empty selection.
24
+ */
25
+ export function resolveVariant(
26
+ product: Product,
27
+ selection: Selection,
28
+ ): Variant | undefined {
29
+ return product.variants.find((variant) =>
30
+ product.options.every(
31
+ (option) =>
32
+ (variant.selection[option.id] ?? null) ===
33
+ (selection[option.id] ?? null),
34
+ ),
35
+ );
36
+ }
37
+
38
+ /**
39
+ * The state of every value of `axisId` given the choices on the axes ABOVE it:
40
+ * - "inStock": at least one matching variant is purchasable → normal chip.
41
+ * - "soldOut": matching variants exist, none in stock → struck, clickable.
42
+ * - absent: a hole in the variant matrix → hard-disabled chip.
43
+ * An empty map means the axis does not apply to the current configuration (a
44
+ * one-size colorway has no Size), and the picker hides its row.
45
+ */
46
+ export function axisStates(
47
+ product: Product,
48
+ axisId: string,
49
+ selection: Selection,
50
+ ): Map<string, "inStock" | "soldOut"> {
51
+ const states = new Map<string, "inStock" | "soldOut">();
52
+ for (const variant of product.variants) {
53
+ let matchesEarlier = true;
54
+ for (const option of product.options) {
55
+ if (option.id === axisId) {
56
+ break; // only the axes above constrain this one
57
+ }
58
+ const chosen = selection[option.id];
59
+ const carried = variant.selection[option.id];
60
+ if (chosen != null && carried !== undefined && carried !== chosen) {
61
+ matchesEarlier = false;
62
+ break;
63
+ }
64
+ }
65
+ if (!matchesEarlier) {
66
+ continue;
67
+ }
68
+ // A variant to which this axis does not apply carries no value to offer.
69
+ const value = variant.selection[axisId];
70
+ if (value !== undefined && states.get(value) !== "inStock") {
71
+ states.set(value, variant.outOfStock ? "soldOut" : "inStock");
72
+ }
73
+ }
74
+ return states;
75
+ }
76
+
77
+ /**
78
+ * The selection after picking `valueId` on `axisId`: the one state transition
79
+ * of the picker, rebuilt top-down.
80
+ * - An axis with no reachable value does not apply: its choice is dropped.
81
+ * - A prior choice that still EXISTS under the axes above is KEPT, even sold
82
+ * out: switching color never silently changes the size the user asked for.
83
+ * - Anything else fills with the first value in display order, preferring one
84
+ * that is in stock.
85
+ * The result resolves to a concrete variant, with one exception: a variant
86
+ * skipping an EARLIER axis keeps offering its later values under any choice on
87
+ * that axis, so picking one can compose a selection no variant matches. The
88
+ * detail renders that as "Combination unavailable".
89
+ */
90
+ export function applyChoice(
91
+ product: Product,
92
+ selection: Selection,
93
+ axisId: string,
94
+ valueId: string,
95
+ ): Selection {
96
+ const next: Selection = {};
97
+ for (const option of product.options) {
98
+ const candidate = option.id === axisId ? valueId : selection[option.id];
99
+ const states = axisStates(product, option.id, next);
100
+ if (states.size === 0) {
101
+ continue; // axis does not apply to the configuration above it
102
+ }
103
+ if (candidate != null && states.has(candidate)) {
104
+ next[option.id] = candidate;
105
+ continue;
106
+ }
107
+ let fill: string | undefined;
108
+ for (const value of option.values) {
109
+ if (states.get(value.id) === "inStock") {
110
+ fill = value.id;
111
+ break;
112
+ }
113
+ }
114
+ if (fill === undefined) {
115
+ for (const value of option.values) {
116
+ if (states.has(value.id)) {
117
+ fill = value.id;
118
+ break;
119
+ }
120
+ }
121
+ }
122
+ if (fill !== undefined) {
123
+ next[option.id] = fill;
124
+ }
125
+ }
126
+ return next;
127
+ }
128
+
129
+ /**
130
+ * The selection to preselect when a product opens: the variant the client
131
+ * tapped (its id equals the opened product id), else the first IN-STOCK
132
+ * variant, else the first variant. A variant is always preselected when the
133
+ * product has any, so the buy CTA is live on open rather than starting
134
+ * disabled.
135
+ */
136
+ export function initialSelection(product: Product): Selection {
137
+ let base: Variant | undefined;
138
+ let firstInStock: Variant | undefined;
139
+ for (const variant of product.variants) {
140
+ if (variant.id === product.id) {
141
+ base = variant;
142
+ break;
143
+ }
144
+ if (firstInStock === undefined && !variant.outOfStock) {
145
+ firstInStock = variant;
146
+ }
147
+ }
148
+ base ??= firstInStock ?? product.variants[0];
149
+ return base ? { ...base.selection } : {};
150
+ }
@@ -0,0 +1,43 @@
1
+ import { existsSync } from "node:fs";
2
+ import { McpServer } from "skybridge/server";
3
+ import { CAROUSEL_RANGE, MIN_SEARCH_ITERATIONS } from "./config.js";
4
+ import {
5
+ renderCarouselDefinition,
6
+ renderCarouselHandler,
7
+ } from "./tools/render-carousel.js";
8
+ import {
9
+ searchProductsDefinition,
10
+ searchProductsHandler,
11
+ } from "./tools/search-products.js";
12
+
13
+ // Load .env into process.env when present (native to Node, no dependency).
14
+ if (existsSync(".env")) {
15
+ process.loadEnvFile();
16
+ }
17
+
18
+ const server = new McpServer(
19
+ {
20
+ // @todo: name and version your app.
21
+ name: "skybridge-ecom",
22
+ version: "0.0.1",
23
+ },
24
+ {
25
+ // @todo: adapt this server-wide prompt to your catalog.
26
+ instructions: `\
27
+ Two phases:
28
+
29
+ SEARCH: Call search-products ${MIN_SEARCH_ITERATIONS}+ times before presenting, never off one call. \
30
+ Vary the keywords or page deeper. \
31
+ Stay silent while searching: emit NO text between calls. Speak only \
32
+ once the carousel renders.
33
+
34
+ RENDER: After curating, call render-carousel with the chosen product IDs (aim for ${CAROUSEL_RANGE}). \
35
+ Speak once it renders, then recommend products in carousel order.`,
36
+ },
37
+ )
38
+ .registerTool(searchProductsDefinition, searchProductsHandler)
39
+ .registerTool(renderCarouselDefinition, renderCarouselHandler);
40
+
41
+ export default await server.run();
42
+
43
+ export type AppType = typeof server;
@@ -0,0 +1,161 @@
1
+ import { z } from "zod";
2
+ import { getProducts } from "../catalog/index.js";
3
+ import { CAROUSEL_MAX_SIZE, CAROUSEL_RANGE } from "../config.js";
4
+ import { PriceSchema, type Product, SpecSchema } from "../types.js";
5
+
6
+ // The `render-carousel` tool: takes the IDs the model curated and returns the
7
+ // matching products for the carousel view to render. Data access lives in
8
+ // `src/catalog/`; everything else this tool needs lives in this file.
9
+
10
+ // ---------------------------------------------------------------------------
11
+ // Input
12
+ // ---------------------------------------------------------------------------
13
+
14
+ const inputSchema = {
15
+ ids: z
16
+ .array(z.string())
17
+ .min(1)
18
+ .max(CAROUSEL_MAX_SIZE)
19
+ .describe("Product IDs to present, in display order."),
20
+ };
21
+
22
+ type RenderInput = z.infer<z.ZodObject<typeof inputSchema>>;
23
+
24
+ // ---------------------------------------------------------------------------
25
+ // Output — model-facing grounding, for the LLM ONLY. The carousel view is NOT
26
+ // built from this; it renders from the full data in `_meta`. Keep it to what the
27
+ // model needs to reference and compare the displayed products afterward.
28
+ // ---------------------------------------------------------------------------
29
+
30
+ const outputSchema = {
31
+ products: z
32
+ .array(
33
+ z.object({
34
+ id: z.string().describe("Product SKU or reference."),
35
+ title: z.string(),
36
+ options: z
37
+ .array(z.object({ label: z.string(), values: z.array(z.string()) }))
38
+ .describe("Variations available (e.g. colors, sizes)."),
39
+ description: z.string().optional(),
40
+ price: PriceSchema.optional(),
41
+ outOfStock: z.boolean(),
42
+ specs: z
43
+ .array(SpecSchema)
44
+ .describe("Product-specific facts (material, dimensions, care…)."),
45
+ }),
46
+ )
47
+ .describe(
48
+ "The products shown in the carousel, in display order. For your reference only — to curate, compare, and answer follow-ups. Ground every claim in this data; never invent facts.",
49
+ ),
50
+ };
51
+
52
+ type RenderOutput = z.infer<z.ZodObject<typeof outputSchema>>;
53
+
54
+ // ---------------------------------------------------------------------------
55
+ // Mapping: trim each product's `card` and `options` into the model-facing
56
+ // grounding (outputSchema), dropping presentational fields (media, url). The
57
+ // full data stays in `_meta` for the view.
58
+ // @todo: choose what the model sees per product. Grounding only: no
59
+ // presentational data (media, styling); that rides in `_meta` for the view.
60
+ // ---------------------------------------------------------------------------
61
+
62
+ function toStructuredContent(products: Product[]): RenderOutput {
63
+ const groundingProducts: RenderOutput["products"] = [];
64
+
65
+ for (const product of products) {
66
+ const { card } = product;
67
+
68
+ const options: { label: string; values: string[] }[] = [];
69
+ for (const option of product.options) {
70
+ const values: string[] = [];
71
+ for (const value of option.values) {
72
+ values.push(value.label);
73
+ }
74
+ options.push({ label: option.label, values });
75
+ }
76
+
77
+ groundingProducts.push({
78
+ id: product.id,
79
+ title: card.title,
80
+ description: card.description,
81
+ price: card.price,
82
+ outOfStock: card.outOfStock ?? false,
83
+ options,
84
+ specs: card.specs,
85
+ });
86
+ }
87
+
88
+ return { products: groundingProducts };
89
+ }
90
+
91
+ // ---------------------------------------------------------------------------
92
+ // Tool (registered from server.ts to keep the typed tool chain intact)
93
+ // ---------------------------------------------------------------------------
94
+
95
+ export const renderCarouselDefinition = {
96
+ name: "render-carousel" as const,
97
+
98
+ // @todo: adapt the wording to your catalog and brand voice (tone, vocabulary,
99
+ // how to present products). The behavioral rules below apply to any catalog.
100
+ description: `\
101
+ Display the products you curated as an inline carousel for the client.
102
+
103
+ ## When to call
104
+ Call this AFTER searching and curating, and BEFORE writing your recommendation. Avoid describing the products in text first since the carousel shows them.
105
+
106
+ ## What to pass
107
+ Pass the IDs of the ${CAROUSEL_RANGE} products you chose, in display order (most relevant first). Order is significant: the carousel shows them in this exact order and your recommendation must follow the same sequence. Pass distinct products, not several variants of the same one; the detail view lets the client explore a product's variants (colors, sizes, and so on).
108
+
109
+ ## After the carousel
110
+ Recommend in carousel order so the client can follow along. The cards already show image, title, price, and key facts, so do not repeat them: add useful analysis tied to the client's need. Suggest a refinement the client has not addressed yet (from the available filters), never one they already used.
111
+
112
+ ## Accuracy
113
+ Use only the data returned for each product. Never invent facts, materials, or availability. If the client asks about something not present, open that product's detail or search again before answering.`,
114
+ annotations: {
115
+ readOnlyHint: true,
116
+ openWorldHint: false,
117
+ destructiveHint: false,
118
+ },
119
+
120
+ // @todo: customize the status messages shown in ChatGPT while the tool runs.
121
+ _meta: {
122
+ "openai/toolInvocation/invoking": "Loading product carousel",
123
+ "openai/toolInvocation/invoked": "Loaded product carousel",
124
+ },
125
+
126
+ // The carousel and product details UI rendered inline in the conversation.
127
+ view: {
128
+ // `as const` keeps this a literal (like `name` above) so it matches the
129
+ // generated ViewNameRegistry; a bare string widens and fails the build.
130
+ component: "carousel" as const,
131
+ description: "Browse the curated products.",
132
+ // @todo: declare the CSP domains this view needs. Add your image origins to
133
+ // `resourceDomains` so product images load, and the product site to
134
+ // `redirectDomains` so the detail view's "View on site" link and the host's
135
+ // "Open in app" URL (useOpenExternal / setOpenInAppUrl) are allowed.
136
+ // csp: {
137
+ // resourceDomains: ["https://images.example.com"],
138
+ // redirectDomains: ["https://www.example.com"],
139
+ // },
140
+ },
141
+
142
+ inputSchema,
143
+ outputSchema,
144
+ };
145
+
146
+ export async function renderCarouselHandler({ ids }: RenderInput) {
147
+ const products = await getProducts(ids);
148
+
149
+ return {
150
+ // Full products (incl. variants) for the view; not in model context.
151
+ _meta: { products },
152
+ structuredContent: toStructuredContent(products),
153
+ content: [
154
+ {
155
+ type: "text" as const,
156
+ text: `Rendered ${products.length} product(s) in the carousel.`,
157
+ },
158
+ ],
159
+ isError: false,
160
+ };
161
+ }