"use strict";exports.id=9484,exports.ids=[9484],exports.modules={3421:(a,b,c)=>{Object.defineProperty(b,"I",{enumerable:!0,get:function(){return g}});let d=c(71237),e=c(55088),f=c(17679);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()}}},27424:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{A3:()=>n,XA:()=>k,ZJ:()=>o,bS:()=>m,e4:()=>l,yb:()=>j});var e=c(34255),f=c(24516),g=a([e,f]);function h(a,b){if(!a)return b;try{let c=JSON.parse(a);return null==c?b:c}catch{return b}}function i(a,b){let c=h(a.manifest_json,{}),d=h(a.tags,[]),e=h(b?.settings_json,{})||{};return{id:a.id,kind:"connection",slug:a.slug,title:a.title,description:a.description||"",category:a.category||null,author:a.author||"madarx",source:{kind:a.source_kind,url:a.source_url||null},version:a.version||null,risk_summary:a.risk_summary||null,tags:Array.isArray(d)?d:[],installed:!!b?.installed,manifest:c,settings:e,last_verified_at:e.last_verified_at||null,account_label:e.account_label||null}}function j(){return(0,e.getDb)().prepare(`
    SELECT i.*, m.installed, m.installed_at, m.settings_json
      FROM marketplace_items i
 LEFT JOIN marketplace_installations m ON m.item_id = i.id
     WHERE i.kind = 'connection'
     ORDER BY i.title ASC
  `).all().map(a=>i(a,{installed:a.installed,installed_at:a.installed_at,settings_json:a.settings_json}))}function k(a){if(!a)return null;let b=(0,e.getDb)().prepare(`
    SELECT i.*, m.installed, m.installed_at, m.settings_json
      FROM marketplace_items i
 LEFT JOIN marketplace_installations m ON m.item_id = i.id
     WHERE i.kind = 'connection' AND i.slug = ?
     LIMIT 1
  `).get(String(a));return b?i(b,{installed:b.installed,installed_at:b.installed_at,settings_json:b.settings_json}):null}function l(a,b={}){let c=k(a);if(!c)throw Error(`Unknown connection: ${a}`);let d=(0,e.getDb)(),f=(0,e.nowIso)(),g=c.settings||{},h={...g,last_verified_at:f,account_label:b.account_label||g.account_label||null,last_4:b.last_4||g.last_4||null,summary:{...g.summary||{},...b.summary||{}}},i=JSON.stringify(h);return d.prepare("SELECT item_id FROM marketplace_installations WHERE item_id = ?").get(c.id)?d.prepare(`
      UPDATE marketplace_installations
         SET installed = 1, installed_at = ?, settings_json = ?
       WHERE item_id = ?
    `).run(f,i,c.id):d.prepare(`
      INSERT INTO marketplace_installations (item_id, installed, installed_at, settings_json)
      VALUES (?, 1, ?, ?)
    `).run(c.id,f,i),p("connection.verified",{service_key:a,account_label:h.account_label,last_4:h.last_4},`Connection verified: ${a}`),k(a)}function m(a){let b=k(a);if(!b)throw Error(`Unknown connection: ${a}`);let c=(0,e.getDb)();return(0,e.nowIso)(),c.prepare("SELECT item_id FROM marketplace_installations WHERE item_id = ?").get(b.id)&&c.prepare(`
      UPDATE marketplace_installations
         SET installed = 0, installed_at = NULL, settings_json = NULL
       WHERE item_id = ?
    `).run(b.id),p("connection.disconnected",{service_key:a},`Connection disconnected: ${a}`),k(a)}function n(a){if(!a?.manifest?.credentials?.length)return!0;for(let b of a.manifest.credentials)if(b.required&&!(0,f.getSecret)(b.name))return!1;return!0}function o(a){return a?.manifest?.credentials?.length?a.manifest.credentials.map(a=>a.name).filter(Boolean):[]}function p(a,b,c){try{(0,e.getDb)().prepare(`
      INSERT INTO audit_logs (id, at, type, summary, status, meta)
      VALUES (?, ?, ?, ?, ?, ?)
    `).run((0,e.newId)("audit"),(0,e.nowIso)(),a,c,"ok",JSON.stringify(b||{}))}catch{}}[e,f]=g.then?(await g)():g,d()}catch(a){d(a)}})},41368:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{ND:()=>i,X_:()=>k,nu:()=>m,pO:()=>l,s7:()=>h});var e=c(34255),f=a([e]);function g(a){return a?{id:a.id,service_key:a.service_key,scope:a.scope,project_id:a.project_id||null,agent_id:a.agent_id||null,account_label:a.account_label||null,last_4:a.last_4||null,summary:function(a,b){if(!a)return null;try{let b=JSON.parse(a);return null==b?null:b}catch{return b}}(a.summary_json,null),verified_at:a.verified_at,created_at:a.created_at}:null}function h(a={}){let b=String(a.scope||"").trim().toLowerCase();if(a.agent_id)return{scope:"agent",project_id:null,agent_id:String(a.agent_id)};if(a.project_id)return{scope:"project",project_id:String(a.project_id),agent_id:null};if("project"===b||"agent"===b)throw Error(`scope '${b}' requires ${"project"===b?"project_id":"agent_id"}`);return{scope:"global",project_id:null,agent_id:null}}function i(a){return a?(0,e.getDb)().prepare(`
    SELECT * FROM connection_instances
     WHERE service_key = ?
     ORDER BY
       CASE scope WHEN 'global' THEN 0 WHEN 'project' THEN 1 WHEN 'agent' THEN 2 ELSE 3 END,
       account_label ASC
  `).all(String(a)).map(g):[]}function j(a,b={}){if(!a)return null;let{scope:c,project_id:d,agent_id:f}=h(b),i=(0,e.getDb)().prepare(`
    SELECT * FROM connection_instances
     WHERE service_key = ? AND scope = ?
       AND COALESCE(project_id, '') = COALESCE(?, '')
       AND COALESCE(agent_id, '')   = COALESCE(?, '')
     LIMIT 1
  `).get(String(a),c,d,f);return g(i)}function k(a,b={},c={}){if(!a)throw Error("service_key is required");let{scope:d,project_id:f,agent_id:g}=h(b),i=(0,e.getDb)(),l=(0,e.nowIso)(),m=c.summary?JSON.stringify(c.summary):null,n=i.prepare(`
    SELECT id FROM connection_instances
     WHERE service_key = ? AND scope = ?
       AND COALESCE(project_id, '') = COALESCE(?, '')
       AND COALESCE(agent_id, '')   = COALESCE(?, '')
     LIMIT 1
  `).get(String(a),d,f,g);return n?i.prepare(`
      UPDATE connection_instances
         SET account_label = ?, last_4 = ?, summary_json = ?, verified_at = ?
       WHERE id = ?
    `).run(c.account_label||null,c.last_4||null,m,l,n.id):i.prepare(`
    INSERT INTO connection_instances
      (id, service_key, scope, project_id, agent_id, account_label, last_4, summary_json, verified_at, created_at)
    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
  `).run((0,e.newId)("conn"),String(a),d,f,g,c.account_label||null,c.last_4||null,m,l,l),j(a,{scope:d,project_id:f,agent_id:g})}function l(a,b={}){if(!a)throw Error("service_key is required");let{scope:c,project_id:d,agent_id:f}=h(b);return{deleted:(0,e.getDb)().prepare(`
    DELETE FROM connection_instances
     WHERE service_key = ? AND scope = ?
       AND COALESCE(project_id, '') = COALESCE(?, '')
       AND COALESCE(agent_id, '')   = COALESCE(?, '')
  `).run(String(a),c,d,f).changes}}function m(a,b=null){if(!a)return[];let c=[String(a)],d="SELECT * FROM connection_instances WHERE agent_id = ?";return b&&(d+=" OR (scope = 'project' AND project_id = ?)",c.push(String(b))),d+=" ORDER BY service_key ASC",(0,e.getDb)().prepare(d).all(...c).map(g)}e=(f.then?(await f)():f)[0],d()}catch(a){d(a)}})},95736:(a,b,c)=>{a.exports=c(44870)},97684:(a,b,c)=>{c.a(a,async(a,d)=>{try{c.d(b,{J:()=>h,u:()=>g});var e=c(27424),f=a([e]);function g(a){return a&&a.installed?(0,e.A3)(a)?{status:"connected",label:"Connected",tone:"ready",footer:function(a){let b=[];return a.account_label&&b.push(a.account_label),a.settings?.last_4&&b.push(`••• ${a.settings.last_4}`),a.last_verified_at&&b.push(`verified ${function(a){try{let b=new Date(a).getTime(),c=Date.now(),d=Math.max(0,c-b),e=Math.round(d/6e4);if(e<1)return"just now";if(e<60)return`${e}m ago`;let f=Math.round(e/60);if(f<24)return`${f}h ago`;let g=Math.round(f/24);return`${g}d ago`}catch{return""}}(a.last_verified_at)}`),b.length?b.join(" \xb7 "):null}(a)}:{status:"reconnect",label:"Reconnect",tone:"warn",footer:"A required credential was revoked."}:{status:"needs_setup",label:"Not connected",tone:"danger",footer:null}}function h(a){if("string"!=typeof a)return null;let b=a.trim();return b.length<8?null:b.slice(-4)}e=(f.then?(await f)():f)[0],d()}catch(a){d(a)}})}};