Partition API cooldowns by workspace
Reduce rate-limit observations into one latest cooldown deadline per workspace without allowing a shorter observation to move a deadline backward.Description
Requirements
Export partitionWorkspaceCooldowns from src/App.js.
Maintain an independent cooldown for each nonempty workspaceId.
Convert each nonnegative retryAfterMs into input.now plus that delay.
Keep the greatest calculated deadline observed for a workspace.
Return a plain record whose keys are inserted in ascending workspace ID order.
Return an observably equivalent result for equivalent inputs without reading time, randomness, network, storage, or DOM globals.
Do not mutate input objects, arrays, nested records, or values retained in the returned result.
Shared cooldown
W1 observes 2s then 5s at now 1000
W1 receives deadline 6000
Maintain an independent cooldown for each nonempty workspaceId.
Separate workspaces
W1 and W2 receive different delays
Each workspace has its own deadline
Convert each nonnegative retryAfterMs into input.now plus that delay.
Constraints
Implement a pure synchronous function with no external side effectsTreat every input collection and nested record as read-onlyReturn JSON-compatible data except where the declared TypeScript API explicitly uses bigint
Hints
Hint 1
Start with the partitions-by-workspace behavior and make its observable result deterministic.
Hint 2
Model converts-delay-to-deadline independently before combining it with the remaining states.
Hint 3
Verify the boundary described by sorts-workspace-keys without changing caller-owned input.