(()=>{var a={};a.id=97748,a.ids=[97748],a.modules={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")},222700:(a,b,c)=>{"use strict";c.r(b),c.d(b,{handler:()=>L,patchFetch:()=>K,routeModule:()=>G,serverHooks:()=>J,workAsyncStorage:()=>H,workUnitAsyncStorage:()=>I});var d={};c.r(d),c.d(d,{POST:()=>F,dynamic:()=>C,runtime:()=>D});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(693349),v=c(731421),w=c(176760),x=c(973024),y=c(380481);let z={".js":{command:"node",args:a=>[a]},".mjs":{command:"node",args:a=>[a]},".cjs":{command:"node",args:a=>[a]},".ts":{command:"npx",args:a=>["tsx",a]},".py":{command:"python3",args:a=>[a]},".sh":{command:"bash",args:a=>[a]},".rb":{command:"ruby",args:a=>[a]},".php":{command:"php",args:a=>[a]}};async function*A(a,b,c){var d;let e;yield{type:"started",entryId:b.entryId,runId:c};let f=a.timeout??6e4,g={...process.env,DENCH_ENTRY_ID:b.entryId,DENCH_ENTRY_DATA:JSON.stringify(b.entryData),DENCH_OBJECT_NAME:b.objectName,DENCH_OBJECT_ID:b.objectId,DENCH_ACTION_ID:b.actionId,DENCH_FIELD_ID:b.fieldId,DENCH_WORKSPACE_PATH:b.workspacePath,DENCH_DB_PATH:b.dbPath,DENCH_API_URL:b.apiUrl},h=null;try{if(a.script&&(!a.scriptPath||"inline"===a.runtime)){let f=(0,w.join)(b.workspacePath,".actions",".tmp");(0,x.existsSync)(f)||(0,x.mkdirSync)(f,{recursive:!0}),h=(0,w.join)(f,`${c}.js`);let i=(0,w.join)(__dirname,"action-sdk-runtime.js");(0,x.writeFileSync)(h,(d=a.script,`const dench = require(${JSON.stringify(i)})(process.env);
const context = {
  entryId: process.env.DENCH_ENTRY_ID,
  entryData: JSON.parse(process.env.DENCH_ENTRY_DATA || '{}'),
  objectName: process.env.DENCH_OBJECT_NAME,
  objectId: process.env.DENCH_OBJECT_ID,
  actionId: process.env.DENCH_ACTION_ID,
  fieldId: process.env.DENCH_FIELD_ID,
  workspacePath: process.env.DENCH_WORKSPACE_PATH,
  dbPath: process.env.DENCH_DB_PATH,
  apiUrl: process.env.DENCH_API_URL,
};
(async () => {
${d}
})().then(r => {
  if (r !== undefined) console.log(JSON.stringify({type:"result",status:"success",data:r}));
  else console.log(JSON.stringify({type:"result",status:"success",data:{}}));
}).catch(e => {
  console.log(JSON.stringify({type:"result",status:"error",data:{message:e.message||String(e)}}));
  process.exit(1);
});
`)),e=(0,v.spawn)("node",[h],{env:g,cwd:b.workspacePath,stdio:["ignore","pipe","pipe"]})}else{if(!a.scriptPath)return void(yield{type:"completed",entryId:b.entryId,status:"error",error:"No script or scriptPath defined"});let c=(0,w.join)(b.workspacePath,b.objectName),d=(0,w.join)(c,a.scriptPath);if(!(0,x.existsSync)(d))return void(yield{type:"completed",entryId:b.entryId,status:"error",error:`Script not found: ${a.scriptPath}`});let{command:f,args:h}=function(a,b){if(b&&"auto"!==b)return{command:({node:"node",python:"python3",bash:"bash",ruby:"ruby"})[b]??b,args:[a]};let c=z[(0,w.extname)(a).toLowerCase()];return c?{command:c.command,args:c.args(a)}:{command:a,args:[]}}(d,a.runtime);e=(0,v.spawn)(f,h,{env:g,cwd:c,stdio:["ignore","pipe","pipe"]})}}catch(a){if(yield{type:"completed",entryId:b.entryId,status:"error",error:`Failed to spawn: ${a instanceof Error?a.message:String(a)}`},h)try{(0,x.unlinkSync)(h)}catch{}return}let i=[],j=[],k=!1,l=setTimeout(()=>{try{e.kill("SIGTERM")}catch{}setTimeout(()=>{try{e.kill("SIGKILL")}catch{}},5e3)},f),m=(0,y.createInterface)({input:e.stdout}),n=[],o=null,p=!1;function q(a){n.push(a),o&&(o(),o=null)}m.on("line",a=>{if(i.push(a),a.trim()){try{let c=JSON.parse(a);if(c&&"object"==typeof c&&c.type)return void("progress"===c.type?q({type:"progress",entryId:b.entryId,percent:c.percent??0,message:c.message}):"log"===c.type?q({type:"log",entryId:b.entryId,level:c.level??"info",message:c.message??""}):"result"===c.type&&(k=!0,q({type:"completed",entryId:b.entryId,status:"error"===c.status?"error":"success",result:c.data,error:"error"===c.status?c.data?.message??"Script error":void 0})))}catch{}q({type:"log",entryId:b.entryId,level:"info",message:a})}}),e.stderr?.on("data",a=>{j.push(a.toString())}),e.on("close",a=>{if(clearTimeout(l),!k){let c=j.join("").trim();q({type:"completed",entryId:b.entryId,status:0===a?"success":"error",result:0===a?{}:void 0,error:0!==a?c||`Process exited with code ${a}`:void 0,exitCode:a??void 0})}p=!0,o&&(o(),o=null)}),e.on("error",a=>{clearTimeout(l),k||q({type:"completed",entryId:b.entryId,status:"error",error:`Process error: ${a.message}`}),p=!0,o&&(o(),o=null)});try{for(;!p||n.length>0;)for(0===n.length&&await new Promise(a=>{o=a});n.length>0;)yield n.shift()}finally{if(h)try{(0,x.unlinkSync)(h)}catch{}}}async function*B(a,b,c){let d=0,e=0,f=[];function g(){if(e>=b.length)return;let g=b[e],h=`${c}_${e}`;e++,d++;let i=A(a,g,h),j={gen:i,promise:i.next()};f.push(j)}for(;d<8&&e<b.length;)g();for(;f.length>0;){let{idx:a,result:b}=await Promise.race(f.map(async(a,b)=>({idx:b,result:await a.promise}))),c=f[a];b.done?(f.splice(a,1),d--,g()):(yield b.value,"completed"===b.value.type?(f.splice(a,1),d--,g()):c.promise=c.gen.next())}yield{type:"done"}}let C="force-dynamic",D="nodejs";function E(a){return a.replace(/'/g,"''")}async function F(a,{params:b}){let{name:c}=await b,{actionId:d,fieldId:e,entryIds:f}=await a.json();if(!d||!e||!Array.isArray(f)||0===f.length)return Response.json({error:"actionId, fieldId, and entryIds[] required"},{status:400});let g=(0,u.fO)(c);if(!g)return Response.json({error:"DuckDB not found"},{status:404});let h=(0,u.hM)(g,`SELECT id, name, type, default_value FROM fields WHERE id = '${E(e)}' AND type = 'action' LIMIT 1`);if(0===h.length)return Response.json({error:"Action field not found"},{status:404});let i=(function(a){if(!a)return[];try{let b=JSON.parse(a);if(b&&Array.isArray(b.actions))return b.actions}catch{}return[]})(h[0].default_value).find(a=>a.id===d);if(!i)return Response.json({error:`Action '${d}' not found on field`},{status:404});let j=(0,u.hM)(g,`SELECT id FROM objects WHERE name = '${E(c)}' LIMIT 1`);if(0===j.length)return Response.json({error:"Object not found"},{status:404});let k=j[0].id,l=(0,u.Yn)()??"",m=(0,u.$1)()??"",n=process.env.PORT||"3000",o=`http://localhost:${n}/api`;(0,u.hM)(g,`SELECT name FROM fields WHERE object_id = '${E(k)}' AND type != 'action' ORDER BY sort_order`).map(a=>a.name);let p=[];for(let a of f){let b={};try{for(let c of(0,u.hM)(g,`SELECT ef.value, f.name as field_name
				 FROM entry_fields ef JOIN fields f ON f.id = ef.field_id
				 WHERE ef.entry_id = '${E(a)}'`))c.field_name&&(b[String(c.field_name)]=c.value);b.entry_id=a}catch{}p.push({entryId:a,entryData:b,objectName:c,objectId:k,actionId:d,fieldId:e,workspacePath:l,dbPath:m,apiUrl:o})}let q=`run_${Date.now()}_${Math.random().toString(36).slice(2,8)}`,r=new TextEncoder,s=new ReadableStream({async start(a){try{for await(let b of 1===p.length?A(i,p[0],`${q}_0`):B(i,p,q)){let c=JSON.stringify(b);a.enqueue(r.encode(`event: ${b.type}
data: ${c}

`)),"completed"===b.type&&function(a,b){try{let c=(0,u.hM)(a,"SELECT COUNT(*) as cnt FROM information_schema.tables WHERE table_name = 'action_runs'");c[0]?.cnt||(0,u.u4)(a,`CREATE TABLE IF NOT EXISTS action_runs (
				id VARCHAR PRIMARY KEY DEFAULT (gen_random_uuid()::VARCHAR),
				action_id VARCHAR NOT NULL,
				field_id VARCHAR NOT NULL,
				entry_id VARCHAR NOT NULL,
				object_id VARCHAR NOT NULL,
				status VARCHAR NOT NULL DEFAULT 'pending',
				started_at TIMESTAMPTZ DEFAULT now(),
				completed_at TIMESTAMPTZ,
				result VARCHAR,
				error VARCHAR,
				stdout VARCHAR,
				exit_code INTEGER
			)`),(0,u.u4)(a,`INSERT INTO action_runs (action_id, field_id, entry_id, object_id, status, completed_at, result, error, exit_code)
			VALUES (
				'${E(b.actionId)}',
				'${E(b.fieldId)}',
				'${E(b.entryId)}',
				'${E(b.objectId)}',
				'${E(b.status)}',
				now(),
				${b.result?`'${E(b.result)}'`:"NULL"},
				${b.error?`'${E(b.error)}'`:"NULL"},
				${null!==b.exitCode?b.exitCode:"NULL"}
			)`)}catch{}}(g,{actionId:d,fieldId:e,entryId:b.entryId,objectId:k,status:b.status,result:b.result?JSON.stringify(b.result):null,error:b.error??null,exitCode:b.exitCode??null})}}catch(c){let b=c instanceof Error?c.message:String(c);a.enqueue(r.encode(`event: error
data: ${JSON.stringify({error:b})}

`))}finally{a.close()}}});return new Response(s,{headers:{"Content-Type":"text/event-stream","Cache-Control":"no-cache",Connection:"keep-alive"}})}let G=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/workspace/objects/[name]/actions/route",pathname:"/api/workspace/objects/[name]/actions",filename:"route",bundlePath:"app/api/workspace/objects/[name]/actions/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/home/runner/work/DenchClaw/DenchClaw/apps/web/app/api/workspace/objects/[name]/actions/route.ts",nextConfigOutput:"standalone",userland:d}),{workAsyncStorage:H,workUnitAsyncStorage:I,serverHooks:J}=G;function K(){return(0,g.patchFetch)({workAsyncStorage:H,workUnitAsyncStorage:I})}async function L(a,b,c){var d;let e="/api/workspace/objects/[name]/actions/route";"/index"===e&&(e="/");let g=await G.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||G.isDev||x||(F="/index"===(F=C)?"/":F);let H=!0===G.isDev||!E,I=E&&!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)=>G.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=>G.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(!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 G.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:A})},z),b}},l=await G.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 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 G.onRequestError(a,b,{routerKind:"App Router",routePath:D,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:A})}),E)throw b;return await (0,o.I)(N,O,new Response(null,{status:500})),null}}},257975:a=>{"use strict";a.exports=require("node:util")},380481:a=>{"use strict";a.exports=require("node:readline")},449714:()=>{},529294:a=>{"use strict";a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},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=222700));module.exports=c})();