@xapp/arachne-web-service 1.33.0 → 1.34.0
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.
- package/lib/ArachneWebService.d.ts +36 -0
- package/lib/ArachneWebService.js +56 -9
- package/lib/ArachneWebService.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/llm/LLMProvider.d.ts +6 -2
- package/lib/llm/LLMProvider.js +5 -4
- package/lib/llm/LLMProvider.js.map +1 -1
- package/lib/services/ServiceExtractor.d.ts +180 -0
- package/lib/services/ServiceExtractor.js +474 -0
- package/lib/services/ServiceExtractor.js.map +1 -0
- package/lib/services/readServicePages.d.ts +37 -0
- package/lib/services/readServicePages.js +58 -0
- package/lib/services/readServicePages.js.map +1 -0
- package/lib/services/selectServicePages.d.ts +34 -0
- package/lib/services/selectServicePages.js +177 -0
- package/lib/services/selectServicePages.js.map +1 -0
- package/lib/taxonomy/ServiceTaxonomy.d.ts +5 -2
- package/lib/taxonomy/ServiceTaxonomy.js +10 -7
- package/lib/taxonomy/ServiceTaxonomy.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.DEFAULT_MAX_SERVICE_PAGES = void 0;
|
|
37
|
+
exports.selectServicePages = selectServicePages;
|
|
38
|
+
/*! Copyright (c) 2026, XAPP AI */
|
|
39
|
+
const cheerio = __importStar(require("cheerio"));
|
|
40
|
+
const subpageDetection_1 = require("../utils/subpageDetection");
|
|
41
|
+
exports.DEFAULT_MAX_SERVICE_PAGES = 12;
|
|
42
|
+
const KIND_ORDER = ["homepage", "service", "about", "area", "brand"];
|
|
43
|
+
const FILE = /\.(pdf|jpe?g|png|gif|svg|webp|docx?|xlsx?|zip|mp3|mp4|mov)$/i;
|
|
44
|
+
const SKIP = /\/(\d{4})\/|(^|[/_-])(blog|news|articles?|posts?|tags?|category|author|feed|wp-|privacy|terms|legal|accessibility|sitemap|login|account|cart|checkout|contact|reviews?|testimonials|gallery|coupons?|specials|promotions?)([/_-]|$)/i;
|
|
45
|
+
const AREA = /service[\s_-]?areas?|areas?[\s_-]we[\s_-]serve|locations?|cities|communities|counties|where[\s_-]we[\s_-]work|serving[\s_-]/i;
|
|
46
|
+
const BRAND = /brands?|manufacturers?|products|equipment|dealer/i;
|
|
47
|
+
const ABOUT = /about|our[\s_-]story|who[\s_-]we[\s_-]are|faqs?\b|frequently|why[\s_-]|financing|warrant|guarantee|careers|join[\s_-]our/i;
|
|
48
|
+
const SERVICE = /services?|what[\s_-]we[\s_-]do|repair|install|replac|maintenance|clean|remodel|inspection|hvac|heating|cooling|air[\s_-]condition|\bac\b|furnace|heat[\s_-]pump|boiler|duct|plumb|drain|sewer|water[\s_-]heater|tankless|leak|pipe|toilet|faucet|electric|panel|wiring|generator|ev[\s_-]charg|lighting|roof|gutter|siding|window|door|insulation|solar|pest|termite|lawn|landscap|tree|irrigation|sprinkler|pool|garage|fence|deck|concrete|paving|masonry|chimney|paint|floor|carpet|tile|kitchen|bath|handyman|appliance|mold|water[\s_-]damage|restoration|septic|well[\s_-]pump|pressure[\s_-]wash|junk|moving|locksmith|foundation|waterproof|drywall|cabinet|countertop/i;
|
|
49
|
+
function siteKey(url) {
|
|
50
|
+
return `${url.hostname.toLowerCase().replace(/^www\./, "")}${url.pathname.replace(/\/+$/, "")}${url.search}`;
|
|
51
|
+
}
|
|
52
|
+
function classify(pathname, text) {
|
|
53
|
+
if (FILE.test(pathname) || SKIP.test(pathname)) {
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
let path = pathname;
|
|
57
|
+
try {
|
|
58
|
+
path = decodeURIComponent(pathname);
|
|
59
|
+
}
|
|
60
|
+
catch (_a) {
|
|
61
|
+
// keep it encoded
|
|
62
|
+
}
|
|
63
|
+
const subject = `${path} ${text}`;
|
|
64
|
+
if (AREA.test(subject)) {
|
|
65
|
+
return "area";
|
|
66
|
+
}
|
|
67
|
+
if (BRAND.test(subject)) {
|
|
68
|
+
return "brand";
|
|
69
|
+
}
|
|
70
|
+
if (ABOUT.test(subject)) {
|
|
71
|
+
return "about";
|
|
72
|
+
}
|
|
73
|
+
if (SERVICE.test(subject)) {
|
|
74
|
+
return "service";
|
|
75
|
+
}
|
|
76
|
+
return undefined;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Breadth over depth: shallower pages first, and within a depth one page per parent section before any section's
|
|
80
|
+
* second page.
|
|
81
|
+
*/
|
|
82
|
+
function breadthFirst(urls) {
|
|
83
|
+
var _a, _b;
|
|
84
|
+
const byDepth = new Map();
|
|
85
|
+
for (const url of urls) {
|
|
86
|
+
const segments = new URL(url).pathname.split("/").filter(Boolean);
|
|
87
|
+
const parent = segments.slice(0, -1).join("/");
|
|
88
|
+
const sections = (_a = byDepth.get(segments.length)) !== null && _a !== void 0 ? _a : new Map();
|
|
89
|
+
sections.set(parent, [...((_b = sections.get(parent)) !== null && _b !== void 0 ? _b : []), url]);
|
|
90
|
+
byDepth.set(segments.length, sections);
|
|
91
|
+
}
|
|
92
|
+
const ordered = [];
|
|
93
|
+
for (const d of [...byDepth.keys()].sort((a, b) => a - b)) {
|
|
94
|
+
const queues = [...byDepth.get(d).values()];
|
|
95
|
+
while (queues.some((q) => q.length > 0)) {
|
|
96
|
+
for (const queue of queues) {
|
|
97
|
+
const next = queue.shift();
|
|
98
|
+
if (next) {
|
|
99
|
+
ordered.push(next);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return ordered;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Picks the same-site pages worth reading for the services a business offers.
|
|
108
|
+
*
|
|
109
|
+
* The homepage comes first and counts against `maxPages`. When there are more candidates than room, one about,
|
|
110
|
+
* one service-area and one brand page are kept (while services keep at least half the room) and the rest goes to
|
|
111
|
+
* service pages, breadth first.
|
|
112
|
+
*
|
|
113
|
+
* @param html The homepage HTML
|
|
114
|
+
* @param homepageUrl The homepage URL, also the base for relative links
|
|
115
|
+
*/
|
|
116
|
+
function selectServicePages(html, homepageUrl, options = {}) {
|
|
117
|
+
var _a, _b, _c;
|
|
118
|
+
const maxPages = Math.max(1, (_a = options.maxPages) !== null && _a !== void 0 ? _a : exports.DEFAULT_MAX_SERVICE_PAGES);
|
|
119
|
+
const home = new URL(homepageUrl);
|
|
120
|
+
const seen = new Set([siteKey(home)]);
|
|
121
|
+
const candidates = {
|
|
122
|
+
service: [],
|
|
123
|
+
about: [],
|
|
124
|
+
area: [],
|
|
125
|
+
brand: [],
|
|
126
|
+
};
|
|
127
|
+
const consider = (href, text, forced) => {
|
|
128
|
+
if (!href || /^(mailto|tel|javascript):/i.test(href)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
let url;
|
|
132
|
+
try {
|
|
133
|
+
url = new URL(href, home);
|
|
134
|
+
}
|
|
135
|
+
catch (_a) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
url.hash = "";
|
|
139
|
+
if (!(0, subpageDetection_1.isSameSite)(url.toString(), homepageUrl)) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const key = siteKey(url);
|
|
143
|
+
if (seen.has(key)) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const kind = forced !== null && forced !== void 0 ? forced : classify(url.pathname, text);
|
|
147
|
+
if (!kind || kind === "homepage") {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
seen.add(key);
|
|
151
|
+
candidates[kind].push(url.toString());
|
|
152
|
+
};
|
|
153
|
+
const $ = cheerio.load(html);
|
|
154
|
+
$("a[href]").each((_, el) => {
|
|
155
|
+
consider($(el).attr("href"), $(el).text().replace(/\s+/g, " ").trim());
|
|
156
|
+
});
|
|
157
|
+
consider((_b = options.known) === null || _b === void 0 ? void 0 : _b.aboutUs, "", "about");
|
|
158
|
+
consider((_c = options.known) === null || _c === void 0 ? void 0 : _c.faqPage, "", "about");
|
|
159
|
+
candidates.service = breadthFirst(candidates.service);
|
|
160
|
+
const budget = maxPages - 1;
|
|
161
|
+
const picked = [];
|
|
162
|
+
const take = (kind, count) => {
|
|
163
|
+
for (const url of candidates[kind].splice(0, Math.max(0, Math.min(count, budget - picked.length)))) {
|
|
164
|
+
picked.push({ url, kind });
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const reserved = ["about", "area", "brand"]
|
|
168
|
+
.filter((kind) => candidates[kind].length > 0)
|
|
169
|
+
.slice(0, Math.floor(budget / 2));
|
|
170
|
+
take("service", budget - reserved.length);
|
|
171
|
+
reserved.forEach((kind) => take(kind, 1));
|
|
172
|
+
take("service", budget);
|
|
173
|
+
["about", "area", "brand"].forEach((kind) => take(kind, budget));
|
|
174
|
+
picked.sort((a, b) => KIND_ORDER.indexOf(a.kind) - KIND_ORDER.indexOf(b.kind));
|
|
175
|
+
return [{ url: homepageUrl, kind: "homepage" }, ...picked];
|
|
176
|
+
}
|
|
177
|
+
//# sourceMappingURL=selectServicePages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectServicePages.js","sourceRoot":"","sources":["../../src/services/selectServicePages.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoHA,gDAqEC;AAzLD,kCAAkC;AAClC,iDAAmC;AAEnC,gEAAuD;AAwB1C,QAAA,yBAAyB,GAAG,EAAE,CAAC;AAE5C,MAAM,UAAU,GAAsB,CAAC,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAExF,MAAM,IAAI,GAAG,8DAA8D,CAAC;AAE5E,MAAM,IAAI,GACN,sOAAsO,CAAC;AAE3O,MAAM,IAAI,GACN,8HAA8H,CAAC;AAEnI,MAAM,KAAK,GAAG,mDAAmD,CAAC;AAElE,MAAM,KAAK,GACP,2HAA2H,CAAC;AAEhI,MAAM,OAAO,GACT,ipBAAipB,CAAC;AAEtpB,SAAS,OAAO,CAAC,GAAQ;IACrB,OAAO,GAAG,GAAG,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,O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,EAAE,CAAC,CAAC;QAC/B,CAAC;IACL,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAW;SACjD,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;SAC7C,KAAK,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IACtC,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1C,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IACvB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAW,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAE5E,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;IAE/E,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,GAAG,MAAM,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -103,13 +103,16 @@ export declare const SERVICE_TAXONOMY_V1: Taxonomy;
|
|
|
103
103
|
* Lookups over a taxonomy: canonical slugs, aliases and the family a job is scored in.
|
|
104
104
|
*/
|
|
105
105
|
export declare class ServiceTaxonomy {
|
|
106
|
-
|
|
106
|
+
readonly definition: Taxonomy;
|
|
107
107
|
readonly version: string;
|
|
108
108
|
readonly jobs: TaxonomyJobEntry[];
|
|
109
109
|
private readonly bySlug;
|
|
110
110
|
private readonly families;
|
|
111
111
|
private readonly trades;
|
|
112
|
-
|
|
112
|
+
/**
|
|
113
|
+
* @param definition The taxonomy JSON, Service Taxonomy v1 by default
|
|
114
|
+
*/
|
|
115
|
+
constructor(definition?: Taxonomy);
|
|
113
116
|
job(slug: string): TaxonomyJobEntry | undefined;
|
|
114
117
|
isFamily(slug: string): boolean;
|
|
115
118
|
isTrade(slug: string): boolean;
|
|
@@ -14,14 +14,17 @@ exports.SERVICE_TAXONOMY_V1 = v1_json_1.default;
|
|
|
14
14
|
* Lookups over a taxonomy: canonical slugs, aliases and the family a job is scored in.
|
|
15
15
|
*/
|
|
16
16
|
class ServiceTaxonomy {
|
|
17
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @param definition The taxonomy JSON, Service Taxonomy v1 by default
|
|
19
|
+
*/
|
|
20
|
+
constructor(definition = exports.SERVICE_TAXONOMY_V1) {
|
|
18
21
|
var _a, _b;
|
|
19
|
-
this.
|
|
20
|
-
this.version =
|
|
22
|
+
this.definition = definition;
|
|
23
|
+
this.version = definition.version;
|
|
21
24
|
this.jobs = [];
|
|
22
25
|
this.families = new Set();
|
|
23
26
|
this.trades = new Set();
|
|
24
|
-
for (const trade of
|
|
27
|
+
for (const trade of definition.trades) {
|
|
25
28
|
this.trades.add(trade.slug);
|
|
26
29
|
for (const job of (_a = trade.jobs) !== null && _a !== void 0 ? _a : []) {
|
|
27
30
|
this.jobs.push(Object.assign(Object.assign({}, job), { trade: trade.slug }));
|
|
@@ -63,11 +66,11 @@ class ServiceTaxonomy {
|
|
|
63
66
|
if (!candidate) {
|
|
64
67
|
return undefined;
|
|
65
68
|
}
|
|
66
|
-
candidate = (_a = this.
|
|
69
|
+
candidate = (_a = this.definition.aliases[candidate]) !== null && _a !== void 0 ? _a : candidate;
|
|
67
70
|
if (!this.bySlug.has(candidate)) {
|
|
68
|
-
const prefix = Object.keys(this.
|
|
71
|
+
const prefix = Object.keys(this.definition.alias_prefixes).find((p) => candidate.startsWith(p));
|
|
69
72
|
if (prefix) {
|
|
70
|
-
candidate = this.
|
|
73
|
+
candidate = this.definition.alias_prefixes[prefix] + candidate.slice(prefix.length);
|
|
71
74
|
}
|
|
72
75
|
}
|
|
73
76
|
// Follow deprecations, guarding against a cycle
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ServiceTaxonomy.js","sourceRoot":"","sources":["../../src/taxonomy/ServiceTaxonomy.ts"],"names":[],"mappings":";;;;;;AAAA,kCAAkC;AAClC,wDAA2B;AAyG3B;;GAEG;AACU,QAAA,mBAAmB,GAAa,iBAAE,CAAC;AAEhD;;GAEG;AACH,MAAa,eAAe;IAWxB,
|
|
1
|
+
{"version":3,"file":"ServiceTaxonomy.js","sourceRoot":"","sources":["../../src/taxonomy/ServiceTaxonomy.ts"],"names":[],"mappings":";;;;;;AAAA,kCAAkC;AAClC,wDAA2B;AAyG3B;;GAEG;AACU,QAAA,mBAAmB,GAAa,iBAAE,CAAC;AAEhD;;GAEG;AACH,MAAa,eAAe;IAWxB;;OAEG;IACH,YAAqB,aAAuB,2BAAmB;;QAA1C,eAAU,GAAV,UAAU,CAAgC;QAC3D,IAAI,CAAC,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;QACf,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;QAC1B,IAAI,CAAC,MAAM,GAAG,IAAI,GAAG,EAAE,CAAC;QAExB,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;YACpC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC5B,KAAK,MAAM,GAAG,IAAI,MAAA,KAAK,CAAC,IAAI,mCAAI,EAAE,EAAE,CAAC;gBACjC,IAAI,CAAC,IAAI,CAAC,IAAI,iCAAM,GAAG,KAA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