UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

45 lines • 1.97 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 { CallStack } from "../../../../shell/call_stack.js"; import { ExitSignal } from "../../../../shell/errors.js"; import { ExecutionNode } from "../../../types.js"; /** * Run the words as a line of the caller's own: in its frame, so `$1`, * `local`, `shift` and `return` act on the function the caller is in, and * a `break`, `continue` or `exit` on its loops and shell. Mirrors Python's * handle_eval. */ export async function handleEval(executeFn, args, session, stdin = null, sink, callStack = new CallStack(session.shellNesting)) { const script = args.join(' '); let io; try { io = await callStack.nested('eval', () => executeFn(script, { sessionId: session.sessionId, stdin, callStack, ...(sink === undefined ? {} : { sink }), })); } catch (err) { if (err instanceof ExitSignal) err.sourced = true; throw err; } return [io.stdout, io, new ExecutionNode({ command: 'eval', exitCode: io.exitCode })]; } /** The `eval` arm. */ export async function evalBuiltin(call) { return handleEval(call.executeFn, [...call.argv.args], call.context.session, call.stdin, call.sink, call.callStack ?? undefined); } //# sourceMappingURL=eval.js.map