UNPKG

auto-gpt-ts

Version:

my take of Auto-GPT in typescript

72 lines 3.33 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Workspace = void 0; const path = __importStar(require("path")); const logging_1 = require("../logging"); class Workspace extends logging_1.Loggable { constructor(workspaceRoot, restrictToWorkspace) { super(); this._root = Workspace._sanitizePath(workspaceRoot.toString()); this._restrictToWorkspace = restrictToWorkspace; } get root() { return this._root; } get restrictToWorkspace() { return this._restrictToWorkspace; } static makeWorkspace(workspaceDirectory, ...args) { workspaceDirectory = this._sanitizePath(workspaceDirectory.toString()); const workspacePath = path.resolve(workspaceDirectory.toString(), ...args); return workspacePath; } getPath(relativePath) { const fullpath = Workspace._sanitizePath(relativePath.toString(), this.root, this.restrictToWorkspace); return fullpath; } static _sanitizePath(relativePath, root = null, restrictToRoot = true) { for (const nullByte of Workspace.NULL_BYTES) { if (relativePath.includes(nullByte) || (root && root.includes(nullByte))) { throw new Error("embedded null byte"); } } let resolvedRoot = root ? path.resolve(root) : undefined; let resolvedPath = path.resolve(relativePath); if (resolvedRoot && path.isAbsolute(resolvedPath)) { return path.join(resolvedRoot, relativePath); // throw new Error(`Attempted to access absolute path '${resolvedPath}' in workspace '${resolvedRoot}'.`); } let fullPath = path.resolve(resolvedRoot !== null && resolvedRoot !== void 0 ? resolvedRoot : "", resolvedPath); if (restrictToRoot && !fullPath.startsWith(resolvedRoot !== null && resolvedRoot !== void 0 ? resolvedRoot : "")) { return path.join(resolvedRoot, relativePath); // throw new Error(`Attempted to access path '${fullPath}' outside of workspace '${resolvedRoot}'.`); } return fullPath; } } Workspace.NULL_BYTES = ["\u0000", "%00"]; //["\0", "u\000", "\x00", "\z", "\u0000", "%00"]; TODO: fix this exports.Workspace = Workspace; //# sourceMappingURL=workspace.js.map