@tool-bridge/server 0.1.0 → 0.3.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 (107) hide show
  1. package/dist/airtable-V6446SVY.js +792 -0
  2. package/dist/alt_text_generator_ai-HV7JZPDT.js +72 -0
  3. package/dist/amap-TTTVB6WS.js +755 -0
  4. package/dist/anthropic-JH3RA363.js +224 -0
  5. package/dist/apify-ETNN7ITU.js +262 -0
  6. package/dist/brave_search-3DDR2MMB.js +322 -0
  7. package/dist/chunk-CSJEZHQO.js +252 -0
  8. package/dist/chunk-JLTYA2B3.js +20121 -0
  9. package/dist/chunk-K7FVSFUX.js +333 -0
  10. package/dist/{chunk-6SMIQ6QU.js → chunk-KGYJEEBI.js} +2770 -21574
  11. package/dist/circleci-MX3TX3HC.js +409 -0
  12. package/dist/clerk-MRPORVF4.js +1036 -0
  13. package/dist/cloudflare_dns-OWP7DD7L.js +605 -0
  14. package/dist/cohere-GPECP66S.js +197 -0
  15. package/dist/confluence-BN7LZ6BC.js +436 -0
  16. package/dist/convertapi-SBEOFOFQ.js +161 -0
  17. package/dist/currencyapi-P2YY7Y7P.js +306 -0
  18. package/dist/deepseek-MWB3NYIN.js +205 -0
  19. package/dist/docker_hub-3JSCIGQ3.js +946 -0
  20. package/dist/dropbox-RFIBDAXO.js +1308 -0
  21. package/dist/dub-YVP57ELQ.js +706 -0
  22. package/dist/e2b-NFSUHTZR.js +305 -0
  23. package/dist/exa-KTDY6IV3.js +360 -0
  24. package/dist/fal_ai-OCUENLNQ.js +405 -0
  25. package/dist/feishu-5CWBQ7E5.js +225 -0
  26. package/dist/feishu_custom_bot-ZJR22OK6.js +240 -0
  27. package/dist/figma-YULGANSA.js +798 -0
  28. package/dist/firehydrant-2V6YSYAP.js +573 -0
  29. package/dist/fixer-LTCDB3CJ.js +171 -0
  30. package/dist/fly-IXPKMAML.js +478 -0
  31. package/dist/front-KRFB4M5X.js +379 -0
  32. package/dist/geocodio-VVURKYHQ.js +236 -0
  33. package/dist/ghost-6J2RIOUB.js +341 -0
  34. package/dist/github-5Z6KQRYH.js +5410 -0
  35. package/dist/gmail-KU4NZ7VA.js +1894 -0
  36. package/dist/googlecalendar-X44DFFXG.js +2539 -0
  37. package/dist/googledocs-WSGLPKSF.js +1322 -0
  38. package/dist/grafana-4PKSSDXY.js +817 -0
  39. package/dist/graphhopper-DF65ZNGK.js +336 -0
  40. package/dist/index.d.ts +181 -2
  41. package/dist/index.js +2 -1
  42. package/dist/ip2proxy-UCAQ5P2J.js +118 -0
  43. package/dist/ipgeolocation_io-UX6FCA2S.js +333 -0
  44. package/dist/ipqualityscore-MKTRXIZJ.js +287 -0
  45. package/dist/jina_ai-MRHPCSV5.js +119 -0
  46. package/dist/jira-EG7ZPOIW.js +627 -0
  47. package/dist/langsmith-FNO3RCOZ.js +597 -0
  48. package/dist/lemlist-SN6BJHSG.js +298 -0
  49. package/dist/linear-H3VU4PSD.js +2163 -0
  50. package/dist/logsnag-OY2JJT2H.js +167 -0
  51. package/dist/main.js +246 -2
  52. package/dist/mattermost-C5SQ7PGD.js +320 -0
  53. package/dist/mem0-LMLE5BFC.js +567 -0
  54. package/dist/memos-UWFAMBZC.js +781 -0
  55. package/dist/metabase-SRYDSDJ6.js +365 -0
  56. package/dist/mistral_ai-YNIJ7VDM.js +1195 -0
  57. package/dist/mother_duck-CPGOFEXE.js +322 -0
  58. package/dist/ngrok-CDJFBSOM.js +375 -0
  59. package/dist/notes-DIVFH3P3.js +109 -0
  60. package/dist/notion-HGDKS4HK.js +945 -0
  61. package/dist/open_exchange_rates-COHHYJDD.js +216 -0
  62. package/dist/openai-4TRT66GW.js +795 -0
  63. package/dist/opengraph_io-YKVW4PXI.js +377 -0
  64. package/dist/openrouter-6CV7B7V5.js +444 -0
  65. package/dist/outline-YWDUK5F7.js +604 -0
  66. package/dist/paddle-MEU7HWDZ.js +464 -0
  67. package/dist/perplexity-MRQUDBIC.js +238 -0
  68. package/dist/pinecone-JI7X2TAF.js +599 -0
  69. package/dist/pipedrive-6JQPAW23.js +453 -0
  70. package/dist/polar-7BF56CMC.js +400 -0
  71. package/dist/posthog-YPU5ADEN.js +3462 -0
  72. package/dist/postmark-BEU5OFKU.js +441 -0
  73. package/dist/prerender-UT5GOOZH.js +180 -0
  74. package/dist/pubmed-3SGOE24Q.js +1052 -0
  75. package/dist/railway-CEK4GLRQ.js +452 -0
  76. package/dist/readwise-DXQUQU67.js +482 -0
  77. package/dist/render-7TGAU5AW.js +473 -0
  78. package/dist/replicate-VICFSQ5A.js +347 -0
  79. package/dist/resend-3E76WK3O.js +100 -0
  80. package/dist/rootly-36GY46BY.js +345 -0
  81. package/dist/scrapfly-VDVUYAHX.js +289 -0
  82. package/dist/scrapingbee-3KTPMAVY.js +247 -0
  83. package/dist/screenshot_fyi-LKG62C3J.js +116 -0
  84. package/dist/semantic_scholar-4WREECYO.js +626 -0
  85. package/dist/sentry-HUQTGXOV.js +1139 -0
  86. package/dist/shodan-SGRKU4KS.js +303 -0
  87. package/dist/shopify-YCZ4L5HT.js +620 -0
  88. package/dist/stripe-OEBKMELB.js +583 -0
  89. package/dist/supabase-I3DBY7L4.js +937 -0
  90. package/dist/tavily-B2YHCNRD.js +349 -0
  91. package/dist/telegram-2VYJELZX.js +1773 -0
  92. package/dist/telnyx-HHXD3CXL.js +237 -0
  93. package/dist/todoist-PHFDEEIS.js +672 -0
  94. package/dist/trello-WUSAK6YN.js +1091 -0
  95. package/dist/turso-FW56U2B3.js +432 -0
  96. package/dist/twilio-M5JI7XHA.js +321 -0
  97. package/dist/umami-HAYODRC4.js +411 -0
  98. package/dist/unsplash-EDPTNEHJ.js +364 -0
  99. package/dist/upstash_redis-GC2CLIWD.js +299 -0
  100. package/dist/uptimerobot-XMSNYLIT.js +481 -0
  101. package/dist/v2ex-KU4ECD65.js +672 -0
  102. package/dist/vercel-THPCEFHW.js +1096 -0
  103. package/dist/wolfram_alpha_api-WHHTH4GU.js +212 -0
  104. package/dist/wordpress-O6TQEQNF.js +822 -0
  105. package/dist/workos-A3VHHWI3.js +681 -0
  106. package/dist/zhihu-BJAI64YJ.js +273 -0
  107. package/package.json +5 -4
