tokenmaxxing 1.104.0 → 1.105.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/package.json +1 -1
- package/src/entries/stopfailurehook.ts +3 -3
- package/src/lib/usage.ts +3 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokenmaxxing",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.105.0",
|
|
4
4
|
"description": "Automatic Claude Code account switching: pool multiple accounts, start each session on its own account, and resume a session on a fresher account when quota fills.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -20,10 +20,10 @@ const StopFailureStdin = z.looseObject({
|
|
|
20
20
|
const ROW_WAIT_MS = 3_000;
|
|
21
21
|
const ROW_POLL_MS = 200;
|
|
22
22
|
|
|
23
|
-
async function awaitEnforcedRow(input: { transcriptPath: string; error: string; lastAssistantMessage: string | undefined
|
|
23
|
+
async function awaitEnforcedRow(input: { transcriptPath: string; error: string; lastAssistantMessage: string | undefined }): Promise<TranscriptRow | null> {
|
|
24
24
|
const deadline = Date.now() + ROW_WAIT_MS;
|
|
25
25
|
while (true) {
|
|
26
|
-
const row = findEnforcedRow({ rows: await readTranscriptTail(input.transcriptPath), error: input.error, lastAssistantMessage: input.lastAssistantMessage
|
|
26
|
+
const row = findEnforcedRow({ rows: await readTranscriptTail(input.transcriptPath), error: input.error, lastAssistantMessage: input.lastAssistantMessage });
|
|
27
27
|
if (row || Date.now() >= deadline) return row;
|
|
28
28
|
await Bun.sleep(ROW_POLL_MS);
|
|
29
29
|
}
|
|
@@ -52,7 +52,7 @@ export async function runStopFailureHook(): Promise<number> {
|
|
|
52
52
|
const canRespawn = session != null && mainLoop;
|
|
53
53
|
const cfg = loadConfig();
|
|
54
54
|
const row = stdin.transcript_path
|
|
55
|
-
? await awaitEnforcedRow({ transcriptPath: stdin.transcript_path, error, lastAssistantMessage: stdin.last_assistant_message
|
|
55
|
+
? await awaitEnforcedRow({ transcriptPath: stdin.transcript_path, error, lastAssistantMessage: stdin.last_assistant_message })
|
|
56
56
|
: null;
|
|
57
57
|
const limit = row ? classifyEnforcedLimit(row, cfg.policy.switchModels) : null;
|
|
58
58
|
|
package/src/lib/usage.ts
CHANGED
|
@@ -52,7 +52,6 @@ export function modelFromFlag(value: string | null): ModelInfo | null {
|
|
|
52
52
|
const TranscriptBlockSchema = z.looseObject({ type: z.string().optional(), text: z.string().optional() });
|
|
53
53
|
export const TranscriptRowSchema = z.looseObject({
|
|
54
54
|
type: z.string().optional(),
|
|
55
|
-
timestamp: z.string().optional(),
|
|
56
55
|
isApiErrorMessage: z.boolean().optional(),
|
|
57
56
|
apiErrorIsTransient: z.boolean().optional(),
|
|
58
57
|
apiError: z.string().optional(),
|
|
@@ -84,21 +83,11 @@ export function transcriptRowText(row: TranscriptRow): string {
|
|
|
84
83
|
return blocks.data.filter((b) => b.type === "text").map((b) => b.text ?? "").join("\n").trim();
|
|
85
84
|
}
|
|
86
85
|
|
|
87
|
-
const ROW_RECENCY_MS = 60_000;
|
|
88
|
-
|
|
89
86
|
export const ENFORCED_ERRORS = ["rate_limit", "oauth_org_not_allowed"];
|
|
90
87
|
|
|
91
|
-
export function findEnforcedRow(input: { rows: TranscriptRow[]; error: string; lastAssistantMessage: string | undefined
|
|
92
|
-
const { rows, error, lastAssistantMessage
|
|
93
|
-
|
|
94
|
-
const row = rows[i]!;
|
|
95
|
-
if (row.isApiErrorMessage !== true || row.error !== error) continue;
|
|
96
|
-
const ts = row.timestamp ? Date.parse(row.timestamp) : Number.NaN;
|
|
97
|
-
const byContent = lastAssistantMessage != null && lastAssistantMessage !== "" && transcriptRowText(row) === lastAssistantMessage;
|
|
98
|
-
const byRecency = Number.isFinite(ts) && Math.abs(now - ts) <= ROW_RECENCY_MS;
|
|
99
|
-
if (byContent || byRecency) return row;
|
|
100
|
-
}
|
|
101
|
-
return null;
|
|
88
|
+
export function findEnforcedRow(input: { rows: TranscriptRow[]; error: string; lastAssistantMessage: string | undefined }): TranscriptRow | null {
|
|
89
|
+
const { rows, error, lastAssistantMessage } = input;
|
|
90
|
+
return rows.findLast((row) => row.isApiErrorMessage === true && row.error === error && transcriptRowText(row) === lastAssistantMessage) ?? null;
|
|
102
91
|
}
|
|
103
92
|
|
|
104
93
|
export type EnforcedClass =
|