"use strict";(()=>{var a={};a.id=92245,a.ids=[92245],a.modules={51455:a=>{a.exports=require("node:fs/promises")},176760:a=>{a.exports=require("node:path")},200261:a=>{a.exports=require("next/dist/shared/lib/router/utils/app-paths")},257975:a=>{a.exports=require("node:util")},322440:(a,b,c)=>{c.r(b),c.d(b,{handler:()=>K,patchFetch:()=>J,routeModule:()=>F,serverHooks:()=>I,workAsyncStorage:()=>G,workUnitAsyncStorage:()=>H});var d={};c.r(d),c.d(d,{GET:()=>E,dynamic:()=>A,runtime:()=>B});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(727488),v=c(864490),w=c(823446),x=c(561766),y=c(918306),z=c(837311);let A="force-dynamic",B="nodejs";function C(a){return JSON.stringify(a).replace(/</g,"\\u003c")}async function D(a){if(!a)return null;let b=(0,u.Bk)();if(!b)return null;try{return(0,w.eF)((0,w.s$)(await (0,u.t3)((0,u.NK)(),b))).find(b=>b.id===a)??null}catch{return null}}async function E(a){let b,{searchParams:c}=new URL(a.url),d=c.get("status")??"unknown",e=c.get("connected_account_id")??"",f=(0,z.F)(a),g="success"===d;g&&((0,v.C8)(),(b=await D(e))&&function(a){if(!a.is_active)return;let b="gmail"===a.normalized_toolkit_slug?"gmail":"google-calendar"===a.normalized_toolkit_slug||"googlecalendar"===a.normalized_toolkit_slug?"calendar":null;if(!b)return;let c={connectionId:a.id,toolkitSlug:a.normalized_toolkit_slug,accountEmail:a.account_email??a.account?.email??void 0,accountLabel:a.display_label,connectedAt:new Date().toISOString()};(0,x.C0)(b,c);let d=(0,x.Pv)();(0,x.ki)({...d,connections:{...d.connections,[b]:c}})}(b),(async()=>{try{await (0,y.nP)()}catch{}})());let h=C({type:"composio-callback",status:d,connected_account_id:e,connected_toolkit_slug:b?.normalized_toolkit_slug??null,connected_toolkit_name:b?.toolkit_name??null,connected_status:b?.normalized_status??null}),i=C(f);return new Response(`<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>${g?"Connected":"Connection Failed"} — DenchClaw</title>
  <style>
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
    body {
      font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
      background: #09090b; color: #fafafa;
      display: flex; align-items: center; justify-content: center;
      min-height: 100vh; padding: 2rem;
    }
    .card {
      max-width: 420px; width: 100%; text-align: center;
      padding: 3rem 2rem; border-radius: 1rem;
      border: 1px solid #27272a; background: #18181b;
    }
    .icon { font-size: 3rem; margin-bottom: 1rem; }
    h1 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.5rem; }
    p { font-size: 0.875rem; color: #a1a1aa; line-height: 1.5; }
  </style>
</head>
<body>
  <div class="card">
    <div class="icon">${g?"&#10003;":"&#10007;"}</div>
    <h1>${g?"Connected successfully":"Connection failed"}</h1>
    <p>${g?"You can close this tab and return to DenchClaw.":"Something went wrong. Please close this tab and try again."}</p>
  </div>
  <script>
    try {
      const payload = ${h};
      const targetOrigin = ${i};
      if (window.opener && !window.opener.closed) {
        window.opener.postMessage(payload, targetOrigin);
        setTimeout(() => window.close(), 150);
      }
    } catch (_) {}
  </script>
</body>
</html>`,{headers:{"content-type":"text/html; charset=utf-8"}})}let F=new e.AppRouteRouteModule({definition:{kind:f.RouteKind.APP_ROUTE,page:"/api/composio/callback/route",pathname:"/api/composio/callback",filename:"route",bundlePath:"app/api/composio/callback/route"},distDir:".next",relativeProjectDir:"",resolvedPagePath:"/home/runner/work/DenchClaw/DenchClaw/apps/web/app/api/composio/callback/route.ts",nextConfigOutput:"standalone",userland:d}),{workAsyncStorage:G,workUnitAsyncStorage:H,serverHooks:I}=F;function J(){return(0,g.patchFetch)({workAsyncStorage:G,workUnitAsyncStorage:H})}async function K(a,b,c){var d;let e="/api/composio/callback/route";"/index"===e&&(e="/");let g=await F.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 G=null;!E||F.isDev||x||(G="/index"===(G=C)?"/":G);let H=!0===F.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)=>F.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=>F.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 F.onRequestError(a,b,{routerKind:"App Router",routePath:e,routeType:"route",revalidateReason:(0,n.c)({isRevalidate:I,isOnDemandRevalidate:A})},z),b}},l=await F.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(!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 F.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}}},499496:(a,b,c)=>{c.d(b,{Cq:()=>d});let d=["target-account-list-builder","icp-outreach-builder","lookalike-customer-finder","funding-signal-prospector","hiring-signal-prospector","website-visitor-follow-up","conference-lead-researcher","linkedin-style-outreach","stale-thread-follow-up-agent","warm-lead-nurture","proposal-chaser","no-show-recovery","champion-job-change-tracker","deck-claim-verifier","pre-call-diff-brief","candidate-ghosting-recovery","month-end-metrics-assembler","plg-expansion-scout","crm-contact-enricher","duplicate-record-cleaner","relationship-strength-scorer","pipeline-hygiene-digest","meeting-prep-brief","executive-daily-brief","investor-meeting-prep","post-meeting-follow-through","company-deep-researcher","competitor-monitor","news-signal-digest","customer-voice-miner","market-map-builder","candidate-research-brief","interview-follow-up-agent","talent-pipeline-hygiene","hiring-manager-weekly-digest","recruiting-outreach-builder","lost-customer-winback","account-health-monitor","renewal-risk-digest","weekly-founder-digest","fundraising-target-builder","board-meeting-prep","partner-pipeline-builder","investor-update-builder"]},529294:a=>{a.exports=require("next/dist/server/app-render/work-async-storage.external.js")},561766:(a,b,c)=>{c.d(b,{A6:()=>u,Bp:()=>C,C0:()=>x,DB:()=>D,F1:()=>v,Pv:()=>s,UU:()=>y,Wx:()=>w,kd:()=>l,ki:()=>t,rB:()=>z,s6:()=>A,wc:()=>E});var d=c(973024),e=c(176760),f=c(693349),g=c(499496);let h="onboarding.json",i="connections.json",j="sync-cursors.json",k="email-body-hydration-attempted.json",l=["welcome","identity","dench-cloud","connect-gmail","connect-calendar","backfill","skill-template","complete"];function m(){return new Date().toISOString()}function n(){let a=m();return{version:1,currentStep:"welcome",completedSteps:[],startedAt:a,updatedAt:a}}function o(a,b){return(0,e.join)((0,f.lA)(b),a)}function p(a,b){try{if(!(0,d.existsSync)(a))return b;let c=JSON.parse((0,d.readFileSync)(a,"utf-8"));if(c&&"object"==typeof c)return c;return b}catch{return b}}function q(a,b){var c;c=(0,e.join)(a,".."),(0,d.existsSync)(c)||(0,d.mkdirSync)(c,{recursive:!0});let f=`${a}.tmp-${process.pid}-${Date.now()}`;try{(0,d.writeFileSync)(f,JSON.stringify(b,null,2)+"\n","utf-8"),(0,d.renameSync)(f,a)}catch(a){try{(0,d.existsSync)(f)&&(0,d.unlinkSync)(f)}catch{}throw a}}function r(a){return"string"==typeof a&&l.includes(a)}function s(a){let b=p(o(h,a),null);if(!b)return n();if(!b||"object"!=typeof b)return n();let c=n(),d=Array.isArray(b.completedSteps)?b.completedSteps.filter(r):[];return{version:1,currentStep:r(b.currentStep)?b.currentStep:"welcome",completedSteps:d,identity:b.identity&&"object"==typeof b.identity?b.identity:void 0,denchCloud:b.denchCloud&&"object"==typeof b.denchCloud?b.denchCloud:void 0,connections:b.connections&&"object"==typeof b.connections?b.connections:void 0,backfill:b.backfill&&"object"==typeof b.backfill?b.backfill:void 0,skillTemplate:function(a){var b;if(!a||"object"!=typeof a)return;let c={};return"string"==typeof(b=a.templateId)&&g.Cq.includes(b)&&(c.templateId=a.templateId),"string"==typeof a.selectedAt&&(c.selectedAt=a.selectedAt),"string"==typeof a.promptConsumedAt&&(c.promptConsumedAt=a.promptConsumedAt),Object.keys(c).length>0?c:void 0}(b.skillTemplate),startedAt:"string"==typeof b.startedAt?b.startedAt:c.startedAt,updatedAt:"string"==typeof b.updatedAt?b.updatedAt:c.updatedAt}}function t(a,b){let c={...a,version:1,updatedAt:m()};return q(o(h,b),c),c}function u(a,b,c={},d){let e=s(d),f=new Set(e.completedSteps);return f.add(a),t({...e,...c,completedSteps:Array.from(f),currentStep:b},d)}function v(a){return"complete"===s(a).currentStep}function w(a){return p(o(i,a),{version:1,updatedAt:m()})}function x(a,b,c){let d={...w(c),version:1,[a]:b,updatedAt:m()};return q(o(i,c),d),d}function y(a,b){let c={...w(b),version:1,updatedAt:m()};return delete c[a],q(o(i,b),c),c}function z(a){return p(o(j,a),{version:1,updatedAt:m()})}function A(a,b){let c=z(b),d={...c,...a,gmail:a.gmail?{...c.gmail,...a.gmail}:c.gmail,calendar:a.calendar?{...c.calendar,...a.calendar}:c.calendar,version:1,updatedAt:m()};return q(o(j,b),d),d}function B(a){if(!Array.isArray(a))return[];let b=new Set;for(let c of a)"string"==typeof c&&c.trim()&&b.add(c.trim().toLowerCase());return Array.from(b)}function C(a){let b=p(o("personal-domains.json",a),null);return b&&"object"==typeof b?{version:1,add:B(b.add),remove:B(b.remove),updatedAt:"string"==typeof b.updatedAt?b.updatedAt:m()}:{version:1,add:[],remove:[],updatedAt:m()}}function D(a){let b=p(o(k,a),null);if(!b||"object"!=typeof b)return new Set;let c=b.attempted;return Array.isArray(c)?new Set(c.filter(a=>"string"==typeof a&&!!a)):new Set}function E(a,b){let c=D(b);for(let b of a)"string"==typeof b&&b&&c.add(b);let d={version:1,attempted:Array.from(c).sort(),updatedAt:m()};return q(o(k,b),d),d}},663033:a=>{a.exports=require("next/dist/server/app-render/work-unit-async-storage.external.js")},710846:a=>{a.exports=require("next/dist/compiled/next-server/app-page.runtime.prod.js")},719771:a=>{a.exports=require("process")},731421:a=>{a.exports=require("node:child_process")},744870:a=>{a.exports=require("next/dist/compiled/next-server/app-route.runtime.prod.js")},823446:(a,b,c)=>{c.d(b,{Kr:()=>d.Kr,O0:()=>i,eF:()=>o,s$:()=>j});var d=c(600420);function e(a){return Array.isArray(a)?a.filter(a=>"string"==typeof a&&a.trim().length>0):[]}function f(a){return"string"==typeof a&&a.trim()?a.trim():void 0}function g(...a){for(let b of a){let a=f(b);if(a)return a}}function h(a){var b;let c=(b=a.meta)&&"object"==typeof b&&!Array.isArray(b)?b:void 0,h=g(a.slug,a.name)??"unknown",i=(0,d.Kr)(h),j="number"==typeof c?.tools_count?c.tools_count:void 0,k="number"==typeof a.tools_count?a.tools_count:"number"==typeof a.toolsCount?a.toolsCount:j??0,l=e(a.categories),m=e(c?.categories),n=l.length>0?l:m;return{slug:i,connect_slug:h,name:(0,d.Cr)(g(a.name,a.slug),h),description:g(a.description,a.description_short,a.summary,f(c?.description))??"",logo:g(a.logo,a.logo_url,a.icon,a.image,f(c?.logo))??null,categories:n,auth_schemes:e(a.auth_schemes??a.authSchemes),tools_count:k}}function i(a){let b=(a.items??[]).map(h),c=a.categories?.length?a.categories:Array.from(new Set(b.flatMap(a=>a.categories)));return{items:b,categories:c,cursor:a.cursor??a.next_cursor??a.nextCursor??null,total:"number"==typeof a.total?a.total:"number"==typeof a.total_items?a.total_items:b.length}}function j(a){return(a.connections?.length?a.connections:a.items??[]).map(k)}function k(a){let b=g(a.id,a.connectionId)??"unknown-connection",c=g(a.toolkit_slug,a.toolkit?.slug)??"unknown",e=(0,d.Kr)(c),f=g(a.toolkit_name,a.toolkit?.name,c),h=g(a.account_label,a.account?.label),i=g(a.account_name,a.account?.label,h),j=g(a.account_email,a.account?.email),k=g(a.external_account_id,a.account?.rawIds?.externalAccountId,a.account?.rawIds?.providerAccountId),l=g(a.account_stable_id,a.account?.stableId);return{id:b,toolkit_slug:e,toolkit_name:(0,d.Cr)(f,c),status:g(a.status)??"UNKNOWN",created_at:g(a.created_at,a.createdAt)??"",updated_at:g(a.updated_at,a.updatedAt)??null,account_label:h??null,account_name:i??null,account_email:j??null,external_account_id:k??null,account_stable_id:l??null,toolkit:{slug:e,name:(0,d.Cr)(g(a.toolkit?.name,f),c)},account:a.account?{...a.account,stableId:l??null,confidence:a.account.confidence??void 0,label:h??null,email:j??null}:void 0,reconnect:a.reconnect?{claim:a.reconnect.claim??"unknown",confidence:a.reconnect.confidence??"unknown",relatedConnectionIds:a.reconnect.relatedConnectionIds??[]}:void 0}}function l(a){var b;let c="string"==typeof(b=a.status)&&b.trim()?b.trim().toUpperCase():"UNKNOWN",e=function(a){let b=g(a.account_stable_id,a.account?.stableId);if(b)return{value:b,source:"gateway_stable_id",confidence:a.account?.confidence??"high"};let c=[a.external_account_id,a.account_email,a.account_name,a.account_label].find(a=>"string"==typeof a&&a.trim());return c?{value:`${(0,d.Kr)(a.toolkit_slug)}:${c.trim().toLowerCase()}`,source:"legacy_heuristic",confidence:a.external_account_id?"high":"low"}:{value:`${(0,d.Kr)(a.toolkit_slug)}:${a.id}`,source:"connection_id",confidence:"unknown"}}(a),f=a.reconnect?.claim??"unknown",h=a.reconnect?.confidence??"unknown",i=a.reconnect?.relatedConnectionIds??[];return{...a,normalized_toolkit_slug:(0,d.Kr)(a.toolkit_slug),normalized_status:c,is_active:"ACTIVE"===c,account_identity:e.value,account_identity_source:e.source,identity_confidence:e.confidence,display_label:function(a){let b=[a.account_label,a.account_name,a.account_email].find(a=>"string"==typeof a&&a.trim());return b||`Connection ${a.id.slice(-6)}`}(a),reconnect_claim:f,reconnect_confidence:h,related_connection_ids:i,is_same_account_reconnect:"same"===f&&"high"===h}}function m(a){let b=Date.parse(a.created_at);return Number.isFinite(b)?b:0}function n(a,b){if(a.is_active!==b.is_active)return a.is_active?-1:1;let c=m(b)-m(a);return 0!==c?c:a.display_label.localeCompare(b.display_label)}function o(a){return a.map(l).sort(n)}},837311:(a,b,c)=>{function d(a){let b=e(a,"x-forwarded-host");if(b){let c=e(a,"x-forwarded-proto");return`${"https"===c?"https":"http"}://${b}`}let c=process.env.DENCHCLAW_PUBLIC_URL?.trim();if(c)try{return new URL(c).origin}catch{}return new URL(a.url).origin}function e(a,b){let c=a.headers.get(b);if(!c)return null;let d=c.split(",")[0]?.trim();return d&&d.length>0?d:null}c.d(b,{F:()=>d})},848161:a=>{a.exports=require("node:os")},864490:(a,b,c)=>{c.d(b,{C8:()=>i,U4:()=>j,i3:()=>l,wo:()=>k});let d=new Map,e=new Map,f=new Map;function g(a,b,c=""){return`${a}::${b}${c?`::${c}`:""}`}async function h(a,b,c,d){let e=Date.now(),f=a.get(b);if(f&&f.expiresAt>e)return"value"in f?f.value:f.promise;let g=d();a.set(b,{expiresAt:e+c,promise:g});try{let d=await g;return a.set(b,{expiresAt:Date.now()+c,value:d}),d}catch(c){throw a.delete(b),c}}function i(){d.clear(),f.clear()}async function j(a,b,c){return await h(d,g(a,b,"connections"),6e4,c)}async function k(a,b,c){return await h(e,g(a,b,"toolkits-bulk:100"),3e5,c)}async function l(a,b,c,d){return await h(f,g(a,b,`resolved-toolkits:${[...c].toSorted().join(",")}`),6e4,d)}},973024:a=>{a.exports=require("node:fs")},979428:a=>{a.exports=require("buffer")},986439:a=>{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,27488,43775],()=>b(b.s=322440));module.exports=c})();