@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
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { z } from 'zod';
1
+ import * as z from './v4/classic/external.cjs';
2
2
  import * as http from 'node:http';
3
3
  import { Sql } from 'postgres';
4
4
  import { Hono } from 'hono';
@@ -530,6 +530,50 @@ interface ContextProvider {
530
530
  write?(path: string, entry: ContextEntryInput): Promise<ContextEntryMeta>;
531
531
  }
532
532
 
533
+ /**
534
+ * Tool Layer 的中立类型。
535
+ *
536
+ * `ToolSpec` 是**上游工具的中立形状**:mcp(`tools/list` 的 `Tool`)与 http
537
+ * (`HttpToolDef`)都归一到它,虚拟化(virtualize.ts)与 `~help` 派生(mcpSchema.ts)
538
+ * 只认 `ToolSpec`,不感知上游是 mcp 还是 http。它把 `ToolMeta`+`ToolDef`
539
+ * 合并为一个形状:`description` 可缺省(上游可能不带),另携 `confirm`(危险工具二次确认)。
540
+ */
541
+ /** 上游工具的中立形状(mcp/http 归一目标)。 */
542
+ interface ToolSpec {
543
+ /** 危险操作二次确认;进 `~help` 的 confirm 行。 */
544
+ confirm?: boolean;
545
+ /** 一句话描述;进 `~help` 的 `h` 行。上游可能不带 → 可缺省。 */
546
+ description?: string;
547
+ /** 副作用标记(read/write/destructive);进 `~help` 的 effect 行。 */
548
+ effect?: string;
549
+ /** JSON Schema;`~help` 的 body 数据源。 */
550
+ inputSchema?: unknown;
551
+ /** 工具名(虚拟化前为上游原名,虚拟化后为对外虚拟名)。 */
552
+ name: string;
553
+ /**
554
+ * 返回值的 JSON Schema(可选)。与 `inputSchema` 对称,同为裸 JSON Schema。
555
+ *
556
+ * 来源:MCP 上游的 `Tool.outputSchema`、plugin 作者在 `OperationSpec.outputSchema` 里的声明。
557
+ * 去处:工具级全量 `~help`(JSON 的 `outputSchema` / DSL 的 `result` 行)与 MCP consumer 端点。
558
+ * 索引形态的 `~help` 不含它(同 inputSchema,两级披露)。
559
+ */
560
+ outputSchema?: unknown;
561
+ }
562
+ /**
563
+ * 工具调用结果。`isError:true` 是**工具业务级错误**(上游 HTTP 200
564
+ * 正常返回、内容为错),按内容协商渲染——**不是** TBError(传输/协议错误才归一为
565
+ * TBError,见 upstreamError.ts)。
566
+ */
567
+ interface ToolResult {
568
+ /** markdown 文本或结构化 JSON(按内容协商输出)。 */
569
+ content: string | unknown;
570
+ /** MCP 等上游的原生多模态 content blocks;HTBP 渲染仍使用归一后的 content。 */
571
+ contentBlocks?: unknown[];
572
+ isError?: boolean;
573
+ /** MCP 上游返回的结构化结果;consumer endpoint 转发时保留。 */
574
+ structuredContent?: Record<string, unknown>;
575
+ }
576
+
533
577
  /**
534
578
  * DeviceFrame:设备 WS 帧协议的类型与编解码。
535
579
  *
@@ -588,50 +632,6 @@ type DeviceCallResult = {
588
632
  ok: false;
589
633
  };
590
634
 
591
- /**
592
- * Tool Layer 的中立类型。
593
- *
594
- * `ToolSpec` 是**上游工具的中立形状**:mcp(`tools/list` 的 `Tool`)与 http
595
- * (`HttpToolDef`)都归一到它,虚拟化(virtualize.ts)与 `~help` 派生(mcpSchema.ts)
596
- * 只认 `ToolSpec`,不感知上游是 mcp 还是 http。它把 `ToolMeta`+`ToolDef`
597
- * 合并为一个形状:`description` 可缺省(上游可能不带),另携 `confirm`(危险工具二次确认)。
598
- */
599
- /** 上游工具的中立形状(mcp/http 归一目标)。 */
600
- interface ToolSpec {
601
- /** 危险操作二次确认;进 `~help` 的 confirm 行。 */
602
- confirm?: boolean;
603
- /** 一句话描述;进 `~help` 的 `h` 行。上游可能不带 → 可缺省。 */
604
- description?: string;
605
- /** 副作用标记(read/write/destructive);进 `~help` 的 effect 行。 */
606
- effect?: string;
607
- /** JSON Schema;`~help` 的 body 数据源。 */
608
- inputSchema?: unknown;
609
- /** 工具名(虚拟化前为上游原名,虚拟化后为对外虚拟名)。 */
610
- name: string;
611
- /**
612
- * 返回值的 JSON Schema(可选)。与 `inputSchema` 对称,同为裸 JSON Schema。
613
- *
614
- * 来源:MCP 上游的 `Tool.outputSchema`、plugin 作者在 `OperationSpec.outputSchema` 里的声明。
615
- * 去处:工具级全量 `~help`(JSON 的 `outputSchema` / DSL 的 `result` 行)与 MCP consumer 端点。
616
- * 索引形态的 `~help` 不含它(同 inputSchema,两级披露)。
617
- */
618
- outputSchema?: unknown;
619
- }
620
- /**
621
- * 工具调用结果。`isError:true` 是**工具业务级错误**(上游 HTTP 200
622
- * 正常返回、内容为错),按内容协商渲染——**不是** TBError(传输/协议错误才归一为
623
- * TBError,见 upstreamError.ts)。
624
- */
625
- interface ToolResult {
626
- /** markdown 文本或结构化 JSON(按内容协商输出)。 */
627
- content: string | unknown;
628
- /** MCP 等上游的原生多模态 content blocks;HTBP 渲染仍使用归一后的 content。 */
629
- contentBlocks?: unknown[];
630
- isError?: boolean;
631
- /** MCP 上游返回的结构化结果;consumer endpoint 转发时保留。 */
632
- structuredContent?: Record<string, unknown>;
633
- }
634
-
635
635
  type SearchCapability = 'search' | 'search:semantic';
