(()=>{var a={};a.id=334,a.ids=[334],a.modules={261:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/app-paths")},1745:(a,b,c)=>{"use strict";c.r(b),c.d(b,{handler:()=>I,patchFetch:()=>H,routeModule:()=>D,serverHooks:()=>G,workAsyncStorage:()=>E,workUnitAsyncStorage:()=>F});var d={};c.r(d),c.d(d,{POST:()=>C});var e=c(41721),f=c(88262),g=c(58397),h=c(34701),i=c(47415),j=c(261),k=c(861),l=c(37747),m=c(8245),n=c(97526),o=c(84312),p=c(31522),q=c(47616),r=c(38873),s=c(86439),t=c(76983),u=c(46008),v=c(31421),w=c(76760),x=c(73024);let y=require("node:os");var z=c(33809);let A=["/usr/local/bin/claude","/opt/homebrew/bin/claude",`${process.env.HOME}/.local/bin/claude`,`${process.env.HOME}/.claude/bin/claude`];async function B(a,b){let c=(0,w.join)((0,y.tmpdir)(),`seo-suggest-${Date.now()}.txt`);return(0,x.writeFileSync)(c,b,"utf-8"),new Promise((b,d)=>{let e=(0,v.spawn)("sh",["-c",`"${a}" --print < "${c}"`],{stdio:["ignore","pipe","pipe"]}),f="",g="";e.stdout.on("data",a=>{f+=a.toString()}),e.stderr.on("data",a=>{g+=a.toString()}),e.on("close",a=>{try{(0,x.rmSync)(c)}catch{}if(0!==a){let b=g.trim()||`claude exited ${a}`;d(Error(b.includes("unknown option")||b.includes("unrecognized")?`claude CLI flag error: ${b}. Try updating Claude Code to the latest version.`:b));return}let e=f.replace(/^```(?:json)?\s*/m,"").replace(/\s*```\s*$/m,"").trim();try{let a=JSON.parse(e);if(!Array.isArray(a))throw Error("Expected JSON array");b(a)}catch{d(Error(`Failed to parse claude output as JSON. Output:
${f.slice(0,500)}`))}}),e.on("error",a=>{try{(0,x.rmSync)(c)}catch{}d(a)})})}async function C(){let a,b=process.env.SEO_TOOLKIT_CWD??process.cwd();if(process.env.ANTHROPIC_API_KEY){let a=(0,z.M)();try{let c="";return await new Promise((d,e)=>{let f=(0,v.spawn)("node",[a,"suggest"],{cwd:b,stdio:"pipe",env:{...process.env,FORCE_COLOR:"0"}});f.stderr.on("data",a=>{c+=a.toString()}),f.stdout.on("data",a=>{c+=a.toString()}),f.on("close",a=>0===a?d():e(Error(c.trim()||`Suggest exited ${a}`))),f.on("error",e)}),u.NextResponse.json({ok:!0})}catch(c){let a=c instanceof Error?c.message:"Suggest failed",b=a.includes("SEO_PLAYBOOK")||a.includes("ENOENT")?"SEO_PLAYBOOK.md not found. Run seo-toolkit init in your project first.":a.includes("401")||a.includes("authentication")||a.includes("api_key")?"ANTHROPIC_API_KEY is invalid or expired.":a.slice(0,300);return u.NextResponse.json({error:b},{status:500})}}let c=function(){try{return(0,v.execSync)("which claude",{encoding:"utf-8",stdio:["pipe","pipe","pipe"]}).trim()}catch{for(let a of A)if((0,x.existsSync)(a))return a;return null}}();if(!c)return u.NextResponse.json({error:"No ANTHROPIC_API_KEY and no `claude` CLI found. Either set ANTHROPIC_API_KEY in your .env, or install Claude Code (claude.ai/code) and make sure `claude` is in your PATH."},{status:500});let d=(0,w.join)(b,".seo-toolkit","audit-report.json"),e=(0,w.join)(b,"SEO_PLAYBOOK.md");if(!(0,x.existsSync)(d))return u.NextResponse.json({error:"audit-report.json not found — run Re-audit first."},{status:500});let f="";try{a=JSON.parse((0,x.readFileSync)(d,"utf-8")),(0,x.existsSync)(e)&&(f=(0,x.readFileSync)(e,"utf-8"))}catch(a){return u.NextResponse.json({error:`Failed to read project files: ${a instanceof Error?a.message:a}`},{status:500})}try{let d=function(a,b){let c=a.pages.filter(a=>a.issues.length>0).slice(0,40).map(a=>({url:a.url,pageType:a.pageType,title:a.title??"",metaDescription:a.metaDescription??"",h1Count:a.h1Count,wordCount:a.wordCount,issues:a.issues.map(a=>({id:a.id,category:a.category,severity:a.severity,title:a.title,description:a.description}))}));return`You are an expert SEO copywriter. Generate concrete SEO fix suggestions for the pages below.

SEO PLAYBOOK
---
${b}
---

SITE: ${a.siteUrl}
ADAPTER: ${a.adapter}

PAGES WITH ISSUES (${c.length} of ${a.pages.length} total):
${JSON.stringify(c,null,2)}

TASK
For each fixable issue produce one suggestion. Only suggest changes for these fields:
- title (must be 50-70 chars, lead with keyword, match brand voice)
- metaDescription (must be 140-160 chars, active voice, include value prop)
- schema (JSON-LD object — only for missing schema issues)

Skip altText and structural issues for now.

OUTPUT FORMAT — respond with a JSON array ONLY, no markdown fences, no commentary:
[
  {
    "pageUrl": "https://...",
    "issueId": "the issue id from above",
    "field": "title|metaDescription|schema",
    "before": "current value or empty string",
    "after": "your improved version",
    "reasoning": "one sentence explaining the improvement",
    "status": "pending"
  }
]

If there are no fixable issues, output an empty array: []`}(a,f),e=await B(c,d),g={siteUrl:a.siteUrl,generatedAt:new Date().toISOString(),modelUsage:{sonnet:e.length},changes:e},h=(0,w.join)(b,".seo-toolkit");return(0,x.mkdirSync)(h,{recursive:!0}),(0,x.writeFileSync)((0,w.join)(h,"suggested-changes.json"),JSON.stringify(g,null,2)),u.NextResponse.json({ok:!0,count:e.length})}catch(b){let a=b instanceof Error?b.message:"Claude CLI suggest failed";return u.NextResponse.json({error:a.slice(0,400)},{status:500})}}let D=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/suggest/run/route",pathname:"/api/suggest/run",filename:"route",bundlePath:"app/api/suggest/run/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/Users/aaricericc/Downloads/seo-toolkit/packages/dashboard/app/api/suggest/run/route.ts",nextConfigOutput:"standalone",userland:d}),{workAsyncStorage:E,workUnitAsyncStorage:F,serverHooks:G}=D;function H(){return(0,g.patchFetch)({workAsyncStorage:E,workUnitAsyncStorage:F})}async function I(a,b,c){var d;let e="/api/suggest/run/route";"/index"===e&&(e="/");let g=await D.prepare(a,b,{srcPage:e,multiZoneDraftMode:!1});if(!g)return b.statusCode=400,b.end("Bad Request"),null==c.waitUntil||c.waitUntil.call(c,Promise.resolve()),null;let{buildId:u,params:v,nextConfig:w,isDraftMode:x,prerenderManifest:y,routerServerContext:z,isOnDemandRevalidate:A,revalidateOnlyGenerated:B,resolvedPathname:C}=g,E=(0,j.normalizeAppPath)(e),F=!!(y.dynamicRoutes[E]||y.routes[C]);if(F&&!x){let a=!!y.routes[C],b=y.dynamicRoutes[E];if(b&&!1===b.fallback&&!a)throw new s.NoFallbackError}let G=null;!F||D.isDev||x||(G="/index"===(G=C)?"/":G);let H=!0===D.isDev||!F,I=F&&!H,J=a.method||"GET",K=(0,i.getTracer)(),L=K.getActiveScopeSpan(),M={params:v,prerenderManifest:y,renderOpts:{experimental:{cacheComponents:!!w.experimental.cacheComponents,authInterrupts:!!w.experimental.authInterrupts},supportsDynamicResponse:H,incrementalCache:(0,h.getRequestMeta)(a,"incrementalCache"),cacheLifeProfiles:null==(d=w.experimental)?void 0:d.cacheLife,isRevalidate:I,waitUntil:c.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:void 0,onInstrumentationRequestError:(b,c,d)=>D.onRequestError(a,b,d,z)},sharedContext:{buildId:u}},N=new k.NodeNextRequest(a),O=new k.NodeNextResponse(b),P=l.NextRequestAdapter.fromNodeNextRequest(N,(0,l.signalFromNodeResponse)(b));try{let d=async c=>D.handle(P,M).finally(()=>{if(!c)return;c.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let d=K.getRootSpanAttributes();if(!d)return;if(d.get("next.span_type")!==m.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${d.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let e=d.get("next.route");if(e){let a=`${J} ${e}`;c.setAttributes({"next.route":e,"http.route":e,"next.span_name":a}),c.updateName(a)}else c.updateName(`${J} ${a.url}`)}),g=async g=>{var i,j;let k=async({previousCacheEntry:f})=>{try{if(!(0,h.getRequestMeta)(a,"minimalMode")&&A&&B&&!f)return b.statusCode=404,b.setHeader("x-nextjs-cache","REVALIDATED"),b.end("This page could not be found"),null;let e=await d(g);a.fetchMetrics=M.renderOpts.fetchMetrics;let i=M.renderOpts.pendingWaitUntil;i&&c.waitUntil&&(c.waitUntil(i),i=void 0);let j=M.renderOpts.collectedTags;if(!F)return await (0,o.I)(N,O,e,M.renderOpts.pendingWaitUntil),null;{let a=await e.blob(),b=(0,p.toNodeOutgoingHttpHeaders)(e.headers);j&&(b[r.NEXT_CACHE_TAGS_HEADER]=j),!b["content-type"]&&a.type&&(b["content-type"]=a.type);let c=void 0!==M.renderOpts.collectedRevalidate&&!(M.renderOpts.collectedRevalidate>=r.INFINITE_CACHE)&&M.renderOpts.collectedRevalidate,d=void 0===M.renderOpts.collectedExpire||M.renderOpts.collectedExpire>=r.INFINITE_CACHE?void 0:M.renderOpts.collectedExpire;return{value:{kind:t.CachedRouteKind.APP_ROUTE,status:e.status,body:Buffer.from(await a.arrayBuffer()),headers:b},cacheControl:{revalidate:c,expire:d}}}}catch(b){throw(null==f?void 0:f.isStale)&&await D.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:A})},z),b}},l=await D.handleResponse({req:a,nextConfig:w,cacheKey:G,routeKind:f.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:y,isRoutePPREnabled:!1,isOnDemandRevalidate:A,revalidateOnlyGenerated:B,responseGenerator:k,waitUntil:c.waitUntil});if(!F)return null;if((null==l||null==(i=l.value)?void 0:i.kind)!==t.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==l||null==(j=l.value)?void 0:j.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});(0,h.getRequestMeta)(a,"minimalMode")||b.setHeader("x-nextjs-cache",A?"REVALIDATED":l.isMiss?"MISS":l.isStale?"STALE":"HIT"),x&&b.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let m=(0,p.fromNodeOutgoingHttpHeaders)(l.value.headers);return(0,h.getRequestMeta)(a,"minimalMode")&&F||m.delete(r.NEXT_CACHE_TAGS_HEADER),!l.cacheControl||b.getHeader("Cache-Control")||m.get("Cache-Control")||m.set("Cache-Control",(0,q.getCacheControlHeader)(l.cacheControl)),await (0,o.I)(N,O,new Response(l.value.body,{headers:m,status:l.value.status||200})),null};L?await g(L):await K.withPropagatedContext(a.headers,()=>K.trace(m.BaseServerSpan.handleRequest,{spanName:`${J} ${a.url}`,kind:i.SpanKind.SERVER,attributes:{"http.method":J,"http.target":a.url}},g))}catch(b){if(b instanceof s.NoFallbackError||await D.onRequestError(a,b,{routerKind:"App Router",routePath:E,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:A})}),F)throw b;return await (0,o.I)(N,O,new Response(null,{status:500})),null}}},3295:a=>{"use strict";a.exports=require("next/dist/server/app-render/after-task-async-storage.external.js")},8e3:()=>{},10846:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},19121:a=>{"use strict";a.exports=require("next/dist/server/app-render/action-async-storage.external.js")},29294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},31421:a=>{"use strict";a.exports=require("node:child_process")},33809:(a,b,c)=>{"use strict";c.d(b,{M:()=>e});var d=c(76760);function e(){return process.env.SEO_TOOLKIT_CLI_PATH??(0,d.resolve)(process.cwd(),"../cli/dist/index.js")}},44448:()=>{},44870:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},63033:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},73024:a=>{"use strict";a.exports=require("node:fs")},76760:a=>{"use strict";a.exports=require("node:path")},86439:a=>{"use strict";a.exports=require("next/dist/shared/lib/no-fallback-error.external")}};var b=require("../../../../webpack-runtime.js");b.C(a);var c=b.X(0,[112,677],()=>b(b.s=1745));module.exports=c})();