@tool-bridge/server 0.16.0 → 0.19.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-23JBIM6X.js} +106 -114
- package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-ADWBTCIH.js} +25 -16
- package/dist/{amap-LGVGNPML.js → amap-CYQCYW2Z.js} +114 -123
- package/dist/{anthropic-27RFZO35.js → anthropic-5P62HDNR.js} +34 -56
- package/dist/{apify-6WLYAIAS.js → apify-54RZUAGW.js} +31 -49
- package/dist/{brave_search-K2SVJ66F.js → brave_search-AHJ6FTD5.js} +52 -77
- package/dist/{chunk-VK3V2WTY.js → chunk-B4P6YZFS.js} +4 -6
- package/dist/{chunk-BB6ZLMTU.js → chunk-CLEZ6YQ6.js} +2600 -481
- package/dist/chunk-JXHMDBAY.js +45 -0
- package/dist/chunk-LMLX3DJF.js +50 -0
- package/dist/{chunk-YB2FLNWI.js → chunk-OKRZPQ3R.js} +2558 -1926
- package/dist/chunk-SWBNHIO4.js +977 -0
- package/dist/chunk-U67V476Y.js +35 -0
- package/dist/chunk-VLOIDU5U.js +283 -0
- package/dist/{circleci-WV3ITU7Q.js → circleci-UM3NSQJ3.js} +36 -55
- package/dist/{clerk-NFQEFKS4.js → clerk-FE5LQ2CZ.js} +60 -80
- package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-KEZABKUT.js} +90 -113
- package/dist/{cohere-5KEW7LWT.js → cohere-4IPJADXP.js} +33 -49
- package/dist/{confluence-SZE63S46.js → confluence-56QEKNQI.js} +79 -115
- package/dist/{convertapi-QPG2JC5K.js → convertapi-3QRM5K5T.js} +13 -16
- package/dist/{currencyapi-UO2APQRY.js → currencyapi-L6G4OND5.js} +30 -53
- package/dist/{deepseek-LJELIMM3.js → deepseek-LGC6HBFG.js} +30 -38
- package/dist/{docker_hub-2MFXSBOF.js → docker_hub-XDMK3BIU.js} +141 -157
- package/dist/{dropbox-GQYNTTVA.js → dropbox-4QARMFZU.js} +134 -141
- package/dist/{dub-KI2LHXST.js → dub-C6JSJKOT.js} +61 -93
- package/dist/{e2b-WO6ISY3C.js → e2b-6A6TVACJ.js} +39 -69
- package/dist/{exa-IZ7B3BPT.js → exa-SIWWW6AA.js} +49 -77
- package/dist/{fal_ai-LTMF36GJ.js → fal_ai-3IJXOKSP.js} +37 -44
- package/dist/{feishu-WM7SLSFD.js → feishu-L4KDA4DC.js} +4 -6
- package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-SDM75H4P.js} +4 -5
- package/dist/{figma-2Z274VQZ.js → figma-6DD436DN.js} +56 -81
- package/dist/{firehydrant-IFI4R65V.js → firehydrant-SYSGYB3R.js} +40 -53
- package/dist/{fixer-BCCZEB3D.js → fixer-FZG7ASTF.js} +31 -43
- package/dist/{fly-755FXYB5.js → fly-HMRCZBUC.js} +50 -66
- package/dist/{front-4FZKKXXK.js → front-FAFSD7I3.js} +43 -66
- package/dist/{geocodio-WYKDJ3DP.js → geocodio-4D3TWENM.js} +37 -63
- package/dist/{ghost-5BNQTCOH.js → ghost-OSO2FOZS.js} +51 -57
- package/dist/{github-ULELF5VX.js → github-OR4I4RHE.js} +48 -41
- package/dist/{gmail-G34WT64J.js → gmail-5AOPJ63E.js} +26 -36
- package/dist/{googlecalendar-BQU255SC.js → googlecalendar-SOJIJUWH.js} +57 -78
- package/dist/{googledocs-HPCNQXYJ.js → googledocs-QSKN5TLN.js} +14 -22
- package/dist/{grafana-VOV24FIC.js → grafana-R3AIZM7M.js} +95 -122
- package/dist/{graphhopper-D5RXW6AP.js → graphhopper-4CR3QOAX.js} +32 -46
- package/dist/index.d.ts +108 -56
- package/dist/index.js +4 -3
- package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-OBCG6X6J.js} +35 -42
- package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-NHH3DTQW.js} +40 -60
- package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-7POMCBEC.js} +30 -42
- package/dist/{jina_ai-E6UXFV2P.js → jina_ai-YXVKROV4.js} +32 -58
- package/dist/{jira-ZDSXGQ6W.js → jira-LADO3VJU.js} +116 -126
- package/dist/{langsmith-TIFJRREW.js → langsmith-XZ6UAQFU.js} +101 -121
- package/dist/{lemlist-DASEMJMA.js → lemlist-P74GLNE7.js} +57 -68
- package/dist/{linear-KE6UP4SP.js → linear-CXJ7D37A.js} +109 -118
- package/dist/{logsnag-IMNDN4R5.js → logsnag-EVVHWFLK.js} +31 -48
- package/dist/main.js +103 -102
- package/dist/{mattermost-HHHMUXQA.js → mattermost-WG2MRGBD.js} +45 -62
- package/dist/{mem0-D2FGGOIY.js → mem0-HQWUKG6U.js} +72 -98
- package/dist/{memos-4OVIGFPH.js → memos-SQMJIFOE.js} +68 -122
- package/dist/{metabase-33WCX5YD.js → metabase-E27G2DZI.js} +47 -60
- package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-MIL63NIT.js} +35 -40
- package/dist/{mother_duck-M6VWS2VH.js → mother_duck-AIZVCBNR.js} +42 -62
- package/dist/{ngrok-Z2PKQBHH.js → ngrok-XS4DVIQS.js} +42 -58
- package/dist/{notes-SS4RPC4K.js → notes-JEOUSL2Y.js} +3 -5
- package/dist/{notion-FJCNQ6I7.js → notion-U4EZVDW2.js} +83 -97
- package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-AZSQEYEJ.js} +35 -39
- package/dist/{openai-JODZ4GKT.js → openai-HW3SYMTQ.js} +51 -55
- package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-QX74MAEL.js} +61 -79
- package/dist/{openrouter-Q5XXEJZ7.js → openrouter-OXSKYL6N.js} +41 -55
- package/dist/{outline-RT2EHJ2X.js → outline-CCQAPDSW.js} +89 -104
- package/dist/{paddle-OF2V7GAC.js → paddle-6KQPSSCK.js} +34 -49
- package/dist/{perplexity-LNZEWLHG.js → perplexity-2TXO7IQE.js} +33 -50
- package/dist/{pinecone-JSJIXZYN.js → pinecone-YOO7NULI.js} +65 -91
- package/dist/{pipedrive-D4CKVUXR.js → pipedrive-Q6RIFIFP.js} +37 -59
- package/dist/{polar-M7ZYP6UR.js → polar-KUMGCES3.js} +43 -53
- package/dist/{posthog-YV7CZOH4.js → posthog-VXQHBSMB.js} +58 -77
- package/dist/{postmark-KYHLECRG.js → postmark-YLIPF52S.js} +52 -71
- package/dist/{prerender-HCMHBKV2.js → prerender-CRY7UJN5.js} +32 -50
- package/dist/{pubmed-WYVLCCN3.js → pubmed-3Z4T5AM7.js} +28 -60
- package/dist/{railway-TWIRD5KR.js → railway-BP37IGFL.js} +32 -39
- package/dist/{readwise-UZ467IQ7.js → readwise-HTKICF4K.js} +62 -78
- package/dist/{render-MECUC5CC.js → render-WIVTUXJH.js} +48 -64
- package/dist/{replicate-A5MEK3SW.js → replicate-JJYPA43D.js} +41 -58
- package/dist/{resend-BC6EAWJQ.js → resend-TKHZVG7A.js} +27 -37
- package/dist/{rootly-ZM3QDUIS.js → rootly-FRSZLG5U.js} +64 -76
- package/dist/{scrapfly-WAML42QJ.js → scrapfly-M5WXGQWE.js} +45 -51
- package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-PMXNLLBK.js} +25 -33
- package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-HFW4TAOH.js} +29 -47
- package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-KXVH2VZQ.js} +37 -56
- package/dist/{sentry-OKBPSTDM.js → sentry-WWOT2LRX.js} +66 -85
- package/dist/{shodan-PPC6DYU4.js → shodan-FY635H35.js} +42 -53
- package/dist/{shopify-EWGUHBXO.js → shopify-HQLBVSA5.js} +32 -49
- package/dist/{stripe-6RPDPC5W.js → stripe-GJN2GOHB.js} +4 -5
- package/dist/{supabase-SK7DQ42N.js → supabase-BBNZGQU6.js} +69 -88
- package/dist/{tavily-YCG5VQMH.js → tavily-DPENIBOG.js} +37 -62
- package/dist/{telegram-2OES5FYB.js → telegram-L4NONG6H.js} +168 -177
- package/dist/{telnyx-POOSBBR4.js → telnyx-H67MAEZS.js} +30 -50
- package/dist/{todoist-M7YD6YSS.js → todoist-G2BSP4DX.js} +77 -89
- package/dist/{trello-IS6V5W3E.js → trello-7WMVFDG2.js} +108 -122
- package/dist/{turso-RCFHUFVH.js → turso-ZUAESFC2.js} +52 -64
- package/dist/{twilio-OS2RXFGO.js → twilio-EYFYIX3B.js} +48 -55
- package/dist/{umami-PQ2SJ2LN.js → umami-AXAUDUVF.js} +49 -69
- package/dist/{unsplash-C6BPZO4E.js → unsplash-UCQAWPLR.js} +35 -52
- package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-ZPZ4ASU6.js} +28 -40
- package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-4QVKKUD5.js} +11 -12
- package/dist/{v2ex-R4JWTEHN.js → v2ex-VGEFJTYC.js} +36 -61
- package/dist/{vercel-FZVYUOQD.js → vercel-JME4TSCN.js} +124 -150
- package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
- package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-TRGU2MDG.js} +26 -34
- package/dist/{wordpress-XRWGO6LG.js → wordpress-WRUKLCZR.js} +87 -104
- package/dist/{workos-WR4NKOYL.js → workos-ZDW4EHS4.js} +37 -56
- package/dist/{zhihu-BKZIB3WA.js → zhihu-4VI67CWU.js} +35 -57
- package/package.json +3 -3
- package/dist/chunk-2O27H4Y2.js +0 -183
- package/dist/chunk-GKX72JMJ.js +0 -378
- package/dist/chunk-MLKGABMK.js +0 -9
|
@@ -1,21 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-VLOIDU5U.js";
|
|
4
|
+
import {
|
|
5
|
+
asJsonObject,
|
|
6
|
+
booleanValue,
|
|
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-B4P6YZFS.js";
|
|
14
|
+
import "./chunk-SWBNHIO4.js";
|
|
10
15
|
import {
|
|
11
16
|
TBError,
|
|
12
17
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-OKRZPQ3R.js";
|
|
19
|
+
import "./chunk-U67V476Y.js";
|
|
15
20
|
|
|
16
21
|
// ../plugins/src/amap/api.ts
|
|
17
22
|
var SERVICE = "amap";
|
|
18
23
|
var API_BASE = "https://restapi.amap.com";
|
|
24
|
+
var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
|
|
19
25
|
var MAX_GET_URL_LENGTH = 2e3;
|
|
20
26
|
var AUTH_INFOS = /* @__PURE__ */ new Set([
|
|
21
27
|
"INVALID_USER_KEY",
|
|
@@ -31,23 +37,12 @@ var RATE_LIMIT_INFOS = /* @__PURE__ */ new Set(["DAILY_QUERY_OVER_LIMIT", "ACCES
|
|
|
31
37
|
var RATE_LIMIT_INFOCODES = /* @__PURE__ */ new Set(["10003", "10004"]);
|
|
32
38
|
var INPUT_ERROR_INFOS = /* @__PURE__ */ new Set(["MISSING_REQUIRED_PARAMS", "INVALID_PARAMS"]);
|
|
33
39
|
var INPUT_ERROR_INFOCODES = /* @__PURE__ */ new Set(["18001", "18002"]);
|
|
34
|
-
function text(value) {
|
|
35
|
-
if (typeof value !== "string") return void 0;
|
|
36
|
-
const trimmed = value.trim();
|
|
37
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
38
|
-
}
|
|
39
40
|
function number(value) {
|
|
40
41
|
return typeof value === "number" ? value : void 0;
|
|
41
42
|
}
|
|
42
|
-
function boolean(value) {
|
|
43
|
-
return typeof value === "boolean" ? value : void 0;
|
|
44
|
-
}
|
|
45
|
-
function record(value) {
|
|
46
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
47
|
-
}
|
|
48
43
|
function recordArray(value) {
|
|
49
44
|
if (!Array.isArray(value)) return [];
|
|
50
|
-
return value.map((item) =>
|
|
45
|
+
return value.map((item) => asJsonObject(item)).filter((item) => item !== void 0);
|
|
51
46
|
}
|
|
52
47
|
function stringOrStringArray(value) {
|
|
53
48
|
if (typeof value === "string") return value;
|
|
@@ -55,7 +50,7 @@ function stringOrStringArray(value) {
|
|
|
55
50
|
return value.filter((item) => typeof item === "string");
|
|
56
51
|
}
|
|
57
52
|
function requireText(value, field) {
|
|
58
|
-
const result =
|
|
53
|
+
const result = trimmedText(value);
|
|
59
54
|
if (result === void 0) throw new TBError("invalid_argument", `${field} is required.`);
|
|
60
55
|
return result;
|
|
61
56
|
}
|
|
@@ -93,30 +88,26 @@ function amapError(status, payload) {
|
|
|
93
88
|
return upstreamError(status === 0 ? 500 : status, message);
|
|
94
89
|
}
|
|
95
90
|
async function amapGet(ctx, path, query) {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
91
|
+
const { data, status } = await http.request({
|
|
92
|
+
path,
|
|
93
|
+
method: "GET",
|
|
94
|
+
query: Object.entries({ ...query, key: requireApiKey(ctx, SERVICE) }),
|
|
95
|
+
headers: { accept: "application/json" },
|
|
96
|
+
invalidJsonMessage: "amap \u8FD4\u56DE\u4E86\u975E JSON \u5BF9\u8C61\u54CD\u5E94",
|
|
97
|
+
mapError: ({ data: payload2, status: status2 }) => {
|
|
98
|
+
const body = asJsonObject(payload2);
|
|
99
|
+
return body === void 0 ? new TBError("unavailable", "amap \u8FD4\u56DE\u4E86\u975E JSON \u5BF9\u8C61\u54CD\u5E94", { retryable: true }) : amapError(status2, body);
|
|
100
|
+
},
|
|
101
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
103
102
|
502,
|
|
104
|
-
|
|
105
|
-
)
|
|
106
|
-
}
|
|
107
|
-
const
|
|
108
|
-
let payload;
|
|
109
|
-
if (raw.trim() !== "") {
|
|
110
|
-
try {
|
|
111
|
-
payload = record(JSON.parse(raw));
|
|
112
|
-
} catch {
|
|
113
|
-
payload = void 0;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
103
|
+
message === void 0 ? "amap request failed" : `amap request failed: ${message}`
|
|
104
|
+
)
|
|
105
|
+
});
|
|
106
|
+
const payload = asJsonObject(data);
|
|
116
107
|
if (payload === void 0) {
|
|
117
108
|
throw new TBError("unavailable", "amap \u8FD4\u56DE\u4E86\u975E JSON \u5BF9\u8C61\u54CD\u5E94", { retryable: true });
|
|
118
109
|
}
|
|
119
|
-
if (
|
|
110
|
+
if (payload.status !== "1") throw amapError(status, payload);
|
|
120
111
|
return payload;
|
|
121
112
|
}
|
|
122
113
|
function assertGetUrlLength(ctx, path, query) {
|
|
@@ -126,37 +117,37 @@ function assertGetUrlLength(ctx, path, query) {
|
|
|
126
117
|
}
|
|
127
118
|
function poi(item) {
|
|
128
119
|
return {
|
|
129
|
-
id:
|
|
130
|
-
name:
|
|
131
|
-
type:
|
|
132
|
-
typecode:
|
|
133
|
-
address:
|
|
134
|
-
location:
|
|
135
|
-
pname:
|
|
136
|
-
cityname:
|
|
137
|
-
adname:
|
|
120
|
+
id: trimmedText(item.id),
|
|
121
|
+
name: trimmedText(item.name),
|
|
122
|
+
type: trimmedText(item.type),
|
|
123
|
+
typecode: trimmedText(item.typecode),
|
|
124
|
+
address: trimmedText(item.address),
|
|
125
|
+
location: trimmedText(item.location),
|
|
126
|
+
pname: trimmedText(item.pname),
|
|
127
|
+
cityname: trimmedText(item.cityname),
|
|
128
|
+
adname: trimmedText(item.adname)
|
|
138
129
|
};
|
|
139
130
|
}
|
|
140
131
|
function poiSearchOutput(payload) {
|
|
141
132
|
return {
|
|
142
|
-
count:
|
|
133
|
+
count: trimmedText(payload.count),
|
|
143
134
|
pois: recordArray(payload.pois).map((item) => poi(item))
|
|
144
135
|
};
|
|
145
136
|
}
|
|
146
137
|
async function geocode(input, ctx) {
|
|
147
138
|
const payload = await amapGet(ctx, "/v3/geocode/geo", {
|
|
148
139
|
address: requireText(input.address, "address"),
|
|
149
|
-
city:
|
|
140
|
+
city: trimmedText(input.city)
|
|
150
141
|
});
|
|
151
142
|
return {
|
|
152
143
|
geocodes: recordArray(payload.geocodes).map((item) => ({
|
|
153
|
-
formattedAddress:
|
|
154
|
-
country:
|
|
155
|
-
province:
|
|
144
|
+
formattedAddress: trimmedText(item.formatted_address),
|
|
145
|
+
country: trimmedText(item.country),
|
|
146
|
+
province: trimmedText(item.province),
|
|
156
147
|
city: stringOrStringArray(item.city),
|
|
157
|
-
district:
|
|
158
|
-
adcode:
|
|
159
|
-
location:
|
|
148
|
+
district: trimmedText(item.district),
|
|
149
|
+
adcode: trimmedText(item.adcode),
|
|
150
|
+
location: trimmedText(item.location)
|
|
160
151
|
}))
|
|
161
152
|
};
|
|
162
153
|
}
|
|
@@ -164,14 +155,14 @@ async function reverseGeocode(input, ctx) {
|
|
|
164
155
|
const payload = await amapGet(ctx, "/v3/geocode/regeo", {
|
|
165
156
|
location: requireText(input.location, "location"),
|
|
166
157
|
radius: number(input.radius),
|
|
167
|
-
extensions:
|
|
158
|
+
extensions: trimmedText(input.extensions),
|
|
168
159
|
// 入参是 camelCase 的 roadLevel,高德认的是全小写 roadlevel。
|
|
169
160
|
roadlevel: number(input.roadLevel)
|
|
170
161
|
});
|
|
171
|
-
const regeocode =
|
|
162
|
+
const regeocode = asJsonObject(payload.regeocode);
|
|
172
163
|
return {
|
|
173
|
-
formattedAddress:
|
|
174
|
-
addressComponent:
|
|
164
|
+
formattedAddress: trimmedText(regeocode?.formatted_address),
|
|
165
|
+
addressComponent: asJsonObject(regeocode?.addressComponent),
|
|
175
166
|
pois: recordArray(regeocode?.pois),
|
|
176
167
|
roads: recordArray(regeocode?.roads),
|
|
177
168
|
roadinters: recordArray(regeocode?.roadinters),
|
|
@@ -181,84 +172,84 @@ async function reverseGeocode(input, ctx) {
|
|
|
181
172
|
async function searchPlaces(input, ctx) {
|
|
182
173
|
return poiSearchOutput(await amapGet(ctx, "/v5/place/text", {
|
|
183
174
|
keywords: requireText(input.keywords, "keywords"),
|
|
184
|
-
region:
|
|
185
|
-
city_limit:
|
|
186
|
-
types:
|
|
175
|
+
region: trimmedText(input.region),
|
|
176
|
+
city_limit: booleanValue(input.cityLimit),
|
|
177
|
+
types: trimmedText(input.types),
|
|
187
178
|
page_num: number(input.pageNum),
|
|
188
179
|
page_size: number(input.pageSize),
|
|
189
|
-
show_fields:
|
|
180
|
+
show_fields: trimmedText(input.showFields)
|
|
190
181
|
}));
|
|
191
182
|
}
|
|
192
183
|
async function searchPlacesAround(input, ctx) {
|
|
193
184
|
return poiSearchOutput(await amapGet(ctx, "/v5/place/around", {
|
|
194
185
|
location: requireText(input.location, "location"),
|
|
195
186
|
radius: number(input.radius),
|
|
196
|
-
keywords:
|
|
197
|
-
types:
|
|
198
|
-
sortrule:
|
|
187
|
+
keywords: trimmedText(input.keywords),
|
|
188
|
+
types: trimmedText(input.types),
|
|
189
|
+
sortrule: trimmedText(input.sortRule),
|
|
199
190
|
page_num: number(input.pageNum),
|
|
200
191
|
page_size: number(input.pageSize),
|
|
201
|
-
show_fields:
|
|
192
|
+
show_fields: trimmedText(input.showFields)
|
|
202
193
|
}));
|
|
203
194
|
}
|
|
204
195
|
async function searchPlacesPolygon(input, ctx) {
|
|
205
196
|
return poiSearchOutput(await amapGet(ctx, "/v5/place/polygon", {
|
|
206
197
|
polygon: requireText(input.polygon, "polygon"),
|
|
207
|
-
keywords:
|
|
208
|
-
types:
|
|
198
|
+
keywords: trimmedText(input.keywords),
|
|
199
|
+
types: trimmedText(input.types),
|
|
209
200
|
page_num: number(input.pageNum),
|
|
210
201
|
page_size: number(input.pageSize),
|
|
211
|
-
show_fields:
|
|
202
|
+
show_fields: trimmedText(input.showFields)
|
|
212
203
|
}));
|
|
213
204
|
}
|
|
214
205
|
async function getPlaceDetail(input, ctx) {
|
|
215
206
|
const payload = await amapGet(ctx, "/v5/place/detail", {
|
|
216
207
|
id: requireText(input.id, "id"),
|
|
217
|
-
show_fields:
|
|
208
|
+
show_fields: trimmedText(input.showFields)
|
|
218
209
|
});
|
|
219
210
|
return { pois: recordArray(payload.pois).map((item) => poi(item)) };
|
|
220
211
|
}
|
|
221
212
|
async function inputTips(input, ctx) {
|
|
222
213
|
const payload = await amapGet(ctx, "/v3/assistant/inputtips", {
|
|
223
214
|
keywords: requireText(input.keywords, "keywords"),
|
|
224
|
-
type:
|
|
225
|
-
location:
|
|
226
|
-
city:
|
|
215
|
+
type: trimmedText(input.type),
|
|
216
|
+
location: trimmedText(input.location),
|
|
217
|
+
city: trimmedText(input.city),
|
|
227
218
|
// 入参 cityLimit,高德认的是全小写 citylimit;下面 datatype 同理。
|
|
228
|
-
citylimit:
|
|
229
|
-
datatype:
|
|
219
|
+
citylimit: booleanValue(input.cityLimit),
|
|
220
|
+
datatype: trimmedText(input.dataType)
|
|
230
221
|
});
|
|
231
222
|
return { tips: recordArray(payload.tips) };
|
|
232
223
|
}
|
|
233
224
|
async function ipLocate(input, ctx) {
|
|
234
|
-
const ip =
|
|
225
|
+
const ip = trimmedText(input.ip);
|
|
235
226
|
if (ip === void 0) {
|
|
236
227
|
throw new TBError("invalid_argument", "ip is required: \u672C\u5C42\u62FF\u4E0D\u5230\u8C03\u7528\u65B9\u7684\u6765\u6E90 IP,\u5FC5\u987B\u663E\u5F0F\u7ED9\u51FA\u8981\u5B9A\u4F4D\u7684 IP");
|
|
237
228
|
}
|
|
238
229
|
const payload = await amapGet(ctx, "/v3/ip", { ip });
|
|
239
230
|
return {
|
|
240
|
-
province:
|
|
241
|
-
city:
|
|
242
|
-
adcode:
|
|
243
|
-
rectangle:
|
|
231
|
+
province: trimmedText(payload.province),
|
|
232
|
+
city: trimmedText(payload.city),
|
|
233
|
+
adcode: trimmedText(payload.adcode),
|
|
234
|
+
rectangle: trimmedText(payload.rectangle)
|
|
244
235
|
};
|
|
245
236
|
}
|
|
246
237
|
async function districtSearch(input, ctx) {
|
|
247
238
|
const payload = await amapGet(ctx, "/v3/config/district", {
|
|
248
239
|
keywords: requireText(input.keywords, "keywords"),
|
|
249
240
|
subdistrict: number(input.subDistrict),
|
|
250
|
-
extensions:
|
|
241
|
+
extensions: trimmedText(input.extensions),
|
|
251
242
|
page: number(input.page),
|
|
252
243
|
offset: number(input.offset),
|
|
253
|
-
filter:
|
|
244
|
+
filter: trimmedText(input.filter)
|
|
254
245
|
});
|
|
255
246
|
return {
|
|
256
|
-
count:
|
|
247
|
+
count: trimmedText(payload.count),
|
|
257
248
|
districts: recordArray(payload.districts)
|
|
258
249
|
};
|
|
259
250
|
}
|
|
260
251
|
async function weather(input, ctx) {
|
|
261
|
-
const extensions =
|
|
252
|
+
const extensions = trimmedText(input.extensions);
|
|
262
253
|
const payload = await amapGet(ctx, "/v3/weather/weatherInfo", {
|
|
263
254
|
city: requireText(input.city, "city"),
|
|
264
255
|
extensions
|
|
@@ -269,28 +260,28 @@ async function weather(input, ctx) {
|
|
|
269
260
|
function simpleRoutePaths(value, includeCost) {
|
|
270
261
|
return recordArray(value).map((item) => {
|
|
271
262
|
const path = {
|
|
272
|
-
distance:
|
|
263
|
+
distance: trimmedText(item.distance),
|
|
273
264
|
steps: recordArray(item.steps)
|
|
274
265
|
};
|
|
275
|
-
const cost =
|
|
266
|
+
const cost = asJsonObject(item.cost);
|
|
276
267
|
if (!includeCost || cost === void 0) return path;
|
|
277
|
-
return { ...path, cost: { duration:
|
|
268
|
+
return { ...path, cost: { duration: trimmedText(cost.duration) } };
|
|
278
269
|
});
|
|
279
270
|
}
|
|
280
271
|
async function simpleRoute(ctx, path, input, extra = {}) {
|
|
281
272
|
const query = {
|
|
282
273
|
origin: requireText(input.origin, "origin"),
|
|
283
274
|
destination: requireText(input.destination, "destination"),
|
|
284
|
-
show_fields:
|
|
275
|
+
show_fields: trimmedText(input.showFields),
|
|
285
276
|
...extra
|
|
286
277
|
};
|
|
287
278
|
assertGetUrlLength(ctx, path, query);
|
|
288
279
|
const payload = await amapGet(ctx, path, query);
|
|
289
|
-
const route =
|
|
280
|
+
const route = asJsonObject(payload.route);
|
|
290
281
|
return {
|
|
291
282
|
route: {
|
|
292
|
-
origin:
|
|
293
|
-
destination:
|
|
283
|
+
origin: trimmedText(route?.origin),
|
|
284
|
+
destination: trimmedText(route?.destination),
|
|
294
285
|
paths: simpleRoutePaths(route?.paths, hasShowField(input.showFields, "cost"))
|
|
295
286
|
}
|
|
296
287
|
};
|
|
@@ -300,7 +291,7 @@ async function routeWalking(input, ctx) {
|
|
|
300
291
|
}
|
|
301
292
|
async function routeBicycling(input, ctx) {
|
|
302
293
|
return simpleRoute(ctx, "/v5/direction/bicycling", input, {
|
|
303
|
-
alternative_route:
|
|
294
|
+
alternative_route: trimmedText(input.alternativeRoute)
|
|
304
295
|
});
|
|
305
296
|
}
|
|
306
297
|
async function routeElectrobike(input, ctx) {
|
|
@@ -310,32 +301,32 @@ async function routeDriving(input, ctx) {
|
|
|
310
301
|
const query = {
|
|
311
302
|
origin: requireText(input.origin, "origin"),
|
|
312
303
|
destination: requireText(input.destination, "destination"),
|
|
313
|
-
waypoints:
|
|
314
|
-
strategy:
|
|
315
|
-
plate:
|
|
316
|
-
cartype:
|
|
317
|
-
avoidpolygons:
|
|
318
|
-
show_fields:
|
|
304
|
+
waypoints: trimmedText(input.waypoints),
|
|
305
|
+
strategy: trimmedText(input.strategy),
|
|
306
|
+
plate: trimmedText(input.plate),
|
|
307
|
+
cartype: trimmedText(input.carType),
|
|
308
|
+
avoidpolygons: trimmedText(input.avoidPolygons),
|
|
309
|
+
show_fields: trimmedText(input.showFields)
|
|
319
310
|
};
|
|
320
311
|
assertGetUrlLength(ctx, "/v5/direction/driving", query);
|
|
321
312
|
const payload = await amapGet(ctx, "/v5/direction/driving", query);
|
|
322
|
-
const route =
|
|
313
|
+
const route = asJsonObject(payload.route);
|
|
323
314
|
const includeCost = hasShowField(input.showFields, "cost");
|
|
324
315
|
return {
|
|
325
316
|
route: {
|
|
326
|
-
origin:
|
|
327
|
-
destination:
|
|
328
|
-
taxi_cost:
|
|
317
|
+
origin: trimmedText(route?.origin),
|
|
318
|
+
destination: trimmedText(route?.destination),
|
|
319
|
+
taxi_cost: trimmedText(route?.taxi_cost),
|
|
329
320
|
// 驾车路径多两个字段:限行信息与过路费。
|
|
330
321
|
paths: recordArray(route?.paths).map((item) => {
|
|
331
322
|
const path = {
|
|
332
|
-
distance:
|
|
333
|
-
restriction:
|
|
323
|
+
distance: trimmedText(item.distance),
|
|
324
|
+
restriction: trimmedText(item.restriction),
|
|
334
325
|
steps: recordArray(item.steps)
|
|
335
326
|
};
|
|
336
|
-
const cost =
|
|
327
|
+
const cost = asJsonObject(item.cost);
|
|
337
328
|
if (!includeCost || cost === void 0) return path;
|
|
338
|
-
return { ...path, cost: { duration:
|
|
329
|
+
return { ...path, cost: { duration: trimmedText(cost.duration), tolls: trimmedText(cost.tolls) } };
|
|
339
330
|
})
|
|
340
331
|
}
|
|
341
332
|
};
|
|
@@ -347,9 +338,9 @@ function transitSegments(value, includeCost) {
|
|
|
347
338
|
delete rest.cost;
|
|
348
339
|
return rest;
|
|
349
340
|
}
|
|
350
|
-
const cost =
|
|
341
|
+
const cost = asJsonObject(item.cost);
|
|
351
342
|
if (cost === void 0) return item;
|
|
352
|
-
return { ...item, cost: { transit_fee:
|
|
343
|
+
return { ...item, cost: { transit_fee: trimmedText(cost.transit_fee) } };
|
|
353
344
|
});
|
|
354
345
|
}
|
|
355
346
|
async function routeTransit(input, ctx) {
|
|
@@ -359,29 +350,29 @@ async function routeTransit(input, ctx) {
|
|
|
359
350
|
// 入参是 originCity / destinationCity,高德认的是 city1 / city2。
|
|
360
351
|
city1: requireText(input.originCity, "originCity"),
|
|
361
352
|
city2: requireText(input.destinationCity, "destinationCity"),
|
|
362
|
-
strategy:
|
|
363
|
-
nightflag:
|
|
364
|
-
show_fields:
|
|
353
|
+
strategy: trimmedText(input.strategy),
|
|
354
|
+
nightflag: trimmedText(input.nightFlag),
|
|
355
|
+
show_fields: trimmedText(input.showFields)
|
|
365
356
|
};
|
|
366
357
|
assertGetUrlLength(ctx, "/v5/direction/transit/integrated", query);
|
|
367
358
|
const payload = await amapGet(ctx, "/v5/direction/transit/integrated", query);
|
|
368
|
-
const route =
|
|
359
|
+
const route = asJsonObject(payload.route);
|
|
369
360
|
const includeCost = hasShowField(input.showFields, "cost");
|
|
370
|
-
const taxiCost =
|
|
361
|
+
const taxiCost = asJsonObject(route?.cost);
|
|
371
362
|
return {
|
|
372
363
|
route: {
|
|
373
|
-
origin:
|
|
374
|
-
destination:
|
|
375
|
-
cost: includeCost && taxiCost !== void 0 ? { taxi_fee:
|
|
364
|
+
origin: trimmedText(route?.origin),
|
|
365
|
+
destination: trimmedText(route?.destination),
|
|
366
|
+
cost: includeCost && taxiCost !== void 0 ? { taxi_fee: trimmedText(taxiCost.taxi_fee) } : void 0,
|
|
376
367
|
transits: recordArray(route?.transits).map((item) => {
|
|
377
368
|
const transit = {
|
|
378
|
-
distance:
|
|
379
|
-
nightflag:
|
|
369
|
+
distance: trimmedText(item.distance),
|
|
370
|
+
nightflag: trimmedText(item.nightflag),
|
|
380
371
|
segments: transitSegments(item.segments, includeCost)
|
|
381
372
|
};
|
|
382
|
-
const cost =
|
|
373
|
+
const cost = asJsonObject(item.cost);
|
|
383
374
|
if (!includeCost || cost === void 0) return transit;
|
|
384
|
-
return { ...transit, cost: { duration:
|
|
375
|
+
return { ...transit, cost: { duration: trimmedText(cost.duration) } };
|
|
385
376
|
})
|
|
386
377
|
}
|
|
387
378
|
};
|
|
@@ -1,38 +1,33 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderHttpClient
|
|
3
|
+
} from "./chunk-VLOIDU5U.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-B4P6YZFS.js";
|
|
14
|
+
import "./chunk-SWBNHIO4.js";
|
|
10
15
|
import {
|
|
11
16
|
TBError,
|
|
12
17
|
external_exports
|
|
13
|
-
} from "./chunk-
|
|
14
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-OKRZPQ3R.js";
|
|
19
|
+
import "./chunk-U67V476Y.js";
|
|
15
20
|
|
|
16
21
|
// ../plugins/src/anthropic/api.ts
|
|
17
22
|
var SERVICE = "anthropic";
|
|
18
23
|
var API_BASE = "https://api.anthropic.com";
|
|
19
24
|
var API_VERSION = "2023-06-01";
|
|
20
|
-
|
|
21
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
22
|
-
}
|
|
23
|
-
function text(value) {
|
|
24
|
-
if (typeof value !== "string") return void 0;
|
|
25
|
-
const trimmed = value.trim();
|
|
26
|
-
return trimmed === "" ? void 0 : trimmed;
|
|
27
|
-
}
|
|
25
|
+
var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
|
|
28
26
|
function requireText(value, field) {
|
|
29
|
-
const result =
|
|
27
|
+
const result = trimmedText(value);
|
|
30
28
|
if (result === void 0) throw new TBError("invalid_argument", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
|
|
31
29
|
return result;
|
|
32
30
|
}
|
|
33
|
-
function compact(input) {
|
|
34
|
-
return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== void 0));
|
|
35
|
-
}
|
|
36
31
|
function headers(apiKey) {
|
|
37
32
|
return {
|
|
38
33
|
"accept": "application/json",
|
|
@@ -41,46 +36,29 @@ function headers(apiKey) {
|
|
|
41
36
|
"x-api-key": apiKey
|
|
42
37
|
};
|
|
43
38
|
}
|
|
44
|
-
function errorMessage(status,
|
|
39
|
+
function errorMessage(status, payload) {
|
|
45
40
|
const fallback = `anthropic request failed with ${status}`;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const message = text(nested?.message);
|
|
49
|
-
if (message !== void 0) return message;
|
|
50
|
-
} catch {
|
|
51
|
-
}
|
|
52
|
-
return text(body) ?? fallback;
|
|
53
|
-
}
|
|
54
|
-
function buildUrl(path, query) {
|
|
55
|
-
const url = new URL(`${API_BASE}${path}`);
|
|
56
|
-
for (const [key, value] of Object.entries(query ?? {})) {
|
|
57
|
-
if (value === void 0 || value === null) continue;
|
|
58
|
-
url.searchParams.set(key, String(value));
|
|
59
|
-
}
|
|
60
|
-
return url.toString();
|
|
41
|
+
const nested = asJsonObject(asJsonObject(payload)?.error);
|
|
42
|
+
return trimmedText(nested?.message) ?? trimmedText(payload) ?? fallback;
|
|
61
43
|
}
|
|
62
44
|
async function request(ctx, input) {
|
|
63
45
|
const apiKey = requireApiKey(ctx, SERVICE);
|
|
64
46
|
const method = input.method ?? "GET";
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (
|
|
79
|
-
|
|
80
|
-
return JSON.parse(raw);
|
|
81
|
-
} catch {
|
|
82
|
-
throw upstreamError(502, "anthropic returned malformed JSON");
|
|
83
|
-
}
|
|
47
|
+
const { data } = await http.request({
|
|
48
|
+
path: input.path,
|
|
49
|
+
method,
|
|
50
|
+
query: Object.entries(input.query ?? {}),
|
|
51
|
+
headers: headers(apiKey),
|
|
52
|
+
...input.body === void 0 ? {} : { json: input.body },
|
|
53
|
+
invalidJsonMessage: "anthropic returned malformed JSON",
|
|
54
|
+
mapError: ({ data: payload, status }) => upstreamError(status, errorMessage(status, payload)),
|
|
55
|
+
mapTransportError: ({ message }) => upstreamError(
|
|
56
|
+
502,
|
|
57
|
+
`anthropic ${method} ${input.path} failed before receiving response: ${message ?? "unknown network error"}`
|
|
58
|
+
)
|
|
59
|
+
});
|
|
60
|
+
if (data === void 0) throw upstreamError(502, "anthropic returned malformed JSON");
|
|
61
|
+
return data;
|
|
84
62
|
}
|
|
85
63
|
function assertStreamingDisabled(input) {
|
|
86
64
|
if (input.stream === true) {
|
|
@@ -98,10 +76,10 @@ async function getModel(input, ctx) {
|
|
|
98
76
|
}
|
|
99
77
|
async function createMessage(input, ctx) {
|
|
100
78
|
assertStreamingDisabled(input);
|
|
101
|
-
return request(ctx, { method: "POST", path: "/v1/messages", body:
|
|
79
|
+
return request(ctx, { method: "POST", path: "/v1/messages", body: compactDefined(input) });
|
|
102
80
|
}
|
|
103
81
|
async function countMessageTokens(input, ctx) {
|
|
104
|
-
return request(ctx, { method: "POST", path: "/v1/messages/count_tokens", body:
|
|
82
|
+
return request(ctx, { method: "POST", path: "/v1/messages/count_tokens", body: compactDefined(input) });
|
|
105
83
|
}
|
|
106
84
|
|
|
107
85
|
// ../plugins/src/anthropic/schema.ts
|