@crewx/sdk 0.9.0-rc.212 → 0.9.0-rc.214

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.
@@ -80,7 +80,7 @@ ${r.join(`
80
80
  active = excluded.active,
81
81
  time_created = excluded.time_created,
82
82
  time_updated = excluded.time_updated
83
- `);r.transaction(i=>{for(let c of i)o.run(c);})(n);}finally{r.close();}}function Rg(t){if(!t)return [];let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){let o=t[n+1],s=o!==void 0&&!o.startsWith("-");e.push({sessionId:s?o:void 0}),s&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&e.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return e}function Sg(t){if(!t)return;let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){t[n+1]!==void 0&&!t[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||e.push(r);}return e}function To(t){let e=Sg(t.additionalArgs);return {...t,...e===void 0?{}:{additionalArgs:e},resumeSessionId:void 0}}function Ig(t,e){try{return !!t.prepare("SELECT id FROM session_v2 WHERE id = ?").get(e)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function Ag(t,e,n){let r=new t(e,{readonly:true,fileMustExist:true});try{return Ig(r,n)}finally{r.close();}}async function Ys(t,e={}){let n;try{n=await(e.loadSqlite??hg)();}catch{throw new W("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=e.crewxHome??yo(),o=fr(r),s=gr(r),i=mg(s),c=kg(e.userDataHome),d=Tg(n,c);if(d.length>0){if(!Zc(n,i))try{await(e.initializeDatabase??wg)(o);}catch{throw new W("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!Zc(n,i))throw new W("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{Eg(n,i,d);}catch{throw new W("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let u=Rg(t.additionalArgs),l=u.map(_=>_.sessionId),p=u.length>0?l[l.length-1]:t.resumeSessionId;if(!p)return u.length>0?To(t):t;if(l.some(_=>_!==p)||!Yc.existsSync(i))return To(t);try{return Ag(n,i,p)?{...t,resumeSessionId:p}:To(t)}catch{throw new W("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var Qs=C(()=>{g();$t();Vs();Qc();});function dn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function Zs(){let t;try{let n=(await import('better-sqlite3')).default,r=Re.join(gr(),"opencode.db");t=new n(r,{readonly:!0,fileMustExist:!0});let o=t.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let s=JSON.parse(o.value);if(!dn(s))throw new Error("OpenCode model catalog shape is unavailable");let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(!dn(i))throw new Error("OpenCode model catalog body shape is unavailable");let c=new Map;for(let[d,u]of Object.entries(i)){if(!d||!dn(u)||!dn(u.models))throw new Error("OpenCode model provider shape is unavailable");for(let[l,p]of Object.entries(u.models)){if(!l||!dn(p))throw new Error("OpenCode model shape is unavailable");let _=p.capabilities;if(_===void 0)continue;if(!dn(_))throw new Error("OpenCode model capability shape is unavailable");let h=_.reasoning;if(h===void 0)continue;if(!dn(h))throw new Error("OpenCode reasoning capability shape is unavailable");let m=h.effort;Array.isArray(m)&&m.length>0&&m.every(k=>typeof k=="string")&&c.set(`${d}/${l}`,m);}}return c}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{t?.close();}catch{}}}var tu=C(()=>{g();ti();Kc();Vc();Vs();Qs();Ht();});function Dg(t){return t?bg[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function ze(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Pg(){let t;try{t=gr();}catch{return Zs().catch(()=>new Map)}let e=Date.now();if(nu===t&&wo&&wo.expiresAt>e)return wo.result;nu=t;let n=Zs().catch(()=>new Map);return wo={expiresAt:e+xg,result:n},n}async function Lg(t){let e=await Ys(t),n=t.additionalArgs??[],r=ze(n,"--model")||ze(n,"-m");if(!t.model||!t.effort||r)return e;let o=(await Pg()).get(t.model);return !o||o.includes(t.effort)?e:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...e,effort:void 0})}function au(t){let e=[],n=0,r=false,o=false,s=0;for(let c=0;c<t.length;c++){let d=t[c];if(o){o=false;continue}if(d==="\\"&&r){o=true;continue}if(d==='"'){r=!r;continue}if(!r){if(d==="{")n++;else if(d==="}"&&(n--,n===0)){let u=t.slice(s,c+1).trim();u&&e.push(u),s=c+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function ie(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function du(t){let e=ie(t.part)?t.part:void 0;return t.type==="reasoning"||e?.type==="reasoning"}function Mg(t){let e=ie(t.part)?t.part:void 0;return (typeof e?.text=="string"?e.text:typeof t.text=="string"?t.text:void 0)?.trim()||void 0}function $g(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let i=JSON.parse(o);ie(i)?e.push(i):n=!0;continue}catch{}let s=au(o);s.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of s)try{let c=JSON.parse(i);ie(c)?e.push(c):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function oi(t){let e=ie(t.error)?t.error:void 0,n=e&&ie(e.data)?e.data:void 0,r=cu(e),o=Ke(e?.name),s=Ke(n?.message)??Ke(e?.message)??ni(r)??Ke(t.message)??Ke(t.errorMessage)??Ke(t.error),i=Ke(t.ref),c=o&&s&&o!==s?`${o}: ${s}`:o??s??iu;return (i?`${c} (ref: ${i})`:c).slice(0,vg)}function ru(t){let e=ie(t.error)?t.error:void 0,n=typeof e?.type=="string"?e.type:void 0,r=typeof e?.status=="number"?e.status:Number(e?.status),o=oi(t),s=cu(e),i=s&&ie(s.error)?s.error:void 0,c=typeof i?.type=="string"?i.type:void 0,d=[o,ni(s)].filter(Boolean).join(`
83
+ `);r.transaction(i=>{for(let c of i)o.run(c);})(n);}finally{r.close();}}function Rg(t){if(!t)return [];let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){let o=t[n+1],s=o!==void 0&&!o.startsWith("-");e.push({sessionId:s?o:void 0}),s&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&e.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return e}function Sg(t){if(!t)return;let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){t[n+1]!==void 0&&!t[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||e.push(r);}return e}function To(t){let e=Sg(t.additionalArgs);return {...t,...e===void 0?{}:{additionalArgs:e},resumeSessionId:void 0}}function Ig(t,e){try{return !!t.prepare("SELECT id FROM session_v2 WHERE id = ?").get(e)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function Ag(t,e,n){let r=new t(e,{readonly:true,fileMustExist:true});try{return Ig(r,n)}finally{r.close();}}async function Ys(t,e={}){let n;try{n=await(e.loadSqlite??hg)();}catch{throw new W("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=e.crewxHome??yo(),o=fr(r),s=gr(r),i=mg(s),c=kg(e.userDataHome),d=Tg(n,c);if(d.length>0){if(!Zc(n,i))try{await(e.initializeDatabase??wg)(o);}catch{throw new W("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!Zc(n,i))throw new W("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{Eg(n,i,d);}catch{throw new W("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let u=Rg(t.additionalArgs),l=u.map(_=>_.sessionId),p=u.length>0?l[l.length-1]:t.resumeSessionId;if(!p)return u.length>0?To(t):t;if(l.some(_=>_!==p)||!Yc.existsSync(i))return To(t);try{return Ag(n,i,p)?{...t,resumeSessionId:p}:To(t)}catch{throw new W("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var Qs=C(()=>{g();$t();Vs();Qc();});function dn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function Zs(){let t;try{let n=(await import('better-sqlite3')).default,r=Re.join(gr(),"opencode.db");t=new n(r,{readonly:!0,fileMustExist:!0});let o=t.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let s=JSON.parse(o.value);if(!dn(s))throw new Error("OpenCode model catalog shape is unavailable");let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(!dn(i))throw new Error("OpenCode model catalog body shape is unavailable");let c=new Map;for(let[d,u]of Object.entries(i)){if(!d||!dn(u)||!dn(u.models))throw new Error("OpenCode model provider shape is unavailable");for(let[l,p]of Object.entries(u.models)){if(!l||!dn(p))throw new Error("OpenCode model shape is unavailable");let _=p.capabilities;if(_===void 0)continue;if(!dn(_))throw new Error("OpenCode model capability shape is unavailable");let h=_.reasoning;if(h===void 0)continue;if(!dn(h))throw new Error("OpenCode reasoning capability shape is unavailable");let m=h.effort;(m===void 0||Array.isArray(m)&&m.every(k=>typeof k=="string"))&&c.set(`${d}/${l}`,Array.isArray(m)?m:[]);}}return c}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{t?.close();}catch{}}}var tu=C(()=>{g();ti();Kc();Vc();Vs();Qs();Ht();});function Dg(t){return t?bg[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function ze(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Pg(){let t;try{t=gr();}catch{return Zs().catch(()=>new Map)}let e=Date.now();if(nu===t&&wo&&wo.expiresAt>e)return wo.result;nu=t;let n=Zs().catch(()=>new Map);return wo={expiresAt:e+xg,result:n},n}async function Lg(t){let e=await Ys(t),n=t.additionalArgs??[],r=ze(n,"--model")||ze(n,"-m");if(!t.model||!t.effort||r)return e;let o=(await Pg()).get(t.model);return !o||o.includes(t.effort)?e:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...e,effort:void 0})}function au(t){let e=[],n=0,r=false,o=false,s=0;for(let c=0;c<t.length;c++){let d=t[c];if(o){o=false;continue}if(d==="\\"&&r){o=true;continue}if(d==='"'){r=!r;continue}if(!r){if(d==="{")n++;else if(d==="}"&&(n--,n===0)){let u=t.slice(s,c+1).trim();u&&e.push(u),s=c+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function ie(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function du(t){let e=ie(t.part)?t.part:void 0;return t.type==="reasoning"||e?.type==="reasoning"}function Mg(t){let e=ie(t.part)?t.part:void 0;return (typeof e?.text=="string"?e.text:typeof t.text=="string"?t.text:void 0)?.trim()||void 0}function $g(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let i=JSON.parse(o);ie(i)?e.push(i):n=!0;continue}catch{}let s=au(o);s.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of s)try{let c=JSON.parse(i);ie(c)?e.push(c):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function oi(t){let e=ie(t.error)?t.error:void 0,n=e&&ie(e.data)?e.data:void 0,r=cu(e),o=Ke(e?.name),s=Ke(n?.message)??Ke(e?.message)??ni(r)??Ke(t.message)??Ke(t.errorMessage)??Ke(t.error),i=Ke(t.ref),c=o&&s&&o!==s?`${o}: ${s}`:o??s??iu;return (i?`${c} (ref: ${i})`:c).slice(0,vg)}function ru(t){let e=ie(t.error)?t.error:void 0,n=typeof e?.type=="string"?e.type:void 0,r=typeof e?.status=="number"?e.status:Number(e?.status),o=oi(t),s=cu(e),i=s&&ie(s.error)?s.error:void 0,c=typeof i?.type=="string"?i.type:void 0,d=[o,ni(s)].filter(Boolean).join(`
84
84
  `);if(r===402||Hg(d))return new W(`OpenCode subscription is required: ${o}`,He,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:pr(o)});if(r===403&&(c==="RegionError"||c==="FreeTierError"))return new W(`OpenCode account settings are required: ${o}`,He,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:pr(o)});if(n==="provider.auth"||r===401||r===403)return new W(`OpenCode authentication is required: ${o}`,He,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||c==="ModelDeprecated")return new W(`OpenCode model has been retired: ${o}`,He,{code:"MODEL_RETIRED",kind:"config",replacementModel:Ug(s,e,t),providerReason:pr(o)});if(n==="provider.free-limit"||r===429){let u=qg(e);return new W(`OpenCode rate limit reached: ${o}`,He,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new W(`OpenCode model or variant unavailable: ${o}`,He,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,ni(s)].filter(h=>h!==void 0),l=u.find(h=>/requires global regions/i.test(h)),p=u.find(h=>/trains on request data/i.test(h)),_=l?"region":p?"training_consent":void 0;if(_)return new W(`OpenCode account settings are required: ${o}`,He,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:_,providerReason:pr(l??p)})}return new W(`OpenCode error: ${o}`,He,{code:"PROVIDER_CRASHED",kind:"transient"})}function cu(t){let n=(t&&ie(t.response)?t.response:void 0)?.body;if(ie(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return ie(r)?r:void 0}catch{return}}function ni(t){let e=t&&ie(t.error)?t.error:void 0;return Ke(e?.message)??Ke(t?.message)}function Hg(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function Ug(t,e,n){let r=t&&ie(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(d=>typeof d=="string"&&d.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",c=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(c)?c:void 0}function qg(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&ie(t.response)?t.response:void 0)?.body,o=typeof r=="string"?Fg(r):ie(r)?r:void 0;if(o){let s=ri(o);if(s)return ou(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return ou(s[1],false)}}function Fg(t){try{let e=JSON.parse(t);return ie(e)?e:void 0}catch{return}}function ri(t){if(Array.isArray(t)){for(let e of t){let n=ri(e);if(n)return n}return}if(ie(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=ri(e);if(n)return n}}}function ou(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function su(t){let e=$g(t),n=[],r=null,o=0,s=[],i=[],c,d=false;for(let u of e.events){if(du(u))continue;let l=typeof u.type=="string"?u.type:void 0;if(l){if(l==="text"){let p=ie(u.part)?u.part:void 0,_=typeof p?.text=="string"?p.text:void 0;_?.trim()&&n.push(_.trim());continue}if(l==="result"){typeof u.result=="string"&&(r=u.result);continue}if(l==="tool_use"){o++;continue}if(l==="error"){s.push(u),i.push(oi(u));continue}if(l==="step_finish"){d=true;let p=ie(u.part)?u.part:void 0;c=typeof p?.reason=="string"?p.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:c,hasTerminal:d}}function uu(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function Bg(){return new W("OpenCode returned no assistant output.",He,{code:"EMPTY_OUTPUT",kind:"transient"})}function Wg(){return new W("OpenCode emitted malformed JSON output.",He,{code:"PROVIDER_CRASHED",kind:"transient"})}function Gg(t,e){switch(uu(t)){case "length":return new W("OpenCode stopped because the context window was exceeded.",He,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new W("OpenCode stopped because the content filter blocked the response.",He,{code:"UNKNOWN",kind:"permanent"});case "error":return new W(`${iu} while generating a response.`,He,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var Og,He,iu,vg,Cg,xg,nu,wo,bg,si,ii=C(()=>{g();$t();jc();lr();Nn();sn();tu();Qs();Og=new Set(["step_start","step_finish"]),He="cli/opencode",iu="OpenCode provider error",vg=240,Cg="Follow the instructions provided on standard input.",xg=3e5,bg={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};si={command:"opencode",prepare:Lg,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];ze(o,"--format")||o.push("--format","json"),ze(o,"--thinking")||o.push("--thinking"),!ze(o,"--standalone")&&!ze(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!ze(o,"-s")&&!ze(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=Dg(e.mode);ze(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!ze(o,"--auto")&&o.push("--auto");let c=ze(o,"--model")||ze(o,"-m");if(e.model&&!c){let d=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",d);}else e.effort&&!e.model&&!c&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(Cg),{args:o,stdinMessage:t,env:fr()}},extractText(t){let e=su(t),n=e.errorEvents[0];if(n)throw ru(n);let r=Gg(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw Wg();let s=uu(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw Bg()},interpretExit(t,e,n=""){if(t===0)return null;let o=su(n).errorEvents[0];return o?ru(o):null},parseResultMeta(t){let e=vn(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e,n){let r=e??new Date().toISOString(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=au(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let c of i){let d;try{d=JSON.parse(c);}catch{continue}let u=nt(d,r),l=d.type;if(du(d)){let p=Mg(d);if(!p)continue;let _=ie(d.part)?d.part:void 0,h=typeof _?.id=="string"?_.id:typeof d.id=="string"?d.id:void 0,m=p;if(h){let k=`opencode.reasoning:${h}`,E=n?.state.get(k),b=typeof E=="string"?E:s.get(h);if(typeof b=="string"&&(b===p||b.startsWith(p))||typeof b=="string"&&p.startsWith(b)&&(m=p.slice(b.length).trim(),!m))continue;s.set(h,p),n?.state.set(k,p);}o.push({timestamp:u,type:"thinking",content:m});continue}if(l){if(l==="text"){let _=d.part?.text;_&&o.push({timestamp:u,type:"text",content:_});continue}if(l==="tool_use"){let p=d.part;if(!p)continue;let _=String(p.tool||""),h=String(p.callID||p.id||""),m=p.state,k=String(m?.status||""),E=m?.input,b=tt(E);if(o.push({timestamp:u,type:"tool_use",toolName:_,toolUseId:h,toolInput:b}),k==="completed"&&m?.output!==void 0){let T=m.output,P=typeof T=="string"?T:JSON.stringify(T);o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:P,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:h,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(l==="error"){let p=oi(d);o.push({timestamp:u,type:"error",content:p,errorMessage:p});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?Og.has(r):!1}catch{return false}}};});var lu=C(()=>{g();});function Eo(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function Vg(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function Xg(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!zg.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function Je(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Yg(t,e){if(!(t?Kg.has(t)||It(ai).some(s=>s.id===t):false)||!t)return e;let r=On(ai,t),o=Bs(ai)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function At(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function ui(t){return t.kind==="step_update"?typeof t.step.conversation_id=="string"?t.step.conversation_id:void 0:typeof t.envelope.conversation_id=="string"?t.envelope.conversation_id:void 0}function li(t){return t.step.step_index}function se(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&lo(e)?.slice(0,500).trim()||void 0}function Qg(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&Jg.has(n))return n;let r=`${n} ${e??""}`.toLowerCase();return /quota|resource_exhausted|usage[ _-]?limit|credits?.{0,20}exhaust/.test(r)?"QUOTA_EXHAUSTED":/rate[ _-]?limit|throttl/.test(r)?"RATE_LIMITED":/auth|sign[ _-]?in|log(?:ged)?[ _-]?in|unauthori[sz]ed|credential/.test(r)?"AUTH_REQUIRED":[/unknown (?:flag|option)/,/flag provided but not defined/,/unrecognized (?:flag|option)/,/invalid value for (?:flag|option)/,/invalid (?:flag|option)/].some(s=>s.test(r))?"INVALID_PROVIDER_FORMAT":/invalid.{0,24}model|model.{0,24}(unknown|unavailable|not found|not recognized)|config/.test(r)?"MODEL_UNAVAILABLE":"UNKNOWN"}function Zg(t){return t==="AUTH_REQUIRED"||t==="TIMEOUT_IDLE"||t==="TIMEOUT_TOTAL"||t==="TIMEOUT_RESUME"||t==="PROVIDER_CRASHED"?"permanent":t==="MODEL_UNAVAILABLE"||t==="INVALID_PROVIDER_FORMAT"||t==="PROVIDER_NOT_FOUND"?"config":"transient"}function fu(t){let e=Je(t)?t:void 0,n=e&&Je(e.error)?e.error:void 0,r=e?se(e.code)??se(e.error_code)??se(n?.code)??se(n?.error_code):void 0,o=typeof t=="string"?se(t):e?se(e.message)??se(e.error)??se(e.reason)??se(n?.message)??se(n?.error)??se(n?.reason):void 0,s=Qg(r,o),i=e?At(e.retry_after_ms)??At(e.retryAfterMs)??At(n?.retry_after_ms)??At(n?.retryAfterMs):void 0;return {code:s,kind:Zg(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function So(t){let e=fu(t);return new W(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function pi(t){return new W(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function eh(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=ci))throw new W(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${ci} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function di(){return new W("Antigravity CLI returned empty output with exit code 0. agy may have hidden an auth/quota/model error in its log file; inspect ~/.gemini/antigravity-cli/log for details.","cli/antigravity",{code:"EMPTY_OUTPUT",kind:"transient"})}function Io(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Ao(t){for(let e=t.length-1;e>=0;e-=1){let n=t[e];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:e}}}function th(t){let e=Ao(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||Io(e.event)?.status!=="SUCCESS"||Ro(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=ui(o),i=li(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!Je(o.usage)||At(o.usage.input_tokens)===void 0||At(o.usage.output_tokens)===void 0)return false;return true}function nh(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function rh(t,e){return Je(t)&&Je(e)?{...e,...t}:Je(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&Je(e)?{...e,message:t}:t??e}function oh(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let s of e){let i=Je(s)?s:void 0,c=typeof s=="string"?se(s):se(i?.display_name)??se(i?.action);c&&!n.includes(c)&&n.length<5&&n.push(c.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"";return new W(`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`,"cli/antigravity",{code:"UNKNOWN",kind:"permanent"})}function Ro(t){let e=Ao(t);if(!e)return;if(e.event.kind==="agy_error")return So(e.event.error);let n=Io(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return oh(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return pi("Antigravity returned a result with an unsupported status.");let r=n.error,o=rh(r==null||r===""?n:r,nh(t,e.index));return So(o)}function gu(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function sh(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function ih(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function hu(t){let e=gu(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function ah(t){let e=Je(t)?t:void 0,n=e&&Je(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(se(e?.type)??se(e?.code)??se(e?.error_type)??se(n?.type)??se(n?.code)??se(n?.error_type)??se(r)??"TOOL_ERROR").slice(0,60),s=fu(t).message.slice(0,250);return hu({type:o,message:s})??"Antigravity reported a tool error."}function pu(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function _u(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var ai,Kg,zg,ci,Jg,_i,fi=C(()=>{g();$t();lu();bs();dr();Ht();ur();$s();ai="antigravity",Kg=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),zg=new Set(["--conversation","--resume","--continue"]),ci=18e4,Jg=new Set(["QUOTA_EXHAUSTED","RATE_LIMITED","EMPTY_OUTPUT","AUTH_REQUIRED","MODEL_UNAVAILABLE","TIMEOUT_IDLE","TIMEOUT_TOTAL","TIMEOUT_RESUME","PROVIDER_NOT_FOUND","INVALID_PROVIDER_FORMAT","PROVIDER_CRASHED","UNKNOWN"]);_i={command:"agy",maxInitialInputBytes:ci,meta:{displayName:"Antigravity",models:mc(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=ir(t);if(e?.kind!=="init")return null;let n=e.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(t,e,n){eh(t);let{model:r,effort:o}=Ut(e.model),s=qs(r),i=s.model,c=e.effort??o??s.effort,d=Yg(i,c),u=e.additionalArgs??[],l=Xg(Vg(u,new Set(["--input-format","--output-format"]))),p=i&&!Eo(u,"--model")?["--model",i]:[],_=Eo(u,"--effort")?[]:Cc(d),h=Eo(u,"--mode")||Eo(u,"--dangerously-skip-permissions")?[]:vc(e.mode),m=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...p,..._,...h,...m,...l],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
85
85
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=ar(t),n=Ao(e)?.event,r=Ro(e);if(r)throw r;let o=n?Io(n):void 0;if(o){if(o.status!=="SUCCESS")throw pi("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw pi("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw di();return o.response}if(e.length>0)throw di();let s=t.trim();if(!s)throw di();return s},extractPartialText(t){let e=ar(t),n=Ao(e)?.event;if(!n||n.kind==="agy_error")return;let r=Io(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=ar(n??""),o=Ro(r);return o||(t!==0&&e.trim()?So(e):null)},parseResultMeta(t){let e=ar(t),n=0,r=0,o=0,s=0,i=new Set;for(let d of e){if(d.kind!=="step_update"||d.step.state!=="DONE"||!Je(d.step.usage))continue;let u=ui(d),l=li(d);if(!u||!Number.isSafeInteger(l))continue;let p=JSON.stringify([u,l]);if(i.has(p))continue;let _=d.step.usage,h=At(_.input_tokens),m=At(_.output_tokens);h===void 0||m===void 0||(i.add(p),n+=h,r+=m,o+=At(_.cache_read_tokens)??0,s+=1);}return {usage:s===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:th(e)},model:null}},parseEvent(t,e,n){let r=ir(t);if(!r)return [];let o=e??new Date().toISOString();if(r.kind==="agy_error")return [_u(o,So(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let h=Ro([r]);return h?[_u(o,h)]:[]}if(r.kind!=="step_update")return [];let{step:s}=r,i=ui(r)??"unknown",c=li(r),d=`${i}:${c}`;if((s.state==="DONE"||s.state==="ERROR")&&pu(n,`antigravity:terminal:${d}`))return [];if(s.step_type==="agent_response")return typeof s.text_delta=="string"&&s.text_delta.length>0?[{timestamp:o,type:"text",content:s.text_delta}]:[];if(s.step_type!=="tool")return [];let u=Je(s.tool_info)?s.tool_info:void 0,l=ih(s,u);if(!l)return [];let p=sh(s);if(s.state==="ACTIVE"){if(pu(n,`antigravity:active:${d}`))return [];let h=gu(u?.parameters);return [{timestamp:o,type:"tool_use",toolName:l,toolUseId:p,...h===void 0?{}:{toolInput:h}}]}let _=s.state==="ERROR"?ah(u?.error):hu(u?.output);return [{timestamp:o,type:"tool_result",toolName:l,toolUseId:p,..._===void 0?{}:{resultPreview:_},...s.state==="ERROR"?{isError:true}:{}}]}};});var mu=C(()=>{g();In();Nn();An();sn();});function xn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function bn(t){return xn(t)?t:void 0}function be(t){return typeof t=="string"?t:void 0}function un(t){let e=typeof t=="number"?t:Number(t??0);return Number.isFinite(e)?e:0}function hh(t){let e=[],n=-1,r=0,o=false,s=false;for(let i=0;i<t.length;i+=1){let c=t[i];if(n===-1){(c==="{"||c==="[")&&(n=i,r=1);continue}if(s){s=false;continue}if(c==="\\"&&o){s=true;continue}if(c==='"'){o=!o;continue}o||(c==="{"||c==="["?r+=1:(c==="}"||c==="]")&&(r-=1,r===0&&(e.push(t.slice(n,i+1)),n=-1)));}return n!==-1&&e.push(t.slice(n)),e}function hr(t){let e=t.trim();if(!e)return [];try{let n=JSON.parse(e);return xn(n)?[n]:[]}catch{return hh(e).flatMap(n=>{try{let r=JSON.parse(n);return xn(r)?[r]:[]}catch{return []}})}}function Su(t){let e=JSON.stringify(t);return e===void 0?String(t):e}function cn(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(cn).filter(n=>n!==void 0);return e.length>0?e.join(`
86
86
  `):void 0}if(xn(t)){if(typeof t.text=="string")return t.text;if(typeof t.message=="string")return t.message;if(typeof t.error=="string")return t.error;if(t.type==="text"&&typeof t.data=="string")return t.data;for(let e of ["content","FileContent","rawOutput"]){let n=cn(t[e]);if(n!==void 0)return n}}}function mh(t){let e=i=>Array.isArray(i)&&i.every(c=>Number.isInteger(c)&&c>=0&&c<=255),n=i=>typeof i=="string"&&i.trim().length>0?i:void 0,r=i=>new TextDecoder("utf-8",{fatal:false}).decode(Uint8Array.from(i)),o=i=>{let c=JSON.stringify(i,(d,u)=>e(u)?`<bytes:${u.length}>`:u);return c===void 0?String(i):c},s=t.rawOutput;if(s!=null){let i=bn(s);if(!i)return n(cn(s))??o(s);let c;if(e(i.output)&&i.output.length>0&&(c=n(r(i.output))),!c&&e(i.stdout)&&i.stdout.length>0&&(c=n(r(i.stdout))),!c){let l=bn(i.Result);c=n(i.output)??n(l?.output)??n(cn(s));}let d=e(i.stderr)&&i.stderr.length>0?r(i.stderr):void 0;if(d!==void 0)if(c){let l=c.endsWith(`
@@ -1,2 +1,3 @@
1
1
  import type { CliProviderAdapter } from '../adapter.types.js';
2
+ export declare function getCachedOpencodeModelEfforts(): Promise<Map<string, string[]>>;
2
3
  export declare const opencodeAdapter: CliProviderAdapter;
@@ -80,7 +80,7 @@ ${r.join(`
80
80
  active = excluded.active,
81
81
  time_created = excluded.time_created,
82
82
  time_updated = excluded.time_updated
83
- `);r.transaction(i=>{for(let a of i)o.run(a);})(n);}finally{r.close();}}function lT(t){if(!t)return [];let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){let o=t[n+1],s=o!==void 0&&!o.startsWith("-");e.push({sessionId:s?o:void 0}),s&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&e.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return e}function pT(t){if(!t)return;let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){t[n+1]!==void 0&&!t[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||e.push(r);}return e}function Us(t){let e=pT(t.additionalArgs);return {...t,...e===void 0?{}:{additionalArgs:e},resumeSessionId:void 0}}function _T(t,e){try{return !!t.prepare("SELECT id FROM session_v2 WHERE id = ?").get(e)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function fT(t,e,n){let r=new t(e,{readonly:true,fileMustExist:true});try{return _T(r,n)}finally{r.close();}}async function Ga(t,e={}){let n;try{n=await(e.loadSqlite??oT)();}catch{throw new V("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=e.crewxHome??$s(),o=bo(r),s=Ao(r),i=sT(s),a=iT(e.userDataHome),c=dT(n,a);if(c.length>0){if(!Lp(n,i))try{await(e.initializeDatabase??cT)(o);}catch{throw new V("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!Lp(n,i))throw new V("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{uT(n,i,c);}catch{throw new V("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let u=lT(t.additionalArgs),p=u.map(f=>f.sessionId),l=u.length>0?p[p.length-1]:t.resumeSessionId;if(!l)return u.length>0?Us(t):t;if(p.some(f=>f!==l)||!gl.existsSync(i))return Us(t);try{return fT(n,i,l)?{...t,resumeSessionId:l}:Us(t)}catch{throw new V("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var za=D(()=>{h();En();ja();xp();});function Gn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function Ka(){let t;try{let n=(await import('better-sqlite3')).default,r=Ke.join(Ao(),"opencode.db");t=new n(r,{readonly:!0,fileMustExist:!0});let o=t.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let s=JSON.parse(o.value);if(!Gn(s))throw new Error("OpenCode model catalog shape is unavailable");let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(!Gn(i))throw new Error("OpenCode model catalog body shape is unavailable");let a=new Map;for(let[c,u]of Object.entries(i)){if(!c||!Gn(u)||!Gn(u.models))throw new Error("OpenCode model provider shape is unavailable");for(let[p,l]of Object.entries(u.models)){if(!p||!Gn(l))throw new Error("OpenCode model shape is unavailable");let f=l.capabilities;if(f===void 0)continue;if(!Gn(f))throw new Error("OpenCode model capability shape is unavailable");let g=f.reasoning;if(g===void 0)continue;if(!Gn(g))throw new Error("OpenCode reasoning capability shape is unavailable");let m=g.effort;Array.isArray(m)&&m.length>0&&m.every(k=>typeof k=="string")&&a.set(`${c}/${p}`,m);}}return a}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{t?.close();}catch{}}}var Mp=D(()=>{h();Ja();Ip();vp();ja();za();Rn();});function wT(t){return t?TT[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function St(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function ET(){let t;try{t=Ao();}catch{return Ka().catch(()=>new Map)}let e=Date.now();if($p===t&&Hs&&Hs.expiresAt>e)return Hs.result;$p=t;let n=Ka().catch(()=>new Map);return Hs={expiresAt:e+yT,result:n},n}async function RT(t){let e=await Ga(t),n=t.additionalArgs??[],r=St(n,"--model")||St(n,"-m");if(!t.model||!t.effort||r)return e;let o=(await ET()).get(t.model);return !o||o.includes(t.effort)?e:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...e,effort:void 0})}function Fp(t){let e=[],n=0,r=false,o=false,s=0;for(let a=0;a<t.length;a++){let c=t[a];if(o){o=false;continue}if(c==="\\"&&r){o=true;continue}if(c==='"'){r=!r;continue}if(!r){if(c==="{")n++;else if(c==="}"&&(n--,n===0)){let u=t.slice(s,a+1).trim();u&&e.push(u),s=a+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function Re(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function jp(t){let e=Re(t.part)?t.part:void 0;return t.type==="reasoning"||e?.type==="reasoning"}function ST(t){let e=Re(t.part)?t.part:void 0;return (typeof e?.text=="string"?e.text:typeof t.text=="string"?t.text:void 0)?.trim()||void 0}function bT(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let i=JSON.parse(o);Re(i)?e.push(i):n=!0;continue}catch{}let s=Fp(o);s.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of s)try{let a=JSON.parse(i);Re(a)?e.push(a):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function Qa(t){let e=Re(t.error)?t.error:void 0,n=e&&Re(e.data)?e.data:void 0,r=Wp(e),o=Rt(e?.name),s=Rt(n?.message)??Rt(e?.message)??Xa(r)??Rt(t.message)??Rt(t.errorMessage)??Rt(t.error),i=Rt(t.ref),a=o&&s&&o!==s?`${o}: ${s}`:o??s??Bp;return (i?`${a} (ref: ${i})`:a).slice(0,mT)}function Up(t){let e=Re(t.error)?t.error:void 0,n=typeof e?.type=="string"?e.type:void 0,r=typeof e?.status=="number"?e.status:Number(e?.status),o=Qa(t),s=Wp(e),i=s&&Re(s.error)?s.error:void 0,a=typeof i?.type=="string"?i.type:void 0,c=[o,Xa(s)].filter(Boolean).join(`
83
+ `);r.transaction(i=>{for(let a of i)o.run(a);})(n);}finally{r.close();}}function lT(t){if(!t)return [];let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){let o=t[n+1],s=o!==void 0&&!o.startsWith("-");e.push({sessionId:s?o:void 0}),s&&(n+=1);continue}(r.startsWith("--session=")||r.startsWith("-s="))&&e.push({sessionId:r.slice(r.indexOf("=")+1)||void 0});}return e}function pT(t){if(!t)return;let e=[];for(let n=0;n<t.length;n+=1){let r=t[n];if(r==="-s"||r==="--session"){t[n+1]!==void 0&&!t[n+1].startsWith("-")&&(n+=1);continue}r.startsWith("--session=")||r.startsWith("-s=")||e.push(r);}return e}function Us(t){let e=pT(t.additionalArgs);return {...t,...e===void 0?{}:{additionalArgs:e},resumeSessionId:void 0}}function _T(t,e){try{return !!t.prepare("SELECT id FROM session_v2 WHERE id = ?").get(e)}catch(n){if(n instanceof Error&&/no such table: session_v2/i.test(n.message))return false;throw n}}function fT(t,e,n){let r=new t(e,{readonly:true,fileMustExist:true});try{return _T(r,n)}finally{r.close();}}async function Ga(t,e={}){let n;try{n=await(e.loadSqlite??oT)();}catch{throw new V("OpenCode isolation requires the optional better-sqlite3 dependency. Install it and retry.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}let r=e.crewxHome??$s(),o=bo(r),s=Ao(r),i=sT(s),a=iT(e.userDataHome),c=dT(n,a);if(c.length>0){if(!Lp(n,i))try{await(e.initializeDatabase??cT)(o);}catch{throw new V("Could not initialize the isolated OpenCode credential database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}if(!Lp(n,i))throw new V("The isolated OpenCode credential database is unavailable.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"});try{uT(n,i,c);}catch{throw new V("Could not copy API-key credentials into the isolated OpenCode database.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}let u=lT(t.additionalArgs),p=u.map(f=>f.sessionId),l=u.length>0?p[p.length-1]:t.resumeSessionId;if(!l)return u.length>0?Us(t):t;if(p.some(f=>f!==l)||!gl.existsSync(i))return Us(t);try{return fT(n,i,l)?{...t,resumeSessionId:l}:Us(t)}catch{throw new V("Could not read the isolated OpenCode session database safely.","cli/opencode",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}}var za=D(()=>{h();En();ja();xp();});function Gn(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}async function Ka(){let t;try{let n=(await import('better-sqlite3')).default,r=Ke.join(Ao(),"opencode.db");t=new n(r,{readonly:!0,fileMustExist:!0});let o=t.prepare("SELECT value FROM kv WHERE key = ?").get("models-dev:v2:catalog");if(!o||typeof o.value!="string")throw new Error("OpenCode model catalog row is unavailable");let s=JSON.parse(o.value);if(!Gn(s))throw new Error("OpenCode model catalog shape is unavailable");let i=typeof s.body=="string"?JSON.parse(s.body):s.body;if(!Gn(i))throw new Error("OpenCode model catalog body shape is unavailable");let a=new Map;for(let[c,u]of Object.entries(i)){if(!c||!Gn(u)||!Gn(u.models))throw new Error("OpenCode model provider shape is unavailable");for(let[p,l]of Object.entries(u.models)){if(!p||!Gn(l))throw new Error("OpenCode model shape is unavailable");let f=l.capabilities;if(f===void 0)continue;if(!Gn(f))throw new Error("OpenCode model capability shape is unavailable");let g=f.reasoning;if(g===void 0)continue;if(!Gn(g))throw new Error("OpenCode reasoning capability shape is unavailable");let m=g.effort;(m===void 0||Array.isArray(m)&&m.every(k=>typeof k=="string"))&&a.set(`${c}/${p}`,Array.isArray(m)?m:[]);}}return a}catch{return console.debug("[opencode] could not read private model effort catalog; omitting effort choices"),new Map}finally{try{t?.close();}catch{}}}var Mp=D(()=>{h();Ja();Ip();vp();ja();za();Rn();});function wT(t){return t?TT[t]??{agent:"build",autoApprove:false}:{agent:void 0,autoApprove:false}}function St(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function ET(){let t;try{t=Ao();}catch{return Ka().catch(()=>new Map)}let e=Date.now();if($p===t&&Hs&&Hs.expiresAt>e)return Hs.result;$p=t;let n=Ka().catch(()=>new Map);return Hs={expiresAt:e+yT,result:n},n}async function RT(t){let e=await Ga(t),n=t.additionalArgs??[],r=St(n,"--model")||St(n,"-m");if(!t.model||!t.effort||r)return e;let o=(await ET()).get(t.model);return !o||o.includes(t.effort)?e:(console.debug("[opencode] requested effort is not listed for this model; using OpenCode default"),{...e,effort:void 0})}function Fp(t){let e=[],n=0,r=false,o=false,s=0;for(let a=0;a<t.length;a++){let c=t[a];if(o){o=false;continue}if(c==="\\"&&r){o=true;continue}if(c==='"'){r=!r;continue}if(!r){if(c==="{")n++;else if(c==="}"&&(n--,n===0)){let u=t.slice(s,a+1).trim();u&&e.push(u),s=a+1;}}}let i=t.slice(s).trim();return i&&e.push(i),e}function Re(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function jp(t){let e=Re(t.part)?t.part:void 0;return t.type==="reasoning"||e?.type==="reasoning"}function ST(t){let e=Re(t.part)?t.part:void 0;return (typeof e?.text=="string"?e.text:typeof t.text=="string"?t.text:void 0)?.trim()||void 0}function bT(t){let e=[],n=false;for(let r of t.split(/\r?\n/)){let o=r.trim();if(!o)continue;try{let i=JSON.parse(o);Re(i)?e.push(i):n=!0;continue}catch{}let s=Fp(o);s.length>1&&console.warn("[opencode] extractText: falling back to concatenated-JSON split for a malformed line");for(let i of s)try{let a=JSON.parse(i);Re(a)?e.push(a):n=!0;}catch{n=true;}}return {events:e,malformed:n}}function Qa(t){let e=Re(t.error)?t.error:void 0,n=e&&Re(e.data)?e.data:void 0,r=Wp(e),o=Rt(e?.name),s=Rt(n?.message)??Rt(e?.message)??Xa(r)??Rt(t.message)??Rt(t.errorMessage)??Rt(t.error),i=Rt(t.ref),a=o&&s&&o!==s?`${o}: ${s}`:o??s??Bp;return (i?`${a} (ref: ${i})`:a).slice(0,mT)}function Up(t){let e=Re(t.error)?t.error:void 0,n=typeof e?.type=="string"?e.type:void 0,r=typeof e?.status=="number"?e.status:Number(e?.status),o=Qa(t),s=Wp(e),i=s&&Re(s.error)?s.error:void 0,a=typeof i?.type=="string"?i.type:void 0,c=[o,Xa(s)].filter(Boolean).join(`
84
84
  `);if(r===402||AT(c))return new V(`OpenCode subscription is required: ${o}`,_t,{code:"SUBSCRIPTION_REQUIRED",kind:"config",providerReason:Ro(o)});if(r===403&&(a==="RegionError"||a==="FreeTierError"))return new V(`OpenCode account settings are required: ${o}`,_t,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:"access",providerReason:Ro(o)});if(n==="provider.auth"||r===401||r===403)return new V(`OpenCode authentication is required: ${o}`,_t,{code:"AUTH_REQUIRED",kind:"config"});if(r===410||a==="ModelDeprecated")return new V(`OpenCode model has been retired: ${o}`,_t,{code:"MODEL_RETIRED",kind:"config",replacementModel:IT(s,e,t),providerReason:Ro(o)});if(n==="provider.free-limit"||r===429){let u=NT(e);return new V(`OpenCode rate limit reached: ${o}`,_t,{code:"RATE_LIMITED",kind:"transient",...u===void 0?{}:{retryAfterMs:u}})}if(n==="provider.no-route")return new V(`OpenCode model or variant unavailable: ${o}`,_t,{code:"MODEL_UNAVAILABLE",kind:"config"});if(n==="provider.invalid-request"&&r===400){let u=[o,Xa(s)].filter(g=>g!==void 0),p=u.find(g=>/requires global regions/i.test(g)),l=u.find(g=>/trains on request data/i.test(g)),f=p?"region":l?"training_consent":void 0;if(f)return new V(`OpenCode account settings are required: ${o}`,_t,{code:"ACCOUNT_SETTING_REQUIRED",kind:"config",settingReason:f,providerReason:Ro(p??l)})}return new V(`OpenCode error: ${o}`,_t,{code:"PROVIDER_CRASHED",kind:"transient"})}function Wp(t){let n=(t&&Re(t.response)?t.response:void 0)?.body;if(Re(n))return n;if(typeof n=="string")try{let r=JSON.parse(n);return Re(r)?r:void 0}catch{return}}function Xa(t){let e=t&&Re(t.error)?t.error:void 0;return Rt(e?.message)??Rt(t?.message)}function AT(t){return /insufficient\s+(?:balance|account funds)|credit\s+limit\s+exceeded|payment\s+required|account invoice is overdue|billing_error|please add or update your payment method|(?:GLM Coding Plan|enterprise) package has expired|your current subscription plan does not yet include access to/i.test(t)}function IT(t,e,n){let r=t&&Re(t.metadata)?t.metadata:void 0,o=typeof r?.replacement=="string"?r.replacement.trim():void 0;if(!o)return;let s=[r?.model,e?.model,n.model,n.modelID].find(c=>typeof c=="string"&&c.trim().length>0)?.trim(),i=s&&s.includes("/")?s.slice(0,s.indexOf("/")):"opencode-go",a=o.includes("/")?o:`${i}/${o}`;return /^[A-Za-z0-9._/-]{1,128}$/.test(a)?a:void 0}function NT(t){let e=t?.retryAfterMs;if(typeof e=="number"&&Number.isFinite(e)&&e>=0)return e;let r=(t&&Re(t.response)?t.response:void 0)?.body,o=typeof r=="string"?OT(r):Re(r)?r:void 0;if(o){let s=Ya(o);if(s)return Hp(s.value,s.key==="retryafterms")}if(typeof r=="string"){let s=r.match(/retry[-_]after(?:\s*[:=]\s*|\s+)["']?([^"'\s,;}]+)/i);if(s?.[1])return Hp(s[1],false)}}function OT(t){try{let e=JSON.parse(t);return Re(e)?e:void 0}catch{return}}function Ya(t){if(Array.isArray(t)){for(let e of t){let n=Ya(e);if(n)return n}return}if(Re(t)){for(let[e,n]of Object.entries(t)){let r=e.toLowerCase().replace(/[-_]/g,"");if(r==="retryafterms"||r==="retryafter")return {value:n,key:r}}for(let e of Object.values(t)){let n=Ya(e);if(n)return n}}}function Hp(t,e){if(typeof t=="number"&&Number.isFinite(t)&&t>=0)return e?t:Math.round(t*1e3);if(typeof t!="string"||!t.trim())return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return e?n:Math.round(n*1e3);if(e)return;let r=Date.parse(t);return Number.isFinite(r)?Math.max(0,r-Date.now()):void 0}function qp(t){let e=bT(t),n=[],r=null,o=0,s=[],i=[],a,c=false;for(let u of e.events){if(jp(u))continue;let p=typeof u.type=="string"?u.type:void 0;if(p){if(p==="text"){let l=Re(u.part)?u.part:void 0,f=typeof l?.text=="string"?l.text:void 0;f?.trim()&&n.push(f.trim());continue}if(p==="result"){typeof u.result=="string"&&(r=u.result);continue}if(p==="tool_use"){o++;continue}if(p==="error"){s.push(u),i.push(Qa(u));continue}if(p==="step_finish"){c=true;let l=Re(u.part)?u.part:void 0;a=typeof l?.reason=="string"?l.reason:void 0;}}}return {...e,texts:n,resultText:r,toolUseCount:o,errorEvents:s,errorMessages:i,terminalReason:a,hasTerminal:c}}function Gp(t){return (t??"unknown").trim().toLowerCase().replace(/_/g,"-")}function vT(){return new V("OpenCode returned no assistant output.",_t,{code:"EMPTY_OUTPUT",kind:"transient"})}function CT(){return new V("OpenCode emitted malformed JSON output.",_t,{code:"PROVIDER_CRASHED",kind:"transient"})}function DT(t,e){switch(Gp(t)){case "length":return new V("OpenCode stopped because the context window was exceeded.",_t,{code:"UNKNOWN",kind:"permanent"});case "content-filter":return new V("OpenCode stopped because the content filter blocked the response.",_t,{code:"UNKNOWN",kind:"permanent"});case "error":return new V(`${Bp} while generating a response.`,_t,{code:"PROVIDER_CRASHED",kind:"transient"});default:return null}}var hT,_t,Bp,mT,kT,yT,$p,Hs,TT,Za,ed=D(()=>{h();En();Ap();Eo();Sr();jn();Mp();za();hT=new Set(["step_start","step_finish"]),_t="cli/opencode",Bp="OpenCode provider error",mT=240,kT="Follow the instructions provided on standard input.",yT=3e5,TT={build:{agent:"build",autoApprove:false},"build-auto":{agent:"build",autoApprove:true},plan:{agent:"plan",autoApprove:false},"plan-auto":{agent:"plan",autoApprove:true}};Za={command:"opencode",prepare:RT,meta:{displayName:"OpenCode",capabilities:{resume:true}},buildArgs(t,e,n){let r=e.additionalArgs,o=r!==void 0?[...r]:["run"];St(o,"--format")||o.push("--format","json"),St(o,"--thinking")||o.push("--thinking"),!St(o,"--standalone")&&!St(o,"--server")&&o.push("--standalone"),e.resumeSessionId&&!St(o,"-s")&&!St(o,"--session")&&o.push("-s",e.resumeSessionId);let{agent:s,autoApprove:i}=wT(e.mode);St(o,"--agent")||s!==void 0&&o.push("--agent",s),i&&!St(o,"--auto")&&o.push("--auto");let a=St(o,"--model")||St(o,"-m");if(e.model&&!a){let c=e.effort?`${e.model}#${e.effort}`:e.model;o.push("--model",c);}else e.effort&&!e.model&&!a&&console.debug("[opencode] ignoring effort because no model is configured");return o.push(kT),{args:o,stdinMessage:t,env:bo()}},extractText(t){let e=qp(t),n=e.errorEvents[0];if(n)throw Up(n);let r=DT(e.terminalReason??"");if(r)throw r;let o=e.texts.length>0?e.texts[e.texts.length-1]:void 0;if(o!==void 0)return o;if(e.resultText?.trim())return e.resultText;if(e.malformed)throw CT();let s=Gp(e.terminalReason);if(e.hasTerminal&&s==="tool-calls"&&e.toolUseCount>0)return "";throw vT()},interpretExit(t,e,n=""){if(t===0)return null;let o=qp(n).errorEvents[0];return o?Up(o):null},parseResultMeta(t){let e=Ar(t);return e?{usage:{inputTokens:e.inputTokens,outputTokens:e.outputTokens,cachedInputTokens:e.cachedInputTokens,costUsd:0},model:null}:{usage:null,model:null}},parseEvent(t,e,n){let r=e??new Date().toISOString(),o=[],s=new Map,i;try{JSON.parse(t),i=[t];}catch{i=Fp(t),i.length>1&&console.warn("[opencode] parseEvent: falling back to concatenated-JSON split for a malformed line");}for(let a of i){let c;try{c=JSON.parse(a);}catch{continue}let u=Mt(c,r),p=c.type;if(jp(c)){let l=ST(c);if(!l)continue;let f=Re(c.part)?c.part:void 0,g=typeof f?.id=="string"?f.id:typeof c.id=="string"?c.id:void 0,m=l;if(g){let k=`opencode.reasoning:${g}`,T=n?.state.get(k),S=typeof T=="string"?T:s.get(g);if(typeof S=="string"&&(S===l||S.startsWith(l))||typeof S=="string"&&l.startsWith(S)&&(m=l.slice(S.length).trim(),!m))continue;s.set(g,l),n?.state.set(k,l);}o.push({timestamp:u,type:"thinking",content:m});continue}if(p){if(p==="text"){let f=c.part?.text;f&&o.push({timestamp:u,type:"text",content:f});continue}if(p==="tool_use"){let l=c.part;if(!l)continue;let f=String(l.tool||""),g=String(l.callID||l.id||""),m=l.state,k=String(m?.status||""),T=m?.input,S=Pt(T);if(o.push({timestamp:u,type:"tool_use",toolName:f,toolUseId:g,toolInput:S}),k==="completed"&&m?.output!==void 0){let w=m.output,P=typeof w=="string"?w:JSON.stringify(w);o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:P,isError:false});}else k==="error"&&o.push({timestamp:u,type:"tool_result",toolUseId:g,resultPreview:String(m?.error||"tool error"),isError:true});continue}if(p==="error"){let l=Qa(c);o.push({timestamp:u,type:"error",content:l,errorMessage:l});continue}}}return o},suppressOutputLine(t){let e=t.trim();if(!e.startsWith("{")||!e.endsWith("}"))return false;try{let r=JSON.parse(e).type;return r?hT.has(r):!1}catch{return false}}};});var zp=D(()=>{h();});function qs(t,e){return t.some(n=>n===e||n.startsWith(`${e}=`))}function $T(t,e){let n=[];for(let r=0;r<t.length;r+=1){let o=t[r],s=[...e].find(i=>o===i||o.startsWith(`${i}=`));s?o===s&&r+1<t.length&&(r+=1):n.push(o);}return n}function UT(t){let e=[];for(let n=0;n<t.length;n+=1){let r=t[n],o=r.indexOf("="),s=o>0?r.slice(0,o):r;if(!PT.has(s)){e.push(r);continue}r===s&&n+1<t.length&&!t[n+1].startsWith("-")&&(n+=1);}return e}function bt(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function HT(t,e){if(!(t?LT.has(t)||pn(td).some(s=>s.id===t):false)||!t)return e;let r=br(td,t),o=Ma(td)[t]?.defaultEffort;if(r.length!==0)return e?r.includes(e)?e:o&&r.includes(o)?o:void 0:o}function _n(t){return typeof t=="number"&&Number.isSafeInteger(t)&&t>=0?t:void 0}function od(t){return t.kind==="step_update"?typeof t.step.conversation_id=="string"?t.step.conversation_id:void 0:typeof t.envelope.conversation_id=="string"?t.envelope.conversation_id:void 0}function sd(t){return t.step.step_index}function Ee(t){if(typeof t!="string")return;let e=t.split(/\r?\n/,1)[0]?.trim();return e&&Ns(e)?.slice(0,500).trim()||void 0}function qT(t,e){let n=(t??"").trim().toUpperCase().replace(/[^A-Z0-9]+/g,"_");if(n!=="UNKNOWN"&&MT.has(n))return n;let r=`${n} ${e??""}`.toLowerCase();return /quota|resource_exhausted|usage[ _-]?limit|credits?.{0,20}exhaust/.test(r)?"QUOTA_EXHAUSTED":/rate[ _-]?limit|throttl/.test(r)?"RATE_LIMITED":/auth|sign[ _-]?in|log(?:ged)?[ _-]?in|unauthori[sz]ed|credential/.test(r)?"AUTH_REQUIRED":[/unknown (?:flag|option)/,/flag provided but not defined/,/unrecognized (?:flag|option)/,/invalid value for (?:flag|option)/,/invalid (?:flag|option)/].some(s=>s.test(r))?"INVALID_PROVIDER_FORMAT":/invalid.{0,24}model|model.{0,24}(unknown|unavailable|not found|not recognized)|config/.test(r)?"MODEL_UNAVAILABLE":"UNKNOWN"}function BT(t){return t==="AUTH_REQUIRED"||t==="TIMEOUT_IDLE"||t==="TIMEOUT_TOTAL"||t==="TIMEOUT_RESUME"||t==="PROVIDER_CRASHED"?"permanent":t==="MODEL_UNAVAILABLE"||t==="INVALID_PROVIDER_FORMAT"||t==="PROVIDER_NOT_FOUND"?"config":"transient"}function Jp(t){let e=bt(t)?t:void 0,n=e&&bt(e.error)?e.error:void 0,r=e?Ee(e.code)??Ee(e.error_code)??Ee(n?.code)??Ee(n?.error_code):void 0,o=typeof t=="string"?Ee(t):e?Ee(e.message)??Ee(e.error)??Ee(e.reason)??Ee(n?.message)??Ee(n?.error)??Ee(n?.reason):void 0,s=qT(r,o),i=e?_n(e.retry_after_ms)??_n(e.retryAfterMs)??_n(n?.retry_after_ms)??_n(n?.retryAfterMs):void 0;return {code:s,kind:BT(s),message:o??"Antigravity reported a terminal error.",...i===void 0?{}:{retryAfterMs:i}}}function Fs(t){let e=Jp(t);return new V(e.message,"cli/antigravity",{code:e.code,kind:e.kind,...e.retryAfterMs===void 0?{}:{retryAfterMs:e.retryAfterMs}})}function id(t){return new V(t,"cli/antigravity",{code:"INVALID_PROVIDER_FORMAT",kind:"config"})}function FT(t){let e=new TextEncoder().encode(t).byteLength;if(!(e<=rd))throw new V(`Input is too large: final provider initial input is ${e} UTF-8 bytes; budget is ${rd} bytes.`,"cli/antigravity",{code:"UNKNOWN",kind:"config"})}function nd(){return new V("Antigravity CLI returned empty output with exit code 0. agy may have hidden an auth/quota/model error in its log file; inspect ~/.gemini/antigravity-cli/log for details.","cli/antigravity",{code:"EMPTY_OUTPUT",kind:"transient"})}function js(t){if(t.kind==="result"||t.kind==="legacy_result")return t.result}function Ws(t){for(let e=t.length-1;e>=0;e-=1){let n=t[e];if(n&&(n.kind==="result"||n.kind==="legacy_result"||n.kind==="agy_error"))return {event:n,index:e}}}function jT(t){let e=Ws(t);if(!e||e.event.kind==="agy_error"||e.index!==t.length-1||js(e.event)?.status!=="SUCCESS"||Bs(t))return false;let r=new Map;for(let o of t){if(o.kind!=="step_update"||o.step.step_type!=="agent_response")continue;let s=od(o),i=sd(o);!s||!Number.isSafeInteger(i)||r.set(JSON.stringify([s,i]),o.step);}if(r.size===0)return false;for(let o of r.values())if(o.state!=="DONE"||!bt(o.usage)||_n(o.usage.input_tokens)===void 0||_n(o.usage.output_tokens)===void 0)return false;return true}function WT(t,e){for(let n=e-1;n>=0;n-=1){let r=t[n];if(r?.kind==="agy_error")return r.error}}function GT(t,e){return bt(t)&&bt(e)?{...e,...t}:bt(t)&&typeof e=="string"?{...t,message:e}:typeof t=="string"&&bt(e)?{...e,message:t}:t??e}function zT(t){let e=Array.isArray(t.denied_actions)?t.denied_actions:[],n=[];for(let s of e){let i=bt(s)?s:void 0,a=typeof s=="string"?Ee(s):Ee(i?.display_name)??Ee(i?.action);a&&!n.includes(a)&&n.length<5&&n.push(a.slice(0,80));}let r=Math.max(0,e.length-n.length),o=n.length>0?` (${n.join(", ")}${r>0?`, +${r} more`:""})`:"";return new V(`Permission denied: Antigravity blocked ${e.length} requested action${e.length===1?"":"s"}${o}.`,"cli/antigravity",{code:"UNKNOWN",kind:"permanent"})}function Bs(t){let e=Ws(t);if(!e)return;if(e.event.kind==="agy_error")return Fs(e.event.error);let n=js(e.event);if(!n)return;if(Array.isArray(n.denied_actions)&&n.denied_actions.length>0)return zT(n);if(n.status==="SUCCESS")return;if(n.status!=="ERROR")return id("Antigravity returned a result with an unsupported status.");let r=n.error,o=GT(r==null||r===""?n:r,WT(t,e.index));return Fs(o)}function Xp(t){if(typeof t=="string")return t;if(t!=null)try{return JSON.stringify(t)}catch{return}}function KT(t){return `agy:${String(t.conversation_id)}:${String(t.step_index)}`}function VT(t,e){let n=typeof e?.name=="string"?e.name:t.tool_name;return typeof n=="string"&&n.trim()?n:void 0}function Yp(t){let e=Xp(t);if(e)return e.length<=2e3?e:`${e.slice(0,1999)}\u2026`}function JT(t){let e=bt(t)?t:void 0,n=e&&bt(e.error)?e.error:void 0,r=typeof t=="string"?t.trim().match(/^([A-Z][A-Z0-9_]*)(?:[:\s]|$)/)?.[1]:void 0,o=(Ee(e?.type)??Ee(e?.code)??Ee(e?.error_type)??Ee(n?.type)??Ee(n?.code)??Ee(n?.error_type)??Ee(r)??"TOOL_ERROR").slice(0,60),s=Jp(t).message.slice(0,250);return Yp({type:o,message:s})??"Antigravity reported a tool error."}function Kp(t,e){return t?t.state.has(e)?true:(t.state.set(e,true),false):false}function Vp(t,e){return {timestamp:t,type:"error",content:e.message,errorMessage:e.message,isError:true}}var td,LT,PT,rd,MT,ad,dd=D(()=>{h();En();zp();Ia();yo();Rn();wo();vs();td="antigravity",LT=new Set(["claude-sonnet-4-6","claude-opus-4-6-thinking","gpt-oss-120b"]),PT=new Set(["--conversation","--resume","--continue"]),rd=18e4,MT=new Set(["QUOTA_EXHAUSTED","RATE_LIMITED","EMPTY_OUTPUT","AUTH_REQUIRED","MODEL_UNAVAILABLE","TIMEOUT_IDLE","TIMEOUT_TOTAL","TIMEOUT_RESUME","PROVIDER_NOT_FOUND","INVALID_PROVIDER_FORMAT","PROVIDER_CRASHED","UNKNOWN"]);ad={command:"agy",maxInitialInputBytes:rd,meta:{displayName:"Antigravity",models:Ql(),defaultIdleMs:6e5,capabilities:{resume:true,usageCompleteness:true}},extractSessionId(t){let e=mo(t);if(e?.kind!=="init")return null;let n=e.envelope.conversation_id;return typeof n=="string"&&n.trim().length>0?n.trim():null},buildArgs(t,e,n){FT(t);let{model:r,effort:o}=Sn(e.model),s=La(r),i=s.model,a=e.effort??o??s.effort,c=HT(i,a),u=e.additionalArgs??[],p=UT($T(u,new Set(["--input-format","--output-format"]))),l=i&&!qs(u,"--model")?["--model",i]:[],f=qs(u,"--effort")?[]:lp(c),g=qs(u,"--mode")||qs(u,"--dangerously-skip-permissions")?[]:up(e.mode),m=typeof e.resumeSessionId=="string"&&e.resumeSessionId.trim().length>0?["--conversation",e.resumeSessionId]:[];return {args:["--input-format","stream-json","--output-format","stream-json",...l,...f,...g,...m,...p],stdinMessage:`${JSON.stringify({event:"user",message:{content:t}})}
85
85
  `,env:{AGY_CLI_DISABLE_AUTO_UPDATE:"true"}}},extractText(t){let e=Fn(t),n=Ws(e)?.event,r=Bs(e);if(r)throw r;let o=n?js(n):void 0;if(o){if(o.status!=="SUCCESS")throw id("Antigravity returned a result with an unsupported status.");if(typeof o.response!="string")throw id("Antigravity returned a successful result without a response string.");if(!o.response.trim())throw nd();return o.response}if(e.length>0)throw nd();let s=t.trim();if(!s)throw nd();return s},extractPartialText(t){let e=Fn(t),n=Ws(e)?.event;if(!n||n.kind==="agy_error")return;let r=js(n);return r&&typeof r.response=="string"&&r.response.trim()?r.response:void 0},interpretExit(t,e,n){let r=Fn(n??""),o=Bs(r);return o||(t!==0&&e.trim()?Fs(e):null)},parseResultMeta(t){let e=Fn(t),n=0,r=0,o=0,s=0,i=new Set;for(let c of e){if(c.kind!=="step_update"||c.step.state!=="DONE"||!bt(c.step.usage))continue;let u=od(c),p=sd(c);if(!u||!Number.isSafeInteger(p))continue;let l=JSON.stringify([u,p]);if(i.has(l))continue;let f=c.step.usage,g=_n(f.input_tokens),m=_n(f.output_tokens);g===void 0||m===void 0||(i.add(l),n+=g,r+=m,o+=_n(f.cache_read_tokens)??0,s+=1);}return {usage:s===0?null:{inputTokens:n,outputTokens:r,cachedInputTokens:o,costUsd:0,complete:jT(e)},model:null}},parseEvent(t,e,n){let r=mo(t);if(!r)return [];let o=e??new Date().toISOString();if(r.kind==="agy_error")return [Vp(o,Fs(r.error))];if(r.kind==="legacy_result"||r.kind==="result"){let g=Bs([r]);return g?[Vp(o,g)]:[]}if(r.kind!=="step_update")return [];let{step:s}=r,i=od(r)??"unknown",a=sd(r),c=`${i}:${a}`;if((s.state==="DONE"||s.state==="ERROR")&&Kp(n,`antigravity:terminal:${c}`))return [];if(s.step_type==="agent_response")return typeof s.text_delta=="string"&&s.text_delta.length>0?[{timestamp:o,type:"text",content:s.text_delta}]:[];if(s.step_type!=="tool")return [];let u=bt(s.tool_info)?s.tool_info:void 0,p=VT(s,u);if(!p)return [];let l=KT(s);if(s.state==="ACTIVE"){if(Kp(n,`antigravity:active:${c}`))return [];let g=Xp(u?.parameters);return [{timestamp:o,type:"tool_use",toolName:p,toolUseId:l,...g===void 0?{}:{toolInput:g}}]}let f=s.state==="ERROR"?JT(u?.error):Yp(u?.output);return [{timestamp:o,type:"tool_result",toolName:p,toolUseId:l,...f===void 0?{}:{resultPreview:f},...s.state==="ERROR"?{isError:true}:{}}]}};});var Qp=D(()=>{h();Er();Sr();Rr();jn();});function Nr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Or(t){return Nr(t)?t:void 0}function rt(t){return typeof t=="string"?t:void 0}function Kn(t){let e=typeof t=="number"?t:Number(t??0);return Number.isFinite(e)?e:0}function ow(t){let e=[],n=-1,r=0,o=false,s=false;for(let i=0;i<t.length;i+=1){let a=t[i];if(n===-1){(a==="{"||a==="[")&&(n=i,r=1);continue}if(s){s=false;continue}if(a==="\\"&&o){s=true;continue}if(a==='"'){o=!o;continue}o||(a==="{"||a==="["?r+=1:(a==="}"||a==="]")&&(r-=1,r===0&&(e.push(t.slice(n,i+1)),n=-1)));}return n!==-1&&e.push(t.slice(n)),e}function Io(t){let e=t.trim();if(!e)return [];try{let n=JSON.parse(e);return Nr(n)?[n]:[]}catch{return ow(e).flatMap(n=>{try{let r=JSON.parse(n);return Nr(r)?[r]:[]}catch{return []}})}}function s_(t){let e=JSON.stringify(t);return e===void 0?String(t):e}function zn(t){if(typeof t=="string")return t;if(Array.isArray(t)){let e=t.map(zn).filter(n=>n!==void 0);return e.length>0?e.join(`
86
86
  `):void 0}if(Nr(t)){if(typeof t.text=="string")return t.text;if(typeof t.message=="string")return t.message;if(typeof t.error=="string")return t.error;if(t.type==="text"&&typeof t.data=="string")return t.data;for(let e of ["content","FileContent","rawOutput"]){let n=zn(t[e]);if(n!==void 0)return n}}}function sw(t){let e=i=>Array.isArray(i)&&i.every(a=>Number.isInteger(a)&&a>=0&&a<=255),n=i=>typeof i=="string"&&i.trim().length>0?i:void 0,r=i=>new TextDecoder("utf-8",{fatal:false}).decode(Uint8Array.from(i)),o=i=>{let a=JSON.stringify(i,(c,u)=>e(u)?`<bytes:${u.length}>`:u);return a===void 0?String(i):a},s=t.rawOutput;if(s!=null){let i=Or(s);if(!i)return n(zn(s))??o(s);let a;if(e(i.output)&&i.output.length>0&&(a=n(r(i.output))),!a&&e(i.stdout)&&i.stdout.length>0&&(a=n(r(i.stdout))),!a){let p=Or(i.Result);a=n(i.output)??n(p?.output)??n(zn(s));}let c=e(i.stderr)&&i.stderr.length>0?r(i.stderr):void 0;if(c!==void 0)if(a){let p=a.endsWith(`
@@ -5,16 +5,19 @@ export declare const RouteModelConfigSchema: z.ZodObject<{
5
5
  model: z.ZodString;
6
6
  weight: z.ZodDefault<z.ZodNumber>;
7
7
  account: z.ZodOptional<z.ZodString>;
8
+ effort: z.ZodOptional<z.ZodString>;
8
9
  }, "strict", z.ZodTypeAny, {
9
10
  id: string;
10
11
  model: string;
11
12
  provider: string;
12
13
  weight: number;
14
+ effort?: string | undefined;
13
15
  account?: string | undefined;
14
16
  }, {
15
17
  id: string;
16
18
  model: string;
17
19
  provider: string;
20
+ effort?: string | undefined;
18
21
  weight?: number | undefined;
19
22
  account?: string | undefined;
20
23
  }>;
@@ -24,16 +27,19 @@ export declare const RouteCandidateConfigSchema: z.ZodObject<{
24
27
  model: z.ZodString;
25
28
  weight: z.ZodDefault<z.ZodNumber>;
26
29
  account: z.ZodOptional<z.ZodString>;
30
+ effort: z.ZodOptional<z.ZodString>;
27
31
  }, "strict", z.ZodTypeAny, {
28
32
  id: string;
29
33
  model: string;
30
34
  provider: string;
31
35
  weight: number;
36
+ effort?: string | undefined;
32
37
  account?: string | undefined;
33
38
  }, {
34
39
  id: string;
35
40
  model: string;
36
41
  provider: string;
42
+ effort?: string | undefined;
37
43
  weight?: number | undefined;
38
44
  account?: string | undefined;
39
45
  }>;
@@ -66,16 +72,19 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
66
72
  model: z.ZodString;
67
73
  weight: z.ZodDefault<z.ZodNumber>;
68
74
  account: z.ZodOptional<z.ZodString>;
75
+ effort: z.ZodOptional<z.ZodString>;
69
76
  }, "strict", z.ZodTypeAny, {
70
77
  id: string;
71
78
  model: string;
72
79
  provider: string;
73
80
  weight: number;
81
+ effort?: string | undefined;
74
82
  account?: string | undefined;
75
83
  }, {
76
84
  id: string;
77
85
  model: string;
78
86
  provider: string;
87
+ effort?: string | undefined;
79
88
  weight?: number | undefined;
80
89
  account?: string | undefined;
81
90
  }>, "many">>;
@@ -85,16 +94,19 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
85
94
  model: z.ZodString;
86
95
  weight: z.ZodDefault<z.ZodNumber>;
87
96
  account: z.ZodOptional<z.ZodString>;
97
+ effort: z.ZodOptional<z.ZodString>;
88
98
  }, "strict", z.ZodTypeAny, {
89
99
  id: string;
90
100
  model: string;
91
101
  provider: string;
92
102
  weight: number;
103
+ effort?: string | undefined;
93
104
  account?: string | undefined;
94
105
  }, {
95
106
  id: string;
96
107
  model: string;
97
108
  provider: string;
109
+ effort?: string | undefined;
98
110
  weight?: number | undefined;
99
111
  account?: string | undefined;
100
112
  }>, "many">>;
@@ -110,6 +122,7 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
110
122
  model: string;
111
123
  provider: string;
112
124
  weight: number;
125
+ effort?: string | undefined;
113
126
  account?: string | undefined;
114
127
  }[] | undefined;
115
128
  chain?: {
@@ -121,6 +134,7 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
121
134
  model: string;
122
135
  provider: string;
123
136
  weight: number;
137
+ effort?: string | undefined;
124
138
  account?: string | undefined;
125
139
  }[] | undefined;
126
140
  defaultModel?: string | undefined;
@@ -132,6 +146,7 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
132
146
  id: string;
133
147
  model: string;
134
148
  provider: string;
149
+ effort?: string | undefined;
135
150
  weight?: number | undefined;
136
151
  account?: string | undefined;
137
152
  }[] | undefined;
@@ -143,6 +158,7 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
143
158
  id: string;
144
159
  model: string;
145
160
  provider: string;
161
+ effort?: string | undefined;
146
162
  weight?: number | undefined;
147
163
  account?: string | undefined;
148
164
  }[] | undefined;
@@ -158,6 +174,7 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
158
174
  model: string;
159
175
  provider: string;
160
176
  weight: number;
177
+ effort?: string | undefined;
161
178
  account?: string | undefined;
162
179
  }[] | undefined;
163
180
  chain?: {
@@ -169,6 +186,7 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
169
186
  model: string;
170
187
  provider: string;
171
188
  weight: number;
189
+ effort?: string | undefined;
172
190
  account?: string | undefined;
173
191
  }[] | undefined;
174
192
  defaultModel?: string | undefined;
@@ -180,6 +198,7 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
180
198
  id: string;
181
199
  model: string;
182
200
  provider: string;
201
+ effort?: string | undefined;
183
202
  weight?: number | undefined;
184
203
  account?: string | undefined;
185
204
  }[] | undefined;
@@ -191,6 +210,7 @@ declare const RouteConfigInputSchema: z.ZodEffects<z.ZodObject<{
191
210
  id: string;
192
211
  model: string;
193
212
  provider: string;
213
+ effort?: string | undefined;
194
214
  weight?: number | undefined;
195
215
  account?: string | undefined;
196
216
  }[] | undefined;
@@ -1418,6 +1418,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
1418
1418
  id: string;
1419
1419
  model: string;
1420
1420
  provider: string;
1421
+ effort?: string | undefined;
1421
1422
  weight?: number | undefined;
1422
1423
  account?: string | undefined;
1423
1424
  }[] | undefined;
@@ -1429,6 +1430,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
1429
1430
  id: string;
1430
1431
  model: string;
1431
1432
  provider: string;
1433
+ effort?: string | undefined;
1432
1434
  weight?: number | undefined;
1433
1435
  account?: string | undefined;
1434
1436
  }[] | undefined;
@@ -2097,6 +2099,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
2097
2099
  id: string;
2098
2100
  model: string;
2099
2101
  provider: string;
2102
+ effort?: string | undefined;
2100
2103
  weight?: number | undefined;
2101
2104
  account?: string | undefined;
2102
2105
  }[] | undefined;
@@ -2108,6 +2111,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
2108
2111
  id: string;
2109
2112
  model: string;
2110
2113
  provider: string;
2114
+ effort?: string | undefined;
2111
2115
  weight?: number | undefined;
2112
2116
  account?: string | undefined;
2113
2117
  }[] | undefined;
@@ -2776,6 +2780,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
2776
2780
  id: string;
2777
2781
  model: string;
2778
2782
  provider: string;
2783
+ effort?: string | undefined;
2779
2784
  weight?: number | undefined;
2780
2785
  account?: string | undefined;
2781
2786
  }[] | undefined;
@@ -2787,6 +2792,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
2787
2792
  id: string;
2788
2793
  model: string;
2789
2794
  provider: string;
2795
+ effort?: string | undefined;
2790
2796
  weight?: number | undefined;
2791
2797
  account?: string | undefined;
2792
2798
  }[] | undefined;
