@aventurevc/aventure-cli 0.7.285 → 0.7.286
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/aventure-cli/index.js +1 -1
- package/dist/aventure-cli/unified-operations.json +1 -1
- package/dist/chunks/{auth-C_5zKmxZ.js → auth-LUwvFMFy.js} +1 -1
- package/dist/chunks/{aventure-cli-C-AcIKim.js → aventure-cli-BsHeYD5h.js} +1 -1
- package/dist/chunks/{mcp-generation-contract-DiJSYiVM.js → mcp-generation-contract-D4imd69O.js} +2 -2
- package/dist/chunks/{openapi-commands-Btt1_itn.js → openapi-commands-CAvtd8DN.js} +2 -2
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{C as e,D as t,_ as n,a as r,k as i,v as a,x as o}from"./person-owner-ChqQWHII.js";import{$ as s,A as c,C as l,E as u,H as d,I as f,J as p,K as m,M as h,N as g,O as _,Q as ee,R as te,S as ne,St as v,T as re,X as ie,Y as ae,Z as oe,_ as se,b as ce,c as le,f as ue,g as de,h as fe,i as pe,j as me,k as y,l as b,m as he,n as ge,nt as x,o as _e,p as ve,q as ye,r as be,rt as S,s as xe,t as Se,tt as Ce,u as we,v as Te,w as Ee}from"./auth-C_5zKmxZ.js";import{A as De,C as Oe,D as ke,E as Ae,F as C,I as je,M as Me,N as Ne,O as Pe,P as Fe,S as Ie,T as Le,_ as Re,a as ze,b as Be,c as Ve,d as He,f as Ue,g as We,h as Ge,j as Ke,k as qe,l as Je,m as Ye,n as Xe,o as w,p as Ze,r as T,s as Qe,t as E,u as $e,v as et,w as tt,x as nt,y as rt}from"./openapi-commands-Btt1_itn.js";import{F as it,a as at,f as ot,i as st,l as ct,m as lt,n as ut,ot as dt,p as ft,r as pt,s as mt,st as ht,t as gt}from"./mcp-generation-contract-DiJSYiVM.js";import{execFile as _t,spawnSync as vt}from"node:child_process";import{createHash as yt,randomBytes as bt,timingSafeEqual as xt,webcrypto as St}from"node:crypto";import{readFile as Ct}from"node:fs/promises";import{homedir as wt,hostname as Tt,platform as Et}from"node:os";import{basename as Dt,dirname as D,join as O,resolve as k,sep as Ot}from"node:path";import A,{stderr as j,stdin as kt}from"node:process";import{appendFileSync as At,copyFileSync as jt,existsSync as M,lstatSync as Mt,mkdirSync as Nt,mkdtempSync as Pt,readFileSync as N,readlinkSync as Ft,realpathSync as It,renameSync as Lt,rmSync as Rt,rmdirSync as zt,unlinkSync as Bt,writeFileSync as P}from"node:fs";import{fileURLToPath as Vt}from"node:url";import{once as Ht}from"node:events";import{TextDecoder as Ut,inspect as Wt}from"node:util";import{createServer as Gt}from"node:http";import{setTimeout as Kt}from"node:timers/promises";import{createInterface as qt}from"node:readline/promises";function Jt(e,t,n){let r={...n};for(let n of t.parameter){let t=n.envName;if(t===void 0)continue;let i=process.env[t]?.trim();if(i===void 0||i.length===0)continue;let a=r[n.optionKey];if(a!==void 0&&(typeof a!=`string`||a!==i))return{...x(`${e} ${n.flag.split(` `)[0]??n.name} conflicts with ${t}; omit the flag or use ${i}.`),data:r};a===void 0&&(r[n.optionKey]=i)}return S(`Environment-bound options applied`,r)}function Yt(e,t,n){if(!F(n))return null;for(let r of t.parameter){let t=r.envName,i=t===void 0?void 0:process.env[t]?.trim();if(t===void 0||i===void 0||i.length===0||!un(n,r.name))continue;let a=ln(n,r.name);if(typeof a!=`string`||a!==i)return`${e} ${r.name} in --from-file conflicts with ${t}; omit the field or use ${i}.`}return null}function Xt(e){let t=new Set(e.parameter.map(({name:e})=>e));return e.kind===`multipart`?e.requiredPath:e.requiredPath.filter(e=>!t.has(e))}function Zt(e,t,n,r=!1){if(r||!pn(t)||!Array.isArray(n))return hn(e,t,n);for(let[r,i]of n.entries()){let n=hn(e,t,i,r);if(!n.ok)return n}return S(`Body value assigned`,null)}function Qt(e,t,n,r){return hn(e,t,r,n)}function $t(e){let t=[];for(let n of e.split(`.`)){let e=_n(n);if(t.push(e.key),e.isArray)return t.join(`.`)}return null}function en(e,t){let n=$t(t);if(n===null)return null;let r=cn(e,n.split(`.`));return Array.isArray(r)?{path:n,rowCount:r.length,firstHole:sn(r)}:null}function tn(e,t){if(pn(e.name)||e.schemaType===`array`)return S(`Repeated body option selected`,typeof t==`string`?[t]:t);if(!Array.isArray(t))return S(`Scalar body option selected`,t);let n=e.flag.split(` `)[0]??e.name;return t.length===1?S(`Scalar body option selected`,t[0]):x(`${n} was already given; pass it once.`)}var nn=/^(?<row>\d+):(?<item>.*)$/su;function rn(e,t){let n=$t(e.name);if(e.schemaType!==`array`||n===null||t===void 0||typeof t==`boolean`)return null;let r=new Map,i=[];for(let e of typeof t==`string`?[t]:t){let t=nn.exec(e)?.groups,n=t?.row,a=t?.item;if(n===void 0||a===void 0){i.push(e);continue}let o=r.get(Number(n));o===void 0?r.set(Number(n),[a]):o.push(a)}return r.size===0?null:{container:n,rows:r,plain:i}}function an(e,t,n){let r=0;for(let i of e.parameter){let e=t[i.optionKey];e!==void 0&&typeof e!=`boolean`&&$t(i.name)===n&&(r=Math.max(r,typeof e==`string`?1:e.length))}return r}function on(e,t,n,r){for(let i of t.parameter){let t=n[i.optionKey];if(t===void 0)continue;let a=en(r,i.name);if(a===null)continue;if(a.firstHole!==null)return x(`${e} has no ${a.path}[] row ${a.firstHole} — number ${a.path}[] rows from 0 with no gaps.`);if(i.schemaType!==`array`||a.rowCount<=1||rn(i,t)!==null)continue;let o=i.flag.split(` `)[0]??i.name;return x(`${o} fills one ${a.path}[] row's list, so ${e} cannot also build ${a.rowCount} ${a.path}[] rows from direct options — prefix each value with its 0-based ${a.path}[] row index, as 0:value, or pass the rows with --from-file.`)}return null}function sn(e){for(let t=0;t<e.length;t+=1)if(e[t]===void 0)return t;return null}function cn(e,t){let n=e;for(let e of t){if(!F(n))return;n=n[e]??null}return n}function ln(e,t){if(!pn(t))return cn(e,t.split(`.`))}function un(e,t){return fn(e,t.split(`.`))}function dn(e,t,n){if(!F(n))return null;let r=new Set(t.parameter.map(({name:e})=>e));for(let i of e)if(i!==t){for(let e of i.parameter)if(!r.has(e.name)&&un(n,e.name))return`${e.name} in --from-file requires --content-type ${i.contentType}.`}return null}function fn(e,t){let[n,...r]=t;if(n===void 0)return!0;let i=_n(n);if(!F(e)||!Object.hasOwn(e,i.key))return!1;let a=e[i.key]??null;return i.isArray?Array.isArray(a)&&a.every(e=>fn(e,r)):fn(a,r)}function pn(e){return e.split(`.`).some(e=>_n(e).isArray)}function mn(e,t){return e.parameter.length===0||!F(t)?null:yn(t,[],vn(e.parameter))}function F(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function hn(e,t,n,r=0){let i=t.split(`.`),a=e;for(let[e,o]of i.entries()){let s=_n(o),c=e===i.length-1,l=gn(a,s,t,c,n,r);if(!l.ok||l.data===null)return x(l.summary,l.warnings);if(c)return S(`Body value assigned`,null);a=l.data}return x(`${t} is not a valid body option path.`)}function gn(e,t,n,r,i,a){let o=()=>x(`${n} cannot be combined with another body option at ${t.key}.`),s=e[t.key];if(t.isArray){if(s!==void 0&&!Array.isArray(s))return o();let n=s??[];if(s===void 0&&(e[t.key]=n),r)return n[a]===void 0?(n[a]=i,S(`Body value assigned`,e)):o();let c=n[a];if(c===void 0){let e={};return n[a]=e,S(`Body path created`,e)}return F(c)?S(`Body path stepped`,c):o()}if(r)return s===void 0?(e[t.key]=i,S(`Body value assigned`,e)):o();if(s===void 0){let n={};return e[t.key]=n,S(`Body path created`,n)}return F(s)?S(`Body path stepped`,s):o()}function _n(e){let t=e.endsWith(`[]`);return{key:t?e.slice(0,-2):e,isArray:t}}function vn(e){let t=new Set,n=new Set,r=new Map;for(let i of e){let e=`${i.name}${i.schemaType===`array`?`[]`:``}`;t.add(e),r.set(e,i.flag.split(` `)[0]??i.name);let a=e.split(`.`);for(let e=1;e<a.length;e+=1)n.add(a.slice(0,e).join(`.`))}return{leaf:t,prefix:n,flagByLeaf:r}}function yn(e,t,n){if(Array.isArray(e)){if(e.length===0)return null;for(let r of e){let e=yn(r,t,n);if(e!==null)return e}return null}if(!F(e))return null;for(let[r,i]of Object.entries(e)){let e=[...t,Array.isArray(i)?`${r}[]`:r],a=e.join(`.`);if(!bn(a,n)){if(!xn(e))continue;return{path:a,suggestion:Sn(e,n)}}let o=yn(i,e,n);if(o!==null)return o}return null}function bn(e,t){return t.prefix.has(e)||t.leaf.has(e)}function xn(e){return e.slice(0,-1).some(e=>e.endsWith(`[]`))}function Sn(e,t){let n=e.slice(0,-1).join(`.`),r=e.at(-1)?.replace(/\[\]$/u,``).toLowerCase()??``,[i]=[...t.leaf].filter(e=>e.split(`.`).slice(0,-1).join(`.`)===n).map(e=>({path:e,score:Cn(r,e.split(`.`).at(-1)??``)})).filter(({score:e})=>e<1/0).toSorted((e,t)=>e.score-t.score||e.path.localeCompare(t.path));if(i!==void 0)return{path:i.path,flag:t.flagByLeaf.get(i.path)??i.path}}function Cn(e,t){let n=t.replace(/\[\]$/u,``).toLowerCase();return n===e?0:n.endsWith(e)||e.endsWith(n)?1:n.includes(e)||e.includes(n)?2:1/0}function wn(e,t){let n=new Map;for(let e of t){let t=e.flag?.split(` `)[0];t!==void 0&&n.set(t,t===`--from-file`?{...e,inputType:`file`}:e)}for(let t of e){let e=t.long===void 0?void 0:n.get(t.long);e!==void 0&&t.helpGroup(Ze(e))}e.sort((e,t)=>{let r=e.long===void 0?void 0:n.get(e.long),i=t.long===void 0?void 0:n.get(t.long);return r!==void 0&&i!==void 0?Mn(r,i):r===void 0?i===void 0?0:1:-1})}function Tn(e){let t=new Map;for(let n of e)for(let e of n.parameter){let r=e.flag.split(` `)[0]??e.flag,i=t.get(r);i===void 0?t.set(r,{variant:[{descriptor:n,parameter:e}]}):t.set(r,{variant:[...i.variant,{descriptor:n,parameter:e}]})}return[...t.values()]}function En(e){let{flag:t}=e.variant[0].parameter;return e.variant.every(({parameter:e})=>e.flag===t)?t:`${t.split(` `)[0]??t} <value>`}function Dn(e){let t=e.variant.map(({descriptor:e,parameter:t})=>({contentType:e.contentType,text:An(e,t)})),n=t[0];return n===void 0?``:t.every(({text:e})=>e===n.text)?`${n.text===``?``:`${n.text} `}Request content: ${t.map(({contentType:e})=>e).join(`, `)}.`:t.map(({contentType:e,text:t})=>`${e}: ${t}`).join(` `)}function On(e,t){return[...new Set((e.cliConflicts??[]).filter(e=>e.includes(t)).flatMap(e=>e.filter(e=>e!==t)))]}function kn(e,t){let n=e.kind===`multipart`?`Read a JSON object keyed by multipart part name from a file, or use - for stdin`:`Read the JSON request body from a file, or use - for stdin`,r=t.filter(e=>!t.some(t=>t.startsWith(`${e}.`)||t.startsWith(`${e}[].`)));return r.length===0?Ye(n):`${Ye(n)} Required JSON paths: ${r.join(`, `)}.`}function An(e,t){return`${He(t.description,void 0)}${e.kind!==`multipart`&&pn(t.name)?` Repeat to add another value.`:``}${jn(e,t)}`}function jn(e,t){if(e.kind===`multipart`||t.schemaType!==`array`)return``;let n=$t(t.name);return n===null?``:` Prefix each value with its 0-based ${n}[] row index, as 0:value, to fill more than one ${n}[] row. A leading digits-and-colon is always read as that index, so name the row of a value that starts the same way, as 0:0:00 for the value 0:00.`}function Mn(e,t){return Ue(e)-Ue(t)||Number(e.required!==!0)-Number(t.required!==!0)}async function Nn(e){let t;try{t=e===`-`?await Pn():await Ct(e,`utf8`)}catch(t){return x(`Could not read input: ${t.message}`,[`path=${e}`])}try{if(t.trim().length===0)return S(`No input provided`,null);let e=JSON.parse(t);return S(`Input parsed`,e)}catch(e){return x(`Input is not valid JSON: ${e.message}`)}}async function Pn(){if(process.stdin.isTTY)throw Error(`--from-file - requires JSON on stdin, but stdin is a TTY`);process.stdin.setEncoding(`utf8`);let e=``;for await(let t of process.stdin)e+=t;return e}var Fn=`--content-type`;function In(e,t){let n=t.requestBody??[];if(n.length>1){let t=n.map(({contentType:e})=>e);e.addOption(new u(`${Fn} <media-type>`,`Select the request content type; omit for ${t[0]}.`).choices(t).argParser(Rn(n)))}if(rr(t)){let r=n[0];if(r===void 0)throw Error(`${t.operationId} has no request body`);e.addOption(new u(`--from-file <path>`,kn(r,r.requiredPath)).argParser(Bn(`--from-file`)))}let r=Tn(n);for(let t of r.toSorted((e,t)=>Mn(e.variant[0].parameter,t.variant[0].parameter))){let{descriptor:r,parameter:i}=t.variant[0],a=new u(En(t),n.length>1?Dn(t):An(r,i));n.length===1&&i.envName!==void 0&&a.env(i.envName);let o=n.length===1?On(r,i.optionKey):[];o.length>0&&a.conflicts(o),n.length>1?a.argParser(Ln):pn(i.name)||i.schemaType===`array`?a.argParser(zn):a.argParser(Bn(i.flag)),e.addOption(a)}nr(e,t,r)}function Ln(e,t){return t===void 0?e:typeof t==`string`?[t,e]:[...t,e]}function Rn(e){return(t,n)=>{if(n!==void 0)throw new _(`${Fn} was already given; pass it once.`);let r=Ee(e,t);if(!r.ok)throw new _(r.summary);return t}}function zn(e,t){return[...t??[],e]}function Bn(e){let t=e.split(/\s+/u)[0]??e;return(e,n)=>{if(n!==void 0)throw new _(`${t} was already given; pass it once.`);return e}}async function Vn(e,t){let n=typeof t.contentType==`string`?t.contentType:void 0,r=Ee(e.requestBody??[],n);if(!r.ok||r.data===null)return x(r.summary,r.warnings);let i=r.data;if(i===void 0)return S(`No body`,void 0);let a=Hn(e,i,t);if(a!==null)return x(a);let o=Jt(e.operationId,i,t);if(!o.ok)return x(o.summary,o.warnings);t=o.data;let s=Un(i,t);if(s!==null)return x(s);let c=await qn(t);if(!c.ok)return x(c.summary,c.warnings);let l=dn(e.requestBody??[],i,c.data);if(l!==null)return x(l);let u=Kn(e.operationId,i,c.data);if(!u.ok)return u;let d=Yt(e.operationId,i,c.data);if(d!==null)return x(d);let f=Jn(e.operationId,i,t);if(!f.ok)return f;if(c.data===void 0&&f.data===void 0)return i.required?x(tr(e.operationId,i)):S(`No body`,void 0);let p=Xn(e.operationId,c.data,f.data);if(!p.ok||p.data===void 0)return p;if(i.schemaType===`array`&&!Array.isArray(p.data))return x(`${e.operationId} requires a JSON array body.`);if(i.parameter.length>0&&!F(p.data)){let t=i.kind===`multipart`?` keyed by multipart part name`:` body`;return x(`${e.operationId} requires a JSON object${t}.`)}let m=Gn(i,p.data);if(m.length>0)return x(`${e.operationId} requires body option(s): ${m.join(`, `)}`);let h=p.data,g=F(h)?Xt(i).filter(e=>!un(h,e)):[];return g.length>0?x(Wn(e.operationId,i,g)):p}function Hn(e,t,n){let r=new Set(t.parameter.map(({optionKey:e})=>e));for(let i of e.requestBody??[])if(i!==t)for(let t of i.parameter){if(r.has(t.optionKey)||n[t.optionKey]===void 0)continue;let i=(e.requestBody??[]).filter(e=>e.parameter.some(({optionKey:e})=>e===t.optionKey)).map(({contentType:e})=>e);return`${I(t)} requires ${Fn} ${i.join(` or `)}.`}return null}function Un(e,t){for(let n of e.cliConflicts??[]){let e=n.filter(e=>t[e]!==void 0);if(e.length>1)return`Options ${e.join(`, `)} cannot be used together.`}return null}function Wn(e,t,n){let r=`${e} requires JSON body path(s): ${n.join(`, `)}`;return t.kind===`multipart`?`${r}. ${n.includes(`body`)?`For multipart --from-file, wrap the endpoint JSON under top-level "body".`:`For multipart --from-file, put the missing nested path(s) inside top-level "body".`}`:r}function Gn(e,t){return F(t)?e.parameter.filter(e=>e.required&&!un(t,e.name)).map(I):[]}function Kn(e,t,n){let r=mn(t,n);if(r===null)return S(`Body file paths validated`,null);let i=r.suggestion===void 0?``:` Use ${r.suggestion.path} (${r.suggestion.flag}).`;return x(`${e} --from-file contains unknown JSON path ${r.path}.${i}`)}async function qn(e){let t=typeof e.fromFile==`string`?e.fromFile:void 0;if(t===void 0)return S(`No body file`,void 0);let n=await Nn(t);if(!n.ok)return x(n.summary,n.warnings);let r=v.safeParse(n.data);return r.success?S(`Input parsed`,r.data):x(`Input is not valid JSON value: ${r.error.message}`)}function Jn(e,t,n){let r={},i=!1;for(let e of t.parameter){let a=tn(e,n[e.optionKey]);if(!a.ok||a.data===null)return x(a.summary,a.warnings);let o=a.data;if(o===void 0)continue;let s=Yn(t,n,r,e,o);if(!s.ok)return x(s.summary,s.warnings);i=!0}if(!i)return S(`No direct body options`,void 0);let a=on(e,t,n,r);return a===null?S(`Direct body options parsed`,r):a}function Yn(e,t,n,r,i){let a=rn(r,i);if(a===null){let e=$n(r,i);return e.ok?Zt(n,r.name,e.data,r.schemaType===`array`):x(e.summary,e.warnings)}if(a.plain.length>0)return x(`${I(r)} mixes row-form values with plain value(s): ${a.plain.join(`, `)} — prefix every value with its 0-based ${a.container}[] row index, as 0:value.`);let o=an(e,t,a.container);for(let e of a.rows.keys())if(!(e<o))return x(`${I(r)} names ${a.container}[] row ${e}, but these options build at most ${o} ${a.container}[] row(s) — number rows from 0, and name the row of a value that itself starts with digits and a colon, as 0:0:00 for the value 0:00.`);for(let[e,t]of a.rows){let i=[];for(let e of t){let t=er(r.name,r.itemSchemaType,e);if(!t.ok)return x(t.summary,t.warnings);i.push(t.data)}let a=Qt(n,r.name,e,i);if(!a.ok)return a}return S(`Body value assigned`,null)}function I(e){return e.flag.split(` `)[0]??e.name}function Xn(e,t,n){if(t===void 0)return S(`Direct body parsed`,n);if(n===void 0)return S(`Input parsed`,t);if(F(t)&&F(n))try{return S(`Input parsed`,Zn(t,n))}catch(t){return x(`${e} ${t.message}`)}return x(`${e} cannot combine --from-file with direct body options unless the file body is an object.`)}function Zn(e,t){let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];if(Array.isArray(t)&&Array.isArray(r))throw Error(`cannot combine --from-file array '${e}' with array body options at the same key — move the per-item fields inside the matching '${e}[]' object(s) in the file body.`);if(t!==void 0&&Qn(t)!==Qn(r))throw Error(`cannot combine --from-file ${Qn(t)} '${e}' with ${Qn(r)} body option(s) at the same key — align the file body shape with the schema.`);n[e]=F(t)&&F(r)?Zn(t,r):r}return n}function Qn(e){return Array.isArray(e)?`array`:F(e)?`object`:`scalar`}function $n(e,t){if(typeof t==`boolean`)return S(`Body value parsed`,t);if(t===void 0||typeof t==`string`)return er(e.name,e.schemaType,t??``);let n=[],r=pn(e.name)&&e.schemaType!==`array`?e.schemaType:e.itemSchemaType;for(let i of t){let t=er(e.name,r,i);if(!t.ok)return t;n.push(t.data)}return S(`Body value parsed`,n)}function er(e,t,n){if(t===`boolean`)return n===`true`?S(`Body value parsed`,!0):n===`false`?S(`Body value parsed`,!1):x(`${e} must be true or false.`);if(t===`number`||t===`integer`){let r=n.trim(),i=Number(r);return r===``||!Number.isFinite(i)?x(`${e} must be a finite ${t}.`):t===`integer`&&!Number.isInteger(i)?x(`${e} must be an integer.`):S(`Body value parsed`,i)}return S(`Body value parsed`,n)}function tr(e,t){let n=t.parameter.filter(e=>e.required);if(n.length>0&&t.requiredPath.every(e=>n.some(({name:t})=>t===e||t.startsWith(`${e}.`))))return`${e} requires body option(s): ${n.map(I).join(`, `)}`;let r=Xt(t);if(r.length>0)return`${e} requires --from-file with JSON body path(s): ${r.join(`, `)}`;let i=t.parameter.map(I).join(`, `);return i.length===0?`${e} requires --from-file`:`${e} requires --from-file or body option(s): ${i}`}function nr(e,t,n){let r=[...t.parameters,...n.map(({variant:e})=>e[0].parameter)];(t.requestBody?.length??0)>1&&r.push({optionKey:`contentType`,flag:Fn,location:`body`}),rr(t)&&r.push({optionKey:`fromFile`,flag:`--from-file`,location:`body`}),wn(e.options,r)}function rr(e){return(e.requestBody??[]).some(e=>e.kind!==`multipart`||e.parameter.some(e=>e.schemaFormat!==`binary`))}function ir(e){let t=Ce(e);return dr(t),process.stdout.write(`${JSON.stringify(t)}\n`),t}function ar(e){dr(e);let t=ut(e.data,e.summary);if(e.ok&&t!==null){process.stdout.write(t.endsWith(`
|
|
1
|
+
import{C as e,D as t,_ as n,a as r,k as i,v as a,x as o}from"./person-owner-ChqQWHII.js";import{$ as s,A as c,C as l,E as u,H as d,I as f,J as p,K as m,M as h,N as g,O as _,Q as ee,R as te,S as ne,St as v,T as re,X as ie,Y as ae,Z as oe,_ as se,b as ce,c as le,f as ue,g as de,h as fe,i as pe,j as me,k as y,l as b,m as he,n as ge,nt as x,o as _e,p as ve,q as ye,r as be,rt as S,s as xe,t as Se,tt as Ce,u as we,v as Te,w as Ee}from"./auth-LUwvFMFy.js";import{A as De,C as Oe,D as ke,E as Ae,F as C,I as je,M as Me,N as Ne,O as Pe,P as Fe,S as Ie,T as Le,_ as Re,a as ze,b as Be,c as Ve,d as He,f as Ue,g as We,h as Ge,j as Ke,k as qe,l as Je,m as Ye,n as Xe,o as w,p as Ze,r as T,s as Qe,t as E,u as $e,v as et,w as tt,x as nt,y as rt}from"./openapi-commands-CAvtd8DN.js";import{F as it,a as at,f as ot,i as st,l as ct,m as lt,n as ut,ot as dt,p as ft,r as pt,s as mt,st as ht,t as gt}from"./mcp-generation-contract-D4imd69O.js";import{execFile as _t,spawnSync as vt}from"node:child_process";import{createHash as yt,randomBytes as bt,timingSafeEqual as xt,webcrypto as St}from"node:crypto";import{readFile as Ct}from"node:fs/promises";import{homedir as wt,hostname as Tt,platform as Et}from"node:os";import{basename as Dt,dirname as D,join as O,resolve as k,sep as Ot}from"node:path";import A,{stderr as j,stdin as kt}from"node:process";import{appendFileSync as At,copyFileSync as jt,existsSync as M,lstatSync as Mt,mkdirSync as Nt,mkdtempSync as Pt,readFileSync as N,readlinkSync as Ft,realpathSync as It,renameSync as Lt,rmSync as Rt,rmdirSync as zt,unlinkSync as Bt,writeFileSync as P}from"node:fs";import{fileURLToPath as Vt}from"node:url";import{once as Ht}from"node:events";import{TextDecoder as Ut,inspect as Wt}from"node:util";import{createServer as Gt}from"node:http";import{setTimeout as Kt}from"node:timers/promises";import{createInterface as qt}from"node:readline/promises";function Jt(e,t,n){let r={...n};for(let n of t.parameter){let t=n.envName;if(t===void 0)continue;let i=process.env[t]?.trim();if(i===void 0||i.length===0)continue;let a=r[n.optionKey];if(a!==void 0&&(typeof a!=`string`||a!==i))return{...x(`${e} ${n.flag.split(` `)[0]??n.name} conflicts with ${t}; omit the flag or use ${i}.`),data:r};a===void 0&&(r[n.optionKey]=i)}return S(`Environment-bound options applied`,r)}function Yt(e,t,n){if(!F(n))return null;for(let r of t.parameter){let t=r.envName,i=t===void 0?void 0:process.env[t]?.trim();if(t===void 0||i===void 0||i.length===0||!un(n,r.name))continue;let a=ln(n,r.name);if(typeof a!=`string`||a!==i)return`${e} ${r.name} in --from-file conflicts with ${t}; omit the field or use ${i}.`}return null}function Xt(e){let t=new Set(e.parameter.map(({name:e})=>e));return e.kind===`multipart`?e.requiredPath:e.requiredPath.filter(e=>!t.has(e))}function Zt(e,t,n,r=!1){if(r||!pn(t)||!Array.isArray(n))return hn(e,t,n);for(let[r,i]of n.entries()){let n=hn(e,t,i,r);if(!n.ok)return n}return S(`Body value assigned`,null)}function Qt(e,t,n,r){return hn(e,t,r,n)}function $t(e){let t=[];for(let n of e.split(`.`)){let e=_n(n);if(t.push(e.key),e.isArray)return t.join(`.`)}return null}function en(e,t){let n=$t(t);if(n===null)return null;let r=cn(e,n.split(`.`));return Array.isArray(r)?{path:n,rowCount:r.length,firstHole:sn(r)}:null}function tn(e,t){if(pn(e.name)||e.schemaType===`array`)return S(`Repeated body option selected`,typeof t==`string`?[t]:t);if(!Array.isArray(t))return S(`Scalar body option selected`,t);let n=e.flag.split(` `)[0]??e.name;return t.length===1?S(`Scalar body option selected`,t[0]):x(`${n} was already given; pass it once.`)}var nn=/^(?<row>\d+):(?<item>.*)$/su;function rn(e,t){let n=$t(e.name);if(e.schemaType!==`array`||n===null||t===void 0||typeof t==`boolean`)return null;let r=new Map,i=[];for(let e of typeof t==`string`?[t]:t){let t=nn.exec(e)?.groups,n=t?.row,a=t?.item;if(n===void 0||a===void 0){i.push(e);continue}let o=r.get(Number(n));o===void 0?r.set(Number(n),[a]):o.push(a)}return r.size===0?null:{container:n,rows:r,plain:i}}function an(e,t,n){let r=0;for(let i of e.parameter){let e=t[i.optionKey];e!==void 0&&typeof e!=`boolean`&&$t(i.name)===n&&(r=Math.max(r,typeof e==`string`?1:e.length))}return r}function on(e,t,n,r){for(let i of t.parameter){let t=n[i.optionKey];if(t===void 0)continue;let a=en(r,i.name);if(a===null)continue;if(a.firstHole!==null)return x(`${e} has no ${a.path}[] row ${a.firstHole} — number ${a.path}[] rows from 0 with no gaps.`);if(i.schemaType!==`array`||a.rowCount<=1||rn(i,t)!==null)continue;let o=i.flag.split(` `)[0]??i.name;return x(`${o} fills one ${a.path}[] row's list, so ${e} cannot also build ${a.rowCount} ${a.path}[] rows from direct options — prefix each value with its 0-based ${a.path}[] row index, as 0:value, or pass the rows with --from-file.`)}return null}function sn(e){for(let t=0;t<e.length;t+=1)if(e[t]===void 0)return t;return null}function cn(e,t){let n=e;for(let e of t){if(!F(n))return;n=n[e]??null}return n}function ln(e,t){if(!pn(t))return cn(e,t.split(`.`))}function un(e,t){return fn(e,t.split(`.`))}function dn(e,t,n){if(!F(n))return null;let r=new Set(t.parameter.map(({name:e})=>e));for(let i of e)if(i!==t){for(let e of i.parameter)if(!r.has(e.name)&&un(n,e.name))return`${e.name} in --from-file requires --content-type ${i.contentType}.`}return null}function fn(e,t){let[n,...r]=t;if(n===void 0)return!0;let i=_n(n);if(!F(e)||!Object.hasOwn(e,i.key))return!1;let a=e[i.key]??null;return i.isArray?Array.isArray(a)&&a.every(e=>fn(e,r)):fn(a,r)}function pn(e){return e.split(`.`).some(e=>_n(e).isArray)}function mn(e,t){return e.parameter.length===0||!F(t)?null:yn(t,[],vn(e.parameter))}function F(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function hn(e,t,n,r=0){let i=t.split(`.`),a=e;for(let[e,o]of i.entries()){let s=_n(o),c=e===i.length-1,l=gn(a,s,t,c,n,r);if(!l.ok||l.data===null)return x(l.summary,l.warnings);if(c)return S(`Body value assigned`,null);a=l.data}return x(`${t} is not a valid body option path.`)}function gn(e,t,n,r,i,a){let o=()=>x(`${n} cannot be combined with another body option at ${t.key}.`),s=e[t.key];if(t.isArray){if(s!==void 0&&!Array.isArray(s))return o();let n=s??[];if(s===void 0&&(e[t.key]=n),r)return n[a]===void 0?(n[a]=i,S(`Body value assigned`,e)):o();let c=n[a];if(c===void 0){let e={};return n[a]=e,S(`Body path created`,e)}return F(c)?S(`Body path stepped`,c):o()}if(r)return s===void 0?(e[t.key]=i,S(`Body value assigned`,e)):o();if(s===void 0){let n={};return e[t.key]=n,S(`Body path created`,n)}return F(s)?S(`Body path stepped`,s):o()}function _n(e){let t=e.endsWith(`[]`);return{key:t?e.slice(0,-2):e,isArray:t}}function vn(e){let t=new Set,n=new Set,r=new Map;for(let i of e){let e=`${i.name}${i.schemaType===`array`?`[]`:``}`;t.add(e),r.set(e,i.flag.split(` `)[0]??i.name);let a=e.split(`.`);for(let e=1;e<a.length;e+=1)n.add(a.slice(0,e).join(`.`))}return{leaf:t,prefix:n,flagByLeaf:r}}function yn(e,t,n){if(Array.isArray(e)){if(e.length===0)return null;for(let r of e){let e=yn(r,t,n);if(e!==null)return e}return null}if(!F(e))return null;for(let[r,i]of Object.entries(e)){let e=[...t,Array.isArray(i)?`${r}[]`:r],a=e.join(`.`);if(!bn(a,n)){if(!xn(e))continue;return{path:a,suggestion:Sn(e,n)}}let o=yn(i,e,n);if(o!==null)return o}return null}function bn(e,t){return t.prefix.has(e)||t.leaf.has(e)}function xn(e){return e.slice(0,-1).some(e=>e.endsWith(`[]`))}function Sn(e,t){let n=e.slice(0,-1).join(`.`),r=e.at(-1)?.replace(/\[\]$/u,``).toLowerCase()??``,[i]=[...t.leaf].filter(e=>e.split(`.`).slice(0,-1).join(`.`)===n).map(e=>({path:e,score:Cn(r,e.split(`.`).at(-1)??``)})).filter(({score:e})=>e<1/0).toSorted((e,t)=>e.score-t.score||e.path.localeCompare(t.path));if(i!==void 0)return{path:i.path,flag:t.flagByLeaf.get(i.path)??i.path}}function Cn(e,t){let n=t.replace(/\[\]$/u,``).toLowerCase();return n===e?0:n.endsWith(e)||e.endsWith(n)?1:n.includes(e)||e.includes(n)?2:1/0}function wn(e,t){let n=new Map;for(let e of t){let t=e.flag?.split(` `)[0];t!==void 0&&n.set(t,t===`--from-file`?{...e,inputType:`file`}:e)}for(let t of e){let e=t.long===void 0?void 0:n.get(t.long);e!==void 0&&t.helpGroup(Ze(e))}e.sort((e,t)=>{let r=e.long===void 0?void 0:n.get(e.long),i=t.long===void 0?void 0:n.get(t.long);return r!==void 0&&i!==void 0?Mn(r,i):r===void 0?i===void 0?0:1:-1})}function Tn(e){let t=new Map;for(let n of e)for(let e of n.parameter){let r=e.flag.split(` `)[0]??e.flag,i=t.get(r);i===void 0?t.set(r,{variant:[{descriptor:n,parameter:e}]}):t.set(r,{variant:[...i.variant,{descriptor:n,parameter:e}]})}return[...t.values()]}function En(e){let{flag:t}=e.variant[0].parameter;return e.variant.every(({parameter:e})=>e.flag===t)?t:`${t.split(` `)[0]??t} <value>`}function Dn(e){let t=e.variant.map(({descriptor:e,parameter:t})=>({contentType:e.contentType,text:An(e,t)})),n=t[0];return n===void 0?``:t.every(({text:e})=>e===n.text)?`${n.text===``?``:`${n.text} `}Request content: ${t.map(({contentType:e})=>e).join(`, `)}.`:t.map(({contentType:e,text:t})=>`${e}: ${t}`).join(` `)}function On(e,t){return[...new Set((e.cliConflicts??[]).filter(e=>e.includes(t)).flatMap(e=>e.filter(e=>e!==t)))]}function kn(e,t){let n=e.kind===`multipart`?`Read a JSON object keyed by multipart part name from a file, or use - for stdin`:`Read the JSON request body from a file, or use - for stdin`,r=t.filter(e=>!t.some(t=>t.startsWith(`${e}.`)||t.startsWith(`${e}[].`)));return r.length===0?Ye(n):`${Ye(n)} Required JSON paths: ${r.join(`, `)}.`}function An(e,t){return`${He(t.description,void 0)}${e.kind!==`multipart`&&pn(t.name)?` Repeat to add another value.`:``}${jn(e,t)}`}function jn(e,t){if(e.kind===`multipart`||t.schemaType!==`array`)return``;let n=$t(t.name);return n===null?``:` Prefix each value with its 0-based ${n}[] row index, as 0:value, to fill more than one ${n}[] row. A leading digits-and-colon is always read as that index, so name the row of a value that starts the same way, as 0:0:00 for the value 0:00.`}function Mn(e,t){return Ue(e)-Ue(t)||Number(e.required!==!0)-Number(t.required!==!0)}async function Nn(e){let t;try{t=e===`-`?await Pn():await Ct(e,`utf8`)}catch(t){return x(`Could not read input: ${t.message}`,[`path=${e}`])}try{if(t.trim().length===0)return S(`No input provided`,null);let e=JSON.parse(t);return S(`Input parsed`,e)}catch(e){return x(`Input is not valid JSON: ${e.message}`)}}async function Pn(){if(process.stdin.isTTY)throw Error(`--from-file - requires JSON on stdin, but stdin is a TTY`);process.stdin.setEncoding(`utf8`);let e=``;for await(let t of process.stdin)e+=t;return e}var Fn=`--content-type`;function In(e,t){let n=t.requestBody??[];if(n.length>1){let t=n.map(({contentType:e})=>e);e.addOption(new u(`${Fn} <media-type>`,`Select the request content type; omit for ${t[0]}.`).choices(t).argParser(Rn(n)))}if(rr(t)){let r=n[0];if(r===void 0)throw Error(`${t.operationId} has no request body`);e.addOption(new u(`--from-file <path>`,kn(r,r.requiredPath)).argParser(Bn(`--from-file`)))}let r=Tn(n);for(let t of r.toSorted((e,t)=>Mn(e.variant[0].parameter,t.variant[0].parameter))){let{descriptor:r,parameter:i}=t.variant[0],a=new u(En(t),n.length>1?Dn(t):An(r,i));n.length===1&&i.envName!==void 0&&a.env(i.envName);let o=n.length===1?On(r,i.optionKey):[];o.length>0&&a.conflicts(o),n.length>1?a.argParser(Ln):pn(i.name)||i.schemaType===`array`?a.argParser(zn):a.argParser(Bn(i.flag)),e.addOption(a)}nr(e,t,r)}function Ln(e,t){return t===void 0?e:typeof t==`string`?[t,e]:[...t,e]}function Rn(e){return(t,n)=>{if(n!==void 0)throw new _(`${Fn} was already given; pass it once.`);let r=Ee(e,t);if(!r.ok)throw new _(r.summary);return t}}function zn(e,t){return[...t??[],e]}function Bn(e){let t=e.split(/\s+/u)[0]??e;return(e,n)=>{if(n!==void 0)throw new _(`${t} was already given; pass it once.`);return e}}async function Vn(e,t){let n=typeof t.contentType==`string`?t.contentType:void 0,r=Ee(e.requestBody??[],n);if(!r.ok||r.data===null)return x(r.summary,r.warnings);let i=r.data;if(i===void 0)return S(`No body`,void 0);let a=Hn(e,i,t);if(a!==null)return x(a);let o=Jt(e.operationId,i,t);if(!o.ok)return x(o.summary,o.warnings);t=o.data;let s=Un(i,t);if(s!==null)return x(s);let c=await qn(t);if(!c.ok)return x(c.summary,c.warnings);let l=dn(e.requestBody??[],i,c.data);if(l!==null)return x(l);let u=Kn(e.operationId,i,c.data);if(!u.ok)return u;let d=Yt(e.operationId,i,c.data);if(d!==null)return x(d);let f=Jn(e.operationId,i,t);if(!f.ok)return f;if(c.data===void 0&&f.data===void 0)return i.required?x(tr(e.operationId,i)):S(`No body`,void 0);let p=Xn(e.operationId,c.data,f.data);if(!p.ok||p.data===void 0)return p;if(i.schemaType===`array`&&!Array.isArray(p.data))return x(`${e.operationId} requires a JSON array body.`);if(i.parameter.length>0&&!F(p.data)){let t=i.kind===`multipart`?` keyed by multipart part name`:` body`;return x(`${e.operationId} requires a JSON object${t}.`)}let m=Gn(i,p.data);if(m.length>0)return x(`${e.operationId} requires body option(s): ${m.join(`, `)}`);let h=p.data,g=F(h)?Xt(i).filter(e=>!un(h,e)):[];return g.length>0?x(Wn(e.operationId,i,g)):p}function Hn(e,t,n){let r=new Set(t.parameter.map(({optionKey:e})=>e));for(let i of e.requestBody??[])if(i!==t)for(let t of i.parameter){if(r.has(t.optionKey)||n[t.optionKey]===void 0)continue;let i=(e.requestBody??[]).filter(e=>e.parameter.some(({optionKey:e})=>e===t.optionKey)).map(({contentType:e})=>e);return`${I(t)} requires ${Fn} ${i.join(` or `)}.`}return null}function Un(e,t){for(let n of e.cliConflicts??[]){let e=n.filter(e=>t[e]!==void 0);if(e.length>1)return`Options ${e.join(`, `)} cannot be used together.`}return null}function Wn(e,t,n){let r=`${e} requires JSON body path(s): ${n.join(`, `)}`;return t.kind===`multipart`?`${r}. ${n.includes(`body`)?`For multipart --from-file, wrap the endpoint JSON under top-level "body".`:`For multipart --from-file, put the missing nested path(s) inside top-level "body".`}`:r}function Gn(e,t){return F(t)?e.parameter.filter(e=>e.required&&!un(t,e.name)).map(I):[]}function Kn(e,t,n){let r=mn(t,n);if(r===null)return S(`Body file paths validated`,null);let i=r.suggestion===void 0?``:` Use ${r.suggestion.path} (${r.suggestion.flag}).`;return x(`${e} --from-file contains unknown JSON path ${r.path}.${i}`)}async function qn(e){let t=typeof e.fromFile==`string`?e.fromFile:void 0;if(t===void 0)return S(`No body file`,void 0);let n=await Nn(t);if(!n.ok)return x(n.summary,n.warnings);let r=v.safeParse(n.data);return r.success?S(`Input parsed`,r.data):x(`Input is not valid JSON value: ${r.error.message}`)}function Jn(e,t,n){let r={},i=!1;for(let e of t.parameter){let a=tn(e,n[e.optionKey]);if(!a.ok||a.data===null)return x(a.summary,a.warnings);let o=a.data;if(o===void 0)continue;let s=Yn(t,n,r,e,o);if(!s.ok)return x(s.summary,s.warnings);i=!0}if(!i)return S(`No direct body options`,void 0);let a=on(e,t,n,r);return a===null?S(`Direct body options parsed`,r):a}function Yn(e,t,n,r,i){let a=rn(r,i);if(a===null){let e=$n(r,i);return e.ok?Zt(n,r.name,e.data,r.schemaType===`array`):x(e.summary,e.warnings)}if(a.plain.length>0)return x(`${I(r)} mixes row-form values with plain value(s): ${a.plain.join(`, `)} — prefix every value with its 0-based ${a.container}[] row index, as 0:value.`);let o=an(e,t,a.container);for(let e of a.rows.keys())if(!(e<o))return x(`${I(r)} names ${a.container}[] row ${e}, but these options build at most ${o} ${a.container}[] row(s) — number rows from 0, and name the row of a value that itself starts with digits and a colon, as 0:0:00 for the value 0:00.`);for(let[e,t]of a.rows){let i=[];for(let e of t){let t=er(r.name,r.itemSchemaType,e);if(!t.ok)return x(t.summary,t.warnings);i.push(t.data)}let a=Qt(n,r.name,e,i);if(!a.ok)return a}return S(`Body value assigned`,null)}function I(e){return e.flag.split(` `)[0]??e.name}function Xn(e,t,n){if(t===void 0)return S(`Direct body parsed`,n);if(n===void 0)return S(`Input parsed`,t);if(F(t)&&F(n))try{return S(`Input parsed`,Zn(t,n))}catch(t){return x(`${e} ${t.message}`)}return x(`${e} cannot combine --from-file with direct body options unless the file body is an object.`)}function Zn(e,t){let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];if(Array.isArray(t)&&Array.isArray(r))throw Error(`cannot combine --from-file array '${e}' with array body options at the same key — move the per-item fields inside the matching '${e}[]' object(s) in the file body.`);if(t!==void 0&&Qn(t)!==Qn(r))throw Error(`cannot combine --from-file ${Qn(t)} '${e}' with ${Qn(r)} body option(s) at the same key — align the file body shape with the schema.`);n[e]=F(t)&&F(r)?Zn(t,r):r}return n}function Qn(e){return Array.isArray(e)?`array`:F(e)?`object`:`scalar`}function $n(e,t){if(typeof t==`boolean`)return S(`Body value parsed`,t);if(t===void 0||typeof t==`string`)return er(e.name,e.schemaType,t??``);let n=[],r=pn(e.name)&&e.schemaType!==`array`?e.schemaType:e.itemSchemaType;for(let i of t){let t=er(e.name,r,i);if(!t.ok)return t;n.push(t.data)}return S(`Body value parsed`,n)}function er(e,t,n){if(t===`boolean`)return n===`true`?S(`Body value parsed`,!0):n===`false`?S(`Body value parsed`,!1):x(`${e} must be true or false.`);if(t===`number`||t===`integer`){let r=n.trim(),i=Number(r);return r===``||!Number.isFinite(i)?x(`${e} must be a finite ${t}.`):t===`integer`&&!Number.isInteger(i)?x(`${e} must be an integer.`):S(`Body value parsed`,i)}return S(`Body value parsed`,n)}function tr(e,t){let n=t.parameter.filter(e=>e.required);if(n.length>0&&t.requiredPath.every(e=>n.some(({name:t})=>t===e||t.startsWith(`${e}.`))))return`${e} requires body option(s): ${n.map(I).join(`, `)}`;let r=Xt(t);if(r.length>0)return`${e} requires --from-file with JSON body path(s): ${r.join(`, `)}`;let i=t.parameter.map(I).join(`, `);return i.length===0?`${e} requires --from-file`:`${e} requires --from-file or body option(s): ${i}`}function nr(e,t,n){let r=[...t.parameters,...n.map(({variant:e})=>e[0].parameter)];(t.requestBody?.length??0)>1&&r.push({optionKey:`contentType`,flag:Fn,location:`body`}),rr(t)&&r.push({optionKey:`fromFile`,flag:`--from-file`,location:`body`}),wn(e.options,r)}function rr(e){return(e.requestBody??[]).some(e=>e.kind!==`multipart`||e.parameter.some(e=>e.schemaFormat!==`binary`))}function ir(e){let t=Ce(e);return dr(t),process.stdout.write(`${JSON.stringify(t)}\n`),t}function ar(e){dr(e);let t=ut(e.data,e.summary);if(e.ok&&t!==null){process.stdout.write(t.endsWith(`
|
|
2
2
|
`)?t:`${t}\n`),or(e);return}let n=e.ok?`OK`:`FAIL`;process.stdout.write(`[${n}] ${e.summary}\n`),!e.ok&&e.problem!==void 0&&cr(e.problem),or(e)}function or(e){e.ids.length>0&&process.stdout.write(` ids: ${e.ids.join(`, `)}\n`);for(let[t,n]of Object.entries(e.counts))process.stdout.write(` ${t}: ${n}\n`);for(let t of e.references)process.stdout.write(` ref: ${t}\n`);if(e.truncation!==void 0){let t=e.truncation.omitted.join(`, `);process.stdout.write(` truncated: byteLength=${e.truncation.byteLength} maxBytes=${e.truncation.maxBytes} omitted=${t}\n`),process.stdout.write(` recovery: ${e.truncation.recovery}\n`)}for(let t of e.warnings)process.stdout.write(` warn: ${t}\n`)}function L(e,t){if(e.mode===`data`||e.mode===`data-full`){let n=e.mode===`data`?Ce(t):t;dr(n),process.stdout.write(`${JSON.stringify(n.ok&&n.truncated!==!0?sr(n.data):n)}\n`),n.ok||(process.exitCode=1);return}let n=e.mode===`json`?ir(t):t;e.mode===`text`&&ar(n),n.ok||(process.exitCode=1)}function sr(e){return typeof e!=`object`||!e||Array.isArray(e)||!Reflect.has(e,`method`)||!Reflect.has(e,`endpoint`)||!(`response`in e)||e.response===void 0?e:e.response}function cr(e){typeof e.code==`string`&&process.stdout.write(` code: ${e.code}\n`),typeof e.detail==`string`&&process.stdout.write(` detail: ${e.detail}\n`),typeof e.hint==`string`&&process.stdout.write(` hint: ${e.hint}\n`),typeof e.suggestion==`string`&&process.stdout.write(` suggestion: ${e.suggestion}\n`);let t=Object.entries(e.suggestions??{});if(t.length>0){let e=t.map(([e,t])=>`${e}=${t}`).join(`; `);process.stdout.write(` suggestions: ${e}\n`)}lr(`unknownParameters`,e.unknownParameters),lr(`validParameters`,e.validParameters),ur(e.resolution)}function lr(e,t){t!=null&&t.length>0&&process.stdout.write(` ${e}: ${t.join(`, `)}\n`)}function ur(e){if(e==null)return;let t=[`action=${e.action}`];typeof e.parameter==`string`&&t.push(`parameter=${e.parameter}`),typeof e.fieldPath==`string`&&t.push(`fieldPath=${e.fieldPath}`),typeof e.endpoint==`string`&&t.push(`endpoint=${e.endpoint}`),e.acceptedValue!==null&&e.acceptedValue!==void 0&&e.acceptedValue.length>0&&t.push(`acceptedValue=${e.acceptedValue.join(`, `)}`),typeof e.retryable==`boolean`&&t.push(`retryable=${e.retryable}`),process.stdout.write(` resolution: ${t.join(` `)}\n`)}function dr(e){e.ok&&e.warnings.length===0||te({component:`aventure-cli`,event:e.ok?`command_warning`:`command_failed`,message:e.warnings.length>0?e.warnings.join(` | `):e.summary,fields:{warningCount:e.warnings.length,summary:e.summary}})}function fr(e,t,n=m().bin[0]){let r=t.length,i=mt(e.q?.trim()??``),a=at(i),o=ct(i),s=hr(t,n).filter(t=>yr(t,e)).map(e=>({operation:e,score:xr(i,a,o,e)})).filter(({score:e})=>i===``||e>0).toSorted((e,t)=>t.score-e.score||e.operation.cli.command.localeCompare(t.operation.cli.command)||e.operation.operationId.localeCompare(t.operation.operationId)).map(({operation:e})=>e),c=Er(e.limit,s.length),l=s.slice(0,c);return S(`Operation catalog matches`,{operation:l,count:{totalOperations:r,matched:s.length,returned:l.length}})}function pr(e,t,n=m().bin[0]){let r=hr(t,n),i=e.operationId===void 0?mr(r,e.command):r.find(t=>t.operationId===e.operationId);return i===void 0?x(`Generated operation not found`,[`List candidates with \`${n} command-catalog search "<text>"\`.`]):S(`Generated operation detail`,{operation:i,usage:Dr(i)})}function mr(e,t){if(t===void 0)return;let n=Ir(t);return e.find(e=>Ir(e.cli.command)===n||e.cli.alias!==null&&Ir(e.cli.alias)===n)}function hr(e,t){return e.map(e=>{let n=e.requestBody??[],r=[...e.parameters.map(e=>gr(e)),...n.flatMap(e=>e.parameter.map(t=>gr(t,n.length>1?e.contentType:void 0))),..._r(n)],i=`${t} ${e.cliPath.join(` `)}`,a=e.cliAliasPath===void 0?null:`${t} ${e.cliAliasPath.join(` `)}`,o=ne(e.intent),s=e.method===`DELETE`||e.intent===`delete`,c=n[0];return{operationId:e.operationId,method:e.method,path:e.path,resource:e.resource,intent:e.intent,scope:e.scope,mutates:o,destructive:s,auth:e.auth,cli:{command:i,path:e.cliPath,alias:a,aliasPath:e.cliAliasPath??null},mcpTool:e.binaryResponse?null:l(e.intent),body:{hasBody:c!==void 0,kind:c?.kind??null,...c!==void 0&&n.length>1?{contentType:c.contentType}:{},required:c?.required??!1,description:c?.description??``,requiredPath:c?.requiredPath??[]},flags:r,errorResponse:e.errorResponse,summary:e.summary,description:e.description}})}function gr(e,t){let n=e.flag.split(/\s+/u);return{name:n[0]??e.flag,optionKey:e.optionKey,wireName:e.name,location:e.location,required:e.required,placeholder:n.length<=1?null:n.slice(1).join(` `),description:e.description,choices:e.choices??[],...t===void 0?{}:{contentType:t}}}function _r(e){if((e?.length??0)<=1)return[];let t=e?.map(({contentType:e})=>e)??[];return[{name:`--content-type`,optionKey:`contentType`,wireName:`Content-Type`,location:`body`,required:!1,placeholder:`<media-type>`,description:`Select the request content type; omit for ${t[0]}.`,choices:t}]}function vr(e){return e.flags.filter(({contentType:t})=>t===void 0||t===e.body.contentType)}function yr(e,t){return!(t.root!==void 0&&!br(e,t.root)||t.scope!==void 0&&t.scope!==`all`&&t.scope!==e.scope||t.mutates!==void 0&&t.mutates!==`any`&&t.mutates===`true`!==e.mutates||t.destructive!==void 0&&t.destructive!==`any`&&t.destructive===`true`!==e.destructive||t.intent!==void 0&&t.intent!==`all`&&t.intent!==e.intent||t.method!==void 0&&t.method!==`all`&&t.method!==e.method)}function br(e,t){let n=mt(t);return n.length===0||mt(e.cli.path.at(0)??``)===n||mt(e.cli.aliasPath?.at(0)??``)===n}function xr(e,t,n,r){if(e.length===0)return 1;let i=Cr(r),a=Sr(e,t,i,{exactQuery:120,partialQuery:60,exactToken:18,partialToken:6})+Sr(e,t,wr(r),{exactQuery:12,partialQuery:6,exactToken:2,partialToken:1});st(n,i)&&(a+=200);for(let e of r.cli.path){let n=new Set;pt(n,e),[...n].some(e=>t.has(e))&&(a+=15)}return mt(r.cli.command).endsWith(e)&&(a+=40),a}function Sr(e,t,n,r){let i=0;n.includes(e)&&(i+=r.exactQuery),n.some(t=>t.includes(e))&&(i+=r.partialQuery);for(let e of t)n.includes(e)?i+=r.exactToken:n.some(t=>t.includes(e))&&(i+=r.partialToken);return i}function Cr(e){return Tr([e.operationId,e.cli.command,e.cli.alias??``,e.summary])}function wr(e){return Tr([e.method,e.path,e.resource,e.intent,e.scope,e.mutates?`mutates mutation write`:`read only no mutation`,e.destructive?`destructive delete`:`non destructive`,e.mcpTool??``,e.body.kind??``,e.body.description,e.body.requiredPath.join(` `),e.description,...e.flags.flatMap(e=>[e.name,e.optionKey,e.wireName,e.description,e.choices.join(` `)])])}function Tr(e){return e.map(mt).filter(e=>e.length>0)}function Er(e,t){if(e===void 0)return t;let n=Number(e);return Number.isFinite(n)?Math.max(0,Math.trunc(n)):t}function Dr(e){let t=vr(e),n=t.filter(e=>e.required),r=t.filter(e=>!e.required);return[`cli: ${e.cli.command}`,e.cli.alias===null?``:`alias: ${e.cli.alias}`,`${e.method} ${e.path}`,`operationId: ${e.operationId}`,`resource: ${e.resource}`,`intent: ${e.intent}`,`scope: ${e.scope}`,`mutates: ${e.mutates}`,`destructive: ${e.destructive}`,`mcpTool: ${e.mcpTool??`unavailable (binary CLI operation)`}`,e.body.hasBody?`body: kind=${e.body.kind??`unknown`} required=${e.body.required} requiredPath=${e.body.requiredPath.join(`,`)}`:`body: none`,R(`required path flags`,n,`path`),R(`required query flags`,n,`query`),R(`required header flags`,n,`header`),R(`required body flags`,n,`body`),R(`optional path flags`,r,`path`),R(`optional query flags`,r,`query`),R(`optional header flags`,r,`header`),R(`optional body flags`,r,`body`),...Mr(e),...Or(e.errorResponse),``,e.summary,e.description].filter(e=>e.length>0).join(`
|
|
3
3
|
`)}function Or(e){return e.length===0?[]:[`Errors:`,...e.map(({status:e,description:t})=>` ${e} ${t}`)]}var kr=[`-id`,`-slug`,`-url`],Ar=[`--id`,`--slug`,`--url`],jr=`--from-file "<path>"`;function Mr(e){return[`example: ${[e.cli.command,...Nr(e),`--data`].join(` `)}`]}function Nr(e){let t=vr(e).filter(e=>e.required),n=(t.length>0?t:Pr(e)).map(Fr);return(e.body.required||e.body.requiredPath.length>0)&&!t.some(e=>e.location===`body`)?[...n,jr]:n}function Pr(e){let t=new Set;pt(t,e.resource);for(let n of kr)for(let r of t){let t=e.flags.find(e=>e.name===`--${r}${n}`);if(t!==void 0)return[t]}for(let t of Ar){let n=e.flags.find(e=>e.name===t);if(n!==void 0)return[n]}return[]}function Fr(e){return e.placeholder===null?e.name:`${e.name} "${e.placeholder}"`}function R(e,t,n){let r=t.filter(e=>e.location===n);return`${e}: ${r.length===0?`none`:r.map(e=>e.name).join(` `)}`}function Ir(e){return e.trim().replace(/^aventure(?:-cli)?\s+/u,``).replaceAll(/\s+/gu,` `)}function Lr(e,t,n=m().bin[0]){e.helpCommand(!1);let r=e.commands.find(e=>e.name()===`help`)??e.command(`help`);r.summary(`Show command help, or ask the platform a grounded question`).description([`Show local --help output for a command path (deterministic, offline),`,`or answer a natural-language platform question with --ask via the grounded`,"help operation (the same generated operation as `help ask`)."].join(`
|
|
4
4
|
`)).argument(`[command...]`,"command path to show help for, e.g. `help search entities`"),r.addOption(new Rr(r));let i=Br(t);i!==void 0&&r.option(`--ask <question>`,i.summary),T(r),r.action(async function(t){let r=this.optsWithGlobals();if(r.help&&t.length===0){this.outputHelp();return}if(!r.help&&i!==void 0&&r.ask!==void 0){let e=w(r);if(t.length>0){L({mode:e},x(`Use either a command path or --ask, not both.`));return}L({mode:e},await Hr(i,r.ask,r.environment,e));return}let a=Vr(e,t);a===void 0&&this.error(`unknown command '${t.join(` `)}' (run \`${n} --help\` for the command tree)`),a.outputHelp()}),zr(e,t)}var Rr=class extends u{helpCommand;constructor(e){super(`-h, --help`,`display help for command`),this.helpCommand=e}is(e){if(e!==this.short&&e!==this.long)return!1;let t=this.helpCommand.parent?.args??[],n=t.findIndex(e=>e===this.helpCommand.name()||this.helpCommand.aliases().includes(e)),r=n<0?void 0:t[n+1];return r===void 0||r.startsWith(`-`)?!0:!this.helpCommand.commands.some(e=>e.name()===r||e.aliases().includes(r))}};function zr(e,t){let n=new Set;for(let r of t){let t=Or(r.errorResponse);if(t.length!==0)for(let i of[r.cliPath,r.cliAliasPath]){let r=i===void 0?void 0:Vr(e,i);r===void 0||n.has(r)||(n.add(r),r.addHelpText(`after`,`\n${t.join(`
|