module.exports=[22734,(e,t,r)=>{t.exports=e.x("fs",()=>require("fs"))},93695,(e,t,r)=>{t.exports=e.x("next/dist/shared/lib/no-fallback-error.external.js",()=>require("next/dist/shared/lib/no-fallback-error.external.js"))},18622,(e,t,r)=>{t.exports=e.x("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js",()=>require("next/dist/compiled/next-server/app-page-turbo.runtime.prod.js"))},56704,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-async-storage.external.js",()=>require("next/dist/server/app-render/work-async-storage.external.js"))},32319,(e,t,r)=>{t.exports=e.x("next/dist/server/app-render/work-unit-async-storage.external.js",()=>require("next/dist/server/app-render/work-unit-async-storage.external.js"))},14747,(e,t,r)=>{t.exports=e.x("path",()=>require("path"))},13427,e=>{"use strict";var t=e.i(22734),r=e.i(14747);let n=r.default.join(process.cwd(),"data","org-brain"),a=r.default.join(n,"nodes"),o=/^---\s*\n([\s\S]*?)\n---\s*\n([\s\S]*)$/,s=/\[\[([a-zA-Z0-9_-]+)(?:#[^\]|]+)?(?:\|[^\]]+)?\]\]/g,i=["document","decision","incident","policy","customer","product","process","note"];function l(e){return e.toLowerCase().trim().replace(/[^a-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"").slice(0,80)}function d(e){return"string"==typeof e?e:""}function u(e){return Array.isArray(e)?e:"string"==typeof e&&e?[e]:[]}function c(e){let t=e.toLowerCase();return i.includes(t)?t:"note"}function p(e){let n=l(e),i=r.default.join(a,`${n}.md`);try{let e=t.default.readFileSync(i,"utf8"),{fm:r,body:a}=function(e){let t=e.match(o);if(!t)return{fm:{},body:e};let r={};for(let e of t[1].split("\n")){let t=e.match(/^([a-zA-Z_]+):\s*(.+)$/);if(!t)continue;let n=t[1],a=t[2].trim();if(a.startsWith("[")&&a.endsWith("]")){let e=a.slice(1,-1).trim();r[n]=e?e.split(",").map(e=>e.trim().replace(/^['"]|['"]$/g,"")):[];continue}r[n]=a.replace(/^['"]|['"]$/g,"")}return{fm:r,body:t[2]?.trim()??""}}(e),l=u(r.linked_nodes),p=function(e){let t=new Set;for(let r of e.matchAll(s))t.add(r[1]);return Array.from(t)}(a),h=Array.from(new Set([...l,...p]));return{slug:d(r.slug)||n,label:d(r.label)||n,type:c(d(r.type)||"note"),description:d(r.description),triggers:u(r.triggers),sources:u(r.sources),linkedNodes:h,lastUpdated:d(r.last_updated),body:a}}catch{return null}}function h(){try{return t.default.readdirSync(a,{withFileTypes:!0}).filter(e=>e.isFile()&&e.name.endsWith(".md")).map(e=>p(e.name.replace(/\.md$/,""))).filter(e=>!!e).sort((e,t)=>e.label.localeCompare(t.label))}catch{return[]}}let g=new Set(["the","and","for","that","this","with","you","are","was","were","what","how","who","why","when","from","can","our","your","של","על","עם","את","זה","מה","איך","מי","למה","מתי"]);function f(e){return new Set((e.toLowerCase().match(/[\p{L}\p{N}_-]{2,}/gu)??[]).filter(e=>!g.has(e)))}e.s(["deleteOrgBrainNode",0,function(e){let n=l(e),o=r.default.join(a,`${n}.md`);try{return t.default.unlinkSync(o),!0}catch{return!1}},"formatOrgBrainBlock",0,function(e){if(0===e.length)return"";let t=e.map(({node:e})=>{let t=[e.type?`type: ${e.type}`:"",e.sources.length?`sources: ${e.sources.join(", ")}`:"",e.lastUpdated?`updated: ${e.lastUpdated.slice(0,10)}`:""].filter(Boolean).join(" · ");return`## ${e.label} \`[[${e.slug}]]\`
${t?`_${t}_
`:""}
${e.body}`}).join("\n\n---\n\n");return`# Relevant company knowledge (Org Brain)

These are organization-wide facts and documents — shared across every twin in
the company. Treat them as ground truth about the company itself (decisions,
policies, customers, incidents, products). They do NOT override your personal
profile, hard boundaries, or the user's direction.

${t}`},"listOrgBrainNodes",0,h,"readOrgBrainNode",0,p,"selectOrgBrainNodesForRun",0,function(e,t=4){let r=h();if(0===r.length)return[];let n=r.map(t=>({node:t,score:function(e,t){let r=f(t);if(0===r.size)return 0;let n=0,a=f([e.slug,e.label,e.description,e.triggers.join(" ")].join(" ").toLowerCase());for(let e of r)a.has(e)&&(n+=1);for(let r of e.triggers)r&&t.toLowerCase().includes(r.toLowerCase())&&(n+=3);return e.label.length>=4&&t.toLowerCase().includes(e.label.toLowerCase())&&(n+=2),n}(t,e)})).sort((e,t)=>t.score-e.score).filter(e=>e.score>0);return 0===n.length?[]:n.slice(0,t)},"writeOrgBrainNode",0,function(e){var n;let o=l(e.slug);if(!o)throw Error("node slug is required");let s={slug:o,label:e.label.trim()||o,type:c(e.type??"note"),description:(e.description??"").trim(),triggers:(e.triggers??[]).map(e=>e.trim()).filter(Boolean),sources:(e.sources??[]).map(e=>e.trim()).filter(Boolean),linkedNodes:(e.linkedNodes??[]).map(e=>l(e)).filter(Boolean),lastUpdated:new Date().toISOString(),body:e.body.trim()};return t.default.mkdirSync(a,{recursive:!0}),t.default.writeFileSync(r.default.join(a,`${o}.md`),(n=s,`---
slug: ${n.slug}
label: ${n.label}
type: ${n.type}
description: ${n.description}
triggers: [${n.triggers.join(", ")}]
sources: [${n.sources.join(", ")}]
linked_nodes: [${n.linkedNodes.join(", ")}]
last_updated: ${n.lastUpdated}
---

${n.body.replace(/\s+$/,"")}
`),"utf8"),s}])},15114,e=>{"use strict";var t=e.i(47909),r=e.i(74017),n=e.i(96250),a=e.i(59756),o=e.i(61916),s=e.i(74677),i=e.i(69741),l=e.i(16795),d=e.i(87718),u=e.i(95169),c=e.i(47587),p=e.i(66012),h=e.i(70101),g=e.i(74838),f=e.i(10372),m=e.i(93695);e.i(20232);var y=e.i(220),w=e.i(13427);async function R(){return Response.json({nodes:(0,w.listOrgBrainNodes)()},{headers:{"Cache-Control":"no-store"}})}async function v(e){let t=await e.json();if(!t.slug?.trim()||!t.label?.trim())return Response.json({error:"slug and label are required"},{status:400});try{let e=(0,w.writeOrgBrainNode)({slug:t.slug,label:t.label,type:t.type,description:t.description??"",triggers:t.triggers??[],sources:t.sources??[],linkedNodes:t.linkedNodes??[],body:t.body??""});return Response.json({node:e},{status:201})}catch(t){let e=t instanceof Error?t.message:"failed to save node";return Response.json({error:e},{status:400})}}e.s(["GET",0,R,"POST",0,v],92630);var b=e.i(92630);let x=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/org/brain/route",pathname:"/api/org/brain",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/org/brain/route.ts",nextConfigOutput:"standalone",userland:b,...{}}),{workAsyncStorage:C,workUnitAsyncStorage:E,serverHooks:N}=x;async function A(e,t,n){n.requestMeta&&(0,a.setRequestMeta)(e,n.requestMeta),x.isDev&&(0,a.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let w="/api/org/brain/route";w=w.replace(/\/index$/,"")||"/";let R=await x.prepare(e,t,{srcPage:w,multiZoneDraftMode:!1});if(!R)return t.statusCode=400,t.end("Bad Request"),null==n.waitUntil||n.waitUntil.call(n,Promise.resolve()),null;let{buildId:v,params:b,nextConfig:C,parsedUrl:E,isDraftMode:N,prerenderManifest:A,routerServerContext:$,isOnDemandRevalidate:S,revalidateOnlyGenerated:j,resolvedPathname:O,clientReferenceManifest:T,serverActionsManifest:_}=R,k=(0,i.normalizeAppPath)(w),q=!!(A.dynamicRoutes[k]||A.routes[O]),P=async()=>((null==$?void 0:$.render404)?await $.render404(e,t,E,!1):t.end("This page could not be found"),null);if(q&&!N){let e=!!A.routes[O],t=A.dynamicRoutes[k];if(t&&!1===t.fallback&&!e){if(C.adapterPath)return await P();throw new m.NoFallbackError}}let U=null;!q||x.isDev||N||(U="/index"===(U=O)?"/":U);let B=!0===x.isDev||!q,H=q&&!B;_&&T&&(0,s.setManifestsSingleton)({page:w,clientReferenceManifest:T,serverActionsManifest:_});let I=e.method||"GET",M=(0,o.getTracer)(),D=M.getActiveScopeSpan(),L=!!(null==$?void 0:$.isWrappedByNextServer),F=!!(0,a.getRequestMeta)(e,"minimalMode"),K=(0,a.getRequestMeta)(e,"incrementalCache")||await x.getIncrementalCache(e,C,A,F);null==K||K.resetRequestCache(),globalThis.__incrementalCache=K;let z={params:b,previewProps:A.preview,renderOpts:{experimental:{authInterrupts:!!C.experimental.authInterrupts},cacheComponents:!!C.cacheComponents,supportsDynamicResponse:B,incrementalCache:K,cacheLifeProfiles:C.cacheLife,waitUntil:n.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,n,a)=>x.onRequestError(e,t,n,a,$)},sharedContext:{buildId:v}},W=new l.NodeNextRequest(e),G=new l.NodeNextResponse(t),V=d.NextRequestAdapter.fromNodeNextRequest(W,(0,d.signalFromNodeResponse)(t));try{let a,s=async e=>x.handle(V,z).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=M.getRootSpanAttributes();if(!r)return;if(r.get("next.span_type")!==u.BaseServerSpan.handleRequest)return void console.warn(`Unexpected root span type '${r.get("next.span_type")}'. Please report this Next.js issue https://github.com/vercel/next.js`);let n=r.get("next.route");if(n){let t=`${I} ${n}`;e.setAttributes({"next.route":n,"http.route":n,"next.span_name":t}),e.updateName(t),a&&a!==e&&(a.setAttribute("http.route",n),a.updateName(t))}else e.updateName(`${I} ${w}`)}),i=async a=>{var o,i;let l=async({previousCacheEntry:r})=>{try{if(!F&&S&&j&&!r)return t.statusCode=404,t.setHeader("x-nextjs-cache","REVALIDATED"),t.end("This page could not be found"),null;let o=await s(a);e.fetchMetrics=z.renderOpts.fetchMetrics;let i=z.renderOpts.pendingWaitUntil;i&&n.waitUntil&&(n.waitUntil(i),i=void 0);let l=z.renderOpts.collectedTags;if(!q)return await (0,p.sendResponse)(W,G,o,z.renderOpts.pendingWaitUntil),null;{let e=await o.blob(),t=(0,h.toNodeOutgoingHttpHeaders)(o.headers);l&&(t[f.NEXT_CACHE_TAGS_HEADER]=l),!t["content-type"]&&e.type&&(t["content-type"]=e.type);let r=void 0!==z.renderOpts.collectedRevalidate&&!(z.renderOpts.collectedRevalidate>=f.INFINITE_CACHE)&&z.renderOpts.collectedRevalidate,n=void 0===z.renderOpts.collectedExpire||z.renderOpts.collectedExpire>=f.INFINITE_CACHE?void 0:z.renderOpts.collectedExpire;return{value:{kind:y.CachedRouteKind.APP_ROUTE,status:o.status,body:Buffer.from(await e.arrayBuffer()),headers:t},cacheControl:{revalidate:r,expire:n}}}}catch(t){throw(null==r?void 0:r.isStale)&&await x.onRequestError(e,t,{routerKind:"App Router",routePath:w,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:S})},!1,$),t}},d=await x.handleResponse({req:e,nextConfig:C,cacheKey:U,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:A,isRoutePPREnabled:!1,isOnDemandRevalidate:S,revalidateOnlyGenerated:j,responseGenerator:l,waitUntil:n.waitUntil,isMinimalMode:F});if(!q)return null;if((null==d||null==(o=d.value)?void 0:o.kind)!==y.CachedRouteKind.APP_ROUTE)throw Object.defineProperty(Error(`Invariant: app-route received invalid cache entry ${null==d||null==(i=d.value)?void 0:i.kind}`),"__NEXT_ERROR_CODE",{value:"E701",enumerable:!1,configurable:!0});F||t.setHeader("x-nextjs-cache",S?"REVALIDATED":d.isMiss?"MISS":d.isStale?"STALE":"HIT"),N&&t.setHeader("Cache-Control","private, no-cache, no-store, max-age=0, must-revalidate");let u=(0,h.fromNodeOutgoingHttpHeaders)(d.value.headers);return F&&q||u.delete(f.NEXT_CACHE_TAGS_HEADER),!d.cacheControl||t.getHeader("Cache-Control")||u.get("Cache-Control")||u.set("Cache-Control",(0,g.getCacheControlHeader)(d.cacheControl)),await (0,p.sendResponse)(W,G,new Response(d.value.body,{headers:u,status:d.value.status||200})),null};L&&D?await i(D):(a=M.getActiveScopeSpan(),await M.withPropagatedContext(e.headers,()=>M.trace(u.BaseServerSpan.handleRequest,{spanName:`${I} ${w}`,kind:o.SpanKind.SERVER,attributes:{"http.method":I,"http.target":e.url}},i),void 0,!L))}catch(t){if(t instanceof m.NoFallbackError||await x.onRequestError(e,t,{routerKind:"App Router",routePath:k,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:S})},!1,$),q)throw t;return await (0,p.sendResponse)(W,G,new Response(null,{status:500})),null}}e.s(["handler",0,A,"patchFetch",0,function(){return(0,n.patchFetch)({workAsyncStorage:C,workUnitAsyncStorage:E})},"routeModule",0,x,"serverHooks",0,N,"workAsyncStorage",0,C,"workUnitAsyncStorage",0,E],15114)}];

//# sourceMappingURL=%5Broot-of-the-server%5D__07vmq9c._.js.map