UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

81 lines • 3.43 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. ========= import { ChromaAccessor } from "../../accessor/chroma.js"; import { readStream } from "../../core/chroma/read.js"; import { filesContaining, searchMany } from "../../core/chroma/search.js"; import { stat } from "../../core/chroma/stat.js"; import { CHROMA_TREE } from "../../core/chroma/tree.js"; import {} from "../../io/types.js"; import { VFSName } from "../../types.js"; import { BaseVFS } from "../base.js"; import { redactChromaConfig, resolveChromaConfig } from "./config.js"; export const VFS_MD = `- One ChromaDB collection, mounted read only. - Paths are document slugs from the collection's path tree. - Inspect documents with \`cat\`, \`head\`, \`tail\`, \`ls\`, \`find\`, \`tree\` and \`grep\`. Writes are not supported.`; export class ChromaVFS extends BaseVFS { name = VFSName.CHROMA; cachesReads = false; supportsSnapshot = false; // Every file is sized exactly, by one chunk scan per directory the caller // stats; the path tree's own size is the producer's source number and // never becomes the reported byte length. sizesAlwaysKnown = true; vfsMd = VFS_MD; config; accessor; handed = { readdir: ['entry'], read: ['entry'], stat: ['entry', 'index'], }; constructor(options) { super(); const config = 'config' in options ? options.config : options; this.config = resolveChromaConfig(config); this.accessor = new ChromaAccessor(this.config); } getState() { return { type: this.name, config: redactChromaConfig(this.config), // TypeScript cannot rebuild a config-backed mount from state: // `buildMountArgs` substitutes a RAMVFS for anything it was // not handed. Saying so out loud turns a silently empty mount // into a refusal to load. Python rebuilds via its registry, so it // writes this on only four mounts and reads it nowhere. needs_override: true, }; } readdir(path, handed) { return CHROMA_TREE.readdir(this.accessor, path, handed?.entry); } // eslint-disable-next-line @typescript-eslint/require-await async read(path, handed) { return readStream(this.accessor, path, handed?.entry); } stat(path, handed) { return stat(this.accessor, path, handed?.entry, handed?.index); } filesContaining(path, text, opts) { return filesContaining(this.accessor, text, [path], opts.ignoreCase); } search(path, query) { return searchMany(this.accessor, [path], query); } searchMany(paths, query) { return searchMany(this.accessor, paths, query); } } //# sourceMappingURL=chroma.js.map