@cortexkit/opencode-anthropic-auth 2.7.3 → 2.9.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/dist/cli.js +1 -1
- package/dist/fable-fallback.d.ts +1 -1
- package/dist/{index-eq1kbq5z.js → index-h508mdrx.js} +1 -1
- package/dist/index-pxnn7mg1.js +2 -0
- package/dist/index-s1efwnr3.js +45 -0
- package/dist/index.js +1 -1
- package/dist/sidebar-state.d.ts +1 -1
- package/dist/sidebar-state.js +1 -1
- package/dist/transform.d.ts +3 -1
- package/dist/v2/adapter.d.ts +2 -2
- package/dist/v2/models.d.ts +2 -1
- package/dist/v2/server.js +9 -9
- package/dist/v2/tui.js +1 -1
- package/package.json +2 -2
- package/src/rpc/rpc-server.ts +34 -3
- package/src/sidebar-state.ts +4 -1
- package/src/tui-compiled/sidebar-state.ts +4 -1
- package/dist/index-d4e8qj37.js +0 -2
- package/dist/index-r16saahs.js +0 -45
package/dist/v2/tui.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{x as q}from"../index-
|
|
1
|
+
import{x as q}from"../index-h508mdrx.js";import"../index-pxnn7mg1.js";import"../index-n8xr16kr.js";var N="Open this link in your browser and sign in. Then choose Finish OAuth sign-in in the Accounts menu and paste the code Claude shows you.";async function g(D,M={}){let B=D.client.rpc(q),Z=!0,V=!1,Y=new AbortController,$=()=>{let j=D.ui.router.current();return j.type==="session"?j.sessionID:void 0};function C(j){return new Promise((Q)=>{let z="",J=!1,G=D.keymap.mode.push("cortexkit-protected-entry"),X=(H,W=!0)=>{if(J)return;J=!0,D.renderer.keyInput.off("keypress",O),D.renderer.keyInput.off("paste",P),Y.signal.removeEventListener("abort",K),G();let F=H?z:void 0;if(z="",W)D.ui.dialog.clear();Q(F)},K=()=>X(!1),O=(H)=>{if(H.preventDefault(),H.stopPropagation(),H.name==="escape"||H.ctrl&&H.name==="c")return X(!1);if(H.name==="return"||H.name==="enter")return X(!0);if(H.name==="backspace"){z=Array.from(z).slice(0,-1).join("");return}if(!H.ctrl&&!H.meta&&!H.option&&Array.from(H.sequence).every((W)=>W.charCodeAt(0)>=32&&W.charCodeAt(0)!==127))z=(z+H.sequence).slice(0,4096)},P=(H)=>{H.preventDefault(),H.stopPropagation(),z=(z+Array.from(new TextDecoder().decode(H.bytes)).filter((W)=>W.charCodeAt(0)>=32&&W.charCodeAt(0)!==127).join("")).slice(0,4096)};if(D.renderer.keyInput.prependListener("keypress",O),D.renderer.keyInput.prependListener("paste",P),Y.signal.addEventListener("abort",K,{once:!0}),D.ui.dialog.alert({title:j,message:"Type or paste the value. Input is hidden. Enter accepts; Escape cancels."}).then(()=>X(!1,!1),()=>X(!1,!1)),Y.signal.aborted)K()})}async function E(j){let Q={};for(let z of j.knobs){if(!Z)return;if(z.kind==="choice"){let J=await D.ui.dialog.select({title:z.label,options:z.choices.map((G)=>({title:G.label,value:G.value})),current:z.value});if(J===void 0)return;Q[z.id]=J}else if(z.kind==="toggle"){let J=await D.ui.dialog.select({title:z.label,options:[{title:"On",value:!0},{title:"Off",value:!1}],current:z.value});if(J===void 0)return;Q[z.id]=J}else{let J=z.kind==="text"&&z.masked?await C(z.label):await D.ui.dialog.prompt({title:z.label,value:z.value===void 0?void 0:String(z.value),placeholder:z.kind==="text"?z.placeholder:void 0});if(J===void 0)return;Q[z.id]=J===""&&!z.required?null:z.kind==="number"?Number(J):J}}return Q}async function A(j){if(M.showSignInLink)try{await M.showSignInLink(D,j,Y.signal);return}catch{}await D.ui.dialog.alert({title:"Claude sign-in",message:`${N}
|
|
2
2
|
|
|
3
3
|
${j}
|
|
4
4
|
`})}async function T(j,Q){let z=`${Q.title} status`;if(M.showStatus)try{await M.showStatus(D,{title:z,lines:Q.lines,...Q.slot==="quota"&&{readQuota:(J)=>B.sidebar({sessionId:j},{signal:J,location:D.location})}},Y.signal);return}catch{}await D.ui.dialog.alert({title:z,message:Q.lines.join(`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cortexkit/opencode-anthropic-auth",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -77,7 +77,7 @@
|
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"@clack/prompts": "^1.6.0",
|
|
80
|
-
"@cortexkit/anthropic-auth-core": "2.
|
|
80
|
+
"@cortexkit/anthropic-auth-core": "2.9.0",
|
|
81
81
|
"@cortexkit/claustrum-client": "0.17.0",
|
|
82
82
|
"@cortexkit/private-files": "0.2.2",
|
|
83
83
|
"@cortexkit/subc-client": "^0.24",
|
package/src/rpc/rpc-server.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
type IncomingMessage,
|
|
6
6
|
type ServerResponse,
|
|
7
7
|
} from 'node:http'
|
|
8
|
+
import type { Socket } from 'node:net'
|
|
8
9
|
import { join } from 'node:path'
|
|
9
10
|
import {
|
|
10
11
|
type CommandApplyRequest,
|
|
@@ -59,13 +60,43 @@ export async function startRpcServer(
|
|
|
59
60
|
options: RpcServerOptions,
|
|
60
61
|
): Promise<RpcServerHandle> {
|
|
61
62
|
const token = randomBytes(32).toString('hex')
|
|
63
|
+
const connections = new Set<Socket>()
|
|
64
|
+
let stopping = false
|
|
65
|
+
let closing: Promise<void> | undefined
|
|
62
66
|
const server = createServer((req, res) => {
|
|
63
67
|
void dispatch(req, res)
|
|
64
68
|
})
|
|
69
|
+
server.on('connection', (socket) => {
|
|
70
|
+
connections.add(socket)
|
|
71
|
+
socket.once('close', () => connections.delete(socket))
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
function closeServer(): Promise<void> {
|
|
75
|
+
closing ??= (async () => {
|
|
76
|
+
stopping = true
|
|
77
|
+
await new Promise<void>((resolve) => server.close(() => resolve()))
|
|
78
|
+
// Bun closes connections that were idle when close() ran, but a request
|
|
79
|
+
// active at that point can leave its keep-alive socket open after replying.
|
|
80
|
+
// Wait for the replies first, then close every remaining owned socket.
|
|
81
|
+
await Promise.all(
|
|
82
|
+
[...connections].map(
|
|
83
|
+
(socket) =>
|
|
84
|
+
new Promise<void>((resolve) => {
|
|
85
|
+
socket.once('close', () => resolve())
|
|
86
|
+
socket.destroy()
|
|
87
|
+
}),
|
|
88
|
+
),
|
|
89
|
+
)
|
|
90
|
+
})()
|
|
91
|
+
return closing
|
|
92
|
+
}
|
|
65
93
|
|
|
66
94
|
async function dispatch(req: IncomingMessage, res: ServerResponse) {
|
|
67
95
|
const json = (status: number, value: unknown) => {
|
|
68
|
-
res.writeHead(status, {
|
|
96
|
+
res.writeHead(status, {
|
|
97
|
+
'content-type': 'application/json',
|
|
98
|
+
...(stopping && { connection: 'close' }),
|
|
99
|
+
})
|
|
69
100
|
res.end(JSON.stringify(value))
|
|
70
101
|
}
|
|
71
102
|
try {
|
|
@@ -129,7 +160,7 @@ export async function startRpcServer(
|
|
|
129
160
|
try {
|
|
130
161
|
await writePortFile(options.dir, { port, token, pid: process.pid })
|
|
131
162
|
} catch (error) {
|
|
132
|
-
await
|
|
163
|
+
await closeServer()
|
|
133
164
|
throw error
|
|
134
165
|
}
|
|
135
166
|
|
|
@@ -137,7 +168,7 @@ export async function startRpcServer(
|
|
|
137
168
|
port,
|
|
138
169
|
token,
|
|
139
170
|
async stop() {
|
|
140
|
-
await
|
|
171
|
+
await closeServer()
|
|
141
172
|
try {
|
|
142
173
|
const portFile = join(options.dir, `port-${process.pid}.json`)
|
|
143
174
|
const current = JSON.parse(await readFile(portFile, 'utf8')) as {
|
package/src/sidebar-state.ts
CHANGED
|
@@ -137,6 +137,7 @@ import {
|
|
|
137
137
|
logger,
|
|
138
138
|
quotaDisplayProjection,
|
|
139
139
|
quotaWindowParts,
|
|
140
|
+
resolveClaudeModelCapabilities,
|
|
140
141
|
} from '@cortexkit/anthropic-auth-core'
|
|
141
142
|
|
|
142
143
|
const STATE_FILE_ENV = 'OPENCODE_ANTHROPIC_AUTH_SIDEBAR_STATE_FILE'
|
|
@@ -859,11 +860,13 @@ export function resolveActiveAccount(state: SidebarState): {
|
|
|
859
860
|
}
|
|
860
861
|
|
|
861
862
|
/**
|
|
862
|
-
* Pretty label for a recoverable-refusal source model (Fable
|
|
863
|
+
* Pretty label for a recoverable-refusal source model (Fable or Opus).
|
|
863
864
|
* Falls back to the raw id for unrecognized ids so the sidebar never goes
|
|
864
865
|
* blank on a future model that has not yet been cataloged here.
|
|
865
866
|
*/
|
|
866
867
|
export function formatFallbackModelLabel(modelId: string | undefined): string {
|
|
868
|
+
const row = resolveClaudeModelCapabilities(modelId)
|
|
869
|
+
if (row?.id === 'claude-fable-5-2') return row.name.replace(/^Claude /, '')
|
|
867
870
|
if (
|
|
868
871
|
modelId === 'claude-mythos-5-1' ||
|
|
869
872
|
modelId?.startsWith('claude-mythos-5-1-')
|
|
@@ -137,6 +137,7 @@ import {
|
|
|
137
137
|
logger,
|
|
138
138
|
quotaDisplayProjection,
|
|
139
139
|
quotaWindowParts,
|
|
140
|
+
resolveClaudeModelCapabilities,
|
|
140
141
|
} from '@cortexkit/anthropic-auth-core'
|
|
141
142
|
|
|
142
143
|
const STATE_FILE_ENV = 'OPENCODE_ANTHROPIC_AUTH_SIDEBAR_STATE_FILE'
|
|
@@ -859,11 +860,13 @@ export function resolveActiveAccount(state: SidebarState): {
|
|
|
859
860
|
}
|
|
860
861
|
|
|
861
862
|
/**
|
|
862
|
-
* Pretty label for a recoverable-refusal source model (Fable
|
|
863
|
+
* Pretty label for a recoverable-refusal source model (Fable or Opus).
|
|
863
864
|
* Falls back to the raw id for unrecognized ids so the sidebar never goes
|
|
864
865
|
* blank on a future model that has not yet been cataloged here.
|
|
865
866
|
*/
|
|
866
867
|
export function formatFallbackModelLabel(modelId: string | undefined): string {
|
|
868
|
+
const row = resolveClaudeModelCapabilities(modelId)
|
|
869
|
+
if (row?.id === 'claude-fable-5-2') return row.name.replace(/^Claude /, '')
|
|
867
870
|
if (
|
|
868
871
|
modelId === 'claude-mythos-5-1' ||
|
|
869
872
|
modelId?.startsWith('claude-mythos-5-1-')
|
package/dist/index-d4e8qj37.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{randomUUID as E}from"node:crypto";import{mkdir as g,readFile as y,rename as S,rm as O,rmdir as w,stat as D,unlink as m,writeFile as b}from"node:fs/promises";import{tmpdir as d}from"node:os";import{dirname as v,join as f}from"node:path";import{formatQuota as c,isQuotaStale as s,logger as C,quotaDisplayProjection as I,quotaWindowParts as u}from"@cortexkit/anthropic-auth-core";var i="OPENCODE_ANTHROPIC_AUTH_SIDEBAR_STATE_FILE",l=f(d(),"opencode-anthropic-auth"),n=f(l,"sidebar-state.json");function P(){return process.env[i]||n}var H={main:{quota:null},fallbacks:[],route:"main",relay:null,fastMode:!1,lastUpdated:0};function Q(J){return J!==null&&typeof J==="object"&&!Array.isArray(J)}function z(J){return typeof J==="number"&&Number.isFinite(J)}function o(J){if(!Q(J))return;let Z=Number(J.count),V=Number(J.inputTokens),X=Number(J.outputTokens),x=Number(J.since);if(![Z,V,X,x].every(Number.isFinite)||Z<0||V<0||X<0||x<0)return;return{count:Math.floor(Z),inputTokens:Math.floor(V),outputTokens:Math.floor(X),since:Math.floor(x)}}function r(J){if(!Q(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(z(J.nextDueAt))Z.nextDueAt=J.nextDueAt;if(J.lastPrimedAt===null)Z.lastPrimedAt=null;else if(z(J.lastPrimedAt))Z.lastPrimedAt=J.lastPrimedAt;if(J.lastResult==="ok"||J.lastResult==="error"||J.lastResult==="skipped")Z.lastResult=J.lastResult;let V=o(J.usage);if(V)Z.usage=V;if(z(J.estimatedCostUsd))Z.estimatedCostUsd=J.estimatedCostUsd;return Z}function a(J){if(!Q(J))return;if(typeof J.enabled!=="boolean")return;let Z=Array.isArray(J.accounts)?J.accounts.map(r).filter((V)=>V!=null):[];return{enabled:J.enabled,accounts:Z}}function q(J){if(!Q(J))return;let Z=Number(J.usedPercent),V=Number(J.remainingPercent);if(!Number.isFinite(Z)||!Number.isFinite(V))return;return{usedPercent:Z,remainingPercent:V,...typeof J.resetsAt==="string"&&{resetsAt:J.resetsAt},...z(J.checkedAt)&&{checkedAt:J.checkedAt}}}function R(J){if(!Q(J))return null;let Z={};if(z(J.checkedAt))Z.checkedAt=J.checkedAt;let V=q(J.five_hour),X=q(J.seven_day);if(V)Z.five_hour=V;if(X)Z.seven_day=X;if(Array.isArray(J.scoped)){let x=J.scoped.map((Y)=>{if(!Q(Y))return;let G=q(Y);if(!G)return;if(typeof Y.id!=="string"||!Y.id.trim())return;if(typeof Y.title!=="string"||!Y.title.trim())return;if(typeof Y.modelName!=="string"||!Y.modelName.trim())return;let $=typeof Y.modelId==="string"&&Y.modelId.trim()?Y.modelId.trim():void 0;return{...G,id:Y.id.trim(),title:Y.title.trim(),...$&&{modelId:$},modelName:Y.modelName.trim()}}).filter((Y)=>Y!=null);Z.scoped=x}if(Q(J.extraUsage)){let x=A(J.extraUsage.used),Y=A(J.extraUsage.limit);if(x&&Y&&typeof J.extraUsage.exhausted==="boolean")Z.extraUsage={used:x,limit:Y,...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(!Q(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 k(J){if(!Q(J))return{...H};let Z={quota:null};if(Q(J.main)){let $=J.main;if(Z.quota=R($.quota),typeof $.enabled==="boolean")Z.enabled=$.enabled;if(typeof $.stateLine==="string")Z.stateLine=$.stateLine;if($.quotaDated===!0)Z.quotaDated=!0;if(typeof $.tierLabel==="string"&&$.tierLabel.trim())Z.tierLabel=$.tierLabel.trim();if(typeof $.quotaBackedOff==="boolean")Z.quotaBackedOff=$.quotaBackedOff;if(z($.quotaBackoffUntil))Z.quotaBackoffUntil=$.quotaBackoffUntil;if(typeof $.refreshBackedOff==="boolean")Z.refreshBackedOff=$.refreshBackedOff;if(z($.refreshBackoffUntil))Z.refreshBackoffUntil=$.refreshBackoffUntil}let V=Array.isArray(J.fallbacks)?J.fallbacks.filter(Q).filter(($)=>typeof $.id==="string").map(($)=>({id:$.id,...typeof $.label==="string"&&{label:$.label},quota:R($.quota),enabled:typeof $.enabled==="boolean"?$.enabled:!1,...typeof $.stateLine==="string"&&{stateLine:$.stateLine},...$.quotaDated===!0&&{quotaDated:!0},needsReauth:typeof $.needsReauth==="boolean"?$.needsReauth:!1,...$.vaultReauth===!0&&{vaultReauth:!0},...$.vaultServed===!0&&{vaultServed:!0},...typeof $.custodyState==="string"&&{custodyState:$.custodyState},...typeof $.tierLabel==="string"&&$.tierLabel.trim()&&{tierLabel:$.tierLabel.trim()}})):[],X=null;if(Q(J.relay)){let $=J.relay;if(typeof $.enabled==="boolean"&&typeof $.transport==="string")X={enabled:$.enabled,transport:$.transport}}let x;if(Q(J.cacheKeep)){let $=J.cacheKeep;if(typeof $.enabled==="boolean")x={enabled:$.enabled,...typeof $.window==="string"&&{window:$.window},...z($.trackedSessions)&&{trackedSessions:$.trackedSessions}}}let Y=Array.isArray(J.fableRecoveries)?J.fableRecoveries.filter(Q).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,...typeof $.requestedModelId==="string"&&{requestedModelId:$.requestedModelId},...typeof $.targetModelId==="string"&&{targetModelId:$.targetModelId}}]}):[],G=a(J.prime);return{main:Z,fallbacks:V,...typeof J.activeId==="string"&&{activeId:J.activeId},route:typeof J.route==="string"?J.route:H.route,relay:X,fastMode:typeof J.fastMode==="boolean"?J.fastMode:H.fastMode,...x&&{cacheKeep:x},...G&&{prime:G},...Y.length>0&&{fableRecoveries:Y},lastUpdated:z(J.lastUpdated)?J.lastUpdated:0}}var W=Promise.resolve(),t=1000,e=2000,JJ=5,ZJ=15,M=new Map;function HJ(J,Z=P()){if(J)M.set(Z,J);else M.delete(Z)}function U(J){return M.get(J)}var p=null;function WJ(J){p=J}function UJ(){return p}function $J(J){return new Promise((Z)=>setTimeout(Z,J))}async function F(J){let Z=`${J}.lock`,V=U(J),X=V?.lockBudgetMs??t,x=V?.lockRetryMinMs??JJ,Y=V?.lockRetryMaxMs??ZJ,G=Date.now()+X;while(!0){try{await g(Z);let K=E(),j=f(Z,K);return await b(j,"",{encoding:"utf8",mode:384,flag:"wx"}),await V?.onLockAcquired?.(Z),{ownsLock:async()=>{try{return await D(j),!0}catch{return!1}},release:async()=>{try{await m(j)}catch{return}await V?.beforeReleaseDirectoryRemoval?.(Z),await w(Z).catch(()=>{})}}}catch(K){if(K.code!=="EEXIST")return C.trace("sidebar","state lock unavailable; write skipped",{stateFile:J,error:K instanceof Error?K.message:String(K)}),null}try{let K=await D(Z);if(Date.now()-K.mtimeMs>e){await V?.afterStaleLockStat?.(Z);let j=`${Z}.evict-${process.pid}-${E()}`;try{await S(Z,j)}catch(N){if(N.code==="ENOENT")continue;throw N}await V?.onStaleLockClaimed?.(Z),await O(j,{recursive:!0,force:!0}).catch(()=>{});continue}}catch(K){if(K.code==="ENOENT")continue;return C.trace("sidebar","state lock inspection failed; write skipped",{stateFile:J,error:K instanceof Error?K.message:String(K)}),null}let $=G-Date.now();if($<=0)return C.warn("sidebar","lock budget exhausted, write skipped",{stateFile:J,budgetMs:X}),null;let B=x+Math.floor(Math.random()*(Y-x+1));await $J(Math.min(B,$))}}async function qJ(J){return(await F(J))?.release??null}async function VJ(J,Z,V){let X=U(J),x=`${J}.${process.pid}.${E()}.tmp`;await b(x,JSON.stringify(Z),{encoding:"utf8",mode:384});try{if(!await V())return C.trace("sidebar","state lock lost before rename; write aborted",{stateFile:J}),await O(x,{force:!0}).catch(()=>{}),"lock-lost-before-rename";if(await X?.beforeRename?.(J,x),!await V())return C.trace("sidebar","state lock lost before rename; write aborted",{stateFile:J}),await O(x,{force:!0}).catch(()=>{}),"lock-lost-before-rename";if(await S(x,J),await U(J)?.afterRename?.(J),!await V())return"lock-lost-after-rename";return"written"}catch(Y){throw await O(x,{force:!0}).catch(()=>{}),Y}}async function T(J=P()){try{let Z=await y(J,"utf8");return k(JSON.parse(Z))}catch{return H}}async function LJ(J,Z=P(),V={}){return W=W.then(async()=>{await g(v(Z),{recursive:!0});for(let X=0;X<2;X++){let x=X===1,Y=await F(Z);if(!Y){if(x)C.warn("sidebar","post-rename repair lock unavailable; write skipped",{stateFile:Z});return}let G=J,$;try{if(V.routingAuthoritative===!1){let B=await T(Z),K=await V.resolvePreservedRouting?.(B);if(K){let j=K.state??J;G={...j,activeId:K.activeId,route:K.route,lastUpdated:Math.max(j.lastUpdated,B.lastUpdated)}}await U(Z)?.afterMergeRead?.(Z)}else if(x){let B=await T(Z);G={...B,activeId:J.activeId,route:J.route,relay:J.relay,fastMode:J.fastMode,cacheKeep:J.cacheKeep,lastUpdated:Math.max(B.lastUpdated,J.lastUpdated)}}G=k(G),$=await VJ(Z,G,Y.ownsLock)}finally{await Y.release()}if($==="lock-lost-after-rename"){if(x){C.warn("sidebar","post-rename repair lost lock; write skipped",{stateFile:Z});return}C.warn("sidebar","state lock lost after rename; repairing write",{stateFile:Z});continue}if($==="lock-lost-before-rename")return;V.onRoutingResolved?.({activeId:G.activeId,route:G.route});return}}).catch(()=>{}),W}async function EJ(){return W}function XJ(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,...V.stateLine&&{stateLine:V.stateLine,quotaDated:V.quotaDated}}}return{id:"main",name:"main",quota:J.main?.quota??null,...J.main?.stateLine&&{stateLine:J.main.stateLine,quotaDated:J.main.quotaDated}}}function L(J){if(J==="claude-mythos-5-1"||J?.startsWith("claude-mythos-5-1-"))return"Mythos 5.1";if(J==="claude-fable-5-1"||J?.startsWith("claude-fable-5-1-"))return"Fable 5.1";if(J==="claude-fable-5"||J?.startsWith("claude-fable-5-"))return"Fable 5";if(J==="claude-opus-5-5"||J?.startsWith("claude-opus-5-5-"))return"Opus 5.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 h(J){return new Date(J).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}function YJ(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 MJ(J,Z=Date.now()){if(J.lastResult==="error")return{text:"err",hasError:!0};if(J.lastResult==="skipped")return{text:"skip",hasError:!1};if(J.nextDueAt&&J.nextDueAt>Z)return{text:h(J.nextDueAt),hasError:!1};if(J.lastPrimedAt)return{text:`primed ${h(J.lastPrimedAt)} ✓`,hasError:!1};if(J.usage?.count)return{text:`✓ ${J.usage.count} ≈ $${YJ(J.estimatedCostUsd??0)}`,hasError:!1};return{text:"—",hasError:!1}}function fJ(J,Z){let V=J.fableRecoveries?.find((X)=>X.sessionId===Z);if(!V)return;if(V.mode==="fable")return`${L(V.requestedModelId)} · restored`;if(V.mode==="server")return`${L(V.requestedModelId)}→${L(V.targetModelId)} · safety`;return`Opus 4.8 · ${V.remaining} left`}function PJ(J,Z=10){if(Z<=0)return"";let V=J;if(Bun.stringWidth(V)>Z){V="";for(let X of J){if(Bun.stringWidth(V+X)>Z-1)break;V+=X}V+="…"}return V+" ".repeat(Math.max(0,Z-Bun.stringWidth(V)))}function xJ(J,Z=Date.now()){let V=J?.scoped??[];if(!V.length)return[];let{windows:X}=u(I({scoped:V},Z),{now:Z});return V.map((x)=>X.find((Y)=>Y.kind==="window"&&Y.name===x.title)?.short||x.title)}function _J(J,Z=Date.now()){return Math.max(2,...J.flatMap((V)=>xJ(V,Z).map((X)=>Bun.stringWidth(X))))}var GJ=3;function DJ(J){let{width:Z,labelWidth:V,barWidth:X,figure:x,reset:Y}=J,G={barCells:X,reset:Y||void 0};if(Z===void 0)return G;let $=(j)=>V+1+(j.barCells>0?j.barCells+1:0)+Bun.stringWidth(x)+(j.reset?1+Bun.stringWidth(j.reset):0),B=Math.min(GJ,X),K=[G];for(let j=X;j>=B;j--)K.push({barCells:j});return K.find((j)=>$(j)<=Z)??{barCells:B}}function RJ(J,Z,V,X,x){if(!J||J.state==="on-pace")return null;let Y=x!==void 0&&x<=0,G=V==="now"||V==="0m"?"<1m":V,$=`${J.state} ${Math.round(Math.abs(J.deltaPercent))}%`,B=Y?X?`used up · resets in ${X}`:"used up":G?`${$} · out in ${G}`:`${$} · lasts to reset`;if(Z===void 0||Bun.stringWidth(B)<=Z)return B;if(Z<=0)return"";let K="";for(let j of B){if(Bun.stringWidth(K+j)>Z-1)break;K+=j}return`${K.trimEnd()}…`}function AJ(J,Z=Date.now()){let V=J?.five_hour?.usedPercent??null,X=J?.seven_day?.usedPercent??null,x=J?.scoped??[],Y=x.map(($)=>$.usedPercent);if(!J||V==null&&X==null&&x.length===0&&!J.extraUsage)return{fiveHourUsedPercent:V,sevenDayUsedPercent:X,scopedUsedPercents:Y,text:null,stale:!1};let G=I(J,Z);return{fiveHourUsedPercent:V,sevenDayUsedPercent:X,scopedUsedPercents:Y,text:c(G,{now:Z,form:"narrow"}),stale:s(G,{now:Z})}}function TJ(J,Z=!0){let V=J.activeId===void 0?void 0:XJ(J).id;return[{id:"main",name:"main",quota:J.main?.quota??null,quotaDated:J.main?.quotaDated,active:V==="main",blocked:J.main?.enabled===!1||Boolean(J.main?.stateLine)},...Z?(J.fallbacks??[]).filter((X)=>X.enabled||X.custodyState&&X.custodyState!=="off").map((X)=>({id:X.id,name:X.label??X.id,quota:X.quota,quotaDated:X.quotaDated,active:V===X.id,blocked:!X.enabled||Boolean(X.stateLine)||X.needsReauth||X.vaultReauth===!0||X.custodyState!=null&&X.custodyState!=="off"&&X.custodyState!=="on-vault-served"})):[]]}var hJ=18000000,gJ=604800000,KJ=300000,jJ=0.01,BJ=1;function SJ(J,Z,V){if(!J.resetsAt)return null;let X=new Date(J.resetsAt).getTime();if(!Number.isFinite(X))return null;let x=X-Z,Y=V-x;if(Y<KJ)return null;if(Y<Z*jJ)return null;if(Y>=Z)return null;let G=J.usedPercent,$=Math.min(Math.max(Y/Z*100,0),100),B=G-$,K=Math.abs(B)<BJ?"on-pace":B>0?"deficit":"reserve",j=null;if(G>0){let N=Y*100/G,_=x+N;if(_<X)j=new Date(_).toISOString()}return{pacePercent:$,deltaPercent:B,state:K,runsOutAt:j}}
|
|
2
|
-
export{P as K,H as L,k as M,HJ as N,WJ as O,UJ as P,qJ as Q,T as R,LJ as S,EJ as T,XJ as U,L as V,h as W,YJ as X,MJ as Y,fJ as Z,PJ as _,xJ as $,_J as aa,GJ as ba,DJ as ca,RJ as da,AJ as ea,TJ as fa,hJ as ga,gJ as ha,SJ as ia};
|