UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

45 lines 2.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PAGE_AI_CACHE_FILE_EXTENSION = exports.PAGE_AI_CACHE_DIRNAME = void 0; exports.buildPageAiCachePath = buildPageAiCachePath; exports.extractCacheKeyHostname = extractCacheKeyHostname; exports.relativePageAiCachePathForSource = relativePageAiCachePathForSource; const node_path_1 = __importDefault(require("node:path")); exports.PAGE_AI_CACHE_DIRNAME = '.cache-lock'; exports.PAGE_AI_CACHE_FILE_EXTENSION = '.cache.js'; /** * Computes the cache file path for a given source file that calls `page.ai`. * Cache files live under a shared `.cache-lock` directory next to the source. */ function buildPageAiCachePath(sourceFilepath) { const cacheDir = node_path_1.default.join(node_path_1.default.dirname(sourceFilepath), exports.PAGE_AI_CACHE_DIRNAME); const cacheFilename = `${node_path_1.default.basename(sourceFilepath)}${exports.PAGE_AI_CACHE_FILE_EXTENSION}`; return node_path_1.default.join(cacheDir, cacheFilename); } /** * Extracts the hostname from a URL string for use as the URL component of a * page.ai cache key. Both `page.ai.act` and `page.ai.assert` use this so that * their URL-keying strategy stays in sync. * * @example * extractCacheKeyHostname('https://localhost:3000/flows/123') // → 'localhost' * extractCacheKeyHostname('https://app.vercel.app/settings') // → 'app.vercel.app' */ function extractCacheKeyHostname(url) { try { return new URL(url).hostname; } catch { return url; } } /** * Returns the cache file path relative to the directory containing the source file. */ function relativePageAiCachePathForSource(sourceFilepath) { return node_path_1.default.join(exports.PAGE_AI_CACHE_DIRNAME, `${node_path_1.default.basename(sourceFilepath)}${exports.PAGE_AI_CACHE_FILE_EXTENSION}`); } //# sourceMappingURL=cacheLocator.js.map