@tool-bridge/server 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{airtable-ZNWHIJMO.js → airtable-DMJEEGJP.js} +19 -16
- package/dist/{alt_text_generator_ai-X7RMDDM5.js → alt_text_generator_ai-RELFQ5FV.js} +4 -4
- package/dist/{amap-3VER75VH.js → amap-YSYEACKQ.js} +4 -4
- package/dist/{anthropic-N7NTB3UC.js → anthropic-D5X5GSYE.js} +23 -25
- package/dist/{apify-JB5P5AJI.js → apify-5NVFU3IZ.js} +20 -19
- package/dist/{brave_search-USL5OOBS.js → brave_search-X557FMGO.js} +16 -14
- package/dist/chunk-JEWFX6Z6.js +71 -0
- package/dist/{chunk-RVUERWUZ.js → chunk-MDY7K5CX.js} +748 -788
- package/dist/{chunk-WIGQCP6O.js → chunk-MZCIPUNQ.js} +141 -176
- package/dist/{chunk-6X55ALDX.js → chunk-Q74GLIDK.js} +3 -3
- package/dist/{chunk-6ANLYNFB.js → chunk-QR4LK3HF.js} +1 -1
- package/dist/{chunk-3WL6EXYX.js → chunk-ZTTN6AJG.js} +1 -1
- package/dist/{circleci-LBGB25LP.js → circleci-3P3QTUX2.js} +20 -24
- package/dist/{clerk-6RX37CNZ.js → clerk-GNMZQ2MY.js} +22 -21
- package/dist/{cloudflare_dns-NQGW7FHV.js → cloudflare_dns-VWZH3ZTR.js} +21 -17
- package/dist/{cohere-XPC2NAEW.js → cohere-C7QVIIMG.js} +19 -17
- package/dist/{confluence-ZUG2LT5A.js → confluence-52I37IUT.js} +16 -11
- package/dist/{convertapi-ZLXKWV3L.js → convertapi-3TRJ3WEO.js} +3 -3
- package/dist/{currencyapi-T3A3HSOD.js → currencyapi-LWEANWVI.js} +23 -26
- package/dist/{deepseek-NJMOD23E.js → deepseek-5U24YG4P.js} +27 -17
- package/dist/{docker_hub-D2MQCSJ7.js → docker_hub-CMISLRSE.js} +4 -4
- package/dist/{dropbox-MI6U3SOT.js → dropbox-TW4QN6FT.js} +9 -8
- package/dist/{dub-P2BYBYV4.js → dub-EFXGI5UH.js} +22 -19
- package/dist/{e2b-BGKIAE54.js → e2b-PHM63OVF.js} +20 -20
- package/dist/{exa-EUY7VV4C.js → exa-DYOQWURR.js} +22 -25
- package/dist/{fal_ai-AAOG5FYJ.js → fal_ai-VJPMCNRH.js} +18 -17
- package/dist/{feishu-AN5IJYOW.js → feishu-TFIZXPIN.js} +2 -2
- package/dist/{feishu_custom_bot-BWGMNVXF.js → feishu_custom_bot-ADSE23KU.js} +3 -3
- package/dist/{figma-SJSWYCGD.js → figma-4AK47AYY.js} +21 -23
- package/dist/{firehydrant-MOXK2PST.js → firehydrant-RGPTW4EA.js} +15 -15
- package/dist/{fixer-ISIDUDZU.js → fixer-OAMF4DKP.js} +4 -4
- package/dist/{fly-U4KPSGBF.js → fly-YB4AQD4O.js} +20 -16
- package/dist/{front-ZHM2YX2E.js → front-6GTVYKUM.js} +20 -23
- package/dist/{geocodio-SVCCAXAV.js → geocodio-YRT4K25M.js} +4 -4
- package/dist/{ghost-INTR7FIY.js → ghost-JCW6UIP2.js} +4 -4
- package/dist/{github-T275VVWR.js → github-CEGVRMNX.js} +28 -27
- package/dist/{gmail-KSSPOE67.js → gmail-JCMJD55P.js} +17 -17
- package/dist/{googlecalendar-JB5RW27L.js → googlecalendar-2EAW4MNM.js} +16 -14
- package/dist/{googledocs-G522PUGW.js → googledocs-YNKKBM6Q.js} +3 -3
- package/dist/{grafana-44ZPIV5P.js → grafana-353VSGXN.js} +24 -25
- package/dist/{graphhopper-2MORXLOW.js → graphhopper-H3IVJNDS.js} +4 -4
- package/dist/index.d.ts +31 -30
- package/dist/index.js +3 -3
- package/dist/{ip2proxy-R4K4KEMI.js → ip2proxy-DBGRWH7S.js} +4 -4
- package/dist/{ipgeolocation_io-H4J55OGI.js → ipgeolocation_io-5I2BDVMG.js} +4 -4
- package/dist/{ipqualityscore-XGID4OHA.js → ipqualityscore-ILV7TQCV.js} +4 -4
- package/dist/{jina_ai-7ZVDOR3Z.js → jina_ai-L5BH455V.js} +20 -21
- package/dist/{jira-CTIYZTT3.js → jira-IGTILUZA.js} +20 -16
- package/dist/{langsmith-ISP567FS.js → langsmith-BYRX4AOF.js} +25 -25
- package/dist/{lemlist-OGKK272F.js → lemlist-ZGNYTIQO.js} +23 -24
- package/dist/{linear-6JX4E3JI.js → linear-HLGOWISN.js} +3 -3
- package/dist/{logsnag-BVB36ZCL.js → logsnag-5RGTMTU2.js} +20 -22
- package/dist/main.js +102 -102
- package/dist/{mattermost-UECVPZGY.js → mattermost-BONGXVC7.js} +21 -17
- package/dist/{mem0-EUA7S2OO.js → mem0-RUVNUPTE.js} +15 -15
- package/dist/{memos-BYSBJRWZ.js → memos-TED4HI54.js} +36 -32
- package/dist/{metabase-4JXZH3YG.js → metabase-ZHXHRHZK.js} +22 -18
- package/dist/{mistral_ai-2C5BTBKW.js → mistral_ai-NGP5SHU7.js} +24 -21
- package/dist/{mother_duck-ZGNNNR3X.js → mother_duck-TKVQM35M.js} +23 -19
- package/dist/{ngrok-NTPGMRXI.js → ngrok-BYCUJ7QV.js} +17 -22
- package/dist/{notes-KGYXX6N6.js → notes-KXRNNYDW.js} +1 -1
- package/dist/{notion-EX3X2G7G.js → notion-2ILYKJOO.js} +20 -17
- package/dist/{open_exchange_rates-2V2LIGPS.js → open_exchange_rates-JU4DC6HZ.js} +4 -4
- package/dist/{openai-KQFQPK7Z.js → openai-6SOT26ZK.js} +22 -16
- package/dist/{opengraph_io-B63SEYJY.js → opengraph_io-ZEFHV2OL.js} +4 -4
- package/dist/{openrouter-62A4H62Q.js → openrouter-R4P7JL5L.js} +19 -14
- package/dist/{outline-QC33XLCK.js → outline-VCTQ5V2X.js} +18 -20
- package/dist/{paddle-HDZG35Y7.js → paddle-AZOAKBJS.js} +17 -15
- package/dist/{perplexity-M7LOMJWA.js → perplexity-OMRLGVAT.js} +19 -23
- package/dist/{pinecone-Y7YCJRZM.js → pinecone-DI62W3ZX.js} +19 -24
- package/dist/{pipedrive-FLJA62UX.js → pipedrive-CW7HONYW.js} +22 -23
- package/dist/{polar-AE55Q425.js → polar-5DRGTXNR.js} +19 -17
- package/dist/{posthog-IAY5D3YW.js → posthog-3DTHFCKE.js} +29 -24
- package/dist/{postmark-NMKAXDXZ.js → postmark-ME2V2XXI.js} +19 -17
- package/dist/{prerender-CDJM7I7N.js → prerender-5EAY7GDM.js} +4 -4
- package/dist/{pubmed-N437ZJOR.js → pubmed-GRQUBGVA.js} +3 -3
- package/dist/{railway-NBWYXCUM.js → railway-FTM75TMX.js} +3 -3
- package/dist/{readwise-QRO3UC3R.js → readwise-IJQGV6IQ.js} +16 -15
- package/dist/{render-NEW7SROG.js → render-TMSPHRTY.js} +21 -20
- package/dist/{replicate-73YQLRTY.js → replicate-RJCMDB7H.js} +20 -21
- package/dist/{resend-R5BAZFHZ.js → resend-YYN22NIL.js} +15 -11
- package/dist/{rootly-5BLALPCS.js → rootly-7RXE4K7L.js} +19 -18
- package/dist/{scrapfly-EHFLNNUZ.js → scrapfly-ZJJ6XM4Q.js} +4 -4
- package/dist/{scrapingbee-UXLYS72S.js → scrapingbee-QNGEOD6D.js} +4 -4
- package/dist/{screenshot_fyi-KC3NLTJ6.js → screenshot_fyi-SPZAABVD.js} +4 -4
- package/dist/{semantic_scholar-SA5OIUWA.js → semantic_scholar-SDPVGDDI.js} +21 -20
- package/dist/{sentry-BAE3XLJN.js → sentry-SJ5NN4C4.js} +22 -19
- package/dist/{shodan-FJR6MKKW.js → shodan-YMGOY7KW.js} +4 -4
- package/dist/{shopify-7OA6SLN5.js → shopify-SU5ABP54.js} +23 -19
- package/dist/{stripe-MUWDZGGF.js → stripe-JAC425KE.js} +3 -3
- package/dist/{supabase-SWWGNWYR.js → supabase-GQ2OFVIL.js} +18 -17
- package/dist/{tavily-XQNJ5EDI.js → tavily-Y7MDA5CI.js} +20 -20
- package/dist/{telegram-RR6JPZOG.js → telegram-OIDT3ZLH.js} +4 -4
- package/dist/{telnyx-7PKXOWSO.js → telnyx-4JGMC3K7.js} +19 -19
- package/dist/{todoist-63X5IUJE.js → todoist-O7S2OUGX.js} +18 -17
- package/dist/{trello-MOG63DAI.js → trello-3LDE4TAQ.js} +4 -4
- package/dist/{turso-ENWTSHDL.js → turso-MUQ44KCA.js} +23 -30
- package/dist/{twilio-FDXUN7VX.js → twilio-VYF3HUU6.js} +3 -3
- package/dist/{umami-TM7PROWF.js → umami-SVQIK26J.js} +23 -28
- package/dist/{unsplash-NWXLKSOW.js → unsplash-333XYDCJ.js} +19 -18
- package/dist/{upstash_redis-CUTQ5L2N.js → upstash_redis-IUM2HDLU.js} +17 -13
- package/dist/{uptimerobot-NNO32M3I.js → uptimerobot-7ZRU2NJV.js} +3 -3
- package/dist/{v2ex-24KMSWS7.js → v2ex-AVSJCQPS.js} +35 -18
- package/dist/{vercel-B45LPF6I.js → vercel-J7RGXNSA.js} +21 -18
- package/dist/{wolfram_alpha_api-DKJWVR6G.js → wolfram_alpha_api-6CRVUZOJ.js} +4 -4
- package/dist/{wordpress-XYFSDZXY.js → wordpress-THOJLPKA.js} +21 -17
- package/dist/{workos-BEM7EPHM.js → workos-ENTGRWF2.js} +26 -27
- package/dist/{zhihu-CFHZ4NC7.js → zhihu-W2BXICTX.js} +21 -21
- package/package.json +5 -5
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-JEWFX6Z6.js";
|
|
4
|
+
import "./chunk-Q74GLIDK.js";
|
|
4
5
|
import {
|
|
5
6
|
asJsonObject,
|
|
6
7
|
booleanValue,
|
|
@@ -10,21 +11,19 @@ import {
|
|
|
10
11
|
} from "./chunk-JXHMDBAY.js";
|
|
11
12
|
import {
|
|
12
13
|
createProviderPlugin,
|
|
13
|
-
requireApiKey,
|
|
14
14
|
upstreamError
|
|
15
|
-
} from "./chunk-
|
|
16
|
-
import "./chunk-
|
|
15
|
+
} from "./chunk-QR4LK3HF.js";
|
|
16
|
+
import "./chunk-ZTTN6AJG.js";
|
|
17
17
|
import {
|
|
18
18
|
TBError,
|
|
19
19
|
external_exports
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-MZCIPUNQ.js";
|
|
21
21
|
import "./chunk-U67V476Y.js";
|
|
22
22
|
|
|
23
23
|
// ../plugins/src/airtable/api.ts
|
|
24
24
|
var SERVICE = "airtable";
|
|
25
25
|
var API_BASE = "https://api.airtable.com";
|
|
26
26
|
var BASES_PATH = "/v0/meta/bases";
|
|
27
|
-
var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
|
|
28
27
|
var GET_URL_LENGTH_SOFT_LIMIT = 15e3;
|
|
29
28
|
function requireText(value, field) {
|
|
30
29
|
const result = trimmedText(value);
|
|
@@ -82,21 +81,25 @@ function mapAirtableError(context) {
|
|
|
82
81
|
return upstreamError(502, "airtable response parsing failed: invalid JSON");
|
|
83
82
|
}
|
|
84
83
|
}
|
|
84
|
+
var http = createAuthedClient({
|
|
85
|
+
baseUrl: API_BASE,
|
|
86
|
+
service: SERVICE,
|
|
87
|
+
auth: { kind: "bearer" },
|
|
88
|
+
headers: { accept: "application/json" },
|
|
89
|
+
mapError: mapAirtableError,
|
|
90
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
91
|
+
502,
|
|
92
|
+
`airtable request failed: ${message ?? "unknown request error"}`
|
|
93
|
+
)
|
|
94
|
+
});
|
|
85
95
|
async function request(ctx, input) {
|
|
86
|
-
const
|
|
87
|
-
const result = await http.request({
|
|
96
|
+
const result = await http.request(ctx, {
|
|
88
97
|
path: input.path,
|
|
89
98
|
method: input.method ?? "GET",
|
|
90
99
|
query: input.query,
|
|
91
|
-
headers: { accept: "application/json", authorization: `Bearer ${apiKey}` },
|
|
92
100
|
...input.body === void 0 ? {} : { json: input.body },
|
|
93
101
|
invalidJson: "text",
|
|
94
|
-
responseType: "auto"
|
|
95
|
-
mapError: mapAirtableError,
|
|
96
|
-
mapTransportError: ({ message }) => upstreamError(
|
|
97
|
-
502,
|
|
98
|
-
`airtable request failed: ${message ?? "unknown request error"}`
|
|
99
|
-
)
|
|
102
|
+
responseType: "auto"
|
|
100
103
|
});
|
|
101
104
|
return responsePayload(result);
|
|
102
105
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createProviderHttpClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q74GLIDK.js";
|
|
4
4
|
import "./chunk-JXHMDBAY.js";
|
|
5
5
|
import {
|
|
6
6
|
createProviderPlugin,
|
|
7
7
|
requireApiKey,
|
|
8
8
|
upstreamError
|
|
9
|
-
} from "./chunk-
|
|
10
|
-
import "./chunk-
|
|
9
|
+
} from "./chunk-QR4LK3HF.js";
|
|
10
|
+
import "./chunk-ZTTN6AJG.js";
|
|
11
11
|
import {
|
|
12
12
|
TBError,
|
|
13
13
|
external_exports
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-MZCIPUNQ.js";
|
|
15
15
|
import "./chunk-U67V476Y.js";
|
|
16
16
|
|
|
17
17
|
// ../plugins/src/alt_text_generator_ai/schema.ts
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createProviderHttpClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-Q74GLIDK.js";
|
|
4
4
|
import {
|
|
5
5
|
asJsonObject,
|
|
6
6
|
booleanValue,
|
|
@@ -10,12 +10,12 @@ import {
|
|
|
10
10
|
createProviderPlugin,
|
|
11
11
|
requireApiKey,
|
|
12
12
|
upstreamError
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-QR4LK3HF.js";
|
|
14
|
+
import "./chunk-ZTTN6AJG.js";
|
|
15
15
|
import {
|
|
16
16
|
TBError,
|
|
17
17
|
external_exports
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-MZCIPUNQ.js";
|
|
19
19
|
import "./chunk-U67V476Y.js";
|
|
20
20
|
|
|
21
21
|
// ../plugins/src/amap/api.ts
|
|
@@ -1,57 +1,55 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-JEWFX6Z6.js";
|
|
4
|
+
import "./chunk-Q74GLIDK.js";
|
|
4
5
|
import {
|
|
5
|
-
asJsonObject,
|
|
6
6
|
compactDefined,
|
|
7
7
|
trimmedText
|
|
8
8
|
} from "./chunk-JXHMDBAY.js";
|
|
9
9
|
import {
|
|
10
10
|
createProviderPlugin,
|
|
11
|
-
requireApiKey,
|
|
12
11
|
upstreamError
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
12
|
+
} from "./chunk-QR4LK3HF.js";
|
|
13
|
+
import "./chunk-ZTTN6AJG.js";
|
|
15
14
|
import {
|
|
16
15
|
TBError,
|
|
17
16
|
external_exports
|
|
18
|
-
} from "./chunk-
|
|
17
|
+
} from "./chunk-MZCIPUNQ.js";
|
|
19
18
|
import "./chunk-U67V476Y.js";
|
|
20
19
|
|
|
21
20
|
// ../plugins/src/anthropic/api.ts
|
|
22
21
|
var SERVICE = "anthropic";
|
|
23
22
|
var API_BASE = "https://api.anthropic.com";
|
|
24
23
|
var API_VERSION = "2023-06-01";
|
|
25
|
-
var http =
|
|
24
|
+
var http = createAuthedClient({
|
|
25
|
+
baseUrl: `${API_BASE}/`,
|
|
26
|
+
service: SERVICE,
|
|
27
|
+
auth: { kind: "header", name: "x-api-key" },
|
|
28
|
+
// content-type 不分 method 全量带,与迁移前的头集合一致(GET 也发)。
|
|
29
|
+
headers: {
|
|
30
|
+
"accept": "application/json",
|
|
31
|
+
"anthropic-version": API_VERSION,
|
|
32
|
+
"content-type": "application/json"
|
|
33
|
+
},
|
|
34
|
+
// Anthropic 的错误体是 `{type, error:{type, message}}`;网关层的错误可能是纯文本。
|
|
35
|
+
errorMessage: {
|
|
36
|
+
keys: ["error.message"],
|
|
37
|
+
fallback: (status) => `anthropic request failed with ${status}`
|
|
38
|
+
}
|
|
39
|
+
});
|
|
26
40
|
function requireText(value, field) {
|
|
27
41
|
const result = trimmedText(value);
|
|
28
42
|
if (result === void 0) throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
|
|
29
43
|
return result;
|
|
30
44
|
}
|
|
31
|
-
function headers(apiKey) {
|
|
32
|
-
return {
|
|
33
|
-
"accept": "application/json",
|
|
34
|
-
"anthropic-version": API_VERSION,
|
|
35
|
-
"content-type": "application/json",
|
|
36
|
-
"x-api-key": apiKey
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function errorMessage(status, payload) {
|
|
40
|
-
const fallback = `anthropic request failed with ${status}`;
|
|
41
|
-
const nested = asJsonObject(asJsonObject(payload)?.error);
|
|
42
|
-
return trimmedText(nested?.message) ?? trimmedText(payload) ?? fallback;
|
|
43
|
-
}
|
|
44
45
|
async function request(ctx, input) {
|
|
45
|
-
const apiKey = requireApiKey(ctx, SERVICE);
|
|
46
46
|
const method = input.method ?? "GET";
|
|
47
|
-
const { data } = await http.request({
|
|
47
|
+
const { data } = await http.request(ctx, {
|
|
48
48
|
path: input.path,
|
|
49
49
|
method,
|
|
50
50
|
query: Object.entries(input.query ?? {}),
|
|
51
|
-
headers: headers(apiKey),
|
|
52
51
|
...input.body === void 0 ? {} : { json: input.body },
|
|
53
52
|
invalidJsonMessage: "anthropic returned malformed JSON",
|
|
54
|
-
mapError: ({ data: payload, status }) => upstreamError(status, errorMessage(status, payload)),
|
|
55
53
|
mapTransportError: ({ message }) => upstreamError(
|
|
56
54
|
502,
|
|
57
55
|
`anthropic ${method} ${input.path} failed before receiving response: ${message ?? "unknown network error"}`
|
|
@@ -1,26 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-JEWFX6Z6.js";
|
|
4
|
+
import "./chunk-Q74GLIDK.js";
|
|
4
5
|
import {
|
|
5
6
|
asJsonObject
|
|
6
7
|
} from "./chunk-JXHMDBAY.js";
|
|
7
8
|
import {
|
|
8
9
|
createProviderPlugin,
|
|
9
|
-
requireApiKey,
|
|
10
10
|
upstreamError
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-QR4LK3HF.js";
|
|
12
|
+
import "./chunk-ZTTN6AJG.js";
|
|
13
13
|
import {
|
|
14
14
|
TBError,
|
|
15
15
|
external_exports
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-MZCIPUNQ.js";
|
|
17
17
|
import "./chunk-U67V476Y.js";
|
|
18
18
|
|
|
19
19
|
// ../plugins/src/apify/api.ts
|
|
20
20
|
var SERVICE = "apify";
|
|
21
21
|
var API_BASE = "https://api.apify.com";
|
|
22
22
|
var CURRENT_USER_PATH = "/v2/users/me";
|
|
23
|
-
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
24
23
|
function nonEmpty(value) {
|
|
25
24
|
return typeof value === "string" && value !== "" ? value : void 0;
|
|
26
25
|
}
|
|
@@ -29,6 +28,18 @@ function errorMessage(payload, status) {
|
|
|
29
28
|
const error = asJsonObject(record?.error);
|
|
30
29
|
return nonEmpty(error?.message) ?? nonEmpty(record?.message) ?? nonEmpty(error?.type) ?? `Apify request failed with status ${status}`;
|
|
31
30
|
}
|
|
31
|
+
var http = createAuthedClient({
|
|
32
|
+
baseUrl: `${API_BASE}/`,
|
|
33
|
+
service: SERVICE,
|
|
34
|
+
auth: { kind: "bearer" },
|
|
35
|
+
headers: { accept: "application/json" },
|
|
36
|
+
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)),
|
|
37
|
+
mapTransportError: ({ message }) => new TBError(
|
|
38
|
+
"unavailable",
|
|
39
|
+
message === void 0 ? "Apify \u8BF7\u6C42\u5931\u8D25" : `Apify \u8BF7\u6C42\u5931\u8D25: ${message}`,
|
|
40
|
+
{ retryable: true }
|
|
41
|
+
)
|
|
42
|
+
});
|
|
32
43
|
function requiredId(value, field) {
|
|
33
44
|
if (value === void 0 || value === "") {
|
|
34
45
|
throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
|
|
@@ -36,22 +47,12 @@ function requiredId(value, field) {
|
|
|
36
47
|
return encodeURIComponent(value);
|
|
37
48
|
}
|
|
38
49
|
async function request(ctx, path, init = {}) {
|
|
39
|
-
const { data } = await http.request({
|
|
50
|
+
const { data } = await http.request(ctx, {
|
|
40
51
|
path,
|
|
41
52
|
method: init.method ?? "GET",
|
|
42
53
|
query: Object.entries(init.query ?? {}),
|
|
43
|
-
headers: {
|
|
44
|
-
accept: "application/json",
|
|
45
|
-
authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
|
|
46
|
-
},
|
|
47
54
|
...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(
|
|
51
|
-
"unavailable",
|
|
52
|
-
message === void 0 ? "Apify \u8BF7\u6C42\u5931\u8D25" : `Apify \u8BF7\u6C42\u5931\u8D25: ${message}`,
|
|
53
|
-
{ retryable: true }
|
|
54
|
-
)
|
|
55
|
+
invalidJsonMessage: "Apify \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94"
|
|
55
56
|
});
|
|
56
57
|
return data ?? null;
|
|
57
58
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-JEWFX6Z6.js";
|
|
4
|
+
import "./chunk-Q74GLIDK.js";
|
|
4
5
|
import {
|
|
5
6
|
asJsonObject,
|
|
6
7
|
compactDefined,
|
|
@@ -8,20 +9,18 @@ import {
|
|
|
8
9
|
} from "./chunk-JXHMDBAY.js";
|
|
9
10
|
import {
|
|
10
11
|
createProviderPlugin,
|
|
11
|
-
requireApiKey,
|
|
12
12
|
upstreamError
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
13
|
+
} from "./chunk-QR4LK3HF.js";
|
|
14
|
+
import "./chunk-ZTTN6AJG.js";
|
|
15
15
|
import {
|
|
16
16
|
TBError,
|
|
17
17
|
external_exports
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-MZCIPUNQ.js";
|
|
19
19
|
import "./chunk-U67V476Y.js";
|
|
20
20
|
|
|
21
21
|
// ../plugins/src/brave_search/api.ts
|
|
22
22
|
var SERVICE = "brave_search";
|
|
23
23
|
var API_BASE = "https://api.search.brave.com";
|
|
24
|
-
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
25
24
|
var RATE_LIMIT_CODES = /* @__PURE__ */ new Set(["QUOTA_LIMITED", "RATE_LIMITED", "USAGE_LIMIT_EXCEEDED"]);
|
|
26
25
|
var AUTH_CODES = /* @__PURE__ */ new Set(["SUBSCRIPTION_TOKEN_INVALID", "SUBSCRIPTION_NOT_FOUND"]);
|
|
27
26
|
var INVALID_CODES = /* @__PURE__ */ new Set(["RESOURCE_NOT_ALLOWED", "OPTION_NOT_IN_PLAN", "INVALID_URL"]);
|
|
@@ -60,17 +59,20 @@ function braveSearchError(status, payload) {
|
|
|
60
59
|
}
|
|
61
60
|
return upstreamError(status, message);
|
|
62
61
|
}
|
|
62
|
+
var http = createAuthedClient({
|
|
63
|
+
baseUrl: `${API_BASE}/`,
|
|
64
|
+
service: SERVICE,
|
|
65
|
+
auth: { kind: "header", name: "x-subscription-token" },
|
|
66
|
+
headers: { accept: "application/json" },
|
|
67
|
+
// 稳定错误码码表比 HTTP 状态准,整段覆写而不用标准键序提取。
|
|
68
|
+
mapError: ({ data: payload, status }) => braveSearchError(status, payload)
|
|
69
|
+
});
|
|
63
70
|
async function request(ctx, path, query) {
|
|
64
|
-
const { data } = await http.request({
|
|
71
|
+
const { data } = await http.request(ctx, {
|
|
65
72
|
path,
|
|
66
73
|
method: "GET",
|
|
67
74
|
query: Object.entries(query),
|
|
68
|
-
|
|
69
|
-
"accept": "application/json",
|
|
70
|
-
"x-subscription-token": requireApiKey(ctx, SERVICE)
|
|
71
|
-
},
|
|
72
|
-
invalidJsonMessage: "Brave Search \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
|
|
73
|
-
mapError: ({ data: payload, status }) => braveSearchError(status, payload)
|
|
75
|
+
invalidJsonMessage: "Brave Search \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94"
|
|
74
76
|
});
|
|
75
77
|
return data ?? null;
|
|
76
78
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-Q74GLIDK.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
trimmedText
|
|
7
|
+
} from "./chunk-JXHMDBAY.js";
|
|
8
|
+
import {
|
|
9
|
+
requireApiKey,
|
|
10
|
+
upstreamError
|
|
11
|
+
} from "./chunk-QR4LK3HF.js";
|
|
12
|
+
import {
|
|
13
|
+
TBError
|
|
14
|
+
} from "./chunk-MZCIPUNQ.js";
|
|
15
|
+
|
|
16
|
+
// ../plugins/src/_runtime/authedClient.ts
|
|
17
|
+
function extractErrorMessage(payload, keys) {
|
|
18
|
+
const direct = trimmedText(payload);
|
|
19
|
+
if (direct !== void 0) return direct;
|
|
20
|
+
if (asJsonObject(payload) === void 0) return void 0;
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
let value = payload;
|
|
23
|
+
for (const segment of key.split(".")) {
|
|
24
|
+
value = asJsonObject(value)?.[segment];
|
|
25
|
+
}
|
|
26
|
+
const candidate = trimmedText(value);
|
|
27
|
+
if (candidate !== void 0) return candidate;
|
|
28
|
+
}
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
function createAuthedClient(options) {
|
|
32
|
+
const { auth, errorMessage, headers: staticHeaders, mapError, mapTransportError, ...clientOptions } = options;
|
|
33
|
+
if (errorMessage !== void 0 && mapError !== void 0) {
|
|
34
|
+
throw new TBError("invalid_argument", `${options.service} \u4E0D\u80FD\u540C\u65F6\u58F0\u660E errorMessage \u4E0E mapError`);
|
|
35
|
+
}
|
|
36
|
+
const http = createProviderHttpClient(clientOptions);
|
|
37
|
+
const defaultMapError = mapError ?? (errorMessage === void 0 ? void 0 : ({ data, status, statusText }) => upstreamError(
|
|
38
|
+
status,
|
|
39
|
+
extractErrorMessage(data, errorMessage.keys) ?? errorMessage.fallback(status, statusText)
|
|
40
|
+
));
|
|
41
|
+
function authHeaders(ctx) {
|
|
42
|
+
switch (auth.kind) {
|
|
43
|
+
case "bearer":
|
|
44
|
+
return { authorization: `Bearer ${requireApiKey(ctx, options.service)}` };
|
|
45
|
+
case "token":
|
|
46
|
+
return { authorization: `Token ${requireApiKey(ctx, options.service)}` };
|
|
47
|
+
case "header":
|
|
48
|
+
return { [auth.name]: requireApiKey(ctx, options.service) };
|
|
49
|
+
case "custom":
|
|
50
|
+
return auth.headers(ctx);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
async request(ctx, request) {
|
|
55
|
+
const resolvedAuth = authHeaders(ctx);
|
|
56
|
+
const headers = new Headers(staticHeaders);
|
|
57
|
+
for (const [name, value] of new Headers(request.headers)) headers.set(name, value);
|
|
58
|
+
for (const [name, value] of new Headers(resolvedAuth)) headers.set(name, value);
|
|
59
|
+
return await http.request({
|
|
60
|
+
...request,
|
|
61
|
+
headers,
|
|
62
|
+
mapError: request.mapError ?? defaultMapError,
|
|
63
|
+
mapTransportError: request.mapTransportError ?? mapTransportError
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export {
|
|
70
|
+
createAuthedClient
|
|
71
|
+
};
|