var x=Object.defineProperty,N=Object.defineProperties;var G=Object.getOwnPropertyDescriptors;var h=Object.getOwnPropertySymbols;var O=Object.prototype.hasOwnProperty,T=Object.prototype.propertyIsEnumerable;var S=(s,t,n)=>t in s?x(s,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):s[t]=n,f=(s,t)=>{for(var n in t||(t={}))O.call(t,n)&&S(s,n,t[n]);if(h)for(var n of h(t))T.call(t,n)&&S(s,n,t[n]);return s},y=(s,t)=>N(s,G(t));var d=(s,t,n)=>new Promise((r,a)=>{var m=c=>{try{o(n.next(c))}catch(i){a(i)}},e=c=>{try{o(n.throw(c))}catch(i){a(i)}},o=c=>c.done?r(c.value):Promise.resolve(c.value).then(m,e);o((n=n.apply(s,t)).next())});var b=n=>d(void 0,[n],function*({exec:s,query:t}){let{stdout:r}=yield s({command:"fig",args:["_","request","--route","/graphql","--method","--body",JSON.stringify({query:t})]});return JSON.parse(r).data}),w={script:["fig","settings","autocomplete.disableForCommands"],postProcess:s=>{let t=s.split(`
`).filter(a=>a.length>0);return[{name:"Disable new CLI...",description:`You must pass a valid JSON array of CLI tools contained within single quotes. e.g. '["npm","cd","ls"]'`,icon:"fig://icon?type=box",insertValue:JSON.stringify(t.concat(["{cursor}"]))},{name:"Enable all commands",icon:"fig://icon?type=box",insertValue:"'[]'"}].concat(t.map(a=>({name:`Enable ${a}`,icon:"fig://icon?type=box",insertValue:JSON.stringify(t.filter(m=>m!=a))})))}},$={script:["fig","theme","--list"],postProcess:s=>{let t=[{name:"system",icon:"\u{1F4BB}",priority:51},{name:"light",icon:"fig://template?color=ffffff&badge=\u2600\uFE0F",priority:51},{name:"dark",icon:"fig://template?color=000000&badge=\u{1F319}",priority:51}];return s.split(`
`).map(n=>({name:n.replace(".json",""),icon:"\u{1F3A8}"})).concat(t)}},I={"autocomplete.disableForCommands":w,"autocomplete.theme":$},U={custom:()=>d(void 0,null,function*(){return["figterm","fig_cli","fig_desktop","daemon"].map(s=>({name:s}))})},k=(s,t)=>d(void 0,null,function*(){let{stdout:n}=yield t({command:"fig",args:["_","request","--method","GET","--route","/settings/all"]}),{settings:r,actions:a}=JSON.parse(n),m=a.map(e=>({name:e.identifier.startsWith("autocomplete.")?e.identifier.slice(13):e.identifier,description:e.description,icon:"\u26A1\uFE0F"}));return{name:"settings",subcommands:r.map(({settingName:e,description:o,type:c,options:i,default:p})=>{let u=c==="boolean"?["true","false"]:e.startsWith("autocomplete.keybindings.")?m:i==null?void 0:i.map(g=>({name:g.name||g,description:g.description||""})),l=I[e];return{name:e,description:o,icon:"fig://icon?type=commandkey",args:{name:c,default:p,suggestions:l?[]:u,generators:l}}})}}),J={script:["fig","internal","local-state","all","--format","json"],postProcess:s=>{let t=JSON.parse(s);return Object.keys(t).map(n=>({name:n,description:JSON.stringify(t[n])}))}},L=s=>({cache:{strategy:"stale-while-revalidate"},custom:(t,n)=>d(void 0,null,function*(){let r=s.installed?["plugins","list","--format","json","--installed"]:["plugins","list","--format","json"],{stdout:a}=yield n({command:"fig",args:r});return JSON.parse(a).map(e=>{var o;return{name:e.name,icon:(o=e.icon)!=null&&o.startsWith("https://")?"\u{1F4E6}":e.icon,description:e.description}})})}),A={cache:{strategy:"stale-while-revalidate"},custom:(s,t)=>d(void 0,null,function*(){let n=s.findIndex(m=>m.startsWith("--team"));if(n===-1)return[];let r;return s[n].includes("=")?r=s[n+1].split("=")[1]:r=s[n+1],JSON.parse((yield t({command:"fig",args:["user","tokens","list","--team",r,"--format","json"]})).stdout).map(m=>({name:m.name,description:`Team: ${m.namespace.username}.${m.description?" "+m.description:""}`}))})},q={cache:{strategy:"stale-while-revalidate"},script:["fig","team","--list","--format","json"],postProcess:s=>JSON.parse(s).map(t=>({name:t.name,priority:75}))},j={cache:{strategy:"stale-while-revalidate",ttl:1e3*60},custom:(s,t)=>d(void 0,null,function*(){let n=s.at(-3);return JSON.parse((yield t({command:"fig",args:["team","--format","json",n,"members"]})).stdout).map(a=>({name:a.email,description:`Role: ${a.role}`}))})},V={cache:{strategy:"stale-while-revalidate",ttl:1e3*60},custom:(s,t)=>d(void 0,null,function*(){let n=s.at(-3);return JSON.parse((yield t({command:"fig",args:["team","--format","json",n,"invitations"]})).stdout).map(a=>({name:a.email,description:`Role: ${a.role}`}))})},F=`fragment ScriptFields on Script {
  name
  fields {
    icon
    displayName
    description
    templateVersion
    tags
    parameters {
      type
      name
      displayName
      description
      text {
        placeholder
      }
      checkbox {
        trueValueSubstitution
        falseValueSubstitution
      }
      selector {
        generators {
          named {
            name
          }
          shellScript {
            script
          }
          type
        }
        placeholder
        suggestions
      }
      path {
        extensions
        fileType
      }
    }
    runtime
  }
  relevanceScore
  lastInvokedAt
  lastInvokedAtByUser
  isOwnedByCurrentUser
}`,C=s=>{var n,r,a,m;let t=[{name:["-h","--help"],description:"Show help for the script"}];for(let e of s.fields.parameters){let o={name:`--${e.name}`,description:(n=e==null?void 0:e.description)!=null?n:e==null?void 0:e.type,isRequired:!0};switch(e.type){case"Text":o.args={name:e.name};break;case"Selector":let c=[];(r=e==null?void 0:e.selector)!=null&&r.generators&&(c=(a=e==null?void 0:e.selector)==null?void 0:a.generators.filter(i=>i.type==="ShellScript").map(i=>{var p;return{script:["bash","-c",(p=i==null?void 0:i.shellScript)==null?void 0:p.script],splitOn:`
`}})),o.args={name:e.name,suggestions:(m=e==null?void 0:e.selector)==null?void 0:m.suggestions,generators:c};break;case"Path":o.args={name:e.name,template:"filepaths"};break;case"Checkbox":t.push(y(f({},o),{name:`--no-${e.name}`,exclusiveOn:[`--${e.name}`]})),o.exclusiveOn=[`--no-${e.name}`];break}t.push(o)}return t},_=(s,t)=>d(void 0,null,function*(){let n=`query Scripts {
    currentUser {
      namespace {
        username
        scripts {
          ...ScriptFields
        }
      }
      teamMemberships {
        team {
          namespace {
            username
            scripts {
              ...ScriptFields
            }
          }
        }
      }
    }
  }

  ${F}`,r=yield b({exec:t,query:n}),m=[...r.currentUser.namespace.scripts.map(e=>y(f({},e),{namespace:r.currentUser.namespace.username})),...r.currentUser.teamMemberships.flatMap(e=>e.team.namespace.scripts.map(o=>y(f({},o),{namespace:e.team.namespace.username})))].map(e=>{var p,u,l,g;let o=`${(p=e.fields.displayName)!=null?p:e.name} | @${e.namespace}`,c=[`@${e.namespace}/${e.name}`];e!=null&&e.isOwnedByCurrentUser&&c.push(e.name);let i=C(e);return{displayName:o,icon:(l=(u=e==null?void 0:e.fields)==null?void 0:u.icon)!=null?l:"\u26A1\uFE0F",name:c,insertValue:e!=null&&e.isOwnedByCurrentUser?e.name:c[0],description:(g=e==null?void 0:e.fields)==null?void 0:g.description,options:i}});return{name:"run",subcommands:m,filterStrategy:"fuzzy"}}),P=(s,t)=>d(void 0,null,function*(){let n=`query CommandLineTool {
      currentUser {
        namespace {
          username
          commandlineTools {
            ...CommandlineToolFields
          }
        }
        teamMemberships {
          team {
            namespace {
              username
              commandlineTools {
                ...CommandlineToolFields
              }
            }
          }
        }
      }
    }
    
    fragment CommandlineToolFields on CommandlineTool {
      root {
        ...CLICommandFields
      }
      flattenedCommands {
        ...CLICommandFields
      }
    }
    
    fragment CLICommandFields on ICLICommand {
      uuid
      name
      description
      ... on NestedCommand {
        subcommands {
          uuid
        }
      }
      ... on ScriptCommand {
        script {
          ...ScriptFields
        }
      }
    }
    
    ${F}`,r=yield b({exec:t,query:n}),m=[...r.currentUser.namespace.commandlineTools.map(e=>y(f({},e),{namespace:r.currentUser.namespace.username})),...r.currentUser.teamMemberships.flatMap(e=>e.team.namespace.commandlineTools.map(o=>y(f({},o),{namespace:e.team.namespace.username})))].map(e=>{let o={};for(let i of e.flattenedCommands)o[i.uuid]=i;let c=(i,p)=>{var u;if("subcommands"in i){let l=[];for(let g of i.subcommands)l.push(c(o[g.uuid],p+1));return{name:p===0?`@${e.namespace}/${i.name}`:i.name,description:i.description,subcommands:l,options:[{name:["-h","--help"],description:"Print help information"}]}}else{let l=i.script,g=C(l);return{icon:(u=l==null?void 0:l.fields)==null?void 0:u.icon,name:i.name,description:i.description,options:g}}};return c(e.root,0)});return{name:"cli",subcommands:m}}),E={script:["fig","_","request","--method","GET","--route","/access/hosts/all"],cache:{strategy:"stale-while-revalidate"},postProcess:s=>JSON.parse(s).map(t=>({insertValue:`@${t.namespace}/${t.nickName}`,displayName:`${t.nickName} (@${t.namespace})`,name:`@${t.namespace}/${t.nickName}`,description:t.description}))},M={custom:(s,t)=>d(void 0,null,function*(){let n=s.slice(2).find(a=>!a.startsWith("-"));return n===void 0?[]:JSON.parse((yield t({command:"fig",args:["ssh",n,"--get-identities"]})).stdout).map(a=>({name:a.displayName}))})},B={script:["fig","user","list-accounts"],postProcess:s=>s.startsWith("error: ")?[]:s.trim().split(`
`).map(t=>({name:t,icon:"\u{1F464}"}))},R={};export{I as SETTINGS_GENERATOR,P as commandLineToolSpecGenerator,R as default,V as invitationsGenerators,j as membersGenerators,L as pluginsGenerator,_ as scriptsSpecGenerator,k as settingsSpecGenerator,E as sshHostsGenerator,M as sshIdentityGenerator,J as stateGenerator,U as subsystemsGenerator,q as teamsGenerators,$ as themesGenerator,A as tokensGenerators,B as userGenerator};
