@waniwani/sdk 0.10.11-beta.2 → 0.10.11-beta.4

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.
@@ -14,6 +14,7 @@ type NextConfigObject = {
14
14
  env?: Record<string, string | undefined>;
15
15
  headers?: () => HeaderRoute[] | Promise<HeaderRoute[]>;
16
16
  webpack?: (config: unknown, context: WebpackContext) => unknown;
17
+ turbopack?: Record<string, unknown>;
17
18
  outputFileTracingIncludes?: Record<string, string[]>;
18
19
  [key: string]: unknown;
19
20
  };
@@ -1,8 +1,8 @@
1
- import{spawnSync as z}from"child_process";import{existsSync as I,mkdirSync as P,readdirSync as V,readFileSync as K,rmSync as L,statSync as Q,writeFileSync as N}from"fs";import{dirname as w,join as x,relative as b,resolve as h}from"path";import{fileURLToPath as Z}from"url";import{createElement as X}from"react";import{renderToStaticMarkup as Y}from"react-dom/server";import{Fragment as U,jsx as p,jsxs as C}from"react/jsx-runtime";function E({baseUrl:t,passthroughOrigins:e}){return C(U,{children:[p("base",{href:t}),p("script",{children:`window.innerBaseUrl = ${JSON.stringify(t)}`}),p("script",{children:`window.__wwPassthroughOrigins = ${JSON.stringify(e??[])}`}),p("script",{children:'window.__isChatGptApp = typeof window.openai !== "undefined";'}),p("script",{children:"("+(()=>{let n=window.innerBaseUrl,i=window.__wwPassthroughOrigins??[],r=document.documentElement;new MutationObserver(g=>{g.forEach(s=>{if(s.type==="attributes"&&s.target===r){let f=s.attributeName;f&&f!=="suppresshydrationwarning"&&f!=="lang"&&f!=="class"&&f!=="style"&&r.removeAttribute(f)}})}).observe(r,{attributes:!0,attributeOldValue:!0});let a=history.replaceState.bind(history);history.replaceState=(g,s,f)=>{try{let u=new URL(String(f??""),window.location.href);a(null,s,u.pathname+u.search+u.hash)}catch{}};let l=history.pushState.bind(history);history.pushState=(g,s,f)=>{try{let u=new URL(String(f??""),window.location.href);l(null,s,u.pathname+u.search+u.hash)}catch{}};let c=new URL(n).origin,d=window.self!==window.top;if(window.addEventListener("click",g=>{let s=g?.target?.closest("a");if(!s||!s.href)return;let f=new URL(s.href,window.location.href);if(f.origin!==window.location.origin&&f.origin!==c)try{window.openai&&(window.openai?.openExternal({href:s.href}),g.preventDefault())}catch{console.warn("openExternal failed, likely not in OpenAI client")}},!0),d&&window.location.origin!==c){let g=window.fetch;window.fetch=((s,f)=>{let u;if(typeof s=="string"||s instanceof URL?u=new URL(s,window.location.href):u=new URL(s.url,window.location.href),u.origin===c)return typeof s=="string"||s instanceof URL?s=u.toString():s=new Request(u.toString(),s),g.call(window,s,{...f,mode:"cors"});if(i.indexOf(u.origin)!==-1)return g.call(window,s,f);if(u.origin===window.location.origin){let m=new URL(n);return m.pathname=u.pathname,m.search=u.search,m.hash=u.hash,u=m,typeof s=="string"||s instanceof URL?s=u.toString():s=new Request(u.toString(),s),g.call(window,s,{...f,mode:"cors"})}return g.call(window,s,f)})}}).toString()+")()"})]})}import{readFileSync as Pt}from"fs";import{resolve as J}from"path";var W="__WANIWANI_WIDGET_BASE_URL__",G=".waniwani",q="widgets-manifest.json",R=`${G}/${q}`;function A(t){return J(t??process.cwd(),R)}var j="__waniwani_build_widgets",T=new Set;function At(t,e){return typeof t=="function"?((...n)=>{let i=t(...n);return i&&typeof i.then=="function"?i.then(r=>v(r,e)):v(i,e)}):v(t,e)}function v(t,e){let n=h(e.projectRoot??process.cwd()),i=B(n,e.resources),r=rt(i);tt(n,r);let o=t.headers,a=t.webpack,l=`./${R}`,c=t.outputFileTracingIncludes??{};return{...t,outputFileTracingIncludes:{...c,"/**/*":[...c["/**/*"]??[],l]},async headers(){return k(n,e),[...o?await o():[],{source:"/widgets/:path*",headers:[{key:"Cache-Control",value:"public, max-age=0, must-revalidate"},{key:"Access-Control-Allow-Origin",value:"*"}]}]},webpack(d,g){return g.isServer&&k(n,e),a?a(d,g):d}}}function tt(t,e){let n=A(t);P(w(n),{recursive:!0}),N(n,JSON.stringify(e))}function k(t,e){if(process.env.WANIWANI_WIDGETS_SKIP_BUILD==="1")return;let n=JSON.stringify({projectRoot:t,options:e});if(T.has(n))return;T.add(n);let i=Buffer.from(JSON.stringify({...e,projectRoot:t}),"utf8").toString("base64"),r=z(process.execPath,[Z(import.meta.url),j,i],{cwd:t,stdio:"inherit",env:process.env});if(r.status!==0)throw new Error(`WaniWani widget build failed with exit code ${r.status??"unknown"}`)}async function et(t){let e=h(t.projectRoot??process.cwd()),i=B(e,t.resources).filter(d=>!d.prebuilt).map(d=>st(e,t,d));if(i.length===0)return;let r=h(e,"node_modules/.cache/waniwani/widgets"),o=h(e,"public/widgets");P(r,{recursive:!0}),P(o,{recursive:!0});let[{build:a},l,c]=await Promise.all([import("vite"),import("@vitejs/plugin-react"),import("@tailwindcss/vite")]);for(let d of i){let g=ut(e,r,t,d),s=d.assetBase;L(h(e,"public",`${s}.js`),{force:!0}),L(h(e,"public",`${s}.css`),{force:!0}),await a({root:e,configFile:!1,publicDir:!1,logLevel:"warn",plugins:[l.default(),c.default()],css:{postcss:{plugins:[]}},resolve:{alias:[{find:"@",replacement:e}]},define:{"process.env.NODE_ENV":JSON.stringify("production")},build:{cssCodeSplit:!1,emptyOutDir:!1,minify:!0,outDir:o,rollupOptions:{input:g,output:{assetFileNames:f=>f.names.some(u=>u.endsWith(".css"))?`${y(s)}.css`:`${y(s)}-[name][extname]`,chunkFileNames:`${y(s)}.js`,codeSplitting:!1,entryFileNames:`${y(s)}.js`}},sourcemap:!1,target:"es2020"}}),gt(e,d)}}function B(t,e){let n=_(t,e),i=K(n,"utf8"),r=[];for(let o of nt(i)){let a=D(o,"id");if(!a)throw new Error(`WaniWani widgets: createResource in ${e} must use a string literal id.`);let l=D(o,"htmlPath")??`/${a}`,c=dt(a,l);r.push({id:a,htmlPath:l,stableHtmlPath:c,prebuilt:H(l)})}return r}function nt(t){let e=[],n=0;for(;n<t.length;){let i=t.indexOf("createResource",n);if(i===-1)break;let r=i+14;for(;/\s/.test(t[r]??"");)r++;if(t[r]!=="("){n=r+1;continue}let o=t.indexOf("{",r);if(o===-1){n=i+14;continue}let a=it(t,o);if(a===-1)throw new Error("WaniWani widgets: could not parse createResource call.");e.push(t.slice(o,a+1)),n=a+1}return e}function it(t,e){let n=0,i=null,r=!1,o=!1,a=!1;for(let l=e;l<t.length;l++){let c=t[l],d=t[l+1];if(o){c===`
2
- `&&(o=!1);continue}if(a){c==="*"&&d==="/"&&(a=!1,l++);continue}if(i){r?r=!1:c==="\\"?r=!0:c===i&&(i=null);continue}if(c==="/"&&d==="/"){o=!0,l++;continue}if(c==="/"&&d==="*"){a=!0,l++;continue}if(c==='"'||c==="'"||c==="`"){i=c;continue}if(c==="{")n++;else if(c==="}"&&(n--,n===0))return l}return-1}function D(t,e){let n=new RegExp(`(?:^|[,\\n\\r])\\s*${e}\\s*:\\s*(["'\`])([^"'\`]+)\\1`);return t.match(n)?.[2]??null}function rt(t){let e={},n={};for(let i of t)e[i.id]=i.stableHtmlPath,n[i.htmlPath]=i.stableHtmlPath;return{version:1,byId:e,byHtmlPath:n}}function st(t,e,n){let i=_(t,e.appDir??"app"),r=F(n.htmlPath),o=ot(i,r);if(!o)throw new Error(`WaniWani widgets: could not find a Next.js page for ${n.htmlPath} under ${b(t,i)}.`);return{...n,assetBase:n.stableHtmlPath.slice(0,-5),pagePath:o.pagePath,layoutPaths:o.layoutPaths}}function ot(t,e){let n=[];M(t,t,n);let i=n.filter(o=>o.routePath===e);if(i.length===0)return null;if(i.length>1)throw new Error(`WaniWani widgets: multiple Next.js pages match ${e}: ${i.map(o=>o.pagePath).join(", ")}`);let r=i[0].pagePath;return{pagePath:r,layoutPaths:ct(t,w(r))}}function M(t,e,n){for(let i of V(e).sort()){let r=x(e,i);if(Q(r).isDirectory()){M(t,r,n);continue}/^page\.(tsx|ts|jsx|js)$/.test(i)&&n.push({pagePath:r,routePath:at(t,r)})}}function at(t,e){return`/${b(t,w(e)).split(/[\\/]/).filter(Boolean).filter(r=>!pt(r)).filter(r=>!r.startsWith("@")).join("/")}`.replace(/\/$/,"")||"/"}function ct(t,e){let i=b(t,e).split(/[\\/]/).filter(Boolean),r=[],o=t;for(let a of i){o=x(o,a);let l=lt(o,"layout");l&&r.push(l)}return r}function lt(t,e){for(let n of["tsx","ts","jsx","js"]){let i=x(t,`${e}.${n}`);if(I(i))return i}return null}function ut(t,e,n,i){let r=h(e,`${ht(i.id)}.tsx`),o=w(r),a=ft(t,n.globalCss),l=i.layoutPaths.map((g,s)=>`import Layout${s} from ${JSON.stringify(S(o,g))};`).join(`
1
+ import{spawnSync as z}from"child_process";import{existsSync as I,mkdirSync as P,readdirSync as V,readFileSync as K,rmSync as k,statSync as Q,writeFileSync as N}from"fs";import{dirname as w,join as _,relative as b,resolve as h}from"path";import{fileURLToPath as Z}from"url";import{createElement as X}from"react";import{renderToStaticMarkup as Y}from"react-dom/server";import{Fragment as U,jsx as p,jsxs as C}from"react/jsx-runtime";function E({baseUrl:t,passthroughOrigins:e}){return C(U,{children:[p("base",{href:t}),p("script",{children:`window.innerBaseUrl = ${JSON.stringify(t)}`}),p("script",{children:`window.__wwPassthroughOrigins = ${JSON.stringify(e??[])}`}),p("script",{children:'window.__isChatGptApp = typeof window.openai !== "undefined";'}),p("script",{children:"("+(()=>{let n=window.innerBaseUrl,i=window.__wwPassthroughOrigins??[],r=document.documentElement;new MutationObserver(g=>{g.forEach(s=>{if(s.type==="attributes"&&s.target===r){let d=s.attributeName;d&&d!=="suppresshydrationwarning"&&d!=="lang"&&d!=="class"&&d!=="style"&&r.removeAttribute(d)}})}).observe(r,{attributes:!0,attributeOldValue:!0});let a=history.replaceState.bind(history);history.replaceState=(g,s,d)=>{try{let u=new URL(String(d??""),window.location.href);a(null,s,u.pathname+u.search+u.hash)}catch{}};let l=history.pushState.bind(history);history.pushState=(g,s,d)=>{try{let u=new URL(String(d??""),window.location.href);l(null,s,u.pathname+u.search+u.hash)}catch{}};let c=new URL(n).origin,f=window.self!==window.top;if(window.addEventListener("click",g=>{let s=g?.target?.closest("a");if(!s||!s.href)return;let d=new URL(s.href,window.location.href);if(d.origin!==window.location.origin&&d.origin!==c)try{window.openai&&(window.openai?.openExternal({href:s.href}),g.preventDefault())}catch{console.warn("openExternal failed, likely not in OpenAI client")}},!0),f&&window.location.origin!==c){let g=window.fetch;window.fetch=((s,d)=>{let u;if(typeof s=="string"||s instanceof URL?u=new URL(s,window.location.href):u=new URL(s.url,window.location.href),u.origin===c)return typeof s=="string"||s instanceof URL?s=u.toString():s=new Request(u.toString(),s),g.call(window,s,{...d,mode:"cors"});if(i.indexOf(u.origin)!==-1)return g.call(window,s,d);if(u.origin===window.location.origin){let m=new URL(n);return m.pathname=u.pathname,m.search=u.search,m.hash=u.hash,u=m,typeof s=="string"||s instanceof URL?s=u.toString():s=new Request(u.toString(),s),g.call(window,s,{...d,mode:"cors"})}return g.call(window,s,d)})}}).toString()+")()"})]})}import{readFileSync as Pt}from"fs";import{resolve as J}from"path";var W="__WANIWANI_WIDGET_BASE_URL__",G=".waniwani",q="widgets-manifest.json",R=`${G}/${q}`;function A(t){return J(t??process.cwd(),R)}var j="__waniwani_build_widgets",L=new Set;function At(t,e){return typeof t=="function"?((...n)=>{let i=t(...n);return i&&typeof i.then=="function"?i.then(r=>v(r,e)):v(i,e)}):v(t,e)}function v(t,e){let n=h(e.projectRoot??process.cwd()),i=B(n,e.resources),r=rt(i);tt(n,r);let o=t.headers,a=t.webpack,l=`./${R}`,c=t.outputFileTracingIncludes??{};return{...t,turbopack:{...t.turbopack??{}},outputFileTracingIncludes:{...c,"/**/*":[...c["/**/*"]??[],l]},async headers(){return T(n,e),[...o?await o():[],{source:"/widgets/:path*",headers:[{key:"Cache-Control",value:"public, max-age=0, must-revalidate"},{key:"Access-Control-Allow-Origin",value:"*"}]}]},webpack(f,g){return g.isServer&&T(n,e),a?a(f,g):f}}}function tt(t,e){let n=A(t);P(w(n),{recursive:!0}),N(n,JSON.stringify(e))}function T(t,e){if(process.env.WANIWANI_WIDGETS_SKIP_BUILD==="1")return;let n=JSON.stringify({projectRoot:t,options:e});if(L.has(n))return;L.add(n);let i=Buffer.from(JSON.stringify({...e,projectRoot:t}),"utf8").toString("base64"),r=z(process.execPath,[Z(import.meta.url),j,i],{cwd:t,stdio:"inherit",env:process.env});if(r.status!==0)throw new Error(`WaniWani widget build failed with exit code ${r.status??"unknown"}`)}async function et(t){let e=h(t.projectRoot??process.cwd()),i=B(e,t.resources).filter(f=>!f.prebuilt).map(f=>st(e,t,f));if(i.length===0)return;let r=h(e,"node_modules/.cache/waniwani/widgets"),o=h(e,"public/widgets");P(r,{recursive:!0}),P(o,{recursive:!0});let[{build:a},l,c]=await Promise.all([import("vite"),import("@vitejs/plugin-react"),import("@tailwindcss/vite")]);for(let f of i){let g=ut(e,r,t,f),s=f.assetBase;k(h(e,"public",`${s}.js`),{force:!0}),k(h(e,"public",`${s}.css`),{force:!0}),await a({root:e,configFile:!1,publicDir:!1,logLevel:"warn",plugins:[l.default(),c.default()],css:{postcss:{plugins:[]}},resolve:{alias:[{find:"@",replacement:e}]},define:{"process.env.NODE_ENV":JSON.stringify("production")},build:{cssCodeSplit:!1,emptyOutDir:!1,minify:!0,outDir:o,rollupOptions:{input:g,output:{assetFileNames:d=>d.names.some(u=>u.endsWith(".css"))?`${y(s)}.css`:`${y(s)}-[name][extname]`,chunkFileNames:`${y(s)}.js`,codeSplitting:!1,entryFileNames:`${y(s)}.js`}},sourcemap:!1,target:"es2020"}}),gt(e,f)}}function B(t,e){let n=x(t,e),i=K(n,"utf8"),r=[];for(let o of nt(i)){let a=D(o,"id");if(!a)throw new Error(`WaniWani widgets: createResource in ${e} must use a string literal id.`);let l=D(o,"htmlPath")??`/${a}`,c=ft(a,l);r.push({id:a,htmlPath:l,stableHtmlPath:c,prebuilt:H(l)})}return r}function nt(t){let e=[],n=0;for(;n<t.length;){let i=t.indexOf("createResource",n);if(i===-1)break;let r=i+14;for(;/\s/.test(t[r]??"");)r++;if(t[r]!=="("){n=r+1;continue}let o=t.indexOf("{",r);if(o===-1){n=i+14;continue}let a=it(t,o);if(a===-1)throw new Error("WaniWani widgets: could not parse createResource call.");e.push(t.slice(o,a+1)),n=a+1}return e}function it(t,e){let n=0,i=null,r=!1,o=!1,a=!1;for(let l=e;l<t.length;l++){let c=t[l],f=t[l+1];if(o){c===`
2
+ `&&(o=!1);continue}if(a){c==="*"&&f==="/"&&(a=!1,l++);continue}if(i){r?r=!1:c==="\\"?r=!0:c===i&&(i=null);continue}if(c==="/"&&f==="/"){o=!0,l++;continue}if(c==="/"&&f==="*"){a=!0,l++;continue}if(c==='"'||c==="'"||c==="`"){i=c;continue}if(c==="{")n++;else if(c==="}"&&(n--,n===0))return l}return-1}function D(t,e){let n=new RegExp(`(?:^|[,\\n\\r])\\s*${e}\\s*:\\s*(["'\`])([^"'\`]+)\\1`);return t.match(n)?.[2]??null}function rt(t){let e={},n={};for(let i of t)e[i.id]=i.stableHtmlPath,n[i.htmlPath]=i.stableHtmlPath;return{version:1,byId:e,byHtmlPath:n}}function st(t,e,n){let i=x(t,e.appDir??"app"),r=F(n.htmlPath),o=ot(i,r);if(!o)throw new Error(`WaniWani widgets: could not find a Next.js page for ${n.htmlPath} under ${b(t,i)}.`);return{...n,assetBase:n.stableHtmlPath.slice(0,-5),pagePath:o.pagePath,layoutPaths:o.layoutPaths}}function ot(t,e){let n=[];M(t,t,n);let i=n.filter(o=>o.routePath===e);if(i.length===0)return null;if(i.length>1)throw new Error(`WaniWani widgets: multiple Next.js pages match ${e}: ${i.map(o=>o.pagePath).join(", ")}`);let r=i[0].pagePath;return{pagePath:r,layoutPaths:ct(t,w(r))}}function M(t,e,n){for(let i of V(e).sort()){let r=_(e,i);if(Q(r).isDirectory()){M(t,r,n);continue}/^page\.(tsx|ts|jsx|js)$/.test(i)&&n.push({pagePath:r,routePath:at(t,r)})}}function at(t,e){return`/${b(t,w(e)).split(/[\\/]/).filter(Boolean).filter(r=>!pt(r)).filter(r=>!r.startsWith("@")).join("/")}`.replace(/\/$/,"")||"/"}function ct(t,e){let i=b(t,e).split(/[\\/]/).filter(Boolean),r=[],o=t;for(let a of i){o=_(o,a);let l=lt(o,"layout");l&&r.push(l)}return r}function lt(t,e){for(let n of["tsx","ts","jsx","js"]){let i=_(t,`${e}.${n}`);if(I(i))return i}return null}function ut(t,e,n,i){let r=h(e,`${ht(i.id)}.tsx`),o=w(r),a=dt(t,n.globalCss),l=i.layoutPaths.map((g,s)=>`import Layout${s} from ${JSON.stringify(S(o,g))};`).join(`
3
3
  `),c=i.layoutPaths.map((g,s)=>` children = <Layout${i.layoutPaths.length-s-1}>{children}</Layout${i.layoutPaths.length-s-1}>;`).join(`
4
- `),d=i.layoutPaths.length===0?" children = <WidgetProvider loading={<LoadingWidget />}>{children}</WidgetProvider>;":"";return N(r,['import React from "react";','import { createRoot } from "react-dom/client";',i.layoutPaths.length===0?'import { LoadingWidget, WidgetProvider } from "@waniwani/sdk/mcp/react";':"",a?`import ${JSON.stringify(S(o,a))};`:"",`import Page from ${JSON.stringify(S(o,i.pagePath))};`,l,"","function Widget() {"," let children = <Page />;",c,d," return children;","}","",'createRoot(document.getElementById("root")!).render(<Widget />);',""].filter(g=>g!=="").join(`
5
- `)),r}function gt(t,e){let n=e.assetBase,i=h(t,"public",`${n}.css`),r=h(t,"public",e.stableHtmlPath.slice(1)),o=Y(X(E,{baseUrl:W})),a=I(i)?`<link rel="stylesheet" href="${W}${n}.css">`:"";P(w(r),{recursive:!0}),N(r,`<!doctype html>
4
+ `),f=i.layoutPaths.length===0?" children = <WidgetProvider loading={<LoadingWidget />}>{children}</WidgetProvider>;":"";return N(r,['import React from "react";','import { createRoot } from "react-dom/client";',i.layoutPaths.length===0?'import { LoadingWidget, WidgetProvider } from "@waniwani/sdk/mcp/react";':"",a?`import ${JSON.stringify(S(o,a))};`:"",`import Page from ${JSON.stringify(S(o,i.pagePath))};`,l,"","function Widget() {"," let children = <Page />;",c,f," return children;","}","",'createRoot(document.getElementById("root")!).render(<Widget />);',""].filter(g=>g!=="").join(`
5
+ `)),r}function gt(t,e){let n=e.assetBase,i=h(t,"public",`${n.replace(/^\//,"")}.css`),r=h(t,"public",e.stableHtmlPath.slice(1)),o=Y(X(E,{baseUrl:W})),a=I(i)?`<link rel="stylesheet" href="${W}${n}.css">`:"";P(w(r),{recursive:!0}),N(r,`<!doctype html>
6
6
  <html lang="en">
7
7
  <head>
8
8
  <meta charset="utf-8">
@@ -15,5 +15,5 @@ ${a}
15
15
  <script type="module" src="${W}${n}.js"></script>
16
16
  </body>
17
17
  </html>
18
- `)}function ft(t,e){if(e===!1)return null;let n=_(t,e??"app/globals.css");return I(n)?n:null}function dt(t,e){if(H(e))return e;let n=F(e);return`/widgets/${n==="/"?t:n.slice(1)}.html`}function H(t){return t.startsWith("/widgets/")&&t.endsWith(".html")&&!t.includes("..")}function F(t){let e=t.split(/[?#]/)[0]||"/",n=e.length>1?e.replace(/\/+$/,""):e;return n.startsWith("/")?n:`/${n}`}function y(t){return t.replace(/^\/widgets\//,"")}function ht(t){return t.replace(/[^a-zA-Z0-9_-]/g,"_")}function S(t,e){let n=b(t,e).replaceAll("\\","/");return n.startsWith(".")?n:`./${n}`}function _(t,e){return e.startsWith("/")?e:h(t,e)}function pt(t){return t.startsWith("(")&&t.endsWith(")")}if(process.argv[2]===j){let t=process.argv[3];t||(console.error("WaniWani widgets: missing build payload."),process.exit(1));let e=JSON.parse(Buffer.from(t,"base64").toString("utf8"));et(e).catch(n=>{console.error(n),process.exit(1)})}export{At as withWaniwaniWidgets};
18
+ `)}function dt(t,e){if(e===!1)return null;let n=x(t,e??"app/globals.css");return I(n)?n:null}function ft(t,e){if(H(e))return e;let n=F(e);return`/widgets/${n==="/"?t:n.slice(1)}.html`}function H(t){return t.startsWith("/widgets/")&&t.endsWith(".html")&&!t.includes("..")}function F(t){let e=t.split(/[?#]/)[0]||"/",n=e.length>1?e.replace(/\/+$/,""):e;return n.startsWith("/")?n:`/${n}`}function y(t){return t.replace(/^\/widgets\//,"")}function ht(t){return t.replace(/[^a-zA-Z0-9_-]/g,"_")}function S(t,e){let n=b(t,e).replaceAll("\\","/");return n.startsWith(".")?n:`./${n}`}function x(t,e){return e.startsWith("/")?e:h(t,e)}function pt(t){return t.startsWith("(")&&t.endsWith(")")}if(process.argv[2]===j){let t=process.argv[3];t||(console.error("WaniWani widgets: missing build payload."),process.exit(1));let e=JSON.parse(Buffer.from(t,"base64").toString("utf8"));et(e).catch(n=>{console.error(n),process.exit(1)})}export{At as withWaniwaniWidgets};
19
19
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/next/index.ts","../../src/mcp/react/components/initialize-next-in-iframe.tsx","../../src/mcp/server/resources/widget-manifest.ts"],"sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport {\n\texistsSync,\n\tmkdirSync,\n\treaddirSync,\n\treadFileSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { createElement } from \"react\";\nimport { renderToStaticMarkup } from \"react-dom/server\";\nimport { InitializeNextJsInIframe } from \"../mcp/react/components/initialize-next-in-iframe\";\nimport {\n\tgetManifestFilePath,\n\tWANIWANI_WIDGET_BASE_URL_PLACEHOLDER,\n\tWANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH,\n\ttype WaniwaniWidgetsManifest,\n} from \"../mcp/server/resources/widget-manifest\";\n\ntype Header = {\n\tkey: string;\n\tvalue: string;\n};\n\ntype HeaderRoute = {\n\tsource: string;\n\theaders: Header[];\n};\n\ntype WebpackContext = {\n\tdev?: boolean;\n\tisServer?: boolean;\n};\n\ntype NextConfigObject = {\n\tenv?: Record<string, string | undefined>;\n\theaders?: () => HeaderRoute[] | Promise<HeaderRoute[]>;\n\twebpack?: (config: unknown, context: WebpackContext) => unknown;\n\toutputFileTracingIncludes?: Record<string, string[]>;\n\t[key: string]: unknown;\n};\n\ntype NextConfigFactory = (\n\t...args: unknown[]\n) => NextConfigObject | Promise<NextConfigObject>;\n\nexport type WithWaniwaniWidgetsOptions = {\n\t/** Resource module that contains createResource(...) calls. */\n\tresources: string;\n\t/** Project root. Defaults to process.cwd(). */\n\tprojectRoot?: string;\n\t/** Next app directory. Defaults to ./app. */\n\tappDir?: string;\n\t/** Global CSS imported into every generated widget entry. Defaults to ./app/globals.css when present. */\n\tglobalCss?: string | false;\n};\n\ntype DiscoveredResource = {\n\tid: string;\n\thtmlPath: string;\n\tstableHtmlPath: string;\n\tprebuilt: boolean;\n};\n\ntype WidgetBuildTarget = DiscoveredResource & {\n\tassetBase: string;\n\tpagePath: string;\n\tlayoutPaths: string[];\n};\n\nconst BUILD_ARG = \"__waniwani_build_widgets\";\nconst builtKeys = new Set<string>();\n\nexport function withWaniwaniWidgets<\n\tT extends NextConfigObject | NextConfigFactory,\n>(nextConfig: T, options: WithWaniwaniWidgetsOptions): T {\n\tif (typeof nextConfig === \"function\") {\n\t\treturn ((...args: unknown[]) => {\n\t\t\tconst result = nextConfig(...args);\n\t\t\tif (\n\t\t\t\tresult &&\n\t\t\t\ttypeof (result as Promise<NextConfigObject>).then === \"function\"\n\t\t\t) {\n\t\t\t\treturn (result as Promise<NextConfigObject>).then((config) =>\n\t\t\t\t\tenhanceNextConfig(config, options),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn enhanceNextConfig(result as NextConfigObject, options);\n\t\t}) as T;\n\t}\n\n\treturn enhanceNextConfig(nextConfig, options) as T;\n}\n\nfunction enhanceNextConfig(\n\tnextConfig: NextConfigObject,\n\toptions: WithWaniwaniWidgetsOptions,\n): NextConfigObject {\n\tconst projectRoot = resolve(options.projectRoot ?? process.cwd());\n\tconst resources = discoverResources(projectRoot, options.resources);\n\tconst manifest = createManifest(resources);\n\twriteManifestFile(projectRoot, manifest);\n\tconst originalHeaders = nextConfig.headers;\n\tconst originalWebpack = nextConfig.webpack;\n\tconst manifestTraceTarget = `./${WANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH}`;\n\tconst existingTracingIncludes = nextConfig.outputFileTracingIncludes ?? {};\n\n\treturn {\n\t\t...nextConfig,\n\t\toutputFileTracingIncludes: {\n\t\t\t...existingTracingIncludes,\n\t\t\t\"/**/*\": [\n\t\t\t\t...(existingTracingIncludes[\"/**/*\"] ?? []),\n\t\t\t\tmanifestTraceTarget,\n\t\t\t],\n\t\t},\n\t\tasync headers() {\n\t\t\tbuildWidgetsSync(projectRoot, options);\n\t\t\tconst existing = originalHeaders ? await originalHeaders() : [];\n\t\t\treturn [\n\t\t\t\t...existing,\n\t\t\t\t{\n\t\t\t\t\tsource: \"/widgets/:path*\",\n\t\t\t\t\theaders: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkey: \"Cache-Control\",\n\t\t\t\t\t\t\tvalue: \"public, max-age=0, must-revalidate\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkey: \"Access-Control-Allow-Origin\",\n\t\t\t\t\t\t\tvalue: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t},\n\t\twebpack(config: unknown, context: WebpackContext) {\n\t\t\tif (context.isServer) {\n\t\t\t\tbuildWidgetsSync(projectRoot, options);\n\t\t\t}\n\t\t\treturn originalWebpack ? originalWebpack(config, context) : config;\n\t\t},\n\t};\n}\n\nfunction writeManifestFile(\n\tprojectRoot: string,\n\tmanifest: WaniwaniWidgetsManifest,\n): void {\n\tconst manifestPath = getManifestFilePath(projectRoot);\n\tmkdirSync(dirname(manifestPath), { recursive: true });\n\twriteFileSync(manifestPath, JSON.stringify(manifest));\n}\n\nfunction buildWidgetsSync(\n\tprojectRoot: string,\n\toptions: WithWaniwaniWidgetsOptions,\n): void {\n\tif (process.env.WANIWANI_WIDGETS_SKIP_BUILD === \"1\") {\n\t\treturn;\n\t}\n\n\tconst key = JSON.stringify({ projectRoot, options });\n\tif (builtKeys.has(key)) {\n\t\treturn;\n\t}\n\tbuiltKeys.add(key);\n\n\tconst payload = Buffer.from(\n\t\tJSON.stringify({ ...options, projectRoot }),\n\t\t\"utf8\",\n\t).toString(\"base64\");\n\tconst result = spawnSync(\n\t\tprocess.execPath,\n\t\t[fileURLToPath(import.meta.url), BUILD_ARG, payload],\n\t\t{\n\t\t\tcwd: projectRoot,\n\t\t\tstdio: \"inherit\",\n\t\t\tenv: process.env,\n\t\t},\n\t);\n\n\tif (result.status !== 0) {\n\t\tthrow new Error(\n\t\t\t`WaniWani widget build failed with exit code ${result.status ?? \"unknown\"}`,\n\t\t);\n\t}\n}\n\nasync function buildWaniwaniWidgets(\n\toptions: WithWaniwaniWidgetsOptions,\n): Promise<void> {\n\tconst projectRoot = resolve(options.projectRoot ?? process.cwd());\n\tconst resources = discoverResources(projectRoot, options.resources);\n\tconst targets = resources\n\t\t.filter((resource) => !resource.prebuilt)\n\t\t.map((resource) => resolveBuildTarget(projectRoot, options, resource));\n\n\tif (targets.length === 0) {\n\t\treturn;\n\t}\n\n\tconst cacheDir = resolve(projectRoot, \"node_modules/.cache/waniwani/widgets\");\n\tconst publicWidgetsDir = resolve(projectRoot, \"public/widgets\");\n\tmkdirSync(cacheDir, { recursive: true });\n\tmkdirSync(publicWidgetsDir, { recursive: true });\n\n\tconst [{ build }, react, tailwindcss] = await Promise.all([\n\t\timport(\"vite\"),\n\t\timport(\"@vitejs/plugin-react\"),\n\t\timport(\"@tailwindcss/vite\"),\n\t]);\n\n\tfor (const target of targets) {\n\t\tconst entryPath = writeGeneratedEntry(\n\t\t\tprojectRoot,\n\t\t\tcacheDir,\n\t\t\toptions,\n\t\t\ttarget,\n\t\t);\n\t\tconst assetBase = target.assetBase;\n\n\t\trmSync(resolve(projectRoot, \"public\", `${assetBase}.js`), { force: true });\n\t\trmSync(resolve(projectRoot, \"public\", `${assetBase}.css`), { force: true });\n\n\t\tawait build({\n\t\t\troot: projectRoot,\n\t\t\tconfigFile: false,\n\t\t\tpublicDir: false,\n\t\t\tlogLevel: \"warn\",\n\t\t\tplugins: [react.default(), tailwindcss.default()],\n\t\t\tcss: {\n\t\t\t\tpostcss: {\n\t\t\t\t\tplugins: [],\n\t\t\t\t},\n\t\t\t},\n\t\t\tresolve: {\n\t\t\t\talias: [{ find: \"@\", replacement: projectRoot }],\n\t\t\t},\n\t\t\tdefine: {\n\t\t\t\t\"process.env.NODE_ENV\": JSON.stringify(\"production\"),\n\t\t\t},\n\t\t\tbuild: {\n\t\t\t\tcssCodeSplit: false,\n\t\t\t\temptyOutDir: false,\n\t\t\t\tminify: true,\n\t\t\t\toutDir: publicWidgetsDir,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: entryPath,\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tassetFileNames: (assetInfo) => {\n\t\t\t\t\t\t\tif (assetInfo.names.some((name) => name.endsWith(\".css\"))) {\n\t\t\t\t\t\t\t\treturn `${stripWidgetsPrefix(assetBase)}.css`;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn `${stripWidgetsPrefix(assetBase)}-[name][extname]`;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tchunkFileNames: `${stripWidgetsPrefix(assetBase)}.js`,\n\t\t\t\t\t\tcodeSplitting: false,\n\t\t\t\t\t\tentryFileNames: `${stripWidgetsPrefix(assetBase)}.js`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tsourcemap: false,\n\t\t\t\ttarget: \"es2020\",\n\t\t\t},\n\t\t});\n\n\t\twriteWidgetHtml(projectRoot, target);\n\t}\n}\n\nfunction discoverResources(\n\tprojectRoot: string,\n\tresourcesPath: string,\n): DiscoveredResource[] {\n\tconst absolutePath = resolveProjectPath(projectRoot, resourcesPath);\n\tconst source = readFileSync(absolutePath, \"utf8\");\n\tconst resources: DiscoveredResource[] = [];\n\n\tfor (const objectSource of findCreateResourceObjects(source)) {\n\t\tconst id = readStringProperty(objectSource, \"id\");\n\t\tif (!id) {\n\t\t\tthrow new Error(\n\t\t\t\t`WaniWani widgets: createResource in ${resourcesPath} must use a string literal id.`,\n\t\t\t);\n\t\t}\n\n\t\tconst htmlPath = readStringProperty(objectSource, \"htmlPath\") ?? `/${id}`;\n\t\tconst stableHtmlPath = toStableHtmlPath(id, htmlPath);\n\t\tresources.push({\n\t\t\tid,\n\t\t\thtmlPath,\n\t\t\tstableHtmlPath,\n\t\t\tprebuilt: isStableWidgetHtmlPath(htmlPath),\n\t\t});\n\t}\n\n\treturn resources;\n}\n\nfunction findCreateResourceObjects(source: string): string[] {\n\tconst objects: string[] = [];\n\tlet index = 0;\n\n\twhile (index < source.length) {\n\t\tconst callIndex = source.indexOf(\"createResource\", index);\n\t\tif (callIndex === -1) {\n\t\t\tbreak;\n\t\t}\n\n\t\tlet openParen = callIndex + \"createResource\".length;\n\t\twhile (/\\s/.test(source[openParen] ?? \"\")) {\n\t\t\topenParen++;\n\t\t}\n\t\tif (source[openParen] !== \"(\") {\n\t\t\tindex = openParen + 1;\n\t\t\tcontinue;\n\t\t}\n\t\tconst openBrace = source.indexOf(\"{\", openParen);\n\t\tif (openBrace === -1) {\n\t\t\tindex = callIndex + \"createResource\".length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst closeBrace = findMatchingBrace(source, openBrace);\n\t\tif (closeBrace === -1) {\n\t\t\tthrow new Error(\"WaniWani widgets: could not parse createResource call.\");\n\t\t}\n\n\t\tobjects.push(source.slice(openBrace, closeBrace + 1));\n\t\tindex = closeBrace + 1;\n\t}\n\n\treturn objects;\n}\n\nfunction findMatchingBrace(source: string, openBrace: number): number {\n\tlet depth = 0;\n\tlet quote: '\"' | \"'\" | \"`\" | null = null;\n\tlet escaped = false;\n\tlet lineComment = false;\n\tlet blockComment = false;\n\n\tfor (let index = openBrace; index < source.length; index++) {\n\t\tconst char = source[index];\n\t\tconst next = source[index + 1];\n\n\t\tif (lineComment) {\n\t\t\tif (char === \"\\n\") {\n\t\t\t\tlineComment = false;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (blockComment) {\n\t\t\tif (char === \"*\" && next === \"/\") {\n\t\t\t\tblockComment = false;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (quote) {\n\t\t\tif (escaped) {\n\t\t\t\tescaped = false;\n\t\t\t} else if (char === \"\\\\\") {\n\t\t\t\tescaped = true;\n\t\t\t} else if (char === quote) {\n\t\t\t\tquote = null;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && next === \"/\") {\n\t\t\tlineComment = true;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && next === \"*\") {\n\t\t\tblockComment = true;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === '\"' || char === \"'\" || char === \"`\") {\n\t\t\tquote = char;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"{\") {\n\t\t\tdepth++;\n\t\t} else if (char === \"}\") {\n\t\t\tdepth--;\n\t\t\tif (depth === 0) {\n\t\t\t\treturn index;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn -1;\n}\n\nfunction readStringProperty(\n\tsource: string,\n\tpropertyName: string,\n): string | null {\n\tconst pattern = new RegExp(\n\t\t`(?:^|[,\\\\n\\\\r])\\\\s*${propertyName}\\\\s*:\\\\s*([\"'\\`])([^\"'\\`]+)\\\\1`,\n\t);\n\tconst match = source.match(pattern);\n\treturn match?.[2] ?? null;\n}\n\nfunction createManifest(\n\tresources: DiscoveredResource[],\n): WaniwaniWidgetsManifest {\n\tconst byId: Record<string, string> = {};\n\tconst byHtmlPath: Record<string, string> = {};\n\n\tfor (const resource of resources) {\n\t\tbyId[resource.id] = resource.stableHtmlPath;\n\t\tbyHtmlPath[resource.htmlPath] = resource.stableHtmlPath;\n\t}\n\n\treturn {\n\t\tversion: 1,\n\t\tbyId,\n\t\tbyHtmlPath,\n\t};\n}\n\nfunction resolveBuildTarget(\n\tprojectRoot: string,\n\toptions: WithWaniwaniWidgetsOptions,\n\tresource: DiscoveredResource,\n): WidgetBuildTarget {\n\tconst appDir = resolveProjectPath(projectRoot, options.appDir ?? \"app\");\n\tconst routePath = normalizeRoutePath(resource.htmlPath);\n\tconst page = findPageForRoute(appDir, routePath);\n\n\tif (!page) {\n\t\tthrow new Error(\n\t\t\t`WaniWani widgets: could not find a Next.js page for ${resource.htmlPath} under ${relative(\n\t\t\t\tprojectRoot,\n\t\t\t\tappDir,\n\t\t\t)}.`,\n\t\t);\n\t}\n\n\treturn {\n\t\t...resource,\n\t\tassetBase: resource.stableHtmlPath.slice(0, -\".html\".length),\n\t\tpagePath: page.pagePath,\n\t\tlayoutPaths: page.layoutPaths,\n\t};\n}\n\nfunction findPageForRoute(\n\tappDir: string,\n\troutePath: string,\n): { pagePath: string; layoutPaths: string[] } | null {\n\tconst pages: Array<{ pagePath: string; routePath: string }> = [];\n\tcollectPages(appDir, appDir, pages);\n\n\tconst matches = pages.filter((page) => page.routePath === routePath);\n\tif (matches.length === 0) {\n\t\treturn null;\n\t}\n\tif (matches.length > 1) {\n\t\tthrow new Error(\n\t\t\t`WaniWani widgets: multiple Next.js pages match ${routePath}: ${matches\n\t\t\t\t.map((match) => match.pagePath)\n\t\t\t\t.join(\", \")}`,\n\t\t);\n\t}\n\n\tconst pagePath = matches[0].pagePath;\n\treturn {\n\t\tpagePath,\n\t\tlayoutPaths: collectLayouts(appDir, dirname(pagePath)),\n\t};\n}\n\nfunction collectPages(\n\tappDir: string,\n\tcurrentDir: string,\n\tpages: Array<{ pagePath: string; routePath: string }>,\n): void {\n\tfor (const entry of readdirSync(currentDir).sort()) {\n\t\tconst absolutePath = join(currentDir, entry);\n\t\tconst stat = statSync(absolutePath);\n\t\tif (stat.isDirectory()) {\n\t\t\tcollectPages(appDir, absolutePath, pages);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!/^page\\.(tsx|ts|jsx|js)$/.test(entry)) {\n\t\t\tcontinue;\n\t\t}\n\t\tpages.push({\n\t\t\tpagePath: absolutePath,\n\t\t\troutePath: routePathForPage(appDir, absolutePath),\n\t\t});\n\t}\n}\n\nfunction routePathForPage(appDir: string, pagePath: string): string {\n\tconst relativeDir = relative(appDir, dirname(pagePath));\n\tconst segments = relativeDir\n\t\t.split(/[\\\\/]/)\n\t\t.filter(Boolean)\n\t\t.filter((segment) => !isRouteGroup(segment))\n\t\t.filter((segment) => !segment.startsWith(\"@\"));\n\n\treturn `/${segments.join(\"/\")}`.replace(/\\/$/, \"\") || \"/\";\n}\n\nfunction collectLayouts(appDir: string, pageDir: string): string[] {\n\tconst relativeDir = relative(appDir, pageDir);\n\tconst segments = relativeDir.split(/[\\\\/]/).filter(Boolean);\n\tconst layouts: string[] = [];\n\tlet currentDir = appDir;\n\n\tfor (const segment of segments) {\n\t\tcurrentDir = join(currentDir, segment);\n\t\tconst layout = findRouteFile(currentDir, \"layout\");\n\t\tif (layout) {\n\t\t\tlayouts.push(layout);\n\t\t}\n\t}\n\n\treturn layouts;\n}\n\nfunction findRouteFile(dir: string, basename: string): string | null {\n\tfor (const extension of [\"tsx\", \"ts\", \"jsx\", \"js\"]) {\n\t\tconst candidate = join(dir, `${basename}.${extension}`);\n\t\tif (existsSync(candidate)) {\n\t\t\treturn candidate;\n\t\t}\n\t}\n\treturn null;\n}\n\nfunction writeGeneratedEntry(\n\tprojectRoot: string,\n\tcacheDir: string,\n\toptions: WithWaniwaniWidgetsOptions,\n\ttarget: WidgetBuildTarget,\n): string {\n\tconst entryPath = resolve(cacheDir, `${safeFileName(target.id)}.tsx`);\n\tconst entryDir = dirname(entryPath);\n\tconst globalCssPath = resolveGlobalCss(projectRoot, options.globalCss);\n\tconst layoutImports = target.layoutPaths\n\t\t.map(\n\t\t\t(layoutPath, index) =>\n\t\t\t\t`import Layout${index} from ${JSON.stringify(importPath(entryDir, layoutPath))};`,\n\t\t)\n\t\t.join(\"\\n\");\n\tconst layoutWraps = target.layoutPaths\n\t\t.map(\n\t\t\t(_, index) =>\n\t\t\t\t`\\tchildren = <Layout${target.layoutPaths.length - index - 1}>{children}</Layout${target.layoutPaths.length - index - 1}>;`,\n\t\t)\n\t\t.join(\"\\n\");\n\tconst fallbackProvider =\n\t\ttarget.layoutPaths.length === 0\n\t\t\t? \"\\tchildren = <WidgetProvider loading={<LoadingWidget />}>{children}</WidgetProvider>;\"\n\t\t\t: \"\";\n\n\twriteFileSync(\n\t\tentryPath,\n\t\t[\n\t\t\t'import React from \"react\";',\n\t\t\t'import { createRoot } from \"react-dom/client\";',\n\t\t\ttarget.layoutPaths.length === 0\n\t\t\t\t? 'import { LoadingWidget, WidgetProvider } from \"@waniwani/sdk/mcp/react\";'\n\t\t\t\t: \"\",\n\t\t\tglobalCssPath\n\t\t\t\t? `import ${JSON.stringify(importPath(entryDir, globalCssPath))};`\n\t\t\t\t: \"\",\n\t\t\t`import Page from ${JSON.stringify(importPath(entryDir, target.pagePath))};`,\n\t\t\tlayoutImports,\n\t\t\t\"\",\n\t\t\t\"function Widget() {\",\n\t\t\t\"\\tlet children = <Page />;\",\n\t\t\tlayoutWraps,\n\t\t\tfallbackProvider,\n\t\t\t\"\\treturn children;\",\n\t\t\t\"}\",\n\t\t\t\"\",\n\t\t\t'createRoot(document.getElementById(\"root\")!).render(<Widget />);',\n\t\t\t\"\",\n\t\t]\n\t\t\t.filter((line) => line !== \"\")\n\t\t\t.join(\"\\n\"),\n\t);\n\n\treturn entryPath;\n}\n\nfunction writeWidgetHtml(projectRoot: string, target: WidgetBuildTarget): void {\n\tconst assetBase = target.assetBase;\n\tconst cssPath = resolve(projectRoot, \"public\", `${assetBase}.css`);\n\tconst htmlPath = resolve(\n\t\tprojectRoot,\n\t\t\"public\",\n\t\ttarget.stableHtmlPath.slice(1),\n\t);\n\tconst initMarkup = renderToStaticMarkup(\n\t\tcreateElement(InitializeNextJsInIframe, {\n\t\t\tbaseUrl: WANIWANI_WIDGET_BASE_URL_PLACEHOLDER,\n\t\t}),\n\t);\n\tconst cssTag = existsSync(cssPath)\n\t\t? `<link rel=\"stylesheet\" href=\"${WANIWANI_WIDGET_BASE_URL_PLACEHOLDER}${assetBase}.css\">`\n\t\t: \"\";\n\n\tmkdirSync(dirname(htmlPath), { recursive: true });\n\twriteFileSync(\n\t\thtmlPath,\n\t\t`<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n${initMarkup}\n${cssTag}\n</head>\n<body>\n<div id=\"root\"></div>\n<script type=\"module\" src=\"${WANIWANI_WIDGET_BASE_URL_PLACEHOLDER}${assetBase}.js\"></script>\n</body>\n</html>\n`,\n\t);\n}\n\nfunction resolveGlobalCss(\n\tprojectRoot: string,\n\tglobalCss: string | false | undefined,\n): string | null {\n\tif (globalCss === false) {\n\t\treturn null;\n\t}\n\tconst candidate = resolveProjectPath(\n\t\tprojectRoot,\n\t\tglobalCss ?? \"app/globals.css\",\n\t);\n\treturn existsSync(candidate) ? candidate : null;\n}\n\nfunction toStableHtmlPath(id: string, htmlPath: string): string {\n\tif (isStableWidgetHtmlPath(htmlPath)) {\n\t\treturn htmlPath;\n\t}\n\n\tconst routePath = normalizeRoutePath(htmlPath);\n\tconst slug = routePath === \"/\" ? id : routePath.slice(1);\n\treturn `/widgets/${slug}.html`;\n}\n\nfunction isStableWidgetHtmlPath(htmlPath: string): boolean {\n\treturn (\n\t\thtmlPath.startsWith(\"/widgets/\") &&\n\t\thtmlPath.endsWith(\".html\") &&\n\t\t!htmlPath.includes(\"..\")\n\t);\n}\n\nfunction normalizeRoutePath(htmlPath: string): string {\n\tconst withoutQuery = htmlPath.split(/[?#]/)[0] || \"/\";\n\tconst withoutTrailingSlash =\n\t\twithoutQuery.length > 1 ? withoutQuery.replace(/\\/+$/, \"\") : withoutQuery;\n\treturn withoutTrailingSlash.startsWith(\"/\")\n\t\t? withoutTrailingSlash\n\t\t: `/${withoutTrailingSlash}`;\n}\n\nfunction stripWidgetsPrefix(assetBase: string): string {\n\treturn assetBase.replace(/^\\/widgets\\//, \"\");\n}\n\nfunction safeFileName(value: string): string {\n\treturn value.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n}\n\nfunction importPath(fromDir: string, targetPath: string): string {\n\tconst path = relative(fromDir, targetPath).replaceAll(\"\\\\\", \"/\");\n\treturn path.startsWith(\".\") ? path : `./${path}`;\n}\n\nfunction resolveProjectPath(projectRoot: string, path: string): string {\n\treturn path.startsWith(\"/\") ? path : resolve(projectRoot, path);\n}\n\nfunction isRouteGroup(segment: string): boolean {\n\treturn segment.startsWith(\"(\") && segment.endsWith(\")\");\n}\n\nif (process.argv[2] === BUILD_ARG) {\n\tconst payload = process.argv[3];\n\tif (!payload) {\n\t\tconsole.error(\"WaniWani widgets: missing build payload.\");\n\t\tprocess.exit(1);\n\t}\n\n\tconst options = JSON.parse(\n\t\tBuffer.from(payload, \"base64\").toString(\"utf8\"),\n\t) as WithWaniwaniWidgetsOptions;\n\n\tbuildWaniwaniWidgets(options).catch((error) => {\n\t\tconsole.error(error);\n\t\tprocess.exit(1);\n\t});\n}\n","/**\n * Initializes & patches Next.js functionality so an app can run as a\n * widget inside a cross-origin iframe. Used by every MCP widget host —\n * ChatGPT's sandbox, the embed's `/api/mcp/chat/resource` proxy, and any\n * future host that renders the widget on a domain other than its own\n * `baseUrl`.\n *\n * What it patches:\n * - `history.pushState` / `history.replaceState` — prevents full-origin\n * URLs from ending up in the iframe's history (browsers reject cross-\n * origin pushes in sandboxed iframes).\n * - `window.fetch` — rewrites same-origin requests to the widget's real\n * `baseUrl`. Without this, relative `/api/...` calls from the widget\n * hit the host's origin (ChatGPT sandbox, WaniWani embed proxy, etc.)\n * and 404. `passthroughOrigins` opts specific origins out of the\n * rewrite (see prop doc).\n * - `<html>` attribute observer — strips attributes the host injects\n * after hydration (ChatGPT mutates `<html>` for theming), while\n * preserving `class` / `style` / `lang`.\n *\n * More background on the ChatGPT case:\n * https://vercel.com/blog/running-next-js-inside-chatgpt-a-deep-dive-into-native-app-integration\n */\nexport function InitializeNextJsInIframe({\n\tbaseUrl,\n\tpassthroughOrigins,\n}: {\n\tbaseUrl: string;\n\t/**\n\t * Origins whose fetches should skip the same-origin → baseUrl rewrite.\n\t * Set this to the WaniWani API origin when the widget is loaded through\n\t * a proxy that shares origin with the API (e.g. the embed's\n\t * `/api/mcp/chat/resource` route on `app.waniwani.ai`). Without this,\n\t * widget tracking calls to the WaniWani API get rewritten to the\n\t * widget's own host and 404.\n\t */\n\tpassthroughOrigins?: string[];\n}) {\n\treturn (\n\t\t<>\n\t\t\t<base href={baseUrl}></base>\n\t\t\t<script>{`window.innerBaseUrl = ${JSON.stringify(baseUrl)}`}</script>\n\t\t\t<script>{`window.__wwPassthroughOrigins = ${JSON.stringify(passthroughOrigins ?? [])}`}</script>\n\t\t\t<script>{`window.__isChatGptApp = typeof window.openai !== \"undefined\";`}</script>\n\t\t\t<script>\n\t\t\t\t{\"(\" +\n\t\t\t\t\t(() => {\n\t\t\t\t\t\tconst baseUrl = window.innerBaseUrl;\n\t\t\t\t\t\tconst passthroughOrigins: string[] =\n\t\t\t\t\t\t\t(window as unknown as { __wwPassthroughOrigins: string[] })\n\t\t\t\t\t\t\t\t.__wwPassthroughOrigins ?? [];\n\t\t\t\t\t\tconst htmlElement = document.documentElement;\n\t\t\t\t\t\tconst observer = new MutationObserver((mutations) => {\n\t\t\t\t\t\t\tmutations.forEach((mutation) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tmutation.type === \"attributes\" &&\n\t\t\t\t\t\t\t\t\tmutation.target === htmlElement\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tconst attrName = mutation.attributeName;\n\t\t\t\t\t\t\t\t\t// Preserve class/style for theming (html.dark) and lang for i18n\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tattrName &&\n\t\t\t\t\t\t\t\t\t\tattrName !== \"suppresshydrationwarning\" &&\n\t\t\t\t\t\t\t\t\t\tattrName !== \"lang\" &&\n\t\t\t\t\t\t\t\t\t\tattrName !== \"class\" &&\n\t\t\t\t\t\t\t\t\t\tattrName !== \"style\"\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\thtmlElement.removeAttribute(attrName);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t\tobserver.observe(htmlElement, {\n\t\t\t\t\t\t\tattributes: true,\n\t\t\t\t\t\t\tattributeOldValue: true,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tconst originalReplaceState = history.replaceState.bind(history);\n\t\t\t\t\t\thistory.replaceState = (\n\t\t\t\t\t\t\t_s: unknown,\n\t\t\t\t\t\t\tunused: string,\n\t\t\t\t\t\t\turl?: string | URL | null,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst u = new URL(String(url ?? \"\"), window.location.href);\n\t\t\t\t\t\t\t\toriginalReplaceState(\n\t\t\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t\t\tunused,\n\t\t\t\t\t\t\t\t\tu.pathname + u.search + u.hash,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t/* SecurityError in sandboxed iframe */\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tconst originalPushState = history.pushState.bind(history);\n\t\t\t\t\t\thistory.pushState = (\n\t\t\t\t\t\t\t_s: unknown,\n\t\t\t\t\t\t\tunused: string,\n\t\t\t\t\t\t\turl?: string | URL | null,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst u = new URL(String(url ?? \"\"), window.location.href);\n\t\t\t\t\t\t\t\toriginalPushState(null, unused, u.pathname + u.search + u.hash);\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t/* SecurityError in sandboxed iframe */\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tconst appOrigin = new URL(baseUrl).origin;\n\t\t\t\t\t\tconst isInIframe = window.self !== window.top;\n\n\t\t\t\t\t\twindow.addEventListener(\n\t\t\t\t\t\t\t\"click\",\n\t\t\t\t\t\t\t(e) => {\n\t\t\t\t\t\t\t\tconst a = (e?.target as HTMLElement)?.closest(\"a\");\n\t\t\t\t\t\t\t\tif (!a || !a.href) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst url = new URL(a.href, window.location.href);\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\turl.origin !== window.location.origin &&\n\t\t\t\t\t\t\t\t\turl.origin !== appOrigin\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tif (window.openai) {\n\t\t\t\t\t\t\t\t\t\t\twindow.openai?.openExternal({ href: a.href });\n\t\t\t\t\t\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t\t\t\"openExternal failed, likely not in OpenAI client\",\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (isInIframe && window.location.origin !== appOrigin) {\n\t\t\t\t\t\t\tconst originalFetch = window.fetch;\n\n\t\t\t\t\t\t\t(window as { fetch: typeof window.fetch }).fetch = ((\n\t\t\t\t\t\t\t\tinput: URL | RequestInfo,\n\t\t\t\t\t\t\t\tinit?: RequestInit,\n\t\t\t\t\t\t\t): Promise<Response> => {\n\t\t\t\t\t\t\t\tlet url: URL;\n\t\t\t\t\t\t\t\tif (typeof input === \"string\" || input instanceof URL) {\n\t\t\t\t\t\t\t\t\turl = new URL(input, window.location.href);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\turl = new URL(input.url, window.location.href);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (url.origin === appOrigin) {\n\t\t\t\t\t\t\t\t\tif (typeof input === \"string\" || input instanceof URL) {\n\t\t\t\t\t\t\t\t\t\tinput = url.toString();\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tinput = new Request(url.toString(), input);\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn originalFetch.call(window, input, {\n\t\t\t\t\t\t\t\t\t\t...init,\n\t\t\t\t\t\t\t\t\t\tmode: \"cors\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// Explicit passthrough list — never rewrite these.\n\t\t\t\t\t\t\t\t// Needed when the widget shares origin with a\n\t\t\t\t\t\t\t\t// non-Next-app host (e.g. the WaniWani app serving the\n\t\t\t\t\t\t\t\t// embed iframe + the tracking API from the same host).\n\t\t\t\t\t\t\t\tif (passthroughOrigins.indexOf(url.origin) !== -1) {\n\t\t\t\t\t\t\t\t\treturn originalFetch.call(window, input, init);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (url.origin === window.location.origin) {\n\t\t\t\t\t\t\t\t\tconst newUrl = new URL(baseUrl);\n\t\t\t\t\t\t\t\t\tnewUrl.pathname = url.pathname;\n\t\t\t\t\t\t\t\t\tnewUrl.search = url.search;\n\t\t\t\t\t\t\t\t\tnewUrl.hash = url.hash;\n\t\t\t\t\t\t\t\t\turl = newUrl;\n\n\t\t\t\t\t\t\t\t\tif (typeof input === \"string\" || input instanceof URL) {\n\t\t\t\t\t\t\t\t\t\tinput = url.toString();\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tinput = new Request(url.toString(), input);\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn originalFetch.call(window, input, {\n\t\t\t\t\t\t\t\t\t\t...init,\n\t\t\t\t\t\t\t\t\t\tmode: \"cors\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn originalFetch.call(window, input, init);\n\t\t\t\t\t\t\t}) as typeof window.fetch;\n\t\t\t\t\t\t}\n\t\t\t\t\t}).toString() +\n\t\t\t\t\t\")()\"}\n\t\t\t</script>\n\t\t</>\n\t);\n}\n","import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nexport const WANIWANI_WIDGET_BASE_URL_PLACEHOLDER =\n\t\"__WANIWANI_WIDGET_BASE_URL__\";\n\n/**\n * Directory inside the consuming project where `withWaniwaniWidgets()`\n * stores generated build artifacts (currently the widget manifest).\n * Anchoring on the project root rather than `node_modules/@waniwani/sdk`\n * avoids polluting pnpm's content-addressed store across consumers.\n */\nexport const WANIWANI_BUILD_DIR = \".waniwani\";\nexport const WANIWANI_WIDGETS_MANIFEST_FILENAME = \"widgets-manifest.json\";\n/** Path relative to the project root, e.g. for `outputFileTracingIncludes`. */\nexport const WANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH = `${WANIWANI_BUILD_DIR}/${WANIWANI_WIDGETS_MANIFEST_FILENAME}`;\n\nexport type WaniwaniWidgetsManifest = {\n\tversion: 1;\n\tbyId: Record<string, string>;\n\tbyHtmlPath: Record<string, string>;\n};\n\n/**\n * Absolute path to the manifest JSON for a given project root. Defaults to\n * `process.cwd()`, which is correct for both `next start` and Vercel\n * serverless functions (where the deployed function root preserves files\n * pulled in via `outputFileTracingIncludes`).\n */\nexport function getManifestFilePath(projectRoot?: string): string {\n\treturn resolve(\n\t\tprojectRoot ?? process.cwd(),\n\t\tWANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH,\n\t);\n}\n\nlet cachedManifestPath: string | undefined;\nlet cachedManifest: WaniwaniWidgetsManifest | null | undefined;\nlet testOverrideManifest: WaniwaniWidgetsManifest | null | undefined;\n\nfunction getManifest(): WaniwaniWidgetsManifest | null {\n\tif (testOverrideManifest !== undefined) {\n\t\treturn testOverrideManifest;\n\t}\n\n\tconst manifestPath = getManifestFilePath();\n\tif (cachedManifestPath === manifestPath && cachedManifest !== undefined) {\n\t\treturn cachedManifest;\n\t}\n\n\tcachedManifestPath = manifestPath;\n\ttry {\n\t\tconst raw = readFileSync(manifestPath, \"utf8\");\n\t\tcachedManifest = JSON.parse(raw) as WaniwaniWidgetsManifest;\n\t} catch {\n\t\tcachedManifest = null;\n\t}\n\treturn cachedManifest;\n}\n\n/** Test-only: override the manifest used by `resolveResourceHtmlPath`. */\nexport function __setManifestForTesting(\n\tmanifest: WaniwaniWidgetsManifest | null | undefined,\n): void {\n\ttestOverrideManifest = manifest;\n\tcachedManifest = undefined;\n\tcachedManifestPath = undefined;\n}\n\nexport function getDefaultResourceHtmlPath(id: string): string {\n\treturn `/${id}`;\n}\n\nexport function resolveResourceHtmlPath(id: string, htmlPath?: string): string {\n\tconst configuredHtmlPath = htmlPath ?? getDefaultResourceHtmlPath(id);\n\tconst manifest = getManifest();\n\n\treturn (\n\t\tmanifest?.byHtmlPath[configuredHtmlPath] ??\n\t\tmanifest?.byId[id] ??\n\t\tconfiguredHtmlPath\n\t);\n}\n\nexport function replaceWidgetTemplatePlaceholders(\n\thtml: string,\n\tbaseUrl: string,\n): string {\n\tconst normalizedBaseUrl = baseUrl.endsWith(\"/\")\n\t\t? baseUrl.slice(0, -1)\n\t\t: baseUrl;\n\treturn html.replaceAll(\n\t\tWANIWANI_WIDGET_BASE_URL_PLACEHOLDER,\n\t\tnormalizedBaseUrl,\n\t);\n}\n"],"mappings":"AAAA,OAAS,aAAAA,MAAiB,gBAC1B,OACC,cAAAC,EACA,aAAAC,EACA,eAAAC,EACA,gBAAAC,EACA,UAAAC,EACA,YAAAC,EACA,iBAAAC,MACM,KACP,OAAS,WAAAC,EAAS,QAAAC,EAAM,Y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,OAAOA,EAAQ,WAAW,GAAG,GAAKA,EAAQ,SAAS,GAAG,CACvD,CAEA,GAAI,QAAQ,KAAK,CAAC,IAAMnG,EAAW,CAClC,IAAM6B,EAAU,QAAQ,KAAK,CAAC,EACzBA,IACJ,QAAQ,MAAM,0CAA0C,EACxD,QAAQ,KAAK,CAAC,GAGf,IAAMzB,EAAU,KAAK,MACpB,OAAO,KAAKyB,EAAS,QAAQ,EAAE,SAAS,MAAM,CAC/C,EAEAG,GAAqB5B,CAAO,EAAE,MAAOoI,GAAU,CAC9C,QAAQ,MAAMA,CAAK,EACnB,QAAQ,KAAK,CAAC,CACf,CAAC,CACF","names":["spawnSync","existsSync","mkdirSync","readdirSync","readFileSync","rmSync","statSync","writeFileSync","dirname","join","relative","resolve","fileURLToPath","createElement","renderToStaticMarkup","Fragment","jsx","jsxs","InitializeNextJsInIframe","baseUrl","passthroughOrigins","htmlElement","mutations","mutation","attrName","originalReplaceState","_s","unused","url","originalPushState","appOrigin","isInIframe","e","a","originalFetch","input","init","newUrl","readFileSync","resolve","WANIWANI_WIDGET_BASE_URL_PLACEHOLDER","WANIWANI_BUILD_DIR","WANIWANI_WIDGETS_MANIFEST_FILENAME","WANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH","getManifestFilePath","projectRoot","BUILD_ARG","builtKeys","withWaniwaniWidgets","nextConfig","options","args","result","config","enhanceNextConfig","projectRoot","resolve","resources","discoverResources","manifest","createManifest","writeManifestFile","originalHeaders","originalWebpack","manifestTraceTarget","WANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH","existingTracingIncludes","buildWidgetsSync","context","manifestPath","getManifestFilePath","mkdirSync","dirname","writeFileSync","key","payload","spawnSync","fileURLToPath","buildWaniwaniWidgets","targets","resource","resolveBuildTarget","cacheDir","publicWidgetsDir","build","react","tailwindcss","target","entryPath","writeGeneratedEntry","assetBase","rmSync","assetInfo","name","stripWidgetsPrefix","writeWidgetHtml","resourcesPath","absolutePath","resolveProjectPath","source","readFileSync","objectSource","findCreateResourceObjects","id","readStringProperty","htmlPath","stableHtmlPath","toStableHtmlPath","isStableWidgetHtmlPath","objects","index","callIndex","openParen","openBrace","closeBrace","findMatchingBrace","depth","quote","escaped","lineComment","blockComment","char","next","propertyName","pattern","byId","byHtmlPath","appDir","routePath","normalizeRoutePath","page","findPageForRoute","relative","pages","collectPages","matches","match","pagePath","collectLayouts","currentDir","entry","readdirSync","join","statSync","routePathForPage","segment","isRouteGroup","pageDir","segments","layouts","layout","findRouteFile","dir","basename","extension","candidate","existsSync","safeFileName","entryDir","globalCssPath","resolveGlobalCss","layoutImports","layoutPath","importPath","layoutWraps","_","fallbackProvider","line","cssPath","initMarkup","renderToStaticMarkup","createElement","InitializeNextJsInIframe","WANIWANI_WIDGET_BASE_URL_PLACEHOLDER","cssTag","globalCss","withoutQuery","withoutTrailingSlash","value","fromDir","targetPath","path","error"]}
1
+ {"version":3,"sources":["../../src/next/index.ts","../../src/mcp/react/components/initialize-next-in-iframe.tsx","../../src/mcp/server/resources/widget-manifest.ts"],"sourcesContent":["import { spawnSync } from \"node:child_process\";\nimport {\n\texistsSync,\n\tmkdirSync,\n\treaddirSync,\n\treadFileSync,\n\trmSync,\n\tstatSync,\n\twriteFileSync,\n} from \"node:fs\";\nimport { dirname, join, relative, resolve } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport { createElement } from \"react\";\nimport { renderToStaticMarkup } from \"react-dom/server\";\nimport { InitializeNextJsInIframe } from \"../mcp/react/components/initialize-next-in-iframe\";\nimport {\n\tgetManifestFilePath,\n\tWANIWANI_WIDGET_BASE_URL_PLACEHOLDER,\n\tWANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH,\n\ttype WaniwaniWidgetsManifest,\n} from \"../mcp/server/resources/widget-manifest\";\n\ntype Header = {\n\tkey: string;\n\tvalue: string;\n};\n\ntype HeaderRoute = {\n\tsource: string;\n\theaders: Header[];\n};\n\ntype WebpackContext = {\n\tdev?: boolean;\n\tisServer?: boolean;\n};\n\ntype NextConfigObject = {\n\tenv?: Record<string, string | undefined>;\n\theaders?: () => HeaderRoute[] | Promise<HeaderRoute[]>;\n\twebpack?: (config: unknown, context: WebpackContext) => unknown;\n\tturbopack?: Record<string, unknown>;\n\toutputFileTracingIncludes?: Record<string, string[]>;\n\t[key: string]: unknown;\n};\n\ntype NextConfigFactory = (\n\t...args: unknown[]\n) => NextConfigObject | Promise<NextConfigObject>;\n\nexport type WithWaniwaniWidgetsOptions = {\n\t/** Resource module that contains createResource(...) calls. */\n\tresources: string;\n\t/** Project root. Defaults to process.cwd(). */\n\tprojectRoot?: string;\n\t/** Next app directory. Defaults to ./app. */\n\tappDir?: string;\n\t/** Global CSS imported into every generated widget entry. Defaults to ./app/globals.css when present. */\n\tglobalCss?: string | false;\n};\n\ntype DiscoveredResource = {\n\tid: string;\n\thtmlPath: string;\n\tstableHtmlPath: string;\n\tprebuilt: boolean;\n};\n\ntype WidgetBuildTarget = DiscoveredResource & {\n\tassetBase: string;\n\tpagePath: string;\n\tlayoutPaths: string[];\n};\n\nconst BUILD_ARG = \"__waniwani_build_widgets\";\nconst builtKeys = new Set<string>();\n\nexport function withWaniwaniWidgets<\n\tT extends NextConfigObject | NextConfigFactory,\n>(nextConfig: T, options: WithWaniwaniWidgetsOptions): T {\n\tif (typeof nextConfig === \"function\") {\n\t\treturn ((...args: unknown[]) => {\n\t\t\tconst result = nextConfig(...args);\n\t\t\tif (\n\t\t\t\tresult &&\n\t\t\t\ttypeof (result as Promise<NextConfigObject>).then === \"function\"\n\t\t\t) {\n\t\t\t\treturn (result as Promise<NextConfigObject>).then((config) =>\n\t\t\t\t\tenhanceNextConfig(config, options),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn enhanceNextConfig(result as NextConfigObject, options);\n\t\t}) as T;\n\t}\n\n\treturn enhanceNextConfig(nextConfig, options) as T;\n}\n\nfunction enhanceNextConfig(\n\tnextConfig: NextConfigObject,\n\toptions: WithWaniwaniWidgetsOptions,\n): NextConfigObject {\n\tconst projectRoot = resolve(options.projectRoot ?? process.cwd());\n\tconst resources = discoverResources(projectRoot, options.resources);\n\tconst manifest = createManifest(resources);\n\twriteManifestFile(projectRoot, manifest);\n\tconst originalHeaders = nextConfig.headers;\n\tconst originalWebpack = nextConfig.webpack;\n\tconst manifestTraceTarget = `./${WANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH}`;\n\tconst existingTracingIncludes = nextConfig.outputFileTracingIncludes ?? {};\n\n\treturn {\n\t\t...nextConfig,\n\t\t// Empty `turbopack` key signals to Next.js 16 that the consumer is\n\t\t// aware their config touches both bundlers; without it Next errors out\n\t\t// when the user runs Turbopack with a custom `webpack()` hook.\n\t\tturbopack: { ...(nextConfig.turbopack ?? {}) },\n\t\toutputFileTracingIncludes: {\n\t\t\t...existingTracingIncludes,\n\t\t\t\"/**/*\": [\n\t\t\t\t...(existingTracingIncludes[\"/**/*\"] ?? []),\n\t\t\t\tmanifestTraceTarget,\n\t\t\t],\n\t\t},\n\t\tasync headers() {\n\t\t\tbuildWidgetsSync(projectRoot, options);\n\t\t\tconst existing = originalHeaders ? await originalHeaders() : [];\n\t\t\treturn [\n\t\t\t\t...existing,\n\t\t\t\t{\n\t\t\t\t\tsource: \"/widgets/:path*\",\n\t\t\t\t\theaders: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkey: \"Cache-Control\",\n\t\t\t\t\t\t\tvalue: \"public, max-age=0, must-revalidate\",\n\t\t\t\t\t\t},\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tkey: \"Access-Control-Allow-Origin\",\n\t\t\t\t\t\t\tvalue: \"*\",\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t];\n\t\t},\n\t\twebpack(config: unknown, context: WebpackContext) {\n\t\t\tif (context.isServer) {\n\t\t\t\tbuildWidgetsSync(projectRoot, options);\n\t\t\t}\n\t\t\treturn originalWebpack ? originalWebpack(config, context) : config;\n\t\t},\n\t};\n}\n\nfunction writeManifestFile(\n\tprojectRoot: string,\n\tmanifest: WaniwaniWidgetsManifest,\n): void {\n\tconst manifestPath = getManifestFilePath(projectRoot);\n\tmkdirSync(dirname(manifestPath), { recursive: true });\n\twriteFileSync(manifestPath, JSON.stringify(manifest));\n}\n\nfunction buildWidgetsSync(\n\tprojectRoot: string,\n\toptions: WithWaniwaniWidgetsOptions,\n): void {\n\tif (process.env.WANIWANI_WIDGETS_SKIP_BUILD === \"1\") {\n\t\treturn;\n\t}\n\n\tconst key = JSON.stringify({ projectRoot, options });\n\tif (builtKeys.has(key)) {\n\t\treturn;\n\t}\n\tbuiltKeys.add(key);\n\n\tconst payload = Buffer.from(\n\t\tJSON.stringify({ ...options, projectRoot }),\n\t\t\"utf8\",\n\t).toString(\"base64\");\n\tconst result = spawnSync(\n\t\tprocess.execPath,\n\t\t[fileURLToPath(import.meta.url), BUILD_ARG, payload],\n\t\t{\n\t\t\tcwd: projectRoot,\n\t\t\tstdio: \"inherit\",\n\t\t\tenv: process.env,\n\t\t},\n\t);\n\n\tif (result.status !== 0) {\n\t\tthrow new Error(\n\t\t\t`WaniWani widget build failed with exit code ${result.status ?? \"unknown\"}`,\n\t\t);\n\t}\n}\n\nasync function buildWaniwaniWidgets(\n\toptions: WithWaniwaniWidgetsOptions,\n): Promise<void> {\n\tconst projectRoot = resolve(options.projectRoot ?? process.cwd());\n\tconst resources = discoverResources(projectRoot, options.resources);\n\tconst targets = resources\n\t\t.filter((resource) => !resource.prebuilt)\n\t\t.map((resource) => resolveBuildTarget(projectRoot, options, resource));\n\n\tif (targets.length === 0) {\n\t\treturn;\n\t}\n\n\tconst cacheDir = resolve(projectRoot, \"node_modules/.cache/waniwani/widgets\");\n\tconst publicWidgetsDir = resolve(projectRoot, \"public/widgets\");\n\tmkdirSync(cacheDir, { recursive: true });\n\tmkdirSync(publicWidgetsDir, { recursive: true });\n\n\tconst [{ build }, react, tailwindcss] = await Promise.all([\n\t\timport(\"vite\"),\n\t\timport(\"@vitejs/plugin-react\"),\n\t\timport(\"@tailwindcss/vite\"),\n\t]);\n\n\tfor (const target of targets) {\n\t\tconst entryPath = writeGeneratedEntry(\n\t\t\tprojectRoot,\n\t\t\tcacheDir,\n\t\t\toptions,\n\t\t\ttarget,\n\t\t);\n\t\tconst assetBase = target.assetBase;\n\n\t\trmSync(resolve(projectRoot, \"public\", `${assetBase}.js`), { force: true });\n\t\trmSync(resolve(projectRoot, \"public\", `${assetBase}.css`), { force: true });\n\n\t\tawait build({\n\t\t\troot: projectRoot,\n\t\t\tconfigFile: false,\n\t\t\tpublicDir: false,\n\t\t\tlogLevel: \"warn\",\n\t\t\tplugins: [react.default(), tailwindcss.default()],\n\t\t\tcss: {\n\t\t\t\tpostcss: {\n\t\t\t\t\tplugins: [],\n\t\t\t\t},\n\t\t\t},\n\t\t\tresolve: {\n\t\t\t\talias: [{ find: \"@\", replacement: projectRoot }],\n\t\t\t},\n\t\t\tdefine: {\n\t\t\t\t\"process.env.NODE_ENV\": JSON.stringify(\"production\"),\n\t\t\t},\n\t\t\tbuild: {\n\t\t\t\tcssCodeSplit: false,\n\t\t\t\temptyOutDir: false,\n\t\t\t\tminify: true,\n\t\t\t\toutDir: publicWidgetsDir,\n\t\t\t\trollupOptions: {\n\t\t\t\t\tinput: entryPath,\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tassetFileNames: (assetInfo) => {\n\t\t\t\t\t\t\tif (assetInfo.names.some((name) => name.endsWith(\".css\"))) {\n\t\t\t\t\t\t\t\treturn `${stripWidgetsPrefix(assetBase)}.css`;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn `${stripWidgetsPrefix(assetBase)}-[name][extname]`;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tchunkFileNames: `${stripWidgetsPrefix(assetBase)}.js`,\n\t\t\t\t\t\tcodeSplitting: false,\n\t\t\t\t\t\tentryFileNames: `${stripWidgetsPrefix(assetBase)}.js`,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tsourcemap: false,\n\t\t\t\ttarget: \"es2020\",\n\t\t\t},\n\t\t});\n\n\t\twriteWidgetHtml(projectRoot, target);\n\t}\n}\n\nfunction discoverResources(\n\tprojectRoot: string,\n\tresourcesPath: string,\n): DiscoveredResource[] {\n\tconst absolutePath = resolveProjectPath(projectRoot, resourcesPath);\n\tconst source = readFileSync(absolutePath, \"utf8\");\n\tconst resources: DiscoveredResource[] = [];\n\n\tfor (const objectSource of findCreateResourceObjects(source)) {\n\t\tconst id = readStringProperty(objectSource, \"id\");\n\t\tif (!id) {\n\t\t\tthrow new Error(\n\t\t\t\t`WaniWani widgets: createResource in ${resourcesPath} must use a string literal id.`,\n\t\t\t);\n\t\t}\n\n\t\tconst htmlPath = readStringProperty(objectSource, \"htmlPath\") ?? `/${id}`;\n\t\tconst stableHtmlPath = toStableHtmlPath(id, htmlPath);\n\t\tresources.push({\n\t\t\tid,\n\t\t\thtmlPath,\n\t\t\tstableHtmlPath,\n\t\t\tprebuilt: isStableWidgetHtmlPath(htmlPath),\n\t\t});\n\t}\n\n\treturn resources;\n}\n\nfunction findCreateResourceObjects(source: string): string[] {\n\tconst objects: string[] = [];\n\tlet index = 0;\n\n\twhile (index < source.length) {\n\t\tconst callIndex = source.indexOf(\"createResource\", index);\n\t\tif (callIndex === -1) {\n\t\t\tbreak;\n\t\t}\n\n\t\tlet openParen = callIndex + \"createResource\".length;\n\t\twhile (/\\s/.test(source[openParen] ?? \"\")) {\n\t\t\topenParen++;\n\t\t}\n\t\tif (source[openParen] !== \"(\") {\n\t\t\tindex = openParen + 1;\n\t\t\tcontinue;\n\t\t}\n\t\tconst openBrace = source.indexOf(\"{\", openParen);\n\t\tif (openBrace === -1) {\n\t\t\tindex = callIndex + \"createResource\".length;\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst closeBrace = findMatchingBrace(source, openBrace);\n\t\tif (closeBrace === -1) {\n\t\t\tthrow new Error(\"WaniWani widgets: could not parse createResource call.\");\n\t\t}\n\n\t\tobjects.push(source.slice(openBrace, closeBrace + 1));\n\t\tindex = closeBrace + 1;\n\t}\n\n\treturn objects;\n}\n\nfunction findMatchingBrace(source: string, openBrace: number): number {\n\tlet depth = 0;\n\tlet quote: '\"' | \"'\" | \"`\" | null = null;\n\tlet escaped = false;\n\tlet lineComment = false;\n\tlet blockComment = false;\n\n\tfor (let index = openBrace; index < source.length; index++) {\n\t\tconst char = source[index];\n\t\tconst next = source[index + 1];\n\n\t\tif (lineComment) {\n\t\t\tif (char === \"\\n\") {\n\t\t\t\tlineComment = false;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (blockComment) {\n\t\t\tif (char === \"*\" && next === \"/\") {\n\t\t\t\tblockComment = false;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (quote) {\n\t\t\tif (escaped) {\n\t\t\t\tescaped = false;\n\t\t\t} else if (char === \"\\\\\") {\n\t\t\t\tescaped = true;\n\t\t\t} else if (char === quote) {\n\t\t\t\tquote = null;\n\t\t\t}\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && next === \"/\") {\n\t\t\tlineComment = true;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && next === \"*\") {\n\t\t\tblockComment = true;\n\t\t\tindex++;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === '\"' || char === \"'\" || char === \"`\") {\n\t\t\tquote = char;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"{\") {\n\t\t\tdepth++;\n\t\t} else if (char === \"}\") {\n\t\t\tdepth--;\n\t\t\tif (depth === 0) {\n\t\t\t\treturn index;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn -1;\n}\n\nfunction readStringProperty(\n\tsource: string,\n\tpropertyName: string,\n): string | null {\n\tconst pattern = new RegExp(\n\t\t`(?:^|[,\\\\n\\\\r])\\\\s*${propertyName}\\\\s*:\\\\s*([\"'\\`])([^\"'\\`]+)\\\\1`,\n\t);\n\tconst match = source.match(pattern);\n\treturn match?.[2] ?? null;\n}\n\nfunction createManifest(\n\tresources: DiscoveredResource[],\n): WaniwaniWidgetsManifest {\n\tconst byId: Record<string, string> = {};\n\tconst byHtmlPath: Record<string, string> = {};\n\n\tfor (const resource of resources) {\n\t\tbyId[resource.id] = resource.stableHtmlPath;\n\t\tbyHtmlPath[resource.htmlPath] = resource.stableHtmlPath;\n\t}\n\n\treturn {\n\t\tversion: 1,\n\t\tbyId,\n\t\tbyHtmlPath,\n\t};\n}\n\nfunction resolveBuildTarget(\n\tprojectRoot: string,\n\toptions: WithWaniwaniWidgetsOptions,\n\tresource: DiscoveredResource,\n): WidgetBuildTarget {\n\tconst appDir = resolveProjectPath(projectRoot, options.appDir ?? \"app\");\n\tconst routePath = normalizeRoutePath(resource.htmlPath);\n\tconst page = findPageForRoute(appDir, routePath);\n\n\tif (!page) {\n\t\tthrow new Error(\n\t\t\t`WaniWani widgets: could not find a Next.js page for ${resource.htmlPath} under ${relative(\n\t\t\t\tprojectRoot,\n\t\t\t\tappDir,\n\t\t\t)}.`,\n\t\t);\n\t}\n\n\treturn {\n\t\t...resource,\n\t\tassetBase: resource.stableHtmlPath.slice(0, -\".html\".length),\n\t\tpagePath: page.pagePath,\n\t\tlayoutPaths: page.layoutPaths,\n\t};\n}\n\nfunction findPageForRoute(\n\tappDir: string,\n\troutePath: string,\n): { pagePath: string; layoutPaths: string[] } | null {\n\tconst pages: Array<{ pagePath: string; routePath: string }> = [];\n\tcollectPages(appDir, appDir, pages);\n\n\tconst matches = pages.filter((page) => page.routePath === routePath);\n\tif (matches.length === 0) {\n\t\treturn null;\n\t}\n\tif (matches.length > 1) {\n\t\tthrow new Error(\n\t\t\t`WaniWani widgets: multiple Next.js pages match ${routePath}: ${matches\n\t\t\t\t.map((match) => match.pagePath)\n\t\t\t\t.join(\", \")}`,\n\t\t);\n\t}\n\n\tconst pagePath = matches[0].pagePath;\n\treturn {\n\t\tpagePath,\n\t\tlayoutPaths: collectLayouts(appDir, dirname(pagePath)),\n\t};\n}\n\nfunction collectPages(\n\tappDir: string,\n\tcurrentDir: string,\n\tpages: Array<{ pagePath: string; routePath: string }>,\n): void {\n\tfor (const entry of readdirSync(currentDir).sort()) {\n\t\tconst absolutePath = join(currentDir, entry);\n\t\tconst stat = statSync(absolutePath);\n\t\tif (stat.isDirectory()) {\n\t\t\tcollectPages(appDir, absolutePath, pages);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!/^page\\.(tsx|ts|jsx|js)$/.test(entry)) {\n\t\t\tcontinue;\n\t\t}\n\t\tpages.push({\n\t\t\tpagePath: absolutePath,\n\t\t\troutePath: routePathForPage(appDir, absolutePath),\n\t\t});\n\t}\n}\n\nfunction routePathForPage(appDir: string, pagePath: string): string {\n\tconst relativeDir = relative(appDir, dirname(pagePath));\n\tconst segments = relativeDir\n\t\t.split(/[\\\\/]/)\n\t\t.filter(Boolean)\n\t\t.filter((segment) => !isRouteGroup(segment))\n\t\t.filter((segment) => !segment.startsWith(\"@\"));\n\n\treturn `/${segments.join(\"/\")}`.replace(/\\/$/, \"\") || \"/\";\n}\n\nfunction collectLayouts(appDir: string, pageDir: string): string[] {\n\tconst relativeDir = relative(appDir, pageDir);\n\tconst segments = relativeDir.split(/[\\\\/]/).filter(Boolean);\n\tconst layouts: string[] = [];\n\tlet currentDir = appDir;\n\n\tfor (const segment of segments) {\n\t\tcurrentDir = join(currentDir, segment);\n\t\tconst layout = findRouteFile(currentDir, \"layout\");\n\t\tif (layout) {\n\t\t\tlayouts.push(layout);\n\t\t}\n\t}\n\n\treturn layouts;\n}\n\nfunction findRouteFile(dir: string, basename: string): string | null {\n\tfor (const extension of [\"tsx\", \"ts\", \"jsx\", \"js\"]) {\n\t\tconst candidate = join(dir, `${basename}.${extension}`);\n\t\tif (existsSync(candidate)) {\n\t\t\treturn candidate;\n\t\t}\n\t}\n\treturn null;\n}\n\nfunction writeGeneratedEntry(\n\tprojectRoot: string,\n\tcacheDir: string,\n\toptions: WithWaniwaniWidgetsOptions,\n\ttarget: WidgetBuildTarget,\n): string {\n\tconst entryPath = resolve(cacheDir, `${safeFileName(target.id)}.tsx`);\n\tconst entryDir = dirname(entryPath);\n\tconst globalCssPath = resolveGlobalCss(projectRoot, options.globalCss);\n\tconst layoutImports = target.layoutPaths\n\t\t.map(\n\t\t\t(layoutPath, index) =>\n\t\t\t\t`import Layout${index} from ${JSON.stringify(importPath(entryDir, layoutPath))};`,\n\t\t)\n\t\t.join(\"\\n\");\n\tconst layoutWraps = target.layoutPaths\n\t\t.map(\n\t\t\t(_, index) =>\n\t\t\t\t`\\tchildren = <Layout${target.layoutPaths.length - index - 1}>{children}</Layout${target.layoutPaths.length - index - 1}>;`,\n\t\t)\n\t\t.join(\"\\n\");\n\tconst fallbackProvider =\n\t\ttarget.layoutPaths.length === 0\n\t\t\t? \"\\tchildren = <WidgetProvider loading={<LoadingWidget />}>{children}</WidgetProvider>;\"\n\t\t\t: \"\";\n\n\twriteFileSync(\n\t\tentryPath,\n\t\t[\n\t\t\t'import React from \"react\";',\n\t\t\t'import { createRoot } from \"react-dom/client\";',\n\t\t\ttarget.layoutPaths.length === 0\n\t\t\t\t? 'import { LoadingWidget, WidgetProvider } from \"@waniwani/sdk/mcp/react\";'\n\t\t\t\t: \"\",\n\t\t\tglobalCssPath\n\t\t\t\t? `import ${JSON.stringify(importPath(entryDir, globalCssPath))};`\n\t\t\t\t: \"\",\n\t\t\t`import Page from ${JSON.stringify(importPath(entryDir, target.pagePath))};`,\n\t\t\tlayoutImports,\n\t\t\t\"\",\n\t\t\t\"function Widget() {\",\n\t\t\t\"\\tlet children = <Page />;\",\n\t\t\tlayoutWraps,\n\t\t\tfallbackProvider,\n\t\t\t\"\\treturn children;\",\n\t\t\t\"}\",\n\t\t\t\"\",\n\t\t\t'createRoot(document.getElementById(\"root\")!).render(<Widget />);',\n\t\t\t\"\",\n\t\t]\n\t\t\t.filter((line) => line !== \"\")\n\t\t\t.join(\"\\n\"),\n\t);\n\n\treturn entryPath;\n}\n\nfunction writeWidgetHtml(projectRoot: string, target: WidgetBuildTarget): void {\n\tconst assetBase = target.assetBase;\n\t// `assetBase` is rooted at \"/\" (e.g. \"/widgets/comparison\"); strip the\n\t// leading slash so `path.resolve` doesn't treat it as an absolute path\n\t// and discard the `projectRoot` + \"public\" segments.\n\tconst cssPath = resolve(\n\t\tprojectRoot,\n\t\t\"public\",\n\t\t`${assetBase.replace(/^\\//, \"\")}.css`,\n\t);\n\tconst htmlPath = resolve(\n\t\tprojectRoot,\n\t\t\"public\",\n\t\ttarget.stableHtmlPath.slice(1),\n\t);\n\tconst initMarkup = renderToStaticMarkup(\n\t\tcreateElement(InitializeNextJsInIframe, {\n\t\t\tbaseUrl: WANIWANI_WIDGET_BASE_URL_PLACEHOLDER,\n\t\t}),\n\t);\n\tconst cssTag = existsSync(cssPath)\n\t\t? `<link rel=\"stylesheet\" href=\"${WANIWANI_WIDGET_BASE_URL_PLACEHOLDER}${assetBase}.css\">`\n\t\t: \"\";\n\n\tmkdirSync(dirname(htmlPath), { recursive: true });\n\twriteFileSync(\n\t\thtmlPath,\n\t\t`<!doctype html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n${initMarkup}\n${cssTag}\n</head>\n<body>\n<div id=\"root\"></div>\n<script type=\"module\" src=\"${WANIWANI_WIDGET_BASE_URL_PLACEHOLDER}${assetBase}.js\"></script>\n</body>\n</html>\n`,\n\t);\n}\n\nfunction resolveGlobalCss(\n\tprojectRoot: string,\n\tglobalCss: string | false | undefined,\n): string | null {\n\tif (globalCss === false) {\n\t\treturn null;\n\t}\n\tconst candidate = resolveProjectPath(\n\t\tprojectRoot,\n\t\tglobalCss ?? \"app/globals.css\",\n\t);\n\treturn existsSync(candidate) ? candidate : null;\n}\n\nfunction toStableHtmlPath(id: string, htmlPath: string): string {\n\tif (isStableWidgetHtmlPath(htmlPath)) {\n\t\treturn htmlPath;\n\t}\n\n\tconst routePath = normalizeRoutePath(htmlPath);\n\tconst slug = routePath === \"/\" ? id : routePath.slice(1);\n\treturn `/widgets/${slug}.html`;\n}\n\nfunction isStableWidgetHtmlPath(htmlPath: string): boolean {\n\treturn (\n\t\thtmlPath.startsWith(\"/widgets/\") &&\n\t\thtmlPath.endsWith(\".html\") &&\n\t\t!htmlPath.includes(\"..\")\n\t);\n}\n\nfunction normalizeRoutePath(htmlPath: string): string {\n\tconst withoutQuery = htmlPath.split(/[?#]/)[0] || \"/\";\n\tconst withoutTrailingSlash =\n\t\twithoutQuery.length > 1 ? withoutQuery.replace(/\\/+$/, \"\") : withoutQuery;\n\treturn withoutTrailingSlash.startsWith(\"/\")\n\t\t? withoutTrailingSlash\n\t\t: `/${withoutTrailingSlash}`;\n}\n\nfunction stripWidgetsPrefix(assetBase: string): string {\n\treturn assetBase.replace(/^\\/widgets\\//, \"\");\n}\n\nfunction safeFileName(value: string): string {\n\treturn value.replace(/[^a-zA-Z0-9_-]/g, \"_\");\n}\n\nfunction importPath(fromDir: string, targetPath: string): string {\n\tconst path = relative(fromDir, targetPath).replaceAll(\"\\\\\", \"/\");\n\treturn path.startsWith(\".\") ? path : `./${path}`;\n}\n\nfunction resolveProjectPath(projectRoot: string, path: string): string {\n\treturn path.startsWith(\"/\") ? path : resolve(projectRoot, path);\n}\n\nfunction isRouteGroup(segment: string): boolean {\n\treturn segment.startsWith(\"(\") && segment.endsWith(\")\");\n}\n\nif (process.argv[2] === BUILD_ARG) {\n\tconst payload = process.argv[3];\n\tif (!payload) {\n\t\tconsole.error(\"WaniWani widgets: missing build payload.\");\n\t\tprocess.exit(1);\n\t}\n\n\tconst options = JSON.parse(\n\t\tBuffer.from(payload, \"base64\").toString(\"utf8\"),\n\t) as WithWaniwaniWidgetsOptions;\n\n\tbuildWaniwaniWidgets(options).catch((error) => {\n\t\tconsole.error(error);\n\t\tprocess.exit(1);\n\t});\n}\n","/**\n * Initializes & patches Next.js functionality so an app can run as a\n * widget inside a cross-origin iframe. Used by every MCP widget host —\n * ChatGPT's sandbox, the embed's `/api/mcp/chat/resource` proxy, and any\n * future host that renders the widget on a domain other than its own\n * `baseUrl`.\n *\n * What it patches:\n * - `history.pushState` / `history.replaceState` — prevents full-origin\n * URLs from ending up in the iframe's history (browsers reject cross-\n * origin pushes in sandboxed iframes).\n * - `window.fetch` — rewrites same-origin requests to the widget's real\n * `baseUrl`. Without this, relative `/api/...` calls from the widget\n * hit the host's origin (ChatGPT sandbox, WaniWani embed proxy, etc.)\n * and 404. `passthroughOrigins` opts specific origins out of the\n * rewrite (see prop doc).\n * - `<html>` attribute observer — strips attributes the host injects\n * after hydration (ChatGPT mutates `<html>` for theming), while\n * preserving `class` / `style` / `lang`.\n *\n * More background on the ChatGPT case:\n * https://vercel.com/blog/running-next-js-inside-chatgpt-a-deep-dive-into-native-app-integration\n */\nexport function InitializeNextJsInIframe({\n\tbaseUrl,\n\tpassthroughOrigins,\n}: {\n\tbaseUrl: string;\n\t/**\n\t * Origins whose fetches should skip the same-origin → baseUrl rewrite.\n\t * Set this to the WaniWani API origin when the widget is loaded through\n\t * a proxy that shares origin with the API (e.g. the embed's\n\t * `/api/mcp/chat/resource` route on `app.waniwani.ai`). Without this,\n\t * widget tracking calls to the WaniWani API get rewritten to the\n\t * widget's own host and 404.\n\t */\n\tpassthroughOrigins?: string[];\n}) {\n\treturn (\n\t\t<>\n\t\t\t<base href={baseUrl}></base>\n\t\t\t<script>{`window.innerBaseUrl = ${JSON.stringify(baseUrl)}`}</script>\n\t\t\t<script>{`window.__wwPassthroughOrigins = ${JSON.stringify(passthroughOrigins ?? [])}`}</script>\n\t\t\t<script>{`window.__isChatGptApp = typeof window.openai !== \"undefined\";`}</script>\n\t\t\t<script>\n\t\t\t\t{\"(\" +\n\t\t\t\t\t(() => {\n\t\t\t\t\t\tconst baseUrl = window.innerBaseUrl;\n\t\t\t\t\t\tconst passthroughOrigins: string[] =\n\t\t\t\t\t\t\t(window as unknown as { __wwPassthroughOrigins: string[] })\n\t\t\t\t\t\t\t\t.__wwPassthroughOrigins ?? [];\n\t\t\t\t\t\tconst htmlElement = document.documentElement;\n\t\t\t\t\t\tconst observer = new MutationObserver((mutations) => {\n\t\t\t\t\t\t\tmutations.forEach((mutation) => {\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\tmutation.type === \"attributes\" &&\n\t\t\t\t\t\t\t\t\tmutation.target === htmlElement\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\tconst attrName = mutation.attributeName;\n\t\t\t\t\t\t\t\t\t// Preserve class/style for theming (html.dark) and lang for i18n\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tattrName &&\n\t\t\t\t\t\t\t\t\t\tattrName !== \"suppresshydrationwarning\" &&\n\t\t\t\t\t\t\t\t\t\tattrName !== \"lang\" &&\n\t\t\t\t\t\t\t\t\t\tattrName !== \"class\" &&\n\t\t\t\t\t\t\t\t\t\tattrName !== \"style\"\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\thtmlElement.removeAttribute(attrName);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t});\n\t\t\t\t\t\tobserver.observe(htmlElement, {\n\t\t\t\t\t\t\tattributes: true,\n\t\t\t\t\t\t\tattributeOldValue: true,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tconst originalReplaceState = history.replaceState.bind(history);\n\t\t\t\t\t\thistory.replaceState = (\n\t\t\t\t\t\t\t_s: unknown,\n\t\t\t\t\t\t\tunused: string,\n\t\t\t\t\t\t\turl?: string | URL | null,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst u = new URL(String(url ?? \"\"), window.location.href);\n\t\t\t\t\t\t\t\toriginalReplaceState(\n\t\t\t\t\t\t\t\t\tnull,\n\t\t\t\t\t\t\t\t\tunused,\n\t\t\t\t\t\t\t\t\tu.pathname + u.search + u.hash,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t/* SecurityError in sandboxed iframe */\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tconst originalPushState = history.pushState.bind(history);\n\t\t\t\t\t\thistory.pushState = (\n\t\t\t\t\t\t\t_s: unknown,\n\t\t\t\t\t\t\tunused: string,\n\t\t\t\t\t\t\turl?: string | URL | null,\n\t\t\t\t\t\t) => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst u = new URL(String(url ?? \"\"), window.location.href);\n\t\t\t\t\t\t\t\toriginalPushState(null, unused, u.pathname + u.search + u.hash);\n\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t/* SecurityError in sandboxed iframe */\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t};\n\n\t\t\t\t\t\tconst appOrigin = new URL(baseUrl).origin;\n\t\t\t\t\t\tconst isInIframe = window.self !== window.top;\n\n\t\t\t\t\t\twindow.addEventListener(\n\t\t\t\t\t\t\t\"click\",\n\t\t\t\t\t\t\t(e) => {\n\t\t\t\t\t\t\t\tconst a = (e?.target as HTMLElement)?.closest(\"a\");\n\t\t\t\t\t\t\t\tif (!a || !a.href) {\n\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tconst url = new URL(a.href, window.location.href);\n\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\turl.origin !== window.location.origin &&\n\t\t\t\t\t\t\t\t\turl.origin !== appOrigin\n\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tif (window.openai) {\n\t\t\t\t\t\t\t\t\t\t\twindow.openai?.openExternal({ href: a.href });\n\t\t\t\t\t\t\t\t\t\t\te.preventDefault();\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\tconsole.warn(\n\t\t\t\t\t\t\t\t\t\t\t\"openExternal failed, likely not in OpenAI client\",\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif (isInIframe && window.location.origin !== appOrigin) {\n\t\t\t\t\t\t\tconst originalFetch = window.fetch;\n\n\t\t\t\t\t\t\t(window as { fetch: typeof window.fetch }).fetch = ((\n\t\t\t\t\t\t\t\tinput: URL | RequestInfo,\n\t\t\t\t\t\t\t\tinit?: RequestInit,\n\t\t\t\t\t\t\t): Promise<Response> => {\n\t\t\t\t\t\t\t\tlet url: URL;\n\t\t\t\t\t\t\t\tif (typeof input === \"string\" || input instanceof URL) {\n\t\t\t\t\t\t\t\t\turl = new URL(input, window.location.href);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\turl = new URL(input.url, window.location.href);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (url.origin === appOrigin) {\n\t\t\t\t\t\t\t\t\tif (typeof input === \"string\" || input instanceof URL) {\n\t\t\t\t\t\t\t\t\t\tinput = url.toString();\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tinput = new Request(url.toString(), input);\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn originalFetch.call(window, input, {\n\t\t\t\t\t\t\t\t\t\t...init,\n\t\t\t\t\t\t\t\t\t\tmode: \"cors\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// Explicit passthrough list — never rewrite these.\n\t\t\t\t\t\t\t\t// Needed when the widget shares origin with a\n\t\t\t\t\t\t\t\t// non-Next-app host (e.g. the WaniWani app serving the\n\t\t\t\t\t\t\t\t// embed iframe + the tracking API from the same host).\n\t\t\t\t\t\t\t\tif (passthroughOrigins.indexOf(url.origin) !== -1) {\n\t\t\t\t\t\t\t\t\treturn originalFetch.call(window, input, init);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (url.origin === window.location.origin) {\n\t\t\t\t\t\t\t\t\tconst newUrl = new URL(baseUrl);\n\t\t\t\t\t\t\t\t\tnewUrl.pathname = url.pathname;\n\t\t\t\t\t\t\t\t\tnewUrl.search = url.search;\n\t\t\t\t\t\t\t\t\tnewUrl.hash = url.hash;\n\t\t\t\t\t\t\t\t\turl = newUrl;\n\n\t\t\t\t\t\t\t\t\tif (typeof input === \"string\" || input instanceof URL) {\n\t\t\t\t\t\t\t\t\t\tinput = url.toString();\n\t\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t\tinput = new Request(url.toString(), input);\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\treturn originalFetch.call(window, input, {\n\t\t\t\t\t\t\t\t\t\t...init,\n\t\t\t\t\t\t\t\t\t\tmode: \"cors\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\treturn originalFetch.call(window, input, init);\n\t\t\t\t\t\t\t}) as typeof window.fetch;\n\t\t\t\t\t\t}\n\t\t\t\t\t}).toString() +\n\t\t\t\t\t\")()\"}\n\t\t\t</script>\n\t\t</>\n\t);\n}\n","import { readFileSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\n\nexport const WANIWANI_WIDGET_BASE_URL_PLACEHOLDER =\n\t\"__WANIWANI_WIDGET_BASE_URL__\";\n\n/**\n * Directory inside the consuming project where `withWaniwaniWidgets()`\n * stores generated build artifacts (currently the widget manifest).\n * Anchoring on the project root rather than `node_modules/@waniwani/sdk`\n * avoids polluting pnpm's content-addressed store across consumers.\n */\nexport const WANIWANI_BUILD_DIR = \".waniwani\";\nexport const WANIWANI_WIDGETS_MANIFEST_FILENAME = \"widgets-manifest.json\";\n/** Path relative to the project root, e.g. for `outputFileTracingIncludes`. */\nexport const WANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH = `${WANIWANI_BUILD_DIR}/${WANIWANI_WIDGETS_MANIFEST_FILENAME}`;\n\nexport type WaniwaniWidgetsManifest = {\n\tversion: 1;\n\tbyId: Record<string, string>;\n\tbyHtmlPath: Record<string, string>;\n};\n\n/**\n * Absolute path to the manifest JSON for a given project root. Defaults to\n * `process.cwd()`, which is correct for both `next start` and Vercel\n * serverless functions (where the deployed function root preserves files\n * pulled in via `outputFileTracingIncludes`).\n */\nexport function getManifestFilePath(projectRoot?: string): string {\n\treturn resolve(\n\t\tprojectRoot ?? process.cwd(),\n\t\tWANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH,\n\t);\n}\n\nlet cachedManifestPath: string | undefined;\nlet cachedManifest: WaniwaniWidgetsManifest | null | undefined;\nlet testOverrideManifest: WaniwaniWidgetsManifest | null | undefined;\n\nfunction getManifest(): WaniwaniWidgetsManifest | null {\n\tif (testOverrideManifest !== undefined) {\n\t\treturn testOverrideManifest;\n\t}\n\n\tconst manifestPath = getManifestFilePath();\n\tif (cachedManifestPath === manifestPath && cachedManifest !== undefined) {\n\t\treturn cachedManifest;\n\t}\n\n\tcachedManifestPath = manifestPath;\n\ttry {\n\t\tconst raw = readFileSync(manifestPath, \"utf8\");\n\t\tcachedManifest = JSON.parse(raw) as WaniwaniWidgetsManifest;\n\t} catch {\n\t\tcachedManifest = null;\n\t}\n\treturn cachedManifest;\n}\n\n/** Test-only: override the manifest used by `resolveResourceHtmlPath`. */\nexport function __setManifestForTesting(\n\tmanifest: WaniwaniWidgetsManifest | null | undefined,\n): void {\n\ttestOverrideManifest = manifest;\n\tcachedManifest = undefined;\n\tcachedManifestPath = undefined;\n}\n\nexport function getDefaultResourceHtmlPath(id: string): string {\n\treturn `/${id}`;\n}\n\nexport function resolveResourceHtmlPath(id: string, htmlPath?: string): string {\n\tconst configuredHtmlPath = htmlPath ?? getDefaultResourceHtmlPath(id);\n\tconst manifest = getManifest();\n\n\treturn (\n\t\tmanifest?.byHtmlPath[configuredHtmlPath] ??\n\t\tmanifest?.byId[id] ??\n\t\tconfiguredHtmlPath\n\t);\n}\n\nexport function replaceWidgetTemplatePlaceholders(\n\thtml: string,\n\tbaseUrl: string,\n): string {\n\tconst normalizedBaseUrl = baseUrl.endsWith(\"/\")\n\t\t? baseUrl.slice(0, -1)\n\t\t: baseUrl;\n\treturn html.replaceAll(\n\t\tWANIWANI_WIDGET_BASE_URL_PLACEHOLDER,\n\t\tnormalizedBaseUrl,\n\t);\n}\n"],"mappings":"AAAA,OAAS,aAAAA,MAAiB,gBAC1B,OACC,cAAAC,EACA,aAAAC,EACA,eAAAC,EACA,gBAAAC,EACA,UAAAC,EACA,YAAAC,EACA,iBAAAC,MACM,KACP,OAAS,WAAAC,EAAS,QAAAC,EAAM,YAAAC,EAAU,WAAAC,MAAe,OACjD,OAAS,iBAAAC,MAAqB,MAC9B,OAAS,iBAAAC,MAAqB,QAC9B,OAAS,wBAAAC,MAA4B,mBC0BnC,mBAAAC,EACC,OAAAC,EADD,QAAAC,MAAA,oBAhBK,SAASC,EAAyB,CACxC,QAAAC,EACA,mBAAAC,CACD,EAWG,CACF,OACCH,EAAAF,EAAA,CACC,UAAAC,EAAC,QAAK,KAAMG,EAAS,EACrBH,EAAC,UAAQ,kCAAyB,KAAK,UAAUG,CAAO,CAAC,GAAG,EAC5DH,EAAC,UAAQ,4CAAmC,KAAK,UAAUI,GAAsB,CAAC,CAAC,CAAC,GAAG,EACvFJ,EAAC,UAAQ,yEAAgE,EACzEA,EAAC,UACC,cACC,IAAM,CACN,IAAMG,EAAU,OAAO,aACjBC,EACJ,OACC,wBAA0B,CAAC,EACxBC,EAAc,SAAS,gBACZ,IAAI,iBAAkBC,GAAc,CACpDA,EAAU,QAASC,GAAa,CAC/B,GACCA,EAAS,OAAS,cAClBA,EAAS,SAAWF,EACnB,CACD,IAAMG,EAAWD,E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M,EAAE,CAAC,GAAK,IAC5CwE,EACLD,EAAa,OAAS,EAAIA,EAAa,QAAQ,OAAQ,EAAE,EAAIA,EAC9D,OAAOC,EAAqB,WAAW,GAAG,EACvCA,EACA,IAAIA,CAAoB,EAC5B,CAEA,SAASnF,EAAmBJ,EAA2B,CACtD,OAAOA,EAAU,QAAQ,eAAgB,EAAE,CAC5C,CAEA,SAASmE,GAAaqB,EAAuB,CAC5C,OAAOA,EAAM,QAAQ,kBAAmB,GAAG,CAC5C,CAEA,SAASf,EAAWgB,EAAiBC,EAA4B,CAChE,IAAMC,EAAOjD,EAAS+C,EAASC,CAAU,EAAE,WAAW,KAAM,GAAG,EAC/D,OAAOC,EAAK,WAAW,GAAG,EAAIA,EAAO,KAAKA,CAAI,EAC/C,CAEA,SAASnF,EAAmB3C,EAAqB8H,EAAsB,CACtE,OAAOA,EAAK,WAAW,GAAG,EAAIA,EAAO7H,EAAQD,EAAa8H,CAAI,CAC/D,CAEA,SAASnC,GAAaD,EAA0B,CAC/C,OAAOA,EAAQ,WAAW,GAAG,GAAKA,EAAQ,SAAS,GAAG,CACvD,CAEA,GAAI,QAAQ,KAAK,CAAC,IAAMnG,EAAW,CAClC,IAAM6B,EAAU,QAAQ,KAAK,CAAC,EACzBA,IACJ,QAAQ,MAAM,0CAA0C,EACxD,QAAQ,KAAK,CAAC,GAGf,IAAMzB,EAAU,KAAK,MACpB,OAAO,KAAKyB,EAAS,QAAQ,EAAE,SAAS,MAAM,CAC/C,EAEAG,GAAqB5B,CAAO,EAAE,MAAOoI,GAAU,CAC9C,QAAQ,MAAMA,CAAK,EACnB,QAAQ,KAAK,CAAC,CACf,CAAC,CACF","names":["spawnSync","existsSync","mkdirSync","readdirSync","readFileSync","rmSync","statSync","writeFileSync","dirname","join","relative","resolve","fileURLToPath","createElement","renderToStaticMarkup","Fragment","jsx","jsxs","InitializeNextJsInIframe","baseUrl","passthroughOrigins","htmlElement","mutations","mutation","attrName","originalReplaceState","_s","unused","url","originalPushState","appOrigin","isInIframe","e","a","originalFetch","input","init","newUrl","readFileSync","resolve","WANIWANI_WIDGET_BASE_URL_PLACEHOLDER","WANIWANI_BUILD_DIR","WANIWANI_WIDGETS_MANIFEST_FILENAME","WANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH","getManifestFilePath","projectRoot","BUILD_ARG","builtKeys","withWaniwaniWidgets","nextConfig","options","args","result","config","enhanceNextConfig","projectRoot","resolve","resources","discoverResources","manifest","createManifest","writeManifestFile","originalHeaders","originalWebpack","manifestTraceTarget","WANIWANI_WIDGETS_MANIFEST_RELATIVE_PATH","existingTracingIncludes","buildWidgetsSync","context","manifestPath","getManifestFilePath","mkdirSync","dirname","writeFileSync","key","payload","spawnSync","fileURLToPath","buildWaniwaniWidgets","targets","resource","resolveBuildTarget","cacheDir","publicWidgetsDir","build","react","tailwindcss","target","entryPath","writeGeneratedEntry","assetBase","rmSync","assetInfo","name","stripWidgetsPrefix","writeWidgetHtml","resourcesPath","absolutePath","resolveProjectPath","source","readFileSync","objectSource","findCreateResourceObjects","id","readStringProperty","htmlPath","stableHtmlPath","toStableHtmlPath","isStableWidgetHtmlPath","objects","index","callIndex","openParen","openBrace","closeBrace","findMatchingBrace","depth","quote","escaped","lineComment","blockComment","char","next","propertyName","pattern","byId","byHtmlPath","appDir","routePath","normalizeRoutePath","page","findPageForRoute","relative","pages","collectPages","matches","match","pagePath","collectLayouts","currentDir","entry","readdirSync","join","statSync","routePathForPage","segment","isRouteGroup","pageDir","segments","layouts","layout","findRouteFile","dir","basename","extension","candidate","existsSync","safeFileName","entryDir","globalCssPath","resolveGlobalCss","layoutImports","layoutPath","importPath","layoutWraps","_","fallbackProvider","line","cssPath","initMarkup","renderToStaticMarkup","createElement","InitializeNextJsInIframe","WANIWANI_WIDGET_BASE_URL_PLACEHOLDER","cssTag","globalCss","withoutQuery","withoutTrailingSlash","value","fromDir","targetPath","path","error"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waniwani/sdk",
3
- "version": "0.10.11-beta.2",
3
+ "version": "0.10.11-beta.4",
4
4
  "description": "WaniWani SDK - MCP event tracking, widget framework, and tools",
5
5
  "type": "module",
6
6
  "exports": {