@tool-bridge/server 0.16.0 → 0.19.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.
Files changed (115) hide show
  1. package/dist/{airtable-S3T4TAN7.js → airtable-23JBIM6X.js} +106 -114
  2. package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-ADWBTCIH.js} +25 -16
  3. package/dist/{amap-LGVGNPML.js → amap-CYQCYW2Z.js} +114 -123
  4. package/dist/{anthropic-27RFZO35.js → anthropic-5P62HDNR.js} +34 -56
  5. package/dist/{apify-6WLYAIAS.js → apify-54RZUAGW.js} +31 -49
  6. package/dist/{brave_search-K2SVJ66F.js → brave_search-AHJ6FTD5.js} +52 -77
  7. package/dist/{chunk-VK3V2WTY.js → chunk-B4P6YZFS.js} +4 -6
  8. package/dist/{chunk-BB6ZLMTU.js → chunk-CLEZ6YQ6.js} +2600 -481
  9. package/dist/chunk-JXHMDBAY.js +45 -0
  10. package/dist/chunk-LMLX3DJF.js +50 -0
  11. package/dist/{chunk-YB2FLNWI.js → chunk-OKRZPQ3R.js} +2558 -1926
  12. package/dist/chunk-SWBNHIO4.js +977 -0
  13. package/dist/chunk-U67V476Y.js +35 -0
  14. package/dist/chunk-VLOIDU5U.js +283 -0
  15. package/dist/{circleci-WV3ITU7Q.js → circleci-UM3NSQJ3.js} +36 -55
  16. package/dist/{clerk-NFQEFKS4.js → clerk-FE5LQ2CZ.js} +60 -80
  17. package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-KEZABKUT.js} +90 -113
  18. package/dist/{cohere-5KEW7LWT.js → cohere-4IPJADXP.js} +33 -49
  19. package/dist/{confluence-SZE63S46.js → confluence-56QEKNQI.js} +79 -115
  20. package/dist/{convertapi-QPG2JC5K.js → convertapi-3QRM5K5T.js} +13 -16
  21. package/dist/{currencyapi-UO2APQRY.js → currencyapi-L6G4OND5.js} +30 -53
  22. package/dist/{deepseek-LJELIMM3.js → deepseek-LGC6HBFG.js} +30 -38
  23. package/dist/{docker_hub-2MFXSBOF.js → docker_hub-XDMK3BIU.js} +141 -157
  24. package/dist/{dropbox-GQYNTTVA.js → dropbox-4QARMFZU.js} +134 -141
  25. package/dist/{dub-KI2LHXST.js → dub-C6JSJKOT.js} +61 -93
  26. package/dist/{e2b-WO6ISY3C.js → e2b-6A6TVACJ.js} +39 -69
  27. package/dist/{exa-IZ7B3BPT.js → exa-SIWWW6AA.js} +49 -77
  28. package/dist/{fal_ai-LTMF36GJ.js → fal_ai-3IJXOKSP.js} +37 -44
  29. package/dist/{feishu-WM7SLSFD.js → feishu-L4KDA4DC.js} +4 -6
  30. package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-SDM75H4P.js} +4 -5
  31. package/dist/{figma-2Z274VQZ.js → figma-6DD436DN.js} +56 -81
  32. package/dist/{firehydrant-IFI4R65V.js → firehydrant-SYSGYB3R.js} +40 -53
  33. package/dist/{fixer-BCCZEB3D.js → fixer-FZG7ASTF.js} +31 -43
  34. package/dist/{fly-755FXYB5.js → fly-HMRCZBUC.js} +50 -66
  35. package/dist/{front-4FZKKXXK.js → front-FAFSD7I3.js} +43 -66
  36. package/dist/{geocodio-WYKDJ3DP.js → geocodio-4D3TWENM.js} +37 -63
  37. package/dist/{ghost-5BNQTCOH.js → ghost-OSO2FOZS.js} +51 -57
  38. package/dist/{github-ULELF5VX.js → github-OR4I4RHE.js} +48 -41
  39. package/dist/{gmail-G34WT64J.js → gmail-5AOPJ63E.js} +26 -36
  40. package/dist/{googlecalendar-BQU255SC.js → googlecalendar-SOJIJUWH.js} +57 -78
  41. package/dist/{googledocs-HPCNQXYJ.js → googledocs-QSKN5TLN.js} +14 -22
  42. package/dist/{grafana-VOV24FIC.js → grafana-R3AIZM7M.js} +95 -122
  43. package/dist/{graphhopper-D5RXW6AP.js → graphhopper-4CR3QOAX.js} +32 -46
  44. package/dist/index.d.ts +108 -56
  45. package/dist/index.js +4 -3
  46. package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-OBCG6X6J.js} +35 -42
  47. package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-NHH3DTQW.js} +40 -60
  48. package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-7POMCBEC.js} +30 -42
  49. package/dist/{jina_ai-E6UXFV2P.js → jina_ai-YXVKROV4.js} +32 -58
  50. package/dist/{jira-ZDSXGQ6W.js → jira-LADO3VJU.js} +116 -126
  51. package/dist/{langsmith-TIFJRREW.js → langsmith-XZ6UAQFU.js} +101 -121
  52. package/dist/{lemlist-DASEMJMA.js → lemlist-P74GLNE7.js} +57 -68
  53. package/dist/{linear-KE6UP4SP.js → linear-CXJ7D37A.js} +109 -118
  54. package/dist/{logsnag-IMNDN4R5.js → logsnag-EVVHWFLK.js} +31 -48
  55. package/dist/main.js +103 -102
  56. package/dist/{mattermost-HHHMUXQA.js → mattermost-WG2MRGBD.js} +45 -62
  57. package/dist/{mem0-D2FGGOIY.js → mem0-HQWUKG6U.js} +72 -98
  58. package/dist/{memos-4OVIGFPH.js → memos-SQMJIFOE.js} +68 -122
  59. package/dist/{metabase-33WCX5YD.js → metabase-E27G2DZI.js} +47 -60
  60. package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-MIL63NIT.js} +35 -40
  61. package/dist/{mother_duck-M6VWS2VH.js → mother_duck-AIZVCBNR.js} +42 -62
  62. package/dist/{ngrok-Z2PKQBHH.js → ngrok-XS4DVIQS.js} +42 -58
  63. package/dist/{notes-SS4RPC4K.js → notes-JEOUSL2Y.js} +3 -5
  64. package/dist/{notion-FJCNQ6I7.js → notion-U4EZVDW2.js} +83 -97
  65. package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-AZSQEYEJ.js} +35 -39
  66. package/dist/{openai-JODZ4GKT.js → openai-HW3SYMTQ.js} +51 -55
  67. package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-QX74MAEL.js} +61 -79
  68. package/dist/{openrouter-Q5XXEJZ7.js → openrouter-OXSKYL6N.js} +41 -55
  69. package/dist/{outline-RT2EHJ2X.js → outline-CCQAPDSW.js} +89 -104
  70. package/dist/{paddle-OF2V7GAC.js → paddle-6KQPSSCK.js} +34 -49
  71. package/dist/{perplexity-LNZEWLHG.js → perplexity-2TXO7IQE.js} +33 -50
  72. package/dist/{pinecone-JSJIXZYN.js → pinecone-YOO7NULI.js} +65 -91
  73. package/dist/{pipedrive-D4CKVUXR.js → pipedrive-Q6RIFIFP.js} +37 -59
  74. package/dist/{polar-M7ZYP6UR.js → polar-KUMGCES3.js} +43 -53
  75. package/dist/{posthog-YV7CZOH4.js → posthog-VXQHBSMB.js} +58 -77
  76. package/dist/{postmark-KYHLECRG.js → postmark-YLIPF52S.js} +52 -71
  77. package/dist/{prerender-HCMHBKV2.js → prerender-CRY7UJN5.js} +32 -50
  78. package/dist/{pubmed-WYVLCCN3.js → pubmed-3Z4T5AM7.js} +28 -60
  79. package/dist/{railway-TWIRD5KR.js → railway-BP37IGFL.js} +32 -39
  80. package/dist/{readwise-UZ467IQ7.js → readwise-HTKICF4K.js} +62 -78
  81. package/dist/{render-MECUC5CC.js → render-WIVTUXJH.js} +48 -64
  82. package/dist/{replicate-A5MEK3SW.js → replicate-JJYPA43D.js} +41 -58
  83. package/dist/{resend-BC6EAWJQ.js → resend-TKHZVG7A.js} +27 -37
  84. package/dist/{rootly-ZM3QDUIS.js → rootly-FRSZLG5U.js} +64 -76
  85. package/dist/{scrapfly-WAML42QJ.js → scrapfly-M5WXGQWE.js} +45 -51
  86. package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-PMXNLLBK.js} +25 -33
  87. package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-HFW4TAOH.js} +29 -47
  88. package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-KXVH2VZQ.js} +37 -56
  89. package/dist/{sentry-OKBPSTDM.js → sentry-WWOT2LRX.js} +66 -85
  90. package/dist/{shodan-PPC6DYU4.js → shodan-FY635H35.js} +42 -53
  91. package/dist/{shopify-EWGUHBXO.js → shopify-HQLBVSA5.js} +32 -49
  92. package/dist/{stripe-6RPDPC5W.js → stripe-GJN2GOHB.js} +4 -5
  93. package/dist/{supabase-SK7DQ42N.js → supabase-BBNZGQU6.js} +69 -88
  94. package/dist/{tavily-YCG5VQMH.js → tavily-DPENIBOG.js} +37 -62
  95. package/dist/{telegram-2OES5FYB.js → telegram-L4NONG6H.js} +168 -177
  96. package/dist/{telnyx-POOSBBR4.js → telnyx-H67MAEZS.js} +30 -50
  97. package/dist/{todoist-M7YD6YSS.js → todoist-G2BSP4DX.js} +77 -89
  98. package/dist/{trello-IS6V5W3E.js → trello-7WMVFDG2.js} +108 -122
  99. package/dist/{turso-RCFHUFVH.js → turso-ZUAESFC2.js} +52 -64
  100. package/dist/{twilio-OS2RXFGO.js → twilio-EYFYIX3B.js} +48 -55
  101. package/dist/{umami-PQ2SJ2LN.js → umami-AXAUDUVF.js} +49 -69
  102. package/dist/{unsplash-C6BPZO4E.js → unsplash-UCQAWPLR.js} +35 -52
  103. package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-ZPZ4ASU6.js} +28 -40
  104. package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-4QVKKUD5.js} +11 -12
  105. package/dist/{v2ex-R4JWTEHN.js → v2ex-VGEFJTYC.js} +36 -61
  106. package/dist/{vercel-FZVYUOQD.js → vercel-JME4TSCN.js} +124 -150
  107. package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
  108. package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-TRGU2MDG.js} +26 -34
  109. package/dist/{wordpress-XRWGO6LG.js → wordpress-WRUKLCZR.js} +87 -104
  110. package/dist/{workos-WR4NKOYL.js → workos-ZDW4EHS4.js} +37 -56
  111. package/dist/{zhihu-BKZIB3WA.js → zhihu-4VI67CWU.js} +35 -57
  112. package/package.json +3 -3
  113. package/dist/chunk-2O27H4Y2.js +0 -183
  114. package/dist/chunk-GKX72JMJ.js +0 -378
  115. package/dist/chunk-MLKGABMK.js +0 -9
