@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.
Files changed (115) hide show
  1. package/dist/{airtable-S3T4TAN7.js → airtable-NOSOMOVB.js} +106 -114
  2. package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-BHIJ4LW5.js} +25 -16
  3. package/dist/{amap-LGVGNPML.js → amap-QRLP4TWZ.js} +114 -123
  4. package/dist/{anthropic-27RFZO35.js → anthropic-IEOI36EV.js} +34 -56
  5. package/dist/{apify-6WLYAIAS.js → apify-3CCYTQVK.js} +31 -49
  6. package/dist/{brave_search-K2SVJ66F.js → brave_search-PZNYDQG7.js} +52 -77
  7. package/dist/chunk-JXHMDBAY.js +45 -0
  8. package/dist/chunk-LMLX3DJF.js +50 -0
  9. package/dist/{chunk-YB2FLNWI.js → chunk-RVWZN3CI.js} +2103 -1775
  10. package/dist/{chunk-BB6ZLMTU.js → chunk-TLNUIPFZ.js} +492 -300
  11. package/dist/chunk-U5UHT7CX.js +977 -0
  12. package/dist/chunk-U67V476Y.js +35 -0
  13. package/dist/chunk-WW2IMPQK.js +283 -0
  14. package/dist/{chunk-VK3V2WTY.js → chunk-YASUMV2K.js} +4 -6
  15. package/dist/{circleci-WV3ITU7Q.js → circleci-VSJ4O5FC.js} +36 -55
  16. package/dist/{clerk-NFQEFKS4.js → clerk-CC2JZBZI.js} +60 -80
  17. package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-PJEBSEYQ.js} +90 -113
  18. package/dist/{cohere-5KEW7LWT.js → cohere-KBACYSPF.js} +33 -49
  19. package/dist/{confluence-SZE63S46.js → confluence-2PX3O7G5.js} +79 -115
  20. package/dist/{convertapi-QPG2JC5K.js → convertapi-BVOTD2PJ.js} +13 -16
  21. package/dist/{currencyapi-UO2APQRY.js → currencyapi-6ZQ2VNQ7.js} +30 -53
  22. package/dist/{deepseek-LJELIMM3.js → deepseek-MB3WVVTB.js} +30 -38
  23. package/dist/{docker_hub-2MFXSBOF.js → docker_hub-7CLQL2IJ.js} +141 -157
  24. package/dist/{dropbox-GQYNTTVA.js → dropbox-VFYDVUNK.js} +134 -141
  25. package/dist/{dub-KI2LHXST.js → dub-QN3EETJY.js} +61 -93
  26. package/dist/{e2b-WO6ISY3C.js → e2b-NKC3Y776.js} +39 -69
  27. package/dist/{exa-IZ7B3BPT.js → exa-KKZ6F25K.js} +49 -77
  28. package/dist/{fal_ai-LTMF36GJ.js → fal_ai-25LYJD2O.js} +37 -44
  29. package/dist/{feishu-WM7SLSFD.js → feishu-NRT55B3Q.js} +4 -6
  30. package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-3W3XXUG4.js} +4 -5
  31. package/dist/{figma-2Z274VQZ.js → figma-4FLP35TC.js} +56 -81
  32. package/dist/{firehydrant-IFI4R65V.js → firehydrant-BLXPLZ3X.js} +40 -53
  33. package/dist/{fixer-BCCZEB3D.js → fixer-4OR62TGE.js} +31 -43
  34. package/dist/{fly-755FXYB5.js → fly-MYCKOZZK.js} +50 -66
  35. package/dist/{front-4FZKKXXK.js → front-3DFYVMF3.js} +43 -66
  36. package/dist/{geocodio-WYKDJ3DP.js → geocodio-CXMD6VKA.js} +37 -63
  37. package/dist/{ghost-5BNQTCOH.js → ghost-4UUE737W.js} +51 -57
  38. package/dist/{github-ULELF5VX.js → github-WFS2ON2N.js} +48 -41
  39. package/dist/{gmail-G34WT64J.js → gmail-KW7FXA7A.js} +26 -36
  40. package/dist/{googlecalendar-BQU255SC.js → googlecalendar-AMH5JQMC.js} +57 -78
  41. package/dist/{googledocs-HPCNQXYJ.js → googledocs-R5VA6CKD.js} +14 -22
  42. package/dist/{grafana-VOV24FIC.js → grafana-IT6DWIVB.js} +95 -122
  43. package/dist/{graphhopper-D5RXW6AP.js → graphhopper-TYFDJZWC.js} +32 -46
  44. package/dist/index.d.ts +57 -50
  45. package/dist/index.js +4 -3
  46. package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-GJ4HXVXO.js} +35 -42
  47. package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-OAGR6PRF.js} +40 -60
  48. package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-BCKAMDGL.js} +30 -42
  49. package/dist/{jina_ai-E6UXFV2P.js → jina_ai-N3NXRVIZ.js} +32 -58
  50. package/dist/{jira-ZDSXGQ6W.js → jira-CHLBKWLO.js} +116 -126
  51. package/dist/{langsmith-TIFJRREW.js → langsmith-OIKOTPY3.js} +101 -121
  52. package/dist/{lemlist-DASEMJMA.js → lemlist-VAKYPKS3.js} +57 -68
  53. package/dist/{linear-KE6UP4SP.js → linear-Q6QTPJ5R.js} +109 -118
  54. package/dist/{logsnag-IMNDN4R5.js → logsnag-SQOQBTES.js} +31 -48
  55. package/dist/main.js +103 -102
  56. package/dist/{mattermost-HHHMUXQA.js → mattermost-G2KBEICM.js} +45 -62
  57. package/dist/{mem0-D2FGGOIY.js → mem0-D2FPLYDX.js} +72 -98
  58. package/dist/{memos-4OVIGFPH.js → memos-76PTWV5V.js} +68 -122
  59. package/dist/{metabase-33WCX5YD.js → metabase-TWSIDVBM.js} +47 -60
  60. package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-TP7TQUEJ.js} +35 -40
  61. package/dist/{mother_duck-M6VWS2VH.js → mother_duck-UXY5THYU.js} +42 -62
  62. package/dist/{ngrok-Z2PKQBHH.js → ngrok-RZW2ISJK.js} +42 -58
  63. package/dist/{notes-SS4RPC4K.js → notes-B2I6FWK2.js} +3 -5
  64. package/dist/{notion-FJCNQ6I7.js → notion-QOKRUE6M.js} +83 -97
  65. package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-ODLFWEJ7.js} +35 -39
  66. package/dist/{openai-JODZ4GKT.js → openai-ZPBPPPGT.js} +51 -55
  67. package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-EOI5UJKT.js} +61 -79
  68. package/dist/{openrouter-Q5XXEJZ7.js → openrouter-BUWLF3BG.js} +41 -55
  69. package/dist/{outline-RT2EHJ2X.js → outline-NXS3QRXO.js} +89 -104
  70. package/dist/{paddle-OF2V7GAC.js → paddle-T4MSKQ76.js} +34 -49
  71. package/dist/{perplexity-LNZEWLHG.js → perplexity-WW5N2LW7.js} +33 -50
  72. package/dist/{pinecone-JSJIXZYN.js → pinecone-RY5AZPQM.js} +65 -91
  73. package/dist/{pipedrive-D4CKVUXR.js → pipedrive-OHYQNZTU.js} +37 -59
  74. package/dist/{polar-M7ZYP6UR.js → polar-XZIAHXS5.js} +43 -53
  75. package/dist/{posthog-YV7CZOH4.js → posthog-DTPTWORY.js} +58 -77
  76. package/dist/{postmark-KYHLECRG.js → postmark-F4UCQKC3.js} +52 -71
  77. package/dist/{prerender-HCMHBKV2.js → prerender-P3Y2MLIC.js} +32 -50
  78. package/dist/{pubmed-WYVLCCN3.js → pubmed-RHU3GXFB.js} +28 -60
  79. package/dist/{railway-TWIRD5KR.js → railway-VB6SRLI6.js} +32 -39
  80. package/dist/{readwise-UZ467IQ7.js → readwise-DIMSKJZR.js} +62 -78
  81. package/dist/{render-MECUC5CC.js → render-XCCDCEEK.js} +48 -64
  82. package/dist/{replicate-A5MEK3SW.js → replicate-IUEOQ4JC.js} +41 -58
  83. package/dist/{resend-BC6EAWJQ.js → resend-N5MJZH5E.js} +27 -37
  84. package/dist/{rootly-ZM3QDUIS.js → rootly-25T4NBTU.js} +64 -76
  85. package/dist/{scrapfly-WAML42QJ.js → scrapfly-PK4XFXUA.js} +45 -51
  86. package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-ITPBMWQU.js} +25 -33
  87. package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-5U6ZYPKR.js} +29 -47
  88. package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-BJGCI2MU.js} +37 -56
  89. package/dist/{sentry-OKBPSTDM.js → sentry-63IC263P.js} +66 -85
  90. package/dist/{shodan-PPC6DYU4.js → shodan-2WBIFHFN.js} +42 -53
  91. package/dist/{shopify-EWGUHBXO.js → shopify-XLLJRAGM.js} +32 -49
  92. package/dist/{stripe-6RPDPC5W.js → stripe-WLVCY3UN.js} +4 -5
  93. package/dist/{supabase-SK7DQ42N.js → supabase-BKNZ35ER.js} +69 -88
  94. package/dist/{tavily-YCG5VQMH.js → tavily-YFSDEUTL.js} +37 -62
  95. package/dist/{telegram-2OES5FYB.js → telegram-FC35W74G.js} +168 -177
  96. package/dist/{telnyx-POOSBBR4.js → telnyx-MI32XZUG.js} +30 -50
  97. package/dist/{todoist-M7YD6YSS.js → todoist-4ZFJKZC6.js} +77 -89
  98. package/dist/{trello-IS6V5W3E.js → trello-UOGFNMK4.js} +108 -122
  99. package/dist/{turso-RCFHUFVH.js → turso-YTSTW3ZS.js} +52 -64
  100. package/dist/{twilio-OS2RXFGO.js → twilio-XAJDFUQH.js} +48 -55
  101. package/dist/{umami-PQ2SJ2LN.js → umami-ZVIUBPAI.js} +49 -69
  102. package/dist/{unsplash-C6BPZO4E.js → unsplash-IU3PLDNS.js} +35 -52
  103. package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-3EYJW7SY.js} +28 -40
  104. package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-PJG2ASRU.js} +11 -12
  105. package/dist/{v2ex-R4JWTEHN.js → v2ex-KFQWWGFC.js} +36 -61
  106. package/dist/{vercel-FZVYUOQD.js → vercel-I2ZDOQRL.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-BNXOJMB6.js} +26 -34
  109. package/dist/{wordpress-XRWGO6LG.js → wordpress-36D7BSMP.js} +87 -104
  110. package/dist/{workos-WR4NKOYL.js → workos-6X4JJRRC.js} +37 -56
  111. package/dist/{zhihu-BKZIB3WA.js → zhihu-CIXKCHIU.js} +35 -57
  112. package/package.json +5 -5
  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,42 +1,34 @@
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-VK3V2WTY.js";
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-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
16
+ } from "./chunk-RVWZN3CI.js";
17
+ import "./chunk-U67V476Y.js";
15
18
 
