@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
43 lines • 2.13 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 { ContentType } from "../../types.js";
import { perAccessor } from "../hierarchy/bind.js";
import { Codec, JSON_NAME, PATH_SAFE, RAW } from "../hierarchy/codec.js";
import { makeDetectScope } from "../hierarchy/scope.js";
import { blobLeaf, rowScopes } from "../vector/scope.js";
const TXT = new Codec({ suffix: '.txt' });
/**
* The mount's scope table, shaped by its config.
*
* A pinned `collection` removes the leading collection segment, and
* `textField` / `blobField` each add a leaf suffix beside the `.json` row. A
* group slot decodes through `PATH_SAFE`, so its filter holds the exact value
* the directory was rendered from; a `basenameFields` slot stays `RAW`
* because its rendering drops the value's parents and the lister resolves it
* against the payload instead.
*/
export function scopesFor(config) {
const leaves = [['row_json', JSON_NAME, ContentType.TEXT]];
if (config.textField !== null)
leaves.push(['row_text', TXT, ContentType.TEXT]);
if (config.blobField !== null)
leaves.push(blobLeaf(config.blobExt));
const groups = config.groupBy.map((column) => config.basenameFields.includes(column) ? RAW : PATH_SAFE);
return rowScopes(config.collection !== null, groups, leaves);
}
function buildDetect(accessor) {
return makeDetectScope(scopesFor(accessor.config));
}
export const detectFor = perAccessor(buildDetect);
//# sourceMappingURL=scope.js.map