@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.
Files changed (115) hide show
  1. package/dist/{airtable-S3T4TAN7.js → airtable-NOSOMOVB.js} +106 -114
  2. package/dist/{alt_text_generator_ai-4DIRIDKL.js → alt_text_generator_ai-BHIJ4LW5.js} +25 -16
  3. package/dist/{amap-LGVGNPML.js → amap-QRLP4TWZ.js} +114 -123
  4. package/dist/{anthropic-27RFZO35.js → anthropic-IEOI36EV.js} +34 -56
  5. package/dist/{apify-6WLYAIAS.js → apify-3CCYTQVK.js} +31 -49
  6. package/dist/{brave_search-K2SVJ66F.js → brave_search-PZNYDQG7.js} +52 -77
  7. package/dist/chunk-JXHMDBAY.js +45 -0
  8. package/dist/chunk-LMLX3DJF.js +50 -0
  9. package/dist/{chunk-YB2FLNWI.js → chunk-RVWZN3CI.js} +2103 -1775
  10. package/dist/{chunk-BB6ZLMTU.js → chunk-TLNUIPFZ.js} +492 -300
  11. package/dist/chunk-U5UHT7CX.js +977 -0
  12. package/dist/chunk-U67V476Y.js +35 -0
  13. package/dist/chunk-WW2IMPQK.js +283 -0
  14. package/dist/{chunk-VK3V2WTY.js → chunk-YASUMV2K.js} +4 -6
  15. package/dist/{circleci-WV3ITU7Q.js → circleci-VSJ4O5FC.js} +36 -55
  16. package/dist/{clerk-NFQEFKS4.js → clerk-CC2JZBZI.js} +60 -80
  17. package/dist/{cloudflare_dns-2RK5ASBJ.js → cloudflare_dns-PJEBSEYQ.js} +90 -113
  18. package/dist/{cohere-5KEW7LWT.js → cohere-KBACYSPF.js} +33 -49
  19. package/dist/{confluence-SZE63S46.js → confluence-2PX3O7G5.js} +79 -115
  20. package/dist/{convertapi-QPG2JC5K.js → convertapi-BVOTD2PJ.js} +13 -16
  21. package/dist/{currencyapi-UO2APQRY.js → currencyapi-6ZQ2VNQ7.js} +30 -53
  22. package/dist/{deepseek-LJELIMM3.js → deepseek-MB3WVVTB.js} +30 -38
  23. package/dist/{docker_hub-2MFXSBOF.js → docker_hub-7CLQL2IJ.js} +141 -157
  24. package/dist/{dropbox-GQYNTTVA.js → dropbox-VFYDVUNK.js} +134 -141
  25. package/dist/{dub-KI2LHXST.js → dub-QN3EETJY.js} +61 -93
  26. package/dist/{e2b-WO6ISY3C.js → e2b-NKC3Y776.js} +39 -69
  27. package/dist/{exa-IZ7B3BPT.js → exa-KKZ6F25K.js} +49 -77
  28. package/dist/{fal_ai-LTMF36GJ.js → fal_ai-25LYJD2O.js} +37 -44
  29. package/dist/{feishu-WM7SLSFD.js → feishu-NRT55B3Q.js} +4 -6
  30. package/dist/{feishu_custom_bot-66W3MXH2.js → feishu_custom_bot-3W3XXUG4.js} +4 -5
  31. package/dist/{figma-2Z274VQZ.js → figma-4FLP35TC.js} +56 -81
  32. package/dist/{firehydrant-IFI4R65V.js → firehydrant-BLXPLZ3X.js} +40 -53
  33. package/dist/{fixer-BCCZEB3D.js → fixer-4OR62TGE.js} +31 -43
  34. package/dist/{fly-755FXYB5.js → fly-MYCKOZZK.js} +50 -66
  35. package/dist/{front-4FZKKXXK.js → front-3DFYVMF3.js} +43 -66
  36. package/dist/{geocodio-WYKDJ3DP.js → geocodio-CXMD6VKA.js} +37 -63
  37. package/dist/{ghost-5BNQTCOH.js → ghost-4UUE737W.js} +51 -57
  38. package/dist/{github-ULELF5VX.js → github-WFS2ON2N.js} +48 -41
  39. package/dist/{gmail-G34WT64J.js → gmail-KW7FXA7A.js} +26 -36
  40. package/dist/{googlecalendar-BQU255SC.js → googlecalendar-AMH5JQMC.js} +57 -78
  41. package/dist/{googledocs-HPCNQXYJ.js → googledocs-R5VA6CKD.js} +14 -22
  42. package/dist/{grafana-VOV24FIC.js → grafana-IT6DWIVB.js} +95 -122
  43. package/dist/{graphhopper-D5RXW6AP.js → graphhopper-TYFDJZWC.js} +32 -46
  44. package/dist/index.d.ts +57 -50
  45. package/dist/index.js +4 -3
  46. package/dist/{ip2proxy-DAYO7EKZ.js → ip2proxy-GJ4HXVXO.js} +35 -42
  47. package/dist/{ipgeolocation_io-XD4PSLII.js → ipgeolocation_io-OAGR6PRF.js} +40 -60
  48. package/dist/{ipqualityscore-K27QEAWK.js → ipqualityscore-BCKAMDGL.js} +30 -42
  49. package/dist/{jina_ai-E6UXFV2P.js → jina_ai-N3NXRVIZ.js} +32 -58
  50. package/dist/{jira-ZDSXGQ6W.js → jira-CHLBKWLO.js} +116 -126
  51. package/dist/{langsmith-TIFJRREW.js → langsmith-OIKOTPY3.js} +101 -121
  52. package/dist/{lemlist-DASEMJMA.js → lemlist-VAKYPKS3.js} +57 -68
  53. package/dist/{linear-KE6UP4SP.js → linear-Q6QTPJ5R.js} +109 -118
  54. package/dist/{logsnag-IMNDN4R5.js → logsnag-SQOQBTES.js} +31 -48
  55. package/dist/main.js +103 -102
  56. package/dist/{mattermost-HHHMUXQA.js → mattermost-G2KBEICM.js} +45 -62
  57. package/dist/{mem0-D2FGGOIY.js → mem0-D2FPLYDX.js} +72 -98
  58. package/dist/{memos-4OVIGFPH.js → memos-76PTWV5V.js} +68 -122
  59. package/dist/{metabase-33WCX5YD.js → metabase-TWSIDVBM.js} +47 -60
  60. package/dist/{mistral_ai-QIMZ2JYL.js → mistral_ai-TP7TQUEJ.js} +35 -40
  61. package/dist/{mother_duck-M6VWS2VH.js → mother_duck-UXY5THYU.js} +42 -62
  62. package/dist/{ngrok-Z2PKQBHH.js → ngrok-RZW2ISJK.js} +42 -58
  63. package/dist/{notes-SS4RPC4K.js → notes-B2I6FWK2.js} +3 -5
  64. package/dist/{notion-FJCNQ6I7.js → notion-QOKRUE6M.js} +83 -97
  65. package/dist/{open_exchange_rates-WU57WTT5.js → open_exchange_rates-ODLFWEJ7.js} +35 -39
  66. package/dist/{openai-JODZ4GKT.js → openai-ZPBPPPGT.js} +51 -55
  67. package/dist/{opengraph_io-SQRAUSV5.js → opengraph_io-EOI5UJKT.js} +61 -79
  68. package/dist/{openrouter-Q5XXEJZ7.js → openrouter-BUWLF3BG.js} +41 -55
  69. package/dist/{outline-RT2EHJ2X.js → outline-NXS3QRXO.js} +89 -104
  70. package/dist/{paddle-OF2V7GAC.js → paddle-T4MSKQ76.js} +34 -49
  71. package/dist/{perplexity-LNZEWLHG.js → perplexity-WW5N2LW7.js} +33 -50
  72. package/dist/{pinecone-JSJIXZYN.js → pinecone-RY5AZPQM.js} +65 -91
  73. package/dist/{pipedrive-D4CKVUXR.js → pipedrive-OHYQNZTU.js} +37 -59
  74. package/dist/{polar-M7ZYP6UR.js → polar-XZIAHXS5.js} +43 -53
  75. package/dist/{posthog-YV7CZOH4.js → posthog-DTPTWORY.js} +58 -77
  76. package/dist/{postmark-KYHLECRG.js → postmark-F4UCQKC3.js} +52 -71
  77. package/dist/{prerender-HCMHBKV2.js → prerender-P3Y2MLIC.js} +32 -50
  78. package/dist/{pubmed-WYVLCCN3.js → pubmed-RHU3GXFB.js} +28 -60
  79. package/dist/{railway-TWIRD5KR.js → railway-VB6SRLI6.js} +32 -39
  80. package/dist/{readwise-UZ467IQ7.js → readwise-DIMSKJZR.js} +62 -78
  81. package/dist/{render-MECUC5CC.js → render-XCCDCEEK.js} +48 -64
  82. package/dist/{replicate-A5MEK3SW.js → replicate-IUEOQ4JC.js} +41 -58
  83. package/dist/{resend-BC6EAWJQ.js → resend-N5MJZH5E.js} +27 -37
  84. package/dist/{rootly-ZM3QDUIS.js → rootly-25T4NBTU.js} +64 -76
  85. package/dist/{scrapfly-WAML42QJ.js → scrapfly-PK4XFXUA.js} +45 -51
  86. package/dist/{scrapingbee-DG7PET3V.js → scrapingbee-ITPBMWQU.js} +25 -33
  87. package/dist/{screenshot_fyi-HY6WTHIO.js → screenshot_fyi-5U6ZYPKR.js} +29 -47
  88. package/dist/{semantic_scholar-C5IZA7IP.js → semantic_scholar-BJGCI2MU.js} +37 -56
  89. package/dist/{sentry-OKBPSTDM.js → sentry-63IC263P.js} +66 -85
  90. package/dist/{shodan-PPC6DYU4.js → shodan-2WBIFHFN.js} +42 -53
  91. package/dist/{shopify-EWGUHBXO.js → shopify-XLLJRAGM.js} +32 -49
  92. package/dist/{stripe-6RPDPC5W.js → stripe-WLVCY3UN.js} +4 -5
  93. package/dist/{supabase-SK7DQ42N.js → supabase-BKNZ35ER.js} +69 -88
  94. package/dist/{tavily-YCG5VQMH.js → tavily-YFSDEUTL.js} +37 -62
  95. package/dist/{telegram-2OES5FYB.js → telegram-FC35W74G.js} +168 -177
  96. package/dist/{telnyx-POOSBBR4.js → telnyx-MI32XZUG.js} +30 -50
  97. package/dist/{todoist-M7YD6YSS.js → todoist-4ZFJKZC6.js} +77 -89
  98. package/dist/{trello-IS6V5W3E.js → trello-UOGFNMK4.js} +108 -122
  99. package/dist/{turso-RCFHUFVH.js → turso-YTSTW3ZS.js} +52 -64
  100. package/dist/{twilio-OS2RXFGO.js → twilio-XAJDFUQH.js} +48 -55
  101. package/dist/{umami-PQ2SJ2LN.js → umami-ZVIUBPAI.js} +49 -69
  102. package/dist/{unsplash-C6BPZO4E.js → unsplash-IU3PLDNS.js} +35 -52
  103. package/dist/{upstash_redis-WH6UER7H.js → upstash_redis-3EYJW7SY.js} +28 -40
  104. package/dist/{uptimerobot-M3YZGS6Z.js → uptimerobot-PJG2ASRU.js} +11 -12
  105. package/dist/{v2ex-R4JWTEHN.js → v2ex-KFQWWGFC.js} +36 -61
  106. package/dist/{vercel-FZVYUOQD.js → vercel-I2ZDOQRL.js} +124 -150
  107. package/dist/{webapi-VLM4IKVB.js → webapi-GW5QXWXE.js} +1 -1
  108. package/dist/{wolfram_alpha_api-2KOLO5DC.js → wolfram_alpha_api-BNXOJMB6.js} +26 -34
  109. package/dist/{wordpress-XRWGO6LG.js → wordpress-36D7BSMP.js} +87 -104
  110. package/dist/{workos-WR4NKOYL.js → workos-6X4JJRRC.js} +37 -56
  111. package/dist/{zhihu-BKZIB3WA.js → zhihu-CIXKCHIU.js} +35 -57
  112. package/package.json +5 -5
  113. package/dist/chunk-2O27H4Y2.js +0 -183
  114. package/dist/chunk-GKX72JMJ.js +0 -378
  115. package/dist/chunk-MLKGABMK.js +0 -9
