create-skybridge 0.0.0-dev.3581704 → 0.0.0-dev.35a7b38

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 (88) hide show
  1. package/dist/index.js +46 -24
  2. package/package.json +4 -4
  3. package/templates/blank/Dockerfile +3 -3
  4. package/templates/blank/_gitignore +2 -1
  5. package/templates/blank/node_modules/.bin/alpic +2 -2
  6. package/templates/blank/node_modules/.bin/tsc +2 -2
  7. package/templates/blank/node_modules/.bin/tsserver +2 -2
  8. package/templates/blank/node_modules/.bin/tsx +21 -0
  9. package/templates/blank/node_modules/.bin/vite +2 -2
  10. package/templates/blank/package.json +8 -7
  11. package/templates/blank/src/server.ts +0 -5
  12. package/templates/demo/Dockerfile +3 -3
  13. package/templates/demo/_gitignore +2 -1
  14. package/templates/demo/node_modules/.bin/alpic +2 -2
  15. package/templates/demo/node_modules/.bin/tsc +2 -2
  16. package/templates/demo/node_modules/.bin/tsserver +2 -2
  17. package/templates/demo/node_modules/.bin/tsx +2 -2
  18. package/templates/demo/node_modules/.bin/vite +2 -2
  19. package/templates/demo/package.json +17 -17
  20. package/templates/demo/src/server.ts +0 -5
  21. package/templates/ecom/.dockerignore +4 -0
  22. package/templates/ecom/.env.template +2 -0
  23. package/templates/ecom/.ladle/components.tsx +26 -0
  24. package/templates/ecom/.ladle/config.mjs +11 -0
  25. package/templates/ecom/.ladle/vite.config.ts +11 -0
  26. package/templates/ecom/AGENTS.md +2 -0
  27. package/templates/ecom/Dockerfile +53 -0
  28. package/templates/ecom/README.md +92 -0
  29. package/templates/ecom/_gitignore +9 -0
  30. package/templates/ecom/alpic.json +3 -0
  31. package/templates/ecom/node_modules/.bin/alpic +21 -0
  32. package/templates/ecom/node_modules/.bin/ladle +21 -0
  33. package/templates/ecom/node_modules/.bin/sb +21 -0
  34. package/templates/ecom/node_modules/.bin/skybridge +21 -0
  35. package/templates/ecom/node_modules/.bin/tsc +21 -0
  36. package/templates/ecom/node_modules/.bin/tsserver +21 -0
  37. package/templates/ecom/node_modules/.bin/tsx +21 -0
  38. package/templates/ecom/node_modules/.bin/vite +21 -0
  39. package/templates/ecom/package.json +41 -0
  40. package/templates/ecom/src/components/chip.css.ts +56 -0
  41. package/templates/ecom/src/components/chip.stories.tsx +26 -0
  42. package/templates/ecom/src/components/chip.tsx +41 -0
  43. package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
  44. package/templates/ecom/src/components/empty-state.tsx +12 -0
  45. package/templates/ecom/src/components/expandable-text.css.ts +49 -0
  46. package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
  47. package/templates/ecom/src/components/expandable-text.tsx +53 -0
  48. package/templates/ecom/src/components/image-gallery.css.ts +172 -0
  49. package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
  50. package/templates/ecom/src/components/image-gallery.tsx +162 -0
  51. package/templates/ecom/src/components/product-card.css.ts +155 -0
  52. package/templates/ecom/src/components/product-card.stories.tsx +58 -0
  53. package/templates/ecom/src/components/product-card.tsx +101 -0
  54. package/templates/ecom/src/components/product-carousel.css.ts +134 -0
  55. package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
  56. package/templates/ecom/src/components/product-carousel.tsx +202 -0
  57. package/templates/ecom/src/components/variant-picker.css.ts +27 -0
  58. package/templates/ecom/src/components/variant-picker.stories.tsx +64 -0
  59. package/templates/ecom/src/components/variant-picker.tsx +82 -0
  60. package/templates/ecom/src/components/view-frame.css.ts +22 -0
  61. package/templates/ecom/src/components/view-frame.tsx +27 -0
  62. package/templates/ecom/src/config.ts +12 -0
  63. package/templates/ecom/src/design/contract.css.ts +39 -0
  64. package/templates/ecom/src/design/fonts.css +15 -0
  65. package/templates/ecom/src/design/primitives.css.ts +101 -0
  66. package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
  67. package/templates/ecom/src/design/sprinkles.css.ts +128 -0
  68. package/templates/ecom/src/design/themes/dark.css.ts +36 -0
  69. package/templates/ecom/src/design/themes/light.css.ts +36 -0
  70. package/templates/ecom/src/design/tokens.ts +8 -0
  71. package/templates/ecom/src/helpers.ts +4 -0
  72. package/templates/ecom/src/i18n.ts +34 -0
  73. package/templates/ecom/src/index.css +9 -0
  74. package/templates/ecom/src/lib/cx.ts +9 -0
  75. package/templates/ecom/src/lib/format.ts +9 -0
  76. package/templates/ecom/src/lib/variants.ts +79 -0
  77. package/templates/ecom/src/server.ts +43 -0
  78. package/templates/ecom/src/tools/render-carousel.ts +242 -0
  79. package/templates/ecom/src/tools/search-products.ts +182 -0
  80. package/templates/ecom/src/types.ts +13 -0
  81. package/templates/ecom/src/views/carousel/detail/detail.css.ts +100 -0
  82. package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +114 -0
  83. package/templates/ecom/src/views/carousel/detail/index.tsx +215 -0
  84. package/templates/ecom/src/views/carousel/index.tsx +234 -0
  85. package/templates/ecom/tsconfig.json +11 -0
  86. package/templates/ecom/vite.config.ts +8 -0
  87. package/templates/blank/src/vite-manifest.d.ts +0 -4
  88. package/templates/demo/src/vite-manifest.d.ts +0 -4
