@greatstore/cli 0.2.10 → 0.2.11

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 CHANGED
@@ -3,6 +3,11 @@
3
3
  All notable changes to `@greatstore/cli` are recorded here. The format
4
4
  follows [Keep a Changelog](https://keepachangelog.com/).
5
5
 
6
+ ## 0.2.11 — 2026-10-28
7
+
8
+ ### Added
9
+ - `useVoiceCall`, a hook every app receives as a prop. It returns `{ status, available, start, end }`, so an app can start and end a voice call with the store's assistant and show how the call is going. A call started this way doesn't open the chat. The agent guide and new apps from `apps init` describe it.
10
+
6
11
  ## 0.2.10 — 2026-10-21
7
12
 
8
13
  ### Added
package/dist/cli.js CHANGED
@@ -20,7 +20,7 @@ p{color:#2c3a38}`,wr=`<!doctype html>
20
20
  h1{font-size:1.4rem;color:#a40000}code{background:#f4f4f4;padding:.1em .3em;border-radius:.2em}</style></head>
21
21
  <body><h1>Sign-in failed.</h1>
22
22
  <p>Return to your terminal for details.</p></body></html>`,te=class extends Error{constructor(t){super(t),this.name="LoopbackError"}};async function Ee(e){let t=(e.generateState??br)(),n=e.timeoutMs??300*1e3,r=e.openBrowser??(s=>xr(s,e.browserCmdEnv)),o=Pt.createServer();try{await new Promise(c=>o.listen(0,"127.0.0.1",c));let s=o.address(),i=new URL(`${e.dashboardBaseUrl}/cli/authorize`);i.searchParams.set("port",String(s.port)),i.searchParams.set("state",t),e.requestedStore&&i.searchParams.set("store",e.requestedStore);let a=i.toString(),l=Sr(o,t,n);return r(a),await l}finally{o.close()}}function Sr(e,t,n){return new Promise((r,o)=>{let s=!1,i=l=>{s||(s=!0,l())},a=setTimeout(()=>{i(()=>o(new te("Sign-in timed out. Re-run `npx greatstore login`.")))},n);typeof a.unref=="function"&&a.unref(),e.on("request",(l,c)=>{let p=new URL(l.url??"/","http://127.0.0.1");if(p.pathname!==gr){c.writeHead(404,{"content-type":"text/plain"}),c.end("Not found");return}let u=p.searchParams,m=u.get("error"),S=u.get("error_description"),d=u.get("code");if(u.get("state")!==t){c.writeHead(400,{"content-type":"text/html"}),c.end($t),clearTimeout(a),i(()=>o(new te("Sign-in didn't complete. Please try again.")));return}if(m||!d){c.writeHead(400,{"content-type":"text/html"}),c.end($t),clearTimeout(a),i(()=>o(new te(S??"Sign-in failed. Please try again.")));return}c.writeHead(200,{"content-type":"text/html"}),c.end(wr),clearTimeout(a);let Pe=u.get("store")?.trim();i(()=>r(Pe?{token:d,store:Pe}:{token:d}))})})}function br(){return kt.randomBytes(16).toString("hex")}function xr(e,t){let r=t?.trim()??vr();if(r)try{let o;if(r==="start"){let s=`start "" "${e}"`;o=vt("cmd.exe",["/d","/s","/c",s],{stdio:"ignore",detached:!0,windowsVerbatimArguments:!0})}else o=vt(r,[e],{stdio:"ignore",detached:!0});o.on("error",()=>{}),o.unref()}catch{}}function vr(){switch(process.platform){case"darwin":return"open";case"win32":return"start";case"linux":return"xdg-open";default:return null}}import*as T from"fs";import*as ae from"os";import*as Ze from"path";var $r=".greatstore",kr="credentials.json";function Ce(e=ae.homedir()){return Ze.join(e,$r)}function et(e=ae.homedir()){return Ze.join(Ce(e),kr)}function I(e=ae.homedir()){let t=et(e),n;try{let r=T.statSync(t);if(process.platform!=="win32"){let o=r.mode&511;if(o&63)throw new Error(`Refusing to read ${t}: permissions are ${o.toString(8)} (should be 600). Run \`chmod 600 ${t}\`.`)}n=T.readFileSync(t,"utf8")}catch(r){if(Pr(r))return null;throw r}try{let r=JSON.parse(n);return typeof r.access_token!="string"?null:r}catch{return null}}function je(e,t=ae.homedir()){let n=Ce(t);if(T.mkdirSync(n,{recursive:!0,mode:448}),process.platform!=="win32")try{T.chmodSync(n,448)}catch{}let r=et(t);T.writeFileSync(r,`${JSON.stringify(e,null,2)}
23
- `,{mode:384}),process.platform!=="win32"&&T.chmodSync(r,384)}function Et(e=ae.homedir()){T.rmSync(et(e),{force:!0})}function Ct(e){let t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT: expected three dot-separated segments");let n=t[1];if(!n)throw new Error("Invalid JWT: empty payload segment");let o=(n+"=".repeat((4-n.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),s=Buffer.from(o,"base64").toString("utf8");return JSON.parse(s)}function Ae(e,t=Math.floor(Date.now()/1e3)){return e.expires_at<=t}function Pr(e){return typeof e=="object"&&e!==null&&e.code==="ENOENT"}var F="0.2.10";var D=class extends Error{constructor(n,r,o){super(r);this.status=n;this.code=o;this.name="HttpError"}},M=class extends Error{constructor(t="Sign in first. Run `npx greatstore login`."){super(t),this.name="AuthRequiredError"}};function Er(e){let t;try{t=new URL(e)}catch{return}let n=t.pathname.split("/").filter(Boolean);if(n[1]==="admin"&&n[0])return n[0];let r=t.hostname.split(".")[0],o=new Set(["my","www","app","api","admin","localhost"]);if(t.hostname.includes(".")&&r&&!o.has(r))return r}function Cr(e){let t=Er(e)??I()?.store;return t?`npx greatstore login --store ${t}`:"npx greatstore login"}var tt=null;function Rt(e){tt=e}async function f(e,t={}){if(tt!==null)return jt(e,t,tt);let n=()=>`Run \`${Cr(e)}\`.`,r=I();if(!r)throw new M(`Sign in first. ${n()}`);if(Ae(r))throw new M(`Session expired. ${n()}`);try{return await jt(e,t,r.access_token)}catch(o){throw o instanceof D&&o.status===401?new M(`Session expired. ${n()}`):o}}async function jt(e,t,n){let r={accept:"application/json",authorization:`Bearer ${n}`,"x-gs-cli-version":F,...t.headers??{}},o;if(t.multipart&&t.body!==void 0)throw new Error("request(): pass either `body` or `multipart`, not both");t.multipart?(o=t.multipart,delete r["content-type"]):t.body!==void 0&&(o=JSON.stringify(t.body),r["content-type"]="application/json");let s={method:t.method??"GET",headers:r};o!==void 0&&(s.body=o);let i=await fetch(e,s);if(i.status>=200&&i.status<300)return i.status===204?void 0:(i.headers.get("content-type")??"").includes("application/json")?await i.json():await i.text();let a=await i.text(),l={};try{l=JSON.parse(a)}catch{}let c=l.code??l.error,p=t.validationDetail&&i.status===400&&l.error?l.error:jr(i.status,c,l.detail);throw new D(i.status,p,l.code??l.error)}var Tt=`This version of the GreatStore CLI is no longer supported. Run the latest one:
23
+ `,{mode:384}),process.platform!=="win32"&&T.chmodSync(r,384)}function Et(e=ae.homedir()){T.rmSync(et(e),{force:!0})}function Ct(e){let t=e.split(".");if(t.length!==3)throw new Error("Invalid JWT: expected three dot-separated segments");let n=t[1];if(!n)throw new Error("Invalid JWT: empty payload segment");let o=(n+"=".repeat((4-n.length%4)%4)).replace(/-/g,"+").replace(/_/g,"/"),s=Buffer.from(o,"base64").toString("utf8");return JSON.parse(s)}function Ae(e,t=Math.floor(Date.now()/1e3)){return e.expires_at<=t}function Pr(e){return typeof e=="object"&&e!==null&&e.code==="ENOENT"}var F="0.2.11";var D=class extends Error{constructor(n,r,o){super(r);this.status=n;this.code=o;this.name="HttpError"}},M=class extends Error{constructor(t="Sign in first. Run `npx greatstore login`."){super(t),this.name="AuthRequiredError"}};function Er(e){let t;try{t=new URL(e)}catch{return}let n=t.pathname.split("/").filter(Boolean);if(n[1]==="admin"&&n[0])return n[0];let r=t.hostname.split(".")[0],o=new Set(["my","www","app","api","admin","localhost"]);if(t.hostname.includes(".")&&r&&!o.has(r))return r}function Cr(e){let t=Er(e)??I()?.store;return t?`npx greatstore login --store ${t}`:"npx greatstore login"}var tt=null;function Rt(e){tt=e}async function f(e,t={}){if(tt!==null)return jt(e,t,tt);let n=()=>`Run \`${Cr(e)}\`.`,r=I();if(!r)throw new M(`Sign in first. ${n()}`);if(Ae(r))throw new M(`Session expired. ${n()}`);try{return await jt(e,t,r.access_token)}catch(o){throw o instanceof D&&o.status===401?new M(`Session expired. ${n()}`):o}}async function jt(e,t,n){let r={accept:"application/json",authorization:`Bearer ${n}`,"x-gs-cli-version":F,...t.headers??{}},o;if(t.multipart&&t.body!==void 0)throw new Error("request(): pass either `body` or `multipart`, not both");t.multipart?(o=t.multipart,delete r["content-type"]):t.body!==void 0&&(o=JSON.stringify(t.body),r["content-type"]="application/json");let s={method:t.method??"GET",headers:r};o!==void 0&&(s.body=o);let i=await fetch(e,s);if(i.status>=200&&i.status<300)return i.status===204?void 0:(i.headers.get("content-type")??"").includes("application/json")?await i.json():await i.text();let a=await i.text(),l={};try{l=JSON.parse(a)}catch{}let c=l.code??l.error,p=t.validationDetail&&i.status===400&&l.error?l.error:jr(i.status,c,l.detail);throw new D(i.status,p,l.code??l.error)}var Tt=`This version of the GreatStore CLI is no longer supported. Run the latest one:
24
24
 
25
25
  npx greatstore@latest <command>
26
26
 
@@ -37,8 +37,8 @@ or, if you installed it, update it:
37
37
  `),t?1:0}async function Ht(e){if(!I())throw new M;let n=e[0]?.trim();process.stdout.write(`Opening browser to switch stores\u2026
38
38
  `);let{token:r,store:o}=await Ee({dashboardBaseUrl:ne(),...n?{requestedStore:n}:{}}),s=Re(r,o);return je(s),s.store?process.stdout.write(`Now working on store "${s.store}".
39
39
  `):process.stdout.write(`Switched.
40
- `),0}import*as C from"fs";import*as Oe from"os";import*as re from"path";import{fileURLToPath as Tr}from"url";var ue="greatstore",Mt=".version";function Lr(){for(let e of["./gs-skill/","../../gs-skill/"]){let t=re.resolve(Tr(new URL(e,import.meta.url)));if(C.existsSync(re.join(t,"SKILL.md")))return t}throw new Error("internal: this install of the CLI is missing the agent skill files")}function Ut(e=Oe.homedir()){return re.join(Ce(e),"skill",ue)}function st(e,t=Oe.homedir()){let n=Ut(t),r=Or(n);if(r!==null&&Ir(r,e)>=0)return n;let o=`${n}.tmp-${process.pid}`,s=`${n}.old-${process.pid}`;return C.rmSync(o,{recursive:!0,force:!0}),C.cpSync(Lr(),o,{recursive:!0}),C.writeFileSync(re.join(o,Mt),e),C.existsSync(n)&&C.renameSync(n,s),C.renameSync(o,n),C.rmSync(s,{recursive:!0,force:!0}),n}function Gt(e,t=Oe.homedir()){try{C.existsSync(Ut(t))&&st(e,t)}catch{}}function Or(e){try{return C.readFileSync(re.join(e,Mt),"utf8").trim()}catch{return null}}function Ir(e,t){let n=s=>s.split("-")[0].split(".").map(i=>Number(i)||0),[r,o]=[n(e),n(t)];for(let s=0;s<Math.max(r.length,o.length);s++){let i=(r[s]??0)-(o[s]??0);if(i!==0)return i}return 0}function qt(){process.stdout.write(Fr(st(F)))}function Fr(e){return["GreatStore agent skill \u2014 installation instructions for an AI coding agent.","","Skill source on this machine:",` ${e}`,"",`Symlink that folder into your skills directory as "${ue}":`,""," mkdir -p <SKILLS_DIR>",` ln -sfn "${e}" "<SKILLS_DIR>/${ue}"`,"","Symlink it, do not copy it: the CLI refreshes that folder whenever a","newer version runs, and the link picks it up with nothing to re-run.","","<SKILLS_DIR> is wherever you load skills from \u2014 for Claude Code that","is ~/.claude/skills for every project, or ./.claude/skills for this","one. Use your own location if it differs, and create it if missing.",`Then read <SKILLS_DIR>/${ue}/SKILL.md to confirm the install.`,"",`On Windows: mklink /D "<SKILLS_DIR>\\${ue}" "${e}"`,""].join(`
41
- `)}var Y={mode:{kind:"string",values:["auto","light","dark","custom"],help:"Color scheme. `auto` follows the shopper's system preference.",brandVisible:!0},radius:{kind:"string",values:["sharp","default","rounded"],help:"Corner rounding preset applied to every surface.",brandVisible:!0},fontFamily:{kind:"string",help:"Primary font family name.",brandVisible:!0},secondaryFontFamily:{kind:"string",help:"Font family for the agent's chat bubbles.",brandVisible:!0},mobileBottomBarOffset:{kind:"integer",help:"Pixels the mobile bottom bar floats above the screen edge while the chat is closed.",brandVisible:!0},hiddenUntilOpenedMobile:{kind:"boolean",help:"Keep the chat off the page on mobile until your site opens it.",brandVisible:!0},hiddenUntilOpenedDesktop:{kind:"boolean",help:"Keep the chat off the page on desktop until your site opens it.",brandVisible:!0},zIndex:{kind:"integer",help:"Stacking order of the chat panel on the host page."},brandColor:{kind:"color",help:"Accent color.",brandVisible:!0},surfaceColor:{kind:"color",help:"Background color.",brandVisible:!0},textColor:{kind:"color",help:"Text color.",brandVisible:!0},surface:{kind:"color",help:"Panel background."},surfaceSecondary:{kind:"color",help:"Secondary background."},surfaceAccent:{kind:"color",help:"Accented background."},surfaceHover:{kind:"color",help:"Hovered background."},foreground:{kind:"color",help:"Body text."},foregroundSecondary:{kind:"color",help:"Secondary text."},foregroundMuted:{kind:"color",help:"Muted text."},foregroundAccent:{kind:"color",help:"Accented text."},border:{kind:"color",help:"Border color."},borderFocus:{kind:"color",help:"Focus-ring color."},primary:{kind:"color",help:"Primary button background."},primaryForeground:{kind:"color",help:"Primary button text."},primaryHover:{kind:"color",help:"Primary button hover."},primaryMuted:{kind:"color",help:"Muted primary background."},primaryMutedForeground:{kind:"color",help:"Muted primary text."},primaryTint:{kind:"color",help:"Primary tint wash."},link:{kind:"color",help:"Link color."}};function Vt(e){let t=e.toLowerCase();return Object.keys(Y).map(n=>{let r=n.toLowerCase();return{name:n,distance:Br(t,r),prefix:Nr(t,r)}}).filter(({name:n,distance:r,prefix:o})=>r<=Math.max(2,n.length/3)||o>=4).sort((n,r)=>r.prefix-n.prefix||n.distance-r.distance).slice(0,3).map(({name:n})=>n)}function Nr(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function Br(e,t){let n=Array.from({length:t.length+1},(r,o)=>o);for(let r=1;r<=e.length;r++){let o=[r];for(let s=1;s<=t.length;s++)o[s]=Math.min((n[s]??0)+1,(o[s-1]??0)+1,(n[s-1]??0)+(e[r-1]===t[s-1]?0:1));n=o}return n[t.length]??0}var Dr=`npx greatstore configure \u2014 view and edit a store's configuration.
40
+ `),0}import*as C from"fs";import*as Oe from"os";import*as re from"path";import{fileURLToPath as Tr}from"url";var ue="greatstore",Mt=".version";function Lr(){for(let e of["./gs-skill/","../../gs-skill/"]){let t=re.resolve(Tr(new URL(e,import.meta.url)));if(C.existsSync(re.join(t,"SKILL.md")))return t}throw new Error("internal: this install of the CLI is missing the agent skill files")}function Ut(e=Oe.homedir()){return re.join(Ce(e),"skill",ue)}function st(e,t=Oe.homedir()){let n=Ut(t),r=Or(n);if(r!==null&&Ir(r,e)>=0)return n;let o=`${n}.tmp-${process.pid}`,s=`${n}.old-${process.pid}`;return C.rmSync(o,{recursive:!0,force:!0}),C.cpSync(Lr(),o,{recursive:!0}),C.writeFileSync(re.join(o,Mt),e),C.existsSync(n)&&C.renameSync(n,s),C.renameSync(o,n),C.rmSync(s,{recursive:!0,force:!0}),n}function Gt(e,t=Oe.homedir()){try{C.existsSync(Ut(t))&&st(e,t)}catch{}}function Or(e){try{return C.readFileSync(re.join(e,Mt),"utf8").trim()}catch{return null}}function Ir(e,t){let n=s=>s.split("-")[0].split(".").map(i=>Number(i)||0),[r,o]=[n(e),n(t)];for(let s=0;s<Math.max(r.length,o.length);s++){let i=(r[s]??0)-(o[s]??0);if(i!==0)return i}return 0}function Vt(){process.stdout.write(Fr(st(F)))}function Fr(e){return["GreatStore agent skill \u2014 installation instructions for an AI coding agent.","","Skill source on this machine:",` ${e}`,"",`Symlink that folder into your skills directory as "${ue}":`,""," mkdir -p <SKILLS_DIR>",` ln -sfn "${e}" "<SKILLS_DIR>/${ue}"`,"","Symlink it, do not copy it: the CLI refreshes that folder whenever a","newer version runs, and the link picks it up with nothing to re-run.","","<SKILLS_DIR> is wherever you load skills from \u2014 for Claude Code that","is ~/.claude/skills for every project, or ./.claude/skills for this","one. Use your own location if it differs, and create it if missing.",`Then read <SKILLS_DIR>/${ue}/SKILL.md to confirm the install.`,"",`On Windows: mklink /D "<SKILLS_DIR>\\${ue}" "${e}"`,""].join(`
41
+ `)}var Y={mode:{kind:"string",values:["auto","light","dark","custom"],help:"Color scheme. `auto` follows the shopper's system preference.",brandVisible:!0},radius:{kind:"string",values:["sharp","default","rounded"],help:"Corner rounding preset applied to every surface.",brandVisible:!0},fontFamily:{kind:"string",help:"Primary font family name.",brandVisible:!0},secondaryFontFamily:{kind:"string",help:"Font family for the agent's chat bubbles.",brandVisible:!0},mobileBottomBarOffset:{kind:"integer",help:"Pixels the mobile bottom bar floats above the screen edge while the chat is closed.",brandVisible:!0},hiddenUntilOpenedMobile:{kind:"boolean",help:"Keep the chat off the page on mobile until your site opens it.",brandVisible:!0},hiddenUntilOpenedDesktop:{kind:"boolean",help:"Keep the chat off the page on desktop until your site opens it.",brandVisible:!0},zIndex:{kind:"integer",help:"Stacking order of the chat panel on the host page."},brandColor:{kind:"color",help:"Accent color.",brandVisible:!0},surfaceColor:{kind:"color",help:"Background color.",brandVisible:!0},textColor:{kind:"color",help:"Text color.",brandVisible:!0},surface:{kind:"color",help:"Panel background."},surfaceSecondary:{kind:"color",help:"Secondary background."},surfaceAccent:{kind:"color",help:"Accented background."},surfaceHover:{kind:"color",help:"Hovered background."},foreground:{kind:"color",help:"Body text."},foregroundSecondary:{kind:"color",help:"Secondary text."},foregroundMuted:{kind:"color",help:"Muted text."},foregroundAccent:{kind:"color",help:"Accented text."},border:{kind:"color",help:"Border color."},borderFocus:{kind:"color",help:"Focus-ring color."},primary:{kind:"color",help:"Primary button background."},primaryForeground:{kind:"color",help:"Primary button text."},primaryHover:{kind:"color",help:"Primary button hover."},primaryMuted:{kind:"color",help:"Muted primary background."},primaryMutedForeground:{kind:"color",help:"Muted primary text."},primaryTint:{kind:"color",help:"Primary tint wash."},link:{kind:"color",help:"Link color."}};function qt(e){let t=e.toLowerCase();return Object.keys(Y).map(n=>{let r=n.toLowerCase();return{name:n,distance:Br(t,r),prefix:Nr(t,r)}}).filter(({name:n,distance:r,prefix:o})=>r<=Math.max(2,n.length/3)||o>=4).sort((n,r)=>r.prefix-n.prefix||n.distance-r.distance).slice(0,3).map(({name:n})=>n)}function Nr(e,t){let n=0;for(;n<e.length&&n<t.length&&e[n]===t[n];)n++;return n}function Br(e,t){let n=Array.from({length:t.length+1},(r,o)=>o);for(let r=1;r<=e.length;r++){let o=[r];for(let s=1;s<=t.length;s++)o[s]=Math.min((n[s]??0)+1,(o[s-1]??0)+1,(n[s-1]??0)+(e[r-1]===t[s-1]?0:1));n=o}return n[t.length]??0}var Dr=`npx greatstore configure \u2014 view and edit a store's configuration.
42
42
 
43
43
  Usage:
44
44
  npx greatstore configure Show the current configuration.
@@ -81,10 +81,10 @@ Examples:
81
81
  npx greatstore configure set --theme.fontFamily Manrope --theme.radius sharp
82
82
  npx greatstore configure set --theme.brandColor "#1e1d66"
83
83
  npx greatstore configure set --theme '{"mode":"dark"}' --replace
84
- `}function Kt(e){if(e===void 0||e==="show")return Dr;if(e==="set")return Ur()}import*as y from"fs";import*as j from"path";import{readdirSync as Ss,readFileSync as bs}from"fs";import{fileURLToPath as vs}from"url";var Ie=null;function Wt(){return Ie||(Ie=JSON.parse('{"component/component.tsx":"import React from \\"react\\";\\nimport \\"./style.css\\";\\n\\n// Add your tool args (matching manifest.json#inputSchema.properties)\\n// alongside the GreatStore-injected lifecycle props. See AGENTS.md for\\n// what each lifecycle prop does.\\ninterface Props {\\n onSendMessage: (text: string) => void;\\n onUpdateModelContext: (context: string) => void;\\n onShowLightbox: (options: { src: string; originRect?: DOMRect }) => void;\\n onClose: () => void;\\n // Ask the store\'s assistant for content matching a JSON Schema (or Zod\\n // schema) \u2014 the app\'s own catalog-grounded generation, for recommended\\n // picks or a personalized summary. Resolves to the generated object.\\n // `fallback` is a required, schema-shaped stand-in rendered in the app\\n // preview (and validated against the schema). See AGENTS.md.\\n onGenerateStructuredContent: <T = unknown>(\\n schema: object,\\n prompt: string,\\n fallback: T,\\n ) => Promise<T>;\\n // Drop-in for <img>: `<Image src=\u2026 alt=\u2026 />`. See AGENTS.md.\\n Image: React.ElementType<React.ComponentProps<\\"img\\">>;\\n}\\n\\n// See AGENTS.md for how an app runs (the assistant picks it by the\\n// manifest\'s name and description, then calls it with these props), the\\n// design rules (style.css, em-based sizing, brand CSS variables), and how to\\n// write an async, backend-backed app.\\nexport default function Component(_props: Props): React.ReactElement {\\n return (\\n <div className=\\"app\\">\\n <strong>__GS_NAME__</strong> \u2014 hello from your app!\\n </div>\\n );\\n}\\n","component/manifest.json":"{\\n \\"name\\": \\"__GS_NAME__\\",\\n \\"displayName\\": \\"__GS_DISPLAY_NAME__\\",\\n \\"description\\": \\"Use when <the shopper situation that should make the assistant open this app \u2014 say when to reach for it and what it reports back, never what it looks like; see AGENTS.md>.\\",\\n \\"displayMode\\": \\"inline\\",\\n \\"async\\": false,\\n \\"inputSchema\\": {\\n \\"type\\": \\"object\\",\\n \\"properties\\": {}\\n }\\n}\\n","component/style.css":"/*\\n * Your app\'s styles. Plain CSS, applied inside the app alone: nothing here\\n * reaches the store\'s page, and nothing on the page reaches in.\\n *\\n * Style with the store\'s theme variables rather than fixed values \u2014 write\\n * `color: var(--color-foreground)`, never `color: #111827`. Each store sets\\n * its colours, fonts and corner style (and dark mode) in its GreatStore\\n * dashboard; an app built on these variables follows those settings, and\\n * changes with them.\\n *\\n * Fonts: --font-primary, --font-secondary\\n * Surfaces: --color-surface, --color-surface-secondary, --color-surface-accent,\\n * --color-surface-hover\\n * Text: --color-foreground, --color-foreground-secondary,\\n * --color-foreground-muted, --color-foreground-accent\\n * Borders: --color-border-default, --color-border-focus\\n * Brand: --color-primary, --color-primary-foreground, --color-primary-hover,\\n * --color-primary-muted, --color-primary-muted-foreground,\\n * --color-primary-tint, --color-link\\n * Status: --color-error, --color-error-surface, --color-error-border,\\n * --color-success\\n * Corners: --radius-xs, --radius-sm, --radius-md, --radius-lg, --radius-xl,\\n * --radius-2xl, --radius-3xl, --radius-4xl, --radius-pill\\n */\\n\\n/* Size in em, never rem: an app sits inside other people\'s pages. */\\n.app {\\n padding: 1em;\\n border: 1px solid var(--color-border-default);\\n border-radius: var(--radius-lg);\\n background: var(--color-surface);\\n color: var(--color-foreground);\\n font-family: var(--font-primary);\\n}\\n","root/.gitignore":"node_modules/\\ncomponents/*/bundle.js\\ncomponents/*/bundle.css\\ncomponents/*/.gssync.json\\n*.tsbuildinfo\\n.DS_Store\\n","root/.gsrc":"{\\n \\"store\\": \\"__GS_STORE__\\"\\n}\\n","root/AGENTS.md":"# AGENTS.md\\n\\n> **Do not edit \u2014 auto-generated by the GreatStore CLI v__GS_VERSION__.**\\n> This file is rewritten by `npx greatstore apps init`, so any changes you make here\\n> will be overwritten. If this version trails your installed CLI, re-run\\n> `npx greatstore apps init` to refresh it. Put project-specific notes in another file.\\n\\nGuidance for AI coding agents working on the apps in this project.\\n`CLAUDE.md` and `GEMINI.md` are symlinks to this file.\\n\\nAn app is interactive UI the store\'s assistant renders inside the\\nconversation \u2014 a configurator, a quiz, a size guide, a booking form. You\\nwrite it in React; each app is one folder under `components/`, holding\\n`manifest.json` and `component.tsx`.\\n\\nApps render inside arbitrary publisher websites (the embed widget mounts\\non a host page) as well as the GreatStore storefront. You control neither\\nthe host page\'s base font size nor its color scheme, and the store owner\\ncontrols the look from GreatStore theme settings. The rules below keep\\napps portable across both.\\n\\n## How an app runs\\n\\nAn app is not a page the shopper navigates to. It is a tool the assistant\\ncalls mid-conversation, and once it is on screen it can talk back \u2014 which\\nis the part that makes apps worth building.\\n\\n```\\nShopper Assistant Your app\\n \u2502 \u2502 \u2502\\n \u2502 \\"what size am I?\\" \u2502 \u2502\\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\u2502 \u2502\\n \u2502 \u2502 picks the app by its \u2502\\n \u2502 \u2502 name + description \u2502\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 calls it with props \u2502\\n \u2502 \u2502 your inputSchema asked \u2502\\n \u2502 \u2502 for (productName, \u2026) \u2502\\n \u2502 \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\u2502\\n \u2502 \u2502 \u251C\u2500\u2500\u2510 onGenerateStructured-\\n \u2502 \u2502 \u2502 \u2502 Content(): its own\\n \u2502 \u2502 \u2502 \u2502 catalog-grounded\\n \u2502 \u2502 \u2502<\u2500\u2518 generation, if wanted\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 \u2502 renders the moment your\\n \u2502 \u2502 \u2502 happy path has what it\\n \u2502 \u2502 \u2502 needs (async: after your\\n \u2502<\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524 promise resolves)\\n \u2502 sees the app \u2502 \u2502\\n \u2502 \u2502 \u2502\\n \u2502 picks size M \u2502 \u2502\\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\u2502\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 onUpdateModelContext() \u2502 silent: the assistant\\n \u2502 \u2502<\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524 now knows the pick\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 onSendMessage() \u2502 visible: a shopper turn\\n \u2502 \u2502<\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524 happens right now\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 calls the app again \u2502 same app, new props \u2014\\n \u2502 \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\u2502 re-rendered in place\\n \u2502 \u2502 \u2502\\n```\\n\\nFour consequences worth designing around:\\n\\n1. **The assistant chooses the app, so `manifest.json` is the interface it\\n sees** \u2014 see the next section.\\n2. **Control is bidirectional once the app is up.** The app reports what\\n the shopper is doing (`onUpdateModelContext`), can speak for the\\n shopper (`onSendMessage`), and the assistant can call the app again\\n with revised props. Keep the render a function of the props it was\\n given, so a re-call is a re-render rather than a reset.\\n3. **The app can run its own generation, not just receive props.**\\n `onGenerateStructuredContent` returns a catalog-grounded,\\n shopper-personalized object matching your schema \u2014 recommended picks, a\\n personalized summary, a reason per option \u2014 which you render in your\\n own markup.\\n4. **Render on the happy path, not on a shell.** Whatever the app needs to\\n be correct \u2014 props, or awaited data in an async app \u2014 should be there\\n before anything paints; GreatStore owns the loading state.\\n\\n## `manifest.json` \u2014 the name and description decide whether your app runs\\n\\nThe assistant never sees your app. It sees a name and a sentence, next to\\nevery other tool it has, and picks one. Write the description for that\\n*caller*, answering one question: when should I reach for this, and what\\ndo I get back?\\n\\n**Describing the UI is the most common mistake.** Layout, sliders, tabs,\\ncarousels and colors are the shopper\'s concern. To the assistant they are\\nnoise \u2014 they say nothing about when to call the tool.\\n\\n| Don\'t | Do |\\n| --- | --- |\\n| \\"Renders a two-column table of measurements with a unit toggle.\\" | \\"Use when a shopper is unsure which size to buy or asks how an item fits.\\" |\\n| \\"A carousel of product cards with images and prices.\\" | \\"Use to show 2\u20138 specific products you have already chosen, when the shopper wants to see them side by side before deciding.\\" |\\n| \\"Modal with a multi-step form and a progress bar.\\" | \\"Use when the shopper wants a gift but can\'t say what \u2014 collects budget, recipient and occasion, then reports them back so you can recommend.\\" |\\n\\nWhat belongs in a description, in this order:\\n\\n1. **The trigger** \u2014 the shopper situation or intent, in the words a\\n shopper would actually use. Start with `Use when \u2026`.\\n2. **The boundary** \u2014 when *not* to, if another tool overlaps. One clause\\n is enough: \\"Use for in-store appointments; not for delivery scheduling.\\"\\n3. **What the assistant gets back** \u2014 if the app reports state or sends\\n messages, say so: \\"reports the size the shopper settles on back to you.\\"\\n\\nOne or two sentences. If a required `inputSchema` field is subtle, say\\nwhat it means here rather than trusting the schema alone.\\n\\nThe same rule governs the **name** (snake_case, matching the folder under\\n`components/`): name it after the job, not the widget. `size_guide`,\\n`gift_finder`, `book_appointment` read as intents; `size_modal`,\\n`quiz_ui`, `product_grid_v2` read as implementation details and get\\nskipped. `displayName` is the one field written for the shopper.\\n\\nKeep `inputSchema` tight: required fields the assistant can\'t infer from\\nthe conversation cause bad calls.\\n\\n## Design requirements\\n\\n### Style in `style.css`\\n\\nEach app\'s styles live in `components/<name>/style.css`, imported once at\\nthe top of `component.tsx`:\\n\\n```tsx\\nimport \\"./style.css\\";\\n```\\n\\nWrite ordinary CSS there and use `className` in the component. The sheet\\napplies to your app alone \u2014 it can\'t affect the store\'s page, and the page\\ncan\'t affect your app \u2014 so short class names like `.card` are safe.\\nInline `style={{\u2026}}` still works for values computed at render time.\\n\\nThe rules for `style.css`:\\n\\n- Import only `./style.css`, and only from `component.tsx`. Every other CSS\\n import fails the build.\\n- Keep it self-contained: no `@import`, and `url()` only with `https:` or\\n `data:` URLs \u2014 nothing beside the sheet is uploaded with it.\\n- At most 256 KB.\\n\\n`npx greatstore apps build` minifies the sheet into `bundle.css` beside\\n`bundle.js`; shoppers get that, so comments in `style.css` are for you and\\nnever reach them. Like `bundle.js`, `bundle.css` is generated \u2014 edit\\n`style.css` and build again.\\n\\nThe comment at the top of the scaffolded `style.css` lists the theme\\nvariables below. Style with them rather than fixed values: each store sets\\nits colours, fonts and corner style in its GreatStore dashboard, and an app\\nbuilt on the variables follows those settings.\\n\\n### Never use `rem` for fonts and sizing \u2014 always use `em`\\n\\n`rem` resolves against the host page\'s root font size, which is\\narbitrary and outside our control. A host that sets `html { font-size:\\n8px }` (or 200%) will shrink or blow up every `rem`-based dimension.\\n`em` resolves against the app\'s own font size, so it stays\\nself-consistent wherever the app is mounted.\\n\\nUse `em` for font sizes, padding, margins, gaps, widths, heights,\\nand any other length. Borders may stay in `px` (hairlines should not\\nscale with text).\\n\\n```css\\n/* Bad \u2014 breaks on hosts with a non-default root font size */\\n.card { padding: 1rem; font-size: 0.875rem; }\\n\\n/* Good */\\n.card { padding: 1em; font-size: 0.875em; }\\n```\\n\\n### Fullscreen apps must leave a safe-zone at the bottom\\n\\nOn the storefront the chat widget floats over the bottom of the screen, so\\nanything a `fullscreen` app renders there can be covered by it. Reserve a\\nsafe-zone of `6.25em` (100px at the default font size) at the bottom of the\\napp\'s scrolling content \u2014 e.g. `padding-bottom: 6.25em` on the scroll\\ncontainer \u2014 so the last row, button, or link can always be scrolled clear of\\nthe widget. Inline and over-input apps don\'t need it.\\n\\n### Don\'t hardcode colors, fonts, or corner radius \u2014 use GreatStore brand variables\\n\\nThe store owner themes the assistant from GreatStore settings. Hardcoded\\nvalues ignore that and make the app clash with the rest of the store.\\nRead from the CSS variables GreatStore injects on the surface instead, so\\nthe app restyles itself when the theme changes.\\n\\nAvailable variables:\\n\\n| Purpose | Variable |\\n| --- | --- |\\n| Surface background | `--color-surface` |\\n| Secondary surface | `--color-surface-secondary` |\\n| Accent surface | `--color-surface-accent` |\\n| Hover surface | `--color-surface-hover` |\\n| Foreground text | `--color-foreground` |\\n| Secondary text | `--color-foreground-secondary` |\\n| Muted text | `--color-foreground-muted` |\\n| Accent text | `--color-foreground-accent` |\\n| Border | `--color-border-default` |\\n| Focus border | `--color-border-focus` |\\n| Primary / brand | `--color-primary` |\\n| Text on primary | `--color-primary-foreground` |\\n| Primary hover | `--color-primary-hover` |\\n| Primary muted | `--color-primary-muted` |\\n| Text on primary muted | `--color-primary-muted-foreground` |\\n| Primary tint | `--color-primary-tint` |\\n| Link | `--color-link` |\\n| Font family | `--font-primary` |\\n| Secondary font family | `--font-secondary` |\\n| Corner radius (scale) | `--radius-xs` \u2026 `--radius-4xl`, `--radius-pill` |\\n\\nThe store owner can set a secondary font family in their GreatStore\\ntheme settings, exposed as `--font-secondary` (it falls back to\\n`--font-primary` when unset). Reach for it to add a tasteful second\\nlayer of typography \u2014 pair `--font-primary` for body copy with\\n`--font-secondary` for headings, prices, or other accents \u2014 so the app\\nreflects the store\'s full type system instead of a single face.\\n\\n```css\\n/* Bad \u2014 hardcoded, ignores the store\'s theme */\\n.buy { background: #4f46e5; border-radius: 8px; font-family: Inter; }\\n\\n/* Good */\\n.buy {\\n background: var(--color-primary);\\n color: var(--color-primary-foreground);\\n border-radius: var(--radius-lg);\\n font-family: var(--font-primary);\\n}\\n```\\n\\nProvide a sensible fallback only when a value might be absent, e.g.\\n`var(--color-primary, currentColor)`.\\n\\n## App props\\n\\nEach app receives its tool args (the fields you declare in\\n`manifest.json#inputSchema.properties`) plus these GreatStore-injected\\nlifecycle props, which are always present:\\n\\n| Prop | What it does |\\n| --- | --- |\\n| `onSendMessage(text)` | Send text into the chat as if the shopper typed it. |\\n| `onUpdateModelContext(context)` | Inject invisible background context for the model (selected variant, configured options, current step). Replaces the prior value \u2014 never appends; pass `\\"\\"` to clear. Read on the next chat turn. Use it when the assistant should *know* in-app state without a visible message; use `onSendMessage` when you want a turn to happen now. |\\n| `onShowLightbox({ src, originRect? })` | Expand an image in the chat\'s shared full-screen lightbox \u2014 an on-brand zoom overlay your app can\'t render itself (it\'s boxed inside its own bounds and shadow root). Pass the image `src`; for a smooth zoom, also pass the clicked element\'s `getBoundingClientRect()` as `originRect` (omit it and the image grows from the viewport centre). |\\n| `onGenerateStructuredContent(schema, prompt, fallback)` | Ask the store\'s assistant for content matching a JSON Schema (or a Zod schema); resolves to the generated object. Personalized to the shopper. Works the same in the conversation on the storefront and every embed. Best inside an async app that builds its render from the generated payload \u2014 `await` it, then return the JSX. `fallback` is **required**: a schema-shaped object you supply that the app preview renders (so a generation-driven app previews without a live store). It\'s validated against the schema and throws if the two don\'t line up. |\\n| `onClose()` | Dismiss the host slot. Over-input clears the overlay, fullscreen reverts the pane, inline is a no-op. |\\n| `Image` | A drop-in for `<img>`: render `<Image src=\u2026 alt=\u2026 />` instead of `<img>` and your images are automatically served at the right size for the store. Takes the same props as `<img>` (`src`, `alt`, `style`, `loading`, `onClick`, \u2026). Previewing the app outside the store? Pass `Image={\\"img\\"}` (or your own component) to render a plain image. |\\n\\n## Async apps (backend-backed, render-blocking data)\\n\\nIf an app must load data from a backend/API before it can render\\ncorrectly, make it async \u2014 don\'t render an empty shell and fetch in a\\n`useEffect`. Set `\\"async\\": true` in `manifest.json` and export an async\\ndefault. GreatStore waits for your promise (showing a normal loading\\nstate, so you don\'t render your own placeholder), then renders what it\\nresolves to. Apps that render purely from their props stay synchronous.\\n\\nA thrown error is a **retry signal**: the in-store AI sees it and\\nusually re-calls the tool. So only throw when a *different* call could\\nhelp:\\n\\n1. `await` the backend call, then return the finished JSX.\\n2. Validate the AI-passed props first and throw on bad input \u2014 the AI\\n can fix the args and retry. (Don\'t validate the API\'s *output* and\\n throw: the AI can\'t fix the backend, it\'ll just loop.)\\n3. Broadcast a backend failure ONLY when retrying differently could\\n succeed, and say what to change (e.g. empty search \u2192 \\"try a broader\\n keyword\\"). For idempotent failures (500, timeout, missing record)\\n re-running the same call changes nothing \u2014 render a graceful fallback\\n instead of throwing.\\n\\n```tsx\\nexport default async function Example(props: Props) {\\n if (!props.query?.trim()) throw new Error(\\"missing required prop: query\\");\\n const res = await fetch(`/api/search?q=${encodeURIComponent(props.query)}`);\\n if (res.ok) {\\n const { results } = await res.json();\\n if (results.length === 0)\\n throw new Error(`no results for \\"${props.query}\\" \u2014 try a broader keyword`);\\n return <ul>{/* render results */}</ul>;\\n }\\n return <p>Couldn\'t load results right now.</p>; // idempotent: don\'t throw\\n}\\n```\\n","root/README.md":"# GreatStore apps\\n\\nCustom in-chat apps published to your GreatStore tenant. Each app is a\\nReact component living in its own folder under `components/`.\\n\\n```\\nnpm install\\nnpx greatstore apps init <app_name> # add a new app\\nnpx greatstore apps build # builds every components/<name>/bundle.js\\nnpx greatstore apps push # uploads every changed app as a draft\\nnpx greatstore apps publish <app_name> # promote a specific app to live\\n```\\n\\n- `npx greatstore apps push` (no args) hashes each app and only uploads the ones that\\n have changed since the last sync.\\n- `npx greatstore apps pull` (no args) refreshes every live app into\\n `components/<name>/`. Apps with unsaved local edits are skipped with a\\n warning; pass `--force` to overwrite.\\n\\nSee `AGENTS.md` for how an app runs, how to write a manifest name and\\ndescription the assistant will actually pick, and the design rules every\\napp must follow (em-based sizing, brand CSS variables) \u2014 it doubles as\\nguidance for AI coding agents (`CLAUDE.md` / `GEMINI.md` symlink to it).\\n","root/package.json":"{\\n \\"name\\": \\"greatstore-components\\",\\n \\"version\\": \\"0.0.1\\",\\n \\"private\\": true,\\n \\"type\\": \\"module\\",\\n \\"scripts\\": {\\n \\"build\\": \\"npx greatstore apps build\\",\\n \\"push\\": \\"npx greatstore apps build && npx greatstore apps push\\"\\n },\\n \\"dependencies\\": {\\n \\"react\\": \\"^19.0.0\\",\\n \\"react-dom\\": \\"^19.0.0\\"\\n },\\n \\"devDependencies\\": {\\n \\"@types/react\\": \\"^19.0.0\\",\\n \\"@types/react-dom\\": \\"^19.0.0\\",\\n \\"@vitejs/plugin-react\\": \\"^4.3.0\\",\\n \\"typescript\\": \\"^5.6.0\\",\\n \\"vite\\": \\"^5.4.0\\"\\n }\\n}\\n","root/tsconfig.json":"{\\n \\"compilerOptions\\": {\\n \\"target\\": \\"ES2022\\",\\n \\"module\\": \\"ESNext\\",\\n \\"moduleResolution\\": \\"Bundler\\",\\n \\"jsx\\": \\"react-jsx\\",\\n \\"lib\\": [\\"ES2022\\", \\"DOM\\"],\\n \\"strict\\": true,\\n \\"esModuleInterop\\": true,\\n \\"skipLibCheck\\": true,\\n \\"isolatedModules\\": true,\\n \\"noEmit\\": true\\n },\\n \\"include\\": [\\"components/**/component.tsx\\", \\"vite.config.ts\\"]\\n}\\n","root/vite.config.ts":"import { defineConfig } from \\"vite\\";\\nimport react from \\"@vitejs/plugin-react\\";\\n\\n// Real builds happen in `npx greatstore build` (one Vite invocation per\\n// component, externals + runtime shim paths owned by the CLI). This\\n// file exists only so editors / language servers can resolve the\\n// React plugin when inspecting components/*/component.tsx.\\nexport default defineConfig({\\n plugins: [react()],\\n});\\n"}'),Ie)}var Jt={name:"__GS_NAME__",displayName:"__GS_DISPLAY_NAME__",store:"__GS_STORE__",version:"__GS_VERSION__"};function Yt(e,t){let n=e;for(let o of Object.keys(Jt)){let s=t[o];s!==void 0&&(n=n.split(Jt[o]).join(s))}let r=n.match(/__GS_[A-Z_]+__/);if(r)throw new Error(`internal: template placeholder ${r[0]} was not provided`);return n}var zt=/^[a-z][a-z0-9_]*$/;function Qt(e){let t=e.positional[0];if(t!==void 0&&!zt.test(t))throw new Error(`Invalid component name: "${t}" (must match ${zt}).`);let n=g(e.flags,"force"),r=b(e.flags,"store"),o=b(e.flags,"out")??".",s=j.resolve(o),i=Gr(s),a;if(i){if(r!==void 0)throw new Error(`Project at ${s} is already pinned to a store via .gsrc. Drop --store; a project folder ships to exactly one store.`);P({cwd:s})}else if(a=r!==void 0?le(r):xe()??void 0,a===void 0){let u=t?`npx greatstore apps init ${t} --store <slug>`:"npx greatstore apps init --store <slug>";throw new Error(`--store <slug> is required when scaffolding a new project root. Run \`${u}\`.`)}let l=qr(s,i,n,{store:a});if(!t){let u=[];i?(u.push(`Updated GreatStore project root in ${s}.`),l.length>0?u.push("",`Added: ${l.join(", ")}`):u.push("","Already up to date \u2014 nothing to add.")):u.push(`Scaffolded GreatStore project root in ${s}.`),u.push("","Next steps:",` cd ${j.relative(process.cwd(),s)||"."}`," npm install"," npx greatstore apps init <component_name> # add your first component",""),process.stdout.write(u.join(`
84
+ `}function Kt(e){if(e===void 0||e==="show")return Dr;if(e==="set")return Ur()}import*as y from"fs";import*as j from"path";import{readdirSync as Ss,readFileSync as bs}from"fs";import{fileURLToPath as vs}from"url";var Ie=null;function Wt(){return Ie||(Ie=JSON.parse('{"component/component.tsx":"import React from \\"react\\";\\nimport \\"./style.css\\";\\n\\n// Add your tool args (matching manifest.json#inputSchema.properties)\\n// alongside the GreatStore-injected lifecycle props. See AGENTS.md for\\n// what each lifecycle prop does.\\ninterface Props {\\n onSendMessage: (text: string) => void;\\n onUpdateModelContext: (context: string) => void;\\n onShowLightbox: (options: { src: string; originRect?: DOMRect }) => void;\\n onClose: () => void;\\n // Ask the store\'s assistant for content matching a JSON Schema (or Zod\\n // schema) \u2014 the app\'s own catalog-grounded generation, for recommended\\n // picks or a personalized summary. Resolves to the generated object.\\n // `fallback` is a required, schema-shaped stand-in rendered in the app\\n // preview (and validated against the schema). See AGENTS.md.\\n onGenerateStructuredContent: <T = unknown>(\\n schema: object,\\n prompt: string,\\n fallback: T,\\n ) => Promise<T>;\\n // Drop-in for <img>: `<Image src=\u2026 alt=\u2026 />`. See AGENTS.md.\\n Image: React.ElementType<React.ComponentProps<\\"img\\">>;\\n // A hook for a voice call with the store\'s assistant: call it at the top of\\n // the component. See AGENTS.md.\\n useVoiceCall: () => {\\n status:\\n | \\"started\\"\\n | \\"connecting\\"\\n | \\"connected\\"\\n | \\"speaking\\"\\n | \\"listening\\"\\n | \\"working\\"\\n | \\"disconnected\\"\\n | \\"ended\\"\\n | null;\\n available: boolean;\\n start: () => Promise<void>;\\n end: () => void;\\n };\\n}\\n\\n// See AGENTS.md for how an app runs (the assistant picks it by the\\n// manifest\'s name and description, then calls it with these props), the\\n// design rules (style.css, em-based sizing, brand CSS variables), and how to\\n// write an async, backend-backed app.\\nexport default function Component(_props: Props): React.ReactElement {\\n return (\\n <div className=\\"app\\">\\n <strong>__GS_NAME__</strong> \u2014 hello from your app!\\n </div>\\n );\\n}\\n","component/manifest.json":"{\\n \\"name\\": \\"__GS_NAME__\\",\\n \\"displayName\\": \\"__GS_DISPLAY_NAME__\\",\\n \\"description\\": \\"Use when <the shopper situation that should make the assistant open this app \u2014 say when to reach for it and what it reports back, never what it looks like; see AGENTS.md>.\\",\\n \\"displayMode\\": \\"inline\\",\\n \\"async\\": false,\\n \\"inputSchema\\": {\\n \\"type\\": \\"object\\",\\n \\"properties\\": {}\\n }\\n}\\n","component/style.css":"/*\\n * Your app\'s styles. Plain CSS, applied inside the app alone: nothing here\\n * reaches the store\'s page, and nothing on the page reaches in.\\n *\\n * Style with the store\'s theme variables rather than fixed values \u2014 write\\n * `color: var(--color-foreground)`, never `color: #111827`. Each store sets\\n * its colours, fonts and corner style (and dark mode) in its GreatStore\\n * dashboard; an app built on these variables follows those settings, and\\n * changes with them.\\n *\\n * Fonts: --font-primary, --font-secondary\\n * Surfaces: --color-surface, --color-surface-secondary, --color-surface-accent,\\n * --color-surface-hover\\n * Text: --color-foreground, --color-foreground-secondary,\\n * --color-foreground-muted, --color-foreground-accent\\n * Borders: --color-border-default, --color-border-focus\\n * Brand: --color-primary, --color-primary-foreground, --color-primary-hover,\\n * --color-primary-muted, --color-primary-muted-foreground,\\n * --color-primary-tint, --color-link\\n * Status: --color-error, --color-error-surface, --color-error-border,\\n * --color-success\\n * Corners: --radius-xs, --radius-sm, --radius-md, --radius-lg, --radius-xl,\\n * --radius-2xl, --radius-3xl, --radius-4xl, --radius-pill\\n */\\n\\n/* Size in em, never rem: an app sits inside other people\'s pages. */\\n.app {\\n padding: 1em;\\n border: 1px solid var(--color-border-default);\\n border-radius: var(--radius-lg);\\n background: var(--color-surface);\\n color: var(--color-foreground);\\n font-family: var(--font-primary);\\n}\\n","root/.gitignore":"node_modules/\\ncomponents/*/bundle.js\\ncomponents/*/bundle.css\\ncomponents/*/.gssync.json\\n*.tsbuildinfo\\n.DS_Store\\n","root/.gsrc":"{\\n \\"store\\": \\"__GS_STORE__\\"\\n}\\n","root/AGENTS.md":"# AGENTS.md\\n\\n> **Do not edit \u2014 auto-generated by the GreatStore CLI v__GS_VERSION__.**\\n> This file is rewritten by `npx greatstore apps init`, so any changes you make here\\n> will be overwritten. If this version trails your installed CLI, re-run\\n> `npx greatstore apps init` to refresh it. Put project-specific notes in another file.\\n\\nGuidance for AI coding agents working on the apps in this project.\\n`CLAUDE.md` and `GEMINI.md` are symlinks to this file.\\n\\nAn app is interactive UI the store\'s assistant renders inside the\\nconversation \u2014 a configurator, a quiz, a size guide, a booking form. You\\nwrite it in React; each app is one folder under `components/`, holding\\n`manifest.json` and `component.tsx`.\\n\\nApps render inside arbitrary publisher websites (the embed widget mounts\\non a host page) as well as the GreatStore storefront. You control neither\\nthe host page\'s base font size nor its color scheme, and the store owner\\ncontrols the look from GreatStore theme settings. The rules below keep\\napps portable across both.\\n\\n## How an app runs\\n\\nAn app is not a page the shopper navigates to. It is a tool the assistant\\ncalls mid-conversation, and once it is on screen it can talk back \u2014 which\\nis the part that makes apps worth building.\\n\\n```\\nShopper Assistant Your app\\n \u2502 \u2502 \u2502\\n \u2502 \\"what size am I?\\" \u2502 \u2502\\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\u2502 \u2502\\n \u2502 \u2502 picks the app by its \u2502\\n \u2502 \u2502 name + description \u2502\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 calls it with props \u2502\\n \u2502 \u2502 your inputSchema asked \u2502\\n \u2502 \u2502 for (productName, \u2026) \u2502\\n \u2502 \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\u2502\\n \u2502 \u2502 \u251C\u2500\u2500\u2510 onGenerateStructured-\\n \u2502 \u2502 \u2502 \u2502 Content(): its own\\n \u2502 \u2502 \u2502 \u2502 catalog-grounded\\n \u2502 \u2502 \u2502<\u2500\u2518 generation, if wanted\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 \u2502 renders the moment your\\n \u2502 \u2502 \u2502 happy path has what it\\n \u2502 \u2502 \u2502 needs (async: after your\\n \u2502<\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524 promise resolves)\\n \u2502 sees the app \u2502 \u2502\\n \u2502 \u2502 \u2502\\n \u2502 picks size M \u2502 \u2502\\n \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\u2502\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 onUpdateModelContext() \u2502 silent: the assistant\\n \u2502 \u2502<\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524 now knows the pick\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 onSendMessage() \u2502 visible: a shopper turn\\n \u2502 \u2502<\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524 happens right now\\n \u2502 \u2502 \u2502\\n \u2502 \u2502 calls the app again \u2502 same app, new props \u2014\\n \u2502 \u251C\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500>\u2502 re-rendered in place\\n \u2502 \u2502 \u2502\\n```\\n\\nFour consequences worth designing around:\\n\\n1. **The assistant chooses the app, so `manifest.json` is the interface it\\n sees** \u2014 see the next section.\\n2. **Control is bidirectional once the app is up.** The app reports what\\n the shopper is doing (`onUpdateModelContext`), can speak for the\\n shopper (`onSendMessage`), and the assistant can call the app again\\n with revised props. Keep the render a function of the props it was\\n given, so a re-call is a re-render rather than a reset.\\n3. **The app can run its own generation, not just receive props.**\\n `onGenerateStructuredContent` returns a catalog-grounded,\\n shopper-personalized object matching your schema \u2014 recommended picks, a\\n personalized summary, a reason per option \u2014 which you render in your\\n own markup.\\n4. **Render on the happy path, not on a shell.** Whatever the app needs to\\n be correct \u2014 props, or awaited data in an async app \u2014 should be there\\n before anything paints; GreatStore owns the loading state.\\n\\n## `manifest.json` \u2014 the name and description decide whether your app runs\\n\\nThe assistant never sees your app. It sees a name and a sentence, next to\\nevery other tool it has, and picks one. Write the description for that\\n*caller*, answering one question: when should I reach for this, and what\\ndo I get back?\\n\\n**Describing the UI is the most common mistake.** Layout, sliders, tabs,\\ncarousels and colors are the shopper\'s concern. To the assistant they are\\nnoise \u2014 they say nothing about when to call the tool.\\n\\n| Don\'t | Do |\\n| --- | --- |\\n| \\"Renders a two-column table of measurements with a unit toggle.\\" | \\"Use when a shopper is unsure which size to buy or asks how an item fits.\\" |\\n| \\"A carousel of product cards with images and prices.\\" | \\"Use to show 2\u20138 specific products you have already chosen, when the shopper wants to see them side by side before deciding.\\" |\\n| \\"Modal with a multi-step form and a progress bar.\\" | \\"Use when the shopper wants a gift but can\'t say what \u2014 collects budget, recipient and occasion, then reports them back so you can recommend.\\" |\\n\\nWhat belongs in a description, in this order:\\n\\n1. **The trigger** \u2014 the shopper situation or intent, in the words a\\n shopper would actually use. Start with `Use when \u2026`.\\n2. **The boundary** \u2014 when *not* to, if another tool overlaps. One clause\\n is enough: \\"Use for in-store appointments; not for delivery scheduling.\\"\\n3. **What the assistant gets back** \u2014 if the app reports state or sends\\n messages, say so: \\"reports the size the shopper settles on back to you.\\"\\n\\nOne or two sentences. If a required `inputSchema` field is subtle, say\\nwhat it means here rather than trusting the schema alone.\\n\\nThe same rule governs the **name** (snake_case, matching the folder under\\n`components/`): name it after the job, not the widget. `size_guide`,\\n`gift_finder`, `book_appointment` read as intents; `size_modal`,\\n`quiz_ui`, `product_grid_v2` read as implementation details and get\\nskipped. `displayName` is the one field written for the shopper.\\n\\nKeep `inputSchema` tight: required fields the assistant can\'t infer from\\nthe conversation cause bad calls.\\n\\n## Design requirements\\n\\n### Style in `style.css`\\n\\nEach app\'s styles live in `components/<name>/style.css`, imported once at\\nthe top of `component.tsx`:\\n\\n```tsx\\nimport \\"./style.css\\";\\n```\\n\\nWrite ordinary CSS there and use `className` in the component. The sheet\\napplies to your app alone \u2014 it can\'t affect the store\'s page, and the page\\ncan\'t affect your app \u2014 so short class names like `.card` are safe.\\nInline `style={{\u2026}}` still works for values computed at render time.\\n\\nThe rules for `style.css`:\\n\\n- Import only `./style.css`, and only from `component.tsx`. Every other CSS\\n import fails the build.\\n- Keep it self-contained: no `@import`, and `url()` only with `https:` or\\n `data:` URLs \u2014 nothing beside the sheet is uploaded with it.\\n- At most 256 KB.\\n\\n`npx greatstore apps build` minifies the sheet into `bundle.css` beside\\n`bundle.js`; shoppers get that, so comments in `style.css` are for you and\\nnever reach them. Like `bundle.js`, `bundle.css` is generated \u2014 edit\\n`style.css` and build again.\\n\\nThe comment at the top of the scaffolded `style.css` lists the theme\\nvariables below. Style with them rather than fixed values: each store sets\\nits colours, fonts and corner style in its GreatStore dashboard, and an app\\nbuilt on the variables follows those settings.\\n\\n### Never use `rem` for fonts and sizing \u2014 always use `em`\\n\\n`rem` resolves against the host page\'s root font size, which is\\narbitrary and outside our control. A host that sets `html { font-size:\\n8px }` (or 200%) will shrink or blow up every `rem`-based dimension.\\n`em` resolves against the app\'s own font size, so it stays\\nself-consistent wherever the app is mounted.\\n\\nUse `em` for font sizes, padding, margins, gaps, widths, heights,\\nand any other length. Borders may stay in `px` (hairlines should not\\nscale with text).\\n\\n```css\\n/* Bad \u2014 breaks on hosts with a non-default root font size */\\n.card { padding: 1rem; font-size: 0.875rem; }\\n\\n/* Good */\\n.card { padding: 1em; font-size: 0.875em; }\\n```\\n\\n### Fullscreen apps must leave a safe-zone at the bottom\\n\\nOn the storefront the chat widget floats over the bottom of the screen, so\\nanything a `fullscreen` app renders there can be covered by it. Reserve a\\nsafe-zone of `6.25em` (100px at the default font size) at the bottom of the\\napp\'s scrolling content \u2014 e.g. `padding-bottom: 6.25em` on the scroll\\ncontainer \u2014 so the last row, button, or link can always be scrolled clear of\\nthe widget. Inline and over-input apps don\'t need it.\\n\\n### Don\'t hardcode colors, fonts, or corner radius \u2014 use GreatStore brand variables\\n\\nThe store owner themes the assistant from GreatStore settings. Hardcoded\\nvalues ignore that and make the app clash with the rest of the store.\\nRead from the CSS variables GreatStore injects on the surface instead, so\\nthe app restyles itself when the theme changes.\\n\\nAvailable variables:\\n\\n| Purpose | Variable |\\n| --- | --- |\\n| Surface background | `--color-surface` |\\n| Secondary surface | `--color-surface-secondary` |\\n| Accent surface | `--color-surface-accent` |\\n| Hover surface | `--color-surface-hover` |\\n| Foreground text | `--color-foreground` |\\n| Secondary text | `--color-foreground-secondary` |\\n| Muted text | `--color-foreground-muted` |\\n| Accent text | `--color-foreground-accent` |\\n| Border | `--color-border-default` |\\n| Focus border | `--color-border-focus` |\\n| Primary / brand | `--color-primary` |\\n| Text on primary | `--color-primary-foreground` |\\n| Primary hover | `--color-primary-hover` |\\n| Primary muted | `--color-primary-muted` |\\n| Text on primary muted | `--color-primary-muted-foreground` |\\n| Primary tint | `--color-primary-tint` |\\n| Link | `--color-link` |\\n| Font family | `--font-primary` |\\n| Secondary font family | `--font-secondary` |\\n| Corner radius (scale) | `--radius-xs` \u2026 `--radius-4xl`, `--radius-pill` |\\n\\nThe store owner can set a secondary font family in their GreatStore\\ntheme settings, exposed as `--font-secondary` (it falls back to\\n`--font-primary` when unset). Reach for it to add a tasteful second\\nlayer of typography \u2014 pair `--font-primary` for body copy with\\n`--font-secondary` for headings, prices, or other accents \u2014 so the app\\nreflects the store\'s full type system instead of a single face.\\n\\n```css\\n/* Bad \u2014 hardcoded, ignores the store\'s theme */\\n.buy { background: #4f46e5; border-radius: 8px; font-family: Inter; }\\n\\n/* Good */\\n.buy {\\n background: var(--color-primary);\\n color: var(--color-primary-foreground);\\n border-radius: var(--radius-lg);\\n font-family: var(--font-primary);\\n}\\n```\\n\\nProvide a sensible fallback only when a value might be absent, e.g.\\n`var(--color-primary, currentColor)`.\\n\\n## App props\\n\\nEach app receives its tool args (the fields you declare in\\n`manifest.json#inputSchema.properties`) plus these GreatStore-injected\\nlifecycle props, which are always present:\\n\\n| Prop | What it does |\\n| --- | --- |\\n| `onSendMessage(text)` | Send text into the chat as if the shopper typed it. |\\n| `onUpdateModelContext(context)` | Inject invisible background context for the model (selected variant, configured options, current step). Replaces the prior value \u2014 never appends; pass `\\"\\"` to clear. Read on the next chat turn. Use it when the assistant should *know* in-app state without a visible message; use `onSendMessage` when you want a turn to happen now. |\\n| `onShowLightbox({ src, originRect? })` | Expand an image in the chat\'s shared full-screen lightbox \u2014 an on-brand zoom overlay your app can\'t render itself (it\'s boxed inside its own bounds and shadow root). Pass the image `src`; for a smooth zoom, also pass the clicked element\'s `getBoundingClientRect()` as `originRect` (omit it and the image grows from the viewport centre). |\\n| `onGenerateStructuredContent(schema, prompt, fallback)` | Ask the store\'s assistant for content matching a JSON Schema (or a Zod schema); resolves to the generated object. Personalized to the shopper. Works the same in the conversation on the storefront and every embed. Best inside an async app that builds its render from the generated payload \u2014 `await` it, then return the JSX. `fallback` is **required**: a schema-shaped object you supply that the app preview renders (so a generation-driven app previews without a live store). It\'s validated against the schema and throws if the two don\'t line up. |\\n| `onClose()` | Dismiss the host slot. Over-input clears the overlay, fullscreen reverts the pane, inline is a no-op. |\\n| `useVoiceCall()` | A hook \u2014 call it at the top of your component like any other \u2014 returning `{ status, available, start, end }` for a voice call with the store\'s assistant. `start()` starts the call without opening the chat \u2014 it runs in the collapsed chat bar (which stays hidden if the store hides the chat until opened), and the chat opens only when the assistant shows an inline app (call it from a click; it rejects when the store has no voice), `end()` hangs up. `available` says whether the store has voice. `status` is `null` until a call starts, then `started`, `connecting`, `connected`, `listening` / `speaking` / `working` as the conversation goes, `disconnected` while the network drops (the call recovers on its own), and `ended`. Your app re-renders on every change. |\\n| `Image` | A drop-in for `<img>`: render `<Image src=\u2026 alt=\u2026 />` instead of `<img>` and your images are automatically served at the right size for the store. Takes the same props as `<img>` (`src`, `alt`, `style`, `loading`, `onClick`, \u2026). Previewing the app outside the store? Pass `Image={\\"img\\"}` (or your own component) to render a plain image. |\\n\\n## Async apps (backend-backed, render-blocking data)\\n\\nIf an app must load data from a backend/API before it can render\\ncorrectly, make it async \u2014 don\'t render an empty shell and fetch in a\\n`useEffect`. Set `\\"async\\": true` in `manifest.json` and export an async\\ndefault. GreatStore waits for your promise (showing a normal loading\\nstate, so you don\'t render your own placeholder), then renders what it\\nresolves to. Apps that render purely from their props stay synchronous.\\n\\nA thrown error is a **retry signal**: the in-store AI sees it and\\nusually re-calls the tool. So only throw when a *different* call could\\nhelp:\\n\\n1. `await` the backend call, then return the finished JSX.\\n2. Validate the AI-passed props first and throw on bad input \u2014 the AI\\n can fix the args and retry. (Don\'t validate the API\'s *output* and\\n throw: the AI can\'t fix the backend, it\'ll just loop.)\\n3. Broadcast a backend failure ONLY when retrying differently could\\n succeed, and say what to change (e.g. empty search \u2192 \\"try a broader\\n keyword\\"). For idempotent failures (500, timeout, missing record)\\n re-running the same call changes nothing \u2014 render a graceful fallback\\n instead of throwing.\\n\\n```tsx\\nexport default async function Example(props: Props) {\\n if (!props.query?.trim()) throw new Error(\\"missing required prop: query\\");\\n const res = await fetch(`/api/search?q=${encodeURIComponent(props.query)}`);\\n if (res.ok) {\\n const { results } = await res.json();\\n if (results.length === 0)\\n throw new Error(`no results for \\"${props.query}\\" \u2014 try a broader keyword`);\\n return <ul>{/* render results */}</ul>;\\n }\\n return <p>Couldn\'t load results right now.</p>; // idempotent: don\'t throw\\n}\\n```\\n","root/README.md":"# GreatStore apps\\n\\nCustom in-chat apps published to your GreatStore tenant. Each app is a\\nReact component living in its own folder under `components/`.\\n\\n```\\nnpm install\\nnpx greatstore apps init <app_name> # add a new app\\nnpx greatstore apps build # builds every components/<name>/bundle.js\\nnpx greatstore apps push # uploads every changed app as a draft\\nnpx greatstore apps publish <app_name> # promote a specific app to live\\n```\\n\\n- `npx greatstore apps push` (no args) hashes each app and only uploads the ones that\\n have changed since the last sync.\\n- `npx greatstore apps pull` (no args) refreshes every live app into\\n `components/<name>/`. Apps with unsaved local edits are skipped with a\\n warning; pass `--force` to overwrite.\\n\\nSee `AGENTS.md` for how an app runs, how to write a manifest name and\\ndescription the assistant will actually pick, and the design rules every\\napp must follow (em-based sizing, brand CSS variables) \u2014 it doubles as\\nguidance for AI coding agents (`CLAUDE.md` / `GEMINI.md` symlink to it).\\n","root/package.json":"{\\n \\"name\\": \\"greatstore-components\\",\\n \\"version\\": \\"0.0.1\\",\\n \\"private\\": true,\\n \\"type\\": \\"module\\",\\n \\"scripts\\": {\\n \\"build\\": \\"npx greatstore apps build\\",\\n \\"push\\": \\"npx greatstore apps build && npx greatstore apps push\\"\\n },\\n \\"dependencies\\": {\\n \\"react\\": \\"^19.0.0\\",\\n \\"react-dom\\": \\"^19.0.0\\"\\n },\\n \\"devDependencies\\": {\\n \\"@types/react\\": \\"^19.0.0\\",\\n \\"@types/react-dom\\": \\"^19.0.0\\",\\n \\"@vitejs/plugin-react\\": \\"^4.3.0\\",\\n \\"typescript\\": \\"^5.6.0\\",\\n \\"vite\\": \\"^5.4.0\\"\\n }\\n}\\n","root/tsconfig.json":"{\\n \\"compilerOptions\\": {\\n \\"target\\": \\"ES2022\\",\\n \\"module\\": \\"ESNext\\",\\n \\"moduleResolution\\": \\"Bundler\\",\\n \\"jsx\\": \\"react-jsx\\",\\n \\"lib\\": [\\"ES2022\\", \\"DOM\\"],\\n \\"strict\\": true,\\n \\"esModuleInterop\\": true,\\n \\"skipLibCheck\\": true,\\n \\"isolatedModules\\": true,\\n \\"noEmit\\": true\\n },\\n \\"include\\": [\\"components/**/component.tsx\\", \\"vite.config.ts\\"]\\n}\\n","root/vite.config.ts":"import { defineConfig } from \\"vite\\";\\nimport react from \\"@vitejs/plugin-react\\";\\n\\n// Real builds happen in `npx greatstore build` (one Vite invocation per\\n// component, externals + runtime shim paths owned by the CLI). This\\n// file exists only so editors / language servers can resolve the\\n// React plugin when inspecting components/*/component.tsx.\\nexport default defineConfig({\\n plugins: [react()],\\n});\\n"}'),Ie)}var Jt={name:"__GS_NAME__",displayName:"__GS_DISPLAY_NAME__",store:"__GS_STORE__",version:"__GS_VERSION__"};function Yt(e,t){let n=e;for(let o of Object.keys(Jt)){let s=t[o];s!==void 0&&(n=n.split(Jt[o]).join(s))}let r=n.match(/__GS_[A-Z_]+__/);if(r)throw new Error(`internal: template placeholder ${r[0]} was not provided`);return n}var zt=/^[a-z][a-z0-9_]*$/;function Qt(e){let t=e.positional[0];if(t!==void 0&&!zt.test(t))throw new Error(`Invalid component name: "${t}" (must match ${zt}).`);let n=g(e.flags,"force"),r=b(e.flags,"store"),o=b(e.flags,"out")??".",s=j.resolve(o),i=Gr(s),a;if(i){if(r!==void 0)throw new Error(`Project at ${s} is already pinned to a store via .gsrc. Drop --store; a project folder ships to exactly one store.`);P({cwd:s})}else if(a=r!==void 0?le(r):xe()??void 0,a===void 0){let u=t?`npx greatstore apps init ${t} --store <slug>`:"npx greatstore apps init --store <slug>";throw new Error(`--store <slug> is required when scaffolding a new project root. Run \`${u}\`.`)}let l=Vr(s,i,n,{store:a});if(!t){let u=[];i?(u.push(`Updated GreatStore project root in ${s}.`),l.length>0?u.push("",`Added: ${l.join(", ")}`):u.push("","Already up to date \u2014 nothing to add.")):u.push(`Scaffolded GreatStore project root in ${s}.`),u.push("","Next steps:",` cd ${j.relative(process.cwd(),s)||"."}`," npm install"," npx greatstore apps init <component_name> # add your first component",""),process.stdout.write(u.join(`
85
85
  `));return}let c=j.join(s,"components",t);Jr(c,t,n);let p=j.relative(process.cwd(),s)||".";process.stdout.write([`Added component "${t}" at components/${t}/.`,...i&&l.length>0?["",`Also added to the project root: ${l.join(", ")}`]:[],"","Next steps:",...i?[]:[` cd ${p}`," npm install"],` # edit components/${t}/component.tsx and manifest.json`," npx greatstore apps build"," npx greatstore apps push",""].join(`
86
- `))}function Gr(e){return y.existsSync(j.join(e,"package.json"))&&y.existsSync(j.join(e,".gsrc"))}function qr(e,t,n,r){if(y.mkdirSync(e,{recursive:!0}),!t&&!n&&y.readdirSync(e).filter(a=>a!==".gsrc").length>0)throw new Error(`Refusing to scaffold project root into non-empty directory ${e}. Pass --force to override.`);let o=t?Yr():Wr({store:r.store}),s=Kr(e,o,n);return y.mkdirSync(j.join(e,"components"),{recursive:!0}),s}var Vr=new Set(["AGENTS.md"]);function Kr(e,t,n){let r=[];for(let[o,s]of t){let i=j.join(e,o);y.mkdirSync(j.dirname(i),{recursive:!0});let a=y.existsSync(i);if(!n&&a&&!Vr.has(o))continue;let l=!a||y.readFileSync(i,"utf8")!==s;y.writeFileSync(i,s),l&&r.push(o)}for(let o of["CLAUDE.md","GEMINI.md"]){let s=j.join(e,o);n&&Xt(s)&&y.rmSync(s),Xt(s)||(y.symlinkSync("AGENTS.md",s),r.push(o))}return r}function Xt(e){try{return y.lstatSync(e),!0}catch{return!1}}function Jr(e,t,n){if(y.existsSync(e)&&!n&&y.readdirSync(e).length>0)throw new Error(`Refusing to overwrite existing components/${t}/. Pass --force to override.`);y.mkdirSync(e,{recursive:!0});for(let[r,o]of zr(t))y.writeFileSync(j.join(e,r),o)}function it(e,t,n=new Set){let r=Wt();return Object.entries(r).filter(([o])=>o.startsWith(e)).map(([o,s])=>[o.slice(e.length),s]).filter(([o])=>!n.has(o)).map(([o,s])=>[o,Yt(s,t)])}function Wr(e){if(!e.store)throw new Error("internal: rootFiles called without a store slug");return it("root/",{store:e.store,version:F})}function Yr(){return it("root/",{version:F},new Set([".gsrc"]))}function zr(e){return it("component/",{name:e,displayName:Xr(e)})}function Xr(e){let t=e.split("_").filter(Boolean);if(t.length===0)return e;let n=t[0];return n.charAt(0).toUpperCase()+n.slice(1)+(t.length>1?" "+t.slice(1).join(" "):"")}import*as $ from"fs";import*as h from"path";import*as pe from"fs";import*as at from"path";var x="style.css",_="bundle.css",Fe=`./${x}`,Zt=256*1024;function Qr(e){let t=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,""),n=[],r=/(?:^|[;{}])\s*import\s+(?:[^'";]*?\s+from\s+)?["']([^"']+\.css)(?:\?[^"']*)?["']/gm,o=/\bimport\s*\(\s*["']([^"']+\.css)(?:\?[^"']*)?["']\s*\)/g;for(let s of t.matchAll(r))n.push(s[1]);for(let s of t.matchAll(o))n.push(s[1]);return n}function N(e){let t=at.join(e,"component.tsx");if(!pe.existsSync(t))return{imported:!1,problems:[]};let n=Qr(pe.readFileSync(t,"utf8")),r=n.filter(i=>i!==Fe).map(i=>({file:"component.tsx",message:`imports "${i}". A component's styles go in its own ${x}, imported as "${Fe}"; move these rules there.`})),o=n.includes(Fe);if(!o)return{imported:o,problems:r};let s=at.join(e,x);if(!pe.existsSync(s))return r.push({file:"component.tsx",message:`imports "${Fe}", but there's no ${x} beside it.`}),{imported:o,problems:r};for(let i of Zr(pe.readFileSync(s,"utf8")))r.push({file:x,message:i});return{imported:o,problems:r}}function Zr(e){let t=[],n=Buffer.byteLength(e,"utf8");n>Zt&&t.push(`is ${(n/1024).toFixed(1)} KB; the limit is ${Zt/1024} KB.`);let r=e.replace(/\/\*[\s\S]*?\*\//g,s=>s.replace(/[^\n]/g," ")),o=s=>r.slice(0,s).split(`
87
- `).length;for(let s of r.matchAll(/@import\b/gi))t.push(`line ${o(s.index)} uses @import. A stylesheet ships on its own, so copy the rules in instead.`);for(let s of r.matchAll(/url\(\s*(["']?)([^"')]*)\1\s*\)/gi)){let i=s[2].trim();/^(https:|data:|#)/i.test(i)||t.push(`line ${o(s.index)} refers to "${i}". Only https: and data: URLs work here \u2014 nothing beside the stylesheet is uploaded with it.`)}return t}import{createRequire as po}from"module";import*as pn from"fs";import*as U from"path";import{createRequire as eo}from"module";import*as Ne from"path";function tn(e,t,n){let r=rn(e);if(!r)return{ok:!1,reason:"couldn't check props against the manifest \u2014 `typescript` isn't installed in this project (run `npm install`)"};try{let o=r.createSourceFile(t,n,r.ScriptTarget.Latest,!0,r.ScriptKind.TSX),s=no(r,o);return s?so(r,o,s):{ok:!1,reason:"couldn't find a default-exported component function to check props against \u2014 export the component as `export default function \u2026`"}}catch(o){return{ok:!1,reason:`couldn't check props against the manifest \u2014 ${Ne.basename(t)} could not be parsed (${o.message})`}}}function nn(e,t,n){let r=rn(e);if(!r)return!1;try{let o=r.createSourceFile(t,n,r.ScriptTarget.Latest,!0,r.ScriptKind.TSX),s=!1,i=a=>{if(!s){if(to(r,a)){s=!0;return}r.forEachChild(a,i)}};return i(o),s}catch{return!1}}function to(e,t){if(e.isPropertyAccessExpression(t))return en(e,t.expression)&&t.name.text==="GreatStore";if(e.isElementAccessExpression(t)){let n=t.argumentExpression;return en(e,t.expression)&&e.isStringLiteralLike(n)&&n.text==="GreatStore"}return!1}function en(e,t){return e.isIdentifier(t)&&(t.text==="window"||t.text==="globalThis")}function rn(e){let t=eo(Ne.join(e,"package.json"));try{return t("typescript")}catch{return null}}function no(e,t){let n=null;for(let o of t.statements){if(e.isFunctionDeclaration(o)&&ro(e,o))return o;e.isExportAssignment(o)&&!o.isExportEquals&&(n=o.expression)}if(!n)return null;let r=on(e,n);return e.isArrowFunction(r)||e.isFunctionExpression(r)?r:e.isIdentifier(r)?oo(e,t,r.text):null}function ro(e,t){return t.modifiers?.some(n=>n.kind===e.SyntaxKind.DefaultKeyword)??!1}function on(e,t){let n=t;for(;e.isParenthesizedExpression(n)||e.isAsExpression(n)||e.isSatisfiesExpression(n);)n=n.expression;return n}function oo(e,t,n){for(let r of t.statements){if(e.isFunctionDeclaration(r)&&r.name?.text===n)return r;if(e.isVariableStatement(r))for(let o of r.declarationList.declarations){if(!e.isIdentifier(o.name)||o.name.text!==n||!o.initializer)continue;let s=on(e,o.initializer);if(e.isArrowFunction(s)||e.isFunctionExpression(s))return s}}return null}function so(e,t,n){let r=n.parameters[0];if(!r)return{ok:!0,props:{names:[],open:!1}};if(r.type){let o=ct(e,t,r.type,new Set);if(o)return{ok:!0,props:o}}return e.isObjectBindingPattern(r.name)?{ok:!0,props:io(e,r.name)}:{ok:!1,reason:"couldn't check props against the manifest \u2014 declare the component's props as a local `interface`/`type` or destructure them in the signature"}}function ct(e,t,n,r){if(e.isTypeLiteralNode(n))return an(e,n.members);if(e.isTypeReferenceNode(n)&&e.isIdentifier(n.typeName))return sn(e,t,n.typeName.text,r);if(e.isIntersectionTypeNode(n)){let o=n.types.map(s=>ct(e,t,s,r));return o.every(s=>s===null)?null:ln(o.map(s=>s??{names:[],open:!0}))}return null}function sn(e,t,n,r){if(r.has(n))return{names:[],open:!1};r.add(n);for(let o of t.statements){if(e.isInterfaceDeclaration(o)&&o.name.text===n){let s=an(e,o.members),i=(o.heritageClauses??[]).flatMap(a=>a.types.map(l=>e.isIdentifier(l.expression)?sn(e,t,l.expression.text,r)??{names:[],open:!0}:{names:[],open:!0}));return ln([s,...i])}if(e.isTypeAliasDeclaration(o)&&o.name.text===n)return ct(e,t,o.type,r)}return null}function an(e,t){let n=[],r=!1;for(let o of t){if(e.isIndexSignatureDeclaration(o)){r=!0;continue}if(!e.isPropertySignature(o)&&!e.isMethodSignature(o))continue;let s=cn(e,o.name);if(s===null){r=!0;continue}n.push(s)}return{names:n,open:r}}function io(e,t){let n=[],r=!1;for(let o of t.elements){if(o.dotDotDotToken){r=!0;continue}let s=o.propertyName??o.name,i=cn(e,s);i===null?r=!0:n.push(i)}return{names:n,open:r}}function cn(e,t){return e.isIdentifier(t)||e.isStringLiteral(t)?t.text:null}function ln(e){let t=[],n=!1;for(let r of e){for(let o of r.names)t.includes(o)||t.push(o);n||=r.open}return{names:t,open:n}}function fn(e){let{root:t,name:n}=e,r=U.join(t,"components",n),o=e.manifestPath??U.join(r,"manifest.json"),s=e.sourcePath??U.join(r,"component.tsx"),i=lt(t,o),a=lt(t,s),l=[],c=null,p=un(o);if(p===null)l.push({severity:"error",rule:"manifest/missing",file:i,message:"manifest not found."});else try{let d=JSON.parse(p);!d||typeof d!="object"||Array.isArray(d)?l.push({severity:"error",rule:"manifest/invalid",file:i,message:"manifest must be a JSON object."}):c=d}catch(d){l.push({severity:"error",rule:"manifest/invalid",file:i,message:`manifest is not valid JSON: ${d.message}`})}let u=un(s),m=u===null?{ok:!1,reason:`couldn't check props against the manifest \u2014 ${a} not found`}:tn(t,s,u),S=u===null?!1:nn(t,s,u);return{ctx:{name:n,manifestFile:i,sourceFile:a,manifest:c,props:m,usesWindowGreatStore:S,styleFile:lt(t,U.join(r,"style.css")),stylesheet:N(r)},diagnostics:l}}function un(e){try{return pn.readFileSync(e,"utf8")}catch{return null}}function lt(e,t){let n=U.relative(e,t);return n.startsWith("..")?t:n.split(U.sep).join("/")}var dn=new Set(["onSendMessage","onClose","onUpdateModelContext","onShowLightbox","onGenerateStructuredContent","storeData","Image"]);var mn=new Map([["onError",'prop `onError` is deprecated and no longer provided \u2014 prefer an async component to report failures. Drop the prop; see the "Async components" section in AGENTS.md for how to signal errors.']]);function hn(e){if(!e.manifest)return[];let t=co(e.manifest.inputSchema);if(t===null)return[];if(!e.props.ok)return[{severity:"warning",rule:"props/not-analyzable",file:e.sourceFile,message:`${e.props.reason}.`}];if(e.props.props.open)return[];let n=new Set(e.props.props.names),r=new Set(t),o=[];for(let i of e.props.props.names){if(dn.has(i))continue;let a=mn.get(i);if(a){o.push({severity:"warning",rule:"props/retired-lifecycle",file:e.sourceFile,message:a});continue}r.has(i)||o.push({severity:"warning",rule:"props/undeclared",file:e.sourceFile,message:`prop \`${i}\` is not declared in ${e.manifestFile}#inputSchema.properties, so nothing will ever pass it. Declare it in the schema, or drop it from the component.`})}let s=t.filter(i=>!n.has(i));return s.length>0&&o.push({severity:"error",rule:"props/missing",file:e.sourceFile,message:ao(e.manifestFile,s)}),o}var gn=8;function ao(e,t){if(t.length===1){let[s]=t;return`${e} declares inputSchema field \`${s}\`, but the component does not accept a \`${s}\` prop. Add it to the component's props, or remove it from the schema.`}let n=t.slice(0,gn).map(s=>`\`${s}\``).join(", "),r=t.length-gn,o=r>0?`${n} (+${r} more)`:n;return`${e} declares ${t.length} inputSchema fields the component does not accept: ${o}. Add them to the component's props, or remove them from the schema.`}function co(e){if(!e||typeof e!="object")return null;let t=e.properties;return!t||typeof t!="object"||Array.isArray(t)?null:Object.keys(t)}var lo=["anyOf","oneOf","allOf","$ref","not"];function Be(e,t,n){if(Array.isArray(e)){e.forEach((s,i)=>Be(s,`${t}[${i}]`,n));return}if(!e||typeof e!="object")return;let r=e;for(let s of lo)s in r&&n.unionPaths.push(`${t}.${s}`);let o=r.properties;if(o&&typeof o=="object"&&!Array.isArray(o))for(let[s,i]of Object.entries(o))n.fields+=1,Be(i,`${t}.${s}`,n);"items"in r&&Be(r.items,`${t}[]`,n)}function yn(e){let t=e.manifest?.inputSchema;if(!t||typeof t!="object")return[];let n={bytes:Buffer.byteLength(JSON.stringify(t),"utf8"),fields:0,unionPaths:[]};Be(t,"inputSchema",n);let r=[];if(n.unionPaths.length>0){let o=n.unionPaths.slice(0,3).join(", "),s=n.unionPaths.length>3?` (+${n.unionPaths.length-3} more)`:"";r.push(`uses ${o}${s} \u2014 declare exactly one type per field; accept alternate shapes in component code instead`)}return n.bytes>8192&&r.push(`is ${(n.bytes/1024).toFixed(1)} KB serialized (limit ${8192/1024} KB)`),n.fields>50&&r.push(`declares ${n.fields} fields (limit 50)`),r.length===0?[]:[{severity:"error",rule:"manifest/input-schema-too-complex",file:e.manifestFile,message:`inputSchema ${r.join("; ")}.
86
+ `))}function Gr(e){return y.existsSync(j.join(e,"package.json"))&&y.existsSync(j.join(e,".gsrc"))}function Vr(e,t,n,r){if(y.mkdirSync(e,{recursive:!0}),!t&&!n&&y.readdirSync(e).filter(a=>a!==".gsrc").length>0)throw new Error(`Refusing to scaffold project root into non-empty directory ${e}. Pass --force to override.`);let o=t?Yr():Wr({store:r.store}),s=Kr(e,o,n);return y.mkdirSync(j.join(e,"components"),{recursive:!0}),s}var qr=new Set(["AGENTS.md"]);function Kr(e,t,n){let r=[];for(let[o,s]of t){let i=j.join(e,o);y.mkdirSync(j.dirname(i),{recursive:!0});let a=y.existsSync(i);if(!n&&a&&!qr.has(o))continue;let l=!a||y.readFileSync(i,"utf8")!==s;y.writeFileSync(i,s),l&&r.push(o)}for(let o of["CLAUDE.md","GEMINI.md"]){let s=j.join(e,o);n&&Xt(s)&&y.rmSync(s),Xt(s)||(y.symlinkSync("AGENTS.md",s),r.push(o))}return r}function Xt(e){try{return y.lstatSync(e),!0}catch{return!1}}function Jr(e,t,n){if(y.existsSync(e)&&!n&&y.readdirSync(e).length>0)throw new Error(`Refusing to overwrite existing components/${t}/. Pass --force to override.`);y.mkdirSync(e,{recursive:!0});for(let[r,o]of zr(t))y.writeFileSync(j.join(e,r),o)}function it(e,t,n=new Set){let r=Wt();return Object.entries(r).filter(([o])=>o.startsWith(e)).map(([o,s])=>[o.slice(e.length),s]).filter(([o])=>!n.has(o)).map(([o,s])=>[o,Yt(s,t)])}function Wr(e){if(!e.store)throw new Error("internal: rootFiles called without a store slug");return it("root/",{store:e.store,version:F})}function Yr(){return it("root/",{version:F},new Set([".gsrc"]))}function zr(e){return it("component/",{name:e,displayName:Xr(e)})}function Xr(e){let t=e.split("_").filter(Boolean);if(t.length===0)return e;let n=t[0];return n.charAt(0).toUpperCase()+n.slice(1)+(t.length>1?" "+t.slice(1).join(" "):"")}import*as $ from"fs";import*as h from"path";import*as pe from"fs";import*as at from"path";var x="style.css",_="bundle.css",Fe=`./${x}`,Zt=256*1024;function Qr(e){let t=e.replace(/\/\*[\s\S]*?\*\//g,"").replace(/^\s*\/\/.*$/gm,""),n=[],r=/(?:^|[;{}])\s*import\s+(?:[^'";]*?\s+from\s+)?["']([^"']+\.css)(?:\?[^"']*)?["']/gm,o=/\bimport\s*\(\s*["']([^"']+\.css)(?:\?[^"']*)?["']\s*\)/g;for(let s of t.matchAll(r))n.push(s[1]);for(let s of t.matchAll(o))n.push(s[1]);return n}function N(e){let t=at.join(e,"component.tsx");if(!pe.existsSync(t))return{imported:!1,problems:[]};let n=Qr(pe.readFileSync(t,"utf8")),r=n.filter(i=>i!==Fe).map(i=>({file:"component.tsx",message:`imports "${i}". A component's styles go in its own ${x}, imported as "${Fe}"; move these rules there.`})),o=n.includes(Fe);if(!o)return{imported:o,problems:r};let s=at.join(e,x);if(!pe.existsSync(s))return r.push({file:"component.tsx",message:`imports "${Fe}", but there's no ${x} beside it.`}),{imported:o,problems:r};for(let i of Zr(pe.readFileSync(s,"utf8")))r.push({file:x,message:i});return{imported:o,problems:r}}function Zr(e){let t=[],n=Buffer.byteLength(e,"utf8");n>Zt&&t.push(`is ${(n/1024).toFixed(1)} KB; the limit is ${Zt/1024} KB.`);let r=e.replace(/\/\*[\s\S]*?\*\//g,s=>s.replace(/[^\n]/g," ")),o=s=>r.slice(0,s).split(`
87
+ `).length;for(let s of r.matchAll(/@import\b/gi))t.push(`line ${o(s.index)} uses @import. A stylesheet ships on its own, so copy the rules in instead.`);for(let s of r.matchAll(/url\(\s*(["']?)([^"')]*)\1\s*\)/gi)){let i=s[2].trim();/^(https:|data:|#)/i.test(i)||t.push(`line ${o(s.index)} refers to "${i}". Only https: and data: URLs work here \u2014 nothing beside the stylesheet is uploaded with it.`)}return t}import{createRequire as po}from"module";import*as pn from"fs";import*as U from"path";import{createRequire as eo}from"module";import*as Ne from"path";function tn(e,t,n){let r=rn(e);if(!r)return{ok:!1,reason:"couldn't check props against the manifest \u2014 `typescript` isn't installed in this project (run `npm install`)"};try{let o=r.createSourceFile(t,n,r.ScriptTarget.Latest,!0,r.ScriptKind.TSX),s=no(r,o);return s?so(r,o,s):{ok:!1,reason:"couldn't find a default-exported component function to check props against \u2014 export the component as `export default function \u2026`"}}catch(o){return{ok:!1,reason:`couldn't check props against the manifest \u2014 ${Ne.basename(t)} could not be parsed (${o.message})`}}}function nn(e,t,n){let r=rn(e);if(!r)return!1;try{let o=r.createSourceFile(t,n,r.ScriptTarget.Latest,!0,r.ScriptKind.TSX),s=!1,i=a=>{if(!s){if(to(r,a)){s=!0;return}r.forEachChild(a,i)}};return i(o),s}catch{return!1}}function to(e,t){if(e.isPropertyAccessExpression(t))return en(e,t.expression)&&t.name.text==="GreatStore";if(e.isElementAccessExpression(t)){let n=t.argumentExpression;return en(e,t.expression)&&e.isStringLiteralLike(n)&&n.text==="GreatStore"}return!1}function en(e,t){return e.isIdentifier(t)&&(t.text==="window"||t.text==="globalThis")}function rn(e){let t=eo(Ne.join(e,"package.json"));try{return t("typescript")}catch{return null}}function no(e,t){let n=null;for(let o of t.statements){if(e.isFunctionDeclaration(o)&&ro(e,o))return o;e.isExportAssignment(o)&&!o.isExportEquals&&(n=o.expression)}if(!n)return null;let r=on(e,n);return e.isArrowFunction(r)||e.isFunctionExpression(r)?r:e.isIdentifier(r)?oo(e,t,r.text):null}function ro(e,t){return t.modifiers?.some(n=>n.kind===e.SyntaxKind.DefaultKeyword)??!1}function on(e,t){let n=t;for(;e.isParenthesizedExpression(n)||e.isAsExpression(n)||e.isSatisfiesExpression(n);)n=n.expression;return n}function oo(e,t,n){for(let r of t.statements){if(e.isFunctionDeclaration(r)&&r.name?.text===n)return r;if(e.isVariableStatement(r))for(let o of r.declarationList.declarations){if(!e.isIdentifier(o.name)||o.name.text!==n||!o.initializer)continue;let s=on(e,o.initializer);if(e.isArrowFunction(s)||e.isFunctionExpression(s))return s}}return null}function so(e,t,n){let r=n.parameters[0];if(!r)return{ok:!0,props:{names:[],open:!1}};if(r.type){let o=ct(e,t,r.type,new Set);if(o)return{ok:!0,props:o}}return e.isObjectBindingPattern(r.name)?{ok:!0,props:io(e,r.name)}:{ok:!1,reason:"couldn't check props against the manifest \u2014 declare the component's props as a local `interface`/`type` or destructure them in the signature"}}function ct(e,t,n,r){if(e.isTypeLiteralNode(n))return an(e,n.members);if(e.isTypeReferenceNode(n)&&e.isIdentifier(n.typeName))return sn(e,t,n.typeName.text,r);if(e.isIntersectionTypeNode(n)){let o=n.types.map(s=>ct(e,t,s,r));return o.every(s=>s===null)?null:ln(o.map(s=>s??{names:[],open:!0}))}return null}function sn(e,t,n,r){if(r.has(n))return{names:[],open:!1};r.add(n);for(let o of t.statements){if(e.isInterfaceDeclaration(o)&&o.name.text===n){let s=an(e,o.members),i=(o.heritageClauses??[]).flatMap(a=>a.types.map(l=>e.isIdentifier(l.expression)?sn(e,t,l.expression.text,r)??{names:[],open:!0}:{names:[],open:!0}));return ln([s,...i])}if(e.isTypeAliasDeclaration(o)&&o.name.text===n)return ct(e,t,o.type,r)}return null}function an(e,t){let n=[],r=!1;for(let o of t){if(e.isIndexSignatureDeclaration(o)){r=!0;continue}if(!e.isPropertySignature(o)&&!e.isMethodSignature(o))continue;let s=cn(e,o.name);if(s===null){r=!0;continue}n.push(s)}return{names:n,open:r}}function io(e,t){let n=[],r=!1;for(let o of t.elements){if(o.dotDotDotToken){r=!0;continue}let s=o.propertyName??o.name,i=cn(e,s);i===null?r=!0:n.push(i)}return{names:n,open:r}}function cn(e,t){return e.isIdentifier(t)||e.isStringLiteral(t)?t.text:null}function ln(e){let t=[],n=!1;for(let r of e){for(let o of r.names)t.includes(o)||t.push(o);n||=r.open}return{names:t,open:n}}function fn(e){let{root:t,name:n}=e,r=U.join(t,"components",n),o=e.manifestPath??U.join(r,"manifest.json"),s=e.sourcePath??U.join(r,"component.tsx"),i=lt(t,o),a=lt(t,s),l=[],c=null,p=un(o);if(p===null)l.push({severity:"error",rule:"manifest/missing",file:i,message:"manifest not found."});else try{let d=JSON.parse(p);!d||typeof d!="object"||Array.isArray(d)?l.push({severity:"error",rule:"manifest/invalid",file:i,message:"manifest must be a JSON object."}):c=d}catch(d){l.push({severity:"error",rule:"manifest/invalid",file:i,message:`manifest is not valid JSON: ${d.message}`})}let u=un(s),m=u===null?{ok:!1,reason:`couldn't check props against the manifest \u2014 ${a} not found`}:tn(t,s,u),S=u===null?!1:nn(t,s,u);return{ctx:{name:n,manifestFile:i,sourceFile:a,manifest:c,props:m,usesWindowGreatStore:S,styleFile:lt(t,U.join(r,"style.css")),stylesheet:N(r)},diagnostics:l}}function un(e){try{return pn.readFileSync(e,"utf8")}catch{return null}}function lt(e,t){let n=U.relative(e,t);return n.startsWith("..")?t:n.split(U.sep).join("/")}var dn=new Set(["onSendMessage","onClose","onUpdateModelContext","onShowLightbox","onGenerateStructuredContent","useVoiceCall","storeData","Image"]);var mn=new Map([["onError",'prop `onError` is deprecated and no longer provided \u2014 prefer an async component to report failures. Drop the prop; see the "Async components" section in AGENTS.md for how to signal errors.']]);function hn(e){if(!e.manifest)return[];let t=co(e.manifest.inputSchema);if(t===null)return[];if(!e.props.ok)return[{severity:"warning",rule:"props/not-analyzable",file:e.sourceFile,message:`${e.props.reason}.`}];if(e.props.props.open)return[];let n=new Set(e.props.props.names),r=new Set(t),o=[];for(let i of e.props.props.names){if(dn.has(i))continue;let a=mn.get(i);if(a){o.push({severity:"warning",rule:"props/retired-lifecycle",file:e.sourceFile,message:a});continue}r.has(i)||o.push({severity:"warning",rule:"props/undeclared",file:e.sourceFile,message:`prop \`${i}\` is not declared in ${e.manifestFile}#inputSchema.properties, so nothing will ever pass it. Declare it in the schema, or drop it from the component.`})}let s=t.filter(i=>!n.has(i));return s.length>0&&o.push({severity:"error",rule:"props/missing",file:e.sourceFile,message:ao(e.manifestFile,s)}),o}var gn=8;function ao(e,t){if(t.length===1){let[s]=t;return`${e} declares inputSchema field \`${s}\`, but the component does not accept a \`${s}\` prop. Add it to the component's props, or remove it from the schema.`}let n=t.slice(0,gn).map(s=>`\`${s}\``).join(", "),r=t.length-gn,o=r>0?`${n} (+${r} more)`:n;return`${e} declares ${t.length} inputSchema fields the component does not accept: ${o}. Add them to the component's props, or remove them from the schema.`}function co(e){if(!e||typeof e!="object")return null;let t=e.properties;return!t||typeof t!="object"||Array.isArray(t)?null:Object.keys(t)}var lo=["anyOf","oneOf","allOf","$ref","not"];function Be(e,t,n){if(Array.isArray(e)){e.forEach((s,i)=>Be(s,`${t}[${i}]`,n));return}if(!e||typeof e!="object")return;let r=e;for(let s of lo)s in r&&n.unionPaths.push(`${t}.${s}`);let o=r.properties;if(o&&typeof o=="object"&&!Array.isArray(o))for(let[s,i]of Object.entries(o))n.fields+=1,Be(i,`${t}.${s}`,n);"items"in r&&Be(r.items,`${t}[]`,n)}function yn(e){let t=e.manifest?.inputSchema;if(!t||typeof t!="object")return[];let n={bytes:Buffer.byteLength(JSON.stringify(t),"utf8"),fields:0,unionPaths:[]};Be(t,"inputSchema",n);let r=[];if(n.unionPaths.length>0){let o=n.unionPaths.slice(0,3).join(", "),s=n.unionPaths.length>3?` (+${n.unionPaths.length-3} more)`:"";r.push(`uses ${o}${s} \u2014 declare exactly one type per field; accept alternate shapes in component code instead`)}return n.bytes>8192&&r.push(`is ${(n.bytes/1024).toFixed(1)} KB serialized (limit ${8192/1024} KB)`),n.fields>50&&r.push(`declares ${n.fields} fields (limit 50)`),r.length===0?[]:[{severity:"error",rule:"manifest/input-schema-too-complex",file:e.manifestFile,message:`inputSchema ${r.join("; ")}.
88
88
  A schema this complex is usually a sign the component is overengineered, and the agent will fill it unreliably or stop calling the tool altogether. Keep it to a small set of flat, single-type fields (one canonical name per concept \u2014 no aliases), and let component code handle formatting, fallbacks, and edge cases.`}]}function wn(e){let t=e.manifest?.name;return typeof t!="string"||t===e.name?[]:[{severity:"error",rule:"manifest/name-mismatch",file:e.manifestFile,message:`manifest name "${t}" does not match folder name "${e.name}".`}]}function Sn(e){return e.usesWindowGreatStore?[{severity:"warning",rule:"globals/window-greatstore",file:e.sourceFile,message:"this component reads `window.GreatStore`, the host-page embed API. Components should interact with GreatStore through their injected lifecycle props (`onSendMessage`, `onGenerateStructuredContent`, \u2026) instead \u2014 those are wired to the surface the component is mounted in."}]:[]}function bn(e){return e.stylesheet.problems.map(t=>({severity:"error",rule:"stylesheet/invalid",file:t.file==="component.tsx"?e.sourceFile:e.styleFile,message:t.message}))}function ve(e){return e.filter(t=>t.severity==="error")}function ut(e){return e.filter(t=>t.severity==="warning")}function $e(e){return`${e.severity==="error"?"error":"warning"} ${e.file}: ${e.message}`}var uo=[wn,yn,hn,Sn,bn];function De(e){let{ctx:t,diagnostics:n}=fn(e);for(let r of uo)n.push(...r(t));return{diagnostics:n,ok:ve(n).length===0}}var G="components";async function He(e){let t=process.cwd();if(!$.existsSync(h.join(t,"package.json"))||!$.existsSync(h.join(t,G)))throw new Error(`\`npx greatstore apps build\` must run from a project root (contains \`package.json\` and \`${G}/\`). Current dir: ${t}`);let n=go(t);if(n.length===0)return process.stdout.write(`(no components in ./${G} \u2014 run \`npx greatstore apps init <name>\` to add one)
89
89
  `),[];let r=e.positional[0],o=r?n.filter(l=>l===r):n;if(r&&o.length===0)throw new Error(`No component named "${r}" in ./${G}`);let s=[],i=[];for(let l of o){let c=De({root:t,name:l});for(let p of c.diagnostics)process.stdout.write(` ${$e(p)}
90
90
  `);(c.ok?i:s).push(l)}if(i.length===0)return process.stdout.write(`
@@ -98,22 +98,22 @@ Not built (fix the errors above): ${s.join(", ")}
98
98
  `);return}if(r.components.length===0){process.stdout.write(`(no components in ${t})
99
99
  `);return}let o=r.components.map(a=>({name:a.name,draft:a.draft?`v${a.draft.version}`:"\u2014",live:a.live?`v${a.live.version}`:"\u2014",updated:a.live?.updatedAt??a.draft?.updatedAt??"",permalink:a.permalink??""})),s={name:Math.max(4,...o.map(a=>a.name.length)),draft:Math.max(5,...o.map(a=>a.draft.length)),live:Math.max(4,...o.map(a=>a.live.length)),updated:Math.max(7,...o.map(a=>a.updated.length))},i=`${z("NAME",s.name)} ${z("DRAFT",s.draft)} ${z("LIVE",s.live)} ${z("UPDATED",s.updated)} LINK`;process.stdout.write(i+`
100
100
  `);for(let a of o)process.stdout.write(`${z(a.name,s.name)} ${z(a.draft,s.draft)} ${z(a.live,s.live)} ${z(a.updated,s.updated)} ${a.permalink}
101
- `)}function z(e,t){return e.length>=t?e:e+" ".repeat(t-e.length)}import*as R from"fs";import*as V from"path";import*as Pn from"crypto";import*as X from"fs";import*as q from"path";var En=".gssync.json";function Q(e){return Pn.createHash("sha256").update(e).digest("hex")}function fe(e){return X.existsSync(e)?Q(X.readFileSync(e,"utf8")):null}function de(e){let t=fe(q.join(e,"manifest.json"));if(t===null)throw new Error(`Missing manifest.json in ${e}`);return{manifestHash:t,sourceHash:fe(q.join(e,"component.tsx")),bundleHash:fe(q.join(e,"bundle.js")),...N(e).imported?{styleHash:fe(q.join(e,x)),styleBundleHash:fe(q.join(e,_))}:{styleHash:null,styleBundleHash:null}}}function me(e){let t=q.join(e,En);if(!X.existsSync(t))return null;try{let n=JSON.parse(X.readFileSync(t,"utf8"));return typeof n.version=="number"&&typeof n.manifestHash=="string"&&typeof n.sourceHash=="string"?{version:n.version,manifestHash:n.manifestHash,sourceHash:n.sourceHash,...typeof n.bundleHash=="string"?{bundleHash:n.bundleHash}:{},...typeof n.styleHash=="string"?{styleHash:n.styleHash}:{},...typeof n.styleBundleHash=="string"?{styleBundleHash:n.styleBundleHash}:{}}:null}catch{return null}}function oe(e,t){X.writeFileSync(q.join(e,En),JSON.stringify(t,null,2)+`
102
- `)}function Cn(e,t){let n=So(e);if(!n)return!1;if(t===null||n.manifestHash!==t.manifestHash)return!0;let r=n.sourceHash??"",o=t.sourceHash??"";return r!==o?!0:(fe(q.join(e,x))??"")!==(t.styleHash??"")}function So(e){try{return de(e)}catch{return null}}async function jn(e){let t=P(),n=g(e.flags,"force"),r=e.positional,o=process.cwd();if(r.length===0||r.length===1&&r[0]==="*")return bo({slug:t,root:o,args:e,force:n});if(r.length>1&&b(e.flags,"version"))throw new Error("--version is per-component; pass it together with a single `npx greatstore apps pull <name>`.");Rn(o);let s=Tn(e),i=[];for(let a of r){let l=await _n({slug:t,componentDir:V.join(o,"components",a),name:a,revisionQuery:s,force:n});i.push(l),Ln(l,n)}i.length>1&&An(i,t),i.some(a=>a.status==="failed")&&(process.exitCode=1)}async function bo(e){let{slug:t,root:n,args:r,force:o}=e;if(b(r.flags,"version"))throw new Error("--version is per-component; pass it together with `npx greatstore apps pull <name>`.");Rn(n);let s=Tn(r),i=`${A(t)}/api/apps/components`,a=await f(i);if(a.components.length===0){process.stdout.write(`(no components in ${t})
103
- `);return}let l=[];for(let c of a.components){let p=V.join(n,"components",c.name),u=await _n({slug:t,componentDir:p,name:c.name,revisionQuery:s===""&&c.live===null?"?revision=draft":s,force:o});l.push(u),Ln(u,o)}An(l,t),l.some(c=>c.status==="failed")&&(process.exitCode=1)}function An(e,t){let n=e.filter(i=>i.status==="pulled").length,r=e.filter(i=>i.status==="skipped").length,o=e.filter(i=>i.status==="failed").length,s=[`${n} pulled`,`${r} skipped`];o>0&&s.push(`${o} failed`),process.stdout.write(`
101
+ `)}function z(e,t){return e.length>=t?e:e+" ".repeat(t-e.length)}import*as R from"fs";import*as q from"path";import*as Pn from"crypto";import*as X from"fs";import*as V from"path";var En=".gssync.json";function Q(e){return Pn.createHash("sha256").update(e).digest("hex")}function fe(e){return X.existsSync(e)?Q(X.readFileSync(e,"utf8")):null}function de(e){let t=fe(V.join(e,"manifest.json"));if(t===null)throw new Error(`Missing manifest.json in ${e}`);return{manifestHash:t,sourceHash:fe(V.join(e,"component.tsx")),bundleHash:fe(V.join(e,"bundle.js")),...N(e).imported?{styleHash:fe(V.join(e,x)),styleBundleHash:fe(V.join(e,_))}:{styleHash:null,styleBundleHash:null}}}function me(e){let t=V.join(e,En);if(!X.existsSync(t))return null;try{let n=JSON.parse(X.readFileSync(t,"utf8"));return typeof n.version=="number"&&typeof n.manifestHash=="string"&&typeof n.sourceHash=="string"?{version:n.version,manifestHash:n.manifestHash,sourceHash:n.sourceHash,...typeof n.bundleHash=="string"?{bundleHash:n.bundleHash}:{},...typeof n.styleHash=="string"?{styleHash:n.styleHash}:{},...typeof n.styleBundleHash=="string"?{styleBundleHash:n.styleBundleHash}:{}}:null}catch{return null}}function oe(e,t){X.writeFileSync(V.join(e,En),JSON.stringify(t,null,2)+`
102
+ `)}function Cn(e,t){let n=So(e);if(!n)return!1;if(t===null||n.manifestHash!==t.manifestHash)return!0;let r=n.sourceHash??"",o=t.sourceHash??"";return r!==o?!0:(fe(V.join(e,x))??"")!==(t.styleHash??"")}function So(e){try{return de(e)}catch{return null}}async function jn(e){let t=P(),n=g(e.flags,"force"),r=e.positional,o=process.cwd();if(r.length===0||r.length===1&&r[0]==="*")return bo({slug:t,root:o,args:e,force:n});if(r.length>1&&b(e.flags,"version"))throw new Error("--version is per-component; pass it together with a single `npx greatstore apps pull <name>`.");Rn(o);let s=Tn(e),i=[];for(let a of r){let l=await _n({slug:t,componentDir:q.join(o,"components",a),name:a,revisionQuery:s,force:n});i.push(l),Ln(l,n)}i.length>1&&An(i,t),i.some(a=>a.status==="failed")&&(process.exitCode=1)}async function bo(e){let{slug:t,root:n,args:r,force:o}=e;if(b(r.flags,"version"))throw new Error("--version is per-component; pass it together with `npx greatstore apps pull <name>`.");Rn(n);let s=Tn(r),i=`${A(t)}/api/apps/components`,a=await f(i);if(a.components.length===0){process.stdout.write(`(no components in ${t})
103
+ `);return}let l=[];for(let c of a.components){let p=q.join(n,"components",c.name),u=await _n({slug:t,componentDir:p,name:c.name,revisionQuery:s===""&&c.live===null?"?revision=draft":s,force:o});l.push(u),Ln(u,o)}An(l,t),l.some(c=>c.status==="failed")&&(process.exitCode=1)}function An(e,t){let n=e.filter(i=>i.status==="pulled").length,r=e.filter(i=>i.status==="skipped").length,o=e.filter(i=>i.status==="failed").length,s=[`${n} pulled`,`${r} skipped`];o>0&&s.push(`${o} failed`),process.stdout.write(`
104
104
  ${s.join(", ")} (of ${e.length}) \u2190 ${t}
105
105
  `)}async function _n(e){let{slug:t,componentDir:n,name:r,revisionQuery:o,force:s}=e;if(!s&&R.existsSync(n)){let d=me(n);if(Cn(n,d))return{name:r,status:"skipped",message:"local has uncommitted changes; pass --force to overwrite"}}let i=`${A(t)}/api/apps/components/${encodeURIComponent(r)}`,a;try{a=await f(`${i}${o}`)}catch(d){if(o===""&&xo(d))try{a=await f(`${i}?revision=draft`)}catch(se){return{name:r,status:"failed",message:se instanceof Error?se.message:String(se)}}else return{name:r,status:"failed",message:d instanceof Error?d.message:String(d)}}R.mkdirSync(n,{recursive:!0});let l=JSON.stringify(a.manifest,null,2)+`
106
- `;R.writeFileSync(V.join(n,"manifest.json"),l),R.writeFileSync(V.join(n,"bundle.js"),a.bundle);let c=["manifest.json","bundle.js"],p="";a.source!==null&&(R.writeFileSync(V.join(n,"component.tsx"),a.source),c.push("component.tsx"),p=Q(a.source));let u=V.join(n,x),m=V.join(n,_);typeof a.style=="string"?(R.writeFileSync(u,a.style),R.writeFileSync(m,a.style_bundle??a.style),c.push(x,_)):(R.rmSync(u,{force:!0}),R.rmSync(m,{force:!0})),oe(n,{version:a.version,manifestHash:Q(l),sourceHash:p,bundleHash:Q(a.bundle)});let S=de(n);return oe(n,{version:a.version,manifestHash:S.manifestHash,sourceHash:S.sourceHash??"",bundleHash:S.bundleHash??"",styleHash:S.styleHash??"",styleBundleHash:S.styleBundleHash??""}),{name:r,status:"pulled",version:a.version,wrote:c}}function Rn(e){R.mkdirSync(V.join(e,"components"),{recursive:!0})}function xo(e){return e instanceof D&&e.status===404}function Tn(e){let t=b(e.flags,"version");return t?`?version=${encodeURIComponent(t)}`:g(e.flags,"draft")?"?revision=draft":g(e.flags,"live")?"?revision=live":""}function Ln(e,t){switch(e.status){case"pulled":{let n=e.wrote?`{${e.wrote.join(", ")}}`:"";process.stdout.write(` pulled ${e.name} v${e.version} ${n}
106
+ `;R.writeFileSync(q.join(n,"manifest.json"),l),R.writeFileSync(q.join(n,"bundle.js"),a.bundle);let c=["manifest.json","bundle.js"],p="";a.source!==null&&(R.writeFileSync(q.join(n,"component.tsx"),a.source),c.push("component.tsx"),p=Q(a.source));let u=q.join(n,x),m=q.join(n,_);typeof a.style=="string"?(R.writeFileSync(u,a.style),R.writeFileSync(m,a.style_bundle??a.style),c.push(x,_)):(R.rmSync(u,{force:!0}),R.rmSync(m,{force:!0})),oe(n,{version:a.version,manifestHash:Q(l),sourceHash:p,bundleHash:Q(a.bundle)});let S=de(n);return oe(n,{version:a.version,manifestHash:S.manifestHash,sourceHash:S.sourceHash??"",bundleHash:S.bundleHash??"",styleHash:S.styleHash??"",styleBundleHash:S.styleBundleHash??""}),{name:r,status:"pulled",version:a.version,wrote:c}}function Rn(e){R.mkdirSync(q.join(e,"components"),{recursive:!0})}function xo(e){return e instanceof D&&e.status===404}function Tn(e){let t=b(e.flags,"version");return t?`?version=${encodeURIComponent(t)}`:g(e.flags,"draft")?"?revision=draft":g(e.flags,"live")?"?revision=live":""}function Ln(e,t){switch(e.status){case"pulled":{let n=e.wrote?`{${e.wrote.join(", ")}}`:"";process.stdout.write(` pulled ${e.name} v${e.version} ${n}
107
107
  `);return}case"skipped":process.stdout.write(` skipped ${e.name}: ${e.message}
108
108
  `);return;case"failed":process.stdout.write(` failed ${e.name}: ${e.message??"unknown error"}
109
- `);return}}import*as w from"fs";import*as k from"path";import*as On from"crypto";import*as Me from"fs";import*as In from"path";function Ue(e){let t=e?.screenshots;return Array.isArray(t)?[...new Set(t.filter(n=>typeof n=="string"))]:null}function vo(e){return e.subarray(1,4).toString("latin1")==="PNG"?"png":e[0]===255&&e[1]===216?"jpg":e.subarray(0,4).toString("latin1")==="RIFF"&&e.subarray(8,12).toString("latin1")==="WEBP"?"webp":null}function Fn(e){let t=vo(e);return t?`${On.createHash("sha256").update(e).digest("hex").slice(0,16)}.${t}`:null}function Ge(e,t){let n=In.join(e,t);return Me.existsSync(n)?Me.readFileSync(n):null}async function Dn(e){let t=P(),n=process.cwd();$o(n);let r=k.join(n,"components");if(!w.existsSync(r))throw new Error("No components/ directory here. Run `npx greatstore apps init <name>` to scaffold the project root and your first component.");let o=e.positional,s=b(e.flags,"manifest"),i=b(e.flags,"bundle");if(o.length!==1&&(s||i))throw new Error("--manifest / --bundle can only be used together with a single `npx greatstore apps push <name>`.");if(o.length>0){let c=g(e.flags,"force")||s!==void 0||i!==void 0,p=[];for(let u of o){let m=await Ve({slug:t,root:n,name:u,...s!==void 0?{manifestPath:s}:{},...i!==void 0?{bundlePath:i}:{},force:c});p.push(m),Bn(m)}p.length>1&&Nn(p,t),p.some(u=>u.status==="failed")&&(process.exitCode=1);return}let a=pt(r);if(a.length===0){process.stdout.write("(no components in ./components \u2014 run `npx greatstore apps init <name>` to add one)\n");return}let l=[];for(let c of a){let p=await Ve({slug:t,root:n,name:c,force:!1});l.push(p),Bn(p)}Nn(l,t),l.some(c=>c.status==="failed")&&(process.exitCode=1)}function Nn(e,t){let n=e.filter(i=>i.status==="pushed").length,r=e.filter(i=>i.status==="unchanged").length,o=e.filter(i=>i.status==="failed").length,s=[`${n} pushed`,`${r} unchanged`];o>0&&s.push(`${o} failed`),process.stdout.write(`
109
+ `);return}}import*as w from"fs";import*as k from"path";import*as On from"crypto";import*as Me from"fs";import*as In from"path";function Ue(e){let t=e?.screenshots;return Array.isArray(t)?[...new Set(t.filter(n=>typeof n=="string"))]:null}function vo(e){return e.subarray(1,4).toString("latin1")==="PNG"?"png":e[0]===255&&e[1]===216?"jpg":e.subarray(0,4).toString("latin1")==="RIFF"&&e.subarray(8,12).toString("latin1")==="WEBP"?"webp":null}function Fn(e){let t=vo(e);return t?`${On.createHash("sha256").update(e).digest("hex").slice(0,16)}.${t}`:null}function Ge(e,t){let n=In.join(e,t);return Me.existsSync(n)?Me.readFileSync(n):null}async function Dn(e){let t=P(),n=process.cwd();$o(n);let r=k.join(n,"components");if(!w.existsSync(r))throw new Error("No components/ directory here. Run `npx greatstore apps init <name>` to scaffold the project root and your first component.");let o=e.positional,s=b(e.flags,"manifest"),i=b(e.flags,"bundle");if(o.length!==1&&(s||i))throw new Error("--manifest / --bundle can only be used together with a single `npx greatstore apps push <name>`.");if(o.length>0){let c=g(e.flags,"force")||s!==void 0||i!==void 0,p=[];for(let u of o){let m=await qe({slug:t,root:n,name:u,...s!==void 0?{manifestPath:s}:{},...i!==void 0?{bundlePath:i}:{},force:c});p.push(m),Bn(m)}p.length>1&&Nn(p,t),p.some(u=>u.status==="failed")&&(process.exitCode=1);return}let a=pt(r);if(a.length===0){process.stdout.write("(no components in ./components \u2014 run `npx greatstore apps init <name>` to add one)\n");return}let l=[];for(let c of a){let p=await qe({slug:t,root:n,name:c,force:!1});l.push(p),Bn(p)}Nn(l,t),l.some(c=>c.status==="failed")&&(process.exitCode=1)}function Nn(e,t){let n=e.filter(i=>i.status==="pushed").length,r=e.filter(i=>i.status==="unchanged").length,o=e.filter(i=>i.status==="failed").length,s=[`${n} pushed`,`${r} unchanged`];o>0&&s.push(`${o} failed`),process.stdout.write(`
110
110
  ${s.join(", ")} (of ${e.length}) \u2192 ${t}
111
- `)}async function Ve(e){let{slug:t,root:n,name:r,force:o}=e,s=k.join(n,"components",r);if(!w.existsSync(s))return{name:r,status:"failed",message:`components/${r}/ does not exist`};let i=e.manifestPath?k.resolve(e.manifestPath):k.join(s,"manifest.json"),a=e.bundlePath?k.resolve(e.bundlePath):k.join(s,"bundle.js"),l=k.join(s,"component.tsx");if(!w.existsSync(a))return{name:r,status:"failed",message:`bundle not found: ${a} (did you run \`npm run build\`?)`};let c=De({root:n,name:r,manifestPath:i,sourcePath:l});for(let L of ut(c.diagnostics))process.stdout.write(` ${$e(L)}
111
+ `)}async function qe(e){let{slug:t,root:n,name:r,force:o}=e,s=k.join(n,"components",r);if(!w.existsSync(s))return{name:r,status:"failed",message:`components/${r}/ does not exist`};let i=e.manifestPath?k.resolve(e.manifestPath):k.join(s,"manifest.json"),a=e.bundlePath?k.resolve(e.bundlePath):k.join(s,"bundle.js"),l=k.join(s,"component.tsx");if(!w.existsSync(a))return{name:r,status:"failed",message:`bundle not found: ${a} (did you run \`npm run build\`?)`};let c=De({root:n,name:r,manifestPath:i,sourcePath:l});for(let L of ut(c.diagnostics))process.stdout.write(` ${$e(L)}
112
112
  `);if(!c.ok)return{name:r,status:"failed",message:ve(c.diagnostics).map(L=>`${L.file}: ${L.message}`).join(`
113
- ${qe}`)};let p=w.readFileSync(i,"utf8"),u=k.join(s,"listing.json"),m=be(t);if(m&&!w.existsSync(u))return{name:r,status:"failed",message:`components/${r}/listing.json is required for a library app`};let S=de(s),d=me(s),se=e.bundlePath===void 0&&d?.bundleHash!==void 0&&d.sourceHash!==(S.sourceHash??"")&&d.bundleHash===(S.bundleHash??""),Pe=d?.styleBundleHash!==void 0&&(d.styleHash??"")!==(S.styleHash??"")&&d.styleBundleHash===(S.styleBundleHash??""),gt=N(s).imported,ht=k.join(s,_);if(gt&&!w.existsSync(ht))return{name:r,status:"failed",message:`components/${r}/${_} is missing \u2014 run \`npx greatstore build ${r}\` first`};if(!o&&d!==null&&d.manifestHash===S.manifestHash&&d.sourceHash===(S.sourceHash??"")&&d.bundleHash!==void 0&&d.bundleHash===(S.bundleHash??"")&&(d.styleHash??"")===(S.styleHash??"")&&(d.styleBundleHash??"")===(S.styleBundleHash??""))return{name:r,status:"unchanged"};let fr=w.readFileSync(a,"utf8"),yt=w.existsSync(l)?w.readFileSync(l,"utf8"):null,B=new FormData;if(B.append("manifest",new Blob([p],{type:"application/json"}),"manifest.json"),B.append("bundle",new Blob([fr],{type:"text/javascript"}),"bundle.js"),yt!==null&&B.append("source",new Blob([yt],{type:"text/plain; charset=utf-8"}),"component.tsx"),gt&&(B.append("style",new Blob([w.readFileSync(ht,"utf8")],{type:"text/css; charset=utf-8"}),_),B.append("style_source",new Blob([w.readFileSync(k.join(s,x),"utf8")],{type:"text/css; charset=utf-8"}),x)),m){let L=w.readFileSync(u,"utf8");B.append("listing",new Blob([L],{type:"application/json"}),"listing.json");let wt=k.join(s,"changelog.json");w.existsSync(wt)&&B.append("changelog",new Blob([w.readFileSync(wt,"utf8")],{type:"application/json"}),"changelog.json");let St=null;try{St=Ue(JSON.parse(L))}catch{}for(let Qe of St??[]){let bt=Ge(s,Qe);if(!bt)return{name:r,status:"failed",message:`components/${r}/${Qe} is named in listing.json but doesn't exist`};B.append("screenshot",new Blob([new Uint8Array(bt)]),Qe)}}o||B.append("base_version",String(d?.version??0));let dr=`${Le(t)}/components/${encodeURIComponent(r)}`,ie;try{ie=await f(dr,{method:"POST",multipart:B})}catch(L){return{name:r,status:"failed",message:L instanceof Error?L.message:String(L)}}let Se=de(s);return oe(s,{version:ie.version,manifestHash:Se.manifestHash,sourceHash:Se.sourceHash??"",bundleHash:Se.bundleHash??"",styleHash:Se.styleHash??"",styleBundleHash:Se.styleBundleHash??""}),{name:r,status:"pushed",version:ie.version,...ie.permalink!==void 0&&{permalink:ie.permalink},...ie.detached&&{detached:!0},...se?{staleBundle:!0}:{},...Pe?{staleStyle:!0}:{}}}function pt(e){return w.readdirSync(e).filter(t=>{let n=k.join(e,t);return w.statSync(n).isDirectory()&&w.existsSync(k.join(n,"manifest.json"))}).sort()}function $o(e){let t=k.join(e,"manifest.json"),n=k.join(e,"components");if(w.existsSync(t)&&!w.existsSync(n))throw new Error(["Detected the old single-component layout (manifest.json at the project root).","The CLI now uses a multi-component layout: scaffold a fresh dir with","`npx greatstore apps init`, then move your component into `components/<name>/`. Re-run `npx greatstore apps push`","from the new project root."].join(" "))}var qe=" ".repeat(12);function Bn(e){switch(e.status){case"pushed":process.stdout.write(` pushed ${e.name} v${e.version}${e.permalink?` \u2192 ${e.permalink}`:""}
114
- `),e.detached&&process.stdout.write(`${qe}This was a ready-made app GreatStore keeps up to date. It's now your own copy and won't get those updates.
115
- `),e.staleBundle&&process.stdout.write(`${qe}component.tsx changed but bundle.js did not \u2014 did you forget to build? Run \`npx greatstore build ${e.name}\` and push again.
116
- `),e.staleStyle&&process.stdout.write(`${qe}style.css changed but bundle.css did not \u2014 did you forget to build? Run \`npx greatstore build ${e.name}\` and push again.
113
+ ${Ve}`)};let p=w.readFileSync(i,"utf8"),u=k.join(s,"listing.json"),m=be(t);if(m&&!w.existsSync(u))return{name:r,status:"failed",message:`components/${r}/listing.json is required for a library app`};let S=de(s),d=me(s),se=e.bundlePath===void 0&&d?.bundleHash!==void 0&&d.sourceHash!==(S.sourceHash??"")&&d.bundleHash===(S.bundleHash??""),Pe=d?.styleBundleHash!==void 0&&(d.styleHash??"")!==(S.styleHash??"")&&d.styleBundleHash===(S.styleBundleHash??""),gt=N(s).imported,ht=k.join(s,_);if(gt&&!w.existsSync(ht))return{name:r,status:"failed",message:`components/${r}/${_} is missing \u2014 run \`npx greatstore build ${r}\` first`};if(!o&&d!==null&&d.manifestHash===S.manifestHash&&d.sourceHash===(S.sourceHash??"")&&d.bundleHash!==void 0&&d.bundleHash===(S.bundleHash??"")&&(d.styleHash??"")===(S.styleHash??"")&&(d.styleBundleHash??"")===(S.styleBundleHash??""))return{name:r,status:"unchanged"};let fr=w.readFileSync(a,"utf8"),yt=w.existsSync(l)?w.readFileSync(l,"utf8"):null,B=new FormData;if(B.append("manifest",new Blob([p],{type:"application/json"}),"manifest.json"),B.append("bundle",new Blob([fr],{type:"text/javascript"}),"bundle.js"),yt!==null&&B.append("source",new Blob([yt],{type:"text/plain; charset=utf-8"}),"component.tsx"),gt&&(B.append("style",new Blob([w.readFileSync(ht,"utf8")],{type:"text/css; charset=utf-8"}),_),B.append("style_source",new Blob([w.readFileSync(k.join(s,x),"utf8")],{type:"text/css; charset=utf-8"}),x)),m){let L=w.readFileSync(u,"utf8");B.append("listing",new Blob([L],{type:"application/json"}),"listing.json");let wt=k.join(s,"changelog.json");w.existsSync(wt)&&B.append("changelog",new Blob([w.readFileSync(wt,"utf8")],{type:"application/json"}),"changelog.json");let St=null;try{St=Ue(JSON.parse(L))}catch{}for(let Qe of St??[]){let bt=Ge(s,Qe);if(!bt)return{name:r,status:"failed",message:`components/${r}/${Qe} is named in listing.json but doesn't exist`};B.append("screenshot",new Blob([new Uint8Array(bt)]),Qe)}}o||B.append("base_version",String(d?.version??0));let dr=`${Le(t)}/components/${encodeURIComponent(r)}`,ie;try{ie=await f(dr,{method:"POST",multipart:B})}catch(L){return{name:r,status:"failed",message:L instanceof Error?L.message:String(L)}}let Se=de(s);return oe(s,{version:ie.version,manifestHash:Se.manifestHash,sourceHash:Se.sourceHash??"",bundleHash:Se.bundleHash??"",styleHash:Se.styleHash??"",styleBundleHash:Se.styleBundleHash??""}),{name:r,status:"pushed",version:ie.version,...ie.permalink!==void 0&&{permalink:ie.permalink},...ie.detached&&{detached:!0},...se?{staleBundle:!0}:{},...Pe?{staleStyle:!0}:{}}}function pt(e){return w.readdirSync(e).filter(t=>{let n=k.join(e,t);return w.statSync(n).isDirectory()&&w.existsSync(k.join(n,"manifest.json"))}).sort()}function $o(e){let t=k.join(e,"manifest.json"),n=k.join(e,"components");if(w.existsSync(t)&&!w.existsSync(n))throw new Error(["Detected the old single-component layout (manifest.json at the project root).","The CLI now uses a multi-component layout: scaffold a fresh dir with","`npx greatstore apps init`, then move your component into `components/<name>/`. Re-run `npx greatstore apps push`","from the new project root."].join(" "))}var Ve=" ".repeat(12);function Bn(e){switch(e.status){case"pushed":process.stdout.write(` pushed ${e.name} v${e.version}${e.permalink?` \u2192 ${e.permalink}`:""}
114
+ `),e.detached&&process.stdout.write(`${Ve}This was a ready-made app GreatStore keeps up to date. It's now your own copy and won't get those updates.
115
+ `),e.staleBundle&&process.stdout.write(`${Ve}component.tsx changed but bundle.js did not \u2014 did you forget to build? Run \`npx greatstore build ${e.name}\` and push again.
116
+ `),e.staleStyle&&process.stdout.write(`${Ve}style.css changed but bundle.css did not \u2014 did you forget to build? Run \`npx greatstore build ${e.name}\` and push again.
117
117
  `);return;case"unchanged":process.stdout.write(` unchanged ${e.name}
118
118
  `);return;case"failed":process.stdout.write(` failed ${e.name}: ${e.message??"unknown error"}
119
119
  `);return}}async function Un(e){let t=e.positional;if(t.length===0)throw new Error("Usage: npx greatstore apps publish <name> [<name>...] [--version N]");let n=P(),r=b(e.flags,"version"),o;if(r!==void 0){if(t.length>1)throw new Error("--version is per-component; pass it together with a single `npx greatstore apps publish <name>`.");let c=Number.parseInt(r,10);if(!Number.isInteger(c)||c<1)throw new Error(`Invalid --version: ${r}`);o=c}if(t.length===1){let c=t[0],p=await Hn(n,c,o);process.stdout.write(`Published ${c} (v${p.live_version}). ${p.permalink}
@@ -130,13 +130,13 @@ If the GreatStore script is already on the page, the second line is enough.
130
130
  `)}function ko(e){if(e.status==="published"){process.stdout.write(` published ${e.name} v${e.version} \u2192 ${e.permalink??""}
131
131
  `);return}process.stdout.write(` failed ${e.name}: ${e.message??"unknown error"}
132
132
  `)}async function Gn(e){let t=e.positional[0];if(!t)throw new Error("Usage: npx greatstore apps unpublish <name>");let n=P(),r=`${A(n)}/api/apps/components/${encodeURIComponent(t)}/unpublish`;await f(r,{method:"POST",body:{}}),process.stdout.write(`Unpublished ${t}.
133
- `)}import*as qn from"readline";async function Vn(e){let t=e.positional[0];if(!t)throw new Error("Usage: npx greatstore apps delete <name> [--yes]");let n=P();if(!g(e.flags,"yes")&&(await Po(`Soft-delete component "${t}" in store "${n}"? Type "yes" to confirm: `)).trim()!=="yes"){process.stdout.write(`Aborted.
133
+ `)}import*as Vn from"readline";async function qn(e){let t=e.positional[0];if(!t)throw new Error("Usage: npx greatstore apps delete <name> [--yes]");let n=P();if(!g(e.flags,"yes")&&(await Po(`Soft-delete component "${t}" in store "${n}"? Type "yes" to confirm: `)).trim()!=="yes"){process.stdout.write(`Aborted.
134
134
  `);return}let r=`${A(n)}/api/apps/components/${encodeURIComponent(t)}`;await f(r,{method:"DELETE"}),process.stdout.write(`Deleted ${t}.
135
- `)}function Po(e){return new Promise(t=>{let n=qn.createInterface({input:process.stdin,output:process.stdout});n.question(e,r=>{n.close(),t(r)})})}import*as H from"fs";import*as Ke from"path";var Eo=/^[a-z][a-z0-9_]*$/;async function Kn(e){let[t,n]=e.positional;if(!t||!n||e.positional.length>2)throw new Error("Usage: npx greatstore apps rename <old-name> <new-name>");if(!Eo.test(n))throw new Error(`Invalid name "${n}": use lowercase letters, digits and underscores, starting with a letter.`);if(t===n)throw new Error(`"${t}" already has that name.`);let r=P(),o=Ke.join(process.cwd(),"components",t),s=Ke.join(process.cwd(),"components",n),i=H.existsSync(o);if(H.existsSync(s))throw new Error(`components/${n}/ already exists; move it aside first.`);let a=`${A(r)}/api/apps/components/${encodeURIComponent(t)}/rename`;if(await f(a,{method:"POST",body:{name:n}}),!i){process.stdout.write(`Renamed ${t} \u2192 ${n}.
135
+ `)}function Po(e){return new Promise(t=>{let n=Vn.createInterface({input:process.stdin,output:process.stdout});n.question(e,r=>{n.close(),t(r)})})}import*as H from"fs";import*as Ke from"path";var Eo=/^[a-z][a-z0-9_]*$/;async function Kn(e){let[t,n]=e.positional;if(!t||!n||e.positional.length>2)throw new Error("Usage: npx greatstore apps rename <old-name> <new-name>");if(!Eo.test(n))throw new Error(`Invalid name "${n}": use lowercase letters, digits and underscores, starting with a letter.`);if(t===n)throw new Error(`"${t}" already has that name.`);let r=P(),o=Ke.join(process.cwd(),"components",t),s=Ke.join(process.cwd(),"components",n),i=H.existsSync(o);if(H.existsSync(s))throw new Error(`components/${n}/ already exists; move it aside first.`);let a=`${A(r)}/api/apps/components/${encodeURIComponent(t)}/rename`;if(await f(a,{method:"POST",body:{name:n}}),!i){process.stdout.write(`Renamed ${t} \u2192 ${n}.
136
136
  `);return}H.renameSync(o,s),Co(s,n),process.stdout.write(`Renamed ${t} \u2192 ${n}, including components/${n}/.
137
137
  `)}function Co(e,t){let n=Ke.join(e,"manifest.json");if(!H.existsSync(n))return;let r=H.readFileSync(n,"utf8"),o=JSON.stringify({...JSON.parse(r),name:t},null,2)+`
138
138
  `;H.writeFileSync(n,o);let s=me(e);s&&s.manifestHash===Q(r)&&oe(e,{...s,manifestHash:Q(o)})}import*as Z from"fs";import*as ke from"path";async function Jn(e){let t=P();if(!be(t))throw new Error("`npx greatstore apps release` runs only in the app library's folder.");let n=rt();Rt(await To(new URL(n).origin));let r=await He({command:"build",positional:[],flags:{}});process.exitCode=0;let o=process.cwd(),s=Le(t),i=ke.join(o,"components"),a=pt(i),l=Z.readdirSync(i).filter(u=>Z.statSync(ke.join(i,u)).isDirectory()),c=(await f(`${s}/components`)).components.filter(u=>u.live!==null).map(u=>u.name),p=[];for(let u of a)p.push(r.includes(u)?{name:u,status:"failed",message:"didn't build; see the errors above"}:await jo(s,o,t,u));for(let u of l.filter(m=>!a.includes(m)))p.push({name:u,status:"failed",message:`components/${u}/manifest.json is missing`});for(let u of c.filter(m=>!l.includes(m)))try{await f(`${s}/components/${encodeURIComponent(u)}/unpublish`,{method:"POST",body:{}}),p.push({name:u,status:"unpublished"})}catch(m){p.push({name:u,status:"failed",message:Wn(m)})}for(let u of p){let m=u.status==="published"?` v${u.version}`:u.status==="failed"?`: ${u.message}`:"";process.stdout.write(` ${u.status.padEnd(11)} ${u.name}${m}
139
- `)}p.some(u=>u.status==="failed")&&(process.exitCode=1)}async function jo(e,t,n,r){try{let o=await Ao(e,r);if(o&&_o(o,ke.join(t,"components",r)))return{name:r,status:"unchanged"};let s=await Ve({slug:n,root:t,name:r,force:!0});return s.status!=="pushed"||s.version===void 0?{name:r,status:"failed",message:s.message??"push failed"}:(await f(`${e}/components/${encodeURIComponent(r)}/publish`,{method:"POST",body:{version:s.version},validationDetail:!0}),{name:r,status:"published",version:s.version})}catch(o){return{name:r,status:"failed",message:Wn(o)}}}async function Ao(e,t){try{return await f(`${e}/components/${encodeURIComponent(t)}?revision=live`)}catch(n){if(n instanceof D&&n.status===404)return null;throw n}}function _o(e,t){let n=i=>{let a=ke.join(t,i);return Z.existsSync(a)?Z.readFileSync(a,"utf8"):null},r=n("manifest.json"),o=n("listing.json"),s=n("changelog.json");if(r===null||o===null)return!1;try{return e.bundle===n("bundle.js")&&e.source===n("component.tsx")&&(e.style??null)===(N(t).imported?n(x):null)&&(e.style_bundle??e.style??null)===(N(t).imported?n(_):null)&&ge(e.manifest)===ge(JSON.parse(r))&&ge(e.listing)===ge(Ro(JSON.parse(o),t))&&ge(e.changelog??null)===ge(s===null?null:Je(JSON.parse(s)))}catch{return!1}}function Ro(e,t){let n=Je(e),r=Ue(n);return r?{...n,screenshots:r.map(o=>{let s=Ge(t,o);return(s&&Fn(s))??o})}:n}function Je(e){return typeof e=="string"?e.trim():Array.isArray(e)?e.map(Je):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([t,n])=>[t,Je(n)])):e}function ge(e){return JSON.stringify(e,(t,n)=>n&&typeof n=="object"&&!Array.isArray(n)?Object.fromEntries(Object.entries(n).sort(([r],[o])=>r.localeCompare(o))):n)}async function To(e){let t=process.env.ACTIONS_ID_TOKEN_REQUEST_URL,n=process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;if(!t||!n)throw new Error("`npx greatstore apps release` isn't available here.");let r=await fetch(`${t}&audience=${encodeURIComponent(e)}`,{headers:{authorization:`Bearer ${n}`}}),o=await r.json().catch(()=>null);if(!r.ok||typeof o?.value!="string")throw new Error("Sign-in needed.");return o.value}function Wn(e){return e instanceof Error?e.message:String(e)}var Yn=`npx greatstore apps \u2014 author and ship custom in-chat apps
139
+ `)}p.some(u=>u.status==="failed")&&(process.exitCode=1)}async function jo(e,t,n,r){try{let o=await Ao(e,r);if(o&&_o(o,ke.join(t,"components",r)))return{name:r,status:"unchanged"};let s=await qe({slug:n,root:t,name:r,force:!0});return s.status!=="pushed"||s.version===void 0?{name:r,status:"failed",message:s.message??"push failed"}:(await f(`${e}/components/${encodeURIComponent(r)}/publish`,{method:"POST",body:{version:s.version},validationDetail:!0}),{name:r,status:"published",version:s.version})}catch(o){return{name:r,status:"failed",message:Wn(o)}}}async function Ao(e,t){try{return await f(`${e}/components/${encodeURIComponent(t)}?revision=live`)}catch(n){if(n instanceof D&&n.status===404)return null;throw n}}function _o(e,t){let n=i=>{let a=ke.join(t,i);return Z.existsSync(a)?Z.readFileSync(a,"utf8"):null},r=n("manifest.json"),o=n("listing.json"),s=n("changelog.json");if(r===null||o===null)return!1;try{return e.bundle===n("bundle.js")&&e.source===n("component.tsx")&&(e.style??null)===(N(t).imported?n(x):null)&&(e.style_bundle??e.style??null)===(N(t).imported?n(_):null)&&ge(e.manifest)===ge(JSON.parse(r))&&ge(e.listing)===ge(Ro(JSON.parse(o),t))&&ge(e.changelog??null)===ge(s===null?null:Je(JSON.parse(s)))}catch{return!1}}function Ro(e,t){let n=Je(e),r=Ue(n);return r?{...n,screenshots:r.map(o=>{let s=Ge(t,o);return(s&&Fn(s))??o})}:n}function Je(e){return typeof e=="string"?e.trim():Array.isArray(e)?e.map(Je):e&&typeof e=="object"?Object.fromEntries(Object.entries(e).map(([t,n])=>[t,Je(n)])):e}function ge(e){return JSON.stringify(e,(t,n)=>n&&typeof n=="object"&&!Array.isArray(n)?Object.fromEntries(Object.entries(n).sort(([r],[o])=>r.localeCompare(o))):n)}async function To(e){let t=process.env.ACTIONS_ID_TOKEN_REQUEST_URL,n=process.env.ACTIONS_ID_TOKEN_REQUEST_TOKEN;if(!t||!n)throw new Error("`npx greatstore apps release` isn't available here.");let r=await fetch(`${t}&audience=${encodeURIComponent(e)}`,{headers:{authorization:`Bearer ${n}`}}),o=await r.json().catch(()=>null);if(!r.ok||typeof o?.value!="string")throw new Error("Sign-in needed.");return o.value}function Wn(e){return e instanceof Error?e.message:String(e)}var Yn=`npx greatstore apps \u2014 author and ship custom in-chat apps
140
140
 
141
141
  Usage:
142
142
  npx greatstore apps <subcommand> [args] [flags]
@@ -151,14 +151,14 @@ Subcommands:
151
151
  unpublish <name> Clear the live pointer.
152
152
  rename <old> <new> Rename a component, keeping its versions and live state.
153
153
  delete <name> Soft-delete the component.
154
- `;async function ft(e){let t=e.positional[0],n={...e,positional:e.positional.slice(1)};switch(t){case void 0:case"help":return process.stdout.write(Yn),0;case"init":return Qt(n),0;case"build":return await He(n),0;case"list":return await kn(n),0;case"pull":return await jn(n),0;case"push":return await Dn(n),0;case"publish":return await Un(n),0;case"unpublish":return await Gn(n),0;case"rename":return await Kn(n),0;case"delete":return await Vn(n),0;case"release":return await Jn(n),0;default:return process.stderr.write(`Unknown apps subcommand: ${t}
154
+ `;async function ft(e){let t=e.positional[0],n={...e,positional:e.positional.slice(1)};switch(t){case void 0:case"help":return process.stdout.write(Yn),0;case"init":return Qt(n),0;case"build":return await He(n),0;case"list":return await kn(n),0;case"pull":return await jn(n),0;case"push":return await Dn(n),0;case"publish":return await Un(n),0;case"unpublish":return await Gn(n),0;case"rename":return await Kn(n),0;case"delete":return await qn(n),0;case"release":return await Jn(n),0;default:return process.stderr.write(`Unknown apps subcommand: ${t}
155
155
 
156
156
  ${Yn}`),1}}async function zn(e){let t=v(e),n=`${E(t)}/configure/config`,r=await f(n);if(g(e.flags,"json")){process.stdout.write(JSON.stringify(r.brand,null,2)+`
157
157
  `);return}Lo(t,r.brand)}function Lo(e,t){let n=[`Configuration for ${e}:`,""];n.push(` displayName ${t.displayName??"\u2014"}`),n.push(` assistantName ${t.assistantName??"\u2014"}`),n.push(` storeLink ${t.storeLink??"\u2014"}`),n.push(` extraOrigins ${dt(t.extraOrigins)}`),n.push(` icon ${t.icon?.url??"\u2014"}`),n.push(` logoLight ${t.logo?.light?.url??"\u2014"}`),n.push(` logoDark ${t.logo?.dark?.url??"\u2014"}`),n.push(` theme ${t.theme?JSON.stringify(t.theme):"\u2014"}`),n.push(` cspScriptHosts ${dt(t.cspScriptHosts)}`),n.push(` cspConnectHosts ${dt(t.cspConnectHosts)}`),process.stdout.write(n.join(`
158
158
  `)+`
159
159
  `)}function dt(e){return!e||e.length===0?"\u2014":e.join(", ")}import*as We from"fs";import*as Zn from"path";var Xn="theme.",Oo=["displayName","assistantName","storeLink"],Io=["extraOrigins","cspScriptHosts","cspConnectHosts"];async function er(e){let t=v(e),n={};for(let c of Oo){if(!(c in e.flags))continue;let p=e.flags[c];if(typeof p!="string")throw new Error(`--${c} requires a value (use --${c} "" to clear).`);n[c]=p===""?null:p}for(let c of Io){if(!(c in e.flags))continue;let p=e.flags[c];if(typeof p!="string")throw new Error(`--${c} requires a comma-separated value (use --${c} "" to clear).`);let u=p.split(",").map(m=>m.trim()).filter(m=>m.length>0);n[c]=u.length===0?null:u}let r=b(e.flags,"themeFile"),o=Bo(e.flags),s=g(e.flags,"replace");if("theme"in e.flags&&r!==void 0)throw new Error("Pass either --theme or --themeFile, not both.");if(o!==null&&("theme"in e.flags||r!==void 0))throw new Error("Pass either --theme.<field> flags or a whole --theme/--themeFile object, not both.");let i;if("theme"in e.flags){let c=e.flags.theme;if(typeof c!="string")throw new Error('--theme requires a JSON value (use --theme "" to clear).');i=c===""?null:Qn(c,"--theme")}else r!==void 0?i=Qn(Fo(r,"--themeFile"),"--themeFile"):o!==null&&(i=o);if(i!==void 0&&(n.theme=i===null||s?i:{...await No(t),...i},n.theme!==null)){let c=n.theme;for(let[p,u]of Object.entries(c))u===""&&delete c[p]}if(Object.keys(n).length===0)throw new Error('Nothing to save. Pass at least one field flag, e.g. `npx greatstore configure set --displayName "Acme"`.');let a=`${E(t)}/configure/save`,l=await f(a,{method:"POST",body:n,validationDetail:!0});if(g(e.flags,"json")){process.stdout.write(JSON.stringify(l.config,null,2)+`
160
160
  `);return}process.stdout.write(`Saved ${Object.keys(n).join(", ")} \u2192 ${t}
161
- `)}function Fo(e,t){let n=Zn.resolve(e);if(!We.existsSync(n))throw new Error(`${t}: file not found: ${n}`);return We.readFileSync(n,"utf8")}function Qn(e,t){let n;try{n=JSON.parse(e)}catch(r){throw new Error(`${t}: not valid JSON: ${r.message}`)}if(typeof n!="object"||n===null||Array.isArray(n))throw new Error(`${t}: theme must be a JSON object.`);return n}async function No(e){let t=`${E(e)}/configure/config`;return(await f(t)).brand.theme??{}}function Bo(e){let t={};for(let[n,r]of Object.entries(e)){if(!n.startsWith(Xn))continue;let o=n.slice(Xn.length),s=Y[o];if(!s){let i=Vt(o);throw new Error(`Unknown theme field "${o}".
161
+ `)}function Fo(e,t){let n=Zn.resolve(e);if(!We.existsSync(n))throw new Error(`${t}: file not found: ${n}`);return We.readFileSync(n,"utf8")}function Qn(e,t){let n;try{n=JSON.parse(e)}catch(r){throw new Error(`${t}: not valid JSON: ${r.message}`)}if(typeof n!="object"||n===null||Array.isArray(n))throw new Error(`${t}: theme must be a JSON object.`);return n}async function No(e){let t=`${E(e)}/configure/config`;return(await f(t)).brand.theme??{}}function Bo(e){let t={};for(let[n,r]of Object.entries(e)){if(!n.startsWith(Xn))continue;let o=n.slice(Xn.length),s=Y[o];if(!s){let i=qt(o);throw new Error(`Unknown theme field "${o}".
162
162
  Valid fields: ${Object.keys(Y).join(", ")}.`+(i.length>0?`
163
163
  Did you mean: ${i.join(", ")}?`:""))}if(typeof r!="string"){if(s.kind==="boolean"){t[o]=!0;continue}throw new Error(`--${n} requires a value (use --${n} "" to clear).`)}t[o]=Do(n,o,r)}return Object.keys(t).length>0?t:null}function Do(e,t,n){let r=Y[t];if(!r||n==="")return n;if(r.values&&!r.values.includes(n))throw new Error(`--${e} must be one of: ${r.values.join(", ")} (got "${n}").`);if(r.kind==="boolean"){if(n!=="true"&&n!=="false")throw new Error(`--${e} must be true or false (got "${n}").`);return n==="true"}if(r.kind==="integer"){let o=Number.parseInt(n,10);if(!Number.isInteger(o)||String(o)!==n.trim())throw new Error(`--${e} must be an integer (got "${n}").`);return o}return n}import*as Xe from"fs";import*as he from"path";var Ye=["icon","logoLight","logoDark"];function ze(e){if(e&&Ye.includes(e))return e;throw new Error(`Asset kind must be one of: ${Ye.join(", ")}.`)}var Ho={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".webp":"image/webp"};async function tr(e){let t=v(e),n=ze(e.positional[0]),r=e.positional[1];if(!r)throw new Error(`Usage: npx greatstore configure upload <${Ye.join("|")}> <file>`);let o=he.resolve(r);if(!Xe.existsSync(o))throw new Error(`File not found: ${o}`);let s=Ho[he.extname(o).toLowerCase()];if(!s)throw new Error("Unsupported image type. Use .png, .jpg, or .webp.");let i=Xe.readFileSync(o),a=new FormData;a.append("file",new Blob([new Uint8Array(i)],{type:s}),he.basename(o));let l=`${E(t)}/configure/upload/${n}`,c=await f(l,{method:"POST",multipart:a});process.stdout.write(`Uploaded ${n} \u2192 ${c.url}
164
164
  `)}async function nr(e){let t=v(e),n=ze(e.positional[0]),r=`${E(t)}/configure/delete/${n}`;await f(r,{method:"POST",body:{}}),process.stdout.write(`Cleared ${n} for ${t}
@@ -183,6 +183,11 @@ Did you mean: ${i.join(", ")}?`:""))}if(typeof r!="string"){if(s.kind==="boolean
183
183
  All notable changes to \`@greatstore/cli\` are recorded here. The format
184
184
  follows [Keep a Changelog](https://keepachangelog.com/).
185
185
 
186
+ ## 0.2.11 \u2014 2026-10-28
187
+
188
+ ### Added
189
+ - \`useVoiceCall\`, a hook every app receives as a prop. It returns \`{ status, available, start, end }\`, so an app can start and end a voice call with the store's assistant and show how the call is going. A call started this way doesn't open the chat. The agent guide and new apps from \`apps init\` describe it.
190
+
186
191
  ## 0.2.10 \u2014 2026-10-21
187
192
 
188
193
  ### Added
@@ -843,7 +848,7 @@ Environment:
843
848
  `,Uo=new Set(["init","build","list","pull","push","publish","unpublish","delete"]);async function Go(){let e=process.argv.slice(2),t=xt(e);if(Gt(F),g(t.flags,"version")){process.stdout.write(`greatstore v${F}
844
849
 
845
850
  `);let n=ur(Mo);return n&&process.stdout.write(`${n}
846
- `),0}if(g(t.flags,"help")||t.command==="help"||t.command===null){let n=t.command==="configure"?Kt(t.positional[0]):void 0;return process.stdout.write(n??pr),0}if(t.command!==null&&Uo.has(t.command))return ft({...t,positional:[t.command,...t.positional]});switch(t.command){case"login":return await Nt(t),0;case"logout":return Bt(),0;case"whoami":return Dt();case"switch":return Ht(t.positional);case"apps":return ft(t);case"configure":return await rr(t),0;case"connectors":return await lr(t),0;case"skill":return qt(),0;default:return process.stderr.write(`Unknown command: ${t.command}
851
+ `),0}if(g(t.flags,"help")||t.command==="help"||t.command===null){let n=t.command==="configure"?Kt(t.positional[0]):void 0;return process.stdout.write(n??pr),0}if(t.command!==null&&Uo.has(t.command))return ft({...t,positional:[t.command,...t.positional]});switch(t.command){case"login":return await Nt(t),0;case"logout":return Bt(),0;case"whoami":return Dt();case"switch":return Ht(t.positional);case"apps":return ft(t);case"configure":return await rr(t),0;case"connectors":return await lr(t),0;case"skill":return Vt(),0;default:return process.stderr.write(`Unknown command: ${t.command}
847
852
 
848
853
  ${pr}`),1}}Go().then(e=>process.exit(e||Number(process.exitCode??0))).catch(e=>{e instanceof M?process.stderr.write(`${e.message}
849
854
  `):e instanceof D?process.stderr.write(`Error: ${e.message}
@@ -205,7 +205,7 @@ gs apps publish size_guide
205
205
 
206
206
  ```html
207
207
  <script src="https://my-store.greatstore.ai/embed.js"></script>
208
- <div data-gs-app="size_guide"></div>
208
+ <greatstore-app name="size_guide"></greatstore-app>
209
209
  ```
210
210
 
211
211
  That is the same script that installs the chat widget, so a page that already
@@ -246,7 +246,7 @@ What to expect:
246
246
  ## The app contract
247
247
 
248
248
  `component.tsx` default-exports a React component. Its props are the
249
- `inputSchema` fields the assistant filled, plus six GreatStore-injected
249
+ `inputSchema` fields the assistant filled, plus seven GreatStore-injected
250
250
  lifecycle props (always present):
251
251
 
252
252
  | Prop | What it does |
@@ -256,6 +256,7 @@ lifecycle props (always present):
256
256
  | `onShowLightbox({ src, originRect? })` | Expand an image in the chat's shared full-screen lightbox — an on-brand zoom overlay you can't render yourself (your app is boxed inside its own bounds and shadow root). Pass the image `src`; for a smooth zoom, also pass the clicked element's `getBoundingClientRect()` as `originRect` (omit it and the image grows from the viewport centre). |
257
257
  | `onGenerateStructuredContent(schema, prompt, fallback)` | Ask the store's assistant for content matching a JSON Schema (or Zod schema) and get back the generated object. Personalized to the shopper. Works the same in the conversation on the storefront and every embed — no `window.GreatStore` needed. Best for async apps that build their render from a generated payload. `fallback` is **required**: a schema-shaped object you provide that the app preview renders (no live store there), validated against the schema — a mismatch throws. |
258
258
  | `onClose()` | Dismiss the host slot. `over-input` clears the overlay, `fullscreen` reverts the pane, `inline` is a no-op. |
259
+ | `useVoiceCall()` | A hook — call it at the top of your component like any other — returning `{ status, available, start, end }` for a voice call with the store's assistant. `start()` starts the call without opening the chat — it runs in the collapsed chat bar (which stays hidden if the store hides the chat until opened), and the chat opens only when the assistant shows an inline app (call it from a click; it rejects when the store has no voice), `end()` hangs up. `available` says whether the store has voice. `status` is `null` until a call starts, then `started`, `connecting`, `connected`, `listening` / `speaking` / `working` as the conversation goes, `disconnected` while the network drops (the call recovers on its own), and `ended`. Your app re-renders on every change. |
259
260
  | `Image` | A drop-in for `<img>` — render `<Image src=… alt=… />` and the image is served at the right size for the store. Takes the same props as `<img>`. |
260
261
 
261
262
  Reach for `onUpdateModelContext` when the shopper changes something inside
@@ -59,6 +59,7 @@ to the store's configured value.
59
59
  | `data-theme-mode` | `auto` \| `light` \| `dark` \| `custom` | Color scheme. |
60
60
  | `data-theme-radius` | `sharp` \| `default` \| `rounded` | Corner roundedness. |
61
61
  | `data-theme-mobile-bar-offset` | integer, `0`–`200` | Pixels the mobile chat bar sits above the bottom of the screen while the chat is closed. Raise it to clear a bottom nav of your own. |
62
+ | `data-theme-scroll-arrow` | `true` \| `false` | `false` drops the small up arrow shown in place of the chat bar while scrolling down has slid it away. The bar still hides and returns on scroll. |
62
63
  | `data-z-index` | integer, `0`–`2147483647` | Stacking order of the chat overlay on your page. Lower it if something on the page must stay above the chat. |
63
64
  | `data-theme-font` | CSS font-family string | Primary font. |
64
65
  | `data-theme-font-secondary` | CSS font-family string | Secondary font. |
@@ -175,6 +176,48 @@ Events emitted:
175
176
  |---|---|
176
177
  | `"open"` | Panel transitions closed → open (including via `sendMessage` or the shopper's own click). |
177
178
  | `"close"` | Panel transitions open → closed. |
179
+ | `"voicestatus"` | A voice call's status changes; the handler receives the status. See `startVoiceCall`. |
180
+
181
+ ### `startVoiceCall(): Promise<void>` / `endVoiceCall(): void`
182
+
183
+ `startVoiceCall` starts a voice call with the assistant **without opening the
184
+ chat**: the call runs in the collapsed chat bar, and the chat opens only when
185
+ the assistant shows an inline app in the conversation. Where the store hides
186
+ the chat until it's opened (on that device), the bar stays hidden for the
187
+ whole call, so the page needs its own hang-up control (`endVoiceCall`).
188
+ Call it from a user gesture (a click handler): the browser asks for the
189
+ microphone, and audio can only start from one. It resolves once the shopper
190
+ has answered the microphone prompt and rejects when the store has no voice. A
191
+ call already in progress is left alone. Loads the chat first if it isn't up
192
+ yet. `endVoiceCall` hangs up; it's a no-op when there's no call.
193
+
194
+ The call's progress is announced as `voicestatus` through `on()` (the handler
195
+ receives the status) and as a `greatstore:voicestatus` event on `window`
196
+ (`event.detail.status`):
197
+
198
+ | Status | Meaning |
199
+ |---|---|
200
+ | `started` | The call was requested; the microphone prompt may be showing. |
201
+ | `connecting` | Microphone granted; the call is connecting. |
202
+ | `connected` | The call is up. Followed straight away by the first of the three below. |
203
+ | `listening` | The shopper's turn to speak. |
204
+ | `speaking` | The assistant is talking. |
205
+ | `working` | The assistant is thinking or looking something up. |
206
+ | `disconnected` | The shopper's network dropped mid-call. The call recovers on its own, back to `listening`. |
207
+ | `ended` | The call is over — hung up, ended by the assistant, failed, or the microphone was refused. Always the last status. |
208
+
209
+ ```js
210
+ const callButton = document.querySelector("#talk");
211
+ callButton.addEventListener("click", () => {
212
+ if (callButton.dataset.live) window.GreatStore.endVoiceCall();
213
+ else window.GreatStore.startVoiceCall().catch(() => (callButton.hidden = true));
214
+ });
215
+ window.addEventListener("greatstore:voicestatus", (event) => {
216
+ const live = event.detail.status !== "ended";
217
+ callButton.dataset.live = live ? "1" : "";
218
+ callButton.textContent = live ? "Hang up" : "Talk to us";
219
+ });
220
+ ```
178
221
 
179
222
  ### `generateStructuredContent(schema: object, prompt: string): Promise<unknown>`
180
223
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@greatstore/cli",
3
- "version": "0.2.10",
3
+ "version": "0.2.11",
4
4
  "description": "CLI for administering GreatStore stores and authoring custom components.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",