app

Local-first trade for farms and co-ops
git clone https://radroots.dev/git/app.git
Log | Files | Refs | README | LICENSE

inbox-budget.ts (1617B)


      1 import {
      2   PRIVATE_TRANSPORT_BUDGETS,
      3   PRIVATE_LIVE_BUDGETS,
      4   LOCAL_PERSISTENCE_BUDGETS
      5 } from '../config/budgets.ts';
      6 // Detached display/recovery metadata only. Original transport/repositories own
      7 // actual admission; these choices never reset a meter, delete or resume work.
      8 export function inboxBudgetSnapshot() {
      9   return {
     10     finite: {
     11       deliveries: PRIVATE_TRANSPORT_BUDGETS.deliveries,
     12       bytes: PRIVATE_TRANSPORT_BUDGETS.processedBytes,
     13       milliseconds: PRIVATE_TRANSPORT_BUDGETS.pageMilliseconds
     14     },
     15     live: {
     16       deliveries: PRIVATE_LIVE_BUDGETS.deliveries,
     17       bytes: PRIVATE_LIVE_BUDGETS.processedBytes,
     18       milliseconds: PRIVATE_LIVE_BUDGETS.windowMilliseconds
     19     },
     20     received: {
     21       records: LOCAL_PERSISTENCE_BUDGETS.receivedEnvelopes,
     22       bytes: LOCAL_PERSISTENCE_BUDGETS.receivedCiphertextBytes
     23     },
     24     outbox: {
     25       records: LOCAL_PERSISTENCE_BUDGETS.unfinishedPrivateSends,
     26       bytes: LOCAL_PERSISTENCE_BUDGETS.privateSendBytes
     27     }
     28   };
     29 }
     30 export function inboxRecoveryChoices(reason: unknown): readonly string[] {
     31   if (typeof reason !== 'string') return [];
     32   if (reason === 'capacity')
     33     return ['review_local_received_copies', 'review_relay_recovery'];
     34   if (reason === 'budget' || reason === 'timeout' || reason === 'elapsed')
     35     return [
     36       'wait_then_review_refresh',
     37       'review_history_scope',
     38       'review_local_received_copies'
     39     ];
     40   if (
     41     [
     42       'aborted',
     43       'unknown_completion',
     44       'conflict',
     45       'corrupt_record',
     46       'unavailable'
     47     ].includes(reason)
     48   )
     49     return ['review_storage_recovery'];
     50   return [];
     51 }