The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | export const MiB = 1024 * 1024; |
| 2 | export const PART_SIZE = 5 * MiB; |
| 3 | export const LEASE_SECONDS = 15 * 60; |
| 4 | export const GRACE_SECONDS = 10 * 60; |
| 5 | |
| 6 | export const defaults = { |
| 7 | key: 16 * 1024, |
| 8 | value: 4 * MiB, |
| 9 | metadata: 5 * MiB, |
| 10 | fetch: 40 * 1024, |
| 11 | blob: 64 * MiB, |
| 12 | store: 72 * MiB, |
| 13 | headers: 8 * 1024, |
| 14 | deadlineMs: 120_000, |
| 15 | }; |
| 16 | export type Limits = typeof defaults; |
| 17 | |
| 18 | export function limitsFrom(raw: string): Limits { |
| 19 | const input: unknown = JSON.parse(raw); |
| 20 | if (!input || typeof input !== 'object' || Array.isArray(input)) |
| 21 | throw new Error('Invalid limits'); |
| 22 | const result = { ...defaults }; |
| 23 | for (const [name, value] of Object.entries(input)) { |
| 24 | if ( |
| 25 | !(name in defaults) || |
| 26 | !Number.isSafeInteger(value) || |
| 27 | value <= 0 || |
| 28 | value > defaults[name as keyof Limits] |
| 29 | ) { |
| 30 | throw new Error('Limits must be positive integers no larger than the tested defaults'); |
| 31 | } |
| 32 | result[name as keyof Limits] = value; |
| 33 | } |
| 34 | if ( |
| 35 | result.metadata < 2 * result.key + result.value + 128 || |
| 36 | result.fetch < 2 * result.key + 128 || |
| 37 | result.store < result.metadata + result.blob + 1024 |
| 38 | ) { |
| 39 | throw new Error('Envelope limits must accommodate field limits and framing'); |
| 40 | } |
| 41 | return result; |
| 42 | } |