Download packages/agent/src/harness/tools/path-utils.ts from SaylorTwift/pi: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/SaylorTwift/pi/resolve/main/packages/agent/src/harness/tools/path-utils.ts
- Command line
-
hf download hf://SaylorTwift/pi/packages/agent/src/harness/tools/path-utils.ts
-
curl -L -o path-utils.ts https://huggingface.co/SaylorTwift/pi/resolve/main/packages/agent/src/harness/tools/path-utils.ts
1.15 kB
| import type { Context } from "../context.ts"; | |
| import type { ExecutionEnv } from "../types.ts"; | |
| import { getOrThrow } from "../types.ts"; | |
| const UNICODE_SPACES = /[\u00A0\u2000-\u200A\u202F\u205F\u3000]/g; | |
| const NARROW_NO_BREAK_SPACE = "\u202F"; | |
| function normalizeToolPath(path: string): string { | |
| const normalized = path.replace(UNICODE_SPACES, " "); | |
| return normalized.startsWith("@") ? normalized.slice(1) : normalized; | |
| } | |
| export async function resolveToolPath(env: ExecutionEnv, path: string, context: Context): Promise<string> { | |
| return getOrThrow(await env.absolutePath(normalizeToolPath(path), context)); | |
| } | |
| export async function resolveReadToolPath(env: ExecutionEnv, path: string, context: Context): Promise<string> { | |
| const resolved = await resolveToolPath(env, path, context); | |
| const variants = [ | |
| resolved, | |
| resolved.replace(/ (AM|PM)\./gi, `${NARROW_NO_BREAK_SPACE}$1.`), | |
| resolved.normalize("NFD"), | |
| resolved.replace(/'/g, "\u2019"), | |
| resolved.normalize("NFD").replace(/'/g, "\u2019"), | |
| ]; | |
| for (const variant of new Set(variants)) { | |
| if (getOrThrow(await env.exists(variant, context))) return variant; | |
| } | |
| return resolved; | |
| } | |