@graphai/puppeteer_agent 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,4 @@
1
+ import type { AgentFunction, AgentFunctionInfo } from "graphai";
2
+ export declare const puppeteerAgent: AgentFunction;
3
+ declare const puppeteerAgentInfo: AgentFunctionInfo;
4
+ export default puppeteerAgentInfo;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.puppeteerAgent = void 0;
7
+ const puppeteer_1 = __importDefault(require("puppeteer"));
8
+ const readability_1 = require("@mozilla/readability");
9
+ const jsdom_1 = require("jsdom");
10
+ const puppeteerAgent = async ({ namedInputs, params }) => {
11
+ const { url } = namedInputs;
12
+ try {
13
+ const browser = await puppeteer_1.default.launch();
14
+ const page = await browser.newPage();
15
+ //console.log(1);
16
+ await page.goto(url, { waitUntil: "networkidle2" });
17
+ // console.log(2);
18
+ const html = await page.content();
19
+ const dom = new jsdom_1.JSDOM(html, { url: page.url() });
20
+ const reader = new readability_1.Readability(dom.window.document);
21
+ const article = reader.parse();
22
+ // console.log(3);
23
+ await browser.close();
24
+ return {
25
+ title: article?.title,
26
+ content: (article?.title ?? "") +
27
+ "\n" +
28
+ (article?.textContent ?? "")
29
+ .replace(/\r\n/g, "\n")
30
+ .replace(/(\n[ \t]*){2,}/g, "\n")
31
+ .trim(),
32
+ };
33
+ }
34
+ catch (error) {
35
+ if (params.supressError) {
36
+ return {
37
+ onError: {
38
+ message: "puppeteerAgent error",
39
+ error,
40
+ },
41
+ };
42
+ }
43
+ throw new Error(`puppeteerAgent error: ${error}`);
44
+ }
45
+ };
46
+ exports.puppeteerAgent = puppeteerAgent;
47
+ const puppeteerAgentInfo = {
48
+ name: "puppeteerAgent",
49
+ agent: exports.puppeteerAgent,
50
+ mock: exports.puppeteerAgent,
51
+ samples: [
52
+ {
53
+ params: {},
54
+ inputs: {},
55
+ result: {},
56
+ },
57
+ ],
58
+ tools: [
59
+ {
60
+ type: "function",
61
+ function: {
62
+ name: "puppeteerAgent--openUrl",
63
+ description: "open web url",
64
+ parameters: {
65
+ type: "object",
66
+ properties: {
67
+ url: {
68
+ type: "string",
69
+ description: "web site url",
70
+ },
71
+ },
72
+ required: ["url"],
73
+ },
74
+ },
75
+ },
76
+ ],
77
+ description: "Puppeteer Agent",
78
+ category: ["net"],
79
+ repository: "https://github.com/receptron/mulmocast-app",
80
+ author: "Receptron team",
81
+ license: "MIT",
82
+ };
83
+ exports.default = puppeteerAgentInfo;
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@graphai/puppeteer_agent",
3
+ "version": "0.0.1",
4
+ "description": "",
5
+ "main": "lib/index.js",
6
+ "files": [
7
+ "./lib"
8
+ ],
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "eslint": "eslint src --fix",
12
+ "format": "prettier --write '{src,tests}/**/*.ts'",
13
+ "doc": "npx agentdoc",
14
+ "test_run": "node --test --require ts-node/register ./tests/run_*.ts",
15
+ "test": "echo nothing",
16
+ "ci": "yarn run format && yarn run eslint && yarn run test && yarn run build"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/receptron/graphai-agents.git"
21
+ },
22
+ "author": "",
23
+ "license": "MIT",
24
+ "bugs": {
25
+ "url": "https://github.com/receptron/graphai-agents/issues"
26
+ },
27
+ "homepage": "https://github.com/receptron/graphai-agents#readme",
28
+ "devDependencies": {
29
+ "@types/jsdom": "^21.1.7"
30
+ },
31
+ "dependencies": {
32
+ "@mozilla/readability": "^0.6.0",
33
+ "jsdom": "^26.1.0",
34
+ "puppeteer": "^24.16.1"
35
+ },
36
+ "types": "./lib/index.d.ts",
37
+ "directories": {
38
+ "lib": "lib"
39
+ }
40
+ }