ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / agents / agentParser.js
Source Blame History 89 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __create = Object.create;
f7eb47b… lmata 3 var __defProp = Object.defineProperty;
f7eb47b… lmata 4 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 5 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 6 var __getProtoOf = Object.getPrototypeOf;
f7eb47b… lmata 7 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 8 var __export = (target, all) => {
f7eb47b… lmata 9 for (var name in all)
f7eb47b… lmata 10 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 11 };
f7eb47b… lmata 12 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 13 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 14 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 15 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 16 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 17 }
f7eb47b… lmata 18 return to;
f7eb47b… lmata 19 };
f7eb47b… lmata 20 var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
f7eb47b… lmata 21 // If the importer is in node compatibility mode or this is not an ESM
f7eb47b… lmata 22 // file that has been converted to a CommonJS file using a Babel-
f7eb47b… lmata 23 // compatible transform (i.e. "__esModule" has not been set), then set
f7eb47b… lmata 24 // "default" to the CommonJS "module.exports" for node compatibility.
f7eb47b… lmata 25 isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
f7eb47b… lmata 26 mod
f7eb47b… lmata 27 ));
f7eb47b… lmata 28 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 29 var agentParser_exports = {};
f7eb47b… lmata 30 __export(agentParser_exports, {
f7eb47b… lmata 31 parseAgentSpec: () => parseAgentSpec
f7eb47b… lmata 32 });
f7eb47b… lmata 33 module.exports = __toCommonJS(agentParser_exports);
f7eb47b… lmata 34 var import_fs = __toESM(require("fs"));
f7eb47b… lmata 35 var import_utilsBundle = require("playwright-core/lib/utilsBundle");
f7eb47b… lmata 36 async function parseAgentSpec(filePath) {
f7eb47b… lmata 37 const source = await import_fs.default.promises.readFile(filePath, "utf-8");
f7eb47b… lmata 38 const { header, content } = extractYamlAndContent(source);
f7eb47b… lmata 39 const { instructions, examples } = extractInstructionsAndExamples(content);
f7eb47b… lmata 40 return {
f7eb47b… lmata 41 ...header,
f7eb47b… lmata 42 instructions,
f7eb47b… lmata 43 examples
f7eb47b… lmata 44 };
f7eb47b… lmata 45 }
f7eb47b… lmata 46 function extractYamlAndContent(markdown) {
f7eb47b… lmata 47 const lines = markdown.split("\n");
f7eb47b… lmata 48 if (lines[0] !== "---")
f7eb47b… lmata 49 throw new Error("Markdown file must start with YAML front matter (---)");
f7eb47b… lmata 50 let yamlEndIndex = -1;
f7eb47b… lmata 51 for (let i = 1; i < lines.length; i++) {
f7eb47b… lmata 52 if (lines[i] === "---") {
f7eb47b… lmata 53 yamlEndIndex = i;
f7eb47b… lmata 54 break;
f7eb47b… lmata 55 }
f7eb47b… lmata 56 }
f7eb47b… lmata 57 if (yamlEndIndex === -1)
f7eb47b… lmata 58 throw new Error("YAML front matter must be closed with ---");
f7eb47b… lmata 59 const yamlLines = lines.slice(1, yamlEndIndex);
f7eb47b… lmata 60 const yamlRaw = yamlLines.join("\n");
f7eb47b… lmata 61 const contentLines = lines.slice(yamlEndIndex + 1);
f7eb47b… lmata 62 const content = contentLines.join("\n");
f7eb47b… lmata 63 let header;
f7eb47b… lmata 64 try {
f7eb47b… lmata 65 header = import_utilsBundle.yaml.parse(yamlRaw);
f7eb47b… lmata 66 } catch (error) {
f7eb47b… lmata 67 throw new Error(`Failed to parse YAML header: ${error.message}`);
f7eb47b… lmata 68 }
f7eb47b… lmata 69 if (!header.name)
f7eb47b… lmata 70 throw new Error('YAML header must contain a "name" field');
f7eb47b… lmata 71 if (!header.description)
f7eb47b… lmata 72 throw new Error('YAML header must contain a "description" field');
f7eb47b… lmata 73 return { header, content };
f7eb47b… lmata 74 }
f7eb47b… lmata 75 function extractInstructionsAndExamples(content) {
f7eb47b… lmata 76 const examples = [];
f7eb47b… lmata 77 const instructions = content.split("<example>")[0].trim();
f7eb47b… lmata 78 const exampleRegex = /<example>([\s\S]*?)<\/example>/g;
f7eb47b… lmata 79 let match;
f7eb47b… lmata 80 while ((match = exampleRegex.exec(content)) !== null) {
f7eb47b… lmata 81 const example = match[1].trim();
f7eb47b… lmata 82 examples.push(example.replace(/[\n]/g, " ").replace(/ +/g, " "));
f7eb47b… lmata 83 }
f7eb47b… lmata 84 return { instructions, examples };
f7eb47b… lmata 85 }
f7eb47b… lmata 86 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 87 0 && (module.exports = {
f7eb47b… lmata 88 parseAgentSpec
f7eb47b… lmata 89 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button