Files
stack/packages/plugins/src/model-quota.mjs
jason.woltje 2627321f64 fix(model-proxy): row 333 R1 repair overlay as reviewed (source-tests.patch a78bc385, #1831)
Commits the 18 product paths of the row 333 R1 repair exactly as the reviewed overlay. Packet hashes: source-tests.patch sha256 a78bc385801b64be270fb9d6e84672c443738a5fce8eb68f7d2a01359a57a770 (40623 bytes), INDEX.json sha256 3eb9b8d10445aa328be3b854385e4792dda2c5712b19d443d485d1b00a18d0f8, changed-source-tests.json sha256 42f770fc3e2384362efd1e416091355c064b6cca22dd40f3b5ef8f7b67e43a52. The committed bytes were checked by applying source-tests.patch to 503b91e56 in a scratch tree and comparing the 18 paths. The approvals are source only: R2 (APPROVE source-only, 2026-10-26 23:32:39Z) and Boyd's first review (APPROVE, source only, 2026-10-27T00:27:55Z), both on HEAD 503b91e56 plus this overlay. No test has run on these bytes yet.
2026-11-02 13:36:45 -06:00

18 lines
1.1 KiB
JavaScript

// The new P5 namespace is the validated DAILY leaf, never a twelve-hex name
// alone. Plain {limit,since} keys remain legacy account limits.
const ID = /^[a-f0-9]{12}$/;
const RESET = /^([01]\d|2[0-3]):[0-5]\d$/;
const ZONE = /^[A-Za-z][A-Za-z0-9_+-]*(\/[A-Za-z0-9_+-]+)*$/;
const SINCE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
export function isDailyModelQuota(key, value) {
if (typeof key !== 'string' || !ID.test(key) || !value || typeof value !== 'object' || Array.isArray(value)
|| Object.keys(value).some(k => !['limit','since','reset','timeZone'].includes(k))
|| !Number.isSafeInteger(value.limit) || value.limit < 0
|| typeof value.since !== 'string' || !SINCE.test(value.since) || Number.isNaN(Date.parse(value.since))
|| new Date(value.since).toISOString() !== value.since
|| typeof value.reset !== 'string' || !RESET.test(value.reset)
|| typeof value.timeZone !== 'string' || !ZONE.test(value.timeZone)) return false;
try { new Intl.DateTimeFormat('en-US', { timeZone:value.timeZone }); return true; }
catch { return false; }
}