create-skybridge 0.0.0-dev.1b2cb1b → 0.0.0-dev.1b3b81f

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 (65) hide show
  1. package/package.json +2 -2
  2. package/templates/blank/node_modules/.bin/alpic +2 -2
  3. package/templates/blank/node_modules/.bin/tsx +2 -2
  4. package/templates/blank/node_modules/.bin/vite +2 -2
  5. package/templates/blank/package.json +6 -6
  6. package/templates/blank/vite.config.ts +6 -0
  7. package/templates/demo/node_modules/.bin/alpic +2 -2
  8. package/templates/demo/node_modules/.bin/tsx +2 -2
  9. package/templates/demo/node_modules/.bin/vite +2 -2
  10. package/templates/demo/package.json +10 -10
  11. package/templates/demo/vite.config.ts +6 -0
  12. package/templates/ecom/.ladle/components.tsx +26 -0
  13. package/templates/ecom/.ladle/config.mjs +11 -0
  14. package/templates/ecom/.ladle/vite.config.ts +11 -0
  15. package/templates/ecom/_gitignore +1 -0
  16. package/templates/ecom/node_modules/.bin/alpic +2 -2
  17. package/templates/ecom/node_modules/.bin/ladle +21 -0
  18. package/templates/ecom/node_modules/.bin/vite +2 -2
  19. package/templates/ecom/package.json +14 -2
  20. package/templates/ecom/src/components/chip.css.ts +63 -0
  21. package/templates/ecom/src/components/chip.stories.tsx +27 -0
  22. package/templates/ecom/src/components/chip.tsx +49 -0
  23. package/templates/ecom/src/components/empty-state.stories.tsx +3 -0
  24. package/templates/ecom/src/components/empty-state.tsx +12 -0
  25. package/templates/ecom/src/components/expandable-text.css.ts +49 -0
  26. package/templates/ecom/src/components/expandable-text.stories.tsx +20 -0
  27. package/templates/ecom/src/components/expandable-text.tsx +53 -0
  28. package/templates/ecom/src/components/image-gallery.css.ts +172 -0
  29. package/templates/ecom/src/components/image-gallery.stories.tsx +30 -0
  30. package/templates/ecom/src/components/image-gallery.tsx +163 -0
  31. package/templates/ecom/src/components/product-card.css.ts +159 -0
  32. package/templates/ecom/src/components/product-card.stories.tsx +58 -0
  33. package/templates/ecom/src/components/product-card.tsx +102 -0
  34. package/templates/ecom/src/components/product-carousel.css.ts +134 -0
  35. package/templates/ecom/src/components/product-carousel.stories.tsx +64 -0
  36. package/templates/ecom/src/components/product-carousel.tsx +202 -0
  37. package/templates/ecom/src/components/variant-picker.css.ts +27 -0
  38. package/templates/ecom/src/components/variant-picker.stories.tsx +67 -0
  39. package/templates/ecom/src/components/variant-picker.tsx +70 -0
  40. package/templates/ecom/src/components/view-frame.css.ts +22 -0
  41. package/templates/ecom/src/components/view-frame.tsx +27 -0
  42. package/templates/ecom/src/config.ts +12 -0
  43. package/templates/ecom/src/design/contract.css.ts +39 -0
  44. package/templates/ecom/src/design/fonts.css +15 -0
  45. package/templates/ecom/src/design/primitives.css.ts +101 -0
  46. package/templates/ecom/src/design/recipes/typography.css.ts +75 -0
  47. package/templates/ecom/src/design/sprinkles.css.ts +128 -0
  48. package/templates/ecom/src/design/themes/dark.css.ts +36 -0
  49. package/templates/ecom/src/design/themes/light.css.ts +36 -0
  50. package/templates/ecom/src/design/tokens.ts +8 -0
  51. package/templates/ecom/src/i18n.ts +35 -0
  52. package/templates/ecom/src/index.css +9 -0
  53. package/templates/ecom/src/lib/cx.ts +9 -0
  54. package/templates/ecom/src/lib/format.ts +8 -55
  55. package/templates/ecom/src/lib/variants.ts +150 -0
  56. package/templates/ecom/src/server.ts +15 -97
  57. package/templates/ecom/src/tools/render-carousel.ts +245 -0
  58. package/templates/ecom/src/tools/search-products.ts +185 -0
  59. package/templates/ecom/src/types.ts +15 -0
  60. package/templates/ecom/src/views/carousel/detail/detail.css.ts +113 -0
  61. package/templates/ecom/src/views/carousel/detail/detail.stories.tsx +126 -0
  62. package/templates/ecom/src/views/carousel/detail/index.tsx +254 -0
  63. package/templates/ecom/src/views/carousel/index.tsx +234 -0
  64. package/templates/ecom/tsconfig.json +6 -0
  65. package/templates/ecom/vite.config.ts +4 -2
