@tool-bridge/server 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{airtable-S3T4TAN7.js → airtable-NOSOMOVB.js} +106 -114
- package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-BHIJ4LW5.js} +25 -16
- package/dist/{amap-LGVGNPML.js → amap-QRLP4TWZ.js} +114 -123
- package/dist/{anthropic-27RFZO35.js → anthropic-IEOI36EV.js} +34 -56
- package/dist/{apify-6WLYAIAS.js → apify-3CCYTQVK.js} +31 -49
- package/dist/{brave_search-K2SVJ66F.js → brave_search-PZNYDQG7.js} +52 -77
- package/dist/chunk-JXHMDBAY.js +45 -0
- package/dist/chunk-LMLX3DJF.js +50 -0
- package/dist/{chunk-YB2FLNWI.js → chunk-RVWZN3CI.js} +2103 -1775
- package/dist/{chunk-BB6ZLMTU.js → chunk-TLNUIPFZ.js} +492 -300
- package/dist/chunk-U5UHT7CX.js +977 -0
- package/dist/chunk-U67V476Y.js +35 -0
- package/dist/chunk-WW2IMPQK.js +283 -0
- package/dist/{chunk-VK3V2WTY.js → chunk-YASUMV2K.js} +4 -6
- package/dist/{circleci-WV3ITU7Q.js → circleci-VSJ4O5FC.js} +36 -55
- package/dist/{clerk-NFQEFKS4.js → clerk-CC2JZBZI.js} +60 -80
- package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-PJEBSEYQ.js} +90 -113
- package/dist/{cohere-5KEW7LWT.js → cohere-KBACYSPF.js} +33 -49
- package/dist/{confluence-SZE63S46.js → confluence-2PX3O7G5.js} +79 -115
- package/dist/{convertapi-QPG2JC5K.js → convertapi-BVOTD2PJ.js} +13 -16
- package/dist/{currencyapi-UO2APQRY.js → currencyapi-6ZQ2VNQ7.js} +30 -53
- package/dist/{deepseek-LJELIMM3.js → deepseek-MB3WVVTB.js} +30 -38
- package/dist/{docker_hub-2MFXSBOF.js → docker_hub-7CLQL2IJ.js} +141 -157
- package/dist/{dropbox-GQYNTTVA.js → dropbox-VFYDVUNK.js} +134 -141
- package/dist/{dub-KI2LHXST.js → dub-QN3EETJY.js} +61 -93
- package/dist/{e2b-WO6ISY3C.js → e2b-NKC3Y776.js} +39 -69
- package/dist/{exa-IZ7B3BPT.js → exa-KKZ6F25K.js} +49 -77
- package/dist/{fal_ai-LTMF36GJ.js → fal_ai-25LYJD2O.js} +37 -44
- package/dist/{feishu-WM7SLSFD.js → feishu-NRT55B3Q.js} +4 -6
- package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-3W3XXUG4.js} +4 -5
- package/dist/{figma-2Z274VQZ.js → figma-4FLP35TC.js} +56 -81
- package/dist/{firehydrant-IFI4R65V.js → firehydrant-BLXPLZ3X.js} +40 -53
- package/dist/{fixer-BCCZEB3D.js → fixer-4OR62TGE.js} +31 -43
- package/dist/{fly-755FXYB5.js → fly-MYCKOZZK.js} +50 -66
- package/dist/{front-4FZKKXXK.js → front-3DFYVMF3.js} +43 -66
- package/dist/{geocodio-WYKDJ3DP.js → geocodio-CXMD6VKA.js} +37 -63
- package/dist/{ghost-5BNQTCOH.js → ghost-4UUE737W.js} +51 -57
- package/dist/{github-ULELF5VX.js → github-WFS2ON2N.js} +48 -41
- package/dist/{gmail-G34WT64J.js → gmail-KW7FXA7A.js} +26 -36
- package/dist/{googlecalendar-BQU255SC.js → googlecalendar-AMH5JQMC.js} +57 -78
- package/dist/{googledocs-HPCNQXYJ.js → googledocs-R5VA6CKD.js} +14 -22
- package/dist/{grafana-VOV24FIC.js → grafana-IT6DWIVB.js} +95 -122
- package/dist/{graphhopper-D5RXW6AP.js → graphhopper-TYFDJZWC.js} +32 -46
- package/dist/index.d.ts +57 -50
- package/dist/index.js +4 -3
- package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-GJ4HXVXO.js} +35 -42
- package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-OAGR6PRF.js} +40 -60
- package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-BCKAMDGL.js} +30 -42
- package/dist/{jina_ai-E6UXFV2P.js → jina_ai-N3NXRVIZ.js} +32 -58
- package/dist/{jira-ZDSXGQ6W.js → jira-CHLBKWLO.js} +116 -126
- package/dist/{langsmith-TIFJRREW.js → langsmith-OIKOTPY3.js} +101 -121
- package/dist/{lemlist-DASEMJMA.js → lemlist-VAKYPKS3.js} +57 -68
- package/dist/{linear-KE6UP4SP.js → linear-Q6QTPJ5R.js} +109 -118
- package/dist/{logsnag-IMNDN4R5.js → logsnag-SQOQBTES.js} +31 -48
- package/dist/main.js +103 -102
- package/dist/{mattermost-HHHMUXQA.js → mattermost-G2KBEICM.js} +45 -62
- package/dist/{mem0-D2FGGOIY.js → mem0-D2FPLYDX.js} +72 -98
- package/dist/{memos-4OVIGFPH.js → memos-76PTWV5V.js} +68 -122
- package/dist/{metabase-33WCX5YD.js → metabase-TWSIDVBM.js} +47 -60
- package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-TP7TQUEJ.js} +35 -40
- package/dist/{mother_duck-M6VWS2VH.js → mother_duck-UXY5THYU.js} +42 -62
- package/dist/{ngrok-Z2PKQBHH.js → ngrok-RZW2ISJK.js} +42 -58
- package/dist/{notes-SS4RPC4K.js → notes-B2I6FWK2.js} +3 -5
- package/dist/{notion-FJCNQ6I7.js → notion-QOKRUE6M.js} +83 -97
- package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-ODLFWEJ7.js} +35 -39
- package/dist/{openai-JODZ4GKT.js → openai-ZPBPPPGT.js} +51 -55
- package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-EOI5UJKT.js} +61 -79
- package/dist/{openrouter-Q5XXEJZ7.js → openrouter-BUWLF3BG.js} +41 -55
- package/dist/{outline-RT2EHJ2X.js → outline-NXS3QRXO.js} +89 -104
- package/dist/{paddle-OF2V7GAC.js → paddle-T4MSKQ76.js} +34 -49
- package/dist/{perplexity-LNZEWLHG.js → perplexity-WW5N2LW7.js} +33 -50
- package/dist/{pinecone-JSJIXZYN.js → pinecone-RY5AZPQM.js} +65 -91
- package/dist/{pipedrive-D4CKVUXR.js → pipedrive-OHYQNZTU.js} +37 -59
- package/dist/{polar-M7ZYP6UR.js → polar-XZIAHXS5.js} +43 -53
- package/dist/{posthog-YV7CZOH4.js → posthog-DTPTWORY.js} +58 -77
- package/dist/{postmark-KYHLECRG.js → postmark-F4UCQKC3.js} +52 -71
- package/dist/{prerender-HCMHBKV2.js → prerender-P3Y2MLIC.js} +32 -50
- package/dist/{pubmed-WYVLCCN3.js → pubmed-RHU3GXFB.js} +28 -60
- package/dist/{railway-TWIRD5KR.js → railway-VB6SRLI6.js} +32 -39
- package/dist/{readwise-UZ467IQ7.js → readwise-DIMSKJZR.js} +62 -78
- package/dist/{render-MECUC5CC.js → render-XCCDCEEK.js} +48 -64
- package/dist/{replicate-A5MEK3SW.js → replicate-IUEOQ4JC.js} +41 -58
- package/dist/{resend-BC6EAWJQ.js → resend-N5MJZH5E.js} +27 -37
- package/dist/{rootly-ZM3QDUIS.js → rootly-25T4NBTU.js} +64 -76
- package/dist/{scrapfly-WAML42QJ.js → scrapfly-PK4XFXUA.js} +45 -51
- package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-ITPBMWQU.js} +25 -33
- package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-5U6ZYPKR.js} +29 -47
- package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-BJGCI2MU.js} +37 -56
- package/dist/{sentry-OKBPSTDM.js → sentry-63IC263P.js} +66 -85
- package/dist/{shodan-PPC6DYU4.js → shodan-2WBIFHFN.js} +42 -53
- package/dist/{shopify-EWGUHBXO.js → shopify-XLLJRAGM.js} +32 -49
- package/dist/{stripe-6RPDPC5W.js → stripe-WLVCY3UN.js} +4 -5
- package/dist/{supabase-SK7DQ42N.js → supabase-BKNZ35ER.js} +69 -88
- package/dist/{tavily-YCG5VQMH.js → tavily-YFSDEUTL.js} +37 -62
- package/dist/{telegram-2OES5FYB.js → telegram-FC35W74G.js} +168 -177
- package/dist/{telnyx-POOSBBR4.js → telnyx-MI32XZUG.js} +30 -50
- package/dist/{todoist-M7YD6YSS.js → todoist-4ZFJKZC6.js} +77 -89
- package/dist/{trello-IS6V5W3E.js → trello-UOGFNMK4.js} +108 -122
- package/dist/{turso-RCFHUFVH.js → turso-YTSTW3ZS.js} +52 -64
- package/dist/{twilio-OS2RXFGO.js → twilio-XAJDFUQH.js} +48 -55
- package/dist/{umami-PQ2SJ2LN.js → umami-ZVIUBPAI.js} +49 -69
- package/dist/{unsplash-C6BPZO4E.js → unsplash-IU3PLDNS.js} +35 -52
- package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-3EYJW7SY.js} +28 -40
- package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-PJG2ASRU.js} +11 -12
- package/dist/{v2ex-R4JWTEHN.js → v2ex-KFQWWGFC.js} +36 -61
- package/dist/{vercel-FZVYUOQD.js → vercel-I2ZDOQRL.js} +124 -150
- package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
- package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-BNXOJMB6.js} +26 -34
- package/dist/{wordpress-XRWGO6LG.js → wordpress-36D7BSMP.js} +87 -104
- package/dist/{workos-WR4NKOYL.js → workos-6X4JJRRC.js} +37 -56
- package/dist/{zhihu-BKZIB3WA.js → zhihu-CIXKCHIU.js} +35 -57
- package/package.json +5 -5
- package/dist/chunk-2O27H4Y2.js +0 -183
- package/dist/chunk-GKX72JMJ.js +0 -378
- package/dist/chunk-MLKGABMK.js +0 -9
|
@@ -1,25 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-WW2IMPQK.js";
|
|
4
|
+
import "./chunk-JXHMDBAY.js";
|
|
1
5
|
import {
|
|
2
6
|
createProviderPlugin,
|
|
3
7
|
requireApiKey,
|
|
4
8
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
9
|
+
} from "./chunk-YASUMV2K.js";
|
|
10
|
+
import "./chunk-U5UHT7CX.js";
|
|
10
11
|
import {
|
|
11
12
|
TBError,
|
|
12
13
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
14
|
+
} from "./chunk-RVWZN3CI.js";
|
|
15
|
+
import "./chunk-U67V476Y.js";
|
|
15
16
|
|
|
16
17
|
// ../plugins/src/scrapfly/api.ts
|
|
17
18
|
var SERVICE = "scrapfly";
|
|
18
19
|
var API_BASE = "https://api.scrapfly.io";
|
|
19
|
-
var
|
|
20
|
-
var
|
|
20
|
+
var SCRAPE_PATH = "/scrape";
|
|
21
|
+
var METRICS_PATH = "/scrape/monitoring/metrics";
|
|
21
22
|
var REQUEST_TIMEOUT_MS = 16e4;
|
|
22
23
|
var MAX_ERROR_MESSAGE_LENGTH = 300;
|
|
24
|
+
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
23
25
|
function looksLikeHtml(value) {
|
|
24
26
|
return /^<!doctype html/i.test(value) || /^<html[\s>]/i.test(value);
|
|
25
27
|
}
|
|
@@ -42,57 +44,49 @@ function errorMessage(body, headers, status) {
|
|
|
42
44
|
}
|
|
43
45
|
return headers.get("x-scrapfly-reject-code") ?? `Scrapfly \u8FD4\u56DE HTTP ${status}`;
|
|
44
46
|
}
|
|
45
|
-
function
|
|
46
|
-
const
|
|
47
|
-
url.searchParams.set("key", apiKey);
|
|
47
|
+
function requestQuery(apiKey, query) {
|
|
48
|
+
const result = [["key", apiKey]];
|
|
48
49
|
for (const [key, value] of Object.entries(query)) {
|
|
49
|
-
if (value === void 0) continue;
|
|
50
50
|
if (Array.isArray(value)) {
|
|
51
|
-
for (const item of value)
|
|
51
|
+
for (const item of value) result.push([`${key}[]`, item]);
|
|
52
52
|
continue;
|
|
53
53
|
}
|
|
54
|
-
|
|
54
|
+
result.push([key, value]);
|
|
55
55
|
}
|
|
56
|
-
return
|
|
56
|
+
return result;
|
|
57
57
|
}
|
|
58
|
-
async function request(ctx,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
58
|
+
async function request(ctx, path, query, init) {
|
|
59
|
+
return await http.request({
|
|
60
|
+
path,
|
|
61
|
+
query: requestQuery(requireApiKey(ctx, SERVICE), query),
|
|
62
|
+
method: init.method ?? "GET",
|
|
63
|
+
headers: { accept: "application/json", ...init.headers },
|
|
64
|
+
...init.body === void 0 ? {} : { body: init.body },
|
|
65
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
66
|
+
invalidJson: "text",
|
|
67
|
+
mapError: ({ bodyKind, data, headers, status }) => upstreamError(
|
|
68
|
+
status,
|
|
69
|
+
errorMessage(
|
|
70
|
+
bodyKind === "empty" ? "" : bodyKind === "json" ? JSON.stringify(data) : String(data),
|
|
71
|
+
headers,
|
|
72
|
+
status
|
|
73
|
+
)
|
|
74
|
+
),
|
|
75
|
+
mapTransportError: ({ kind, message }) => kind === "timeout" ? upstreamError(504, `Scrapfly ${REQUEST_TIMEOUT_MS / 1e3}s \u5185\u6CA1\u6709\u8FD4\u56DE`) : new TBError(
|
|
73
76
|
"unavailable",
|
|
74
|
-
|
|
77
|
+
message === void 0 ? "Scrapfly \u8BF7\u6C42\u5931\u8D25" : `Scrapfly \u8BF7\u6C42\u5931\u8D25: ${message}`,
|
|
75
78
|
{ retryable: true }
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
if (!response.ok) {
|
|
79
|
-
throw upstreamError(
|
|
80
|
-
response.status,
|
|
81
|
-
errorMessage(await response.text().catch(() => ""), response.headers, response.status)
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
return response;
|
|
79
|
+
)
|
|
80
|
+
});
|
|
85
81
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (body.trim() === "") {
|
|
82
|
+
function readJson(response, label) {
|
|
83
|
+
if (response.bodyKind === "empty") {
|
|
89
84
|
throw new TBError("unavailable", `${label}\u8FD4\u56DE\u4E86\u7A7A\u54CD\u5E94\u4F53`, { retryable: true });
|
|
90
85
|
}
|
|
91
|
-
|
|
92
|
-
return JSON.parse(body);
|
|
93
|
-
} catch {
|
|
86
|
+
if (response.bodyKind !== "json") {
|
|
94
87
|
throw new TBError("unavailable", `${label}\u8FD4\u56DE\u4E86\u975E\u6CD5 JSON`, { retryable: true });
|
|
95
88
|
}
|
|
89
|
+
return response.data;
|
|
96
90
|
}
|
|
97
91
|
function requireRecord(payload, label) {
|
|
98
92
|
if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
|
|
@@ -135,7 +129,7 @@ async function scrape(input, ctx) {
|
|
|
135
129
|
const tags = input.tags?.map((tag) => tag.trim()).filter((tag) => tag !== "");
|
|
136
130
|
const response = await request(
|
|
137
131
|
ctx,
|
|
138
|
-
|
|
132
|
+
SCRAPE_PATH,
|
|
139
133
|
{
|
|
140
134
|
url: input.url,
|
|
141
135
|
country: input.country,
|
|
@@ -162,7 +156,7 @@ async function scrape(input, ctx) {
|
|
|
162
156
|
headers: input.content_type === void 0 ? void 0 : { "content-type": input.content_type }
|
|
163
157
|
}
|
|
164
158
|
);
|
|
165
|
-
const payload = requireRecord(
|
|
159
|
+
const payload = requireRecord(readJson(response, "Scrapfly \u6293\u53D6\u54CD\u5E94"), "Scrapfly \u6293\u53D6\u54CD\u5E94");
|
|
166
160
|
return {
|
|
167
161
|
result: requireRecord(payload.result, "Scrapfly \u6293\u53D6\u7ED3\u679C"),
|
|
168
162
|
config: toRecord(payload.config),
|
|
@@ -174,7 +168,7 @@ async function scrape(input, ctx) {
|
|
|
174
168
|
async function getMonitoringMetrics(input, ctx) {
|
|
175
169
|
const response = await request(
|
|
176
170
|
ctx,
|
|
177
|
-
|
|
171
|
+
METRICS_PATH,
|
|
178
172
|
{
|
|
179
173
|
aggregation: input.aggregation,
|
|
180
174
|
period: input.period,
|
|
@@ -186,7 +180,7 @@ async function getMonitoringMetrics(input, ctx) {
|
|
|
186
180
|
);
|
|
187
181
|
return {
|
|
188
182
|
metrics: requireRecord(
|
|
189
|
-
|
|
183
|
+
readJson(response, "Scrapfly \u76D1\u63A7\u6307\u6807\u54CD\u5E94"),
|
|
190
184
|
"Scrapfly \u76D1\u63A7\u6307\u6807\u54CD\u5E94"
|
|
191
185
|
),
|
|
192
186
|
metadata: responseMetadata(response),
|
|
@@ -1,28 +1,25 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-WW2IMPQK.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
compactDefined
|
|
7
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
8
|
import {
|
|
2
9
|
createProviderPlugin,
|
|
3
10
|
requireApiKey,
|
|
4
11
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
12
|
+
} from "./chunk-YASUMV2K.js";
|
|
13
|
+
import "./chunk-U5UHT7CX.js";
|
|
10
14
|
import {
|
|
11
15
|
external_exports
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-RVWZN3CI.js";
|
|
17
|
+
import "./chunk-U67V476Y.js";
|
|
14
18
|
|
|
15
19
|
// ../plugins/src/scrapingbee/api.ts
|
|
16
20
|
var SERVICE = "scrapingbee";
|
|
17
21
|
var API_BASE = "https://app.scrapingbee.com/api/v1/";
|
|
18
|
-
|
|
19
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
20
|
-
}
|
|
21
|
-
function compact(input) {
|
|
22
|
-
return Object.fromEntries(
|
|
23
|
-
Object.entries(input).filter((entry) => entry[1] !== void 0)
|
|
24
|
-
);
|
|
25
|
-
}
|
|
22
|
+
var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
|
|
26
23
|
function str(value) {
|
|
27
24
|
return value === void 0 || value === "" ? void 0 : value;
|
|
28
25
|
}
|
|
@@ -32,19 +29,11 @@ function bool(value) {
|
|
|
32
29
|
function int(value) {
|
|
33
30
|
return value === void 0 ? void 0 : String(value);
|
|
34
31
|
}
|
|
35
|
-
function buildUrl(path, apiKey, params) {
|
|
36
|
-
const url = new URL(path, API_BASE);
|
|
37
|
-
url.searchParams.set("api_key", apiKey);
|
|
38
|
-
for (const [key, value] of Object.entries(params)) {
|
|
39
|
-
if (value !== void 0) url.searchParams.set(key, value);
|
|
40
|
-
}
|
|
41
|
-
return url.toString();
|
|
42
|
-
}
|
|
43
32
|
function errorMessage(body, status) {
|
|
44
33
|
const trimmed = body.trim();
|
|
45
34
|
if (trimmed === "") return `ScrapingBee request failed with status ${status}`;
|
|
46
35
|
try {
|
|
47
|
-
const payload =
|
|
36
|
+
const payload = asJsonObject(JSON.parse(trimmed));
|
|
48
37
|
const message = typeof payload?.message === "string" ? payload.message.trim() : "";
|
|
49
38
|
if (message !== "") return message;
|
|
50
39
|
const error = typeof payload?.error === "string" ? payload.error.trim() : "";
|
|
@@ -80,7 +69,7 @@ function requireStr(value, field) {
|
|
|
80
69
|
return value;
|
|
81
70
|
}
|
|
82
71
|
function fetchParams(input) {
|
|
83
|
-
return
|
|
72
|
+
return compactDefined({
|
|
84
73
|
url: input.url,
|
|
85
74
|
render_js: bool(input.renderJs),
|
|
86
75
|
wait: int(input.waitMs),
|
|
@@ -96,14 +85,17 @@ function fetchParams(input) {
|
|
|
96
85
|
});
|
|
97
86
|
}
|
|
98
87
|
async function requestText(ctx, path, params) {
|
|
99
|
-
const response = await
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
88
|
+
const response = await http.request({
|
|
89
|
+
path,
|
|
90
|
+
query: [["api_key", requireApiKey(ctx, SERVICE)], ...Object.entries(params)],
|
|
91
|
+
responseType: "text",
|
|
92
|
+
mapError: ({ data, status }) => upstreamError(status, errorMessage(String(data ?? ""), status))
|
|
93
|
+
});
|
|
94
|
+
return { body: response.data, response };
|
|
103
95
|
}
|
|
104
96
|
async function fetchHtml(input, ctx) {
|
|
105
97
|
const { body, response } = await requestText(ctx, "", fetchParams(input));
|
|
106
|
-
return
|
|
98
|
+
return compactDefined({
|
|
107
99
|
html: body,
|
|
108
100
|
statusCode: response.status,
|
|
109
101
|
contentType: response.headers.get("content-type") ?? void 0,
|
|
@@ -123,9 +115,9 @@ async function extractData(input, ctx) {
|
|
|
123
115
|
} catch {
|
|
124
116
|
throw upstreamError(502, "scrapingbee extract_data response is not valid JSON");
|
|
125
117
|
}
|
|
126
|
-
const data =
|
|
118
|
+
const data = asJsonObject(payload);
|
|
127
119
|
if (data === void 0) throw upstreamError(502, "scrapingbee extract_data response must be a JSON object");
|
|
128
|
-
return
|
|
120
|
+
return compactDefined({
|
|
129
121
|
data: { ...data },
|
|
130
122
|
statusCode: response.status,
|
|
131
123
|
resolvedUrl: response.headers.get("spb-resolved-url") ?? void 0,
|
|
@@ -140,7 +132,7 @@ async function getUsageStats(_input, ctx) {
|
|
|
140
132
|
} catch {
|
|
141
133
|
throw upstreamError(502, "scrapingbee usage response is not valid JSON");
|
|
142
134
|
}
|
|
143
|
-
const usage =
|
|
135
|
+
const usage = asJsonObject(payload);
|
|
144
136
|
if (usage === void 0) throw upstreamError(502, "scrapingbee usage response must be an object");
|
|
145
137
|
return {
|
|
146
138
|
usage: {
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-WW2IMPQK.js";
|
|
4
|
+
import {
|
|
5
|
+
trimmedText
|
|
6
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
7
|
import {
|
|
2
8
|
createProviderPlugin,
|
|
3
9
|
requireApiKey,
|
|
4
10
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
11
|
+
} from "./chunk-YASUMV2K.js";
|
|
12
|
+
import "./chunk-U5UHT7CX.js";
|
|
10
13
|
import {
|
|
11
14
|
external_exports
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-RVWZN3CI.js";
|
|
16
|
+
import "./chunk-U67V476Y.js";
|
|
14
17
|
|
|
15
18
|
// ../plugins/src/screenshot_fyi/schema.ts
|
|
16
19
|
var takeScreenshotInput = external_exports.strictObject({
|
|
@@ -38,32 +41,19 @@ var SERVICE = "screenshot_fyi";
|
|
|
38
41
|
var API_BASE = "https://www.screenshot.fyi";
|
|
39
42
|
var CAPTURE_PATH = "/api/take";
|
|
40
43
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
44
|
+
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
41
45
|
function toRecord(value) {
|
|
42
46
|
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
43
47
|
}
|
|
44
|
-
function text(value) {
|
|
45
|
-
if (typeof value !== "string") return void 0;
|
|
46
|
-
const trimmed = value.trim();
|
|
47
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
48
|
-
}
|
|
49
48
|
function errorMessage(payload, status) {
|
|
50
|
-
const direct =
|
|
49
|
+
const direct = trimmedText(payload);
|
|
51
50
|
if (direct !== void 0) return direct;
|
|
52
51
|
const record = toRecord(payload);
|
|
53
|
-
const top =
|
|
54
|
-
const detail = Array.isArray(record?.details) ?
|
|
52
|
+
const top = trimmedText(record?.error);
|
|
53
|
+
const detail = Array.isArray(record?.details) ? trimmedText(toRecord(record.details[0])?.message) : void 0;
|
|
55
54
|
if (top !== void 0 && detail !== void 0) return `${top}: ${detail}`;
|
|
56
55
|
return top ?? detail ?? `screenshot.fyi \u8FD4\u56DE HTTP ${status}`;
|
|
57
56
|
}
|
|
58
|
-
async function readPayload(response) {
|
|
59
|
-
const body = await response.text();
|
|
60
|
-
if (body.trim() === "") return null;
|
|
61
|
-
try {
|
|
62
|
-
return JSON.parse(body);
|
|
63
|
-
} catch {
|
|
64
|
-
throw upstreamError(502, "screenshot.fyi \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94");
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
57
|
function buildQuery(input) {
|
|
68
58
|
const query = { url: input.url };
|
|
69
59
|
if (input.width !== void 0) query.width = String(input.width);
|
|
@@ -73,30 +63,22 @@ function buildQuery(input) {
|
|
|
73
63
|
if (input.disableCookieBanners !== void 0) query.disableCookieBanners = String(input.disableCookieBanners);
|
|
74
64
|
return query;
|
|
75
65
|
}
|
|
76
|
-
async function capture(url) {
|
|
77
|
-
try {
|
|
78
|
-
return await guardedFetch(url.toString(), {
|
|
79
|
-
method: "GET",
|
|
80
|
-
headers: { accept: "application/json" },
|
|
81
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
82
|
-
});
|
|
83
|
-
} catch (error) {
|
|
84
|
-
if (error instanceof Error && error.name === "TimeoutError") {
|
|
85
|
-
throw upstreamError(504, `screenshot.fyi ${REQUEST_TIMEOUT_MS / 1e3}s \u5185\u6CA1\u6709\u8FD4\u56DE\u622A\u56FE`);
|
|
86
|
-
}
|
|
87
|
-
throw error;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
66
|
async function takeScreenshot(input, ctx) {
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
67
|
+
const query = [
|
|
68
|
+
["accessKey", requireApiKey(ctx, SERVICE)],
|
|
69
|
+
...Object.entries(buildQuery(input))
|
|
70
|
+
];
|
|
71
|
+
const response = await http.request({
|
|
72
|
+
path: CAPTURE_PATH,
|
|
73
|
+
query,
|
|
74
|
+
headers: { accept: "application/json" },
|
|
75
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
76
|
+
invalidJsonMessage: "screenshot.fyi \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
|
|
77
|
+
mapError: ({ bodyKind, data, status }) => bodyKind === "invalid-json" ? upstreamError(502, "screenshot.fyi \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94") : upstreamError(status, errorMessage(bodyKind === "empty" ? null : data, status)),
|
|
78
|
+
mapTransportError: ({ kind }) => kind === "timeout" ? upstreamError(504, `screenshot.fyi ${REQUEST_TIMEOUT_MS / 1e3}s \u5185\u6CA1\u6709\u8FD4\u56DE\u622A\u56FE`) : upstreamError(502, "screenshot.fyi \u8BF7\u6C42\u5931\u8D25")
|
|
79
|
+
});
|
|
80
|
+
const payload = response.bodyKind === "empty" ? null : response.data;
|
|
81
|
+
const screenshotUrl = trimmedText(toRecord(payload)?.url);
|
|
100
82
|
if (screenshotUrl === void 0) {
|
|
101
83
|
throw upstreamError(502, "screenshot.fyi \u7684\u6210\u529F\u54CD\u5E94\u91CC\u6CA1\u6709\u622A\u56FE url");
|
|
102
84
|
}
|
|
@@ -1,26 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-WW2IMPQK.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject
|
|
6
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
7
|
import {
|
|
2
8
|
createProviderPlugin,
|
|
3
9
|
requireApiKey,
|
|
4
10
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
11
|
+
} from "./chunk-YASUMV2K.js";
|
|
12
|
+
import "./chunk-U5UHT7CX.js";
|
|
10
13
|
import {
|
|
11
14
|
TBError,
|
|
12
15
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-RVWZN3CI.js";
|
|
17
|
+
import "./chunk-U67V476Y.js";
|
|
15
18
|
|
|
16
19
|
// ../plugins/src/semantic_scholar/api.ts
|
|
17
20
|
var SERVICE = "semantic_scholar";
|
|
18
21
|
var GRAPH_BASE = "https://api.semanticscholar.org/graph/v1";
|
|
19
22
|
var RECOMMENDATIONS_BASE = "https://api.semanticscholar.org/recommendations/v1";
|
|
20
23
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
+
var graphHttp = createProviderHttpClient({ baseUrl: `${GRAPH_BASE}/`, service: SERVICE });
|
|
25
|
+
var recommendationsHttp = createProviderHttpClient({
|
|
26
|
+
baseUrl: `${RECOMMENDATIONS_BASE}/`,
|
|
27
|
+
service: SERVICE
|
|
28
|
+
});
|
|
24
29
|
function trimmed(value) {
|
|
25
30
|
if (typeof value !== "string") return void 0;
|
|
26
31
|
const result = value.trim();
|
|
@@ -35,7 +40,7 @@ function array(value) {
|
|
|
35
40
|
return Array.isArray(value) ? value : [];
|
|
36
41
|
}
|
|
37
42
|
function rawObject(value) {
|
|
38
|
-
return
|
|
43
|
+
return asJsonObject(value) ?? {};
|
|
39
44
|
}
|
|
40
45
|
function nullableInt(value) {
|
|
41
46
|
return Number.isInteger(value) ? value : null;
|
|
@@ -71,27 +76,10 @@ var PAPER_SEARCH_FILTER_KEYS = [
|
|
|
71
76
|
function paperSearchParams(input, pagingKey) {
|
|
72
77
|
return { ...params(input, PAPER_SEARCH_FILTER_KEYS), ...params(input, [pagingKey]) };
|
|
73
78
|
}
|
|
74
|
-
function buildUrl(input) {
|
|
75
|
-
const base = input.family === "graph" ? GRAPH_BASE : RECOMMENDATIONS_BASE;
|
|
76
|
-
const url = new URL(`${base}${input.path}`);
|
|
77
|
-
for (const [key, value] of Object.entries(input.params ?? {})) {
|
|
78
|
-
if (value !== void 0) url.searchParams.set(key, value);
|
|
79
|
-
}
|
|
80
|
-
return url.toString();
|
|
81
|
-
}
|
|
82
|
-
async function readPayload(response) {
|
|
83
|
-
const body = await response.text();
|
|
84
|
-
if (body.trim() === "") return null;
|
|
85
|
-
try {
|
|
86
|
-
return JSON.parse(body);
|
|
87
|
-
} catch {
|
|
88
|
-
throw new TBError("unavailable", "Semantic Scholar \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
79
|
function errorMessage(payload, status) {
|
|
92
80
|
const direct = trimmed(payload);
|
|
93
81
|
if (direct !== void 0) return direct;
|
|
94
|
-
const body =
|
|
82
|
+
const body = asJsonObject(payload);
|
|
95
83
|
return trimmed(body?.message) ?? trimmed(body?.error) ?? trimmed(body?.detail) ?? `Semantic Scholar \u8FD4\u56DE HTTP ${status}`;
|
|
96
84
|
}
|
|
97
85
|
async function request(ctx, input) {
|
|
@@ -99,30 +87,23 @@ async function request(ctx, input) {
|
|
|
99
87
|
"accept": "application/json",
|
|
100
88
|
"x-api-key": requireApiKey(ctx, SERVICE)
|
|
101
89
|
};
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
const message = error instanceof Error ? error.message : "unknown network error";
|
|
118
|
-
throw upstreamError(502, `Semantic Scholar \u8BF7\u6C42\u5931\u8D25:${message}`);
|
|
119
|
-
}
|
|
120
|
-
const payload = await readPayload(response);
|
|
121
|
-
if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
|
|
122
|
-
return payload;
|
|
90
|
+
const http = input.family === "graph" ? graphHttp : recommendationsHttp;
|
|
91
|
+
const response = await http.request({
|
|
92
|
+
method: input.method,
|
|
93
|
+
path: input.path,
|
|
94
|
+
query: Object.entries(input.params ?? {}),
|
|
95
|
+
headers,
|
|
96
|
+
// 上游对 POST 一律发 body(没给就发 `{}`),保留:batch 端点不接受空请求。
|
|
97
|
+
...input.method === "POST" ? { json: input.body ?? {} } : {},
|
|
98
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
99
|
+
invalidJsonMessage: "Semantic Scholar \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
|
|
100
|
+
mapError: ({ bodyKind, data, status }) => bodyKind === "invalid-json" ? new TBError("unavailable", "Semantic Scholar \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true }) : upstreamError(status, errorMessage(data, status)),
|
|
101
|
+
mapTransportError: ({ kind, message }) => kind === "timeout" ? upstreamError(504, `Semantic Scholar \u8BF7\u6C42\u8D85\u65F6(${REQUEST_TIMEOUT_MS / 1e3} \u79D2)`) : upstreamError(502, `Semantic Scholar \u8BF7\u6C42\u5931\u8D25:${message ?? "unknown network error"}`)
|
|
102
|
+
});
|
|
103
|
+
return response.bodyKind === "empty" ? null : response.data;
|
|
123
104
|
}
|
|
124
105
|
function normalizePaperList(payload) {
|
|
125
|
-
const body =
|
|
106
|
+
const body = asJsonObject(payload);
|
|
126
107
|
return {
|
|
127
108
|
total: nullableInt(body?.total),
|
|
128
109
|
offset: nullableInt(body?.offset),
|
|
@@ -133,7 +114,7 @@ function normalizePaperList(payload) {
|
|
|
133
114
|
};
|
|
134
115
|
}
|
|
135
116
|
function normalizeAuthorList(payload) {
|
|
136
|
-
const body =
|
|
117
|
+
const body = asJsonObject(payload);
|
|
137
118
|
return {
|
|
138
119
|
total: nullableInt(body?.total),
|
|
139
120
|
offset: nullableInt(body?.offset),
|
|
@@ -143,7 +124,7 @@ function normalizeAuthorList(payload) {
|
|
|
143
124
|
};
|
|
144
125
|
}
|
|
145
126
|
function normalizeEdgeList(payload) {
|
|
146
|
-
const body =
|
|
127
|
+
const body = asJsonObject(payload);
|
|
147
128
|
return {
|
|
148
129
|
total: nullableInt(body?.total),
|
|
149
130
|
offset: nullableInt(body?.offset),
|
|
@@ -195,7 +176,7 @@ async function matchPaperTitle(input, ctx) {
|
|
|
195
176
|
path: "/paper/search/match",
|
|
196
177
|
params: params(input, ["query", "fields"])
|
|
197
178
|
});
|
|
198
|
-
return { paper:
|
|
179
|
+
return { paper: asJsonObject(payload), raw: rawObject(payload) };
|
|
199
180
|
}
|
|
200
181
|
async function autocompletePapers(input, ctx) {
|
|
201
182
|
const payload = await request(ctx, {
|
|
@@ -204,7 +185,7 @@ async function autocompletePapers(input, ctx) {
|
|
|
204
185
|
path: "/paper/autocomplete",
|
|
205
186
|
params: params(input, ["query", "limit"])
|
|
206
187
|
});
|
|
207
|
-
const body =
|
|
188
|
+
const body = asJsonObject(payload);
|
|
208
189
|
return { completions: array(body?.matches ?? body?.data), raw: rawObject(payload) };
|
|
209
190
|
}
|
|
210
191
|
async function getPaperAuthors(input, ctx) {
|
|
@@ -273,7 +254,7 @@ async function searchSnippets(input, ctx) {
|
|
|
273
254
|
path: "/snippet/search",
|
|
274
255
|
params: params(input, ["query", "limit"])
|
|
275
256
|
});
|
|
276
|
-
const body =
|
|
257
|
+
const body = asJsonObject(payload);
|
|
277
258
|
return {
|
|
278
259
|
total: nullableInt(body?.total),
|
|
279
260
|
offset: nullableInt(body?.offset),
|