@tool-bridge/server 0.16.0 → 0.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{airtable-S3T4TAN7.js → airtable-NOSOMOVB.js} +106 -114
- package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-BHIJ4LW5.js} +25 -16
- package/dist/{amap-LGVGNPML.js → amap-QRLP4TWZ.js} +114 -123
- package/dist/{anthropic-27RFZO35.js → anthropic-IEOI36EV.js} +34 -56
- package/dist/{apify-6WLYAIAS.js → apify-3CCYTQVK.js} +31 -49
- package/dist/{brave_search-K2SVJ66F.js → brave_search-PZNYDQG7.js} +52 -77
- package/dist/chunk-JXHMDBAY.js +45 -0
- package/dist/chunk-LMLX3DJF.js +50 -0
- package/dist/{chunk-YB2FLNWI.js → chunk-RVWZN3CI.js} +2103 -1775
- package/dist/{chunk-BB6ZLMTU.js → chunk-TLNUIPFZ.js} +492 -300
- package/dist/chunk-U5UHT7CX.js +977 -0
- package/dist/chunk-U67V476Y.js +35 -0
- package/dist/chunk-WW2IMPQK.js +283 -0
- package/dist/{chunk-VK3V2WTY.js → chunk-YASUMV2K.js} +4 -6
- package/dist/{circleci-WV3ITU7Q.js → circleci-VSJ4O5FC.js} +36 -55
- package/dist/{clerk-NFQEFKS4.js → clerk-CC2JZBZI.js} +60 -80
- package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-PJEBSEYQ.js} +90 -113
- package/dist/{cohere-5KEW7LWT.js → cohere-KBACYSPF.js} +33 -49
- package/dist/{confluence-SZE63S46.js → confluence-2PX3O7G5.js} +79 -115
- package/dist/{convertapi-QPG2JC5K.js → convertapi-BVOTD2PJ.js} +13 -16
- package/dist/{currencyapi-UO2APQRY.js → currencyapi-6ZQ2VNQ7.js} +30 -53
- package/dist/{deepseek-LJELIMM3.js → deepseek-MB3WVVTB.js} +30 -38
- package/dist/{docker_hub-2MFXSBOF.js → docker_hub-7CLQL2IJ.js} +141 -157
- package/dist/{dropbox-GQYNTTVA.js → dropbox-VFYDVUNK.js} +134 -141
- package/dist/{dub-KI2LHXST.js → dub-QN3EETJY.js} +61 -93
- package/dist/{e2b-WO6ISY3C.js → e2b-NKC3Y776.js} +39 -69
- package/dist/{exa-IZ7B3BPT.js → exa-KKZ6F25K.js} +49 -77
- package/dist/{fal_ai-LTMF36GJ.js → fal_ai-25LYJD2O.js} +37 -44
- package/dist/{feishu-WM7SLSFD.js → feishu-NRT55B3Q.js} +4 -6
- package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-3W3XXUG4.js} +4 -5
- package/dist/{figma-2Z274VQZ.js → figma-4FLP35TC.js} +56 -81
- package/dist/{firehydrant-IFI4R65V.js → firehydrant-BLXPLZ3X.js} +40 -53
- package/dist/{fixer-BCCZEB3D.js → fixer-4OR62TGE.js} +31 -43
- package/dist/{fly-755FXYB5.js → fly-MYCKOZZK.js} +50 -66
- package/dist/{front-4FZKKXXK.js → front-3DFYVMF3.js} +43 -66
- package/dist/{geocodio-WYKDJ3DP.js → geocodio-CXMD6VKA.js} +37 -63
- package/dist/{ghost-5BNQTCOH.js → ghost-4UUE737W.js} +51 -57
- package/dist/{github-ULELF5VX.js → github-WFS2ON2N.js} +48 -41
- package/dist/{gmail-G34WT64J.js → gmail-KW7FXA7A.js} +26 -36
- package/dist/{googlecalendar-BQU255SC.js → googlecalendar-AMH5JQMC.js} +57 -78
- package/dist/{googledocs-HPCNQXYJ.js → googledocs-R5VA6CKD.js} +14 -22
- package/dist/{grafana-VOV24FIC.js → grafana-IT6DWIVB.js} +95 -122
- package/dist/{graphhopper-D5RXW6AP.js → graphhopper-TYFDJZWC.js} +32 -46
- package/dist/index.d.ts +57 -50
- package/dist/index.js +4 -3
- package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-GJ4HXVXO.js} +35 -42
- package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-OAGR6PRF.js} +40 -60
- package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-BCKAMDGL.js} +30 -42
- package/dist/{jina_ai-E6UXFV2P.js → jina_ai-N3NXRVIZ.js} +32 -58
- package/dist/{jira-ZDSXGQ6W.js → jira-CHLBKWLO.js} +116 -126
- package/dist/{langsmith-TIFJRREW.js → langsmith-OIKOTPY3.js} +101 -121
- package/dist/{lemlist-DASEMJMA.js → lemlist-VAKYPKS3.js} +57 -68
- package/dist/{linear-KE6UP4SP.js → linear-Q6QTPJ5R.js} +109 -118
- package/dist/{logsnag-IMNDN4R5.js → logsnag-SQOQBTES.js} +31 -48
- package/dist/main.js +103 -102
- package/dist/{mattermost-HHHMUXQA.js → mattermost-G2KBEICM.js} +45 -62
- package/dist/{mem0-D2FGGOIY.js → mem0-D2FPLYDX.js} +72 -98
- package/dist/{memos-4OVIGFPH.js → memos-76PTWV5V.js} +68 -122
- package/dist/{metabase-33WCX5YD.js → metabase-TWSIDVBM.js} +47 -60
- package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-TP7TQUEJ.js} +35 -40
- package/dist/{mother_duck-M6VWS2VH.js → mother_duck-UXY5THYU.js} +42 -62
- package/dist/{ngrok-Z2PKQBHH.js → ngrok-RZW2ISJK.js} +42 -58
- package/dist/{notes-SS4RPC4K.js → notes-B2I6FWK2.js} +3 -5
- package/dist/{notion-FJCNQ6I7.js → notion-QOKRUE6M.js} +83 -97
- package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-ODLFWEJ7.js} +35 -39
- package/dist/{openai-JODZ4GKT.js → openai-ZPBPPPGT.js} +51 -55
- package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-EOI5UJKT.js} +61 -79
- package/dist/{openrouter-Q5XXEJZ7.js → openrouter-BUWLF3BG.js} +41 -55
- package/dist/{outline-RT2EHJ2X.js → outline-NXS3QRXO.js} +89 -104
- package/dist/{paddle-OF2V7GAC.js → paddle-T4MSKQ76.js} +34 -49
- package/dist/{perplexity-LNZEWLHG.js → perplexity-WW5N2LW7.js} +33 -50
- package/dist/{pinecone-JSJIXZYN.js → pinecone-RY5AZPQM.js} +65 -91
- package/dist/{pipedrive-D4CKVUXR.js → pipedrive-OHYQNZTU.js} +37 -59
- package/dist/{polar-M7ZYP6UR.js → polar-XZIAHXS5.js} +43 -53
- package/dist/{posthog-YV7CZOH4.js → posthog-DTPTWORY.js} +58 -77
- package/dist/{postmark-KYHLECRG.js → postmark-F4UCQKC3.js} +52 -71
- package/dist/{prerender-HCMHBKV2.js → prerender-P3Y2MLIC.js} +32 -50
- package/dist/{pubmed-WYVLCCN3.js → pubmed-RHU3GXFB.js} +28 -60
- package/dist/{railway-TWIRD5KR.js → railway-VB6SRLI6.js} +32 -39
- package/dist/{readwise-UZ467IQ7.js → readwise-DIMSKJZR.js} +62 -78
- package/dist/{render-MECUC5CC.js → render-XCCDCEEK.js} +48 -64
- package/dist/{replicate-A5MEK3SW.js → replicate-IUEOQ4JC.js} +41 -58
- package/dist/{resend-BC6EAWJQ.js → resend-N5MJZH5E.js} +27 -37
- package/dist/{rootly-ZM3QDUIS.js → rootly-25T4NBTU.js} +64 -76
- package/dist/{scrapfly-WAML42QJ.js → scrapfly-PK4XFXUA.js} +45 -51
- package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-ITPBMWQU.js} +25 -33
- package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-5U6ZYPKR.js} +29 -47
- package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-BJGCI2MU.js} +37 -56
- package/dist/{sentry-OKBPSTDM.js → sentry-63IC263P.js} +66 -85
- package/dist/{shodan-PPC6DYU4.js → shodan-2WBIFHFN.js} +42 -53
- package/dist/{shopify-EWGUHBXO.js → shopify-XLLJRAGM.js} +32 -49
- package/dist/{stripe-6RPDPC5W.js → stripe-WLVCY3UN.js} +4 -5
- package/dist/{supabase-SK7DQ42N.js → supabase-BKNZ35ER.js} +69 -88
- package/dist/{tavily-YCG5VQMH.js → tavily-YFSDEUTL.js} +37 -62
- package/dist/{telegram-2OES5FYB.js → telegram-FC35W74G.js} +168 -177
- package/dist/{telnyx-POOSBBR4.js → telnyx-MI32XZUG.js} +30 -50
- package/dist/{todoist-M7YD6YSS.js → todoist-4ZFJKZC6.js} +77 -89
- package/dist/{trello-IS6V5W3E.js → trello-UOGFNMK4.js} +108 -122
- package/dist/{turso-RCFHUFVH.js → turso-YTSTW3ZS.js} +52 -64
- package/dist/{twilio-OS2RXFGO.js → twilio-XAJDFUQH.js} +48 -55
- package/dist/{umami-PQ2SJ2LN.js → umami-ZVIUBPAI.js} +49 -69
- package/dist/{unsplash-C6BPZO4E.js → unsplash-IU3PLDNS.js} +35 -52
- package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-3EYJW7SY.js} +28 -40
- package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-PJG2ASRU.js} +11 -12
- package/dist/{v2ex-R4JWTEHN.js → v2ex-KFQWWGFC.js} +36 -61
- package/dist/{vercel-FZVYUOQD.js → vercel-I2ZDOQRL.js} +124 -150
- package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
- package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-BNXOJMB6.js} +26 -34
- package/dist/{wordpress-XRWGO6LG.js → wordpress-36D7BSMP.js} +87 -104
- package/dist/{workos-WR4NKOYL.js → workos-6X4JJRRC.js} +37 -56
- package/dist/{zhihu-BKZIB3WA.js → zhihu-CIXKCHIU.js} +35 -57
- package/package.json +5 -5
- package/dist/chunk-2O27H4Y2.js +0 -183
- package/dist/chunk-GKX72JMJ.js +0 -378
- package/dist/chunk-MLKGABMK.js +0 -9
|
@@ -1,98 +1,73 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-WW2IMPQK.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
compactDefined,
|
|
7
|
+
finiteNumber,
|
|
8
|
+
trimmedText
|
|
9
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
10
|
import {
|
|
2
11
|
createProviderPlugin,
|
|
3
12
|
requireApiKey,
|
|
4
13
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
14
|
+
} from "./chunk-YASUMV2K.js";
|
|
15
|
+
import "./chunk-U5UHT7CX.js";
|
|
10
16
|
import {
|
|
11
17
|
TBError,
|
|
12
18
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
19
|
+
} from "./chunk-RVWZN3CI.js";
|
|
20
|
+
import "./chunk-U67V476Y.js";
|
|
15
21
|
|
|
16
22
|
// ../plugins/src/dub/api.ts
|
|
17
23
|
var SERVICE = "dub";
|
|
18
24
|
var API_BASE = "https://api.dub.co";
|
|
25
|
+
var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
|
|
19
26
|
var LINKS_PATH = "/links";
|
|
20
27
|
var LINKS_INFO_PATH = "/links/info";
|
|
21
28
|
var LINKS_COUNT_PATH = "/links/count";
|
|
22
29
|
var TAGS_PATH = "/tags";
|
|
23
30
|
var FOLDERS_PATH = "/folders";
|
|
24
31
|
var ANALYTICS_PATH = "/analytics";
|
|
25
|
-
function asRecord(value) {
|
|
26
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
27
|
-
}
|
|
28
|
-
function optionalText(value) {
|
|
29
|
-
if (typeof value !== "string") return void 0;
|
|
30
|
-
const trimmed = value.trim();
|
|
31
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
32
|
-
}
|
|
33
32
|
function nullableText(value) {
|
|
34
|
-
return value === null ? null :
|
|
35
|
-
}
|
|
36
|
-
function optionalNumber(value) {
|
|
37
|
-
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
38
|
-
}
|
|
39
|
-
function appendQuery(url, query) {
|
|
40
|
-
for (const [key, value] of Object.entries(query)) {
|
|
41
|
-
if (value === void 0 || value === null || value === "") continue;
|
|
42
|
-
url.searchParams.set(key, Array.isArray(value) ? value.map(String).join(",") : String(value));
|
|
43
|
-
}
|
|
33
|
+
return value === null ? null : trimmedText(value);
|
|
44
34
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (text.trim() === "") return null;
|
|
48
|
-
try {
|
|
49
|
-
return JSON.parse(text);
|
|
50
|
-
} catch {
|
|
51
|
-
return text;
|
|
52
|
-
}
|
|
35
|
+
function providerQuery(query) {
|
|
36
|
+
return Object.entries(query).filter(([, value]) => value !== void 0 && value !== null && value !== "").map(([key, value]) => [key, Array.isArray(value) ? value.map(String).join(",") : String(value)]);
|
|
53
37
|
}
|
|
54
38
|
function errorMessage(payload) {
|
|
55
39
|
if (typeof payload === "string") return payload;
|
|
56
|
-
const object =
|
|
40
|
+
const object = asJsonObject(payload);
|
|
57
41
|
if (object === void 0) return void 0;
|
|
58
|
-
return
|
|
42
|
+
return trimmedText(asJsonObject(object.error)?.message) ?? trimmedText(object.message) ?? trimmedText(object.error);
|
|
59
43
|
}
|
|
60
44
|
async function request(ctx, path, input) {
|
|
61
45
|
const apiKey = requireApiKey(ctx, SERVICE);
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
authorization: `Bearer ${apiKey}`
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
throw upstreamError(502, error instanceof Error ? `dub \u8BF7\u6C42\u5931\u8D25: ${error.message}` : "dub \u8BF7\u6C42\u5931\u8D25");
|
|
80
|
-
}
|
|
81
|
-
if (!response.ok) {
|
|
82
|
-
throw upstreamError(
|
|
83
|
-
response.status,
|
|
84
|
-
errorMessage(payload) ?? (response.statusText || `dub \u8FD4\u56DE HTTP ${response.status}`)
|
|
85
|
-
);
|
|
86
|
-
}
|
|
87
|
-
return payload;
|
|
46
|
+
const { bodyKind, data } = await http.request({
|
|
47
|
+
path,
|
|
48
|
+
method: input.method,
|
|
49
|
+
query: providerQuery(input.query ?? {}),
|
|
50
|
+
headers: { accept: "application/json", authorization: `Bearer ${apiKey}` },
|
|
51
|
+
...input.body === void 0 ? {} : { json: input.body },
|
|
52
|
+
invalidJson: "text",
|
|
53
|
+
mapError: ({ data: payload, status, statusText }) => upstreamError(
|
|
54
|
+
status,
|
|
55
|
+
errorMessage(payload) ?? (statusText || `dub \u8FD4\u56DE HTTP ${status}`)
|
|
56
|
+
),
|
|
57
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
58
|
+
502,
|
|
59
|
+
message === void 0 ? "dub \u8BF7\u6C42\u5931\u8D25" : `dub \u8BF7\u6C42\u5931\u8D25: ${message}`
|
|
60
|
+
)
|
|
61
|
+
});
|
|
62
|
+
return bodyKind === "empty" ? null : data;
|
|
88
63
|
}
|
|
89
64
|
function responseText(value, field) {
|
|
90
|
-
const text =
|
|
65
|
+
const text = trimmedText(value);
|
|
91
66
|
if (text === void 0) throw upstreamError(502, `dub \u54CD\u5E94\u7F3A\u5C11 ${field}`);
|
|
92
67
|
return text;
|
|
93
68
|
}
|
|
94
69
|
function responseRecord(value, field) {
|
|
95
|
-
const object =
|
|
70
|
+
const object = asJsonObject(value);
|
|
96
71
|
if (object === void 0) throw upstreamError(502, `dub \u8FD4\u56DE\u7684 ${field} \u4E0D\u662F\u5BF9\u8C61`);
|
|
97
72
|
return object;
|
|
98
73
|
}
|
|
@@ -111,10 +86,10 @@ function normalizeLink(payload) {
|
|
|
111
86
|
qrCode: nullableText(object.qrCode),
|
|
112
87
|
title: nullableText(object.title),
|
|
113
88
|
archived: typeof object.archived === "boolean" ? object.archived : null,
|
|
114
|
-
clicks:
|
|
115
|
-
leads:
|
|
116
|
-
sales:
|
|
117
|
-
saleAmount:
|
|
89
|
+
clicks: finiteNumber(object.clicks) ?? null,
|
|
90
|
+
leads: finiteNumber(object.leads) ?? null,
|
|
91
|
+
sales: finiteNumber(object.sales) ?? null,
|
|
92
|
+
saleAmount: finiteNumber(object.saleAmount) ?? null,
|
|
118
93
|
createdAt: nullableText(object.createdAt),
|
|
119
94
|
updatedAt: nullableText(object.updatedAt),
|
|
120
95
|
raw: object
|
|
@@ -140,25 +115,18 @@ function normalizeFolder(payload) {
|
|
|
140
115
|
}
|
|
141
116
|
function extractCount(payload) {
|
|
142
117
|
if (typeof payload === "number") return payload;
|
|
143
|
-
const object =
|
|
144
|
-
const count =
|
|
118
|
+
const object = asJsonObject(payload);
|
|
119
|
+
const count = finiteNumber(object?.count) ?? finiteNumber(object?.links);
|
|
145
120
|
if (count === void 0) throw upstreamError(502, "dub count \u54CD\u5E94\u91CC\u6CA1\u6709 count");
|
|
146
121
|
return count;
|
|
147
122
|
}
|
|
148
|
-
function compact(input) {
|
|
149
|
-
const output = {};
|
|
150
|
-
for (const [key, value] of Object.entries(input)) {
|
|
151
|
-
if (value !== void 0) output[key] = value;
|
|
152
|
-
}
|
|
153
|
-
return output;
|
|
154
|
-
}
|
|
155
123
|
function assertNonEmptyPatch(patch, action) {
|
|
156
124
|
if (Object.keys(patch).length === 0) {
|
|
157
125
|
throw new TBError("invalid_argument", `${action} \u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u5F85\u66F4\u65B0\u5B57\u6BB5`);
|
|
158
126
|
}
|
|
159
127
|
}
|
|
160
128
|
function requirePathId(value, field) {
|
|
161
|
-
const text =
|
|
129
|
+
const text = trimmedText(value);
|
|
162
130
|
if (text === void 0) throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
|
|
163
131
|
return encodeURIComponent(text);
|
|
164
132
|
}
|
|
@@ -167,19 +135,19 @@ async function deleteResource(ctx, path) {
|
|
|
167
135
|
return { deleted: true, raw: payload };
|
|
168
136
|
}
|
|
169
137
|
async function createLink(input, ctx) {
|
|
170
|
-
const payload = await request(ctx, LINKS_PATH, { method: "POST", body:
|
|
138
|
+
const payload = await request(ctx, LINKS_PATH, { method: "POST", body: compactDefined(input) });
|
|
171
139
|
return { link: normalizeLink(payload) };
|
|
172
140
|
}
|
|
173
141
|
async function listLinks(input, ctx) {
|
|
174
|
-
const payload = await request(ctx, LINKS_PATH, { method: "GET", query:
|
|
142
|
+
const payload = await request(ctx, LINKS_PATH, { method: "GET", query: compactDefined(input) });
|
|
175
143
|
return { links: asArray(payload, "links").map((item) => normalizeLink(item)) };
|
|
176
144
|
}
|
|
177
145
|
async function retrieveLink(input, ctx) {
|
|
178
|
-
const query =
|
|
179
|
-
linkId:
|
|
180
|
-
domain:
|
|
181
|
-
key:
|
|
182
|
-
externalId:
|
|
146
|
+
const query = compactDefined({
|
|
147
|
+
linkId: trimmedText(input.linkId),
|
|
148
|
+
domain: trimmedText(input.domain),
|
|
149
|
+
key: trimmedText(input.key),
|
|
150
|
+
externalId: trimmedText(input.externalId)
|
|
183
151
|
});
|
|
184
152
|
if (Object.keys(query).length === 0) {
|
|
185
153
|
throw new TBError("invalid_argument", "retrieve_link \u9700\u8981 linkId\u3001externalId,\u6216 domain \u4E0E key \u6210\u5BF9");
|
|
@@ -192,7 +160,7 @@ async function retrieveLink(input, ctx) {
|
|
|
192
160
|
}
|
|
193
161
|
async function updateLink(input, ctx) {
|
|
194
162
|
const { linkId, ...body } = input;
|
|
195
|
-
const patch =
|
|
163
|
+
const patch = compactDefined(body);
|
|
196
164
|
assertNonEmptyPatch(patch, "update_link");
|
|
197
165
|
const path = `${LINKS_PATH}/${requirePathId(linkId, "linkId")}`;
|
|
198
166
|
const payload = await request(ctx, path, { method: "PATCH", body: patch });
|
|
@@ -202,20 +170,20 @@ async function deleteLink(input, ctx) {
|
|
|
202
170
|
return deleteResource(ctx, `${LINKS_PATH}/${requirePathId(input.linkId, "linkId")}`);
|
|
203
171
|
}
|
|
204
172
|
async function countLinks(input, ctx) {
|
|
205
|
-
const payload = await request(ctx, LINKS_COUNT_PATH, { method: "GET", query:
|
|
173
|
+
const payload = await request(ctx, LINKS_COUNT_PATH, { method: "GET", query: compactDefined(input) });
|
|
206
174
|
return { count: extractCount(payload), raw: payload };
|
|
207
175
|
}
|
|
208
176
|
async function listTags(input, ctx) {
|
|
209
|
-
const payload = await request(ctx, TAGS_PATH, { method: "GET", query:
|
|
177
|
+
const payload = await request(ctx, TAGS_PATH, { method: "GET", query: compactDefined(input) });
|
|
210
178
|
return { tags: asArray(payload, "tags").map((item) => normalizeTag(item)) };
|
|
211
179
|
}
|
|
212
180
|
async function createTag(input, ctx) {
|
|
213
|
-
const payload = await request(ctx, TAGS_PATH, { method: "POST", body:
|
|
181
|
+
const payload = await request(ctx, TAGS_PATH, { method: "POST", body: compactDefined(input) });
|
|
214
182
|
return { tag: normalizeTag(payload) };
|
|
215
183
|
}
|
|
216
184
|
async function updateTag(input, ctx) {
|
|
217
185
|
const { id, ...body } = input;
|
|
218
|
-
const patch =
|
|
186
|
+
const patch = compactDefined(body);
|
|
219
187
|
assertNonEmptyPatch(patch, "update_tag");
|
|
220
188
|
const payload = await request(ctx, `${TAGS_PATH}/${requirePathId(id, "id")}`, {
|
|
221
189
|
method: "PATCH",
|
|
@@ -227,16 +195,16 @@ async function deleteTag(input, ctx) {
|
|
|
227
195
|
return deleteResource(ctx, `${TAGS_PATH}/${requirePathId(input.id, "id")}`);
|
|
228
196
|
}
|
|
229
197
|
async function listFolders(input, ctx) {
|
|
230
|
-
const payload = await request(ctx, FOLDERS_PATH, { method: "GET", query:
|
|
198
|
+
const payload = await request(ctx, FOLDERS_PATH, { method: "GET", query: compactDefined(input) });
|
|
231
199
|
return { folders: asArray(payload, "folders").map((item) => normalizeFolder(item)) };
|
|
232
200
|
}
|
|
233
201
|
async function createFolder(input, ctx) {
|
|
234
|
-
const payload = await request(ctx, FOLDERS_PATH, { method: "POST", body:
|
|
202
|
+
const payload = await request(ctx, FOLDERS_PATH, { method: "POST", body: compactDefined(input) });
|
|
235
203
|
return { folder: normalizeFolder(payload) };
|
|
236
204
|
}
|
|
237
205
|
async function updateFolder(input, ctx) {
|
|
238
206
|
const { id, ...body } = input;
|
|
239
|
-
const patch =
|
|
207
|
+
const patch = compactDefined(body);
|
|
240
208
|
assertNonEmptyPatch(patch, "update_folder");
|
|
241
209
|
const payload = await request(ctx, `${FOLDERS_PATH}/${requirePathId(id, "id")}`, {
|
|
242
210
|
method: "PATCH",
|
|
@@ -248,7 +216,7 @@ async function deleteFolder(input, ctx) {
|
|
|
248
216
|
return deleteResource(ctx, `${FOLDERS_PATH}/${requirePathId(input.id, "id")}`);
|
|
249
217
|
}
|
|
250
218
|
async function retrieveAnalytics(input, ctx) {
|
|
251
|
-
const payload = await request(ctx, ANALYTICS_PATH, { method: "GET", query:
|
|
219
|
+
const payload = await request(ctx, ANALYTICS_PATH, { method: "GET", query: compactDefined(input) });
|
|
252
220
|
return { data: payload };
|
|
253
221
|
}
|
|
254
222
|
|
|
@@ -1,42 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-WW2IMPQK.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
compactDefined,
|
|
7
|
+
trimmedText
|
|
8
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
9
|
import {
|
|
2
10
|
createProviderPlugin,
|
|
3
11
|
requireApiKey,
|
|
4
12
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
13
|
+
} from "./chunk-YASUMV2K.js";
|
|
14
|
+
import "./chunk-U5UHT7CX.js";
|
|
10
15
|
import {
|
|
11
16
|
TBError,
|
|
12
17
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-RVWZN3CI.js";
|
|
19
|
+
import "./chunk-U67V476Y.js";
|
|
15
20
|
|
|
16
21
|
// ../plugins/src/e2b/api.ts
|
|
17
22
|
var SERVICE = "e2b";
|
|
18
23
|
var API_BASE = "https://api.e2b.app";
|
|
24
|
+
var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
|
|
19
25
|
var REQUEST_TIMEOUT_MS = 3e4;
|
|
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 compact(input) {
|
|
29
|
-
return Object.fromEntries(
|
|
30
|
-
Object.entries(input).filter(([, value]) => value !== void 0)
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
26
|
function requireText(value, field) {
|
|
34
|
-
const result =
|
|
27
|
+
const result = trimmedText(value);
|
|
35
28
|
if (result === void 0) throw new TBError("invalid_argument", `${field} is required.`);
|
|
36
29
|
return result;
|
|
37
30
|
}
|
|
38
31
|
function requireRecord(value, label) {
|
|
39
|
-
const result =
|
|
32
|
+
const result = asJsonObject(value);
|
|
40
33
|
if (result === void 0) throw upstreamError(502, `${label} was not an object`);
|
|
41
34
|
return result;
|
|
42
35
|
}
|
|
@@ -50,50 +43,27 @@ function errorMessage(payload, status) {
|
|
|
50
43
|
const trimmed = payload.trim();
|
|
51
44
|
if (trimmed !== "") return trimmed;
|
|
52
45
|
}
|
|
53
|
-
const body =
|
|
54
|
-
return
|
|
55
|
-
}
|
|
56
|
-
function buildUrl(path, query) {
|
|
57
|
-
const url = new URL(`${API_BASE}${path}`);
|
|
58
|
-
for (const [key, value] of Object.entries(query ?? {})) {
|
|
59
|
-
if (value === void 0) continue;
|
|
60
|
-
url.searchParams.set(key, Array.isArray(value) ? value.join(",") : String(value));
|
|
61
|
-
}
|
|
62
|
-
return url.toString();
|
|
46
|
+
const body = asJsonObject(payload);
|
|
47
|
+
return trimmedText(body?.message) ?? trimmedText(body?.error) ?? trimmedText(body?.detail) ?? `E2B request failed with status ${status}`;
|
|
63
48
|
}
|
|
64
49
|
async function request(ctx, options) {
|
|
65
|
-
const
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
throw upstreamError(502, error instanceof Error ? `E2B request failed: ${error.message}` : "E2B request failed");
|
|
84
|
-
}
|
|
85
|
-
const raw = response.status === 204 ? "" : await response.text().catch(() => "");
|
|
86
|
-
let payload = raw === "" ? options.emptySuccess ?? null : null;
|
|
87
|
-
if (raw !== "") {
|
|
88
|
-
try {
|
|
89
|
-
payload = JSON.parse(raw);
|
|
90
|
-
} catch {
|
|
91
|
-
if (!response.ok) payload = raw;
|
|
92
|
-
else throw upstreamError(502, "E2B returned invalid JSON");
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response.status));
|
|
96
|
-
return payload;
|
|
50
|
+
const query = Object.entries(options.query ?? {}).map(([key, value]) => [
|
|
51
|
+
key,
|
|
52
|
+
// 数组 query 拼成一个逗号串:E2B 不认重复的同名参数。
|
|
53
|
+
Array.isArray(value) ? value.join(",") : value
|
|
54
|
+
]);
|
|
55
|
+
const { data } = await http.request({
|
|
56
|
+
path: options.path,
|
|
57
|
+
method: options.method ?? "GET",
|
|
58
|
+
query,
|
|
59
|
+
headers: { "accept": "application/json", "x-api-key": requireApiKey(ctx, SERVICE) },
|
|
60
|
+
...options.body === void 0 ? {} : { json: options.body },
|
|
61
|
+
timeoutMs: REQUEST_TIMEOUT_MS,
|
|
62
|
+
invalidJsonMessage: "E2B returned invalid JSON",
|
|
63
|
+
mapError: ({ data: payload, status }) => upstreamError(status, errorMessage(payload, status)),
|
|
64
|
+
mapTransportError: ({ kind, message }) => kind === "timeout" ? upstreamError(504, `E2B ${REQUEST_TIMEOUT_MS / 1e3}s \u5185\u6CA1\u6709\u8FD4\u56DE`) : upstreamError(502, message === void 0 ? "E2B request failed" : `E2B request failed: ${message}`)
|
|
65
|
+
});
|
|
66
|
+
return data === void 0 ? options.emptySuccess ?? null : data;
|
|
97
67
|
}
|
|
98
68
|
async function requestSandboxArray(ctx, options) {
|
|
99
69
|
const payload = await request(ctx, options);
|
|
@@ -105,7 +75,7 @@ async function createSandbox(input, ctx) {
|
|
|
105
75
|
// 创建走的是 v1 路径,不是列表那个 /v2/sandboxes。
|
|
106
76
|
path: "/sandboxes",
|
|
107
77
|
method: "POST",
|
|
108
|
-
body:
|
|
78
|
+
body: compactDefined({
|
|
109
79
|
templateID: requireText(input.templateID, "templateID"),
|
|
110
80
|
timeout: input.timeout,
|
|
111
81
|
autoPause: input.autoPause,
|
|
@@ -117,7 +87,7 @@ async function createSandbox(input, ctx) {
|
|
|
117
87
|
metadata: input.metadata,
|
|
118
88
|
envVars: input.envVars,
|
|
119
89
|
// `mcp: null` 是"显式关掉 MCP",与"没给这个字段"不是一回事,故不能被 compact 掉。
|
|
120
|
-
mcp: input.mcp === null ? null :
|
|
90
|
+
mcp: input.mcp === null ? null : asJsonObject(input.mcp),
|
|
121
91
|
volumeMounts: input.volumeMounts
|
|
122
92
|
})
|
|
123
93
|
});
|
|
@@ -126,10 +96,10 @@ async function createSandbox(input, ctx) {
|
|
|
126
96
|
async function listSandboxes(input, ctx) {
|
|
127
97
|
const sandboxes = await requestSandboxArray(ctx, {
|
|
128
98
|
path: "/v2/sandboxes",
|
|
129
|
-
query:
|
|
130
|
-
metadata:
|
|
99
|
+
query: compactDefined({
|
|
100
|
+
metadata: trimmedText(input.metadata),
|
|
131
101
|
state: stringArray(input.state),
|
|
132
|
-
nextToken:
|
|
102
|
+
nextToken: trimmedText(input.nextToken),
|
|
133
103
|
limit: input.limit
|
|
134
104
|
})
|
|
135
105
|
});
|
|
@@ -1,93 +1,65 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-WW2IMPQK.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
compactDefined,
|
|
7
|
+
trimmedText
|
|
8
|
+
} from "./chunk-JXHMDBAY.js";
|
|
1
9
|
import {
|
|
2
10
|
createProviderPlugin,
|
|
3
11
|
requireApiKey,
|
|
4
12
|
upstreamError
|
|
5
|
-
} from "./chunk-
|
|
6
|
-
import
|
|
7
|
-
guardedFetch
|
|
8
|
-
} from "./chunk-2O27H4Y2.js";
|
|
9
|
-
import "./chunk-GKX72JMJ.js";
|
|
13
|
+
} from "./chunk-YASUMV2K.js";
|
|
14
|
+
import "./chunk-U5UHT7CX.js";
|
|
10
15
|
import {
|
|
11
16
|
TBError,
|
|
12
17
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-RVWZN3CI.js";
|
|
19
|
+
import "./chunk-U67V476Y.js";
|
|
15
20
|
|
|
16
21
|
// ../plugins/src/exa/api.ts
|
|
17
22
|
var SERVICE = "exa";
|
|
18
23
|
var API_BASE = "https://api.exa.ai";
|
|
24
|
+
var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
|
|
19
25
|
var SEARCH_PATH = "/search";
|
|
20
26
|
var CONTENTS_PATH = "/contents";
|
|
21
27
|
var ANSWER_PATH = "/answer";
|
|
22
28
|
var FIND_SIMILAR_PATH = "/findSimilar";
|
|
23
|
-
function asRecord(value) {
|
|
24
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
25
|
-
}
|
|
26
|
-
function optionalText(value) {
|
|
27
|
-
if (typeof value !== "string") return void 0;
|
|
28
|
-
const trimmed = value.trim();
|
|
29
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
30
|
-
}
|
|
31
|
-
function compact(input) {
|
|
32
|
-
const output = {};
|
|
33
|
-
for (const [key, value] of Object.entries(input)) {
|
|
34
|
-
if (value !== void 0) output[key] = value;
|
|
35
|
-
}
|
|
36
|
-
return output;
|
|
37
|
-
}
|
|
38
|
-
async function readPayload(response) {
|
|
39
|
-
const text = await response.text().catch(() => "");
|
|
40
|
-
if (text.trim() === "") return null;
|
|
41
|
-
try {
|
|
42
|
-
return JSON.parse(text);
|
|
43
|
-
} catch {
|
|
44
|
-
return text;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
29
|
function errorMessage(payload) {
|
|
48
|
-
if (typeof payload === "string") return
|
|
49
|
-
const object =
|
|
30
|
+
if (typeof payload === "string") return trimmedText(payload);
|
|
31
|
+
const object = asJsonObject(payload);
|
|
50
32
|
if (object === void 0) return void 0;
|
|
51
|
-
return
|
|
33
|
+
return trimmedText(object.error) ?? trimmedText(object.message) ?? trimmedText(object.detail);
|
|
52
34
|
}
|
|
53
35
|
async function request(ctx, path, body) {
|
|
54
36
|
const apiKey = requireApiKey(ctx, SERVICE);
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
throw upstreamError(
|
|
74
|
-
response.status,
|
|
75
|
-
errorMessage(payload) ?? (response.statusText || `exa \u8FD4\u56DE HTTP ${response.status}`)
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
if (payload === null) return {};
|
|
79
|
-
if (typeof payload === "string") {
|
|
80
|
-
throw upstreamError(502, "exa \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94");
|
|
81
|
-
}
|
|
82
|
-
return payload;
|
|
37
|
+
const { bodyKind, data } = await http.request({
|
|
38
|
+
path,
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { "accept": "application/json", "x-api-key": apiKey },
|
|
41
|
+
json: body,
|
|
42
|
+
invalidJson: "text",
|
|
43
|
+
mapError: ({ data: payload, status, statusText }) => upstreamError(
|
|
44
|
+
status,
|
|
45
|
+
errorMessage(payload) ?? (statusText || `exa \u8FD4\u56DE HTTP ${status}`)
|
|
46
|
+
),
|
|
47
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
48
|
+
502,
|
|
49
|
+
message === void 0 ? "exa \u8BF7\u6C42\u5931\u8D25" : `exa \u8BF7\u6C42\u5931\u8D25: ${message}`
|
|
50
|
+
)
|
|
51
|
+
});
|
|
52
|
+
if (bodyKind === "empty") return {};
|
|
53
|
+
if (bodyKind === "invalid-json") throw upstreamError(502, "exa \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94");
|
|
54
|
+
return data;
|
|
83
55
|
}
|
|
84
56
|
function responseText(value, field) {
|
|
85
|
-
const text =
|
|
57
|
+
const text = trimmedText(value);
|
|
86
58
|
if (text === void 0) throw upstreamError(502, `exa \u54CD\u5E94\u7F3A\u5C11 ${field}`);
|
|
87
59
|
return text;
|
|
88
60
|
}
|
|
89
61
|
function responseRecord(payload, field) {
|
|
90
|
-
const object =
|
|
62
|
+
const object = asJsonObject(payload);
|
|
91
63
|
if (object === void 0) throw upstreamError(502, `exa ${field} \u54CD\u5E94\u4E0D\u662F\u5BF9\u8C61`);
|
|
92
64
|
return object;
|
|
93
65
|
}
|
|
@@ -104,44 +76,44 @@ function assertDomainFilters(input) {
|
|
|
104
76
|
}
|
|
105
77
|
}
|
|
106
78
|
function normalizeResults(object, extra = {}) {
|
|
107
|
-
return
|
|
79
|
+
return compactDefined({
|
|
108
80
|
requestId: responseText(object.requestId, "requestId"),
|
|
109
81
|
results: resultItems(object.results, "results"),
|
|
110
82
|
...extra,
|
|
111
|
-
costDollars:
|
|
83
|
+
costDollars: asJsonObject(object.costDollars)
|
|
112
84
|
});
|
|
113
85
|
}
|
|
114
86
|
async function search(input, ctx) {
|
|
115
87
|
assertDomainFilters(input);
|
|
116
|
-
const object = responseRecord(await request(ctx, SEARCH_PATH,
|
|
88
|
+
const object = responseRecord(await request(ctx, SEARCH_PATH, compactDefined(input)), "\u641C\u7D22");
|
|
117
89
|
return normalizeResults(object, {
|
|
118
|
-
searchType:
|
|
119
|
-
output:
|
|
90
|
+
searchType: trimmedText(object.searchType),
|
|
91
|
+
output: asJsonObject(object.output)
|
|
120
92
|
});
|
|
121
93
|
}
|
|
122
94
|
async function getContents(input, ctx) {
|
|
123
|
-
const object = responseRecord(await request(ctx, CONTENTS_PATH,
|
|
124
|
-
return
|
|
95
|
+
const object = responseRecord(await request(ctx, CONTENTS_PATH, compactDefined(input)), "contents");
|
|
96
|
+
return compactDefined({
|
|
125
97
|
requestId: responseText(object.requestId, "requestId"),
|
|
126
98
|
results: resultItems(object.results, "results"),
|
|
127
99
|
// statuses 是可选的:字段缺席与"空数组"不是一回事,前者不该被伪造成后者。
|
|
128
100
|
statuses: object.statuses === void 0 ? void 0 : resultItems(object.statuses, "statuses"),
|
|
129
|
-
costDollars:
|
|
101
|
+
costDollars: asJsonObject(object.costDollars)
|
|
130
102
|
});
|
|
131
103
|
}
|
|
132
104
|
async function answer(input, ctx) {
|
|
133
|
-
const object = responseRecord(await request(ctx, ANSWER_PATH,
|
|
134
|
-
return
|
|
105
|
+
const object = responseRecord(await request(ctx, ANSWER_PATH, compactDefined(input)), "answer");
|
|
106
|
+
return compactDefined({
|
|
135
107
|
// answer 既可能是一段文本,也可能是结构化对象(取决于 Exa 选的答案形态)。
|
|
136
108
|
// 文本这里**不 trim**:它是内容而非标识符,首尾空白由调用方自己决定怎么处理。
|
|
137
|
-
answer: typeof object.answer === "string" ? object.answer :
|
|
109
|
+
answer: typeof object.answer === "string" ? object.answer : asJsonObject(object.answer),
|
|
138
110
|
citations: resultItems(object.citations, "citations"),
|
|
139
|
-
costDollars:
|
|
111
|
+
costDollars: asJsonObject(object.costDollars)
|
|
140
112
|
});
|
|
141
113
|
}
|
|
142
114
|
async function findSimilar(input, ctx) {
|
|
143
115
|
assertDomainFilters(input);
|
|
144
|
-
return normalizeResults(responseRecord(await request(ctx, FIND_SIMILAR_PATH,
|
|
116
|
+
return normalizeResults(responseRecord(await request(ctx, FIND_SIMILAR_PATH, compactDefined(input)), "\u641C\u7D22"));
|
|
145
117
|
}
|
|
146
118
|
|
|
147
119
|
// ../plugins/src/exa/schema.ts
|