(()=>{var a={};a.id=81583,a.ids=[81583],a.modules={50647:(a,b,c)=>{"use strict";c.r(b),c.d(b,{handler:()=>P,patchFetch:()=>O,routeModule:()=>K,serverHooks:()=>N,workAsyncStorage:()=>L,workUnitAsyncStorage:()=>M});var d={};c.r(d),c.d(d,{GET:()=>I,PUT:()=>J,dynamic:()=>x,runtime:()=>y});var e=c(940527),f=c(41752),g=c(633335),h=c(573615),i=c(301769),j=c(200261),k=c(405563),l=c(439285),m=c(443399),n=c(295860),o=c(161730),p=c(728392),q=c(976618),r=c(406527),s=c(986439),t=c(975973),u=c(629021),v=c(333873),w=c(693349);let x="force-dynamic",y="nodejs";function z(a){return a.replace(/'/g,"''")}function A(a){let b=(0,w.fO)(a);if(!b)return null;let c=(0,w.hM)(b,`SELECT id FROM objects WHERE name = '${z(a)}' LIMIT 1`);if(0===c.length)return null;let d=(0,w.gp)(a);return d?{objectName:a,objectId:c[0].id,dbFile:b,objectDir:d,workspaceRoot:(0,w.Yn)()}:null}function B(a,b,c,d){return{absolute:b,workspaceRelative:a.workspaceRoot?(0,v.relative)(a.workspaceRoot,b):`${a.objectName}/${b.split("/").pop()??""}`,title:c,source:d}}function C(a){let b=(0,w.hM)(a,`SELECT COUNT(*) as cnt
		 FROM information_schema.columns
		 WHERE table_name = 'documents' AND column_name = 'entry_id'`);return(b[0]?.cnt??0)>0}function D(a,b){let c=(0,w.hM)(a.dbFile,`SELECT f.name as field_name, ef.value
		 FROM entry_fields ef
		 JOIN fields f ON f.id = ef.field_id
		 WHERE ef.entry_id = '${z(b)}'`),d={};for(let a of c)a.field_name&&a.value&&(d[a.field_name]=a.value);return d}function E(...a){for(let b of a){let a=b?.trim();if(a)return a}return null}function F(a){return a.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").toLowerCase().replace(/&/g," and ").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"").replace(/-+/g,"-")}function G(a,b,c){return E(c["Document Title"],c.Title,c["Channel Name"],c["Creator Name"],c["Full Name"],c.Name,c["Company Name"],c["Deal Name"],c["Case Number"],c["Invoice Number"],c.Address,c.Email)??`${a.objectName} ${b}`}function H(a,b){let c=A(a);if(!c)return null;let d=C(c.dbFile)?(0,w.hM)(c.dbFile,`SELECT file_path, title
		 FROM documents
		 WHERE entry_id = '${z(b)}'
		   AND parent_object_id = '${z(c.objectId)}'
		 ORDER BY updated_at DESC
		 LIMIT 1`)[0]??null:null;if(d){let a=c.workspaceRoot&&!d.file_path.startsWith("/")?(0,v.join)(c.workspaceRoot,d.file_path):d.file_path.startsWith("/")?d.file_path:(0,v.join)(c.objectDir,d.file_path.split("/").pop()??d.file_path);return B(c,a,d.title?.trim()||d.file_path.split("/").pop()?.replace(/\.mdx?$/,"")||b,"documents")}let e=(0,v.join)(c.objectDir,`${b}.md`);if((0,u.existsSync)(e)){let a=D(c,b);return B(c,e,G(c,b,a),"legacy")}return function(a,b){let c=D(a,b),d=G(a,b,c),e=function(a,b,c){let d=E(b["Document Slug"],b.Slug,b["File Slug"]);if(d)return F(d)||"entry";let e=function(a){let b=a?.trim();if(!b)return null;try{let a=new URL(b.startsWith("http://")||b.startsWith("https://")?b:`https://${b}`),c=a.hostname.toLowerCase();if(!c.includes("youtube.com")&&!c.includes("youtu.be"))return null;let d=a.pathname.split("/").filter(Boolean);if(d[0]?.startsWith("@"))return d[0].slice(1);if(("channel"===d[0]||"c"===d[0]||"user"===d[0])&&d[1])return d[1]}catch{}let c=b.match(/@([A-Za-z0-9._-]+)/);return c?.[1]??null}(b["YouTube URL"]);return e?`yt-${F(e)}`:F(c)||F(a.objectName)||"entry"}(a,c,d);for(let c=1;c<=999;c++){let f=`${e}-${String(c).padStart(3,"0")}.md`,g=(0,v.join)(a.objectDir,f),h=B(a,g,d,"generated"),i=function(a,b){if(!C(a.dbFile))return null;let c=(0,w.hM)(a.dbFile,`SELECT entry_id
		 FROM documents
		 WHERE file_path = '${z(b)}'
		 LIMIT 1`);return c[0]?.entry_id??null}(a,h.workspaceRelative);if(i===b||!i&&!(0,u.existsSync)(g))return h}return B(a,(0,v.join)(a.objectDir,`${e}-999.md`),d,"generated")}(c,b)}async function I(a,{params:b}){let{name:c,id:d}=await b;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c))return Response.json({error:"Invalid object name"},{status:400});if(!d||d.length>64)return Response.json({error:"Invalid entry ID"},{status:400});if(!A(c))return Response.json({content:"",exists:!1,path:`${c}/${d}.md`});let e=H(c,d);if(!e)return Response.json({content:"",exists:!1,path:`${c}/${d}.md`});if((0,u.existsSync)(e.absolute)){let a=(0,u.readFileSync)(e.absolute,"utf-8");return Response.json({content:a,exists:!0,path:e.workspaceRelative})}return Response.json({content:"",exists:!1,path:e.workspaceRelative})}async function J(a,{params:b}){let{name:c,id:d}=await b;if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(c))return Response.json({error:"Invalid object name"},{status:400});if(!d||d.length>64)return Response.json({error:"Invalid entry ID"},{status:400});let e=A(c);if(!e)return Response.json({error:"Object directory not found"},{status:404});if(!function(a,b){let c=(0,w.hM)(a.dbFile,`SELECT COUNT(*) as cnt
		 FROM entries
		 WHERE id = '${z(b)}' AND object_id = '${z(a.objectId)}'`);return(c[0]?.cnt??0)>0}(e,d))return Response.json({error:"Entry not found"},{status:404});let f=H(c,d);if(!f)return Response.json({error:"Object directory not found"},{status:404});let g=await a.json(),h="string"==typeof g.content?g.content:"";if(!h.trim()&&!(0,u.existsSync)(f.absolute))return Response.json({ok:!0,created:!1,path:f.workspaceRelative});let i=(0,u.existsSync)(f.absolute);return(0,u.mkdirSync)((0,v.dirname)(f.absolute),{recursive:!0}),(0,u.writeFileSync)(f.absolute,h,"utf-8"),!function(a,b,c){var d;if(d=a.dbFile,(0,w.u4)(d,`CREATE TABLE IF NOT EXISTS documents (
			id VARCHAR PRIMARY KEY DEFAULT (gen_random_uuid()::VARCHAR),
			title VARCHAR DEFAULT 'Untitled',
			icon VARCHAR,
			cover_image VARCHAR,
			file_path VARCHAR NOT NULL UNIQUE,
			parent_id VARCHAR REFERENCES documents(id),
			parent_object_id VARCHAR REFERENCES objects(id),
			entry_id VARCHAR REFERENCES entries(id),
			sort_order INTEGER DEFAULT 0,
			is_published BOOLEAN DEFAULT false,
			created_at TIMESTAMPTZ DEFAULT now(),
			updated_at TIMESTAMPTZ DEFAULT now()
		)`),(0,w.u4)(d,"ALTER TABLE documents ADD COLUMN IF NOT EXISTS entry_id VARCHAR"),!C(a.dbFile))return;let e=z(c.title),f=z(c.workspaceRelative),g=z(a.objectId),h=z(b);(0,w.u4)(a.dbFile,`UPDATE documents
		 SET title = '${e}',
		     file_path = '${f}',
		     parent_object_id = '${g}',
		     entry_id = '${h}',
		     updated_at = now()
		 WHERE entry_id = '${h}' AND parent_object_id = '${g}'`),(0,w.u4)(a.dbFile,`UPDATE documents
		 SET title = '${e}',
		     parent_object_id = '${g}',
		     entry_id = '${h}',
		     updated_at = now()
		 WHERE file_path = '${f}' AND (entry_id IS NULL OR entry_id = '${h}')`),(0,w.u4)(a.dbFile,`INSERT INTO documents (title, file_path, parent_object_id, entry_id)
		 SELECT '${e}', '${f}', '${g}', '${h}'
		 WHERE NOT EXISTS (
		   SELECT 1 FROM documents
		   WHERE (entry_id = '${h}' AND parent_object_id = '${g}')
		      OR file_path = '${f}'
		 )`)}(e,d,f),Response.json({ok:!0,created:!i,path:f.workspaceRelative})}let K=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/workspace/objects/[name]/entries/[id]/content/route",pathname:"/api/workspace/objects/[name]/entries/[id]/content",filename:"route",bundlePath:"app/api/workspace/objects/[name]/entries/[id]/content/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/home/runner/work/DenchClaw/DenchClaw/apps/web/app/api/workspace/objects/[name]/entries/[id]/content/route.ts",nextConfigOutput:"standalone",userland:d}),{workAsyncStorage:L,workUnitAsyncStorage:M,serverHooks:N}=K;function O(){return(0,g.patchFetch)({workAsyncStorage:L,workUnitAsyncStorage:M})}async function P(a,b,c){var d;let e="/api/workspace/objects/[name]/entries/[id]/content/route";"/index"===e&&(e="/");let g=await K.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,D=(0,j.normalizeAppPath)(e),E=!!(y.dynamicRoutes[D]||y.routes[C]);if(E&&!x){let a=!!y.routes[C],b=y.dynamicRoutes[D];if(b&&!1===b.fallback&&!a)throw new s.NoFallbackError}let F=null;!E||K.isDev||x||(F="/index"===(F=C)?"/":F);let G=!0===K.isDev||!E,H=E&&!G,I=a.method||"GET",J=(0,i.getTracer)(),L=J.getActiveScopeSpan(),M={params:v,prerenderManifest:y,renderOpts:{experimental:{cacheComponents:!!w.experimental.cacheComponents,authInterrupts:!!w.experimental.authInterrupts},supportsDynamicResponse:G,incrementalCache:(0,h.getRequestMeta)(a,"incrementalCache"),cacheLifeProfiles:null==(d=w.experimental)?void 0:d.cacheLife,isRevalidate:H,waitUntil:c.waitUntil,onClose:a=>{b.on("close",a)},onAfterTaskError:void 0,onInstrumentationRequestError:(b,c,d)=>K.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=>K.handle(P,M).finally(()=>{if(!c)return;c.setAttributes({"http.status_code":b.statusCode,"next.rsc":!1});let d=J.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=`${I} ${e}`;c.setAttributes({"next.route":e,"http.route":e,"next.span_name":a}),c.updateName(a)}else c.updateName(`${I} ${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(!E)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 K.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:H,isOnDemandRevalidate:A})},z),b}},l=await K.handleResponse({req:a,nextConfig:w,cacheKey:F,routeKind:f.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:y,isRoutePPREnabled:!1,isOnDemandRevalidate:A,revalidateOnlyGenerated:B,responseGenerator:k,waitUntil:c.waitUntil});if(!E)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")&&E||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 J.withPropagatedContext(a.headers,()=>J.trace(m.BaseServerSpan.handleRequest,{spanName:`${I} ${a.url}`,kind:i.SpanKind.SERVER,attributes:{"http.method":I,"http.target":a.url}},g))}catch(b){if(b instanceof s.NoFallbackError||await K.onRequestError(a,b,{routerKind:"App Router",routePath:D,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:H,isOnDemandRevalidate:A})}),E)throw b;return await (0,o.I)(N,O,new Response(null,{status:500})),null}}},51455:a=>{"use strict";a.exports=require("node:fs/promises")},161730:(a,b,c)=>{"use strict";Object.defineProperty(b,"I",{enumerable:!0,get:function(){return g}});let d=c(554226),e=c(884327),f=c(728392);async function g(a,b,c,g){if((0,d.isNodeNextResponse)(b)){var h;b.statusCode=c.status,b.statusMessage=c.statusText;let d=["set-cookie","www-authenticate","proxy-authenticate","vary"];null==(h=c.headers)||h.forEach((a,c)=>{if("x-middleware-set-cookie"!==c.toLowerCase())if("set-cookie"===c.toLowerCase())for(let d of(0,f.splitCookiesString)(a))b.appendHeader(c,d);else{let e=void 0!==b.getHeader(c);(d.includes(c.toLowerCase())||!e)&&b.appendHeader(c,a)}});let{originalResponse:i}=b;c.body&&"HEAD"!==a.method?await (0,e.pipeToNodeResponse)(c.body,i,g):i.end()}}},176760:a=>{"use strict";a.exports=require("node:path")},200261:a=>{"use strict";a.exports=require("next/dist/shared/lib/router/utils/app-paths")},257975:a=>{"use strict";a.exports=require("node:util")},333873:a=>{"use strict";a.exports=require("path")},449714:()=>{},529294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},629021:a=>{"use strict";a.exports=require("fs")},663033:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},709962:()=>{},710846:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},719771:a=>{"use strict";a.exports=require("process")},731421:a=>{"use strict";a.exports=require("node:child_process")},744870:a=>{"use strict";a.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},848161:a=>{"use strict";a.exports=require("node:os")},940527:(a,b,c)=>{"use strict";a.exports=c(744870)},973024:a=>{"use strict";a.exports=require("node:fs")},979428:a=>{"use strict";a.exports=require("buffer")},986439: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,[76973,22137,93349],()=>b(b.s=50647));module.exports=c})();