create-skybridge 0.0.0-dev.171ea52 → 0.0.0-dev.173bfe3
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/dist/index.js +357 -157
- package/package.json +9 -7
- package/templates/blank/.dockerignore +4 -0
- package/templates/blank/AGENTS.md +1 -0
- package/templates/blank/Dockerfile +53 -0
- package/templates/blank/README.md +92 -0
- package/{template → templates/blank}/_gitignore +3 -1
- package/templates/blank/node_modules/.bin/alpic +21 -0
- package/templates/blank/node_modules/.bin/sb +21 -0
- package/templates/blank/node_modules/.bin/skybridge +21 -0
- package/templates/blank/node_modules/.bin/tsc +21 -0
- package/templates/blank/node_modules/.bin/tsserver +21 -0
- package/templates/blank/node_modules/.bin/tsx +21 -0
- package/templates/blank/node_modules/.bin/vite +21 -0
- package/templates/blank/package.json +29 -0
- package/templates/blank/src/helpers.ts +4 -0
- package/templates/blank/src/server.ts +16 -0
- package/templates/blank/tsconfig.json +5 -0
- package/templates/blank/vite.config.ts +12 -0
- package/templates/demo/.dockerignore +4 -0
- package/templates/demo/AGENTS.md +1 -0
- package/templates/demo/Dockerfile +53 -0
- package/templates/demo/README.md +95 -0
- package/templates/demo/_gitignore +7 -0
- package/templates/demo/alpic.json +3 -0
- package/templates/demo/node_modules/.bin/alpic +21 -0
- package/templates/demo/node_modules/.bin/sb +21 -0
- package/templates/demo/node_modules/.bin/skybridge +21 -0
- package/templates/demo/node_modules/.bin/tsc +21 -0
- package/templates/demo/node_modules/.bin/tsserver +21 -0
- package/templates/demo/node_modules/.bin/tsx +21 -0
- package/templates/demo/node_modules/.bin/vite +21 -0
- package/templates/demo/package.json +41 -0
- package/templates/demo/src/helpers.ts +4 -0
- package/templates/demo/src/index.css +59 -0
- package/templates/demo/src/server.ts +94 -0
- package/templates/demo/src/views/components/doc-link.tsx +22 -0
- package/templates/demo/src/views/components/doc.tsx +21 -0
- package/templates/demo/src/views/components/nav.tsx +31 -0
- package/templates/demo/src/views/components/progress.tsx +35 -0
- package/templates/demo/src/views/components/steps/outro.tsx +68 -0
- package/templates/demo/src/views/components/steps/state.tsx +47 -0
- package/templates/demo/src/views/components/steps/tool-call.tsx +53 -0
- package/templates/demo/src/views/components/steps/tool-output.tsx +40 -0
- package/templates/demo/src/views/images/mascot/beret.png +0 -0
- package/templates/demo/src/views/images/mascot/chapka.png +0 -0
- package/templates/demo/src/views/images/mascot/cowboy-hat.png +0 -0
- package/templates/demo/src/views/images/mascot/fez.png +0 -0
- package/templates/demo/src/views/images/mascot/jester-hat.png +0 -0
- package/templates/demo/src/views/images/mascot/mitre.png +0 -0
- package/templates/demo/src/views/images/mascot/non-la.png +0 -0
- package/templates/demo/src/views/images/mascot/original.png +0 -0
- package/templates/demo/src/views/images/mascot/propeller-beanie.png +0 -0
- package/templates/demo/src/views/images/mascot/ski-mask.png +0 -0
- package/templates/demo/src/views/images/mascot/sombrero.png +0 -0
- package/templates/demo/src/views/images/mascot/top-hat.png +0 -0
- package/templates/demo/src/views/images/mascot/viking-helmet.png +0 -0
- package/templates/demo/src/views/onboarding.tsx +63 -0
- package/templates/demo/src/views/use-mascot.ts +60 -0
- package/templates/demo/tsconfig.json +11 -0
- package/templates/demo/vite.config.ts +20 -0
- package/templates/ecom/.dockerignore +4 -0
- package/templates/ecom/.env.template +7 -0
- package/templates/ecom/.ladle/components.tsx +26 -0
- package/templates/ecom/.ladle/config.mjs +11 -0
- package/templates/ecom/.ladle/vite.config.ts +11 -0
- package/templates/ecom/AGENTS.md +2 -0
- package/templates/ecom/Dockerfile +53 -0
- package/templates/ecom/README.md +92 -0
- package/templates/ecom/_gitignore +9 -0
- package/templates/ecom/alpic.json +3 -0
- package/templates/ecom/node_modules/.bin/alpic +21 -0
- package/templates/ecom/node_modules/.bin/ladle +21 -0
- package/templates/ecom/node_modules/.bin/sb +21 -0
- package/templates/ecom/node_modules/.bin/skybridge +21 -0
- package/templates/ecom/node_modules/.bin/tsc +21 -0
- package/templates/ecom/node_modules/.bin/tsserver +21 -0
- package/templates/ecom/node_modules/.bin/tsx +21 -0
- package/templates/ecom/node_modules/.bin/vite +21 -0
- package/templates/ecom/package.json +41 -0
- package/templates/ecom/src/catalog/index.ts +19 -0
- package/templates/ecom/src/catalog/mock.ts +134 -0
- package/templates/ecom/src/catalog/shopify.ts +264 -0
- package/templates/ecom/src/components/chip.css.ts +63 -0
- package/templates/ecom/src/components/chip.stories.tsx +27 -0
- package/templates/ecom/src/components/chip.tsx +49 -0
- package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
- package/templates/ecom/src/components/empty-state.tsx +12 -0
- package/templates/ecom/src/components/expandable-text.css.ts +49 -0
- package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
- package/templates/ecom/src/components/expandable-text.tsx +53 -0
- package/templates/ecom/src/components/image-gallery.css.ts +172 -0
- package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
- package/templates/ecom/src/components/image-gallery.tsx +163 -0
- package/templates/ecom/src/components/product-card.css.ts +159 -0
- package/templates/ecom/src/components/product-card.stories.tsx +58 -0
- package/templates/ecom/src/components/product-card.tsx +102 -0
- package/templates/ecom/src/components/product-carousel.css.ts +134 -0
- package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
- package/templates/ecom/src/components/product-carousel.tsx +202 -0
- package/templates/ecom/src/components/variant-picker.css.ts +27 -0
- package/templates/ecom/src/components/variant-picker.stories.tsx +67 -0
- package/templates/ecom/src/components/variant-picker.tsx +70 -0
- package/templates/ecom/src/components/view-frame.css.ts +22 -0
- package/templates/ecom/src/components/view-frame.tsx +27 -0
- package/templates/ecom/src/config.ts +12 -0
- package/templates/ecom/src/design/contract.css.ts +39 -0
- package/templates/ecom/src/design/fonts.css +15 -0
- package/templates/ecom/src/design/primitives.css.ts +101 -0
- package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
- package/templates/ecom/src/design/sprinkles.css.ts +128 -0
- package/templates/ecom/src/design/themes/dark.css.ts +36 -0
- package/templates/ecom/src/design/themes/light.css.ts +36 -0
- package/templates/ecom/src/design/tokens.ts +8 -0
- package/templates/ecom/src/helpers.ts +4 -0
- package/templates/ecom/src/i18n.ts +35 -0
- package/templates/ecom/src/index.css +9 -0
- package/templates/ecom/src/lib/cx.ts +9 -0
- package/templates/ecom/src/lib/format.ts +9 -0
- package/templates/ecom/src/lib/variants.ts +150 -0
- package/templates/ecom/src/server.ts +43 -0
- package/templates/ecom/src/tools/render-carousel.ts +161 -0
- package/templates/ecom/src/tools/search-products.ts +196 -0
- package/templates/ecom/src/types.ts +87 -0
- package/templates/ecom/src/views/carousel/detail/detail.css.ts +115 -0
- package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +133 -0
- package/templates/ecom/src/views/carousel/detail/index.tsx +254 -0
- package/templates/ecom/src/views/carousel/index.tsx +233 -0
- package/templates/ecom/tsconfig.json +11 -0
- package/templates/ecom/vite.config.ts +8 -0
- package/dist/index.test.d.ts +0 -1
- package/dist/index.test.js +0 -23
- package/template/README.md +0 -77
- package/template/node_modules/.bin/mcp-inspector +0 -21
- package/template/node_modules/.bin/nodemon +0 -21
- package/template/node_modules/.bin/sb +0 -21
- package/template/node_modules/.bin/shx +0 -21
- package/template/node_modules/.bin/skybridge +0 -21
- package/template/node_modules/.bin/tsc +0 -21
- package/template/node_modules/.bin/tsserver +0 -21
- package/template/node_modules/.bin/tsx +0 -21
- package/template/node_modules/.bin/vite +0 -21
- package/template/nodemon.json +0 -5
- package/template/package.json +0 -43
- package/template/server/src/index.ts +0 -51
- package/template/server/src/middleware.ts +0 -54
- package/template/server/src/server.ts +0 -61
- package/template/tsconfig.json +0 -23
- package/template/tsconfig.server.json +0 -11
- package/template/web/src/helpers.ts +0 -4
- package/template/web/src/index.css +0 -31
- package/template/web/src/widgets/magic-8-ball.tsx +0 -24
- package/template/web/vite.config.ts +0 -15
- /package/{template → templates/blank}/alpic.json +0 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { search } from "../catalog/index.js";
|
|
3
|
+
import {
|
|
4
|
+
CAROUSEL_MAX_SIZE,
|
|
5
|
+
CAROUSEL_RANGE,
|
|
6
|
+
MIN_SEARCH_ITERATIONS,
|
|
7
|
+
} from "../config.js";
|
|
8
|
+
import { PriceSchema, type SearchResult, SpecSchema } from "../types.js";
|
|
9
|
+
|
|
10
|
+
// The `search-products` tool: keyword + filters in, matching products out as
|
|
11
|
+
// structured output for the model. It has NO view — include only what the model
|
|
12
|
+
// needs to curate (ids + properties), never presentational data (images, media);
|
|
13
|
+
// render-carousel handles that. Data access lives in `src/catalog/`; everything
|
|
14
|
+
// else this tool needs lives in this file.
|
|
15
|
+
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Input
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
const inputSchema = {
|
|
21
|
+
// @todo: tune this guidance to your catalog's vocabulary. The model reads
|
|
22
|
+
// it to turn conversational input into a good keyword.
|
|
23
|
+
keyword: z.string().describe(
|
|
24
|
+
`\
|
|
25
|
+
Short noun phrases extracted from conversational input. Never pass full sentences. \
|
|
26
|
+
Include color, material, and style descriptors for accuracy. \
|
|
27
|
+
For vague gift or occasion queries without a clear product type, use broad category terms.`,
|
|
28
|
+
),
|
|
29
|
+
|
|
30
|
+
// @todo: set the sort options your backend supports (or remove).
|
|
31
|
+
sort: z.enum(["price-asc", "price-desc"]).optional().describe("Sort order."),
|
|
32
|
+
|
|
33
|
+
// @todo: declare the filters your catalog supports. Add one param per
|
|
34
|
+
// facet (category, color, size...), each optional so the model only sends
|
|
35
|
+
// what the user asked for. `priceRange` below is just an example, remove it.
|
|
36
|
+
priceRange: z
|
|
37
|
+
.string()
|
|
38
|
+
.optional()
|
|
39
|
+
.describe(
|
|
40
|
+
"Price range in dollars. Format: 'min-max' e.g. '0-500', '1000-2000'.",
|
|
41
|
+
),
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
export type SearchInput = z.infer<z.ZodObject<typeof inputSchema>>;
|
|
45
|
+
|
|
46
|
+
// ---------------------------------------------------------------------------
|
|
47
|
+
// Output — model-facing grounding, returned in structuredContent.
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
const productSchema = z.object({
|
|
51
|
+
id: z.string().describe("Stable product ID; pass to render-carousel."),
|
|
52
|
+
title: z.string(),
|
|
53
|
+
description: z.string().optional(),
|
|
54
|
+
price: PriceSchema.optional(),
|
|
55
|
+
outOfStock: z
|
|
56
|
+
.boolean()
|
|
57
|
+
.optional()
|
|
58
|
+
.describe("True when the product is not purchasable."),
|
|
59
|
+
specs: z
|
|
60
|
+
.array(SpecSchema)
|
|
61
|
+
.describe("Product-specific facts to curate on (material, dimensions…)."),
|
|
62
|
+
|
|
63
|
+
// @todo: Add whatever custom fields the model should curate on as real types,
|
|
64
|
+
// not `specs` strings (e.g. `rating`, `discountPct`, `badges`).
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const outputSchema = {
|
|
68
|
+
products: z.array(productSchema).describe("Matching products, sorted."),
|
|
69
|
+
pages: z
|
|
70
|
+
.object({
|
|
71
|
+
current: z.number(),
|
|
72
|
+
total: z.number(),
|
|
73
|
+
})
|
|
74
|
+
.optional()
|
|
75
|
+
.describe("Pagination: current page and total page count."),
|
|
76
|
+
totalHits: z
|
|
77
|
+
.number()
|
|
78
|
+
.optional()
|
|
79
|
+
.describe("Total matching products across all pages."),
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
type SearchOutput = z.infer<z.ZodObject<typeof outputSchema>>;
|
|
83
|
+
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
// Mapping: project each product's `card` into the model-facing grounding
|
|
86
|
+
// (outputSchema), dropping presentational fields (media, url).
|
|
87
|
+
// @todo: choose what the model sees per product. Grounding only: the model
|
|
88
|
+
// curates on facts, so presentational data never belongs here.
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
|
|
91
|
+
function toStructuredContent({
|
|
92
|
+
products,
|
|
93
|
+
pages,
|
|
94
|
+
totalHits,
|
|
95
|
+
}: SearchResult): SearchOutput {
|
|
96
|
+
const results: SearchOutput["products"] = [];
|
|
97
|
+
for (const { id, card } of products) {
|
|
98
|
+
results.push({
|
|
99
|
+
id,
|
|
100
|
+
title: card.title,
|
|
101
|
+
description: card.description,
|
|
102
|
+
price: card.price,
|
|
103
|
+
outOfStock: card.outOfStock,
|
|
104
|
+
specs: card.specs,
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return { products: results, pages, totalHits };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ---------------------------------------------------------------------------
|
|
111
|
+
// Narration — framing + next-step instructions for the model. The products
|
|
112
|
+
// themselves ride in structuredContent; this text carries NO result data.
|
|
113
|
+
// @todo: customize the NEXT STEPS guidance below for your flow (keep searching
|
|
114
|
+
// vs. curate and render). Remind the model to ground claims in the structured
|
|
115
|
+
// results and never invent facts.
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
|
|
118
|
+
function narrate({ products }: SearchOutput): string {
|
|
119
|
+
const size = products.length;
|
|
120
|
+
|
|
121
|
+
if (size === 0) {
|
|
122
|
+
return `\
|
|
123
|
+
No products found.
|
|
124
|
+
|
|
125
|
+
NEXT STEP: Broaden the keyword or relax filters, then search again.`;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
if (size < CAROUSEL_MAX_SIZE) {
|
|
129
|
+
return `\
|
|
130
|
+
Only a few results.
|
|
131
|
+
|
|
132
|
+
NEXT STEPS:
|
|
133
|
+
1. If the client asked for a specific product by name, these are fine: curate and call render-carousel with the selected IDs.
|
|
134
|
+
2. Otherwise, search again with broader terms before rendering.`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return `\
|
|
138
|
+
Enough results to present.
|
|
139
|
+
|
|
140
|
+
NEXT STEPS:
|
|
141
|
+
1. Curate the best matches for the client's intent from the structured results.
|
|
142
|
+
2. Write your recommendation mentioning the selected products.
|
|
143
|
+
3. Call render-carousel with the selected IDs.`;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ---------------------------------------------------------------------------
|
|
147
|
+
// Tool (registered from server.ts to keep the typed tool chain intact)
|
|
148
|
+
// ---------------------------------------------------------------------------
|
|
149
|
+
|
|
150
|
+
export const searchProductsDefinition = {
|
|
151
|
+
name: "search-products" as const,
|
|
152
|
+
|
|
153
|
+
// @todo: describe YOUR catalog and how the agent should search and curate
|
|
154
|
+
// it. This is the model's main guide: be specific about your categories,
|
|
155
|
+
// the multi-call search loop, and when to render vs. keep searching.
|
|
156
|
+
description: `\
|
|
157
|
+
Search the product catalog. Handles any query: specific products, broad categories, gifts, occasions, or open discovery.
|
|
158
|
+
Never assume a category is unavailable: always search before responding.
|
|
159
|
+
|
|
160
|
+
The response is data only: a list of matching products (name, ID, price, description, and any product-specific facts) plus pagination and the available filters. The raw results are for your eyes only: the client never sees them.
|
|
161
|
+
|
|
162
|
+
NEVER describe or characterize the raw results to the client: do not mention how many there are, what categories they fall into, or that they look off-topic.
|
|
163
|
+
|
|
164
|
+
Act on the response as follows:
|
|
165
|
+
|
|
166
|
+
- FIRST SEARCH: use keywords only (plus sort if needed).
|
|
167
|
+
- ITERATE: a single search is not always enough. Run several searches (${MIN_SEARCH_ITERATIONS} minimum) before rendering: vary the keyword, apply a filter, or page deeper, and compare results across them. Quality comes from this multi-call exploration; one call then render gives shallow results.
|
|
168
|
+
- CURATION: read results and pick the best matches for the client's intent, grounding your choice in each product's description. If zero results, broaden the keyword or relax filters and search again: do NOT call render-carousel. If fewer than 3 results and the user didn't ask for a specific product, search again with broader terms. Only after exploring across several searches, call render-carousel with the selected IDs.
|
|
169
|
+
- PRESENT: Once you have ${CAROUSEL_RANGE} distinct, relevant products, call render-carousel with their IDs. Recommend ONLY AFTER the carousel displays, in carousel order.
|
|
170
|
+
|
|
171
|
+
The sweet spot is ${CAROUSEL_RANGE} products.
|
|
172
|
+
`,
|
|
173
|
+
annotations: {
|
|
174
|
+
readOnlyHint: true,
|
|
175
|
+
openWorldHint: false,
|
|
176
|
+
destructiveHint: false,
|
|
177
|
+
},
|
|
178
|
+
|
|
179
|
+
// @todo: customize the status messages shown in ChatGPT while the tool runs.
|
|
180
|
+
_meta: {
|
|
181
|
+
"openai/toolInvocation/invoking": "Searching the catalog",
|
|
182
|
+
"openai/toolInvocation/invoked": "Searched the catalog",
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
inputSchema,
|
|
186
|
+
outputSchema,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
export async function searchProductsHandler(input: SearchInput) {
|
|
190
|
+
const results = toStructuredContent(await search(input));
|
|
191
|
+
return {
|
|
192
|
+
structuredContent: results,
|
|
193
|
+
content: [{ type: "text" as const, text: narrate(results) }],
|
|
194
|
+
isError: false,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
export const PriceSchema = z.object({
|
|
4
|
+
amount: z.number(),
|
|
5
|
+
currency: z.string(),
|
|
6
|
+
});
|
|
7
|
+
export type Price = z.infer<typeof PriceSchema>;
|
|
8
|
+
|
|
9
|
+
// A product-specific fact (an objective spec: material, dimensions, capacity,
|
|
10
|
+
// care…). `label` is optional so a fact can be a bare value (e.g. "Waterproof").
|
|
11
|
+
export const SpecSchema = z.object({
|
|
12
|
+
label: z.string().optional(),
|
|
13
|
+
value: z.string(),
|
|
14
|
+
});
|
|
15
|
+
export type Spec = z.infer<typeof SpecSchema>;
|
|
16
|
+
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Product model — what the catalog providers in `src/catalog/` return and the
|
|
19
|
+
// views render. Model: variant-as-full-product. Each `Variant` is a complete,
|
|
20
|
+
// buyable product (its own title, price, media). A `Product` ties sibling
|
|
21
|
+
// variants together and declares the axes (`Option`s) they vary on. A product
|
|
22
|
+
// with no variations is just a product with a single variant and no options.
|
|
23
|
+
// ---------------------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
// One selectable value on an axis, e.g. the "Black" choice on the "Color" axis.
|
|
26
|
+
type OptionValue = {
|
|
27
|
+
id: string; // stable key referenced by Variant.selection, e.g. "black"
|
|
28
|
+
label: string; // shown to the user, e.g. "Black"
|
|
29
|
+
media?: string; // optional swatch / image representing this value
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// A variation axis the variants differ on, e.g. Color or Size.
|
|
33
|
+
export type Option = {
|
|
34
|
+
id: string; // stable key, used as a key in Variant.selection, e.g. "color"
|
|
35
|
+
label: string; // shown to the user, e.g. "Color"
|
|
36
|
+
values: OptionValue[]; // in display order
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Display fields shared by a Variant and by a product's `card`.
|
|
40
|
+
type Meta = {
|
|
41
|
+
title: string;
|
|
42
|
+
description?: string;
|
|
43
|
+
price?: Price;
|
|
44
|
+
media: string[]; // images for this item; media[0] is the primary/cover
|
|
45
|
+
url?: string; // link to this item's external product page
|
|
46
|
+
outOfStock?: boolean; // true = not purchasable
|
|
47
|
+
// Objective, product-specific facts (material, dimensions, capacity, care…),
|
|
48
|
+
// rendered as-is. Each fact's label is optional.
|
|
49
|
+
specs: Spec[];
|
|
50
|
+
|
|
51
|
+
// @todo: Add whatever custom fields the carousel should render as real types
|
|
52
|
+
// (e.g. `rating` → stars, `discountPct` → badge, `badges` → chips).
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// One buyable product: full display Meta plus which value it takes on each axis.
|
|
56
|
+
export type Variant = Meta & {
|
|
57
|
+
id: string; // SKU / article number; unique within the catalog
|
|
58
|
+
// The chosen value per axis: keys are Option.id, values are OptionValue.id.
|
|
59
|
+
// e.g. { color: "black", size: "40" }
|
|
60
|
+
selection: Record<string, string>;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// A product: one carousel card backed by one or more variants and the axes they
|
|
64
|
+
// vary on (none for a single-variant product).
|
|
65
|
+
export type Product = {
|
|
66
|
+
id: string; // stable product key
|
|
67
|
+
// The axes the variants vary on, in display order. Order is semantic: the
|
|
68
|
+
// detail picker narrows availability top-down (each axis constrained by the
|
|
69
|
+
// ones before it), so put the imagery-driving axis (usually color) first.
|
|
70
|
+
options: Option[];
|
|
71
|
+
// Only the variants that actually exist. A missing combination (e.g. no
|
|
72
|
+
// { color: "black", size: "40" }) is simply absent from this list — that is how
|
|
73
|
+
// contingent variations are expressed. Derive the selectable values for an axis
|
|
74
|
+
// by filtering this list on the choices already made.
|
|
75
|
+
variants: Variant[];
|
|
76
|
+
// The product's carousel card. Surfaced both in the carousel (the view
|
|
77
|
+
// renders it) and to the model (structuredContent is projected from it).
|
|
78
|
+
card: Meta;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// What a catalog provider's `search` returns. `pages` and `totalHits` are
|
|
82
|
+
// optional: not every backend reports them.
|
|
83
|
+
export type SearchResult = {
|
|
84
|
+
products: Product[];
|
|
85
|
+
pages?: { current: number; total: number };
|
|
86
|
+
totalHits?: number;
|
|
87
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { style } from "@vanilla-extract/css";
|
|
2
|
+
import { colors, primitives } from "../../../design/tokens";
|
|
3
|
+
|
|
4
|
+
// Two-column breakpoint. Layout is driven by the pane's own width (container
|
|
5
|
+
// query), never the viewport, so a phone and a resized desktop pane agree.
|
|
6
|
+
const TWO_COLUMN_MIN_WIDTH = "560px";
|
|
7
|
+
|
|
8
|
+
export const detail = style({
|
|
9
|
+
containerType: "inline-size",
|
|
10
|
+
maxHeight: "100dvh",
|
|
11
|
+
overflowY: "auto",
|
|
12
|
+
padding: primitives.space.s,
|
|
13
|
+
// Clear the notch / home indicator when the page bleeds to the screen edge.
|
|
14
|
+
paddingBottom: `calc(${primitives.space.s} + env(safe-area-inset-bottom))`,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
// Product / variant id, idiomatically top-right. @todo: reposition (drop the
|
|
18
|
+
// right align, or move it in the JSX) or remove it.
|
|
19
|
+
export const reference = style({
|
|
20
|
+
textAlign: "right",
|
|
21
|
+
color: colors.content.subtle,
|
|
22
|
+
marginBottom: primitives.space["3xs"],
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Single column by default; two columns (gallery | info) once the pane is wide.
|
|
26
|
+
export const grid = style({
|
|
27
|
+
display: "flex",
|
|
28
|
+
flexDirection: "column",
|
|
29
|
+
gap: primitives.space.s,
|
|
30
|
+
maxWidth: "1099px",
|
|
31
|
+
marginInline: "auto",
|
|
32
|
+
"@container": {
|
|
33
|
+
[`(min-width: ${TWO_COLUMN_MIN_WIDTH})`]: {
|
|
34
|
+
display: "grid",
|
|
35
|
+
// `minmax(0, 1fr)` (not `1fr`) lets a column shrink below its content's
|
|
36
|
+
// intrinsic width, so a chip row scrolls/wraps instead of blowing out.
|
|
37
|
+
gridTemplateColumns: "minmax(0, 1fr) minmax(0, 1fr)",
|
|
38
|
+
gridTemplateAreas: '"gallery info"',
|
|
39
|
+
alignItems: "start",
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
export const galleryCell = style({
|
|
45
|
+
"@container": {
|
|
46
|
+
[`(min-width: ${TWO_COLUMN_MIN_WIDTH})`]: {
|
|
47
|
+
gridArea: "gallery",
|
|
48
|
+
position: "sticky",
|
|
49
|
+
top: primitives.space.s,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// The info column owns all inter-section spacing; sections set no outer margin.
|
|
55
|
+
export const info = style({
|
|
56
|
+
display: "flex",
|
|
57
|
+
flexDirection: "column",
|
|
58
|
+
gap: primitives.space.xs,
|
|
59
|
+
"@container": {
|
|
60
|
+
[`(min-width: ${TWO_COLUMN_MIN_WIDTH})`]: { gridArea: "info" },
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
export const title = style({ color: colors.content.intense });
|
|
65
|
+
|
|
66
|
+
export const price = style({ color: colors.content.intense });
|
|
67
|
+
|
|
68
|
+
// Product facts as a simple list: one line per fact, "label: value" (or just
|
|
69
|
+
// the value when unlabeled). marginTop separates it from the section heading.
|
|
70
|
+
// @todo: reshape freely (a table, grouped sections, inline chips…)
|
|
71
|
+
export const specList = style({
|
|
72
|
+
display: "flex",
|
|
73
|
+
flexDirection: "column",
|
|
74
|
+
gap: primitives.space["3xs"],
|
|
75
|
+
marginTop: primitives.space["3xs"],
|
|
76
|
+
marginBottom: 0,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
// One fact on a line: "label:" then value.
|
|
80
|
+
export const specRow = style({
|
|
81
|
+
display: "flex",
|
|
82
|
+
gap: primitives.space["4xs"],
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
export const specLabel = style({
|
|
86
|
+
margin: 0,
|
|
87
|
+
color: colors.content.subtle,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
export const specValue = style({
|
|
91
|
+
margin: 0,
|
|
92
|
+
color: colors.content.intense,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Primary CTA. @todo: tune to your brand; add a secondary action beside it
|
|
96
|
+
// (ask-the-assistant, contact) as a per-catalog extension.
|
|
97
|
+
export const cta = style({
|
|
98
|
+
minHeight: "44px",
|
|
99
|
+
padding: `${primitives.space["3xs"]} ${primitives.space.s}`,
|
|
100
|
+
borderRadius: primitives.radius.m,
|
|
101
|
+
border: "none",
|
|
102
|
+
backgroundColor: colors.common.accent,
|
|
103
|
+
color: colors.content.invertIntense,
|
|
104
|
+
fontFamily: primitives.font.family.primary,
|
|
105
|
+
fontSize: primitives.font.size.m,
|
|
106
|
+
fontWeight: primitives.font.weight.medium,
|
|
107
|
+
cursor: "pointer",
|
|
108
|
+
selectors: {
|
|
109
|
+
"&:disabled": {
|
|
110
|
+
backgroundColor: colors.surface.intense,
|
|
111
|
+
color: colors.content.subtle,
|
|
112
|
+
cursor: "not-allowed",
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
});
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import type { Product } from "../../../types.js";
|
|
2
|
+
import { DetailView } from "./index";
|
|
3
|
+
|
|
4
|
+
function shot(fill: string) {
|
|
5
|
+
return `data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Crect width='400' height='400' fill='%23${fill}'/%3E%3Ccircle cx='200' cy='200' r='110' fill='%23ffffff' fill-opacity='0.5'/%3E%3C/svg%3E`;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// A long media set (primary shot + several accents) so the desktop thumbnail
|
|
9
|
+
// rail is taller than the image and overflows past its bottom.
|
|
10
|
+
const ACCENT_FILLS = [
|
|
11
|
+
"c9d4f5",
|
|
12
|
+
"f5d4c9",
|
|
13
|
+
"d4f5c9",
|
|
14
|
+
"f5f0c9",
|
|
15
|
+
"e0c9f5",
|
|
16
|
+
"c9f5f0",
|
|
17
|
+
"f5c9e0",
|
|
18
|
+
"d9d9d9",
|
|
19
|
+
];
|
|
20
|
+
|
|
21
|
+
function galleryMedia(primaryFill: string): string[] {
|
|
22
|
+
const media = [shot(primaryFill)];
|
|
23
|
+
for (const fill of ACCENT_FILLS) {
|
|
24
|
+
media.push(shot(fill));
|
|
25
|
+
}
|
|
26
|
+
return media;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const DESCRIPTION =
|
|
30
|
+
"A relaxed-fit jacket in water-repellent cotton.\n\nDropped shoulders, a two-way zip, and ribbed cuffs. Fully lined, with two zip pockets at the front and one inside.";
|
|
31
|
+
|
|
32
|
+
// One story, every picker behavior:
|
|
33
|
+
// - Hole in the matrix: {sand,L} does not exist, so under Sand, L is
|
|
34
|
+
// hard-disabled; switching to Sand while L is selected snaps Size to M.
|
|
35
|
+
// - Sold out: {black,L} renders struck but selectable; the CTA locks as
|
|
36
|
+
// "Out of stock".
|
|
37
|
+
// - Axis not applicable: the indigo colorway is one-size (no `size` key), so
|
|
38
|
+
// choosing "Indigo" hides the Size row; indigo resolves and stays buyable.
|
|
39
|
+
function jacket(
|
|
40
|
+
id: string,
|
|
41
|
+
color: string,
|
|
42
|
+
colorLabel: string,
|
|
43
|
+
size: string | null,
|
|
44
|
+
outOfStock = false,
|
|
45
|
+
): Product["variants"][number] {
|
|
46
|
+
const fill =
|
|
47
|
+
color === "sand" ? "d8c7a8" : color === "indigo" ? "3f4a8a" : "2b2b2b";
|
|
48
|
+
return {
|
|
49
|
+
id,
|
|
50
|
+
selection: size == null ? { color } : { color, size },
|
|
51
|
+
title: `Field jacket — ${colorLabel}`,
|
|
52
|
+
description: DESCRIPTION,
|
|
53
|
+
price: { amount: color === "black" ? 229 : 249, currency: "EUR" },
|
|
54
|
+
media: galleryMedia(fill),
|
|
55
|
+
url: "https://example.com/jacket",
|
|
56
|
+
outOfStock,
|
|
57
|
+
specs: [
|
|
58
|
+
{ label: "Material", value: "Water-repellent cotton" },
|
|
59
|
+
{ label: "Lining", value: "Recycled polyester" },
|
|
60
|
+
{ label: "Fit", value: "Relaxed" },
|
|
61
|
+
{ label: "Closure", value: "Two-way zip" },
|
|
62
|
+
{ label: "Pockets", value: "Two zip front, one inside" },
|
|
63
|
+
{ label: "Collar", value: "Stand-up" },
|
|
64
|
+
{ label: "Cuffs", value: "Ribbed" },
|
|
65
|
+
{ label: "Weight", value: "780 g" },
|
|
66
|
+
{ label: "Origin", value: "Made in Portugal" },
|
|
67
|
+
{ value: "Machine washable" }, // label-less fact (renders value only)
|
|
68
|
+
],
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const PRODUCT: Product = {
|
|
73
|
+
id: "field-jacket",
|
|
74
|
+
options: [
|
|
75
|
+
{
|
|
76
|
+
id: "color",
|
|
77
|
+
label: "Color",
|
|
78
|
+
values: [
|
|
79
|
+
{ id: "black", label: "Black", media: shot("2b2b2b") },
|
|
80
|
+
{ id: "sand", label: "Sand", media: shot("d8c7a8") },
|
|
81
|
+
{ id: "indigo", label: "Indigo", media: shot("3f4a8a") },
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: "size",
|
|
86
|
+
label: "Size",
|
|
87
|
+
values: [
|
|
88
|
+
{ id: "m", label: "M" },
|
|
89
|
+
{ id: "l", label: "L" },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
variants: [
|
|
94
|
+
jacket("fj-black-m", "black", "Black", "m"),
|
|
95
|
+
jacket("fj-black-l", "black", "Black", "l", true),
|
|
96
|
+
jacket("fj-sand-m", "sand", "Sand", "m"),
|
|
97
|
+
jacket("fj-indigo", "indigo", "Indigo", null),
|
|
98
|
+
],
|
|
99
|
+
card: {
|
|
100
|
+
title: "Field jacket",
|
|
101
|
+
price: { amount: 229, currency: "EUR" },
|
|
102
|
+
media: [shot("2b2b2b")],
|
|
103
|
+
specs: [],
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const Default = () => <DetailView product={PRODUCT} />;
|
|
108
|
+
|
|
109
|
+
// Single-variant product: no picker, buyable immediately.
|
|
110
|
+
const SIMPLE: Product = {
|
|
111
|
+
id: "tote",
|
|
112
|
+
options: [],
|
|
113
|
+
variants: [
|
|
114
|
+
{
|
|
115
|
+
id: "tote",
|
|
116
|
+
selection: {},
|
|
117
|
+
title: "Canvas tote",
|
|
118
|
+
description: "A sturdy everyday canvas tote.",
|
|
119
|
+
price: { amount: 39, currency: "EUR" },
|
|
120
|
+
media: [shot("e1e1e1")],
|
|
121
|
+
url: "https://example.com/tote",
|
|
122
|
+
specs: [{ label: "Material", value: "Canvas" }],
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
card: {
|
|
126
|
+
title: "Canvas tote",
|
|
127
|
+
price: { amount: 39, currency: "EUR" },
|
|
128
|
+
media: [shot("e1e1e1")],
|
|
129
|
+
specs: [],
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const SingleVariant = () => <DetailView product={SIMPLE} />;
|