@herbertgao/pi-extensions 2026.11.17 → 2026.11.19
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/CHANGELOG.md +25 -0
- package/README.md +3 -3
- package/THIRD_PARTY_NOTICES.md +2 -23
- package/node_modules/@estebanforge/pi-antigravity-bridge/CHANGELOG.md +956 -0
- package/node_modules/{pi-antigravity → @estebanforge/pi-antigravity-bridge}/LICENSE +1 -1
- package/node_modules/@estebanforge/pi-antigravity-bridge/README.md +240 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/extensions/index.ts +2117 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/package.json +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/connection.ts +644 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/driver.ts +1043 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/events.ts +323 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/home.ts +145 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/jsonrpc.ts +243 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/setup.ts +107 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/acp/usage-estimate.ts +61 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agents.ts +64 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-install.ts +93 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-paths.ts +30 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-setup.ts +81 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/agy-version.ts +289 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-detect.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-gate.ts +233 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/approval-hook.ts +325 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts-ui.ts +88 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/artifacts.ts +144 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/ask-tool.ts +1221 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/background-watch.ts +225 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/bridge-catalog.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/config.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/daily-log.ts +196 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/dialog-lock.ts +48 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/diff-render.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver-types.ts +168 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/driver.ts +907 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/engine-picker.ts +160 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/frame-guard.ts +38 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/handoff-toast.ts +21 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-registration.ts +376 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/mcp-server.ts +618 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/models.ts +404 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/native-tools.ts +104 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/parked-turn.ts +125 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/patch-cleanup.ts +523 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/poll-fold.ts +55 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/prompt-images.ts +92 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/provider.ts +2214 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/queued-messages.ts +152 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/quota-notice.ts +40 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/redact.ts +27 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sessions.ts +197 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/skills.ts +207 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-events.ts +161 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/stream-sanitizer.ts +180 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/subagent-roster.ts +245 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/sysprompt-agent.ts +130 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks-ui.ts +90 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/tasks.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/usage.ts +174 -0
- package/node_modules/@estebanforge/pi-antigravity-bridge/src/web-tools.ts +320 -0
- package/node_modules/@herbertgao/pi-cc-extensions/CHANGELOG.md +12 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/feature/shell/prompt-editor.ts +3 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/index.ts +7 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/agent-badge.ts +244 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/ccstyle-tool.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/grouping.ts +10 -3
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/tool/names.ts +18 -0
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +1 -1
- package/node_modules/@herbertgao/pi-inline-skill-commands/README.md +18 -0
- package/node_modules/@herbertgao/pi-inline-skill-commands/package.json +1 -1
- package/node_modules/@herbertgao/pi-inline-skill-commands/src/index.ts +80 -0
- package/node_modules/@herbertgao/pi-subagents/CHANGELOG.md +320 -102
- package/node_modules/@herbertgao/pi-subagents/SECURITY.md +2 -2
- package/node_modules/@herbertgao/pi-subagents/docs/rpc.md +240 -30
- package/node_modules/@herbertgao/pi-subagents/docs/translations.md +63 -0
- package/node_modules/@herbertgao/pi-subagents/docs/workflows.md +1 -1
- package/node_modules/@herbertgao/pi-subagents/package.json +4 -4
- package/node_modules/@herbertgao/pi-subagents/src/agent-file-toggle.ts +2 -0
- package/node_modules/@herbertgao/pi-subagents/src/agent-manager.ts +89 -6
- package/node_modules/@herbertgao/pi-subagents/src/agent-runner.ts +6 -2
- package/node_modules/@herbertgao/pi-subagents/src/agent-types.ts +27 -13
- package/node_modules/@herbertgao/pi-subagents/src/cache-retention.ts +39 -0
- package/node_modules/@herbertgao/pi-subagents/src/completion-outbox.ts +5 -0
- package/node_modules/@herbertgao/pi-subagents/src/cross-extension-rpc.ts +217 -41
- package/node_modules/@herbertgao/pi-subagents/src/custom-agents.ts +7 -0
- package/node_modules/@herbertgao/pi-subagents/src/group-join.ts +9 -0
- package/node_modules/@herbertgao/pi-subagents/src/index.ts +126 -93
- package/node_modules/@herbertgao/pi-subagents/src/mention-clone.ts +3 -2
- package/node_modules/@herbertgao/pi-subagents/src/settings.ts +21 -0
- package/node_modules/@herbertgao/pi-subagents/src/subagent-info.ts +115 -0
- package/node_modules/@herbertgao/pi-subagents/src/types.ts +11 -7
- package/node_modules/@herbertgao/pi-subagents/src/ui/agent-widget.ts +2 -3
- package/node_modules/@herbertgao/pi-subagents/src/ui/conversation-viewer.ts +1 -1
- package/node_modules/@herbertgao/pi-subagents/src/workflow/meta.ts +2 -2
- package/node_modules/@herbertgao/pi-subagents/src/workflow-info.ts +184 -0
- package/node_modules/pi-commandcode-provider/CHANGELOG.md +10 -0
- package/node_modules/pi-commandcode-provider/README.md +3 -2
- package/node_modules/pi-commandcode-provider/index.ts +120 -13
- package/node_modules/pi-commandcode-provider/package.json +4 -3
- package/node_modules/pi-commandcode-provider/src/commandcode-catalog.ts +11 -2
- package/node_modules/pi-commandcode-provider/src/pricing.ts +17 -1
- package/node_modules/pi-commandcode-provider/src/quota-command.ts +3 -2
- package/node_modules/pi-commandcode-provider/src/zdr.ts +163 -0
- package/package.json +12 -15
- package/node_modules/pi-antigravity/README.md +0 -298
- package/node_modules/pi-antigravity/docs/reader-guarantees.md +0 -35
- package/node_modules/pi-antigravity/package.json +0 -87
- package/node_modules/pi-antigravity/src/auth/accounts.ts +0 -327
- package/node_modules/pi-antigravity/src/auth/index.ts +0 -23
- package/node_modules/pi-antigravity/src/auth/oauth.ts +0 -445
- package/node_modules/pi-antigravity/src/client/client.ts +0 -602
- package/node_modules/pi-antigravity/src/client/enterprise.ts +0 -150
- package/node_modules/pi-antigravity/src/client/index.ts +0 -2
- package/node_modules/pi-antigravity/src/diagnostics/diagnostics.ts +0 -104
- package/node_modules/pi-antigravity/src/diagnostics/index.ts +0 -1
- package/node_modules/pi-antigravity/src/features/generate-image.ts +0 -132
- package/node_modules/pi-antigravity/src/features/google-search.ts +0 -72
- package/node_modules/pi-antigravity/src/features/read-url-content.ts +0 -124
- package/node_modules/pi-antigravity/src/image/image.ts +0 -427
- package/node_modules/pi-antigravity/src/image/index.ts +0 -1
- package/node_modules/pi-antigravity/src/image/native.ts +0 -69
- package/node_modules/pi-antigravity/src/index.ts +0 -547
- package/node_modules/pi-antigravity/src/models/discovery.ts +0 -176
- package/node_modules/pi-antigravity/src/models/grouping.ts +0 -487
- package/node_modules/pi-antigravity/src/models/index.ts +0 -3
- package/node_modules/pi-antigravity/src/models/models.ts +0 -647
- package/node_modules/pi-antigravity/src/search/index.ts +0 -1
- package/node_modules/pi-antigravity/src/search/search.ts +0 -967
- package/node_modules/pi-antigravity/src/stream/index.ts +0 -1
- package/node_modules/pi-antigravity/src/stream/stream.ts +0 -1961
- package/node_modules/pi-antigravity/src/types/enums.ts +0 -52
- package/node_modules/pi-antigravity/src/types/index.ts +0 -2
- package/node_modules/pi-antigravity/src/types/types.ts +0 -329
- package/node_modules/pi-antigravity/src/usage/index.ts +0 -1
- package/node_modules/pi-antigravity/src/usage/usage.ts +0 -437
- package/node_modules/pi-antigravity/src/utils/address.ts +0 -180
- package/node_modules/pi-antigravity/src/utils/credits.ts +0 -149
- package/node_modules/pi-antigravity/src/utils/html.ts +0 -31
- package/node_modules/pi-antigravity/src/utils/http.ts +0 -96
- package/node_modules/pi-antigravity/src/utils/index.ts +0 -5
- package/node_modules/pi-antigravity/src/utils/security.ts +0 -278
- package/node_modules/pi-antigravity/src/utils/text.ts +0 -66
- package/node_modules/pi-antigravity/src/utils/util.ts +0 -217
- package/node_modules/pi-antigravity/src/web-fetch/document.ts +0 -83
- package/node_modules/pi-antigravity/src/web-fetch/fences.ts +0 -24
- package/node_modules/pi-antigravity/src/web-fetch/header.ts +0 -97
- package/node_modules/pi-antigravity/src/web-fetch/index.ts +0 -3
- package/node_modules/pi-antigravity/src/web-fetch/inspect.ts +0 -328
- package/node_modules/pi-antigravity/src/web-fetch/limits.ts +0 -4
- package/node_modules/pi-antigravity/src/web-fetch/markdown.ts +0 -744
- package/node_modules/pi-antigravity/src/web-fetch/mdn.ts +0 -164
- package/node_modules/pi-antigravity/src/web-fetch/media.ts +0 -11
- package/node_modules/pi-antigravity/src/web-fetch/metadata.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/representation.ts +0 -93
- package/node_modules/pi-antigravity/src/web-fetch/save.ts +0 -71
- package/node_modules/pi-antigravity/src/web-fetch/sites.ts +0 -138
- package/node_modules/pi-antigravity/src/web-fetch/vendor.d.ts +0 -9
- package/node_modules/pi-antigravity/src/web-fetch/web-fetch.ts +0 -957
- package/node_modules/pi-antigravity/tsconfig.json +0 -21
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import { parseDocument } from "./document.js";
|
|
2
|
-
import { advanceFence, FENCE_LINE, type Fence } from "./fences.js";
|
|
3
|
-
import { repairText } from "../utils/text.js";
|
|
4
|
-
import { isRecord } from "../utils/util.js";
|
|
5
|
-
import { METADATA_LIMITS } from "./metadata.js";
|
|
6
|
-
import {
|
|
7
|
-
classifyCopyCompleteness,
|
|
8
|
-
extractPageMetadata,
|
|
9
|
-
htmlToMarkdown,
|
|
10
|
-
looksLikeHtml,
|
|
11
|
-
sanitizeMetadataText,
|
|
12
|
-
} from "./markdown.js";
|
|
13
|
-
|
|
14
|
-
export type ContentAssessment = "readable" | "empty" | "suspected-shell" | "suspected-access-wall";
|
|
15
|
-
|
|
16
|
-
export type PageInspection = {
|
|
17
|
-
rendered: string;
|
|
18
|
-
completeness: "complete" | "incomplete" | "unknown";
|
|
19
|
-
assessment: ContentAssessment;
|
|
20
|
-
notes?: string[];
|
|
21
|
-
metadata: ReturnType<typeof extractPageMetadata> & {
|
|
22
|
-
author?: string;
|
|
23
|
-
published?: string;
|
|
24
|
-
language?: string;
|
|
25
|
-
};
|
|
26
|
-
alternates: Array<{
|
|
27
|
-
url: string;
|
|
28
|
-
type: "text/markdown" | "application/json";
|
|
29
|
-
language?: string;
|
|
30
|
-
}>;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
function normalizedWallHeading(value: string): string {
|
|
34
|
-
return value
|
|
35
|
-
.replace(/\s*[|•–—-]\s*cloudflare\s*$/i, "")
|
|
36
|
-
.replace(/\s+/g, " ")
|
|
37
|
-
.trim();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Headings that are a wall on their own. They stay exact: "429 Too Many Requests"
|
|
42
|
-
* is also the title of a real article about that status, and "Forbidden error
|
|
43
|
-
* handling" is a real article title.
|
|
44
|
-
*/
|
|
45
|
-
const ACCESS_WALL_HEADINGS = [
|
|
46
|
-
"forbidden",
|
|
47
|
-
"403 forbidden",
|
|
48
|
-
"unauthorized",
|
|
49
|
-
"401 unauthorized",
|
|
50
|
-
"access denied",
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Openings of the interstitials that stand in for an article. The heading of a real
|
|
55
|
-
* wall usually carries more than the phrase itself ("Please enable JavaScript to
|
|
56
|
-
* continue"), so a phrase that opens the heading marks a wall.
|
|
57
|
-
*/
|
|
58
|
-
const ACCESS_WALL_OPENINGS = [
|
|
59
|
-
"just a moment",
|
|
60
|
-
"just a second",
|
|
61
|
-
"one more step",
|
|
62
|
-
"robot or human",
|
|
63
|
-
"please wait while we verify",
|
|
64
|
-
"access to this page has been denied",
|
|
65
|
-
"you don't have permission",
|
|
66
|
-
"verifying your browser",
|
|
67
|
-
"too many requests",
|
|
68
|
-
"verify you are human",
|
|
69
|
-
"verifying you are human",
|
|
70
|
-
"attention required",
|
|
71
|
-
"you have been blocked",
|
|
72
|
-
"sorry, you have been blocked",
|
|
73
|
-
"checking your browser",
|
|
74
|
-
"security check",
|
|
75
|
-
"enable javascript",
|
|
76
|
-
"please enable javascript",
|
|
77
|
-
"javascript is required",
|
|
78
|
-
"javascript required",
|
|
79
|
-
"are you a robot",
|
|
80
|
-
"unusual traffic",
|
|
81
|
-
"request blocked",
|
|
82
|
-
"rate limited",
|
|
83
|
-
"you are being rate limited",
|
|
84
|
-
];
|
|
85
|
-
|
|
86
|
-
/** Sign-in pages read like a wall, but an article title may also start with one. */
|
|
87
|
-
const ACCESS_WALL_SIGN_IN_OPENINGS = ["sign in", "log in"];
|
|
88
|
-
|
|
89
|
-
/** How much text may follow the wall phrase before the heading is an article title. */
|
|
90
|
-
const ACCESS_WALL_TAIL = 40;
|
|
91
|
-
const ACCESS_WALL_SIGN_IN_TAIL = 24;
|
|
92
|
-
|
|
93
|
-
/** A short block/sign-in heading, not an article that happens to discuss one. */
|
|
94
|
-
function isAccessWallHeading(value: string | undefined): boolean {
|
|
95
|
-
if (!value) return false;
|
|
96
|
-
const text = normalizedWallHeading(value).toLowerCase();
|
|
97
|
-
if (!text) return false;
|
|
98
|
-
if (ACCESS_WALL_HEADINGS.includes(text.replace(/[.!…\s]*$/, ""))) return true;
|
|
99
|
-
const opens = (opening: string, tail: number) =>
|
|
100
|
-
text.startsWith(opening) &&
|
|
101
|
-
(text.length - opening.length <= tail || /browser|human|verify|access/.test(text));
|
|
102
|
-
return (
|
|
103
|
-
ACCESS_WALL_OPENINGS.some((opening) => opens(opening, ACCESS_WALL_TAIL)) ||
|
|
104
|
-
ACCESS_WALL_SIGN_IN_OPENINGS.some((opening) => opens(opening, ACCESS_WALL_SIGN_IN_TAIL))
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** A wall heading alone cannot overrule substantial article content. */
|
|
109
|
-
function hasArticleContent(rendered: string): boolean {
|
|
110
|
-
const body = rendered.replace(/^#{1,6} .*$/gm, "").trim();
|
|
111
|
-
return (
|
|
112
|
-
(body.length >= 500 && /[.!?:]/.test(body)) ||
|
|
113
|
-
(body.length >= 80 && /\b(?:HTTP|status code|response|client|server)\b/i.test(body))
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function isLoadingShell(rendered: string): boolean {
|
|
118
|
-
const visible = rendered.replace(/^#{1,6} .*$/gm, "").trim();
|
|
119
|
-
return /^(?:loading|please wait|redirecting|initializing)[.!…\s]*$/i.test(visible);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/** Match structured data to this page without treating fragments as separate pages. */
|
|
123
|
-
function pageIdentity(value: unknown, baseUrl: string): string | undefined {
|
|
124
|
-
if (isRecord(value)) value = value["@id"];
|
|
125
|
-
if (typeof value !== "string") return undefined;
|
|
126
|
-
try {
|
|
127
|
-
const url = new URL(value, baseUrl);
|
|
128
|
-
url.hash = "";
|
|
129
|
-
return url.href;
|
|
130
|
-
} catch {
|
|
131
|
-
return undefined;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/** Inspect data before destructive Markdown cleanup; never execute page scripts. */
|
|
136
|
-
export function inspectPage(content: string, url: string, contentType?: string): PageInspection {
|
|
137
|
-
if (!looksLikeHtml(content, contentType)) {
|
|
138
|
-
const rendered = repairText(content).trim();
|
|
139
|
-
let title: string | undefined;
|
|
140
|
-
let fence: Fence | undefined;
|
|
141
|
-
for (const line of rendered.split("\n")) {
|
|
142
|
-
const previous = fence;
|
|
143
|
-
fence = advanceFence(fence, line);
|
|
144
|
-
if (!previous && !fence && !FENCE_LINE.test(line)) {
|
|
145
|
-
title = /^ {0,3}# +(.+?)(?: +#+)?\s*$/.exec(line)?.[1];
|
|
146
|
-
if (title) break;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return {
|
|
150
|
-
rendered,
|
|
151
|
-
completeness: "unknown",
|
|
152
|
-
assessment: rendered ? "readable" : "empty",
|
|
153
|
-
metadata: { title: sanitizeMetadataText(title, 300) },
|
|
154
|
-
alternates: [],
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
const document = parseDocument(content);
|
|
158
|
-
const metadata: PageInspection["metadata"] = extractPageMetadata(content, document);
|
|
159
|
-
metadata.language = sanitizeMetadataText(document.documentElement.lang || undefined, 50);
|
|
160
|
-
const nodes: Record<string, unknown>[] = [];
|
|
161
|
-
let budget = 256_000;
|
|
162
|
-
for (const script of Array.from(
|
|
163
|
-
document.querySelectorAll('script[type="application/ld+json"]'),
|
|
164
|
-
).slice(0, 16)) {
|
|
165
|
-
const text = script.textContent ?? "";
|
|
166
|
-
budget -= text.length;
|
|
167
|
-
if (budget < 0) break;
|
|
168
|
-
try {
|
|
169
|
-
const value: unknown = JSON.parse(text);
|
|
170
|
-
const roots = Array.isArray(value) ? value : [value];
|
|
171
|
-
for (const root of roots) {
|
|
172
|
-
if (!isRecord(root)) continue;
|
|
173
|
-
nodes.push(root);
|
|
174
|
-
if (Array.isArray(root["@graph"])) nodes.push(...root["@graph"].filter(isRecord));
|
|
175
|
-
}
|
|
176
|
-
} catch {
|
|
177
|
-
// Invalid or truncated structured data is not evidence.
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const identity = pageIdentity(url, url);
|
|
181
|
-
const article = nodes.find((node) => {
|
|
182
|
-
const types = Array.isArray(node["@type"]) ? node["@type"] : [node["@type"]];
|
|
183
|
-
return (
|
|
184
|
-
types.some(
|
|
185
|
-
(type) =>
|
|
186
|
-
typeof type === "string" && /^(Article|NewsArticle|BlogPosting|TechArticle)$/.test(type),
|
|
187
|
-
) &&
|
|
188
|
-
[node.url, node.mainEntityOfPage, node["@id"]].some(
|
|
189
|
-
(value) => pageIdentity(value, url) === identity,
|
|
190
|
-
)
|
|
191
|
-
);
|
|
192
|
-
});
|
|
193
|
-
if (article) {
|
|
194
|
-
const text = (value: unknown, field: keyof typeof METADATA_LIMITS) =>
|
|
195
|
-
typeof value === "string" && value.trim()
|
|
196
|
-
? sanitizeMetadataText(value, METADATA_LIMITS[field])
|
|
197
|
-
: undefined;
|
|
198
|
-
metadata.title ??= text(article.headline, "title");
|
|
199
|
-
metadata.description ??= text(article.description, "description");
|
|
200
|
-
metadata.updated ??= text(article.dateModified, "updated");
|
|
201
|
-
metadata.published = text(article.datePublished, "published");
|
|
202
|
-
metadata.language ??= text(article.inLanguage, "language");
|
|
203
|
-
const author: unknown = Array.isArray(article.author) ? article.author[0] : article.author;
|
|
204
|
-
const person: unknown =
|
|
205
|
-
isRecord(author) && !author.name && typeof author["@id"] === "string"
|
|
206
|
-
? nodes.find((node) => node["@id"] === author["@id"])
|
|
207
|
-
: author;
|
|
208
|
-
metadata.author = isRecord(person) ? text(person.name, "author") : text(person, "author");
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const alternates: PageInspection["alternates"] = [];
|
|
212
|
-
for (const link of Array.from(document.querySelectorAll("link[href][type]"))) {
|
|
213
|
-
if (!(link.getAttribute("rel") ?? "").toLowerCase().split(/\s+/).includes("alternate"))
|
|
214
|
-
continue;
|
|
215
|
-
const type = link.getAttribute("type")?.split(";")[0].toLowerCase().trim();
|
|
216
|
-
if (type !== "text/markdown" && type !== "application/json") continue;
|
|
217
|
-
try {
|
|
218
|
-
const alternate = new URL(link.getAttribute("href")!, url);
|
|
219
|
-
if (alternate.origin !== new URL(url).origin || alternate.username || alternate.password)
|
|
220
|
-
continue;
|
|
221
|
-
if (/\.pdf$/i.test(alternate.pathname)) continue;
|
|
222
|
-
alternate.hash = "";
|
|
223
|
-
if (alternate.href === identity || alternates.some((item) => item.url === alternate.href))
|
|
224
|
-
continue;
|
|
225
|
-
const language = sanitizeMetadataText(
|
|
226
|
-
link.getAttribute("hreflang") ?? undefined,
|
|
227
|
-
35,
|
|
228
|
-
)?.toLowerCase();
|
|
229
|
-
const declaredLanguage = language && language !== "x-default" ? language : undefined;
|
|
230
|
-
alternates.push({
|
|
231
|
-
url: alternate.href,
|
|
232
|
-
type,
|
|
233
|
-
...(declaredLanguage ? { language: declaredLanguage } : {}),
|
|
234
|
-
});
|
|
235
|
-
} catch {
|
|
236
|
-
// Ignore invalid URLs, including malformed base-relative references.
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
const pageLanguage = metadata.language?.split("-")[0].toLowerCase();
|
|
240
|
-
const sameLanguage = pageLanguage
|
|
241
|
-
? alternates.filter((item) => !item.language || item.language.split("-")[0] === pageLanguage)
|
|
242
|
-
: alternates;
|
|
243
|
-
const preferred = sameLanguage.length ? sameLanguage : alternates;
|
|
244
|
-
preferred.sort((a, b) => Number(b.type === "text/markdown") - Number(a.type === "text/markdown"));
|
|
245
|
-
const appScript = Boolean(document.querySelector('script[src], script[type="module"]'));
|
|
246
|
-
const rendered = htmlToMarkdown(content, { baseUrl: url, document });
|
|
247
|
-
const heading = /^# +(.+)$/m.exec(rendered)?.[1] || "";
|
|
248
|
-
// A page that loads an application script and shows nothing else is a shell.
|
|
249
|
-
const completeness = classifyCopyCompleteness(content);
|
|
250
|
-
// A page that loads application JavaScript and shows only a placeholder is a shell.
|
|
251
|
-
// A cut-off copy holding only a heading has lost its body; report it as empty.
|
|
252
|
-
const bodyMissing =
|
|
253
|
-
!rendered.trim() ||
|
|
254
|
-
(completeness === "incomplete" && !rendered.replace(/^#{1,6} .*$/gm, "").trim());
|
|
255
|
-
const assessment: ContentAssessment = bodyMissing
|
|
256
|
-
? // A copy that ends before the content is cut off, not an application shell.
|
|
257
|
-
appScript && completeness !== "incomplete"
|
|
258
|
-
? "suspected-shell"
|
|
259
|
-
: "empty"
|
|
260
|
-
: isAccessWallHeading(heading || metadata.title) &&
|
|
261
|
-
/\b(?:check(?:ing)?|verif\w*|captcha|blocked|denied|permission|enable javascript|sign in|log in)\b/i.test(
|
|
262
|
-
rendered.replace(/^#{1,6} .*$/gm, ""),
|
|
263
|
-
) &&
|
|
264
|
-
!hasArticleContent(rendered)
|
|
265
|
-
? "suspected-access-wall"
|
|
266
|
-
: appScript && isLoadingShell(rendered)
|
|
267
|
-
? "suspected-shell"
|
|
268
|
-
: "readable";
|
|
269
|
-
return {
|
|
270
|
-
rendered,
|
|
271
|
-
completeness,
|
|
272
|
-
assessment,
|
|
273
|
-
metadata,
|
|
274
|
-
alternates: preferred.slice(0, 8),
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* Inspection of a source the converter will not take on. Raw mode returns the crawled
|
|
280
|
-
* source as it is, so the page's size limits the answer, not the read.
|
|
281
|
-
*/
|
|
282
|
-
export function inspectUnconverted(content: string, reason: string): PageInspection {
|
|
283
|
-
return {
|
|
284
|
-
rendered: "",
|
|
285
|
-
completeness: classifyCopyCompleteness(content),
|
|
286
|
-
assessment: content.trim() ? "readable" : "empty",
|
|
287
|
-
notes: [`Not converted: ${reason}`],
|
|
288
|
-
metadata: {},
|
|
289
|
-
alternates: [],
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/** Decode only explicit article-body JSON shapes from an advertised representation. */
|
|
294
|
-
export function articleRepresentation(content: string, articleUrl: string): string | undefined {
|
|
295
|
-
let value: unknown;
|
|
296
|
-
try {
|
|
297
|
-
value = JSON.parse(content);
|
|
298
|
-
} catch {
|
|
299
|
-
return undefined;
|
|
300
|
-
}
|
|
301
|
-
if (!isRecord(value)) return undefined;
|
|
302
|
-
// GitHub Docs article API.
|
|
303
|
-
if (
|
|
304
|
-
isRecord(value.meta) &&
|
|
305
|
-
value.meta.documentType === "article" &&
|
|
306
|
-
typeof value.body === "string" &&
|
|
307
|
-
Array.isArray(value.meta.breadcrumbs)
|
|
308
|
-
) {
|
|
309
|
-
const current: unknown = value.meta.breadcrumbs.at(-1);
|
|
310
|
-
if (
|
|
311
|
-
isRecord(current) &&
|
|
312
|
-
pageIdentity(current.href, articleUrl) === pageIdentity(articleUrl, articleUrl)
|
|
313
|
-
)
|
|
314
|
-
return value.body;
|
|
315
|
-
}
|
|
316
|
-
// WordPress single-post REST representation (not an index or oEmbed summary).
|
|
317
|
-
if (
|
|
318
|
-
typeof value.id === "number" &&
|
|
319
|
-
typeof value.link === "string" &&
|
|
320
|
-
pageIdentity(value.link, articleUrl) === pageIdentity(articleUrl, articleUrl) &&
|
|
321
|
-
isRecord(value.content) &&
|
|
322
|
-
value.content.protected !== true &&
|
|
323
|
-
typeof value.content.rendered === "string"
|
|
324
|
-
) {
|
|
325
|
-
return value.content.rendered;
|
|
326
|
-
}
|
|
327
|
-
return undefined;
|
|
328
|
-
}
|