@@ -0,0 +1,322 @@
1
+ import {
2
+ createProviderPlugin,
3
+ guardedFetch,
4
+ requireApiKey,
5
+ upstreamError
6
+ } from "./chunk-CSJEZHQO.js";
7
+ import "./chunk-K7FVSFUX.js";
8
+ import {
9
+ TBError,
10
+ external_exports
11
+ } from "./chunk-JLTYA2B3.js";
12
+ import "./chunk-MLKGABMK.js";
13
+
14
+ // ../plugins/src/brave_search/api.ts
15
+ var SERVICE = "brave_search";
16
+ var API_BASE = "https://api.search.brave.com";
17
+ var RATE_LIMIT_CODES = /* @__PURE__ */ new Set(["QUOTA_LIMITED", "RATE_LIMITED", "USAGE_LIMIT_EXCEEDED"]);
18
+ var AUTH_CODES = /* @__PURE__ */ new Set(["SUBSCRIPTION_TOKEN_INVALID", "SUBSCRIPTION_NOT_FOUND"]);
19
+ var INVALID_CODES = /* @__PURE__ */ new Set(["RESOURCE_NOT_ALLOWED", "OPTION_NOT_IN_PLAN", "INVALID_URL"]);
20
+ function text(value) {
21
+ if (typeof value !== "string") return void 0;
22
+ const trimmed = value.trim();
23
+ return trimmed === "" ? void 0 : trimmed;
24
+ }
25
+ function record(value) {
26
+ return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
27
+ }
28
+ function nullableRecord(value) {
29
+ return value === null ? null : record(value);
30
+ }
31
+ function requireRecord(value, label) {
32
+ const result = record(value);
33
+ if (result === void 0) {
34
+ throw new TBError("unavailable", `${label}\u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
35
+ }
36
+ return result;
37
+ }
38
+ function objectArray(value) {
39
+ if (!Array.isArray(value)) return void 0;
40
+ return value.map((item) => requireRecord(item, "Brave Search \u7ED3\u679C\u9879"));
41
+ }
42
+ function compact(input) {
43
+ return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
44
+ }
45
+ function searchTerm(value) {
46
+ const term = text(value);
47
+ if (term === void 0) throw new TBError("invalid_argument", "q \u4E0D\u80FD\u662F\u7A7A\u767D");
48
+ return term;
49
+ }
50
+ function goggles(value) {
51
+ if (value === void 0 || typeof value === "string") return text(value);
52
+ const items = value.map((item) => text(item)).filter((item) => item !== void 0);
53
+ return items.length > 0 ? items : void 0;
54
+ }
55
+ function buildUrl(path, query) {
56
+ const url = new URL(`${API_BASE}${path}`);
57
+ for (const [key, value] of Object.entries(query)) {
58
+ if (value === void 0) continue;
59
+ if (Array.isArray(value)) {
60
+ for (const item of value) url.searchParams.append(key, item);
61
+ continue;
62
+ }
63
+ url.searchParams.set(key, String(value));
64
+ }
65
+ return url.toString();
66
+ }
67
+ function braveSearchError(status, payload) {
68
+ const error = record(record(payload)?.error);
69
+ const message = text(error?.detail) ?? text(error?.code) ?? `Brave Search \u8FD4\u56DE HTTP ${status}`;
70
+ const code = text(error?.code);
71
+ if (code !== void 0) {
72
+ if (RATE_LIMIT_CODES.has(code)) return upstreamError(429, message);
73
+ if (AUTH_CODES.has(code)) return upstreamError(401, message);
74
+ if (INVALID_CODES.has(code)) return upstreamError(400, message);
75
+ }
76
+ return upstreamError(status, message);
77
+ }
78
+ async function request(ctx, path, query) {
79
+ const response = await guardedFetch(buildUrl(path, query), {
80
+ method: "GET",
81
+ headers: {
82
+ "accept": "application/json",
83
+ "x-subscription-token": requireApiKey(ctx, SERVICE)
84
+ }
85
+ });
86
+ const body = await response.text();
87
+ let payload = null;
88
+ if (body !== "") {
89
+ try {
90
+ payload = JSON.parse(body);
91
+ } catch {
92
+ if (response.ok) {
93
+ throw new TBError("unavailable", "Brave Search \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
94
+ }
95
+ }
96
+ }
97
+ if (!response.ok) throw braveSearchError(response.status, payload);
98
+ return payload;
99
+ }
100
+ function normalizeWebSearch(payload) {
101
+ const result = requireRecord(payload, "Brave Search \u54CD\u5E94");
102
+ return compact({
103
+ type: text(result.type) ?? "search",
104
+ query: nullableRecord(result.query),
105
+ web: nullableRecord(result.web),
106
+ news: nullableRecord(result.news),
107
+ videos: nullableRecord(result.videos),
108
+ locations: nullableRecord(result.locations),
109
+ discussions: nullableRecord(result.discussions),
110
+ faq: nullableRecord(result.faq),
111
+ infobox: nullableRecord(result.infobox),
112
+ mixed: nullableRecord(result.mixed),
113
+ summarizer: nullableRecord(result.summarizer),
114
+ rich: nullableRecord(result.rich)
115
+ });
116
+ }
117
+ function normalizeCollection(payload, withExtra) {
118
+ const result = requireRecord(payload, "Brave Search \u54CD\u5E94");
119
+ return compact({
120
+ type: text(result.type) ?? "search",
121
+ query: nullableRecord(result.query),
122
+ results: objectArray(result.results),
123
+ extra: withExtra ? nullableRecord(result.extra) : void 0
124
+ });
125
+ }
126
+ async function webSearch(input, ctx) {
127
+ return normalizeWebSearch(await request(ctx, "/res/v1/web/search", {
128
+ q: searchTerm(input.q),
129
+ search_lang: text(input.search_lang),
130
+ ui_lang: text(input.ui_lang),
131
+ country: text(input.country),
132
+ safesearch: text(input.safesearch),
133
+ count: input.count,
134
+ offset: input.offset,
135
+ spellcheck: input.spellcheck,
136
+ freshness: text(input.freshness),
137
+ result_filter: text(input.result_filter),
138
+ extra_snippets: input.extra_snippets,
139
+ goggles: goggles(input.goggles),
140
+ text_decorations: input.text_decorations,
141
+ units: text(input.units),
142
+ operators: input.operators,
143
+ include_fetch_metadata: input.include_fetch_metadata
144
+ }));
145
+ }
146
+ async function newsSearch(input, ctx) {
147
+ const payload = await request(ctx, "/res/v1/news/search", {
148
+ q: searchTerm(input.q),
149
+ search_lang: text(input.search_lang),
150
+ ui_lang: text(input.ui_lang),
151
+ country: text(input.country),
152
+ safesearch: text(input.safesearch),
153
+ count: input.count,
154
+ offset: input.offset,
155
+ spellcheck: input.spellcheck,
156
+ freshness: text(input.freshness),
157
+ extra_snippets: input.extra_snippets,
158
+ goggles: goggles(input.goggles),
159
+ operators: input.operators,
160
+ include_fetch_metadata: input.include_fetch_metadata
161
+ });
162
+ return normalizeCollection(payload, false);
163
+ }
164
+ async function videoSearch(input, ctx) {
165
+ const payload = await request(ctx, "/res/v1/videos/search", {
166
+ q: searchTerm(input.q),
167
+ search_lang: text(input.search_lang),
168
+ ui_lang: text(input.ui_lang),
169
+ country: text(input.country),
170
+ safesearch: text(input.safesearch),
171
+ count: input.count,
172
+ offset: input.offset,
173
+ spellcheck: input.spellcheck,
174
+ freshness: text(input.freshness),
175
+ operators: input.operators,
176
+ include_fetch_metadata: input.include_fetch_metadata
177
+ });
178
+ return normalizeCollection(payload, true);
179
+ }
180
+ async function imageSearch(input, ctx) {
181
+ const payload = await request(ctx, "/res/v1/images/search", {
182
+ q: searchTerm(input.q),
183
+ search_lang: text(input.search_lang),
184
+ country: text(input.country),
185
+ safesearch: text(input.safesearch),
186
+ count: input.count,
187
+ spellcheck: input.spellcheck
188
+ });
189
+ return normalizeCollection(payload, true);
190
+ }
191
+
192
+ // ../plugins/src/brave_search/schema.ts
193
+ var webSearchInput = external_exports.strictObject({
194
+ q: external_exports.string().min(1).max(400).describe("The user's search query term. Maximum of 400 characters."),
195
+ search_lang: external_exports.string().min(2).describe("The preferred search result language code.").optional(),
196
+ ui_lang: external_exports.string().min(2).describe("The preferred user interface language for response formatting.").optional(),
197
+ country: external_exports.string().min(2).max(3).describe("The two-letter country code for result localization, or ALL for worldwide results.").optional(),
198
+ safesearch: external_exports.enum(["off", "moderate", "strict"]).describe("Filters adult content from web results.").optional(),
199
+ count: external_exports.int().min(1).max(20).describe("The maximum number of web results to return.").optional(),
200
+ offset: external_exports.int().min(0).max(9).describe("The zero-based results page offset used for pagination.").optional(),
201
+ spellcheck: external_exports.boolean().describe("Whether Brave Search should spellcheck the query before searching.").optional(),
202
+ freshness: external_exports.union([external_exports.enum(["pd", "pw", "pm", "py"]).describe("A predefined freshness window such as past day or past year."), external_exports.string().min(1).describe("A custom date range in the format YYYY-MM-DDtoYYYY-MM-DD.")]).describe("Filters web results by page age.").optional(),
203
+ result_filter: external_exports.string().min(1).describe("A comma-delimited list of result types to include, such as web,news,videos,locations,discussions,faq,infobox,mixed,summarizer or rich.").optional(),
204
+ extra_snippets: external_exports.boolean().describe("Whether Brave Search should return extra alternate snippets.").optional(),
205
+ goggles: external_exports.union([external_exports.string().min(1).describe("One goggle URL or inline definition."), external_exports.array(external_exports.string().min(1).describe("One goggle URL or inline definition.")).min(1).describe("Multiple goggles to apply to the search request.")]).describe("One or more Brave Search goggles used to rerank results.").optional(),
206
+ text_decorations: external_exports.boolean().describe("Whether display strings should include decoration markers such as highlights.").optional(),
207
+ units: external_exports.enum(["metric", "imperial"]).describe("The measurement units used for localized results.").optional(),
208
+ operators: external_exports.boolean().describe("Whether Brave Search should apply search operators.").optional(),
209
+ include_fetch_metadata: external_exports.boolean().describe("Whether Brave Search should include fetch metadata in results when available.").optional()
210
+ }).describe("Input parameters for a Brave Search web search request.");
211
+ var webSearchOutput = external_exports.strictObject({
212
+ type: external_exports.string().describe("The Brave Search response type."),
213
+ query: external_exports.looseObject({}).describe("Query metadata returned by Brave Search.").nullable().optional(),
214
+ web: external_exports.looseObject({}).describe("Web result payload returned by Brave Search.").nullable().optional(),
215
+ news: external_exports.looseObject({}).describe("News result payload returned by Brave Search.").nullable().optional(),
216
+ videos: external_exports.looseObject({}).describe("Video result payload returned by Brave Search.").nullable().optional(),
217
+ locations: external_exports.looseObject({}).describe("Location result payload returned by Brave Search.").nullable().optional(),
218
+ discussions: external_exports.looseObject({}).describe("Discussion clusters returned by Brave Search.").nullable().optional(),
219
+ faq: external_exports.looseObject({}).describe("Frequently asked questions returned by Brave Search.").nullable().optional(),
220
+ infobox: external_exports.looseObject({}).describe("Infobox payload returned by Brave Search.").nullable().optional(),
221
+ mixed: external_exports.looseObject({}).describe("Mixed ranking payload returned by Brave Search.").nullable().optional(),
222
+ summarizer: external_exports.looseObject({}).describe("Summary metadata returned by Brave Search.").nullable().optional(),
223
+ rich: external_exports.looseObject({}).describe("Rich result callback payload returned by Brave Search.").nullable().optional()
224
+ }).describe("A normalized Brave Search web search response.");
225
+ var newsSearchInput = external_exports.strictObject({
226
+ q: external_exports.string().min(1).max(400).describe("The user's search query term. Maximum of 400 characters."),
227
+ search_lang: external_exports.string().min(2).describe("The preferred search result language code.").optional(),
228
+ ui_lang: external_exports.string().min(2).describe("The preferred user interface language for response formatting.").optional(),
229
+ country: external_exports.string().min(2).max(3).describe("The two-letter country code for result localization, or ALL for worldwide results.").optional(),
230
+ safesearch: external_exports.enum(["off", "moderate", "strict"]).describe("Filters adult content from news results.").optional(),
231
+ count: external_exports.int().min(1).max(50).describe("The maximum number of results to return.").optional(),
232
+ offset: external_exports.int().min(0).max(9).describe("The zero-based results page offset used for pagination.").optional(),
233
+ spellcheck: external_exports.boolean().describe("Whether Brave Search should spellcheck the query before searching.").optional(),
234
+ freshness: external_exports.union([external_exports.enum(["pd", "pw", "pm", "py"]).describe("A predefined freshness window such as past day or past year."), external_exports.string().min(1).describe("A custom date range in the format YYYY-MM-DDtoYYYY-MM-DD.")]).describe("Filters news results by page age.").optional(),
235
+ extra_snippets: external_exports.boolean().describe("Whether Brave Search should return extra alternate snippets.").optional(),
236
+ goggles: external_exports.union([external_exports.string().min(1).describe("One goggle URL or inline definition."), external_exports.array(external_exports.string().min(1).describe("One goggle URL or inline definition.")).min(1).describe("Multiple goggles to apply to the search request.")]).describe("One or more Brave Search goggles used to rerank results.").optional(),
237
+ operators: external_exports.boolean().describe("Whether Brave Search should apply search operators.").optional(),
238
+ include_fetch_metadata: external_exports.boolean().describe("Whether Brave Search should include fetch metadata in results when available.").optional()
239
+ }).describe("Input parameters for a Brave Search news request.");
240
+ var newsSearchOutput = external_exports.strictObject({
241
+ type: external_exports.string().describe("The Brave Search response type."),
242
+ query: external_exports.looseObject({}).describe("Query metadata returned by Brave Search.").nullable().optional(),
243
+ results: external_exports.array(external_exports.looseObject({}).describe("One news result item returned by Brave Search.")).describe("The list of news results returned by Brave Search.").optional()
244
+ }).describe("A normalized Brave Search news response.");
245
+ var videoSearchInput = external_exports.strictObject({
246
+ q: external_exports.string().min(1).max(400).describe("The user's search query term. Maximum of 400 characters."),
247
+ search_lang: external_exports.string().min(2).describe("The preferred search result language code.").optional(),
248
+ ui_lang: external_exports.string().min(2).describe("The preferred user interface language for response formatting.").optional(),
249
+ country: external_exports.string().min(2).max(3).describe("The two-letter country code for result localization, or ALL for worldwide results.").optional(),
250
+ safesearch: external_exports.enum(["off", "moderate", "strict"]).describe("Filters adult content from video results.").optional(),
251
+ count: external_exports.int().min(1).max(50).describe("The maximum number of results to return.").optional(),
252
+ offset: external_exports.int().min(0).max(9).describe("The zero-based results page offset used for pagination.").optional(),
253
+ spellcheck: external_exports.boolean().describe("Whether Brave Search should spellcheck the query before searching.").optional(),
254
+ freshness: external_exports.union([external_exports.enum(["pd", "pw", "pm", "py"]).describe("A predefined freshness window such as past day or past year."), external_exports.string().min(1).describe("A custom date range in the format YYYY-MM-DDtoYYYY-MM-DD.")]).describe("Filters video results by page age.").optional(),
255
+ operators: external_exports.boolean().describe("Whether Brave Search should apply search operators.").optional(),
256
+ include_fetch_metadata: external_exports.boolean().describe("Whether Brave Search should include fetch metadata in results when available.").optional()
257
+ }).describe("Input parameters for a Brave Search video request.");
258
+ var videoSearchOutput = external_exports.strictObject({
259
+ type: external_exports.string().describe("The Brave Search response type."),
260
+ query: external_exports.looseObject({}).describe("Query metadata returned by Brave Search.").nullable().optional(),
261
+ results: external_exports.array(external_exports.looseObject({}).describe("One video result item returned by Brave Search.")).describe("The list of video results returned by Brave Search.").optional(),
262
+ extra: external_exports.looseObject({}).describe("Additional metadata returned with the video results.").nullable().optional()
263
+ }).describe("A normalized Brave Search video response.");
264
+ var imageSearchInput = external_exports.strictObject({
265
+ q: external_exports.string().min(1).max(400).describe("The user's search query term. Maximum of 400 characters."),
266
+ search_lang: external_exports.string().min(2).describe("The preferred search result language code.").optional(),
267
+ country: external_exports.string().min(2).max(3).describe("The two-letter country code for result localization, or ALL for worldwide results.").optional(),
268
+ safesearch: external_exports.enum(["off", "strict"]).describe("Filters adult content from image results.").optional(),
269
+ count: external_exports.int().min(1).max(200).describe("The maximum number of image results to return.").optional(),
270
+ spellcheck: external_exports.boolean().describe("Whether Brave Search should spellcheck the query before searching.").optional()
271
+ }).describe("Input parameters for a Brave Search image request.");
272
+ var imageSearchOutput = external_exports.strictObject({
273
+ type: external_exports.string().describe("The Brave Search response type."),
274
+ query: external_exports.looseObject({}).describe("Query metadata returned by Brave Search.").nullable().optional(),
275
+ results: external_exports.array(external_exports.looseObject({}).describe("One image result item returned by Brave Search.")).describe("The list of image results returned by Brave Search.").optional(),
276
+ extra: external_exports.looseObject({}).describe("Additional metadata returned with the image results.").nullable().optional()
277
+ }).describe("A normalized Brave Search image response.");
278
+ var braveSearchActions = {
279
+ web_search: {
280
+ description: "Search the Brave Search web index and return the selected result families.",
281
+ effect: "write",
282
+ inputSchema: webSearchInput,
283
+ outputSchema: external_exports.toJSONSchema(webSearchOutput, { io: "output", unrepresentable: "any" })
284
+ },
285
+ news_search: {
286
+ description: "Search Brave's news index for recent articles related to a query.",
287
+ effect: "write",
288
+ inputSchema: newsSearchInput,
289
+ outputSchema: external_exports.toJSONSchema(newsSearchOutput, { io: "output", unrepresentable: "any" })
290
+ },
291
+ video_search: {
292
+ description: "Search Brave's video index for videos related to a query.",
293
+ effect: "write",
294
+ inputSchema: videoSearchInput,
295
+ outputSchema: external_exports.toJSONSchema(videoSearchOutput, { io: "output", unrepresentable: "any" })
296
+ },
297
+ image_search: {
298
+ description: "Search Brave's image index for images related to a query.",
299
+ effect: "write",
300
+ inputSchema: imageSearchInput,
301
+ outputSchema: external_exports.toJSONSchema(imageSearchOutput, { io: "output", unrepresentable: "any" })
302
+ }
303
+ };
304
+
305
+ // ../plugins/src/brave_search/index.ts
306
+ function createBraveSearchPlugin() {
307
+ return createProviderPlugin({
308
+ description: "Brave Search",
309
+ actions: braveSearchActions,
310
+ handlers: {
311
+ web_search: webSearch,
312
+ news_search: newsSearch,
313
+ video_search: videoSearch,
314
+ image_search: imageSearch
315
+ }
316
+ });
317
+ }
318
+ var brave_search_default = createBraveSearchPlugin();
319
+ export {
320
+ createBraveSearchPlugin,
321
+ brave_search_default as default
322
+ };
@@ -0,0 +1,252 @@
1
+ import {
2
+ createPlugin
3
+ } from "./chunk-K7FVSFUX.js";
4
+ import {
5
+ TBError
6
+ } from "./chunk-JLTYA2B3.js";
7
+
8
+ // ../plugins/src/_runtime/plugin.ts
9
+ function requireApiKey(ctx, service) {
10
+ const key = ctx.upstreamAuth;
11
+ if (key === void 0 || key === "") {
12
+ throw new TBError(
13
+ "unavailable",
14
+ `${service} \u9700\u8981 API key:\u7ED9\u6302\u8F7D\u8282\u70B9\u914D config.authRef \u6307\u5411\u5DF2\u5B58\u5165 system/secret \u7684\u51ED\u8BC1`
15
+ );
16
+ }
17
+ return key;
18
+ }
19
+ function requireCredential(ctx, service, field) {
20
+ const values = ctx.credentials;
21
+ if (values === void 0) {
22
+ throw new TBError(
23
+ "unavailable",
24
+ `${service} \u9700\u8981\u591A\u5B57\u6BB5\u51ED\u8BC1:\u7ED9\u6302\u8F7D\u8282\u70B9\u914D config.authRef \u6307\u5411\u5DF2\u5B58\u5165 system/secret \u7684\u51ED\u8BC1(\u7528 \`tb secret set <name> --field ...\` \u5199\u5165)`
25
+ );
26
+ }
27
+ const value = values[field];
28
+ if (value === void 0 || value === "") {
29
+ throw new TBError("internal", `${service} \u7684\u51ED\u8BC1\u5B57\u6BB5 '${field}' \u672A\u5728 credentialFields \u91CC\u58F0\u660E`);
30
+ }
31
+ return value;
32
+ }
33
+ function createProviderPlugin(input) {
34
+ const names = Object.keys(input.actions);
35
+ const handlerNames = Object.keys(input.handlers);
36
+ const missing = names.filter((name) => !handlerNames.includes(name));
37
+ const extra = handlerNames.filter((name) => !names.includes(name));
38
+ if (missing.length > 0 || extra.length > 0) {
39
+ throw new Error(
40
+ `action \u8868\u4E0E handler \u8868\u4E0D\u543B\u5408:\u7F3A handler [${missing.join(", ")}];\u591A\u4F59 handler [${extra.join(", ")}]`
41
+ );
42
+ }
43
+ const plugin = createPlugin({ token: (env) => env.PLUGIN_TOKEN });
44
+ const tools = plugin.tools(input.exportId ?? "actions", { description: input.description });
45
+ if (input.oauth !== void 0) tools.oauth(input.oauth);
46
+ if (input.credentialFields !== void 0) tools.credentials(input.credentialFields);
47
+ for (const name of names) {
48
+ tools.register(name, input.actions[name], (args, ctx) => input.handlers[name](args, {
49
+ upstreamAuth: ctx.upstreamAuth,
50
+ credentials: ctx.credentials,
51
+ config: ctx.mountConfig
52
+ }));
53
+ }
54
+ if (input.credentialProbe !== void 0) {
55
+ const effect = input.actions[input.credentialProbe]?.effect;
56
+ if (effect !== "read") {
57
+ throw new Error(
58
+ `credentialProbe '${input.credentialProbe}' \u7684 effect \u662F '${effect ?? "\u672A\u58F0\u660E"}', \u63A2\u9488\u5FC5\u987B\u662F read \u2014\u2014 \u6302\u8F7D\u65F6\u4F1A\u771F\u5B9E\u8C03\u7528\u5B83`
59
+ );
60
+ }
61
+ tools.probeCredentialWith(input.credentialProbe);
62
+ }
63
+ return plugin;
64
+ }
65
+
66
+ // ../plugins/src/_runtime/upstreamError.ts
67
+ function upstreamError(status, message) {
68
+ if (status === 401) {
69
+ return new TBError("permission_denied", message, { httpStatus: 401 });
70
+ }
71
+ if (status === 403) return new TBError("permission_denied", message);
72
+ if (status === 404) return new TBError("not_found", message);
73
+ if (status === 409) return new TBError("conflict", message);
74
+ if (status === 429) return new TBError("rate_limited", message, { retryable: true });
75
+ if (status >= 500) return new TBError("unavailable", message, { retryable: true });
76
+ return new TBError("invalid_argument", message);
77
+ }
78
+
79
+ // ../plugins/src/_runtime/ipPolicy.ts
80
+ function parseIpv4(value) {
81
+ const parts = value.split(".");
82
+ if (parts.length !== 4) return void 0;
83
+ let result = 0;
84
+ for (const part of parts) {
85
+ if (!/^\d{1,3}$/.test(part) || part.length > 1 && part.startsWith("0")) return void 0;
86
+ const octet = Number(part);
87
+ if (octet > 255) return void 0;
88
+ result = result << 8 | octet;
89
+ }
90
+ return result >>> 0;
91
+ }
92
+ function parseIpv6(value) {
93
+ let text = value;
94
+ if (text.startsWith("[") && text.endsWith("]")) text = text.slice(1, -1);
95
+ const zone = text.indexOf("%");
96
+ if (zone !== -1) text = text.slice(0, zone);
97
+ if (!text.includes(":")) return void 0;
98
+ const halves = text.split("::");
99
+ if (halves.length > 2) return void 0;
100
+ const expand = (part) => {
101
+ if (part === "") return [];
102
+ const groups2 = [];
103
+ const chunks = part.split(":");
104
+ for (let i = 0; i < chunks.length; i += 1) {
105
+ const chunk = chunks[i];
106
+ if (i === chunks.length - 1 && chunk.includes(".")) {
107
+ const v4 = parseIpv4(chunk);
108
+ if (v4 === void 0) return void 0;
109
+ groups2.push(v4 >>> 16 & 65535, v4 & 65535);
110
+ continue;
111
+ }
112
+ if (!/^[0-9a-fA-F]{1,4}$/.test(chunk)) return void 0;
113
+ groups2.push(Number.parseInt(chunk, 16));
114
+ }
115
+ return groups2;
116
+ };
117
+ const head = expand(halves[0] ?? "");
118
+ const tail = halves.length === 2 ? expand(halves[1] ?? "") : [];
119
+ if (head === void 0 || tail === void 0) return void 0;
120
+ const missing = 8 - head.length - tail.length;
121
+ if (halves.length === 2 ? missing < 0 : missing !== 0) return void 0;
122
+ const groups = [...head, ...Array.from({ length: halves.length === 2 ? missing : 0 }, () => 0), ...tail];
123
+ if (groups.length !== 8) return void 0;
124
+ const bytes = new Uint8Array(16);
125
+ groups.forEach((group, i) => {
126
+ bytes[i * 2] = group >>> 8 & 255;
127
+ bytes[i * 2 + 1] = group & 255;
128
+ });
129
+ return bytes;
130
+ }
131
+ function classifyIpv4(value) {
132
+ const a = value >>> 24 & 255;
133
+ const b = value >>> 16 & 255;
134
+ const c = value >>> 8 & 255;
135
+ if (a === 0) return "blocked";
136
+ if (a === 10) return "blocked";
137
+ if (a === 127) return "blocked";
138
+ if (a === 169 && b === 254) return "blocked";
139
+ if (a === 172 && b >= 16 && b <= 31) return "blocked";
140
+ if (a === 192 && b === 0 && c === 0) return "blocked";
141
+ if (a === 192 && b === 0 && c === 2) return "blocked";
142
+ if (a === 192 && b === 168) return "blocked";
143
+ if (a === 198 && (b === 18 || b === 19)) return "blocked";
144
+ if (a === 198 && b === 51 && c === 100) return "blocked";
145
+ if (a === 203 && b === 0 && c === 113) return "blocked";
146
+ if (a === 100 && b >= 64 && b <= 127) return "blocked";
147
+ if (a >= 224) return "blocked";
148
+ return "public";
149
+ }
150
+ function classifyIpv6(bytes) {
151
+ const isZero = bytes.every((byte) => byte === 0);
152
+ if (isZero) return "blocked";
153
+ if (bytes.slice(0, 15).every((byte) => byte === 0) && bytes[15] === 1) return "blocked";
154
+ const v4Mapped = bytes.slice(0, 10).every((byte) => byte === 0) && (bytes[10] === 255 && bytes[11] === 255 || bytes[10] === 0 && bytes[11] === 0);
155
+ if (v4Mapped) {
156
+ const v4 = (bytes[12] << 24 | bytes[13] << 16 | bytes[14] << 8 | bytes[15]) >>> 0;
157
+ return classifyIpv4(v4);
158
+ }
159
+ const first = bytes[0];
160
+ if ((first & 254) === 252) return "blocked";
161
+ if (first === 254 && (bytes[1] & 192) === 128) return "blocked";
162
+ if (first === 255) return "blocked";
163
+ if (first === 32 && bytes[1] === 1 && bytes[2] === 13 && bytes[3] === 184) return "blocked";
164
+ return "public";
165
+ }
166
+ function isIpAddress(value) {
167
+ return parseIpv4(value) !== void 0 || parseIpv6(value) !== void 0;
168
+ }
169
+ function classifyIpAddress(address) {
170
+ const v4 = parseIpv4(address);
171
+ if (v4 !== void 0) return classifyIpv4(v4);
172
+ const v6 = parseIpv6(address);
173
+ if (v6 !== void 0) return classifyIpv6(v6);
174
+ return "blocked";
175
+ }
176
+
177
+ // ../plugins/src/_runtime/guardedFetch.ts
178
+ var MAX_REDIRECTS = 5;
179
+ var CROSS_ORIGIN_STRIPPED_HEADERS = [
180
+ "authorization",
181
+ "cookie",
182
+ "proxy-authorization"
183
+ // 各家自定义的密钥头没有统一命名,凡是名字里带 key/token/secret 的一律剥掉:
184
+ // 宁可让跨源跳转少带一个无关头,也不能漏带走一个凭证。
185
+ ];
186
+ function looksLikeCredentialHeader(name) {
187
+ return /(?:^|-)(?:api[-_]?key|key|token|secret|auth)(?:$|-)/i.test(name);
188
+ }
189
+ function stripCredentials(headers) {
190
+ const next = new Headers(headers);
191
+ for (const [name] of headers) {
192
+ if (CROSS_ORIGIN_STRIPPED_HEADERS.includes(name.toLowerCase()) || looksLikeCredentialHeader(name)) {
193
+ next.delete(name);
194
+ }
195
+ }
196
+ return next;
197
+ }
198
+ var EgressBlockedError = class extends TBError {
199
+ constructor(message) {
200
+ super("invalid_argument", message);
201
+ this.name = "EgressBlockedError";
202
+ }
203
+ };
204
+ function assertPublicHttpUrl(value) {
205
+ let url;
206
+ try {
207
+ url = value instanceof URL ? value : new URL(value);
208
+ } catch {
209
+ throw new EgressBlockedError(`\u51FA\u7AD9\u76EE\u6807\u4E0D\u662F\u5408\u6CD5 URL: ${String(value)}`);
210
+ }
211
+ if (url.protocol !== "https:" && url.protocol !== "http:") {
212
+ throw new EgressBlockedError(`\u51FA\u7AD9\u76EE\u6807\u534F\u8BAE\u4E0D\u88AB\u5141\u8BB8: ${url.protocol}`);
213
+ }
214
+ const hostname = url.hostname.startsWith("[") && url.hostname.endsWith("]") ? url.hostname.slice(1, -1) : url.hostname;
215
+ if (hostname === "") throw new EgressBlockedError("\u51FA\u7AD9\u76EE\u6807\u7F3A\u5C11\u4E3B\u673A\u540D");
216
+ if (isIpAddress(hostname) && classifyIpAddress(hostname) === "blocked") {
217
+ throw new EgressBlockedError("\u51FA\u7AD9\u76EE\u6807\u6307\u5411\u79C1\u6709\u6216\u4FDD\u7559\u5730\u5740");
218
+ }
219
+ return url;
220
+ }
221
+ function createGuardedFetch(options = {}) {
222
+ const maxRedirects = options.maxRedirects ?? MAX_REDIRECTS;
223
+ return async function guardedFetch2(input, init) {
224
+ const transport = options.fetch ?? globalThis.fetch;
225
+ const initial = input instanceof Request ? input.url : String(input);
226
+ let url = assertPublicHttpUrl(initial);
227
+ let request = input instanceof Request ? new Request(url, new Request(input, init)) : new Request(url, { ...init, redirect: "manual" });
228
+ for (let hop = 0; ; hop += 1) {
229
+ const response = await transport(new Request(request, { redirect: "manual" }));
230
+ const location = response.headers.get("location");
231
+ if (response.status < 300 || response.status > 399 || location === null) return response;
232
+ if (hop >= maxRedirects) {
233
+ throw new EgressBlockedError(`\u51FA\u7AD9\u91CD\u5B9A\u5411\u8D85\u8FC7 ${maxRedirects} \u8DF3`);
234
+ }
235
+ const previousOrigin = new URL(request.url).origin;
236
+ url = assertPublicHttpUrl(new URL(location, url));
237
+ const headers = url.origin === previousOrigin ? request.headers : stripCredentials(request.headers);
238
+ const downgrade = response.status === 303 || (response.status === 301 || response.status === 302) && request.method !== "GET";
239
+ request = downgrade ? new Request(url, { method: "GET", headers, redirect: "manual" }) : new Request(url, { ...request, headers, redirect: "manual" });
240
+ }
241
+ };
242
+ }
243
+ var guardedFetch = createGuardedFetch();
244
+
245
+ export {
246
+ requireApiKey,
247
+ requireCredential,
248
+ createProviderPlugin,
249
+ upstreamError,
250
+ assertPublicHttpUrl,
251
+ guardedFetch
252
+ };