@@ -3455,6 +3461,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
3455
3461
  id: string;
3456
3462
  model: string;
3457
3463
  provider: string;
3464
+ effort?: string | undefined;
3458
3465
  weight?: number | undefined;
3459
3466
  account?: string | undefined;
3460
3467
  }[] | undefined;
@@ -3466,6 +3473,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
3466
3473
  id: string;
3467
3474
  model: string;
3468
3475
  provider: string;
3476
+ effort?: string | undefined;
3469
3477
  weight?: number | undefined;
3470
3478
  account?: string | undefined;
3471
3479
  }[] | undefined;
@@ -4134,6 +4142,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
4134
4142
  id: string;
4135
4143
  model: string;
4136
4144
  provider: string;
4145
+ effort?: string | undefined;
4137
4146
  weight?: number | undefined;
4138
4147
  account?: string | undefined;
4139
4148
  }[] | undefined;
@@ -4145,6 +4154,7 @@ export declare const CrewxProjectConfigSchema: z.ZodEffects<z.ZodObject<{
4145
4154
  id: string;
4146
4155
  model: string;
4147
4156
  provider: string;
4157
+ effort?: string | undefined;
4148
4158
  weight?: number | undefined;
4149
4159
  account?: string | undefined;
4150
4160
  }[] | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewx/sdk",
3
- "version": "0.9.0-rc.212",
3
+ "version": "0.9.0-rc.214",
4
4
  "license": "UNLICENSED",
5
5
  "engines": {
6
6
  "node": ">=20.19.0"