@cortexkit/opencode-anthropic-auth 1.21.0 → 1.22.0
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/README.md +36 -8
- package/dist/cli.js +1 -1
- package/dist/effort-history.d.ts +58 -0
- package/dist/fable-fallback.d.ts +6 -7
- package/dist/{index-y0khnbt6.js → index-7f57ewkp.js} +1 -1
- package/dist/{index-4nz423bt.js → index-8aga2zwv.js} +1 -1
- package/dist/{index-w9d41yy9.js → index-926t2bzc.js} +1 -1
- package/dist/{index-1db17bc2.js → index-bx5hsgf8.js} +1 -1
- package/dist/{index-4x20896x.js → index-cgez4m0h.js} +1 -1
- package/dist/index-d3f8g6ve.js +428 -0
- package/dist/index-sh51yqxs.js +2 -0
- package/dist/index.js +23 -21
- package/dist/{logger-ftk4bg3p.js → logger-jrkranbz.js} +1 -1
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.d.ts +15 -0
- package/dist/rpc/protocol.js +1 -1
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/sidebar-state.d.ts +2 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/transform.d.ts +13 -1
- package/dist/tui/command-dialogs.d.ts +2 -8
- package/dist/tui-preferences.js +1 -1
- package/package.json +2 -2
- package/src/rpc/protocol.ts +17 -0
- package/src/sidebar-state.ts +16 -1
- package/src/tui/command-dialogs.tsx +40 -41
- package/src/tui-compiled/rpc/protocol.ts +17 -0
- package/src/tui-compiled/sidebar-state.ts +16 -1
- package/src/tui-compiled/tui/command-dialogs.tsx +49 -33
- package/src/tui-compiled/tui.tsx +7 -3
- package/src/tui.tsx +17 -3
- package/dist/index-wezdyxst.js +0 -2
- package/dist/index-yskwj5e6.js +0 -428
package/src/tui.tsx
CHANGED
|
@@ -313,13 +313,24 @@ function AccountBlock(props: {
|
|
|
313
313
|
active: boolean
|
|
314
314
|
pacingEnabled: boolean
|
|
315
315
|
needsReauth?: boolean
|
|
316
|
+
vaultReauth?: boolean
|
|
316
317
|
tierLabel?: string
|
|
317
318
|
marginTop?: number
|
|
318
319
|
}) {
|
|
319
320
|
const statusWord = () =>
|
|
320
|
-
props.needsReauth
|
|
321
|
+
props.needsReauth
|
|
322
|
+
? 're-login'
|
|
323
|
+
: props.vaultReauth
|
|
324
|
+
? 'vault reauth'
|
|
325
|
+
: props.active
|
|
326
|
+
? 'active'
|
|
327
|
+
: 'idle'
|
|
321
328
|
const statusTone = (): Tone =>
|
|
322
|
-
props.needsReauth
|
|
329
|
+
props.needsReauth || props.vaultReauth
|
|
330
|
+
? 'warn'
|
|
331
|
+
: props.active
|
|
332
|
+
? 'ok'
|
|
333
|
+
: 'muted'
|
|
323
334
|
const pacingFor = (
|
|
324
335
|
window:
|
|
325
336
|
| { usedPercent: number; remainingPercent: number; resetsAt?: string }
|
|
@@ -638,7 +649,9 @@ function QuotaSidebar(props: {
|
|
|
638
649
|
const quotaBackedOff = () => state().main?.quotaBackedOff === true
|
|
639
650
|
const refreshBackedOff = () => state().main?.refreshBackedOff === true
|
|
640
651
|
const needsReauth = () => enabledFallbacks().some((f) => f.needsReauth)
|
|
641
|
-
const
|
|
652
|
+
const vaultReauth = () => enabledFallbacks().some((f) => f.vaultReauth)
|
|
653
|
+
const degraded = () =>
|
|
654
|
+
quotaBackedOff() || refreshBackedOff() || needsReauth() || vaultReauth()
|
|
642
655
|
|
|
643
656
|
const fableRecoverySummary = () =>
|
|
644
657
|
getFableRecoverySummary(state(), props.sessionId)
|
|
@@ -773,6 +786,7 @@ function QuotaSidebar(props: {
|
|
|
773
786
|
pacingEnabled={prefs().sections.pacing}
|
|
774
787
|
tierLabel={fb.tierLabel}
|
|
775
788
|
needsReauth={fb.needsReauth}
|
|
789
|
+
vaultReauth={fb.vaultReauth}
|
|
776
790
|
marginTop={1}
|
|
777
791
|
/>
|
|
778
792
|
)}
|
package/dist/index-wezdyxst.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{Pc as O}from"./index-4nz423bt.js";import{randomUUID as H}from"node:crypto";import{mkdir as I,readFile as k,rename as g,rm as N,rmdir as F,stat as P,unlink as w,writeFile as T}from"node:fs/promises";import{tmpdir as m}from"node:os";import{dirname as y,join as L}from"node:path";var d="OPENCODE_ANTHROPIC_AUTH_SIDEBAR_STATE_FILE",v=L(m(),"opencode-anthropic-auth"),c=L(v,"sidebar-state.json");function E(){return process.env[d]||c}var C={main:{quota:null},fallbacks:[],activeId:void 0,route:"main",relay:null,fastMode:!1,lastUpdated:0};function K(J){return J!==null&&typeof J==="object"&&!Array.isArray(J)}function q(J){return typeof J==="number"&&Number.isFinite(J)}function u(J){if(!K(J))return;let Z=Number(J.count),V=Number(J.inputTokens),x=Number(J.outputTokens),Y=Number(J.since);if(![Z,V,x,Y].every(Number.isFinite)||Z<0||V<0||x<0||Y<0)return;return{count:Math.floor(Z),inputTokens:Math.floor(V),outputTokens:Math.floor(x),since:Math.floor(Y)}}function n(J){if(!K(J))return;if(typeof J.id!=="string"||!J.id.trim())return;if(typeof J.label!=="string"||!J.label.trim())return;let Z={id:J.id.trim(),label:J.label.trim()};if(J.nextDueAt===null)Z.nextDueAt=null;else if(q(J.nextDueAt))Z.nextDueAt=J.nextDueAt;if(J.lastPrimedAt===null)Z.lastPrimedAt=null;else if(q(J.lastPrimedAt))Z.lastPrimedAt=J.lastPrimedAt;if(J.lastResult==="ok"||J.lastResult==="error")Z.lastResult=J.lastResult;let V=u(J.usage);if(V)Z.usage=V;if(q(J.estimatedCostUsd))Z.estimatedCostUsd=J.estimatedCostUsd;return Z}function i(J){if(!K(J))return;if(typeof J.enabled!=="boolean")return;let Z=Array.isArray(J.accounts)?J.accounts.map(n).filter((V)=>V!=null):[];return{enabled:J.enabled,accounts:Z}}function h(J){if(!K(J))return;let Z=Number(J.usedPercent),V=Number(J.remainingPercent);if(!Number.isFinite(Z)||!Number.isFinite(V))return;return{usedPercent:Z,remainingPercent:V,resetsAt:typeof J.resetsAt==="string"?J.resetsAt:void 0}}function b(J){if(!K(J))return null;let Z={},V=h(J.five_hour),x=h(J.seven_day);if(V)Z.five_hour=V;if(x)Z.seven_day=x;if(Array.isArray(J.scoped)){let Y=J.scoped.map((X)=>{if(!K(X))return;let $=h(X);if(!$)return;if(typeof X.id!=="string"||!X.id.trim())return;if(typeof X.title!=="string"||!X.title.trim())return;if(typeof X.modelName!=="string"||!X.modelName.trim())return;let j=typeof X.modelId==="string"&&X.modelId.trim()?X.modelId.trim():void 0;return{...$,id:X.id.trim(),title:X.title.trim(),...j&&{modelId:j},modelName:X.modelName.trim()}}).filter((X)=>X!=null);Z.scoped=Y}if(K(J.extraUsage)){let Y=A(J.extraUsage.used),X=A(J.extraUsage.limit);if(Y&&X&&typeof J.extraUsage.exhausted==="boolean")Z.extraUsage={used:Y,limit:X,...typeof J.extraUsage.utilizationPercent==="number"&&Number.isFinite(J.extraUsage.utilizationPercent)&&{utilizationPercent:J.extraUsage.utilizationPercent},...typeof J.extraUsage.severity==="string"&&{severity:J.extraUsage.severity},exhausted:J.extraUsage.exhausted}}if(typeof J.bindingWindow==="string"&&J.bindingWindow.trim())Z.bindingWindow=J.bindingWindow.trim();if(typeof J.fallbackAdvised==="boolean")Z.fallbackAdvised=J.fallbackAdvised;return Object.keys(Z).length?Z:null}function A(J){if(!K(J))return;if(!Number.isInteger(J.amountMinor)||typeof J.currency!=="string"||!/^[A-Za-z]{3}$/.test(J.currency.trim())||!Number.isInteger(J.exponent)||J.exponent<0||J.exponent>20)return;return{amountMinor:J.amountMinor,currency:J.currency.trim(),exponent:J.exponent}}function s(J){if(!K(J))return{...C};let Z={quota:null};if(K(J.main)){let $=J.main;if(Z.quota=b($.quota),typeof $.tierLabel==="string"&&$.tierLabel.trim())Z.tierLabel=$.tierLabel.trim();if(typeof $.quotaBackedOff==="boolean")Z.quotaBackedOff=$.quotaBackedOff;if(typeof $.quotaBackoffUntil==="number")Z.quotaBackoffUntil=$.quotaBackoffUntil;if(typeof $.refreshBackedOff==="boolean")Z.refreshBackedOff=$.refreshBackedOff;if(typeof $.refreshBackoffUntil==="number")Z.refreshBackoffUntil=$.refreshBackoffUntil}let V=Array.isArray(J.fallbacks)?J.fallbacks.filter(K).filter(($)=>typeof $.id==="string").map(($)=>({id:$.id,label:typeof $.label==="string"?$.label:void 0,quota:b($.quota),enabled:typeof $.enabled==="boolean"?$.enabled:!1,needsReauth:typeof $.needsReauth==="boolean"?$.needsReauth:!1,tierLabel:typeof $.tierLabel==="string"&&$.tierLabel.trim()?$.tierLabel.trim():void 0})):[],x=null;if(K(J.relay)){let $=J.relay;if(typeof $.enabled==="boolean"&&typeof $.transport==="string")x={enabled:$.enabled,transport:$.transport}}let Y;if(K(J.cacheKeep)){let $=J.cacheKeep;if(typeof $.enabled==="boolean")Y={enabled:$.enabled,window:typeof $.window==="string"?$.window:void 0,trackedSessions:typeof $.trackedSessions==="number"?$.trackedSessions:void 0}}let X=Array.isArray(J.fableRecoveries)?J.fableRecoveries.filter(K).flatMap(($)=>{if(typeof $.sessionId!=="string"||$.mode!=="opus"&&$.mode!=="fable"&&$.mode!=="server"||typeof $.remaining!=="number"||!Number.isFinite($.remaining)||typeof $.changedAt!=="number"||!Number.isFinite($.changedAt))return[];return[{sessionId:$.sessionId,mode:$.mode,remaining:Math.max(0,Math.floor($.remaining)),changedAt:$.changedAt,requestedModelId:typeof $.requestedModelId==="string"?$.requestedModelId:void 0,targetModelId:typeof $.targetModelId==="string"?$.targetModelId:void 0}]}):[];return{main:Z,fallbacks:V,activeId:typeof J.activeId==="string"?J.activeId:void 0,route:typeof J.route==="string"?J.route:C.route,relay:x,fastMode:typeof J.fastMode==="boolean"?J.fastMode:C.fastMode,cacheKeep:Y,prime:i(J.prime),fableRecoveries:X.length>0?X:void 0,lastUpdated:typeof J.lastUpdated==="number"?J.lastUpdated:0}}var W=Promise.resolve(),l=1000,o=2000,r=5,a=15,U=new Map;function QJ(J,Z=E()){if(J)U.set(Z,J);else U.delete(Z)}function M(J){return U.get(J)}var S=null;function BJ(J){S=J}function OJ(){return S}function t(J){return new Promise((Z)=>setTimeout(Z,J))}async function p(J){let Z=`${J}.lock`,V=M(J),x=V?.lockBudgetMs??l,Y=V?.lockRetryMinMs??r,X=V?.lockRetryMaxMs??a,$=Date.now()+x;while(!0){try{await I(Z);let G=H(),Q=L(Z,G);return await T(Q,"",{encoding:"utf8",mode:384,flag:"wx"}),await V?.onLockAcquired?.(Z),{ownsLock:async()=>{try{return await P(Q),!0}catch{return!1}},release:async()=>{try{await w(Q)}catch{return}await V?.beforeReleaseDirectoryRemoval?.(Z),await F(Z).catch(()=>{})}}}catch(G){if(G.code!=="EEXIST")return O.trace("sidebar","state lock unavailable; write skipped",{stateFile:J,error:G instanceof Error?G.message:String(G)}),null}try{let G=await P(Z);if(Date.now()-G.mtimeMs>o){await V?.afterStaleLockStat?.(Z);let Q=`${Z}.evict-${process.pid}-${H()}`;try{await g(Z,Q)}catch(z){if(z.code==="ENOENT")continue;throw z}await V?.onStaleLockClaimed?.(Z),await N(Q,{recursive:!0,force:!0}).catch(()=>{});continue}}catch(G){if(G.code==="ENOENT")continue;return O.trace("sidebar","state lock inspection failed; write skipped",{stateFile:J,error:G instanceof Error?G.message:String(G)}),null}let j=$-Date.now();if(j<=0)return O.warn("sidebar","lock budget exhausted, write skipped",{stateFile:J,budgetMs:x}),null;let B=Y+Math.floor(Math.random()*(X-Y+1));await t(Math.min(B,j))}}async function zJ(J){return(await p(J))?.release??null}async function e(J,Z,V){let x=M(J),Y=`${J}.${process.pid}.${H()}.tmp`;await T(Y,JSON.stringify(Z),{encoding:"utf8",mode:384});try{if(!await V())return O.trace("sidebar","state lock lost before rename; write aborted",{stateFile:J}),await N(Y,{force:!0}).catch(()=>{}),"lock-lost-before-rename";if(await x?.beforeRename?.(J,Y),!await V())return O.trace("sidebar","state lock lost before rename; write aborted",{stateFile:J}),await N(Y,{force:!0}).catch(()=>{}),"lock-lost-before-rename";if(await g(Y,J),await x?.afterRename?.(J),!await V())return"lock-lost-after-rename";return"written"}catch(X){throw await N(Y,{force:!0}).catch(()=>{}),X}}async function R(J=E()){try{let Z=await k(J,"utf8");return s(JSON.parse(Z))}catch{return C}}async function NJ(J,Z=E(),V={}){return W=W.then(async()=>{await I(y(Z),{recursive:!0});for(let x=0;x<2;x++){let Y=x===1,X=await p(Z);if(!X){if(Y)O.warn("sidebar","post-rename repair lock unavailable; write skipped",{stateFile:Z});return}let $=J,j;try{if(V.routingAuthoritative===!1){let B=await R(Z),G=await V.resolvePreservedRouting?.(B);if(G){let Q=G.state??J;$={...Q,activeId:G.activeId,route:G.route,lastUpdated:Math.max(Q.lastUpdated,B.lastUpdated)}}await M(Z)?.afterMergeRead?.(Z)}else if(Y){let B=await R(Z);$={...B,activeId:J.activeId,route:J.route,relay:J.relay,fastMode:J.fastMode,cacheKeep:J.cacheKeep,lastUpdated:Math.max(B.lastUpdated,J.lastUpdated)}}j=await e(Z,$,X.ownsLock)}finally{await X.release()}if(j==="lock-lost-after-rename"){if(Y){O.warn("sidebar","post-rename repair lost lock; write skipped",{stateFile:Z});return}O.warn("sidebar","state lock lost after rename; repairing write",{stateFile:Z});continue}if(j==="lock-lost-before-rename")return;V.onRoutingResolved?.({activeId:$.activeId,route:$.route});return}}).catch(()=>{}),W}async function CJ(){return W}function WJ(J){let Z=J.activeId;if(Z&&Z!=="main"){let V=J.fallbacks?.find((x)=>x.enabled&&x.id===Z);if(V)return{id:V.id,name:V.label??V.id,quota:V.quota}}return{id:"main",name:"main",quota:J.main?.quota??null}}function JJ(J){let Z=J.replace(/\s+only$/i,"").trim();return/^fable$/i.test(Z)?"Fa":Z}function f(J){if(J==="claude-fable-5"||J?.startsWith("claude-fable-5-"))return"Fable 5";if(J==="claude-opus-5"||J?.startsWith("claude-opus-5-"))return"Opus 5";if(J==="claude-opus-4-8"||J?.startsWith("claude-opus-4-8-"))return"Opus 4.8";return J??"Fable 5"}function D(J){return new Date(J).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function ZJ(J){if(J===0)return"0";if(J<0.0001)return J.toExponential(2);return J.toFixed(Math.min(6,Math.max(0,4)))}function qJ(J){if(J.lastResult==="error")return{text:"err",hasError:!0};if(J.nextDueAt&&J.nextDueAt>Date.now())return{text:D(J.nextDueAt),hasError:!1};if(J.lastPrimedAt)return{text:`primed ${D(J.lastPrimedAt)} ✓`,hasError:!1};if(J.usage?.count)return{text:`✓ ${J.usage.count} ≈ $${ZJ(J.estimatedCostUsd??0)}`,hasError:!1};return{text:"—",hasError:!1}}function hJ(J,Z){let V=J.fableRecoveries?.find((x)=>x.sessionId===Z);if(!V)return;if(V.mode==="fable")return`${f(V.requestedModelId)} · restored`;if(V.mode==="server")return`${f(V.requestedModelId)}→${f(V.targetModelId)} · safety`;return`Opus 4.8 · ${V.remaining} left`}function fJ(J){let Z=J?.five_hour?.usedPercent??null,V=J?.seven_day?.usedPercent??null,x=J?.scoped??[],Y=x.map((j)=>j.usedPercent);if(Z==null&&V==null&&x.length===0)return{fiveHourUsedPercent:Z,sevenDayUsedPercent:V,scopedUsedPercents:Y,text:null};let X=x.map((j)=>`${JJ(j.title)}: ${Math.round(j.usedPercent)}%`),$=Z==null&&V==null?[]:[`5h: ${Z==null?"—":`${Math.round(Z)}%`}`,`7d: ${V==null?"—":`${Math.round(V)}%`}`];return{fiveHourUsedPercent:Z,sevenDayUsedPercent:V,scopedUsedPercents:Y,text:[...$,...X].join(" ")}}var HJ=18000000,UJ=604800000,$J=300000,VJ=0.01,XJ=1;function LJ(J,Z,V){if(!J.resetsAt)return null;let x=new Date(J.resetsAt).getTime();if(!Number.isFinite(x))return null;let Y=x-Z,X=V-Y;if(X<$J)return null;if(X<Z*VJ)return null;if(X>=Z)return null;let $=J.usedPercent,j=Math.min(Math.max(X/Z*100,0),100),B=$-j,G=Math.abs(B)<XJ?"on-pace":B>0?"deficit":"reserve",Q=null;if($>0){let z=X*100/$,_=Y+z;if(_<x)Q=new Date(_).toISOString()}return{pacePercent:j,deltaPercent:B,state:G,runsOutAt:Q}}
|
|
2
|
-
export{E as a,C as b,s as c,QJ as d,BJ as e,OJ as f,zJ as g,R as h,NJ as i,CJ as j,WJ as k,JJ as l,f as m,D as n,ZJ as o,qJ as p,hJ as q,fJ as r,HJ as s,UJ as t,LJ as u};
|