@@ -0,0 +1,15 @@
1
+ /* @todo: add your brand's @font-face rules here, then point
2
+ primitives.font.family.primary at the family name. Drop the font files in
3
+ public/fonts/ so they are served under /assets/fonts/.
4
+
5
+ The template ships with the system font stack, which needs no @font-face,
6
+ so this file is empty by default. Example:
7
+
8
+ @font-face {
9
+ font-family: "My Brand";
10
+ font-style: normal;
11
+ font-weight: 400;
12
+ font-display: block;
13
+ src: url("/assets/fonts/MyBrand-Regular.woff2") format("woff2");
14
+ }
15
+ */
@@ -0,0 +1,101 @@
1
+ import { createGlobalTheme } from "@vanilla-extract/css";
2
+
3
+ /**
4
+ * Non-mode-aware design primitives: the raw scales every theme and recipe
5
+ * draws from. Values here are brand-neutral placeholders.
6
+ *
7
+ * @todo: replace these with your brand's real tokens (ideally extracted from
8
+ * a Figma design file). Change values, not the shape: the space/radius/font
9
+ * keys are referenced by sprinkles.css.ts and the recipes. Nothing outside
10
+ * this file should hard-code a hex, size, or spacing value.
11
+ */
12
+ export const primitives = createGlobalTheme(":root", {
13
+ // Spacing scale (4px based). Used for padding, margin, and gap via sprinkles.
14
+ space: {
15
+ none: "0",
16
+ "5xs": "2px",
17
+ "4xs": "4px",
18
+ "3xs": "8px",
19
+ "2xs": "12px",
20
+ xs: "16px",
21
+ s: "24px",
22
+ m: "32px",
23
+ l: "40px",
24
+ xl: "48px",
25
+ "2xl": "56px",
26
+ "3xl": "64px",
27
+ },
28
+ radius: {
29
+ none: "0",
30
+ xs: "2px",
31
+ s: "4px",
32
+ m: "8px",
33
+ l: "16px",
34
+ xl: "32px",
35
+ full: "999px",
36
+ },
37
+ font: {
38
+ family: {
39
+ // @todo: swap in your brand font (add its @font-face to fonts.css). The
40
+ // system stack is the zero-asset default.
41
+ primary:
42
+ '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif',
43
+ },
44
+ weight: {
45
+ regular: "400",
46
+ medium: "500",
47
+ semibold: "600",
48
+ bold: "700",
49
+ },
50
+ size: {
51
+ xs: "12px",
52
+ s: "14px",
53
+ m: "16px",
54
+ l: "20px",
55
+ xl: "24px",
56
+ "2xl": "32px",
57
+ "3xl": "40px",
58
+ },
59
+ lineHeight: {
60
+ tight: "1.25",
61
+ normal: "1.5",
62
+ },
63
+ letterSpacing: {
64
+ default: "0",
65
+ wide: "0.5px",
66
+ },
67
+ },
68
+ stroke: {
69
+ thin: "1px",
70
+ medium: "1.5px",
71
+ thick: "2px",
72
+ },
73
+ // Raw greyscale ramp. Themes pick from these for surface/content/border.
74
+ grey: {
75
+ white: "#ffffff",
76
+ "50": "#f8f8f8",
77
+ "100": "#f2f2f2",
78
+ "200": "#e1e1e1",
79
+ "300": "#b4b4b4",
80
+ "400": "#929292",
81
+ "500": "#727272",
82
+ "600": "#636363",
83
+ "700": "#4c4c4c",
84
+ "800": "#333333",
85
+ "900": "#1a1a1a",
86
+ black: "#000000",
87
+ },
88
+ // @todo: your brand accent ramp (call-to-action, links, highlights). Steps
89
+ // named by lightness, like the grey ramp; each theme picks the shade that
90
+ // reads well on its surface (light mode the darker step, dark mode the
91
+ // lighter one). Add more steps as needed.
92
+ accent: {
93
+ "400": "#7ba0f5",
94
+ "600": "#3b6cf0",
95
+ },
96
+ // Status colors, shared across themes.
97
+ status: {
98
+ error: "#c53929",
99
+ success: "#5c7d0b",
100
+ },
101
+ });
@@ -0,0 +1,75 @@
1
+ import { recipe } from "@vanilla-extract/recipes";
2
+ import { primitives } from "../primitives.css";
3
+
4
+ /**
5
+ * The one text style, driven by variants. Call it as:
6
+ * text({ style: "headingM", weight: "medium" })
7
+ *
8
+ * `style` picks the size/line-height pair; `weight` picks the font weight.
9
+ * This is the workhorse recipe: use it for all typography rather than setting
10
+ * fontSize/fontWeight by hand.
11
+ *
12
+ * @todo: adjust the styles to your type scale. Add a component recipe (button,
13
+ * tag, card) only when a component has real variants; otherwise style with
14
+ * sprinkles or a `style()` block.
15
+ */
16
+ export const text = recipe({
17
+ base: {
18
+ fontFamily: primitives.font.family.primary,
19
+ letterSpacing: primitives.font.letterSpacing.default,
20
+ fontWeight: primitives.font.weight.regular,
21
+ margin: 0,
22
+ },
23
+ variants: {
24
+ style: {
25
+ display: {
26
+ fontSize: primitives.font.size["3xl"],
27
+ lineHeight: primitives.font.lineHeight.tight,
28
+ },
29
+ headingL: {
30
+ fontSize: primitives.font.size["2xl"],
31
+ lineHeight: primitives.font.lineHeight.tight,
32
+ },
33
+ headingM: {
34
+ fontSize: primitives.font.size.xl,
35
+ lineHeight: primitives.font.lineHeight.tight,
36
+ },
37
+ headingS: {
38
+ fontSize: primitives.font.size.l,
39
+ lineHeight: primitives.font.lineHeight.tight,
40
+ },
41
+ bodyM: {
42
+ fontSize: primitives.font.size.m,
43
+ lineHeight: primitives.font.lineHeight.normal,
44
+ },
45
+ bodyS: {
46
+ fontSize: primitives.font.size.s,
47
+ lineHeight: primitives.font.lineHeight.normal,
48
+ },
49
+ labelM: {
50
+ fontSize: primitives.font.size.m,
51
+ lineHeight: primitives.font.lineHeight.tight,
52
+ },
53
+ labelS: {
54
+ fontSize: primitives.font.size.s,
55
+ lineHeight: primitives.font.lineHeight.tight,
56
+ },
57
+ overline: {
58
+ fontSize: primitives.font.size.xs,
59
+ lineHeight: primitives.font.lineHeight.normal,
60
+ letterSpacing: primitives.font.letterSpacing.wide,
61
+ textTransform: "uppercase",
62
+ },
63
+ },
64
+ weight: {
65
+ regular: { fontWeight: primitives.font.weight.regular },
66
+ medium: { fontWeight: primitives.font.weight.medium },
67
+ semibold: { fontWeight: primitives.font.weight.semibold },
68
+ bold: { fontWeight: primitives.font.weight.bold },
69
+ },
70
+ },
71
+ defaultVariants: {
72
+ style: "bodyM",
73
+ weight: "regular",
74
+ },
75
+ });
@@ -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,34 @@
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
+ noProducts: "No products to show.",
12
+ carousel: "carousel",
13
+ products: "Products",
14
+ previous: "Previous",
15
+ next: "Next",
16
+ // Detail view.
17
+ viewOnSite: "View on site",
18
+ selectOptions: "Select options",
19
+ priceOnRequest: "Price on request",
20
+ specifications: "Specifications",
21
+ readMore: "Read more",
22
+ readLess: "Read less",
23
+ },
24
+ } as const;
25
+
26
+ const DEFAULT_LOCALE = "en";
27
+
28
+ export type Labels = (typeof LABELS)[typeof DEFAULT_LOCALE];
29
+
30
+ export function useLabels(): Labels {
31
+ const { locale } = useUser();
32
+ const lang = locale.split("-")[0] ?? DEFAULT_LOCALE;
33
+ return lang in LABELS ? LABELS[lang as keyof typeof LABELS] : LABELS.en;
34
+ }
@@ -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,79 @@
1
+ import type { Product, Variant } from "../tools/render-carousel.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.
7
+
8
+ // A selection is one chosen value per axis, keyed by Option.id -> OptionValue.id.
9
+ export type Selection = Record<string, string>;
10
+
11
+ /**
12
+ * The variant matching a full selection (one value per axis), or undefined if
13
+ * the selection is partial or the combination does not exist. A product with no
14
+ * options resolves to its single variant on an empty selection.
15
+ */
16
+ export function resolveVariant(
17
+ product: Product,
18
+ selection: Selection,
19
+ ): Variant | undefined {
20
+ for (const option of product.options) {
21
+ if (selection[option.id] == null) {
22
+ return undefined; // partial selection: nothing resolved yet
23
+ }
24
+ }
25
+ return product.variants.find((variant) =>
26
+ product.options.every(
27
+ (option) => variant.selection[option.id] === selection[option.id],
28
+ ),
29
+ );
30
+ }
31
+
32
+ /**
33
+ * The values of `axisId` still reachable given the choices already made on the
34
+ * OTHER axes. A value is reachable if at least one variant carries it while
35
+ * matching every other current choice. Values not in this set have no surviving
36
+ * variant, so the picker disables them ("Red only in M").
37
+ */
38
+ export function selectableValues(
39
+ product: Product,
40
+ axisId: string,
41
+ selection: Selection,
42
+ ): Set<string> {
43
+ const reachable = new Set<string>();
44
+ for (const variant of product.variants) {
45
+ let matchesOthers = true;
46
+ for (const option of product.options) {
47
+ if (option.id === axisId) {
48
+ continue;
49
+ }
50
+ const chosen = selection[option.id];
51
+ if (chosen != null && variant.selection[option.id] !== chosen) {
52
+ matchesOthers = false;
53
+ break;
54
+ }
55
+ }
56
+ if (matchesOthers) {
57
+ reachable.add(variant.selection[axisId]);
58
+ }
59
+ }
60
+ return reachable;
61
+ }
62
+
63
+ /**
64
+ * The selection to preselect when a product opens: the variant the client
65
+ * tapped (its id equals the opened product id), else the first variant. A
66
+ * variant is always preselected when the product has any, so the buy CTA is
67
+ * live on open rather than starting disabled.
68
+ */
69
+ export function initialSelection(product: Product): Selection {
70
+ let base: Variant | undefined;
71
+ for (const variant of product.variants) {
72
+ if (variant.id === product.id) {
73
+ base = variant;
74
+ break;
75
+ }
76
+ }
77
+ base ??= product.variants[0];
78
+ return base ? { ...base.selection } : {};
79
+ }
@@ -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 keyword, apply filters from a prior response, or page deeper. \
31
+ Stay silent while searching: emit NO text between calls. Speak only \
32
+ once the carousel renders. Never call a category unavailable before searching.
33
+
34
+ RENDER: After curating, call render-carousel with the chosen product IDs (aim for ${CAROUSEL_RANGE}). \
35
+ Speak only once it renders, then recommend 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;