@hiperplano/aluy-cli 1.0.0-rc.40 → 1.0.0-rc.41
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-bundle/bin/aluy.js +41 -41
- package/dist-bundle/index.js +3 -3
- package/package.json +1 -1
package/dist-bundle/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var LN=Object.defineProperty;var S=(t,e,o)=>()=>{if(o)throw o[0];try{return t&&(e=t(t=0)),e}catch(n){throw o=[n],n}};var Wf=(t,e)=>{for(var o in e)LN(t,o,{get:e[o],enumerable:!0})};var ca,Tx=S(()=>{"use strict";ca="1.0.0-rc.
|
|
1
|
+
var LN=Object.defineProperty;var S=(t,e,o)=>()=>{if(o)throw o[0];try{return t&&(e=t(t=0)),e}catch(n){throw o=[n],n}};var Wf=(t,e)=>{for(var o in e)LN(t,o,{get:e[o],enumerable:!0})};var ca,Tx=S(()=>{"use strict";ca="1.0.0-rc.41"});function Pn(t,e){return t.decide(e)}var qr=S(()=>{"use strict"});var en,Nn,In=S(()=>{"use strict";en="remember",Nn="recall"});var Gf,PN,Ws,zf=S(()=>{"use strict";Gf=class{id;horizon;label;parentId;children;dependencies;pinned;closed;createdAt;lastAccessedAt;accessCount;context;constructor(e,o,n,r,s){this.id=e,this.horizon=o,this.label=n,this.parentId=r,this.children=new Set,this.dependencies=new Set,this.pinned=!1,this.closed=!1,this.createdAt=s,this.lastAccessedAt=s,this.accessCount=0,this.context=[]}touch(e){this.lastAccessedAt=e,this.accessCount+=1}snapshot(){return{id:this.id,horizon:this.horizon,label:this.label,parentId:this.parentId,children:[...this.children],dependencies:[...this.dependencies],pinned:this.pinned,closed:this.closed,createdAt:this.createdAt,lastAccessedAt:this.lastAccessedAt,accessCount:this.accessCount,contextSize:this.context.length}}},PN=200,Ws=class{nodes=new Map;maxBoxes;now;constructor(e){this.maxBoxes=e?.maxBoxes??PN,this.now=e?.clock??Date.now}static boxId(e,o){return`${e.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,60)}-${o.toString(36)}`}openBox(e,o,n,r){let s=this.nodes.get(e);if(s)return s.touch(this.now()),{box:s.snapshot(),created:!1};if(this.nodes.size>=this.maxBoxes&&(this.evictOne(),this.nodes.size>=this.maxBoxes))return null;let i=this.now(),a=new Gf(e,o,n,r??null,i);if(r){let c=this.nodes.get(r);c&&c.children.add(e)}return this.nodes.set(e,a),{box:a.snapshot(),created:!0}}closeBox(e){let o=this.nodes.get(e);return o?(o.closed=!0,o.touch(this.now()),o.snapshot()):null}isClosed(e){let o=this.nodes.get(e);return o?o.closed:!1}reopenBox(e){let o=this.nodes.get(e);return o?(o.closed=!1,o.touch(this.now()),o.snapshot()):null}setHorizon(e,o){let n=this.nodes.get(e);return n?(n.horizon=o,n.touch(this.now()),n.snapshot()):null}setParent(e,o){let n=this.nodes.get(e);return n?n.parentId===o?n.snapshot():o!==null&&this.wouldCreateCycle(e,o)?null:(n.parentId&&this.nodes.get(n.parentId)?.children.delete(e),n.parentId=o,o&&this.nodes.get(o)?.children.add(e),n.touch(this.now()),n.snapshot()):null}wouldCreateCycle(e,o){let n=new Set,r=o;for(;r!==null;){if(r===e||n.has(r))return!0;n.add(r),r=this.nodes.get(r)?.parentId??null}return!1}getBox(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),o.snapshot()):null}listBoxes(e="lastAccessedAt"){let o=[...this.nodes.values()].map(n=>n.snapshot());switch(e){case"createdAt":return o.sort((n,r)=>n.createdAt-r.createdAt);case"accessCount":return o.sort((n,r)=>r.accessCount-n.accessCount);default:return o.sort((n,r)=>r.lastAccessedAt-n.lastAccessedAt)}}get size(){return this.nodes.size}addContext(e,o){let n=this.nodes.get(e);return n?(n.context.push({ts:this.now(),text:o}),n.touch(this.now()),n.snapshot()):null}getContext(e){let o=this.nodes.get(e);return o?(o.touch(this.now()),[...o.context]):[]}getContextChain(e){let o=[],n=new Set,r=e;for(;r&&!n.has(r);){n.add(r);let s=this.nodes.get(r);if(!s)break;s.touch(this.now()),o.push({boxId:s.id,entries:[...s.context]}),r=s.parentId}return o}addDependency(e,o){let n=this.nodes.get(e);return!n||!this.nodes.has(o)||n.id===o?!1:(n.dependencies.add(o),n.touch(this.now()),!0)}getDependencies(e){let o=this.nodes.get(e);return o?[...o.dependencies]:[]}pinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!0,o.touch(this.now()),o.snapshot()):null}unpinBox(e){let o=this.nodes.get(e);return o?(o.pinned=!1,o.touch(this.now()),o.snapshot()):null}evictOne(){let e=[];for(let n of this.nodes.values())n.horizon==="longo"||n.pinned||e.push(n);if(e.length===0)return null;e.sort((n,r)=>{let s=n.horizon==="curto"?0:1,i=r.horizon==="curto"?0:1;if(s!==i)return s-i;let a=n.closed?0:1,c=r.closed?0:1;return a!==c?a-c:n.lastAccessedAt!==r.lastAccessedAt?n.lastAccessedAt-r.lastAccessedAt:n.accessCount-r.accessCount});let o=e[0];return this.removeNode(o)}forceEvict(e){let o=this.nodes.get(e);return!o||o.horizon==="longo"||o.pinned?null:this.removeNode(o)}removeBox(e){let o=this.nodes.get(e);return o?this.removeNode(o):null}removeNode(e){if(e.parentId){let o=this.nodes.get(e.parentId);o&&o.children.delete(e.id)}return this.nodes.delete(e.id),e.snapshot()}}});function sd(t){let e=[];for(let o of t){e.push({step:o,depth:0});for(let n of o.substeps??[])e.push({step:n,depth:1})}return e}function Cx(t,e){let o,n="pending",r;if(typeof t=="string")o=t;else if(t!==null&&typeof t=="object"){let i=t,a=i.title??i.step??i.text??i.name??i.content;if(typeof a=="string"&&(o=a),typeof i.status=="string"&&NN.has(i.status)&&(n=i.status),e){let c=i.substeps??i.subtasks??i.subpassos??i.children;if(Array.isArray(c)&&c.length>0){let l=[];for(let d of c){let f=Cx(d,!1);if(typeof f=="string")return f;l.push(f)}r=l}}}if(o===void 0||o.trim()==="")return DN;let s=o.trim().slice(0,IN);return r?{title:s,status:n,substeps:r}:{title:s,status:n}}function $N(t){let e=t.steps??t.plan??t.todos??t.items;if(!Array.isArray(e))return{error:'update_plan: passe "steps" como uma LISTA de passos (string ou {title,status}).'};if(e.length===0)return{error:"update_plan: a lista de passos est\xE1 vazia."};let o=[];for(let i of e){let a=Cx(i,!0);if(typeof a=="string")return{error:a};o.push(a)}let n=new Set,r=i=>{if(!n.has(i))return n.add(i),i;for(let a=2;;a++){let c=`${i} #${a}`;if(!n.has(c))return n.add(c),c}};for(let i=0;i<o.length;i++){let a=o[i],c=r(a.title),l=a.substeps?.map(d=>({...d,title:r(d.title)}));o[i]=l!==void 0?{...a,title:c,substeps:l}:{...a,title:c}}let s=sd(o).length;return s>_x?{error:`update_plan: no m\xE1ximo ${_x} passos (recebidos ${s}).`}:{steps:o}}function FN(t){let e=sd(t),o=e.filter(r=>r.step.status==="completed").length,n=e.map(r=>`${" ".repeat(r.depth)}${Ox[r.step.status]} ${r.step.title}`).join(`
|
|
2
2
|
`);return`plano (${o}/${e.length}):
|
|
3
3
|
${n}`}function UN(t,e){return e<0?"m\xE9dio":t===e?"curto":t>e?"longo":"m\xE9dio"}function jN(t,e){let o=new Map;for(let i of e.listBoxes())o.set(i.label,i.id);let n=t.findIndex(i=>i.status==="in_progress"||(i.substeps??[]).some(a=>a.status==="in_progress")),r=(i,a,c)=>{let l=i.status==="in_progress"?"curto":c,d=o.get(i.title),f=d??Ws.boxId(i.title,0);return d?(i.status!=="completed"&&e.isClosed(d)&&e.reopenBox(d),e.setHorizon(d,l),e.setParent(d,a)):e.openBox(f,l,i.title,a),i.status==="completed"&&!e.isClosed(f)&&e.closeBox(f),o.set(i.title,f),f};t.forEach((i,a)=>{let c=UN(a,n),l=r(i,null,c);for(let d of i.substeps??[])r(d,l,c)});let s=new Set;for(let i of t){s.add(i.title);for(let a of i.substeps??[])s.add(a.title)}for(let i of e.listBoxes())s.has(i.label)||e.removeBox(i.id)}function HN(t,e){if(!e)return FN(t);let o=new Map;for(let l of e.listBoxes())o.set(l.label,l);let n=new Map;for(let l of e.listBoxes())n.set(l.id,l);let r=new Map,s=(l,d=new Set)=>{let f=r.get(l);if(f!==void 0)return f;let u=n.get(l);if(!u||!u.parentId||d.has(l))return r.set(l,0),0;let p=s(u.parentId,new Set(d).add(l))+1;return r.set(l,p),p},i=sd(t),c=[`plano (${i.filter(l=>l.step.status==="completed").length}/${i.length}):`];for(let{step:l,depth:d}of i){let f=o.get(l.title),u=f?BN[f.horizon]:"",p=f?s(f.id):d,h=" ".repeat(p),g=Ox[l.status];c.push(`${h}${u} ${g} ${l.title}`)}return c.join(`
|
|
4
4
|
`)}var la,NN,_x,IN,DN,Ox,BN,Rx,qN,Mx,id=S(()=>{"use strict";zf();la="update_plan";NN=new Set(["pending","in_progress","completed"]),_x=30,IN=120,DN="update_plan: cada passo precisa de um t\xEDtulo (texto) n\xE3o-vazio.";Ox={pending:"\u2610",in_progress:"\u25B6",completed:"\u2611"};BN={longo:"[\u{1F4D0}]",m\u00E9dio:"[\u{1F4CB}]",curto:"[\u{1F4CC}]"};Rx=Object.freeze({type:"string",enum:["pending","in_progress","completed"],description:"pending (a fazer) \xB7 in_progress (em curso) \xB7 completed (feito)."}),qN=Object.freeze({type:"object",properties:{steps:{type:"array",description:"A lista COMPLETA de passos do plano (re-emita TODOS a cada atualiza\xE7\xE3o \u2014 substitui o anterior).",items:{type:"object",properties:{title:{type:"string",description:"O passo, curto e no imperativo."},status:Rx,substeps:{type:"array",description:"OPCIONAL: sub-passos que detalham este passo (1 n\xEDvel). Aparecem indentados sob o passo e seguem o foco dele. Use quando um passo tem a\xE7\xF5es menores distintas.",items:{type:"object",properties:{title:{type:"string",description:"O sub-passo, curto e no imperativo."},status:Rx},required:["title"],additionalProperties:!1}}},required:["title"],additionalProperties:!1}}},required:["steps"],additionalProperties:!1}),Mx={name:la,effect:"read",description:"Declara/atualiza um PLANO vis\xEDvel (checklist de passos). Use ao iniciar uma tarefa com V\xC1RIOS passos e a cada progresso: re-emita a lista TODA marcando o status de cada passo (pending/in_progress/completed). Mantenha 1 passo in_progress por vez. N\xE3o tem efeito no sistema \u2014 \xE9 s\xF3 o seu plano, para voc\xEA e para o usu\xE1rio acompanharem.",parameters:qN,async run(t,e){let o=$N(t);return"error"in o?{ok:!1,observation:o.error}:(e.graph&&jN(o.steps,e.graph),e.plan&&e.plan.set(sd(o.steps).map(r=>({title:r.step.title,status:r.step.status}))),{ok:!0,observation:HN(o.steps,e.graph)})}}});function Lx(t){let e=t.question??t.prompt??t.text??t.message;if(typeof e!="string"||e.trim()==="")return{error:'perguntar: passe "question" (a pergunta em texto). Para escolha, passe tamb\xE9m "options".'};let o=e.trim().slice(0,2e3),n=t.header??t.title,r=typeof n=="string"&&n.trim()!==""?n.trim().slice(0,200):void 0,s=t.options??t.choices,i=Array.isArray(s)?GN(s):void 0;if(typeof i=="string")return{error:i};let a,c=t.kind??t.type;if(typeof c=="string"&&WN.has(c))a=c;else{if(typeof c=="string"&&c.trim()!=="")return{error:`perguntar: "kind" inv\xE1lido "${c}". Use "single", "multi" ou "text".`};a=i!==void 0&&i.length>0?"single":"text"}if((a==="single"||a==="multi")&&(i===void 0||i.length===0))return{error:`perguntar: kind "${a}" requer "options" (uma lista de ao menos 1 op\xE7\xE3o).`};let l=t.allowOther!==!1;return{spec:{kind:a,question:o,...r!==void 0?{header:r}:{},...a!=="text"&&i!==void 0?{options:i}:{},...a!=="text"?{allowOther:l}:{}}}}function GN(t){if(t.length===0)return'perguntar: a lista de "options" est\xE1 vazia.';if(t.length>12)return`perguntar: no m\xE1ximo 12 op\xE7\xF5es (recebidas ${t.length}).`;let e=[];for(let o of t){let n,r;if(typeof o=="string")n=o;else if(o!==null&&typeof o=="object"){let s=o,i=s.label??s.text??s.value??s.name??s.title;typeof i=="string"&&(n=i),typeof s.description=="string"&&s.description.trim()!==""&&(r=s.description.trim().slice(0,300))}if(n===void 0||n.trim()==="")return'perguntar: cada op\xE7\xE3o precisa de um "label" (texto) n\xE3o-vazio.';e.push({label:n.trim().slice(0,200),...r!==void 0?{description:r}:{}})}return e}function zN(t){switch(t.kind){case"choice":return t.label;case"choices":return t.labels.length===0?"(nenhuma)":t.labels.join(", ");case"text":{let e=t.text.split(`
|
|
@@ -27,7 +27,7 @@ ${e.text}`,display:o};case"unavailable":return{ok:!1,observation:`N\xE3o foi pos
|
|
|
27
27
|
|
|
28
28
|
`)}}if(o+=e.decode(),o.trim().length>0){let r=bS(o);r&&(yield r)}}function bS(t){let e="message",o=[],n=!1;for(let r of t.split(`
|
|
29
29
|
`)){if(r===""||r.startsWith(":"))continue;let s=r.indexOf(":"),i=s===-1?r:r.slice(0,s),a=s===-1?"":r.slice(s+1);a.startsWith(" ")&&(a=a.slice(1)),i==="event"?(e=a,n=!0):i==="data"&&(o.push(a),n=!0)}return n?{event:e,data:o.join(`
|
|
30
|
-
`)}:null}var Od=S(()=>{"use strict"});function ES(t=globalThis.process?.env??{}){let e=kS(t[SS]),o=kS(t[wS]);return{maxConsecutiveLineRepeats:e!==void 0?Math.max(3,e):25,maxCycleLen:80,minCycleSpanChars:o!==void 0?Math.max(200,o):2e3,trivialLineMaxLen:1}}function TS(t=globalThis.process?.env??{}){let e=(t[AS]??"").trim().toLowerCase();return!(e==="1"||e==="true"||e==="yes"||e==="on")}function _S(t,e,o){let n=t.length;if(!(n<o))for(let r=1;r<=e&&!(r*2>n);r++){let s=r;for(;s<n&&t.charCodeAt(n-1-s)===t.charCodeAt(n-1-s%r);)s++;if(s>=o&&s>=r*2){let i=t.slice(n-r);return{period:r,unit:i,repeats:Math.floor(s/r)}}}}function zr(t,e){return TS(t)?new Ld(ES(t),e):QI}function Md(t){let e=t.replace(/\s+/g," ").trim();return e.length<=vS?e:`${e.slice(0,vS)}\u2026`}function kS(t){if(t===void 0)return;let e=t.trim();if(e==="")return;let o=Number(e);if(!(!Number.isFinite(o)||o<=0))return Math.floor(o)}var xS,SS,wS,AS,Gr,vS,Ld,QI,xa=S(()=>{"use strict";xS={maxConsecutiveLineRepeats:25,maxCycleLen:80,minCycleSpanChars:2e3,trivialLineMaxLen:1},SS="ALUY_DEGENERATE_LINE_REPEATS",wS="ALUY_DEGENERATE_CYCLE_SPAN",AS="ALUY_DEGENERATE_OFF";Gr=class extends Error{kind;repeats;sample;constructor(e,o,n){super(`loop de repeti\xE7\xE3o degenerado detectado (${e}, ${o}\xD7)`),this.name="DegenerateLoopError",this.kind=e,this.repeats=o,this.sample=n}},vS=60,Ld=class{cfg;bus;lineBuf="";lastLine;lineRepeatCount=1;tail="";tailMax;constructor(e=xS,o){this.cfg=e,this.bus=o,this.tailMax=e.minCycleSpanChars+e.maxCycleLen+1}push(e){e.length!==0&&(this.pushForLineHeuristic(e),this.pushForCycleHeuristic(e))}pushForLineHeuristic(e){let o=0;for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&(this.lineBuf+=e.slice(o,n),this.commitLine(this.lineBuf),this.lineBuf="",o=n+1);o<e.length&&(this.lineBuf+=e.slice(o))}commitLine(e){let o=e.trim();if(o.length<=this.cfg.trivialLineMaxLen){this.lastLine=void 0,this.lineRepeatCount=1;return}if(o===this.lastLine){if(this.lineRepeatCount+=1,this.lineRepeatCount>=this.cfg.maxConsecutiveLineRepeats)throw this.bus?.publish({origin:"degeneration",severity:"warning",ts:Date.now(),payload:{kind:"line-repeat",repeats:this.lineRepeatCount,sample:Md(o)}}),new Gr("line-repeat",this.lineRepeatCount,Md(o))}else this.lastLine=o,this.lineRepeatCount=1}pushForCycleHeuristic(e){if(this.tail+=e,this.tail.length>this.tailMax&&(this.tail=this.tail.slice(this.tail.length-this.tailMax)),this.tail.length<this.cfg.minCycleSpanChars)return;let o=_S(this.tail,this.cfg.maxCycleLen,this.cfg.minCycleSpanChars);if(o)throw this.bus?.publish({origin:"degeneration",severity:"critical",ts:Date.now(),payload:{kind:"short-cycle",repeats:o.repeats,sample:Md(o.unit)}}),new Gr("short-cycle",o.repeats,Md(o.unit))}};QI={push(){}}});function ZI(t){if(t===void 0)return;let e=t.trim();if(e==="")return;let o=Number(e);if(!(!Number.isFinite(o)||o<=0))return Math.floor(o)}function eD(t){let e=t[CS]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"||e==="on"}function Yr(t=process.env){return eD(t)?new Sa(0):new Sa(ZI(t[RS])??25165824)}var RS,CS,Kr,Sa,Pd=S(()=>{"use strict";RS="ALUY_STREAM_MAX_BYTES",CS="ALUY_STREAM_CAP_OFF",Kr="length_client_cap",Sa=class{max;total=0;_tripped=!1;constructor(e=25165824){this.max=e>0?Math.floor(e):0}get tripped(){return this._tripped}get bytes(){return this.total}get limit(){return this.max}addText(e){return this.addBytes(Buffer.byteLength(e,"utf8"))}addToolCall(e){let o=0;try{o=Buffer.byteLength(JSON.stringify(e.input??{}),"utf8")}catch{o=256}return this.addBytes(Buffer.byteLength(e.id,"utf8")+Buffer.byteLength(e.name,"utf8")+o)}addBytes(e){return this.max<=0?!1:(this.total+=e>0?e:0,this.total>this.max&&(this._tripped=!0),this._tripped)}}});function Id(t){if(!Dd(t))return;let{fiveHour:e,week:o}=tD(t.windows),n=oD(t.credit);return{windows:{...e!==void 0?{fiveHour:e}:{},...o!==void 0?{week:o}:{}},...n!==void 0?{credit:n}:{}}}function Gp(t){if(!Dd(t))return;let e=OS(t,"quota_5h"),o=OS(t,"quota_week");if(!(e===void 0&&o===void 0))return{windows:{...e!==void 0?{fiveHour:e}:{},...o!==void 0?{week:o}:{}}}}function PS(t,e,o){if(!(e===void 0||e<=0))return{used:Math.max(0,t??0),limit:e,...o!==void 0?{resetAt:o}:{}}}function tD(t){if(!Array.isArray(t))return{};let e={};for(let o of t){if(!Dd(o))continue;let n=NS(o.period);if(n===void 0)continue;let r=PS(Nd(o.used),Nd(o.limit),Aa(o.reset_at??o.resetAt));r!==void 0&&(n==="5h"?e.fiveHour=r:(n==="week"||n==="weekly")&&(e.week=r))}return e}function OS(t,e){return PS(Nd(t[`${e}_used`]),Nd(t[`${e}_limit`]),Aa(t[`${e}_reset_at`]))}function oD(t){if(!Dd(t))return;let e=NS(t.balance);return e!==void 0?{balance:e}:void 0}function Nd(t){if(t==null)return;let e=typeof t=="number"?t:String(t).trim();if(e==="")return;let o=typeof e=="number"?e:Number(e);if(!(!Number.isFinite(o)||o<0))return Math.round(o)}function NS(t){if(typeof t!="string")return;let e=t.trim();return e===""?void 0:e}function Aa(t){if(t==null)return;if(typeof t=="number")return MS(t);let e=String(t).trim();if(e==="")return;if(/^\d+(\.\d+)?$/.test(e)){let n=Number(e);return Number.isFinite(n)?MS(n):void 0}let o=Date.parse(e);return Number.isFinite(o)?o:void 0}function MS(t){if(!(!Number.isFinite(t)||t<=0))return t<1e12?Math.round(t*1e3):Math.round(t)}function IS(t){return t.limit<=0?0:Math.min(100,Math.max(0,Math.floor(t.used/t.limit*100)))}function wa(t,e=Date.now()){let o=t-e;if(!Number.isFinite(o)||o<=0)return"agora";let n=Math.floor(o/6e4);if(n<1)return"agora";let r=Math.floor(n/60),s=n%60;return r===0?`${s}min`:`${r}h${String(s).padStart(2,"0")}`}function FS(t){return t>=$S?"crit":t>=DS?"warn":"ok"}function Ea(t,e=Date.now()){if(t===void 0)return;let o=[],n,r="ok",s=(c,l)=>{if(l===void 0)return;let d=IS(l),f=FS(d);o.push({label:c,pct:d,level:f}),n===void 0&&l.resetAt!==void 0&&(n=l),r=nD(r,f)};s("5h",t.windows.fiveHour),s("semana",t.windows.week);let i=t.credit?.balance;if(o.length===0&&i===void 0)return;let a=n?.resetAt!==void 0?wa(n.resetAt,e)==="agora"?"reseta agora":`reseta em ${wa(n.resetAt,e)}`:void 0;return{segments:o,...i!==void 0?{creditBalance:i}:{},...a!==void 0?{resetText:a}:{},maxLevel:r}}function nD(t,e){return LS[e]>LS[t]?e:t}function Dd(t){return typeof t=="object"&&t!==null}var DS,$S,LS,Ta=S(()=>{"use strict";DS=70,$S=90;LS={ok:0,warn:1,crit:2}});function jS(t,e){let o={tier:t.tier,messages:t.messages.map(sD),stream:e};t.session_id!==void 0&&(o.session_id=t.session_id),t.max_tokens!==void 0&&(o.max_tokens=t.max_tokens),t.temperature!==void 0&&(o.temperature=t.temperature),t.context!==void 0&&(o.context=t.context),t.tools!==void 0&&t.tools.length>0&&(o.tools=t.tools,o.tool_choice=t.tool_choice??"auto",t.parallel_tool_calls!==void 0&&(o.parallel_tool_calls=t.parallel_tool_calls));let n=t.model?.trim(),r=n!==void 0&&n!=="";r&&t.tier==="custom"&&(o.model=n);let s=t.provider?.trim();s!==void 0&&s!==""&&r&&t.tier==="custom"&&(o.provider=s);let a=t.reasoning_effort?.trim();return a!==void 0&&a!==""&&(o.reasoning_effort=a),o}function sD(t){let e={role:t.role,content:t.content};return t.tool_calls!==void 0&&t.tool_calls.length>0&&(e.tool_calls=t.tool_calls.map(o=>({id:o.id,type:"function",function:{name:o.name,arguments:JSON.stringify(o.input??{})}}))),t.tool_call_id!==void 0&&(e.tool_call_id=t.tool_call_id),e}function iD(t,e){let o=Yp(e);switch(t){case"start":return{type:"start",request_id:Vt(o,"request_id")??"",...Vt(o,"session_id")!==void 0?{session_id:Vt(o,"session_id")}:{}};case"delta":{let n=Vt(o,"content");return n!==void 0?{type:"delta",content:n}:null}case"tool_call":{let n=HS(o);return n!==null?{type:"tool_call",call:n}:null}case"usage":return{type:"usage",usage:aD(o)};case"done":return{type:"done",finish_reason:Vt(o,"finish_reason")??"stop"};case"error":throw new Le(uo(Kp(o,"status")??502,o));default:return null}}function aD(t){let e={request_id:Vt(t,"request_id")??"",tier:Vt(t,"tier")??""},o=Vt(t,"provider");o!==void 0&&(e.provider=o);let n=Vt(t,"model");n!==void 0&&(e.model=n);let r=Kp(t,"tokens_in");r!==void 0&&(e.tokens_in=r);let s=Kp(t,"tokens_out");s!==void 0&&(e.tokens_out=s);let i=Vt(t,"cost");i!==void 0&&(e.cost=i);let a=Vt(t,"price_version");a!==void 0&&(e.price_version=a);let c=lD(t,"partial");c!==void 0&&(e.partial=c);let l=Vt(t,"balance_after");return l!==void 0&&(e.balance_after=l),e}function HS(t){if(!ur(t))return null;let e=ur(t.function)?t.function:void 0,o=(typeof t.name=="string"?t.name:void 0)??Vt(e,"name");if(o===void 0||o.length===0)return null;let n=Vt(t,"id")??"",r={};return ur(t.input)?r=t.input:e!==void 0&&e.arguments!==void 0?r=BS(e.arguments):t.arguments!==void 0&&(r=BS(t.arguments)),{id:n,name:o,input:r}}function BS(t){if(ur(t))return t;if(typeof t=="string"&&t.trim()!==""){let e=Yp(t);if(ur(e))return e}return{}}function Zs(t,e){if(e.id!==""){let o=t.find(n=>n.id===e.id);if(o!==void 0){let n=t.indexOf(o);t[n]={id:o.id,name:e.name.length>0?e.name:o.name,input:{...o.input,...e.input}};return}}t.push(e)}function cD(t,e){if(t===null)return;let o=t.trim();if(o==="")return;if(/^\d+$/.test(o)){let s=Number(o);return Number.isFinite(s)?s:void 0}let n=Date.parse(o);if(!Number.isFinite(n))return;let r=Math.round((n-e)/1e3);return r>=0?r:0}function Yp(t){try{return JSON.parse(t)}catch{return}}function ur(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Vt(t,e){if(!ur(t))return;let o=t[e];return typeof o=="string"?o:void 0}function Kp(t,e){if(!ur(t))return;let o=t[e];return typeof o=="number"?o:void 0}function lD(t,e){if(!ur(t))return;let o=t[e];return typeof o=="boolean"?o:void 0}function zp(t){if(t?.aborted)throw new ze}function US(t){return typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError"}var rD,_a,$d=S(()=>{"use strict";mo();Od();xa();Pd();Ta();rD="/v1/chat",_a=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async*stream(e){let{request:o,signal:n,idempotencyKey:r}=e;zp(n);let s=await this.getAccessToken();zp(n);let i=await this.send(s,o,n,!0,r);if(!i.ok)throw await this.toBrokerError(i);if(i.body===null)throw new Pe("broker respondeu 2xx sem corpo de stream.");try{for await(let a of ka(i.body)){zp(n);let c=iD(a.event,a.data);if(c&&(yield c),a.event==="usage"){let l=Gp(Yp(a.data));l!==void 0&&(yield{type:"quota",quota:l})}if(a.event==="done")return}}catch(a){throw US(a)||a instanceof ze?new ze:a instanceof Le?a:new Pe("falha ao ler o stream do broker.",a)}}async call(e){let o="",n="",r,s="stop",i,a,c=[],l=zr(),d=Yr(),f=!1;for await(let u of this.stream(e)){switch(u.type){case"start":n=u.request_id,r=u.session_id;break;case"delta":o+=u.content,l.push(u.content),d.addText(u.content)&&(f=!0);break;case"tool_call":Zs(c,u.call),d.addToolCall(u.call)&&(f=!0);break;case"usage":i=u.usage;break;case"quota":a=u.quota;break;case"done":s=u.finish_reason;break}if(f){s=Kr;break}}return{request_id:n,...r!==void 0?{session_id:r}:{},content:o,finish_reason:s,...i!==void 0?{usage:i}:{},...c.length>0?{tool_calls:c}:{},...a!==void 0?{quota:a}:{}}}async send(e,o,n,r,s){let i=jS(o,r),a={authorization:`Bearer ${e}`,"content-type":"application/json",accept:"text/event-stream"};s!==void 0&&(a["idempotency-key"]=s);try{return await this.doFetch(`${this.baseUrl}${rD}`,{method:"POST",headers:a,body:JSON.stringify(i),...n?{signal:n}:{}})}catch(c){throw US(c)?new ze:new Pe("falha de transporte ao chamar o broker.",c)}}async toBrokerError(e){let o;try{o=await e.json()}catch{o=void 0}let n=uo(e.status,o);if(n.retry_after===void 0){let r=cD(e.headers.get("retry-after"),Date.now());if(r!==void 0)return new Le({...n,retry_after:r})}return new Le(n)}}});function uD(t,e){if(t===401||t===403)return"UNAUTHENTICATED";if(t===429)return"RATE_LIMITED";let o=(WS(e)??"").toLowerCase();return(t===400||t===422)&&(o.includes("tool")||o.includes("function calling")||o.includes("function_call"))?"TOOLS_UNSUPPORTED":t>=500?"PROVIDER_ERROR":t===400||t===422?"VALIDATION_FAILED":"PROVIDER_ERROR"}function WS(t){if(typeof t!="object"||t===null)return;let e=t;if(typeof e.message=="string")return e.message;let o=e.error;if(typeof o=="string")return o;if(typeof o=="object"&&o!==null){let n=o.message;if(typeof n=="string")return n}}function Vp(t){if(t?.aborted)throw new ze}function qS(t){return typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError"}var dD,Ra,GS=S(()=>{"use strict";mo();Od();xa();Pd();$d();Wp();dD=8192,Ra=class{adapter;config;baseUrl;getCredential;doFetch;maxTokens;constructor(e){this.adapter=e.adapter,this.config=e.config,this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getCredential=e.getCredential,this.doFetch=e.fetch??globalThis.fetch,this.maxTokens=e.maxTokens??dD}async*stream(e){let{request:o,signal:n}=e;Vp(n);let r=await this.getCredential();Vp(n);let s=this.toLocalRequest(o),i=this.adapter.buildRequest({request:s,baseUrl:this.baseUrl,credential:r}),a;try{a=await this.doFetch(i.url,{method:"POST",headers:i.headers,body:i.body,redirect:"error",...n?{signal:n}:{}})}catch(l){throw qS(l)?new ze:new Pe("falha de transporte ao chamar o provider (backend local).",l)}if(!a.ok)throw await this.toProviderError(a);if(a.body===null)throw new Pe("provider respondeu 2xx sem corpo de stream.");let c=qp();try{for await(let l of ka(a.body)){Vp(n);let d=this.adapter.mapSse(l.event,l.data,c);for(let f of d)if(yield f,f.type==="done")return}}catch(l){throw qS(l)||l instanceof ze?new ze:l instanceof Le?l:new Pe("falha ao ler o stream do provider (backend local).",l)}}async call(e){let o="",n="",r="stop",s,i=[],a=zr(),c=Yr(),l=!1;for await(let d of this.stream(e)){switch(d.type){case"start":n=d.request_id;break;case"delta":o+=d.content,a.push(d.content),c.addText(d.content)&&(l=!0);break;case"tool_call":Zs(i,d.call),c.addToolCall(d.call)&&(l=!0);break;case"usage":s=d.usage;break;case"done":r=d.finish_reason;break}if(l){r=Kr;break}}return{request_id:n,content:o,finish_reason:r,...s!==void 0?{usage:s}:{},...i.length>0?{tool_calls:i}:{}}}toLocalRequest(e){let o,n=[];for(let a of e.messages){if(a.role==="system"&&o===void 0){o=a.content;continue}n.push({role:a.role,content:a.content,...a.tool_calls!==void 0?{tool_calls:a.tool_calls.map(c=>({id:c.id,name:c.name,input:{...c.input}}))}:{},...a.tool_call_id!==void 0?{tool_call_id:a.tool_call_id}:{}})}let r=e.tier==="custom"?e.model?.trim():void 0,i={model:r&&r.length>0?r:this.config.model,messages:n,maxTokens:e.max_tokens??this.maxTokens};return o!==void 0&&(i.system=o),e.temperature!==void 0&&(i.temperature=e.temperature),e.reasoning_effort!==void 0&&(i.reasoningEffort=e.reasoning_effort),e.tools!==void 0&&e.tools.length>0&&(i.tools=e.tools,i.toolChoice=e.tool_choice??"auto"),i}async toProviderError(e){let o;try{o=await e.json()}catch{o=void 0}let n=WS(o),r=uD(e.status,o),s=r==="TOOLS_UNSUPPORTED"?422:e.status,i=uo(s,{code:r,...n!==void 0?{detail:n}:{}});return new Le(i)}}});function Vr(t){let e=t.trim();if(e==="")return;let o=e.split(".");if(o.length===0||o.length>4)return;let n=[];for(let d of o){let f=mD(d);if(f===void 0)return;n.push(f)}let r,s=n.length;if(s===1){if(r=n[0],r>4294967295)return}else{let d=0;for(let h=0;h<s-1;h++){let g=n[h];if(g>255)return;d=d*256+g}let f=n[s-1],u=4-(s-1),p=Math.pow(256,u)-1;if(f>p)return;r=d*Math.pow(256,u)+f}if(r<0||r>4294967295)return;let i=r>>>24&255,a=r>>>16&255,c=r>>>8&255,l=r&255;return`${i}.${a}.${c}.${l}`}function mD(t){if(t==="")return;let e;if(/^0[xX][0-9a-fA-F]+$/.test(t))e=parseInt(t.slice(2),16);else if(/^0[0-7]+$/.test(t))e=parseInt(t,8);else if(/^[0-9]+$/.test(t))e=parseInt(t,10);else return;return Number.isFinite(e)?e:void 0}function Ca(t){let e=t.trim().toLowerCase();e=e.replace(/%.*$/,"").replace(/^\[/,"").replace(/\]$/,"");let o=e.match(/:((?:\d{1,3}\.){3}\d{1,3})$/);if(o&&(e.startsWith("::ffff:")||e.startsWith("::")))return Vr(o[1]);let n=e.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);if(n){let r=parseInt(n[1],16),s=parseInt(n[2],16);if(Number.isFinite(r)&&Number.isFinite(s)){let i=r>>8&255,a=r&255,c=s>>8&255,l=s&255;return`${i}.${a}.${c}.${l}`}}}function Oa(t){let e=t.trim().replace(/^\[/,"").replace(/\]$/,"").replace(/%.*$/,"");return e.includes(":")&&/^[0-9a-fA-F:.]+$/.test(e)}function zS(t){let e=t.trim().toLowerCase().replace(/^\[/,"").replace(/\]$/,"").replace(/%.*$/,""),o=e.match(/((?:\d{1,3}\.){3}\d{1,3})$/);if(o){let c=Vr(o[1]);if(!c)return;let l=c.split(".").map(Number),d=(l[0]<<8|l[1]).toString(16),f=(l[2]<<8|l[3]).toString(16);e=e.slice(0,o.index)+d+":"+f}let n=e.split("::");if(n.length>2)return;let r=n[0]?n[0].split(":").filter(c=>c!==""):[],s=n.length===2&&n[1]?n[1].split(":").filter(c=>c!==""):[],i=[];for(let c of r){let l=parseInt(c,16);if(!/^[0-9a-f]{1,4}$/.test(c)||!Number.isFinite(l))return;i.push(l)}let a=8-r.length-s.length;if(n.length===2){if(a<0)return;for(let c=0;c<a;c++)i.push(0)}else if(r.length!==8)return;for(let c of s){let l=parseInt(c,16);if(!/^[0-9a-f]{1,4}$/.test(c)||!Number.isFinite(l))return;i.push(l)}return i.length===8?i:void 0}function $n(t){let e=t.trim();if(e==="")return{blocked:!0,reason:"IP vazio",canonical:e};let o=Ca(e);if(o){let r=Xp(o);return r.blocked?{...r,reason:`IPv4-mapped-IPv6 \u2192 ${r.reason}`}:r}if(Oa(e))return fD(e);let n=Vr(e);return n?Xp(n):{blocked:!0,reason:`IP n\xE3o-reconhecido: "${e}"`,canonical:e}}function Jp(t){let e=t.trim();if(e==="")return!1;let o=Ca(e);if(o)return o.split(".")[0]==="127";if(Oa(e)){let r=zS(e);return r?r.slice(0,7).every(s=>s===0)&&r[7]===1:!1}let n=Vr(e);return n?n.split(".")[0]==="127":!1}function Xp(t){let e=t.split(".").map(Number);if(e.length!==4||e.some(s=>!Number.isInteger(s)||s<0||s>255))return{blocked:!0,reason:`IPv4 inv\xE1lido: "${t}"`,canonical:t};let[o,n]=e,r=s=>({blocked:!0,reason:s,canonical:t});return t==="169.254.169.254"?r("endpoint de metadata da cloud (169.254.169.254)"):o===0?r("0.0.0.0/8 (este host / n\xE3o-rote\xE1vel)"):o===127?r("loopback (127.0.0.0/8)"):o===10?r("rede privada RFC1918 (10.0.0.0/8)"):o===172&&n>=16&&n<=31?r("rede privada RFC1918 (172.16.0.0/12)"):o===192&&n===168?r("rede privada RFC1918 (192.168.0.0/16)"):o===169&&n===254?r("link-local (169.254.0.0/16)"):o===100&&n>=64&&n<=127?r("CGNAT (100.64.0.0/10)"):o===198&&(n===18||n===19)?r("rede de benchmark (198.18.0.0/15)"):o>=224?r("multicast/reservado (\u2265224.0.0.0/4)"):t==="255.255.255.255"?r("broadcast (255.255.255.255)"):{blocked:!1,canonical:t}}function fD(t){let e=zS(t);if(!e)return{blocked:!0,reason:`IPv6 inv\xE1lido: "${t}"`,canonical:t};let o=e.map(c=>c.toString(16)).join(":"),n=c=>({blocked:!0,reason:c,canonical:o});if(e.slice(0,7).every(c=>c===0)&&e[7]===1)return n("loopback IPv6 (::1)");if(e.every(c=>c===0))return n("IPv6 unspecified (::)");let s=e[0],i=s>>8&255;if(i===252||i===253)return n("IPv6 ULA privada (fc00::/7)");if((s&65472)===65152)return n("IPv6 link-local (fe80::/10)");if(i===255)return n("IPv6 multicast (ff00::/8)");let a=pD(e);if(a){let c=Xp(a.ipv4);if(c.blocked)return{blocked:!0,reason:`IPv6 ${a.kind} \u2192 ${c.reason}`,canonical:o}}return{blocked:!1,canonical:o}}function pD(t){let e=t,o=(n,r)=>`${n>>8&255}.${n&255}.${r>>8&255}.${r&255}`;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0)return{ipv4:o(e[6],e[7]),kind:"NAT64 (64:ff9b::/96)"};if(e[0]===100&&e[1]===65435&&e[2]===1)return{ipv4:o(e[6],e[7]),kind:"NAT64 (64:ff9b:1::/48)"};if(e[0]===8194)return{ipv4:o(e[1],e[2]),kind:"6to4 (2002::/16)"}}function ei(t){if(t.length===0)return{ok:!1,reason:"host n\xE3o resolveu para nenhum IP",offendingIp:""};for(let e of t){let o=$n(e);if(o.blocked)return{ok:!1,reason:o.reason??"IP bloqueado pela denylist anti-SSRF",offendingIp:o.canonical}}return{ok:!0,pinnedIp:$n(t[0]).canonical}}var Ma=S(()=>{"use strict"});function KS(t){let e;try{e=new URL(t)}catch{return{reason:`base_url inv\xE1lida: "${t}"`}}return e.protocol!=="https:"&&e.protocol!=="http:"?{reason:`base_url precisa ser http(s): "${t}"`}:e.hostname===""?{reason:`base_url sem host: "${t}"`}:{url:e}}async function Qp(t,e){let o=KS(t);if("reason"in o)return{ok:!1,reason:o.reason};let n=o.url.hostname.replace(/^\[/,"").replace(/\]$/,""),r=$n(n);if(r.blocked&&YS(n))return{ok:!1,reason:`base_url aponta p/ IP interno (${r.reason})`};let s;try{s=await e.resolve(n)}catch{return{ok:!1,reason:`base_url: host "${n}" n\xE3o resolveu (anti-SSRF, fail-safe)`}}let i=ei(s);return i.ok?{ok:!0,url:o.url.toString()}:{ok:!1,reason:`base_url aponta p/ IP interno (${i.reason})`}}async function Zp(t,e){let o=KS(t);if("reason"in o)return{ok:!1,reason:o.reason};let n=o.url.hostname.replace(/^\[/,"").replace(/\]$/,"");if(YS(n)){let i=$n(n);return i.blocked?{ok:!1,reason:`aponta p/ IP interno (${i.reason})`}:{ok:!0,host:n,pinnedIp:i.canonical}}let r;try{r=await e.resolve(n)}catch{return{ok:!1,reason:`host "${n}" n\xE3o resolveu (anti-SSRF, fail-safe)`}}let s=ei(r);return s.ok?{ok:!0,host:n,pinnedIp:s.pinnedIp}:{ok:!1,reason:`aponta p/ IP interno (${s.reason})`}}function YS(t){return!!(t.includes(":")||/^\d+$/.test(t)||/^0x[0-9a-fA-F]+$/.test(t)||/^(\d{1,3}\.){1,3}\d{1,3}$/.test(t)||/^0[0-7]+(\.|$)/.test(t))}var VS=S(()=>{"use strict";Ma()});function fr(){return{entries:QS(hD)}}function mr(t){if(typeof t!="string")return!1;let e=t.trim();return e===""||e.length>gD?!1:!kD.test(e)}function xD(t){let e=Array.isArray(t)?t:t!==void 0?[t]:[],o=[];for(let n of e)if(typeof n=="string"){let r=n.trim().toLowerCase();vD.includes(r)&&!o.includes(r)&&o.push(r)}return o.length>0?o:void 0}function SD(t){if(!Array.isArray(t))return[];let e=[];for(let o of t){if(mr(o)){let n=o.trim();e.includes(n)||e.push(n)}if(e.length>=yD)break}return e}function wD(t){return t===1||t===2||t===3?t:void 0}function XS(t){if(typeof t!="object"||t===null)return;let e=t;if(!mr(e.id))return;let o=e.id.trim();if(!mr(e.wireFormat))return;let n=e.wireFormat.trim().toLowerCase();if(!bD.includes(n)||!mr(e.baseUrl))return;let r=xD(e.auth);if(r===void 0||!mr(e.defaultModel))return;let s=mr(e.label)?e.label.trim():o,i={id:o,label:s,wireFormat:n,baseUrl:e.baseUrl.trim(),auth:r,defaultModel:e.defaultModel.trim(),models:SD(e.models)},a=wD(e.wave);return a!==void 0&&(i.wave=a),mr(e.catalogHint)&&(i.catalogHint=e.catalogHint.trim()),mr(e.notes)&&(i.notes=e.notes.trim()),i}function JS(t){let e=Array.isArray(t)?t:typeof t=="object"&&t!==null&&Array.isArray(t.providers)?t.providers:[],o=new Map;for(let n of e){let r=XS(n);r!==void 0&&o.set(r.id,r)}return[...o.values()]}function QS(t){return[...t].sort((e,o)=>{let n=e.wave??99,r=o.wave??99;return n!==r?n-r:e.id.localeCompare(o.id)})}function ZS(t,e){let o=new Map;for(let n of t.entries)o.set(n.id,n);for(let n of e)o.set(n.id,n);return{entries:QS([...o.values()])}}function eh(t){let e=fr();return t==null?e:ZS(e,JS(t))}function Fn(t,e){let o=e.trim().toLowerCase();return t.entries.find(n=>n.id.toLowerCase()===o)}var hD,gD,yD,bD,vD,kD,ew=S(()=>{"use strict";hD=[{id:"anthropic",label:"Anthropic",wireFormat:"anthropic",baseUrl:"https://api.anthropic.com",auth:["apikey","oauth"],defaultModel:"claude-opus-4-8",models:["claude-opus-4-8","claude-3-5-sonnet-latest","claude-3-5-haiku-latest"],wave:1},{id:"openai",label:"OpenAI",wireFormat:"openai-compat",baseUrl:"https://api.openai.com/v1",auth:["apikey","oauth"],defaultModel:"gpt-4o",models:["gpt-4o","gpt-4o-mini","o3","o3-mini","o4-mini"],wave:1},{id:"openrouter",label:"OpenRouter",wireFormat:"openai-compat",baseUrl:"https://openrouter.ai/api/v1",auth:["apikey"],defaultModel:"anthropic/claude-3.5-sonnet",models:["anthropic/claude-3.5-sonnet","openai/gpt-4o","google/gemini-2.0-flash","meta-llama/llama-3.3-70b-instruct","deepseek/deepseek-chat"],wave:1,catalogHint:"centenas via OpenRouter (veja o cat\xE1logo p\xFAblico do provider)"},{id:"google",label:"Google Gemini",wireFormat:"gemini",baseUrl:"https://generativelanguage.googleapis.com/v1beta",auth:["apikey"],defaultModel:"gemini-2.0-flash",models:["gemini-2.0-flash","gemini-2.0-pro","gemini-1.5-pro"],wave:2},{id:"deepseek",label:"DeepSeek",wireFormat:"openai-compat",baseUrl:"https://api.deepseek.com",auth:["apikey"],defaultModel:"deepseek-chat",models:["deepseek-chat","deepseek-reasoner"],wave:2},{id:"groq",label:"Groq",wireFormat:"openai-compat",baseUrl:"https://api.groq.com/openai/v1",auth:["apikey"],defaultModel:"llama-3.3-70b-versatile",models:["llama-3.3-70b-versatile","llama-3.1-8b-instant","mixtral-8x7b-32768"],wave:2},{id:"mistral",label:"Mistral",wireFormat:"openai-compat",baseUrl:"https://api.mistral.ai/v1",auth:["apikey"],defaultModel:"mistral-large-latest",models:["mistral-large-latest","mistral-small-latest","codestral-latest"],wave:2},{id:"xai",label:"xAI (Grok)",wireFormat:"openai-compat",baseUrl:"https://api.x.ai/v1",auth:["apikey"],defaultModel:"grok-2-latest",models:["grok-2-latest","grok-2-vision-latest"],wave:3},{id:"ollama",label:"Ollama (local)",wireFormat:"openai-compat",baseUrl:"http://127.0.0.1:11434/v1",auth:["none"],defaultModel:"llama3.2",models:["llama3.2","qwen2.5-coder","deepseek-r1"],wave:3,notes:"roda local; sem credencial (auth none). O egress local ainda \xE9 pinado/validado."}];gD=256,yD=200,bD=["openai-compat","anthropic","gemini"],vD=["apikey","oauth","none"],kD=/[\u0000-\u001F\u007F]/});var tw=S(()=>{"use strict";lS();uS();Wp();hS();yS();GS();VS();ew()});var ow,La,th=S(()=>{"use strict";mo();Ta();ow="/v1/quota",La=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async fetchQuota(){let e;try{e=await this.getAccessToken()}catch{return}let o;try{o=await this.doFetch(`${this.baseUrl}${ow}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch{return}if(!o.ok)return;let n;try{n=await o.json()}catch{return}return Id(n)}async fetchQuotaOrThrow(){let e=await this.getAccessToken(),o;try{o=await this.doFetch(`${this.baseUrl}${ow}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch(r){throw new Pe("falha de transporte ao ler a quota do broker.",r)}if(!o.ok){let r;try{r=await o.json()}catch{r=void 0}throw new Le(uo(o.status,r))}let n;try{n=await o.json()}catch(r){throw new Pe("quota do broker com corpo inv\xE1lido.",r)}return Id(n)}}});function nh(t){if(t===void 0)return;let e=uw(t.balance_after),o=AD(t.limits);if(!(e===void 0&&o===void 0))return{...o??{},...e!==void 0?{balanceAfter:e}:{}}}function AD(t){if(t==null||typeof t!="object")return;let e=oh(t.limit),o=oh(t.used),n=oh(t.remaining),r=ED(t.unit),s=TD(t.period),i=Aa(t.reset_at);if(e!==void 0&&(n===void 0&&o!==void 0&&(n=Math.max(0,e-o)),o===void 0&&n!==void 0&&(o=Math.max(0,e-n))),!(e===void 0&&o===void 0&&n===void 0&&s===void 0&&i===void 0))return{...e!==void 0?{limit:e}:{},...o!==void 0?{used:o}:{},...n!==void 0?{remaining:n}:{},...r!==void 0?{unit:r}:{},...s!==void 0?{period:s}:{},...i!==void 0?{resetAt:i}:{}}}function sw(t){if(t!==void 0&&t.unit!=="credit")return t.limit!==void 0&&t.limit>0?t.limit:void 0}function cw(t){return t>=aw?"crit":t>=iw?"warn":"ok"}function lw(t){if(t===void 0||t.limit===void 0||t.limit<=0)return;let e=t.used!==void 0?t.used:t.remaining!==void 0?Math.max(0,t.limit-t.remaining):void 0;if(e!==void 0)return Math.min(100,Math.max(0,Math.floor(e/t.limit*100)))}function Fd(t,e=dw){return t===void 0||t.balanceAfter===void 0?!1:t.balanceAfter<=e}function Bd(t){if(t===void 0||t.balanceAfter===void 0)return;let e=t.balanceAfter;return Number.isInteger(e)?String(e):String(Math.round(e*100)/100)}function rh(t,e=Date.now()){if(t===void 0)return;let o=[],n="ok",r=lw(t);if(r!==void 0&&sw(t)!==void 0){let a=cw(r),c=t.period!==void 0?t.period:"quota";o.push({label:c,value:`${r}%`,level:a}),n=rw(n,a)}let s=Bd(t);if(s!==void 0){let a=Fd(t)?"crit":"ok";o.push({label:"cr\xE9dito",value:s,level:a}),n=rw(n,a)}if(o.length===0)return;let i;if(t.resetAt!==void 0){let a=wa(t.resetAt,e);i=a==="agora"?"reseta agora":`reseta em ${a}`}return{segments:o,...i!==void 0?{resetText:i}:{},maxLevel:n}}function rw(t,e){return nw[e]>nw[t]?e:t}function uw(t){if(t==null||t==="")return;let e=typeof t=="number"?t:Number(String(t).trim());return Number.isFinite(e)?e:void 0}function oh(t){let e=uw(t);if(!(e===void 0||e<0))return Math.round(e)}function ED(t){if(t==null)return;let e=String(t).trim().toLowerCase();if(e==="credit"||e==="credits"||e==="currency")return"credit";if(e==="tokens"||e==="token")return"tokens"}function TD(t){if(t==null)return;let e=String(t).trim();if(e!=="")return e.length>16?e.slice(0,16):e}var iw,aw,dw,nw,mw=S(()=>{"use strict";Ta();iw=70,aw=90;dw=1;nw={ok:0,warn:1,crit:2}});function fw(t){let e=sh(t)?t.data:void 0;if(!Array.isArray(e))return[];let o=[];for(let n of e){if(!sh(n))continue;let r=Xr(n,"key");r===void 0||r===""||o.push({key:r,displayName:Xr(n,"display_name")??r,costSignal:Xr(n,"cost_signal")??"standard",composition:RD(n.composition)})}return o}function RD(t){if(!Array.isArray(t))return[];let e=[];for(let o of t){if(!sh(o))continue;let n=Xr(o,"name");n===void 0||n===""||e.push({name:n,family:Xr(o,"family")??"",role:Xr(o,"role")??"principal",context:Xr(o,"context")??""})}return e}function sh(t){return typeof t=="object"&&t!==null}function Xr(t,e){let o=t[e];return typeof o=="string"?o:void 0}var _D,Pa,ih=S(()=>{"use strict";mo();_D="/v1/tiers/catalog",Pa=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async list(){let e=await this.getAccessToken(),o;try{o=await this.doFetch(`${this.baseUrl}${_D}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch(r){throw new Pe("falha de transporte ao ler o cat\xE1logo do broker.",r)}if(!o.ok){let r;try{r=await o.json()}catch{r=void 0}throw new Le(uo(o.status,r))}let n;try{n=await o.json()}catch(r){throw new Pe("cat\xE1logo do broker com corpo inv\xE1lido.",r)}return fw(n)}}});function hw(t){let e=pw(t)?t.data:void 0;if(!Array.isArray(e))return[];let o=[],n=new Set;for(let r of e){if(!pw(r))continue;let s=Ud(r,"id");if(s===void 0||s===""||n.has(s))continue;n.add(s);let i=OD(r,"supports_tools");o.push({id:s,name:Ud(r,"name")??"",family:Ud(r,"family")??"",context:Ud(r,"context")??"",...i===void 0?{}:{supportsTools:i}})}return o}function pw(t){return typeof t=="object"&&t!==null}function Ud(t,e){let o=t[e];return typeof o=="string"?o:void 0}function OD(t,e){let o=t[e];return typeof o=="boolean"?o:void 0}var CD,Na,ah=S(()=>{"use strict";mo();CD="/v1/models/custom",Na=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async list(){let e=await this.getAccessToken(),o;try{o=await this.doFetch(`${this.baseUrl}${CD}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch(r){throw new Pe("falha de transporte ao ler a lista de modelos custom do broker.",r)}if(!o.ok){let r;try{r=await o.json()}catch{r=void 0}throw new Le(uo(o.status,r))}let n;try{n=await o.json()}catch(r){throw new Pe("lista de modelos custom do broker com corpo inv\xE1lido.",r)}return hw(n)}}});function bw(t){let e=gw(t)?t.data:void 0;if(!Array.isArray(e))return[];let o=[],n=new Set;for(let r of e){if(!gw(r))continue;let s=yw(r,"name");s===void 0||s===""||n.has(s)||(n.add(s),o.push({name:s,adapter:yw(r,"adapter")??""}))}return o}function gw(t){return typeof t=="object"&&t!==null}function yw(t,e){let o=t[e];return typeof o=="string"?o:void 0}var MD,Ia,ch=S(()=>{"use strict";mo();MD="/v1/providers",Ia=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async list(){let e=await this.getAccessToken(),o;try{o=await this.doFetch(`${this.baseUrl}${MD}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch(r){throw new Pe("falha de transporte ao ler a lista de providers do broker.",r)}if(!o.ok){let r;try{r=await o.json()}catch{r=void 0}throw new Le(uo(o.status,r))}let n;try{n=await o.json()}catch(r){throw new Pe("lista de providers do broker com corpo inv\xE1lido.",r)}return bw(n)}}});function Da(t){return new _a({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}function lh(t){return new Pa({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}function dh(t){return new Na({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}function uh(t){return new Ia({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}function mh(t){return new La({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}var vw=S(()=>{"use strict";$d();ih();ah();ch();th()});var kw=S(()=>{"use strict"});function $a(){return[{kind:"keep",id:"keep"},...xw.map(t=>({kind:"level",value:t,id:t})),{kind:"custom",id:"custom"}]}function Sw(){return $a().length}function ti(t){return Math.min(Math.max(0,t),Sw()-1)}function ww(t){return t.trim()}function jd(t){let e=ww(t);return e===""?{ok:!1,reason:"empty"}:e.length>32?{ok:!1,reason:"too-long"}:{ok:!0,value:e}}function fh(t){let e=$a()[t];return e===void 0?null:e.kind==="keep"?{kind:"keep"}:e.kind==="level"&&e.value!==void 0?{kind:"set",value:e.value}:null}function ph(t){let e=jd(t);return e.ok?{kind:"set",value:e.value}:null}var xw,Aw=S(()=>{"use strict";xw=["low","medium","high"]});var Ew=S(()=>{"use strict";aS();mo();tw();Ta();th();mw();Od();$d();vw();ih();ah();ch();kw();Aw()});function Hd(t){let e=null;for(let o of _w){let n=t.indexOf(o.open);if(n===-1||e!==null&&n>=e.openIdx)continue;let r=t.indexOf(o.close,n+o.open.length);e={format:o,openIdx:n,closeIdx:r}}return e}function Rw(t){let e=Ow(t),o=Hd(e);if(o===null)return{kind:"final",text:t};if(o.closeIdx===-1)return{kind:"malformed",reason:`bloco de tool-call aberto (${o.format.open}) sem fechamento (${o.format.close}).`,text:t};let n=e.slice(o.openIdx+o.format.open.length,o.closeIdx).trim(),r;try{r=JSON.parse(n)}catch{return{kind:"malformed",reason:"o miolo do bloco de tool-call n\xE3o \xE9 JSON v\xE1lido.",text:t}}if(typeof r!="object"||r===null)return{kind:"malformed",reason:"tool-call n\xE3o \xE9 um objeto JSON.",text:t};let s=r,i=s.name;if(typeof i!="string"||i.length===0)return{kind:"malformed",reason:'tool-call sem campo "name" (string n\xE3o-vazia).',text:t};let a=typeof s.input=="object"&&s.input!==null&&!Array.isArray(s.input)?s.input:{};return{kind:"tool_call",call:{name:i,input:a},text:t}}function Tw(t){let e=Hd(t);if(e===null)return t;let o=t.slice(0,e.openIdx),n=e.closeIdx===-1?"":t.slice(e.closeIdx+e.format.close.length),r=o.replace(/\s+$/,""),s=n.replace(/^\s+/,"");return r!==""&&s!==""?`${r}
|
|
30
|
+
`)}:null}var Od=S(()=>{"use strict"});function ES(t=globalThis.process?.env??{}){let e=kS(t[SS]),o=kS(t[wS]);return{maxConsecutiveLineRepeats:e!==void 0?Math.max(3,e):25,maxCycleLen:80,minCycleSpanChars:o!==void 0?Math.max(200,o):2e3,trivialLineMaxLen:1}}function TS(t=globalThis.process?.env??{}){let e=(t[AS]??"").trim().toLowerCase();return!(e==="1"||e==="true"||e==="yes"||e==="on")}function _S(t,e,o){let n=t.length;if(!(n<o))for(let r=1;r<=e&&!(r*2>n);r++){let s=r;for(;s<n&&t.charCodeAt(n-1-s)===t.charCodeAt(n-1-s%r);)s++;if(s>=o&&s>=r*2){let i=t.slice(n-r);return{period:r,unit:i,repeats:Math.floor(s/r)}}}}function zr(t,e){return TS(t)?new Ld(ES(t),e):QI}function Md(t){let e=t.replace(/\s+/g," ").trim();return e.length<=vS?e:`${e.slice(0,vS)}\u2026`}function kS(t){if(t===void 0)return;let e=t.trim();if(e==="")return;let o=Number(e);if(!(!Number.isFinite(o)||o<=0))return Math.floor(o)}var xS,SS,wS,AS,Gr,vS,Ld,QI,xa=S(()=>{"use strict";xS={maxConsecutiveLineRepeats:25,maxCycleLen:80,minCycleSpanChars:2e3,trivialLineMaxLen:1},SS="ALUY_DEGENERATE_LINE_REPEATS",wS="ALUY_DEGENERATE_CYCLE_SPAN",AS="ALUY_DEGENERATE_OFF";Gr=class extends Error{kind;repeats;sample;constructor(e,o,n){super(`loop de repeti\xE7\xE3o degenerado detectado (${e}, ${o}\xD7)`),this.name="DegenerateLoopError",this.kind=e,this.repeats=o,this.sample=n}},vS=60,Ld=class{cfg;bus;lineBuf="";lastLine;lineRepeatCount=1;tail="";tailMax;constructor(e=xS,o){this.cfg=e,this.bus=o,this.tailMax=e.minCycleSpanChars+e.maxCycleLen+1}push(e){e.length!==0&&(this.pushForLineHeuristic(e),this.pushForCycleHeuristic(e))}pushForLineHeuristic(e){let o=0;for(let n=0;n<e.length;n++)e.charCodeAt(n)===10&&(this.lineBuf+=e.slice(o,n),this.commitLine(this.lineBuf),this.lineBuf="",o=n+1);o<e.length&&(this.lineBuf+=e.slice(o))}commitLine(e){let o=e.trim();if(o.length<=this.cfg.trivialLineMaxLen){this.lastLine=void 0,this.lineRepeatCount=1;return}if(o===this.lastLine){if(this.lineRepeatCount+=1,this.lineRepeatCount>=this.cfg.maxConsecutiveLineRepeats)throw this.bus?.publish({origin:"degeneration",severity:"warning",ts:Date.now(),payload:{kind:"line-repeat",repeats:this.lineRepeatCount,sample:Md(o)}}),new Gr("line-repeat",this.lineRepeatCount,Md(o))}else this.lastLine=o,this.lineRepeatCount=1}pushForCycleHeuristic(e){if(this.tail+=e,this.tail.length>this.tailMax&&(this.tail=this.tail.slice(this.tail.length-this.tailMax)),this.tail.length<this.cfg.minCycleSpanChars)return;let o=_S(this.tail,this.cfg.maxCycleLen,this.cfg.minCycleSpanChars);if(o)throw this.bus?.publish({origin:"degeneration",severity:"critical",ts:Date.now(),payload:{kind:"short-cycle",repeats:o.repeats,sample:Md(o.unit)}}),new Gr("short-cycle",o.repeats,Md(o.unit))}};QI={push(){}}});function ZI(t){if(t===void 0)return;let e=t.trim();if(e==="")return;let o=Number(e);if(!(!Number.isFinite(o)||o<=0))return Math.floor(o)}function eD(t){let e=t[CS]?.trim().toLowerCase();return e==="1"||e==="true"||e==="yes"||e==="on"}function Yr(t=process.env){return eD(t)?new Sa(0):new Sa(ZI(t[RS])??25165824)}var RS,CS,Kr,Sa,Pd=S(()=>{"use strict";RS="ALUY_STREAM_MAX_BYTES",CS="ALUY_STREAM_CAP_OFF",Kr="length_client_cap",Sa=class{max;total=0;_tripped=!1;constructor(e=25165824){this.max=e>0?Math.floor(e):0}get tripped(){return this._tripped}get bytes(){return this.total}get limit(){return this.max}addText(e){return this.addBytes(Buffer.byteLength(e,"utf8"))}addToolCall(e){let o=0;try{o=Buffer.byteLength(JSON.stringify(e.input??{}),"utf8")}catch{o=256}return this.addBytes(Buffer.byteLength(e.id,"utf8")+Buffer.byteLength(e.name,"utf8")+o)}addBytes(e){return this.max<=0?!1:(this.total+=e>0?e:0,this.total>this.max&&(this._tripped=!0),this._tripped)}}});function Id(t){if(!Dd(t))return;let{fiveHour:e,week:o}=tD(t.windows),n=oD(t.credit);return{windows:{...e!==void 0?{fiveHour:e}:{},...o!==void 0?{week:o}:{}},...n!==void 0?{credit:n}:{}}}function Gp(t){if(!Dd(t))return;let e=OS(t,"quota_5h"),o=OS(t,"quota_week");if(!(e===void 0&&o===void 0))return{windows:{...e!==void 0?{fiveHour:e}:{},...o!==void 0?{week:o}:{}}}}function PS(t,e,o){if(!(e===void 0||e<=0))return{used:Math.max(0,t??0),limit:e,...o!==void 0?{resetAt:o}:{}}}function tD(t){if(!Array.isArray(t))return{};let e={};for(let o of t){if(!Dd(o))continue;let n=NS(o.period);if(n===void 0)continue;let r=PS(Nd(o.used),Nd(o.limit),Aa(o.reset_at??o.resetAt));r!==void 0&&(n==="5h"?e.fiveHour=r:(n==="week"||n==="weekly")&&(e.week=r))}return e}function OS(t,e){return PS(Nd(t[`${e}_used`]),Nd(t[`${e}_limit`]),Aa(t[`${e}_reset_at`]))}function oD(t){if(!Dd(t))return;let e=NS(t.balance);return e!==void 0?{balance:e}:void 0}function Nd(t){if(t==null)return;let e=typeof t=="number"?t:String(t).trim();if(e==="")return;let o=typeof e=="number"?e:Number(e);if(!(!Number.isFinite(o)||o<0))return Math.round(o)}function NS(t){if(typeof t!="string")return;let e=t.trim();return e===""?void 0:e}function Aa(t){if(t==null)return;if(typeof t=="number")return MS(t);let e=String(t).trim();if(e==="")return;if(/^\d+(\.\d+)?$/.test(e)){let n=Number(e);return Number.isFinite(n)?MS(n):void 0}let o=Date.parse(e);return Number.isFinite(o)?o:void 0}function MS(t){if(!(!Number.isFinite(t)||t<=0))return t<1e12?Math.round(t*1e3):Math.round(t)}function IS(t){return t.limit<=0?0:Math.min(100,Math.max(0,Math.floor(t.used/t.limit*100)))}function wa(t,e=Date.now()){let o=t-e;if(!Number.isFinite(o)||o<=0)return"agora";let n=Math.floor(o/6e4);if(n<1)return"agora";let r=Math.floor(n/60),s=n%60;return r===0?`${s}min`:`${r}h${String(s).padStart(2,"0")}`}function FS(t){return t>=$S?"crit":t>=DS?"warn":"ok"}function Ea(t,e=Date.now()){if(t===void 0)return;let o=[],n,r="ok",s=(c,l)=>{if(l===void 0)return;let d=IS(l),f=FS(d);o.push({label:c,pct:d,level:f}),n===void 0&&l.resetAt!==void 0&&(n=l),r=nD(r,f)};s("5h",t.windows.fiveHour),s("semana",t.windows.week);let i=t.credit?.balance;if(o.length===0&&i===void 0)return;let a=n?.resetAt!==void 0?wa(n.resetAt,e)==="agora"?"reseta agora":`reseta em ${wa(n.resetAt,e)}`:void 0;return{segments:o,...i!==void 0?{creditBalance:i}:{},...a!==void 0?{resetText:a}:{},maxLevel:r}}function nD(t,e){return LS[e]>LS[t]?e:t}function Dd(t){return typeof t=="object"&&t!==null}var DS,$S,LS,Ta=S(()=>{"use strict";DS=70,$S=90;LS={ok:0,warn:1,crit:2}});function jS(t,e){let o={tier:t.tier,messages:t.messages.map(sD),stream:e};t.session_id!==void 0&&(o.session_id=t.session_id),t.max_tokens!==void 0&&(o.max_tokens=t.max_tokens),t.temperature!==void 0&&(o.temperature=t.temperature),t.context!==void 0&&(o.context=t.context),t.tools!==void 0&&t.tools.length>0&&(o.tools=t.tools,o.tool_choice=t.tool_choice??"auto",t.parallel_tool_calls!==void 0&&(o.parallel_tool_calls=t.parallel_tool_calls));let n=t.model?.trim(),r=n!==void 0&&n!=="";r&&t.tier==="custom"&&(o.model=n);let s=t.provider?.trim();s!==void 0&&s!==""&&r&&t.tier==="custom"&&(o.provider=s);let a=t.reasoning_effort?.trim();return a!==void 0&&a!==""&&(o.reasoning_effort=a),o}function sD(t){let e={role:t.role,content:t.content};return t.tool_calls!==void 0&&t.tool_calls.length>0&&(e.tool_calls=t.tool_calls.map(o=>({id:o.id,type:"function",function:{name:o.name,arguments:JSON.stringify(o.input??{})}}))),t.tool_call_id!==void 0&&(e.tool_call_id=t.tool_call_id),e}function iD(t,e){let o=Yp(e);switch(t){case"start":return{type:"start",request_id:Vt(o,"request_id")??"",...Vt(o,"session_id")!==void 0?{session_id:Vt(o,"session_id")}:{}};case"delta":{let n=Vt(o,"content");return n!==void 0?{type:"delta",content:n}:null}case"tool_call":{let n=HS(o);return n!==null?{type:"tool_call",call:n}:null}case"usage":return{type:"usage",usage:aD(o)};case"done":return{type:"done",finish_reason:Vt(o,"finish_reason")??"stop"};case"error":throw new Le(uo(Kp(o,"status")??502,o));default:return null}}function aD(t){let e={request_id:Vt(t,"request_id")??"",tier:Vt(t,"tier")??""},o=Vt(t,"provider");o!==void 0&&(e.provider=o);let n=Vt(t,"model");n!==void 0&&(e.model=n);let r=Kp(t,"tokens_in");r!==void 0&&(e.tokens_in=r);let s=Kp(t,"tokens_out");s!==void 0&&(e.tokens_out=s);let i=Vt(t,"cost");i!==void 0&&(e.cost=i);let a=Vt(t,"price_version");a!==void 0&&(e.price_version=a);let c=lD(t,"partial");c!==void 0&&(e.partial=c);let l=Vt(t,"balance_after");return l!==void 0&&(e.balance_after=l),e}function HS(t){if(!ur(t))return null;let e=ur(t.function)?t.function:void 0,o=(typeof t.name=="string"?t.name:void 0)??Vt(e,"name");if(o===void 0||o.length===0)return null;let n=Vt(t,"id")??"",r={};return ur(t.input)?r=t.input:e!==void 0&&e.arguments!==void 0?r=BS(e.arguments):t.arguments!==void 0&&(r=BS(t.arguments)),{id:n,name:o,input:r}}function BS(t){if(ur(t))return t;if(typeof t=="string"&&t.trim()!==""){let e=Yp(t);if(ur(e))return e}return{}}function Zs(t,e){if(e.id!==""){let o=t.find(n=>n.id===e.id);if(o!==void 0){let n=t.indexOf(o);t[n]={id:o.id,name:e.name.length>0?e.name:o.name,input:{...o.input,...e.input}};return}}t.push(e)}function cD(t,e){if(t===null)return;let o=t.trim();if(o==="")return;if(/^\d+$/.test(o)){let s=Number(o);return Number.isFinite(s)?s:void 0}let n=Date.parse(o);if(!Number.isFinite(n))return;let r=Math.round((n-e)/1e3);return r>=0?r:0}function Yp(t){try{return JSON.parse(t)}catch{return}}function ur(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Vt(t,e){if(!ur(t))return;let o=t[e];return typeof o=="string"?o:void 0}function Kp(t,e){if(!ur(t))return;let o=t[e];return typeof o=="number"?o:void 0}function lD(t,e){if(!ur(t))return;let o=t[e];return typeof o=="boolean"?o:void 0}function zp(t){if(t?.aborted)throw new ze}function US(t){return typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError"}var rD,_a,$d=S(()=>{"use strict";mo();Od();xa();Pd();Ta();rD="/v1/chat",_a=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async*stream(e){let{request:o,signal:n,idempotencyKey:r}=e;zp(n);let s=await this.getAccessToken();zp(n);let i=await this.send(s,o,n,!0,r);if(!i.ok)throw await this.toBrokerError(i);if(i.body===null)throw new Pe("broker respondeu 2xx sem corpo de stream.");try{for await(let a of ka(i.body)){zp(n);let c=iD(a.event,a.data);if(c&&(yield c),a.event==="usage"){let l=Gp(Yp(a.data));l!==void 0&&(yield{type:"quota",quota:l})}if(a.event==="done")return}}catch(a){throw US(a)||a instanceof ze?new ze:a instanceof Le?a:new Pe("falha ao ler o stream do broker.",a)}}async call(e){let o="",n="",r,s="stop",i,a,c=[],l=zr(),d=Yr(),f=!1;for await(let u of this.stream(e)){switch(u.type){case"start":n=u.request_id,r=u.session_id;break;case"delta":o+=u.content,l.push(u.content),d.addText(u.content)&&(f=!0);break;case"tool_call":Zs(c,u.call),d.addToolCall(u.call)&&(f=!0);break;case"usage":i=u.usage;break;case"quota":a=u.quota;break;case"done":s=u.finish_reason;break}if(f){s=Kr;break}}return{request_id:n,...r!==void 0?{session_id:r}:{},content:o,finish_reason:s,...i!==void 0?{usage:i}:{},...c.length>0?{tool_calls:c}:{},...a!==void 0?{quota:a}:{}}}async send(e,o,n,r,s){let i=jS(o,r),a={authorization:`Bearer ${e}`,"content-type":"application/json",accept:"text/event-stream"};s!==void 0&&(a["idempotency-key"]=s);try{return await this.doFetch(`${this.baseUrl}${rD}`,{method:"POST",headers:a,body:JSON.stringify(i),...n?{signal:n}:{}})}catch(c){throw US(c)?new ze:new Pe("falha de transporte ao chamar o broker.",c)}}async toBrokerError(e){let o;try{o=await e.json()}catch{o=void 0}let n=uo(e.status,o);if(n.retry_after===void 0){let r=cD(e.headers.get("retry-after"),Date.now());if(r!==void 0)return new Le({...n,retry_after:r})}return new Le(n)}}});function uD(t,e){if(t===401||t===403)return"UNAUTHENTICATED";if(t===429)return"RATE_LIMITED";let o=(WS(e)??"").toLowerCase();return(t===400||t===422)&&(o.includes("tool")||o.includes("function calling")||o.includes("function_call"))?"TOOLS_UNSUPPORTED":t>=500?"PROVIDER_ERROR":t===400||t===422?"VALIDATION_FAILED":"PROVIDER_ERROR"}function WS(t){if(typeof t!="object"||t===null)return;let e=t;if(typeof e.message=="string")return e.message;let o=e.error;if(typeof o=="string")return o;if(typeof o=="object"&&o!==null){let n=o.message;if(typeof n=="string")return n}}function Vp(t){if(t?.aborted)throw new ze}function qS(t){return typeof t=="object"&&t!==null&&"name"in t&&t.name==="AbortError"}var dD,Ra,GS=S(()=>{"use strict";mo();Od();xa();Pd();$d();Wp();dD=8192,Ra=class{adapter;config;baseUrl;getCredential;doFetch;maxTokens;constructor(e){this.adapter=e.adapter,this.config=e.config,this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getCredential=e.getCredential,this.doFetch=e.fetch??globalThis.fetch,this.maxTokens=e.maxTokens??dD}async*stream(e){let{request:o,signal:n}=e;Vp(n);let r=await this.getCredential();Vp(n);let s=this.toLocalRequest(o),i=this.adapter.buildRequest({request:s,baseUrl:this.baseUrl,credential:r}),a;try{a=await this.doFetch(i.url,{method:"POST",headers:i.headers,body:i.body,redirect:"error",...n?{signal:n}:{}})}catch(l){throw qS(l)?new ze:new Pe("falha de transporte ao chamar o provider (backend local).",l)}if(!a.ok)throw await this.toProviderError(a);if(a.body===null)throw new Pe("provider respondeu 2xx sem corpo de stream.");let c=qp();try{for await(let l of ka(a.body)){Vp(n);let d=this.adapter.mapSse(l.event,l.data,c);for(let f of d)if(yield f,f.type==="done")return}}catch(l){throw qS(l)||l instanceof ze?new ze:l instanceof Le?l:new Pe("falha ao ler o stream do provider (backend local).",l)}}async call(e){let o="",n="",r="stop",s,i=[],a=zr(),c=Yr(),l=!1;for await(let d of this.stream(e)){switch(d.type){case"start":n=d.request_id;break;case"delta":o+=d.content,a.push(d.content),c.addText(d.content)&&(l=!0);break;case"tool_call":Zs(i,d.call),c.addToolCall(d.call)&&(l=!0);break;case"usage":s=d.usage;break;case"done":r=d.finish_reason;break}if(l){r=Kr;break}}return{request_id:n,content:o,finish_reason:r,...s!==void 0?{usage:s}:{},...i.length>0?{tool_calls:i}:{}}}toLocalRequest(e){let o,n=[];for(let a of e.messages){if(a.role==="system"&&o===void 0){o=a.content;continue}n.push({role:a.role,content:a.content,...a.tool_calls!==void 0?{tool_calls:a.tool_calls.map(c=>({id:c.id,name:c.name,input:{...c.input}}))}:{},...a.tool_call_id!==void 0?{tool_call_id:a.tool_call_id}:{}})}let r=e.tier==="custom"?e.model?.trim():void 0,i={model:r&&r.length>0?r:this.config.model,messages:n,maxTokens:e.max_tokens??this.maxTokens};return o!==void 0&&(i.system=o),e.temperature!==void 0&&(i.temperature=e.temperature),e.reasoning_effort!==void 0&&(i.reasoningEffort=e.reasoning_effort),e.tools!==void 0&&e.tools.length>0&&(i.tools=e.tools,i.toolChoice=e.tool_choice??"auto"),i}async toProviderError(e){let o;try{o=await e.json()}catch{o=void 0}let n=WS(o),r=uD(e.status,o),s=r==="TOOLS_UNSUPPORTED"?422:e.status,i=uo(s,{code:r,...n!==void 0?{detail:n}:{}});return new Le(i)}}});function Vr(t){let e=t.trim();if(e==="")return;let o=e.split(".");if(o.length===0||o.length>4)return;let n=[];for(let d of o){let f=mD(d);if(f===void 0)return;n.push(f)}let r,s=n.length;if(s===1){if(r=n[0],r>4294967295)return}else{let d=0;for(let h=0;h<s-1;h++){let g=n[h];if(g>255)return;d=d*256+g}let f=n[s-1],u=4-(s-1),p=Math.pow(256,u)-1;if(f>p)return;r=d*Math.pow(256,u)+f}if(r<0||r>4294967295)return;let i=r>>>24&255,a=r>>>16&255,c=r>>>8&255,l=r&255;return`${i}.${a}.${c}.${l}`}function mD(t){if(t==="")return;let e;if(/^0[xX][0-9a-fA-F]+$/.test(t))e=parseInt(t.slice(2),16);else if(/^0[0-7]+$/.test(t))e=parseInt(t,8);else if(/^[0-9]+$/.test(t))e=parseInt(t,10);else return;return Number.isFinite(e)?e:void 0}function Ca(t){let e=t.trim().toLowerCase();e=e.replace(/%.*$/,"").replace(/^\[/,"").replace(/\]$/,"");let o=e.match(/:((?:\d{1,3}\.){3}\d{1,3})$/);if(o&&(e.startsWith("::ffff:")||e.startsWith("::")))return Vr(o[1]);let n=e.match(/^::ffff:([0-9a-f]{1,4}):([0-9a-f]{1,4})$/);if(n){let r=parseInt(n[1],16),s=parseInt(n[2],16);if(Number.isFinite(r)&&Number.isFinite(s)){let i=r>>8&255,a=r&255,c=s>>8&255,l=s&255;return`${i}.${a}.${c}.${l}`}}}function Oa(t){let e=t.trim().replace(/^\[/,"").replace(/\]$/,"").replace(/%.*$/,"");return e.includes(":")&&/^[0-9a-fA-F:.]+$/.test(e)}function zS(t){let e=t.trim().toLowerCase().replace(/^\[/,"").replace(/\]$/,"").replace(/%.*$/,""),o=e.match(/((?:\d{1,3}\.){3}\d{1,3})$/);if(o){let c=Vr(o[1]);if(!c)return;let l=c.split(".").map(Number),d=(l[0]<<8|l[1]).toString(16),f=(l[2]<<8|l[3]).toString(16);e=e.slice(0,o.index)+d+":"+f}let n=e.split("::");if(n.length>2)return;let r=n[0]?n[0].split(":").filter(c=>c!==""):[],s=n.length===2&&n[1]?n[1].split(":").filter(c=>c!==""):[],i=[];for(let c of r){let l=parseInt(c,16);if(!/^[0-9a-f]{1,4}$/.test(c)||!Number.isFinite(l))return;i.push(l)}let a=8-r.length-s.length;if(n.length===2){if(a<0)return;for(let c=0;c<a;c++)i.push(0)}else if(r.length!==8)return;for(let c of s){let l=parseInt(c,16);if(!/^[0-9a-f]{1,4}$/.test(c)||!Number.isFinite(l))return;i.push(l)}return i.length===8?i:void 0}function $n(t){let e=t.trim();if(e==="")return{blocked:!0,reason:"IP vazio",canonical:e};let o=Ca(e);if(o){let r=Xp(o);return r.blocked?{...r,reason:`IPv4-mapped-IPv6 \u2192 ${r.reason}`}:r}if(Oa(e))return fD(e);let n=Vr(e);return n?Xp(n):{blocked:!0,reason:`IP n\xE3o-reconhecido: "${e}"`,canonical:e}}function Jp(t){let e=t.trim();if(e==="")return!1;let o=Ca(e);if(o)return o.split(".")[0]==="127";if(Oa(e)){let r=zS(e);return r?r.slice(0,7).every(s=>s===0)&&r[7]===1:!1}let n=Vr(e);return n?n.split(".")[0]==="127":!1}function Xp(t){let e=t.split(".").map(Number);if(e.length!==4||e.some(s=>!Number.isInteger(s)||s<0||s>255))return{blocked:!0,reason:`IPv4 inv\xE1lido: "${t}"`,canonical:t};let[o,n]=e,r=s=>({blocked:!0,reason:s,canonical:t});return t==="169.254.169.254"?r("endpoint de metadata da cloud (169.254.169.254)"):o===0?r("0.0.0.0/8 (este host / n\xE3o-rote\xE1vel)"):o===127?r("loopback (127.0.0.0/8)"):o===10?r("rede privada RFC1918 (10.0.0.0/8)"):o===172&&n>=16&&n<=31?r("rede privada RFC1918 (172.16.0.0/12)"):o===192&&n===168?r("rede privada RFC1918 (192.168.0.0/16)"):o===169&&n===254?r("link-local (169.254.0.0/16)"):o===100&&n>=64&&n<=127?r("CGNAT (100.64.0.0/10)"):o===198&&(n===18||n===19)?r("rede de benchmark (198.18.0.0/15)"):o>=224?r("multicast/reservado (\u2265224.0.0.0/4)"):t==="255.255.255.255"?r("broadcast (255.255.255.255)"):{blocked:!1,canonical:t}}function fD(t){let e=zS(t);if(!e)return{blocked:!0,reason:`IPv6 inv\xE1lido: "${t}"`,canonical:t};let o=e.map(c=>c.toString(16)).join(":"),n=c=>({blocked:!0,reason:c,canonical:o});if(e.slice(0,7).every(c=>c===0)&&e[7]===1)return n("loopback IPv6 (::1)");if(e.every(c=>c===0))return n("IPv6 unspecified (::)");let s=e[0],i=s>>8&255;if(i===252||i===253)return n("IPv6 ULA privada (fc00::/7)");if((s&65472)===65152)return n("IPv6 link-local (fe80::/10)");if(i===255)return n("IPv6 multicast (ff00::/8)");let a=pD(e);if(a){let c=Xp(a.ipv4);if(c.blocked)return{blocked:!0,reason:`IPv6 ${a.kind} \u2192 ${c.reason}`,canonical:o}}return{blocked:!1,canonical:o}}function pD(t){let e=t,o=(n,r)=>`${n>>8&255}.${n&255}.${r>>8&255}.${r&255}`;if(e[0]===100&&e[1]===65435&&e[2]===0&&e[3]===0&&e[4]===0&&e[5]===0)return{ipv4:o(e[6],e[7]),kind:"NAT64 (64:ff9b::/96)"};if(e[0]===100&&e[1]===65435&&e[2]===1)return{ipv4:o(e[6],e[7]),kind:"NAT64 (64:ff9b:1::/48)"};if(e[0]===8194)return{ipv4:o(e[1],e[2]),kind:"6to4 (2002::/16)"}}function ei(t){if(t.length===0)return{ok:!1,reason:"host n\xE3o resolveu para nenhum IP",offendingIp:""};for(let e of t){let o=$n(e);if(o.blocked)return{ok:!1,reason:o.reason??"IP bloqueado pela denylist anti-SSRF",offendingIp:o.canonical}}return{ok:!0,pinnedIp:$n(t[0]).canonical}}var Ma=S(()=>{"use strict"});function KS(t){let e;try{e=new URL(t)}catch{return{reason:`base_url inv\xE1lida: "${t}"`}}return e.protocol!=="https:"&&e.protocol!=="http:"?{reason:`base_url precisa ser http(s): "${t}"`}:e.hostname===""?{reason:`base_url sem host: "${t}"`}:{url:e}}async function Qp(t,e){let o=KS(t);if("reason"in o)return{ok:!1,reason:o.reason};let n=o.url.hostname.replace(/^\[/,"").replace(/\]$/,""),r=$n(n);if(r.blocked&&YS(n))return{ok:!1,reason:`base_url aponta p/ IP interno (${r.reason})`};let s;try{s=await e.resolve(n)}catch{return{ok:!1,reason:`base_url: host "${n}" n\xE3o resolveu (anti-SSRF, fail-safe)`}}let i=ei(s);return i.ok?{ok:!0,url:o.url.toString()}:{ok:!1,reason:`base_url aponta p/ IP interno (${i.reason})`}}async function Zp(t,e){let o=KS(t);if("reason"in o)return{ok:!1,reason:o.reason};let n=o.url.hostname.replace(/^\[/,"").replace(/\]$/,"");if(YS(n)){let i=$n(n);return i.blocked?{ok:!1,reason:`aponta p/ IP interno (${i.reason})`}:{ok:!0,host:n,pinnedIp:i.canonical}}let r;try{r=await e.resolve(n)}catch{return{ok:!1,reason:`host "${n}" n\xE3o resolveu (anti-SSRF, fail-safe)`}}let s=ei(r);return s.ok?{ok:!0,host:n,pinnedIp:s.pinnedIp}:{ok:!1,reason:`aponta p/ IP interno (${s.reason})`}}function YS(t){return!!(t.includes(":")||/^\d+$/.test(t)||/^0x[0-9a-fA-F]+$/.test(t)||/^(\d{1,3}\.){1,3}\d{1,3}$/.test(t)||/^0[0-7]+(\.|$)/.test(t))}var VS=S(()=>{"use strict";Ma()});function fr(){return{entries:QS(hD)}}function mr(t){if(typeof t!="string")return!1;let e=t.trim();return e===""||e.length>gD?!1:!kD.test(e)}function xD(t){let e=Array.isArray(t)?t:t!==void 0?[t]:[],o=[];for(let n of e)if(typeof n=="string"){let r=n.trim().toLowerCase();vD.includes(r)&&!o.includes(r)&&o.push(r)}return o.length>0?o:void 0}function SD(t){if(!Array.isArray(t))return[];let e=[];for(let o of t){if(mr(o)){let n=o.trim();e.includes(n)||e.push(n)}if(e.length>=yD)break}return e}function wD(t){return t===1||t===2||t===3?t:void 0}function XS(t){if(typeof t!="object"||t===null)return;let e=t;if(!mr(e.id))return;let o=e.id.trim();if(!mr(e.wireFormat))return;let n=e.wireFormat.trim().toLowerCase();if(!bD.includes(n)||!mr(e.baseUrl))return;let r=xD(e.auth);if(r===void 0||!mr(e.defaultModel))return;let s=mr(e.label)?e.label.trim():o,i={id:o,label:s,wireFormat:n,baseUrl:e.baseUrl.trim(),auth:r,defaultModel:e.defaultModel.trim(),models:SD(e.models)},a=wD(e.wave);return a!==void 0&&(i.wave=a),mr(e.catalogHint)&&(i.catalogHint=e.catalogHint.trim()),mr(e.notes)&&(i.notes=e.notes.trim()),i}function JS(t){let e=Array.isArray(t)?t:typeof t=="object"&&t!==null&&Array.isArray(t.providers)?t.providers:[],o=new Map;for(let n of e){let r=XS(n);r!==void 0&&o.set(r.id,r)}return[...o.values()]}function QS(t){return[...t].sort((e,o)=>{let n=e.wave??99,r=o.wave??99;return n!==r?n-r:e.id.localeCompare(o.id)})}function ZS(t,e){let o=new Map;for(let n of t.entries)o.set(n.id,n);for(let n of e)o.set(n.id,n);return{entries:QS([...o.values()])}}function eh(t){let e=fr();return t==null?e:ZS(e,JS(t))}function Fn(t,e){let o=e.trim().toLowerCase();return t.entries.find(n=>n.id.toLowerCase()===o)}var hD,gD,yD,bD,vD,kD,ew=S(()=>{"use strict";hD=[{id:"anthropic",label:"Anthropic",wireFormat:"anthropic",baseUrl:"https://api.anthropic.com",auth:["apikey","oauth"],defaultModel:"claude-opus-4-8",models:["claude-opus-4-8","claude-3-5-sonnet-latest","claude-3-5-haiku-latest"],wave:1},{id:"openai",label:"OpenAI",wireFormat:"openai-compat",baseUrl:"https://api.openai.com/v1",auth:["apikey","oauth"],defaultModel:"gpt-4o",models:["gpt-4o","gpt-4o-mini","o3","o3-mini","o4-mini"],wave:1},{id:"openrouter",label:"OpenRouter",wireFormat:"openai-compat",baseUrl:"https://openrouter.ai/api/v1",auth:["apikey"],defaultModel:"anthropic/claude-3.5-sonnet",models:["anthropic/claude-3.5-sonnet","openai/gpt-4o","google/gemini-2.0-flash","meta-llama/llama-3.3-70b-instruct","deepseek/deepseek-chat"],wave:1,catalogHint:"centenas via OpenRouter (veja o cat\xE1logo p\xFAblico do provider)"},{id:"google",label:"Google Gemini",wireFormat:"gemini",baseUrl:"https://generativelanguage.googleapis.com/v1beta",auth:["apikey"],defaultModel:"gemini-2.0-flash",models:["gemini-2.0-flash","gemini-2.0-pro","gemini-1.5-pro"],wave:2},{id:"deepseek",label:"DeepSeek",wireFormat:"openai-compat",baseUrl:"https://api.deepseek.com",auth:["apikey"],defaultModel:"deepseek-chat",models:["deepseek-chat","deepseek-reasoner"],wave:2},{id:"groq",label:"Groq",wireFormat:"openai-compat",baseUrl:"https://api.groq.com/openai/v1",auth:["apikey"],defaultModel:"llama-3.3-70b-versatile",models:["llama-3.3-70b-versatile","llama-3.1-8b-instant","mixtral-8x7b-32768"],wave:2},{id:"mistral",label:"Mistral",wireFormat:"openai-compat",baseUrl:"https://api.mistral.ai/v1",auth:["apikey"],defaultModel:"mistral-large-latest",models:["mistral-large-latest","mistral-small-latest","codestral-latest"],wave:2},{id:"xai",label:"xAI (Grok)",wireFormat:"openai-compat",baseUrl:"https://api.x.ai/v1",auth:["apikey"],defaultModel:"grok-2-latest",models:["grok-2-latest","grok-2-vision-latest"],wave:3},{id:"ollama",label:"Ollama (local)",wireFormat:"openai-compat",baseUrl:"http://127.0.0.1:11434/v1",auth:["none"],defaultModel:"llama3.2",models:["llama3.2","gemma3:4b","qwen2.5-coder","deepseek-r1"],wave:3,notes:"roda local; sem credencial (auth none). O egress local ainda \xE9 pinado/validado."}];gD=256,yD=200,bD=["openai-compat","anthropic","gemini"],vD=["apikey","oauth","none"],kD=/[\u0000-\u001F\u007F]/});var tw=S(()=>{"use strict";lS();uS();Wp();hS();yS();GS();VS();ew()});var ow,La,th=S(()=>{"use strict";mo();Ta();ow="/v1/quota",La=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async fetchQuota(){let e;try{e=await this.getAccessToken()}catch{return}let o;try{o=await this.doFetch(`${this.baseUrl}${ow}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch{return}if(!o.ok)return;let n;try{n=await o.json()}catch{return}return Id(n)}async fetchQuotaOrThrow(){let e=await this.getAccessToken(),o;try{o=await this.doFetch(`${this.baseUrl}${ow}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch(r){throw new Pe("falha de transporte ao ler a quota do broker.",r)}if(!o.ok){let r;try{r=await o.json()}catch{r=void 0}throw new Le(uo(o.status,r))}let n;try{n=await o.json()}catch(r){throw new Pe("quota do broker com corpo inv\xE1lido.",r)}return Id(n)}}});function nh(t){if(t===void 0)return;let e=uw(t.balance_after),o=AD(t.limits);if(!(e===void 0&&o===void 0))return{...o??{},...e!==void 0?{balanceAfter:e}:{}}}function AD(t){if(t==null||typeof t!="object")return;let e=oh(t.limit),o=oh(t.used),n=oh(t.remaining),r=ED(t.unit),s=TD(t.period),i=Aa(t.reset_at);if(e!==void 0&&(n===void 0&&o!==void 0&&(n=Math.max(0,e-o)),o===void 0&&n!==void 0&&(o=Math.max(0,e-n))),!(e===void 0&&o===void 0&&n===void 0&&s===void 0&&i===void 0))return{...e!==void 0?{limit:e}:{},...o!==void 0?{used:o}:{},...n!==void 0?{remaining:n}:{},...r!==void 0?{unit:r}:{},...s!==void 0?{period:s}:{},...i!==void 0?{resetAt:i}:{}}}function sw(t){if(t!==void 0&&t.unit!=="credit")return t.limit!==void 0&&t.limit>0?t.limit:void 0}function cw(t){return t>=aw?"crit":t>=iw?"warn":"ok"}function lw(t){if(t===void 0||t.limit===void 0||t.limit<=0)return;let e=t.used!==void 0?t.used:t.remaining!==void 0?Math.max(0,t.limit-t.remaining):void 0;if(e!==void 0)return Math.min(100,Math.max(0,Math.floor(e/t.limit*100)))}function Fd(t,e=dw){return t===void 0||t.balanceAfter===void 0?!1:t.balanceAfter<=e}function Bd(t){if(t===void 0||t.balanceAfter===void 0)return;let e=t.balanceAfter;return Number.isInteger(e)?String(e):String(Math.round(e*100)/100)}function rh(t,e=Date.now()){if(t===void 0)return;let o=[],n="ok",r=lw(t);if(r!==void 0&&sw(t)!==void 0){let a=cw(r),c=t.period!==void 0?t.period:"quota";o.push({label:c,value:`${r}%`,level:a}),n=rw(n,a)}let s=Bd(t);if(s!==void 0){let a=Fd(t)?"crit":"ok";o.push({label:"cr\xE9dito",value:s,level:a}),n=rw(n,a)}if(o.length===0)return;let i;if(t.resetAt!==void 0){let a=wa(t.resetAt,e);i=a==="agora"?"reseta agora":`reseta em ${a}`}return{segments:o,...i!==void 0?{resetText:i}:{},maxLevel:n}}function rw(t,e){return nw[e]>nw[t]?e:t}function uw(t){if(t==null||t==="")return;let e=typeof t=="number"?t:Number(String(t).trim());return Number.isFinite(e)?e:void 0}function oh(t){let e=uw(t);if(!(e===void 0||e<0))return Math.round(e)}function ED(t){if(t==null)return;let e=String(t).trim().toLowerCase();if(e==="credit"||e==="credits"||e==="currency")return"credit";if(e==="tokens"||e==="token")return"tokens"}function TD(t){if(t==null)return;let e=String(t).trim();if(e!=="")return e.length>16?e.slice(0,16):e}var iw,aw,dw,nw,mw=S(()=>{"use strict";Ta();iw=70,aw=90;dw=1;nw={ok:0,warn:1,crit:2}});function fw(t){let e=sh(t)?t.data:void 0;if(!Array.isArray(e))return[];let o=[];for(let n of e){if(!sh(n))continue;let r=Xr(n,"key");r===void 0||r===""||o.push({key:r,displayName:Xr(n,"display_name")??r,costSignal:Xr(n,"cost_signal")??"standard",composition:RD(n.composition)})}return o}function RD(t){if(!Array.isArray(t))return[];let e=[];for(let o of t){if(!sh(o))continue;let n=Xr(o,"name");n===void 0||n===""||e.push({name:n,family:Xr(o,"family")??"",role:Xr(o,"role")??"principal",context:Xr(o,"context")??""})}return e}function sh(t){return typeof t=="object"&&t!==null}function Xr(t,e){let o=t[e];return typeof o=="string"?o:void 0}var _D,Pa,ih=S(()=>{"use strict";mo();_D="/v1/tiers/catalog",Pa=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async list(){let e=await this.getAccessToken(),o;try{o=await this.doFetch(`${this.baseUrl}${_D}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch(r){throw new Pe("falha de transporte ao ler o cat\xE1logo do broker.",r)}if(!o.ok){let r;try{r=await o.json()}catch{r=void 0}throw new Le(uo(o.status,r))}let n;try{n=await o.json()}catch(r){throw new Pe("cat\xE1logo do broker com corpo inv\xE1lido.",r)}return fw(n)}}});function hw(t){let e=pw(t)?t.data:void 0;if(!Array.isArray(e))return[];let o=[],n=new Set;for(let r of e){if(!pw(r))continue;let s=Ud(r,"id");if(s===void 0||s===""||n.has(s))continue;n.add(s);let i=OD(r,"supports_tools");o.push({id:s,name:Ud(r,"name")??"",family:Ud(r,"family")??"",context:Ud(r,"context")??"",...i===void 0?{}:{supportsTools:i}})}return o}function pw(t){return typeof t=="object"&&t!==null}function Ud(t,e){let o=t[e];return typeof o=="string"?o:void 0}function OD(t,e){let o=t[e];return typeof o=="boolean"?o:void 0}var CD,Na,ah=S(()=>{"use strict";mo();CD="/v1/models/custom",Na=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async list(){let e=await this.getAccessToken(),o;try{o=await this.doFetch(`${this.baseUrl}${CD}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch(r){throw new Pe("falha de transporte ao ler a lista de modelos custom do broker.",r)}if(!o.ok){let r;try{r=await o.json()}catch{r=void 0}throw new Le(uo(o.status,r))}let n;try{n=await o.json()}catch(r){throw new Pe("lista de modelos custom do broker com corpo inv\xE1lido.",r)}return hw(n)}}});function bw(t){let e=gw(t)?t.data:void 0;if(!Array.isArray(e))return[];let o=[],n=new Set;for(let r of e){if(!gw(r))continue;let s=yw(r,"name");s===void 0||s===""||n.has(s)||(n.add(s),o.push({name:s,adapter:yw(r,"adapter")??""}))}return o}function gw(t){return typeof t=="object"&&t!==null}function yw(t,e){let o=t[e];return typeof o=="string"?o:void 0}var MD,Ia,ch=S(()=>{"use strict";mo();MD="/v1/providers",Ia=class{baseUrl;getAccessToken;doFetch;constructor(e){this.baseUrl=e.baseUrl.replace(/\/+$/,""),this.getAccessToken=e.getAccessToken,this.doFetch=e.fetch??globalThis.fetch}async list(){let e=await this.getAccessToken(),o;try{o=await this.doFetch(`${this.baseUrl}${MD}`,{method:"GET",headers:{authorization:`Bearer ${e}`,accept:"application/json"}})}catch(r){throw new Pe("falha de transporte ao ler a lista de providers do broker.",r)}if(!o.ok){let r;try{r=await o.json()}catch{r=void 0}throw new Le(uo(o.status,r))}let n;try{n=await o.json()}catch(r){throw new Pe("lista de providers do broker com corpo inv\xE1lido.",r)}return bw(n)}}});function Da(t){return new _a({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}function lh(t){return new Pa({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}function dh(t){return new Na({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}function uh(t){return new Ia({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}function mh(t){return new La({baseUrl:t.brokerBaseUrl,getAccessToken:()=>t.login.getAccessToken(),...t.fetch?{fetch:t.fetch}:{}})}var vw=S(()=>{"use strict";$d();ih();ah();ch();th()});var kw=S(()=>{"use strict"});function $a(){return[{kind:"keep",id:"keep"},...xw.map(t=>({kind:"level",value:t,id:t})),{kind:"custom",id:"custom"}]}function Sw(){return $a().length}function ti(t){return Math.min(Math.max(0,t),Sw()-1)}function ww(t){return t.trim()}function jd(t){let e=ww(t);return e===""?{ok:!1,reason:"empty"}:e.length>32?{ok:!1,reason:"too-long"}:{ok:!0,value:e}}function fh(t){let e=$a()[t];return e===void 0?null:e.kind==="keep"?{kind:"keep"}:e.kind==="level"&&e.value!==void 0?{kind:"set",value:e.value}:null}function ph(t){let e=jd(t);return e.ok?{kind:"set",value:e.value}:null}var xw,Aw=S(()=>{"use strict";xw=["low","medium","high"]});var Ew=S(()=>{"use strict";aS();mo();tw();Ta();th();mw();Od();$d();vw();ih();ah();ch();kw();Aw()});function Hd(t){let e=null;for(let o of _w){let n=t.indexOf(o.open);if(n===-1||e!==null&&n>=e.openIdx)continue;let r=t.indexOf(o.close,n+o.open.length);e={format:o,openIdx:n,closeIdx:r}}return e}function Rw(t){let e=Ow(t),o=Hd(e);if(o===null)return{kind:"final",text:t};if(o.closeIdx===-1)return{kind:"malformed",reason:`bloco de tool-call aberto (${o.format.open}) sem fechamento (${o.format.close}).`,text:t};let n=e.slice(o.openIdx+o.format.open.length,o.closeIdx).trim(),r;try{r=JSON.parse(n)}catch{return{kind:"malformed",reason:"o miolo do bloco de tool-call n\xE3o \xE9 JSON v\xE1lido.",text:t}}if(typeof r!="object"||r===null)return{kind:"malformed",reason:"tool-call n\xE3o \xE9 um objeto JSON.",text:t};let s=r,i=s.name;if(typeof i!="string"||i.length===0)return{kind:"malformed",reason:'tool-call sem campo "name" (string n\xE3o-vazia).',text:t};let a=typeof s.input=="object"&&s.input!==null&&!Array.isArray(s.input)?s.input:{};return{kind:"tool_call",call:{name:i,input:a},text:t}}function Tw(t){let e=Hd(t);if(e===null)return t;let o=t.slice(0,e.openIdx),n=e.closeIdx===-1?"":t.slice(e.closeIdx+e.format.close.length),r=o.replace(/\s+$/,""),s=n.replace(/^\s+/,"");return r!==""&&s!==""?`${r}
|
|
31
31
|
${s}`:(r+s).trim()}function Cw(t,e){let o=Math.min(t.length,e.length-1);for(let n=o;n>=1;n--)if(t.endsWith(e.slice(0,n)))return n;return 0}function Ow(t){let e=t.replace(/<think>[\s\S]*?<\/think>/gi,""),o=e.search(/<\/think>/i);o!==-1&&(e=e.slice(o).replace(/^<\/think>/i,""));let n=e.search(/<think>/i);return n!==-1&&(e=e.slice(0,n)),e}function Jr(t){let e=Ow(t),o=e.length;for(let n of LD){let r=Cw(e,n);r>0&&(o=Math.min(o,e.length-r))}return o<e.length&&(e=e.slice(0,o).replace(/\s+$/,"")),e}function pr(t){let e=Jr(t);for(let n=0;n<64;n++){let r=Hd(e);if(r===null||r.closeIdx===-1)break;e=Tw(e)}Hd(e)!==null&&(e=Tw(e));let o=e.length;for(let n of _w){let r=Cw(e,n.open);r>0&&(o=Math.min(o,e.length-r))}return o<e.length&&(e=e.slice(0,o).replace(/\s+$/,"")),e}var hh,gh,_w,LD,oi=S(()=>{"use strict";hh="<<<ALUY_TOOL_CALL",gh="ALUY_TOOL_CALL>>>",_w=[{label:"nativo",open:hh,close:gh},{label:"tool_call",open:"<tool_call>",close:"</tool_call>"}];LD=["<think>","</think>"]});function bh(t){if(t===null||typeof t!="object")return"any";let e=t,o=e.type;if(typeof o=="string"){if(o==="array"){let r=e.items;return`array<${r!==null&&typeof r=="object"?bh(r):"any"}>`}return o}if(Array.isArray(o)){let r=o.filter(s=>typeof s=="string");if(r.length>0)return r.join("|")}let n=e.enum;return Array.isArray(n)&&n.length>0?typeof n[0]:(Array.isArray(e.anyOf)||Array.isArray(e.oneOf)||Array.isArray(e.allOf),"any")}function vh(t){if(t===null||typeof t!="object")return[];let e=t,o=e.properties;if(o===null||typeof o!="object")return[];let n=e.required,r=new Set(Array.isArray(n)?n.filter(i=>typeof i=="string"):[]),s=[];for(let[i,a]of Object.entries(o)){let c=a!==null&&typeof a=="object"?a:{},l=c.description,d={name:i,type:bh(c),required:r.has(i),...typeof l=="string"&&l.trim()!==""?{description:l.trim()}:{}};s.push(d)}return[...s.filter(i=>i.required),...s.filter(i=>!i.required)]}function Bn(t){return t.split(hh).join("[ALUY_TOOL_CALL_neutralizado]").split(gh).join("[ALUY_TOOL_CALL_neutralizado]").split(Fa).join("[DADO_NAO_CONFIAVEL_neutralizado]").split(ni).join("[DADO_NAO_CONFIAVEL_neutralizado]").replace(/[\r\n\t\f\v]+/g," ").replace(/ {2,}/g," ").trim()}function PD(t){return t.length<=yh?t:`${t.slice(0,yh)}\u2026`}function ND(t){let e=Bn(t.name)||"(?)",o=Bn(t.type)||"any",n=t.required?`${e}: ${o} (obrigat\xF3rio)`:`${e}?: ${o}`;if(t.description!==void 0){let r=Bn(t.description);if(r!=="")return` ${n} \u2014 ${PD(r)}`}return` ${n}`}function kh(t){if(t.length===0)return"";let e=[...t].sort((c,l)=>Number(l.required)-Number(c.required)),o=e.slice(0,Mw),n=e.length-o.length,r=[],s=0,i=!1;for(let c of o){let l=ND(c);if(s+l.length+1>Lw){i=!0;break}r.push(l),s+=l.length+1}let a=[];return n>0&&a.push(` \u2026(+${n} par\xE2metro(s) opcional(is) omitido(s) \u2014 priorizados os obrigat\xF3rios)`),i&&a.push(" \u2026(lista de par\xE2metros truncada por tamanho)"),[...r,...a].join(`
|
|
32
32
|
`)}var yh,Mw,Lw,qd=S(()=>{"use strict";oi();Un();yh=120,Mw=16,Lw=1200});function Pw(t){let e=Jr(t);return e.trim()===""?t:e}function Wd(t){if(t===void 0)return;let e=t.trim();if(e!=="")return e.length<=xh?e:e.slice(0,xh)+`
|
|
33
33
|
[\u2026AGENT.md truncado: maior que ${xh} caracteres \u2014 s\xF3 o in\xEDcio foi injetado\u2026]`}function $D(t){let e=`- ${Bn(t.name)} (efeito: ${t.effect}): ${Bn(t.description)}`,o=t.parameters?kh(vh(t.parameters)):"";return o===""?e:`${e}
|
|
@@ -135,7 +135,7 @@ ${t.trim()}`}}function TT(t,e,o=gc){let{older:n,recent:r}=Cu(t,o);if(n.length===
|
|
|
135
135
|
\u2026[truncado: ${t.length-$y} chars omitidos]`}function PB(t){return t.length<=By?t:`${t.slice(0,By)}\u2026`}function d_(t){let e=l_(t.server,t.descriptor.name),o=PB(t.descriptor.description.trim()),n=`[tool de um SERVER MCP de terceiro "${t.server}" \u2014 efeito n\xE3o-confi\xE1vel, passa pela catraca] ${o||"(sem descri\xE7\xE3o)"}`,r=t.descriptor.inputSchema,s=r!==null&&typeof r=="object"&&!Array.isArray(r)?r:void 0;return{name:e,effect:"mcp",description:n,...s?{parameters:s}:{},async run(i,a,c){try{let l=await t.transport.callTool(t.descriptor.name,i,c?.signal),d=Ue(l.content);return l.ok?{ok:!0,observation:c_(d),display:`${e}(${NB(i)})`}:{ok:!1,observation:c_(`MCP "${e}" erro: ${d}`)}}catch(l){return{ok:!1,observation:`MCP "${e}" falhou: ${l instanceof Error?l.message:String(l)}`}}}}}function Uy(t,e){let o=[],n=new Set,r=new Map,s=new Map,i=new Set;for(let a of t){let c=d_(a);if(n.has(c.name))continue;n.add(c.name);let l=a.server;s.set(l,(s.get(l)??0)+1);let d=r.get(l)??0;if(d>=Fy){i.add(l);continue}r.set(l,d+1),o.push(c)}if(e)for(let a of i){let c=s.get(a)??0;e(`server MCP "${a}" exp\xF4s ${c} tools; usando as primeiras ${Fy} (teto por server, anti-estouro de contexto). As demais foram ignoradas \u2014 revise o server ou reduza as tools que ele exp\xF5e.`)}return o}function NB(t){if(Object.keys(t).length===0)return"";let o=JSON.stringify(t);return o.length<=200?o:`${o.slice(0,200)}\u2026`}var $y,Fy,By,u_=S(()=>{"use strict";ld();jn();$y=2e4;Fy=128,By=1024});function p_(t,e){let o=new URL(f_);return t.trim().length>0&&o.searchParams.set("search",t.trim()),o.searchParams.set("limit",String(DB)),e!==void 0&&e.length>0&&o.searchParams.set("cursor",e),o.toString()}async function Hy(t,e,o){let n=t.trim(),r=[],s;for(let i=0;i<IB;i++){let a=p_(n,s),c;try{c=await e(a,o)}catch(f){return{ok:!1,query:n,reason:Fu(HB(f))}}if(!c.ok)return{ok:!1,query:n,reason:Fu(c.reason)};if(c.status<200||c.status>=300)return{ok:!1,query:n,reason:Fu(`HTTP ${c.status}`)};let l;try{l=JSON.parse(c.body)}catch{return{ok:!1,query:n,reason:Fu("resposta n\xE3o \xE9 JSON v\xE1lido")}}let d=g_(l);for(let f of d.servers)if(h_(f,n)&&r.push(f),r.length>=jy)break;if(r.length>=jy||(s=d.nextCursor,s===void 0||s.length===0))break}return{ok:!0,query:n,results:r}}function Fu(t){return`registro MCP indispon\xEDvel (${vi}): ${t}`}function h_(t,e){if(e.length===0)return!0;let o=e.toLowerCase();return[t.name,t.title??"",t.description,t.run.command??"",t.run.args.join(" ")].join(" ").toLowerCase().includes(o)}function g_(t){if(!Gn(t))return{servers:[]};let e=Array.isArray(t.servers)?t.servers:[],o=[];for(let s of e){let i=$B(s);i!==void 0&&o.push(i)}let n=Gn(t.metadata)?t.metadata:void 0,r=n!==void 0&&typeof n.nextCursor=="string"?n.nextCursor:void 0;return{servers:o,...r!==void 0?{nextCursor:r}:{}}}function $B(t){if(!Gn(t))return;let e=Gn(t.server)?t.server:t,o=typeof e.name=="string"?e.name.trim():"";if(o.length===0)return;let n=typeof e.description=="string"?e.description.trim():"",r=typeof e.title=="string"&&e.title.trim().length>0?e.title.trim():void 0,s=typeof e.version=="string"?e.version.trim():void 0,i=FB(e);return{name:o,description:n,run:i,...r!==void 0?{title:r}:{},...s!==void 0?{version:s}:{}}}function FB(t){let e=[],o=Array.isArray(t.remotes)?t.remotes:[];for(let r of o)Gn(r)&&typeof r.url=="string"&&e.push(r.url);let n=Array.isArray(t.packages)?t.packages:[];for(let r of n){if(!Gn(r))continue;let s=BB(r);if(s!==void 0)return{...s,remoteUrls:e}}return{args:[],env:[],remoteUrls:e}}function BB(t){let e=cs(t.registryType)??cs(t.registry_name),o=cs(t.identifier)??cs(t.name);if(o===void 0)return;let n=cs(t.version),r=cs(t.runtimeHint),s=Gn(t.transport)?cs(t.transport.type):void 0,i=jB(t.environmentVariables),a=m_(t.runtimeArguments),c=m_(t.packageArguments),l=n!==void 0?`${o}@${n}`:o;return e==="npm"||r==="npx"?{command:"npx",args:UB(["-y",...a,l,...c]),env:i,...s!==void 0?{transport:s}:{}}:e==="pypi"||r==="uvx"||r==="uv"?{command:"uvx",args:[...a,o,...c],env:i,...s!==void 0?{transport:s}:{}}:e==="oci"||r==="docker"?{command:"docker",args:["run","-i","--rm",...a,l,...c],env:i,...s!==void 0?{transport:s}:{}}:{args:[l],env:i,...s!==void 0?{transport:s}:{}}}function UB(t){let e=[],o=!1;for(let n of t){if(n==="-y"||n==="--yes"){if(o)continue;o=!0}e.push(n)}return e}function m_(t){if(!Array.isArray(t))return[];let e=[];for(let o of t)Gn(o)&&typeof o.value=="string"&&e.push(o.value);return e}function jB(t){if(!Array.isArray(t))return[];let e=[];for(let o of t)Gn(o)&&typeof o.name=="string"&&o.name.length>0&&e.push({name:o.name,required:o.isRequired===!0});return e}function cs(t){return typeof t=="string"&&t.trim().length>0?t.trim():void 0}function Gn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function HB(t){return t instanceof Error?t.message:String(t)}var vi,f_,IB,DB,jy,y_=S(()=>{"use strict";vi="registry.modelcontextprotocol.io",f_=`https://${vi}/v0/servers`,IB=5,DB=100,jy=25});function v_(t){let{command:e,args:o}=t.run;if(e===void 0)return;let n=k_(t.name);return["aluy","mcp","add",b_(n),"--",e,...o.map(b_)].join(" ")}function k_(t){let o=(t.split("/").pop()??t).replace(/[^A-Za-z0-9_-]+/g,"-").replace(/^-+|-+$/g,"");return o.length>0?o:"server"}function b_(t){return/^[A-Za-z0-9_./@:+=-]+$/.test(t)?t:`'${t.replace(/'/g,"'\\''")}'`}function qy(t){if(!t.ok)return`\u26A0 ${t.reason}
|
|
136
136
|
Tente de novo em instantes; a busca no registro n\xE3o bloqueia o resto do aluy.`;if(t.results.length===0)return`nenhum server encontrado para "${t.query}" no registro oficial MCP.`;let e=[],o=t.results.length;e.push(`${o} server${o===1?"":"s"} para "${t.query}" (registro oficial MCP):`),e.push("");for(let n of t.results)e.push(qB(n)),e.push("");return e.push('Para instalar, copie a linha "\u2192 aluy mcp add \u2026" do server desejado.'),e.push("A sa\xEDda do registro \xE9 apenas informativa \u2014 nada \xE9 executado pela busca."),e.join(`
|
|
137
137
|
`)}function qB(t){let o=[`\u2022 ${t.version!==void 0?`${t.name} (v${t.version})`:t.name}`],n=t.title!==void 0&&t.title!==t.name?t.title:void 0;n!==void 0&&o.push(` ${n}`),t.description.length>0&&o.push(` ${WB(t.description,200)}`);let r=v_(t);if(r!==void 0){o.push(` \u2192 ${r}`),t.run.transport!==void 0&&t.run.transport!=="stdio"&&o.push(` (transporte "${t.run.transport}" \u2014 v1 do aluy s\xF3 pluga servers stdio LOCAIS)`);let s=t.run.env.filter(i=>i.required).map(i=>i.name);s.length>0&&o.push(` requer env: ${s.join(", ")} (defina por-server no mcp.json)`)}else t.run.remoteUrls.length>0?o.push(` (server REMOTO: ${t.run.remoteUrls.join(", ")} \u2014 fora do v1 de \`aluy mcp add\`)`):o.push(" (sem pacote local conhecido \u2014 nada a instalar pelo aluy)");return o.join(`
|
|
138
|
-
`)}function WB(t,e){return t.length<=e?t:t.slice(0,e-1).trimEnd()+"\u2026"}var x_=S(()=>{"use strict"});var S_=S(()=>{"use strict";$u();o_();n_();r_();s_();a_();u_();ld();y_();x_()});function Wy(t){let e=/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/.exec(t.trim());if(!e)return null;let o=e[4]?e[4].split(".").map(n=>/^\d+$/.test(n)?Number(n):n):[];return{major:Number(e[1]),minor:Number(e[2]),patch:Number(e[3]),pre:o}}function w_(t,e){let o=Wy(t),n=Wy(e);if(!o||!n)return null;for(let s of["major","minor","patch"])if(o[s]!==n[s])return o[s]<n[s]?-1:1;if(o.pre.length===0&&n.pre.length===0)return 0;if(o.pre.length===0)return 1;if(n.pre.length===0)return-1;let r=Math.max(o.pre.length,n.pre.length);for(let s=0;s<r;s++){let i=o.pre[s],a=n.pre[s];if(i===void 0)return-1;if(a===void 0)return 1;if(i===a)continue;let c=typeof i=="number",l=typeof a=="number";return c&&l?i<a?-1:1:c?-1:l?1:i<a?-1:1}return 0}function Gy(t,e){return w_(t,e)===1}var A_=S(()=>{"use strict"});var zy=S(()=>{"use strict"});var E_=S(()=>{"use strict";zy()});var T_=S(()=>{"use strict"});var __=S(()=>{"use strict"});function Ky(t){return`connector-${t}-token`}function Yy(t){let e=t.trim(),o=e.indexOf(":");return o<=0?`\u2026(${e.length} chars)`:`${e.slice(0,o)}:\u2026(${e.length-o-1} chars)`}var R_=S(()=>{"use strict"});var j=S(()=>{"use strict";Tx();Yx();iS();Ew();GT();ZT();S_();Ay();hu();A_();zy();E_();T_();__();R_()});import{posix as uj}from"node:path";function mj(t){return uj.normalize(t)}function Jt(t){let e=mj(t);for(let o of fj)if(o.re.test(e))return o.deny?{kind:"deny",why:o.why}:{kind:"ask",why:o.why};return{kind:"allow"}}function fb(t){return Jt(t).kind==="allow"}var fj,wr=S(()=>{"use strict";fj=[{re:/(?:^|\/|~\/)\.ssh(?:\/|$)/,why:"chaves SSH (~/.ssh)",deny:!0},{re:/(?:^|\/|~\/)\.aws(?:\/|$)/,why:"credenciais AWS (~/.aws)",deny:!0},{re:/(?:^|\/|~\/)\.gnupg(?:\/|$)/,why:"chaves GPG (~/.gnupg)",deny:!0},{re:/(?:~\/|\$\{?HOME\}?\/|\/(?:home|Users)\/[^/]+\/)\.aluy\/rooms(?:\/|$)/,why:"arquivos de sala do Aluy (~/.aluy/rooms)",deny:!0},{re:/~\/\.aluy(?:\/|$)/,why:"estado/credencial do Aluy (~/.aluy)",deny:!0},{re:/(?:^|\/)\.aluy(?:\/(?!agents\/|workflows\/|commands\/)|$)/,why:"estado/credencial do Aluy (.aluy/)",deny:!0},{re:/(?:^|\/|~\/)\.config\/gh\/hosts\.yml$/,why:"token do gh CLI",deny:!0},{re:/(?:^|\/|~\/)\.docker\/config\.json$/,why:"credenciais Docker",deny:!0},{re:/(?:^|\/|~\/)\.kube\/config$/,why:"kubeconfig",deny:!0},{re:/(?:^|\/)id_(?:rsa|ed25519|ecdsa|dsa)\b/,why:"chave privada",deny:!0},{re:/\.pem$|\.p12$|\.pfx$|\.key$/i,why:"material de chave privada",deny:!0},{re:/(?:^|[/\w.-])\.env(?:\.(?!example$|sample$|template$|dist$)[\w.-]+)?$/,why:"arquivo .env (segredos)",deny:!1},{re:/(?:^|\/)[^/]*(?:secret|credential|token|apikey|api_key|password|passwd)[^/]*$/i,why:"arquivo com nome sens\xEDvel (token/secret)",deny:!1}]});var Db={};Wf(Db,{UserWorkflowsLoader:()=>_i,WORKFLOWS_DIRNAME:()=>Ib});import{homedir as QH}from"node:os";import{join as Nb}from"node:path";import{readdirSync as ZH,readFileSync as eq,mkdirSync as tq,statSync as oq}from"node:fs";var nq,Ib,rq,sq,_i,sm=S(()=>{"use strict";j();nq=448,Ib="workflows",rq=64*1024,sq=256,_i=class{dir;constructor(e={}){let o=e.baseDir??Nb(QH(),".aluy");this.dir=Nb(o,Ib)}get workflowsDir(){return this.dir}ensureDir(){try{tq(this.dir,{mode:nq,recursive:!0})}catch{}}load(){let e;try{e=ZH(this.dir,{withFileTypes:!0})}catch{return{workflows:[],errors:[]}}let o=e.filter(i=>i.isFile()&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=sq)break;let a=this.readOne(i);if(a!==null){if(sc(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{workflows:r,errors:s}}readOne(e){let o=Nb(this.dir,e);try{let n=oq(o);if(!n.isFile()||n.size>rq)return null;let r=eq(o,"utf8");return ic(e,r,"global")}catch{return null}}}});var Fb={};Wf(Fb,{PROJECT_WORKFLOWS_DIRNAMES:()=>$b,ProjectWorkflowsLoader:()=>Ri});import{join as iq}from"node:path";import{readdirSync as aq,readFileSync as cq,statSync as lq}from"node:fs";var $b,dq,uq,Ri,im=S(()=>{"use strict";j();wr();$b=[".claude/workflows",".aluy/workflows"],dq=64*1024,uq=256,Ri=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of $b){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=aq(s,{withFileTypes:!0})}catch{continue}let a=i.filter(c=>c.isFile()&&c.name.toLowerCase().endsWith(".md")).map(c=>c.name).sort((c,l)=>c.localeCompare(l));for(let c of a){if(o.length>=uq)break;let l=this.readOne(r,s,c);if(l!==null){if(sc(l)){n.push(l);continue}e.has(l.name)||(e.add(l.name),o.push(l))}}}return{workflows:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(Jt(r).kind!=="allow")return null;let s=iq(o,n);try{this.workspace.resolveInside(r);let i=lq(s);if(!i.isFile()||i.size>dq)return null;let a=cq(s,"utf8");return ic(n,a,"project")}catch{return null}}}});var Ln="1.0.0-rc.
|
|
138
|
+
`)}function WB(t,e){return t.length<=e?t:t.slice(0,e-1).trimEnd()+"\u2026"}var x_=S(()=>{"use strict"});var S_=S(()=>{"use strict";$u();o_();n_();r_();s_();a_();u_();ld();y_();x_()});function Wy(t){let e=/^v?(\d+)\.(\d+)\.(\d+)(?:-([0-9A-Za-z.-]+))?/.exec(t.trim());if(!e)return null;let o=e[4]?e[4].split(".").map(n=>/^\d+$/.test(n)?Number(n):n):[];return{major:Number(e[1]),minor:Number(e[2]),patch:Number(e[3]),pre:o}}function w_(t,e){let o=Wy(t),n=Wy(e);if(!o||!n)return null;for(let s of["major","minor","patch"])if(o[s]!==n[s])return o[s]<n[s]?-1:1;if(o.pre.length===0&&n.pre.length===0)return 0;if(o.pre.length===0)return 1;if(n.pre.length===0)return-1;let r=Math.max(o.pre.length,n.pre.length);for(let s=0;s<r;s++){let i=o.pre[s],a=n.pre[s];if(i===void 0)return-1;if(a===void 0)return 1;if(i===a)continue;let c=typeof i=="number",l=typeof a=="number";return c&&l?i<a?-1:1:c?-1:l?1:i<a?-1:1}return 0}function Gy(t,e){return w_(t,e)===1}var A_=S(()=>{"use strict"});var zy=S(()=>{"use strict"});var E_=S(()=>{"use strict";zy()});var T_=S(()=>{"use strict"});var __=S(()=>{"use strict"});function Ky(t){return`connector-${t}-token`}function Yy(t){let e=t.trim(),o=e.indexOf(":");return o<=0?`\u2026(${e.length} chars)`:`${e.slice(0,o)}:\u2026(${e.length-o-1} chars)`}var R_=S(()=>{"use strict"});var j=S(()=>{"use strict";Tx();Yx();iS();Ew();GT();ZT();S_();Ay();hu();A_();zy();E_();T_();__();R_()});import{posix as uj}from"node:path";function mj(t){return uj.normalize(t)}function Jt(t){let e=mj(t);for(let o of fj)if(o.re.test(e))return o.deny?{kind:"deny",why:o.why}:{kind:"ask",why:o.why};return{kind:"allow"}}function fb(t){return Jt(t).kind==="allow"}var fj,wr=S(()=>{"use strict";fj=[{re:/(?:^|\/|~\/)\.ssh(?:\/|$)/,why:"chaves SSH (~/.ssh)",deny:!0},{re:/(?:^|\/|~\/)\.aws(?:\/|$)/,why:"credenciais AWS (~/.aws)",deny:!0},{re:/(?:^|\/|~\/)\.gnupg(?:\/|$)/,why:"chaves GPG (~/.gnupg)",deny:!0},{re:/(?:~\/|\$\{?HOME\}?\/|\/(?:home|Users)\/[^/]+\/)\.aluy\/rooms(?:\/|$)/,why:"arquivos de sala do Aluy (~/.aluy/rooms)",deny:!0},{re:/~\/\.aluy(?:\/|$)/,why:"estado/credencial do Aluy (~/.aluy)",deny:!0},{re:/(?:^|\/)\.aluy(?:\/(?!agents\/|workflows\/|commands\/)|$)/,why:"estado/credencial do Aluy (.aluy/)",deny:!0},{re:/(?:^|\/|~\/)\.config\/gh\/hosts\.yml$/,why:"token do gh CLI",deny:!0},{re:/(?:^|\/|~\/)\.docker\/config\.json$/,why:"credenciais Docker",deny:!0},{re:/(?:^|\/|~\/)\.kube\/config$/,why:"kubeconfig",deny:!0},{re:/(?:^|\/)id_(?:rsa|ed25519|ecdsa|dsa)\b/,why:"chave privada",deny:!0},{re:/\.pem$|\.p12$|\.pfx$|\.key$/i,why:"material de chave privada",deny:!0},{re:/(?:^|[/\w.-])\.env(?:\.(?!example$|sample$|template$|dist$)[\w.-]+)?$/,why:"arquivo .env (segredos)",deny:!1},{re:/(?:^|\/)[^/]*(?:secret|credential|token|apikey|api_key|password|passwd)[^/]*$/i,why:"arquivo com nome sens\xEDvel (token/secret)",deny:!1}]});var Db={};Wf(Db,{UserWorkflowsLoader:()=>_i,WORKFLOWS_DIRNAME:()=>Ib});import{homedir as QH}from"node:os";import{join as Nb}from"node:path";import{readdirSync as ZH,readFileSync as eq,mkdirSync as tq,statSync as oq}from"node:fs";var nq,Ib,rq,sq,_i,sm=S(()=>{"use strict";j();nq=448,Ib="workflows",rq=64*1024,sq=256,_i=class{dir;constructor(e={}){let o=e.baseDir??Nb(QH(),".aluy");this.dir=Nb(o,Ib)}get workflowsDir(){return this.dir}ensureDir(){try{tq(this.dir,{mode:nq,recursive:!0})}catch{}}load(){let e;try{e=ZH(this.dir,{withFileTypes:!0})}catch{return{workflows:[],errors:[]}}let o=e.filter(i=>i.isFile()&&i.name.toLowerCase().endsWith(".md")).map(i=>i.name).sort((i,a)=>i.localeCompare(a)),n=new Set,r=[],s=[];for(let i of o){if(r.length>=sq)break;let a=this.readOne(i);if(a!==null){if(sc(a)){s.push(a);continue}n.has(a.name)||(n.add(a.name),r.push(a))}}return{workflows:r,errors:s}}readOne(e){let o=Nb(this.dir,e);try{let n=oq(o);if(!n.isFile()||n.size>rq)return null;let r=eq(o,"utf8");return ic(e,r,"global")}catch{return null}}}});var Fb={};Wf(Fb,{PROJECT_WORKFLOWS_DIRNAMES:()=>$b,ProjectWorkflowsLoader:()=>Ri});import{join as iq}from"node:path";import{readdirSync as aq,readFileSync as cq,statSync as lq}from"node:fs";var $b,dq,uq,Ri,im=S(()=>{"use strict";j();wr();$b=[".claude/workflows",".aluy/workflows"],dq=64*1024,uq=256,Ri=class{workspace;constructor(e){this.workspace=e.workspace}load(){let e=new Set,o=[],n=[];for(let r of $b){let s;try{s=this.workspace.resolveInside(r)}catch{continue}let i;try{i=aq(s,{withFileTypes:!0})}catch{continue}let a=i.filter(c=>c.isFile()&&c.name.toLowerCase().endsWith(".md")).map(c=>c.name).sort((c,l)=>c.localeCompare(l));for(let c of a){if(o.length>=uq)break;let l=this.readOne(r,s,c);if(l!==null){if(sc(l)){n.push(l);continue}e.has(l.name)||(e.add(l.name),o.push(l))}}}return{workflows:o,errors:n}}readOne(e,o,n){let r=`${e}/${n}`;if(Jt(r).kind!=="allow")return null;let s=iq(o,n);try{this.workspace.resolveInside(r);let i=lq(s);if(!i.isFile()||i.size>dq)return null;let a=cq(s,"utf8");return ic(n,a,"project")}catch{return null}}}});var Ln="1.0.0-rc.41";j();var C_=`aluy \u2014 agente de terminal que roda na sua m\xE1quina, com o seu provider de LLM
|
|
139
139
|
|
|
140
140
|
Uso:
|
|
141
141
|
aluy ["objetivo"] [--plan | --yolo] [--dense] [--tier <tier>] [--lang <pt-BR|en>]
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hiperplano/aluy-cli",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.41",
|
|
4
4
|
"description": "Aluy CLI — TUI (Ink) + binário `aluy` + wiring. Consome @hiperplano/aluy-cli-core (engine portável). Credenciais só no keychain do SO.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|