UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

56 lines • 2.31 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 { command } from "../../config.js"; import { LanguageRuntime } from "../../../runtime/language.js"; import { scriptOperand } from "../../../runtime/source.js"; import { specOf } from "../../spec/builtins.js"; import { FlagView } from "../../spec/flag_view.js"; import { execRefusal, notBound, runInterpreter, runtimeVersion } from "./interpreter.js"; function js(_accessor, paths, texts, ctx) { const named = ctx.spec?.name ?? ''; const label = named === '' ? 'js' : named; const runtime = ctx.runtime?.bound; if (!(runtime instanceof LanguageRuntime)) return notBound(label); const fl = new FlagView(ctx.flags, specOf('js')); if (fl.asBool('version')) { return runtimeVersion(label, runtime, ctx.env ?? {}, ctx.signal, ctx.timeoutSeconds); } const switches = {}; const payload = fl.asStr('e'); if (payload !== undefined) switches.c = payload; const script = scriptOperand(paths, texts, switches, ctx.cwd); const refusal = execRefusal(label, script, ctx.runtime); if (refusal !== null) return refusal; // A .mjs script is a module whatever the flag said. switches.module = fl.asBool('module') || (script?.virtual.endsWith('.mjs') ?? false); return runInterpreter(label, runtime, paths, texts, { ...ctx, flags: switches }, script); } export const GENERAL_JS = command({ name: 'js', vfs: null, spec: specOf('js'), write: true, fn: js, }); export const node = command({ name: 'node', vfs: null, spec: specOf('node'), write: true, fn: js, }); //# sourceMappingURL=js.js.map