@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
38 lines • 1.73 kB
JavaScript
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
/**
* Max bytes a streamed read may buffer to fill the cache.
*
* null (the default) caps each fill at 8 MiB or `cacheLimit`. An explicit
* value keeps larger streams out of the cache and may not exceed the
* cache's intended capacity. Mirrors Python `drain_budget`.
*/
export function drainBudget(cache) {
validateMaxDrainBytes(cache.cacheLimit, cache.maxDrainBytes);
return cache.maxDrainBytes ?? Math.min(cache.cacheLimit, 8 * 1024 * 1024);
}
export function validateMaxDrainBytes(cacheLimit, maxDrainBytes) {
if (!Number.isSafeInteger(cacheLimit) || cacheLimit < 0) {
throw new RangeError('cacheLimit must be a non-negative safe integer');
}
if (maxDrainBytes === null)
return;
if (!Number.isSafeInteger(maxDrainBytes) || maxDrainBytes < 0) {
throw new RangeError('maxDrainBytes must be a non-negative safe integer');
}
if (maxDrainBytes > cacheLimit) {
throw new RangeError('maxDrainBytes cannot exceed cacheLimit');
}
}
//# sourceMappingURL=mixin.js.map