ScuttleBot

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

Keyboard Shortcuts

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