@xiaoso/dsh-tool-plus 0.1.0-beta.5 → 0.1.0-beta.6
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/README.en.md +1 -1
- package/README.md +2 -2
- package/THIRD_PARTY_NOTICES.md +42 -42
- package/lib/{abort-dIkZBV7Q.mjs → abort-CsjZitYv.mjs} +1 -1
- package/lib/{amazon-bedrock-WQhvjHYu.mjs → amazon-bedrock-CfNIDi5k.mjs} +7 -7
- package/lib/{anthropic-CJCauvYz.mjs → anthropic-BVfZdnMp.mjs} +12 -12
- package/lib/{anthropic-tTntD8BD.mjs → anthropic-DGXmmg43.mjs} +2 -2
- package/lib/{api-key-login-BzqNdM2y.mjs → api-key-login-BikQAfD-.mjs} +1 -1
- package/lib/{aws-credentials-CXryMobh.mjs → aws-credentials-DrssNMn_.mjs} +4 -4
- package/lib/{azure-openai-responses-DuukbD0F.mjs → azure-openai-responses-C-5q-5K2.mjs} +8 -8
- package/lib/browser-render-z6b8Ljo9.mjs +183 -0
- package/lib/{bundled-references-Cavaffah.mjs → bundled-references-D71z7_T3.mjs} +2 -2
- package/lib/{callback-server-CQ5Jo8F-.mjs → callback-server-Di6C4RqI.mjs} +1 -1
- package/lib/client.js +327 -4
- package/lib/{cursor-B6TUEmgP.mjs → cursor-CQQtygwl.mjs} +1 -1
- package/lib/{cursor-DkSX2h3H.mjs → cursor-DXJxwdcg.mjs} +7 -7
- package/lib/{cursor-aJrXeYCb.mjs → cursor-Hr5Zw1gt.mjs} +3 -3
- package/lib/{device-code-DBo3B5nh.mjs → device-code-wZUbgPdB.mjs} +1 -1
- package/lib/{devin-BHZZyMhO.mjs → devin-CF6UhCFw.mjs} +2 -2
- package/lib/{devin-BK7DHeca.mjs → devin-DXJoDlW2.mjs} +1 -1
- package/lib/{devin-vNZTNUON.mjs → devin-P37gURs_.mjs} +5 -5
- package/lib/{dom-DGdYAVTv.mjs → dom-CawWi8fa.mjs} +14 -1
- package/lib/{error-Dd8DIqs-.mjs → error-DoHuatWw.mjs} +1 -1
- package/lib/{event-stream-BbFZJy-z.mjs → event-stream-C-FmBYUt.mjs} +1 -1
- package/lib/{github-copilot-CYkjeTi3.mjs → github-copilot-C2dTonBX.mjs} +3 -3
- package/lib/{github-copilot-B1yiyVRh.mjs → github-copilot-qETlj_bD.mjs} +1 -1
- package/lib/{gitlab-duo-CM7Ref1H.mjs → gitlab-duo-FQZiFRQe.mjs} +3 -3
- package/lib/{gitlab-duo-workflow-BGAF6JDw.mjs → gitlab-duo-workflow-DLTabzOy.mjs} +2 -2
- package/lib/{google-BS4T25Pn.mjs → google-BilwFSzx.mjs} +3 -3
- package/lib/{google-antigravity-DGmwC2KV.mjs → google-antigravity-BfBiINdu.mjs} +2 -2
- package/lib/{google-auth-B6gjsZvg.mjs → google-auth-CWlKXJ-H.mjs} +3 -3
- package/lib/{google-gemini-cli-Dsztq0N5.mjs → google-gemini-cli-CB89ljNz.mjs} +3 -3
- package/lib/{google-gemini-cli-Cqds_Q5T.mjs → google-gemini-cli-CygFcR6N.mjs} +8 -8
- package/lib/{google-oauth-shared-CuEHaDDj.mjs → google-oauth-shared-Cn82h1o2.mjs} +2 -2
- package/lib/{google-shared-Dr-VG-ap.mjs → google-shared-CF1JrqTM.mjs} +6 -6
- package/lib/{google-vertex-BDN2tLaD.mjs → google-vertex-DgMhhFw8.mjs} +5 -5
- package/lib/{identity-Da1GPU9a.mjs → identity-C0SPVyIZ.mjs} +1 -1
- package/lib/{idle-iterator-DUjKQEGT.mjs → idle-iterator-HzbbfXP4.mjs} +2 -2
- package/lib/index.mjs +310 -29
- package/lib/{kimi-Dh0pv3WZ.mjs → kimi-DHDO6Fde.mjs} +3 -3
- package/lib/launch-DwpE70Pv.mjs +148 -0
- package/lib/{markit-BL3cH47U.mjs → markit-B9exZ0ZV.mjs} +1 -1
- package/lib/{minimax-code-Uq8Qu9LW.mjs → minimax-code-vAhEXhev.mjs} +1 -1
- package/lib/{models-SGASygJ3.mjs → models-Cp3PzU3l.mjs} +1 -1
- package/lib/{ollama-DPzBmq89.mjs → ollama-TrkXTNqE.mjs} +8 -8
- package/lib/{openai-codex-Ch8CkT3p.mjs → openai-codex-CrjHtSH4.mjs} +3 -3
- package/lib/{openai-codex-responses-pejZgdZo.mjs → openai-codex-responses-C4uMpWNy.mjs} +10 -10
- package/lib/{openai-completions-DIf361kF.mjs → openai-completions-1ydXm5vF.mjs} +13 -13
- package/lib/{openai-reasoning-fallback-Nj6yB2rY.mjs → openai-reasoning-fallback-CigKCyzc.mjs} +2 -2
- package/lib/{openai-responses-Db_a-U4-.mjs → openai-responses-CN79gRGQ.mjs} +10 -10
- package/lib/{opencode-Rq_Q2vAO.mjs → opencode-CEGlimzL.mjs} +1 -1
- package/lib/{perplexity-C4iLVMUj.mjs → perplexity-BLJN-8dM.mjs} +2 -2
- package/lib/{proxy-pM_NIv-H.mjs → proxy-XOYi58TM.mjs} +1 -1
- package/lib/readability-Cpm-ocau.mjs +455 -0
- package/lib/{scrapers-1FTlHNQV.mjs → scrapers-BlWQMGjU.mjs} +11 -10
- package/lib/{src-BgpusnsB.mjs → src-D_e1qMwi.mjs} +5 -1
- package/lib/{stream-CRtexYLe.mjs → stream-DveNFWSN.mjs} +56 -56
- package/lib/{stream-markup-healing-KMkiAA00.mjs → stream-markup-healing-C9eC7Gf8.mjs} +3 -3
- package/lib/tool-errors-DoyxivAR.mjs +47 -0
- package/lib/types-BUO0JXO-.mjs +251 -0
- package/lib/{utils-D2YknRk4.mjs → utils-B-mTYQBc.mjs} +1 -1
- package/lib/{utils-C616y7eF.mjs → utils-D1QPFbRk.mjs} +28 -268
- package/lib/{utils-Cp76gCyk.mjs → utils-fnV2zzp3.mjs} +3 -3
- package/lib/{vision-guard-01qSwFpf.mjs → vision-guard-BsvOWmfB.mjs} +2 -2
- package/lib/{wafer-CgtPHerf.mjs → wafer-Dpy7tL3l.mjs} +1 -1
- package/lib/{xai-oauth-Buk8XVvM.mjs → xai-oauth-BkPNQS-q.mjs} +2 -2
- package/lib/{xiaomi-D2qT5cAC.mjs → xiaomi-CG3TsYRz.mjs} +1 -1
- package/lib/{zai-C59YnomG.mjs → zai--cewobzN.mjs} +2 -2
- package/lib/{zip-Cg9ANN_U.mjs → zip-CqKW2-TK.mjs} +3 -46
- package/package.json +147 -145
- package/presets/package.json +1 -1
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
|
+
__installBunShim();
|
|
3
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-utils@17.3.5/node_modules/@oh-my-pi/pi-utils/src/readability/readability.ts
|
|
4
|
+
const UNLIKELY$1 = /-ad-|ai2html|banner|breadcrumbs|comment|community|combx|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup/i;
|
|
5
|
+
const POSSIBLE$1 = /and|article|body|column|content|main|shadow/i;
|
|
6
|
+
const POSITIVE = /article|body|content|entry|hentry|h-entry|main|page|pagination|post|text|blog|story/i;
|
|
7
|
+
const NEGATIVE = /-ad-|hidden|^hid$| hid$| hid |^hid |banner|comment|com-|contact|footer|gdpr|masthead|media|meta|outbrain|promo|related|scroll|share|shoutbox|sidebar|skyscraper|sponsor|shopping|tags|widget/i;
|
|
8
|
+
const BYLINE = /byline|author|dateline|writtenby|p-author/i;
|
|
9
|
+
const SCORE_TAGS = /* @__PURE__ */ new Set([
|
|
10
|
+
"SECTION",
|
|
11
|
+
"H2",
|
|
12
|
+
"H3",
|
|
13
|
+
"H4",
|
|
14
|
+
"H5",
|
|
15
|
+
"H6",
|
|
16
|
+
"P",
|
|
17
|
+
"TD",
|
|
18
|
+
"PRE"
|
|
19
|
+
]);
|
|
20
|
+
const DROP_TAGS = [
|
|
21
|
+
"form",
|
|
22
|
+
"fieldset",
|
|
23
|
+
"object",
|
|
24
|
+
"embed",
|
|
25
|
+
"footer",
|
|
26
|
+
"link",
|
|
27
|
+
"aside",
|
|
28
|
+
"iframe",
|
|
29
|
+
"input",
|
|
30
|
+
"textarea",
|
|
31
|
+
"select",
|
|
32
|
+
"button"
|
|
33
|
+
];
|
|
34
|
+
const UNLIKELY_ROLES = /* @__PURE__ */ new Set([
|
|
35
|
+
"menu",
|
|
36
|
+
"menubar",
|
|
37
|
+
"complementary",
|
|
38
|
+
"navigation",
|
|
39
|
+
"alert",
|
|
40
|
+
"alertdialog",
|
|
41
|
+
"dialog"
|
|
42
|
+
]);
|
|
43
|
+
const ARTICLE_TYPES = /^(?:Article|AdvertiserContentArticle|NewsArticle|AnalysisNewsArticle|OpinionNewsArticle|ReportageNewsArticle|ReviewNewsArticle|Report|ScholarlyArticle|MedicalScholarlyArticle|SocialMediaPosting|BlogPosting|LiveBlogPosting|DiscussionForumPosting|TechArticle|APIReference)$/;
|
|
44
|
+
const NORMALIZE = /\s{2,}/g;
|
|
45
|
+
function elements(collection) {
|
|
46
|
+
return Array.from(collection);
|
|
47
|
+
}
|
|
48
|
+
function descendants(root) {
|
|
49
|
+
const result = [];
|
|
50
|
+
const pending = elements(root.children).reverse();
|
|
51
|
+
while (pending.length) {
|
|
52
|
+
const node = pending.pop();
|
|
53
|
+
if (!node) continue;
|
|
54
|
+
result.push(node);
|
|
55
|
+
const children = elements(node.children);
|
|
56
|
+
for (let index = children.length - 1; index >= 0; index--) pending.push(children[index]);
|
|
57
|
+
}
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
function text(node) {
|
|
61
|
+
return (node.textContent ?? "").trim().replace(NORMALIZE, " ");
|
|
62
|
+
}
|
|
63
|
+
function matchLabel(node) {
|
|
64
|
+
return `${typeof node.className === "string" ? node.className : ""} ${node.id ?? ""}`;
|
|
65
|
+
}
|
|
66
|
+
function classWeight(node) {
|
|
67
|
+
const label = matchLabel(node);
|
|
68
|
+
return (POSITIVE.test(label) ? 25 : 0) - (NEGATIVE.test(label) ? 25 : 0);
|
|
69
|
+
}
|
|
70
|
+
function initialScore(node) {
|
|
71
|
+
let score = classWeight(node);
|
|
72
|
+
switch (node.tagName) {
|
|
73
|
+
case "DIV":
|
|
74
|
+
score += 5;
|
|
75
|
+
break;
|
|
76
|
+
case "PRE":
|
|
77
|
+
case "TD":
|
|
78
|
+
case "BLOCKQUOTE":
|
|
79
|
+
score += 3;
|
|
80
|
+
break;
|
|
81
|
+
case "ADDRESS":
|
|
82
|
+
case "OL":
|
|
83
|
+
case "UL":
|
|
84
|
+
case "DL":
|
|
85
|
+
case "DD":
|
|
86
|
+
case "DT":
|
|
87
|
+
case "LI":
|
|
88
|
+
case "FORM":
|
|
89
|
+
score -= 3;
|
|
90
|
+
break;
|
|
91
|
+
case "H1":
|
|
92
|
+
case "H2":
|
|
93
|
+
case "H3":
|
|
94
|
+
case "H4":
|
|
95
|
+
case "H5":
|
|
96
|
+
case "H6":
|
|
97
|
+
case "TH": score -= 5;
|
|
98
|
+
}
|
|
99
|
+
return score;
|
|
100
|
+
}
|
|
101
|
+
function linkDensity(node) {
|
|
102
|
+
const total = text(node).length;
|
|
103
|
+
if (!total) return 0;
|
|
104
|
+
let linked = 0;
|
|
105
|
+
for (const link of elements(node.getElementsByTagName("a"))) linked += text(link).length * ((link.getAttribute("href") ?? "").startsWith("#") ? .3 : 1);
|
|
106
|
+
return linked / total;
|
|
107
|
+
}
|
|
108
|
+
function visible(node) {
|
|
109
|
+
const style = node.getAttribute("style")?.toLowerCase() ?? "";
|
|
110
|
+
return !node.hasAttribute("hidden") && node.getAttribute("aria-hidden") !== "true" && !/display\s*:\s*none|visibility\s*:\s*hidden/.test(style);
|
|
111
|
+
}
|
|
112
|
+
function removeAll(root, tags) {
|
|
113
|
+
const container = root;
|
|
114
|
+
for (const tag of tags) for (const node of elements(container.getElementsByTagName(tag))) node.remove();
|
|
115
|
+
}
|
|
116
|
+
function entityDecode(value) {
|
|
117
|
+
if (!value) return value;
|
|
118
|
+
const named = {
|
|
119
|
+
quot: "\"",
|
|
120
|
+
amp: "&",
|
|
121
|
+
apos: "'",
|
|
122
|
+
lt: "<",
|
|
123
|
+
gt: ">"
|
|
124
|
+
};
|
|
125
|
+
return value.replace(/&(quot|amp|apos|lt|gt);/g, (_, name) => named[name] ?? "").replace(/&#(?:x([0-9a-f]+)|(\d+));/gi, (_, hex, decimal) => {
|
|
126
|
+
const value = Number.parseInt(hex ?? decimal ?? "0", hex ? 16 : 10);
|
|
127
|
+
return String.fromCodePoint(value === 0 || value > 1114111 || value >= 55296 && value <= 57343 ? 65533 : value);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function titleFromDocument(document) {
|
|
131
|
+
const titleElement = elements(document.getElementsByTagName("title"))[0];
|
|
132
|
+
const original = typeof document.title === "string" ? document.title.trim() : titleElement ? text(titleElement) : "";
|
|
133
|
+
let title = original;
|
|
134
|
+
const separators = [...original.matchAll(/ [|\\/>»-] /g)];
|
|
135
|
+
if (separators.length) {
|
|
136
|
+
title = original.slice(0, separators.at(-1)?.index);
|
|
137
|
+
if (title.trim().split(/\s+/).length < 3) title = original.replace(/^[^|\\/>»-]*[|\\/>»-]/, "");
|
|
138
|
+
} else if (title.includes(": ")) {
|
|
139
|
+
if (!elements(document.querySelectorAll("h1, h2")).some((node) => text(node) === title)) {
|
|
140
|
+
const suffix = original.slice(original.lastIndexOf(":") + 1);
|
|
141
|
+
title = suffix.trim().split(/\s+/).length < 3 ? original.slice(original.indexOf(":") + 1) : suffix;
|
|
142
|
+
}
|
|
143
|
+
} else if (title.length > 150 || title.length < 15) {
|
|
144
|
+
const headings = elements(document.getElementsByTagName("h1"));
|
|
145
|
+
if (headings.length === 1) title = text(headings[0]);
|
|
146
|
+
}
|
|
147
|
+
title = title.trim().replace(NORMALIZE, " ");
|
|
148
|
+
if (title.split(/\s+/).length <= 4) return original;
|
|
149
|
+
return title;
|
|
150
|
+
}
|
|
151
|
+
function jsonLdMetadata(document) {
|
|
152
|
+
for (const script of elements(document.getElementsByTagName("script"))) {
|
|
153
|
+
if (script.getAttribute("type") !== "application/ld+json") continue;
|
|
154
|
+
try {
|
|
155
|
+
const decoded = JSON.parse((script.textContent ?? "").replace(/^\s*<!\[CDATA\[|\]\]>\s*$/g, ""));
|
|
156
|
+
const records = Array.isArray(decoded) ? decoded : [decoded];
|
|
157
|
+
for (const candidate of records) {
|
|
158
|
+
if (!candidate || typeof candidate !== "object") continue;
|
|
159
|
+
const record = candidate;
|
|
160
|
+
if (typeof record["@type"] !== "string" || !ARTICLE_TYPES.test(record["@type"])) continue;
|
|
161
|
+
const author = record.author;
|
|
162
|
+
let byline;
|
|
163
|
+
if (author && typeof author === "object" && !Array.isArray(author)) {
|
|
164
|
+
const name = author.name;
|
|
165
|
+
if (typeof name === "string") byline = name.trim();
|
|
166
|
+
} else if (Array.isArray(author)) {
|
|
167
|
+
const names = author.flatMap((item) => {
|
|
168
|
+
if (!item || typeof item !== "object") return [];
|
|
169
|
+
const name = item.name;
|
|
170
|
+
return typeof name === "string" ? [name.trim()] : [];
|
|
171
|
+
});
|
|
172
|
+
if (names.length) byline = names.join(", ");
|
|
173
|
+
}
|
|
174
|
+
const publisher = record.publisher;
|
|
175
|
+
const publisherName = publisher && typeof publisher === "object" ? publisher.name : void 0;
|
|
176
|
+
return {
|
|
177
|
+
title: typeof record.name === "string" ? record.name.trim() : typeof record.headline === "string" ? record.headline.trim() : void 0,
|
|
178
|
+
byline,
|
|
179
|
+
excerpt: typeof record.description === "string" ? record.description.trim() : void 0,
|
|
180
|
+
siteName: typeof publisherName === "string" ? publisherName.trim() : void 0,
|
|
181
|
+
publishedTime: typeof record.datePublished === "string" ? record.datePublished.trim() : void 0
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
} catch {}
|
|
185
|
+
}
|
|
186
|
+
return {};
|
|
187
|
+
}
|
|
188
|
+
function metadataFromDocument(document, jsonLd) {
|
|
189
|
+
const values = /* @__PURE__ */ new Map();
|
|
190
|
+
for (const meta of elements(document.getElementsByTagName("meta"))) {
|
|
191
|
+
const content = meta.getAttribute("content")?.trim();
|
|
192
|
+
if (!content) continue;
|
|
193
|
+
const property = meta.getAttribute("property")?.toLowerCase().replace(/\s/g, "");
|
|
194
|
+
const name = meta.getAttribute("name")?.toLowerCase().replace(/\s/g, "").replace(/\./g, ":");
|
|
195
|
+
if (property && /^(?:article|dc|dcterm|og|twitter):(?:author|creator|description|published_time|title|site_name)$/.test(property)) values.set(property, content);
|
|
196
|
+
else if (name && /^(?:(?:dc|dcterm|og|twitter|parsely|weibo:(?:article|webpage))[-:]?)?(?:author|creator|pub-date|description|title|site_name)$/.test(name)) values.set(name, content);
|
|
197
|
+
}
|
|
198
|
+
const articleAuthor = values.get("article:author");
|
|
199
|
+
const result = {
|
|
200
|
+
title: jsonLd.title ?? values.get("dc:title") ?? values.get("dcterm:title") ?? values.get("og:title") ?? values.get("title") ?? values.get("twitter:title") ?? titleFromDocument(document),
|
|
201
|
+
byline: jsonLd.byline ?? values.get("dc:creator") ?? values.get("dcterm:creator") ?? values.get("author") ?? values.get("parsely-author") ?? (articleAuthor && !/^https?:\/\//.test(articleAuthor) ? articleAuthor : void 0),
|
|
202
|
+
excerpt: jsonLd.excerpt ?? values.get("dc:description") ?? values.get("dcterm:description") ?? values.get("og:description") ?? values.get("description") ?? values.get("twitter:description"),
|
|
203
|
+
siteName: jsonLd.siteName ?? values.get("og:site_name"),
|
|
204
|
+
publishedTime: jsonLd.publishedTime ?? values.get("article:published_time") ?? values.get("parsely-pub-date") ?? null
|
|
205
|
+
};
|
|
206
|
+
return {
|
|
207
|
+
title: entityDecode(result.title) ?? void 0,
|
|
208
|
+
byline: entityDecode(result.byline) ?? void 0,
|
|
209
|
+
excerpt: entityDecode(result.excerpt) ?? void 0,
|
|
210
|
+
siteName: entityDecode(result.siteName) ?? void 0,
|
|
211
|
+
publishedTime: entityDecode(result.publishedTime)
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/** Extracts the article body and metadata from a standards-shaped document. */
|
|
215
|
+
var Readability = class {
|
|
216
|
+
#document;
|
|
217
|
+
#options;
|
|
218
|
+
#scores = /* @__PURE__ */ new Map();
|
|
219
|
+
#byline;
|
|
220
|
+
#lang = null;
|
|
221
|
+
constructor(document, options = {}) {
|
|
222
|
+
this.#document = document;
|
|
223
|
+
this.#options = options;
|
|
224
|
+
}
|
|
225
|
+
/** Runs extraction once; the supplied document is consumed and should not be reused. */
|
|
226
|
+
parse() {
|
|
227
|
+
const documentElement = this.#document.documentElement;
|
|
228
|
+
if (!documentElement) return null;
|
|
229
|
+
const max = this.#options.maxElemsToParse ?? 0;
|
|
230
|
+
if (max > 0) {
|
|
231
|
+
const count = descendants(documentElement).length + 1;
|
|
232
|
+
if (count > max) throw new Error(`Aborting parsing document; ${count} elements found`);
|
|
233
|
+
}
|
|
234
|
+
const jsonLd = this.#options.disableJSONLD ? {} : jsonLdMetadata(this.#document);
|
|
235
|
+
const metadata = metadataFromDocument(this.#document, jsonLd);
|
|
236
|
+
removeAll(this.#document, ["script", "style"]);
|
|
237
|
+
const body = this.#document.body;
|
|
238
|
+
if (!body) return null;
|
|
239
|
+
const source = body.innerHTML;
|
|
240
|
+
const attempts = [];
|
|
241
|
+
for (const mode of [
|
|
242
|
+
0,
|
|
243
|
+
1,
|
|
244
|
+
2,
|
|
245
|
+
3
|
|
246
|
+
]) {
|
|
247
|
+
if (mode) body.innerHTML = source;
|
|
248
|
+
this.#scores.clear();
|
|
249
|
+
this.#byline = void 0;
|
|
250
|
+
const attempt = this.#extract(body, documentElement, metadata.title ?? "", mode);
|
|
251
|
+
if (attempt) attempts.push(attempt);
|
|
252
|
+
if (attempt && attempt.length >= (this.#options.charThreshold || 500)) break;
|
|
253
|
+
}
|
|
254
|
+
attempts.sort((left, right) => right.length - left.length);
|
|
255
|
+
const best = attempts[0];
|
|
256
|
+
if (!best?.length) return null;
|
|
257
|
+
if (!metadata.excerpt) {
|
|
258
|
+
const firstParagraph = elements(best.element.getElementsByTagName("p"))[0];
|
|
259
|
+
if (firstParagraph) metadata.excerpt = (firstParagraph.textContent ?? "").trim();
|
|
260
|
+
}
|
|
261
|
+
const contentText = best.element.textContent ?? "";
|
|
262
|
+
const serializer = this.#options.serializer ?? ((node) => node.innerHTML);
|
|
263
|
+
return {
|
|
264
|
+
title: metadata.title,
|
|
265
|
+
byline: metadata.byline ?? this.#byline,
|
|
266
|
+
dir: best.dir,
|
|
267
|
+
lang: this.#lang,
|
|
268
|
+
content: serializer(best.element),
|
|
269
|
+
textContent: contentText,
|
|
270
|
+
length: contentText.length,
|
|
271
|
+
excerpt: metadata.excerpt,
|
|
272
|
+
siteName: metadata.siteName,
|
|
273
|
+
publishedTime: metadata.publishedTime
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
#extract(body, documentElement, articleTitle, mode) {
|
|
277
|
+
this.#lang = documentElement.getAttribute("lang");
|
|
278
|
+
const stripUnlikely = mode === 0;
|
|
279
|
+
const weightClasses = mode < 2;
|
|
280
|
+
const all = [documentElement, ...descendants(documentElement)];
|
|
281
|
+
const scored = [];
|
|
282
|
+
let titleRemoved = false;
|
|
283
|
+
for (const node of all) {
|
|
284
|
+
if (node === documentElement || node.tagName === "BODY") continue;
|
|
285
|
+
const label = matchLabel(node);
|
|
286
|
+
if (!visible(node) || node.getAttribute("aria-modal") === "true" && node.getAttribute("role") === "dialog") {
|
|
287
|
+
node.remove();
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (!this.#byline && this.#isByline(node, label)) {
|
|
291
|
+
this.#byline = text(node);
|
|
292
|
+
node.remove();
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
if (!titleRemoved && /^(?:H1|H2)$/.test(node.tagName) && this.#similar(articleTitle, text(node)) > .75) {
|
|
296
|
+
titleRemoved = true;
|
|
297
|
+
node.remove();
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
if (stripUnlikely && UNLIKELY$1.test(label) && !POSSIBLE$1.test(label) || UNLIKELY_ROLES.has(node.getAttribute("role") ?? "")) {
|
|
301
|
+
node.remove();
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
if (SCORE_TAGS.has(node.tagName)) scored.push(node);
|
|
305
|
+
}
|
|
306
|
+
for (const paragraph of scored) this.#scoreParagraph(paragraph, weightClasses);
|
|
307
|
+
let top;
|
|
308
|
+
let topScore = Number.NEGATIVE_INFINITY;
|
|
309
|
+
for (const [candidate, raw] of this.#scores) {
|
|
310
|
+
if (candidate.tagName === "BODY" || candidate.tagName === "HTML") continue;
|
|
311
|
+
const score = raw * (1 - linkDensity(candidate));
|
|
312
|
+
this.#scores.set(candidate, score);
|
|
313
|
+
if (score > topScore) {
|
|
314
|
+
top = candidate;
|
|
315
|
+
topScore = score;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
if (!top || top.tagName === "BODY") top = body;
|
|
319
|
+
while (top.parentNode && top.parentNode.tagName !== "BODY" && top.parentNode.children.length === 1) top = top.parentNode;
|
|
320
|
+
const parent = top.parentNode;
|
|
321
|
+
const article = this.#document.createElement("DIV");
|
|
322
|
+
const siblings = parent ? elements(parent.children) : [top];
|
|
323
|
+
const threshold = Math.max(10, (this.#scores.get(top) ?? topScore) * .2);
|
|
324
|
+
for (const sibling of siblings) {
|
|
325
|
+
const siblingText = text(sibling);
|
|
326
|
+
const sameClassBonus = sibling.className && sibling.className === top.className ? (this.#scores.get(top) ?? 0) * .2 : 0;
|
|
327
|
+
if (!(sibling === top || (this.#scores.get(sibling) ?? 0) + sameClassBonus >= threshold || sibling.tagName === "P" && (siblingText.length > 80 && linkDensity(sibling) < .25 || siblingText.length > 0 && siblingText.length < 80 && linkDensity(sibling) === 0 && /\.(?: |$)/.test(siblingText)))) continue;
|
|
328
|
+
if ([
|
|
329
|
+
"DIV",
|
|
330
|
+
"ARTICLE",
|
|
331
|
+
"SECTION",
|
|
332
|
+
"P",
|
|
333
|
+
"OL",
|
|
334
|
+
"UL"
|
|
335
|
+
].includes(sibling.tagName)) {
|
|
336
|
+
article.appendChild(sibling);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const replacement = this.#document.createElement("DIV");
|
|
340
|
+
for (const attribute of Array.from(sibling.attributes)) replacement.setAttribute(attribute.name, attribute.value);
|
|
341
|
+
while (sibling.firstChild) replacement.appendChild(sibling.firstChild);
|
|
342
|
+
article.appendChild(replacement);
|
|
343
|
+
}
|
|
344
|
+
this.#clean(article, mode < 3);
|
|
345
|
+
const page = this.#document.createElement("DIV");
|
|
346
|
+
page.id = "readability-page-1";
|
|
347
|
+
page.className = "page";
|
|
348
|
+
while (article.firstChild) page.appendChild(article.firstChild);
|
|
349
|
+
article.appendChild(page);
|
|
350
|
+
const content = text(article);
|
|
351
|
+
let dir;
|
|
352
|
+
let ancestor = top;
|
|
353
|
+
while (ancestor) {
|
|
354
|
+
if (ancestor.getAttribute) {
|
|
355
|
+
dir = ancestor.getAttribute("dir");
|
|
356
|
+
if (dir) break;
|
|
357
|
+
}
|
|
358
|
+
ancestor = ancestor.parentNode;
|
|
359
|
+
}
|
|
360
|
+
return {
|
|
361
|
+
element: article,
|
|
362
|
+
length: content.length,
|
|
363
|
+
dir
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
#scoreParagraph(node, weightClasses) {
|
|
367
|
+
const content = text(node);
|
|
368
|
+
if (content.length < 25) return;
|
|
369
|
+
const score = 1 + content.split(/[\u002c\u060c\ufe50\ufe10\ufe11\u2e41\u2e34\u2e32\uff0c]/).length + Math.min(Math.floor(content.length / 100), 3);
|
|
370
|
+
let ancestor = node.parentNode;
|
|
371
|
+
for (let level = 0; ancestor && level < 5; level++, ancestor = ancestor.parentNode) {
|
|
372
|
+
const element = ancestor;
|
|
373
|
+
if (!element.tagName || !element.parentNode || !element.parentNode.tagName) continue;
|
|
374
|
+
const baseline = this.#scores.get(element) ?? initialScore(element) - (weightClasses ? 0 : classWeight(element));
|
|
375
|
+
const divisor = level === 0 ? 1 : level === 1 ? 2 : level * 3;
|
|
376
|
+
this.#scores.set(element, baseline + score / divisor);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
#clean(root, conditional) {
|
|
380
|
+
removeAll(root, DROP_TAGS);
|
|
381
|
+
for (const heading of elements(root.querySelectorAll("h1, h2, h3, h4, h5, h6"))) if (classWeight(heading) < 0 || linkDensity(heading) > .33) heading.remove();
|
|
382
|
+
if (conditional) for (const node of elements(root.querySelectorAll("table, ul, div"))) {
|
|
383
|
+
if (node === root) continue;
|
|
384
|
+
const nodeText = text(node);
|
|
385
|
+
const paragraphs = node.getElementsByTagName("p").length;
|
|
386
|
+
const images = node.getElementsByTagName("img").length;
|
|
387
|
+
const inputs = node.getElementsByTagName("input").length;
|
|
388
|
+
if (classWeight(node) < 0 || !nodeText && !images || nodeText.split(",").length < 10 && (images > paragraphs && paragraphs > 0 || inputs > Math.floor(paragraphs / 3) || linkDensity(node) > .5)) node.remove();
|
|
389
|
+
}
|
|
390
|
+
for (const paragraph of elements(root.getElementsByTagName("p"))) if (!text(paragraph) && !paragraph.querySelector("img, embed, object, iframe")) paragraph.remove();
|
|
391
|
+
for (const node of [root, ...descendants(root)]) {
|
|
392
|
+
if (!this.#options.keepClasses) {
|
|
393
|
+
const preserved = (this.#options.classesToPreserve ?? []).filter((name) => node.className.split(/\s+/).includes(name));
|
|
394
|
+
if (node.id === "readability-page-1") preserved.unshift("page");
|
|
395
|
+
if (preserved.length) node.className = [...new Set(preserved)].join(" ");
|
|
396
|
+
else node.removeAttribute("class");
|
|
397
|
+
}
|
|
398
|
+
for (const attr of [
|
|
399
|
+
"style",
|
|
400
|
+
"align",
|
|
401
|
+
"background",
|
|
402
|
+
"bgcolor",
|
|
403
|
+
"border",
|
|
404
|
+
"cellpadding",
|
|
405
|
+
"cellspacing",
|
|
406
|
+
"frame",
|
|
407
|
+
"hspace",
|
|
408
|
+
"rules",
|
|
409
|
+
"valign",
|
|
410
|
+
"vspace"
|
|
411
|
+
]) node.removeAttribute(attr);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
#isByline(node, label) {
|
|
415
|
+
const value = text(node);
|
|
416
|
+
return value.length > 0 && value.length < 100 && (node.getAttribute("rel") === "author" || (node.getAttribute("itemprop") ?? "").includes("author") || BYLINE.test(label));
|
|
417
|
+
}
|
|
418
|
+
#similar(left, right) {
|
|
419
|
+
const leftTokens = left.toLowerCase().split(/\W+/).filter(Boolean);
|
|
420
|
+
const rightTokens = right.toLowerCase().split(/\W+/).filter(Boolean);
|
|
421
|
+
if (!leftTokens.length || !rightTokens.length) return 0;
|
|
422
|
+
return 1 - rightTokens.filter((token) => !leftTokens.includes(token)).join(" ").length / rightTokens.join(" ").length;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
//#endregion
|
|
426
|
+
//#region node_modules/.pnpm/@oh-my-pi+pi-utils@17.3.5/node_modules/@oh-my-pi/pi-utils/src/readability/readerable.ts
|
|
427
|
+
const UNLIKELY = /-ad-|ai2html|banner|breadcrumbs|combx|comment|community|cover-wrap|disqus|extra|footer|gdpr|header|legends|menu|related|remark|replies|rss|shoutbox|sidebar|skyscraper|social|sponsor|supplemental|ad-break|agegate|pagination|pager|popup|yom-remote/i;
|
|
428
|
+
const POSSIBLE = /and|article|body|column|content|main|shadow/i;
|
|
429
|
+
/** Estimates whether a document contains enough prose for article extraction. */
|
|
430
|
+
function isProbablyReaderable(document, options = {}) {
|
|
431
|
+
const resolved = typeof options === "function" ? { visibilityChecker: options } : options;
|
|
432
|
+
const minLength = resolved.minContentLength ?? 140;
|
|
433
|
+
const minScore = resolved.minScore ?? 20;
|
|
434
|
+
const visible = resolved.visibilityChecker ?? ((node) => {
|
|
435
|
+
const element = node;
|
|
436
|
+
const style = element.getAttribute("style")?.toLowerCase() ?? "";
|
|
437
|
+
return !element.hasAttribute("hidden") && element.getAttribute("aria-hidden") !== "true" && !/display\s*:\s*none/.test(style);
|
|
438
|
+
});
|
|
439
|
+
const candidates = new Set(Array.from(document.querySelectorAll("p, pre, article")));
|
|
440
|
+
for (const br of Array.from(document.querySelectorAll("div > br"))) if (br.parentNode) candidates.add(br.parentNode);
|
|
441
|
+
let score = 0;
|
|
442
|
+
for (const node of candidates) {
|
|
443
|
+
if (!visible(node)) continue;
|
|
444
|
+
const label = `${node.className} ${node.id}`;
|
|
445
|
+
if (UNLIKELY.test(label) && !POSSIBLE.test(label)) continue;
|
|
446
|
+
if (node.parentNode?.tagName === "LI" && node.tagName === "P") continue;
|
|
447
|
+
const length = (node.textContent ?? "").trim().length;
|
|
448
|
+
if (length < minLength) continue;
|
|
449
|
+
score += Math.sqrt(length - minLength);
|
|
450
|
+
if (score > minScore) return true;
|
|
451
|
+
}
|
|
452
|
+
return false;
|
|
453
|
+
}
|
|
454
|
+
//#endregion
|
|
455
|
+
export { Readability, isProbablyReaderable };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { installBunShim as __installBunShim } from "./bun-shim.mjs";
|
|
2
2
|
__installBunShim();
|
|
3
3
|
import { n as fs_promises_shim_exports } from "./fs-promises-shim-Bx0fpxuk.mjs";
|
|
4
|
-
import { B as USER_AGENT, G as getDocsRsCacheDir, N as formatNumber, P as $env, T as warn, c as combineSignals, j as formatBytes, l as exec, s as Snowflake, x as parseFrontmatter, y as isEnoent } from "./src-
|
|
5
|
-
import { V as tryParseJson } from "./utils-
|
|
6
|
-
import {
|
|
4
|
+
import { B as USER_AGENT, G as getDocsRsCacheDir, N as formatNumber, P as $env, T as warn, c as combineSignals, j as formatBytes, l as exec, s as Snowflake, x as parseFrontmatter, y as isEnoent } from "./src-D_e1qMwi.mjs";
|
|
5
|
+
import { V as tryParseJson } from "./utils-fnV2zzp3.mjs";
|
|
6
|
+
import { a as fetchBinary, c as getParallelExtractContent, i as convertWithMarkit, l as ensureTool, m as settings, n as asRecord, o as extractWithParallel, r as asString, s as findParallelApiKey, t as asNumber } from "./utils-D1QPFbRk.mjs";
|
|
7
7
|
import { n as isRecord } from "./type-guards-B9VVjRDK.mjs";
|
|
8
|
-
import {
|
|
8
|
+
import { r as throwIfAborted, t as ToolAbortError } from "./tool-errors-DoyxivAR.mjs";
|
|
9
|
+
import { c as getLocalizedText, d as looksLikeHtml, i as decodeHtmlEntities, l as htmlToBasicMarkdown, o as formatIsoDate, r as buildResult, s as formatMediaDuration, u as loadPage } from "./types-BUO0JXO-.mjs";
|
|
9
10
|
import * as path from "node:path";
|
|
10
11
|
import * as os from "node:os";
|
|
11
12
|
import { gunzipSync } from "node:zlib";
|
|
@@ -221,7 +222,7 @@ const handleArxiv = async (url, timeout, signal) => {
|
|
|
221
222
|
signal
|
|
222
223
|
});
|
|
223
224
|
if (!result.ok) return null;
|
|
224
|
-
const { parseHTML } = await import("./dom-
|
|
225
|
+
const { parseHTML } = await import("./dom-CawWi8fa.mjs");
|
|
225
226
|
const entry = parseHTML(result.content).document.querySelector("entry");
|
|
226
227
|
if (!entry) return null;
|
|
227
228
|
const title = entry.querySelector("title")?.textContent?.trim()?.replace(/\s+/g, " ");
|
|
@@ -3526,7 +3527,7 @@ const handleGoPkg = async (url, timeout, signal) => {
|
|
|
3526
3527
|
notes: ["error"],
|
|
3527
3528
|
contentType: "text/plain"
|
|
3528
3529
|
});
|
|
3529
|
-
const { parseHTML } = await import("./dom-
|
|
3530
|
+
const { parseHTML } = await import("./dom-CawWi8fa.mjs");
|
|
3530
3531
|
const doc = parseHTML(pageResult.content).document;
|
|
3531
3532
|
const breadcrumb = doc.querySelector(".go-Breadcrumb");
|
|
3532
3533
|
if (breadcrumb) {
|
|
@@ -4182,7 +4183,7 @@ const handleIacr = async (url, timeout, signal) => {
|
|
|
4182
4183
|
signal
|
|
4183
4184
|
});
|
|
4184
4185
|
if (!result.ok) return null;
|
|
4185
|
-
const { parseHTML } = await import("./dom-
|
|
4186
|
+
const { parseHTML } = await import("./dom-CawWi8fa.mjs");
|
|
4186
4187
|
const doc = parseHTML(result.content).document;
|
|
4187
4188
|
const title = doc.querySelector("h3.mb-3")?.textContent?.trim() || doc.querySelector("meta[name=\"citation_title\"]")?.getAttribute("content");
|
|
4188
4189
|
const authors = Array.from(doc.querySelectorAll("meta[name=\"citation_author\"]")).map((m) => m.getAttribute("content")).filter((author) => Boolean(author));
|
|
@@ -6607,7 +6608,7 @@ const handleReadTheDocs = async (url, timeout, signal) => {
|
|
|
6607
6608
|
truncated: false,
|
|
6608
6609
|
notes
|
|
6609
6610
|
};
|
|
6610
|
-
const { parseHTML } = await import("./dom-
|
|
6611
|
+
const { parseHTML } = await import("./dom-CawWi8fa.mjs");
|
|
6611
6612
|
const root = parseHTML(result.content).document;
|
|
6612
6613
|
let mainContent = root.querySelector(".document") || root.querySelector("[role=\"main\"]") || root.querySelector("main") || root.querySelector(".rst-content") || root.querySelector(".body");
|
|
6613
6614
|
if (!mainContent) {
|
|
@@ -8238,7 +8239,7 @@ const handleTwitter = async (url, timeout, signal) => {
|
|
|
8238
8239
|
signal
|
|
8239
8240
|
});
|
|
8240
8241
|
if (result.ok && result.content.length > 500) {
|
|
8241
|
-
const { parseHTML } = await import("./dom-
|
|
8242
|
+
const { parseHTML } = await import("./dom-CawWi8fa.mjs");
|
|
8242
8243
|
const doc = parseHTML(result.content).document;
|
|
8243
8244
|
const tweetContent = doc.querySelector(".tweet-content")?.textContent?.trim();
|
|
8244
8245
|
const fullname = doc.querySelector(".fullname")?.textContent?.trim();
|
|
@@ -8859,7 +8860,7 @@ const handleWikipedia = async (url, timeout, signal) => {
|
|
|
8859
8860
|
signal
|
|
8860
8861
|
});
|
|
8861
8862
|
if (contentResult.ok) {
|
|
8862
|
-
const { parseHTML } = await import("./dom-
|
|
8863
|
+
const { parseHTML } = await import("./dom-CawWi8fa.mjs");
|
|
8863
8864
|
const sections = parseHTML(contentResult.content).document.querySelectorAll("section");
|
|
8864
8865
|
for (const section of sections) {
|
|
8865
8866
|
const heading = section.querySelector("h2, h3, h4");
|
|
@@ -452,6 +452,10 @@ function getLogsDir() {
|
|
|
452
452
|
function getRemoteDir() {
|
|
453
453
|
return dirs.rootSubdir("remote", "data");
|
|
454
454
|
}
|
|
455
|
+
/** Get the puppeteer sandbox directory (~/.omp/puppeteer). */
|
|
456
|
+
function getPuppeteerDir() {
|
|
457
|
+
return dirs.rootSubdir("puppeteer", "cache");
|
|
458
|
+
}
|
|
455
459
|
/** Get DOCS_RS cache directory () */
|
|
456
460
|
function getDocsRsCacheDir() {
|
|
457
461
|
return dirs.rootSubdir("webcache", "cache");
|
|
@@ -5073,4 +5077,4 @@ function structuredCloneJSON(value) {
|
|
|
5073
5077
|
return JSON.parse(JSON.stringify(value));
|
|
5074
5078
|
}
|
|
5075
5079
|
//#endregion
|
|
5076
|
-
export {
|
|
5080
|
+
export { peekFile as $, formatAge as A, USER_AGENT as B, error as C, Cookie as D, $ as E, $envpos as F, getDocsRsCacheDir as G, getAgentDir as H, $flag as I, getLogsDir as J, getDocumentConversionCacheDir as K, $pickenv as L, formatCount as M, formatNumber as N, CookieMap as O, $env as P, isProbablyBinary as Q, isBunTestRuntime as R, debug as S, warn as T, getAutoQaDbPath as U, VERSION as V, getDebugLogPath as W, getRemoteDir as X, getPuppeteerDir as Y, getToolsDir as Z, parseStreamingJsonThrottled as _, readSseEvents as a, isEnotdir as b, combineSignals as c, $which as d, once as et, parseImageMetadata as f, parseStreamingJson as g, parseJsonWithRepair as h, readJsonl as i, formatBytes as j, installBunShim as k, exec as l, classifyJsonPrefix as m, wrapFetchForExtraCa as n, readSseJson as o, readImageMetadata as p, getInstallId as q, TempDir as r, Snowflake as s, structuredCloneJSON as t, untilAborted as tt, render as u, hasFsCode as v, time as w, parseFrontmatter as x, isEnoent as y, isTerminalHeadless as z };
|