UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

45 lines • 1.9 kB
// ========= 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. ========= /** * The stat a write's reply names for the stored item, or null. * * `statOf` is the backend's own stat parser, so the stat reads as its `stat` * does. The write has landed by now, so a reply that is not an object, or * that the parser cannot read, answers null instead of throwing. Mirrors * python's `upload_stat`. */ export function uploadStat(item, statOf, virtual) { if (typeof item !== 'object' || item === null || Array.isArray(item)) return null; try { return statOf(item); } catch (err) { console.warn(`unreadable upload reply for ${virtual}: ${String(err)}`); return null; } } /** * The token an upload reply names for the stored file, or null. * * `statOf` is the backend's own stat parser, so the write's token is the * kind its `stat` reports. The upload has landed by now, so a reply that is * not an object, or that the parser cannot read, answers null instead of * throwing. Mirrors python's `upload_token`. */ export function uploadToken(item, statOf, virtual) { const token = uploadStat(item, statOf, virtual)?.fingerprint ?? null; return token === '' ? null : token; } //# sourceMappingURL=upload.js.map