@@ -1,65 +1,20 @@
1
1
  import { existsSync } from "node:fs";
2
2
  import { McpServer } from "skybridge/server";
3
- import { z } from "zod";
3
+ import { CAROUSEL_RANGE, MIN_SEARCH_ITERATIONS } from "./config.js";
4
4
  import {
5
- type NarrateSearchResultsInput,
6
- narrateSearchResults,
7
- } from "./lib/format.js";
5
+ renderCarouselDefinition,
6
+ renderCarouselHandler,
7
+ } from "./tools/render-carousel.js";
8
+ import {
9
+ searchProductsDefinition,
10
+ searchProductsHandler,
11
+ } from "./tools/search-products.js";
8
12
 
9
13
  // Load .env into process.env when present (native to Node, no dependency).
10
14
  if (existsSync(".env")) {
11
15
  process.loadEnvFile();
12
16
  }
13
17
 
14
- // @todo: how many products the carousel curates toward. CAROUSEL_RANGE is
15
- // interpolated into the prompts below so the model aims for the right amount.
16
- const CAROUSEL_MAX_SIZE = 6;
17
- const CAROUSEL_RANGE = `${Math.ceil(CAROUSEL_MAX_SIZE / 2)}-${CAROUSEL_MAX_SIZE}`;
18
-
19
- // @todo: minimum number of searches the model runs before rendering. Feeds the
20
- // prompts below to enforce multi-call exploration; raise for deeper results.
21
- const MIN_SEARCH_ITERATIONS = 2;
22
-
23
- const inputSchema = {
24
- // @todo: tune this guidance to your catalog's vocabulary. The model reads
25
- // it to turn conversational input into a good keyword.
26
- keyword: z.string().describe(
27
- `\
28
- Short noun phrases extracted from conversational input. Never pass full sentences. \
29
- ALWAYS use the singular form, not the plural. \
30
- Include color, material, and style descriptors for accuracy. \
31
- For vague gift or occasion queries without a clear product type, use broad category terms. \
32
- Preserve the existing keyword across filter refinements; only replace when the user makes a completely different request.`,
33
- ),
34
-
35
- // @todo: set the sort options your backend supports (or remove).
36
- sort: z.enum(["price-asc", "price-desc"]).optional().describe("Sort order."),
37
-
38
- // @todo: declare the filters your catalog supports. Add one param per
39
- // facet (category, color, size...), each optional so the model only sends
40
- // what the user asked for. `priceRange` below is just an example, remove it.
41
- priceRange: z
42
- .string()
43
- .optional()
44
- .describe(
45
- "Price range in dollars. Format: 'min-max' e.g. '0-500', '1000-2000'.",
46
- ),
47
- };
48
-
49
- type SearchInput = z.infer<z.ZodObject<typeof inputSchema>>;
50
-
51
- function search(input: SearchInput): NarrateSearchResultsInput {
52
- // @todo: plug in your product API / DB. Query it with the input params and map
53
- // each result into `products` below. `pages` and `totalHits` are optional.
54
- return {
55
- keyword: input.keyword,
56
- products: [], // { id: string; properties: { name: string; value: string[] }[] }[]
57
- pages: { current: 1, total: 1 },
58
- totalHits: 0,
59
- carouselMaxSize: CAROUSEL_MAX_SIZE,
60
- };
61
- }
62
-
63
18
  const server = new McpServer(
64
19
  {
65
20
  // @todo: name and version your app.
@@ -71,54 +26,17 @@ const server = new McpServer(
71
26
  instructions: `\
72
27
  Two phases:
73
28
 
74
- SEARCH: Call search_products ${MIN_SEARCH_ITERATIONS}+ times before presenting—never off one call. \
29
+ SEARCH: Call search-products ${MIN_SEARCH_ITERATIONS}+ times before presenting—never off one call. \
75
30
  Vary the keyword, apply filters from a prior response, or page deeper. \
76
31
  Stay silent while searching: emit NO text between calls. Speak only \
77
- once the carousel renders. Never call a category unavailable before searching.`,
78
- },
79
- ).registerTool(
80
- {
81
- name: "search_products",
82
- // @todo: describe YOUR catalog and how the agent should search and curate
83
- // it. This is the model's main guide: be specific about your categories,
84
- // the multi-call search loop, and when to render vs. keep searching.
85
- description: `\
86
- Search the product catalog. Handles any query: specific products, broad categories, gifts, occasions, or open discovery.
87
- Never assume a category is unavailable: always search before responding.
88
-
89
- The response is data only: a list of matching products (name, ID, price, description, and any product-specific attributes) plus pagination and the available filters. The raw results are for your eyes only: the client never sees them.
32
+ once the carousel renders. Never call a category unavailable before searching.
90
33
 
91
- 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. While searching, stay silent: do not narrate what you are doing, announce searches, or report progress between tool calls. Speak only once the carousel is rendered.
92
-
93
- Act on the response as follows:
94
-
95
- - FIRST SEARCH: use the keyword only (plus sort if needed). Read the available filters in the response; these are the only valid filter options for follow-ups.
96
- - REFINEMENT: if the user's intent matches an available filter, apply it. If it doesn't match any filter, start a new keyword search.
97
- - ITERATE: a single search is never 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.
98
- - 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.
99
- - PRESENT: Once you have ${CAROUSEL_RANGE} distinct, relevant products, call render-carousel with their IDs. Recommend ONLY AFTER the carousel displays, in carousel order.
100
-
101
- The sweet spot is ${CAROUSEL_RANGE} products.
102
- `,
103
- annotations: {
104
- readOnlyHint: true,
105
- openWorldHint: false,
106
- destructiveHint: false,
107
- },
108
- // @todo: customize the status messages shown in ChatGPT while the tool runs.
109
- _meta: {
110
- "openai/toolInvocation/invoking": "Searching",
111
- "openai/toolInvocation/invoked": "Done searching",
112
- },
113
- inputSchema,
114
- outputSchema: {},
115
- },
116
- (input) => {
117
- const results = search(input);
118
- const { content } = narrateSearchResults(results);
119
- return { structuredContent: {}, content, isError: false };
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.`,
120
36
  },
121
- );
37
+ )
38
+ .registerTool(searchProductsDefinition, searchProductsHandler)
39
+ .registerTool(renderCarouselDefinition, renderCarouselHandler);
122
40
 
123
41
  export default await server.run();
124
42
 
@@ -0,0 +1,245 @@
1
+ import { z } from "zod";
2
+ import { CAROUSEL_MAX_SIZE, CAROUSEL_RANGE } from "../config.js";
3
+ import { type Price, PriceSchema, type Spec, SpecSchema } from "../types.js";
4
+
5
+ // The `render-carousel` tool: takes the IDs the model curated and returns the
6
+ // matching products for the carousel view to render.
7
+ // Everything this tool needs lives in this file.
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // Product model
11
+ // ---------------------------------------------------------------------------
12
+ // Model: variant-as-full-product. Each `Variant` is a complete, buyable product
13
+ // (its own title, price, media). A `Product` ties sibling variants together and
14
+ // declares the axes (`Option`s) they vary on. A product with no variations is
15
+ // just a product with a single variant and no options.
16
+
17
+ // One selectable value on an axis, e.g. the "Black" choice on the "Color" axis.
18
+ type OptionValue = {
19
+ id: string; // stable key referenced by Variant.selection, e.g. "black"
20
+ label: string; // shown to the user, e.g. "Black"
21
+ media?: string; // optional swatch / image representing this value
22
+ };
23
+
24
+ // A variation axis the variants differ on, e.g. Color or Size.
25
+ type Option = {
26
+ id: string; // stable key, used as a key in Variant.selection, e.g. "color"
27
+ label: string; // shown to the user, e.g. "Color"
28
+ values: OptionValue[]; // in display order
29
+ };
30
+
31
+ // Display fields shared by a Variant and by a product's `card`.
32
+ type Meta = {
33
+ title: string;
34
+ description?: string;
35
+ price?: Price;
36
+ media: string[]; // images for this item; media[0] is the primary/cover
37
+ url?: string; // link to this item's external product page
38
+ outOfStock?: boolean; // true = not purchasable
39
+ // Objective, product-specific facts (material, dimensions, capacity, care…),
40
+ // rendered as-is. Each fact's label is optional.
41
+ specs: Spec[];
42
+
43
+ // @todo: Add whatever custom fields the carousel should render as real types
44
+ // (e.g. `rating` → stars, `discountPct` → badge, `badges` → chips).
45
+ };
46
+
47
+ // One buyable product: full display Meta plus which value it takes on each axis.
48
+ export type Variant = Meta & {
49
+ id: string; // SKU / article number; unique within the catalog
50
+ // The chosen value per axis: keys are Option.id, values are OptionValue.id.
51
+ // e.g. { color: "black", size: "40" }
52
+ selection: Record<string, string>;
53
+ };
54
+
55
+ // A product: one carousel card backed by one or more variants and the axes they
56
+ // vary on (none for a single-variant product).
57
+ export type Product = {
58
+ id: string; // stable product key
59
+ // The axes the variants vary on, in display order. Order is semantic: the
60
+ // detail picker narrows availability top-down (each axis constrained by the
61
+ // ones before it), so put the imagery-driving axis (usually color) first.
62
+ options: Option[];
63
+ // Only the variants that actually exist. A missing combination (e.g. no
64
+ // { color: "black", size: "40" }) is simply absent from this list — that is how
65
+ // contingent variations are expressed. Derive the selectable values for an axis
66
+ // by filtering this list on the choices already made.
67
+ variants: Variant[];
68
+ // The product's carousel card. Surfaced both in the carousel (the view
69
+ // renders it) and to the model (structuredContent is projected from it).
70
+ // How you build it depends on your mapping strategy: see getProducts.
71
+ card: Meta;
72
+ };
73
+
74
+ // ---------------------------------------------------------------------------
75
+ // Input
76
+ // ---------------------------------------------------------------------------
77
+
78
+ const inputSchema = {
79
+ ids: z
80
+ .array(z.string())
81
+ .min(1)
82
+ .max(CAROUSEL_MAX_SIZE)
83
+ .describe("Product IDs to present, in display order."),
84
+ };
85
+
86
+ type RenderInput = z.infer<z.ZodObject<typeof inputSchema>>;
87
+
88
+ // ---------------------------------------------------------------------------
89
+ // Output — model-facing grounding, for the LLM ONLY. The carousel view is NOT
90
+ // built from this; it renders from the full data in `_meta`. Keep it to what the
91
+ // model needs to reference and compare the displayed products afterward.
92
+ // ---------------------------------------------------------------------------
93
+
94
+ const outputSchema = {
95
+ products: z
96
+ .array(
97
+ z.object({
98
+ id: z.string().describe("Product SKU or reference."),
99
+ title: z.string(),
100
+ options: z
101
+ .array(z.object({ label: z.string(), values: z.array(z.string()) }))
102
+ .describe("Variations available (e.g. colors, sizes)."),
103
+ description: z.string().optional(),
104
+ price: PriceSchema.optional(),
105
+ outOfStock: z.boolean(),
106
+ specs: z
107
+ .array(SpecSchema)
108
+ .describe("Product-specific facts (material, dimensions, care…)."),
109
+ }),
110
+ )
111
+ .describe(
112
+ "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.",
113
+ ),
114
+ };
115
+
116
+ type RenderOutput = z.infer<z.ZodObject<typeof outputSchema>>;
117
+
118
+ // ---------------------------------------------------------------------------
119
+ // Data access
120
+ // ---------------------------------------------------------------------------
121
+
122
+ async function getProducts(_ids: string[]): Promise<Product[]> {
123
+ // @todo: fetch each id from your product API / DB and map the results into
124
+ // `Product`s (rename `_ids` -> `ids` once you use it).
125
+ //
126
+ // First decide your mapping strategy — it depends on your catalog:
127
+ // - no variants (simple products): one `Product`, a single variant, card = that variant, options: [],
128
+ // - grouped: one `Product` per product; `card` = union of its variants, one picture per requested variant
129
+ // - one card per requested variant: `card` = that variant
130
+ // Either way, set `variants` to ALL variants the source returns for the product;
131
+ // the detail view reads them so the client can switch variant. Order `options`
132
+ // with the imagery-driving axis first (see the Product type: order is semantic).
133
+ //
134
+ // Returns [] for now, so the carousel is empty.
135
+ return [];
136
+ }
137
+
138
+ // ---------------------------------------------------------------------------
139
+ // Mapping: trim each product's `card` and `options` into the model-facing
140
+ // grounding (outputSchema), dropping presentational fields (media, url). The
141
+ // full data stays in `_meta` for the view.
142
+ // @todo: choose what the model sees per product. Grounding only: no
143
+ // presentational data (media, styling); that rides in `_meta` for the view.
144
+ // ---------------------------------------------------------------------------
145
+
146
+ function toStructuredContent(products: Product[]): RenderOutput {
147
+ const groundingProducts: RenderOutput["products"] = [];
148
+
149
+ for (const product of products) {
150
+ const { card } = product;
151
+
152
+ const options: { label: string; values: string[] }[] = [];
153
+ for (const option of product.options) {
154
+ const values: string[] = [];
155
+ for (const value of option.values) {
156
+ values.push(value.label);
157
+ }
158
+ options.push({ label: option.label, values });
159
+ }
160
+
161
+ groundingProducts.push({
162
+ id: product.id,
163
+ title: card.title,
164
+ description: card.description,
165
+ price: card.price,
166
+ outOfStock: card.outOfStock ?? false,
167
+ options,
168
+ specs: card.specs,
169
+ });
170
+ }
171
+
172
+ return { products: groundingProducts };
173
+ }
174
+
175
+ // ---------------------------------------------------------------------------
176
+ // Tool (registered from server.ts to keep the typed tool chain intact)
177
+ // ---------------------------------------------------------------------------
178
+
179
+ export const renderCarouselDefinition = {
180
+ name: "render-carousel" as const,
181
+
182
+ // @todo: adapt the wording to your catalog and brand voice (tone, vocabulary,
183
+ // how to present products). The behavioral rules below apply to any catalog.
184
+ description: `\
185
+ Display the products you curated as an inline carousel for the client.
186
+
187
+ ## When to call
188
+ Call this AFTER searching and curating, and BEFORE writing your recommendation. Do not describe the products in text first; the carousel shows them. Stay silent until it has rendered, then speak.
189
+
190
+ ## What to pass
191
+ 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).
192
+
193
+ ## After the carousel
194
+ 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.
195
+
196
+ ## Accuracy
197
+ 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.`,
198
+ annotations: {
199
+ readOnlyHint: true,
200
+ openWorldHint: false,
201
+ destructiveHint: false,
202
+ },
203
+
204
+ // @todo: customize the status messages shown in ChatGPT while the tool runs.
205
+ _meta: {
206
+ "openai/toolInvocation/invoking": "Loading product carousel",
207
+ "openai/toolInvocation/invoked": "Loaded product carousel",
208
+ },
209
+
210
+ // The carousel and product details UI rendered inline in the conversation.
211
+ view: {
212
+ // `as const` keeps this a literal (like `name` above) so it matches the
213
+ // generated ViewNameRegistry; a bare string widens and fails the build.
214
+ component: "carousel" as const,
215
+ description: "Browse the curated products.",
216
+ // @todo: declare the CSP domains this view needs. Add your image origins to
217
+ // `resourceDomains` so product images load, and the product site to
218
+ // `redirectDomains` so the detail view's "View on site" link and the host's
219
+ // "Open in app" URL (useOpenExternal / setOpenInAppUrl) are allowed.
220
+ // csp: {
221
+ // resourceDomains: ["https://images.example.com"],
222
+ // redirectDomains: ["https://www.example.com"],
223
+ // },
224
+ },
225
+
226
+ inputSchema,
227
+ outputSchema,
228
+ };
229
+
230
+ export async function renderCarouselHandler({ ids }: RenderInput) {
231
+ const products = await getProducts(ids);
232
+
233
+ return {
234
+ // Full products (incl. variants) for the view; not in model context.
235
+ _meta: { products },
236
+ structuredContent: toStructuredContent(products),
237
+ content: [
238
+ {
239
+ type: "text" as const,
240
+ text: `Rendered ${products.length} product(s) in the carousel.`,
241
+ },
242
+ ],
243
+ isError: false,
244
+ };
245
+ }
@@ -0,0 +1,185 @@
1
+ import { z } from "zod";
2
+ import {
3
+ CAROUSEL_MAX_SIZE,
4
+ CAROUSEL_RANGE,
5
+ MIN_SEARCH_ITERATIONS,
6
+ } from "../config.js";
7
+ import { PriceSchema, SpecSchema } from "../types.js";
8
+
9
+ // The `search-products` tool: keyword + filters in, matching products out as
10
+ // structured output for the model. It has NO view — include only what the model
11
+ // needs to curate (ids + properties), never presentational data (images, media);
12
+ // render-carousel handles that. Everything this tool needs lives in this file.
13
+
14
+ // ---------------------------------------------------------------------------
15
+ // Input
16
+ // ---------------------------------------------------------------------------
17
+
18
+ const inputSchema = {
19
+ // @todo: tune this guidance to your catalog's vocabulary. The model reads
20
+ // it to turn conversational input into a good keyword.
21
+ keyword: z.string().describe(
22
+ `\
23
+ Short noun phrases extracted from conversational input. Never pass full sentences. \
24
+ ALWAYS use the singular form, not the plural. \
25
+ Include color, material, and style descriptors for accuracy. \
26
+ For vague gift or occasion queries without a clear product type, use broad category terms. \
27
+ Preserve the existing keyword across filter refinements; only replace when the user makes a completely different request.`,
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
+ 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
+ // Data access
86
+ // ---------------------------------------------------------------------------
87
+
88
+ function search(_input: SearchInput): SearchOutput {
89
+ // @todo: plug in your product API / DB. Query it with the input params and map
90
+ // each result into `products` below. `pages` and `totalHits` are optional.
91
+ return {
92
+ products: [], // { id: string; properties: { name: PropertyName; value: string[] }[] }[]
93
+ pages: { current: 1, total: 1 },
94
+ totalHits: 0,
95
+ };
96
+ }
97
+
98
+ // ---------------------------------------------------------------------------
99
+ // Narration — framing + next-step instructions for the model. The products
100
+ // themselves ride in structuredContent; this text carries NO result data.
101
+ // @todo: customize the NEXT STEPS guidance below for your flow (keep searching
102
+ // vs. curate and render). Remind the model to ground claims in the structured
103
+ // results and never invent facts.
104
+ // ---------------------------------------------------------------------------
105
+
106
+ function narrate({ products }: SearchOutput): string {
107
+ const size = products.length;
108
+
109
+ if (size === 0) {
110
+ return `\
111
+ No products found.
112
+
113
+ NEXT STEP: Broaden the keyword or relax filters, then search again.`;
114
+ }
115
+
116
+ if (size < CAROUSEL_MAX_SIZE) {
117
+ return `\
118
+ Only a few results.
119
+
120
+ NEXT STEPS:
121
+ 1. If the client asked for a specific product by name, these are fine: curate and call render-carousel with the selected IDs.
122
+ 2. Otherwise, search again with broader terms before rendering.`;
123
+ }
124
+
125
+ return `\
126
+ Enough results to present.
127
+
128
+ NEXT STEPS:
129
+ 1. Curate the best matches for the client's intent from the structured results.
130
+ 2. Write your recommendation mentioning the selected products.
131
+ 3. Call render-carousel with the selected IDs.`;
132
+ }
133
+
134
+ // ---------------------------------------------------------------------------
135
+ // Tool (registered from server.ts to keep the typed tool chain intact)
136
+ // ---------------------------------------------------------------------------
137
+
138
+ export const searchProductsDefinition = {
139
+ name: "search-products" as const,
140
+
141
+ // @todo: describe YOUR catalog and how the agent should search and curate
142
+ // it. This is the model's main guide: be specific about your categories,
143
+ // the multi-call search loop, and when to render vs. keep searching.
144
+ description: `\
145
+ Search the product catalog. Handles any query: specific products, broad categories, gifts, occasions, or open discovery.
146
+ Never assume a category is unavailable: always search before responding.
147
+
148
+ 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.
149
+
150
+ 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. While searching, stay silent: do not narrate what you are doing, announce searches, or report progress between tool calls. Speak only once the carousel is rendered.
151
+
152
+ Act on the response as follows:
153
+
154
+ - FIRST SEARCH: use the keyword only (plus sort if needed). Read the available filters in the response; these are the only valid filter options for follow-ups.
155
+ - REFINEMENT: if the user's intent matches an available filter, apply it. If it doesn't match any filter, start a new keyword search.
156
+ - ITERATE: a single search is never 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.
157
+ - 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.
158
+ - PRESENT: Once you have ${CAROUSEL_RANGE} distinct, relevant products, call render-carousel with their IDs. Recommend ONLY AFTER the carousel displays, in carousel order.
159
+
160
+ The sweet spot is ${CAROUSEL_RANGE} products.
161
+ `,
162
+ annotations: {
163
+ readOnlyHint: true,
164
+ openWorldHint: false,
165
+ destructiveHint: false,
166
+ },
167
+
168
+ // @todo: customize the status messages shown in ChatGPT while the tool runs.
169
+ _meta: {
170
+ "openai/toolInvocation/invoking": "Searching the catalog",
171
+ "openai/toolInvocation/invoked": "Searched the catalog",
172
+ },
173
+
174
+ inputSchema,
175
+ outputSchema,
176
+ };
177
+
178
+ export function searchProductsHandler(input: SearchInput) {
179
+ const results = search(input);
180
+ return {
181
+ structuredContent: results,
182
+ content: [{ type: "text" as const, text: narrate(results) }],
183
+ isError: false,
184
+ };
185
+ }
@@ -0,0 +1,15 @@
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>;