@snowcone-app/mcp 0.9.1 → 0.10.0
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/CHANGELOG.md +12 -0
- package/dist/index.js +1096 -625
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -7,11 +7,235 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
7
7
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
|
|
10
|
+
// ../mockup-url/src/index.ts
|
|
11
|
+
var SNOWCONE_HOSTS = {
|
|
12
|
+
/** REST API: shops, orders, AI generation, realtime grants. */
|
|
13
|
+
api: "https://api.snowcone.app",
|
|
14
|
+
/** Public mockup-image resolver (`/{productCode}?shop=…&asset=…`). */
|
|
15
|
+
img: "https://img.snowcone.app",
|
|
16
|
+
/** Hosted buy page (same grammar as `img`, opens checkout). */
|
|
17
|
+
buy: "https://buy.snowcone.app",
|
|
18
|
+
/** Public product / designs catalog (Meilisearch-compatible). */
|
|
19
|
+
search: "https://search.snowcone.app",
|
|
20
|
+
/** Render CDN — signed render URLs and the realtime socket. */
|
|
21
|
+
cdn: "https://cdn.snowcone.app",
|
|
22
|
+
/** Legacy URL signer. */
|
|
23
|
+
sign: "https://s.snowcone.app",
|
|
24
|
+
/** Content-addressed artwork store (ingest handles). */
|
|
25
|
+
raws: "https://raws.snowcone.app",
|
|
26
|
+
/** Developer docs. */
|
|
27
|
+
docs: "https://developers.snowcone.app",
|
|
28
|
+
/** The storefront site; `/api/launch` says whether orders are open yet. */
|
|
29
|
+
site: "https://snowcone.app"
|
|
30
|
+
};
|
|
31
|
+
var SNOWCONE_REALTIME_WS_URL = `${SNOWCONE_HOSTS.cdn.replace(/^http/, "ws")}/realtime`;
|
|
32
|
+
var PARAMS = {
|
|
33
|
+
shop: "shop",
|
|
34
|
+
asset: "asset",
|
|
35
|
+
assets: "assets",
|
|
36
|
+
/**
|
|
37
|
+
* Render a catalog design by reference (ADR-0086): `design=<pairingId|slug>`.
|
|
38
|
+
* The resolver looks the design up in the public `snowcone-designs` index
|
|
39
|
+
* (membership = license) and injects its asset components server-side, so no
|
|
40
|
+
* raw asset URL crosses the wire and no origin allowlisting is involved.
|
|
41
|
+
* Catalog renders are FREE — mutually exclusive with `asset`/`asset.<key>`/
|
|
42
|
+
* `color.<key>` (free = the design as published).
|
|
43
|
+
*/
|
|
44
|
+
design: "design",
|
|
45
|
+
placement: "placement",
|
|
46
|
+
/**
|
|
47
|
+
* Album page selector (ADR-0086 §5): `page=N` (positive integer) picks which
|
|
48
|
+
* page/spread of an album product a mockup renders. Only valid on products
|
|
49
|
+
* whose catalog entry carries an `album` block — the edge resolver maps page
|
|
50
|
+
* N onto the repeating page placement (`page_N` → the geometry of
|
|
51
|
+
* `album.pagePlacement`); the catalog never enumerates `page_1…page_100` and
|
|
52
|
+
* the render server is unchanged.
|
|
53
|
+
*/
|
|
54
|
+
page: "page",
|
|
55
|
+
variant: "variant",
|
|
56
|
+
mockup: "mockup",
|
|
57
|
+
width: "width",
|
|
58
|
+
grain: "grain",
|
|
59
|
+
aspect: "aspect",
|
|
60
|
+
/**
|
|
61
|
+
* Background color (6-hex, no '#') painted behind the mockup — visible only
|
|
62
|
+
* where the mockup itself has transparency (studio-cutout shots) — or the
|
|
63
|
+
* reserved `transparent` token, which suppresses the shop default for this
|
|
64
|
+
* one render. Absent = the shop's configured default, else transparent.
|
|
65
|
+
*/
|
|
66
|
+
bg: "bg",
|
|
67
|
+
/** Live preview/calibration mask overrides (not cached). */
|
|
68
|
+
maskOverrides: "maskOverrides",
|
|
69
|
+
/**
|
|
70
|
+
* Render-only option picks (the `affectsCombinations:false` attributes), as a
|
|
71
|
+
* base64 JSON map `{ attributeName: choiceLabel }`. The render server already parses
|
|
72
|
+
* this and resolves per-choice underlays from it; the builder emits it so the
|
|
73
|
+
* edge resolver can forward render-only picks (e.g. a cap's Crown/Strap color)
|
|
74
|
+
* without changing the server grammar.
|
|
75
|
+
*/
|
|
76
|
+
optionSelections: "optionSelections",
|
|
77
|
+
signature: "signature",
|
|
78
|
+
seal: "seal"
|
|
79
|
+
};
|
|
80
|
+
var BG_TRANSPARENT = "transparent";
|
|
81
|
+
function normalizeBgColor(raw) {
|
|
82
|
+
const value = raw.trim().replace(/^#/, "").toLowerCase();
|
|
83
|
+
if (value === BG_TRANSPARENT) return BG_TRANSPARENT;
|
|
84
|
+
return /^[0-9a-f]{6}$/.test(value) ? value : null;
|
|
85
|
+
}
|
|
86
|
+
function requireBgColor(raw) {
|
|
87
|
+
const bg = normalizeBgColor(raw);
|
|
88
|
+
if (bg === null) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
`[snowcone] bg must be a 6-digit hex color ('#' optional, e.g. "f5f0ea") or "transparent", got "${raw}"`
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return bg;
|
|
94
|
+
}
|
|
95
|
+
var MAX_RENDER_URL_LENGTH = 12 * 1024;
|
|
96
|
+
var INGEST_HANDLE_BASE = `${SNOWCONE_HOSTS.raws}/art-ingest/`;
|
|
97
|
+
var PARAM_PREFIX = {
|
|
98
|
+
asset: "asset.",
|
|
99
|
+
color: "color.",
|
|
100
|
+
tile: "tile.",
|
|
101
|
+
align: "align.",
|
|
102
|
+
opt: "opt.",
|
|
103
|
+
/** ADR-0099 bundles: `variant.<role>=<gvid>` — one SKU per member slot. */
|
|
104
|
+
variant: "variant.",
|
|
105
|
+
/** ADR-0099 bundles: `pick.<role>=<productCode>` — which alternative fills a slot. */
|
|
106
|
+
pick: "pick."
|
|
107
|
+
};
|
|
108
|
+
var DEFAULT_PUBLIC_BASE_URL = SNOWCONE_HOSTS.img;
|
|
109
|
+
function buildPublicMockupUrl(options, cfg = {}) {
|
|
110
|
+
const base = (cfg.baseUrl ?? DEFAULT_PUBLIC_BASE_URL).replace(/\/+$/, "");
|
|
111
|
+
const path = `/${encodeURIComponent(options.productCode)}`;
|
|
112
|
+
const enc = encodeURIComponent;
|
|
113
|
+
const parts = [];
|
|
114
|
+
parts.push(`${PARAMS.shop}=${enc(options.shop)}`);
|
|
115
|
+
if (options.designRef !== void 0) {
|
|
116
|
+
parts.push(`${PARAMS.design}=${enc(options.designRef)}`);
|
|
117
|
+
} else {
|
|
118
|
+
if (options.assetUrl !== void 0) {
|
|
119
|
+
parts.push(`${PARAMS.asset}=${enc(options.assetUrl)}`);
|
|
120
|
+
}
|
|
121
|
+
const overrides = options.design || options.placements ? { ...options.design ?? {}, ...options.placements ?? {} } : void 0;
|
|
122
|
+
if (overrides) {
|
|
123
|
+
for (const key of Object.keys(overrides).sort()) {
|
|
124
|
+
const fill = overrides[key];
|
|
125
|
+
const k = enc(key);
|
|
126
|
+
if (typeof fill === "string") {
|
|
127
|
+
parts.push(`${PARAM_PREFIX.asset}${k}=${enc(fill)}`);
|
|
128
|
+
} else if ("color" in fill) {
|
|
129
|
+
parts.push(`${PARAM_PREFIX.color}${k}=${enc(fill.color)}`);
|
|
130
|
+
} else {
|
|
131
|
+
parts.push(`${PARAM_PREFIX.asset}${k}=${enc(fill.src)}`);
|
|
132
|
+
if (fill.tile !== void 0) {
|
|
133
|
+
parts.push(`${PARAM_PREFIX.tile}${k}=${fill.tile}`);
|
|
134
|
+
}
|
|
135
|
+
if (fill.align !== void 0) {
|
|
136
|
+
parts.push(`${PARAM_PREFIX.align}${k}=${enc(fill.align)}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
if (options.placement !== void 0) {
|
|
143
|
+
parts.push(`${PARAMS.placement}=${enc(options.placement)}`);
|
|
144
|
+
}
|
|
145
|
+
if (options.page !== void 0) {
|
|
146
|
+
parts.push(`${PARAMS.page}=${options.page}`);
|
|
147
|
+
}
|
|
148
|
+
if (options.options) {
|
|
149
|
+
for (const attr of Object.keys(options.options).sort()) {
|
|
150
|
+
parts.push(`${PARAM_PREFIX.opt}${enc(attr)}=${enc(options.options[attr])}`);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (options.variant !== void 0) {
|
|
154
|
+
parts.push(`${PARAMS.variant}=${enc(options.variant)}`);
|
|
155
|
+
}
|
|
156
|
+
if (options.mockup !== void 0) {
|
|
157
|
+
parts.push(`${PARAMS.mockup}=${enc(options.mockup)}`);
|
|
158
|
+
}
|
|
159
|
+
if (options.width !== void 0) parts.push(`${PARAMS.width}=${options.width}`);
|
|
160
|
+
if (options.aspect !== void 0 && options.aspect !== "16:9") {
|
|
161
|
+
parts.push(`${PARAMS.aspect}=${enc(options.aspect)}`);
|
|
162
|
+
}
|
|
163
|
+
if (options.bg) {
|
|
164
|
+
parts.push(`${PARAMS.bg}=${requireBgColor(options.bg)}`);
|
|
165
|
+
}
|
|
166
|
+
return `${base}${path}?${parts.join("&")}`;
|
|
167
|
+
}
|
|
168
|
+
var PUBLIC_PARAM_NAMES = [
|
|
169
|
+
PARAMS.asset,
|
|
170
|
+
PARAMS.design,
|
|
171
|
+
PARAMS.shop,
|
|
172
|
+
PARAMS.placement,
|
|
173
|
+
PARAMS.page,
|
|
174
|
+
PARAMS.variant,
|
|
175
|
+
PARAMS.mockup,
|
|
176
|
+
PARAMS.width,
|
|
177
|
+
PARAMS.aspect,
|
|
178
|
+
PARAMS.bg,
|
|
179
|
+
PARAMS.signature
|
|
180
|
+
];
|
|
181
|
+
function canonicalForSig(url) {
|
|
182
|
+
const hashIdx = url.indexOf("#");
|
|
183
|
+
const noHash = hashIdx === -1 ? url : url.slice(0, hashIdx);
|
|
184
|
+
const qIdx = noHash.indexOf("?");
|
|
185
|
+
const beforeQuery = qIdx === -1 ? noHash : noHash.slice(0, qIdx);
|
|
186
|
+
const rawQuery = qIdx === -1 ? "" : noHash.slice(qIdx + 1);
|
|
187
|
+
let pathname;
|
|
188
|
+
const schemeMatch = beforeQuery.match(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//);
|
|
189
|
+
if (schemeMatch) {
|
|
190
|
+
const afterScheme = beforeQuery.slice(schemeMatch[0].length);
|
|
191
|
+
const slashIdx = afterScheme.indexOf("/");
|
|
192
|
+
pathname = slashIdx === -1 ? "/" : afterScheme.slice(slashIdx);
|
|
193
|
+
} else {
|
|
194
|
+
pathname = beforeQuery;
|
|
195
|
+
}
|
|
196
|
+
const pairs = [];
|
|
197
|
+
if (rawQuery.length > 0) {
|
|
198
|
+
for (const segment of rawQuery.split("&")) {
|
|
199
|
+
if (segment.length === 0) continue;
|
|
200
|
+
const eq = segment.indexOf("=");
|
|
201
|
+
const rawKey = eq === -1 ? segment : segment.slice(0, eq);
|
|
202
|
+
const rawValue = eq === -1 ? "" : segment.slice(eq + 1);
|
|
203
|
+
const key = decodeURIComponent(rawKey);
|
|
204
|
+
if (key === "signature") continue;
|
|
205
|
+
if (key === "debug") continue;
|
|
206
|
+
pairs.push({ key, raw: rawValue });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
pairs.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
210
|
+
const canonicalQuery = pairs.map((p) => `${p.key}=${p.raw}`).join("&");
|
|
211
|
+
return `${pathname}?${canonicalQuery}`;
|
|
212
|
+
}
|
|
213
|
+
function toHex(bytes) {
|
|
214
|
+
let out = "";
|
|
215
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
216
|
+
out += bytes[i].toString(16).padStart(2, "0");
|
|
217
|
+
}
|
|
218
|
+
return out;
|
|
219
|
+
}
|
|
220
|
+
async function signDevSig(canonical, secret) {
|
|
221
|
+
const encoder = new TextEncoder();
|
|
222
|
+
const key = await crypto.subtle.importKey(
|
|
223
|
+
"raw",
|
|
224
|
+
encoder.encode(secret),
|
|
225
|
+
{ name: "HMAC", hash: "SHA-256" },
|
|
226
|
+
false,
|
|
227
|
+
["sign"]
|
|
228
|
+
);
|
|
229
|
+
const sigBuf = await crypto.subtle.sign("HMAC", key, encoder.encode(canonical));
|
|
230
|
+
return toHex(new Uint8Array(sigBuf)).slice(0, 16);
|
|
231
|
+
}
|
|
232
|
+
|
|
10
233
|
// src/constants.ts
|
|
11
|
-
var API_BASE = stripSlash(process.env.SNOWCONE_API_BASE ??
|
|
12
|
-
var IMG_BASE = stripSlash(process.env.SNOWCONE_IMG_BASE ??
|
|
13
|
-
var BUY_BASE = stripSlash(process.env.SNOWCONE_BUY_BASE ??
|
|
14
|
-
var
|
|
234
|
+
var API_BASE = stripSlash(process.env.SNOWCONE_API_BASE ?? SNOWCONE_HOSTS.api);
|
|
235
|
+
var IMG_BASE = stripSlash(process.env.SNOWCONE_IMG_BASE ?? SNOWCONE_HOSTS.img);
|
|
236
|
+
var BUY_BASE = stripSlash(process.env.SNOWCONE_BUY_BASE ?? SNOWCONE_HOSTS.buy);
|
|
237
|
+
var LAUNCH_URL = process.env.SNOWCONE_LAUNCH_URL ?? `${stripSlash(SNOWCONE_HOSTS.site)}/api/launch`;
|
|
238
|
+
var MEILI_HOST = stripSlash(process.env.SNOWCONE_MEILI_HOST ?? SNOWCONE_HOSTS.search);
|
|
15
239
|
var MEILI_KEY = process.env.SNOWCONE_MEILI_KEY ?? "73f573ead9be75531c56ee89d104caa49d79154db387f119a013d33eccfe654b";
|
|
16
240
|
var MEILI_INDEX = process.env.SNOWCONE_MEILI_INDEX ?? "snowcone";
|
|
17
241
|
var MEILI_DESIGNS_INDEX = process.env.SNOWCONE_MEILI_DESIGNS_INDEX ?? "snowcone-designs";
|
|
@@ -22,6 +246,362 @@ function stripSlash(s) {
|
|
|
22
246
|
return s.replace(/\/+$/, "");
|
|
23
247
|
}
|
|
24
248
|
|
|
249
|
+
// package.json
|
|
250
|
+
var package_default = {
|
|
251
|
+
name: "@snowcone-app/mcp",
|
|
252
|
+
version: "0.10.0",
|
|
253
|
+
mcpName: "io.github.snowcone-app/snowcone",
|
|
254
|
+
description: "Snowcone MCP server \u2014 the agent-native quickstart. Mint a sandbox shop, browse the catalog, and turn any image into a buyable printed-merch mockup URL, all as callable tools.",
|
|
255
|
+
keywords: [
|
|
256
|
+
"mcp",
|
|
257
|
+
"model-context-protocol",
|
|
258
|
+
"snowcone",
|
|
259
|
+
"print-on-demand",
|
|
260
|
+
"mockup",
|
|
261
|
+
"merch",
|
|
262
|
+
"agent"
|
|
263
|
+
],
|
|
264
|
+
author: "Snowcone <dev@snowcone.app>",
|
|
265
|
+
license: "MIT",
|
|
266
|
+
repository: {
|
|
267
|
+
type: "git",
|
|
268
|
+
url: "https://github.com/snowcone-app/snowcone-monorepo.git",
|
|
269
|
+
directory: "packages/mcp"
|
|
270
|
+
},
|
|
271
|
+
bugs: {
|
|
272
|
+
url: "https://github.com/snowcone-app/snowcone-monorepo/issues"
|
|
273
|
+
},
|
|
274
|
+
homepage: "https://developers.snowcone.app",
|
|
275
|
+
private: false,
|
|
276
|
+
type: "module",
|
|
277
|
+
bin: {
|
|
278
|
+
"snowcone-mcp": "./dist/index.js"
|
|
279
|
+
},
|
|
280
|
+
main: "dist/index.js",
|
|
281
|
+
files: [
|
|
282
|
+
"dist",
|
|
283
|
+
"README.md",
|
|
284
|
+
"CHANGELOG.md"
|
|
285
|
+
],
|
|
286
|
+
scripts: {
|
|
287
|
+
build: "tsup",
|
|
288
|
+
dev: "tsup --watch",
|
|
289
|
+
start: "node dist/index.js",
|
|
290
|
+
"worker:dev": "wrangler dev",
|
|
291
|
+
deploy: "wrangler deploy --env production",
|
|
292
|
+
clean: "rm -rf dist",
|
|
293
|
+
typecheck: "tsc --noEmit",
|
|
294
|
+
test: "vitest run",
|
|
295
|
+
prepack: "pnpm run build"
|
|
296
|
+
},
|
|
297
|
+
dependencies: {
|
|
298
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
299
|
+
zod: "^3.23.8"
|
|
300
|
+
},
|
|
301
|
+
devDependencies: {
|
|
302
|
+
"@snowcone-app/mockup-url": "workspace:*",
|
|
303
|
+
"@types/node": "^20.11.0",
|
|
304
|
+
tsup: "^8.1.0",
|
|
305
|
+
typescript: "^5.5.4",
|
|
306
|
+
vitest: "^2.1.9",
|
|
307
|
+
wrangler: "^3.91.0"
|
|
308
|
+
},
|
|
309
|
+
publishConfig: {
|
|
310
|
+
access: "public"
|
|
311
|
+
},
|
|
312
|
+
engines: {
|
|
313
|
+
node: ">=18"
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// src/version.ts
|
|
318
|
+
var VERSION = package_default.version ?? "0.0.0";
|
|
319
|
+
|
|
320
|
+
// src/card.ts
|
|
321
|
+
var CARD_URI = "ui://snowcone/mockup-card.html";
|
|
322
|
+
var CARD_MIME = "text/html;profile=mcp-app";
|
|
323
|
+
var CARD_TOOL_META = {
|
|
324
|
+
ui: { resourceUri: CARD_URI },
|
|
325
|
+
"ui/resourceUri": CARD_URI,
|
|
326
|
+
"openai/outputTemplate": CARD_URI,
|
|
327
|
+
"openai/widgetAccessible": true,
|
|
328
|
+
"openai/toolInvocation/invoking": "Rendering the mockup\u2026",
|
|
329
|
+
"openai/toolInvocation/invoked": "Mockup ready"
|
|
330
|
+
};
|
|
331
|
+
function cardResourceMeta() {
|
|
332
|
+
const img = new URL(IMG_BASE).origin;
|
|
333
|
+
return {
|
|
334
|
+
ui: { csp: { resourceDomains: [img], connectDomains: [] }, prefersBorder: true },
|
|
335
|
+
"openai/widgetCSP": { resource_domains: [img], connect_domains: [] },
|
|
336
|
+
"openai/widgetPrefersBorder": true,
|
|
337
|
+
"openai/widgetDescription": "A preview of the person's design printed on the product, with its price, option choices, and a Buy button (or 'Orders open soon' before launch)."
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
function cardHtml() {
|
|
341
|
+
return CARD_HTML.replace("__VERSION__", VERSION);
|
|
342
|
+
}
|
|
343
|
+
var CARD_HTML = `<!doctype html>
|
|
344
|
+
<html lang="en">
|
|
345
|
+
<head>
|
|
346
|
+
<meta charset="utf-8" />
|
|
347
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
348
|
+
<title>Snowcone mockup</title>
|
|
349
|
+
<style>
|
|
350
|
+
:root { color-scheme: light dark; --bg:#fff; --fg:#14161a; --muted:#5d636e; --line:#e4e6ea; --well:#f4f5f7; --accent:#14161a; --accent-fg:#fff; }
|
|
351
|
+
:root[data-theme="dark"] { --bg:#16181c; --fg:#f2f3f5; --muted:#a2a8b3; --line:#2c3038; --well:#1f2228; --accent:#f2f3f5; --accent-fg:#14161a; }
|
|
352
|
+
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg:#16181c; --fg:#f2f3f5; --muted:#a2a8b3; --line:#2c3038; --well:#1f2228; --accent:#f2f3f5; --accent-fg:#14161a; } }
|
|
353
|
+
* { box-sizing: border-box; }
|
|
354
|
+
html, body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
355
|
+
.card { max-width: 560px; margin: 0 auto; padding: 12px; }
|
|
356
|
+
.well { position: relative; background: var(--well); border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; display: grid; place-items: center; }
|
|
357
|
+
.well img { width: 100%; height: 100%; object-fit: contain; display: block; transition: opacity .2s; }
|
|
358
|
+
.card[data-state="loading"] .well img, .card[data-busy="true"] .well img { opacity: .45; }
|
|
359
|
+
.placeholder { color: var(--muted); font-size: 13px; padding: 16px; text-align: center; }
|
|
360
|
+
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 12px 2px 0; }
|
|
361
|
+
.name { font-weight: 600; font-size: 15px; }
|
|
362
|
+
.price { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
|
|
363
|
+
.opts { margin: 10px 2px 0; display: grid; gap: 8px; }
|
|
364
|
+
.opt-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; text-transform: capitalize; }
|
|
365
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
366
|
+
.chip { border: 1px solid var(--line); background: transparent; color: var(--fg); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer; }
|
|
367
|
+
.chip[aria-pressed="true"] { border-color: var(--fg); font-weight: 600; }
|
|
368
|
+
.chip:disabled { cursor: default; opacity: .6; }
|
|
369
|
+
.buy { margin: 12px 2px 0; }
|
|
370
|
+
.btn { width: 100%; border: 0; border-radius: 10px; padding: 11px 14px; font: inherit; font-weight: 600; background: var(--accent); color: var(--accent-fg); cursor: pointer; }
|
|
371
|
+
.btn:disabled { background: var(--well); color: var(--muted); cursor: default; }
|
|
372
|
+
.note { margin: 6px 2px 0; font-size: 12px; color: var(--muted); }
|
|
373
|
+
.error { margin: 12px 2px 0; font-size: 13px; color: #c0392b; white-space: pre-wrap; }
|
|
374
|
+
.foot { margin: 10px 2px 0; font-size: 11px; color: var(--muted); }
|
|
375
|
+
</style>
|
|
376
|
+
</head>
|
|
377
|
+
<body>
|
|
378
|
+
<div class="card" id="card" data-state="loading" data-orders="" data-busy="false" data-missing-option="">
|
|
379
|
+
<div class="well"><div class="placeholder" id="placeholder">Rendering your mockup\u2026</div><img id="img" alt="" hidden /></div>
|
|
380
|
+
<div class="head" id="head" hidden><div class="name" id="name"></div><div class="price" id="price"></div></div>
|
|
381
|
+
<div class="opts" id="opts"></div>
|
|
382
|
+
<div class="buy" id="buy" hidden><button class="btn" id="buyBtn" type="button"></button><div class="note" id="note"></div></div>
|
|
383
|
+
<div class="error" id="error" hidden></div>
|
|
384
|
+
<div class="foot">Printed and shipped by Snowcone</div>
|
|
385
|
+
</div>
|
|
386
|
+
<script>
|
|
387
|
+
(() => {
|
|
388
|
+
"use strict";
|
|
389
|
+
const $ = (id) => document.getElementById(id);
|
|
390
|
+
const cardEl = $("card");
|
|
391
|
+
let card = null;
|
|
392
|
+
let bridge = false; // MCP Apps bridge is up
|
|
393
|
+
let nextId = 1;
|
|
394
|
+
const pending = new Map();
|
|
395
|
+
|
|
396
|
+
function post(msg) { window.parent.postMessage(msg, "*"); }
|
|
397
|
+
function request(method, params) {
|
|
398
|
+
return new Promise((resolve, reject) => {
|
|
399
|
+
const id = nextId++;
|
|
400
|
+
pending.set(id, { resolve, reject });
|
|
401
|
+
post({ jsonrpc: "2.0", id, method, params });
|
|
402
|
+
setTimeout(() => { if (pending.has(id)) { pending.delete(id); reject(new Error(method + " timed out")); } }, 30000);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function notify(method, params) { post({ jsonrpc: "2.0", method, params: params || {} }); }
|
|
406
|
+
|
|
407
|
+
function applyTheme(ctx) {
|
|
408
|
+
const theme = ctx && ctx.theme;
|
|
409
|
+
if (theme === "dark" || theme === "light") document.documentElement.setAttribute("data-theme", theme);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function money(cents) {
|
|
413
|
+
if (typeof cents !== "number") return "";
|
|
414
|
+
return "$" + (cents / 100).toFixed(2);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function showError(text) {
|
|
418
|
+
cardEl.dataset.state = "error";
|
|
419
|
+
$("placeholder").textContent = "This mockup didn't render.";
|
|
420
|
+
$("img").hidden = true;
|
|
421
|
+
$("placeholder").hidden = false;
|
|
422
|
+
const e = $("error");
|
|
423
|
+
e.textContent = text || "";
|
|
424
|
+
e.hidden = !text;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function render(next) {
|
|
428
|
+
if (!next || typeof next !== "object") return;
|
|
429
|
+
card = next;
|
|
430
|
+
cardEl.dataset.state = "ready";
|
|
431
|
+
cardEl.dataset.orders = card.orders && card.orders.orders === "open" ? "open" : "not-open";
|
|
432
|
+
$("error").hidden = true;
|
|
433
|
+
|
|
434
|
+
const img = $("img");
|
|
435
|
+
if (typeof card.image_url === "string" && /^https:\\/\\//.test(card.image_url)) {
|
|
436
|
+
img.onload = () => { $("placeholder").hidden = true; img.hidden = false; cardEl.dataset.busy = "false"; resize(); };
|
|
437
|
+
img.onerror = () => { cardEl.dataset.busy = "false"; showError("The image host refused the picture."); };
|
|
438
|
+
img.alt = card.product ? "Mockup of " + card.product.name : "Product mockup";
|
|
439
|
+
if (img.src === card.image_url && img.complete) cardEl.dataset.busy = "false"; // same picture: no load event comes
|
|
440
|
+
else img.src = card.image_url;
|
|
441
|
+
} else {
|
|
442
|
+
cardEl.dataset.busy = "false";
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (card.product) {
|
|
446
|
+
$("name").textContent = card.product.name;
|
|
447
|
+
$("price").textContent = money(card.product.price_cents);
|
|
448
|
+
$("head").hidden = false;
|
|
449
|
+
} else {
|
|
450
|
+
$("head").hidden = true;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const opts = $("opts");
|
|
454
|
+
opts.textContent = "";
|
|
455
|
+
const canPick = !!card.render_args && (bridge || (window.openai && typeof window.openai.callTool === "function"));
|
|
456
|
+
for (const [attr, o] of Object.entries(card.options || {})) {
|
|
457
|
+
const row = document.createElement("div");
|
|
458
|
+
const label = document.createElement("div");
|
|
459
|
+
label.className = "opt-label";
|
|
460
|
+
label.textContent = attr;
|
|
461
|
+
const chips = document.createElement("div");
|
|
462
|
+
chips.className = "chips";
|
|
463
|
+
for (const choice of o.choices || []) {
|
|
464
|
+
const b = document.createElement("button");
|
|
465
|
+
b.type = "button";
|
|
466
|
+
b.className = "chip";
|
|
467
|
+
b.textContent = choice;
|
|
468
|
+
b.dataset.attr = attr;
|
|
469
|
+
b.dataset.choice = choice;
|
|
470
|
+
b.setAttribute("aria-pressed", String(o.selected === choice));
|
|
471
|
+
b.disabled = !canPick;
|
|
472
|
+
b.addEventListener("click", () => pick(attr, choice));
|
|
473
|
+
chips.appendChild(b);
|
|
474
|
+
}
|
|
475
|
+
row.appendChild(label);
|
|
476
|
+
row.appendChild(chips);
|
|
477
|
+
opts.appendChild(row);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const btn = $("buyBtn");
|
|
481
|
+
const note = $("note");
|
|
482
|
+
const missing = Object.entries(card.options || {}).find(([, o]) => !o.selected);
|
|
483
|
+
cardEl.dataset.missingOption = missing ? missing[0] : "";
|
|
484
|
+
if (card.orders && card.orders.orders === "open" && missing) {
|
|
485
|
+
// Never let a shopper buy a size (or colour) nobody chose.
|
|
486
|
+
btn.disabled = true;
|
|
487
|
+
btn.textContent = "Choose a " + missing[0];
|
|
488
|
+
note.textContent = canPick ? "Pick one above, then buy." : "Ask for the " + missing[0] + " you want.";
|
|
489
|
+
} else if (card.orders && card.orders.orders === "open") {
|
|
490
|
+
btn.disabled = false;
|
|
491
|
+
btn.textContent = card.product && card.product.price_cents != null ? "Buy \xB7 " + money(card.product.price_cents) : "Buy";
|
|
492
|
+
note.textContent = "Opens checkout in your browser.";
|
|
493
|
+
} else {
|
|
494
|
+
btn.disabled = true;
|
|
495
|
+
btn.textContent = "Orders open soon";
|
|
496
|
+
note.textContent = card.orders && card.orders.reason === "prelaunch"
|
|
497
|
+
? "Snowcone hasn't launched yet. This is exactly what you'd get."
|
|
498
|
+
: "We couldn't confirm ordering is available right now.";
|
|
499
|
+
}
|
|
500
|
+
$("buy").hidden = false;
|
|
501
|
+
resize();
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
async function pick(attr, choice) {
|
|
505
|
+
if (!card || !card.render_args) return;
|
|
506
|
+
const current = {};
|
|
507
|
+
for (const [a, o] of Object.entries(card.options || {})) if (o.selected) current[a] = o.selected;
|
|
508
|
+
const args = Object.assign({}, card.render_args, { options: Object.assign(current, { [attr]: choice }) });
|
|
509
|
+
cardEl.dataset.busy = "true";
|
|
510
|
+
try {
|
|
511
|
+
let result;
|
|
512
|
+
if (bridge) result = await request("tools/call", { name: "snowcone_render_mockup", arguments: args });
|
|
513
|
+
else result = await window.openai.callTool("snowcone_render_mockup", args);
|
|
514
|
+
const sc = result && (result.structuredContent || (result.result && result.result.structuredContent));
|
|
515
|
+
if (result && result.isError) {
|
|
516
|
+
cardEl.dataset.busy = "false";
|
|
517
|
+
showError(textOf(result));
|
|
518
|
+
} else if (sc && sc.card) render(sc.card);
|
|
519
|
+
else cardEl.dataset.busy = "false";
|
|
520
|
+
} catch (err) {
|
|
521
|
+
cardEl.dataset.busy = "false";
|
|
522
|
+
showError(String(err && err.message || err));
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function textOf(result) {
|
|
527
|
+
const c = (result && result.content) || [];
|
|
528
|
+
return c.filter((x) => x && x.type === "text").map((x) => x.text).join("\\n");
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
$("buyBtn").addEventListener("click", async () => {
|
|
532
|
+
if (!card || !card.orders || card.orders.orders !== "open" || cardEl.dataset.missingOption) return;
|
|
533
|
+
const url = card.buy_url;
|
|
534
|
+
if (!/^https:\\/\\//.test(url)) return;
|
|
535
|
+
try {
|
|
536
|
+
if (bridge) { await request("ui/open-link", { url }); return; }
|
|
537
|
+
if (window.openai && typeof window.openai.openExternal === "function") { window.openai.openExternal({ href: url }); return; }
|
|
538
|
+
} catch (_) { /* fall through to a plain new tab */ }
|
|
539
|
+
window.open(url, "_blank", "noopener");
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
let lastH = 0;
|
|
543
|
+
function resize() {
|
|
544
|
+
const h = Math.ceil(document.documentElement.getBoundingClientRect().height);
|
|
545
|
+
if (bridge && h !== lastH) { lastH = h; notify("ui/notifications/size-changed", { height: h }); }
|
|
546
|
+
}
|
|
547
|
+
if (typeof ResizeObserver === "function") new ResizeObserver(resize).observe(document.body);
|
|
548
|
+
|
|
549
|
+
function onToolResult(result) {
|
|
550
|
+
if (!result) return;
|
|
551
|
+
if (result.isError) { showError(textOf(result)); return; }
|
|
552
|
+
const sc = result.structuredContent;
|
|
553
|
+
if (sc && sc.card) render(sc.card);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
window.addEventListener("message", (event) => {
|
|
557
|
+
if (event.source !== window.parent) return;
|
|
558
|
+
const m = event.data;
|
|
559
|
+
if (!m || m.jsonrpc !== "2.0") return;
|
|
560
|
+
if (m.method === undefined && m.id !== undefined && pending.has(m.id)) {
|
|
561
|
+
const p = pending.get(m.id);
|
|
562
|
+
pending.delete(m.id);
|
|
563
|
+
if (m.error) p.reject(new Error(m.error.message || "host error"));
|
|
564
|
+
else p.resolve(m.result);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
switch (m.method) {
|
|
568
|
+
case "ui/notifications/tool-result": onToolResult(m.params); break;
|
|
569
|
+
case "ui/notifications/tool-cancelled": showError("The render was cancelled."); break;
|
|
570
|
+
case "ui/notifications/host-context-changed": applyTheme(m.params); break;
|
|
571
|
+
default:
|
|
572
|
+
// Answer any host request we don't handle (e.g. ui/resource-teardown) so the host never hangs.
|
|
573
|
+
if (m.id !== undefined && m.method) post({ jsonrpc: "2.0", id: m.id, result: {} });
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
// OpenAI Apps SDK globals, where a host injects them.
|
|
578
|
+
function fromOpenAi() {
|
|
579
|
+
const o = window.openai;
|
|
580
|
+
if (!o) return;
|
|
581
|
+
applyTheme({ theme: o.theme });
|
|
582
|
+
if (o.toolOutput && o.toolOutput.card) render(o.toolOutput.card);
|
|
583
|
+
}
|
|
584
|
+
window.addEventListener("openai:set_globals", fromOpenAi);
|
|
585
|
+
fromOpenAi();
|
|
586
|
+
|
|
587
|
+
// MCP Apps handshake.
|
|
588
|
+
request("ui/initialize", {
|
|
589
|
+
appInfo: { name: "snowcone-mockup-card", version: "__VERSION__" },
|
|
590
|
+
appCapabilities: {},
|
|
591
|
+
protocolVersion: "2026-01-26",
|
|
592
|
+
}).then((r) => {
|
|
593
|
+
bridge = true;
|
|
594
|
+
applyTheme(r && r.hostContext);
|
|
595
|
+
notify("ui/notifications/initialized", {});
|
|
596
|
+
if (card) render(card); // re-enable the picker now that tools/call is available
|
|
597
|
+
resize();
|
|
598
|
+
}).catch(() => { /* no MCP Apps host: the openai globals (if any) drive the card */ });
|
|
599
|
+
})();
|
|
600
|
+
</script>
|
|
601
|
+
</body>
|
|
602
|
+
</html>
|
|
603
|
+
`;
|
|
604
|
+
|
|
25
605
|
// src/http.ts
|
|
26
606
|
function ok(structured, text) {
|
|
27
607
|
return {
|
|
@@ -260,6 +840,37 @@ async function searchDesigns(query, limit, offset, filter, semanticRatio) {
|
|
|
260
840
|
return { hits: body.hits ?? [], estimatedTotalHits: body.estimatedTotalHits ?? body.hits?.length ?? 0 };
|
|
261
841
|
}
|
|
262
842
|
|
|
843
|
+
// src/launch.ts
|
|
844
|
+
var TTL_MS = 6e4;
|
|
845
|
+
var cached = null;
|
|
846
|
+
async function readOrdersState(now = Date.now()) {
|
|
847
|
+
if (cached && now - cached.at < TTL_MS) return cached.state;
|
|
848
|
+
const state = await fetchState();
|
|
849
|
+
if (!(state.orders === "not-open" && state.reason === "unreadable")) cached = { at: now, state };
|
|
850
|
+
return state;
|
|
851
|
+
}
|
|
852
|
+
async function fetchState() {
|
|
853
|
+
try {
|
|
854
|
+
const res = await fetch(LAUNCH_URL, { headers: { Accept: "application/json" }, signal: AbortSignal.timeout(3e3) });
|
|
855
|
+
if (!res.ok) return unreadable(`HTTP ${res.status} from ${LAUNCH_URL}`);
|
|
856
|
+
const body = await res.json();
|
|
857
|
+
if (body.orders === "open") return { orders: "open" };
|
|
858
|
+
if (body.orders === "not-open" && body.reason === "prelaunch") return { orders: "not-open", reason: "prelaunch" };
|
|
859
|
+
return unreadable(`unexpected answer from ${LAUNCH_URL}: ${JSON.stringify(body).slice(0, 200)}`);
|
|
860
|
+
} catch (err) {
|
|
861
|
+
return unreadable(`${LAUNCH_URL}: ${err instanceof Error ? err.message : String(err)}`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
function unreadable(detail) {
|
|
865
|
+
return { orders: "not-open", reason: "unreadable", detail };
|
|
866
|
+
}
|
|
867
|
+
function ordersLine(s) {
|
|
868
|
+
if (s.orders === "open") return "Orders are open: the buy link takes the person to checkout.";
|
|
869
|
+
if (s.reason === "prelaunch")
|
|
870
|
+
return "Orders open soon: Snowcone hasn't launched yet. Show the person the mockup, but don't offer the buy link as a way to order today.";
|
|
871
|
+
return "Couldn't confirm that orders are open right now, so don't offer the buy link yet; the mockup is fine to show.";
|
|
872
|
+
}
|
|
873
|
+
|
|
263
874
|
// src/orders.ts
|
|
264
875
|
async function getQuote(input) {
|
|
265
876
|
const q = new URLSearchParams({ quote: "1" });
|
|
@@ -298,17 +909,6 @@ function orderStatusText(r) {
|
|
|
298
909
|
].join("\n");
|
|
299
910
|
}
|
|
300
911
|
|
|
301
|
-
// src/version.ts
|
|
302
|
-
import { createRequire } from "module";
|
|
303
|
-
var VERSION = (() => {
|
|
304
|
-
try {
|
|
305
|
-
const pkg = createRequire(import.meta.url)("../package.json");
|
|
306
|
-
return pkg.version ?? "0.0.0";
|
|
307
|
-
} catch {
|
|
308
|
-
return "0.0.0";
|
|
309
|
-
}
|
|
310
|
-
})();
|
|
311
|
-
|
|
312
912
|
// src/quickstart.ts
|
|
313
913
|
var QUICKSTART = `# Snowcone in one screen (for agents)
|
|
314
914
|
|
|
@@ -412,6 +1012,7 @@ Until you lock the shop, treat any artwork you render on it as effectively publi
|
|
|
412
1012
|
function mintShop(input) {
|
|
413
1013
|
return httpJson(`${API_BASE}/shops/sandbox`, {
|
|
414
1014
|
method: "POST",
|
|
1015
|
+
...input.forwardedFor ? { headers: { "X-Forwarded-For": input.forwardedFor } } : {},
|
|
415
1016
|
body: {
|
|
416
1017
|
...input.name ? { name: input.name } : {},
|
|
417
1018
|
...input.claim_pin ? { claim_pin: input.claim_pin } : {},
|
|
@@ -420,230 +1021,29 @@ function mintShop(input) {
|
|
|
420
1021
|
// backend and fail loudly there, exactly like it would on the PATCH.
|
|
421
1022
|
...input.mockup_bg_color !== void 0 ? { mockup_bg_color: input.mockup_bg_color } : {},
|
|
422
1023
|
...input.image_url !== void 0 ? { image_url: input.image_url } : {}
|
|
423
|
-
}
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
function setMockupBackground(shopId, shopSecret, mockupBgColor) {
|
|
427
|
-
return httpJson(
|
|
428
|
-
`${API_BASE}/shops/sandbox/${encodeURIComponent(shopId)}/render-settings`,
|
|
429
|
-
{
|
|
430
|
-
method: "PATCH",
|
|
431
|
-
headers: { Authorization: `Bearer ${shopSecret}` },
|
|
432
|
-
body: { mockup_bg_color: mockupBgColor }
|
|
433
|
-
}
|
|
434
|
-
);
|
|
435
|
-
}
|
|
436
|
-
function claimStatus(claimToken) {
|
|
437
|
-
return httpJson(`${API_BASE}/shops/claim`, {
|
|
438
|
-
headers: { Authorization: `Bearer ${claimToken}` }
|
|
439
|
-
});
|
|
440
|
-
}
|
|
441
|
-
function releaseShop(shopId, shopSecret) {
|
|
442
|
-
return httpJson(`${API_BASE}/shops/sandbox/${encodeURIComponent(shopId)}`, {
|
|
443
|
-
method: "DELETE",
|
|
444
|
-
headers: { Authorization: `Bearer ${shopSecret}` }
|
|
445
|
-
});
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// ../mockup-url/src/index.ts
|
|
449
|
-
var PARAMS = {
|
|
450
|
-
shop: "shop",
|
|
451
|
-
asset: "asset",
|
|
452
|
-
assets: "assets",
|
|
453
|
-
/**
|
|
454
|
-
* Render a catalog design by reference (ADR-0086): `design=<pairingId|slug>`.
|
|
455
|
-
* The resolver looks the design up in the public `snowcone-designs` index
|
|
456
|
-
* (membership = license) and injects its asset components server-side, so no
|
|
457
|
-
* raw asset URL crosses the wire and no origin allowlisting is involved.
|
|
458
|
-
* Catalog renders are FREE — mutually exclusive with `asset`/`asset.<key>`/
|
|
459
|
-
* `color.<key>` (free = the design as published).
|
|
460
|
-
*/
|
|
461
|
-
design: "design",
|
|
462
|
-
placement: "placement",
|
|
463
|
-
/**
|
|
464
|
-
* Album page selector (ADR-0086 §5): `page=N` (positive integer) picks which
|
|
465
|
-
* page/spread of an album product a mockup renders. Only valid on products
|
|
466
|
-
* whose catalog entry carries an `album` block — the edge resolver maps page
|
|
467
|
-
* N onto the repeating page placement (`page_N` → the geometry of
|
|
468
|
-
* `album.pagePlacement`); the catalog never enumerates `page_1…page_100` and
|
|
469
|
-
* the render server is unchanged.
|
|
470
|
-
*/
|
|
471
|
-
page: "page",
|
|
472
|
-
variant: "variant",
|
|
473
|
-
mockup: "mockup",
|
|
474
|
-
width: "width",
|
|
475
|
-
grain: "grain",
|
|
476
|
-
aspect: "aspect",
|
|
477
|
-
/**
|
|
478
|
-
* Background color (6-hex, no '#') painted behind the mockup — visible only
|
|
479
|
-
* where the mockup itself has transparency (studio-cutout shots) — or the
|
|
480
|
-
* reserved `transparent` token, which suppresses the shop default for this
|
|
481
|
-
* one render. Absent = the shop's configured default, else transparent.
|
|
482
|
-
*/
|
|
483
|
-
bg: "bg",
|
|
484
|
-
/** Live preview/calibration mask overrides (not cached). */
|
|
485
|
-
maskOverrides: "maskOverrides",
|
|
486
|
-
/**
|
|
487
|
-
* Render-only option picks (the `affectsCombinations:false` attributes), as a
|
|
488
|
-
* base64 JSON map `{ attributeName: choiceLabel }`. The render server already parses
|
|
489
|
-
* this and resolves per-choice underlays from it; the builder emits it so the
|
|
490
|
-
* edge resolver can forward render-only picks (e.g. a cap's Crown/Strap color)
|
|
491
|
-
* without changing the server grammar.
|
|
492
|
-
*/
|
|
493
|
-
optionSelections: "optionSelections",
|
|
494
|
-
signature: "signature",
|
|
495
|
-
seal: "seal"
|
|
496
|
-
};
|
|
497
|
-
var BG_TRANSPARENT = "transparent";
|
|
498
|
-
function normalizeBgColor(raw) {
|
|
499
|
-
const value = raw.trim().replace(/^#/, "").toLowerCase();
|
|
500
|
-
if (value === BG_TRANSPARENT) return BG_TRANSPARENT;
|
|
501
|
-
return /^[0-9a-f]{6}$/.test(value) ? value : null;
|
|
502
|
-
}
|
|
503
|
-
function requireBgColor(raw) {
|
|
504
|
-
const bg = normalizeBgColor(raw);
|
|
505
|
-
if (bg === null) {
|
|
506
|
-
throw new Error(
|
|
507
|
-
`[snowcone] bg must be a 6-digit hex color ('#' optional, e.g. "f5f0ea") or "transparent", got "${raw}"`
|
|
508
|
-
);
|
|
509
|
-
}
|
|
510
|
-
return bg;
|
|
511
|
-
}
|
|
512
|
-
var MAX_RENDER_URL_LENGTH = 12 * 1024;
|
|
513
|
-
var PARAM_PREFIX = {
|
|
514
|
-
asset: "asset.",
|
|
515
|
-
color: "color.",
|
|
516
|
-
tile: "tile.",
|
|
517
|
-
align: "align.",
|
|
518
|
-
opt: "opt.",
|
|
519
|
-
/** ADR-0099 bundles: `variant.<role>=<gvid>` — one SKU per member slot. */
|
|
520
|
-
variant: "variant.",
|
|
521
|
-
/** ADR-0099 bundles: `pick.<role>=<productCode>` — which alternative fills a slot. */
|
|
522
|
-
pick: "pick."
|
|
523
|
-
};
|
|
524
|
-
var DEFAULT_PUBLIC_BASE_URL = "https://img.snowcone.app";
|
|
525
|
-
function buildPublicMockupUrl(options, cfg = {}) {
|
|
526
|
-
const base = (cfg.baseUrl ?? DEFAULT_PUBLIC_BASE_URL).replace(/\/+$/, "");
|
|
527
|
-
const path = `/${encodeURIComponent(options.productCode)}`;
|
|
528
|
-
const enc = encodeURIComponent;
|
|
529
|
-
const parts = [];
|
|
530
|
-
parts.push(`${PARAMS.shop}=${enc(options.shop)}`);
|
|
531
|
-
if (options.designRef !== void 0) {
|
|
532
|
-
parts.push(`${PARAMS.design}=${enc(options.designRef)}`);
|
|
533
|
-
} else {
|
|
534
|
-
if (options.assetUrl !== void 0) {
|
|
535
|
-
parts.push(`${PARAMS.asset}=${enc(options.assetUrl)}`);
|
|
536
|
-
}
|
|
537
|
-
const overrides = options.design || options.placements ? { ...options.design ?? {}, ...options.placements ?? {} } : void 0;
|
|
538
|
-
if (overrides) {
|
|
539
|
-
for (const key of Object.keys(overrides).sort()) {
|
|
540
|
-
const fill = overrides[key];
|
|
541
|
-
const k = enc(key);
|
|
542
|
-
if (typeof fill === "string") {
|
|
543
|
-
parts.push(`${PARAM_PREFIX.asset}${k}=${enc(fill)}`);
|
|
544
|
-
} else if ("color" in fill) {
|
|
545
|
-
parts.push(`${PARAM_PREFIX.color}${k}=${enc(fill.color)}`);
|
|
546
|
-
} else {
|
|
547
|
-
parts.push(`${PARAM_PREFIX.asset}${k}=${enc(fill.src)}`);
|
|
548
|
-
if (fill.tile !== void 0) {
|
|
549
|
-
parts.push(`${PARAM_PREFIX.tile}${k}=${fill.tile}`);
|
|
550
|
-
}
|
|
551
|
-
if (fill.align !== void 0) {
|
|
552
|
-
parts.push(`${PARAM_PREFIX.align}${k}=${enc(fill.align)}`);
|
|
553
|
-
}
|
|
554
|
-
}
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
if (options.placement !== void 0) {
|
|
559
|
-
parts.push(`${PARAMS.placement}=${enc(options.placement)}`);
|
|
560
|
-
}
|
|
561
|
-
if (options.page !== void 0) {
|
|
562
|
-
parts.push(`${PARAMS.page}=${options.page}`);
|
|
563
|
-
}
|
|
564
|
-
if (options.options) {
|
|
565
|
-
for (const attr of Object.keys(options.options).sort()) {
|
|
566
|
-
parts.push(`${PARAM_PREFIX.opt}${enc(attr)}=${enc(options.options[attr])}`);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
if (options.variant !== void 0) {
|
|
570
|
-
parts.push(`${PARAMS.variant}=${enc(options.variant)}`);
|
|
571
|
-
}
|
|
572
|
-
if (options.mockup !== void 0) {
|
|
573
|
-
parts.push(`${PARAMS.mockup}=${enc(options.mockup)}`);
|
|
574
|
-
}
|
|
575
|
-
if (options.width !== void 0) parts.push(`${PARAMS.width}=${options.width}`);
|
|
576
|
-
if (options.aspect !== void 0 && options.aspect !== "16:9") {
|
|
577
|
-
parts.push(`${PARAMS.aspect}=${enc(options.aspect)}`);
|
|
578
|
-
}
|
|
579
|
-
if (options.bg) {
|
|
580
|
-
parts.push(`${PARAMS.bg}=${requireBgColor(options.bg)}`);
|
|
581
|
-
}
|
|
582
|
-
return `${base}${path}?${parts.join("&")}`;
|
|
1024
|
+
}
|
|
1025
|
+
});
|
|
583
1026
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
PARAMS.mockup,
|
|
592
|
-
PARAMS.width,
|
|
593
|
-
PARAMS.aspect,
|
|
594
|
-
PARAMS.bg,
|
|
595
|
-
PARAMS.signature
|
|
596
|
-
];
|
|
597
|
-
function canonicalForSig(url) {
|
|
598
|
-
const hashIdx = url.indexOf("#");
|
|
599
|
-
const noHash = hashIdx === -1 ? url : url.slice(0, hashIdx);
|
|
600
|
-
const qIdx = noHash.indexOf("?");
|
|
601
|
-
const beforeQuery = qIdx === -1 ? noHash : noHash.slice(0, qIdx);
|
|
602
|
-
const rawQuery = qIdx === -1 ? "" : noHash.slice(qIdx + 1);
|
|
603
|
-
let pathname;
|
|
604
|
-
const schemeMatch = beforeQuery.match(/^[a-zA-Z][a-zA-Z0-9+.-]*:\/\//);
|
|
605
|
-
if (schemeMatch) {
|
|
606
|
-
const afterScheme = beforeQuery.slice(schemeMatch[0].length);
|
|
607
|
-
const slashIdx = afterScheme.indexOf("/");
|
|
608
|
-
pathname = slashIdx === -1 ? "/" : afterScheme.slice(slashIdx);
|
|
609
|
-
} else {
|
|
610
|
-
pathname = beforeQuery;
|
|
611
|
-
}
|
|
612
|
-
const pairs = [];
|
|
613
|
-
if (rawQuery.length > 0) {
|
|
614
|
-
for (const segment of rawQuery.split("&")) {
|
|
615
|
-
if (segment.length === 0) continue;
|
|
616
|
-
const eq = segment.indexOf("=");
|
|
617
|
-
const rawKey = eq === -1 ? segment : segment.slice(0, eq);
|
|
618
|
-
const rawValue = eq === -1 ? "" : segment.slice(eq + 1);
|
|
619
|
-
const key = decodeURIComponent(rawKey);
|
|
620
|
-
if (key === "signature") continue;
|
|
621
|
-
if (key === "debug") continue;
|
|
622
|
-
pairs.push({ key, raw: rawValue });
|
|
1027
|
+
function setMockupBackground(shopId, shopSecret, mockupBgColor) {
|
|
1028
|
+
return httpJson(
|
|
1029
|
+
`${API_BASE}/shops/sandbox/${encodeURIComponent(shopId)}/render-settings`,
|
|
1030
|
+
{
|
|
1031
|
+
method: "PATCH",
|
|
1032
|
+
headers: { Authorization: `Bearer ${shopSecret}` },
|
|
1033
|
+
body: { mockup_bg_color: mockupBgColor }
|
|
623
1034
|
}
|
|
624
|
-
|
|
625
|
-
pairs.sort((a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0);
|
|
626
|
-
const canonicalQuery = pairs.map((p) => `${p.key}=${p.raw}`).join("&");
|
|
627
|
-
return `${pathname}?${canonicalQuery}`;
|
|
1035
|
+
);
|
|
628
1036
|
}
|
|
629
|
-
function
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
}
|
|
634
|
-
return out;
|
|
1037
|
+
function claimStatus(claimToken) {
|
|
1038
|
+
return httpJson(`${API_BASE}/shops/claim`, {
|
|
1039
|
+
headers: { Authorization: `Bearer ${claimToken}` }
|
|
1040
|
+
});
|
|
635
1041
|
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
{ name: "HMAC", hash: "SHA-256" },
|
|
642
|
-
false,
|
|
643
|
-
["sign"]
|
|
644
|
-
);
|
|
645
|
-
const sigBuf = await crypto.subtle.sign("HMAC", key, encoder.encode(canonical));
|
|
646
|
-
return toHex(new Uint8Array(sigBuf)).slice(0, 16);
|
|
1042
|
+
function releaseShop(shopId, shopSecret) {
|
|
1043
|
+
return httpJson(`${API_BASE}/shops/sandbox/${encodeURIComponent(shopId)}`, {
|
|
1044
|
+
method: "DELETE",
|
|
1045
|
+
headers: { Authorization: `Bearer ${shopSecret}` }
|
|
1046
|
+
});
|
|
647
1047
|
}
|
|
648
1048
|
|
|
649
1049
|
// src/urls.ts
|
|
@@ -671,7 +1071,12 @@ var renderUrl = (input) => buildUrl(input, IMG_BASE);
|
|
|
671
1071
|
var buyUrl = (input) => buildUrl(input, BUY_BASE);
|
|
672
1072
|
|
|
673
1073
|
// src/server.ts
|
|
674
|
-
|
|
1074
|
+
function createServer(ctx = {}) {
|
|
1075
|
+
const server2 = new McpServer({ name: "snowcone-mcp-server", version: VERSION });
|
|
1076
|
+
registerCard(server2);
|
|
1077
|
+
registerTools(server2, ctx);
|
|
1078
|
+
return server2;
|
|
1079
|
+
}
|
|
675
1080
|
var fillSchema = z.union([
|
|
676
1081
|
z.string().describe("A public image URL for this placement."),
|
|
677
1082
|
z.object({
|
|
@@ -719,170 +1124,6 @@ function toUrlInput(a) {
|
|
|
719
1124
|
...a.shop_secret !== void 0 ? { shopSecret: a.shop_secret } : {}
|
|
720
1125
|
};
|
|
721
1126
|
}
|
|
722
|
-
server.registerTool(
|
|
723
|
-
"snowcone_quickstart",
|
|
724
|
-
{
|
|
725
|
-
title: "Snowcone Quickstart",
|
|
726
|
-
description: "Make custom printed products from any photo, design or text \u2014 t-shirts, mugs, hoodies, totes, posters \u2014 with a photoreal preview and a link to buy, printed and shipped for the user. Return the entire Snowcone model and the recommended tool order in one screen. Call this FIRST when you're new to Snowcone \u2014 it explains how to mint a shop, render a mockup, and sell it, plus the silent-failure gotchas.",
|
|
727
|
-
inputSchema: {},
|
|
728
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
729
|
-
},
|
|
730
|
-
async () => ({ content: [{ type: "text", text: QUICKSTART }] })
|
|
731
|
-
);
|
|
732
|
-
server.registerTool(
|
|
733
|
-
"snowcone_mint_shop",
|
|
734
|
-
{
|
|
735
|
-
title: "Mint a sandbox Shop",
|
|
736
|
-
description: "Start a print-on-demand merch store for a creator, podcast or brand in one call \u2014 no account, no inventory; every order is printed and shipped. Mint your OWN sandbox Shop ID \u2014 no account or human needed. Returns { shop_id, shop_secret, api_key, api_key_scopes, store_url, lineup, claim }. When store_url is set, the shop is already a live store at that link \u2014 show it to the person you're helping. Pass image_url (the person's art, logo or photo) and the store opens stocked with best-sellers wearing that image \u2014 real listings at catalog prices, with mockups and checkout \u2014 listed in lineup. IMPORTANT: mint ONCE and reuse the shop_id for all render/buy calls \u2014 minting is rate-limited (60/hour, 200 unclaimed per IP \u2192 HTTP 429). shop_id is public (use it as 'shop'); shop_secret and api_key are secret (server-side only). To get paid, hand claim.verification_uri_complete to your human and poll snowcone_claim_status.",
|
|
737
|
-
inputSchema: {
|
|
738
|
-
name: z.string().optional().describe("Optional shop name (e.g. 'Jess Prints'); it also names the store's web address. Defaults to 'Sandbox <id>'."),
|
|
739
|
-
claim_pin: z.string().optional().describe("Optional out-of-band PIN your human must enter to claim (deliver it separately from the link)."),
|
|
740
|
-
require_signature: z.boolean().optional().describe(
|
|
741
|
-
"Lock the shop down: require SIGNED mockup URLs (L3). Default false \u2014 the shop is open and any unsigned URL renders (simplest to start). Set true to harden against Shop-ID theft: then every render/buy URL must be signed with the returned shop_secret (pass it as shop_secret to snowcone_render_mockup / buy URLs). Unsigned URLs will 403."
|
|
742
|
-
),
|
|
743
|
-
mockup_bg_color: z.string().optional().describe(
|
|
744
|
-
"Default background painted behind every mockup render (6-hex, '#' optional, e.g. 'f5f0ea'). Visible only where the mockup scene is transparent (studio-cutout shots). Omit for transparent (the default). Change it later with snowcone_set_mockup_background; a per-render bg overrides it."
|
|
745
|
-
),
|
|
746
|
-
image_url: z.string().url().optional().describe(
|
|
747
|
-
"Optional art for the store to open with: an https URL of a public PNG, JPEG, WebP or AVIF image (at most 10 MB). The store then opens stocked with best-sellers wearing that image, ready to sell. A bad image fails the mint with a typed E_MINT_IMAGE_* error and creates nothing. Omit for an empty store that shows what it will sell once art is added."
|
|
748
|
-
)
|
|
749
|
-
},
|
|
750
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }
|
|
751
|
-
},
|
|
752
|
-
async (args) => {
|
|
753
|
-
try {
|
|
754
|
-
const r = await mintShop({
|
|
755
|
-
...args.name !== void 0 ? { name: args.name } : {},
|
|
756
|
-
...args.claim_pin !== void 0 ? { claim_pin: args.claim_pin } : {},
|
|
757
|
-
...args.require_signature ? { require_signed_urls: true } : {},
|
|
758
|
-
...args.mockup_bg_color !== void 0 ? { mockup_bg_color: args.mockup_bg_color } : {},
|
|
759
|
-
...args.image_url !== void 0 ? { image_url: args.image_url } : {}
|
|
760
|
-
});
|
|
761
|
-
const sigLine = r.require_signed_urls ? `This shop REQUIRES signed URLs: pass shop_secret=${r.shop_secret} as shop_secret on every render/buy call, or the edge 403s.
|
|
762
|
-
` : `This shop is OPEN (unsigned URLs render). To lock it later, your human can toggle "Require signed URLs" on /studio/api-keys.
|
|
763
|
-
`;
|
|
764
|
-
const storeLine = r.store_url ? `Your store is live at ${r.store_url} \u2014 show this link to the person you're helping.
|
|
765
|
-
` : "";
|
|
766
|
-
const lineupLine = r.lineup?.listings.length ? `It opened stocked with ${r.lineup.listings.length} best-sellers wearing your image:
|
|
767
|
-
` + r.lineup.listings.map((l) => `- ${l.product_name} \u2014 $${(l.price_cents / 100).toFixed(2)}${l.url ? ` \u2014 ${l.url}` : ""} (mockup: ${l.mockup_url})`).join("\n") + "\n" : "";
|
|
768
|
-
const text = storeLine + lineupLine + `Minted shop_id=${r.shop_id} (REUSE this \u2014 don't mint again).
|
|
769
|
-
shop_secret=${r.shop_secret} (secret)
|
|
770
|
-
api_key=${r.api_key} (secret; scopes: ${r.api_key_scopes.join(", ")})
|
|
771
|
-
` + sigLine + `To get paid, send your human: ${r.claim.verification_uri_complete}
|
|
772
|
-
claim_token=${r.claim.claim_token} (secret)
|
|
773
|
-
Poll claim with that claim_token via snowcone_claim_status. Expires in ${r.claim.expires_in}s.
|
|
774
|
-
Note: the shop takes ~1-3s to propagate to the render edge \u2014 a render right after minting can 404 "Unknown shop"; wait a second and retry.`;
|
|
775
|
-
return ok(r, text);
|
|
776
|
-
} catch (err) {
|
|
777
|
-
return fail(formatError(err));
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
);
|
|
781
|
-
server.registerTool(
|
|
782
|
-
"snowcone_claim_status",
|
|
783
|
-
{
|
|
784
|
-
title: "Poll Shop claim status",
|
|
785
|
-
description: "Check whether your human has claimed the shop yet. Pass the claim_token from snowcone_mint_shop. Returns status: 'pending' | 'claimed' | 'expired'. Once 'claimed', sales route to your human's account.",
|
|
786
|
-
inputSchema: {
|
|
787
|
-
claim_token: z.string().min(1).describe("The claim_token returned by snowcone_mint_shop (ct_\u2026).")
|
|
788
|
-
},
|
|
789
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
790
|
-
},
|
|
791
|
-
async (args) => {
|
|
792
|
-
try {
|
|
793
|
-
return ok(await claimStatus(args.claim_token));
|
|
794
|
-
} catch (err) {
|
|
795
|
-
return fail(formatError(err));
|
|
796
|
-
}
|
|
797
|
-
}
|
|
798
|
-
);
|
|
799
|
-
server.registerTool(
|
|
800
|
-
"snowcone_release_shop",
|
|
801
|
-
{
|
|
802
|
-
title: "Release a sandbox Shop",
|
|
803
|
-
description: "Delete an UNCLAIMED sandbox shop you minted, freeing your per-IP mint budget. Authenticated by the shop_secret. Refused if the shop has already been claimed. Use this when you're done iterating. What survives: already-produced mockup IMAGE URLs keep rendering (they're public marketing imagery). What dies: buy/checkout URLs, the shop's credentials (shop_secret, api_key), and the claim link. Irreversible.",
|
|
804
|
-
inputSchema: {
|
|
805
|
-
shop_id: z.string().min(1).describe("The sandbox shop_id to release."),
|
|
806
|
-
shop_secret: z.string().min(1).describe("The shop_secret from snowcone_mint_shop (scsec_\u2026).")
|
|
807
|
-
},
|
|
808
|
-
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }
|
|
809
|
-
},
|
|
810
|
-
async (args) => {
|
|
811
|
-
try {
|
|
812
|
-
const r = await releaseShop(args.shop_id, args.shop_secret);
|
|
813
|
-
return ok(
|
|
814
|
-
r,
|
|
815
|
-
`Released shop_id=${r.shop_id}. Already-produced mockup IMAGE URLs keep rendering (public marketing imagery survives release). Buy/checkout URLs, the shop_secret, the api_key, and the claim link are now dead. Your per-IP mint budget is freed.`
|
|
816
|
-
);
|
|
817
|
-
} catch (err) {
|
|
818
|
-
return fail(formatError(err));
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
);
|
|
822
|
-
server.registerTool(
|
|
823
|
-
"snowcone_set_mockup_background",
|
|
824
|
-
{
|
|
825
|
-
title: "Set the shop's default mockup background",
|
|
826
|
-
description: "Set (or clear) the shop's DEFAULT background color for mockup renders \u2014 painted behind every render where the mockup scene is transparent (studio-cutout shots). Applies to all renders for the shop that don't pass an explicit bg; a per-render bg on snowcone_render_mockup overrides it. Sandbox shops only (authenticated by shop_secret); once claimed, your human manages this in shop settings \u2192 Branding. Takes effect on new renders within a few seconds (already-cached mockup URLs keep their old background).",
|
|
827
|
-
inputSchema: {
|
|
828
|
-
shop_id: z.string().min(1).describe("The sandbox shop_id to update."),
|
|
829
|
-
shop_secret: z.string().min(1).describe("The shop_secret from snowcone_mint_shop (scsec_\u2026)."),
|
|
830
|
-
color: z.string().nullable().describe("6-hex color ('#' optional, e.g. 'f5f0ea' or '#F5F0EA'), or null to clear back to transparent.")
|
|
831
|
-
},
|
|
832
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
833
|
-
},
|
|
834
|
-
async (args) => {
|
|
835
|
-
try {
|
|
836
|
-
const r = await setMockupBackground(args.shop_id, args.shop_secret, args.color);
|
|
837
|
-
const stated = r.mockup_bg_color === null ? "transparent (cleared)" : `#${r.mockup_bg_color}`;
|
|
838
|
-
return ok(
|
|
839
|
-
r,
|
|
840
|
-
`Default mockup background for shop_id=${r.shop_id} is now ${stated}. New renders pick it up within a few seconds; pass bg on snowcone_render_mockup to override per render.`
|
|
841
|
-
);
|
|
842
|
-
} catch (err) {
|
|
843
|
-
return fail(formatError(err));
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
);
|
|
847
|
-
server.registerTool(
|
|
848
|
-
"snowcone_search_catalog",
|
|
849
|
-
{
|
|
850
|
-
title: "Search the product catalog",
|
|
851
|
-
description: "Find products to put a photo or design on \u2014 t-shirts, hoodies, mugs, totes, posters and more \u2014 with their suggested retail prices. Full-text search the public Snowcone catalog (t-shirts, hoodies, mugs, \u2026). Returns matching products with their code (id), name, price_cents (suggested retail, USD cents), and placement/mockup counts. Use snowcone_get_product for the full placement/mockup/option detail needed to render.",
|
|
852
|
-
inputSchema: {
|
|
853
|
-
query: z.string().default("").describe("Search text. Empty string lists popular products."),
|
|
854
|
-
limit: z.number().int().min(1).max(50).default(10).describe("Max results (1-50)."),
|
|
855
|
-
offset: z.number().int().min(0).default(0).describe("Pagination offset.")
|
|
856
|
-
},
|
|
857
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
858
|
-
},
|
|
859
|
-
async (args) => {
|
|
860
|
-
try {
|
|
861
|
-
const { hits, estimatedTotalHits } = await searchCatalog(args.query, args.limit, args.offset);
|
|
862
|
-
const items = hits.map((h) => ({
|
|
863
|
-
id: h.id,
|
|
864
|
-
name: h.name,
|
|
865
|
-
price_cents: h.basePrice ?? h.price,
|
|
866
|
-
placements: h.placements?.length ?? 0,
|
|
867
|
-
mockups: h.mockups?.length ?? 0
|
|
868
|
-
}));
|
|
869
|
-
const out = {
|
|
870
|
-
total: estimatedTotalHits,
|
|
871
|
-
count: items.length,
|
|
872
|
-
offset: args.offset,
|
|
873
|
-
items,
|
|
874
|
-
has_more: estimatedTotalHits > args.offset + items.length
|
|
875
|
-
};
|
|
876
|
-
let text = JSON.stringify(out, null, 2);
|
|
877
|
-
if (text.length > CHARACTER_LIMIT) {
|
|
878
|
-
text = JSON.stringify({ ...out, items: items.slice(0, 5), truncated: true }, null, 2);
|
|
879
|
-
}
|
|
880
|
-
return { content: [{ type: "text", text }], structuredContent: out };
|
|
881
|
-
} catch (err) {
|
|
882
|
-
return fail(formatError(err));
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
);
|
|
886
1127
|
async function summarizeDesign(d, shop, shopSecret) {
|
|
887
1128
|
const base = {
|
|
888
1129
|
pairing_id: d.pairingId ?? d.id,
|
|
@@ -906,256 +1147,486 @@ async function summarizeDesign(d, shop, shopSecret) {
|
|
|
906
1147
|
const url = await renderUrl(input);
|
|
907
1148
|
return shop ? { ...base, mockup_url: url } : { ...base, mockup_url_template: url };
|
|
908
1149
|
}
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
filter: z.string().optional().describe(`Meilisearch filter expression, e.g. "occasion = 'christmas' AND style = 'watercolor'".`),
|
|
919
|
-
semantic_ratio: z.number().min(0).max(1).default(0.5).describe("Semantic vs keyword blend (0 = keyword-only, 1 = fully semantic). Default 0.5."),
|
|
920
|
-
shop: z.string().optional().describe("Your public Shop ID \u2014 when set, each result includes a ready-to-render mockup_url."),
|
|
921
|
-
shop_secret: z.string().optional().describe("Per-shop secret (scsec_\u2026). With 'shop', URLs are L3-signed (server-side only \u2014 never expose it).")
|
|
1150
|
+
function registerCard(server2) {
|
|
1151
|
+
server2.registerResource(
|
|
1152
|
+
"Snowcone mockup card",
|
|
1153
|
+
CARD_URI,
|
|
1154
|
+
{
|
|
1155
|
+
title: "Snowcone mockup card",
|
|
1156
|
+
description: "The person's design on the product, with price, option choices and Buy.",
|
|
1157
|
+
mimeType: CARD_MIME,
|
|
1158
|
+
_meta: cardResourceMeta()
|
|
922
1159
|
},
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
1160
|
+
async () => ({
|
|
1161
|
+
contents: [{ uri: CARD_URI, mimeType: CARD_MIME, text: cardHtml(), _meta: cardResourceMeta() }]
|
|
1162
|
+
})
|
|
1163
|
+
);
|
|
1164
|
+
}
|
|
1165
|
+
function pickableOptions(p, chosen) {
|
|
1166
|
+
const attrs = p?.options?.attributes;
|
|
1167
|
+
const out = {};
|
|
1168
|
+
for (const [attr, meta] of Object.entries(attrs ?? {})) {
|
|
1169
|
+
const choices = (meta.choices ?? []).map((c) => c.label).filter((l) => typeof l === "string" && l.length > 0);
|
|
1170
|
+
if (choices.length < 2) continue;
|
|
1171
|
+
const picked = chosen?.[attr];
|
|
1172
|
+
out[attr] = { choices, selected: picked !== void 0 && choices.includes(picked) ? picked : null };
|
|
1173
|
+
}
|
|
1174
|
+
return out;
|
|
1175
|
+
}
|
|
1176
|
+
async function buildCard(args, imageUrl, orders, product) {
|
|
1177
|
+
const { shop_secret, verify: _verify, ...rest } = args;
|
|
1178
|
+
return {
|
|
1179
|
+
image_url: imageUrl,
|
|
1180
|
+
product: product ? {
|
|
1181
|
+
id: product.id,
|
|
1182
|
+
name: product.name ?? product.id,
|
|
1183
|
+
price_cents: typeof (product.basePrice ?? product.price) === "number" ? product.basePrice ?? product.price : null
|
|
1184
|
+
} : null,
|
|
1185
|
+
options: pickableOptions(product, args.options),
|
|
1186
|
+
buy_url: await buyUrl(toUrlInput(args)),
|
|
1187
|
+
orders,
|
|
1188
|
+
// A signed shop's secret never goes into the card, so its picker can't re-sign: no picker there.
|
|
1189
|
+
render_args: shop_secret ? null : rest
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
function registerTools(server2, ctx) {
|
|
1193
|
+
server2.registerTool(
|
|
1194
|
+
"snowcone_quickstart",
|
|
1195
|
+
{
|
|
1196
|
+
title: "Snowcone Quickstart",
|
|
1197
|
+
description: "Make custom printed products from any photo, design or text \u2014 t-shirts, mugs, hoodies, totes, posters \u2014 with a photoreal preview and a link to buy, printed and shipped for the user. Return the entire Snowcone model and the recommended tool order in one screen. Call this FIRST when you're new to Snowcone \u2014 it explains how to mint a shop, render a mockup, and sell it, plus the silent-failure gotchas.",
|
|
1198
|
+
inputSchema: {},
|
|
1199
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1200
|
+
},
|
|
1201
|
+
async () => ({ content: [{ type: "text", text: QUICKSTART }] })
|
|
1202
|
+
);
|
|
1203
|
+
server2.registerTool(
|
|
1204
|
+
"snowcone_mint_shop",
|
|
1205
|
+
{
|
|
1206
|
+
title: "Mint a sandbox Shop",
|
|
1207
|
+
description: "Start a print-on-demand merch store for a creator, podcast or brand in one call \u2014 no account, no inventory; every order is printed and shipped. Mint your OWN sandbox Shop ID \u2014 no account or human needed. Returns { shop_id, shop_secret, api_key, api_key_scopes, store_url, lineup, claim }. When store_url is set, the shop is already a live store at that link \u2014 show it to the person you're helping. Pass image_url (the person's art, logo or photo) and the store opens stocked with best-sellers wearing that image \u2014 real listings at catalog prices, with mockups and checkout \u2014 listed in lineup. IMPORTANT: mint ONCE and reuse the shop_id for all render/buy calls \u2014 minting is rate-limited (60/hour, 200 unclaimed per IP \u2192 HTTP 429). shop_id is public (use it as 'shop'); shop_secret and api_key are secret (server-side only). To get paid, hand claim.verification_uri_complete to your human and poll snowcone_claim_status.",
|
|
1208
|
+
inputSchema: {
|
|
1209
|
+
name: z.string().optional().describe("Optional shop name (e.g. 'Jess Prints'); it also names the store's web address. Defaults to 'Sandbox <id>'."),
|
|
1210
|
+
claim_pin: z.string().optional().describe("Optional out-of-band PIN your human must enter to claim (deliver it separately from the link)."),
|
|
1211
|
+
require_signature: z.boolean().optional().describe(
|
|
1212
|
+
"Lock the shop down: require SIGNED mockup URLs (L3). Default false \u2014 the shop is open and any unsigned URL renders (simplest to start). Set true to harden against Shop-ID theft: then every render/buy URL must be signed with the returned shop_secret (pass it as shop_secret to snowcone_render_mockup / buy URLs). Unsigned URLs will 403."
|
|
1213
|
+
),
|
|
1214
|
+
mockup_bg_color: z.string().optional().describe(
|
|
1215
|
+
"Default background painted behind every mockup render (6-hex, '#' optional, e.g. 'f5f0ea'). Visible only where the mockup scene is transparent (studio-cutout shots). Omit for transparent (the default). Change it later with snowcone_set_mockup_background; a per-render bg overrides it."
|
|
1216
|
+
),
|
|
1217
|
+
image_url: z.string().url().optional().describe(
|
|
1218
|
+
"Optional art for the store to open with: an https URL of a public PNG, JPEG, WebP or AVIF image (at most 10 MB). The store then opens stocked with best-sellers wearing that image, ready to sell. A bad image fails the mint with a typed E_MINT_IMAGE_* error and creates nothing. Omit for an empty store that shows what it will sell once art is added."
|
|
1219
|
+
)
|
|
1220
|
+
},
|
|
1221
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }
|
|
1222
|
+
},
|
|
1223
|
+
async (args) => {
|
|
1224
|
+
try {
|
|
1225
|
+
const r = await mintShop({
|
|
1226
|
+
...ctx.forwardedFor ? { forwardedFor: ctx.forwardedFor } : {},
|
|
1227
|
+
...args.name !== void 0 ? { name: args.name } : {},
|
|
1228
|
+
...args.claim_pin !== void 0 ? { claim_pin: args.claim_pin } : {},
|
|
1229
|
+
...args.require_signature ? { require_signed_urls: true } : {},
|
|
1230
|
+
...args.mockup_bg_color !== void 0 ? { mockup_bg_color: args.mockup_bg_color } : {},
|
|
1231
|
+
...args.image_url !== void 0 ? { image_url: args.image_url } : {}
|
|
1232
|
+
});
|
|
1233
|
+
const sigLine = r.require_signed_urls ? `This shop REQUIRES signed URLs: pass shop_secret=${r.shop_secret} as shop_secret on every render/buy call, or the edge 403s.
|
|
1234
|
+
` : `This shop is OPEN (unsigned URLs render). To lock it later, your human can toggle "Require signed URLs" on /studio/api-keys.
|
|
1235
|
+
`;
|
|
1236
|
+
const storeLine = r.store_url ? `Your store is live at ${r.store_url} \u2014 show this link to the person you're helping.
|
|
1237
|
+
` : "";
|
|
1238
|
+
const lineupLine = r.lineup?.listings.length ? `It opened stocked with ${r.lineup.listings.length} best-sellers wearing your image:
|
|
1239
|
+
` + r.lineup.listings.map((l) => `- ${l.product_name} \u2014 $${(l.price_cents / 100).toFixed(2)}${l.url ? ` \u2014 ${l.url}` : ""} (mockup: ${l.mockup_url})`).join("\n") + "\n" : "";
|
|
1240
|
+
const text = storeLine + lineupLine + `Minted shop_id=${r.shop_id} (REUSE this \u2014 don't mint again).
|
|
1241
|
+
shop_secret=${r.shop_secret} (secret)
|
|
1242
|
+
api_key=${r.api_key} (secret; scopes: ${r.api_key_scopes.join(", ")})
|
|
1243
|
+
` + sigLine + `To get paid, send your human: ${r.claim.verification_uri_complete}
|
|
1244
|
+
claim_token=${r.claim.claim_token} (secret)
|
|
1245
|
+
Poll claim with that claim_token via snowcone_claim_status. Expires in ${r.claim.expires_in}s.
|
|
1246
|
+
Note: the shop takes ~1-3s to propagate to the render edge \u2014 a render right after minting can 404 "Unknown shop"; wait a second and retry.`;
|
|
1247
|
+
return ok(r, text);
|
|
1248
|
+
} catch (err) {
|
|
1249
|
+
return fail(formatError(err));
|
|
939
1250
|
}
|
|
940
|
-
return { content: [{ type: "text", text }], structuredContent: out };
|
|
941
|
-
} catch (err) {
|
|
942
|
-
return fail(formatError(err));
|
|
943
1251
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
// spelled it `id_or_slug` cost every cold agent a guaranteed failed
|
|
955
|
-
// round-trip. `product` is the canonical name; `id_or_slug` stays as a
|
|
956
|
-
// silent alias so agents that learned the old name keep working.
|
|
957
|
-
product: z.string().min(1).optional().describe("Product code (the catalog document id) or slug, e.g. 'BC43BE'. Same name as every other tool."),
|
|
958
|
-
id_or_slug: z.string().min(1).optional().describe("Deprecated alias of 'product' \u2014 accepted for back-compat; prefer 'product'.")
|
|
1252
|
+
);
|
|
1253
|
+
server2.registerTool(
|
|
1254
|
+
"snowcone_claim_status",
|
|
1255
|
+
{
|
|
1256
|
+
title: "Poll Shop claim status",
|
|
1257
|
+
description: "Check whether your human has claimed the shop yet. Pass the claim_token from snowcone_mint_shop. Returns status: 'pending' | 'claimed' | 'expired'. Once 'claimed', sales route to your human's account.",
|
|
1258
|
+
inputSchema: {
|
|
1259
|
+
claim_token: z.string().min(1).describe("The claim_token returned by snowcone_mint_shop (ct_\u2026).")
|
|
1260
|
+
},
|
|
1261
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
959
1262
|
},
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
1263
|
+
async (args) => {
|
|
1264
|
+
try {
|
|
1265
|
+
return ok(await claimStatus(args.claim_token));
|
|
1266
|
+
} catch (err) {
|
|
1267
|
+
return fail(formatError(err));
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
);
|
|
1271
|
+
server2.registerTool(
|
|
1272
|
+
"snowcone_release_shop",
|
|
1273
|
+
{
|
|
1274
|
+
title: "Release a sandbox Shop",
|
|
1275
|
+
description: "Delete an UNCLAIMED sandbox shop you minted, freeing your per-IP mint budget. Authenticated by the shop_secret. Refused if the shop has already been claimed. Use this when you're done iterating. What survives: already-produced mockup IMAGE URLs keep rendering (they're public marketing imagery). What dies: buy/checkout URLs, the shop's credentials (shop_secret, api_key), and the claim link. Irreversible.",
|
|
1276
|
+
inputSchema: {
|
|
1277
|
+
shop_id: z.string().min(1).describe("The sandbox shop_id to release."),
|
|
1278
|
+
shop_secret: z.string().min(1).describe("The shop_secret from snowcone_mint_shop (scsec_\u2026).")
|
|
1279
|
+
},
|
|
1280
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }
|
|
1281
|
+
},
|
|
1282
|
+
async (args) => {
|
|
1283
|
+
try {
|
|
1284
|
+
const r = await releaseShop(args.shop_id, args.shop_secret);
|
|
1285
|
+
return ok(
|
|
1286
|
+
r,
|
|
1287
|
+
`Released shop_id=${r.shop_id}. Already-produced mockup IMAGE URLs keep rendering (public marketing imagery survives release). Buy/checkout URLs, the shop_secret, the api_key, and the claim link are now dead. Your per-IP mint budget is freed.`
|
|
968
1288
|
);
|
|
1289
|
+
} catch (err) {
|
|
1290
|
+
return fail(formatError(err));
|
|
969
1291
|
}
|
|
970
|
-
const p = await getProduct(code);
|
|
971
|
-
if (!p) return fail(`Error: no product found for '${code}'. It would render blank \u2014 pick one from snowcone_search_catalog.`);
|
|
972
|
-
return ok(summarizeProduct(p));
|
|
973
|
-
} catch (err) {
|
|
974
|
-
return fail(formatError(err));
|
|
975
1292
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1293
|
+
);
|
|
1294
|
+
server2.registerTool(
|
|
1295
|
+
"snowcone_set_mockup_background",
|
|
1296
|
+
{
|
|
1297
|
+
title: "Set the shop's default mockup background",
|
|
1298
|
+
description: "Set (or clear) the shop's DEFAULT background color for mockup renders \u2014 painted behind every render where the mockup scene is transparent (studio-cutout shots). Applies to all renders for the shop that don't pass an explicit bg; a per-render bg on snowcone_render_mockup overrides it. Sandbox shops only (authenticated by shop_secret); once claimed, your human manages this in shop settings \u2192 Branding. Takes effect on new renders within a few seconds (already-cached mockup URLs keep their old background).",
|
|
1299
|
+
inputSchema: {
|
|
1300
|
+
shop_id: z.string().min(1).describe("The sandbox shop_id to update."),
|
|
1301
|
+
shop_secret: z.string().min(1).describe("The shop_secret from snowcone_mint_shop (scsec_\u2026)."),
|
|
1302
|
+
color: z.string().nullable().describe("6-hex color ('#' optional, e.g. 'f5f0ea' or '#F5F0EA'), or null to clear back to transparent.")
|
|
1303
|
+
},
|
|
1304
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
988
1305
|
},
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
const url = await renderUrl(toUrlInput(args));
|
|
994
|
-
const img_html = `<img src="${url}" style="object-fit:cover" alt="mockup" />`;
|
|
995
|
-
if (args.verify === false) {
|
|
1306
|
+
async (args) => {
|
|
1307
|
+
try {
|
|
1308
|
+
const r = await setMockupBackground(args.shop_id, args.shop_secret, args.color);
|
|
1309
|
+
const stated = r.mockup_bg_color === null ? "transparent (cleared)" : `#${r.mockup_bg_color}`;
|
|
996
1310
|
return ok(
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
img_html,
|
|
1000
|
-
notes: "Unverified (verify=false). Display with object-fit:cover and request ~2\xD7 the displayed size. The asset URL must be a publicly-fetchable raster image."
|
|
1001
|
-
},
|
|
1002
|
-
url
|
|
1311
|
+
r,
|
|
1312
|
+
`Default mockup background for shop_id=${r.shop_id} is now ${stated}. New renders pick it up within a few seconds; pass bg on snowcone_render_mockup to override per render.`
|
|
1003
1313
|
);
|
|
1314
|
+
} catch (err) {
|
|
1315
|
+
return fail(formatError(err));
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
);
|
|
1319
|
+
server2.registerTool(
|
|
1320
|
+
"snowcone_search_catalog",
|
|
1321
|
+
{
|
|
1322
|
+
title: "Search the product catalog",
|
|
1323
|
+
description: "Find products to put a photo or design on \u2014 t-shirts, hoodies, mugs, totes, posters and more \u2014 with their suggested retail prices. Full-text search the public Snowcone catalog (t-shirts, hoodies, mugs, \u2026). Returns matching products with their code (id), name, price_cents (suggested retail, USD cents), and placement/mockup counts. Use snowcone_get_product for the full placement/mockup/option detail needed to render.",
|
|
1324
|
+
inputSchema: {
|
|
1325
|
+
query: z.string().default("").describe("Search text. Empty string lists popular products."),
|
|
1326
|
+
limit: z.number().int().min(1).max(50).default(10).describe("Max results (1-50)."),
|
|
1327
|
+
offset: z.number().int().min(0).default(0).describe("Pagination offset.")
|
|
1328
|
+
},
|
|
1329
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1330
|
+
},
|
|
1331
|
+
async (args) => {
|
|
1332
|
+
try {
|
|
1333
|
+
const { hits, estimatedTotalHits } = await searchCatalog(args.query, args.limit, args.offset);
|
|
1334
|
+
const items = hits.map((h) => ({
|
|
1335
|
+
id: h.id,
|
|
1336
|
+
name: h.name,
|
|
1337
|
+
price_cents: h.basePrice ?? h.price,
|
|
1338
|
+
placements: h.placements?.length ?? 0,
|
|
1339
|
+
mockups: h.mockups?.length ?? 0
|
|
1340
|
+
}));
|
|
1341
|
+
const out = {
|
|
1342
|
+
total: estimatedTotalHits,
|
|
1343
|
+
count: items.length,
|
|
1344
|
+
offset: args.offset,
|
|
1345
|
+
items,
|
|
1346
|
+
has_more: estimatedTotalHits > args.offset + items.length
|
|
1347
|
+
};
|
|
1348
|
+
let text = JSON.stringify(out, null, 2);
|
|
1349
|
+
if (text.length > CHARACTER_LIMIT) {
|
|
1350
|
+
text = JSON.stringify({ ...out, items: items.slice(0, 5), truncated: true }, null, 2);
|
|
1351
|
+
}
|
|
1352
|
+
return { content: [{ type: "text", text }], structuredContent: out };
|
|
1353
|
+
} catch (err) {
|
|
1354
|
+
return fail(formatError(err));
|
|
1004
1355
|
}
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1356
|
+
}
|
|
1357
|
+
);
|
|
1358
|
+
server2.registerTool(
|
|
1359
|
+
"snowcone_search_designs",
|
|
1360
|
+
{
|
|
1361
|
+
title: "Search the pre-made designs catalog",
|
|
1362
|
+
description: "Search the public catalog of remixable published designs \u2014 hybrid semantic + keyword over each design's AI visual caption, so descriptive queries like 'pink cowgirl boots on the moon' work (e.g. holiday cards, tees, posters; filter curated = true for first-party-curated picks) so an integration never starts from a blank canvas. Filterable facets: tags, occasion, style, productId, minPriceCents, curated. Each result includes the design's product, license, and a ready-to-render mockup_url (a design=<pairingId> reference URL) when you pass your 'shop'. Catalog design renders are FREE \u2014 they don't count against the shop's usage budget. Without 'shop' you get a mockup_url_template containing YOUR_SHOP_ID to substitute.",
|
|
1363
|
+
inputSchema: {
|
|
1364
|
+
query: z.string().default("").describe("Search text, e.g. 'christmas card'. Empty string lists curated designs."),
|
|
1365
|
+
limit: z.number().int().min(1).max(50).default(10).describe("Max results (1-50)."),
|
|
1366
|
+
offset: z.number().int().min(0).default(0).describe("Pagination offset."),
|
|
1367
|
+
filter: z.string().optional().describe(`Meilisearch filter expression, e.g. "occasion = 'christmas' AND style = 'watercolor'".`),
|
|
1368
|
+
semantic_ratio: z.number().min(0).max(1).default(0.5).describe("Semantic vs keyword blend (0 = keyword-only, 1 = fully semantic). Default 0.5."),
|
|
1369
|
+
shop: z.string().optional().describe("Your public Shop ID \u2014 when set, each result includes a ready-to-render mockup_url."),
|
|
1370
|
+
shop_secret: z.string().optional().describe("Per-shop secret (scsec_\u2026). With 'shop', URLs are L3-signed (server-side only \u2014 never expose it).")
|
|
1371
|
+
},
|
|
1372
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1373
|
+
},
|
|
1374
|
+
async (args) => {
|
|
1375
|
+
try {
|
|
1376
|
+
const { hits, estimatedTotalHits } = await searchDesigns(args.query, args.limit, args.offset, args.filter, args.semantic_ratio);
|
|
1377
|
+
const items = await Promise.all(hits.map((h) => summarizeDesign(h, args.shop, args.shop_secret)));
|
|
1378
|
+
const out = {
|
|
1379
|
+
total: estimatedTotalHits,
|
|
1380
|
+
count: items.length,
|
|
1381
|
+
offset: args.offset,
|
|
1382
|
+
items,
|
|
1383
|
+
has_more: estimatedTotalHits > args.offset + items.length
|
|
1384
|
+
};
|
|
1385
|
+
let text = JSON.stringify(out, null, 2);
|
|
1386
|
+
if (text.length > CHARACTER_LIMIT) {
|
|
1387
|
+
text = JSON.stringify({ ...out, items: items.slice(0, 5), truncated: true }, null, 2);
|
|
1388
|
+
}
|
|
1389
|
+
return { content: [{ type: "text", text }], structuredContent: out };
|
|
1390
|
+
} catch (err) {
|
|
1391
|
+
return fail(formatError(err));
|
|
1009
1392
|
}
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1393
|
+
}
|
|
1394
|
+
);
|
|
1395
|
+
server2.registerTool(
|
|
1396
|
+
"snowcone_get_product",
|
|
1397
|
+
{
|
|
1398
|
+
title: "Get a product",
|
|
1399
|
+
description: "Fetch one product by its code (id) or slug. Returns placements (where art goes), mockups (scene ids for the 'view' param), and variant options \u2014 everything you need to build a render URL. Returns an error if the code doesn't exist (it would render blank).",
|
|
1400
|
+
inputSchema: {
|
|
1401
|
+
// eng/0049 F1 (growth/0013 cold-agent run): every sibling tool takes
|
|
1402
|
+
// `product`, and the prose says "product code" — the one tool that
|
|
1403
|
+
// spelled it `id_or_slug` cost every cold agent a guaranteed failed
|
|
1404
|
+
// round-trip. `product` is the canonical name; `id_or_slug` stays as a
|
|
1405
|
+
// silent alias so agents that learned the old name keep working.
|
|
1406
|
+
product: z.string().min(1).optional().describe("Product code (the catalog document id) or slug, e.g. 'BC43BE'. Same name as every other tool."),
|
|
1407
|
+
id_or_slug: z.string().min(1).optional().describe("Deprecated alias of 'product' \u2014 accepted for back-compat; prefer 'product'.")
|
|
1408
|
+
},
|
|
1409
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1410
|
+
},
|
|
1411
|
+
async (args) => {
|
|
1412
|
+
try {
|
|
1413
|
+
const code = args.product ?? args.id_or_slug;
|
|
1414
|
+
if (!code) {
|
|
1415
|
+
return fail(
|
|
1416
|
+
"E_MISSING_PRODUCT: pass product (the product code or slug, e.g. { product: 'BC43BE' }) \u2014 the same 'product' argument snowcone_render_mockup and snowcone_buy_url take."
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
const p = await getProduct(code);
|
|
1420
|
+
if (!p) return fail(`Error: no product found for '${code}'. It would render blank \u2014 pick one from snowcone_search_catalog.`);
|
|
1421
|
+
return ok(summarizeProduct(p));
|
|
1422
|
+
} catch (err) {
|
|
1423
|
+
return fail(formatError(err));
|
|
1014
1424
|
}
|
|
1015
|
-
const designKeys = args.design ? Object.keys(args.design) : [];
|
|
1016
|
-
const verifiedView = args.view ? `view '${args.view}'` : "the default view";
|
|
1017
|
-
const scopeNote = designKeys.length > 1 ? `verify confirmed ${verifiedView} only \u2014 placements not visible in it (design keys: ${designKeys.join(", ")}) are built into the URL but NOT independently confirmed. Render each placement's own view to confirm it.` : void 0;
|
|
1018
|
-
return ok(
|
|
1019
|
-
{
|
|
1020
|
-
url,
|
|
1021
|
-
img_html,
|
|
1022
|
-
verified: true,
|
|
1023
|
-
kind: v.kind,
|
|
1024
|
-
bytes: v.bytes,
|
|
1025
|
-
...scopeNote ? { verified_scope: scopeNote } : {}
|
|
1026
|
-
},
|
|
1027
|
-
`\u2713 verified \u2014 renders ${v.kind} (${v.bytes} bytes): ${url}${scopeNote ? `
|
|
1028
|
-
\u26A0\uFE0F ${scopeNote}` : ""}`
|
|
1029
|
-
);
|
|
1030
|
-
} catch (err) {
|
|
1031
|
-
return fail(formatError(err));
|
|
1032
1425
|
}
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1426
|
+
);
|
|
1427
|
+
server2.registerTool(
|
|
1428
|
+
"snowcone_render_mockup",
|
|
1429
|
+
{
|
|
1430
|
+
title: "Render a mockup URL",
|
|
1431
|
+
description: "Show the user their photo, design or text on a real product (t-shirt, mug, hoodie, tote, poster\u2026) as a photoreal preview image. Build a public mockup IMAGE url for a product + your artwork + your shop. The result is an <img>-ready URL \u2014 no API call, no upload. Provide 'asset' (one image) OR 'design' (per-placement map). The asset must be a publicly-fetchable raster image (PNG/JPEG/WebP/AVIF; not SVG), and the product code must exist in the catalog. Pass shop_secret to get an L3-signed URL. By DEFAULT the server fetches the built URL and confirms it actually renders, so a bad product code, wrong placement key, or unusable asset comes back as a clear error instead of a confident-but-broken URL. Pass verify=false to skip that check and just get the URL string instantly. In ChatGPT, Claude and other MCP Apps hosts the result shows as a card: the mockup, name, price, option choices and Buy. The result's 'orders' says whether Snowcone is taking orders yet; when it is 'not-open', show the mockup but don't offer the buy link as a way to order.",
|
|
1432
|
+
_meta: CARD_TOOL_META,
|
|
1433
|
+
inputSchema: {
|
|
1434
|
+
...urlShape,
|
|
1435
|
+
verify: z.boolean().optional().describe(
|
|
1436
|
+
"Fetch the built URL and confirm it returns a real image before reporting success (DEFAULT true). Turns silent failures into a clear, actionable error and retries once on a not-yet-propagated shop. Set false to skip the network round-trip and return the URL string unchecked."
|
|
1437
|
+
)
|
|
1438
|
+
},
|
|
1439
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1045
1440
|
},
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1441
|
+
async (args) => {
|
|
1442
|
+
try {
|
|
1443
|
+
const url = await renderUrl(toUrlInput(args));
|
|
1444
|
+
const img_html = `<img src="${url}" style="object-fit:cover" alt="mockup" />`;
|
|
1445
|
+
if (args.verify === false) {
|
|
1446
|
+
const orders2 = await readOrdersState();
|
|
1447
|
+
const card2 = await buildCard(args, url, orders2, null);
|
|
1448
|
+
return ok(
|
|
1449
|
+
{
|
|
1450
|
+
url,
|
|
1451
|
+
img_html,
|
|
1452
|
+
buy_url: card2.buy_url,
|
|
1453
|
+
orders: orders2,
|
|
1454
|
+
card: card2,
|
|
1455
|
+
notes: "Unverified (verify=false). Display with object-fit:cover and request ~2\xD7 the displayed size. The asset URL must be a publicly-fetchable raster image."
|
|
1456
|
+
},
|
|
1457
|
+
`${url}
|
|
1458
|
+
${ordersLine(orders2)}`
|
|
1459
|
+
);
|
|
1460
|
+
}
|
|
1461
|
+
const productP = getProduct(args.product).catch(() => null);
|
|
1462
|
+
const ordersP = readOrdersState();
|
|
1463
|
+
let v = await verifyImageUrl(url);
|
|
1464
|
+
if (!v.ok && /unknown shop/i.test(v.error ?? "")) {
|
|
1465
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
1466
|
+
v = await verifyImageUrl(url);
|
|
1467
|
+
}
|
|
1468
|
+
if (!v.ok) {
|
|
1469
|
+
const hint = renderFixHint(v.error);
|
|
1470
|
+
const reason = (v.error ?? "render failed").replace(/\.*$/, "");
|
|
1471
|
+
return fail(`Built ${url} but it does NOT render: ${reason}.${hint ? " " + hint : ""}`);
|
|
1472
|
+
}
|
|
1473
|
+
const designKeys = args.design ? Object.keys(args.design) : [];
|
|
1474
|
+
const verifiedView = args.view ? `view '${args.view}'` : "the default view";
|
|
1475
|
+
const scopeNote = designKeys.length > 1 ? `verify confirmed ${verifiedView} only \u2014 placements not visible in it (design keys: ${designKeys.join(", ")}) are built into the URL but NOT independently confirmed. Render each placement's own view to confirm it.` : void 0;
|
|
1476
|
+
const [product, orders] = await Promise.all([productP, ordersP]);
|
|
1477
|
+
const card = await buildCard(args, url, orders, product);
|
|
1052
1478
|
return ok(
|
|
1053
|
-
{
|
|
1054
|
-
|
|
1479
|
+
{
|
|
1480
|
+
url,
|
|
1481
|
+
img_html,
|
|
1482
|
+
verified: true,
|
|
1483
|
+
kind: v.kind,
|
|
1484
|
+
bytes: v.bytes,
|
|
1485
|
+
...scopeNote ? { verified_scope: scopeNote } : {},
|
|
1486
|
+
buy_url: card.buy_url,
|
|
1487
|
+
orders,
|
|
1488
|
+
card
|
|
1489
|
+
},
|
|
1490
|
+
`\u2713 verified \u2014 renders ${v.kind} (${v.bytes} bytes): ${url}${scopeNote ? `
|
|
1491
|
+
\u26A0\uFE0F ${scopeNote}` : ""}
|
|
1492
|
+
${ordersLine(orders)}`
|
|
1055
1493
|
);
|
|
1494
|
+
} catch (err) {
|
|
1495
|
+
return fail(formatError(err));
|
|
1056
1496
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1497
|
+
}
|
|
1498
|
+
);
|
|
1499
|
+
server2.registerTool(
|
|
1500
|
+
"snowcone_buy_url",
|
|
1501
|
+
{
|
|
1502
|
+
title: "Build a checkout URL",
|
|
1503
|
+
description: "Give the user a link to buy the printed product they just previewed \u2014 it's printed and shipped to them. Build the buyable checkout url for the same product + artwork + shop you'd render. Same inputs as snowcone_render_mockup. Send a customer here to purchase the printed item. Sales route to Snowcone until your human claims the shop. By DEFAULT the server follows the URL and confirms it resolves to a live checkout (the Stripe session actually builds) AND that the matching mockup image renders \u2014 so a bad product code, shop, option combo, or unusable asset comes back as a clear error instead of a confident-but-broken link. 'verified' means the same thing here as in snowcone_render_mockup. This does NOT charge anything; it only builds the session. Pass verify=false to skip the check and get the URL string instantly. The result's 'orders' says whether Snowcone is taking orders yet: while it is 'not-open', don't offer this link to the person as a way to order.",
|
|
1504
|
+
inputSchema: {
|
|
1505
|
+
...urlShape,
|
|
1506
|
+
verify: z.boolean().optional().describe(
|
|
1507
|
+
"Follow the built URL and confirm it resolves to a live checkout, and fetch the matching mockup to confirm the product image renders, before reporting success (DEFAULT true). Set false to skip the network round-trip and return the URL string unchecked."
|
|
1508
|
+
)
|
|
1509
|
+
},
|
|
1510
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1511
|
+
},
|
|
1512
|
+
async (args) => {
|
|
1513
|
+
try {
|
|
1514
|
+
const url = await buyUrl(toUrlInput(args));
|
|
1515
|
+
const ordersP = readOrdersState();
|
|
1516
|
+
if (args.verify === false) {
|
|
1517
|
+
const orders2 = await ordersP;
|
|
1518
|
+
return ok(
|
|
1519
|
+
{ url, orders: orders2, notes: "Unverified (verify=false). Send a customer here to purchase the printed item." },
|
|
1520
|
+
`${url}
|
|
1521
|
+
${ordersLine(orders2)}`
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
const [v, img] = await Promise.all([verifyCheckoutUrl(url), verifyImageUrl(await renderUrl(toUrlInput(args)))]);
|
|
1525
|
+
if (!v.ok) {
|
|
1526
|
+
const reason = (v.error ?? "checkout failed").replace(/\.*$/, "");
|
|
1527
|
+
return fail(`Built ${url} but it does NOT resolve to a live checkout: ${reason}.`);
|
|
1528
|
+
}
|
|
1529
|
+
if (!img.ok) {
|
|
1530
|
+
const hint = renderFixHint(img.error);
|
|
1531
|
+
const reason = (img.error ?? "render failed").replace(/\.*$/, "");
|
|
1532
|
+
return fail(
|
|
1533
|
+
`Built ${url} \u2014 the checkout is live, but the product image for these inputs does NOT render, so a customer would buy a broken mockup: ${reason}.${hint ? " " + hint : ""} Fix the inputs (same as snowcone_render_mockup) and call again.`
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
const orders = await ordersP;
|
|
1537
|
+
return ok(
|
|
1538
|
+
{ url, verified: true, checkout_url: v.checkout_url, render_verified: true, render_kind: img.kind, orders },
|
|
1539
|
+
`\u2713 verified \u2014 resolves to a live checkout AND the product image renders (${img.kind}): ${url}
|
|
1540
|
+
${ordersLine(orders)}`
|
|
1067
1541
|
);
|
|
1542
|
+
} catch (err) {
|
|
1543
|
+
return fail(formatError(err));
|
|
1068
1544
|
}
|
|
1069
|
-
return ok(
|
|
1070
|
-
{ url, verified: true, checkout_url: v.checkout_url, render_verified: true, render_kind: img.kind },
|
|
1071
|
-
`\u2713 verified \u2014 resolves to a live checkout AND the product image renders (${img.kind}): ${url}`
|
|
1072
|
-
);
|
|
1073
|
-
} catch (err) {
|
|
1074
|
-
return fail(formatError(err));
|
|
1075
1545
|
}
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1546
|
+
);
|
|
1547
|
+
server2.registerTool(
|
|
1548
|
+
"snowcone_get_quote",
|
|
1549
|
+
{
|
|
1550
|
+
title: "Get the price, shipping and delivery",
|
|
1551
|
+
description: "Tell the user what a printed product costs and when it would arrive, before they buy. Returns the price the buy link will charge (before tax), and each shipping option with its cost and delivery estimate for where it's going. Takes the same product and options as snowcone_buy_url; no artwork or shop needed. Nothing is created or charged. Only promise what comes back: an option with no estimated_delivery means we have no date for it yet.",
|
|
1552
|
+
inputSchema: {
|
|
1553
|
+
product: z.string().min(1).describe("Product code (the catalog document id), e.g. 'BC43BE'."),
|
|
1554
|
+
options: z.record(z.string()).optional().describe("Variant option picks: attribute \u2192 choice, e.g. { size: 'M', color: 'black' }. The price depends on these."),
|
|
1555
|
+
quantity: z.number().int().min(1).max(100).optional().describe("How many (1 to 100). Default 1."),
|
|
1556
|
+
ship_to: z.string().length(2).optional().describe("2-letter destination country, e.g. 'US'. Default US. A country we can't ship to returns an error listing the ones we can.")
|
|
1557
|
+
},
|
|
1558
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1088
1559
|
},
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
return fail(formatError(err));
|
|
1560
|
+
async (args) => {
|
|
1561
|
+
try {
|
|
1562
|
+
const q = await getQuote({
|
|
1563
|
+
product: args.product,
|
|
1564
|
+
...args.options ? { options: args.options } : {},
|
|
1565
|
+
...args.quantity !== void 0 ? { quantity: args.quantity } : {},
|
|
1566
|
+
...args.ship_to !== void 0 ? { shipTo: args.ship_to } : {}
|
|
1567
|
+
});
|
|
1568
|
+
return ok(
|
|
1569
|
+
{
|
|
1570
|
+
product: q.product,
|
|
1571
|
+
variant_id: q.variantId,
|
|
1572
|
+
variant_label: q.variantLabel,
|
|
1573
|
+
quantity: q.quantity,
|
|
1574
|
+
currency: q.currency,
|
|
1575
|
+
unit_price_cents: q.unitPriceCents,
|
|
1576
|
+
items_total_cents: q.itemsTotalCents,
|
|
1577
|
+
tax_included: q.taxIncluded,
|
|
1578
|
+
ship_to: q.shipTo,
|
|
1579
|
+
shipping: q.shipping.map((s) => ({
|
|
1580
|
+
speed: s.speed,
|
|
1581
|
+
price_cents: s.priceCents,
|
|
1582
|
+
...s.minTransitDays !== void 0 ? { min_transit_days: s.minTransitDays } : {},
|
|
1583
|
+
...s.maxTransitDays !== void 0 ? { max_transit_days: s.maxTransitDays } : {},
|
|
1584
|
+
...s.estimatedDelivery ? { estimated_delivery: s.estimatedDelivery } : {}
|
|
1585
|
+
})),
|
|
1586
|
+
quoted_at: q.quotedAt
|
|
1587
|
+
},
|
|
1588
|
+
quoteText(q)
|
|
1589
|
+
);
|
|
1590
|
+
} catch (err) {
|
|
1591
|
+
return fail(formatError(err));
|
|
1592
|
+
}
|
|
1123
1593
|
}
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1594
|
+
);
|
|
1595
|
+
server2.registerTool(
|
|
1596
|
+
"snowcone_get_order_status",
|
|
1597
|
+
{
|
|
1598
|
+
title: "Find out where an order is",
|
|
1599
|
+
description: "Tell the user where their order is: whether it's being made or on its way, the carrier and tracking number, and the latest scan. Ask them for the order number and the email from their order confirmation. Read-only. If nothing matches, the error doesn't say which of the two was wrong, and repeated tries are limited, so check both with the person before retrying.",
|
|
1600
|
+
inputSchema: {
|
|
1601
|
+
order_number: z.string().min(1).describe("The order number from the confirmation email, e.g. '8532-5134'."),
|
|
1602
|
+
email: z.string().min(3).describe("The email the order was placed with.")
|
|
1603
|
+
},
|
|
1604
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1134
1605
|
},
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
return fail(formatError(err));
|
|
1606
|
+
async (args) => {
|
|
1607
|
+
try {
|
|
1608
|
+
const r = await getOrderStatus({ orderNumber: args.order_number, email: args.email });
|
|
1609
|
+
return ok(
|
|
1610
|
+
{
|
|
1611
|
+
order_number: r.order.order.number,
|
|
1612
|
+
placed_at: r.order.order.placedAt,
|
|
1613
|
+
status: r.order.status,
|
|
1614
|
+
headline: r.order.headline,
|
|
1615
|
+
stages: r.order.stages,
|
|
1616
|
+
packages: r.order.packages,
|
|
1617
|
+
events: r.order.events,
|
|
1618
|
+
items: r.order.items,
|
|
1619
|
+
status_url: r.statusUrl
|
|
1620
|
+
},
|
|
1621
|
+
orderStatusText(r)
|
|
1622
|
+
);
|
|
1623
|
+
} catch (err) {
|
|
1624
|
+
return fail(formatError(err));
|
|
1625
|
+
}
|
|
1156
1626
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1627
|
+
);
|
|
1628
|
+
}
|
|
1629
|
+
var server = createServer();
|
|
1159
1630
|
|
|
1160
1631
|
// src/index.ts
|
|
1161
1632
|
async function main() {
|