@@ -1,25 +1,27 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-VLOIDU5U.js";
4
+ import "./chunk-JXHMDBAY.js";
1
5
  import {
2
6
  createProviderPlugin,
3
7
  requireApiKey,
4
8
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
9
+ } from "./chunk-B4P6YZFS.js";
10
+ import "./chunk-SWBNHIO4.js";
10
11
  import {
11
12
  TBError,
12
13
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
14
+ } from "./chunk-OKRZPQ3R.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 SCRAPE_URL = `${API_BASE}/scrape`;
20
- var METRICS_URL = `${API_BASE}/scrape/monitoring/metrics`;
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 buildUrl(base, apiKey, query) {
46
- const url = new URL(base);
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) url.searchParams.append(`${key}[]`, item);
51
+ for (const item of value) result.push([`${key}[]`, item]);
52
52
  continue;
53
53
  }
54
- url.searchParams.set(key, String(value));
54
+ result.push([key, value]);
55
55
  }
56
- return url;
56
+ return result;
57
57
  }
58
- async function request(ctx, base, query, init) {
59
- const url = buildUrl(base, requireApiKey(ctx, SERVICE), query);
60
- let response;
61
- try {
62
- response = await guardedFetch(url.toString(), {
63
- ...init,
64
- headers: { accept: "application/json", ...init.headers },
65
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
66
- });
67
- } catch (error) {
68
- if (error instanceof TBError) throw error;
69
- if (error instanceof Error && error.name === "TimeoutError") {
70
- throw upstreamError(504, `Scrapfly ${REQUEST_TIMEOUT_MS / 1e3}s \u5185\u6CA1\u6709\u8FD4\u56DE`);
71
- }
72
- throw new TBError(
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
- error instanceof Error ? `Scrapfly \u8BF7\u6C42\u5931\u8D25: ${error.message}` : "Scrapfly \u8BF7\u6C42\u5931\u8D25",
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
- async function readJson(response, label) {
87
- const body = await response.text();
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
- try {
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
- SCRAPE_URL,
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(await readJson(response, "Scrapfly \u6293\u53D6\u54CD\u5E94"), "Scrapfly \u6293\u53D6\u54CD\u5E94");
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
- METRICS_URL,
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
- await readJson(response, "Scrapfly \u76D1\u63A7\u6307\u6807\u54CD\u5E94"),
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-VLOIDU5U.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-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
12
+ } from "./chunk-B4P6YZFS.js";
13
+ import "./chunk-SWBNHIO4.js";
10
14
  import {
11
15
  external_exports
12
- } from "./chunk-YB2FLNWI.js";
13
- import "./chunk-MLKGABMK.js";
16
+ } from "./chunk-OKRZPQ3R.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
- function record(value) {
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 = record(JSON.parse(trimmed));
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 compact({
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 guardedFetch(buildUrl(path, requireApiKey(ctx, SERVICE), params), { method: "GET" });
100
- const body = await response.text();
101
- if (!response.ok) throw upstreamError(response.status, errorMessage(body, response.status));
102
- return { body, response };
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 compact({
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 = record(payload);
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 compact({
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 = record(payload);
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-VLOIDU5U.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-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
11
+ } from "./chunk-B4P6YZFS.js";
12
+ import "./chunk-SWBNHIO4.js";
10
13
  import {
11
14
  external_exports
12
- } from "./chunk-YB2FLNWI.js";
13
- import "./chunk-MLKGABMK.js";
15
+ } from "./chunk-OKRZPQ3R.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 = text(payload);
49
+ const direct = trimmedText(payload);
51
50
  if (direct !== void 0) return direct;
52
51
  const record = toRecord(payload);
53
- const top = text(record?.error);
54
- const detail = Array.isArray(record?.details) ? text(toRecord(record.details[0])?.message) : void 0;
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 target = new URL(CAPTURE_PATH, API_BASE);
92
- target.searchParams.set("accessKey", requireApiKey(ctx, SERVICE));
93
- for (const [key, value] of Object.entries(buildQuery(input))) {
94
- target.searchParams.set(key, value);
95
- }
96
- const response = await capture(target);
97
- const payload = await readPayload(response);
98
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
99
- const screenshotUrl = text(toRecord(payload)?.url);
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-VLOIDU5U.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-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
11
+ } from "./chunk-B4P6YZFS.js";
12
+ import "./chunk-SWBNHIO4.js";
10
13
  import {
11
14
  TBError,
12
15
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
16
+ } from "./chunk-OKRZPQ3R.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
- function record(value) {
22
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
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 record(value) ?? {};
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 = record(payload);
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
- if (input.method === "POST") headers["content-type"] = "application/json";
103
- let response;
104
- try {
105
- response = await guardedFetch(buildUrl(input), {
106
- method: input.method,
107
- headers,
108
- // 上游对 POST 一律发 body(没给就发 `{}`),保留:batch 端点不接受空请求。
109
- body: input.method === "POST" ? JSON.stringify(input.body ?? {}) : void 0,
110
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
111
- });
112
- } catch (error) {
113
- if (error instanceof TBError) throw error;
114
- if (error instanceof Error && error.name === "TimeoutError") {
115
- throw upstreamError(504, `Semantic Scholar \u8BF7\u6C42\u8D85\u65F6(${REQUEST_TIMEOUT_MS / 1e3} \u79D2)`);
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 = record(payload);
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 = record(payload);
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 = record(payload);
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: record(payload), raw: rawObject(payload) };
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 = record(payload);
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 = record(payload);
257
+ const body = asJsonObject(payload);
277
258
  return {
278
259
  total: nullableInt(body?.total),
279
260
  offset: nullableInt(body?.offset),