@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
85 lines • 2.19 kB
JavaScript
export function hasBackslashPathSeparator(path) {
return path.trim().includes('\\');
}
export function hasParentPathSegment(path) {
return path
.trim()
.split('/')
.some((segment) => segment === '..');
}
export function hasEscapingParentPathSegment(path) {
let depth = 0;
for (const segment of path.trim().split('/')) {
if (!segment || segment === '.') {
continue;
}
if (segment !== '..') {
depth += 1;
continue;
}
if (depth === 0) {
return true;
}
depth -= 1;
}
return false;
}
export function normalizePosixPath(path) {
const trimmed = path.trim();
const isAbsolute = trimmed.startsWith('/');
const segments = [];
for (const segment of trimmed.split('/')) {
if (!segment || segment === '.') {
continue;
}
if (segment === '..') {
if (segments.length > 0) {
segments.pop();
}
continue;
}
segments.push(segment);
}
const normalized = segments.join('/');
if (isAbsolute) {
return normalized ? `/${normalized}` : '/';
}
return normalized || '.';
}
export function posixDirname(path) {
if (path === '/') {
return '/';
}
let end = path.length;
while (end > 0 && path[end - 1] === '/') {
end -= 1;
}
const normalized = path.slice(0, end);
if (!normalized || normalized === '/') {
return '.';
}
const index = normalized.lastIndexOf('/');
if (index < 0) {
return '.';
}
return index === 0 ? '/' : normalized.slice(0, index);
}
export function isUnderPosixPath(path, root) {
if (root === '/') {
return path.startsWith('/');
}
return path === root || path.startsWith(`${root}/`);
}
export function relativePosixPathWithinRoot(root, path) {
if (!isUnderPosixPath(path, root)) {
return null;
}
if (path === root) {
return '';
}
if (root === '/') {
return path.slice(1);
}
return path.slice(root.length + 1);
}
//# sourceMappingURL=posixPath.mjs.map