@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
package/dist/chunk-GKX72JMJ.js
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HEADER_TB_CONTEXT,
|
|
3
|
-
HEADER_TB_REQUEST_ID,
|
|
4
|
-
HEADER_TB_UPSTREAM_AUTH,
|
|
5
|
-
OperationRegistry,
|
|
6
|
-
RequestDedupe,
|
|
7
|
-
TBError,
|
|
8
|
-
decodeCallContext,
|
|
9
|
-
decodePluginCall,
|
|
10
|
-
isTBError,
|
|
11
|
-
parseCredentialValues,
|
|
12
|
-
toToolResult
|
|
13
|
-
} from "./chunk-YB2FLNWI.js";
|
|
14
|
-
|
|
15
|
-
// ../plugin-sdk/src/index.ts
|
|
16
|
-
var CONTEXT_HANDLER_VERBS = ["list", "get", "write", "update", "delete", "search"];
|
|
17
|
-
var CAPABILITY_BY_VERB = { search: "search", delete: "delete" };
|
|
18
|
-
var PROTOCOL_VERSION = "plugin/v2";
|
|
19
|
-
function json(value, status = 200) {
|
|
20
|
-
return new Response(JSON.stringify(value), {
|
|
21
|
-
status,
|
|
22
|
-
headers: { "content-type": "application/json; charset=utf-8" }
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
function errorResponse(err) {
|
|
26
|
-
if (isTBError(err)) return json(err.toJSON(), err.httpStatus);
|
|
27
|
-
return json(new TBError("internal", "internal plugin error").toJSON(), 500);
|
|
28
|
-
}
|
|
29
|
-
function contextVerbs(handlers) {
|
|
30
|
-
const verbs = [];
|
|
31
|
-
for (const verb of CONTEXT_HANDLER_VERBS) {
|
|
32
|
-
if (typeof handlers[verb] === "function") verbs.push(verb);
|
|
33
|
-
}
|
|
34
|
-
return verbs;
|
|
35
|
-
}
|
|
36
|
-
function helpCmds(state) {
|
|
37
|
-
if (state.kind === "tools") return state.registry.list();
|
|
38
|
-
if (state.kind === "proxyTools") return [];
|
|
39
|
-
return contextVerbs(state.handlers).map((name) => ({ name }));
|
|
40
|
-
}
|
|
41
|
-
function createPlugin(opts = {}) {
|
|
42
|
-
const healthPath = opts.healthPath ?? "/healthz";
|
|
43
|
-
const exports = /* @__PURE__ */ new Map();
|
|
44
|
-
const dedupe = new RequestDedupe();
|
|
45
|
-
const assertFreshId = (id) => {
|
|
46
|
-
if (id.length === 0) throw new TBError("invalid_argument", "export id must be non-empty");
|
|
47
|
-
if (exports.has(id)) {
|
|
48
|
-
throw new TBError("invalid_argument", `export '${id}' is already declared`);
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
function describe() {
|
|
52
|
-
return {
|
|
53
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
54
|
-
exports: [...exports.values()].map((state) => {
|
|
55
|
-
if (state.kind === "tools" || state.kind === "proxyTools") {
|
|
56
|
-
return {
|
|
57
|
-
id: state.id,
|
|
58
|
-
profile: "tools/v1",
|
|
59
|
-
...state.description !== void 0 ? { description: state.description } : {},
|
|
60
|
-
...state.auth !== void 0 ? { auth: state.auth } : {},
|
|
61
|
-
...state.kind === "tools" && state.credentialProbe !== void 0 ? { credentialProbe: state.credentialProbe } : {},
|
|
62
|
-
...state.credentialFields !== void 0 ? { credentialFields: state.credentialFields } : {},
|
|
63
|
-
...state.kind === "tools" && state.mountConfigFields !== void 0 ? { mountConfigFields: state.mountConfigFields } : {},
|
|
64
|
-
...state.kind === "tools" && state.oauth !== void 0 ? { oauth: state.oauth } : {}
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
const methods = contextVerbs(state.handlers);
|
|
68
|
-
const capabilities = methods.map((verb) => CAPABILITY_BY_VERB[verb]).filter((c) => c !== void 0);
|
|
69
|
-
return {
|
|
70
|
-
id: state.id,
|
|
71
|
-
profile: "context/v1",
|
|
72
|
-
...state.description !== void 0 ? { description: state.description } : {},
|
|
73
|
-
...state.auth !== void 0 ? { auth: state.auth } : {},
|
|
74
|
-
methods,
|
|
75
|
-
...capabilities.length > 0 ? { capabilities } : {},
|
|
76
|
-
...state.mountConfigFields !== void 0 ? { mountConfigFields: state.mountConfigFields } : {}
|
|
77
|
-
};
|
|
78
|
-
})
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function help() {
|
|
82
|
-
return {
|
|
83
|
-
protocolVersion: PROTOCOL_VERSION,
|
|
84
|
-
exports: [...exports.values()].map((state) => ({
|
|
85
|
-
id: state.id,
|
|
86
|
-
...state.kind === "proxyTools" ? { dynamic: true } : {},
|
|
87
|
-
cmds: helpCmds(state)
|
|
88
|
-
}))
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
function assertAuthorized(request, env) {
|
|
92
|
-
if (env?.TB_PLUGIN_IN_PROCESS === true) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const header = request.headers.get("authorization") ?? "";
|
|
96
|
-
const presented = header.startsWith("Bearer ") ? header.slice("Bearer ".length) : "";
|
|
97
|
-
const expected = opts.token?.(env);
|
|
98
|
-
if (expected === void 0) {
|
|
99
|
-
const devBypass = env?.TB_PLUGIN_ALLOW_ANY_TOKEN;
|
|
100
|
-
if (devBypass !== "true") {
|
|
101
|
-
throw new TBError(
|
|
102
|
-
"unavailable",
|
|
103
|
-
"plugin \u672A\u914D\u7F6E PLUGIN_TOKEN:\u751F\u4EA7\u90E8\u7F72\u5FC5\u987B\u914D\u7F6E;\u672C\u5730\u5F00\u53D1\u53EF\u8BBE TB_PLUGIN_ALLOW_ANY_TOKEN=true",
|
|
104
|
-
{ retryable: false }
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
if (presented.length === 0) throw TBError.unauthenticated();
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
if (presented !== expected) throw TBError.unauthenticated();
|
|
111
|
-
}
|
|
112
|
-
function decodeUpstreamAuth(request) {
|
|
113
|
-
const raw = request.headers.get(HEADER_TB_UPSTREAM_AUTH);
|
|
114
|
-
if (raw === null || raw.length === 0) return void 0;
|
|
115
|
-
const b64 = raw.replaceAll("-", "+").replaceAll("_", "/");
|
|
116
|
-
const padded = b64.padEnd(b64.length + (4 - b64.length % 4) % 4, "=");
|
|
117
|
-
try {
|
|
118
|
-
const bytes = Uint8Array.from(atob(padded), (c) => c.charCodeAt(0));
|
|
119
|
-
return new TextDecoder().decode(bytes);
|
|
120
|
-
} catch {
|
|
121
|
-
throw new TBError("invalid_argument", `${HEADER_TB_UPSTREAM_AUTH} is not valid base64url`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
async function dispatchTools(state, method, args, ctx) {
|
|
125
|
-
switch (method.toLowerCase()) {
|
|
126
|
-
case "list":
|
|
127
|
-
return state.registry.list();
|
|
128
|
-
case "call": {
|
|
129
|
-
const name = args.name;
|
|
130
|
-
if (typeof name !== "string") {
|
|
131
|
-
throw new TBError("invalid_argument", "call requires a string 'name'");
|
|
132
|
-
}
|
|
133
|
-
const callArgs = args.args ?? {};
|
|
134
|
-
return await state.registry.call(name, callArgs, ctx);
|
|
135
|
-
}
|
|
136
|
-
default:
|
|
137
|
-
throw new TBError("invalid_argument", `unknown method '${method}' on a tools export`);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
async function dispatchProxyTools(state, method, args, ctx) {
|
|
141
|
-
switch (method.toLowerCase()) {
|
|
142
|
-
case "list":
|
|
143
|
-
return await state.handlers.list(ctx);
|
|
144
|
-
case "call": {
|
|
145
|
-
const name = args.name;
|
|
146
|
-
if (typeof name !== "string" || name === "") {
|
|
147
|
-
throw new TBError("invalid_argument", "call requires a non-empty string 'name'");
|
|
148
|
-
}
|
|
149
|
-
const callArgs = typeof args.args === "object" && args.args !== null ? args.args : {};
|
|
150
|
-
return toToolResult(await state.handlers.call({ name, args: callArgs }, ctx));
|
|
151
|
-
}
|
|
152
|
-
default:
|
|
153
|
-
throw new TBError("invalid_argument", `unknown method '${method}' on a tools export`);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
async function dispatchContext(state, method, args, ctx) {
|
|
157
|
-
const handlers = state.handlers;
|
|
158
|
-
switch (method.toLowerCase()) {
|
|
159
|
-
case "list":
|
|
160
|
-
if (handlers.list === void 0) break;
|
|
161
|
-
return await handlers.list(
|
|
162
|
-
{ path: String(args.path ?? ""), ...args.opts !== void 0 ? { opts: args.opts } : {} },
|
|
163
|
-
ctx
|
|
164
|
-
);
|
|
165
|
-
case "get":
|
|
166
|
-
if (handlers.get === void 0) break;
|
|
167
|
-
return await handlers.get({ path: String(args.path ?? "") }, ctx);
|
|
168
|
-
case "write":
|
|
169
|
-
if (handlers.write === void 0) break;
|
|
170
|
-
return await handlers.write(
|
|
171
|
-
{ path: String(args.path ?? ""), entry: args.entry ?? {} },
|
|
172
|
-
ctx
|
|
173
|
-
);
|
|
174
|
-
case "update":
|
|
175
|
-
if (handlers.update === void 0) break;
|
|
176
|
-
return await handlers.update(
|
|
177
|
-
{ path: String(args.path ?? ""), patch: args.patch ?? {} },
|
|
178
|
-
ctx
|
|
179
|
-
);
|
|
180
|
-
case "delete":
|
|
181
|
-
if (handlers.delete === void 0) break;
|
|
182
|
-
return await handlers.delete({ path: String(args.path ?? "") }, ctx);
|
|
183
|
-
case "search":
|
|
184
|
-
if (handlers.search === void 0) break;
|
|
185
|
-
return await handlers.search(
|
|
186
|
-
{ query: String(args.query ?? ""), ...args.opts !== void 0 ? { opts: args.opts } : {} },
|
|
187
|
-
ctx
|
|
188
|
-
);
|
|
189
|
-
default:
|
|
190
|
-
throw new TBError("invalid_argument", `unknown method '${method}' on a context export`);
|
|
191
|
-
}
|
|
192
|
-
throw new TBError("invalid_argument", `method '${method}' is not implemented by export '${state.id}'`);
|
|
193
|
-
}
|
|
194
|
-
async function handleEnvelope(request, env) {
|
|
195
|
-
assertAuthorized(request, env);
|
|
196
|
-
const ctxHeader = request.headers.get(HEADER_TB_CONTEXT);
|
|
197
|
-
if (ctxHeader === null) {
|
|
198
|
-
throw new TBError("invalid_argument", `missing ${HEADER_TB_CONTEXT}`);
|
|
199
|
-
}
|
|
200
|
-
const caller = decodeCallContext(ctxHeader);
|
|
201
|
-
const call = decodePluginCall(await request.text());
|
|
202
|
-
const exportId = caller.exportId ?? (exports.size === 1 ? [...exports.keys()][0] : void 0);
|
|
203
|
-
if (exportId === void 0) {
|
|
204
|
-
throw new TBError("invalid_argument", "call context carries no exportId and this plugin declares multiple exports");
|
|
205
|
-
}
|
|
206
|
-
const state = exports.get(exportId);
|
|
207
|
-
if (state === void 0) throw new TBError("invalid_argument", `unknown export '${exportId}'`);
|
|
208
|
-
const upstreamAuth = decodeUpstreamAuth(request);
|
|
209
|
-
const credentialFields = state.kind === "context" ? void 0 : state.credentialFields;
|
|
210
|
-
const ctx = {
|
|
211
|
-
env,
|
|
212
|
-
caller,
|
|
213
|
-
exportId,
|
|
214
|
-
mountPath: caller.mountPath,
|
|
215
|
-
mountConfig: caller.mountConfig,
|
|
216
|
-
upstreamAuth,
|
|
217
|
-
credentials: credentialFields !== void 0 && upstreamAuth !== void 0 ? parseCredentialValues(upstreamAuth, credentialFields) : void 0
|
|
218
|
-
};
|
|
219
|
-
const requestId = request.headers.get(HEADER_TB_REQUEST_ID);
|
|
220
|
-
const run = async () => {
|
|
221
|
-
if (state.kind === "tools") return await dispatchTools(state, call.tool, call.arguments, ctx);
|
|
222
|
-
if (state.kind === "proxyTools") {
|
|
223
|
-
return await dispatchProxyTools(state, call.tool, call.arguments, ctx);
|
|
224
|
-
}
|
|
225
|
-
return await dispatchContext(state, call.tool, call.arguments, ctx);
|
|
226
|
-
};
|
|
227
|
-
const value = requestId === null ? await run() : await dedupe.run(requestId, run);
|
|
228
|
-
return json(value ?? null);
|
|
229
|
-
}
|
|
230
|
-
const plugin = {
|
|
231
|
-
tools(id, meta) {
|
|
232
|
-
assertFreshId(id);
|
|
233
|
-
const state = {
|
|
234
|
-
auth: void 0,
|
|
235
|
-
kind: "tools",
|
|
236
|
-
id,
|
|
237
|
-
description: meta?.description,
|
|
238
|
-
credentialProbe: void 0,
|
|
239
|
-
credentialFields: void 0,
|
|
240
|
-
mountConfigFields: void 0,
|
|
241
|
-
oauth: void 0,
|
|
242
|
-
registry: new OperationRegistry()
|
|
243
|
-
};
|
|
244
|
-
exports.set(id, state);
|
|
245
|
-
const surface = {
|
|
246
|
-
auth(config) {
|
|
247
|
-
if (state.oauth !== void 0 || state.credentialFields !== void 0) {
|
|
248
|
-
throw new TBError(
|
|
249
|
-
"invalid_argument",
|
|
250
|
-
`export '${id}' \u5DF2\u58F0\u660E oauth/credentials(),\u4E0D\u80FD\u518D\u58F0\u660E auth`
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
if (config.kind === "none" && state.credentialProbe !== void 0) {
|
|
254
|
-
throw new TBError(
|
|
255
|
-
"invalid_argument",
|
|
256
|
-
`export '${id}' \u5DF2\u58F0\u660E credentialProbe,\u4E0D\u80FD\u518D\u58F0\u660E auth:none`
|
|
257
|
-
);
|
|
258
|
-
}
|
|
259
|
-
state.auth = config;
|
|
260
|
-
return surface;
|
|
261
|
-
},
|
|
262
|
-
register(name, spec, handler) {
|
|
263
|
-
state.registry.register(name, spec, handler);
|
|
264
|
-
return surface;
|
|
265
|
-
},
|
|
266
|
-
credentials(fields) {
|
|
267
|
-
if (fields.length === 0) {
|
|
268
|
-
throw new TBError("invalid_argument", "credentials() \u81F3\u5C11\u8981\u58F0\u660E\u4E00\u4E2A\u5B57\u6BB5");
|
|
269
|
-
}
|
|
270
|
-
if (state.oauth !== void 0) {
|
|
271
|
-
throw new TBError(
|
|
272
|
-
"invalid_argument",
|
|
273
|
-
`export '${id}' \u5DF2\u58F0\u660E oauth,\u4E0D\u80FD\u518D\u58F0\u660E credentials()(oauth \u6A21\u5F0F\u4E0B authRef \u6307\u5411\u7684 secret \u56FA\u5B9A\u5B58 clientId/clientSecret)`
|
|
274
|
-
);
|
|
275
|
-
}
|
|
276
|
-
if (state.auth !== void 0) {
|
|
277
|
-
throw new TBError("invalid_argument", `export '${id}' \u5DF2\u58F0\u660E auth,\u4E0D\u80FD\u518D\u58F0\u660E credentials()`);
|
|
278
|
-
}
|
|
279
|
-
state.credentialFields = fields;
|
|
280
|
-
return surface;
|
|
281
|
-
},
|
|
282
|
-
mountConfig(fields) {
|
|
283
|
-
if (fields.length === 0) {
|
|
284
|
-
throw new TBError("invalid_argument", "mountConfig() \u81F3\u5C11\u8981\u58F0\u660E\u4E00\u4E2A\u5B57\u6BB5");
|
|
285
|
-
}
|
|
286
|
-
state.mountConfigFields = fields;
|
|
287
|
-
return surface;
|
|
288
|
-
},
|
|
289
|
-
oauth(config) {
|
|
290
|
-
if (state.credentialFields !== void 0) {
|
|
291
|
-
throw new TBError(
|
|
292
|
-
"invalid_argument",
|
|
293
|
-
`export '${id}' \u5DF2\u58F0\u660E credentials(),\u4E0D\u80FD\u518D\u58F0\u660E oauth(oauth \u6A21\u5F0F\u4E0B authRef \u6307\u5411\u7684 secret \u56FA\u5B9A\u5B58 clientId/clientSecret)`
|
|
294
|
-
);
|
|
295
|
-
}
|
|
296
|
-
if (state.auth !== void 0) {
|
|
297
|
-
throw new TBError("invalid_argument", `export '${id}' \u5DF2\u58F0\u660E auth,\u4E0D\u80FD\u518D\u58F0\u660E oauth`);
|
|
298
|
-
}
|
|
299
|
-
if (state.credentialProbe !== void 0) {
|
|
300
|
-
throw new TBError(
|
|
301
|
-
"invalid_argument",
|
|
302
|
-
`export '${id}' \u5DF2\u58F0\u660E credentialProbe,\u4E0D\u80FD\u518D\u58F0\u660E oauth(\u51ED\u8BC1\u53EF\u7528\u6027\u7531\u6388\u6743\u6D41\u7A0B\u672C\u8EAB\u8BC1\u660E;\u62FF client \u51ED\u8BC1\u53BB\u8C03\u63A2\u9488\u65E2\u8BC1\u660E\u4E0D\u4E86\u4EC0\u4E48,\u53C8\u4F1A\u628A clientSecret \u9001\u8FDB\u63D2\u4EF6)`
|
|
303
|
-
);
|
|
304
|
-
}
|
|
305
|
-
state.oauth = config;
|
|
306
|
-
return surface;
|
|
307
|
-
},
|
|
308
|
-
probeCredentialWith(name) {
|
|
309
|
-
if (!state.registry.list().some((tool) => tool.name === name)) {
|
|
310
|
-
throw new TBError(
|
|
311
|
-
"invalid_argument",
|
|
312
|
-
`credentialProbe '${name}' \u4E0D\u662F export '${id}' \u5DF2\u6CE8\u518C\u7684\u5DE5\u5177`
|
|
313
|
-
);
|
|
314
|
-
}
|
|
315
|
-
if (state.oauth !== void 0) {
|
|
316
|
-
throw new TBError(
|
|
317
|
-
"invalid_argument",
|
|
318
|
-
`export '${id}' \u5DF2\u58F0\u660E oauth,\u4E0D\u80FD\u518D\u58F0\u660E credentialProbe(\u51ED\u8BC1\u53EF\u7528\u6027\u7531\u6388\u6743\u6D41\u7A0B\u672C\u8EAB\u8BC1\u660E;\u62FF client \u51ED\u8BC1\u53BB\u8C03\u63A2\u9488\u65E2\u8BC1\u660E\u4E0D\u4E86\u4EC0\u4E48,\u53C8\u4F1A\u628A clientSecret \u9001\u8FDB\u63D2\u4EF6)`
|
|
319
|
-
);
|
|
320
|
-
}
|
|
321
|
-
if (state.auth?.kind === "none") {
|
|
322
|
-
throw new TBError("invalid_argument", `export '${id}' \u58F0\u660E auth:none,\u4E0D\u80FD\u518D\u58F0\u660E credentialProbe`);
|
|
323
|
-
}
|
|
324
|
-
state.credentialProbe = name;
|
|
325
|
-
return surface;
|
|
326
|
-
}
|
|
327
|
-
};
|
|
328
|
-
return surface;
|
|
329
|
-
},
|
|
330
|
-
proxyTools(id, handlers) {
|
|
331
|
-
assertFreshId(id);
|
|
332
|
-
if (handlers.auth !== void 0 && handlers.credentialFields !== void 0) {
|
|
333
|
-
throw new TBError("invalid_argument", `export '${id}' \u7684 auth \u4E0D\u80FD\u4E0E credentialFields \u540C\u65F6\u58F0\u660E`);
|
|
334
|
-
}
|
|
335
|
-
exports.set(id, {
|
|
336
|
-
auth: handlers.auth,
|
|
337
|
-
kind: "proxyTools",
|
|
338
|
-
id,
|
|
339
|
-
description: handlers.description,
|
|
340
|
-
credentialFields: handlers.credentialFields,
|
|
341
|
-
handlers
|
|
342
|
-
});
|
|
343
|
-
return plugin;
|
|
344
|
-
},
|
|
345
|
-
context(id, handlers) {
|
|
346
|
-
assertFreshId(id);
|
|
347
|
-
exports.set(id, {
|
|
348
|
-
auth: handlers.auth,
|
|
349
|
-
kind: "context",
|
|
350
|
-
id,
|
|
351
|
-
description: handlers.description,
|
|
352
|
-
handlers,
|
|
353
|
-
mountConfigFields: handlers.mountConfigFields
|
|
354
|
-
});
|
|
355
|
-
return plugin;
|
|
356
|
-
},
|
|
357
|
-
async fetch(request, env) {
|
|
358
|
-
try {
|
|
359
|
-
const url = new URL(request.url);
|
|
360
|
-
if (request.method === "GET") {
|
|
361
|
-
if (url.pathname === healthPath) return json({ healthy: true });
|
|
362
|
-
if (url.pathname === "/~describe") return json(describe());
|
|
363
|
-
if (url.pathname === "/~help") return json(help());
|
|
364
|
-
throw TBError.notFound("no such path");
|
|
365
|
-
}
|
|
366
|
-
if (request.method !== "POST") throw TBError.notFound("no such path");
|
|
367
|
-
return await handleEnvelope(request, env);
|
|
368
|
-
} catch (err) {
|
|
369
|
-
return errorResponse(err);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
return plugin;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
export {
|
|
377
|
-
createPlugin
|
|
378
|
-
};
|