@cortexkit/opencode-anthropic-auth 1.10.3 → 1.11.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/src/tui.tsx CHANGED
@@ -304,10 +304,13 @@ function AccountBlock(props: {
304
304
  quota: AccountQuota | null
305
305
  active: boolean
306
306
  pacingEnabled: boolean
307
+ needsReauth?: boolean
307
308
  marginTop?: number
308
309
  }) {
309
- const statusWord = () => (props.active ? 'active' : 'idle')
310
- const statusTone = (): Tone => (props.active ? 'ok' : 'muted')
310
+ const statusWord = () =>
311
+ props.needsReauth ? 're-login' : props.active ? 'active' : 'idle'
312
+ const statusTone = (): Tone =>
313
+ props.needsReauth ? 'err' : props.active ? 'ok' : 'muted'
311
314
  const pacingFor = (
312
315
  window:
313
316
  | { usedPercent: number; remainingPercent: number; resetsAt?: string }
@@ -374,7 +377,8 @@ function QuotaDialogContent(props: {
374
377
  })
375
378
  setTimeout(refresh, 0)
376
379
  const theme = () => props.api.theme.current
377
- const enabledFallbacks = () => state().fallbacks.filter((f) => f.enabled)
380
+ const enabledFallbacks = () =>
381
+ (state().fallbacks ?? []).filter((f) => f.enabled)
378
382
  return (
379
383
  <box flexDirection='column' padding={2} width='100%' alignItems='center'>
380
384
  <box flexDirection='column' width={58}>
@@ -387,7 +391,7 @@ function QuotaDialogContent(props: {
387
391
  theme={theme()}
388
392
  appearance={prefs().appearance}
389
393
  name='main'
390
- quota={state().main.quota}
394
+ quota={state().main?.quota}
391
395
  active={state().activeId === 'main'}
392
396
  pacingEnabled={prefs().sections.pacing}
393
397
  />
@@ -401,6 +405,7 @@ function QuotaDialogContent(props: {
401
405
  quota={fb.quota}
402
406
  active={state().activeId === fb.id}
403
407
  pacingEnabled={prefs().sections.pacing}
408
+ needsReauth={fb.needsReauth}
404
409
  marginTop={1}
405
410
  />
406
411
  )}
@@ -526,9 +531,10 @@ function QuotaSidebar(props: {
526
531
  })
527
532
 
528
533
  const theme = () => props.api.theme.current
529
- const enabledFallbacks = () => state().fallbacks.filter((f) => f.enabled)
534
+ const enabledFallbacks = () =>
535
+ (state().fallbacks ?? []).filter((f) => f.enabled)
530
536
  const hasData = () =>
531
- state().main.quota != null || enabledFallbacks().length > 0
537
+ state().main?.quota != null || enabledFallbacks().length > 0
532
538
 
533
539
  const headerLabel = () => {
534
540
  const name = prefs().header.label
@@ -568,9 +574,10 @@ function QuotaSidebar(props: {
568
574
  return base === 'ok' || base === 'muted' ? 'warn' : base
569
575
  }
570
576
 
571
- const quotaBackedOff = () => state().main.quotaBackedOff === true
572
- const refreshBackedOff = () => state().main.refreshBackedOff === true
573
- const degraded = () => quotaBackedOff() || refreshBackedOff()
577
+ const quotaBackedOff = () => state().main?.quotaBackedOff === true
578
+ const refreshBackedOff = () => state().main?.refreshBackedOff === true
579
+ const needsReauth = () => enabledFallbacks().some((f) => f.needsReauth)
580
+ const degraded = () => quotaBackedOff() || refreshBackedOff() || needsReauth()
574
581
 
575
582
  const cacheKeep = () => state().cacheKeep
576
583
  const showCache = () =>
@@ -667,7 +674,7 @@ function QuotaSidebar(props: {
667
674
  theme={theme()}
668
675
  appearance={prefs().appearance}
669
676
  name='main'
670
- quota={state().main.quota}
677
+ quota={state().main?.quota}
671
678
  active={state().activeId === 'main'}
672
679
  pacingEnabled={prefs().sections.pacing}
673
680
  />
@@ -681,6 +688,7 @@ function QuotaSidebar(props: {
681
688
  quota={fb.quota}
682
689
  active={state().activeId === fb.id}
683
690
  pacingEnabled={prefs().sections.pacing}
691
+ needsReauth={fb.needsReauth}
684
692
  marginTop={1}
685
693
  />
686
694
  )}
@@ -738,7 +746,7 @@ function QuotaSidebar(props: {
738
746
  <StatRow
739
747
  theme={theme()}
740
748
  label='Quota API'
741
- value={`backoff ${formatUntil(state().main.quotaBackoffUntil)}`}
749
+ value={`backoff ${formatUntil(state().main?.quotaBackoffUntil)}`}
742
750
  tone='warn'
743
751
  />
744
752
  </Show>
@@ -746,7 +754,7 @@ function QuotaSidebar(props: {
746
754
  <StatRow
747
755
  theme={theme()}
748
756
  label='Token refresh'
749
- value={`backoff ${formatUntil(state().main.refreshBackoffUntil)}`}
757
+ value={`backoff ${formatUntil(state().main?.refreshBackoffUntil)}`}
750
758
  tone='warn'
751
759
  />
752
760
  </Show>
@@ -770,7 +778,10 @@ const tui: TuiPlugin = async (api) => {
770
778
 
771
779
  if (!rpcPollStarted) {
772
780
  rpcPollStarted = true
773
- const rpcClient = createRpcClient(getRpcDir(api.state.path.directory ?? ''))
781
+ const rpcClient = createRpcClient(
782
+ getRpcDir(api.state.path.directory ?? ''),
783
+ process.pid,
784
+ )
774
785
  let lastNotificationId = 0
775
786
  let rpcInFlight = false
776
787
  setInterval(() => {
@@ -795,7 +806,7 @@ const tui: TuiPlugin = async (api) => {
795
806
  continue
796
807
  }
797
808
  openCommandDialog(api, message.payload, (command, args) =>
798
- rpcClient.apply({ command, arguments: args }),
809
+ rpcClient.apply({ command, arguments: args, sessionId }),
799
810
  )
800
811
  }
801
812
  })
@@ -1 +0,0 @@
1
- import{createHash as z}from"node:crypto";import{homedir as F,tmpdir as L}from"node:os";import{join as k}from"node:path";var G="OPENCODE_ANTHROPIC_AUTH_RPC_DIR";function Q(q){let g=process.env[G]?.trim();if(g)return g;let w=z("sha256").update(q).digest("hex").slice(0,16),x=process.env.XDG_STATE_HOME||k(F(),".local","state");return k(x,"cortexkit","anthropic-auth","rpc",w)}export{L as fb,Q as gb};
@@ -1,2 +0,0 @@
1
- import{mkdir as R,readFile as g,writeFile as q}from"node:fs/promises";import{tmpdir as C}from"node:os";import{dirname as y,join as V}from"node:path";var H="OPENCODE_ANTHROPIC_AUTH_SIDEBAR_STATE_FILE",k=V(C(),"opencode-anthropic-auth"),O=V(k,"sidebar-state.json");function h(){return process.env[H]||O}var b={main:{quota:null},fallbacks:[],activeId:void 0,route:"main",relay:null,fastMode:!1,lastUpdated:0};async function I(){try{let z=await g(h(),"utf8");return JSON.parse(z)}catch{return b}}async function S(z){try{let x=h();await R(y(x),{recursive:!0}),await q(x,JSON.stringify(z),"utf8")}catch{}}function D(z){let x=z.activeId;if(x&&x!=="main"){let J=z.fallbacks.find((K)=>K.enabled&&K.id===x);if(J)return{id:J.id,name:J.label??J.id,quota:J.quota}}return{id:"main",name:"main",quota:z.main.quota}}function F(z){let x=z?.five_hour?.usedPercent??null,J=z?.seven_day?.usedPercent??null;if(x==null&&J==null)return{fiveHourUsedPercent:x,sevenDayUsedPercent:J,text:null};return{fiveHourUsedPercent:x,sevenDayUsedPercent:J,text:`5h: ${x==null?"—":`${Math.round(x)}%`} 7d: ${J==null?"—":`${Math.round(J)}%`}`}}var U=18000000,v=604800000,N=300000,L=0.01,m=1;function T(z,x,J){if(!z.resetsAt)return null;let K=new Date(z.resetsAt).getTime();if(!Number.isFinite(K))return null;let Y=K-x,Q=J-Y;if(Q<N)return null;if(Q<x*L)return null;if(Q>=x)return null;let W=z.usedPercent,Z=Math.min(Math.max(Q/x*100,0),100),X=W-Z,j=Math.abs(X)<m?"on-pace":X>0?"deficit":"reserve",$=null;if(W>0){let G=Q*100/W,B=Y+G;if(B<K)$=new Date(B).toISOString()}return{pacePercent:Z,deltaPercent:X,state:j,runsOutAt:$}}
2
- export{h as Wa,b as Xa,I as Ya,S as Za,D as _a,F as $a,U as ab,v as bb,T as cb};
@@ -1,2 +0,0 @@
1
- import{mkdir as s,readdir as a,readFile as u,rename as c,unlink as l,writeFile as p}from"node:fs/promises";import{join as o}from"node:path";function m(r){try{return process.kill(r,0),!0}catch(n){return n.code==="EPERM"}}async function g(r,n){await s(r,{recursive:!0});let i={...n,startedAt:Date.now()},t=o(r,`port-${n.pid}.json`),e=`${t}.${process.pid}.tmp`;return await p(e,JSON.stringify(i),{encoding:"utf8",mode:384}),await c(e,t),t}async function y(r){let n;try{n=await a(r)}catch{return null}let i=[];for(let t of n){if(!t.startsWith("port-")||!t.endsWith(".json"))continue;try{let e=JSON.parse(await u(o(r,t),"utf8"));if(Number.isFinite(e.port))if(m(e.pid))i.push(e);else l(o(r,t)).catch(()=>{})}catch{}}if(i.length===0)return null;return i.sort((t,e)=>e.startedAt-t.startedAt)[0]??null}
2
- export{g as db,y as eb};