@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
126 lines (125 loc) • 4.66 kB
JavaScript
import { SharePointAccessor, SharePointConfig } from "../../accessor/sharepoint.js";
import { copy } from "../../core/sharepoint/copy.js";
import { create } from "../../core/sharepoint/create.js";
import { buildDeltaHook } from "../../core/sharepoint/events.js";
import { exists } from "../../core/sharepoint/exists.js";
import { mkdir } from "../../core/sharepoint/mkdir.js";
import { read } from "../../core/sharepoint/read.js";
import { readdir, tree } from "../../core/sharepoint/readdir.js";
import { rename } from "../../core/sharepoint/rename.js";
import { rmR } from "../../core/sharepoint/rm.js";
import { rmdir } from "../../core/sharepoint/rmdir.js";
import { filesContaining } from "../../core/sharepoint/search.js";
import { stat } from "../../core/sharepoint/stat.js";
import { readStream } from "../../core/sharepoint/stream.js";
import { truncate } from "../../core/sharepoint/truncate.js";
import { unlink } from "../../core/sharepoint/unlink.js";
import { write } from "../../core/sharepoint/write.js";
import { VFSName } from "../../types.js";
import { BaseVFS } from "../base.js";
export const VFS_MD = `\`\`\`text
{prefix}
<site>/ # every SharePoint site you can reach
<library>/ # its document libraries (drives)
<path> # the drive's files and folders
\`\`\`
- SharePoint document libraries, discovered across sites and drives. An
unscoped mount reads \`/{site_name}/{library_name}/{path_to_file}\`:
\`ls /\` lists the sites, \`ls /site/\` a site's libraries, and
\`ls /site/lib/...\` a drive's files and folders.
- This is a remote mount: prefer targeted reads (\`grep\`, \`head\`) over
full scans, and pipe a large file to \`head\` or \`tail\` rather than
\`cat\` it whole.
- File versions are retained; a snapshot pins and reads prior
versions.`;
export class SharePointVFS extends BaseVFS {
name = VFSName.SHAREPOINT;
cachesReads = true;
// Graph drive items carry an exact content-length size and the site
// and drive levels are plain directories; unlike onedrive there is
// no aggregate-size root item.
sizesAlwaysKnown = true;
supportsSnapshot = true;
// stat and every read that can fill the cache stamp the item's cTag, the
// read taking it before the bytes, so the gate compares like with like.
readRevalidatable = true;
indexTtl = 86_400;
vfsMd = VFS_MD;
wholeWordSearch = true;
accessor;
config;
constructor(config) {
super();
this.config = config;
this.accessor = new SharePointAccessor(config);
}
readsRanges = true;
readdir(path, handed) {
return readdir(this.accessor, path, handed?.limit);
}
read(path, _handed, offset = 0, size = null) {
if (offset === 0 && size === null)
return readStream(this.accessor, path);
return read(this.accessor, path, size === null ? { offset } : { offset, size });
}
stat(path) {
return stat(this.accessor, path);
}
exists(path) {
return exists(this.accessor, path);
}
readTree(path, handed) {
return tree(this.accessor, path, handed?.limit);
}
write(path, data, signal) {
return write(this.accessor, path, data, signal);
}
create(path) {
return create(this.accessor, path);
}
mkdir(path, parents = false) {
return mkdir(this.accessor, path, parents);
}
unlink(path) {
return unlink(this.accessor, path);
}
rmdir(path) {
return rmdir(this.accessor, path);
}
rmR(path) {
return rmR(this.accessor, path);
}
rename(src, dst) {
return rename(this.accessor, src, dst);
}
copy(src, dst) {
return copy(this.accessor, src, dst);
}
dirCopy(src, dst) {
return copy(this.accessor, src, dst);
}
truncate(path, length, noCreate = false) {
return truncate(this.accessor, path, length, noCreate);
}
/**
* Whether this VFS answers `name`; with no walk limit it reads every
* file rather than ask the service's search.
*/
supports(name) {
if (name === 'files_containing' && this.walkLimit < 0)
return false;
return super.supports(name);
}
filesContaining(path, text, opts) {
if (!opts.wholeWord || this.walkLimit < 0)
return Promise.resolve(null);
return filesContaining(this.accessor, text, [path]);
}
deltaHook() {
return buildDeltaHook(this.accessor);
}
getState() {
return this.configState(SharePointConfig, this.config);
}
}
//# sourceMappingURL=sharepoint.js.map