5a027a0081
Splitting the god files made a pile of copy-paste helpers visible and, for the first time, fixable — sharing them previously meant importing a god file. Hashing function bodies through the TypeScript AST found twelve groups desktop-wide; production code is now at zero duplicates. Each helper went to the module that already owns its concern: firstStringField to lib/text, the two REST 404 predicates to lib/gateway-rpc beside isMissingRpcMethod, useDebounced and prefersReducedMotion to their hooks, the superseded-bootstrap guard to electron/ssh-connection, the composer keyup handler to the trigger hook that owns the rest of that state machine, and clampDataUrlReadMaxMb to apps/shared, replacing a "keep these in sync" comment between two copies. Only helpers with no existing owner got a new file: lib/mcp-servers, lib/audio-context, lib/keyed-timeouts, lib/pointer-drag, and the command palette's status row. Error-shape predicates are the worst thing to copy — when the backend changes how it reports a missing route, every copy has to be found.
28 lines
985 B
TypeScript
28 lines
985 B
TypeScript
/**
|
|
* Size cap for local files Desktop loads as data URLs (composer attach, image
|
|
* preview, …).
|
|
*
|
|
* Main owns the persisted value; the renderer mirrors it in Settings → Chat and
|
|
* clamps optimistically before sending. Both ends have to agree on the default
|
|
* and the bounds, so they live here rather than as two constants with a
|
|
* "keep these in sync" comment between them.
|
|
*
|
|
* The whole file is base64-buffered in main, so this is a memory guard, not a
|
|
* model limit. The ceiling is only a typo guard — values well below it can
|
|
* still OOM the app.
|
|
*/
|
|
|
|
export const DATA_URL_READ_DEFAULT_MAX_MB = 16
|
|
export const DATA_URL_READ_MIN_MAX_MB = 1
|
|
export const DATA_URL_READ_MAX_MAX_MB = 4096
|
|
|
|
export function clampDataUrlReadMaxMb(value: unknown): number {
|
|
const parsed = Number(value)
|
|
|
|
if (!Number.isFinite(parsed)) {
|
|
return DATA_URL_READ_DEFAULT_MAX_MB
|
|
}
|
|
|
|
return Math.min(DATA_URL_READ_MAX_MAX_MB, Math.max(DATA_URL_READ_MIN_MAX_MB, Math.round(parsed)))
|
|
}
|