@@ -1,17 +1,23 @@
1
+ import {
2
+ bytesToBase64
3
+ } from "./chunk-LMLX3DJF.js";
4
+ import {
5
+ asJsonObject,
6
+ compactDefined
7
+ } from "./chunk-JXHMDBAY.js";
1
8
  import {
2
9
  createProviderPlugin,
3
10
  requireApiKey,
4
11
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
12
+ } from "./chunk-YASUMV2K.js";
6
13
  import {
7
14
  guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
15
+ } from "./chunk-U5UHT7CX.js";
10
16
  import {
11
17
  TBError,
12
18
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
19
+ } from "./chunk-RVWZN3CI.js";
20
+ import "./chunk-U67V476Y.js";
15
21
 
16
22
  // ../plugins/src/googledocs/api/shared.ts
17
23
  var SERVICE = "googledocs";
@@ -20,7 +26,6 @@ var DRIVE_API_BASE = "https://www.googleapis.com/drive/v3";
20
26
  var SHEETS_API_BASE = "https://sheets.googleapis.com/v4";
21
27
  var REQUEST_TIMEOUT_MS = 3e4;
22
28
  var MAX_ERROR_MESSAGE_LENGTH = 500;
23
- var BASE64_CHUNK = 8192;
24
29
  var RATE_LIMIT_REASONS = /* @__PURE__ */ new Set([
25
30
  "rateLimitExceeded",
26
31
  "userRateLimitExceeded",
@@ -41,17 +46,11 @@ var DRIVE_FILE_FIELDS = [
41
46
  "starred",
42
47
  "trashed"
43
48
  ].join(",");
44
- function record(value) {
45
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
46
- }
49
+ var record = asJsonObject;
47
50
  function optionalText(value) {
48
51
  return value === void 0 || value === "" ? void 0 : value;
49
52
  }
50
- function compact(input) {
51
- return Object.fromEntries(
52
- Object.entries(input).filter((entry) => entry[1] !== void 0)
53
- );
54
- }
53
+ var compact = compactDefined;
55
54
  function requireRecord(value, label) {
56
55
  const result = record(value);
57
56
  if (result === void 0) throw new TBError("unavailable", `${label}\u4E0D\u662F\u5BF9\u8C61`, { retryable: true });
@@ -183,13 +182,6 @@ async function requestJson(ctx, input) {
183
182
  async function requestRecord(ctx, input) {
184
183
  return requireRecord(await requestJson(ctx, input), "Google Docs \u54CD\u5E94");
185
184
  }
186
- function base64(bytes) {
187
- let binary = "";
188
- for (let offset = 0; offset < bytes.length; offset += BASE64_CHUNK) {
189
- binary += String.fromCharCode(...bytes.subarray(offset, offset + BASE64_CHUNK));
190
- }
191
- return btoa(binary);
192
- }
193
185
  async function runBatch(ctx, documentId, requests, writeControl) {
194
186
  const payload = await requestRecord(ctx, {
195
187
  url: `${DOCS_API_BASE}/documents/${documentId}:batchUpdate`,
@@ -617,7 +609,7 @@ async function exportDocumentAsPdf(input, ctx) {
617
609
  fileId,
618
610
  filename: filename === void 0 ? `${fileId}.pdf` : filename.endsWith(".pdf") ? filename : `${filename}.pdf`,
619
611
  mimeType: "application/pdf",
620
- dataBase64: base64(bytes),
612
+ dataBase64: bytesToBase64(bytes),
621
613
  sizeBytes: bytes.byteLength
622
614
  };
623
615
  }
@@ -1,18 +1,26 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import {
5
+ asJsonObject,
6
+ booleanValue,
7
+ compactDefined,
8
+ integerValue,
9
+ trimmedText
10
+ } from "./chunk-JXHMDBAY.js";
1
11
  import {
2
12
  createProviderPlugin,
3
13
  requireApiKey,
4
14
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
15
+ } from "./chunk-YASUMV2K.js";
6
16
  import {
7
- assertPublicHttpUrl,
8
- guardedFetch
9
- } from "./chunk-2O27H4Y2.js";
10
- import "./chunk-GKX72JMJ.js";
17
+ assertPublicHttpUrl
18
+ } from "./chunk-U5UHT7CX.js";
11
19
  import {
12
20
  TBError,
13
21
  external_exports
14
- } from "./chunk-YB2FLNWI.js";
15
- import "./chunk-MLKGABMK.js";
22
+ } from "./chunk-RVWZN3CI.js";
23
+ import "./chunk-U67V476Y.js";
16
24
 
17
25
  // ../plugins/src/grafana/api.ts
18
26
  var SERVICE = "grafana";
@@ -25,47 +33,29 @@ var API_GROUPS = {
25
33
  folders: "folder.grafana.app"
26
34
  };
27
35
  var API_VERSION_CACHE_MAX = 256;
36
+ var http = createProviderHttpClient({ service: SERVICE });
28
37
  var apiVersionCache = /* @__PURE__ */ new Map();
29
- function record(value) {
30
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
31
- }
32
- function text(value) {
33
- if (typeof value !== "string") return void 0;
34
- const trimmed = value.trim();
35
- return trimmed === "" ? void 0 : trimmed;
36
- }
37
- function integer(value) {
38
- return typeof value === "number" && Number.isInteger(value) ? value : void 0;
39
- }
40
- function boolean(value) {
41
- return typeof value === "boolean" ? value : void 0;
42
- }
43
- function compact(input) {
44
- return Object.fromEntries(
45
- Object.entries(input).filter(([, value]) => value !== void 0)
46
- );
47
- }
48
38
  function requireText(value, field) {
49
- const result = text(value);
39
+ const result = trimmedText(value);
50
40
  if (result === void 0) throw new TBError("invalid_argument", `${field} is required`);
51
41
  return result;
52
42
  }
53
43
  function requireObject(value, field) {
54
- const object = record(value);
44
+ const object = asJsonObject(value);
55
45
  if (object === void 0) throw new TBError("invalid_argument", `${field} object is required`);
56
46
  return object;
57
47
  }
58
48
  function objectArray(value) {
59
49
  if (!Array.isArray(value)) return [];
60
50
  return value.flatMap((item) => {
61
- const fields = record(item);
51
+ const fields = asJsonObject(item);
62
52
  return fields === void 0 ? [] : [fields];
63
53
  });
64
54
  }
65
55
  function stringArray(value) {
66
56
  if (value === void 0) return void 0;
67
57
  return value.flatMap((item) => {
68
- const trimmed = text(item);
58
+ const trimmed = trimmedText(item);
69
59
  return trimmed === void 0 ? [] : [trimmed];
70
60
  });
71
61
  }
@@ -75,7 +65,7 @@ function configError(message) {
75
65
  function resolveBaseUrl(ctx) {
76
66
  const configured = ctx.config?.baseUrl;
77
67
  if (configured !== void 0 && typeof configured !== "string") throw configError("\u5FC5\u987B\u662F\u5B57\u7B26\u4E32");
78
- const candidate = text(configured);
68
+ const candidate = trimmedText(configured);
79
69
  if (candidate === void 0) {
80
70
  throw configError(
81
71
  "\u662F\u5FC5\u914D\u9879:\u7ED9\u6302\u8F7D\u8282\u70B9\u914D providerConfig.baseUrl \u6307\u5411\u4F60\u7684 Grafana \u5B9E\u4F8B(\u5982 https://your-stack.grafana.net)\u3002Grafana \u6CA1\u6709\u516C\u5171\u7F3A\u7701\u5730\u5740,\u62FF\u4E0D\u5230\u5B83\u65E0\u6CD5\u51FA\u7AD9"
@@ -99,53 +89,36 @@ function resolveTarget(ctx) {
99
89
  return { apiKey: requireApiKey(ctx, SERVICE), baseUrl: resolveBaseUrl(ctx) };
100
90
  }
101
91
  function errorMessage(payload, status, statusText) {
102
- const direct = text(payload);
92
+ const direct = trimmedText(payload);
103
93
  if (direct !== void 0) return direct;
104
- const fields = record(payload);
105
- const message = text(fields?.message) ?? text(fields?.error) ?? text(fields?.detail) ?? text(fields?.title);
106
- return message ?? text(statusText) ?? `Grafana request failed with ${status}`;
107
- }
108
- function buildUrl(baseUrl, input) {
109
- const url = new URL(input.path.replace(/^\/+/, ""), `${baseUrl}/`);
110
- for (const [key, value] of Object.entries(input.query ?? {})) {
111
- if (value !== void 0) url.searchParams.set(key, String(value));
112
- }
113
- for (const [key, values] of Object.entries(input.multiValueQuery ?? {})) {
114
- for (const value of values ?? []) url.searchParams.append(key, value);
115
- }
116
- return url.toString();
117
- }
118
- function readPayload(body) {
119
- if (body.trim() === "") return null;
120
- try {
121
- return JSON.parse(body);
122
- } catch {
123
- return body;
124
- }
94
+ const fields = asJsonObject(payload);
95
+ const message = trimmedText(fields?.message) ?? trimmedText(fields?.error) ?? trimmedText(fields?.detail) ?? trimmedText(fields?.title);
96
+ return message ?? trimmedText(statusText) ?? `Grafana request failed with ${status}`;
125
97
  }
126
98
  async function request(target, input) {
127
- let response;
128
- let payload;
129
- try {
130
- response = await guardedFetch(buildUrl(target.baseUrl, input), {
131
- method: input.method,
132
- headers: {
133
- accept: "application/json",
134
- authorization: `Bearer ${target.apiKey}`,
135
- ...input.body === void 0 ? {} : { "content-type": "application/json" }
136
- },
137
- body: input.body === void 0 ? void 0 : JSON.stringify(input.body)
138
- });
139
- payload = readPayload(await response.text());
140
- } catch (error) {
141
- if (error instanceof TBError) throw error;
142
- const detail = error instanceof Error ? error.message : "unknown network error";
143
- throw upstreamError(502, `Grafana request failed: ${detail}`);
144
- }
145
- if (!response.ok) {
146
- throw upstreamError(response.status, errorMessage(payload, response.status, response.statusText));
147
- }
148
- return payload;
99
+ const query = [
100
+ ...Object.entries(input.query ?? {}),
101
+ ...Object.entries(input.multiValueQuery ?? {})
102
+ ];
103
+ const result = await http.request({
104
+ // 尾斜杠保住实例部署上下文路径(`/grafana`);薄层再强制 path 不得换 origin。
105
+ baseUrl: `${target.baseUrl}/`,
106
+ path: input.path,
107
+ method: input.method,
108
+ query,
109
+ headers: { accept: "application/json", authorization: `Bearer ${target.apiKey}` },
110
+ ...input.body === void 0 ? {} : { json: input.body },
111
+ invalidJson: "text",
112
+ mapError: ({ data, status, statusText }) => upstreamError(
113
+ status,
114
+ errorMessage(data, status, statusText)
115
+ ),
116
+ mapTransportError: ({ message }) => upstreamError(
117
+ 502,
118
+ `Grafana request failed: ${message ?? "unknown network error"}`
119
+ )
120
+ });
121
+ return result.data === void 0 ? null : result.data;
149
122
  }
150
123
  function cacheApiVersion(key, version) {
151
124
  apiVersionCache.delete(key);
@@ -161,7 +134,7 @@ async function resolveApiVersion(target, group) {
161
134
  if (cached !== void 0) return cached;
162
135
  try {
163
136
  const payload = await request(target, { method: "GET", path: `/apis/${group}` });
164
- const served = new Set(objectArray(record(payload)?.versions).map((entry) => text(entry.version)).filter((version) => version !== void 0));
137
+ const served = new Set(objectArray(asJsonObject(payload)?.versions).map((entry) => trimmedText(entry.version)).filter((version) => version !== void 0));
165
138
  const match = API_VERSION_PREFERENCE.find((version) => served.has(version));
166
139
  if (match !== void 0) {
167
140
  cacheApiVersion(key, match);
@@ -174,7 +147,7 @@ async function resolveApiVersion(target, group) {
174
147
  async function appPath(target, resource, namespace) {
175
148
  const group = API_GROUPS[resource];
176
149
  const version = await resolveApiVersion(target, group);
177
- const ns = encodeURIComponent(text(namespace) ?? DEFAULT_NAMESPACE);
150
+ const ns = encodeURIComponent(trimmedText(namespace) ?? DEFAULT_NAMESPACE);
178
151
  return `/apis/${group}/${version}/namespaces/${ns}/${resource}`;
179
152
  }
180
153
  async function appResourcePath(target, resource, namespace, uid) {
@@ -183,56 +156,56 @@ async function appResourcePath(target, resource, namespace, uid) {
183
156
  }
184
157
  function resourceBody(input) {
185
158
  return {
186
- metadata: compact({
187
- name: text(input.uid),
188
- generateName: text(input.generateName),
189
- resourceVersion: text(input.resourceVersion),
159
+ metadata: compactDefined({
160
+ name: trimmedText(input.uid),
161
+ generateName: trimmedText(input.generateName),
162
+ resourceVersion: trimmedText(input.resourceVersion),
190
163
  annotations: input.parent === void 0 ? void 0 : { [FOLDER_PARENT_ANNOTATION]: input.parent }
191
164
  }),
192
165
  spec: input.spec
193
166
  };
194
167
  }
195
168
  function normalizeAppResource(value, parentKey) {
196
- const fields = record(value) ?? {};
197
- const metadata = record(fields.metadata) ?? {};
198
- const spec = record(fields.spec) ?? {};
199
- const annotations = record(metadata.annotations) ?? {};
169
+ const fields = asJsonObject(value) ?? {};
170
+ const metadata = asJsonObject(fields.metadata) ?? {};
171
+ const spec = asJsonObject(fields.spec) ?? {};
172
+ const annotations = asJsonObject(metadata.annotations) ?? {};
200
173
  return {
201
- uid: text(metadata.name) ?? text(metadata.uid) ?? null,
202
- title: text(spec.title) ?? null,
203
- namespace: text(metadata.namespace) ?? null,
204
- resourceVersion: text(metadata.resourceVersion) ?? null,
205
- [parentKey]: text(annotations[FOLDER_PARENT_ANNOTATION]) ?? null,
174
+ uid: trimmedText(metadata.name) ?? trimmedText(metadata.uid) ?? null,
175
+ title: trimmedText(spec.title) ?? null,
176
+ namespace: trimmedText(metadata.namespace) ?? null,
177
+ resourceVersion: trimmedText(metadata.resourceVersion) ?? null,
178
+ [parentKey]: trimmedText(annotations[FOLDER_PARENT_ANNOTATION]) ?? null,
206
179
  raw: fields
207
180
  };
208
181
  }
209
182
  function normalizeSearchItem(value) {
210
183
  return {
211
184
  ...value,
212
- id: integer(value.id) ?? null,
213
- uid: text(value.uid) ?? null,
214
- title: text(value.title) ?? null,
215
- type: text(value.type) ?? null,
216
- url: text(value.url) ?? null,
217
- isStarred: boolean(value.isStarred) ?? null
185
+ id: integerValue(value.id) ?? null,
186
+ uid: trimmedText(value.uid) ?? null,
187
+ title: trimmedText(value.title) ?? null,
188
+ type: trimmedText(value.type) ?? null,
189
+ url: trimmedText(value.url) ?? null,
190
+ isStarred: booleanValue(value.isStarred) ?? null
218
191
  };
219
192
  }
220
193
  function normalizeDataSource(value) {
221
- const fields = record(value) ?? {};
194
+ const fields = asJsonObject(value) ?? {};
222
195
  return {
223
196
  ...fields,
224
- id: integer(fields.id) ?? null,
225
- uid: text(fields.uid) ?? null,
226
- name: text(fields.name) ?? null,
227
- type: text(fields.type) ?? null,
228
- access: text(fields.access) ?? null,
229
- url: text(fields.url) ?? null,
230
- isDefault: boolean(fields.isDefault) ?? null,
231
- readOnly: boolean(fields.readOnly) ?? null
197
+ id: integerValue(fields.id) ?? null,
198
+ uid: trimmedText(fields.uid) ?? null,
199
+ name: trimmedText(fields.name) ?? null,
200
+ type: trimmedText(fields.type) ?? null,
201
+ access: trimmedText(fields.access) ?? null,
202
+ url: trimmedText(fields.url) ?? null,
203
+ isDefault: booleanValue(fields.isDefault) ?? null,
204
+ readOnly: booleanValue(fields.readOnly) ?? null
232
205
  };
233
206
  }
234
207
  function deleted(payload) {
235
- return { deleted: true, raw: record(payload) ?? null };
208
+ return { deleted: true, raw: asJsonObject(payload) ?? null };
236
209
  }
237
210
  function dataSourcePath(uid) {
238
211
  return `/api/datasources/uid/${encodeURIComponent(requireText(uid, "uid"))}`;
@@ -243,12 +216,12 @@ async function listFolders(input, ctx) {
243
216
  method: "GET",
244
217
  path: await appPath(target, "folders", input.namespace),
245
218
  // Kubernetes 风格的分页:游标叫 `continue`,入参里叫 `continueToken`。
246
- query: compact({ limit: input.limit, continue: text(input.continueToken) })
219
+ query: compactDefined({ limit: input.limit, continue: trimmedText(input.continueToken) })
247
220
  });
248
- const fields = record(payload) ?? {};
221
+ const fields = asJsonObject(payload) ?? {};
249
222
  return {
250
223
  folders: objectArray(fields.items).map((item) => normalizeAppResource(item, "parentUid")),
251
- continueToken: text(record(fields.metadata)?.continue) ?? null,
224
+ continueToken: trimmedText(asJsonObject(fields.metadata)?.continue) ?? null,
252
225
  raw: fields
253
226
  };
254
227
  }
@@ -268,7 +241,7 @@ async function createFolder(input, ctx) {
268
241
  body: resourceBody({
269
242
  uid: input.uid,
270
243
  generateName: input.generateName,
271
- parent: text(input.parentUid),
244
+ parent: trimmedText(input.parentUid),
272
245
  spec: { title: requireText(input.title, "title") }
273
246
  })
274
247
  });
@@ -284,7 +257,7 @@ async function updateFolder(input, ctx) {
284
257
  body: resourceBody({
285
258
  uid,
286
259
  resourceVersion: input.resourceVersion,
287
- parent: text(input.parentUid),
260
+ parent: trimmedText(input.parentUid),
288
261
  spec: { title: requireText(input.title, "title") }
289
262
  })
290
263
  });
@@ -302,9 +275,9 @@ async function searchDashboards(input, ctx) {
302
275
  const payload = await request(resolveTarget(ctx), {
303
276
  method: "GET",
304
277
  path: "/api/search",
305
- query: compact({
306
- query: text(input.query),
307
- type: text(input.type),
278
+ query: compactDefined({
279
+ query: trimmedText(input.query),
280
+ type: trimmedText(input.type),
308
281
  starred: input.starred,
309
282
  limit: input.limit,
310
283
  page: input.page
@@ -334,7 +307,7 @@ async function createDashboard(input, ctx) {
334
307
  body: resourceBody({
335
308
  uid: input.uid,
336
309
  generateName: input.generateName,
337
- parent: text(input.folderUid),
310
+ parent: trimmedText(input.folderUid),
338
311
  spec: requireObject(input.spec, "spec")
339
312
  })
340
313
  });
@@ -349,7 +322,7 @@ async function updateDashboard(input, ctx) {
349
322
  body: resourceBody({
350
323
  uid,
351
324
  resourceVersion: input.resourceVersion,
352
- parent: text(input.folderUid),
325
+ parent: trimmedText(input.folderUid),
353
326
  spec: requireObject(input.spec, "spec")
354
327
  })
355
328
  });
@@ -379,8 +352,8 @@ async function createDataSource(input, ctx) {
379
352
  body: requireObject(input.dataSource, "dataSource")
380
353
  });
381
354
  return {
382
- dataSource: normalizeDataSource(record(payload)?.datasource ?? payload),
383
- raw: record(payload) ?? {}
355
+ dataSource: normalizeDataSource(asJsonObject(payload)?.datasource ?? payload),
356
+ raw: asJsonObject(payload) ?? {}
384
357
  };
385
358
  }
386
359
  async function updateDataSource(input, ctx) {
@@ -390,8 +363,8 @@ async function updateDataSource(input, ctx) {
390
363
  body: requireObject(input.dataSource, "dataSource")
391
364
  });
392
365
  return {
393
- dataSource: normalizeDataSource(record(payload)?.datasource ?? payload),
394
- raw: record(payload) ?? {}
366
+ dataSource: normalizeDataSource(asJsonObject(payload)?.datasource ?? payload),
367
+ raw: asJsonObject(payload) ?? {}
395
368
  };
396
369
  }
397
370
  async function deleteDataSource(input, ctx) {
@@ -408,14 +381,14 @@ async function getAlertRule(input, ctx) {
408
381
  method: "GET",
409
382
  path: `/api/v1/provisioning/alert-rules/${uid}`
410
383
  });
411
- return { alertRule: record(payload) ?? {} };
384
+ return { alertRule: asJsonObject(payload) ?? {} };
412
385
  }
413
386
  async function listAlertInstances(input, ctx) {
414
387
  const payload = await request(resolveTarget(ctx), {
415
388
  method: "GET",
416
389
  // 内置 Alertmanager 的 v2 端点,与 App Platform 的版本协商无关。
417
390
  path: "/api/alertmanager/grafana/api/v2/alerts",
418
- query: compact({ active: input.active, silenced: input.silenced, inhibited: input.inhibited })
391
+ query: compactDefined({ active: input.active, silenced: input.silenced, inhibited: input.inhibited })
419
392
  });
420
393
  return { alertInstances: objectArray(payload) };
421
394
  }
@@ -1,75 +1,61 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import {
5
+ asJsonObject
6
+ } from "./chunk-JXHMDBAY.js";
1
7
  import {
2
8
  createProviderPlugin,
3
9
  requireApiKey,
4
10
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
11
+ } from "./chunk-YASUMV2K.js";
12
+ import "./chunk-U5UHT7CX.js";
10
13
  import {
11
14
  TBError,
12
15
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
16
+ } from "./chunk-RVWZN3CI.js";
17
+ import "./chunk-U67V476Y.js";
15
18
 
16
19
  // ../plugins/src/graphhopper/api.ts
17
20
  var SERVICE = "graphhopper";
18
21
  var API_BASE = "https://graphhopper.com";
19
22
  var API_PREFIX = "/api/1";
20
- function record(value) {
21
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
22
- }
23
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}${API_PREFIX}/`, service: SERVICE });
23
24
  function text(value) {
24
25
  return typeof value === "string" && value.trim() !== "" ? value : void 0;
25
26
  }
26
- function errorMessage(payload, response) {
27
+ function errorMessage(payload, context) {
27
28
  if (typeof payload === "string" && payload.trim() !== "") return payload;
28
- const body = record(payload);
29
+ const body = asJsonObject(payload);
29
30
  if (body !== void 0) {
30
31
  const direct = text(body.message) ?? text(body.error) ?? text(body.details);
31
32
  if (direct !== void 0) return direct;
32
33
  if (Array.isArray(body.hints)) {
33
34
  for (const hint of body.hints) {
34
- const message = text(record(hint)?.message);
35
+ const message = text(asJsonObject(hint)?.message);
35
36
  if (message !== void 0) return message;
36
37
  }
37
38
  }
38
39
  }
39
- return text(response.statusText) ?? "GraphHopper request failed";
40
+ return text(context.statusText) ?? "GraphHopper request failed";
40
41
  }
41
42
  async function request(ctx, path, query) {
42
- const url = new URL(`${API_PREFIX}${path}`, API_BASE);
43
- for (const [key, value] of Object.entries(query)) {
44
- if (value === void 0) continue;
45
- if (Array.isArray(value)) {
46
- for (const item of value) url.searchParams.append(key, String(item));
47
- continue;
48
- }
49
- url.searchParams.set(key, String(value));
50
- }
51
- url.searchParams.set("key", requireApiKey(ctx, SERVICE));
52
- let response;
53
- let payload = null;
54
- try {
55
- response = await guardedFetch(url.toString(), {
56
- method: "GET",
57
- headers: { accept: "application/json" }
58
- });
59
- const raw = await response.text();
60
- if (raw.trim() !== "") {
61
- try {
62
- payload = JSON.parse(raw);
63
- } catch {
64
- payload = raw;
65
- }
66
- }
67
- } catch (error) {
68
- const message = error instanceof Error ? `GraphHopper request failed: ${error.message}` : "GraphHopper request failed";
69
- throw upstreamError(502, message);
70
- }
71
- if (!response.ok) throw upstreamError(response.status, errorMessage(payload, response));
72
- return payload;
43
+ const result = await http.request({
44
+ path,
45
+ method: "GET",
46
+ query: [
47
+ ...Object.entries(query),
48
+ ["key", requireApiKey(ctx, SERVICE)]
49
+ ],
50
+ headers: { accept: "application/json" },
51
+ invalidJson: "text",
52
+ mapError: (context) => upstreamError(context.status, errorMessage(context.data, context)),
53
+ mapTransportError: ({ message }) => upstreamError(
54
+ 502,
55
+ message === void 0 ? "GraphHopper request failed" : `GraphHopper request failed: ${message}`
56
+ )
57
+ });
58
+ return result.bodyKind === "empty" ? null : result.data;
73
59
  }
74
60
  async function calculateRoute(input, ctx) {
75
61
  return request(ctx, "/route", {
@@ -159,7 +145,7 @@ async function computeIsochrone(input, ctx) {
159
145
  async function listProfiles(_input, ctx) {
160
146
  const payload = await request(ctx, "/profiles", {});
161
147
  if (Array.isArray(payload)) return { profiles: payload };
162
- const profiles = record(payload)?.profiles;
148
+ const profiles = asJsonObject(payload)?.profiles;
163
149
  return { profiles: Array.isArray(profiles) ? profiles : [] };
164
150
  }
165
151