feat(freebuff): enhance Freebucks handling and pricing logic across services

This commit is contained in:
MUH. IQRAM BAHRING committed 2026-09-07 22:26:28 +08:00
1 parent eedfdf982b
commit 9c17c5f96c
9 files changed
+352 -19

No files matched your search

+20 -2
View File
@@ -334,8 +334,26 @@ async function requestSession(token, model, proxyOptions) {
premium_slot_taken: "Freebuff premium slot is taken — try another model.",
};
if (GATE_MESSAGES[status]) {
const message = data?.message ? `${GATE_MESSAGES[status]} ${data.message}` : GATE_MESSAGES[status];
throw new Error(message);
const err = new Error(data?.message ? `${GATE_MESSAGES[status]} ${data.message}` : GATE_MESSAGES[status]);
// Freebucks / session-allowance exhaustion is a hard stop until the daily
// Pacific reset — mark the account unavailable until then so accountFallback
// SKIPS it for the rest of the day instead of retrying every 30s and getting
// refused repeatedly. resetsAtMs is honored by markAccountUnavailable;
// freebuff bypasses the generic 30-min cap (see auth.js).
if (status === "rate_limited" || status === "spend_limited") {
const resetAtMs = Date.parse(data?.resetAt || "");
if (Number.isFinite(resetAtMs) && resetAtMs > Date.now()) {
err.resetsAtMs = resetAtMs;
err.status = 429;
} else {
const retryAfterMs = Number(data?.retryAfterMs);
if (Number.isFinite(retryAfterMs) && retryAfterMs > 0) {
err.resetsAtMs = Date.now() + retryAfterMs;
err.status = 429;
}
}
}
throw err;
}
throw new Error(`Freebuff session rejected (${status || response.status}): ${JSON.stringify(data).slice(0, 200)}`);
}
+16 -10
View File
@@ -34,7 +34,7 @@ export default {
website: "https://freebuff.com",
notice: {
signupUrl: "https://freebuff.com",
text: "Free ad-supported coding agent by Codebuff. Sign in with your Freebuff/Codebuff account via browser login. Free tier is ad-supported and limited in some regions (limited mode: 6 x 1-hour sessions/day); full mode runs in select countries. ⚠️ One account has ONE active session locked to ONE model — requesting a different model while a session is active returns 'model_locked' (409); use a separate account per model, or wait for the session to expire.",
text: "Free ad-supported coding agent by Codebuff. Sign in with your Freebuff/Codebuff account via browser login. Each model is priced in Freebucks per hour of session, charged once when the session starts. Your daily Freebucks refill at midnight Pacific; the wallet keeps what you buy or earn. Free tier is ad-supported and limited in some regions (limited mode: 6 x 1-hour sessions/day); full mode runs in select countries. ⚠️ One account has ONE active session locked to ONE model — rLine truncated
},
},
category: "free",
@@ -63,15 +63,21 @@ export default {
usage: true,
},
// Mirrors the Freebuff waiting-room picker (upstream FREEBUFF_MODELS) as of
// 2026-09-05, plus the capacity-limited Fable trial. deepseek-v4-pro and
// minimax-m3 were withdrawn upstream (2026-08-26 / 2026-08-20) and ox-alpha
// (2026-08-27) + gemini-3.8-flash (2026-09-03) never stuck — none are
// claimable anymore. z-ai/glm-5.2 is a referral reward (not a free pick),
// luna-es / kimi-k3-eco are god-only rows, and the `-max` variants are
// provisioned per-account — all intentionally omitted. Fable is a
// capacity-limited WAVE trial: sessions only claim while the backend
// advertises it via limitedModelOffers on the session status (the executor
// auto-checks before claiming); the model is otherwise refused.
// 2026-09-07. NO per-model prices live here: Freebucks pricing is
// server-authoritative — the session response's `freebucks` block carries
// `prices` (model → Freebucks/hr) plus an announced `priceChanges` schedule
// (promos like Solar Pro 4's Labor Day run expire server-side; see
// services/usage/freebuff.js which folds both in, exactly like the upstream
// CLI which hardcodes no number). Plus the capacity-limited Fable trial.
// deepseek-v4-pro and minimax-m3 were withdrawn upstream (2026-08-26 /
// 2026-08-20) and ox-alpha (2026-08-27) + gemini-3.8-flash (2026-09-03)
// never stuck — none are claimable anymore.
// z-ai/glm-5.2 is a referral reward (not a free pick), luna-es / kimi-k3-eco
// are god-only rows, and the `-max` variants are provisioned per-account —
// all intentionally omitted. Fable is a capacity-limited WAVE trial: sessions
// only claim while the backend advertises it via limitedModelOffers on the
// session status (the executor auto-checks before claiming); the model is
// otherwise refused.
models: [
{ id: "z-ai/glm-5.3-flash", name: "GLM 5.3 Flash" },
{ id: "deepseek/deepseek-v4-flash", name: "DeepSeek V4 Flash" },
+87 -1
View File
@@ -15,6 +15,22 @@
* includes the active session's own 1.0-unit reservation. `limit` can be
* raised by referral/streak rewards (entitlementBreakdown.base + referral +
* streak).
*
* Freebucks-metered accounts (2026-09-02+) get NO pool rows: the server sends
* a `freebucks` block instead — { balance, daily:{limit,spent,remaining,resetAt},
* wallet:{balance,...}, monthly?:{limitUsd,spentUsd,remainingUsd,resetAt},
* planId, prices:{model→Freebucks/hr}, priceNotices?, priceChanges? }. The
* daily pool replaces rateLimitsByModel, so the tracker folds it in by
* replicating the pool snapshot under every priced model id, exactly as the
* official picker does.
*
* Pricing is SERVER-AUTHORITATIVE and nothing here hardcodes a number: each
* row carries the live `prices[model]` (plus its `priceNotices` tagline), and
* `applyFreebucksPriceChanges` folds the server's announced `priceChanges`
* schedule into the map — a promo (e.g. Solar Pro 4's Labor Day 0-Freebucks
* offer) expires and reverts on the server's timeline with no client release,
* mirroring upstream common/src/util/freebuff-price-changes.ts. A compact
* account summary (`freebucks`) rides the response for the card header.
*/
import REGISTRY from "../../providers/registry/index.js";
@@ -26,6 +42,28 @@ const MODEL_LABELS = Object.fromEntries(
(freebuffRegistry.models || []).map((m) => [m.id, m.name]),
);
// Fold the server's announced price schedule into the live price map —
// mirrors upstream applyFreebucksPriceChanges: due changes override the price
// AND its picker tagline, and drop off the pending list.
function applyFreebucksPriceChanges(info) {
const now = Date.now();
const due = (info?.priceChanges || []).filter((c) => Date.parse(c.at) <= now);
if (due.length === 0) return info;
const prices = { ...(info.prices || {}) };
const priceNotices = { ...(info.priceNotices || {}) };
for (const change of due.sort((a, b) => Date.parse(a.at) - Date.parse(b.at))) {
if (prices[change.modelId] === undefined) continue;
prices[change.modelId] = change.price;
priceNotices[change.modelId] = change.tagline;
}
return {
...info,
prices,
priceNotices,
priceChanges: (info.priceChanges || []).filter((c) => Date.parse(c.at) > now),
};
}
function sessionUrl() {
return U("freebuff").url;
}
@@ -102,11 +140,59 @@ export async function getFreebuffUsage(accessToken, providerSpecificData, proxyO
};
}
// Freebucks meter: the daily Freebucks pool is the quota for metered
// accounts, replicated under each priced model like the picker's rings.
// Prices come off the wire (prices + priceChanges folded in); each row
// carries its own price/tagline, and a compact summary rides the response
// for the account header in the UI.
let freebucksSummary = null;
const rawFreebucks = data.freebucks;
if (rawFreebucks && rawFreebucks.daily && typeof rawFreebucks.daily === "object") {
const freebucks = applyFreebucksPriceChanges(rawFreebucks);
const spent = Number(freebucks.daily.spent);
const limit = Number(freebucks.daily.limit);
for (const [model, price] of Object.entries(freebucks.prices || {})) {
quotas[model] = {
used: Number.isFinite(spent) ? spent : 0,
total: Number.isFinite(limit) ? limit : 0,
resetAt: freebucks.daily.resetAt || null,
unlimited: false,
recurring: true,
price: Number.isFinite(Number(price)) ? Number(price) : undefined,
...(freebucks.priceNotices?.[model] ? { priceNote: freebucks.priceNotices[model] } : {}),
...(MODEL_LABELS[model] ? { displayName: MODEL_LABELS[model] } : {}),
};
}
freebucksSummary = {
balance: Number.isFinite(Number(freebucks.balance)) ? Number(freebucks.balance) : null,
daily: {
limit: Number.isFinite(limit) ? limit : 0,
spent: Number.isFinite(spent) ? spent : 0,
remaining: Number.isFinite(Number(freebucks.daily.remaining)) ? Number(freebucks.daily.remaining) : 0,
resetAt: freebucks.daily.resetAt || null,
},
wallet: {
balance: Number.isFinite(Number(freebucks.wallet?.balance)) ? Number(freebucks.wallet.balance) : 0,
},
...(freebucks.monthly && Number.isFinite(Number(freebucks.monthly.remainingUsd))
? {
monthly: {
remainingUsd: Number(freebucks.monthly.remainingUsd),
limitUsd: Number.isFinite(Number(freebucks.monthly.limitUsd)) ? Number(freebucks.monthly.limitUsd) : null,
resetAt: freebucks.monthly.resetAt || null,
},
}
: {}),
};
}
const plan = data.accessTier === "limited" ? "Freebuff (Limited)" : "Freebuff";
if (Object.keys(quotas).length === 0) {
return { plan, message: "Freebuff connected. No session quota to report right now." };
}
return { plan, quotas };
const out = { plan, quotas };
if (freebucksSummary) out.freebucks = freebucksSummary;
return out;
} catch (error) {
return { message: `Freebuff usage error: ${error.message}` };
}