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),g=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:g,lastUpdated:d(r.last_updated),body:a}}catch{return null}}function g(){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 f=new Set(["the","and","for","that","this","with","you","are","was","were","what","how","who","why","when","from","can","our","your","של","על","עם","את","זה","מה","איך","מי","למה","מתי"]);function h(e){return new Set((e.toLowerCase().match(/[\p{L}\p{N}_-]{2,}/gu)??[]).filter(e=>!f.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,g,"readOrgBrainNode",0,p,"selectOrgBrainNodesForRun",0,function(e,t=4){let r=g();if(0===r.length)return[];let n=r.map(t=>({node:t,score:function(e,t){let r=h(t);if(0===r.size)return 0;let n=0,a=h([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}])},88743,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),g=e.i(70101),f=e.i(74838),h=e.i(10372),m=e.i(93695);e.i(20232);var y=e.i(220),w=e.i(13427);async function R(e,t){let{slug:r}=await t.params,n=(0,w.readOrgBrainNode)(r);return n?Response.json({node:n},{headers:{"Cache-Control":"no-store"}}):Response.json({error:"node not found"},{status:404})}async function v(e,t){let{slug:r}=await t.params,n=(0,w.readOrgBrainNode)(r);if(!n)return Response.json({error:"node not found"},{status:404});let a=await e.json(),o=(0,w.writeOrgBrainNode)({slug:n.slug,label:a.label??n.label,type:a.type??n.type,description:a.description??n.description,triggers:a.triggers??n.triggers,sources:a.sources??n.sources,linkedNodes:a.linkedNodes??n.linkedNodes,body:a.body??n.body});return Response.json({node:o})}async function b(e,t){let{slug:r}=await t.params;return(0,w.deleteOrgBrainNode)(r)?Response.json({ok:!0}):Response.json({error:"node not found"},{status:404})}e.s(["DELETE",0,b,"GET",0,R,"PATCH",0,v],59605);var x=e.i(59605);let C=new t.AppRouteRouteModule({definition:{kind:r.RouteKind.APP_ROUTE,page:"/api/org/brain/[slug]/route",pathname:"/api/org/brain/[slug]",filename:"route",bundlePath:""},distDir:".next",relativeProjectDir:"",resolvedPagePath:"[project]/src/app/api/org/brain/[slug]/route.ts",nextConfigOutput:"standalone",userland:x,...{}}),{workAsyncStorage:E,workUnitAsyncStorage:N,serverHooks:A}=C;async function $(e,t,n){n.requestMeta&&(0,a.setRequestMeta)(e,n.requestMeta),C.isDev&&(0,a.addRequestMeta)(e,"devRequestTimingInternalsEnd",process.hrtime.bigint());let w="/api/org/brain/[slug]/route";w=w.replace(/\/index$/,"")||"/";let R=await C.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:x,parsedUrl:E,isDraftMode:N,prerenderManifest:A,routerServerContext:$,isOnDemandRevalidate:j,revalidateOnlyGenerated:S,resolvedPathname:O,clientReferenceManifest:T,serverActionsManifest:k}=R,_=(0,i.normalizeAppPath)(w),q=!!(A.dynamicRoutes[_]||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[_];if(t&&!1===t.fallback&&!e){if(x.adapterPath)return await P();throw new m.NoFallbackError}}let B=null;!q||C.isDev||N||(B="/index"===(B=O)?"/":B);let U=!0===C.isDev||!q,H=q&&!U;k&&T&&(0,s.setManifestsSingleton)({page:w,clientReferenceManifest:T,serverActionsManifest:k});let I=e.method||"GET",D=(0,o.getTracer)(),L=D.getActiveScopeSpan(),M=!!(null==$?void 0:$.isWrappedByNextServer),F=!!(0,a.getRequestMeta)(e,"minimalMode"),K=(0,a.getRequestMeta)(e,"incrementalCache")||await C.getIncrementalCache(e,x,A,F);null==K||K.resetRequestCache(),globalThis.__incrementalCache=K;let z={params:b,previewProps:A.preview,renderOpts:{experimental:{authInterrupts:!!x.experimental.authInterrupts},cacheComponents:!!x.cacheComponents,supportsDynamicResponse:U,incrementalCache:K,cacheLifeProfiles:x.cacheLife,waitUntil:n.waitUntil,onClose:e=>{t.on("close",e)},onAfterTaskError:void 0,onInstrumentationRequestError:(t,r,n,a)=>C.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=>C.handle(V,z).finally(()=>{if(!e)return;e.setAttributes({"http.status_code":t.statusCode,"next.rsc":!1});let r=D.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&&j&&S&&!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,g.toNodeOutgoingHttpHeaders)(o.headers);l&&(t[h.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>=h.INFINITE_CACHE)&&z.renderOpts.collectedRevalidate,n=void 0===z.renderOpts.collectedExpire||z.renderOpts.collectedExpire>=h.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 C.onRequestError(e,t,{routerKind:"App Router",routePath:w,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:j})},!1,$),t}},d=await C.handleResponse({req:e,nextConfig:x,cacheKey:B,routeKind:r.RouteKind.APP_ROUTE,isFallback:!1,prerenderManifest:A,isRoutePPREnabled:!1,isOnDemandRevalidate:j,revalidateOnlyGenerated:S,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",j?"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,g.fromNodeOutgoingHttpHeaders)(d.value.headers);return F&&q||u.delete(h.NEXT_CACHE_TAGS_HEADER),!d.cacheControl||t.getHeader("Cache-Control")||u.get("Cache-Control")||u.set("Cache-Control",(0,f.getCacheControlHeader)(d.cacheControl)),await (0,p.sendResponse)(W,G,new Response(d.value.body,{headers:u,status:d.value.status||200})),null};M&&L?await i(L):(a=D.getActiveScopeSpan(),await D.withPropagatedContext(e.headers,()=>D.trace(u.BaseServerSpan.handleRequest,{spanName:`${I} ${w}`,kind:o.SpanKind.SERVER,attributes:{"http.method":I,"http.target":e.url}},i),void 0,!M))}catch(t){if(t instanceof m.NoFallbackError||await C.onRequestError(e,t,{routerKind:"App Router",routePath:_,routeType:"route",revalidateReason:(0,c.getRevalidateReason)({isStaticGeneration:H,isOnDemandRevalidate:j})},!1,$),q)throw t;return await (0,p.sendResponse)(W,G,new Response(null,{status:500})),null}}e.s(["handler",0,$,"patchFetch",0,function(){return(0,n.patchFetch)({workAsyncStorage:E,workUnitAsyncStorage:N})},"routeModule",0,C,"serverHooks",0,A,"workAsyncStorage",0,E,"workUnitAsyncStorage",0,N],88743)}];

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