@tool-bridge/server 0.20.0 → 0.21.1
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-LLZDFN7M.js} +19 -16
- package/dist/{alt_text_generator_ai-X7RMDDM5.js → alt_text_generator_ai-W7O34SNG.js} +4 -4
- package/dist/{amap-3VER75VH.js → amap-VOX4T2AW.js} +4 -4
- package/dist/{anthropic-N7NTB3UC.js → anthropic-G23NN3X5.js} +23 -25
- package/dist/{apify-JB5P5AJI.js → apify-Y3SS734K.js} +20 -19
- package/dist/{brave_search-USL5OOBS.js → brave_search-ZC7OAPSZ.js} +16 -14
- package/dist/{chunk-6ANLYNFB.js → chunk-ATK45BXV.js} +1 -1
- package/dist/{chunk-6X55ALDX.js → chunk-E6JCVKW6.js} +6 -5
- package/dist/{chunk-RVUERWUZ.js → chunk-KMTT3I6D.js} +768 -1048
- package/dist/chunk-R6P4XAE5.js +248 -0
- package/dist/{chunk-3WL6EXYX.js → chunk-U7B6DS2O.js} +1 -1
- package/dist/{chunk-WIGQCP6O.js → chunk-UZM2RXZH.js} +159 -182
- package/dist/chunk-XYBU3WZH.js +71 -0
- package/dist/{circleci-LBGB25LP.js → circleci-3BAX5FCG.js} +20 -24
- package/dist/{clerk-6RX37CNZ.js → clerk-6LEM6TNU.js} +22 -21
- package/dist/{cloudflare_dns-NQGW7FHV.js → cloudflare_dns-KINYTJUD.js} +21 -17
- package/dist/{cohere-XPC2NAEW.js → cohere-XCJ5AJ6B.js} +19 -17
- package/dist/{confluence-ZUG2LT5A.js → confluence-B3EWPZVE.js} +16 -11
- package/dist/{convertapi-ZLXKWV3L.js → convertapi-EUWSQYPF.js} +3 -3
- package/dist/{currencyapi-T3A3HSOD.js → currencyapi-KVTIK3GL.js} +23 -26
- package/dist/{deepseek-NJMOD23E.js → deepseek-PC5YGNC5.js} +27 -17
- package/dist/{docker_hub-D2MQCSJ7.js → docker_hub-C3MA5FU6.js} +4 -4
- package/dist/{dropbox-MI6U3SOT.js → dropbox-XBV7Z2IR.js} +9 -8
- package/dist/{dub-P2BYBYV4.js → dub-LDOFG3HC.js} +22 -19
- package/dist/{e2b-BGKIAE54.js → e2b-JMCPSVBW.js} +20 -20
- package/dist/{exa-EUY7VV4C.js → exa-RAK7O7RD.js} +22 -25
- package/dist/{fal_ai-AAOG5FYJ.js → fal_ai-23E7JPNT.js} +18 -17
- package/dist/feishu-7QRIDUV6.js +12019 -0
- package/dist/{feishu_custom_bot-BWGMNVXF.js → feishu_custom_bot-TJ4K7QNJ.js} +3 -3
- package/dist/{figma-SJSWYCGD.js → figma-E6IX5DTH.js} +21 -23
- package/dist/{firehydrant-MOXK2PST.js → firehydrant-ZBLPQREE.js} +15 -15
- package/dist/{fixer-ISIDUDZU.js → fixer-BWON27UO.js} +4 -4
- package/dist/{fly-U4KPSGBF.js → fly-ZH3HFCZJ.js} +20 -16
- package/dist/{front-ZHM2YX2E.js → front-QCGXYEDJ.js} +20 -23
- package/dist/{geocodio-SVCCAXAV.js → geocodio-YGNI7DA4.js} +4 -4
- package/dist/{ghost-INTR7FIY.js → ghost-EVSGKH2Q.js} +4 -4
- package/dist/{github-T275VVWR.js → github-MA2BGRCJ.js} +28 -27
- package/dist/{gmail-KSSPOE67.js → gmail-E5E6AADE.js} +17 -17
- package/dist/{googlecalendar-JB5RW27L.js → googlecalendar-BTLFPXTD.js} +22 -19
- package/dist/{googledocs-G522PUGW.js → googledocs-BUHL4J2H.js} +6 -5
- package/dist/{grafana-44ZPIV5P.js → grafana-GLU2DWF2.js} +24 -25
- package/dist/{graphhopper-2MORXLOW.js → graphhopper-WSMB3TCD.js} +4 -4
- package/dist/index.d.ts +31 -30
- package/dist/index.js +4 -3
- package/dist/{ip2proxy-R4K4KEMI.js → ip2proxy-EZ64Y4ZH.js} +4 -4
- package/dist/{ipgeolocation_io-H4J55OGI.js → ipgeolocation_io-AA7HAS22.js} +4 -4
- package/dist/{ipqualityscore-XGID4OHA.js → ipqualityscore-BHJXVTJT.js} +4 -4
- package/dist/{jina_ai-7ZVDOR3Z.js → jina_ai-EFBHTBXL.js} +20 -21
- package/dist/{jira-CTIYZTT3.js → jira-HQSHAA5K.js} +20 -16
- package/dist/{langsmith-ISP567FS.js → langsmith-5W6SCT6F.js} +25 -25
- package/dist/{lemlist-OGKK272F.js → lemlist-HJWH6UMK.js} +23 -24
- package/dist/{linear-6JX4E3JI.js → linear-K7RYFYAD.js} +6 -5
- package/dist/{logsnag-BVB36ZCL.js → logsnag-4KFOHL37.js} +20 -22
- package/dist/main.js +103 -102
- package/dist/{mattermost-UECVPZGY.js → mattermost-S2BRCWLQ.js} +21 -17
- package/dist/{mem0-EUA7S2OO.js → mem0-CAW43CIC.js} +15 -15
- package/dist/{memos-BYSBJRWZ.js → memos-TWEGPKFM.js} +39 -34
- package/dist/{metabase-4JXZH3YG.js → metabase-MMSEPCOF.js} +22 -18
- package/dist/{mistral_ai-2C5BTBKW.js → mistral_ai-64BGZQHP.js} +24 -21
- package/dist/{mother_duck-ZGNNNR3X.js → mother_duck-H7PCQNZ2.js} +23 -19
- package/dist/{ngrok-NTPGMRXI.js → ngrok-GQCUGZKJ.js} +17 -22
- package/dist/{notes-KGYXX6N6.js → notes-PFMKRO33.js} +1 -1
- package/dist/{notion-EX3X2G7G.js → notion-DQWZWP4N.js} +20 -17
- package/dist/{open_exchange_rates-2V2LIGPS.js → open_exchange_rates-QMMD735E.js} +4 -4
- package/dist/{openai-KQFQPK7Z.js → openai-W6PX32NZ.js} +22 -16
- package/dist/{opengraph_io-B63SEYJY.js → opengraph_io-HNDBXYNW.js} +4 -4
- package/dist/{openrouter-62A4H62Q.js → openrouter-JJYMEAUL.js} +19 -14
- package/dist/{outline-QC33XLCK.js → outline-MCBNQZYY.js} +18 -20
- package/dist/{paddle-HDZG35Y7.js → paddle-D2SKLUDN.js} +17 -15
- package/dist/{perplexity-M7LOMJWA.js → perplexity-XIFMKUAE.js} +19 -23
- package/dist/{pinecone-Y7YCJRZM.js → pinecone-HUFTALV2.js} +19 -24
- package/dist/{pipedrive-FLJA62UX.js → pipedrive-Y2O7QGFF.js} +22 -23
- package/dist/{polar-AE55Q425.js → polar-TYTOMOSR.js} +19 -17
- package/dist/{posthog-IAY5D3YW.js → posthog-43JAR3VW.js} +29 -24
- package/dist/{postmark-NMKAXDXZ.js → postmark-KL2QJYSG.js} +19 -17
- package/dist/{prerender-CDJM7I7N.js → prerender-MENYM2TY.js} +4 -4
- package/dist/{pubmed-N437ZJOR.js → pubmed-GOXUVVH5.js} +6 -5
- package/dist/{railway-NBWYXCUM.js → railway-V2SID4WV.js} +3 -3
- package/dist/{readwise-QRO3UC3R.js → readwise-CI4GIMMJ.js} +16 -15
- package/dist/{render-NEW7SROG.js → render-SUBJ6YRZ.js} +21 -20
- package/dist/{replicate-73YQLRTY.js → replicate-756MXPYX.js} +20 -21
- package/dist/{resend-R5BAZFHZ.js → resend-ZKH3BTBI.js} +15 -11
- package/dist/{rootly-5BLALPCS.js → rootly-CD2LJHPI.js} +19 -18
- package/dist/{scrapfly-EHFLNNUZ.js → scrapfly-NSRHFDIQ.js} +4 -4
- package/dist/{scrapingbee-UXLYS72S.js → scrapingbee-OQHLAVEY.js} +4 -4
- package/dist/{screenshot_fyi-KC3NLTJ6.js → screenshot_fyi-DVWG3AXC.js} +4 -4
- package/dist/{semantic_scholar-SA5OIUWA.js → semantic_scholar-T4A252KW.js} +21 -20
- package/dist/{sentry-BAE3XLJN.js → sentry-546MNDJG.js} +22 -19
- package/dist/{shodan-FJR6MKKW.js → shodan-C3OON3Z3.js} +4 -4
- package/dist/{shopify-7OA6SLN5.js → shopify-Y2HN2MCQ.js} +23 -19
- package/dist/{stripe-MUWDZGGF.js → stripe-VE3CD3AY.js} +3 -3
- package/dist/{supabase-SWWGNWYR.js → supabase-U2SL4D63.js} +18 -17
- package/dist/{tavily-XQNJ5EDI.js → tavily-KCZHK6HE.js} +20 -20
- package/dist/{telegram-RR6JPZOG.js → telegram-3URFBCMY.js} +4 -4
- package/dist/{telnyx-7PKXOWSO.js → telnyx-CXQ4EZUX.js} +19 -19
- package/dist/{todoist-63X5IUJE.js → todoist-HNPWNYTD.js} +18 -17
- package/dist/{trello-MOG63DAI.js → trello-3W2MIXRP.js} +4 -4
- package/dist/{turso-ENWTSHDL.js → turso-2EQF7C2Z.js} +23 -30
- package/dist/{twilio-FDXUN7VX.js → twilio-4PDBJKWX.js} +6 -5
- package/dist/{umami-TM7PROWF.js → umami-5REN7TGP.js} +23 -28
- package/dist/{unsplash-NWXLKSOW.js → unsplash-EIXL424F.js} +19 -18
- package/dist/{upstash_redis-CUTQ5L2N.js → upstash_redis-G4LQBYHA.js} +17 -13
- package/dist/{uptimerobot-NNO32M3I.js → uptimerobot-KNJ3EYLY.js} +3 -3
- package/dist/{v2ex-24KMSWS7.js → v2ex-RHJ234PZ.js} +35 -18
- package/dist/{vercel-B45LPF6I.js → vercel-AS6NCIC7.js} +21 -18
- package/dist/{wolfram_alpha_api-DKJWVR6G.js → wolfram_alpha_api-3G4PUJWB.js} +4 -4
- package/dist/{wordpress-XYFSDZXY.js → wordpress-KNDAAUV7.js} +21 -17
- package/dist/{workos-BEM7EPHM.js → workos-R6UITSJ7.js} +26 -27
- package/dist/{zhihu-CFHZ4NC7.js → zhihu-AGK4HILK.js} +21 -21
- package/package.json +5 -5
- package/dist/feishu-AN5IJYOW.js +0 -231
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-XYBU3WZH.js";
|
|
4
|
+
import "./chunk-E6JCVKW6.js";
|
|
4
5
|
import {
|
|
5
6
|
asJsonObject,
|
|
6
7
|
trimmedText
|
|
@@ -9,21 +10,20 @@ import {
|
|
|
9
10
|
createProviderPlugin,
|
|
10
11
|
requireApiKey,
|
|
11
12
|
upstreamError
|
|
12
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-ATK45BXV.js";
|
|
13
14
|
import {
|
|
14
15
|
assertPublicHttpUrl
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-U7B6DS2O.js";
|
|
16
17
|
import {
|
|
17
18
|
TBError,
|
|
18
19
|
external_exports
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-UZM2RXZH.js";
|
|
20
21
|
import "./chunk-U67V476Y.js";
|
|
21
22
|
|
|
22
23
|
// ../plugins/src/metabase/api.ts
|
|
23
24
|
var SERVICE = "metabase";
|
|
24
25
|
var API_PATH_PREFIX = "/api";
|
|
25
26
|
var CURRENT_USER_PATH = "/user/current";
|
|
26
|
-
var http = createProviderHttpClient({ service: SERVICE });
|
|
27
27
|
function configError(message) {
|
|
28
28
|
return new TBError("invalid_argument", `${SERVICE} \u7684 ${message}`);
|
|
29
29
|
}
|
|
@@ -65,23 +65,27 @@ function errorMessage(payload, status) {
|
|
|
65
65
|
function errorPayload(data, bodyKind) {
|
|
66
66
|
return bodyKind === "invalid-json" ? { message: data } : data;
|
|
67
67
|
}
|
|
68
|
+
var http = createAuthedClient({
|
|
69
|
+
service: SERVICE,
|
|
70
|
+
auth: { kind: "header", name: "x-api-key" },
|
|
71
|
+
headers: { accept: "application/json" },
|
|
72
|
+
mapError: ({ bodyKind, data, status }) => upstreamError(
|
|
73
|
+
status,
|
|
74
|
+
errorMessage(errorPayload(data, bodyKind), status)
|
|
75
|
+
),
|
|
76
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
77
|
+
502,
|
|
78
|
+
`Metabase \u8BF7\u6C42\u5931\u8D25:${message ?? "\u672A\u77E5\u9519\u8BEF"}`
|
|
79
|
+
)
|
|
80
|
+
});
|
|
68
81
|
async function request(ctx, path, query) {
|
|
69
|
-
|
|
70
|
-
const result = await http.request({
|
|
82
|
+
requireApiKey(ctx, SERVICE);
|
|
83
|
+
const result = await http.request(ctx, {
|
|
71
84
|
baseUrl: `${resolveApiBase(ctx)}/`,
|
|
72
85
|
path,
|
|
73
86
|
// `models` 是多选,数组由薄层展开成重复同名参数。
|
|
74
87
|
query: Object.entries(query ?? {}),
|
|
75
|
-
|
|
76
|
-
invalidJsonMessage: "Metabase \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
|
|
77
|
-
mapError: ({ bodyKind, data, status }) => upstreamError(
|
|
78
|
-
status,
|
|
79
|
-
errorMessage(errorPayload(data, bodyKind), status)
|
|
80
|
-
),
|
|
81
|
-
mapTransportError: ({ message }) => upstreamError(
|
|
82
|
-
502,
|
|
83
|
-
`Metabase \u8BF7\u6C42\u5931\u8D25:${message ?? "\u672A\u77E5\u9519\u8BEF"}`
|
|
84
|
-
)
|
|
88
|
+
invalidJsonMessage: "Metabase \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94"
|
|
85
89
|
});
|
|
86
90
|
return result.data === void 0 ? null : result.data;
|
|
87
91
|
}
|
|
@@ -2,8 +2,9 @@ import {
|
|
|
2
2
|
readBoundedResponseBytes
|
|
3
3
|
} from "./chunk-LMLX3DJF.js";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
} from "./chunk-
|
|
5
|
+
createAuthedClient
|
|
6
|
+
} from "./chunk-XYBU3WZH.js";
|
|
7
|
+
import "./chunk-E6JCVKW6.js";
|
|
7
8
|
import {
|
|
8
9
|
asJsonObject
|
|
9
10
|
} from "./chunk-JXHMDBAY.js";
|
|
@@ -11,15 +12,15 @@ import {
|
|
|
11
12
|
createProviderPlugin,
|
|
12
13
|
requireApiKey,
|
|
13
14
|
upstreamError
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-ATK45BXV.js";
|
|
15
16
|
import {
|
|
16
17
|
assertPublicHttpUrl,
|
|
17
18
|
guardedFetch
|
|
18
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-U7B6DS2O.js";
|
|
19
20
|
import {
|
|
20
21
|
TBError,
|
|
21
22
|
external_exports
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-UZM2RXZH.js";
|
|
23
24
|
import "./chunk-U67V476Y.js";
|
|
24
25
|
|
|
25
26
|
// ../plugins/src/mistral_ai/schema.ts
|
|
@@ -814,7 +815,6 @@ var mistralAiActions = {
|
|
|
814
815
|
var SERVICE = "mistral_ai";
|
|
815
816
|
var API_BASE = "https://api.mistral.ai";
|
|
816
817
|
var MAX_REMOTE_UPLOAD_BYTES = 100 * 1024 * 1024;
|
|
817
|
-
var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
|
|
818
818
|
var SPECS = {
|
|
819
819
|
list_models: { method: "GET", path: "/v1/models" },
|
|
820
820
|
get_model: { method: "GET", path: "/v1/models/{model_id}", pathKeys: ["model_id"] },
|
|
@@ -946,6 +946,18 @@ var SPECS = {
|
|
|
946
946
|
function text(value) {
|
|
947
947
|
return typeof value === "string" && value !== "" ? value : void 0;
|
|
948
948
|
}
|
|
949
|
+
var http = createAuthedClient({
|
|
950
|
+
baseUrl: API_BASE,
|
|
951
|
+
service: SERVICE,
|
|
952
|
+
auth: { kind: "bearer" },
|
|
953
|
+
headers: { "content-type": "application/json" },
|
|
954
|
+
mapError: ({ data, rawText, status }) => {
|
|
955
|
+
const payload = asJsonObject(data);
|
|
956
|
+
const fallback = `mistral_ai request failed with ${status}`;
|
|
957
|
+
const message = text(payload?.detail) ?? text(payload?.message) ?? text(payload?.error) ?? text(rawText) ?? fallback;
|
|
958
|
+
return upstreamError(status === 422 ? 400 : status || 502, message);
|
|
959
|
+
}
|
|
960
|
+
});
|
|
949
961
|
function compactJson(value) {
|
|
950
962
|
if (Array.isArray(value)) return value.map((item) => compactJson(item));
|
|
951
963
|
if (value === null || typeof value !== "object") return value;
|
|
@@ -1075,27 +1087,18 @@ async function resolveUpload(remaining) {
|
|
|
1075
1087
|
mimeType: mimeType ?? response.headers.get("content-type") ?? "application/octet-stream"
|
|
1076
1088
|
};
|
|
1077
1089
|
}
|
|
1078
|
-
function authHeaders(ctx
|
|
1079
|
-
|
|
1080
|
-
if (json) headers["content-type"] = "application/json";
|
|
1081
|
-
return headers;
|
|
1090
|
+
function authHeaders(ctx) {
|
|
1091
|
+
return { authorization: `Bearer ${requireApiKey(ctx, SERVICE)}` };
|
|
1082
1092
|
}
|
|
1083
1093
|
async function executeJson(spec, input, ctx) {
|
|
1084
1094
|
const { url, remaining } = buildUrl(spec, input);
|
|
1085
1095
|
const sendsBody = spec.method === "POST" || spec.method === "PUT" || spec.method === "PATCH" || spec.method === "DELETE" && spec.bodyOnDelete === true;
|
|
1086
|
-
const result = await http.request({
|
|
1096
|
+
const result = await http.request(ctx, {
|
|
1087
1097
|
path: url,
|
|
1088
1098
|
method: spec.method,
|
|
1089
|
-
headers: authHeaders(ctx, true),
|
|
1090
1099
|
...sendsBody ? { json: compactJson(remaining) } : {},
|
|
1091
1100
|
responseType: "auto",
|
|
1092
|
-
invalidJsonMessage: "mistral_ai returned malformed JSON"
|
|
1093
|
-
mapError: ({ data, rawText, status }) => {
|
|
1094
|
-
const payload = asJsonObject(data);
|
|
1095
|
-
const fallback = `mistral_ai request failed with ${status}`;
|
|
1096
|
-
const message = text(payload?.detail) ?? text(payload?.message) ?? text(payload?.error) ?? text(rawText) ?? fallback;
|
|
1097
|
-
return upstreamError(status === 422 ? 400 : status || 502, message);
|
|
1098
|
-
}
|
|
1101
|
+
invalidJsonMessage: "mistral_ai returned malformed JSON"
|
|
1099
1102
|
});
|
|
1100
1103
|
if (result.status === 204) return { deleted: true };
|
|
1101
1104
|
return result.bodyKind === "empty" ? "" : result.data;
|
|
@@ -1110,7 +1113,7 @@ async function executeMultipart(spec, input, ctx) {
|
|
|
1110
1113
|
}
|
|
1111
1114
|
const response = await guardedFetch(url, {
|
|
1112
1115
|
method: spec.method,
|
|
1113
|
-
headers: authHeaders(ctx
|
|
1116
|
+
headers: authHeaders(ctx),
|
|
1114
1117
|
body: form
|
|
1115
1118
|
});
|
|
1116
1119
|
await assertOk(response);
|
|
@@ -1148,7 +1151,7 @@ async function executeAudioTranscription(spec, input, ctx) {
|
|
|
1148
1151
|
}
|
|
1149
1152
|
const response = await guardedFetch(url, {
|
|
1150
1153
|
method: spec.method,
|
|
1151
|
-
headers: authHeaders(ctx
|
|
1154
|
+
headers: authHeaders(ctx),
|
|
1152
1155
|
body: form
|
|
1153
1156
|
});
|
|
1154
1157
|
await assertOk(response);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-XYBU3WZH.js";
|
|
4
|
+
import "./chunk-E6JCVKW6.js";
|
|
4
5
|
import {
|
|
5
6
|
asJsonObject,
|
|
6
7
|
compactDefined,
|
|
@@ -8,45 +9,48 @@ 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-ATK45BXV.js";
|
|
14
|
+
import "./chunk-U7B6DS2O.js";
|
|
15
15
|
import {
|
|
16
16
|
TBError,
|
|
17
17
|
external_exports
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-UZM2RXZH.js";
|
|
19
19
|
import "./chunk-U67V476Y.js";
|
|
20
20
|
|
|
21
21
|
// ../plugins/src/mother_duck/api.ts
|
|
22
22
|
var SERVICE = "mother_duck";
|
|
23
23
|
var API_BASE = "https://api.motherduck.com";
|
|
24
|
-
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
25
24
|
function errorMessage(payload) {
|
|
26
25
|
const body = asJsonObject(payload);
|
|
27
26
|
if (body === void 0) return void 0;
|
|
28
27
|
return trimmedText(body.message) ?? trimmedText(body.error) ?? trimmedText(body.code);
|
|
29
28
|
}
|
|
29
|
+
var http = createAuthedClient({
|
|
30
|
+
baseUrl: `${API_BASE}/`,
|
|
31
|
+
service: SERVICE,
|
|
32
|
+
auth: { kind: "bearer" },
|
|
33
|
+
headers: { accept: "application/json" },
|
|
34
|
+
// invalid-json 错误体按**原文不 trim**透出 —— 标准 errorMessage 的 trim 语义接不住,整段覆写。
|
|
35
|
+
mapError: ({ bodyKind, data, status }) => upstreamError(
|
|
36
|
+
status,
|
|
37
|
+
bodyKind === "invalid-json" && typeof data === "string" ? data : errorMessage(data) ?? `MotherDuck \u8BF7\u6C42\u5931\u8D25,HTTP ${status}`
|
|
38
|
+
),
|
|
39
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
40
|
+
502,
|
|
41
|
+
message === void 0 ? "MotherDuck \u8BF7\u6C42\u5931\u8D25" : `MotherDuck \u8BF7\u6C42\u5931\u8D25: ${message}`
|
|
42
|
+
)
|
|
43
|
+
});
|
|
30
44
|
function isEmpty(payload) {
|
|
31
45
|
const object = asJsonObject(payload);
|
|
32
46
|
return object !== void 0 && Object.keys(object).length === 0;
|
|
33
47
|
}
|
|
34
48
|
async function request(ctx, path, input = {}) {
|
|
35
|
-
const
|
|
36
|
-
const result = await http.request({
|
|
49
|
+
const result = await http.request(ctx, {
|
|
37
50
|
path,
|
|
38
51
|
method: input.method ?? "GET",
|
|
39
|
-
headers: { accept: "application/json", authorization: `Bearer ${apiKey}` },
|
|
40
52
|
...input.body === void 0 ? {} : { json: input.body },
|
|
41
|
-
invalidJson: "text"
|
|
42
|
-
mapError: ({ bodyKind, data, status }) => upstreamError(
|
|
43
|
-
status,
|
|
44
|
-
bodyKind === "invalid-json" && typeof data === "string" ? data : errorMessage(data) ?? `MotherDuck \u8BF7\u6C42\u5931\u8D25,HTTP ${status}`
|
|
45
|
-
),
|
|
46
|
-
mapTransportError: ({ message }) => upstreamError(
|
|
47
|
-
502,
|
|
48
|
-
message === void 0 ? "MotherDuck \u8BF7\u6C42\u5931\u8D25" : `MotherDuck \u8BF7\u6C42\u5931\u8D25: ${message}`
|
|
49
|
-
)
|
|
53
|
+
invalidJson: "text"
|
|
50
54
|
});
|
|
51
55
|
const payload = result.bodyKind === "empty" ? {} : result.bodyKind === "invalid-json" && typeof result.data === "string" ? { message: result.data } : result.data;
|
|
52
56
|
if (input.allowEmpty === true && isEmpty(payload)) return {};
|
|
@@ -1,40 +1,35 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-XYBU3WZH.js";
|
|
4
|
+
import "./chunk-E6JCVKW6.js";
|
|
4
5
|
import {
|
|
5
6
|
asJsonObject,
|
|
6
|
-
messageFrom,
|
|
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-ATK45BXV.js";
|
|
13
|
+
import "./chunk-U7B6DS2O.js";
|
|
15
14
|
import {
|
|
16
15
|
external_exports
|
|
17
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-UZM2RXZH.js";
|
|
18
17
|
import "./chunk-U67V476Y.js";
|
|
19
18
|
|
|
20
19
|
// ../plugins/src/ngrok/api.ts
|
|
21
20
|
var SERVICE = "ngrok";
|
|
22
|
-
var http =
|
|
21
|
+
var http = createAuthedClient({
|
|
22
|
+
baseUrl: "https://api.ngrok.com/",
|
|
23
|
+
service: SERVICE,
|
|
24
|
+
auth: { kind: "bearer" },
|
|
25
|
+
headers: { "accept": "application/json", "ngrok-version": "2" },
|
|
26
|
+
errorMessage: {
|
|
27
|
+
keys: ["msg", "message", "error"],
|
|
28
|
+
fallback: (status) => `ngrok request failed with ${status}`
|
|
29
|
+
}
|
|
30
|
+
});
|
|
23
31
|
async function request(ctx, path, query) {
|
|
24
|
-
const { data } = await http.request({
|
|
25
|
-
path,
|
|
26
|
-
query,
|
|
27
|
-
headers: {
|
|
28
|
-
"accept": "application/json",
|
|
29
|
-
"authorization": `Bearer ${requireApiKey(ctx, SERVICE)}`,
|
|
30
|
-
"ngrok-version": "2"
|
|
31
|
-
},
|
|
32
|
-
invalidJson: "text",
|
|
33
|
-
mapError: ({ data: payload, status }) => upstreamError(
|
|
34
|
-
status,
|
|
35
|
-
messageFrom(payload, ["msg", "message", "error"], `ngrok request failed with ${status}`)
|
|
36
|
-
)
|
|
37
|
-
});
|
|
32
|
+
const { data } = await http.request(ctx, { path, query, invalidJson: "text" });
|
|
38
33
|
const result = asJsonObject(data);
|
|
39
34
|
if (result === void 0) throw upstreamError(502, "ngrok response was not a JSON object");
|
|
40
35
|
return result;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-XYBU3WZH.js";
|
|
4
|
+
import "./chunk-E6JCVKW6.js";
|
|
4
5
|
import {
|
|
5
6
|
asJsonObject,
|
|
6
7
|
booleanValue,
|
|
@@ -8,21 +9,19 @@ 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-ATK45BXV.js";
|
|
14
|
+
import "./chunk-U7B6DS2O.js";
|
|
15
15
|
import {
|
|
16
16
|
TBError,
|
|
17
17
|
external_exports
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-UZM2RXZH.js";
|
|
19
19
|
import "./chunk-U67V476Y.js";
|
|
20
20
|
|
|
21
21
|
// ../plugins/src/notion/api.ts
|
|
22
22
|
var SERVICE = "notion";
|
|
23
23
|
var API_BASE = "https://api.notion.com/v1";
|
|
24
24
|
var NOTION_VERSION = "2026-03-11";
|
|
25
|
-
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
26
25
|
function nonEmpty(value) {
|
|
27
26
|
return typeof value === "string" && value.length > 0 ? value : void 0;
|
|
28
27
|
}
|
|
@@ -40,23 +39,27 @@ function errorMessage(status, payload, bodyKind) {
|
|
|
40
39
|
const parsed = asJsonObject(payload);
|
|
41
40
|
return nonEmpty(parsed?.message) ?? nonEmpty(parsed?.error) ?? JSON.stringify(payload) ?? `notion request failed with ${status}`;
|
|
42
41
|
}
|
|
42
|
+
var http = createAuthedClient({
|
|
43
|
+
baseUrl: `${API_BASE}/`,
|
|
44
|
+
service: SERVICE,
|
|
45
|
+
auth: { kind: "bearer" },
|
|
46
|
+
headers: { "notion-version": NOTION_VERSION },
|
|
47
|
+
// 提取**不 trim**(nonEmpty)且兜底走 JSON.stringify —— 与标准 errorMessage 的 trim 语义
|
|
48
|
+
// 不同,整段覆写。
|
|
49
|
+
mapError: ({ bodyKind, data: payload, status }) => upstreamError(
|
|
50
|
+
status,
|
|
51
|
+
errorMessage(status, payload, bodyKind)
|
|
52
|
+
)
|
|
53
|
+
});
|
|
43
54
|
async function request(ctx, input) {
|
|
44
55
|
const hasBody = input.body !== void 0;
|
|
45
|
-
const { data } = await http.request({
|
|
56
|
+
const { data } = await http.request(ctx, {
|
|
46
57
|
path: input.path,
|
|
47
58
|
method: input.method ?? "GET",
|
|
48
59
|
// filter_properties[] 靠**重复同名参数**表达;空数组在调用处就丢掉了。
|
|
49
60
|
query: Object.entries(input.query ?? {}),
|
|
50
|
-
headers: {
|
|
51
|
-
"authorization": `Bearer ${requireApiKey(ctx, SERVICE)}`,
|
|
52
|
-
"notion-version": NOTION_VERSION
|
|
53
|
-
},
|
|
54
61
|
...hasBody ? { json: input.body } : {},
|
|
55
|
-
invalidJsonMessage: "Notion \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94"
|
|
56
|
-
mapError: ({ bodyKind, data: payload, status }) => upstreamError(
|
|
57
|
-
status,
|
|
58
|
-
errorMessage(status, payload, bodyKind)
|
|
59
|
-
)
|
|
62
|
+
invalidJsonMessage: "Notion \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94"
|
|
60
63
|
});
|
|
61
64
|
if (data === void 0) return {};
|
|
62
65
|
const result = asJsonObject(data);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createProviderHttpClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-E6JCVKW6.js";
|
|
4
4
|
import {
|
|
5
5
|
asJsonObject
|
|
6
6
|
} from "./chunk-JXHMDBAY.js";
|
|
@@ -8,12 +8,12 @@ import {
|
|
|
8
8
|
createProviderPlugin,
|
|
9
9
|
requireApiKey,
|
|
10
10
|
upstreamError
|
|
11
|
-
} from "./chunk-
|
|
12
|
-
import "./chunk-
|
|
11
|
+
} from "./chunk-ATK45BXV.js";
|
|
12
|
+
import "./chunk-U7B6DS2O.js";
|
|
13
13
|
import {
|
|
14
14
|
TBError,
|
|
15
15
|
external_exports
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-UZM2RXZH.js";
|
|
17
17
|
import "./chunk-U67V476Y.js";
|
|
18
18
|
|
|
19
19
|
// ../plugins/src/open_exchange_rates/api.ts
|
|
@@ -3,8 +3,9 @@ import {
|
|
|
3
3
|
readBoundedResponseBytes
|
|
4
4
|
} from "./chunk-LMLX3DJF.js";
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
} from "./chunk-
|
|
6
|
+
createAuthedClient
|
|
7
|
+
} from "./chunk-XYBU3WZH.js";
|
|
8
|
+
import "./chunk-E6JCVKW6.js";
|
|
8
9
|
import {
|
|
9
10
|
trimmedText
|
|
10
11
|
} from "./chunk-JXHMDBAY.js";
|
|
@@ -12,15 +13,15 @@ import {
|
|
|
12
13
|
createProviderPlugin,
|
|
13
14
|
requireApiKey,
|
|
14
15
|
upstreamError
|
|
15
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-ATK45BXV.js";
|
|
16
17
|
import {
|
|
17
18
|
assertPublicHttpUrl,
|
|
18
19
|
guardedFetch
|
|
19
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-U7B6DS2O.js";
|
|
20
21
|
import {
|
|
21
22
|
TBError,
|
|
22
23
|
external_exports
|
|
23
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-UZM2RXZH.js";
|
|
24
25
|
import "./chunk-U67V476Y.js";
|
|
25
26
|
|
|
26
27
|
// ../plugins/src/openai/api.ts
|
|
@@ -28,7 +29,6 @@ var SERVICE = "openai";
|
|
|
28
29
|
var API_BASE = "https://api.openai.com/v1";
|
|
29
30
|
var AUDIO_SOURCE_MAX_BYTES = 25 * 1024 * 1024;
|
|
30
31
|
var AUDIO_SOURCE_FETCH_TIMEOUT_MS = 3e4;
|
|
31
|
-
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
32
32
|
function normalizedContentType(value, fallback) {
|
|
33
33
|
if (value === null || value === "") return fallback;
|
|
34
34
|
return value.split(";", 1)[0]?.trim() || fallback;
|
|
@@ -103,22 +103,28 @@ function errorMessageFromContext(context) {
|
|
|
103
103
|
if (typeof message === "string" && message !== "") return message;
|
|
104
104
|
return context.rawText?.trim() || fallback;
|
|
105
105
|
}
|
|
106
|
+
var http = createAuthedClient({
|
|
107
|
+
baseUrl: `${API_BASE}/`,
|
|
108
|
+
service: SERVICE,
|
|
109
|
+
auth: { kind: "bearer" },
|
|
110
|
+
headers: { accept: "application/json" },
|
|
111
|
+
// 提取不 trim 且兜底回显 rawText 原文,标准键序提取表达不了,整段覆写。
|
|
112
|
+
mapError: (context) => upstreamError(context.status, errorMessageFromContext(context)),
|
|
113
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
114
|
+
502,
|
|
115
|
+
`openai request failed before receiving response: ${message ?? "unknown network error"}`
|
|
116
|
+
)
|
|
117
|
+
});
|
|
106
118
|
async function jsonRequest(ctx, input) {
|
|
107
119
|
if (input.body instanceof FormData) {
|
|
108
120
|
throw new TBError("internal", "openai jsonRequest cannot send multipart data");
|
|
109
121
|
}
|
|
110
|
-
const
|
|
111
|
-
const result = await http.request({
|
|
122
|
+
const result = await http.request(ctx, {
|
|
112
123
|
path: input.path,
|
|
113
|
-
method,
|
|
114
|
-
headers: input.headers
|
|
124
|
+
method: input.method ?? "GET",
|
|
125
|
+
headers: input.headers,
|
|
115
126
|
...input.body === void 0 ? {} : { json: input.body },
|
|
116
|
-
invalidJsonMessage: "OpenAI \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94"
|
|
117
|
-
mapError: (context) => upstreamError(context.status, errorMessageFromContext(context)),
|
|
118
|
-
mapTransportError: ({ message }) => upstreamError(
|
|
119
|
-
502,
|
|
120
|
-
`openai request failed before receiving response: ${message ?? "unknown network error"}`
|
|
121
|
-
)
|
|
127
|
+
invalidJsonMessage: "OpenAI \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94"
|
|
122
128
|
});
|
|
123
129
|
return result.data;
|
|
124
130
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
createProviderHttpClient
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-E6JCVKW6.js";
|
|
4
4
|
import {
|
|
5
5
|
asJsonObject,
|
|
6
6
|
booleanValue,
|
|
@@ -12,14 +12,14 @@ import {
|
|
|
12
12
|
createProviderPlugin,
|
|
13
13
|
requireApiKey,
|
|
14
14
|
upstreamError
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-ATK45BXV.js";
|
|
16
16
|
import {
|
|
17
17
|
assertPublicHttpUrl
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-U7B6DS2O.js";
|
|
19
19
|
import {
|
|
20
20
|
TBError,
|
|
21
21
|
external_exports
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-UZM2RXZH.js";
|
|
23
23
|
import "./chunk-U67V476Y.js";
|
|
24
24
|
|
|
25
25
|
// ../plugins/src/opengraph_io/api.ts
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-XYBU3WZH.js";
|
|
4
|
+
import "./chunk-E6JCVKW6.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-ATK45BXV.js";
|
|
14
|
+
import "./chunk-U7B6DS2O.js";
|
|
15
15
|
import {
|
|
16
16
|
TBError,
|
|
17
17
|
external_exports
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-UZM2RXZH.js";
|
|
19
19
|
import "./chunk-U67V476Y.js";
|
|
20
20
|
|
|
21
21
|
// ../plugins/src/openrouter/api.ts
|
|
22
22
|
var SERVICE = "openrouter";
|
|
23
23
|
var API_BASE = "https://openrouter.ai/api/v1";
|
|
24
|
-
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
25
24
|
var HEADER_INPUT_KEYS = ["httpReferer", "xTitle"];
|
|
26
25
|
function requireRecord(value, label) {
|
|
27
26
|
const result = asJsonObject(value);
|
|
@@ -55,25 +54,31 @@ function errorMessage(payload) {
|
|
|
55
54
|
if (body === void 0) return void 0;
|
|
56
55
|
return trimmedText(asJsonObject(body.error)?.message) ?? trimmedText(body.message);
|
|
57
56
|
}
|
|
57
|
+
var http = createAuthedClient({
|
|
58
|
+
baseUrl: `${API_BASE}/`,
|
|
59
|
+
service: SERVICE,
|
|
60
|
+
auth: { kind: "bearer" },
|
|
61
|
+
// 非 JSON 错误体**不回显原文**(bodyKind 门控),与标准提取的 string 取文语义不同,整段覆写。
|
|
62
|
+
mapError: ({ bodyKind, data, status }) => upstreamError(
|
|
63
|
+
status,
|
|
64
|
+
bodyKind === "json" ? errorMessage(data) ?? `OpenRouter \u8FD4\u56DE HTTP ${status}` : `OpenRouter \u8FD4\u56DE HTTP ${status}`
|
|
65
|
+
)
|
|
66
|
+
});
|
|
58
67
|
async function request(ctx, input) {
|
|
59
68
|
const hasBody = input.body !== void 0;
|
|
60
|
-
const headers = new Headers(
|
|
69
|
+
const headers = new Headers();
|
|
61
70
|
const referer = trimmedText(input.headerSource?.httpReferer);
|
|
62
71
|
const title = trimmedText(input.headerSource?.xTitle);
|
|
63
72
|
if (referer !== void 0) headers.set("HTTP-Referer", referer);
|
|
64
73
|
if (title !== void 0) headers.set("X-Title", title);
|
|
65
|
-
const response = await http.request({
|
|
74
|
+
const response = await http.request(ctx, {
|
|
66
75
|
method: input.method ?? "GET",
|
|
67
76
|
path: input.path,
|
|
68
77
|
query: Object.entries(input.query ?? {}),
|
|
69
78
|
headers,
|
|
70
79
|
...hasBody ? { json: compactDefined(input.body ?? {}) } : {},
|
|
71
80
|
responseType: "json",
|
|
72
|
-
invalidJson: "text"
|
|
73
|
-
mapError: ({ bodyKind, data, status }) => upstreamError(
|
|
74
|
-
status,
|
|
75
|
-
bodyKind === "json" ? errorMessage(data) ?? `OpenRouter \u8FD4\u56DE HTTP ${status}` : `OpenRouter \u8FD4\u56DE HTTP ${status}`
|
|
76
|
-
)
|
|
81
|
+
invalidJson: "text"
|
|
77
82
|
});
|
|
78
83
|
const contentType = response.headers.get("content-type") ?? "";
|
|
79
84
|
const isText = contentType.includes("xml") || contentType.includes("rss") || contentType.startsWith("text/");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
} from "./chunk-
|
|
2
|
+
createAuthedClient
|
|
3
|
+
} from "./chunk-XYBU3WZH.js";
|
|
4
|
+
import "./chunk-E6JCVKW6.js";
|
|
4
5
|
import {
|
|
5
6
|
asJsonObject,
|
|
6
7
|
compactDefined,
|
|
@@ -11,20 +12,29 @@ import {
|
|
|
11
12
|
createProviderPlugin,
|
|
12
13
|
requireApiKey,
|
|
13
14
|
upstreamError
|
|
14
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-ATK45BXV.js";
|
|
15
16
|
import {
|
|
16
17
|
assertPublicHttpUrl
|
|
17
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-U7B6DS2O.js";
|
|
18
19
|
import {
|
|
19
20
|
TBError,
|
|
20
21
|
external_exports
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-UZM2RXZH.js";
|
|
22
23
|
import "./chunk-U67V476Y.js";
|
|
23
24
|
|
|
24
25
|
// ../plugins/src/outline/api.ts
|
|
25
26
|
var SERVICE = "outline";
|
|
26
27
|
var CLOUD_API_BASE = "https://app.getoutline.com/api";
|
|
27
|
-
var http =
|
|
28
|
+
var http = createAuthedClient({
|
|
29
|
+
service: SERVICE,
|
|
30
|
+
auth: { kind: "bearer" },
|
|
31
|
+
headers: { accept: "application/json" },
|
|
32
|
+
errorMessage: {
|
|
33
|
+
// Outline 的错误消息在 `message` / `error` / `status` 三处之一。
|
|
34
|
+
keys: ["message", "error", "status"],
|
|
35
|
+
fallback: (status) => `outline request failed with status ${status}`
|
|
36
|
+
}
|
|
37
|
+
});
|
|
28
38
|
function nullableText(value) {
|
|
29
39
|
return value === null ? null : trimmedText(value);
|
|
30
40
|
}
|
|
@@ -60,26 +70,14 @@ function resolveApiBase(ctx) {
|
|
|
60
70
|
const normalized = `${url.origin}${path}`;
|
|
61
71
|
return normalized.endsWith("/api") ? normalized : `${normalized}/api`;
|
|
62
72
|
}
|
|
63
|
-
function errorMessage(status, payload) {
|
|
64
|
-
const body = asJsonObject(payload);
|
|
65
|
-
return trimmedText(body?.message) ?? trimmedText(body?.error) ?? trimmedText(body?.status) ?? `outline request failed with status ${status}`;
|
|
66
|
-
}
|
|
67
|
-
function errorPayload(data, bodyKind) {
|
|
68
|
-
return bodyKind === "invalid-json" && typeof data === "string" ? { message: data.trim() } : data;
|
|
69
|
-
}
|
|
70
73
|
async function request(ctx, path, body = {}) {
|
|
71
|
-
|
|
72
|
-
const result = await http.request({
|
|
74
|
+
requireApiKey(ctx, SERVICE);
|
|
75
|
+
const result = await http.request(ctx, {
|
|
73
76
|
baseUrl: `${resolveApiBase(ctx)}/`,
|
|
74
77
|
path,
|
|
75
78
|
method: "POST",
|
|
76
|
-
headers: { accept: "application/json", authorization: `Bearer ${apiKey}` },
|
|
77
79
|
json: body,
|
|
78
80
|
invalidJsonMessage: "outline \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
|
|
79
|
-
mapError: ({ bodyKind, data, status }) => upstreamError(
|
|
80
|
-
status,
|
|
81
|
-
errorMessage(status, errorPayload(data, bodyKind))
|
|
82
|
-
),
|
|
83
81
|
mapTransportError: ({ message }) => upstreamError(
|
|
84
82
|
502,
|
|
85
83
|
`outline ${path} failed before receiving response: ${message ?? "unknown network error"}`
|