@herbertgao/pi-extensions 2026.10.10 → 2026.10.11
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.md +10 -8
- package/THIRD_PARTY_NOTICES.md +2 -2
- package/node_modules/@herbertgao/pi-cc-extensions/README.en.md +3 -0
- package/node_modules/@herbertgao/pi-cc-extensions/README.md +3 -0
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/config.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/config/panel.ts +3 -3
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/compact-mode.ts +126 -42
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/interaction.ts +24 -6
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/scroll.ts +69 -16
- package/node_modules/@herbertgao/pi-cc-extensions/extensions/renderer/mouse/sticky-prompt.ts +1 -1
- package/node_modules/@herbertgao/pi-cc-extensions/package.json +4 -4
- package/node_modules/@herbertgao/sol-pi/README.md +7 -1
- package/node_modules/@herbertgao/sol-pi/docs/compatibility.md +28 -4
- package/node_modules/@herbertgao/sol-pi/docs/configuration.md +17 -4
- package/node_modules/@herbertgao/sol-pi/package.json +1 -1
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/action-fusion/index.ts +35 -25
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/action-fusion/then-run.ts +95 -26
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/evidence-preserving-reducer/candidate.ts +39 -2
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/evidence-preserving-reducer/index.ts +24 -0
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/observation-pack/index.ts +12 -7
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/extension.ts +138 -130
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/projection.ts +88 -14
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/extensions/online-context-compact/tools.ts +9 -0
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/index.ts +14 -5
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/shell-options.ts +22 -0
- package/node_modules/@herbertgao/sol-pi/src/sol-pi/tui.ts +11 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/answer-channel.ts +109 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/ask-user-question.ts +117 -71
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/hosts.md +2 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/keyboard.md +3 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/startup-performance.md +83 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/docs/tool-schema.md +74 -5
- package/node_modules/@juicesharp/rpiv-ask-user-question/events.ts +84 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/index.ts +10 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/package.json +4 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/presentation.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/reconcile.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/rpc-fallback.ts +5 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/build-questionnaire.ts +19 -19
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/i18n-bridge.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/key-router.ts +7 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/questionnaire-session.ts +10 -10
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/row-intent.ts +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/contract.ts +6 -6
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/derivations.ts +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/focus.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/selectors/projections.ts +9 -9
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/state-reducer.ts +5 -5
- package/node_modules/@juicesharp/rpiv-ask-user-question/state/state.ts +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/external-answer.ts +125 -0
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/format-answer.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/normalize-params.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/response-envelope.ts +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/types.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/tool/validate-questionnaire.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/component-binding.ts +4 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/multi-select-view.ts +4 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/option-list-view.ts +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/markdown-content-cache.ts +3 -3
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-block-renderer.ts +5 -5
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-layout-decider.ts +3 -3
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/preview/preview-pane.ts +10 -10
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/submit-picker.ts +2 -2
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/tab-bar.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/components/wrapping-select.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-builder.ts +9 -9
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/dialog-copy.ts +1 -1
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/props-adapter.ts +8 -8
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/tab-components.ts +4 -4
- package/node_modules/@juicesharp/rpiv-ask-user-question/view/tab-content-strategy.ts +10 -10
- package/node_modules/@narumitw/pi-btw/dist/index.ts +3 -0
- package/node_modules/@narumitw/pi-btw/dist/index.ts.map +2 -2
- package/node_modules/@narumitw/pi-btw/package.json +4 -4
- package/node_modules/@narumitw/pi-btw/src/fullscreen-ui.ts +6 -0
- package/node_modules/@narumitw/pi-btw/src/keybindings.ts +1 -1
- package/node_modules/@narumitw/pi-caffeinate/dist/index.ts +1 -0
- package/node_modules/@narumitw/pi-caffeinate/dist/index.ts.map +2 -2
- package/node_modules/@narumitw/pi-caffeinate/package.json +3 -3
- package/node_modules/@narumitw/pi-caffeinate/src/inhibitor-process.ts +1 -0
- package/node_modules/pi-antigravity/README.md +6 -2
- package/node_modules/pi-antigravity/package.json +2 -2
- package/node_modules/pi-antigravity/src/client/client.ts +44 -52
- package/node_modules/pi-antigravity/src/index.ts +13 -0
- package/node_modules/pi-antigravity/src/models/discovery.ts +25 -2
- package/node_modules/pi-antigravity/src/models/grouping.ts +107 -68
- package/node_modules/pi-antigravity/src/models/models.ts +10 -0
- package/node_modules/pi-antigravity/src/search/search.ts +581 -43
- package/node_modules/pi-antigravity/src/stream/stream.ts +53 -13
- package/node_modules/pi-antigravity/src/types/types.ts +13 -0
- package/node_modules/pi-antigravity/src/usage/usage.ts +11 -3
- package/node_modules/pi-web-access/CHANGELOG.md +21 -0
- package/node_modules/pi-web-access/README.md +22 -7
- package/node_modules/pi-web-access/credential-source.ts +54 -4
- package/node_modules/pi-web-access/curator-page.ts +3 -1
- package/node_modules/pi-web-access/curator-server.ts +1 -0
- package/node_modules/pi-web-access/deepseek.ts +204 -0
- package/node_modules/pi-web-access/dist/index.js +927 -642
- package/node_modules/pi-web-access/dist/mcp-cli.js +877 -615
- package/node_modules/pi-web-access/gemini-adc.ts +48 -1
- package/node_modules/pi-web-access/gemini-search.ts +8 -4
- package/node_modules/pi-web-access/index.ts +16 -1
- package/node_modules/pi-web-access/package.json +1 -1
- package/node_modules/pi-web-access/page-query.ts +12 -6
- package/node_modules/pi-web-access/query-rewrite.ts +16 -13
- package/node_modules/pi-web-access/summary-review.ts +16 -6
- package/node_modules/pi-web-access/utils.ts +3 -0
- package/node_modules/pi-web-access/web-tool-core.ts +2 -0
- package/package.json +9 -9
|
@@ -88,10 +88,11 @@ var init_activity = __esm({
|
|
|
88
88
|
});
|
|
89
89
|
|
|
90
90
|
// credential-source.ts
|
|
91
|
-
import { exec } from "node:child_process";
|
|
91
|
+
import { exec, execFile } from "node:child_process";
|
|
92
|
+
import { existsSync } from "node:fs";
|
|
92
93
|
import { promisify } from "node:util";
|
|
93
|
-
function redactCredential(
|
|
94
|
-
return credential ?
|
|
94
|
+
function redactCredential(text5, credential) {
|
|
95
|
+
return credential ? text5.split(credential).join("[redacted]") : text5;
|
|
95
96
|
}
|
|
96
97
|
function normalize(value) {
|
|
97
98
|
if (typeof value !== "string") return null;
|
|
@@ -123,15 +124,34 @@ function escapedSource(source) {
|
|
|
123
124
|
function isMalformedExplicitSource(source) {
|
|
124
125
|
return source.startsWith("$") && escapedSource(source) === null && explicitEnvironmentName(source) === null;
|
|
125
126
|
}
|
|
127
|
+
async function bashOnPath(signal, timeoutMs) {
|
|
128
|
+
try {
|
|
129
|
+
const { stdout } = await execFileAsync("where", ["bash.exe"], { encoding: "utf8", signal, timeout: timeoutMs, windowsHide: true });
|
|
130
|
+
return stdout.trim().split(/\r?\n/)[0] || null;
|
|
131
|
+
} catch {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
async function findWindowsBash(environment, exists, findOnPath) {
|
|
136
|
+
for (const root of [environment.ProgramFiles, environment["ProgramFiles(x86)"]]) {
|
|
137
|
+
const candidate = root ? `${root}\\Git\\bin\\bash.exe` : null;
|
|
138
|
+
if (candidate && exists(candidate)) return candidate;
|
|
139
|
+
}
|
|
140
|
+
const found = await findOnPath();
|
|
141
|
+
return found && exists(found) && !LEGACY_WSL_BASH.test(found.replace(/\//g, "\\")) ? found : null;
|
|
142
|
+
}
|
|
126
143
|
async function defaultRunCommand(command, options) {
|
|
127
|
-
const
|
|
144
|
+
const deadline = Date.now() + options.timeoutMs;
|
|
145
|
+
const bash = process.platform === "win32" ? await findWindowsBash(process.env, existsSync, () => bashOnPath(options.signal, options.timeoutMs)) : null;
|
|
146
|
+
const execOptions = {
|
|
128
147
|
encoding: "utf8",
|
|
129
148
|
env: options.environment,
|
|
130
149
|
maxBuffer: options.maxOutputBytes + 1,
|
|
131
150
|
signal: options.signal,
|
|
132
|
-
timeout:
|
|
151
|
+
timeout: Math.max(1, deadline - Date.now()),
|
|
133
152
|
windowsHide: true
|
|
134
|
-
}
|
|
153
|
+
};
|
|
154
|
+
const result = bash ? await execFileAsync(bash, ["-c", command], execOptions) : await execAsync(command, execOptions);
|
|
135
155
|
return { stdout: result.stdout };
|
|
136
156
|
}
|
|
137
157
|
function commandFailureCategory(error, signal) {
|
|
@@ -190,14 +210,16 @@ async function resolveCredential(options) {
|
|
|
190
210
|
}
|
|
191
211
|
return normalize(options.environmentValue) ?? source;
|
|
192
212
|
}
|
|
193
|
-
var execAsync, COMMAND_TIMEOUT_MS, MAX_CREDENTIAL_BYTES, ENV_SOURCE, OP_SESSION_NAME, COMMAND_ENVIRONMENT_NAMES, CredentialResolutionError;
|
|
213
|
+
var execAsync, execFileAsync, COMMAND_TIMEOUT_MS, MAX_CREDENTIAL_BYTES, ENV_SOURCE, OP_SESSION_NAME, LEGACY_WSL_BASH, COMMAND_ENVIRONMENT_NAMES, CredentialResolutionError;
|
|
194
214
|
var init_credential_source = __esm({
|
|
195
215
|
"credential-source.ts"() {
|
|
196
216
|
execAsync = promisify(exec);
|
|
217
|
+
execFileAsync = promisify(execFile);
|
|
197
218
|
COMMAND_TIMEOUT_MS = 5e3;
|
|
198
219
|
MAX_CREDENTIAL_BYTES = 16384;
|
|
199
220
|
ENV_SOURCE = /^\$(?:([A-Za-z_][A-Za-z0-9_]*)|\{([A-Za-z_][A-Za-z0-9_]*)\})$/;
|
|
200
221
|
OP_SESSION_NAME = /^OP_SESSION_[A-Za-z0-9_]+$/;
|
|
222
|
+
LEGACY_WSL_BASH = /^[a-z]:\\windows\\(?:system32|sysnative)\\bash\.exe$/i;
|
|
201
223
|
COMMAND_ENVIRONMENT_NAMES = [
|
|
202
224
|
"HOME",
|
|
203
225
|
"USER",
|
|
@@ -214,7 +236,22 @@ var init_credential_source = __esm({
|
|
|
214
236
|
"DBUS_SESSION_BUS_ADDRESS",
|
|
215
237
|
"SSH_AUTH_SOCK",
|
|
216
238
|
"WSL_DISTRO_NAME",
|
|
217
|
-
"WSL_INTEROP"
|
|
239
|
+
"WSL_INTEROP",
|
|
240
|
+
// Git Bash derives $HOME from USERPROFILE, and Windows children need SystemRoot for networking and crypto.
|
|
241
|
+
"SystemRoot",
|
|
242
|
+
"windir",
|
|
243
|
+
"ComSpec",
|
|
244
|
+
"PATHEXT",
|
|
245
|
+
"USERPROFILE",
|
|
246
|
+
"HOMEDRIVE",
|
|
247
|
+
"HOMEPATH",
|
|
248
|
+
"APPDATA",
|
|
249
|
+
"LOCALAPPDATA",
|
|
250
|
+
"TEMP",
|
|
251
|
+
"TMP",
|
|
252
|
+
"ProgramData",
|
|
253
|
+
"ProgramFiles",
|
|
254
|
+
"ProgramFiles(x86)"
|
|
218
255
|
];
|
|
219
256
|
CredentialResolutionError = class extends Error {
|
|
220
257
|
provider;
|
|
@@ -233,7 +270,7 @@ var init_credential_source = __esm({
|
|
|
233
270
|
// utils.ts
|
|
234
271
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
235
272
|
import { spawn } from "node:child_process";
|
|
236
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
273
|
+
import { existsSync as existsSync2, readFileSync } from "node:fs";
|
|
237
274
|
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
238
275
|
import { isIP } from "node:net";
|
|
239
276
|
import { homedir, hostname, tmpdir } from "node:os";
|
|
@@ -245,15 +282,15 @@ function getWebSearchConfigDir() {
|
|
|
245
282
|
const xdgConfigHome = process.env.XDG_CONFIG_HOME;
|
|
246
283
|
if (xdgConfigHome) {
|
|
247
284
|
const xdgDir = join(xdgConfigHome, "pi");
|
|
248
|
-
if (
|
|
285
|
+
if (existsSync2(join(xdgDir, "web-search.json"))) return cachedWebSearchConfigDir = xdgDir;
|
|
249
286
|
const legacyDir2 = join(homedir(), ".pi");
|
|
250
|
-
if (
|
|
287
|
+
if (existsSync2(join(legacyDir2, "web-search.json"))) return cachedWebSearchConfigDir = legacyDir2;
|
|
251
288
|
return cachedWebSearchConfigDir = xdgDir;
|
|
252
289
|
}
|
|
253
290
|
const agentDir = join(homedir(), ".pi", "agent");
|
|
254
|
-
if (
|
|
291
|
+
if (existsSync2(join(agentDir, "web-search.json"))) return cachedWebSearchConfigDir = agentDir;
|
|
255
292
|
const legacyDir = join(homedir(), ".pi");
|
|
256
|
-
if (
|
|
293
|
+
if (existsSync2(join(legacyDir, "web-search.json"))) return cachedWebSearchConfigDir = legacyDir;
|
|
257
294
|
return cachedWebSearchConfigDir = agentDir;
|
|
258
295
|
}
|
|
259
296
|
function getWebSearchConfigPath() {
|
|
@@ -346,8 +383,8 @@ function isTimeoutError(err) {
|
|
|
346
383
|
const message = err.message ?? "";
|
|
347
384
|
return name === "AbortError" || code === "ETIMEDOUT" || message.toLowerCase().includes("timed out");
|
|
348
385
|
}
|
|
349
|
-
function trimErrorText(
|
|
350
|
-
return
|
|
386
|
+
function trimErrorText(text5) {
|
|
387
|
+
return text5.replace(/\s+/g, " ").trim().slice(0, 200);
|
|
351
388
|
}
|
|
352
389
|
function mapFfmpegError(err) {
|
|
353
390
|
const { code, stderr, message } = readExecError(err);
|
|
@@ -385,7 +422,7 @@ function redactProxyUrl(value) {
|
|
|
385
422
|
function loadConfiguredProxy() {
|
|
386
423
|
let configured;
|
|
387
424
|
const path = getWebSearchConfigPath();
|
|
388
|
-
if (
|
|
425
|
+
if (existsSync2(path)) {
|
|
389
426
|
let raw;
|
|
390
427
|
try {
|
|
391
428
|
raw = JSON.parse(readFileSync(path, "utf-8"));
|
|
@@ -433,6 +470,8 @@ function noProxyEntryMatches(hostname2, entry) {
|
|
|
433
470
|
function isProxyBypassedUrl(url) {
|
|
434
471
|
const hostname2 = url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
|
|
435
472
|
if (hostname2 === "localhost" || hostname2.endsWith(".localhost") || hostname2 === "127.0.0.1" || hostname2 === "::1") return true;
|
|
473
|
+
const gceHost = process.env.GCE_METADATA_HOST?.trim().replace(/^https?:\/\//i, "").replace(/\/+$/, "");
|
|
474
|
+
if (hostname2 === "metadata.google.internal" || hostname2 === "169.254.169.254" || gceHost && noProxyEntryMatches(hostname2, gceHost)) return true;
|
|
436
475
|
const noProxy = process.env.NO_PROXY || process.env.no_proxy;
|
|
437
476
|
if (noProxy && noProxy.split(",").some((entry) => noProxyEntryMatches(hostname2, entry.trim()))) return true;
|
|
438
477
|
return false;
|
|
@@ -658,13 +697,13 @@ var init_utils = __esm({
|
|
|
658
697
|
});
|
|
659
698
|
|
|
660
699
|
// gemini-adc.ts
|
|
661
|
-
import { existsSync as
|
|
700
|
+
import { existsSync as existsSync3, readFileSync as readFileSync2 } from "node:fs";
|
|
662
701
|
import { createSign } from "node:crypto";
|
|
663
702
|
import { homedir as homedir2 } from "node:os";
|
|
664
703
|
import { join as join2 } from "node:path";
|
|
665
704
|
function loadConfig() {
|
|
666
705
|
if (cachedConfig) return cachedConfig;
|
|
667
|
-
if (!
|
|
706
|
+
if (!existsSync3(CONFIG_PATH)) {
|
|
668
707
|
cachedConfig = {};
|
|
669
708
|
return cachedConfig;
|
|
670
709
|
}
|
|
@@ -701,6 +740,21 @@ function getAdcLocation() {
|
|
|
701
740
|
function getAdcPath() {
|
|
702
741
|
return process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim() || DEFAULT_ADC_PATH;
|
|
703
742
|
}
|
|
743
|
+
function hasExplicitAdcPath() {
|
|
744
|
+
return !!process.env.GOOGLE_APPLICATION_CREDENTIALS?.trim();
|
|
745
|
+
}
|
|
746
|
+
function getMetadataHost() {
|
|
747
|
+
return (process.env.GCE_METADATA_HOST?.trim() || DEFAULT_METADATA_HOST).replace(/^https?:\/\//i, "").replace(/\/+$/, "");
|
|
748
|
+
}
|
|
749
|
+
function isOnGcp() {
|
|
750
|
+
if (process.env.METADATA_SERVER_DETECTION?.trim().toLowerCase() === "none") return false;
|
|
751
|
+
if (process.env.GCE_METADATA_HOST?.trim()) return true;
|
|
752
|
+
try {
|
|
753
|
+
return /Google/.test(readFileSync2("/sys/class/dmi/id/bios_vendor", "utf8"));
|
|
754
|
+
} catch {
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
}
|
|
704
758
|
function getVertexApiBase(project, location) {
|
|
705
759
|
return `${VERTEX_HOST}/${VERTEX_API_VERSION}/projects/${encodeURIComponent(project)}/locations/${encodeURIComponent(location)}/publishers/google`;
|
|
706
760
|
}
|
|
@@ -744,10 +798,10 @@ function parseAdcFile(raw) {
|
|
|
744
798
|
}
|
|
745
799
|
return { type };
|
|
746
800
|
}
|
|
747
|
-
function parseTokenExchangeResponse(
|
|
801
|
+
function parseTokenExchangeResponse(text5, context) {
|
|
748
802
|
let raw;
|
|
749
803
|
try {
|
|
750
|
-
raw = JSON.parse(
|
|
804
|
+
raw = JSON.parse(text5);
|
|
751
805
|
} catch (err) {
|
|
752
806
|
const message = err instanceof Error ? err.message : String(err);
|
|
753
807
|
throw new Error(`${context} returned invalid JSON: ${message}`);
|
|
@@ -764,7 +818,7 @@ function parseTokenExchangeResponse(text4, context) {
|
|
|
764
818
|
}
|
|
765
819
|
async function loadAdcFile() {
|
|
766
820
|
const path = getAdcPath();
|
|
767
|
-
if (!path || !
|
|
821
|
+
if (!path || !existsSync3(path)) {
|
|
768
822
|
throw new Error(`Google Application Default Credentials file not found at ${path}`);
|
|
769
823
|
}
|
|
770
824
|
const raw = readFileSync2(path, "utf-8");
|
|
@@ -794,11 +848,11 @@ async function exchangeRefreshToken(cfg, signal) {
|
|
|
794
848
|
body,
|
|
795
849
|
signal
|
|
796
850
|
});
|
|
797
|
-
const
|
|
851
|
+
const text5 = await res.text();
|
|
798
852
|
if (!res.ok) {
|
|
799
|
-
throwOnTokenExchangeFailure(res,
|
|
853
|
+
throwOnTokenExchangeFailure(res, text5, res.status);
|
|
800
854
|
}
|
|
801
|
-
return parseTokenExchangeResponse(
|
|
855
|
+
return parseTokenExchangeResponse(text5, "Gemini ADC token exchange");
|
|
802
856
|
}
|
|
803
857
|
async function exchangeServiceAccountJwt(cfg, signal) {
|
|
804
858
|
if (!cfg.client_email || !cfg.private_key) {
|
|
@@ -830,16 +884,42 @@ async function exchangeServiceAccountJwt(cfg, signal) {
|
|
|
830
884
|
body,
|
|
831
885
|
signal
|
|
832
886
|
});
|
|
833
|
-
const
|
|
887
|
+
const text5 = await res.text();
|
|
888
|
+
if (!res.ok) {
|
|
889
|
+
throwOnTokenExchangeFailure(res, text5, res.status);
|
|
890
|
+
}
|
|
891
|
+
return parseTokenExchangeResponse(text5, "Gemini ADC service account token exchange");
|
|
892
|
+
}
|
|
893
|
+
async function fetchMetadataToken(signal) {
|
|
894
|
+
const url = `http://${getMetadataHost()}/computeMetadata/v1/instance/service-accounts/default/token`;
|
|
895
|
+
let res;
|
|
896
|
+
try {
|
|
897
|
+
res = await fetch(url, {
|
|
898
|
+
headers: { "Metadata-Flavor": "Google" },
|
|
899
|
+
redirect: "error",
|
|
900
|
+
signal
|
|
901
|
+
});
|
|
902
|
+
} catch (err) {
|
|
903
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
904
|
+
throw new Error(`Gemini ADC metadata server token request failed: ${message}`);
|
|
905
|
+
}
|
|
906
|
+
const text5 = await res.text();
|
|
834
907
|
if (!res.ok) {
|
|
835
|
-
|
|
908
|
+
if (res.status === 401 || res.status === 403) {
|
|
909
|
+
throw new CredentialResolutionError("Gemini ADC", "oauth-credential-rejected");
|
|
910
|
+
}
|
|
911
|
+
throw new Error(`Gemini ADC metadata server token request failed (HTTP ${res.status}): ${text5.slice(0, 300)}`);
|
|
836
912
|
}
|
|
837
|
-
return parseTokenExchangeResponse(
|
|
913
|
+
return parseTokenExchangeResponse(text5, "Gemini ADC metadata server token");
|
|
838
914
|
}
|
|
839
915
|
async function getAdcAccessToken(signal) {
|
|
840
916
|
if (cachedToken && cachedToken.expiresAt > Date.now()) {
|
|
841
917
|
return cachedToken.token;
|
|
842
918
|
}
|
|
919
|
+
if (!hasExplicitAdcPath() && !existsSync3(DEFAULT_ADC_PATH) && isOnGcp()) {
|
|
920
|
+
cachedToken = await fetchMetadataToken(signal);
|
|
921
|
+
return cachedToken.token;
|
|
922
|
+
}
|
|
843
923
|
const cfg = await loadAdcFile();
|
|
844
924
|
const type = cfg.type ?? "authorized_user";
|
|
845
925
|
if (type === "authorized_user") {
|
|
@@ -856,7 +936,8 @@ function isGeminiAdcAvailable() {
|
|
|
856
936
|
if (hasGeminiApiKeySource()) return false;
|
|
857
937
|
if (hasExplicitApiBase()) return false;
|
|
858
938
|
if (!getAdcProject() || !getAdcLocation()) return false;
|
|
859
|
-
|
|
939
|
+
if (existsSync3(getAdcPath())) return true;
|
|
940
|
+
return !hasExplicitAdcPath() && isOnGcp();
|
|
860
941
|
}
|
|
861
942
|
function hasGeminiApiKeySource() {
|
|
862
943
|
const configured = loadConfig().geminiApiKey;
|
|
@@ -870,7 +951,7 @@ function hasExplicitApiBase() {
|
|
|
870
951
|
const configured = loadConfig().geminiBaseUrl;
|
|
871
952
|
return typeof configured === "string" && configured.trim().length > 0;
|
|
872
953
|
}
|
|
873
|
-
var CONFIG_PATH, DEFAULT_ADC_PATH, TOKEN_ENDPOINT, VERTEX_HOST, VERTEX_API_VERSION, REFRESH_SKEW_MS, cachedConfig, cachedToken, OAUTH_CREDENTIAL_REJECTION_STATUSES;
|
|
954
|
+
var CONFIG_PATH, DEFAULT_ADC_PATH, TOKEN_ENDPOINT, DEFAULT_METADATA_HOST, VERTEX_HOST, VERTEX_API_VERSION, REFRESH_SKEW_MS, cachedConfig, cachedToken, OAUTH_CREDENTIAL_REJECTION_STATUSES;
|
|
874
955
|
var init_gemini_adc = __esm({
|
|
875
956
|
"gemini-adc.ts"() {
|
|
876
957
|
init_utils();
|
|
@@ -878,6 +959,7 @@ var init_gemini_adc = __esm({
|
|
|
878
959
|
CONFIG_PATH = getWebSearchConfigPath();
|
|
879
960
|
DEFAULT_ADC_PATH = join2(homedir2(), ".config", "gcloud", "application_default_credentials.json");
|
|
880
961
|
TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
|
|
962
|
+
DEFAULT_METADATA_HOST = "metadata.google.internal";
|
|
881
963
|
VERTEX_HOST = "https://aiplatform.googleapis.com";
|
|
882
964
|
VERTEX_API_VERSION = "v1";
|
|
883
965
|
REFRESH_SKEW_MS = 6e4;
|
|
@@ -888,10 +970,10 @@ var init_gemini_adc = __esm({
|
|
|
888
970
|
});
|
|
889
971
|
|
|
890
972
|
// gemini-api.ts
|
|
891
|
-
import { existsSync as
|
|
973
|
+
import { existsSync as existsSync4, readFileSync as readFileSync3 } from "node:fs";
|
|
892
974
|
function loadConfig2() {
|
|
893
975
|
if (cachedConfig2) return cachedConfig2;
|
|
894
|
-
if (!
|
|
976
|
+
if (!existsSync4(CONFIG_PATH2)) {
|
|
895
977
|
cachedConfig2 = {};
|
|
896
978
|
return cachedConfig2;
|
|
897
979
|
}
|
|
@@ -975,14 +1057,14 @@ function buildAuthHeaders(apiKey = null, cloudflareApiKey = getLegacyCloudflareA
|
|
|
975
1057
|
if (!isCloudflareGateway()) return apiKey ? { "x-goog-api-key": apiKey } : {};
|
|
976
1058
|
return cloudflareApiKey ? { "cf-aig-authorization": `Bearer ${cloudflareApiKey}` } : {};
|
|
977
1059
|
}
|
|
978
|
-
function redactGeminiCredentials(
|
|
979
|
-
let out = redactCredential(redactCredential(
|
|
1060
|
+
function redactGeminiCredentials(text5, apiKey, cloudflareApiKey, adcToken) {
|
|
1061
|
+
let out = redactCredential(redactCredential(text5, apiKey), cloudflareApiKey);
|
|
980
1062
|
if (adcToken) out = redactCredential(out, adcToken);
|
|
981
1063
|
return out;
|
|
982
1064
|
}
|
|
983
|
-
function redactGeminiApiResponse(response,
|
|
1065
|
+
function redactGeminiApiResponse(response, text5, apiKey, adcToken) {
|
|
984
1066
|
const credentials = responseCredentials.get(response);
|
|
985
|
-
return redactGeminiCredentials(
|
|
1067
|
+
return redactGeminiCredentials(text5, credentials?.apiKey ?? apiKey, credentials?.cloudflareApiKey, credentials?.adcToken ?? adcToken);
|
|
986
1068
|
}
|
|
987
1069
|
async function fetchGeminiApi(url, init = {}, apiKey) {
|
|
988
1070
|
const parsedUrl = new URL(url);
|
|
@@ -1082,9 +1164,9 @@ async function queryGeminiApiWithInlineData(prompt, data, mimeType, options = {}
|
|
|
1082
1164
|
}
|
|
1083
1165
|
const response = await res.json();
|
|
1084
1166
|
const candidate = response.candidates?.[0];
|
|
1085
|
-
const
|
|
1167
|
+
const text5 = candidate?.content?.parts?.map((part) => part.text).filter((part) => typeof part === "string" && part.length > 0).join("\n") ?? "";
|
|
1086
1168
|
return {
|
|
1087
|
-
text:
|
|
1169
|
+
text: text5,
|
|
1088
1170
|
...candidate?.finishReason ? { finishReason: candidate.finishReason } : {},
|
|
1089
1171
|
...response.promptFeedback?.blockReason ? { blockReason: response.promptFeedback.blockReason } : {}
|
|
1090
1172
|
};
|
|
@@ -1125,9 +1207,9 @@ async function queryGeminiApiWithVideo(prompt, videoUri, options = {}) {
|
|
|
1125
1207
|
throw new Error(`Gemini API error ${res.status}: ${errorText.slice(0, 300)}`);
|
|
1126
1208
|
}
|
|
1127
1209
|
const data = await res.json();
|
|
1128
|
-
const
|
|
1129
|
-
if (!
|
|
1130
|
-
return
|
|
1210
|
+
const text5 = data.candidates?.[0]?.content?.parts?.map((p) => p.text).filter(Boolean).join("\n");
|
|
1211
|
+
if (!text5) throw new Error("Gemini API returned empty response");
|
|
1212
|
+
return text5;
|
|
1131
1213
|
}
|
|
1132
1214
|
var DEFAULT_API_HOST, API_VERSION, API_BASE, CONFIG_PATH2, DEFAULT_MODEL, cachedConfig2, responseCredentials;
|
|
1133
1215
|
var init_gemini_api = __esm({
|
|
@@ -1146,7 +1228,7 @@ var init_gemini_api = __esm({
|
|
|
1146
1228
|
});
|
|
1147
1229
|
|
|
1148
1230
|
// gemini-web-config.ts
|
|
1149
|
-
import { existsSync as
|
|
1231
|
+
import { existsSync as existsSync5, readFileSync as readFileSync4 } from "node:fs";
|
|
1150
1232
|
function normalizeChromeProfile(value) {
|
|
1151
1233
|
if (typeof value !== "string") return void 0;
|
|
1152
1234
|
const normalized = value.trim();
|
|
@@ -1182,7 +1264,7 @@ function parseBrowserCookies(value) {
|
|
|
1182
1264
|
}
|
|
1183
1265
|
function loadConfig3() {
|
|
1184
1266
|
if (cachedConfig3) return cachedConfig3;
|
|
1185
|
-
if (!
|
|
1267
|
+
if (!existsSync5(CONFIG_PATH3)) {
|
|
1186
1268
|
cachedConfig3 = {};
|
|
1187
1269
|
return cachedConfig3;
|
|
1188
1270
|
}
|
|
@@ -1210,7 +1292,7 @@ function isBrowserCookieAccessAllowed() {
|
|
|
1210
1292
|
if (process.env.PI_ALLOW_BROWSER_COOKIES === "1" || process.env.FEYNMAN_ALLOW_BROWSER_COOKIES === "1") {
|
|
1211
1293
|
return true;
|
|
1212
1294
|
}
|
|
1213
|
-
if (!
|
|
1295
|
+
if (!existsSync5(CONFIG_PATH3)) return false;
|
|
1214
1296
|
const rawText = readFileSync4(CONFIG_PATH3, "utf-8");
|
|
1215
1297
|
let raw;
|
|
1216
1298
|
try {
|
|
@@ -1232,9 +1314,9 @@ var init_gemini_web_config = __esm({
|
|
|
1232
1314
|
});
|
|
1233
1315
|
|
|
1234
1316
|
// chrome-cookies.ts
|
|
1235
|
-
import { execFile } from "node:child_process";
|
|
1317
|
+
import { execFile as execFile2 } from "node:child_process";
|
|
1236
1318
|
import { pbkdf2Sync, createDecipheriv } from "node:crypto";
|
|
1237
|
-
import { copyFileSync, existsSync as
|
|
1319
|
+
import { copyFileSync, existsSync as existsSync6, mkdtempSync, readdirSync, readFileSync as readFileSync5, realpathSync, rmSync } from "node:fs";
|
|
1238
1320
|
import { tmpdir as tmpdir2, homedir as homedir3 } from "node:os";
|
|
1239
1321
|
import { isAbsolute, join as join3, sep } from "node:path";
|
|
1240
1322
|
function getLastGoogleCookieDiagnostic() {
|
|
@@ -1473,9 +1555,9 @@ function resolveProfilePath(home, config, profile) {
|
|
|
1473
1555
|
}
|
|
1474
1556
|
function cookieDatabasePath(profilePath, config) {
|
|
1475
1557
|
const networkCookies = join3(profilePath, "Network", "Cookies");
|
|
1476
|
-
if (config.usesLocalAppData &&
|
|
1558
|
+
if (config.usesLocalAppData && existsSync6(networkCookies)) return networkCookies;
|
|
1477
1559
|
const legacyCookies = join3(profilePath, "Cookies");
|
|
1478
|
-
return
|
|
1560
|
+
return existsSync6(legacyCookies) ? legacyCookies : null;
|
|
1479
1561
|
}
|
|
1480
1562
|
function browserBasePath(home, config) {
|
|
1481
1563
|
return config.usesLocalAppData ? join3(process.env.LOCALAPPDATA || join3(home, "AppData", "Local"), config.baseDir) : join3(home, config.baseDir);
|
|
@@ -1490,7 +1572,7 @@ function normalizeHosts(hosts) {
|
|
|
1490
1572
|
}
|
|
1491
1573
|
function listBrowserProfiles(home, config) {
|
|
1492
1574
|
const basePath = browserBasePath(home, config);
|
|
1493
|
-
if (!
|
|
1575
|
+
if (!existsSync6(basePath)) return ["Default"];
|
|
1494
1576
|
const profiles = /* @__PURE__ */ new Set();
|
|
1495
1577
|
try {
|
|
1496
1578
|
for (const entry of readdirSync(basePath, { withFileTypes: true })) {
|
|
@@ -1586,7 +1668,7 @@ function unprotectWindowsData(protectedData) {
|
|
|
1586
1668
|
return new Promise((resolve2) => {
|
|
1587
1669
|
const script = "Add-Type -AssemblyName System.Security;$data=[Convert]::FromBase64String($env:PIWA_PROTECTED);$clear=[System.Security.Cryptography.ProtectedData]::Unprotect($data,$null,[System.Security.Cryptography.DataProtectionScope]::CurrentUser);[Console]::Write([Convert]::ToBase64String($clear))";
|
|
1588
1670
|
const encoded = Buffer.from(script, "utf16le").toString("base64");
|
|
1589
|
-
|
|
1671
|
+
execFile2("powershell.exe", ["-NoProfile", "-NonInteractive", "-EncodedCommand", encoded], { timeout: 5e3, maxBuffer: 1024 * 1024, env: { ...process.env, PIWA_PROTECTED: protectedData.toString("base64") } }, (err, stdout) => {
|
|
1590
1672
|
if (err) {
|
|
1591
1673
|
resolve2(null);
|
|
1592
1674
|
return;
|
|
@@ -1601,7 +1683,7 @@ function unprotectWindowsData(protectedData) {
|
|
|
1601
1683
|
}
|
|
1602
1684
|
function readKeychainPassword(account, service) {
|
|
1603
1685
|
return new Promise((resolve2) => {
|
|
1604
|
-
|
|
1686
|
+
execFile2("security", ["find-generic-password", "-w", "-a", account, "-s", service], { timeout: 5e3 }, (err, stdout) => {
|
|
1605
1687
|
if (err) {
|
|
1606
1688
|
resolve2(null);
|
|
1607
1689
|
return;
|
|
@@ -1612,7 +1694,7 @@ function readKeychainPassword(account, service) {
|
|
|
1612
1694
|
}
|
|
1613
1695
|
function readLinuxCommandPassword(command, args) {
|
|
1614
1696
|
return new Promise((resolve2) => {
|
|
1615
|
-
|
|
1697
|
+
execFile2(command, args, { timeout: 5e3 }, (err, stdout) => resolve2({ value: err ? null : stdout.trim() || null, failed: Boolean(err) }));
|
|
1616
1698
|
});
|
|
1617
1699
|
}
|
|
1618
1700
|
function isKdeSession() {
|
|
@@ -1680,7 +1762,7 @@ async function runSqliteQuery(dbPath, sql) {
|
|
|
1680
1762
|
}
|
|
1681
1763
|
function runSqliteCli(dbPath, sql) {
|
|
1682
1764
|
return new Promise((resolve2) => {
|
|
1683
|
-
|
|
1765
|
+
execFile2("sqlite3", ["-readonly", "-json", dbPath, sql], { timeout: 5e3, maxBuffer: 1024 * 1024 }, (err, stdout) => {
|
|
1684
1766
|
if (err) {
|
|
1685
1767
|
resolve2({ status: "failure", failure: err.code === "ENOENT" ? "unavailable" : "query" });
|
|
1686
1768
|
return;
|
|
@@ -1697,7 +1779,7 @@ function runSqliteCli(dbPath, sql) {
|
|
|
1697
1779
|
function runPythonSqlite(dbPath, sql) {
|
|
1698
1780
|
const script = "import json,sqlite3,sys\ntry:\n c=sqlite3.connect('file:'+sys.argv[1]+'?mode=ro',uri=True)\n c.row_factory=sqlite3.Row\n print(json.dumps([dict(r) for r in c.execute(sys.argv[2]).fetchall()]))\nexcept Exception:\n sys.exit(1)";
|
|
1699
1781
|
return new Promise((resolve2) => {
|
|
1700
|
-
|
|
1782
|
+
execFile2("python3", ["-c", script, dbPath, sql], { timeout: 5e3, maxBuffer: 1024 * 1024 }, (err, stdout) => {
|
|
1701
1783
|
if (err) {
|
|
1702
1784
|
resolve2({ status: "failure", failure: err.code === "ENOENT" ? "unavailable" : "query" });
|
|
1703
1785
|
return;
|
|
@@ -1789,7 +1871,7 @@ function domainCookieHosts(host) {
|
|
|
1789
1871
|
}
|
|
1790
1872
|
function copySidecar(srcDb, targetDb, suffix) {
|
|
1791
1873
|
const sidecar = `${srcDb}${suffix}`;
|
|
1792
|
-
if (!
|
|
1874
|
+
if (!existsSync6(sidecar)) return;
|
|
1793
1875
|
try {
|
|
1794
1876
|
copyFileSync(sidecar, `${targetDb}${suffix}`);
|
|
1795
1877
|
} catch {
|
|
@@ -2017,8 +2099,8 @@ Content-Type: ${file.mimeType}\r
|
|
|
2017
2099
|
signal
|
|
2018
2100
|
});
|
|
2019
2101
|
if (!res.ok) {
|
|
2020
|
-
const
|
|
2021
|
-
throw new Error(`File upload failed: ${res.status} (${
|
|
2102
|
+
const text5 = await res.text();
|
|
2103
|
+
throw new Error(`File upload failed: ${res.status} (${text5.slice(0, 200)})`);
|
|
2022
2104
|
}
|
|
2023
2105
|
return { id: await res.text(), name: fileName };
|
|
2024
2106
|
}
|
|
@@ -2043,13 +2125,13 @@ function getNestedValue(value, pathParts) {
|
|
|
2043
2125
|
}
|
|
2044
2126
|
return current;
|
|
2045
2127
|
}
|
|
2046
|
-
function trimJsonEnvelope(
|
|
2047
|
-
const start =
|
|
2048
|
-
const end =
|
|
2128
|
+
function trimJsonEnvelope(text5) {
|
|
2129
|
+
const start = text5.indexOf("[");
|
|
2130
|
+
const end = text5.lastIndexOf("]");
|
|
2049
2131
|
if (start === -1 || end === -1 || end <= start) {
|
|
2050
2132
|
throw new Error("Gemini response did not contain a JSON payload.");
|
|
2051
2133
|
}
|
|
2052
|
-
return
|
|
2134
|
+
return text5.slice(start, end + 1);
|
|
2053
2135
|
}
|
|
2054
2136
|
function extractErrorCode(responseJson) {
|
|
2055
2137
|
const code = getNestedValue(responseJson, [0, 5, 2, 0, 1, 0]);
|
|
@@ -2057,12 +2139,12 @@ function extractErrorCode(responseJson) {
|
|
|
2057
2139
|
}
|
|
2058
2140
|
function extractCandidateText(candidate) {
|
|
2059
2141
|
const textRaw = getNestedValue(candidate, [1, 0]);
|
|
2060
|
-
let
|
|
2061
|
-
if (/^http:\/\/googleusercontent\.com\/card_content\/\d+/.test(
|
|
2142
|
+
let text5 = typeof textRaw === "string" ? textRaw : "";
|
|
2143
|
+
if (/^http:\/\/googleusercontent\.com\/card_content\/\d+/.test(text5)) {
|
|
2062
2144
|
const alt = getNestedValue(candidate, [22, 0]);
|
|
2063
|
-
if (typeof alt === "string" && alt.length > 0)
|
|
2145
|
+
if (typeof alt === "string" && alt.length > 0) text5 = alt;
|
|
2064
2146
|
}
|
|
2065
|
-
return
|
|
2147
|
+
return text5;
|
|
2066
2148
|
}
|
|
2067
2149
|
function parseStreamGenerateResponse(rawText) {
|
|
2068
2150
|
const responseJson = JSON.parse(trimJsonEnvelope(rawText));
|
|
@@ -2079,13 +2161,13 @@ function parseStreamGenerateResponse(rawText) {
|
|
|
2079
2161
|
if (!Array.isArray(candidateList) || candidateList.length === 0) continue;
|
|
2080
2162
|
const firstCandidate = candidateList[0];
|
|
2081
2163
|
if (firstCandidateSeen === void 0) firstCandidateSeen = firstCandidate;
|
|
2082
|
-
const
|
|
2083
|
-
if (
|
|
2164
|
+
const text6 = extractCandidateText(firstCandidate);
|
|
2165
|
+
if (text6.length > 0) latestNonEmptyText = text6;
|
|
2084
2166
|
} catch {
|
|
2085
2167
|
}
|
|
2086
2168
|
}
|
|
2087
|
-
const
|
|
2088
|
-
return { text:
|
|
2169
|
+
const text5 = latestNonEmptyText.length > 0 ? latestNonEmptyText : extractCandidateText(firstCandidateSeen);
|
|
2170
|
+
return { text: text5, errorCode };
|
|
2089
2171
|
}
|
|
2090
2172
|
var GEMINI_APP_URL, GEMINI_STREAM_GENERATE_URL, GEMINI_UPLOAD_URL, GEMINI_UPLOAD_PUSH_ID, USER_AGENT, MODEL_HEADER_NAME, DEFAULT_GEMINI_WEB_MODEL, MODEL_HEADERS, REQUIRED_COOKIES, geminiFetchImpl, geminiFetchOverride, GEMINI_MAX_HEADER_SIZE;
|
|
2091
2173
|
var init_gemini_web = __esm({
|
|
@@ -2122,10 +2204,10 @@ var init_search_answer_formatting = __esm({
|
|
|
2122
2204
|
});
|
|
2123
2205
|
|
|
2124
2206
|
// perplexity.ts
|
|
2125
|
-
import { existsSync as
|
|
2207
|
+
import { existsSync as existsSync7, readFileSync as readFileSync7 } from "node:fs";
|
|
2126
2208
|
function loadConfig4() {
|
|
2127
2209
|
if (cachedConfig4) return cachedConfig4;
|
|
2128
|
-
if (!
|
|
2210
|
+
if (!existsSync7(CONFIG_PATH4)) {
|
|
2129
2211
|
cachedConfig4 = {};
|
|
2130
2212
|
return cachedConfig4;
|
|
2131
2213
|
}
|
|
@@ -2331,10 +2413,10 @@ var init_search_result_count_normalization = __esm({
|
|
|
2331
2413
|
});
|
|
2332
2414
|
|
|
2333
2415
|
// parallel.ts
|
|
2334
|
-
import { existsSync as
|
|
2416
|
+
import { existsSync as existsSync11, readFileSync as readFileSync11 } from "node:fs";
|
|
2335
2417
|
function loadConfig8() {
|
|
2336
2418
|
if (cachedConfig8) return cachedConfig8;
|
|
2337
|
-
if (!
|
|
2419
|
+
if (!existsSync11(CONFIG_PATH8)) {
|
|
2338
2420
|
cachedConfig8 = {};
|
|
2339
2421
|
return cachedConfig8;
|
|
2340
2422
|
}
|
|
@@ -2726,20 +2808,20 @@ async function callParallelMcp(toolName, args, signal) {
|
|
|
2726
2808
|
throw new Error(`Parallel MCP error${code}: ${message}`);
|
|
2727
2809
|
}
|
|
2728
2810
|
if (parsed.result?.isError) {
|
|
2729
|
-
const
|
|
2730
|
-
throw new Error(apiKey ? redactCredential(
|
|
2811
|
+
const text6 = parsed.result.content?.find((item) => item.type === "text" && typeof item.text === "string")?.text?.trim() || "Parallel MCP returned an error";
|
|
2812
|
+
throw new Error(apiKey ? redactCredential(text6, apiKey) : text6);
|
|
2731
2813
|
}
|
|
2732
2814
|
if (parsed.result?.structuredContent && typeof parsed.result.structuredContent === "object") return parsed.result.structuredContent;
|
|
2733
|
-
const
|
|
2734
|
-
if (!
|
|
2815
|
+
const text5 = parsed.result?.content?.find((item) => item.type === "text" && typeof item.text === "string" && item.text.trim())?.text;
|
|
2816
|
+
if (!text5) throw new Error("Parallel MCP returned empty content");
|
|
2735
2817
|
try {
|
|
2736
|
-
return JSON.parse(
|
|
2818
|
+
return JSON.parse(text5);
|
|
2737
2819
|
} catch {
|
|
2738
|
-
return
|
|
2820
|
+
return text5;
|
|
2739
2821
|
}
|
|
2740
2822
|
}
|
|
2741
|
-
function parseTextResults(
|
|
2742
|
-
return
|
|
2823
|
+
function parseTextResults(text5) {
|
|
2824
|
+
return text5.split(/(?=^Title: )/m).flatMap((block) => {
|
|
2743
2825
|
const url = block.match(/^URL: (.+)/m)?.[1]?.trim();
|
|
2744
2826
|
if (!url) return [];
|
|
2745
2827
|
const title = block.match(/^Title: (.+)/m)?.[1]?.trim() ?? "";
|
|
@@ -2835,10 +2917,10 @@ var init_parallel_mcp = __esm({
|
|
|
2835
2917
|
});
|
|
2836
2918
|
|
|
2837
2919
|
// tinyfish.ts
|
|
2838
|
-
import { existsSync as
|
|
2920
|
+
import { existsSync as existsSync12, readFileSync as readFileSync12 } from "node:fs";
|
|
2839
2921
|
function loadConfig9() {
|
|
2840
2922
|
if (cachedConfig9) return cachedConfig9;
|
|
2841
|
-
if (!
|
|
2923
|
+
if (!existsSync12(CONFIG_PATH10)) {
|
|
2842
2924
|
cachedConfig9 = {};
|
|
2843
2925
|
return cachedConfig9;
|
|
2844
2926
|
}
|
|
@@ -3118,10 +3200,10 @@ var init_tinyfish = __esm({
|
|
|
3118
3200
|
});
|
|
3119
3201
|
|
|
3120
3202
|
// search1api.ts
|
|
3121
|
-
import { existsSync as
|
|
3203
|
+
import { existsSync as existsSync13, readFileSync as readFileSync13 } from "node:fs";
|
|
3122
3204
|
function loadConfig10() {
|
|
3123
3205
|
if (cachedConfig10) return cachedConfig10;
|
|
3124
|
-
if (!
|
|
3206
|
+
if (!existsSync13(CONFIG_PATH11)) {
|
|
3125
3207
|
cachedConfig10 = {};
|
|
3126
3208
|
return cachedConfig10;
|
|
3127
3209
|
}
|
|
@@ -3339,10 +3421,10 @@ var init_search1api = __esm({
|
|
|
3339
3421
|
});
|
|
3340
3422
|
|
|
3341
3423
|
// querit.ts
|
|
3342
|
-
import { existsSync as
|
|
3424
|
+
import { existsSync as existsSync15, readFileSync as readFileSync15 } from "node:fs";
|
|
3343
3425
|
function loadConfig12() {
|
|
3344
3426
|
if (cachedConfig12) return cachedConfig12;
|
|
3345
|
-
if (!
|
|
3427
|
+
if (!existsSync15(CONFIG_PATH13)) {
|
|
3346
3428
|
cachedConfig12 = {};
|
|
3347
3429
|
return cachedConfig12;
|
|
3348
3430
|
}
|
|
@@ -3633,10 +3715,10 @@ var init_querit = __esm({
|
|
|
3633
3715
|
|
|
3634
3716
|
// ssrf-protection.ts
|
|
3635
3717
|
import { lookup as dnsLookup } from "node:dns/promises";
|
|
3636
|
-
import { existsSync as
|
|
3718
|
+
import { existsSync as existsSync18, readFileSync as readFileSync18, statSync } from "node:fs";
|
|
3637
3719
|
import net from "node:net";
|
|
3638
3720
|
function loadConfigRoot() {
|
|
3639
|
-
if (!
|
|
3721
|
+
if (!existsSync18(WEB_SEARCH_CONFIG_PATH)) return null;
|
|
3640
3722
|
let signature;
|
|
3641
3723
|
try {
|
|
3642
3724
|
const stat = statSync(WEB_SEARCH_CONFIG_PATH);
|
|
@@ -4045,10 +4127,10 @@ var init_ssrf_protection = __esm({
|
|
|
4045
4127
|
});
|
|
4046
4128
|
|
|
4047
4129
|
// firecrawl.ts
|
|
4048
|
-
import { existsSync as
|
|
4130
|
+
import { existsSync as existsSync19, readFileSync as readFileSync19 } from "node:fs";
|
|
4049
4131
|
function loadConfig15() {
|
|
4050
4132
|
if (cachedConfig15) return cachedConfig15;
|
|
4051
|
-
if (!
|
|
4133
|
+
if (!existsSync19(CONFIG_PATH16)) {
|
|
4052
4134
|
cachedConfig15 = {};
|
|
4053
4135
|
return cachedConfig15;
|
|
4054
4136
|
}
|
|
@@ -4309,8 +4391,8 @@ async function firecrawlFetch(endpoint, body, signal, options, label = endpoint,
|
|
|
4309
4391
|
signal: requestSignal9(options?.timeoutMs ?? EXTRACT_TIMEOUT_MS, signal)
|
|
4310
4392
|
}, options);
|
|
4311
4393
|
if (!response.ok) {
|
|
4312
|
-
const
|
|
4313
|
-
throw new Error(`Firecrawl ${label} error ${response.status}: ${redactCredential(
|
|
4394
|
+
const text5 = await response.text().catch(() => "");
|
|
4395
|
+
throw new Error(`Firecrawl ${label} error ${response.status}: ${redactCredential(text5.slice(0, 300), apiKey)}`);
|
|
4314
4396
|
}
|
|
4315
4397
|
let data;
|
|
4316
4398
|
try {
|
|
@@ -4397,10 +4479,10 @@ var init_firecrawl = __esm({
|
|
|
4397
4479
|
});
|
|
4398
4480
|
|
|
4399
4481
|
// kagi.ts
|
|
4400
|
-
import { existsSync as
|
|
4482
|
+
import { existsSync as existsSync22, readFileSync as readFileSync22 } from "node:fs";
|
|
4401
4483
|
function loadConfig18() {
|
|
4402
4484
|
if (cachedConfig18) return cachedConfig18;
|
|
4403
|
-
if (!
|
|
4485
|
+
if (!existsSync22(CONFIG_PATH19)) {
|
|
4404
4486
|
cachedConfig18 = {};
|
|
4405
4487
|
return cachedConfig18;
|
|
4406
4488
|
}
|
|
@@ -4628,10 +4710,10 @@ var init_kagi = __esm({
|
|
|
4628
4710
|
});
|
|
4629
4711
|
|
|
4630
4712
|
// ollama.ts
|
|
4631
|
-
import { existsSync as
|
|
4713
|
+
import { existsSync as existsSync24, readFileSync as readFileSync24 } from "node:fs";
|
|
4632
4714
|
function loadConfig20() {
|
|
4633
4715
|
if (cachedConfig20) return cachedConfig20;
|
|
4634
|
-
if (!
|
|
4716
|
+
if (!existsSync24(CONFIG_PATH21)) {
|
|
4635
4717
|
cachedConfig20 = {};
|
|
4636
4718
|
return cachedConfig20;
|
|
4637
4719
|
}
|
|
@@ -4820,7 +4902,7 @@ var init_ollama = __esm({
|
|
|
4820
4902
|
});
|
|
4821
4903
|
|
|
4822
4904
|
// auth-fetch.ts
|
|
4823
|
-
import { existsSync as
|
|
4905
|
+
import { existsSync as existsSync43, readFileSync as readFileSync43 } from "node:fs";
|
|
4824
4906
|
function resolveAuthFetchProfile(request) {
|
|
4825
4907
|
const profiles = loadAuthFetchProfiles();
|
|
4826
4908
|
if (profiles.length === 0) {
|
|
@@ -4858,8 +4940,8 @@ function authFetchRedirectGuard(profile, from, to) {
|
|
|
4858
4940
|
}
|
|
4859
4941
|
}
|
|
4860
4942
|
function loadAuthFetchProfiles() {
|
|
4861
|
-
if (!
|
|
4862
|
-
const raw =
|
|
4943
|
+
if (!existsSync43(WEB_SEARCH_CONFIG_PATH2)) return [];
|
|
4944
|
+
const raw = readFileSync43(WEB_SEARCH_CONFIG_PATH2, "utf-8");
|
|
4863
4945
|
let parsed;
|
|
4864
4946
|
try {
|
|
4865
4947
|
const value = JSON.parse(raw);
|
|
@@ -5193,8 +5275,8 @@ function extractRSCContent(html) {
|
|
|
5193
5275
|
if (!Array.isArray(node)) return;
|
|
5194
5276
|
if (node[0] === "$" && (node[1] === "td" || node[1] === "th")) {
|
|
5195
5277
|
const cellProps = node[3] || {};
|
|
5196
|
-
const
|
|
5197
|
-
cells.push(
|
|
5278
|
+
const text5 = extractNode(cellProps.children, { inTable: true, inCode: false }).trim().replace(/\n/g, " ").replace(/\\/g, "\\\\").replace(/\|/g, "\\|");
|
|
5279
|
+
cells.push(text5);
|
|
5198
5280
|
} else if (node[0] === "$" && typeof node[1] === "string" && node[1].startsWith("$L")) {
|
|
5199
5281
|
const refId = node[1].slice(2);
|
|
5200
5282
|
if (!visitedRefs.has(refId)) {
|
|
@@ -5234,9 +5316,9 @@ function extractRSCContent(html) {
|
|
|
5234
5316
|
const parsed = getParsedChunk(id);
|
|
5235
5317
|
if (!parsed) continue;
|
|
5236
5318
|
visitedRefs.clear();
|
|
5237
|
-
const
|
|
5238
|
-
if (
|
|
5239
|
-
contentParts.push({ order: parseInt(id, 16), text:
|
|
5319
|
+
const text5 = extractNode(parsed);
|
|
5320
|
+
if (text5.trim().length > 50 && !text5.includes("page was not found") && !text5.includes("404")) {
|
|
5321
|
+
contentParts.push({ order: parseInt(id, 16), text: text5.trim() });
|
|
5240
5322
|
}
|
|
5241
5323
|
}
|
|
5242
5324
|
if (contentParts.length === 0) return null;
|
|
@@ -5259,20 +5341,20 @@ var init_rsc_extract = __esm({
|
|
|
5259
5341
|
});
|
|
5260
5342
|
|
|
5261
5343
|
// datalab-pdf-extract.ts
|
|
5262
|
-
import { existsSync as
|
|
5263
|
-
function
|
|
5264
|
-
if (
|
|
5265
|
-
if (!
|
|
5266
|
-
|
|
5267
|
-
return
|
|
5344
|
+
import { existsSync as existsSync44, readFileSync as readFileSync45 } from "node:fs";
|
|
5345
|
+
function loadConfig37() {
|
|
5346
|
+
if (cachedConfig36) return cachedConfig36;
|
|
5347
|
+
if (!existsSync44(CONFIG_PATH40)) {
|
|
5348
|
+
cachedConfig36 = {};
|
|
5349
|
+
return cachedConfig36;
|
|
5268
5350
|
}
|
|
5269
|
-
const rawText =
|
|
5351
|
+
const rawText = readFileSync45(CONFIG_PATH40, "utf-8");
|
|
5270
5352
|
try {
|
|
5271
|
-
|
|
5272
|
-
return
|
|
5353
|
+
cachedConfig36 = JSON.parse(rawText);
|
|
5354
|
+
return cachedConfig36;
|
|
5273
5355
|
} catch (err) {
|
|
5274
5356
|
const message = err instanceof Error ? err.message : String(err);
|
|
5275
|
-
throw new Error(`Failed to parse ${
|
|
5357
|
+
throw new Error(`Failed to parse ${CONFIG_PATH40}: ${message}`);
|
|
5276
5358
|
}
|
|
5277
5359
|
}
|
|
5278
5360
|
function normalizeString(value) {
|
|
@@ -5287,14 +5369,14 @@ function normalizeFileId(value) {
|
|
|
5287
5369
|
function isDatalabApiAvailable() {
|
|
5288
5370
|
return hasCredentialSource({
|
|
5289
5371
|
provider: "Datalab",
|
|
5290
|
-
configuredValue:
|
|
5372
|
+
configuredValue: loadConfig37().datalabApiKey,
|
|
5291
5373
|
environmentValue: process.env.DATALAB_API_KEY
|
|
5292
5374
|
});
|
|
5293
5375
|
}
|
|
5294
5376
|
async function getDatalabApiKey(signal) {
|
|
5295
5377
|
return resolveCredential({
|
|
5296
5378
|
provider: "Datalab",
|
|
5297
|
-
configuredValue:
|
|
5379
|
+
configuredValue: loadConfig37().datalabApiKey,
|
|
5298
5380
|
environmentValue: process.env.DATALAB_API_KEY,
|
|
5299
5381
|
signal
|
|
5300
5382
|
});
|
|
@@ -5566,18 +5648,18 @@ async function fetchDatalab(url, init, apiKey) {
|
|
|
5566
5648
|
}
|
|
5567
5649
|
}
|
|
5568
5650
|
async function readJsonResponse(response, apiKey) {
|
|
5569
|
-
const
|
|
5651
|
+
const text5 = await readResponseText(response);
|
|
5570
5652
|
if (!response.ok) {
|
|
5571
|
-
const detail =
|
|
5653
|
+
const detail = text5.trim().slice(0, MAX_ERROR_BODY_BYTES);
|
|
5572
5654
|
const message = detail ? `Datalab PDF conversion failed: HTTP ${response.status} ${response.statusText}: ${detail}` : `Datalab PDF conversion failed: HTTP ${response.status} ${response.statusText}`;
|
|
5573
5655
|
throw new Error(redactCredential(message, apiKey));
|
|
5574
5656
|
}
|
|
5575
|
-
return parseJsonRecord(
|
|
5657
|
+
return parseJsonRecord(text5);
|
|
5576
5658
|
}
|
|
5577
|
-
function parseJsonRecord(
|
|
5659
|
+
function parseJsonRecord(text5) {
|
|
5578
5660
|
let parsed;
|
|
5579
5661
|
try {
|
|
5580
|
-
parsed = JSON.parse(
|
|
5662
|
+
parsed = JSON.parse(text5);
|
|
5581
5663
|
} catch (error) {
|
|
5582
5664
|
throw new Error("Datalab PDF conversion returned invalid JSON", { cause: error });
|
|
5583
5665
|
}
|
|
@@ -5619,7 +5701,7 @@ async function readResponseText(response) {
|
|
|
5619
5701
|
function datalabFilename(title) {
|
|
5620
5702
|
return title.toLowerCase().replace(/[^a-z0-9\s-]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 60) || "document";
|
|
5621
5703
|
}
|
|
5622
|
-
var DEFAULT_API_HOST2, API_PREFIX, DEFAULT_TIMEOUT_MS, DEFAULT_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES, MAX_ERROR_BODY_BYTES, CLEANUP_TIMEOUT_MS,
|
|
5704
|
+
var DEFAULT_API_HOST2, API_PREFIX, DEFAULT_TIMEOUT_MS, DEFAULT_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES, MAX_ERROR_BODY_BYTES, CLEANUP_TIMEOUT_MS, CONFIG_PATH40, DATALAB_MODE_VALUES, DATALAB_LOCATION_VALUES, DEFAULT_DATALAB_MODE, DEFAULT_PROCESSING_LOCATION, DEFAULT_DATALAB_TIMEOUT_MS, cachedConfig36;
|
|
5623
5705
|
var init_datalab_pdf_extract = __esm({
|
|
5624
5706
|
"datalab-pdf-extract.ts"() {
|
|
5625
5707
|
init_credential_source();
|
|
@@ -5631,7 +5713,7 @@ var init_datalab_pdf_extract = __esm({
|
|
|
5631
5713
|
MAX_RESPONSE_BYTES = 4 * 1024 * 1024;
|
|
5632
5714
|
MAX_ERROR_BODY_BYTES = 300;
|
|
5633
5715
|
CLEANUP_TIMEOUT_MS = 5e3;
|
|
5634
|
-
|
|
5716
|
+
CONFIG_PATH40 = getWebSearchConfigPath();
|
|
5635
5717
|
DATALAB_MODE_VALUES = /* @__PURE__ */ new Set([
|
|
5636
5718
|
"fast",
|
|
5637
5719
|
"balanced",
|
|
@@ -5644,21 +5726,21 @@ var init_datalab_pdf_extract = __esm({
|
|
|
5644
5726
|
DEFAULT_DATALAB_MODE = "balanced";
|
|
5645
5727
|
DEFAULT_PROCESSING_LOCATION = "us";
|
|
5646
5728
|
DEFAULT_DATALAB_TIMEOUT_MS = DEFAULT_TIMEOUT_MS;
|
|
5647
|
-
|
|
5729
|
+
cachedConfig36 = null;
|
|
5648
5730
|
}
|
|
5649
5731
|
});
|
|
5650
5732
|
|
|
5651
5733
|
// endpoint-pdf-extract.ts
|
|
5652
|
-
import { existsSync as
|
|
5734
|
+
import { existsSync as existsSync45, readFileSync as readFileSync46 } from "node:fs";
|
|
5653
5735
|
import { setTimeout as sleep2 } from "node:timers/promises";
|
|
5654
5736
|
function pdfSection() {
|
|
5655
|
-
if (!
|
|
5737
|
+
if (!existsSync45(CONFIG_PATH41)) return {};
|
|
5656
5738
|
let parsed;
|
|
5657
5739
|
try {
|
|
5658
|
-
parsed = JSON.parse(
|
|
5740
|
+
parsed = JSON.parse(readFileSync46(CONFIG_PATH41, "utf-8"));
|
|
5659
5741
|
} catch (err) {
|
|
5660
5742
|
const message = err instanceof Error ? err.message : String(err);
|
|
5661
|
-
throw new Error(`Failed to parse ${
|
|
5743
|
+
throw new Error(`Failed to parse ${CONFIG_PATH41}: ${message}`);
|
|
5662
5744
|
}
|
|
5663
5745
|
const pdf = parsed?.pdf;
|
|
5664
5746
|
return pdf && typeof pdf === "object" ? pdf : {};
|
|
@@ -5697,11 +5779,11 @@ async function readCapped(response, maxBytes, overflowThrows) {
|
|
|
5697
5779
|
const reader = response.body?.getReader();
|
|
5698
5780
|
if (!reader) return "";
|
|
5699
5781
|
const decoder = new TextDecoder();
|
|
5700
|
-
let
|
|
5782
|
+
let text5 = "";
|
|
5701
5783
|
let received = 0;
|
|
5702
5784
|
for (; ; ) {
|
|
5703
5785
|
const { done, value } = await reader.read();
|
|
5704
|
-
if (done) return
|
|
5786
|
+
if (done) return text5 + decoder.decode();
|
|
5705
5787
|
const room = maxBytes - received;
|
|
5706
5788
|
received += value.byteLength;
|
|
5707
5789
|
if (received >= maxBytes) {
|
|
@@ -5709,15 +5791,15 @@ async function readCapped(response, maxBytes, overflowThrows) {
|
|
|
5709
5791
|
if (overflowThrows && received > maxBytes) {
|
|
5710
5792
|
throw new Error("PDF parser endpoint returned an oversized response");
|
|
5711
5793
|
}
|
|
5712
|
-
return
|
|
5794
|
+
return text5 + decoder.decode(value.subarray(0, room));
|
|
5713
5795
|
}
|
|
5714
|
-
|
|
5796
|
+
text5 += decoder.decode(value, { stream: true });
|
|
5715
5797
|
}
|
|
5716
5798
|
}
|
|
5717
5799
|
async function readJson(response) {
|
|
5718
|
-
const
|
|
5800
|
+
const text5 = await readCapped(response, MAX_RESPONSE_BYTES2, true);
|
|
5719
5801
|
try {
|
|
5720
|
-
const parsed = JSON.parse(
|
|
5802
|
+
const parsed = JSON.parse(text5);
|
|
5721
5803
|
if (parsed && typeof parsed === "object") return parsed;
|
|
5722
5804
|
} catch {
|
|
5723
5805
|
}
|
|
@@ -5725,8 +5807,8 @@ async function readJson(response) {
|
|
|
5725
5807
|
}
|
|
5726
5808
|
async function errorBody(response) {
|
|
5727
5809
|
try {
|
|
5728
|
-
const
|
|
5729
|
-
return
|
|
5810
|
+
const text5 = await readCapped(response, MAX_ERROR_BODY_BYTES2, false);
|
|
5811
|
+
return text5 ? `: ${text5}` : "";
|
|
5730
5812
|
} catch {
|
|
5731
5813
|
return "";
|
|
5732
5814
|
}
|
|
@@ -5810,7 +5892,7 @@ async function extractPDFViaEndpoint(buffer, options) {
|
|
|
5810
5892
|
}
|
|
5811
5893
|
throw new Error("PDF parser endpoint job timed out");
|
|
5812
5894
|
}
|
|
5813
|
-
var DEFAULT_TIMEOUT_MS2, MAX_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES2, MAX_ERROR_BODY_BYTES2,
|
|
5895
|
+
var DEFAULT_TIMEOUT_MS2, MAX_POLL_INTERVAL_MS, MAX_RESPONSE_BYTES2, MAX_ERROR_BODY_BYTES2, CONFIG_PATH41;
|
|
5814
5896
|
var init_endpoint_pdf_extract = __esm({
|
|
5815
5897
|
"endpoint-pdf-extract.ts"() {
|
|
5816
5898
|
init_ssrf_protection();
|
|
@@ -5819,7 +5901,7 @@ var init_endpoint_pdf_extract = __esm({
|
|
|
5819
5901
|
MAX_POLL_INTERVAL_MS = 3e3;
|
|
5820
5902
|
MAX_RESPONSE_BYTES2 = 4 * 1024 * 1024;
|
|
5821
5903
|
MAX_ERROR_BODY_BYTES2 = 300;
|
|
5822
|
-
|
|
5904
|
+
CONFIG_PATH41 = getWebSearchConfigPath();
|
|
5823
5905
|
}
|
|
5824
5906
|
});
|
|
5825
5907
|
|
|
@@ -5909,12 +5991,12 @@ var init_gemini_pdf_extract = __esm({
|
|
|
5909
5991
|
});
|
|
5910
5992
|
|
|
5911
5993
|
// pdf-extract.ts
|
|
5912
|
-
import { existsSync as
|
|
5994
|
+
import { existsSync as existsSync46, readFileSync as readFileSync47 } from "node:fs";
|
|
5913
5995
|
import { writeFile as writeFile2, mkdir } from "node:fs/promises";
|
|
5914
5996
|
import { join as join5, basename as basename2 } from "node:path";
|
|
5915
5997
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
5916
5998
|
function loadPDFConfig() {
|
|
5917
|
-
if (!
|
|
5999
|
+
if (!existsSync46(CONFIG_PATH42)) {
|
|
5918
6000
|
return {
|
|
5919
6001
|
enabled: true,
|
|
5920
6002
|
maxSizeMB: DEFAULT_PDF_MAX_SIZE_MB,
|
|
@@ -5924,13 +6006,13 @@ function loadPDFConfig() {
|
|
|
5924
6006
|
datalabTimeoutMs: DEFAULT_DATALAB_TIMEOUT_MS
|
|
5925
6007
|
};
|
|
5926
6008
|
}
|
|
5927
|
-
const rawText =
|
|
6009
|
+
const rawText = readFileSync47(CONFIG_PATH42, "utf-8");
|
|
5928
6010
|
let raw;
|
|
5929
6011
|
try {
|
|
5930
6012
|
raw = JSON.parse(rawText);
|
|
5931
6013
|
} catch (err) {
|
|
5932
6014
|
const message = err instanceof Error ? err.message : String(err);
|
|
5933
|
-
throw new Error(`Failed to parse ${
|
|
6015
|
+
throw new Error(`Failed to parse ${CONFIG_PATH42}: ${message}`);
|
|
5934
6016
|
}
|
|
5935
6017
|
const root = raw && typeof raw === "object" ? raw : {};
|
|
5936
6018
|
const pdf = root.pdf && typeof root.pdf === "object" ? root.pdf : {};
|
|
@@ -6166,7 +6248,7 @@ function isPDF(url, contentType) {
|
|
|
6166
6248
|
return false;
|
|
6167
6249
|
}
|
|
6168
6250
|
}
|
|
6169
|
-
var PDF_PROVIDER_VALUES, DEFAULT_PDF_MAX_SIZE_MB, MAX_PDF_MAX_SIZE_MB, MAX_DATALAB_TIMEOUT_MS, DEFAULT_MAX_PAGES, DEFAULT_OUTPUT_DIR,
|
|
6251
|
+
var PDF_PROVIDER_VALUES, DEFAULT_PDF_MAX_SIZE_MB, MAX_PDF_MAX_SIZE_MB, MAX_DATALAB_TIMEOUT_MS, DEFAULT_MAX_PAGES, DEFAULT_OUTPUT_DIR, CONFIG_PATH42, PAGE_MARKER_PATTERN2;
|
|
6170
6252
|
var init_pdf_extract = __esm({
|
|
6171
6253
|
"pdf-extract.ts"() {
|
|
6172
6254
|
init_credential_source();
|
|
@@ -6187,17 +6269,17 @@ var init_pdf_extract = __esm({
|
|
|
6187
6269
|
MAX_DATALAB_TIMEOUT_MS = 3e5;
|
|
6188
6270
|
DEFAULT_MAX_PAGES = 100;
|
|
6189
6271
|
DEFAULT_OUTPUT_DIR = join5(tmpdir3(), "pi-web-pdf");
|
|
6190
|
-
|
|
6272
|
+
CONFIG_PATH42 = getWebSearchConfigPath();
|
|
6191
6273
|
PAGE_MARKER_PATTERN2 = /^<!-- Page (\d+) -->$/gm;
|
|
6192
6274
|
}
|
|
6193
6275
|
});
|
|
6194
6276
|
|
|
6195
6277
|
// github-api.ts
|
|
6196
|
-
import { execFile as
|
|
6278
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
6197
6279
|
async function checkGhAvailable(signal) {
|
|
6198
6280
|
if (ghAvailable !== null) return ghAvailable;
|
|
6199
6281
|
return new Promise((resolve2) => {
|
|
6200
|
-
|
|
6282
|
+
execFile3("gh", ["--version"], { timeout: 5e3, ...signal ? { signal } : {} }, (err) => {
|
|
6201
6283
|
const available = !err;
|
|
6202
6284
|
if (!signal?.aborted) ghAvailable = available;
|
|
6203
6285
|
resolve2(available);
|
|
@@ -6213,7 +6295,7 @@ function showGhHint() {
|
|
|
6213
6295
|
async function checkRepoSize(owner, repo) {
|
|
6214
6296
|
if (!await checkGhAvailable()) return null;
|
|
6215
6297
|
return new Promise((resolve2) => {
|
|
6216
|
-
|
|
6298
|
+
execFile3("gh", ["api", `repos/${owner}/${repo}`, "--jq", ".size"], { timeout: 1e4 }, (err, stdout) => {
|
|
6217
6299
|
if (err) {
|
|
6218
6300
|
resolve2(null);
|
|
6219
6301
|
return;
|
|
@@ -6226,7 +6308,7 @@ async function checkRepoSize(owner, repo) {
|
|
|
6226
6308
|
async function getDefaultBranch(owner, repo) {
|
|
6227
6309
|
if (!await checkGhAvailable()) return null;
|
|
6228
6310
|
return new Promise((resolve2) => {
|
|
6229
|
-
|
|
6311
|
+
execFile3("gh", ["api", `repos/${owner}/${repo}`, "--jq", ".default_branch"], { timeout: 1e4 }, (err, stdout) => {
|
|
6230
6312
|
if (err) {
|
|
6231
6313
|
resolve2(null);
|
|
6232
6314
|
return;
|
|
@@ -6239,7 +6321,7 @@ async function getDefaultBranch(owner, repo) {
|
|
|
6239
6321
|
async function fetchTreeViaApi(owner, repo, ref) {
|
|
6240
6322
|
if (!await checkGhAvailable()) return null;
|
|
6241
6323
|
return new Promise((resolve2) => {
|
|
6242
|
-
|
|
6324
|
+
execFile3(
|
|
6243
6325
|
"gh",
|
|
6244
6326
|
["api", `repos/${owner}/${repo}/git/trees/${ref}?recursive=1`, "--jq", ".tree[].path"],
|
|
6245
6327
|
{ timeout: 15e3, maxBuffer: 5 * 1024 * 1024 },
|
|
@@ -6264,7 +6346,7 @@ async function fetchTreeViaApi(owner, repo, ref) {
|
|
|
6264
6346
|
async function fetchReadmeViaApi(owner, repo, ref) {
|
|
6265
6347
|
if (!await checkGhAvailable()) return null;
|
|
6266
6348
|
return new Promise((resolve2) => {
|
|
6267
|
-
|
|
6349
|
+
execFile3(
|
|
6268
6350
|
"gh",
|
|
6269
6351
|
["api", `repos/${owner}/${repo}/readme?ref=${ref}`, "--jq", ".content"],
|
|
6270
6352
|
{ timeout: 1e4 },
|
|
@@ -6286,7 +6368,7 @@ async function fetchReadmeViaApi(owner, repo, ref) {
|
|
|
6286
6368
|
async function fetchFileViaApi(owner, repo, path, ref) {
|
|
6287
6369
|
if (!await checkGhAvailable()) return null;
|
|
6288
6370
|
return new Promise((resolve2) => {
|
|
6289
|
-
|
|
6371
|
+
execFile3(
|
|
6290
6372
|
"gh",
|
|
6291
6373
|
["api", `repos/${owner}/${repo}/contents/${path}?ref=${ref}`, "--jq", ".content"],
|
|
6292
6374
|
{ timeout: 1e4, maxBuffer: 2 * 1024 * 1024 },
|
|
@@ -6365,9 +6447,9 @@ var init_github_api = __esm({
|
|
|
6365
6447
|
});
|
|
6366
6448
|
|
|
6367
6449
|
// github-extract.ts
|
|
6368
|
-
import { chmodSync, closeSync as closeSync2, constants as fsConstants, existsSync as
|
|
6450
|
+
import { chmodSync, closeSync as closeSync2, constants as fsConstants, existsSync as existsSync47, lstatSync as lstatSync2, mkdirSync as mkdirSync2, mkdtempSync as mkdtempSync2, openSync as openSync2, readFileSync as readFileSync48, readSync, readdirSync as readdirSync3, realpathSync as realpathSync2, rmSync as rmSync2, statSync as statSync2, unlinkSync as unlinkSync2, writeFileSync as writeFileSync2 } from "node:fs";
|
|
6369
6451
|
import { lstat as lstatAsync, open as openAsync, opendir as opendirAsync, readFile as readFileAsync, realpath as realpathAsync, rm as rmAsync } from "node:fs/promises";
|
|
6370
|
-
import { execFile as
|
|
6452
|
+
import { execFile as execFile4, spawn as spawn2 } from "node:child_process";
|
|
6371
6453
|
import { createHash as createHash2 } from "node:crypto";
|
|
6372
6454
|
import { basename as basename3, dirname, extname, join as join6, resolve as resolvePath, sep as pathSep } from "node:path";
|
|
6373
6455
|
function normalizeEnabled(value, fallback) {
|
|
@@ -6394,33 +6476,33 @@ function normalizeClonePath(value, fallback) {
|
|
|
6394
6476
|
return expandPath(normalized);
|
|
6395
6477
|
}
|
|
6396
6478
|
function loadGitHubConfig() {
|
|
6397
|
-
if (
|
|
6479
|
+
if (cachedConfig37) return cachedConfig37;
|
|
6398
6480
|
const defaults2 = {
|
|
6399
6481
|
enabled: true,
|
|
6400
6482
|
maxRepoSizeMB: 350,
|
|
6401
6483
|
cloneTimeoutSeconds: 30,
|
|
6402
6484
|
clonePath: "/tmp/pi-github-repos"
|
|
6403
6485
|
};
|
|
6404
|
-
if (!
|
|
6405
|
-
|
|
6406
|
-
return
|
|
6486
|
+
if (!existsSync47(CONFIG_PATH43)) {
|
|
6487
|
+
cachedConfig37 = defaults2;
|
|
6488
|
+
return cachedConfig37;
|
|
6407
6489
|
}
|
|
6408
|
-
const rawText =
|
|
6490
|
+
const rawText = readFileSync48(CONFIG_PATH43, "utf-8");
|
|
6409
6491
|
let raw;
|
|
6410
6492
|
try {
|
|
6411
6493
|
raw = JSON.parse(rawText);
|
|
6412
6494
|
} catch (err) {
|
|
6413
6495
|
const message = err instanceof Error ? err.message : String(err);
|
|
6414
|
-
throw new Error(`Failed to parse ${
|
|
6496
|
+
throw new Error(`Failed to parse ${CONFIG_PATH43}: ${message}`);
|
|
6415
6497
|
}
|
|
6416
6498
|
const gc = raw.githubClone ?? {};
|
|
6417
|
-
|
|
6499
|
+
cachedConfig37 = {
|
|
6418
6500
|
enabled: normalizeEnabled(gc.enabled, defaults2.enabled),
|
|
6419
6501
|
maxRepoSizeMB: normalizePositiveNumber(gc.maxRepoSizeMB, defaults2.maxRepoSizeMB),
|
|
6420
6502
|
cloneTimeoutSeconds: normalizePositiveNumber(gc.cloneTimeoutSeconds, defaults2.cloneTimeoutSeconds),
|
|
6421
6503
|
clonePath: normalizeClonePath(gc.clonePath, defaults2.clonePath)
|
|
6422
6504
|
};
|
|
6423
|
-
return
|
|
6505
|
+
return cachedConfig37;
|
|
6424
6506
|
}
|
|
6425
6507
|
function parseGitHubUrl(url) {
|
|
6426
6508
|
let parsed;
|
|
@@ -6471,7 +6553,7 @@ function cacheKey(owner, repo, ref) {
|
|
|
6471
6553
|
}
|
|
6472
6554
|
function readLinuxBootId() {
|
|
6473
6555
|
try {
|
|
6474
|
-
const bootId =
|
|
6556
|
+
const bootId = readFileSync48("/proc/sys/kernel/random/boot_id", "utf-8").trim();
|
|
6475
6557
|
return bootId.length > 0 ? bootId : null;
|
|
6476
6558
|
} catch {
|
|
6477
6559
|
return null;
|
|
@@ -6496,7 +6578,7 @@ function parseLinuxProcessInfo(stat) {
|
|
|
6496
6578
|
}
|
|
6497
6579
|
function readLinuxProcessInfo(pid) {
|
|
6498
6580
|
try {
|
|
6499
|
-
return parseLinuxProcessInfo(
|
|
6581
|
+
return parseLinuxProcessInfo(readFileSync48(`/proc/${pid}/stat`, "utf-8"));
|
|
6500
6582
|
} catch (err) {
|
|
6501
6583
|
if (err && typeof err === "object" && "code" in err && err.code === "ENOENT") {
|
|
6502
6584
|
return { state: "", startTime: null, dead: true };
|
|
@@ -6538,10 +6620,10 @@ function writeCloneRuntimeOwner(runtimePath) {
|
|
|
6538
6620
|
mode: 384
|
|
6539
6621
|
});
|
|
6540
6622
|
}
|
|
6541
|
-
function parseCloneRuntimeOwner(
|
|
6623
|
+
function parseCloneRuntimeOwner(text5) {
|
|
6542
6624
|
let parsed;
|
|
6543
6625
|
try {
|
|
6544
|
-
parsed = JSON.parse(
|
|
6626
|
+
parsed = JSON.parse(text5);
|
|
6545
6627
|
} catch {
|
|
6546
6628
|
return null;
|
|
6547
6629
|
}
|
|
@@ -6715,7 +6797,7 @@ function terminateProcessTree(child) {
|
|
|
6715
6797
|
const pid = child.pid;
|
|
6716
6798
|
if (!pid) return;
|
|
6717
6799
|
if (process.platform === "win32") {
|
|
6718
|
-
const killer =
|
|
6800
|
+
const killer = execFile4(
|
|
6719
6801
|
"taskkill",
|
|
6720
6802
|
["/pid", String(pid), "/T", "/F"],
|
|
6721
6803
|
{ windowsHide: true },
|
|
@@ -6834,7 +6916,7 @@ function resolveWithinRepo(rootPath, relativePath) {
|
|
|
6834
6916
|
const rootPrefix = normalizedRoot.endsWith(pathSep) ? normalizedRoot : normalizedRoot + pathSep;
|
|
6835
6917
|
if (!candidate.startsWith(rootPrefix)) return null;
|
|
6836
6918
|
}
|
|
6837
|
-
if (!
|
|
6919
|
+
if (!existsSync47(candidate)) return candidate;
|
|
6838
6920
|
try {
|
|
6839
6921
|
const realRoot = realpathSync2(normalizedRoot);
|
|
6840
6922
|
const realCandidate = realpathSync2(candidate);
|
|
@@ -6847,7 +6929,7 @@ function resolveWithinRepo(rootPath, relativePath) {
|
|
|
6847
6929
|
}
|
|
6848
6930
|
function readTextFile(path) {
|
|
6849
6931
|
try {
|
|
6850
|
-
return
|
|
6932
|
+
return readFileSync48(path, "utf-8");
|
|
6851
6933
|
} catch {
|
|
6852
6934
|
return null;
|
|
6853
6935
|
}
|
|
@@ -6930,9 +7012,9 @@ function readReadme(localPath) {
|
|
|
6930
7012
|
const candidates = ["README.md", "readme.md", "README", "README.txt", "README.rst"];
|
|
6931
7013
|
for (const name of candidates) {
|
|
6932
7014
|
const readmePath = join6(localPath, name);
|
|
6933
|
-
if (
|
|
7015
|
+
if (existsSync47(readmePath)) {
|
|
6934
7016
|
try {
|
|
6935
|
-
const content =
|
|
7017
|
+
const content = readFileSync48(readmePath, "utf-8");
|
|
6936
7018
|
return content.length > 8192 ? content.slice(0, 8192) + "\n\n[README truncated at 8K chars]" : content;
|
|
6937
7019
|
} catch {
|
|
6938
7020
|
continue;
|
|
@@ -6961,7 +7043,7 @@ function generateContent(localPath, info) {
|
|
|
6961
7043
|
if (info.type === "tree") {
|
|
6962
7044
|
const dirPath = info.path || "";
|
|
6963
7045
|
const fullDirPath = resolveWithinRepo(localPath, dirPath);
|
|
6964
|
-
if (!fullDirPath || !
|
|
7046
|
+
if (!fullDirPath || !existsSync47(fullDirPath)) {
|
|
6965
7047
|
lines.push(`Path \`${dirPath}\` not found in clone. Showing repository root instead.`);
|
|
6966
7048
|
lines.push("");
|
|
6967
7049
|
lines.push("## Structure");
|
|
@@ -6977,7 +7059,7 @@ function generateContent(localPath, info) {
|
|
|
6977
7059
|
if (info.type === "blob") {
|
|
6978
7060
|
const filePath = info.path || "";
|
|
6979
7061
|
const fullFilePath = resolveWithinRepo(localPath, filePath);
|
|
6980
|
-
if (!fullFilePath || !
|
|
7062
|
+
if (!fullFilePath || !existsSync47(fullFilePath)) {
|
|
6981
7063
|
lines.push(`Path \`${filePath}\` not found in clone. Showing repository root instead.`);
|
|
6982
7064
|
lines.push("");
|
|
6983
7065
|
lines.push("## Structure");
|
|
@@ -7139,13 +7221,13 @@ async function extractGitHub(url, signal, forceClone) {
|
|
|
7139
7221
|
const title = info.path ? `${owner}/${repo} - ${info.path}` : `${owner}/${repo}`;
|
|
7140
7222
|
return { url, title, content, error: null };
|
|
7141
7223
|
}
|
|
7142
|
-
var
|
|
7224
|
+
var CONFIG_PATH43, BINARY_EXTENSIONS, NOISE_DIRS, MAX_INLINE_FILE_CHARS2, MAX_TREE_ENTRIES2, CLONE_RUNTIME_OWNER_FILENAME, CLONE_RUNTIME_OWNER_VERSION, MAX_CLONE_RUNTIME_OWNER_BYTES, cloneCache, startedCloneRuntimeCleanups, cachedConfig37, cloneRuntime, NON_CODE_SEGMENTS, PROCESS_KILL_GRACE_MS;
|
|
7143
7225
|
var init_github_extract = __esm({
|
|
7144
7226
|
"github-extract.ts"() {
|
|
7145
7227
|
init_activity();
|
|
7146
7228
|
init_github_api();
|
|
7147
7229
|
init_utils();
|
|
7148
|
-
|
|
7230
|
+
CONFIG_PATH43 = getWebSearchConfigPath();
|
|
7149
7231
|
BINARY_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
7150
7232
|
".png",
|
|
7151
7233
|
".jpg",
|
|
@@ -7233,7 +7315,7 @@ var init_github_extract = __esm({
|
|
|
7233
7315
|
MAX_CLONE_RUNTIME_OWNER_BYTES = 1024;
|
|
7234
7316
|
cloneCache = /* @__PURE__ */ new Map();
|
|
7235
7317
|
startedCloneRuntimeCleanups = /* @__PURE__ */ new Set();
|
|
7236
|
-
|
|
7318
|
+
cachedConfig37 = null;
|
|
7237
7319
|
cloneRuntime = null;
|
|
7238
7320
|
NON_CODE_SEGMENTS = /* @__PURE__ */ new Set([
|
|
7239
7321
|
"issues",
|
|
@@ -7271,30 +7353,30 @@ var init_github_extract = __esm({
|
|
|
7271
7353
|
});
|
|
7272
7354
|
|
|
7273
7355
|
// github-issue-pr.ts
|
|
7274
|
-
import { execFile as
|
|
7275
|
-
import { existsSync as
|
|
7276
|
-
function
|
|
7277
|
-
if (
|
|
7356
|
+
import { execFile as execFile5 } from "node:child_process";
|
|
7357
|
+
import { existsSync as existsSync48, readFileSync as readFileSync49 } from "node:fs";
|
|
7358
|
+
function loadConfig38() {
|
|
7359
|
+
if (cachedConfig38) return cachedConfig38;
|
|
7278
7360
|
const defaults2 = { enabled: true };
|
|
7279
|
-
if (!
|
|
7280
|
-
|
|
7281
|
-
return
|
|
7361
|
+
if (!existsSync48(CONFIG_PATH44)) {
|
|
7362
|
+
cachedConfig38 = defaults2;
|
|
7363
|
+
return cachedConfig38;
|
|
7282
7364
|
}
|
|
7283
7365
|
let parsed;
|
|
7284
7366
|
try {
|
|
7285
|
-
parsed = JSON.parse(
|
|
7367
|
+
parsed = JSON.parse(readFileSync49(CONFIG_PATH44, "utf-8"));
|
|
7286
7368
|
} catch (err) {
|
|
7287
7369
|
const message = err instanceof Error ? err.message : String(err);
|
|
7288
|
-
throw new Error(`Failed to parse ${
|
|
7370
|
+
throw new Error(`Failed to parse ${CONFIG_PATH44}: ${message}`);
|
|
7289
7371
|
}
|
|
7290
7372
|
const root = parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : {};
|
|
7291
7373
|
const value = root.githubPrIssue;
|
|
7292
7374
|
if (value !== void 0 && (typeof value !== "object" || value === null || Array.isArray(value))) {
|
|
7293
|
-
throw new Error(`githubPrIssue in ${
|
|
7375
|
+
throw new Error(`githubPrIssue in ${CONFIG_PATH44} must be an object`);
|
|
7294
7376
|
}
|
|
7295
7377
|
const enabled = typeof value?.enabled === "boolean" ? value.enabled : true;
|
|
7296
|
-
|
|
7297
|
-
return
|
|
7378
|
+
cachedConfig38 = { enabled };
|
|
7379
|
+
return cachedConfig38;
|
|
7298
7380
|
}
|
|
7299
7381
|
function validOwner(owner) {
|
|
7300
7382
|
return /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/.test(owner) && !owner.includes("--");
|
|
@@ -7302,11 +7384,11 @@ function validOwner(owner) {
|
|
|
7302
7384
|
function validRepo(repo) {
|
|
7303
7385
|
return /^[A-Za-z0-9._-]{1,100}$/.test(repo) && repo !== "." && repo !== "..";
|
|
7304
7386
|
}
|
|
7305
|
-
function
|
|
7387
|
+
function errorMessage29(err) {
|
|
7306
7388
|
return err instanceof Error ? err.message : String(err);
|
|
7307
7389
|
}
|
|
7308
7390
|
function isAbortError3(err) {
|
|
7309
|
-
return
|
|
7391
|
+
return errorMessage29(err).toLowerCase().includes("abort");
|
|
7310
7392
|
}
|
|
7311
7393
|
function parseGitHubIssuePrUrl(url) {
|
|
7312
7394
|
let parsed;
|
|
@@ -7344,7 +7426,7 @@ function parseGitHubIssuePrUrl(url) {
|
|
|
7344
7426
|
}
|
|
7345
7427
|
function runGh(args, timeoutMs = GH_TIMEOUT_MS, signal) {
|
|
7346
7428
|
return new Promise((resolve2) => {
|
|
7347
|
-
|
|
7429
|
+
execFile5("gh", args, {
|
|
7348
7430
|
timeout: timeoutMs,
|
|
7349
7431
|
maxBuffer: 10 * 1024 * 1024,
|
|
7350
7432
|
...signal ? { signal } : {},
|
|
@@ -7542,7 +7624,7 @@ async function restFallback(url, info, options, signal) {
|
|
|
7542
7624
|
return { data: { url, owner: info.owner, repo: info.repo, kind: info.kind, number: info.number, anchor: info.anchor, view, reviewThreads, fallbackNotes: notes } };
|
|
7543
7625
|
} catch (err) {
|
|
7544
7626
|
if (signal?.aborted || isAbortError3(err)) return { url, title: "", content: "", error: "Aborted" };
|
|
7545
|
-
const message =
|
|
7627
|
+
const message = errorMessage29(err);
|
|
7546
7628
|
return { url, title: `${info.owner}/${info.repo}#${info.number}`, content: message, error: `GitHub REST fallback failed: ${message}` };
|
|
7547
7629
|
}
|
|
7548
7630
|
}
|
|
@@ -7600,14 +7682,14 @@ function milestoneTitle(value) {
|
|
|
7600
7682
|
if (!value || typeof value !== "object" || Array.isArray(value)) return "none";
|
|
7601
7683
|
return stringValue(value.title) || "none";
|
|
7602
7684
|
}
|
|
7603
|
-
function truncateText(
|
|
7604
|
-
if (
|
|
7605
|
-
const lastSpace =
|
|
7685
|
+
function truncateText(text5, limit, label, appendix, tool) {
|
|
7686
|
+
if (text5.length <= limit) return text5;
|
|
7687
|
+
const lastSpace = text5.slice(0, limit + 1).search(/\s\S*$/);
|
|
7606
7688
|
const cut = lastSpace > limit * 0.8 ? lastSpace : limit;
|
|
7607
7689
|
appendix.push(`## ${label} (continued)
|
|
7608
7690
|
|
|
7609
|
-
${
|
|
7610
|
-
return `${
|
|
7691
|
+
${text5.slice(cut)}`);
|
|
7692
|
+
return `${text5.slice(0, cut)}
|
|
7611
7693
|
|
|
7612
7694
|
[${label} truncated; ${tool ? `the rest is stored under "${label} (continued)": use ${tool} findText or offset` : "use the gh escalation commands below for the rest"}]`;
|
|
7613
7695
|
}
|
|
@@ -7653,9 +7735,9 @@ function renderComments(comments, anchor, appendix, tool) {
|
|
|
7653
7735
|
const render = (comment, inline) => {
|
|
7654
7736
|
const body = stringValue(comment.body);
|
|
7655
7737
|
const label = `comment ${commentId(comment) || comments.indexOf(comment) + 1}`;
|
|
7656
|
-
const
|
|
7738
|
+
const text5 = inline ? truncateText(body, COMMENT_INLINE_CHARS, label, appendix, tool) : body;
|
|
7657
7739
|
return `- ${authorLogin(comment.author ?? comment.user)} at ${stringValue(comment.createdAt) || stringValue(comment.created_at)}${forced === comment ? " [anchored]" : ""}:
|
|
7658
|
-
${
|
|
7740
|
+
${text5.replace(/\n/g, "\n ")}`;
|
|
7659
7741
|
};
|
|
7660
7742
|
const lines = selected.map((comment) => render(comment, true));
|
|
7661
7743
|
storeOmitted(appendix, "Conversation comments", comments.slice(MAX_INLINE_COMMENTS).filter((comment) => comment !== forced).map((comment) => render(comment, false)));
|
|
@@ -7748,8 +7830,8 @@ function renderReviewThreads(comments, anchor, appendix, tool, total, bounded, u
|
|
|
7748
7830
|
const render = (comment, inline) => {
|
|
7749
7831
|
const path = stringValue(comment.path) || "unknown path";
|
|
7750
7832
|
const line = numberValue(comment.line) ?? numberValue(comment.original_line) ?? numberValue(comment.position) ?? "?";
|
|
7751
|
-
const
|
|
7752
|
-
const body = inline ? truncateText(
|
|
7833
|
+
const text5 = stringValue(comment.body);
|
|
7834
|
+
const body = inline ? truncateText(text5, COMMENT_INLINE_CHARS, `review thread comment ${commentId(comment) || comments.indexOf(comment) + 1}`, appendix, tool) : text5;
|
|
7753
7835
|
return `- ${path}:${line} \u2014 ${authorLogin(comment.user ?? comment.author)}${forced === comment ? " [anchored]" : ""} (resolution state unknown):
|
|
7754
7836
|
${body.replace(/\n/g, "\n ")}`;
|
|
7755
7837
|
};
|
|
@@ -7840,7 +7922,7 @@ function renderGitHubPrIssue(data) {
|
|
|
7840
7922
|
async function extractGitHubIssuePr(url, signal, options) {
|
|
7841
7923
|
const info = parseGitHubIssuePrUrl(url);
|
|
7842
7924
|
if (!info) return null;
|
|
7843
|
-
if (!
|
|
7925
|
+
if (!loadConfig38().enabled) return null;
|
|
7844
7926
|
if (signal?.aborted) return { url, title: "", content: "", error: "Aborted" };
|
|
7845
7927
|
const retrievalTool = options?.toolNames ? options.toolNames.getSearchContent ?? null : void 0;
|
|
7846
7928
|
const ghAvailable2 = await checkGhAvailable(signal);
|
|
@@ -7864,13 +7946,13 @@ async function extractGitHubIssuePr(url, signal, options) {
|
|
|
7864
7946
|
if ("data" in fallback) return renderGitHubPrIssue({ ...fallback.data, retrievalTool });
|
|
7865
7947
|
return fallback;
|
|
7866
7948
|
}
|
|
7867
|
-
var
|
|
7949
|
+
var CONFIG_PATH44, GH_TIMEOUT_MS, GH_TOTAL_TIMEOUT_MS, MAX_DOC_CHARS, BODY_INLINE_CHARS, COMMENT_INLINE_CHARS, MAX_INLINE_COMMENTS, MAX_INLINE_REVIEWS, MAX_INLINE_CHECKS, MAX_INLINE_FILES, MAX_INLINE_COMMITS, MAX_INLINE_REVIEW_THREADS, REST_HEADERS, PR_SUBPATHS, PR_FIELDS, PR_CORE_FIELDS, ISSUE_FIELDS, ISSUE_CORE_FIELDS, cachedConfig38;
|
|
7868
7950
|
var init_github_issue_pr = __esm({
|
|
7869
7951
|
"github-issue-pr.ts"() {
|
|
7870
7952
|
init_github_api();
|
|
7871
7953
|
init_ssrf_protection();
|
|
7872
7954
|
init_utils();
|
|
7873
|
-
|
|
7955
|
+
CONFIG_PATH44 = getWebSearchConfigPath();
|
|
7874
7956
|
GH_TIMEOUT_MS = 1e4;
|
|
7875
7957
|
GH_TOTAL_TIMEOUT_MS = 2e4;
|
|
7876
7958
|
MAX_DOC_CHARS = 15e4;
|
|
@@ -7951,20 +8033,20 @@ var init_github_issue_pr = __esm({
|
|
|
7951
8033
|
"url"
|
|
7952
8034
|
];
|
|
7953
8035
|
ISSUE_CORE_FIELDS = ["title", "number", "state", "author", "createdAt", "closedAt", "labels", "assignees", "milestone", "comments", "body", "url"];
|
|
7954
|
-
|
|
8036
|
+
cachedConfig38 = null;
|
|
7955
8037
|
}
|
|
7956
8038
|
});
|
|
7957
8039
|
|
|
7958
8040
|
// feature-config.ts
|
|
7959
|
-
import { existsSync as
|
|
8041
|
+
import { existsSync as existsSync49, readFileSync as readFileSync50 } from "node:fs";
|
|
7960
8042
|
function loadFeatureConfig() {
|
|
7961
|
-
if (!
|
|
8043
|
+
if (!existsSync49(CONFIG_PATH45)) return {};
|
|
7962
8044
|
try {
|
|
7963
|
-
const raw = JSON.parse(
|
|
8045
|
+
const raw = JSON.parse(readFileSync50(CONFIG_PATH45, "utf-8"));
|
|
7964
8046
|
return raw && typeof raw === "object" ? raw : {};
|
|
7965
8047
|
} catch (err) {
|
|
7966
8048
|
const message = err instanceof Error ? err.message : String(err);
|
|
7967
|
-
throw new Error(`Failed to parse ${
|
|
8049
|
+
throw new Error(`Failed to parse ${CONFIG_PATH45}: ${message}`);
|
|
7968
8050
|
}
|
|
7969
8051
|
}
|
|
7970
8052
|
function isImageEnabled() {
|
|
@@ -7977,25 +8059,25 @@ function canAttachImages() {
|
|
|
7977
8059
|
return false;
|
|
7978
8060
|
}
|
|
7979
8061
|
}
|
|
7980
|
-
var
|
|
8062
|
+
var CONFIG_PATH45;
|
|
7981
8063
|
var init_feature_config = __esm({
|
|
7982
8064
|
"feature-config.ts"() {
|
|
7983
8065
|
init_utils();
|
|
7984
|
-
|
|
8066
|
+
CONFIG_PATH45 = getWebSearchConfigPath();
|
|
7985
8067
|
}
|
|
7986
8068
|
});
|
|
7987
8069
|
|
|
7988
8070
|
// youtube-extract.ts
|
|
7989
8071
|
import { execFileSync } from "node:child_process";
|
|
7990
|
-
import { existsSync as
|
|
7991
|
-
function
|
|
8072
|
+
import { existsSync as existsSync50, readFileSync as readFileSync51 } from "node:fs";
|
|
8073
|
+
function errorMessage30(err) {
|
|
7992
8074
|
return err instanceof Error ? err.message : String(err);
|
|
7993
8075
|
}
|
|
7994
8076
|
function shouldRethrow(err) {
|
|
7995
|
-
return
|
|
8077
|
+
return errorMessage30(err).startsWith("Failed to parse ");
|
|
7996
8078
|
}
|
|
7997
8079
|
function addAttemptError(errors, label, err) {
|
|
7998
|
-
const message =
|
|
8080
|
+
const message = errorMessage30(err).replace(/\s+/g, " ").trim();
|
|
7999
8081
|
if (message) errors.push(`${label}: ${message}`);
|
|
8000
8082
|
}
|
|
8001
8083
|
function normalizePreferredModel(value, fallback) {
|
|
@@ -8007,25 +8089,25 @@ function normalizeEnabled2(value, fallback) {
|
|
|
8007
8089
|
return typeof value === "boolean" ? value : fallback;
|
|
8008
8090
|
}
|
|
8009
8091
|
function loadYouTubeConfig() {
|
|
8010
|
-
if (
|
|
8011
|
-
if (!
|
|
8012
|
-
|
|
8013
|
-
return
|
|
8092
|
+
if (cachedConfig39) return cachedConfig39;
|
|
8093
|
+
if (!existsSync50(CONFIG_PATH46)) {
|
|
8094
|
+
cachedConfig39 = { ...defaults };
|
|
8095
|
+
return cachedConfig39;
|
|
8014
8096
|
}
|
|
8015
|
-
const rawText =
|
|
8097
|
+
const rawText = readFileSync51(CONFIG_PATH46, "utf-8");
|
|
8016
8098
|
let raw;
|
|
8017
8099
|
try {
|
|
8018
8100
|
raw = JSON.parse(rawText);
|
|
8019
8101
|
} catch (err) {
|
|
8020
8102
|
const message = err instanceof Error ? err.message : String(err);
|
|
8021
|
-
throw new Error(`Failed to parse ${
|
|
8103
|
+
throw new Error(`Failed to parse ${CONFIG_PATH46}: ${message}`);
|
|
8022
8104
|
}
|
|
8023
8105
|
const yt = raw.youtube ?? {};
|
|
8024
|
-
|
|
8106
|
+
cachedConfig39 = {
|
|
8025
8107
|
enabled: normalizeEnabled2(yt.enabled, defaults.enabled),
|
|
8026
8108
|
preferredModel: normalizePreferredModel(yt.preferredModel, defaults.preferredModel)
|
|
8027
8109
|
};
|
|
8028
|
-
return
|
|
8110
|
+
return cachedConfig39;
|
|
8029
8111
|
}
|
|
8030
8112
|
function isYouTubeURL(url) {
|
|
8031
8113
|
try {
|
|
@@ -8155,7 +8237,7 @@ async function tryGeminiWeb(url, prompt, model, signal, attemptErrors) {
|
|
|
8155
8237
|
const cookies = await isGeminiWebAvailable();
|
|
8156
8238
|
if (!cookies) return null;
|
|
8157
8239
|
if (signal?.aborted) return null;
|
|
8158
|
-
const
|
|
8240
|
+
const text5 = await queryWithCookies(prompt, cookies, {
|
|
8159
8241
|
youtubeUrl: url,
|
|
8160
8242
|
...model !== "gemini-3.6-flash" ? { model } : {},
|
|
8161
8243
|
signal,
|
|
@@ -8163,8 +8245,8 @@ async function tryGeminiWeb(url, prompt, model, signal, attemptErrors) {
|
|
|
8163
8245
|
});
|
|
8164
8246
|
return {
|
|
8165
8247
|
url,
|
|
8166
|
-
title: extractHeadingTitle(
|
|
8167
|
-
content:
|
|
8248
|
+
title: extractHeadingTitle(text5) ?? "YouTube Video",
|
|
8249
|
+
content: text5,
|
|
8168
8250
|
error: null
|
|
8169
8251
|
};
|
|
8170
8252
|
} catch (err) {
|
|
@@ -8177,15 +8259,15 @@ async function tryGeminiApi(url, prompt, model, signal, attemptErrors) {
|
|
|
8177
8259
|
try {
|
|
8178
8260
|
if (!isGeminiApiAvailableWithVideo()) return null;
|
|
8179
8261
|
if (signal?.aborted) return null;
|
|
8180
|
-
const
|
|
8262
|
+
const text5 = await queryGeminiApiWithVideo(prompt, url, {
|
|
8181
8263
|
model,
|
|
8182
8264
|
signal,
|
|
8183
8265
|
timeoutMs: 12e4
|
|
8184
8266
|
});
|
|
8185
8267
|
return {
|
|
8186
8268
|
url,
|
|
8187
|
-
title: extractHeadingTitle(
|
|
8188
|
-
content:
|
|
8269
|
+
title: extractHeadingTitle(text5) ?? "YouTube Video",
|
|
8270
|
+
content: text5,
|
|
8189
8271
|
error: null
|
|
8190
8272
|
};
|
|
8191
8273
|
} catch (err) {
|
|
@@ -8217,7 +8299,7 @@ ${answer}
|
|
|
8217
8299
|
return null;
|
|
8218
8300
|
}
|
|
8219
8301
|
}
|
|
8220
|
-
var
|
|
8302
|
+
var CONFIG_PATH46, YOUTUBE_PROMPT, YOUTUBE_REGEX, defaults, cachedConfig39;
|
|
8221
8303
|
var init_youtube_extract = __esm({
|
|
8222
8304
|
"youtube-extract.ts"() {
|
|
8223
8305
|
init_activity();
|
|
@@ -8227,7 +8309,7 @@ var init_youtube_extract = __esm({
|
|
|
8227
8309
|
init_perplexity();
|
|
8228
8310
|
init_extract();
|
|
8229
8311
|
init_utils();
|
|
8230
|
-
|
|
8312
|
+
CONFIG_PATH46 = getWebSearchConfigPath();
|
|
8231
8313
|
YOUTUBE_PROMPT = `Extract the complete content of this YouTube video. Include:
|
|
8232
8314
|
1. Video title, channel name, and duration
|
|
8233
8315
|
2. A brief summary (2-3 sentences)
|
|
@@ -8237,7 +8319,7 @@ var init_youtube_extract = __esm({
|
|
|
8237
8319
|
Format as markdown.`;
|
|
8238
8320
|
YOUTUBE_REGEX = /(?:(?:www\.|m\.)?youtube\.com\/(?:watch\?.*v=|shorts\/|live\/|embed\/|v\/)|youtu\.be\/)([a-zA-Z0-9_-]{11})/;
|
|
8239
8321
|
defaults = { enabled: true, preferredModel: "gemini-3.6-flash" };
|
|
8240
|
-
|
|
8322
|
+
cachedConfig39 = null;
|
|
8241
8323
|
}
|
|
8242
8324
|
});
|
|
8243
8325
|
|
|
@@ -8299,14 +8381,14 @@ async function extractWithGeminiWeb(url, signal) {
|
|
|
8299
8381
|
if (!cookies) return null;
|
|
8300
8382
|
const activityId = activityMonitor.logStart({ type: "api", query: `gemini_web: ${url}` });
|
|
8301
8383
|
try {
|
|
8302
|
-
const
|
|
8384
|
+
const text5 = await queryWithCookies(EXTRACTION_PROMPT + url, cookies, {
|
|
8303
8385
|
signal,
|
|
8304
8386
|
timeoutMs: 6e4
|
|
8305
8387
|
});
|
|
8306
8388
|
activityMonitor.logComplete(activityId, 200);
|
|
8307
|
-
if (!
|
|
8308
|
-
const title = extractTitleFromContent(
|
|
8309
|
-
return { url, title, content:
|
|
8389
|
+
if (!text5 || text5.length < 50) return null;
|
|
8390
|
+
const title = extractTitleFromContent(text5, url);
|
|
8391
|
+
return { url, title, content: text5, error: null };
|
|
8310
8392
|
} catch (err) {
|
|
8311
8393
|
if (shouldRethrow2(err)) throw err;
|
|
8312
8394
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -8318,8 +8400,8 @@ async function extractWithGeminiWeb(url, signal) {
|
|
|
8318
8400
|
return null;
|
|
8319
8401
|
}
|
|
8320
8402
|
}
|
|
8321
|
-
function extractTitleFromContent(
|
|
8322
|
-
return extractHeadingTitle(
|
|
8403
|
+
function extractTitleFromContent(text5, url) {
|
|
8404
|
+
return extractHeadingTitle(text5) ?? (new URL(url).pathname.split("/").pop() || url);
|
|
8323
8405
|
}
|
|
8324
8406
|
var EXTRACTION_PROMPT;
|
|
8325
8407
|
var init_gemini_url_context = __esm({
|
|
@@ -8339,26 +8421,26 @@ URL: `;
|
|
|
8339
8421
|
});
|
|
8340
8422
|
|
|
8341
8423
|
// crawl4ai.ts
|
|
8342
|
-
import { existsSync as
|
|
8343
|
-
function
|
|
8344
|
-
if (
|
|
8345
|
-
if (!
|
|
8346
|
-
|
|
8347
|
-
return
|
|
8424
|
+
import { existsSync as existsSync51, readFileSync as readFileSync52 } from "node:fs";
|
|
8425
|
+
function loadConfig39() {
|
|
8426
|
+
if (cachedConfig40) return cachedConfig40;
|
|
8427
|
+
if (!existsSync51(CONFIG_PATH47)) {
|
|
8428
|
+
cachedConfig40 = {};
|
|
8429
|
+
return cachedConfig40;
|
|
8348
8430
|
}
|
|
8349
|
-
const raw =
|
|
8431
|
+
const raw = readFileSync52(CONFIG_PATH47, "utf8");
|
|
8350
8432
|
let parsed;
|
|
8351
8433
|
try {
|
|
8352
8434
|
parsed = JSON.parse(raw);
|
|
8353
8435
|
} catch (err) {
|
|
8354
8436
|
const message = err instanceof Error ? err.message : String(err);
|
|
8355
|
-
throw new Error(`Failed to parse ${
|
|
8437
|
+
throw new Error(`Failed to parse ${CONFIG_PATH47}: ${message}`);
|
|
8356
8438
|
}
|
|
8357
8439
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
8358
|
-
throw new Error(`Invalid config in ${
|
|
8440
|
+
throw new Error(`Invalid config in ${CONFIG_PATH47}: expected a JSON object`);
|
|
8359
8441
|
}
|
|
8360
|
-
|
|
8361
|
-
return
|
|
8442
|
+
cachedConfig40 = parsed;
|
|
8443
|
+
return cachedConfig40;
|
|
8362
8444
|
}
|
|
8363
8445
|
function normalizeBaseUrl5(value) {
|
|
8364
8446
|
if (typeof value !== "string") return null;
|
|
@@ -8368,13 +8450,13 @@ function normalizeBaseUrl5(value) {
|
|
|
8368
8450
|
try {
|
|
8369
8451
|
parsed = new URL(trimmed);
|
|
8370
8452
|
} catch {
|
|
8371
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
8453
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH47}: expected an HTTP or HTTPS URL`);
|
|
8372
8454
|
}
|
|
8373
8455
|
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
8374
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
8456
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH47}: expected an HTTP or HTTPS URL`);
|
|
8375
8457
|
}
|
|
8376
8458
|
if (parsed.username || parsed.password) {
|
|
8377
|
-
throw new Error(`Invalid Crawl4AI base URL in ${
|
|
8459
|
+
throw new Error(`Invalid Crawl4AI base URL in ${CONFIG_PATH47}: URL credentials are not allowed`);
|
|
8378
8460
|
}
|
|
8379
8461
|
parsed.pathname = parsed.pathname.replace(/\/+$/, "");
|
|
8380
8462
|
parsed.search = "";
|
|
@@ -8382,14 +8464,14 @@ function normalizeBaseUrl5(value) {
|
|
|
8382
8464
|
return parsed.toString().replace(/\/+$/, "");
|
|
8383
8465
|
}
|
|
8384
8466
|
function getBaseUrl4() {
|
|
8385
|
-
return normalizeBaseUrl5(process.env.CRAWL4AI_BASE_URL) ?? normalizeBaseUrl5(
|
|
8467
|
+
return normalizeBaseUrl5(process.env.CRAWL4AI_BASE_URL) ?? normalizeBaseUrl5(loadConfig39().crawl4aiBaseUrl);
|
|
8386
8468
|
}
|
|
8387
8469
|
function requireBaseUrl4() {
|
|
8388
8470
|
const baseUrl = getBaseUrl4();
|
|
8389
8471
|
if (!baseUrl) {
|
|
8390
8472
|
throw new Error(
|
|
8391
8473
|
`Crawl4AI base URL not configured. Either:
|
|
8392
|
-
1. Set crawl4aiBaseUrl in ${
|
|
8474
|
+
1. Set crawl4aiBaseUrl in ${CONFIG_PATH47}
|
|
8393
8475
|
2. Set CRAWL4AI_BASE_URL environment variable`
|
|
8394
8476
|
);
|
|
8395
8477
|
}
|
|
@@ -8398,7 +8480,7 @@ function requireBaseUrl4() {
|
|
|
8398
8480
|
async function getApiToken(signal) {
|
|
8399
8481
|
return resolveCredential({
|
|
8400
8482
|
provider: "Crawl4AI",
|
|
8401
|
-
configuredValue:
|
|
8483
|
+
configuredValue: loadConfig39().crawl4aiApiToken,
|
|
8402
8484
|
environmentValue: process.env.CRAWL4AI_API_TOKEN,
|
|
8403
8485
|
signal
|
|
8404
8486
|
});
|
|
@@ -8407,7 +8489,7 @@ function requestSignal13(timeoutMs, signal) {
|
|
|
8407
8489
|
const timeout = AbortSignal.timeout(timeoutMs);
|
|
8408
8490
|
return signal ? AbortSignal.any([timeout, signal]) : timeout;
|
|
8409
8491
|
}
|
|
8410
|
-
function
|
|
8492
|
+
function errorMessage31(err) {
|
|
8411
8493
|
return err instanceof Error ? err.message : String(err);
|
|
8412
8494
|
}
|
|
8413
8495
|
function isAbortException(err) {
|
|
@@ -8455,8 +8537,8 @@ async function extractWithCrawl4ai(url, signal, options) {
|
|
|
8455
8537
|
}
|
|
8456
8538
|
});
|
|
8457
8539
|
if (!response.ok) {
|
|
8458
|
-
const
|
|
8459
|
-
throw new Error(`Crawl4AI md error ${response.status}: ${redactCredential(
|
|
8540
|
+
const text5 = await response.text().catch(() => "");
|
|
8541
|
+
throw new Error(`Crawl4AI md error ${response.status}: ${redactCredential(text5, token).slice(0, 300)}`);
|
|
8460
8542
|
}
|
|
8461
8543
|
let data;
|
|
8462
8544
|
try {
|
|
@@ -8484,49 +8566,49 @@ async function extractWithCrawl4ai(url, signal, options) {
|
|
|
8484
8566
|
return { url, title: firstHeadingTitle(content), content, error: null };
|
|
8485
8567
|
} catch (err) {
|
|
8486
8568
|
if (signal?.aborted || isAbortException(err)) activityMonitor.logComplete(activityId, 0);
|
|
8487
|
-
else activityMonitor.logError(activityId,
|
|
8569
|
+
else activityMonitor.logError(activityId, errorMessage31(err));
|
|
8488
8570
|
throw err;
|
|
8489
8571
|
}
|
|
8490
8572
|
}
|
|
8491
|
-
var
|
|
8573
|
+
var CONFIG_PATH47, EXTRACT_TIMEOUT_MS2, MARKDOWN_FILTER, cachedConfig40;
|
|
8492
8574
|
var init_crawl4ai = __esm({
|
|
8493
8575
|
"crawl4ai.ts"() {
|
|
8494
8576
|
init_activity();
|
|
8495
8577
|
init_credential_source();
|
|
8496
8578
|
init_ssrf_protection();
|
|
8497
8579
|
init_utils();
|
|
8498
|
-
|
|
8580
|
+
CONFIG_PATH47 = getWebSearchConfigPath();
|
|
8499
8581
|
EXTRACT_TIMEOUT_MS2 = 6e4;
|
|
8500
8582
|
MARKDOWN_FILTER = "fit";
|
|
8501
|
-
|
|
8583
|
+
cachedConfig40 = null;
|
|
8502
8584
|
}
|
|
8503
8585
|
});
|
|
8504
8586
|
|
|
8505
8587
|
// brightdata-unlocker.ts
|
|
8506
|
-
import { existsSync as
|
|
8588
|
+
import { existsSync as existsSync52, readFileSync as readFileSync53 } from "node:fs";
|
|
8507
8589
|
function parseFailureDetail(err) {
|
|
8508
8590
|
const message = err instanceof Error ? err.message : String(err);
|
|
8509
8591
|
const position = message.match(/at position \d+(?: \(line \d+ column \d+\))?/);
|
|
8510
8592
|
return position ? `invalid JSON ${position[0]}` : "invalid JSON";
|
|
8511
8593
|
}
|
|
8512
|
-
function
|
|
8513
|
-
if (
|
|
8514
|
-
if (!
|
|
8515
|
-
|
|
8516
|
-
return
|
|
8594
|
+
function loadConfig40() {
|
|
8595
|
+
if (cachedConfig41) return cachedConfig41;
|
|
8596
|
+
if (!existsSync52(CONFIG_PATH48)) {
|
|
8597
|
+
cachedConfig41 = {};
|
|
8598
|
+
return cachedConfig41;
|
|
8517
8599
|
}
|
|
8518
|
-
const raw =
|
|
8600
|
+
const raw = readFileSync53(CONFIG_PATH48, "utf8");
|
|
8519
8601
|
let parsed;
|
|
8520
8602
|
try {
|
|
8521
8603
|
parsed = JSON.parse(raw);
|
|
8522
8604
|
} catch (err) {
|
|
8523
|
-
throw new Error(`Failed to parse ${
|
|
8605
|
+
throw new Error(`Failed to parse ${CONFIG_PATH48}: ${parseFailureDetail(err)}`);
|
|
8524
8606
|
}
|
|
8525
8607
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
8526
|
-
throw new Error(`Invalid config in ${
|
|
8608
|
+
throw new Error(`Invalid config in ${CONFIG_PATH48}: expected a JSON object`);
|
|
8527
8609
|
}
|
|
8528
|
-
|
|
8529
|
-
return
|
|
8610
|
+
cachedConfig41 = parsed;
|
|
8611
|
+
return cachedConfig41;
|
|
8530
8612
|
}
|
|
8531
8613
|
function normalizeZone2(value) {
|
|
8532
8614
|
if (typeof value !== "string") return null;
|
|
@@ -8537,8 +8619,8 @@ function normalizeZone2(value) {
|
|
|
8537
8619
|
function zoneSetting() {
|
|
8538
8620
|
const fromEnv = process.env.BRIGHTDATA_UNLOCKER_ZONE;
|
|
8539
8621
|
if (typeof fromEnv === "string" && fromEnv.trim()) return { raw: fromEnv.trim(), label: "BRIGHTDATA_UNLOCKER_ZONE" };
|
|
8540
|
-
const configured =
|
|
8541
|
-
if (typeof configured === "string" && configured.trim()) return { raw: configured.trim(), label: `brightdataUnlockerZone in ${
|
|
8622
|
+
const configured = loadConfig40().brightdataUnlockerZone;
|
|
8623
|
+
if (typeof configured === "string" && configured.trim()) return { raw: configured.trim(), label: `brightdataUnlockerZone in ${CONFIG_PATH48}` };
|
|
8542
8624
|
return null;
|
|
8543
8625
|
}
|
|
8544
8626
|
function getZone() {
|
|
@@ -8556,7 +8638,7 @@ function requireZone() {
|
|
|
8556
8638
|
}
|
|
8557
8639
|
throw new Error(
|
|
8558
8640
|
`Bright Data Web Unlocker zone not configured. Either:
|
|
8559
|
-
1. Set brightdataUnlockerZone in ${
|
|
8641
|
+
1. Set brightdataUnlockerZone in ${CONFIG_PATH48}
|
|
8560
8642
|
2. Set BRIGHTDATA_UNLOCKER_ZONE environment variable
|
|
8561
8643
|
The zone must be of type "unblocker"; a SERP zone will not serve Web Unlocker requests.`
|
|
8562
8644
|
);
|
|
@@ -8564,14 +8646,14 @@ The zone must be of type "unblocker"; a SERP zone will not serve Web Unlocker re
|
|
|
8564
8646
|
async function getApiKey27(signal) {
|
|
8565
8647
|
const apiKey = await resolveCredential({
|
|
8566
8648
|
provider: "Bright Data",
|
|
8567
|
-
configuredValue:
|
|
8649
|
+
configuredValue: loadConfig40().brightdataApiKey,
|
|
8568
8650
|
environmentValue: process.env.BRIGHTDATA_API_KEY,
|
|
8569
8651
|
signal
|
|
8570
8652
|
});
|
|
8571
8653
|
if (!apiKey) {
|
|
8572
8654
|
throw new Error(
|
|
8573
8655
|
`Bright Data API key not found. Either:
|
|
8574
|
-
1. Create ${
|
|
8656
|
+
1. Create ${CONFIG_PATH48} with { "brightdataApiKey": "your-key" }
|
|
8575
8657
|
2. Set BRIGHTDATA_API_KEY environment variable
|
|
8576
8658
|
Get a key at https://brightdata.com/cp/setting/users`
|
|
8577
8659
|
);
|
|
@@ -8582,11 +8664,11 @@ function requestSignal14(timeoutMs, signal) {
|
|
|
8582
8664
|
const timeout = AbortSignal.timeout(timeoutMs);
|
|
8583
8665
|
return signal ? AbortSignal.any([timeout, signal]) : timeout;
|
|
8584
8666
|
}
|
|
8585
|
-
function
|
|
8667
|
+
function errorMessage32(err) {
|
|
8586
8668
|
return err instanceof Error ? err.message : String(err);
|
|
8587
8669
|
}
|
|
8588
8670
|
function isAbortError4(err) {
|
|
8589
|
-
return
|
|
8671
|
+
return errorMessage32(err).toLowerCase().includes("abort");
|
|
8590
8672
|
}
|
|
8591
8673
|
function ssrfOptions3(options) {
|
|
8592
8674
|
return {
|
|
@@ -8645,11 +8727,11 @@ async function brightDataRequest(url, zone, signal, options) {
|
|
|
8645
8727
|
const errorText = await response.text().catch(() => "");
|
|
8646
8728
|
throw new Error(`Bright Data Web Unlocker error ${response.status}: ${redactCredential(errorText, apiKey).slice(0, 300)}`);
|
|
8647
8729
|
}
|
|
8648
|
-
const
|
|
8730
|
+
const text5 = await response.text();
|
|
8649
8731
|
activityMonitor.logComplete(activityId, response.status);
|
|
8650
|
-
return
|
|
8732
|
+
return text5;
|
|
8651
8733
|
} catch (err) {
|
|
8652
|
-
const message =
|
|
8734
|
+
const message = errorMessage32(err);
|
|
8653
8735
|
const redactedMessage = redactCredential(message, apiKey);
|
|
8654
8736
|
if (isAbortError4(err)) activityMonitor.logComplete(activityId, 0);
|
|
8655
8737
|
else activityMonitor.logError(activityId, redactedMessage);
|
|
@@ -8659,8 +8741,8 @@ async function brightDataRequest(url, zone, signal, options) {
|
|
|
8659
8741
|
throw redactedError;
|
|
8660
8742
|
}
|
|
8661
8743
|
}
|
|
8662
|
-
function headingTitle(
|
|
8663
|
-
const match =
|
|
8744
|
+
function headingTitle(text5) {
|
|
8745
|
+
const match = text5.match(/^#{1,2}\s+(.+)/m);
|
|
8664
8746
|
if (!match) return "";
|
|
8665
8747
|
return match[1].replace(/\*+/g, "").trim();
|
|
8666
8748
|
}
|
|
@@ -8668,7 +8750,7 @@ function isBrightDataUnlockerAvailable() {
|
|
|
8668
8750
|
if (getZone() === null) return false;
|
|
8669
8751
|
return hasCredentialSource({
|
|
8670
8752
|
provider: "Bright Data",
|
|
8671
|
-
configuredValue:
|
|
8753
|
+
configuredValue: loadConfig40().brightdataApiKey,
|
|
8672
8754
|
environmentValue: process.env.BRIGHTDATA_API_KEY
|
|
8673
8755
|
});
|
|
8674
8756
|
}
|
|
@@ -8680,26 +8762,26 @@ async function extractWithBrightDataUnlocker(url, signal, options) {
|
|
|
8680
8762
|
if (!content) return null;
|
|
8681
8763
|
return { url, title: headingTitle(content), content, error: null };
|
|
8682
8764
|
}
|
|
8683
|
-
var
|
|
8765
|
+
var CONFIG_PATH48, BRIGHTDATA_REQUEST_URL, EXTRACT_TIMEOUT_MS3, DEFAULT_MAX_REDIRECTS3, REDIRECT_STATUSES3, ZONE_PATTERN2, cachedConfig41;
|
|
8684
8766
|
var init_brightdata_unlocker = __esm({
|
|
8685
8767
|
"brightdata-unlocker.ts"() {
|
|
8686
8768
|
init_activity();
|
|
8687
8769
|
init_credential_source();
|
|
8688
8770
|
init_ssrf_protection();
|
|
8689
8771
|
init_utils();
|
|
8690
|
-
|
|
8772
|
+
CONFIG_PATH48 = getWebSearchConfigPath();
|
|
8691
8773
|
BRIGHTDATA_REQUEST_URL = "https://api.brightdata.com/request";
|
|
8692
8774
|
EXTRACT_TIMEOUT_MS3 = 6e4;
|
|
8693
8775
|
DEFAULT_MAX_REDIRECTS3 = 5;
|
|
8694
8776
|
REDIRECT_STATUSES3 = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
|
|
8695
8777
|
ZONE_PATTERN2 = /^[a-z0-9_-]+$/i;
|
|
8696
|
-
|
|
8778
|
+
cachedConfig41 = null;
|
|
8697
8779
|
}
|
|
8698
8780
|
});
|
|
8699
8781
|
|
|
8700
8782
|
// video-extract.ts
|
|
8701
8783
|
import { execFileSync as execFileSync2 } from "node:child_process";
|
|
8702
|
-
import { existsSync as
|
|
8784
|
+
import { existsSync as existsSync53, readFileSync as readFileSync54, readdirSync as readdirSync4, statSync as statSync3 } from "node:fs";
|
|
8703
8785
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
8704
8786
|
import { resolve, extname as extname2, basename as basename4, join as join7, dirname as dirname2 } from "node:path";
|
|
8705
8787
|
function shouldRethrow3(err) {
|
|
@@ -8720,17 +8802,17 @@ function normalizeMaxSizeMB(value, fallback) {
|
|
|
8720
8802
|
}
|
|
8721
8803
|
function loadVideoConfig() {
|
|
8722
8804
|
if (cachedVideoConfig) return cachedVideoConfig;
|
|
8723
|
-
if (!
|
|
8805
|
+
if (!existsSync53(CONFIG_PATH49)) {
|
|
8724
8806
|
cachedVideoConfig = { ...VIDEO_CONFIG_DEFAULTS };
|
|
8725
8807
|
return cachedVideoConfig;
|
|
8726
8808
|
}
|
|
8727
|
-
const rawText =
|
|
8809
|
+
const rawText = readFileSync54(CONFIG_PATH49, "utf-8");
|
|
8728
8810
|
let raw;
|
|
8729
8811
|
try {
|
|
8730
8812
|
raw = JSON.parse(rawText);
|
|
8731
8813
|
} catch (err) {
|
|
8732
8814
|
const message = err instanceof Error ? err.message : String(err);
|
|
8733
|
-
throw new Error(`Failed to parse ${
|
|
8815
|
+
throw new Error(`Failed to parse ${CONFIG_PATH49}: ${message}`);
|
|
8734
8816
|
}
|
|
8735
8817
|
const v = raw.video ?? {};
|
|
8736
8818
|
cachedVideoConfig = {
|
|
@@ -8776,10 +8858,10 @@ function isVideoFile(input) {
|
|
|
8776
8858
|
}
|
|
8777
8859
|
function resolveFilePath(filePath) {
|
|
8778
8860
|
const absolutePath = resolve(filePath);
|
|
8779
|
-
if (
|
|
8861
|
+
if (existsSync53(absolutePath)) return absolutePath;
|
|
8780
8862
|
const dir = dirname2(absolutePath);
|
|
8781
8863
|
const base = basename4(absolutePath);
|
|
8782
|
-
if (!
|
|
8864
|
+
if (!existsSync53(dir)) return null;
|
|
8783
8865
|
try {
|
|
8784
8866
|
const normalizedBase = normalizeSpaces(base);
|
|
8785
8867
|
const match = readdirSync4(dir).find((f) => normalizeSpaces(f) === normalizedBase);
|
|
@@ -8871,7 +8953,7 @@ async function tryVideoGeminiWeb(info, prompt, model, signal) {
|
|
|
8871
8953
|
const cookies = await isGeminiWebAvailable();
|
|
8872
8954
|
if (!cookies) return null;
|
|
8873
8955
|
if (signal?.aborted) return null;
|
|
8874
|
-
const
|
|
8956
|
+
const text5 = await queryWithCookies(prompt, cookies, {
|
|
8875
8957
|
files: [{ path: info.absolutePath, mimeType: info.mimeType }],
|
|
8876
8958
|
...model !== "gemini-3.6-flash" ? { model } : {},
|
|
8877
8959
|
signal,
|
|
@@ -8879,8 +8961,8 @@ async function tryVideoGeminiWeb(info, prompt, model, signal) {
|
|
|
8879
8961
|
});
|
|
8880
8962
|
return {
|
|
8881
8963
|
url: info.absolutePath,
|
|
8882
|
-
title: extractVideoTitle(
|
|
8883
|
-
content:
|
|
8964
|
+
title: extractVideoTitle(text5, info.absolutePath),
|
|
8965
|
+
content: text5,
|
|
8884
8966
|
error: null
|
|
8885
8967
|
};
|
|
8886
8968
|
} catch (err) {
|
|
@@ -8897,7 +8979,7 @@ async function tryVideoGeminiApi(info, prompt, model, signal) {
|
|
|
8897
8979
|
const uploaded = await uploadToFilesApi(info, apiKey, signal);
|
|
8898
8980
|
fileName = uploaded.name;
|
|
8899
8981
|
await pollFileState(fileName, apiKey, signal, 12e4);
|
|
8900
|
-
const
|
|
8982
|
+
const text5 = await queryGeminiApiWithVideo(prompt, uploaded.uri, {
|
|
8901
8983
|
apiKey,
|
|
8902
8984
|
model,
|
|
8903
8985
|
mimeType: info.mimeType,
|
|
@@ -8906,8 +8988,8 @@ async function tryVideoGeminiApi(info, prompt, model, signal) {
|
|
|
8906
8988
|
});
|
|
8907
8989
|
return {
|
|
8908
8990
|
url: info.absolutePath,
|
|
8909
|
-
title: extractVideoTitle(
|
|
8910
|
-
content:
|
|
8991
|
+
title: extractVideoTitle(text5, info.absolutePath),
|
|
8992
|
+
content: text5,
|
|
8911
8993
|
error: null
|
|
8912
8994
|
};
|
|
8913
8995
|
} catch (err) {
|
|
@@ -8932,8 +9014,8 @@ async function uploadToFilesApi(info, apiKey, signal) {
|
|
|
8932
9014
|
signal
|
|
8933
9015
|
}, apiKey);
|
|
8934
9016
|
if (!initRes.ok) {
|
|
8935
|
-
const
|
|
8936
|
-
throw new Error(`File upload init failed: ${initRes.status} (${
|
|
9017
|
+
const text5 = redactGeminiApiResponse(initRes, await initRes.text(), apiKey);
|
|
9018
|
+
throw new Error(`File upload init failed: ${initRes.status} (${text5.slice(0, 200)})`);
|
|
8937
9019
|
}
|
|
8938
9020
|
const uploadUrl = initRes.headers.get("x-goog-upload-url");
|
|
8939
9021
|
if (!uploadUrl) throw new Error("No upload URL in response headers");
|
|
@@ -8950,8 +9032,8 @@ async function uploadToFilesApi(info, apiKey, signal) {
|
|
|
8950
9032
|
signal
|
|
8951
9033
|
}, apiKey);
|
|
8952
9034
|
if (!uploadRes.ok) {
|
|
8953
|
-
const
|
|
8954
|
-
throw new Error(`File upload failed: ${uploadRes.status} (${
|
|
9035
|
+
const text5 = redactGeminiApiResponse(uploadRes, await uploadRes.text(), apiKey);
|
|
9036
|
+
throw new Error(`File upload failed: ${uploadRes.status} (${text5.slice(0, 200)})`);
|
|
8955
9037
|
}
|
|
8956
9038
|
const result = await uploadRes.json();
|
|
8957
9039
|
return result.file;
|
|
@@ -8975,10 +9057,10 @@ function deleteGeminiFile(fileName, apiKey) {
|
|
|
8975
9057
|
console.error(`Failed to delete Gemini file ${fileName}: ${message}`);
|
|
8976
9058
|
});
|
|
8977
9059
|
}
|
|
8978
|
-
function extractVideoTitle(
|
|
8979
|
-
return extractHeadingTitle(
|
|
9060
|
+
function extractVideoTitle(text5, filePath) {
|
|
9061
|
+
return extractHeadingTitle(text5) ?? basename4(filePath, extname2(filePath));
|
|
8980
9062
|
}
|
|
8981
|
-
var
|
|
9063
|
+
var CONFIG_PATH49, DEFAULT_VIDEO_PROMPT, VIDEO_EXTENSIONS, VIDEO_CONFIG_DEFAULTS, cachedVideoConfig;
|
|
8982
9064
|
var init_video_extract = __esm({
|
|
8983
9065
|
"video-extract.ts"() {
|
|
8984
9066
|
init_activity();
|
|
@@ -8987,7 +9069,7 @@ var init_video_extract = __esm({
|
|
|
8987
9069
|
init_gemini_api();
|
|
8988
9070
|
init_extract();
|
|
8989
9071
|
init_utils();
|
|
8990
|
-
|
|
9072
|
+
CONFIG_PATH49 = getWebSearchConfigPath();
|
|
8991
9073
|
DEFAULT_VIDEO_PROMPT = `Extract the complete content of this video. Include:
|
|
8992
9074
|
1. Video title (infer from content if not explicit), duration
|
|
8993
9075
|
2. A brief summary (2-3 sentences)
|
|
@@ -9177,33 +9259,33 @@ function sha256Bytes(value) {
|
|
|
9177
9259
|
function asciiLowerCode(code) {
|
|
9178
9260
|
return code >= 65 && code <= 90 ? code + 32 : code;
|
|
9179
9261
|
}
|
|
9180
|
-
function matchesDataScheme(
|
|
9181
|
-
return index + 5 <=
|
|
9262
|
+
function matchesDataScheme(text5, index) {
|
|
9263
|
+
return index + 5 <= text5.length && asciiLowerCode(text5.charCodeAt(index)) === 100 && asciiLowerCode(text5.charCodeAt(index + 1)) === 97 && asciiLowerCode(text5.charCodeAt(index + 2)) === 116 && asciiLowerCode(text5.charCodeAt(index + 3)) === 97 && text5.charCodeAt(index + 4) === 58;
|
|
9182
9264
|
}
|
|
9183
|
-
function isSchemeBoundary(
|
|
9265
|
+
function isSchemeBoundary(text5, index) {
|
|
9184
9266
|
if (index === 0) return true;
|
|
9185
|
-
const code =
|
|
9267
|
+
const code = text5.charCodeAt(index - 1);
|
|
9186
9268
|
const alphaNumeric = code >= 48 && code <= 57 || code >= 65 && code <= 90 || code >= 97 && code <= 122;
|
|
9187
9269
|
return !alphaNumeric && code !== 43 && code !== 45 && code !== 46;
|
|
9188
9270
|
}
|
|
9189
|
-
function findNextDataScheme(
|
|
9190
|
-
for (let i = from; i + 5 <=
|
|
9191
|
-
if (matchesDataScheme(
|
|
9271
|
+
function findNextDataScheme(text5, from) {
|
|
9272
|
+
for (let i = from; i + 5 <= text5.length; i++) {
|
|
9273
|
+
if (matchesDataScheme(text5, i) && isSchemeBoundary(text5, i)) return i;
|
|
9192
9274
|
}
|
|
9193
9275
|
return -1;
|
|
9194
9276
|
}
|
|
9195
|
-
function dataUriEnclosure(
|
|
9277
|
+
function dataUriEnclosure(text5, start) {
|
|
9196
9278
|
if (start === 0) return null;
|
|
9197
9279
|
const immediateIndex = start - 1;
|
|
9198
|
-
const immediate =
|
|
9280
|
+
const immediate = text5[immediateIndex];
|
|
9199
9281
|
if (immediate === '"' || immediate === "'" || immediate === "`") {
|
|
9200
|
-
const beforeQuote = immediateIndex > 0 ?
|
|
9282
|
+
const beforeQuote = immediateIndex > 0 ? text5[immediateIndex - 1] : "";
|
|
9201
9283
|
const likelyOpeningQuote = immediateIndex === 0 || beforeQuote === "=" || beforeQuote === "(" || beforeQuote === "[" || beforeQuote === "{" || beforeQuote === ":" || beforeQuote === "," || /\s/.test(beforeQuote);
|
|
9202
9284
|
if (likelyOpeningQuote) return { kind: "quote", close: immediate };
|
|
9203
9285
|
}
|
|
9204
9286
|
let openerIndex = immediateIndex;
|
|
9205
|
-
while (openerIndex >= 0 && (
|
|
9206
|
-
const opener =
|
|
9287
|
+
while (openerIndex >= 0 && (text5[openerIndex] === " " || text5[openerIndex] === " ")) openerIndex--;
|
|
9288
|
+
const opener = text5[openerIndex];
|
|
9207
9289
|
if (opener === "(") return { kind: "parentheses" };
|
|
9208
9290
|
if (opener === "<") return { kind: "angle" };
|
|
9209
9291
|
return null;
|
|
@@ -9212,13 +9294,13 @@ function isBareDataUriTerminator(ch) {
|
|
|
9212
9294
|
const code = ch.charCodeAt(0);
|
|
9213
9295
|
return code <= 32 || code === 127 || ch === '"' || ch === "`" || ch === "<" || ch === ">";
|
|
9214
9296
|
}
|
|
9215
|
-
function scanDataUriCandidate(
|
|
9216
|
-
const enclosure = dataUriEnclosure(
|
|
9297
|
+
function scanDataUriCandidate(text5, start) {
|
|
9298
|
+
const enclosure = dataUriEnclosure(text5, start);
|
|
9217
9299
|
let comma = -1;
|
|
9218
9300
|
let depth = enclosure?.kind === "parentheses" ? 1 : 0;
|
|
9219
9301
|
let index = start + 5;
|
|
9220
|
-
for (; index <
|
|
9221
|
-
const ch =
|
|
9302
|
+
for (; index < text5.length; index++) {
|
|
9303
|
+
const ch = text5[index];
|
|
9222
9304
|
if (enclosure?.kind === "quote") {
|
|
9223
9305
|
if (ch === enclosure.close) break;
|
|
9224
9306
|
} else if (enclosure?.kind === "parentheses") {
|
|
@@ -9237,16 +9319,16 @@ function scanDataUriCandidate(text4, start) {
|
|
|
9237
9319
|
}
|
|
9238
9320
|
return { end: index, comma, enclosure };
|
|
9239
9321
|
}
|
|
9240
|
-
function headerEndsWithBase64(
|
|
9322
|
+
function headerEndsWithBase64(text5, headerStart, comma) {
|
|
9241
9323
|
let end = comma;
|
|
9242
|
-
while (end > headerStart && (
|
|
9324
|
+
while (end > headerStart && (text5[end - 1] === " " || text5[end - 1] === " ")) end--;
|
|
9243
9325
|
const token = "base64";
|
|
9244
9326
|
if (end - headerStart < token.length + 1) return false;
|
|
9245
9327
|
const tokenStart = end - token.length;
|
|
9246
9328
|
for (let i = 0; i < token.length; i++) {
|
|
9247
|
-
if (asciiLowerCode(
|
|
9329
|
+
if (asciiLowerCode(text5.charCodeAt(tokenStart + i)) !== token.charCodeAt(i)) return false;
|
|
9248
9330
|
}
|
|
9249
|
-
return tokenStart > headerStart &&
|
|
9331
|
+
return tokenStart > headerStart && text5[tokenStart - 1] === ";";
|
|
9250
9332
|
}
|
|
9251
9333
|
function isMimeTokenChar(code) {
|
|
9252
9334
|
if (code < 33 || code > 126) return false;
|
|
@@ -9285,14 +9367,14 @@ function isMimeTokenChar(code) {
|
|
|
9285
9367
|
return true;
|
|
9286
9368
|
}
|
|
9287
9369
|
}
|
|
9288
|
-
function normalizeMimeType(
|
|
9370
|
+
function normalizeMimeType(text5, headerStart, comma) {
|
|
9289
9371
|
let end = headerStart;
|
|
9290
|
-
while (end < comma &&
|
|
9372
|
+
while (end < comma && text5[end] !== ";") end++;
|
|
9291
9373
|
if (end === headerStart) return "text/plain";
|
|
9292
9374
|
if (end - headerStart > MAX_MIME_CHARS) return "application/octet-stream";
|
|
9293
9375
|
let slashCount = 0;
|
|
9294
9376
|
for (let i = headerStart; i < end; i++) {
|
|
9295
|
-
const code =
|
|
9377
|
+
const code = text5.charCodeAt(i);
|
|
9296
9378
|
if (code === 47) {
|
|
9297
9379
|
slashCount++;
|
|
9298
9380
|
if (i === headerStart || i === end - 1) return "application/octet-stream";
|
|
@@ -9301,7 +9383,7 @@ function normalizeMimeType(text4, headerStart, comma) {
|
|
|
9301
9383
|
if (!isMimeTokenChar(code)) return "application/octet-stream";
|
|
9302
9384
|
}
|
|
9303
9385
|
if (slashCount !== 1) return "application/octet-stream";
|
|
9304
|
-
return
|
|
9386
|
+
return text5.slice(headerStart, end).toLowerCase();
|
|
9305
9387
|
}
|
|
9306
9388
|
function hexValue(code) {
|
|
9307
9389
|
if (code >= 48 && code <= 57) return code - 48;
|
|
@@ -9375,15 +9457,15 @@ function buildDataUriMarker(omission) {
|
|
|
9375
9457
|
const decodeError = omission.decodeError ? `; decodeError=${omission.decodeError}` : "";
|
|
9376
9458
|
return `[pi-web-access inline data URI omitted; ordinal=${omission.ordinal}; source=${omission.sourcePath}; mime=${omission.mimeType}; encoding=${omission.encoding}; encodedBytes=${omission.encodedBytes}; decodedBytes=${decoded}${decodeError}; sha256=${omission.sha256}; digestBasis=${omission.digestBasis}; retrieval=not-retained]`;
|
|
9377
9459
|
}
|
|
9378
|
-
function sanitizeTextInternal(
|
|
9460
|
+
function sanitizeTextInternal(text5, sourcePath, state) {
|
|
9379
9461
|
let scanFrom = 0;
|
|
9380
9462
|
let retainedFrom = 0;
|
|
9381
9463
|
let outputLength = 0;
|
|
9382
9464
|
const pieces = [];
|
|
9383
|
-
while (scanFrom <
|
|
9384
|
-
const start = findNextDataScheme(
|
|
9465
|
+
while (scanFrom < text5.length) {
|
|
9466
|
+
const start = findNextDataScheme(text5, scanFrom);
|
|
9385
9467
|
if (start < 0) break;
|
|
9386
|
-
const candidate = scanDataUriCandidate(
|
|
9468
|
+
const candidate = scanDataUriCandidate(text5, start);
|
|
9387
9469
|
const end = candidate.end;
|
|
9388
9470
|
const headerStart = start + 5;
|
|
9389
9471
|
const missingComma = candidate.comma < 0;
|
|
@@ -9393,9 +9475,9 @@ function sanitizeTextInternal(text4, sourcePath, state) {
|
|
|
9393
9475
|
}
|
|
9394
9476
|
const headerEnd = missingComma ? end : candidate.comma;
|
|
9395
9477
|
const headerLength = headerEnd - headerStart;
|
|
9396
|
-
const encoding = headerEndsWithBase64(
|
|
9397
|
-
const mimeType = normalizeMimeType(
|
|
9398
|
-
const payload = missingComma ?
|
|
9478
|
+
const encoding = headerEndsWithBase64(text5, headerStart, headerEnd) ? "base64" : "percent-encoded";
|
|
9479
|
+
const mimeType = normalizeMimeType(text5, headerStart, headerEnd);
|
|
9480
|
+
const payload = missingComma ? text5.slice(headerStart, end) : text5.slice(candidate.comma + 1, end);
|
|
9399
9481
|
const encodedBytes = Buffer3.byteLength(payload, "utf8");
|
|
9400
9482
|
let decodedBytes = null;
|
|
9401
9483
|
let decodeError;
|
|
@@ -9431,7 +9513,7 @@ function sanitizeTextInternal(text4, sourcePath, state) {
|
|
|
9431
9513
|
retrieval: "not-retained"
|
|
9432
9514
|
};
|
|
9433
9515
|
const marker = buildDataUriMarker(omission);
|
|
9434
|
-
const prefix =
|
|
9516
|
+
const prefix = text5.slice(retainedFrom, start);
|
|
9435
9517
|
pieces.push(prefix, marker);
|
|
9436
9518
|
outputLength += prefix.length;
|
|
9437
9519
|
const markerStart = outputLength;
|
|
@@ -9440,13 +9522,13 @@ function sanitizeTextInternal(text4, sourcePath, state) {
|
|
|
9440
9522
|
retainedFrom = end;
|
|
9441
9523
|
scanFrom = end;
|
|
9442
9524
|
}
|
|
9443
|
-
if (state.omissions.length === 0 && retainedFrom === 0) return
|
|
9444
|
-
pieces.push(
|
|
9525
|
+
if (state.omissions.length === 0 && retainedFrom === 0) return text5;
|
|
9526
|
+
pieces.push(text5.slice(retainedFrom));
|
|
9445
9527
|
return pieces.join("");
|
|
9446
9528
|
}
|
|
9447
|
-
function sanitizeInlineDataUris(
|
|
9529
|
+
function sanitizeInlineDataUris(text5, sourcePath) {
|
|
9448
9530
|
const state = { nextOrdinal: 1, omissions: [] };
|
|
9449
|
-
const sanitized = sanitizeTextInternal(
|
|
9531
|
+
const sanitized = sanitizeTextInternal(text5, sourcePath, state);
|
|
9450
9532
|
return {
|
|
9451
9533
|
text: sanitized,
|
|
9452
9534
|
omissions: state.omissions.map(({ markerStart: _start, markerEnd: _end, ...omission }) => omission)
|
|
@@ -9472,13 +9554,13 @@ __export(extract_exports, {
|
|
|
9472
9554
|
readPDFResponseBuffer: () => readPDFResponseBuffer,
|
|
9473
9555
|
resolveFetchTimeoutMs: () => resolveFetchTimeoutMs
|
|
9474
9556
|
});
|
|
9475
|
-
import { existsSync as
|
|
9557
|
+
import { existsSync as existsSync54, readFileSync as readFileSync55 } from "node:fs";
|
|
9476
9558
|
import pLimit from "p-limit";
|
|
9477
9559
|
function loadFetchTimeoutMs() {
|
|
9478
|
-
if (!
|
|
9560
|
+
if (!existsSync54(WEB_SEARCH_CONFIG_PATH3)) return DEFAULT_TIMEOUT_MS4;
|
|
9479
9561
|
let raw;
|
|
9480
9562
|
try {
|
|
9481
|
-
raw = JSON.parse(
|
|
9563
|
+
raw = JSON.parse(readFileSync55(WEB_SEARCH_CONFIG_PATH3, "utf-8"));
|
|
9482
9564
|
} catch (err) {
|
|
9483
9565
|
const message = err instanceof Error ? err.message : String(err);
|
|
9484
9566
|
throw new Error(`Failed to parse ${WEB_SEARCH_CONFIG_PATH3}: ${message}`);
|
|
@@ -9506,10 +9588,10 @@ function isDefuddleConsoleError(args) {
|
|
|
9506
9588
|
const prefix = args[0];
|
|
9507
9589
|
return prefix === "Defuddle" || typeof prefix === "string" && /^Defuddle(?:\s|:)/.test(prefix);
|
|
9508
9590
|
}
|
|
9509
|
-
async function extractWithDefuddle(
|
|
9591
|
+
async function extractWithDefuddle(text5, url) {
|
|
9510
9592
|
const { Defuddle } = await import("defuddle/node");
|
|
9511
9593
|
const { parseHTML } = await import("linkedom");
|
|
9512
|
-
const { document } = parseHTML(
|
|
9594
|
+
const { document } = parseHTML(text5);
|
|
9513
9595
|
Object.defineProperty(document, "location", {
|
|
9514
9596
|
value: new URL(url),
|
|
9515
9597
|
configurable: true
|
|
@@ -9533,21 +9615,21 @@ async function extractWithDefuddle(text4, url) {
|
|
|
9533
9615
|
}
|
|
9534
9616
|
const result = await resultPromise;
|
|
9535
9617
|
if (processingError !== void 0) {
|
|
9536
|
-
throw new Error(`Defuddle failed to process document: ${
|
|
9618
|
+
throw new Error(`Defuddle failed to process document: ${errorMessage33(processingError)}`);
|
|
9537
9619
|
}
|
|
9538
9620
|
return typeof result.content === "string" ? { title: result.title, content: result.content } : null;
|
|
9539
9621
|
}
|
|
9540
9622
|
function loadSsrfAllowRanges() {
|
|
9541
9623
|
return loadSsrfConfig().allowRanges;
|
|
9542
9624
|
}
|
|
9543
|
-
function
|
|
9625
|
+
function errorMessage33(err) {
|
|
9544
9626
|
return err instanceof Error ? err.message : String(err);
|
|
9545
9627
|
}
|
|
9546
9628
|
function isConfigParseError(err) {
|
|
9547
|
-
return
|
|
9629
|
+
return errorMessage33(err).startsWith("Failed to parse ");
|
|
9548
9630
|
}
|
|
9549
9631
|
function isAbortError5(err) {
|
|
9550
|
-
return
|
|
9632
|
+
return errorMessage33(err).toLowerCase().includes("abort");
|
|
9551
9633
|
}
|
|
9552
9634
|
function isAbortException2(err) {
|
|
9553
9635
|
return err instanceof DOMException && (err.name === "AbortError" || err.name === "TimeoutError");
|
|
@@ -9562,7 +9644,7 @@ function imageGateError() {
|
|
|
9562
9644
|
try {
|
|
9563
9645
|
return isImageEnabled() ? null : "Image fetching is disabled by image.enabled";
|
|
9564
9646
|
} catch (err) {
|
|
9565
|
-
return
|
|
9647
|
+
return errorMessage33(err);
|
|
9566
9648
|
}
|
|
9567
9649
|
}
|
|
9568
9650
|
function redirectPolicyRouteRefusal(url, path) {
|
|
@@ -9617,12 +9699,12 @@ async function fetchAuthenticatedRemoteUrl(url, init, validationOptions, profile
|
|
|
9617
9699
|
throw new Error(`Too many redirects fetching ${current.toString()}`);
|
|
9618
9700
|
}
|
|
9619
9701
|
function loadFetchRouting() {
|
|
9620
|
-
if (!
|
|
9702
|
+
if (!existsSync54(WEB_SEARCH_CONFIG_PATH3)) {
|
|
9621
9703
|
return { providers: DEFAULT_FETCH_PROVIDER_ORDER, allowRemoteHostedProviders: false };
|
|
9622
9704
|
}
|
|
9623
9705
|
let raw;
|
|
9624
9706
|
try {
|
|
9625
|
-
const parsed = JSON.parse(
|
|
9707
|
+
const parsed = JSON.parse(readFileSync55(WEB_SEARCH_CONFIG_PATH3, "utf-8"));
|
|
9626
9708
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
9627
9709
|
throw new Error("expected a JSON object");
|
|
9628
9710
|
}
|
|
@@ -9813,7 +9895,7 @@ function safeVideoInfo(url) {
|
|
|
9813
9895
|
const info = isVideoFile(url);
|
|
9814
9896
|
return info ? { status: "video", info } : { status: "not-video" };
|
|
9815
9897
|
} catch (err) {
|
|
9816
|
-
return { status: "invalid", error:
|
|
9898
|
+
return { status: "invalid", error: errorMessage33(err) };
|
|
9817
9899
|
}
|
|
9818
9900
|
}
|
|
9819
9901
|
async function extractContent(url, signal, options) {
|
|
@@ -9824,7 +9906,7 @@ async function extractContent(url, signal, options) {
|
|
|
9824
9906
|
try {
|
|
9825
9907
|
redirectPolicy = options?.redirects ?? loadFetchContentRedirectPolicy();
|
|
9826
9908
|
} catch (err) {
|
|
9827
|
-
return { url, title: "", content: "", error:
|
|
9909
|
+
return { url, title: "", content: "", error: errorMessage33(err) };
|
|
9828
9910
|
}
|
|
9829
9911
|
let remoteUrl = null;
|
|
9830
9912
|
try {
|
|
@@ -9845,14 +9927,14 @@ async function extractContent(url, signal, options) {
|
|
|
9845
9927
|
...options?.lookup ? { lookup: options.lookup } : {}
|
|
9846
9928
|
});
|
|
9847
9929
|
} catch (err) {
|
|
9848
|
-
return { url, title: "", content: "", error:
|
|
9930
|
+
return { url, title: "", content: "", error: errorMessage33(err) };
|
|
9849
9931
|
}
|
|
9850
9932
|
}
|
|
9851
9933
|
if (options?.authFetchProfile || options?.mode === "raw") {
|
|
9852
9934
|
try {
|
|
9853
9935
|
return await extractViaHttp(url, resolveFetchTimeoutMs(options), signal, options);
|
|
9854
9936
|
} catch (err) {
|
|
9855
|
-
return { url, title: "", content: "", error:
|
|
9937
|
+
return { url, title: "", content: "", error: errorMessage33(err) };
|
|
9856
9938
|
}
|
|
9857
9939
|
}
|
|
9858
9940
|
if (redirectPolicy) {
|
|
@@ -9995,20 +10077,20 @@ async function extractContent(url, signal, options) {
|
|
|
9995
10077
|
2. Set GEMINI_API_KEY in ${WEB_SEARCH_CONFIG_PATH3}` };
|
|
9996
10078
|
} catch (err) {
|
|
9997
10079
|
if (isAbortError5(err)) return abortedResult(url);
|
|
9998
|
-
return { url, title: "", content: "", error:
|
|
10080
|
+
return { url, title: "", content: "", error: errorMessage33(err) };
|
|
9999
10081
|
}
|
|
10000
10082
|
}
|
|
10001
10083
|
try {
|
|
10002
10084
|
if (!remoteUrl) new URL(url);
|
|
10003
10085
|
} catch (err) {
|
|
10004
|
-
return { url, title: "", content: "", error:
|
|
10086
|
+
return { url, title: "", content: "", error: errorMessage33(err) };
|
|
10005
10087
|
}
|
|
10006
10088
|
try {
|
|
10007
10089
|
const ghIssuePrResult = await extractGitHubIssuePr(url, signal, options);
|
|
10008
10090
|
if (ghIssuePrResult) return ghIssuePrResult;
|
|
10009
10091
|
if (signal?.aborted) return abortedResult(url);
|
|
10010
10092
|
} catch (err) {
|
|
10011
|
-
const message =
|
|
10093
|
+
const message = errorMessage33(err);
|
|
10012
10094
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10013
10095
|
if (isConfigParseError(err)) {
|
|
10014
10096
|
return { url, title: "", content: "", error: message };
|
|
@@ -10019,7 +10101,7 @@ async function extractContent(url, signal, options) {
|
|
|
10019
10101
|
if (ghResult) return ghResult;
|
|
10020
10102
|
if (signal?.aborted) return abortedResult(url);
|
|
10021
10103
|
} catch (err) {
|
|
10022
|
-
const message =
|
|
10104
|
+
const message = errorMessage33(err);
|
|
10023
10105
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10024
10106
|
if (isConfigParseError(err)) {
|
|
10025
10107
|
return { url, title: "", content: "", error: message };
|
|
@@ -10030,7 +10112,7 @@ async function extractContent(url, signal, options) {
|
|
|
10030
10112
|
try {
|
|
10031
10113
|
youtubeEnabled = isYouTubeEnabled();
|
|
10032
10114
|
} catch (err) {
|
|
10033
|
-
return { url, title: "", content: "", error:
|
|
10115
|
+
return { url, title: "", content: "", error: errorMessage33(err) };
|
|
10034
10116
|
}
|
|
10035
10117
|
if (ytInfo.isYouTube && youtubeEnabled) {
|
|
10036
10118
|
try {
|
|
@@ -10038,7 +10120,7 @@ async function extractContent(url, signal, options) {
|
|
|
10038
10120
|
if (ytResult) return ytResult;
|
|
10039
10121
|
if (signal?.aborted) return abortedResult(url);
|
|
10040
10122
|
} catch (err) {
|
|
10041
|
-
const message =
|
|
10123
|
+
const message = errorMessage33(err);
|
|
10042
10124
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10043
10125
|
return { url, title: "", content: "", error: message };
|
|
10044
10126
|
}
|
|
@@ -10054,13 +10136,13 @@ async function extractContent(url, signal, options) {
|
|
|
10054
10136
|
try {
|
|
10055
10137
|
fetchTimeoutMs = resolveFetchTimeoutMs(options);
|
|
10056
10138
|
} catch (err) {
|
|
10057
|
-
return { url, title: "", content: "", error:
|
|
10139
|
+
return { url, title: "", content: "", error: errorMessage33(err) };
|
|
10058
10140
|
}
|
|
10059
10141
|
let fetchRouting;
|
|
10060
10142
|
try {
|
|
10061
10143
|
fetchRouting = loadFetchRouting();
|
|
10062
10144
|
} catch (err) {
|
|
10063
|
-
return { url, title: "", content: "", error:
|
|
10145
|
+
return { url, title: "", content: "", error: errorMessage33(err) };
|
|
10064
10146
|
}
|
|
10065
10147
|
if (redirectPolicy && !fetchRouting.providers.includes("http")) {
|
|
10066
10148
|
return redirectPolicyRouteRefusal(url, fetchRouting.providers[0]);
|
|
@@ -10126,7 +10208,7 @@ async function extractContent(url, signal, options) {
|
|
|
10126
10208
|
}
|
|
10127
10209
|
} catch (err) {
|
|
10128
10210
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10129
|
-
firecrawlError =
|
|
10211
|
+
firecrawlError = errorMessage33(err);
|
|
10130
10212
|
if (isConfigParseError(err)) return parseErrorResult(firecrawlError);
|
|
10131
10213
|
}
|
|
10132
10214
|
continue;
|
|
@@ -10144,7 +10226,7 @@ async function extractContent(url, signal, options) {
|
|
|
10144
10226
|
}
|
|
10145
10227
|
} catch (err) {
|
|
10146
10228
|
if (signal?.aborted || isAbortException2(err)) return abortedResult(url);
|
|
10147
|
-
crawl4aiError =
|
|
10229
|
+
crawl4aiError = errorMessage33(err);
|
|
10148
10230
|
if (isConfigParseError(err)) return parseErrorResult(crawl4aiError);
|
|
10149
10231
|
}
|
|
10150
10232
|
continue;
|
|
@@ -10162,7 +10244,7 @@ async function extractContent(url, signal, options) {
|
|
|
10162
10244
|
}
|
|
10163
10245
|
} catch (err) {
|
|
10164
10246
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10165
|
-
tinyfishError =
|
|
10247
|
+
tinyfishError = errorMessage33(err);
|
|
10166
10248
|
if (isConfigParseError(err)) return parseErrorResult(tinyfishError);
|
|
10167
10249
|
}
|
|
10168
10250
|
continue;
|
|
@@ -10175,7 +10257,7 @@ async function extractContent(url, signal, options) {
|
|
|
10175
10257
|
}
|
|
10176
10258
|
} catch (err) {
|
|
10177
10259
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10178
|
-
search1apiError =
|
|
10260
|
+
search1apiError = errorMessage33(err);
|
|
10179
10261
|
if (isConfigParseError(err)) return parseErrorResult(search1apiError);
|
|
10180
10262
|
}
|
|
10181
10263
|
continue;
|
|
@@ -10188,7 +10270,7 @@ async function extractContent(url, signal, options) {
|
|
|
10188
10270
|
}
|
|
10189
10271
|
} catch (err) {
|
|
10190
10272
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10191
|
-
queritError =
|
|
10273
|
+
queritError = errorMessage33(err);
|
|
10192
10274
|
if (isConfigParseError(err)) return parseErrorResult(queritError);
|
|
10193
10275
|
}
|
|
10194
10276
|
continue;
|
|
@@ -10206,7 +10288,7 @@ async function extractContent(url, signal, options) {
|
|
|
10206
10288
|
}
|
|
10207
10289
|
} catch (err) {
|
|
10208
10290
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10209
|
-
kagiError =
|
|
10291
|
+
kagiError = errorMessage33(err);
|
|
10210
10292
|
if (isConfigParseError(err)) return parseErrorResult(kagiError);
|
|
10211
10293
|
}
|
|
10212
10294
|
continue;
|
|
@@ -10224,7 +10306,7 @@ async function extractContent(url, signal, options) {
|
|
|
10224
10306
|
}
|
|
10225
10307
|
} catch (err) {
|
|
10226
10308
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10227
|
-
ollamaError =
|
|
10309
|
+
ollamaError = errorMessage33(err);
|
|
10228
10310
|
if (isConfigParseError(err)) return parseErrorResult(ollamaError);
|
|
10229
10311
|
}
|
|
10230
10312
|
continue;
|
|
@@ -10237,7 +10319,7 @@ async function extractContent(url, signal, options) {
|
|
|
10237
10319
|
}
|
|
10238
10320
|
} catch (err) {
|
|
10239
10321
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10240
|
-
parallelError =
|
|
10322
|
+
parallelError = errorMessage33(err);
|
|
10241
10323
|
if (isConfigParseError(err)) return parseErrorResult(parallelError);
|
|
10242
10324
|
}
|
|
10243
10325
|
continue;
|
|
@@ -10248,7 +10330,7 @@ async function extractContent(url, signal, options) {
|
|
|
10248
10330
|
if (parallelMcpResult) return withDeclaredLinks(parallelMcpResult);
|
|
10249
10331
|
} catch (err) {
|
|
10250
10332
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10251
|
-
parallelMcpError =
|
|
10333
|
+
parallelMcpError = errorMessage33(err);
|
|
10252
10334
|
if (isConfigParseError(err)) return parseErrorResult(parallelMcpError);
|
|
10253
10335
|
}
|
|
10254
10336
|
continue;
|
|
@@ -10266,7 +10348,7 @@ async function extractContent(url, signal, options) {
|
|
|
10266
10348
|
}
|
|
10267
10349
|
} catch (err) {
|
|
10268
10350
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10269
|
-
brightdataError =
|
|
10351
|
+
brightdataError = errorMessage33(err);
|
|
10270
10352
|
if (isConfigParseError(err)) return parseErrorResult(brightdataError);
|
|
10271
10353
|
}
|
|
10272
10354
|
continue;
|
|
@@ -10278,7 +10360,7 @@ async function extractContent(url, signal, options) {
|
|
|
10278
10360
|
} catch (err) {
|
|
10279
10361
|
if (isAbortError5(err)) return abortedResult(url);
|
|
10280
10362
|
if (err instanceof CredentialResolutionError || isConfigParseError(err)) {
|
|
10281
|
-
return parseErrorResult(
|
|
10363
|
+
return parseErrorResult(errorMessage33(err));
|
|
10282
10364
|
}
|
|
10283
10365
|
}
|
|
10284
10366
|
if (geminiResult) return withDeclaredLinks(geminiResult);
|
|
@@ -10323,10 +10405,10 @@ async function extractContent(url, signal, options) {
|
|
|
10323
10405
|
].join("\n");
|
|
10324
10406
|
return { ...finalHttpResult ?? { url, title: "", content: "", error: null }, error: guidance };
|
|
10325
10407
|
}
|
|
10326
|
-
function isCloudflareChallenge(response,
|
|
10408
|
+
function isCloudflareChallenge(response, text5, isHTML) {
|
|
10327
10409
|
if (response.status !== 200) return false;
|
|
10328
10410
|
if (response.headers.get("cf-mitigated") === "challenge") return true;
|
|
10329
|
-
return isHTML && /<title>\s*Just a moment\.\.\.\s*<\/title>/i.test(
|
|
10411
|
+
return isHTML && /<title>\s*Just a moment\.\.\.\s*<\/title>/i.test(text5) && text5.includes("window._cf_chl_opt") && text5.includes("/cdn-cgi/challenge-platform/");
|
|
10330
10412
|
}
|
|
10331
10413
|
function isLikelyJSRendered(html) {
|
|
10332
10414
|
const bodyMatch = html.match(/<body[^>]*>([\s\S]*?)<\/body>/i);
|
|
@@ -10468,9 +10550,9 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
|
|
|
10468
10550
|
const hint = isPDFContent ? '; retry without mode for Markdown, or with mode "answer" and a prompt' : "";
|
|
10469
10551
|
return { url, title: "", content: "", error: `Unsupported content type in raw mode: ${mimeType || "missing"}${hint}`, mimeType, status: response.status };
|
|
10470
10552
|
}
|
|
10471
|
-
const
|
|
10553
|
+
const text6 = await readTextResponseWithLimit(response, maxResponseSize);
|
|
10472
10554
|
activityMonitor.logComplete(activityId, response.status);
|
|
10473
|
-
return { url, title: extractTextTitle(
|
|
10555
|
+
return { url, title: extractTextTitle(text6, url), content: text6, error: null, mimeType, status: response.status };
|
|
10474
10556
|
}
|
|
10475
10557
|
if (SUPPORTED_IMAGE_TYPES.has(mimeType)) {
|
|
10476
10558
|
const disabled = imageGateError();
|
|
@@ -10499,7 +10581,7 @@ async function extractViaHttp(url, timeoutMs, signal, options, preferMarkdown =
|
|
|
10499
10581
|
status: response.status
|
|
10500
10582
|
};
|
|
10501
10583
|
} catch (err) {
|
|
10502
|
-
const message =
|
|
10584
|
+
const message = errorMessage33(err);
|
|
10503
10585
|
activityMonitor.logError(activityId, message);
|
|
10504
10586
|
return { url, title: "", content: "", error: message, mimeType, status: response.status };
|
|
10505
10587
|
}
|
|
@@ -10540,19 +10622,19 @@ ${result.pages > 0 ? `Pages: ${result.pages}
|
|
|
10540
10622
|
error: `Unsupported content type: ${contentType.split(";")[0]}`
|
|
10541
10623
|
};
|
|
10542
10624
|
}
|
|
10543
|
-
const
|
|
10625
|
+
const text5 = await readTextResponseWithLimit(response, maxResponseSize);
|
|
10544
10626
|
const isHTML = contentType.includes("text/html") || contentType.includes("application/xhtml+xml");
|
|
10545
|
-
if (isCloudflareChallenge(response,
|
|
10627
|
+
if (isCloudflareChallenge(response, text5, isHTML)) {
|
|
10546
10628
|
activityMonitor.logComplete(activityId, response.status);
|
|
10547
10629
|
return { url, title: "", content: "", error: `HTTP ${response.status}: Blocked by Cloudflare challenge page`, status: response.status };
|
|
10548
10630
|
}
|
|
10549
10631
|
if (!isHTML) {
|
|
10550
10632
|
activityMonitor.logComplete(activityId, response.status);
|
|
10551
|
-
const title = extractTextTitle(
|
|
10552
|
-
if (mimeType !== "text/markdown" && mimeType !== "text/x-markdown") return { url, title, content:
|
|
10633
|
+
const title = extractTextTitle(text5, url);
|
|
10634
|
+
if (mimeType !== "text/markdown" && mimeType !== "text/x-markdown") return { url, title, content: text5, error: null };
|
|
10553
10635
|
const declaredLinks2 = discoverDeclaredWebLinks(null, response.headers.get("link"), response.url || url);
|
|
10554
|
-
const markdown2 = { url, title, content: appendDeclaredWebLinks(
|
|
10555
|
-
if (!preferMarkdown ||
|
|
10636
|
+
const markdown2 = { url, title, content: appendDeclaredWebLinks(text5, declaredLinks2), error: null, declaredLinks: declaredLinks2 };
|
|
10637
|
+
if (!preferMarkdown || text5.trim().length >= MIN_USEFUL_CONTENT2) return markdown2;
|
|
10556
10638
|
const normal = await extractViaHttp(url, Math.max(1, timeoutMs - (Date.now() - startedAt)), signal, options, false);
|
|
10557
10639
|
if (signal?.aborted || isNonRecoverableHttpError(normal.error) || normal.status === 404 || normal.status === 410 || isAbortError5(normal.error)) return normal;
|
|
10558
10640
|
const normalHasBody = normal.content.trim() !== appendDeclaredWebLinks("", normal.declaredLinks ?? []).trim();
|
|
@@ -10565,7 +10647,7 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
10565
10647
|
};
|
|
10566
10648
|
}
|
|
10567
10649
|
const { parseHTML } = await import("linkedom");
|
|
10568
|
-
const { document } = parseHTML(
|
|
10650
|
+
const { document } = parseHTML(text5);
|
|
10569
10651
|
const documentTitle = document.title?.trim() ?? "";
|
|
10570
10652
|
const declaredLinks = discoverDeclaredWebLinks(
|
|
10571
10653
|
document,
|
|
@@ -10576,7 +10658,7 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
10576
10658
|
const reader = new Readability(document);
|
|
10577
10659
|
const article = reader.parse();
|
|
10578
10660
|
if (!article) {
|
|
10579
|
-
const rscResult = extractRSCContent(
|
|
10661
|
+
const rscResult = extractRSCContent(text5);
|
|
10580
10662
|
if (rscResult && rscResult.content.length >= MIN_USEFUL_CONTENT2) {
|
|
10581
10663
|
activityMonitor.logComplete(activityId, response.status);
|
|
10582
10664
|
return {
|
|
@@ -10588,7 +10670,7 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
10588
10670
|
};
|
|
10589
10671
|
}
|
|
10590
10672
|
controller.signal.throwIfAborted();
|
|
10591
|
-
const defuddleResult = await extractWithDefuddle(
|
|
10673
|
+
const defuddleResult = await extractWithDefuddle(text5, response.url || url);
|
|
10592
10674
|
controller.signal.throwIfAborted();
|
|
10593
10675
|
if (defuddleResult && defuddleResult.content.length >= MIN_USEFUL_CONTENT2) {
|
|
10594
10676
|
activityMonitor.logComplete(activityId, response.status);
|
|
@@ -10601,7 +10683,7 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
10601
10683
|
};
|
|
10602
10684
|
}
|
|
10603
10685
|
activityMonitor.logComplete(activityId, response.status);
|
|
10604
|
-
const jsRendered = isLikelyJSRendered(
|
|
10686
|
+
const jsRendered = isLikelyJSRendered(text5);
|
|
10605
10687
|
const errorMsg = jsRendered ? "Page appears to be JavaScript-rendered (content loads dynamically)" : "Could not extract readable content from HTML structure";
|
|
10606
10688
|
return {
|
|
10607
10689
|
url,
|
|
@@ -10617,7 +10699,7 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
10617
10699
|
const markdown = (await getTurndown()).turndown(article.content);
|
|
10618
10700
|
activityMonitor.logComplete(activityId, response.status);
|
|
10619
10701
|
if (markdown.length < MIN_USEFUL_CONTENT2) {
|
|
10620
|
-
const rscResult = extractRSCContent(
|
|
10702
|
+
const rscResult = extractRSCContent(text5);
|
|
10621
10703
|
if (rscResult && rscResult.content.length >= MIN_USEFUL_CONTENT2) {
|
|
10622
10704
|
return {
|
|
10623
10705
|
url,
|
|
@@ -10628,7 +10710,7 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
10628
10710
|
};
|
|
10629
10711
|
}
|
|
10630
10712
|
controller.signal.throwIfAborted();
|
|
10631
|
-
const defuddleResult = await extractWithDefuddle(
|
|
10713
|
+
const defuddleResult = await extractWithDefuddle(text5, response.url || url);
|
|
10632
10714
|
controller.signal.throwIfAborted();
|
|
10633
10715
|
if (defuddleResult && defuddleResult.content.length >= MIN_USEFUL_CONTENT2) {
|
|
10634
10716
|
return {
|
|
@@ -10643,7 +10725,7 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
10643
10725
|
url,
|
|
10644
10726
|
title: article.title || documentTitle,
|
|
10645
10727
|
content: appendDeclaredWebLinks(markdown, declaredLinks),
|
|
10646
|
-
error: isLikelyJSRendered(
|
|
10728
|
+
error: isLikelyJSRendered(text5) ? "Page appears to be JavaScript-rendered (content loads dynamically)" : "Extracted content appears incomplete",
|
|
10647
10729
|
declaredLinks
|
|
10648
10730
|
};
|
|
10649
10731
|
}
|
|
@@ -10671,14 +10753,14 @@ Browser retry failed: ${normal.error}` : "")
|
|
|
10671
10753
|
}
|
|
10672
10754
|
}
|
|
10673
10755
|
}
|
|
10674
|
-
function extractHeadingTitle(
|
|
10675
|
-
const match =
|
|
10756
|
+
function extractHeadingTitle(text5) {
|
|
10757
|
+
const match = text5.match(/^#{1,2}\s+(.+)/m);
|
|
10676
10758
|
if (!match) return null;
|
|
10677
10759
|
const cleaned = match[1].replace(/\*+/g, "").trim();
|
|
10678
10760
|
return cleaned || null;
|
|
10679
10761
|
}
|
|
10680
|
-
function extractTextTitle(
|
|
10681
|
-
return extractHeadingTitle(
|
|
10762
|
+
function extractTextTitle(text5, url) {
|
|
10763
|
+
return extractHeadingTitle(text5) ?? (new URL(url).pathname.split("/").pop() || url);
|
|
10682
10764
|
}
|
|
10683
10765
|
async function fetchAllContent(urls, signal, options) {
|
|
10684
10766
|
const results = await Promise.all(urls.map((url) => fetchLimit(() => extractContent(url, signal, options))));
|
|
@@ -10745,7 +10827,7 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
10745
10827
|
// package.json
|
|
10746
10828
|
var package_default = {
|
|
10747
10829
|
name: "pi-web-access",
|
|
10748
|
-
version: "0.
|
|
10830
|
+
version: "0.42.0",
|
|
10749
10831
|
description: "Web search, URL fetching, GitHub repo cloning, PDF extraction, YouTube video understanding, and local video analysis for Pi coding agent. Supports OpenAI, Brave, Parallel, TinyFish, Search1API, Searchinfinity, Querit, Tavily, Firecrawl, Crawl4AI, Jina, SERPdive, Kagi, Ollama, AnySearch, Bright Data SERP, SerpBase, SerpApi, Serply, You.com, SearXNG, degoog, Exa, Perplexity, Gemini, Kimi, and Mistral.",
|
|
10750
10832
|
type: "module",
|
|
10751
10833
|
bin: {
|
|
@@ -10835,7 +10917,7 @@ var package_default = {
|
|
|
10835
10917
|
},
|
|
10836
10918
|
pi: {
|
|
10837
10919
|
extensions: [
|
|
10838
|
-
"./
|
|
10920
|
+
"./dist"
|
|
10839
10921
|
],
|
|
10840
10922
|
video: "https://github.com/nicobailon/pi-web-access/raw/refs/heads/main/pi-web-fetch-demo.mp4"
|
|
10841
10923
|
}
|
|
@@ -19322,13 +19404,13 @@ init_gemini_api();
|
|
|
19322
19404
|
init_gemini_adc();
|
|
19323
19405
|
init_gemini_web();
|
|
19324
19406
|
init_perplexity();
|
|
19325
|
-
import { existsSync as
|
|
19407
|
+
import { existsSync as existsSync42, readFileSync as readFileSync42 } from "node:fs";
|
|
19326
19408
|
|
|
19327
19409
|
// exa.ts
|
|
19328
19410
|
init_activity();
|
|
19329
19411
|
init_credential_source();
|
|
19330
19412
|
init_utils();
|
|
19331
|
-
import { existsSync as
|
|
19413
|
+
import { existsSync as existsSync8, readFileSync as readFileSync8 } from "node:fs";
|
|
19332
19414
|
var EXA_API_BASE_URL = "https://api.exa.ai";
|
|
19333
19415
|
var EXA_MCP_URL = "https://mcp.exa.ai/mcp";
|
|
19334
19416
|
var CONFIG_PATH5 = getWebSearchConfigPath();
|
|
@@ -19337,7 +19419,7 @@ var EXA_MCP_BASIC_TOOL = "web_search_exa";
|
|
|
19337
19419
|
var cachedConfig5 = null;
|
|
19338
19420
|
function loadConfig5() {
|
|
19339
19421
|
if (cachedConfig5) return cachedConfig5;
|
|
19340
|
-
if (!
|
|
19422
|
+
if (!existsSync8(CONFIG_PATH5)) {
|
|
19341
19423
|
cachedConfig5 = {};
|
|
19342
19424
|
return cachedConfig5;
|
|
19343
19425
|
}
|
|
@@ -19523,14 +19605,14 @@ async function callExaMcp(toolName, args, signal) {
|
|
|
19523
19605
|
const message = parsed.result.content?.find((item) => item.type === "text" && typeof item.text === "string")?.text?.trim();
|
|
19524
19606
|
throw new Error(message || "Exa MCP returned an error");
|
|
19525
19607
|
}
|
|
19526
|
-
const
|
|
19527
|
-
if (!
|
|
19608
|
+
const text5 = parsed.result?.content?.find((item) => item.type === "text" && typeof item.text === "string" && item.text.trim().length > 0)?.text;
|
|
19609
|
+
if (!text5) {
|
|
19528
19610
|
throw new Error("Exa MCP returned empty content");
|
|
19529
19611
|
}
|
|
19530
|
-
return
|
|
19612
|
+
return text5;
|
|
19531
19613
|
}
|
|
19532
|
-
function parseMcpResults(
|
|
19533
|
-
const blocks =
|
|
19614
|
+
function parseMcpResults(text5) {
|
|
19615
|
+
const blocks = text5.split(/(?=^Title: )/m).filter((block) => block.trim().length > 0);
|
|
19534
19616
|
const parsed = blocks.map((block) => {
|
|
19535
19617
|
const title = block.match(/^Title: (.+)/m)?.[1]?.trim() ?? "";
|
|
19536
19618
|
const url = block.match(/^URL: (.+)/m)?.[1]?.trim() ?? "";
|
|
@@ -19595,17 +19677,17 @@ function buildMcpQuery(query, options) {
|
|
|
19595
19677
|
function isAbortMessage(message) {
|
|
19596
19678
|
return message.toLowerCase().includes("abort");
|
|
19597
19679
|
}
|
|
19598
|
-
function parseJsonMcpResults(
|
|
19680
|
+
function parseJsonMcpResults(text5) {
|
|
19599
19681
|
try {
|
|
19600
|
-
const results = JSON.parse(
|
|
19682
|
+
const results = JSON.parse(text5).results;
|
|
19601
19683
|
return Array.isArray(results) && results.length > 0 ? results : null;
|
|
19602
19684
|
} catch {
|
|
19603
19685
|
return null;
|
|
19604
19686
|
}
|
|
19605
19687
|
}
|
|
19606
19688
|
async function searchWithExaMcpTool(tool, args, options) {
|
|
19607
|
-
const
|
|
19608
|
-
const jsonResults = parseJsonMcpResults(
|
|
19689
|
+
const text5 = await callExaMcp(tool, args, options.signal);
|
|
19690
|
+
const jsonResults = parseJsonMcpResults(text5);
|
|
19609
19691
|
if (jsonResults) {
|
|
19610
19692
|
return toSearchResponse(
|
|
19611
19693
|
buildAnswerFromSearchResults(jsonResults),
|
|
@@ -19613,7 +19695,7 @@ async function searchWithExaMcpTool(tool, args, options) {
|
|
|
19613
19695
|
options.includeContent ? mapInlineContent(jsonResults) : null
|
|
19614
19696
|
);
|
|
19615
19697
|
}
|
|
19616
|
-
const textResults = parseMcpResults(
|
|
19698
|
+
const textResults = parseMcpResults(text5);
|
|
19617
19699
|
if (!textResults) return null;
|
|
19618
19700
|
return toSearchResponse(
|
|
19619
19701
|
buildAnswerFromMcpResults(textResults),
|
|
@@ -19697,7 +19779,7 @@ async function searchWithExa(query, options = {}) {
|
|
|
19697
19779
|
|
|
19698
19780
|
// brave.ts
|
|
19699
19781
|
init_activity();
|
|
19700
|
-
import { existsSync as
|
|
19782
|
+
import { existsSync as existsSync9, readFileSync as readFileSync9 } from "node:fs";
|
|
19701
19783
|
|
|
19702
19784
|
// brave-rate-limit.ts
|
|
19703
19785
|
var DEFAULT_SAFETY_MARGIN_MS = 100;
|
|
@@ -19851,7 +19933,7 @@ var braveRateLimit = new BraveRateLimitCoordinator();
|
|
|
19851
19933
|
var cachedConfig6 = null;
|
|
19852
19934
|
function loadConfig6() {
|
|
19853
19935
|
if (cachedConfig6) return cachedConfig6;
|
|
19854
|
-
if (!
|
|
19936
|
+
if (!existsSync9(CONFIG_PATH6)) {
|
|
19855
19937
|
cachedConfig6 = {};
|
|
19856
19938
|
return cachedConfig6;
|
|
19857
19939
|
}
|
|
@@ -20050,7 +20132,7 @@ init_domain_filter_normalization();
|
|
|
20050
20132
|
init_credential_source();
|
|
20051
20133
|
init_utils();
|
|
20052
20134
|
import { randomUUID } from "node:crypto";
|
|
20053
|
-
import { existsSync as
|
|
20135
|
+
import { existsSync as existsSync10, readFileSync as readFileSync10 } from "node:fs";
|
|
20054
20136
|
var OPENAI_RESPONSES_URL = "https://api.openai.com/v1/responses";
|
|
20055
20137
|
var CODEX_RESPONSES_URL = "https://chatgpt.com/backend-api/codex/responses";
|
|
20056
20138
|
var CONFIG_PATH7 = getWebSearchConfigPath();
|
|
@@ -20105,7 +20187,7 @@ function isCurrentModelHostedSearchEligible(ctx) {
|
|
|
20105
20187
|
var cachedConfig7 = null;
|
|
20106
20188
|
function loadConfig7() {
|
|
20107
20189
|
if (cachedConfig7) return cachedConfig7;
|
|
20108
|
-
if (!
|
|
20190
|
+
if (!existsSync10(CONFIG_PATH7)) {
|
|
20109
20191
|
cachedConfig7 = {};
|
|
20110
20192
|
return cachedConfig7;
|
|
20111
20193
|
}
|
|
@@ -20394,8 +20476,8 @@ function isWebSearchCall(item) {
|
|
|
20394
20476
|
return !!item && typeof item === "object" && item.type === "web_search_call";
|
|
20395
20477
|
}
|
|
20396
20478
|
async function parseOpenAIResponse(response) {
|
|
20397
|
-
const
|
|
20398
|
-
const trimmed =
|
|
20479
|
+
const text5 = await response.text();
|
|
20480
|
+
const trimmed = text5.trim();
|
|
20399
20481
|
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
20400
20482
|
try {
|
|
20401
20483
|
const parsed = JSON.parse(trimmed);
|
|
@@ -20411,7 +20493,7 @@ async function parseOpenAIResponse(response) {
|
|
|
20411
20493
|
let completedResponse = null;
|
|
20412
20494
|
let webSearchCallSeen = false;
|
|
20413
20495
|
let streamError = null;
|
|
20414
|
-
for (const line of
|
|
20496
|
+
for (const line of text5.split("\n")) {
|
|
20415
20497
|
if (!line.startsWith("data: ")) continue;
|
|
20416
20498
|
const data = line.slice(6).trim();
|
|
20417
20499
|
if (!data || data === "[DONE]") continue;
|
|
@@ -20463,11 +20545,11 @@ function cleanSourceUrl(rawUrl) {
|
|
|
20463
20545
|
return rawUrl.replace(/[?&]utm_source=openai$/, "");
|
|
20464
20546
|
}
|
|
20465
20547
|
}
|
|
20466
|
-
function extractSnippetAround(
|
|
20467
|
-
if (typeof start !== "number" || typeof end !== "number" || !
|
|
20548
|
+
function extractSnippetAround(text5, start, end) {
|
|
20549
|
+
if (typeof start !== "number" || typeof end !== "number" || !text5) return "";
|
|
20468
20550
|
const before = Math.max(0, start - 100);
|
|
20469
|
-
const after = Math.min(
|
|
20470
|
-
const snippet =
|
|
20551
|
+
const after = Math.min(text5.length, end + 100);
|
|
20552
|
+
const snippet = text5.slice(before, after).replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").trim();
|
|
20471
20553
|
return snippet.length > 300 ? `${snippet.slice(0, 297)}...` : snippet;
|
|
20472
20554
|
}
|
|
20473
20555
|
function addResult(results, seen, url, title, snippet = "") {
|
|
@@ -20490,7 +20572,7 @@ function extractSearchResults(output, numResults) {
|
|
|
20490
20572
|
if (!Array.isArray(content)) continue;
|
|
20491
20573
|
for (const part of content) {
|
|
20492
20574
|
if (!part || typeof part !== "object") continue;
|
|
20493
|
-
const
|
|
20575
|
+
const text5 = typeof part.text === "string" ? part.text : "";
|
|
20494
20576
|
const annotations = part.annotations;
|
|
20495
20577
|
if (!Array.isArray(annotations)) continue;
|
|
20496
20578
|
for (const annotation of annotations) {
|
|
@@ -20500,7 +20582,7 @@ function extractSearchResults(output, numResults) {
|
|
|
20500
20582
|
seenUrls,
|
|
20501
20583
|
annotation.url,
|
|
20502
20584
|
annotation.title,
|
|
20503
|
-
extractSnippetAround(
|
|
20585
|
+
extractSnippetAround(text5, annotation.start_index, annotation.end_index)
|
|
20504
20586
|
);
|
|
20505
20587
|
}
|
|
20506
20588
|
}
|
|
@@ -20532,8 +20614,8 @@ function extractAnswer(output) {
|
|
|
20532
20614
|
if (!Array.isArray(content)) continue;
|
|
20533
20615
|
for (const part of content) {
|
|
20534
20616
|
if (!part || typeof part !== "object") continue;
|
|
20535
|
-
const
|
|
20536
|
-
if (typeof
|
|
20617
|
+
const text5 = part.text;
|
|
20618
|
+
if (typeof text5 === "string" && text5.trim().length > 0) parts.push(text5);
|
|
20537
20619
|
}
|
|
20538
20620
|
}
|
|
20539
20621
|
return parts.join("\n").trim();
|
|
@@ -20585,10 +20667,10 @@ function buildAlphaSearchHeaders(headers, apiKey) {
|
|
|
20585
20667
|
return result;
|
|
20586
20668
|
}
|
|
20587
20669
|
async function parseAlphaSearchResponse(response, numResults = 5) {
|
|
20588
|
-
const
|
|
20670
|
+
const text5 = await response.text();
|
|
20589
20671
|
let payload;
|
|
20590
20672
|
try {
|
|
20591
|
-
payload = JSON.parse(
|
|
20673
|
+
payload = JSON.parse(text5);
|
|
20592
20674
|
} catch {
|
|
20593
20675
|
throw new Error("OpenAI alpha/search returned invalid JSON");
|
|
20594
20676
|
}
|
|
@@ -20724,14 +20806,14 @@ init_credential_source();
|
|
|
20724
20806
|
init_search_answer_formatting();
|
|
20725
20807
|
init_search_result_count_normalization();
|
|
20726
20808
|
init_utils();
|
|
20727
|
-
import { existsSync as
|
|
20809
|
+
import { existsSync as existsSync14, readFileSync as readFileSync14 } from "node:fs";
|
|
20728
20810
|
var SEARCHINFINITY_SEARCH_URL = "https://torchlight.byteintlapi.com/search_api/web_search";
|
|
20729
20811
|
var CONFIG_PATH12 = getWebSearchConfigPath();
|
|
20730
20812
|
var SEARCH_TIMEOUT_MS7 = 3e4;
|
|
20731
20813
|
var cachedConfig11 = null;
|
|
20732
20814
|
function loadConfig11() {
|
|
20733
20815
|
if (cachedConfig11) return cachedConfig11;
|
|
20734
|
-
if (!
|
|
20816
|
+
if (!existsSync14(CONFIG_PATH12)) {
|
|
20735
20817
|
cachedConfig11 = {};
|
|
20736
20818
|
return cachedConfig11;
|
|
20737
20819
|
}
|
|
@@ -20903,14 +20985,14 @@ init_domain_filter_normalization();
|
|
|
20903
20985
|
init_search_result_count_normalization();
|
|
20904
20986
|
init_credential_source();
|
|
20905
20987
|
init_utils();
|
|
20906
|
-
import { existsSync as
|
|
20988
|
+
import { existsSync as existsSync16, readFileSync as readFileSync16 } from "node:fs";
|
|
20907
20989
|
var TAVILY_API_BASE_URL = "https://api.tavily.com";
|
|
20908
20990
|
var CONFIG_PATH14 = getWebSearchConfigPath();
|
|
20909
20991
|
var SEARCH_TIMEOUT_MS9 = 6e4;
|
|
20910
20992
|
var cachedConfig13 = null;
|
|
20911
20993
|
function loadConfig13() {
|
|
20912
20994
|
if (cachedConfig13) return cachedConfig13;
|
|
20913
|
-
if (!
|
|
20995
|
+
if (!existsSync16(CONFIG_PATH14)) {
|
|
20914
20996
|
cachedConfig13 = {};
|
|
20915
20997
|
return cachedConfig13;
|
|
20916
20998
|
}
|
|
@@ -21114,14 +21196,14 @@ init_search_answer_formatting();
|
|
|
21114
21196
|
init_search_result_count_normalization();
|
|
21115
21197
|
init_credential_source();
|
|
21116
21198
|
init_utils();
|
|
21117
|
-
import { existsSync as
|
|
21199
|
+
import { existsSync as existsSync17, readFileSync as readFileSync17 } from "node:fs";
|
|
21118
21200
|
var YOU_SEARCH_URL = "https://ydc-index.io/v1/search";
|
|
21119
21201
|
var CONFIG_PATH15 = getWebSearchConfigPath();
|
|
21120
21202
|
var SEARCH_TIMEOUT_MS10 = 6e4;
|
|
21121
21203
|
var cachedConfig14 = null;
|
|
21122
21204
|
function loadConfig14() {
|
|
21123
21205
|
if (cachedConfig14) return cachedConfig14;
|
|
21124
|
-
if (!
|
|
21206
|
+
if (!existsSync17(CONFIG_PATH15)) {
|
|
21125
21207
|
cachedConfig14 = {};
|
|
21126
21208
|
return cachedConfig14;
|
|
21127
21209
|
}
|
|
@@ -21264,14 +21346,14 @@ init_credential_source();
|
|
|
21264
21346
|
init_search_answer_formatting();
|
|
21265
21347
|
init_search_result_count_normalization();
|
|
21266
21348
|
init_utils();
|
|
21267
|
-
import { existsSync as
|
|
21349
|
+
import { existsSync as existsSync20, readFileSync as readFileSync20 } from "node:fs";
|
|
21268
21350
|
var JINA_SEARCH_BASE_URL = "https://s.jina.ai/";
|
|
21269
21351
|
var CONFIG_PATH17 = getWebSearchConfigPath();
|
|
21270
21352
|
var SEARCH_TIMEOUT_MS12 = 6e4;
|
|
21271
21353
|
var cachedConfig16 = null;
|
|
21272
21354
|
function loadConfig16() {
|
|
21273
21355
|
if (cachedConfig16) return cachedConfig16;
|
|
21274
|
-
if (!
|
|
21356
|
+
if (!existsSync20(CONFIG_PATH17)) {
|
|
21275
21357
|
cachedConfig16 = {};
|
|
21276
21358
|
return cachedConfig16;
|
|
21277
21359
|
}
|
|
@@ -21484,7 +21566,7 @@ init_domain_filter_normalization();
|
|
|
21484
21566
|
init_search_result_count_normalization();
|
|
21485
21567
|
init_credential_source();
|
|
21486
21568
|
init_utils();
|
|
21487
|
-
import { existsSync as
|
|
21569
|
+
import { existsSync as existsSync21, readFileSync as readFileSync21 } from "node:fs";
|
|
21488
21570
|
var SERPDIVE_API_URL = "https://api.serpdive.com/v1/search";
|
|
21489
21571
|
var CONFIG_PATH18 = getWebSearchConfigPath();
|
|
21490
21572
|
var SEARCH_TIMEOUT_MS13 = 6e4;
|
|
@@ -21493,7 +21575,7 @@ var DEFAULT_MODEL2 = "krill";
|
|
|
21493
21575
|
var cachedConfig17 = null;
|
|
21494
21576
|
function loadConfig17() {
|
|
21495
21577
|
if (cachedConfig17) return cachedConfig17;
|
|
21496
|
-
if (!
|
|
21578
|
+
if (!existsSync21(CONFIG_PATH18)) {
|
|
21497
21579
|
cachedConfig17 = {};
|
|
21498
21580
|
return cachedConfig17;
|
|
21499
21581
|
}
|
|
@@ -21689,14 +21771,14 @@ init_domain_filter_normalization();
|
|
|
21689
21771
|
init_search_answer_formatting();
|
|
21690
21772
|
init_credential_source();
|
|
21691
21773
|
init_utils();
|
|
21692
|
-
import { existsSync as
|
|
21774
|
+
import { existsSync as existsSync23, readFileSync as readFileSync23 } from "node:fs";
|
|
21693
21775
|
var BOCHA_SEARCH_URL = "https://api.bochaai.com/v1/web-search";
|
|
21694
21776
|
var CONFIG_PATH20 = getWebSearchConfigPath();
|
|
21695
21777
|
var SEARCH_TIMEOUT_MS15 = 6e4;
|
|
21696
21778
|
var cachedConfig19 = null;
|
|
21697
21779
|
function loadConfig19() {
|
|
21698
21780
|
if (cachedConfig19) return cachedConfig19;
|
|
21699
|
-
if (!
|
|
21781
|
+
if (!existsSync23(CONFIG_PATH20)) {
|
|
21700
21782
|
cachedConfig19 = {};
|
|
21701
21783
|
return cachedConfig19;
|
|
21702
21784
|
}
|
|
@@ -21872,13 +21954,13 @@ init_domain_filter_normalization();
|
|
|
21872
21954
|
init_ssrf_protection();
|
|
21873
21955
|
init_search_result_count_normalization();
|
|
21874
21956
|
init_utils();
|
|
21875
|
-
import { existsSync as
|
|
21957
|
+
import { existsSync as existsSync25, readFileSync as readFileSync25 } from "node:fs";
|
|
21876
21958
|
var CONFIG_PATH22 = getWebSearchConfigPath();
|
|
21877
21959
|
var SEARCH_TIMEOUT_MS17 = 3e4;
|
|
21878
21960
|
var cachedConfig21 = null;
|
|
21879
21961
|
function loadConfig21() {
|
|
21880
21962
|
if (cachedConfig21) return cachedConfig21;
|
|
21881
|
-
if (!
|
|
21963
|
+
if (!existsSync25(CONFIG_PATH22)) {
|
|
21882
21964
|
cachedConfig21 = {};
|
|
21883
21965
|
return cachedConfig21;
|
|
21884
21966
|
}
|
|
@@ -22059,14 +22141,14 @@ init_ssrf_protection();
|
|
|
22059
22141
|
init_search_answer_formatting();
|
|
22060
22142
|
init_search_result_count_normalization();
|
|
22061
22143
|
init_utils();
|
|
22062
|
-
import { existsSync as
|
|
22144
|
+
import { existsSync as existsSync26, readFileSync as readFileSync26 } from "node:fs";
|
|
22063
22145
|
var CONFIG_PATH23 = getWebSearchConfigPath();
|
|
22064
22146
|
var DEFAULT_BASE_URL = "https://degoog.org";
|
|
22065
22147
|
var SEARCH_TIMEOUT_MS18 = 3e4;
|
|
22066
22148
|
var cachedConfig22 = null;
|
|
22067
22149
|
function loadConfig22() {
|
|
22068
22150
|
if (cachedConfig22) return cachedConfig22;
|
|
22069
|
-
if (!
|
|
22151
|
+
if (!existsSync26(CONFIG_PATH23)) {
|
|
22070
22152
|
cachedConfig22 = {};
|
|
22071
22153
|
return cachedConfig22;
|
|
22072
22154
|
}
|
|
@@ -22207,8 +22289,8 @@ function parseResponse(value) {
|
|
|
22207
22289
|
if (!Array.isArray(envelope.results)) throw invalidResponse4("expected a results array");
|
|
22208
22290
|
return envelope.results;
|
|
22209
22291
|
}
|
|
22210
|
-
function redactSecrets(
|
|
22211
|
-
let redacted =
|
|
22292
|
+
function redactSecrets(text5, secrets) {
|
|
22293
|
+
let redacted = text5;
|
|
22212
22294
|
for (const secret of secrets) redacted = redactCredential(redacted, secret);
|
|
22213
22295
|
return redacted;
|
|
22214
22296
|
}
|
|
@@ -22408,14 +22490,14 @@ init_search_answer_formatting();
|
|
|
22408
22490
|
init_search_result_count_normalization();
|
|
22409
22491
|
init_credential_source();
|
|
22410
22492
|
init_utils();
|
|
22411
|
-
import { existsSync as
|
|
22493
|
+
import { existsSync as existsSync27, readFileSync as readFileSync27 } from "node:fs";
|
|
22412
22494
|
var ANYSEARCH_API_URL = "https://api.anysearch.com/v1/search";
|
|
22413
22495
|
var CONFIG_PATH24 = getWebSearchConfigPath();
|
|
22414
22496
|
var SEARCH_TIMEOUT_MS20 = 3e4;
|
|
22415
22497
|
var cachedConfig23 = null;
|
|
22416
22498
|
function loadConfig23() {
|
|
22417
22499
|
if (cachedConfig23) return cachedConfig23;
|
|
22418
|
-
if (!
|
|
22500
|
+
if (!existsSync27(CONFIG_PATH24)) {
|
|
22419
22501
|
cachedConfig23 = {};
|
|
22420
22502
|
return cachedConfig23;
|
|
22421
22503
|
}
|
|
@@ -22548,14 +22630,14 @@ init_search_answer_formatting();
|
|
|
22548
22630
|
init_search_result_count_normalization();
|
|
22549
22631
|
init_credential_source();
|
|
22550
22632
|
init_utils();
|
|
22551
|
-
import { existsSync as
|
|
22633
|
+
import { existsSync as existsSync28, readFileSync as readFileSync28 } from "node:fs";
|
|
22552
22634
|
var XCRAWL_API_URL = "https://run.xcrawl.com/v1/serp";
|
|
22553
22635
|
var CONFIG_PATH25 = getWebSearchConfigPath();
|
|
22554
22636
|
var SEARCH_TIMEOUT_MS21 = 6e4;
|
|
22555
22637
|
var cachedConfig24 = null;
|
|
22556
22638
|
function loadConfig24() {
|
|
22557
22639
|
if (cachedConfig24) return cachedConfig24;
|
|
22558
|
-
if (!
|
|
22640
|
+
if (!existsSync28(CONFIG_PATH25)) {
|
|
22559
22641
|
cachedConfig24 = {};
|
|
22560
22642
|
return cachedConfig24;
|
|
22561
22643
|
}
|
|
@@ -22733,7 +22815,7 @@ init_activity();
|
|
|
22733
22815
|
init_domain_filter_normalization();
|
|
22734
22816
|
init_credential_source();
|
|
22735
22817
|
init_utils();
|
|
22736
|
-
import { existsSync as
|
|
22818
|
+
import { existsSync as existsSync29, readFileSync as readFileSync29 } from "node:fs";
|
|
22737
22819
|
var XAI_RESPONSES_URL = "https://api.x.ai/v1/responses";
|
|
22738
22820
|
var CONFIG_PATH26 = getWebSearchConfigPath();
|
|
22739
22821
|
var SEARCH_TIMEOUT_MS22 = 6e4;
|
|
@@ -22743,7 +22825,7 @@ var DEFAULT_XAI_SEARCH_TOOLS = ["web_search"];
|
|
|
22743
22825
|
var cachedConfig25 = null;
|
|
22744
22826
|
function loadConfig25() {
|
|
22745
22827
|
if (cachedConfig25) return cachedConfig25;
|
|
22746
|
-
if (!
|
|
22828
|
+
if (!existsSync29(CONFIG_PATH26)) {
|
|
22747
22829
|
cachedConfig25 = {};
|
|
22748
22830
|
return cachedConfig25;
|
|
22749
22831
|
}
|
|
@@ -22904,11 +22986,11 @@ function addSources(results, seen, sources) {
|
|
|
22904
22986
|
if (!Array.isArray(sources)) return;
|
|
22905
22987
|
for (const source of sources) addSource(results, seen, source);
|
|
22906
22988
|
}
|
|
22907
|
-
function extractSnippetAround2(
|
|
22908
|
-
if (typeof start !== "number" || typeof end !== "number" || !
|
|
22989
|
+
function extractSnippetAround2(text5, start, end) {
|
|
22990
|
+
if (typeof start !== "number" || typeof end !== "number" || !text5) return "";
|
|
22909
22991
|
const before = Math.max(0, start - 100);
|
|
22910
|
-
const after = Math.min(
|
|
22911
|
-
const snippet =
|
|
22992
|
+
const after = Math.min(text5.length, end + 100);
|
|
22993
|
+
const snippet = text5.slice(before, after).replace(/\[([^\]]*)\]\([^)]*\)/g, "$1").trim();
|
|
22912
22994
|
return snippet.length > 300 ? `${snippet.slice(0, 297)}...` : snippet;
|
|
22913
22995
|
}
|
|
22914
22996
|
function extractAnswer2(output) {
|
|
@@ -22919,8 +23001,8 @@ function extractAnswer2(output) {
|
|
|
22919
23001
|
if (!Array.isArray(content)) continue;
|
|
22920
23002
|
for (const part of content) {
|
|
22921
23003
|
if (!part || typeof part !== "object") continue;
|
|
22922
|
-
const
|
|
22923
|
-
if (typeof
|
|
23004
|
+
const text5 = part.text;
|
|
23005
|
+
if (typeof text5 === "string" && text5.trim().length > 0) parts.push(text5);
|
|
22924
23006
|
}
|
|
22925
23007
|
}
|
|
22926
23008
|
return parts.join("\n").trim();
|
|
@@ -22934,7 +23016,7 @@ function extractSearchResults2(output, citations, numResults) {
|
|
|
22934
23016
|
if (!Array.isArray(content)) continue;
|
|
22935
23017
|
for (const part of content) {
|
|
22936
23018
|
if (!part || typeof part !== "object") continue;
|
|
22937
|
-
const
|
|
23019
|
+
const text5 = typeof part.text === "string" ? part.text : "";
|
|
22938
23020
|
const annotations = part.annotations;
|
|
22939
23021
|
if (!Array.isArray(annotations)) continue;
|
|
22940
23022
|
for (const annotation of annotations) {
|
|
@@ -22945,7 +23027,7 @@ function extractSearchResults2(output, citations, numResults) {
|
|
|
22945
23027
|
seenUrls,
|
|
22946
23028
|
annotation.url,
|
|
22947
23029
|
annotation.title,
|
|
22948
|
-
extractSnippetAround2(
|
|
23030
|
+
extractSnippetAround2(text5, annotation.start_index, annotation.end_index)
|
|
22949
23031
|
);
|
|
22950
23032
|
}
|
|
22951
23033
|
}
|
|
@@ -23033,7 +23115,7 @@ init_search_answer_formatting();
|
|
|
23033
23115
|
init_search_result_count_normalization();
|
|
23034
23116
|
init_credential_source();
|
|
23035
23117
|
init_utils();
|
|
23036
|
-
import { existsSync as
|
|
23118
|
+
import { existsSync as existsSync30, readFileSync as readFileSync30 } from "node:fs";
|
|
23037
23119
|
var BRIGHTDATA_API_URL = "https://api.brightdata.com/request";
|
|
23038
23120
|
var CONFIG_PATH27 = getWebSearchConfigPath();
|
|
23039
23121
|
var SEARCH_TIMEOUT_MS23 = 6e4;
|
|
@@ -23051,7 +23133,7 @@ function configParseDetail(err) {
|
|
|
23051
23133
|
}
|
|
23052
23134
|
function loadConfig26() {
|
|
23053
23135
|
if (cachedConfig26) return cachedConfig26;
|
|
23054
|
-
if (!
|
|
23136
|
+
if (!existsSync30(CONFIG_PATH27)) {
|
|
23055
23137
|
cachedConfig26 = {};
|
|
23056
23138
|
return cachedConfig26;
|
|
23057
23139
|
}
|
|
@@ -23183,8 +23265,8 @@ function errorMessage18(err) {
|
|
|
23183
23265
|
}
|
|
23184
23266
|
var STATUS_SHAPED_PATTERN = /\b(?:error|status|http)[\s:=-]{1,4}(\d{3})\b/gi;
|
|
23185
23267
|
var QUOTA_SHAPED_PATTERN = /rate limit|quota|too many requests/gi;
|
|
23186
|
-
function untrustedText(
|
|
23187
|
-
return
|
|
23268
|
+
function untrustedText(text5, limit = 300) {
|
|
23269
|
+
return text5.replace(/\s+/g, " ").trim().slice(0, limit).replace(STATUS_SHAPED_PATTERN, "upstream $1").replace(QUOTA_SHAPED_PATTERN, "upstream rate-limit notice");
|
|
23188
23270
|
}
|
|
23189
23271
|
function invalidResponse7(zone, message) {
|
|
23190
23272
|
return new Error(`Bright Data API returned invalid response for zone ${zone}: ${message}`);
|
|
@@ -23330,7 +23412,7 @@ init_domain_filter_normalization();
|
|
|
23330
23412
|
init_search_answer_formatting();
|
|
23331
23413
|
init_credential_source();
|
|
23332
23414
|
init_utils();
|
|
23333
|
-
import { existsSync as
|
|
23415
|
+
import { existsSync as existsSync31, readFileSync as readFileSync31 } from "node:fs";
|
|
23334
23416
|
var SERPBASE_API_URL = "https://api.serpbase.dev/google/search";
|
|
23335
23417
|
var CONFIG_PATH28 = getWebSearchConfigPath();
|
|
23336
23418
|
var SEARCH_TIMEOUT_MS24 = 6e4;
|
|
@@ -23343,7 +23425,7 @@ var RECENCY_TBS2 = {
|
|
|
23343
23425
|
var cachedConfig27 = null;
|
|
23344
23426
|
function loadConfig27() {
|
|
23345
23427
|
if (cachedConfig27) return cachedConfig27;
|
|
23346
|
-
if (!
|
|
23428
|
+
if (!existsSync31(CONFIG_PATH28)) {
|
|
23347
23429
|
cachedConfig27 = {};
|
|
23348
23430
|
return cachedConfig27;
|
|
23349
23431
|
}
|
|
@@ -23499,7 +23581,7 @@ init_search_answer_formatting();
|
|
|
23499
23581
|
init_search_result_count_normalization();
|
|
23500
23582
|
init_credential_source();
|
|
23501
23583
|
init_utils();
|
|
23502
|
-
import { existsSync as
|
|
23584
|
+
import { existsSync as existsSync32, readFileSync as readFileSync32 } from "node:fs";
|
|
23503
23585
|
var SERPAPI_SEARCH_URL = "https://serpapi.com/search.json";
|
|
23504
23586
|
var CONFIG_PATH29 = getWebSearchConfigPath();
|
|
23505
23587
|
var SEARCH_TIMEOUT_MS25 = 6e4;
|
|
@@ -23512,7 +23594,7 @@ var RECENCY_TBS3 = {
|
|
|
23512
23594
|
var cachedConfig28 = null;
|
|
23513
23595
|
function loadConfig28() {
|
|
23514
23596
|
if (cachedConfig28) return cachedConfig28;
|
|
23515
|
-
if (!
|
|
23597
|
+
if (!existsSync32(CONFIG_PATH29)) {
|
|
23516
23598
|
cachedConfig28 = {};
|
|
23517
23599
|
return cachedConfig28;
|
|
23518
23600
|
}
|
|
@@ -23667,7 +23749,7 @@ init_search_answer_formatting();
|
|
|
23667
23749
|
init_search_result_count_normalization();
|
|
23668
23750
|
init_credential_source();
|
|
23669
23751
|
init_utils();
|
|
23670
|
-
import { existsSync as
|
|
23752
|
+
import { existsSync as existsSync33, readFileSync as readFileSync33 } from "node:fs";
|
|
23671
23753
|
var SERPER_SEARCH_URL = "https://google.serper.dev/search";
|
|
23672
23754
|
var CONFIG_PATH30 = getWebSearchConfigPath();
|
|
23673
23755
|
var SEARCH_TIMEOUT_MS26 = 6e4;
|
|
@@ -23680,7 +23762,7 @@ var RECENCY_TBS4 = {
|
|
|
23680
23762
|
var cachedConfig29 = null;
|
|
23681
23763
|
function loadConfig29() {
|
|
23682
23764
|
if (cachedConfig29) return cachedConfig29;
|
|
23683
|
-
if (!
|
|
23765
|
+
if (!existsSync33(CONFIG_PATH30)) {
|
|
23684
23766
|
cachedConfig29 = {};
|
|
23685
23767
|
return cachedConfig29;
|
|
23686
23768
|
}
|
|
@@ -23828,7 +23910,7 @@ init_search_answer_formatting();
|
|
|
23828
23910
|
init_search_result_count_normalization();
|
|
23829
23911
|
init_credential_source();
|
|
23830
23912
|
init_utils();
|
|
23831
|
-
import { existsSync as
|
|
23913
|
+
import { existsSync as existsSync34, readFileSync as readFileSync34 } from "node:fs";
|
|
23832
23914
|
var SERPLY_SEARCH_URL = "https://api.serply.io/v1/search";
|
|
23833
23915
|
var CONFIG_PATH31 = getWebSearchConfigPath();
|
|
23834
23916
|
var SEARCH_TIMEOUT_MS27 = 6e4;
|
|
@@ -23841,7 +23923,7 @@ var RECENCY_TBS5 = {
|
|
|
23841
23923
|
var cachedConfig30 = null;
|
|
23842
23924
|
function loadConfig30() {
|
|
23843
23925
|
if (cachedConfig30) return cachedConfig30;
|
|
23844
|
-
if (!
|
|
23926
|
+
if (!existsSync34(CONFIG_PATH31)) {
|
|
23845
23927
|
cachedConfig30 = {};
|
|
23846
23928
|
return cachedConfig30;
|
|
23847
23929
|
}
|
|
@@ -23995,14 +24077,14 @@ init_credential_source();
|
|
|
23995
24077
|
init_domain_filter_normalization();
|
|
23996
24078
|
init_search_result_count_normalization();
|
|
23997
24079
|
init_utils();
|
|
23998
|
-
import { existsSync as
|
|
24080
|
+
import { existsSync as existsSync35, readFileSync as readFileSync35 } from "node:fs";
|
|
23999
24081
|
import { isIP as isIP2 } from "node:net";
|
|
24000
24082
|
var MCP_URL = "https://agent-toolkit.app.baizhi.cloud/mcp";
|
|
24001
24083
|
var SEARCH_TIMEOUT_MS28 = 6e4;
|
|
24002
24084
|
var CONFIG_PATH32 = getWebSearchConfigPath();
|
|
24003
24085
|
function credentialOptions() {
|
|
24004
24086
|
let config = {};
|
|
24005
|
-
if (
|
|
24087
|
+
if (existsSync35(CONFIG_PATH32)) {
|
|
24006
24088
|
try {
|
|
24007
24089
|
const parsed = JSON.parse(readFileSync35(CONFIG_PATH32, "utf8"));
|
|
24008
24090
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error();
|
|
@@ -24108,7 +24190,7 @@ init_domain_filter_normalization();
|
|
|
24108
24190
|
init_search_answer_formatting();
|
|
24109
24191
|
init_search_result_count_normalization();
|
|
24110
24192
|
init_utils();
|
|
24111
|
-
import { existsSync as
|
|
24193
|
+
import { existsSync as existsSync36, readFileSync as readFileSync36 } from "node:fs";
|
|
24112
24194
|
var MCP_URLS = {
|
|
24113
24195
|
global: "https://api.z.ai/api/mcp/web_search_prime/mcp",
|
|
24114
24196
|
china: "https://open.bigmodel.cn/api/mcp/web_search_prime/mcp"
|
|
@@ -24117,7 +24199,7 @@ var RECENCY = { day: "oneDay", week: "oneWeek", month: "oneMonth", year: "oneYea
|
|
|
24117
24199
|
var SEARCH_TIMEOUT_MS29 = 6e4;
|
|
24118
24200
|
var CONFIG_PATH33 = getWebSearchConfigPath();
|
|
24119
24201
|
function loadConfig31() {
|
|
24120
|
-
if (!
|
|
24202
|
+
if (!existsSync36(CONFIG_PATH33)) return {};
|
|
24121
24203
|
try {
|
|
24122
24204
|
const parsed = JSON.parse(readFileSync36(CONFIG_PATH33, "utf8"));
|
|
24123
24205
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) throw new Error();
|
|
@@ -24153,8 +24235,8 @@ function searchArguments2(query, options) {
|
|
|
24153
24235
|
...domain ? { search_domain_filter: domain } : {}
|
|
24154
24236
|
};
|
|
24155
24237
|
}
|
|
24156
|
-
function parseResults(
|
|
24157
|
-
let value = JSON.parse(
|
|
24238
|
+
function parseResults(text5, limit, domain) {
|
|
24239
|
+
let value = JSON.parse(text5);
|
|
24158
24240
|
if (typeof value === "string") value = JSON.parse(value);
|
|
24159
24241
|
if (!Array.isArray(value)) throw new Error("Z.ai returned invalid response: expected a result list");
|
|
24160
24242
|
const results = [];
|
|
@@ -24219,9 +24301,9 @@ async function searchWithZai(query, options = {}) {
|
|
|
24219
24301
|
if (!toolName) throw new Error("Z.ai returned invalid response: web search tool not listed");
|
|
24220
24302
|
const result = await client.callTool({ name: toolName, arguments: args }, void 0, { signal, timeout: SEARCH_TIMEOUT_MS29 });
|
|
24221
24303
|
if (result.isError) throw new Error("Z.ai search tool returned an error");
|
|
24222
|
-
const
|
|
24223
|
-
if (!
|
|
24224
|
-
const results = parseResults(
|
|
24304
|
+
const text5 = (Array.isArray(result.content) ? result.content : []).find((item) => item.type === "text" && typeof item.text === "string");
|
|
24305
|
+
if (!text5) throw new Error("Z.ai returned invalid response: no search text");
|
|
24306
|
+
const results = parseResults(text5.text, limit, args.search_domain_filter);
|
|
24225
24307
|
activityMonitor.logComplete(activityId, 200);
|
|
24226
24308
|
return { answer: formatSearchResultsAsAnswer(results), results };
|
|
24227
24309
|
} catch (err) {
|
|
@@ -24251,7 +24333,7 @@ init_search_answer_formatting();
|
|
|
24251
24333
|
init_search_result_count_normalization();
|
|
24252
24334
|
init_credential_source();
|
|
24253
24335
|
init_utils();
|
|
24254
|
-
import { existsSync as
|
|
24336
|
+
import { existsSync as existsSync37, readFileSync as readFileSync37 } from "node:fs";
|
|
24255
24337
|
var VALYU_SEARCH_URL = "https://api.valyu.ai/v1/search";
|
|
24256
24338
|
var CONFIG_PATH34 = getWebSearchConfigPath();
|
|
24257
24339
|
var SEARCH_TIMEOUT_MS30 = 6e4;
|
|
@@ -24260,7 +24342,7 @@ var MAX_CONTENT_CHARS = 4e3;
|
|
|
24260
24342
|
var cachedConfig31 = null;
|
|
24261
24343
|
function loadConfig32() {
|
|
24262
24344
|
if (cachedConfig31) return cachedConfig31;
|
|
24263
|
-
if (!
|
|
24345
|
+
if (!existsSync37(CONFIG_PATH34)) {
|
|
24264
24346
|
cachedConfig31 = {};
|
|
24265
24347
|
return cachedConfig31;
|
|
24266
24348
|
}
|
|
@@ -24403,7 +24485,7 @@ init_search_answer_formatting();
|
|
|
24403
24485
|
init_search_result_count_normalization();
|
|
24404
24486
|
init_credential_source();
|
|
24405
24487
|
init_utils();
|
|
24406
|
-
import { existsSync as
|
|
24488
|
+
import { existsSync as existsSync38, readFileSync as readFileSync38 } from "node:fs";
|
|
24407
24489
|
var KEENABLE_SEARCH_URL = "https://api.keenable.ai/v1/search";
|
|
24408
24490
|
var KEENABLE_PUBLIC_SEARCH_URL = "https://api.keenable.ai/v1/search/public";
|
|
24409
24491
|
var KEENABLE_CLIENT_TITLE = "pi-web-access";
|
|
@@ -24420,7 +24502,7 @@ var RECENCY_DAYS = {
|
|
|
24420
24502
|
var cachedConfig32 = null;
|
|
24421
24503
|
function loadConfig33() {
|
|
24422
24504
|
if (cachedConfig32) return cachedConfig32;
|
|
24423
|
-
if (!
|
|
24505
|
+
if (!existsSync38(CONFIG_PATH35)) {
|
|
24424
24506
|
cachedConfig32 = {};
|
|
24425
24507
|
return cachedConfig32;
|
|
24426
24508
|
}
|
|
@@ -24584,7 +24666,7 @@ init_search_answer_formatting();
|
|
|
24584
24666
|
init_search_result_count_normalization();
|
|
24585
24667
|
init_credential_source();
|
|
24586
24668
|
init_utils();
|
|
24587
|
-
import { existsSync as
|
|
24669
|
+
import { existsSync as existsSync39, readFileSync as readFileSync39 } from "node:fs";
|
|
24588
24670
|
var CERAMIC_SEARCH_URL = "https://api.ceramic.ai/search";
|
|
24589
24671
|
var CONFIG_PATH36 = getWebSearchConfigPath();
|
|
24590
24672
|
var SEARCH_TIMEOUT_MS32 = 3e4;
|
|
@@ -24594,7 +24676,7 @@ var MAX_SNIPPET_CHARS3 = 500;
|
|
|
24594
24676
|
var cachedConfig33 = null;
|
|
24595
24677
|
function loadConfig34() {
|
|
24596
24678
|
if (cachedConfig33) return cachedConfig33;
|
|
24597
|
-
if (!
|
|
24679
|
+
if (!existsSync39(CONFIG_PATH36)) {
|
|
24598
24680
|
cachedConfig33 = {};
|
|
24599
24681
|
return cachedConfig33;
|
|
24600
24682
|
}
|
|
@@ -24760,6 +24842,183 @@ async function searchWithCeramic(query, options = {}) {
|
|
|
24760
24842
|
return { answer: formatSearchResultsAsAnswer(results), results };
|
|
24761
24843
|
}
|
|
24762
24844
|
|
|
24845
|
+
// deepseek.ts
|
|
24846
|
+
init_activity();
|
|
24847
|
+
init_domain_filter_normalization();
|
|
24848
|
+
init_search_answer_formatting();
|
|
24849
|
+
init_search_result_count_normalization();
|
|
24850
|
+
init_credential_source();
|
|
24851
|
+
init_utils();
|
|
24852
|
+
import { existsSync as existsSync40, readFileSync as readFileSync40 } from "node:fs";
|
|
24853
|
+
var DEEPSEEK_SEARCH_URL = "https://api.deepseek.com/v1/tools/search";
|
|
24854
|
+
var CONFIG_PATH37 = getWebSearchConfigPath();
|
|
24855
|
+
var SEARCH_TIMEOUT_MS33 = 3e4;
|
|
24856
|
+
var MAX_QUERY_CHARS = 128;
|
|
24857
|
+
var MAX_SNIPPET_CHARS4 = 800;
|
|
24858
|
+
var RECENCY_DAYS2 = {
|
|
24859
|
+
day: 1,
|
|
24860
|
+
week: 7,
|
|
24861
|
+
month: 30,
|
|
24862
|
+
year: 365
|
|
24863
|
+
};
|
|
24864
|
+
var cachedConfig34 = null;
|
|
24865
|
+
function loadConfig35() {
|
|
24866
|
+
if (cachedConfig34) return cachedConfig34;
|
|
24867
|
+
if (!existsSync40(CONFIG_PATH37)) {
|
|
24868
|
+
cachedConfig34 = {};
|
|
24869
|
+
return cachedConfig34;
|
|
24870
|
+
}
|
|
24871
|
+
const raw = readFileSync40(CONFIG_PATH37, "utf-8");
|
|
24872
|
+
let parsed;
|
|
24873
|
+
try {
|
|
24874
|
+
parsed = JSON.parse(raw);
|
|
24875
|
+
} catch (err) {
|
|
24876
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
24877
|
+
throw new Error(`Failed to parse ${CONFIG_PATH37}: ${message}`);
|
|
24878
|
+
}
|
|
24879
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
24880
|
+
throw new Error(`Invalid config in ${CONFIG_PATH37}: expected a JSON object`);
|
|
24881
|
+
}
|
|
24882
|
+
cachedConfig34 = parsed;
|
|
24883
|
+
return cachedConfig34;
|
|
24884
|
+
}
|
|
24885
|
+
async function requireApiKey15(signal) {
|
|
24886
|
+
const apiKey = await resolveCredential({
|
|
24887
|
+
provider: "DeepSeek",
|
|
24888
|
+
configuredValue: loadConfig35().deepseekApiKey,
|
|
24889
|
+
environmentValue: process.env.DEEPSEEK_API_KEY,
|
|
24890
|
+
signal
|
|
24891
|
+
});
|
|
24892
|
+
if (!apiKey) {
|
|
24893
|
+
throw new Error(
|
|
24894
|
+
`DeepSeek API key not found. Either:
|
|
24895
|
+
1. Create ${CONFIG_PATH37} with { "deepseekApiKey": "your-key" }
|
|
24896
|
+
2. Set DEEPSEEK_API_KEY environment variable
|
|
24897
|
+
Get a key at https://platform.deepseek.com/api_keys`
|
|
24898
|
+
);
|
|
24899
|
+
}
|
|
24900
|
+
return apiKey;
|
|
24901
|
+
}
|
|
24902
|
+
function buildQuery8(query, options) {
|
|
24903
|
+
const include = [];
|
|
24904
|
+
const exclude = [];
|
|
24905
|
+
for (const raw of options.domainFilter ?? []) {
|
|
24906
|
+
const domain = normalizeDomain(raw);
|
|
24907
|
+
if (!domain) continue;
|
|
24908
|
+
const target = raw.trim().startsWith("-") ? exclude : include;
|
|
24909
|
+
if (!target.includes(domain)) target.push(domain);
|
|
24910
|
+
}
|
|
24911
|
+
const parts = [query.trim()];
|
|
24912
|
+
if (include.length > 0) parts.push(include.map((domain) => `site:${domain}`).join(" OR "));
|
|
24913
|
+
for (const domain of exclude) parts.push(`-site:${domain}`);
|
|
24914
|
+
if (options.recencyFilter) {
|
|
24915
|
+
const after = new Date(Date.now() - RECENCY_DAYS2[options.recencyFilter] * 864e5).toISOString().slice(0, 10);
|
|
24916
|
+
parts.push(`after:${after}`);
|
|
24917
|
+
}
|
|
24918
|
+
const built = parts.join(" ");
|
|
24919
|
+
const length = [...built].length;
|
|
24920
|
+
if (length > MAX_QUERY_CHARS) {
|
|
24921
|
+
throw new Error(`DeepSeek invalid request: the query is ${length} characters with domain and date filters; DeepSeek accepts at most ${MAX_QUERY_CHARS}`);
|
|
24922
|
+
}
|
|
24923
|
+
return built;
|
|
24924
|
+
}
|
|
24925
|
+
function text4(value) {
|
|
24926
|
+
return typeof value === "string" ? value.replace(/\s+/g, " ").trim() : "";
|
|
24927
|
+
}
|
|
24928
|
+
function errorMessage26(err) {
|
|
24929
|
+
return err instanceof Error ? err.message : String(err);
|
|
24930
|
+
}
|
|
24931
|
+
function parseResponse11(value) {
|
|
24932
|
+
const results = value && typeof value === "object" && !Array.isArray(value) ? value.results : void 0;
|
|
24933
|
+
if (!Array.isArray(results)) throw new Error("DeepSeek returned invalid response: expected a results array");
|
|
24934
|
+
return results;
|
|
24935
|
+
}
|
|
24936
|
+
function describeError2(body) {
|
|
24937
|
+
try {
|
|
24938
|
+
const error = JSON.parse(body).error;
|
|
24939
|
+
const message = text4(error?.message);
|
|
24940
|
+
if (message) return message;
|
|
24941
|
+
} catch {
|
|
24942
|
+
}
|
|
24943
|
+
return body;
|
|
24944
|
+
}
|
|
24945
|
+
function isDeepSeekAvailable() {
|
|
24946
|
+
return hasCredentialSource({ provider: "DeepSeek", configuredValue: loadConfig35().deepseekApiKey, environmentValue: process.env.DEEPSEEK_API_KEY });
|
|
24947
|
+
}
|
|
24948
|
+
async function searchWithDeepSeek(query, options = {}) {
|
|
24949
|
+
const builtQuery = buildQuery8(query, options);
|
|
24950
|
+
const apiKey = await requireApiKey15(options.signal);
|
|
24951
|
+
const numResults = normalizeSearchResultCount(options.numResults);
|
|
24952
|
+
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
24953
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS33);
|
|
24954
|
+
let response;
|
|
24955
|
+
let entries;
|
|
24956
|
+
try {
|
|
24957
|
+
response = await fetchWithCredentialRedirects(DEEPSEEK_SEARCH_URL, {
|
|
24958
|
+
method: "POST",
|
|
24959
|
+
headers: {
|
|
24960
|
+
Accept: "application/json",
|
|
24961
|
+
"Content-Type": "application/json",
|
|
24962
|
+
Authorization: `Bearer ${apiKey}`
|
|
24963
|
+
},
|
|
24964
|
+
body: JSON.stringify({ query: builtQuery, count: numResults }),
|
|
24965
|
+
signal: options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal
|
|
24966
|
+
}, ["Authorization"]);
|
|
24967
|
+
if (!response.ok) {
|
|
24968
|
+
const errorText = redactCredential(describeError2(await response.text()), apiKey).slice(0, 300);
|
|
24969
|
+
throw new Error(`DeepSeek error ${response.status}: ${errorText}`);
|
|
24970
|
+
}
|
|
24971
|
+
let rawData;
|
|
24972
|
+
try {
|
|
24973
|
+
rawData = await response.json();
|
|
24974
|
+
} catch (err) {
|
|
24975
|
+
if (err instanceof Error && err.name === "TimeoutError") throw err;
|
|
24976
|
+
throw new Error(`DeepSeek returned invalid JSON: ${errorMessage26(err)}`);
|
|
24977
|
+
}
|
|
24978
|
+
entries = parseResponse11(rawData);
|
|
24979
|
+
} catch (err) {
|
|
24980
|
+
if (options.signal?.aborted) {
|
|
24981
|
+
activityMonitor.logComplete(activityId, 0);
|
|
24982
|
+
throw new Error("Aborted");
|
|
24983
|
+
}
|
|
24984
|
+
const message = errorMessage26(err);
|
|
24985
|
+
const providerTimeout = timeoutSignal.aborted || err instanceof Error && err.name === "TimeoutError";
|
|
24986
|
+
const outgoing = providerTimeout ? new Error(`DeepSeek request timed out after ${Math.round(SEARCH_TIMEOUT_MS33 / 1e3)}s`) : (() => {
|
|
24987
|
+
const redactedMessage = redactCredential(message, apiKey);
|
|
24988
|
+
if (redactedMessage === message && err instanceof Error) return err;
|
|
24989
|
+
const redactedError = new Error(redactedMessage);
|
|
24990
|
+
if (err instanceof Error) redactedError.name = err.name;
|
|
24991
|
+
return redactedError;
|
|
24992
|
+
})();
|
|
24993
|
+
activityMonitor.logError(activityId, redactCredential(errorMessage26(outgoing), apiKey));
|
|
24994
|
+
throw outgoing;
|
|
24995
|
+
}
|
|
24996
|
+
activityMonitor.logComplete(activityId, response.status);
|
|
24997
|
+
const results = [];
|
|
24998
|
+
const seen = /* @__PURE__ */ new Set();
|
|
24999
|
+
for (const entry of entries) {
|
|
25000
|
+
if (!entry || typeof entry !== "object") continue;
|
|
25001
|
+
if (typeof entry.url !== "string" || !entry.url) continue;
|
|
25002
|
+
let resultUrl;
|
|
25003
|
+
try {
|
|
25004
|
+
resultUrl = new URL(entry.url);
|
|
25005
|
+
} catch {
|
|
25006
|
+
continue;
|
|
25007
|
+
}
|
|
25008
|
+
if (resultUrl.protocol !== "http:" && resultUrl.protocol !== "https:") continue;
|
|
25009
|
+
if (seen.has(resultUrl.href)) continue;
|
|
25010
|
+
seen.add(resultUrl.href);
|
|
25011
|
+
results.push({
|
|
25012
|
+
title: text4(entry.title) || `Source ${results.length + 1}`,
|
|
25013
|
+
url: resultUrl.href,
|
|
25014
|
+
snippet: (text4(entry.summary) || text4(entry.snippet)).slice(0, MAX_SNIPPET_CHARS4)
|
|
25015
|
+
});
|
|
25016
|
+
if (results.length >= numResults) break;
|
|
25017
|
+
}
|
|
25018
|
+
if (entries.length > 0 && results.length === 0) throw new Error("DeepSeek returned invalid response: no result had an http(s) URL");
|
|
25019
|
+
return { answer: formatSearchResultsAsAnswer(results), results };
|
|
25020
|
+
}
|
|
25021
|
+
|
|
24763
25022
|
// kimi-search.ts
|
|
24764
25023
|
init_activity();
|
|
24765
25024
|
init_domain_filter_normalization();
|
|
@@ -24769,7 +25028,7 @@ init_search_result_count_normalization();
|
|
|
24769
25028
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
24770
25029
|
var KIMI_SEARCH_URL = "https://api.kimi.com/coding/v1/search";
|
|
24771
25030
|
var KIMI_PROVIDERS = ["kimi-coding", "kimi-code"];
|
|
24772
|
-
var
|
|
25031
|
+
var SEARCH_TIMEOUT_MS34 = 3e4;
|
|
24773
25032
|
function buildRequestHeaders(auth) {
|
|
24774
25033
|
const headers = new Headers();
|
|
24775
25034
|
for (const [name, value] of Object.entries(auth.headers)) {
|
|
@@ -24884,7 +25143,7 @@ async function searchWithKimi(query, options = {}, ctx) {
|
|
|
24884
25143
|
throw new Error("Kimi Code web search unavailable. Run /login kimi-coding to authenticate a Kimi Code Plan account.");
|
|
24885
25144
|
}
|
|
24886
25145
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
24887
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
25146
|
+
const timeoutSignal = AbortSignal.timeout(SEARCH_TIMEOUT_MS34);
|
|
24888
25147
|
const requestSignal15 = options.signal ? AbortSignal.any([timeoutSignal, options.signal]) : timeoutSignal;
|
|
24889
25148
|
try {
|
|
24890
25149
|
const response = await fetch(KIMI_SEARCH_URL, {
|
|
@@ -24936,45 +25195,45 @@ init_activity();
|
|
|
24936
25195
|
init_domain_filter_normalization();
|
|
24937
25196
|
init_credential_source();
|
|
24938
25197
|
init_utils();
|
|
24939
|
-
import { existsSync as
|
|
25198
|
+
import { existsSync as existsSync41, readFileSync as readFileSync41 } from "node:fs";
|
|
24940
25199
|
var MISTRAL_CONVERSATIONS_URL = "https://api.mistral.ai/v1/conversations";
|
|
24941
|
-
var
|
|
24942
|
-
var
|
|
25200
|
+
var CONFIG_PATH38 = getWebSearchConfigPath();
|
|
25201
|
+
var SEARCH_TIMEOUT_MS35 = 6e4;
|
|
24943
25202
|
var DEFAULT_SEARCH_MODEL = "mistral-small-latest";
|
|
24944
25203
|
var DEFAULT_SEARCH_TOOL = "web_search";
|
|
24945
25204
|
var MAX_RESULTS = 20;
|
|
24946
|
-
var
|
|
24947
|
-
function
|
|
24948
|
-
if (
|
|
24949
|
-
if (!
|
|
24950
|
-
|
|
24951
|
-
return
|
|
25205
|
+
var cachedConfig35 = null;
|
|
25206
|
+
function loadConfig36() {
|
|
25207
|
+
if (cachedConfig35) return cachedConfig35;
|
|
25208
|
+
if (!existsSync41(CONFIG_PATH38)) {
|
|
25209
|
+
cachedConfig35 = {};
|
|
25210
|
+
return cachedConfig35;
|
|
24952
25211
|
}
|
|
24953
|
-
const raw =
|
|
25212
|
+
const raw = readFileSync41(CONFIG_PATH38, "utf-8");
|
|
24954
25213
|
let parsed;
|
|
24955
25214
|
try {
|
|
24956
25215
|
parsed = JSON.parse(raw);
|
|
24957
25216
|
} catch (err) {
|
|
24958
25217
|
const message = err instanceof Error ? err.message : String(err);
|
|
24959
|
-
throw new Error(`Failed to parse ${
|
|
25218
|
+
throw new Error(`Failed to parse ${CONFIG_PATH38}: ${message}`);
|
|
24960
25219
|
}
|
|
24961
25220
|
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
24962
|
-
throw new Error(`Invalid config in ${
|
|
25221
|
+
throw new Error(`Invalid config in ${CONFIG_PATH38}: expected a JSON object`);
|
|
24963
25222
|
}
|
|
24964
|
-
|
|
24965
|
-
return
|
|
25223
|
+
cachedConfig35 = parsed;
|
|
25224
|
+
return cachedConfig35;
|
|
24966
25225
|
}
|
|
24967
25226
|
function resolveSearchModel(value) {
|
|
24968
25227
|
if (value === void 0) return DEFAULT_SEARCH_MODEL;
|
|
24969
25228
|
if (typeof value !== "string" || value.trim().length === 0) {
|
|
24970
|
-
throw new Error(`mistralSearchModel in ${
|
|
25229
|
+
throw new Error(`mistralSearchModel in ${CONFIG_PATH38} must be a non-empty string`);
|
|
24971
25230
|
}
|
|
24972
25231
|
return value.trim();
|
|
24973
25232
|
}
|
|
24974
25233
|
function resolveSearchTool(value) {
|
|
24975
25234
|
if (value === void 0) return DEFAULT_SEARCH_TOOL;
|
|
24976
25235
|
if (value !== "web_search" && value !== "web_search_premium") {
|
|
24977
|
-
throw new Error(`mistralSearchTool in ${
|
|
25236
|
+
throw new Error(`mistralSearchTool in ${CONFIG_PATH38} must be either web_search or web_search_premium`);
|
|
24978
25237
|
}
|
|
24979
25238
|
return value;
|
|
24980
25239
|
}
|
|
@@ -25032,7 +25291,7 @@ function buildSearchPrompt(query, options, numResults) {
|
|
|
25032
25291
|
|
|
25033
25292
|
${query}` : query;
|
|
25034
25293
|
}
|
|
25035
|
-
function
|
|
25294
|
+
function errorMessage27(err) {
|
|
25036
25295
|
return err instanceof Error ? err.message : String(err);
|
|
25037
25296
|
}
|
|
25038
25297
|
function invalidResponse15(message) {
|
|
@@ -25081,14 +25340,14 @@ function parseConversationResponse(value, options, numResults) {
|
|
|
25081
25340
|
async function getApiKey26(signal) {
|
|
25082
25341
|
const apiKey = await resolveCredential({
|
|
25083
25342
|
provider: "Mistral",
|
|
25084
|
-
configuredValue:
|
|
25343
|
+
configuredValue: loadConfig36().mistralApiKey,
|
|
25085
25344
|
environmentValue: process.env.MISTRAL_API_KEY,
|
|
25086
25345
|
signal
|
|
25087
25346
|
});
|
|
25088
25347
|
if (!apiKey) {
|
|
25089
25348
|
throw new Error(
|
|
25090
25349
|
`Mistral API key not found. Either:
|
|
25091
|
-
1. Create ${
|
|
25350
|
+
1. Create ${CONFIG_PATH38} with { "mistralApiKey": "your-key" }
|
|
25092
25351
|
2. Set MISTRAL_API_KEY environment variable
|
|
25093
25352
|
Get a key at https://console.mistral.ai/api-keys`
|
|
25094
25353
|
);
|
|
@@ -25097,7 +25356,7 @@ Get a key at https://console.mistral.ai/api-keys`
|
|
|
25097
25356
|
}
|
|
25098
25357
|
function isMistralAvailable() {
|
|
25099
25358
|
try {
|
|
25100
|
-
const config =
|
|
25359
|
+
const config = loadConfig36();
|
|
25101
25360
|
resolveSearchModel(config.mistralSearchModel);
|
|
25102
25361
|
resolveSearchTool(config.mistralSearchTool);
|
|
25103
25362
|
return hasCredentialSource({
|
|
@@ -25110,12 +25369,12 @@ function isMistralAvailable() {
|
|
|
25110
25369
|
}
|
|
25111
25370
|
}
|
|
25112
25371
|
async function searchWithMistral(query, options = {}) {
|
|
25113
|
-
const config =
|
|
25372
|
+
const config = loadConfig36();
|
|
25114
25373
|
const model = resolveSearchModel(config.mistralSearchModel);
|
|
25115
25374
|
const tool = resolveSearchTool(config.mistralSearchTool);
|
|
25116
25375
|
const numResults = normalizeCount4(options.numResults);
|
|
25117
25376
|
const apiKey = await getApiKey26(options.signal);
|
|
25118
|
-
const requestSignal15 = options.signal ? AbortSignal.any([AbortSignal.timeout(
|
|
25377
|
+
const requestSignal15 = options.signal ? AbortSignal.any([AbortSignal.timeout(SEARCH_TIMEOUT_MS35), options.signal]) : AbortSignal.timeout(SEARCH_TIMEOUT_MS35);
|
|
25119
25378
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
25120
25379
|
try {
|
|
25121
25380
|
const response = await fetch(MISTRAL_CONVERSATIONS_URL, {
|
|
@@ -25140,13 +25399,13 @@ async function searchWithMistral(query, options = {}) {
|
|
|
25140
25399
|
try {
|
|
25141
25400
|
parsed = await response.json();
|
|
25142
25401
|
} catch (err) {
|
|
25143
|
-
throw new Error(`Mistral API returned invalid JSON: ${
|
|
25402
|
+
throw new Error(`Mistral API returned invalid JSON: ${errorMessage27(err)}`);
|
|
25144
25403
|
}
|
|
25145
25404
|
const result = parseConversationResponse(parsed, options, numResults);
|
|
25146
25405
|
activityMonitor.logComplete(activityId, response.status);
|
|
25147
25406
|
return result;
|
|
25148
25407
|
} catch (err) {
|
|
25149
|
-
const message =
|
|
25408
|
+
const message = errorMessage27(err);
|
|
25150
25409
|
const redactedMessage = redactCredential(message, apiKey);
|
|
25151
25410
|
if (redactedMessage.toLowerCase().includes("abort")) {
|
|
25152
25411
|
activityMonitor.logComplete(activityId, 0);
|
|
@@ -25162,7 +25421,7 @@ async function searchWithMistral(query, options = {}) {
|
|
|
25162
25421
|
|
|
25163
25422
|
// gemini-search.ts
|
|
25164
25423
|
init_utils();
|
|
25165
|
-
var RESOLVED_SEARCH_PROVIDERS = ["openai", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "you", "firecrawl", "jina", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "exa", "serpdive", "kagi", "ollama", "anysearch", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "bocha", "xcrawl", "baizhi", "zai", "keenable", "ceramic"];
|
|
25424
|
+
var RESOLVED_SEARCH_PROVIDERS = ["openai", "brave", "parallel", "parallel-mcp", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "you", "firecrawl", "jina", "searxng", "degoog", "duckduckgo", "perplexity", "gemini", "kimi", "exa", "serpdive", "kagi", "ollama", "anysearch", "xai", "mistral", "brightdata", "serpbase", "serpapi", "serper", "serply", "valyu", "bocha", "xcrawl", "baizhi", "zai", "keenable", "ceramic", "deepseek"];
|
|
25166
25425
|
var SEARCH_PROVIDERS = ["auto", "all", ...RESOLVED_SEARCH_PROVIDERS];
|
|
25167
25426
|
var SearchProviderError = class extends Error {
|
|
25168
25427
|
provider;
|
|
@@ -25178,18 +25437,18 @@ var SearchProviderError = class extends Error {
|
|
|
25178
25437
|
this.causeError = cause;
|
|
25179
25438
|
}
|
|
25180
25439
|
};
|
|
25181
|
-
var
|
|
25440
|
+
var CONFIG_PATH39 = getWebSearchConfigPath();
|
|
25182
25441
|
var DEFAULT_SEARCH_MODEL2 = "gemini-3.6-flash";
|
|
25183
25442
|
var ALL_SEARCH_PROVIDERS = ["searxng", "openai", "exa", "brave", "parallel", "tinyfish", "search1api", "searchinfinity", "querit", "tavily", "firecrawl", "jina", "serpdive", "kagi", "ollama", "perplexity", "gemini", "bocha"];
|
|
25184
25443
|
var VALID_ROUTING_KINDS = ["transient", "quota", "network", "invalid-response", "unsupported"];
|
|
25185
25444
|
var cachedSearchConfig = null;
|
|
25186
25445
|
function getSearchConfig() {
|
|
25187
25446
|
if (cachedSearchConfig) return cachedSearchConfig;
|
|
25188
|
-
if (!
|
|
25447
|
+
if (!existsSync42(CONFIG_PATH39)) {
|
|
25189
25448
|
cachedSearchConfig = { searchProvider: "auto", searchProviderConfigured: false };
|
|
25190
25449
|
return cachedSearchConfig;
|
|
25191
25450
|
}
|
|
25192
|
-
const rawText =
|
|
25451
|
+
const rawText = readFileSync42(CONFIG_PATH39, "utf-8");
|
|
25193
25452
|
let raw;
|
|
25194
25453
|
try {
|
|
25195
25454
|
const parsed = JSON.parse(rawText);
|
|
@@ -25199,25 +25458,25 @@ function getSearchConfig() {
|
|
|
25199
25458
|
raw = parsed;
|
|
25200
25459
|
} catch (err) {
|
|
25201
25460
|
const message = err instanceof Error ? err.message : String(err);
|
|
25202
|
-
throw new Error(`Failed to parse ${
|
|
25461
|
+
throw new Error(`Failed to parse ${CONFIG_PATH39}: ${message}`);
|
|
25203
25462
|
}
|
|
25204
25463
|
const searchModel = normalizeSearchModel(raw.searchModel);
|
|
25205
25464
|
const webSearch = raw.webSearch;
|
|
25206
25465
|
if (webSearch !== void 0 && (!webSearch || typeof webSearch !== "object" || Array.isArray(webSearch))) {
|
|
25207
|
-
throw new Error(`webSearch in ${
|
|
25466
|
+
throw new Error(`webSearch in ${CONFIG_PATH39} must be an object`);
|
|
25208
25467
|
}
|
|
25209
|
-
const allowedProviders = webSearch && Object.hasOwn(webSearch, "allowedProviders") ? normalizeResolvedProviderList(webSearch.allowedProviders, `webSearch.allowedProviders in ${
|
|
25468
|
+
const allowedProviders = webSearch && Object.hasOwn(webSearch, "allowedProviders") ? normalizeResolvedProviderList(webSearch.allowedProviders, `webSearch.allowedProviders in ${CONFIG_PATH39}`) : void 0;
|
|
25210
25469
|
const searchProviderConfigured = Object.hasOwn(raw, "searchProvider") || Object.hasOwn(raw, "provider");
|
|
25211
|
-
const searchProvider = normalizeSearchProviderSelection(raw.searchProvider ?? raw.provider, `provider in ${
|
|
25470
|
+
const searchProvider = normalizeSearchProviderSelection(raw.searchProvider ?? raw.provider, `provider in ${CONFIG_PATH39}`);
|
|
25212
25471
|
const searchRouting = Object.hasOwn(raw, "searchRouting") ? normalizeSearchRouting(raw.searchRouting) : void 0;
|
|
25213
25472
|
if (allowedProviders) {
|
|
25214
25473
|
if (Object.hasOwn(raw, "searchProvider")) {
|
|
25215
|
-
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.searchProvider), `searchProvider in ${
|
|
25474
|
+
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.searchProvider), `searchProvider in ${CONFIG_PATH39}`, allowedProviders);
|
|
25216
25475
|
}
|
|
25217
25476
|
if (Object.hasOwn(raw, "provider")) {
|
|
25218
|
-
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.provider), `provider in ${
|
|
25477
|
+
assertSearchProviderSelectionAllowed(normalizeSearchProviderSelection(raw.provider), `provider in ${CONFIG_PATH39}`, allowedProviders);
|
|
25219
25478
|
}
|
|
25220
|
-
if (searchRouting) assertSearchProviderSelectionAllowed(searchRouting.providers, `searchRouting.providers in ${
|
|
25479
|
+
if (searchRouting) assertSearchProviderSelectionAllowed(searchRouting.providers, `searchRouting.providers in ${CONFIG_PATH39}`, allowedProviders);
|
|
25221
25480
|
}
|
|
25222
25481
|
cachedSearchConfig = {
|
|
25223
25482
|
searchProvider,
|
|
@@ -25230,21 +25489,21 @@ function getSearchConfig() {
|
|
|
25230
25489
|
}
|
|
25231
25490
|
function normalizeSearchRouting(value) {
|
|
25232
25491
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
25233
|
-
throw new Error(`searchRouting in ${
|
|
25492
|
+
throw new Error(`searchRouting in ${CONFIG_PATH39} must be an object`);
|
|
25234
25493
|
}
|
|
25235
25494
|
const raw = value;
|
|
25236
|
-
const providers = normalizeResolvedProviderList(raw.providers, `searchRouting.providers in ${
|
|
25495
|
+
const providers = normalizeResolvedProviderList(raw.providers, `searchRouting.providers in ${CONFIG_PATH39}`);
|
|
25237
25496
|
const useCurrentModel = raw.useCurrentModel;
|
|
25238
25497
|
if (useCurrentModel !== void 0 && typeof useCurrentModel !== "boolean") {
|
|
25239
|
-
throw new Error(`searchRouting.useCurrentModel in ${
|
|
25498
|
+
throw new Error(`searchRouting.useCurrentModel in ${CONFIG_PATH39} must be a boolean`);
|
|
25240
25499
|
}
|
|
25241
25500
|
if (!Array.isArray(raw.fallbackOn) || raw.fallbackOn.length === 0) {
|
|
25242
|
-
throw new Error(`searchRouting.fallbackOn in ${
|
|
25501
|
+
throw new Error(`searchRouting.fallbackOn in ${CONFIG_PATH39} must be a non-empty array`);
|
|
25243
25502
|
}
|
|
25244
25503
|
const fallbackOn = [];
|
|
25245
25504
|
for (const kind of raw.fallbackOn) {
|
|
25246
25505
|
if (typeof kind !== "string" || !VALID_ROUTING_KINDS.includes(kind)) {
|
|
25247
|
-
throw new Error(`searchRouting.fallbackOn in ${
|
|
25506
|
+
throw new Error(`searchRouting.fallbackOn in ${CONFIG_PATH39} may only contain transient, quota, network, invalid-response, or unsupported`);
|
|
25248
25507
|
}
|
|
25249
25508
|
if (!fallbackOn.includes(kind)) {
|
|
25250
25509
|
fallbackOn.push(kind);
|
|
@@ -25294,11 +25553,11 @@ function normalizeSearchProviderSelection(value, label = "provider") {
|
|
|
25294
25553
|
const normalized = typeof value === "string" ? value.trim().toLowerCase() : "";
|
|
25295
25554
|
return SEARCH_PROVIDERS.includes(normalized) ? normalized : "auto";
|
|
25296
25555
|
}
|
|
25297
|
-
function
|
|
25556
|
+
function errorMessage28(err) {
|
|
25298
25557
|
return err instanceof Error ? err.message : String(err);
|
|
25299
25558
|
}
|
|
25300
25559
|
function isAbortError2(err) {
|
|
25301
|
-
return
|
|
25560
|
+
return errorMessage28(err).toLowerCase().includes("abort");
|
|
25302
25561
|
}
|
|
25303
25562
|
async function tryOpenAIInAuto(query, options, fallbackErrors, take) {
|
|
25304
25563
|
try {
|
|
@@ -25308,7 +25567,7 @@ async function tryOpenAIInAuto(query, options, fallbackErrors, take) {
|
|
|
25308
25567
|
}
|
|
25309
25568
|
} catch (err) {
|
|
25310
25569
|
if (isAbortError2(err)) throw err;
|
|
25311
|
-
fallbackErrors.push(`OpenAI: ${
|
|
25570
|
+
fallbackErrors.push(`OpenAI: ${errorMessage28(err)}`);
|
|
25312
25571
|
}
|
|
25313
25572
|
return null;
|
|
25314
25573
|
}
|
|
@@ -25319,7 +25578,7 @@ async function searchWithGemini(query, options, strictErrors) {
|
|
|
25319
25578
|
if (apiResult) return apiResult;
|
|
25320
25579
|
} catch (err) {
|
|
25321
25580
|
if (err instanceof CredentialResolutionError || isAbortError2(err)) throw err;
|
|
25322
|
-
errors.push(`Gemini API: ${
|
|
25581
|
+
errors.push(`Gemini API: ${errorMessage28(err)}`);
|
|
25323
25582
|
}
|
|
25324
25583
|
try {
|
|
25325
25584
|
const webResult = await searchWithGeminiWeb(query, options);
|
|
@@ -25328,7 +25587,7 @@ async function searchWithGemini(query, options, strictErrors) {
|
|
|
25328
25587
|
if (diagnostic) errors.push(`Gemini Web: ${diagnostic}`);
|
|
25329
25588
|
} catch (err) {
|
|
25330
25589
|
if (isAbortError2(err)) throw err;
|
|
25331
|
-
errors.push(`Gemini Web: ${
|
|
25590
|
+
errors.push(`Gemini Web: ${errorMessage28(err)}`);
|
|
25332
25591
|
}
|
|
25333
25592
|
if (strictErrors && errors.length > 0) {
|
|
25334
25593
|
throw new Error(`Gemini search failed:
|
|
@@ -25343,11 +25602,11 @@ function providerErrorStatus(message) {
|
|
|
25343
25602
|
}
|
|
25344
25603
|
function classifyProviderError(provider, err) {
|
|
25345
25604
|
if (err instanceof SearchProviderError) return err;
|
|
25346
|
-
const message =
|
|
25605
|
+
const message = errorMessage28(err);
|
|
25347
25606
|
const lower = message.toLowerCase();
|
|
25348
25607
|
const status = providerErrorStatus(message);
|
|
25349
25608
|
const openAIStreamError = provider === "openai" && lower.includes("openai api stream error");
|
|
25350
|
-
const
|
|
25609
|
+
const text5 = openAIStreamError ? lower.replace(/_/g, " ") : lower;
|
|
25351
25610
|
let kind = "unknown";
|
|
25352
25611
|
const mentionsUnsupportedWebSearch = /(?:web[_ -]?search|web[_ -]?search_preview|(?:the )?tool)\b.*\b(?:unsupported|not supported|does not support|doesn't support|unknown|unrecognized|unavailable|not found)|\b(?:unsupported|not supported|does not support|doesn't support|unknown|unrecognized|unavailable|not found)\b.*\b(?:web[_ -]?search|web[_ -]?search_preview|(?:the )?tool)/i.test(lower);
|
|
25353
25612
|
if (err instanceof CredentialResolutionError || /(?:api )?key (?:not found|missing)|credential resolution/.test(lower)) {
|
|
@@ -25368,19 +25627,19 @@ function classifyProviderError(provider, err) {
|
|
|
25368
25627
|
kind = "quota";
|
|
25369
25628
|
} else if (status !== void 0 && (status === 408 || status === 425 || status >= 500)) {
|
|
25370
25629
|
kind = "transient";
|
|
25371
|
-
} else if (/rate limit|quota|too many requests/.test(
|
|
25630
|
+
} else if (/rate limit|quota|too many requests/.test(text5) || openAIStreamError && /usage limit/.test(text5)) {
|
|
25372
25631
|
kind = "quota";
|
|
25373
|
-
} else if (/unauthorized|forbidden|permission denied/.test(
|
|
25632
|
+
} else if (/unauthorized|forbidden|permission denied/.test(text5) || openAIStreamError && /authentication error|permission error|invalid api key/.test(text5)) {
|
|
25374
25633
|
kind = "auth";
|
|
25375
|
-
} else if (/bad request|invalid request/.test(
|
|
25634
|
+
} else if (/bad request|invalid request/.test(text5)) {
|
|
25376
25635
|
kind = "invalid-request";
|
|
25377
|
-
} else if (/invalid json|no parseable response|no parseable results|invalid response|returned empty response|no web_search_call/.test(
|
|
25636
|
+
} else if (/invalid json|no parseable response|no parseable results|invalid response|returned empty response|no web_search_call/.test(text5)) {
|
|
25378
25637
|
kind = "invalid-response";
|
|
25379
|
-
} else if (/temporar|service unavailable|server error/.test(
|
|
25638
|
+
} else if (/temporar|service unavailable|server error/.test(text5) || openAIStreamError && /internal error|\bapi error|overloaded/.test(text5)) {
|
|
25380
25639
|
kind = "transient";
|
|
25381
|
-
} else if (err instanceof TypeError || /fetch failed|network|econnreset|econnrefused|enotfound|etimedout|timed out|socket/.test(
|
|
25640
|
+
} else if (err instanceof TypeError || /fetch failed|network|econnreset|econnrefused|enotfound|etimedout|timed out|socket/.test(text5)) {
|
|
25382
25641
|
kind = "network";
|
|
25383
|
-
} else if (/invalid or missing|invalid config|failed to parse|must be an? |configuration/.test(
|
|
25642
|
+
} else if (/invalid or missing|invalid config|failed to parse|must be an? |configuration/.test(text5)) {
|
|
25384
25643
|
kind = "config";
|
|
25385
25644
|
} else if (openAIStreamError) {
|
|
25386
25645
|
kind = "invalid-response";
|
|
@@ -25420,6 +25679,7 @@ async function searchWithResolvedProvider(provider, query, options, useCurrentMo
|
|
|
25420
25679
|
if (provider === "valyu") return { ...await searchWithValyu(query, options), provider };
|
|
25421
25680
|
if (provider === "keenable") return { ...await searchWithKeenable(query, options), provider };
|
|
25422
25681
|
if (provider === "ceramic") return { ...await searchWithCeramic(query, options), provider };
|
|
25682
|
+
if (provider === "deepseek") return { ...await searchWithDeepSeek(query, options), provider };
|
|
25423
25683
|
if (provider === "xcrawl") return { ...await searchWithXCrawl(query, options), provider };
|
|
25424
25684
|
if (provider === "perplexity") return { ...await searchWithPerplexity(query, options), provider };
|
|
25425
25685
|
if (provider === "searxng") return { ...await searchWithSearXNG(query, options), provider };
|
|
@@ -25431,7 +25691,7 @@ async function searchWithResolvedProvider(provider, query, options, useCurrentMo
|
|
|
25431
25691
|
if (result2) return { ...result2, provider };
|
|
25432
25692
|
throw new Error(
|
|
25433
25693
|
`Gemini search unavailable. Either:
|
|
25434
|
-
1. Configure geminiApiKey in ${
|
|
25694
|
+
1. Configure geminiApiKey in ${CONFIG_PATH39} or set GEMINI_API_KEY
|
|
25435
25695
|
2. Set GOOGLE_GEMINI_BASE_URL + CLOUDFLARE_API_KEY for Cloudflare AI Gateway routing
|
|
25436
25696
|
3. Set geminiAuth to "adc" in web-search.json with a Google Cloud ADC + project/location
|
|
25437
25697
|
4. Sign into gemini.google.com in a supported Chromium-based browser`
|
|
@@ -25473,6 +25733,7 @@ async function isResolvedProviderAvailable(provider, options, useCurrentModel =
|
|
|
25473
25733
|
if (provider === "valyu") return isValyuAvailable();
|
|
25474
25734
|
if (provider === "keenable") return isKeenableAvailable();
|
|
25475
25735
|
if (provider === "ceramic") return isCeramicAvailable();
|
|
25736
|
+
if (provider === "deepseek") return isDeepSeekAvailable();
|
|
25476
25737
|
if (provider === "xcrawl") return isXcrawlAvailable();
|
|
25477
25738
|
if (provider === "perplexity") return isPerplexityAvailable();
|
|
25478
25739
|
if (provider === "searxng") return isSearXNGAvailable();
|
|
@@ -25519,6 +25780,7 @@ function providerLabel(provider) {
|
|
|
25519
25780
|
if (provider === "valyu") return "Valyu";
|
|
25520
25781
|
if (provider === "keenable") return "Keenable";
|
|
25521
25782
|
if (provider === "ceramic") return "Ceramic";
|
|
25783
|
+
if (provider === "deepseek") return "DeepSeek";
|
|
25522
25784
|
return provider.charAt(0).toUpperCase() + provider.slice(1);
|
|
25523
25785
|
}
|
|
25524
25786
|
async function searchWithAllProvider(provider, query, options) {
|
|
@@ -25534,7 +25796,7 @@ async function searchWithProviders(query, options, selectedProviders) {
|
|
|
25534
25796
|
available: provider === "gemini" ? isGeminiApiAvailable() : await isResolvedProviderAvailable(provider, options)
|
|
25535
25797
|
})))).filter((entry) => entry.available).map((entry) => entry.provider);
|
|
25536
25798
|
if (providers.length === 0) {
|
|
25537
|
-
throw new Error('No configured search provider available for provider "all". Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, XCrawl, Keenable, and
|
|
25799
|
+
throw new Error('No configured search provider available for provider "all". Parallel MCP, degoog, DuckDuckGo, Kimi, AnySearch, xAI, Mistral, Bright Data, SerpBase, SerpApi, Serper, Serply, You.com, Valyu, Baizhi, Z.ai, XCrawl, Keenable, Ceramic, and DeepSeek are excluded.');
|
|
25538
25800
|
}
|
|
25539
25801
|
const settled = await Promise.allSettled(
|
|
25540
25802
|
providers.map((provider) => selectedProviders ? searchWithResolvedProvider(provider, query, options) : searchWithAllProvider(provider, query, options))
|
|
@@ -25547,7 +25809,7 @@ async function searchWithProviders(query, options, selectedProviders) {
|
|
|
25547
25809
|
if (outcome.status === "fulfilled") {
|
|
25548
25810
|
successes.push(outcome.value);
|
|
25549
25811
|
} else {
|
|
25550
|
-
failures.push({ provider: providers[index], error:
|
|
25812
|
+
failures.push({ provider: providers[index], error: errorMessage28(outcome.reason) });
|
|
25551
25813
|
}
|
|
25552
25814
|
}
|
|
25553
25815
|
if (successes.length === 0) {
|
|
@@ -25604,7 +25866,7 @@ async function searchWithConfiguredRouting(query, options, routing) {
|
|
|
25604
25866
|
return await searchWithResolvedProvider(provider, query, options, useCurrentModel);
|
|
25605
25867
|
} catch (err) {
|
|
25606
25868
|
const classified = classifyProviderError(provider, err);
|
|
25607
|
-
diagnostics.push(`${provider} [${classified.kind}]: ${
|
|
25869
|
+
diagnostics.push(`${provider} [${classified.kind}]: ${errorMessage28(err)}`);
|
|
25608
25870
|
if (!routing.fallbackOn.includes(classified.kind)) {
|
|
25609
25871
|
throw classified;
|
|
25610
25872
|
}
|
|
@@ -25641,7 +25903,7 @@ async function search(query, options = {}) {
|
|
|
25641
25903
|
return take(await searchWithResolvedProvider(provider2, query, options), provider2);
|
|
25642
25904
|
} catch (err) {
|
|
25643
25905
|
if (isAbortError2(err)) throw err;
|
|
25644
|
-
fallbackErrors.push(`${providerLabel(provider2)}: ${
|
|
25906
|
+
fallbackErrors.push(`${providerLabel(provider2)}: ${errorMessage28(err)}`);
|
|
25645
25907
|
return null;
|
|
25646
25908
|
}
|
|
25647
25909
|
};
|
|
@@ -25659,7 +25921,7 @@ async function search(query, options = {}) {
|
|
|
25659
25921
|
if (response) return response;
|
|
25660
25922
|
} catch (err) {
|
|
25661
25923
|
if (err instanceof CredentialResolutionError || isAbortError2(err)) throw err;
|
|
25662
|
-
fallbackErrors.push(`Exa: ${
|
|
25924
|
+
fallbackErrors.push(`Exa: ${errorMessage28(err)}`);
|
|
25663
25925
|
}
|
|
25664
25926
|
}
|
|
25665
25927
|
if (allowed.has("openai") && !triedOpenAI) {
|
|
@@ -25675,7 +25937,7 @@ async function search(query, options = {}) {
|
|
|
25675
25937
|
if (response) return response;
|
|
25676
25938
|
} catch (err) {
|
|
25677
25939
|
if (isAbortError2(err)) throw err;
|
|
25678
|
-
fallbackErrors.push(`Gemini: ${
|
|
25940
|
+
fallbackErrors.push(`Gemini: ${errorMessage28(err)}`);
|
|
25679
25941
|
}
|
|
25680
25942
|
if (firstEmpty) return firstEmpty;
|
|
25681
25943
|
if (fallbackErrors.length > 0) {
|
|
@@ -25685,11 +25947,11 @@ async function search(query, options = {}) {
|
|
|
25685
25947
|
throw new Error(
|
|
25686
25948
|
`No search provider available. Either:
|
|
25687
25949
|
1. Use /login to sign in with a Codex subscription for OpenAI web search
|
|
25688
|
-
2. Set openaiApiKey, braveApiKey, parallelApiKey, tinyfishApiKey, search1apiApiKey, searchinfinityApiKey, queritApiKey, tavilyApiKey, firecrawlBaseUrl, jinaApiKey, serpdiveApiKey, kagiApiKey, ollamaApiKey, searxngBaseUrl, perplexityApiKey, exaApiKey, geminiApiKey, bochaApiKey, or cloudflareApiKey in ${
|
|
25950
|
+
2. Set openaiApiKey, braveApiKey, parallelApiKey, tinyfishApiKey, search1apiApiKey, searchinfinityApiKey, queritApiKey, tavilyApiKey, firecrawlBaseUrl, jinaApiKey, serpdiveApiKey, kagiApiKey, ollamaApiKey, searxngBaseUrl, perplexityApiKey, exaApiKey, geminiApiKey, bochaApiKey, or cloudflareApiKey in ${CONFIG_PATH39}
|
|
25689
25951
|
3. Set OPENAI_API_KEY, BRAVE_API_KEY, PARALLEL_API_KEY, TINYFISH_API_KEY, SEARCH1API_KEY, SEARCHINFINITY_API_KEY, QUERIT_API_KEY, TAVILY_API_KEY, FIRECRAWL_BASE_URL, JINA_API_KEY, SERPDIVE_API_KEY, KAGI_API_KEY, BOCHA_API_KEY, OLLAMA_API_KEY, SEARXNG_BASE_URL, EXA_API_KEY, PERPLEXITY_API_KEY, GEMINI_API_KEY, or CLOUDFLARE_API_KEY env vars
|
|
25690
25952
|
4. Set GOOGLE_GEMINI_BASE_URL with CLOUDFLARE_API_KEY for Cloudflare AI Gateway routing
|
|
25691
25953
|
5. Sign into gemini.google.com in a supported Chromium-based browser
|
|
25692
|
-
6. Explicitly select provider: "anysearch" for anonymous AnySearch, "xcrawl" for XCrawl, "xai" for Grok, "mistral" for Mistral Conversations web search, "brightdata" with brightdataSerpZone for paid Bright Data SERP, "serpbase", "serpapi", "serper", or "serply" for Google SERP, "you" for You.com, "zai" for Z.ai GLM Coding Plan search, "valyu" for research search, "keenable" for keyless Keenable search,
|
|
25954
|
+
6. Explicitly select provider: "anysearch" for anonymous AnySearch, "xcrawl" for XCrawl, "xai" for Grok, "mistral" for Mistral Conversations web search, "brightdata" with brightdataSerpZone for paid Bright Data SERP, "serpbase", "serpapi", "serper", or "serply" for Google SERP, "you" for You.com, "zai" for Z.ai GLM Coding Plan search, "valyu" for research search, "keenable" for keyless Keenable search, "ceramic" for Ceramic search, or "deepseek" for DeepSeek search`
|
|
25693
25955
|
);
|
|
25694
25956
|
}
|
|
25695
25957
|
async function searchWithGeminiApi(query, options = {}) {
|
|
@@ -25739,13 +26001,13 @@ async function searchWithGeminiWeb(query, options = {}) {
|
|
|
25739
26001
|
const prompt = buildSearchPrompt2(query, options);
|
|
25740
26002
|
const activityId = activityMonitor.logStart({ type: "api", query });
|
|
25741
26003
|
try {
|
|
25742
|
-
const
|
|
26004
|
+
const text5 = await queryWithCookies(prompt, cookies, {
|
|
25743
26005
|
signal: options.signal,
|
|
25744
26006
|
timeoutMs: 12e4
|
|
25745
26007
|
});
|
|
25746
26008
|
activityMonitor.logComplete(activityId, 200);
|
|
25747
|
-
const results = extractSourceUrls(
|
|
25748
|
-
return { answer:
|
|
26009
|
+
const results = extractSourceUrls(text5);
|
|
26010
|
+
return { answer: text5, results };
|
|
25749
26011
|
} catch (err) {
|
|
25750
26012
|
const message = err instanceof Error ? err.message : String(err);
|
|
25751
26013
|
if (message.toLowerCase().includes("abort")) {
|
|
@@ -25926,8 +26188,8 @@ var TOOL_RUNNERS = {
|
|
|
25926
26188
|
get_search_content: (core2, args, signal) => core2.getSearchContent(args, signal),
|
|
25927
26189
|
source_check: (core2, args, signal) => core2.sourceCheck(args, signal)
|
|
25928
26190
|
};
|
|
25929
|
-
function errorResult(
|
|
25930
|
-
return { content: [{ type: "text", text:
|
|
26191
|
+
function errorResult(text5) {
|
|
26192
|
+
return { content: [{ type: "text", text: text5 }], isError: true };
|
|
25931
26193
|
}
|
|
25932
26194
|
function toCallToolResult(result) {
|
|
25933
26195
|
return { content: result.content, ...result.isError && { isError: true } };
|
|
@@ -25962,7 +26224,7 @@ function createMcpServer(core2, info, enabledTools) {
|
|
|
25962
26224
|
}
|
|
25963
26225
|
|
|
25964
26226
|
// web-tool-core.ts
|
|
25965
|
-
import { existsSync as
|
|
26227
|
+
import { existsSync as existsSync55, readFileSync as readFileSync56 } from "node:fs";
|
|
25966
26228
|
import pLimit2 from "p-limit";
|
|
25967
26229
|
|
|
25968
26230
|
// fetch-params.ts
|
|
@@ -26073,8 +26335,8 @@ function editDistanceWithin(left, right, maximum) {
|
|
|
26073
26335
|
}
|
|
26074
26336
|
return previous[right.length] <= maximum;
|
|
26075
26337
|
}
|
|
26076
|
-
function literalMatches(
|
|
26077
|
-
const haystack = caseInsensitive ?
|
|
26338
|
+
function literalMatches(text5, query, caseInsensitive) {
|
|
26339
|
+
const haystack = caseInsensitive ? text5.toLocaleLowerCase() : text5;
|
|
26078
26340
|
const needle = caseInsensitive ? query.toLocaleLowerCase() : query;
|
|
26079
26341
|
const matches = [];
|
|
26080
26342
|
for (let start = haystack.indexOf(needle); start >= 0; start = haystack.indexOf(needle, start + Math.max(needle.length, 1))) {
|
|
@@ -26082,12 +26344,12 @@ function literalMatches(text4, query, caseInsensitive) {
|
|
|
26082
26344
|
}
|
|
26083
26345
|
return matches;
|
|
26084
26346
|
}
|
|
26085
|
-
function fuzzyMatches(
|
|
26347
|
+
function fuzzyMatches(text5, query) {
|
|
26086
26348
|
const queryTokens = normalize2(query).match(/[\p{L}\p{N}]+/gu) ?? [];
|
|
26087
26349
|
if (queryTokens.length === 0) return [];
|
|
26088
26350
|
const matches = [];
|
|
26089
26351
|
const paragraphs = /[^\n]+(?:\n(?!\n)[^\n]+)*/g;
|
|
26090
|
-
for (const paragraph of
|
|
26352
|
+
for (const paragraph of text5.matchAll(paragraphs)) {
|
|
26091
26353
|
const paragraphText = paragraph[0];
|
|
26092
26354
|
if (paragraphText.trim().length === 0 || paragraph.index === void 0) continue;
|
|
26093
26355
|
const tokens = [...paragraphText.matchAll(/[\p{L}\p{N}]+/gu)];
|
|
@@ -26146,10 +26408,10 @@ function upperBound(values, target) {
|
|
|
26146
26408
|
}
|
|
26147
26409
|
return low;
|
|
26148
26410
|
}
|
|
26149
|
-
function findContent(
|
|
26411
|
+
function findContent(text5, queries, mode) {
|
|
26150
26412
|
const normalizedQueries = [...new Set(queries.map((query) => query.trim()).filter(Boolean))];
|
|
26151
26413
|
const occurrences = normalizedQueries.map((query) => {
|
|
26152
|
-
const matches2 = mode === "fuzzy" ? fuzzyMatches(
|
|
26414
|
+
const matches2 = mode === "fuzzy" ? fuzzyMatches(text5, query) : literalMatches(text5, query, mode === "case-insensitive");
|
|
26153
26415
|
return { query, matches: matches2, starts: matches2.map((match) => match.start), ends: matches2.map((match) => match.end) };
|
|
26154
26416
|
});
|
|
26155
26417
|
const matches = occurrences.flatMap((result) => result.matches);
|
|
@@ -26161,7 +26423,7 @@ function findContent(text4, queries, mode) {
|
|
|
26161
26423
|
id: `Q${index + 1}`,
|
|
26162
26424
|
order: index
|
|
26163
26425
|
}));
|
|
26164
|
-
const whitespaceRuns = [...
|
|
26426
|
+
const whitespaceRuns = [...text5.matchAll(/\s+/g)].map((run) => ({ start: run.index, end: run.index + run[0].length }));
|
|
26165
26427
|
const whitespaceStarts = whitespaceRuns.map((run) => run.start);
|
|
26166
26428
|
const whitespaceEnds = whitespaceRuns.map((run) => run.end);
|
|
26167
26429
|
const whitespaceSavings = [0];
|
|
@@ -26194,7 +26456,7 @@ function findContent(text4, queries, mode) {
|
|
|
26194
26456
|
const counts = rangeCounts(range);
|
|
26195
26457
|
if (counts.length === 0) continue;
|
|
26196
26458
|
const labelsLength = counts.reduce((total, result) => total + (overflow ? result.id.length : result.query.length + 2) + 2 + String(result.count).length, 2 * (counts.length - 1));
|
|
26197
|
-
const snippetLength = normalizedLength(range.start, range.end) + (range.start > 0 ? 1 : 0) + (range.end <
|
|
26459
|
+
const snippetLength = normalizedLength(range.start, range.end) + (range.start > 0 ? 1 : 0) + (range.end < text5.length ? 1 : 0);
|
|
26198
26460
|
length += 2 + String(index + 1).length + 2 + labelsLength + 1 + snippetLength;
|
|
26199
26461
|
returnedMatches += counts.reduce((total, result) => total + result.count, 0);
|
|
26200
26462
|
}
|
|
@@ -26211,8 +26473,8 @@ function findContent(text4, queries, mode) {
|
|
|
26211
26473
|
const contained = rangeCounts(range);
|
|
26212
26474
|
if (contained.length === 0) continue;
|
|
26213
26475
|
const prefix = range.start > 0 ? "\u2026" : "";
|
|
26214
|
-
const suffix = range.end <
|
|
26215
|
-
const snippet = `${prefix}${
|
|
26476
|
+
const suffix = range.end < text5.length ? "\u2026" : "";
|
|
26477
|
+
const snippet = `${prefix}${text5.slice(range.start, range.end).replace(/[\uD800-\uDFFF]/gu, "\uFFFD").replace(/\s+/g, " ").trim()}${suffix}`;
|
|
26216
26478
|
const counts = contained.map((result) => `${overflow ? result.id : `"${result.query}"`} \xD7${result.count}`).join(", ");
|
|
26217
26479
|
sections.push(`${index + 1}. ${counts}
|
|
26218
26480
|
${snippet}`);
|
|
@@ -26223,18 +26485,18 @@ ${snippet}`);
|
|
|
26223
26485
|
if (returnedMatches < matches.length) sections.push(`Showing ${returnedMatches} of ${matches.length} matches.`);
|
|
26224
26486
|
return { text: sections.join("\n\n"), matchCount: matches.length, returnedMatches, queryResults };
|
|
26225
26487
|
}
|
|
26226
|
-
const fullRanges = contextRanges(
|
|
26488
|
+
const fullRanges = contextRanges(text5.length, matches);
|
|
26227
26489
|
const full = measure(fullRanges);
|
|
26228
26490
|
if (full.returnedMatches === matches.length && full.length <= MAX_OUTPUT_CHARS) return formatRanges(fullRanges);
|
|
26229
26491
|
let ranges = [];
|
|
26230
26492
|
let omitted = matchingQueries.map((result) => result.id);
|
|
26231
26493
|
if (measure(ranges, true, omitted).length > MAX_OUTPUT_CHARS) {
|
|
26232
|
-
const
|
|
26494
|
+
const text6 = `${heading}
|
|
26233
26495
|
|
|
26234
26496
|
Unable to format bounded excerpts: query metadata exceeds ${MAX_OUTPUT_CHARS} characters.
|
|
26235
26497
|
|
|
26236
26498
|
Showing 0 of ${matches.length} matches.`;
|
|
26237
|
-
return { text:
|
|
26499
|
+
return { text: text6, matchCount: matches.length, returnedMatches: 0, queryResults };
|
|
26238
26500
|
}
|
|
26239
26501
|
const witnesses = [];
|
|
26240
26502
|
for (const { id, matches: queryMatches } of matchingQueries) {
|
|
@@ -26260,7 +26522,7 @@ Showing 0 of ${matches.length} matches.`;
|
|
|
26260
26522
|
for (const witness of witnesses) {
|
|
26261
26523
|
const proposed = mergeRanges([...ranges, {
|
|
26262
26524
|
start: Math.max(0, witness.start - CONTEXT_CHARS),
|
|
26263
|
-
end: Math.min(
|
|
26525
|
+
end: Math.min(text5.length, witness.end + CONTEXT_CHARS)
|
|
26264
26526
|
}]);
|
|
26265
26527
|
if (measure(proposed, true, omitted).length <= MAX_OUTPUT_CHARS) ranges = proposed;
|
|
26266
26528
|
}
|
|
@@ -26273,7 +26535,7 @@ Showing 0 of ${matches.length} matches.`;
|
|
|
26273
26535
|
init_utils();
|
|
26274
26536
|
|
|
26275
26537
|
// storage.ts
|
|
26276
|
-
import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync as
|
|
26538
|
+
import { closeSync, constants, fchmodSync, fstatSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync as readFileSync44, readdirSync as readdirSync2, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
26277
26539
|
init_utils();
|
|
26278
26540
|
import { join as join4 } from "node:path";
|
|
26279
26541
|
var CACHE_TTL_MS = 60 * 60 * 1e3;
|
|
@@ -26434,7 +26696,7 @@ function readCachedFetchData(data) {
|
|
|
26434
26696
|
const opened = openRegularFile(path);
|
|
26435
26697
|
fd = opened.fd;
|
|
26436
26698
|
enforceMode(fd, 384);
|
|
26437
|
-
const parsed = JSON.parse(
|
|
26699
|
+
const parsed = JSON.parse(readFileSync44(fd, "utf8"));
|
|
26438
26700
|
if (!isValidStoredData(parsed) || parsed.type !== "fetch" || parsed.id !== data.id || !isInlineFetchData(parsed)) {
|
|
26439
26701
|
return unavailableFetchData(data, "Cached fetched content is invalid");
|
|
26440
26702
|
}
|
|
@@ -26526,8 +26788,8 @@ function classifySource(url) {
|
|
|
26526
26788
|
if (BLOG_HOSTS.test(host) || BLOG_PATHS.test(path)) return "blog";
|
|
26527
26789
|
return "unknown";
|
|
26528
26790
|
}
|
|
26529
|
-
function hashContent(
|
|
26530
|
-
return `sha256:${createHash("sha256").update(
|
|
26791
|
+
function hashContent(text5) {
|
|
26792
|
+
return `sha256:${createHash("sha256").update(text5, "utf8").digest("hex")}`;
|
|
26531
26793
|
}
|
|
26532
26794
|
function tokenize(value) {
|
|
26533
26795
|
return [...new Set(value.toLowerCase().split(/[^a-z0-9]+/).filter((term) => term.length > 3))];
|
|
@@ -26537,10 +26799,10 @@ function extractRelevantSpans(content, hint) {
|
|
|
26537
26799
|
const sentencePattern = /[^.!?]+(?:[.!?]+(?=\s|$)|$)/g;
|
|
26538
26800
|
for (const match of content.matchAll(sentencePattern)) {
|
|
26539
26801
|
const raw = match[0];
|
|
26540
|
-
const
|
|
26541
|
-
if (
|
|
26542
|
-
const start = (match.index ?? 0) + raw.indexOf(
|
|
26543
|
-
sentences.push({ text:
|
|
26802
|
+
const text5 = raw.trim();
|
|
26803
|
+
if (text5.length > 0 && text5.length <= 400) {
|
|
26804
|
+
const start = (match.index ?? 0) + raw.indexOf(text5);
|
|
26805
|
+
sentences.push({ text: text5, start, end: start + text5.length });
|
|
26544
26806
|
}
|
|
26545
26807
|
}
|
|
26546
26808
|
const terms = tokenize(hint);
|
|
@@ -26663,9 +26925,9 @@ function parseConfigRoot(raw) {
|
|
|
26663
26925
|
}
|
|
26664
26926
|
return parsed;
|
|
26665
26927
|
}
|
|
26666
|
-
function
|
|
26667
|
-
if (!
|
|
26668
|
-
return parseConfigRoot(
|
|
26928
|
+
function loadConfig41() {
|
|
26929
|
+
if (!existsSync55(WEB_SEARCH_CONFIG_PATH4)) return {};
|
|
26930
|
+
return parseConfigRoot(readFileSync56(WEB_SEARCH_CONFIG_PATH4, "utf-8"));
|
|
26669
26931
|
}
|
|
26670
26932
|
var DEFAULT_TOOL_NAMES = {
|
|
26671
26933
|
webSearch: "web_search",
|
|
@@ -26716,7 +26978,7 @@ function resolveRequestedProvider(requested) {
|
|
|
26716
26978
|
assertSearchProviderSelectionAllowed(normalizedRequested, "Requested provider");
|
|
26717
26979
|
return normalizedRequested;
|
|
26718
26980
|
}
|
|
26719
|
-
const config =
|
|
26981
|
+
const config = loadConfig41();
|
|
26720
26982
|
const provider = normalizeProviderInput(config.searchProvider ?? config.provider, `provider in ${WEB_SEARCH_CONFIG_PATH4}`) ?? "auto";
|
|
26721
26983
|
assertSearchProviderSelectionAllowed(provider, `configured provider in ${WEB_SEARCH_CONFIG_PATH4}`);
|
|
26722
26984
|
return provider;
|
|
@@ -26779,7 +27041,7 @@ function isAbortError6(err) {
|
|
|
26779
27041
|
var DEFAULT_MAX_INLINE_CONTENT_CHARS = 3e4;
|
|
26780
27042
|
var MIN_INLINE_CONTENT_CHARS = 1e3;
|
|
26781
27043
|
var MAX_INLINE_CONTENT_CHARS = 2e5;
|
|
26782
|
-
function getMaxInlineContentChars(config =
|
|
27044
|
+
function getMaxInlineContentChars(config = loadConfig41()) {
|
|
26783
27045
|
const value = config.maxInlineContentChars;
|
|
26784
27046
|
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value) || value < MIN_INLINE_CONTENT_CHARS) {
|
|
26785
27047
|
return DEFAULT_MAX_INLINE_CONTENT_CHARS;
|
|
@@ -26815,14 +27077,14 @@ function initialContentSlice(content, maxChars) {
|
|
|
26815
27077
|
const lineBreak = content.lastIndexOf("\n", endOffset);
|
|
26816
27078
|
if (lineBreak >= Math.floor(maxChars * 0.8)) endOffset = lineBreak + 1;
|
|
26817
27079
|
}
|
|
26818
|
-
const
|
|
27080
|
+
const text5 = content.slice(0, endOffset);
|
|
26819
27081
|
return {
|
|
26820
|
-
text:
|
|
27082
|
+
text: text5,
|
|
26821
27083
|
endOffset,
|
|
26822
27084
|
totalBytes: Buffer.byteLength(content),
|
|
26823
27085
|
totalLines: content.length === 0 ? 0 : content.split("\n").length,
|
|
26824
|
-
shownBytes: Buffer.byteLength(
|
|
26825
|
-
shownLines:
|
|
27086
|
+
shownBytes: Buffer.byteLength(text5),
|
|
27087
|
+
shownLines: text5.length === 0 ? 0 : text5.split("\n").length
|
|
26826
27088
|
};
|
|
26827
27089
|
}
|
|
26828
27090
|
function normalizeFindQueries(value) {
|
|
@@ -26941,23 +27203,23 @@ ${r.snippet}` : ""}
|
|
|
26941
27203
|
}
|
|
26942
27204
|
return output;
|
|
26943
27205
|
}
|
|
26944
|
-
function boundSearchPresentation(
|
|
26945
|
-
const fullText = `${
|
|
27206
|
+
function boundSearchPresentation(text5, guidance, truncationGuidance, maxChars) {
|
|
27207
|
+
const fullText = `${text5}${guidance}`;
|
|
26946
27208
|
if (fullText.length <= maxChars) {
|
|
26947
|
-
return { text: fullText, truncated: false, originalChars:
|
|
27209
|
+
return { text: fullText, truncated: false, originalChars: text5.length, returnedChars: text5.length, omittedChars: 0 };
|
|
26948
27210
|
}
|
|
26949
27211
|
const marker = `
|
|
26950
27212
|
|
|
26951
27213
|
---
|
|
26952
27214
|
[Output truncated.]${truncationGuidance}`;
|
|
26953
27215
|
const prefixLength = maxChars - marker.length;
|
|
26954
|
-
const bounded = `${
|
|
27216
|
+
const bounded = `${text5.slice(0, prefixLength)}${marker}`;
|
|
26955
27217
|
return {
|
|
26956
27218
|
text: bounded,
|
|
26957
27219
|
truncated: true,
|
|
26958
|
-
originalChars:
|
|
27220
|
+
originalChars: text5.length,
|
|
26959
27221
|
returnedChars: prefixLength,
|
|
26960
|
-
omittedChars:
|
|
27222
|
+
omittedChars: text5.length - prefixLength
|
|
26961
27223
|
};
|
|
26962
27224
|
}
|
|
26963
27225
|
function registeredFetchToolNames(settings2) {
|
|
@@ -27521,9 +27783,9 @@ ${retrievalHint}` : "\n---\nContent retrieval is not registered." : "\n---\nAuth
|
|
|
27521
27783
|
if (params.findText !== void 0) {
|
|
27522
27784
|
try {
|
|
27523
27785
|
const found = findContent(serialized, normalizeFindQueries(params.findText), params.findMode ?? "case-insensitive");
|
|
27524
|
-
const { text:
|
|
27786
|
+
const { text: text6, ...findDetails } = found;
|
|
27525
27787
|
return {
|
|
27526
|
-
content: [{ type: "text", text:
|
|
27788
|
+
content: [{ type: "text", text: text6 }],
|
|
27527
27789
|
details: { responseId: artifact.id, type: "research", contentLength: serialized.length, findMode: params.findMode ?? "case-insensitive", ...findDetails }
|
|
27528
27790
|
};
|
|
27529
27791
|
} catch (err) {
|
|
@@ -27554,13 +27816,13 @@ ${retrievalHint}` : "\n---\nContent retrieval is not registered." : "\n---\nAuth
|
|
|
27554
27816
|
details: { error: "Offset out of range", offset, contentLength: serialized.length }
|
|
27555
27817
|
};
|
|
27556
27818
|
}
|
|
27557
|
-
const { endOffset, text:
|
|
27819
|
+
const { endOffset, text: text5 } = sliceWithContinuation(serialized, offset, limit, maxInlineContentChars, (end) => `
|
|
27558
27820
|
|
|
27559
27821
|
---
|
|
27560
27822
|
Showing chars ${offset}-${end} of ${serialized.length}. Use ${toolNames.getSearchContent}({ responseId: "${artifact.id}", offset: ${end}, limit: ${limit} }) for the next slice.`);
|
|
27561
27823
|
const hasMore = endOffset < serialized.length;
|
|
27562
27824
|
return {
|
|
27563
|
-
content: [{ type: "text", text:
|
|
27825
|
+
content: [{ type: "text", text: text5 }],
|
|
27564
27826
|
details: { responseId: artifact.id, type: "research", contentLength: serialized.length, offset, limit, returnedChars: endOffset - offset, nextOffset: hasMore ? endOffset : null, truncated: hasMore }
|
|
27565
27827
|
};
|
|
27566
27828
|
}
|
|
@@ -27601,9 +27863,9 @@ Showing chars ${offset}-${end} of ${serialized.length}. Use ${toolNames.getSearc
|
|
|
27601
27863
|
if (params.findText !== void 0) {
|
|
27602
27864
|
try {
|
|
27603
27865
|
const found = findContent(fullResults, normalizeFindQueries(params.findText), params.findMode ?? "case-insensitive");
|
|
27604
|
-
const { text:
|
|
27866
|
+
const { text: text6, ...findDetails } = found;
|
|
27605
27867
|
return {
|
|
27606
|
-
content: [{ type: "text", text:
|
|
27868
|
+
content: [{ type: "text", text: text6 }],
|
|
27607
27869
|
details: { responseId: params.responseId, query: queryData.query, resultCount: queryData.results.length, contentLength: fullResults.length, findMode: params.findMode ?? "case-insensitive", ...findDetails }
|
|
27608
27870
|
};
|
|
27609
27871
|
} catch (err) {
|
|
@@ -27635,14 +27897,14 @@ Showing chars ${offset}-${end} of ${serialized.length}. Use ${toolNames.getSearc
|
|
|
27635
27897
|
};
|
|
27636
27898
|
}
|
|
27637
27899
|
const queryIndex = data.queries.indexOf(queryData);
|
|
27638
|
-
const { endOffset, text:
|
|
27900
|
+
const { endOffset, text: text5 } = sliceWithContinuation(fullResults, offset, limit, maxInlineContentChars, (end) => `
|
|
27639
27901
|
|
|
27640
27902
|
---
|
|
27641
27903
|
Showing chars ${offset}-${end} of ${fullResults.length}. Use ${toolNames.getSearchContent}({ responseId: "${params.responseId}", queryIndex: ${queryIndex}, offset: ${end}, limit: ${limit} }) for the next slice.`);
|
|
27642
27904
|
const returnedChars = endOffset - offset;
|
|
27643
27905
|
const hasMore = endOffset < fullResults.length;
|
|
27644
27906
|
return {
|
|
27645
|
-
content: [{ type: "text", text:
|
|
27907
|
+
content: [{ type: "text", text: text5 }],
|
|
27646
27908
|
details: {
|
|
27647
27909
|
responseId: params.responseId,
|
|
27648
27910
|
query: queryData.query,
|
|
@@ -27703,11 +27965,11 @@ Use one of the available indexes.` }],
|
|
|
27703
27965
|
if (params.findText !== void 0) {
|
|
27704
27966
|
try {
|
|
27705
27967
|
const found = findContent(urlData.content, normalizeFindQueries(params.findText), params.findMode ?? "case-insensitive");
|
|
27706
|
-
const { text:
|
|
27968
|
+
const { text: text6, ...findDetails } = found;
|
|
27707
27969
|
return {
|
|
27708
27970
|
content: [{ type: "text", text: `# ${urlData.title || urlData.url}
|
|
27709
27971
|
|
|
27710
|
-
${
|
|
27972
|
+
${text6}` }],
|
|
27711
27973
|
details: { url: urlData.url, title: urlData.title, contentLength: urlData.content.length, findMode: params.findMode ?? "case-insensitive", ...findDetails }
|
|
27712
27974
|
};
|
|
27713
27975
|
} catch (err) {
|
|
@@ -27741,20 +28003,20 @@ ${text5}` }],
|
|
|
27741
28003
|
const endOffset = pageEnd(urlData.content, offset, Math.min(offset + limit, urlData.content.length));
|
|
27742
28004
|
const contentSlice = urlData.content.slice(offset, endOffset);
|
|
27743
28005
|
const hasMore = endOffset < urlData.content.length;
|
|
27744
|
-
let
|
|
28006
|
+
let text5 = `# ${urlData.title || urlData.url}
|
|
27745
28007
|
|
|
27746
28008
|
${contentSlice}`;
|
|
27747
28009
|
if (hasMore || offset > 0) {
|
|
27748
|
-
|
|
28010
|
+
text5 += `
|
|
27749
28011
|
|
|
27750
28012
|
---
|
|
27751
28013
|
Showing chars ${offset}-${endOffset} of ${urlData.content.length}.`;
|
|
27752
28014
|
if (hasMore) {
|
|
27753
|
-
|
|
28015
|
+
text5 += ` Use ${toolNames.getSearchContent}({ responseId: "${params.responseId}", urlIndex: ${selectedUrlIndex}, offset: ${endOffset}, limit: ${limit} }) for the next slice.`;
|
|
27754
28016
|
}
|
|
27755
28017
|
}
|
|
27756
28018
|
return {
|
|
27757
|
-
content: [{ type: "text", text:
|
|
28019
|
+
content: [{ type: "text", text: text5 }],
|
|
27758
28020
|
details: {
|
|
27759
28021
|
url: urlData.url,
|
|
27760
28022
|
title: urlData.title,
|
|
@@ -27824,7 +28086,7 @@ function standaloneFetchRejection(params, fetchModes) {
|
|
|
27824
28086
|
return void 0;
|
|
27825
28087
|
}
|
|
27826
28088
|
function createStandaloneWebToolCore() {
|
|
27827
|
-
const config =
|
|
28089
|
+
const config = loadConfig41();
|
|
27828
28090
|
const settings2 = {
|
|
27829
28091
|
toolNames: { ...DEFAULT_TOOL_NAMES },
|
|
27830
28092
|
enabledTools: {
|