@cortexkit/opencode-anthropic-auth 1.19.1 → 1.21.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 +119 -2
- package/dist/cache-diagnostics.d.ts +79 -0
- package/dist/cli.js +2 -2
- package/dist/index-1db17bc2.js +2 -0
- package/dist/{index-dex8fs0m.js → index-4nz423bt.js} +1 -1
- package/dist/{index-dzs7w297.js → index-4x20896x.js} +1 -1
- package/dist/{index-2k47hc8b.js → index-w9d41yy9.js} +1 -1
- package/dist/index-wezdyxst.js +2 -0
- package/dist/{index-075t8qec.js → index-y0khnbt6.js} +1 -1
- package/dist/index-yskwj5e6.js +428 -0
- package/dist/index.d.ts +0 -37
- package/dist/index.js +23 -19
- package/dist/lane-start.d.ts +17 -0
- package/dist/{logger-n49md99d.js → logger-ftk4bg3p.js} +1 -1
- package/dist/prime-manager-registry.d.ts +7 -0
- package/dist/request-policy.d.ts +25 -0
- package/dist/rpc/port-file.js +1 -1
- package/dist/rpc/protocol.d.ts +2 -1
- package/dist/rpc/protocol.js +1 -0
- package/dist/rpc/rpc-client.js +1 -1
- package/dist/rpc/rpc-dir.js +1 -1
- package/dist/server-fallback.d.ts +2 -0
- package/dist/sidebar-state.d.ts +26 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/transform.d.ts +13 -0
- package/dist/tui/command-dialogs.d.ts +16 -1
- package/dist/tui-preferences.js +1 -1
- package/package.json +4 -4
- package/src/rpc/protocol.ts +15 -10
- package/src/sidebar-state.ts +154 -17
- package/src/tui/command-dialogs.tsx +112 -0
- package/src/tui-compiled/rpc/protocol.ts +15 -10
- package/src/tui-compiled/sidebar-state.ts +154 -17
- package/src/tui-compiled/tui/command-dialogs.tsx +134 -18
- package/src/tui-compiled/tui.tsx +43 -1
- package/src/tui.tsx +28 -0
- package/dist/index-a13w4gm9.js +0 -2
- package/dist/index-vwgzgh5x.js +0 -422
package/src/tui-compiled/tui.tsx
CHANGED
|
@@ -15,7 +15,7 @@ import { formatQuotaMoney } from "@cortexkit/anthropic-auth-core";
|
|
|
15
15
|
import { createEffect, createSignal, For, onCleanup, Show } from "opentui:runtime-module:solid-js";
|
|
16
16
|
import { createRpcClient } from "./rpc/rpc-client.js";
|
|
17
17
|
import { getRpcDir } from "./rpc/rpc-dir.js";
|
|
18
|
-
import { computeQuotaPacing, DEFAULT_SIDEBAR_STATE, FIVE_HOUR_MS, formatScopedQuotaLabel, getCollapsedQuotaSummary, getFableRecoverySummary, getSidebarState, resolveActiveAccount, SEVEN_DAY_MS } from "./sidebar-state.js";
|
|
18
|
+
import { computeQuotaPacing, DEFAULT_SIDEBAR_STATE, FIVE_HOUR_MS, formatPrimeAccountValue, formatScopedQuotaLabel, getCollapsedQuotaSummary, getFableRecoverySummary, getSidebarState, resolveActiveAccount, SEVEN_DAY_MS } from "./sidebar-state.js";
|
|
19
19
|
import { openCommandDialog } from "./tui/command-dialogs.js";
|
|
20
20
|
import { computeEffectiveOrder, DEFAULT_SLOT_ORDER, PLUGIN_KEY, queueTuiPreferenceUpdate, readTuiPreferencesFile, resolveAnthropicAuthPrefs, watchTuiPreferences } from "./tui-preferences.js";
|
|
21
21
|
const RPC_POLL_MS = 500;
|
|
@@ -685,6 +685,9 @@ function QuotaSidebar(props) {
|
|
|
685
685
|
const fableRecoveryTone = () => state().fableRecoveries?.find(recovery => recovery.sessionId === props.sessionId)?.mode === 'fable' ? 'ok' : 'warn';
|
|
686
686
|
const cacheKeep = () => state().cacheKeep;
|
|
687
687
|
const showCache = () => prefs().sections.cache && cacheKeep() != null && cacheKeep()?.window != null;
|
|
688
|
+
const prime = () => state().prime;
|
|
689
|
+
const showPrime = () => prime() != null;
|
|
690
|
+
const primeHasError = () => prime()?.accounts.some(account => account.lastResult === 'error') ?? false;
|
|
688
691
|
const relayValue = () => {
|
|
689
692
|
const r = state().relay;
|
|
690
693
|
if (!r) return '\u2014';
|
|
@@ -1024,6 +1027,45 @@ function QuotaSidebar(props) {
|
|
|
1024
1027
|
}
|
|
1025
1028
|
})];
|
|
1026
1029
|
}
|
|
1030
|
+
}), _$createComponent(Show, {
|
|
1031
|
+
get when() {
|
|
1032
|
+
return showPrime();
|
|
1033
|
+
},
|
|
1034
|
+
get children() {
|
|
1035
|
+
return [_$createComponent(StatRow, {
|
|
1036
|
+
get theme() {
|
|
1037
|
+
return theme();
|
|
1038
|
+
},
|
|
1039
|
+
label: "Prime",
|
|
1040
|
+
get value() {
|
|
1041
|
+
return primeHasError() ? 'err' : 'on';
|
|
1042
|
+
},
|
|
1043
|
+
get tone() {
|
|
1044
|
+
return primeHasError() ? 'warn' : 'ok';
|
|
1045
|
+
}
|
|
1046
|
+
}), _$createComponent(For, {
|
|
1047
|
+
get each() {
|
|
1048
|
+
return prime()?.accounts ?? [];
|
|
1049
|
+
},
|
|
1050
|
+
children: account => {
|
|
1051
|
+
const value = () => formatPrimeAccountValue(account);
|
|
1052
|
+
return _$createComponent(StatRow, {
|
|
1053
|
+
get theme() {
|
|
1054
|
+
return theme();
|
|
1055
|
+
},
|
|
1056
|
+
get label() {
|
|
1057
|
+
return account.label;
|
|
1058
|
+
},
|
|
1059
|
+
get value() {
|
|
1060
|
+
return value().text;
|
|
1061
|
+
},
|
|
1062
|
+
get tone() {
|
|
1063
|
+
return value().hasError ? 'warn' : 'text';
|
|
1064
|
+
}
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
})];
|
|
1068
|
+
}
|
|
1027
1069
|
}), _$createComponent(Show, {
|
|
1028
1070
|
get when() {
|
|
1029
1071
|
return _$memo(() => !!degraded())() && prefs().sections.health;
|
package/src/tui.tsx
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
computeQuotaPacing,
|
|
25
25
|
DEFAULT_SIDEBAR_STATE,
|
|
26
26
|
FIVE_HOUR_MS,
|
|
27
|
+
formatPrimeAccountValue,
|
|
27
28
|
formatScopedQuotaLabel,
|
|
28
29
|
getCollapsedQuotaSummary,
|
|
29
30
|
getFableRecoverySummary,
|
|
@@ -650,6 +651,10 @@ function QuotaSidebar(props: {
|
|
|
650
651
|
const cacheKeep = () => state().cacheKeep
|
|
651
652
|
const showCache = () =>
|
|
652
653
|
prefs().sections.cache && cacheKeep() != null && cacheKeep()?.window != null
|
|
654
|
+
const prime = () => state().prime
|
|
655
|
+
const showPrime = () => prime() != null
|
|
656
|
+
const primeHasError = () =>
|
|
657
|
+
prime()?.accounts.some((account) => account.lastResult === 'error') ?? false
|
|
653
658
|
const relayValue = () => {
|
|
654
659
|
const r = state().relay
|
|
655
660
|
if (!r) return '\u2014'
|
|
@@ -829,6 +834,29 @@ function QuotaSidebar(props: {
|
|
|
829
834
|
</Show>
|
|
830
835
|
</Show>
|
|
831
836
|
|
|
837
|
+
{/* Prime — only when enabled. Expanded view only (no collapsed surface). */}
|
|
838
|
+
<Show when={showPrime()}>
|
|
839
|
+
<StatRow
|
|
840
|
+
theme={theme()}
|
|
841
|
+
label='Prime'
|
|
842
|
+
value={primeHasError() ? 'err' : 'on'}
|
|
843
|
+
tone={primeHasError() ? 'warn' : 'ok'}
|
|
844
|
+
/>
|
|
845
|
+
<For each={prime()?.accounts ?? []}>
|
|
846
|
+
{(account) => {
|
|
847
|
+
const value = () => formatPrimeAccountValue(account)
|
|
848
|
+
return (
|
|
849
|
+
<StatRow
|
|
850
|
+
theme={theme()}
|
|
851
|
+
label={account.label}
|
|
852
|
+
value={value().text}
|
|
853
|
+
tone={value().hasError ? 'warn' : 'text'}
|
|
854
|
+
/>
|
|
855
|
+
)
|
|
856
|
+
}}
|
|
857
|
+
</For>
|
|
858
|
+
</Show>
|
|
859
|
+
|
|
832
860
|
{/* Health — only when something is wrong */}
|
|
833
861
|
<Show when={degraded() && prefs().sections.health}>
|
|
834
862
|
<SectionHeader theme={theme()} title='Health' />
|
package/dist/index-a13w4gm9.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{mc as Q}from"./index-dex8fs0m.js";import{randomUUID as H}from"node:crypto";import{mkdir as R,readFile as T,rename as _,rm as O,rmdir as p,stat as P,unlink as S,writeFile as A}from"node:fs/promises";import{tmpdir as k}from"node:os";import{dirname as F,join as f}from"node:path";var m="OPENCODE_ANTHROPIC_AUTH_SIDEBAR_STATE_FILE",w=f(k(),"opencode-anthropic-auth"),y=f(w,"sidebar-state.json");function g(){return process.env[m]||y}var C={main:{quota:null},fallbacks:[],activeId:void 0,route:"main",relay:null,fastMode:!1,lastUpdated:0};function N(J){return J!==null&&typeof J==="object"&&!Array.isArray(J)}function q(J){if(!N(J))return;let $=Number(J.usedPercent),V=Number(J.remainingPercent);if(!Number.isFinite($)||!Number.isFinite(V))return;return{usedPercent:$,remainingPercent:V,resetsAt:typeof J.resetsAt==="string"?J.resetsAt:void 0}}function L(J){if(!N(J))return null;let $={},V=q(J.five_hour),x=q(J.seven_day);if(V)$.five_hour=V;if(x)$.seven_day=x;if(Array.isArray(J.scoped)){let G=J.scoped.map((X)=>{if(!N(X))return;let Z=q(X);if(!Z)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{...Z,id:X.id.trim(),title:X.title.trim(),...j&&{modelId:j},modelName:X.modelName.trim()}}).filter((X)=>X!=null);$.scoped=G}if(N(J.extraUsage)){let G=M(J.extraUsage.used),X=M(J.extraUsage.limit);if(G&&X&&typeof J.extraUsage.exhausted==="boolean")$.extraUsage={used:G,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())$.bindingWindow=J.bindingWindow.trim();if(typeof J.fallbackAdvised==="boolean")$.fallbackAdvised=J.fallbackAdvised;return Object.keys($).length?$:null}function M(J){if(!N(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 u(J){if(!N(J))return{...C};let $={quota:null};if(N(J.main)){let Z=J.main;if($.quota=L(Z.quota),typeof Z.tierLabel==="string"&&Z.tierLabel.trim())$.tierLabel=Z.tierLabel.trim();if(typeof Z.quotaBackedOff==="boolean")$.quotaBackedOff=Z.quotaBackedOff;if(typeof Z.quotaBackoffUntil==="number")$.quotaBackoffUntil=Z.quotaBackoffUntil;if(typeof Z.refreshBackedOff==="boolean")$.refreshBackedOff=Z.refreshBackedOff;if(typeof Z.refreshBackoffUntil==="number")$.refreshBackoffUntil=Z.refreshBackoffUntil}let V=Array.isArray(J.fallbacks)?J.fallbacks.filter(N).filter((Z)=>typeof Z.id==="string").map((Z)=>({id:Z.id,label:typeof Z.label==="string"?Z.label:void 0,quota:L(Z.quota),enabled:typeof Z.enabled==="boolean"?Z.enabled:!1,needsReauth:typeof Z.needsReauth==="boolean"?Z.needsReauth:!1,tierLabel:typeof Z.tierLabel==="string"&&Z.tierLabel.trim()?Z.tierLabel.trim():void 0})):[],x=null;if(N(J.relay)){let Z=J.relay;if(typeof Z.enabled==="boolean"&&typeof Z.transport==="string")x={enabled:Z.enabled,transport:Z.transport}}let G;if(N(J.cacheKeep)){let Z=J.cacheKeep;if(typeof Z.enabled==="boolean")G={enabled:Z.enabled,window:typeof Z.window==="string"?Z.window:void 0,trackedSessions:typeof Z.trackedSessions==="number"?Z.trackedSessions:void 0}}let X=Array.isArray(J.fableRecoveries)?J.fableRecoveries.filter(N).flatMap((Z)=>{if(typeof Z.sessionId!=="string"||Z.mode!=="opus"&&Z.mode!=="fable"&&Z.mode!=="server"||typeof Z.remaining!=="number"||!Number.isFinite(Z.remaining)||typeof Z.changedAt!=="number"||!Number.isFinite(Z.changedAt))return[];return[{sessionId:Z.sessionId,mode:Z.mode,remaining:Math.max(0,Math.floor(Z.remaining)),changedAt:Z.changedAt,requestedModelId:typeof Z.requestedModelId==="string"?Z.requestedModelId:void 0,targetModelId:typeof Z.targetModelId==="string"?Z.targetModelId:void 0}]}):[];return{main:$,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:G,fableRecoveries:X.length>0?X:void 0,lastUpdated:typeof J.lastUpdated==="number"?J.lastUpdated:0}}var h=Promise.resolve(),v=1000,c=2000,d=5,n=15,z=null;function VJ(J){z=J}var b=null;function XJ(J){b=J}function xJ(){return b}function l(J){return new Promise(($)=>setTimeout($,J))}async function D(J){let $=`${J}.lock`,V=z?.lockBudgetMs??v,x=z?.lockRetryMinMs??d,G=z?.lockRetryMaxMs??n,X=Date.now()+V;while(!0){try{await R($);let Y=H(),K=f($,Y);return await A(K,"",{encoding:"utf8",mode:384,flag:"wx"}),await z?.onLockAcquired?.($),{ownsLock:async()=>{try{return await P(K),!0}catch{return!1}},release:async()=>{try{await S(K)}catch{return}await z?.beforeReleaseDirectoryRemoval?.($),await p($).catch(()=>{})}}}catch(Y){if(Y.code!=="EEXIST")return Q.trace("sidebar","state lock unavailable; write skipped",{stateFile:J,error:Y instanceof Error?Y.message:String(Y)}),null}try{let Y=await P($);if(Date.now()-Y.mtimeMs>c){await z?.afterStaleLockStat?.($);let K=`${$}.evict-${process.pid}-${H()}`;try{await _($,K)}catch(B){if(B.code==="ENOENT")continue;throw B}await z?.onStaleLockClaimed?.($),await O(K,{recursive:!0,force:!0}).catch(()=>{});continue}}catch(Y){if(Y.code==="ENOENT")continue;return Q.trace("sidebar","state lock inspection failed; write skipped",{stateFile:J,error:Y instanceof Error?Y.message:String(Y)}),null}let Z=X-Date.now();if(Z<=0)return Q.warn("sidebar","lock budget exhausted, write skipped",{stateFile:J,budgetMs:V}),null;let j=x+Math.floor(Math.random()*(G-x+1));await l(Math.min(j,Z))}}async function YJ(J){return(await D(J))?.release??null}async function i(J,$,V){let x=`${J}.${process.pid}.${H()}.tmp`;await A(x,JSON.stringify($),{encoding:"utf8",mode:384});try{if(!await V())return Q.trace("sidebar","state lock lost before rename; write aborted",{stateFile:J}),await O(x,{force:!0}).catch(()=>{}),"lock-lost-before-rename";if(await z?.beforeRename?.(J,x),!await V())return Q.trace("sidebar","state lock lost before rename; write aborted",{stateFile:J}),await O(x,{force:!0}).catch(()=>{}),"lock-lost-before-rename";if(await _(x,J),await z?.afterRename?.(J),!await V())return"lock-lost-after-rename";return"written"}catch(G){throw await O(x,{force:!0}).catch(()=>{}),G}}async function E(J=g()){try{let $=await T(J,"utf8");return u(JSON.parse($))}catch{return C}}async function GJ(J,$=g(),V={}){return h=h.then(async()=>{await R(F($),{recursive:!0});for(let x=0;x<2;x++){let G=x===1,X=await D($);if(!X){if(G)Q.warn("sidebar","post-rename repair lock unavailable; write skipped",{stateFile:$});return}let Z=J,j;try{if(V.routingAuthoritative===!1){let Y=await E($),K=await V.resolvePreservedRouting?.(Y);if(K){let B=K.state??J;Z={...B,activeId:K.activeId,route:K.route,lastUpdated:Math.max(B.lastUpdated,Y.lastUpdated)}}await z?.afterMergeRead?.($)}else if(G){let Y=await E($);Z={...Y,activeId:J.activeId,route:J.route,relay:J.relay,fastMode:J.fastMode,cacheKeep:J.cacheKeep,lastUpdated:Math.max(Y.lastUpdated,J.lastUpdated)}}j=await i($,Z,X.ownsLock)}finally{await X.release()}if(j==="lock-lost-after-rename"){if(G){Q.warn("sidebar","post-rename repair lost lock; write skipped",{stateFile:$});return}Q.warn("sidebar","state lock lost after rename; repairing write",{stateFile:$});continue}if(j==="lock-lost-before-rename")return;V.onRoutingResolved?.({activeId:Z.activeId,route:Z.route});return}}).catch(()=>{}),h}async function jJ(){return h}function KJ(J){let $=J.activeId;if($&&$!=="main"){let V=J.fallbacks?.find((x)=>x.enabled&&x.id===$);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 s(J){let $=J.replace(/\s+only$/i,"").trim();return/^fable$/i.test($)?"Fa":$}function W(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 zJ(J,$){let V=J.fableRecoveries?.find((x)=>x.sessionId===$);if(!V)return;if(V.mode==="fable")return`${W(V.requestedModelId)} · restored`;if(V.mode==="server")return`${W(V.requestedModelId)}→${W(V.targetModelId)} · safety`;return`Opus 4.8 · ${V.remaining} left`}function NJ(J){let $=J?.five_hour?.usedPercent??null,V=J?.seven_day?.usedPercent??null,x=J?.scoped??[],G=x.map((j)=>j.usedPercent);if($==null&&V==null&&x.length===0)return{fiveHourUsedPercent:$,sevenDayUsedPercent:V,scopedUsedPercents:G,text:null};let X=x.map((j)=>`${s(j.title)}: ${Math.round(j.usedPercent)}%`),Z=$==null&&V==null?[]:[`5h: ${$==null?"—":`${Math.round($)}%`}`,`7d: ${V==null?"—":`${Math.round(V)}%`}`];return{fiveHourUsedPercent:$,sevenDayUsedPercent:V,scopedUsedPercents:G,text:[...Z,...X].join(" ")}}var QJ=18000000,BJ=604800000,o=300000,a=0.01,r=1;function OJ(J,$,V){if(!J.resetsAt)return null;let x=new Date(J.resetsAt).getTime();if(!Number.isFinite(x))return null;let G=x-$,X=V-G;if(X<o)return null;if(X<$*a)return null;if(X>=$)return null;let Z=J.usedPercent,j=Math.min(Math.max(X/$*100,0),100),Y=Z-j,K=Math.abs(Y)<r?"on-pace":Y>0?"deficit":"reserve",B=null;if(Z>0){let I=X*100/Z,U=G+I;if(U<x)B=new Date(U).toISOString()}return{pacePercent:j,deltaPercent:Y,state:K,runsOutAt:B}}
|
|
2
|
-
export{g as a,C as b,u as c,VJ as d,XJ as e,xJ as f,YJ as g,E as h,GJ as i,jJ as j,KJ as k,s as l,W as m,zJ as n,NJ as o,QJ as p,BJ as q,OJ as r};
|