@struktoai/mirage-core
Version:
A Unified Virtual Filesystem For AI Agents
86 lines • 3.74 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 { z } from 'zod';
import { MSGRAPH_CONFIG_SHAPE, optionalText, resolveMsGraphConfig, } from "../core/msgraph/config.js";
import { stripSlash } from "../utils/slash.js";
import { Accessor } from "./base.js";
const DRIVE_TARGETS = ['driveId', 'siteId', 'groupId', 'userId'];
// Names the count and the fields actually set, the way python's
// `OneDriveConfig` validator does; a fixed message listing all four
// targets pointed at two the caller never wrote.
function driveTargetError(named) {
return (`OneDriveConfig names ${String(named.length)} drives (${named.join(', ')}); ` +
"set exactly one, or none for the signed-in user's drive");
}
export const OneDriveConfig = z
.object({
...MSGRAPH_CONFIG_SHAPE,
driveId: z
.string()
.optional()
.describe("Graph drive ID of the drive to mount. Set at most one of `driveId`, `siteId`, `groupId` and `userId`; with none the mount uses the signed-in user's drive."),
siteId: z
.string()
.optional()
.describe('Graph site ID whose default document library the mount uses.'),
groupId: z
.string()
.optional()
.describe('Microsoft 365 or Teams group ID whose document library the mount uses.'),
userId: z
.string()
.optional()
.describe('User ID or UPN whose drive the mount uses, under app-only auth.'),
keyPrefix: z
.string()
.optional()
.describe('Folder path from the drive root that the mount uses as its root.'),
})
// With four fields and a fixed precedence, setting two would make the
// mount silently address whichever won, which is the kind of
// misconfiguration that only shows up as a confusing 404.
.superRefine((c, ctx) => {
const named = DRIVE_TARGETS.filter((f) => c[f] !== undefined);
if (named.length > 1)
ctx.addIssue({ code: 'custom', message: driveTargetError(named) });
});
export function resolveOneDriveConfig(config) {
const graph = resolveMsGraphConfig(config);
const resolved = {
...graph,
driveId: optionalText(config.driveId),
siteId: optionalText(config.siteId),
groupId: optionalText(config.groupId),
userId: optionalText(config.userId),
keyPrefix: stripSlash(config.keyPrefix ?? ''),
};
// Checked here and not only in the schema: a config built in code never
// goes through the schema, and that is the path the accessor takes.
const named = DRIVE_TARGETS.filter((f) => resolved[f] !== null);
if (named.length > 1)
throw new Error(driveTargetError(named));
return resolved;
}
export class OneDriveAccessor extends Accessor {
config;
// The drive's Graph `driveType` (personal, business or documentLibrary),
// asked once and kept: it decides whether the `/delta` feed can start below
// the drive root.
driveType = null;
constructor(config) {
super();
this.config = resolveOneDriveConfig(config);
}
}
//# sourceMappingURL=onedrive.js.map