16
19
  // ../plugins/src/apify/api.ts
17
20
  var SERVICE = "apify";
18
21
  var API_BASE = "https://api.apify.com";
19
22
  var CURRENT_USER_PATH = "/v2/users/me";
20
- function asRecord(value) {
21
- return value !== null && typeof value === "object" && !Array.isArray(value) ? value : void 0;
22
- }
23
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
23
24
  function nonEmpty(value) {
24
25
  return typeof value === "string" && value !== "" ? value : void 0;
25
26
  }
26
27
  function errorMessage(payload, status) {
27
- const record = asRecord(payload);
28
- const error = asRecord(record?.error);
28
+ const record = asJsonObject(payload);
29
+ const error = asJsonObject(record?.error);
29
30
  return nonEmpty(error?.message) ?? nonEmpty(record?.message) ?? nonEmpty(error?.type) ?? `Apify request failed with status ${status}`;
30
31
  }
31
- async function readPayload(response) {
32
- const text = await response.text().catch(() => "");
33
- if (text === "") return null;
34
- try {
35
- return JSON.parse(text);
36
- } catch {
37
- throw new TBError("unavailable", "Apify \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
38
- }
39
- }
40
32
  function requiredId(value, field) {
41
33
  if (value === void 0 || value === "") {
42
34
  throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
@@ -44,42 +36,32 @@ function requiredId(value, field) {
44
36
  return encodeURIComponent(value);
45
37
  }
46
38
  async function request(ctx, path, init = {}) {
47
- const url = new URL(path, API_BASE);
48
- for (const [key, value] of Object.entries(init.query ?? {})) {
49
- if (value !== void 0) url.searchParams.set(key, String(value));
50
- }
51
- const headers = {
52
- accept: "application/json",
53
- authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
54
- };
55
- if (init.body !== void 0) headers["content-type"] = "application/json";
56
- let response;
57
- let payload;
58
- try {
59
- response = await guardedFetch(url.toString(), {
60
- method: init.method ?? "GET",
61
- headers,
62
- ...init.body === void 0 ? {} : { body: JSON.stringify(init.body) }
63
- });
64
- payload = await readPayload(response);
65
- } catch (error) {
66
- if (error instanceof TBError) throw error;
67
- throw new TBError(
39
+ const { data } = await http.request({
40
+ path,
41
+ method: init.method ?? "GET",
42
+ query: Object.entries(init.query ?? {}),
43
+ headers: {
44
+ accept: "application/json",
45
+ authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
46
+ },
47
+ ...init.body === void 0 ? {} : { json: init.body },
48
+ invalidJsonMessage: "Apify \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
49
+ mapError: ({ bodyKind, data: payload, status }) => bodyKind === "invalid-json" ? new TBError("unavailable", "Apify \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true }) : upstreamError(status, errorMessage(payload, status)),
50
+ mapTransportError: ({ message }) => new TBError(
68
51
  "unavailable",
69
- error instanceof Error ? `Apify \u8BF7\u6C42\u5931\u8D25: ${error.message}` : "Apify \u8BF7\u6C42\u5931\u8D25",
52
+ message === void 0 ? "Apify \u8BF7\u6C42\u5931\u8D25" : `Apify \u8BF7\u6C42\u5931\u8D25: ${message}`,
70
53
  { retryable: true }
71
- );
72
- }
73
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
74
- return payload;
54
+ )
55
+ });
56
+ return data ?? null;
75
57
  }
76
58
  function unwrap(payload, label) {
77
- const record = asRecord(payload);
59
+ const record = asJsonObject(payload);
78
60
  if (record === void 0) {
79
61
  throw new TBError("unavailable", `Apify \u7684${label}\u54CD\u5E94\u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
80
62
  }
81
63
  if (!Object.prototype.hasOwnProperty.call(record, "data")) return record;
82
- const data = asRecord(record.data);
64
+ const data = asJsonObject(record.data);
83
65
  if (data === void 0) {
84
66
  throw new TBError("unavailable", `Apify \u7684${label}\u54CD\u5E94 data \u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
85
67
  }
@@ -1,37 +1,35 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import {
5
+ asJsonObject,
6
+ compactDefined,
7
+ trimmedText
8
+ } from "./chunk-JXHMDBAY.js";
1
9
  import {
2
10
  createProviderPlugin,
3
11
  requireApiKey,
4
12
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
13
+ } from "./chunk-YASUMV2K.js";
14
+ import "./chunk-U5UHT7CX.js";
10
15
  import {
11
16
  TBError,
12
17
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
18
+ } from "./chunk-RVWZN3CI.js";
19
+ import "./chunk-U67V476Y.js";
15
20
 
16
21
  // ../plugins/src/brave_search/api.ts
17
22
  var SERVICE = "brave_search";
18
23
  var API_BASE = "https://api.search.brave.com";
24
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
19
25
  var RATE_LIMIT_CODES = /* @__PURE__ */ new Set(["QUOTA_LIMITED", "RATE_LIMITED", "USAGE_LIMIT_EXCEEDED"]);
20
26
  var AUTH_CODES = /* @__PURE__ */ new Set(["SUBSCRIPTION_TOKEN_INVALID", "SUBSCRIPTION_NOT_FOUND"]);
21
27
  var INVALID_CODES = /* @__PURE__ */ new Set(["RESOURCE_NOT_ALLOWED", "OPTION_NOT_IN_PLAN", "INVALID_URL"]);
22
- function text(value) {
23
- if (typeof value !== "string") return void 0;
24
- const trimmed = value.trim();
25
- return trimmed === "" ? void 0 : trimmed;
26
- }
27
- function record(value) {
28
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
29
- }
30
28
  function nullableRecord(value) {
31
- return value === null ? null : record(value);
29
+ return value === null ? null : asJsonObject(value);
32
30
  }
33
31
  function requireRecord(value, label) {
34
- const result = record(value);
32
+ const result = asJsonObject(value);
35
33
  if (result === void 0) {
36
34
  throw new TBError("unavailable", `${label}\u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
37
35
  }
@@ -41,35 +39,20 @@ function objectArray(value) {
41
39
  if (!Array.isArray(value)) return void 0;
42
40
  return value.map((item) => requireRecord(item, "Brave Search \u7ED3\u679C\u9879"));
43
41
  }
44
- function compact(input) {
45
- return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
46
- }
47
42
  function searchTerm(value) {
48
- const term = text(value);
43
+ const term = trimmedText(value);
49
44
  if (term === void 0) throw new TBError("invalid_argument", "q \u4E0D\u80FD\u662F\u7A7A\u767D");
50
45
  return term;
51
46
  }
52
47
  function goggles(value) {
53
- if (value === void 0 || typeof value === "string") return text(value);
54
- const items = value.map((item) => text(item)).filter((item) => item !== void 0);
48
+ if (value === void 0 || typeof value === "string") return trimmedText(value);
49
+ const items = value.map((item) => trimmedText(item)).filter((item) => item !== void 0);
55
50
  return items.length > 0 ? items : void 0;
56
51
  }
57
- function buildUrl(path, query) {
58
- const url = new URL(`${API_BASE}${path}`);
59
- for (const [key, value] of Object.entries(query)) {
60
- if (value === void 0) continue;
61
- if (Array.isArray(value)) {
62
- for (const item of value) url.searchParams.append(key, item);
63
- continue;
64
- }
65
- url.searchParams.set(key, String(value));
66
- }
67
- return url.toString();
68
- }
69
52
  function braveSearchError(status, payload) {
70
- const error = record(record(payload)?.error);
71
- const message = text(error?.detail) ?? text(error?.code) ?? `Brave Search \u8FD4\u56DE HTTP ${status}`;
72
- const code = text(error?.code);
53
+ const error = asJsonObject(asJsonObject(payload)?.error);
54
+ const message = trimmedText(error?.detail) ?? trimmedText(error?.code) ?? `Brave Search \u8FD4\u56DE HTTP ${status}`;
55
+ const code = trimmedText(error?.code);
73
56
  if (code !== void 0) {
74
57
  if (RATE_LIMIT_CODES.has(code)) return upstreamError(429, message);
75
58
  if (AUTH_CODES.has(code)) return upstreamError(401, message);
@@ -78,31 +61,23 @@ function braveSearchError(status, payload) {
78
61
  return upstreamError(status, message);
79
62
  }
80
63
  async function request(ctx, path, query) {
81
- const response = await guardedFetch(buildUrl(path, query), {
64
+ const { data } = await http.request({
65
+ path,
82
66
  method: "GET",
67
+ query: Object.entries(query),
83
68
  headers: {
84
69
  "accept": "application/json",
85
70
  "x-subscription-token": requireApiKey(ctx, SERVICE)
86
- }
71
+ },
72
+ invalidJsonMessage: "Brave Search \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
73
+ mapError: ({ data: payload, status }) => braveSearchError(status, payload)
87
74
  });
88
- const body = await response.text();
89
- let payload = null;
90
- if (body !== "") {
91
- try {
92
- payload = JSON.parse(body);
93
- } catch {
94
- if (response.ok) {
95
- throw new TBError("unavailable", "Brave Search \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
96
- }
97
- }
98
- }
99
- if (!response.ok) throw braveSearchError(response.status, payload);
100
- return payload;
75
+ return data ?? null;
101
76
  }
102
77
  function normalizeWebSearch(payload) {
103
78
  const result = requireRecord(payload, "Brave Search \u54CD\u5E94");
104
- return compact({
105
- type: text(result.type) ?? "search",
79
+ return compactDefined({
80
+ type: trimmedText(result.type) ?? "search",
106
81
  query: nullableRecord(result.query),
107
82
  web: nullableRecord(result.web),
108
83
  news: nullableRecord(result.news),
@@ -118,8 +93,8 @@ function normalizeWebSearch(payload) {
118
93
  }
119
94
  function normalizeCollection(payload, withExtra) {
120
95
  const result = requireRecord(payload, "Brave Search \u54CD\u5E94");
121
- return compact({
122
- type: text(result.type) ?? "search",
96
+ return compactDefined({
97
+ type: trimmedText(result.type) ?? "search",
123
98
  query: nullableRecord(result.query),
124
99
  results: objectArray(result.results),
125
100
  extra: withExtra ? nullableRecord(result.extra) : void 0
@@ -128,19 +103,19 @@ function normalizeCollection(payload, withExtra) {
128
103
  async function webSearch(input, ctx) {
129
104
  return normalizeWebSearch(await request(ctx, "/res/v1/web/search", {
130
105
  q: searchTerm(input.q),
131
- search_lang: text(input.search_lang),
132
- ui_lang: text(input.ui_lang),
133
- country: text(input.country),
134
- safesearch: text(input.safesearch),
106
+ search_lang: trimmedText(input.search_lang),
107
+ ui_lang: trimmedText(input.ui_lang),
108
+ country: trimmedText(input.country),
109
+ safesearch: trimmedText(input.safesearch),
135
110
  count: input.count,
136
111
  offset: input.offset,
137
112
  spellcheck: input.spellcheck,
138
- freshness: text(input.freshness),
139
- result_filter: text(input.result_filter),
113
+ freshness: trimmedText(input.freshness),
114
+ result_filter: trimmedText(input.result_filter),
140
115
  extra_snippets: input.extra_snippets,
141
116
  goggles: goggles(input.goggles),
142
117
  text_decorations: input.text_decorations,
143
- units: text(input.units),
118
+ units: trimmedText(input.units),
144
119
  operators: input.operators,
145
120
  include_fetch_metadata: input.include_fetch_metadata
146
121
  }));
@@ -148,14 +123,14 @@ async function webSearch(input, ctx) {
148
123
  async function newsSearch(input, ctx) {
149
124
  const payload = await request(ctx, "/res/v1/news/search", {
150
125
  q: searchTerm(input.q),
151
- search_lang: text(input.search_lang),
152
- ui_lang: text(input.ui_lang),
153
- country: text(input.country),
154
- safesearch: text(input.safesearch),
126
+ search_lang: trimmedText(input.search_lang),
127
+ ui_lang: trimmedText(input.ui_lang),
128
+ country: trimmedText(input.country),
129
+ safesearch: trimmedText(input.safesearch),
155
130
  count: input.count,
156
131
  offset: input.offset,
157
132
  spellcheck: input.spellcheck,
158
- freshness: text(input.freshness),
133
+ freshness: trimmedText(input.freshness),
159
134
  extra_snippets: input.extra_snippets,
160
135
  goggles: goggles(input.goggles),
161
136
  operators: input.operators,
@@ -166,14 +141,14 @@ async function newsSearch(input, ctx) {
166
141
  async function videoSearch(input, ctx) {
167
142
  const payload = await request(ctx, "/res/v1/videos/search", {
168
143
  q: searchTerm(input.q),
169
- search_lang: text(input.search_lang),
170
- ui_lang: text(input.ui_lang),
171
- country: text(input.country),
172
- safesearch: text(input.safesearch),
144
+ search_lang: trimmedText(input.search_lang),
145
+ ui_lang: trimmedText(input.ui_lang),
146
+ country: trimmedText(input.country),
147
+ safesearch: trimmedText(input.safesearch),
173
148
  count: input.count,
174
149
  offset: input.offset,
175
150
  spellcheck: input.spellcheck,
176
- freshness: text(input.freshness),
151
+ freshness: trimmedText(input.freshness),
177
152
  operators: input.operators,
178
153
  include_fetch_metadata: input.include_fetch_metadata
179
154
  });
@@ -182,9 +157,9 @@ async function videoSearch(input, ctx) {
182
157
  async function imageSearch(input, ctx) {
183
158
  const payload = await request(ctx, "/res/v1/images/search", {
184
159
  q: searchTerm(input.q),
185
- search_lang: text(input.search_lang),
186
- country: text(input.country),
187
- safesearch: text(input.safesearch),
160
+ search_lang: trimmedText(input.search_lang),
161
+ country: trimmedText(input.country),
162
+ safesearch: trimmedText(input.safesearch),
188
163
  count: input.count,
189
164
  spellcheck: input.spellcheck
190
165
  });
@@ -0,0 +1,45 @@
1
+ // ../plugins/src/_runtime/jsonValue.ts
2
+ function asJsonObject(value) {
3
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
4
+ }
5
+ function trimmedText(value) {
6
+ if (typeof value !== "string") return void 0;
7
+ const trimmed = value.trim();
8
+ return trimmed === "" ? void 0 : trimmed;
9
+ }
10
+ function finiteNumber(value) {
11
+ return typeof value === "number" && Number.isFinite(value) ? value : void 0;
12
+ }
13
+ function integerValue(value) {
14
+ return typeof value === "number" && Number.isInteger(value) ? value : void 0;
15
+ }
16
+ function booleanValue(value) {
17
+ return typeof value === "boolean" ? value : void 0;
18
+ }
19
+ function compactDefined(input) {
20
+ return Object.fromEntries(
21
+ Object.entries(input).filter((entry) => entry[1] !== void 0)
22
+ );
23
+ }
24
+ function messageFrom(value, fields, fallback) {
25
+ const direct = trimmedText(value);
26
+ if (direct !== void 0) return direct;
27
+ const object = asJsonObject(value);
28
+ if (object !== void 0) {
29
+ for (const field of fields) {
30
+ const candidate = trimmedText(object[field]);
31
+ if (candidate !== void 0) return candidate;
32
+ }
33
+ }
34
+ return fallback;
35
+ }
36
+
37
+ export {
38
+ asJsonObject,
39
+ trimmedText,
40
+ finiteNumber,
41
+ integerValue,
42
+ booleanValue,
43
+ compactDefined,
44
+ messageFrom
45
+ };
@@ -0,0 +1,50 @@
1
+ // ../plugins/src/_runtime/responseBytes.ts
2
+ var BASE64_CHUNK_BYTES = 32768;
3
+ async function readBoundedResponseBytes(response, options) {
4
+ const declared = Number(response.headers.get("content-length"));
5
+ if (options.checkContentLength !== false && Number.isFinite(declared) && declared > options.maxBytes) {
6
+ await response.body?.cancel().catch(() => void 0);
7
+ throw options.tooLarge();
8
+ }
9
+ if (response.body === null) {
10
+ const bytes2 = new Uint8Array(await response.arrayBuffer());
11
+ if (bytes2.byteLength > options.maxBytes) throw options.tooLarge();
12
+ return bytes2;
13
+ }
14
+ const reader = response.body.getReader();
15
+ const chunks = [];
16
+ let total = 0;
17
+ try {
18
+ for (; ; ) {
19
+ const { done, value } = await reader.read();
20
+ if (done) break;
21
+ total += value.byteLength;
22
+ if (total > options.maxBytes) {
23
+ await reader.cancel().catch(() => void 0);
24
+ throw options.tooLarge();
25
+ }
26
+ chunks.push(value);
27
+ }
28
+ } finally {
29
+ reader.releaseLock();
30
+ }
31
+ const bytes = new Uint8Array(total);
32
+ let offset = 0;
33
+ for (const chunk of chunks) {
34
+ bytes.set(chunk, offset);
35
+ offset += chunk.byteLength;
36
+ }
37
+ return bytes;
38
+ }
39
+ function bytesToBase64(bytes) {
40
+ let binary = "";
41
+ for (let offset = 0; offset < bytes.length; offset += BASE64_CHUNK_BYTES) {
42
+ binary += String.fromCharCode(...bytes.subarray(offset, offset + BASE64_CHUNK_BYTES));
43
+ }
44
+ return btoa(binary);
45
+ }
46
+
47
+ export {
48
+ readBoundedResponseBytes,
49
+ bytesToBase64
50
+ };