@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
42 lines • 1.95 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. =========
import { writesConditioned } from "../../cache/context.js";
import { record, startOp } from "../../observe/context.js";
import { getFileInfo } from "./api.js";
import { SHA1 } from "./constants.js";
import { readToken, tokenOf } from "./fingerprint.js";
import { fileEntry } from "../hierarchy/probe.js";
/**
* The sha1 Box keeps for a file's content, asked live: a listing row's sha1
* can be older than the bytes a read downloads, so the file's own record is
* asked. Box keeps no other digest. A digest answered is recorded as the read
* it stands in for, with the token a whole read of those bytes would record.
* Mirrors Python's core/box/checksum.py.
*/
export async function checksum(accessor, path, algorithm, entry) {
if (algorithm !== SHA1)
return null;
const row = fileEntry(path, entry);
const timer = startOp();
const item = await getFileInfo(accessor.tokenManager, row.extra.box_id);
const found = tokenOf(item.sha1);
if (found === null)
return null;
const digest = found.toLowerCase();
record('read', path.virtual, 'box', 0, timer, {
fingerprint: writesConditioned(path) ? digest : readToken(row, digest),
});
return digest;
}
//# sourceMappingURL=checksum.js.map