636
636
  /** 全局工具搜索的完整结果;只在权限和可见性候选筛选后 hydrate。 */
637
637
  interface ToolSearchHit {
@@ -860,9 +860,10 @@ interface RemoteSettings {
860
860
  /**
861
861
  * 宿主注入面与请求期公共类型。
862
862
  *
863
- * 这里只放形状:五个注入点(state / objects / secrets / device / search)、进程内
864
- * Provider 钩子与解析后的部署配置。行为实现分散在 paths/federation/deviceNodes/
865
- * toolNodes/contextNodes/helpModel 与 routes/*,装配在 tbApp.ts。
863
+ * 这里只放形状:五个数据/设备注入点(state / objects / secrets / device / search)
864
+ * Provider OAuth 安全出站通道、进程内 Provider 钩子与解析后的部署配置。行为实现
865
+ * 分散在 paths/federation/deviceNodes/toolNodes/contextNodes/helpModel 与 routes/*,
866
+ * 装配在 tbApp.ts。
866
867
  */
867
868
 
868
869
  /** 帧协议 call 转发的入参(id 由调用点生成,幂等键)。 */
@@ -901,7 +902,7 @@ interface ReadinessReport {
901
902
  ready: boolean;
902
903
  }
903
904
  /**
904
- * tb app 的宿主注入面(五注入点 + 解析后的部署配置)。
905
+ * tb app 的宿主注入面(数据/设备五注入点 + 安全出站通道 + 解析后的部署配置)。
905
906
  * 核心业务逻辑零分叉:Workers 适配层(app.ts)与 SDK(packages/sdk)都注入此形状。
906
907
  */
907
908
  interface TbAppDeps {
@@ -941,6 +942,12 @@ interface TbAppDeps {
941
942
  * 那个插件解析不出 export;反之则解析得出但调不动(unavailable)。宿主该两者同源装配。
942
943
  */
943
944
  pluginCatalog?: BuiltinCatalog;
945
+ /**
946
+ * Provider OAuth 令牌端点的宿主出站通道。必须由宿主显式注入;缺省时 OAuth
947
+ * 发起、回调兑换与 access-token 解析全部 fail closed,绝不回退到全局 fetch。
948
+ * 标准宿主注入逐跳校验且拒绝跨源 body 重定向的 guarded fetch。
949
+ */
950
+ providerOAuthFetch?: typeof fetch;
944
951
  /**
945
952
  * 后端连通性探测(GET /readyz;k8s readiness)。宿主注入闭包,自行探测其长连接
946
953
  * 后端(PG 池 / Redis)并叠加 draining 状态。缺省 → /readyz 恒 200:请求期绑定
@@ -1003,7 +1010,7 @@ declare function createTbApp(deps: TbAppDeps): Hono<{
1003
1010
  * Node 宿主的 env 配置面。变量名与语义对齐 CF 宿主(gateway/src/app.ts 的 Env),
1004
1011
  * 仅新增宿主形态相关的 TB_PORT / TB_HOST / TB_DATA_DIR / TB_UI_DIR / TB_DATABASE_URL。
1005
1012
  * 端口额外兜底平台注入的 PORT(PaaS 通行约定)。
1006
- * 解析函数镜像 app.ts allowInsecure / remoteSettingsFromEnv / positiveIntEnv。
1013
+ * Node/Workers 共用字段由 core runtimeEnv Zod schema 解析,本文件只保留 Node 宿主字段。
1007
1014
  */
1008
1015
 
1009
1016
  interface ServerConfig {
package/dist/index.js CHANGED
@@ -12,9 +12,10 @@ import {
12
12
  configFromEnv,
13
13
  createDataObjectStore,
14
14
  createTbServer
15
- } from "./chunk-BB6ZLMTU.js";
16
- import "./chunk-YB2FLNWI.js";
17
- import "./chunk-MLKGABMK.js";
15
+ } from "./chunk-TLNUIPFZ.js";
16
+ import "./chunk-U5UHT7CX.js";
17
+ import "./chunk-RVWZN3CI.js";
18
+ import "./chunk-U67V476Y.js";
18
19
  export {
19
20
  DEVICE_FORWARD_TIMEOUT_MS,
20
21
  DEVICE_ROUTE_TTL_SEC,
@@ -1,17 +1,18 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import "./chunk-JXHMDBAY.js";
1
5
  import {
2
6
  createProviderPlugin,
3
7
  requireApiKey,
4
8
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
9
+ } from "./chunk-YASUMV2K.js";
10
+ import "./chunk-U5UHT7CX.js";
10
11
  import {
11
12
  TBError,
12
13
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
14
+ } from "./chunk-RVWZN3CI.js";
15
+ import "./chunk-U67V476Y.js";
15
16
 
16
17
  // ../plugins/src/ip2proxy/schema.ts
17
18
  var lookupIpInput = external_exports.strictObject({
@@ -48,55 +49,47 @@ var ip2proxyActions = {
48
49
  // ../plugins/src/ip2proxy/api.ts
49
50
  var SERVICE = "ip2proxy";
50
51
  var API_BASE = "https://api.ip2proxy.com";
52
+ var http = createProviderHttpClient({ baseUrl: `${API_BASE}/`, service: SERVICE });
51
53
  var DEFAULT_PACKAGE = "PX1";
52
- async function readPayload(response) {
53
- const body = await response.text();
54
- if (body === "") return null;
55
- try {
56
- return JSON.parse(body);
57
- } catch {
58
- return body;
59
- }
60
- }
61
54
  function payloadError(payload) {
62
55
  if (payload === null || typeof payload !== "object" || Array.isArray(payload)) return void 0;
63
56
  const message = payload.response;
64
57
  if (typeof message !== "string" || message === "" || message === "OK") return void 0;
65
58
  return message;
66
59
  }
60
+ function classifiedPayloadError(message) {
61
+ const lower = message.toLowerCase();
62
+ return upstreamError(lower.includes("api key") || lower.includes("credit") ? 401 : 502, message);
63
+ }
67
64
  async function lookupIp(input, ctx) {
68
65
  if (input.ip === void 0 || input.ip === "") {
69
66
  throw new TBError("invalid_argument", "ip \u4E0D\u80FD\u4E3A\u7A7A");
70
67
  }
71
- const url = new URL("/", API_BASE);
72
- url.searchParams.set("key", requireApiKey(ctx, SERVICE));
73
- url.searchParams.set("format", "json");
74
- url.searchParams.set("ip", input.ip);
75
- url.searchParams.set("package", input.package ?? DEFAULT_PACKAGE);
76
- let response;
77
- let payload;
78
- try {
79
- response = await guardedFetch(url.toString(), {
80
- method: "GET",
81
- headers: { accept: "application/json" }
82
- });
83
- payload = await readPayload(response);
84
- } catch (error) {
85
- throw new TBError(
68
+ const result = await http.request({
69
+ path: "/",
70
+ method: "GET",
71
+ query: [
72
+ ["key", requireApiKey(ctx, SERVICE)],
73
+ ["format", "json"],
74
+ ["ip", input.ip],
75
+ ["package", input.package ?? DEFAULT_PACKAGE]
76
+ ],
77
+ headers: { accept: "application/json" },
78
+ invalidJson: "text",
79
+ mapError: ({ data: payload2, status, statusText }) => {
80
+ const failure2 = payloadError(payload2);
81
+ if (failure2 !== void 0) return classifiedPayloadError(failure2);
82
+ return upstreamError(status || 500, statusText || "IP2Proxy request failed");
83
+ },
84
+ mapTransportError: ({ message }) => new TBError(
86
85
  "unavailable",
87
- error instanceof Error ? `IP2Proxy \u8BF7\u6C42\u5931\u8D25: ${error.message}` : "IP2Proxy \u8BF7\u6C42\u5931\u8D25",
86
+ message === void 0 ? "IP2Proxy \u8BF7\u6C42\u5931\u8D25" : `IP2Proxy \u8BF7\u6C42\u5931\u8D25: ${message}`,
88
87
  { retryable: true }
89
- );
90
- }
88
+ )
89
+ });
90
+ const payload = result.bodyKind === "empty" ? null : result.data;
91
91
  const failure = payloadError(payload);
92
- if (failure !== void 0) {
93
- const lower = failure.toLowerCase();
94
- const credentialIssue = lower.includes("api key") || lower.includes("credit");
95
- throw upstreamError(credentialIssue ? 401 : 502, failure);
96
- }
97
- if (!response.ok) {
98
- throw upstreamError(response.status || 500, response.statusText || "IP2Proxy request failed");
99
- }
92
+ if (failure !== void 0) throw classifiedPayloadError(failure);
100
93
  if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
101
94
  throw new TBError("unavailable", "IP2Proxy \u8FD4\u56DE\u7684\u4E0D\u662F JSON \u5BF9\u8C61", { retryable: true });
102
95
  }
@@ -1,25 +1,25 @@
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
- TBError,
12
14
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
15
+ } from "./chunk-RVWZN3CI.js";
16
+ import "./chunk-U67V476Y.js";
15
17
 
16
18
  // ../plugins/src/ipgeolocation_io/api.ts
17
19
  var SERVICE = "ipgeolocation_io";
18
20
  var API_BASE = "https://api.ipgeolocation.io/";
19
21
  var REQUEST_TIMEOUT_MS = 3e4;
20
- function toRecord(value) {
21
- return typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
22
- }
22
+ var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
23
23
  function nullableString(value) {
24
24
  if (typeof value === "string") return value;
25
25
  if (typeof value === "number" || typeof value === "boolean") return String(value);
@@ -39,47 +39,27 @@ function nullableInteger(value) {
39
39
  }
40
40
  function errorMessage(payload, status) {
41
41
  if (typeof payload === "string" && payload.trim() !== "") return payload;
42
- const record = toRecord(payload);
42
+ const record = asJsonObject(payload);
43
43
  const message = record?.message ?? record?.error;
44
44
  if (typeof message === "string" && message.trim() !== "") return message;
45
45
  return `IPGeolocation.io request failed with status ${status}`;
46
46
  }
47
- async function readPayload(response) {
48
- const body = await response.text();
49
- if (body.trim() === "") return null;
50
- try {
51
- return JSON.parse(body);
52
- } catch {
53
- throw upstreamError(502, "IPGeolocation.io returned invalid JSON");
54
- }
55
- }
56
47
  async function request(ctx, path, params) {
57
- const url = new URL(path, API_BASE);
58
- url.searchParams.set("apiKey", requireApiKey(ctx, SERVICE));
59
- for (const [key, value] of Object.entries(params)) {
60
- if (value !== void 0) url.searchParams.set(key, value);
61
- }
62
- let response;
63
- try {
64
- response = await guardedFetch(url.toString(), {
65
- method: "GET",
66
- headers: { accept: "application/json" },
67
- signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
68
- });
69
- } catch (error) {
70
- if (error instanceof TBError) throw error;
71
- if (error instanceof Error && error.name === "TimeoutError") {
72
- throw upstreamError(504, "IPGeolocation.io request timed out");
73
- }
74
- throw error;
75
- }
76
- const payload = await readPayload(response);
77
- if (!response.ok) {
78
- const status = response.status;
79
- const normalized = status === 429 || status === 401 || status === 403 ? status : status >= 400 && status < 500 ? 400 : status || 500;
80
- throw upstreamError(normalized, errorMessage(payload, status));
81
- }
82
- const record = toRecord(payload);
48
+ const { data: payload } = await http.request({
49
+ path,
50
+ method: "GET",
51
+ query: [["apiKey", requireApiKey(ctx, SERVICE)], ...Object.entries(params)],
52
+ headers: { accept: "application/json" },
53
+ timeoutMs: REQUEST_TIMEOUT_MS,
54
+ invalidJsonMessage: "IPGeolocation.io returned invalid JSON",
55
+ mapError: ({ bodyKind, data, status }) => {
56
+ if (bodyKind === "invalid-json") return upstreamError(502, "IPGeolocation.io returned invalid JSON");
57
+ const normalized = status === 429 || status === 401 || status === 403 ? status : status >= 400 && status < 500 ? 400 : status || 500;
58
+ return upstreamError(normalized, errorMessage(data, status));
59
+ },
60
+ mapTransportError: ({ kind }) => kind === "timeout" ? upstreamError(504, "IPGeolocation.io request timed out") : upstreamError(502, "IPGeolocation.io request failed")
61
+ });
62
+ const record = asJsonObject(payload);
83
63
  if (record === void 0) throw upstreamError(502, "IPGeolocation.io returned an invalid payload");
84
64
  return record;
85
65
  }
@@ -106,7 +86,7 @@ async function lookupIp(input, ctx) {
106
86
  excludes: joinList(input.excludes),
107
87
  include: includes.length > 0 ? includes.join(",") : void 0
108
88
  });
109
- const location = toRecord(payload.location) ?? payload;
89
+ const location = asJsonObject(payload.location) ?? payload;
110
90
  return {
111
91
  geolocation: {
112
92
  ip: nullableString(payload.ip),
@@ -122,17 +102,17 @@ async function lookupIp(input, ctx) {
122
102
  zipcode: nullableString(location.zipcode),
123
103
  latitude: nullableNumber(location.latitude),
124
104
  longitude: nullableNumber(location.longitude),
125
- callingCode: nullableString(toRecord(payload.country_metadata)?.calling_code),
105
+ callingCode: nullableString(asJsonObject(payload.country_metadata)?.calling_code),
126
106
  countryFlag: nullableString(location.country_flag),
127
- countryMetadata: toRecord(payload.country_metadata) ?? null,
128
- network: toRecord(payload.network) ?? null,
129
- asn: toRecord(payload.asn) ?? null,
130
- company: toRecord(payload.company) ?? null,
131
- timeZone: toRecord(payload.time_zone) ?? null,
132
- currency: toRecord(payload.currency) ?? null,
133
- security: toRecord(payload.security) ?? null,
134
- abuse: toRecord(payload.abuse) ?? null,
135
- userAgent: toRecord(payload.user_agent) ?? null,
107
+ countryMetadata: asJsonObject(payload.country_metadata) ?? null,
108
+ network: asJsonObject(payload.network) ?? null,
109
+ asn: asJsonObject(payload.asn) ?? null,
110
+ company: asJsonObject(payload.company) ?? null,
111
+ timeZone: asJsonObject(payload.time_zone) ?? null,
112
+ currency: asJsonObject(payload.currency) ?? null,
113
+ security: asJsonObject(payload.security) ?? null,
114
+ abuse: asJsonObject(payload.abuse) ?? null,
115
+ userAgent: asJsonObject(payload.user_agent) ?? null,
136
116
  raw: payload
137
117
  }
138
118
  };
@@ -163,7 +143,7 @@ async function getTimezone(input, ctx) {
163
143
  yearAbbr: nullableString(payload.year_abbr),
164
144
  isDst: typeof payload.is_dst === "boolean" ? payload.is_dst : null,
165
145
  dstSavings: nullableInteger(payload.dst_savings),
166
- geo: toRecord(payload.geo) ?? null,
146
+ geo: asJsonObject(payload.geo) ?? null,
167
147
  raw: payload
168
148
  }
169
149
  };
@@ -178,7 +158,7 @@ async function getAstronomy(input, ctx) {
178
158
  });
179
159
  return {
180
160
  astronomy: {
181
- location: toRecord(payload.location) ?? null,
161
+ location: asJsonObject(payload.location) ?? null,
182
162
  date: nullableString(payload.date),
183
163
  currentTime: nullableString(payload.current_time),
184
164
  sunrise: nullableString(payload.sunrise),
@@ -1,21 +1,23 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import "./chunk-JXHMDBAY.js";
1
5
  import {
2
6
  createProviderPlugin,
3
7
  requireApiKey,
4
8
  upstreamError
5
- } from "./chunk-VK3V2WTY.js";
6
- import {
7
- guardedFetch
8
- } from "./chunk-2O27H4Y2.js";
9
- import "./chunk-GKX72JMJ.js";
9
+ } from "./chunk-YASUMV2K.js";
10
+ import "./chunk-U5UHT7CX.js";
10
11
  import {
11
12
  TBError,
12
13
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
14
+ } from "./chunk-RVWZN3CI.js";
15
+ import "./chunk-U67V476Y.js";
15
16
 
16
17
  // ../plugins/src/ipqualityscore/api.ts
17
18
  var SERVICE = "ipqualityscore";
18
19
  var API_BASE = "https://www.ipqualityscore.com";
20
+ var http = createProviderHttpClient({ baseUrl: API_BASE, service: SERVICE });
19
21
  var IP_LITERAL = external_exports.union([external_exports.ipv4(), external_exports.ipv6()]);
20
22
  function optionalText(value) {
21
23
  return value?.trim() || void 0;
@@ -32,55 +34,41 @@ function messageOf(payload) {
32
34
  const pick = (value) => typeof value === "string" ? optionalText(value) : void 0;
33
35
  return pick(record.message) ?? pick(record.error);
34
36
  }
35
- function ipqsError(response, payload) {
36
- const message = messageOf(payload) ?? optionalText(response.statusText) ?? `IPQualityScore request failed with ${response.status}`;
37
+ function ipqsError(status, statusText, payload) {
38
+ const message = messageOf(payload) ?? optionalText(statusText) ?? `IPQualityScore request failed with ${status}`;
37
39
  const lower = message.toLowerCase();
38
- if (response.status === 429 || response.status === 402 || lower.includes("insufficient credits")) {
40
+ if (status === 429 || status === 402 || lower.includes("insufficient credits")) {
39
41
  return upstreamError(429, message);
40
42
  }
41
- if (lower.includes("invalid api key") || lower.includes("api key") || response.status === 401 || response.status === 403) {
43
+ if (lower.includes("invalid api key") || lower.includes("api key") || status === 401 || status === 403) {
42
44
  return upstreamError(401, message);
43
45
  }
44
- if (response.status === 400 || lower.includes("invalid ip") || lower.includes("invalid email") || lower.includes("invalid phone") || lower.includes("invalid url")) {
46
+ if (status === 400 || lower.includes("invalid ip") || lower.includes("invalid email") || lower.includes("invalid phone") || lower.includes("invalid url")) {
45
47
  return upstreamError(400, message);
46
48
  }
47
- return upstreamError(response.status >= 400 ? response.status : 502, message);
48
- }
49
- async function readPayload(response) {
50
- const body = await response.text();
51
- if (body === "") return null;
52
- try {
53
- return JSON.parse(body);
54
- } catch {
55
- return body;
56
- }
49
+ return upstreamError(status >= 400 ? status : 502, message);
57
50
  }
58
51
  async function request(ctx, family, value, query = []) {
59
- const path = `/api/json/${family}/${encodeURIComponent(requireApiKey(ctx, SERVICE))}/${encodeURIComponent(value)}`;
60
- const url = new URL(path, API_BASE);
61
- for (const [key, queryValue] of query) {
62
- if (queryValue !== void 0) url.searchParams.append(key, queryValue);
63
- }
64
- let response;
65
- let payload;
66
- try {
67
- response = await guardedFetch(url.toString(), {
68
- method: "GET",
69
- headers: { accept: "application/json" }
70
- });
71
- payload = await readPayload(response);
72
- } catch (error) {
73
- throw new TBError(
52
+ const apiKey = requireApiKey(ctx, SERVICE);
53
+ const result = await http.request({
54
+ path: `/api/json/${family}/${encodeURIComponent(apiKey)}/${encodeURIComponent(value)}`,
55
+ method: "GET",
56
+ query,
57
+ headers: { accept: "application/json" },
58
+ invalidJson: "text",
59
+ sensitiveValues: [apiKey],
60
+ mapError: ({ data, status, statusText }) => ipqsError(status, statusText, data),
61
+ mapTransportError: ({ message }) => new TBError(
74
62
  "unavailable",
75
- error instanceof Error ? `IPQualityScore \u8BF7\u6C42\u5931\u8D25: ${error.message}` : "IPQualityScore \u8BF7\u6C42\u5931\u8D25",
63
+ message === void 0 ? "IPQualityScore \u8BF7\u6C42\u5931\u8D25" : `IPQualityScore \u8BF7\u6C42\u5931\u8D25: ${message}`,
76
64
  { retryable: true }
77
- );
78
- }
79
- if (!response.ok) throw ipqsError(response, payload);
65
+ )
66
+ });
67
+ const payload = result.bodyKind === "empty" ? null : result.data;
80
68
  if (payload === null || typeof payload !== "object" || Array.isArray(payload)) {
81
69
  throw new TBError("unavailable", `IPQualityScore \u5BF9 ${family} \u7684\u54CD\u5E94\u4E0D\u662F JSON \u5BF9\u8C61`, { retryable: true });
82
70
  }
83
- if (payload.success === false) throw ipqsError(response, payload);
71
+ if (payload.success === false) throw ipqsError(result.status, result.statusText, payload);
84
72
  return payload;
85
73
  }
86
74
  async function checkIpReputation(input, ctx) {
@@ -1,74 +1,48 @@
1
+ import {
2
+ createProviderHttpClient
3
+ } from "./chunk-WW2IMPQK.js";
4
+ import {
5
+ messageFrom
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
- TBError,
12
14
  external_exports
13
- } from "./chunk-YB2FLNWI.js";
14
- import "./chunk-MLKGABMK.js";
15
+ } from "./chunk-RVWZN3CI.js";
16
+ import "./chunk-U67V476Y.js";
15
17
 
16
18
  // ../plugins/src/jina_ai/api.ts
17
19
  var SERVICE = "jina_ai";
18
- var API_BASE = "https://api.jina.ai";
19
20
  var REQUEST_TIMEOUT_MS = 3e4;
20
- function record(value) {
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
- }
28
- function errorMessage(status, body, payload) {
29
- const top = record(payload);
30
- return text(top?.detail) ?? text(top?.message) ?? text(body) ?? `Jina AI request failed with ${status}`;
31
- }
21
+ var http = createProviderHttpClient({ baseUrl: "https://api.jina.ai/", service: SERVICE });
32
22
  async function request(ctx, path, body) {
33
- const apiKey = requireApiKey(ctx, SERVICE);
34
- const timeoutSignal = AbortSignal.timeout(REQUEST_TIMEOUT_MS);
35
- let response;
36
- try {
37
- response = await guardedFetch(`${API_BASE}${path}`, {
38
- method: "POST",
39
- headers: {
40
- "accept": "application/json",
41
- "authorization": `Bearer ${apiKey}`,
42
- "content-type": "application/json"
43
- },
44
- body: JSON.stringify(body),
45
- signal: timeoutSignal
46
- });
47
- } catch (error) {
48
- if (error instanceof TBError) throw error;
49
- if (timeoutSignal.aborted) throw upstreamError(504, `Jina AI ${REQUEST_TIMEOUT_MS / 1e3}s \u5185\u6CA1\u6709\u8FD4\u56DE`);
50
- const message = error instanceof Error ? error.message : "unknown network error";
51
- throw upstreamError(502, `Jina AI \u8BF7\u6C42\u5931\u8D25: ${message}`);
52
- }
53
- const raw = await response.text();
54
- let payload = null;
55
- if (raw !== "") {
56
- try {
57
- payload = JSON.parse(raw);
58
- } catch {
59
- if (response.ok) {
60
- throw new TBError("unavailable", "Jina AI \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94", { retryable: true });
61
- }
62
- }
63
- }
64
- if (!response.ok) throw upstreamError(response.status, errorMessage(response.status, raw, payload));
65
- return payload;
23
+ const { data } = await http.request({
24
+ path,
25
+ method: "POST",
26
+ headers: {
27
+ accept: "application/json",
28
+ authorization: `Bearer ${requireApiKey(ctx, SERVICE)}`
29
+ },
30
+ json: body,
31
+ timeoutMs: REQUEST_TIMEOUT_MS,
32
+ invalidJsonMessage: "Jina AI \u8FD4\u56DE\u4E86\u975E JSON \u54CD\u5E94",
33
+ mapError: ({ data: payload, status }) => upstreamError(
34
+ status,
35
+ messageFrom(payload, ["detail", "message"], `Jina AI request failed with ${status}`)
36
+ ),
37
+ mapTransportError: ({ kind, message }) => kind === "timeout" ? upstreamError(504, `Jina AI ${REQUEST_TIMEOUT_MS / 1e3}s \u5185\u6CA1\u6709\u8FD4\u56DE`) : upstreamError(502, `Jina AI \u8BF7\u6C42\u5931\u8D25: ${message ?? "unknown network error"}`)
38
+ });
39
+ return data ?? null;
66
40
  }
67
- async function createEmbeddings(input, ctx) {
68
- return request(ctx, "/v1/embeddings", input);
41
+ function createEmbeddings(input, ctx) {
42
+ return request(ctx, "v1/embeddings", input);
69
43
  }
70
- async function rerankDocuments(input, ctx) {
71
- return request(ctx, "/v1/rerank", input);
44
+ function rerankDocuments(input, ctx) {
45
+ return request(ctx, "v1/rerank", input);
72
46
  }
73
47
 
74
48
  // ../plugins/src/jina_ai/schema.ts