openclaw-multi-auto 1.6.2 → 1.6.5

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 (192) hide show
  1. package/dist/{audio-preflight-DoPfNXDz.js → audio-preflight-DpxQCpsA.js} +4 -4
  2. package/dist/{audio-transcription-runner-CzjuH3uL.js → audio-transcription-runner-28fcRNNi.js} +1 -1
  3. package/dist/build-info.json +3 -3
  4. package/dist/bundled/boot-md/handler.js +6 -6
  5. package/dist/bundled/session-memory/handler.js +6 -6
  6. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  7. package/dist/{chrome-DlhJHqj8.js → chrome-DwizpzOC.js} +8 -8
  8. package/dist/{deliver-CApVJA_l.js → deliver-D4o6VIur.js} +1 -1
  9. package/dist/{deliver-runtime-D1z-h5eg.js → deliver-runtime-P-G3bPjW.js} +3 -3
  10. package/dist/{deps-send-whatsapp.runtime-Dz_4fi2D.js → deps-send-whatsapp.runtime-CJkTHkah.js} +7 -7
  11. package/dist/{image-B3Mz7N5I.js → image-Bbn53mzj.js} +1 -1
  12. package/dist/{image-runtime-DWjhow2W.js → image-runtime-CVv2ra9J.js} +3 -3
  13. package/dist/llm-slug-generator.js +6 -6
  14. package/dist/{pi-embedded-bcjMe3wj.js → pi-embedded-BaGj07T0.js} +24 -24
  15. package/dist/{pi-embedded-helpers-D5yyGEvA.js → pi-embedded-helpers-wy0DZvx1.js} +3 -3
  16. package/dist/plugin-sdk/{accounts-DyFCXtHv.js → accounts-BslAlVYS.js} +2 -2
  17. package/dist/plugin-sdk/{accounts-BJAXxY46.js → accounts-C3m65--E.js} +2 -2
  18. package/dist/plugin-sdk/{accounts-C1j7HSL0.js → accounts-CNCCkdEF.js} +3 -3
  19. package/dist/plugin-sdk/{active-listener-B_sLJTXM.js → active-listener-CkPnMUkB.js} +2 -2
  20. package/dist/plugin-sdk/{api-key-rotation-8nyyt1kx.js → api-key-rotation-BXnNsojA.js} +2 -2
  21. package/dist/plugin-sdk/{audio-preflight-C_aSAPR1.js → audio-preflight-CtO4fFvp.js} +26 -26
  22. package/dist/plugin-sdk/{audio-transcription-runner-CB53F7_7.js → audio-transcription-runner-DnxvOS1-.js} +11 -11
  23. package/dist/plugin-sdk/{audit-membership-runtime-BXndI4LG.js → audit-membership-runtime-BpfoSk8M.js} +2 -2
  24. package/dist/plugin-sdk/{channel-activity-C5y8AgAV.js → channel-activity-WJYxcJ3S.js} +3 -3
  25. package/dist/plugin-sdk/{channel-web-DBTRO03V.js → channel-web-dO5k3ubM.js} +18 -18
  26. package/dist/plugin-sdk/{chrome-f00sZkDX.js → chrome-CjNTuJML.js} +6 -6
  27. package/dist/plugin-sdk/{commands-registry-BJ_NxG2F.js → commands-registry-CdYjoI0i.js} +4 -4
  28. package/dist/plugin-sdk/{common-Cf27Jwxu.js → common-oYc5vPFl.js} +2 -2
  29. package/dist/plugin-sdk/compat.js +50 -50
  30. package/dist/plugin-sdk/{config-CHQrpx-Q.js → config-B1z-UxQ3.js} +7 -7
  31. package/dist/plugin-sdk/{deliver-DNEuetST.js → deliver-D5_6T567.js} +10 -10
  32. package/dist/plugin-sdk/deliver-runtime-C5dgvvga.js +32 -0
  33. package/dist/plugin-sdk/deps-send-discord.runtime-Dg4N7PHJ.js +23 -0
  34. package/dist/plugin-sdk/deps-send-imessage.runtime-0OEwzMQm.js +22 -0
  35. package/dist/plugin-sdk/deps-send-signal.runtime-BM1jRt3G.js +21 -0
  36. package/dist/plugin-sdk/deps-send-slack.runtime-1E3BYRdF.js +19 -0
  37. package/dist/plugin-sdk/deps-send-telegram.runtime-DNCxIflA.js +24 -0
  38. package/dist/plugin-sdk/deps-send-whatsapp.runtime-OLwr-9c8.js +57 -0
  39. package/dist/plugin-sdk/{diagnostic-LYUUmjJ5.js → diagnostic-Bxxu0ig-.js} +2 -2
  40. package/dist/plugin-sdk/discord.js +6 -6
  41. package/dist/plugin-sdk/{errors-CtMWwS2Z.js → errors-B3cHyZZA.js} +1 -1
  42. package/dist/plugin-sdk/{fetch-guard-CxYB5Kg6.js → fetch-guard-Dcgod0tg.js} +2 -2
  43. package/dist/plugin-sdk/{fs-safe-DtfhxbrI.js → fs-safe-BaKqI3G4.js} +3 -3
  44. package/dist/plugin-sdk/{image-BwjYjRHx.js → image-B2mQW9Rb.js} +6 -6
  45. package/dist/plugin-sdk/{image-ops-BnZKcbd6.js → image-ops-Cbzr4U9l.js} +2 -2
  46. package/dist/plugin-sdk/image-runtime-BFm45j49.js +25 -0
  47. package/dist/plugin-sdk/{ir-Z4hX67TJ.js → ir-ZEmrTr4J.js} +7 -7
  48. package/dist/plugin-sdk/{local-roots-KhjQw04O.js → local-roots-CIPRxA-4.js} +4 -4
  49. package/dist/plugin-sdk/{logger-DHIIvMxj.js → logger-CvPFVOgT.js} +2 -2
  50. package/dist/plugin-sdk/{login-C31642Ld.js → login-CCTew9bt.js} +4 -4
  51. package/dist/plugin-sdk/{login-qr--y2SG_Ue.js → login-qr-BI3Vi_wJ.js} +5 -5
  52. package/dist/plugin-sdk/{manager-2UZBMCc7.js → manager-BEoYPn7R.js} +8 -8
  53. package/dist/plugin-sdk/manager-runtime-DxclHQ4U.js +15 -0
  54. package/dist/plugin-sdk/{outbound-Ba0QUI5h.js → outbound-ByOw1K6W.js} +5 -5
  55. package/dist/plugin-sdk/{outbound-attachment-B1Laso-8.js → outbound-attachment-BzVhxRRw.js} +2 -2
  56. package/dist/plugin-sdk/{path-alias-guards-C7Vm5DZ1.js → path-alias-guards-sWayacde.js} +1 -1
  57. package/dist/plugin-sdk/{paths-DopV9PQG.js → paths-Dpg3qxcl.js} +1 -1
  58. package/dist/plugin-sdk/{pi-embedded-helpers-DnA_OCzP.js → pi-embedded-helpers-DIxXkGJf.js} +16 -16
  59. package/dist/plugin-sdk/{pi-model-discovery-DdPqXk8f.js → pi-model-discovery-DM_2uFtj.js} +1 -1
  60. package/dist/plugin-sdk/pi-model-discovery-runtime-BuzvkvNR.js +8 -0
  61. package/dist/plugin-sdk/{pi-tools.before-tool-call.runtime-DxFHiLUE.js → pi-tools.before-tool-call.runtime-w1dqL_ty.js} +4 -4
  62. package/dist/plugin-sdk/{plugins-CbCt4osF.js → plugins-C4USiH29.js} +4 -4
  63. package/dist/plugin-sdk/{proxy-env-C63mMdas.js → proxy-env-ET-rp8eg.js} +1 -1
  64. package/dist/plugin-sdk/{proxy-fetch-Ch95c_Y2.js → proxy-fetch-uDXGKG3Z.js} +1 -1
  65. package/dist/plugin-sdk/{pw-ai-DpJk62D4.js → pw-ai-CyOt3RDA.js} +9 -9
  66. package/dist/plugin-sdk/{qmd-manager-Ca-iSfEE.js → qmd-manager-BySdoVR7.js} +7 -7
  67. package/dist/plugin-sdk/{query-expansion-B_Xe41Ab.js → query-expansion-C6uS-7lj.js} +4 -4
  68. package/dist/plugin-sdk/{redact-hp9TOulW.js → redact-Bvxt1T_Q.js} +1 -1
  69. package/dist/plugin-sdk/{reply-CovBlFea.js → reply-CTCSeQqW.js} +73 -73
  70. package/dist/plugin-sdk/{resolve-outbound-target-BbrHgyUk.js → resolve-outbound-target-Bw8YNANu.js} +2 -2
  71. package/dist/plugin-sdk/{run-with-concurrency-BR1DXa8T.js → run-with-concurrency-C_KCHwvf.js} +1 -1
  72. package/dist/plugin-sdk/runtime-whatsapp-login.runtime-BxgRDkhc.js +10 -0
  73. package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-elOqrkfg.js +19 -0
  74. package/dist/plugin-sdk/{send-BvAtLLPl.js → send-BZ6nYFZr.js} +5 -5
  75. package/dist/plugin-sdk/{send-BTztm3D2.js → send-C0w6xP2x.js} +6 -6
  76. package/dist/plugin-sdk/{send-CWJUuG0i.js → send-CFf-1V89.js} +8 -8
  77. package/dist/plugin-sdk/{send-EcglC4cG.js → send-CY-Qfwia.js} +7 -7
  78. package/dist/plugin-sdk/{send-BXpXBwM_.js → send-qPyNGSe4.js} +13 -13
  79. package/dist/plugin-sdk/{session-k256LJZT.js → session-COrvpvUQ.js} +3 -3
  80. package/dist/plugin-sdk/{skill-commands-DoRqLzxm.js → skill-commands-DZqhtmiv.js} +4 -4
  81. package/dist/plugin-sdk/{skills-QudILG6e.js → skills-Cw_vXEJb.js} +6 -6
  82. package/dist/plugin-sdk/slack.js +2 -2
  83. package/dist/plugin-sdk/slash-commands.runtime-D67JLweo.js +13 -0
  84. package/dist/plugin-sdk/slash-dispatch.runtime-DvcpvCJ0.js +52 -0
  85. package/dist/plugin-sdk/slash-skill-commands.runtime-BM1x3azR.js +16 -0
  86. package/dist/plugin-sdk/{store-BbDQw3g6.js → store-CMHj6IIw.js} +2 -2
  87. package/dist/plugin-sdk/subagent-registry-runtime-1lbDyRzz.js +52 -0
  88. package/dist/plugin-sdk/{tables-BhvloMKN.js → tables-CSqrHsKL.js} +1 -1
  89. package/dist/plugin-sdk/{thinking-URzkT-3p.js → thinking-DOnsR_A8.js} +7 -7
  90. package/dist/plugin-sdk/{tokens-DgNRBwIg.js → tokens-BDr0Z9o3.js} +1 -1
  91. package/dist/plugin-sdk/{tool-images-Gk_-0y2N.js → tool-images-eEfOVkzf.js} +2 -2
  92. package/dist/plugin-sdk/web-BLyT64pW.js +56 -0
  93. package/dist/plugin-sdk/{whatsapp-actions-RcZ6vp61.js → whatsapp-actions-xcleMoMv.js} +17 -17
  94. package/dist/plugin-sdk/whatsapp.js +50 -50
  95. package/dist/{pw-ai-CDQDCfUa.js → pw-ai-Cl1Lc7RC.js} +1 -1
  96. package/dist/{slash-dispatch.runtime-CWbpp23S.js → slash-dispatch.runtime-DoBAQBU5.js} +6 -6
  97. package/dist/{subagent-registry-runtime-DEVpAaAP.js → subagent-registry-runtime-ppWS3tVu.js} +6 -6
  98. package/dist/{web-NWKn8ABz.js → web-CzWRVmFt.js} +6 -6
  99. package/package.json +1 -1
  100. package/scripts/create-instance.sh +11 -13
  101. package/dist/plugin-sdk/accounts-CJWOBzwB.js +0 -35
  102. package/dist/plugin-sdk/accounts-DP1-L-QS.js +0 -288
  103. package/dist/plugin-sdk/accounts-DZhWlEg3.js +0 -46
  104. package/dist/plugin-sdk/active-listener-CftX5jLD.js +0 -50
  105. package/dist/plugin-sdk/api-key-rotation-BRE4X2tf.js +0 -181
  106. package/dist/plugin-sdk/audio-preflight-DGEUDxxR.js +0 -69
  107. package/dist/plugin-sdk/audio-transcription-runner-DkoPNPYt.js +0 -2176
  108. package/dist/plugin-sdk/audit-membership-runtime-DSBHHw7o.js +0 -58
  109. package/dist/plugin-sdk/channel-activity-F3d0yUwy.js +0 -94
  110. package/dist/plugin-sdk/channel-web-QF7EpjeP.js +0 -2256
  111. package/dist/plugin-sdk/chrome-BXoCyCkY.js +0 -2415
  112. package/dist/plugin-sdk/commands-registry-t7cXBTfN.js +0 -1125
  113. package/dist/plugin-sdk/config-BkEnz2Po.js +0 -17913
  114. package/dist/plugin-sdk/deliver-B6AG_l67.js +0 -1694
  115. package/dist/plugin-sdk/deliver-runtime-BFdqklJM.js +0 -32
  116. package/dist/plugin-sdk/deliver-runtime-D585kJZc.js +0 -32
  117. package/dist/plugin-sdk/deps-send-discord.runtime-DuqpYwU0.js +0 -23
  118. package/dist/plugin-sdk/deps-send-discord.runtime-a_OKY2js.js +0 -23
  119. package/dist/plugin-sdk/deps-send-imessage.runtime-Baxy9TD4.js +0 -22
  120. package/dist/plugin-sdk/deps-send-imessage.runtime-CZ2rS8Lb.js +0 -22
  121. package/dist/plugin-sdk/deps-send-signal.runtime-BdqiWhIh.js +0 -21
  122. package/dist/plugin-sdk/deps-send-signal.runtime-BwXoCrFl.js +0 -21
  123. package/dist/plugin-sdk/deps-send-slack.runtime-04s36qiC.js +0 -19
  124. package/dist/plugin-sdk/deps-send-slack.runtime-CLmKjgso.js +0 -19
  125. package/dist/plugin-sdk/deps-send-telegram.runtime-BKfdBKnZ.js +0 -24
  126. package/dist/plugin-sdk/deps-send-telegram.runtime-LE5tkPvr.js +0 -24
  127. package/dist/plugin-sdk/deps-send-whatsapp.runtime-BOTwkbx_.js +0 -57
  128. package/dist/plugin-sdk/deps-send-whatsapp.runtime-Bz57lobC.js +0 -57
  129. package/dist/plugin-sdk/diagnostic-CsP-lEkI.js +0 -319
  130. package/dist/plugin-sdk/errors-DaiAM-yU.js +0 -54
  131. package/dist/plugin-sdk/fetch-guard-DETCcJzQ.js +0 -156
  132. package/dist/plugin-sdk/fs-safe-B8y811FR.js +0 -352
  133. package/dist/plugin-sdk/image-DjTEkYZE.js +0 -2310
  134. package/dist/plugin-sdk/image-ops-BSiMpAw4.js +0 -584
  135. package/dist/plugin-sdk/image-runtime-6xPp8m5a.js +0 -25
  136. package/dist/plugin-sdk/image-runtime-B8twoubs.js +0 -25
  137. package/dist/plugin-sdk/ir-DQ7_HbvK.js +0 -1296
  138. package/dist/plugin-sdk/local-roots-BUP4YBmR.js +0 -186
  139. package/dist/plugin-sdk/logger-CZY9KIoY.js +0 -1163
  140. package/dist/plugin-sdk/login-BxEKLlCo.js +0 -57
  141. package/dist/plugin-sdk/login-qr-BQIpMPr9.js +0 -320
  142. package/dist/plugin-sdk/manager-I6KbPihW.js +0 -3917
  143. package/dist/plugin-sdk/manager-runtime-CFfYYWIQ.js +0 -15
  144. package/dist/plugin-sdk/manager-runtime-CMeLwose.js +0 -15
  145. package/dist/plugin-sdk/outbound-NS6UHnB6.js +0 -212
  146. package/dist/plugin-sdk/outbound-attachment-Dy6fyf6H.js +0 -19
  147. package/dist/plugin-sdk/path-alias-guards-DBjLbIX_.js +0 -43
  148. package/dist/plugin-sdk/paths-vTM3Lh3X.js +0 -166
  149. package/dist/plugin-sdk/pi-embedded-helpers-1R1gu7eX.js +0 -9627
  150. package/dist/plugin-sdk/pi-model-discovery-runtime-D8CJhtJY.js +0 -8
  151. package/dist/plugin-sdk/pi-model-discovery-runtime-Do9o-dUd.js +0 -8
  152. package/dist/plugin-sdk/pi-model-discovery-v-XPUOOf.js +0 -134
  153. package/dist/plugin-sdk/pi-tools.before-tool-call.runtime-D4sFsIks.js +0 -354
  154. package/dist/plugin-sdk/plugins-DeBZB9l_.js +0 -864
  155. package/dist/plugin-sdk/proxy-fetch-ChxOhWF4.js +0 -38
  156. package/dist/plugin-sdk/pw-ai-DEOmCSSC.js +0 -1938
  157. package/dist/plugin-sdk/qmd-manager-HyYKoEch.js +0 -1448
  158. package/dist/plugin-sdk/query-expansion-CeyKUeDW.js +0 -1011
  159. package/dist/plugin-sdk/redact-DjVX-1N3.js +0 -319
  160. package/dist/plugin-sdk/reply-DAo_Jt8K.js +0 -97916
  161. package/dist/plugin-sdk/resolve-outbound-target-B42qgQS9.js +0 -40
  162. package/dist/plugin-sdk/run-with-concurrency-Bt_ks0Qa.js +0 -1994
  163. package/dist/plugin-sdk/runtime-whatsapp-login.runtime-B6W989eF.js +0 -10
  164. package/dist/plugin-sdk/runtime-whatsapp-login.runtime-SkO91TZH.js +0 -10
  165. package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-B0VWK5hm.js +0 -19
  166. package/dist/plugin-sdk/runtime-whatsapp-outbound.runtime-c_GDFy37.js +0 -19
  167. package/dist/plugin-sdk/send-CQpMudwO.js +0 -2587
  168. package/dist/plugin-sdk/send-DQHLzVyO.js +0 -414
  169. package/dist/plugin-sdk/send-DTB24bEF.js +0 -3135
  170. package/dist/plugin-sdk/send-DfHadjZ_.js +0 -503
  171. package/dist/plugin-sdk/send-XXlW2iny.js +0 -540
  172. package/dist/plugin-sdk/session-6TF6MyaC.js +0 -169
  173. package/dist/plugin-sdk/skill-commands-CkGeFUMl.js +0 -342
  174. package/dist/plugin-sdk/skills-CBkHBYPq.js +0 -1428
  175. package/dist/plugin-sdk/slash-commands.runtime-CxliuGaP.js +0 -13
  176. package/dist/plugin-sdk/slash-commands.runtime-DS6vCNSL.js +0 -13
  177. package/dist/plugin-sdk/slash-dispatch.runtime-BXrxb2wd.js +0 -52
  178. package/dist/plugin-sdk/slash-dispatch.runtime-DFaeYlJQ.js +0 -52
  179. package/dist/plugin-sdk/slash-skill-commands.runtime-0M0OLCxq.js +0 -16
  180. package/dist/plugin-sdk/slash-skill-commands.runtime-Bd6qQ2oT.js +0 -16
  181. package/dist/plugin-sdk/ssrf-cFtplYtS.js +0 -202
  182. package/dist/plugin-sdk/store-5nyxY3WU.js +0 -81
  183. package/dist/plugin-sdk/subagent-registry-runtime-1uwQbuXj.js +0 -52
  184. package/dist/plugin-sdk/subagent-registry-runtime-DCtmDwna.js +0 -52
  185. package/dist/plugin-sdk/tables-C47P4GTN.js +0 -55
  186. package/dist/plugin-sdk/target-errors-Blia4S69.js +0 -195
  187. package/dist/plugin-sdk/thinking-Bo2eosVa.js +0 -1206
  188. package/dist/plugin-sdk/tokens-B1PW5Ayy.js +0 -52
  189. package/dist/plugin-sdk/tool-images-xpqbP6RR.js +0 -274
  190. package/dist/plugin-sdk/web-B74yhL2N.js +0 -56
  191. package/dist/plugin-sdk/web-CVxZbXyH.js +0 -56
  192. package/dist/plugin-sdk/whatsapp-actions-Bw0H9g-n.js +0 -80
@@ -97,13 +97,13 @@ fi
97
97
  # --- 7. 核心代码同步 (物理对齐) ---
98
98
  echo -e "${BLUE}🔄 分发代码产物...${NC}"
99
99
  rm -rf "$DIST_DIR" && mkdir -p "$DIST_DIR"
100
- if [ -d "${SOURCE_CODE}/dist" ]; then
101
- cp -r "${SOURCE_CODE}/dist/." "${DIST_DIR}/"
100
+ if [ -d "${SOURCE_CODE}" ]; then
101
+ cp -r "${SOURCE_CODE}/." "${DIST_DIR}/"
102
102
  echo "cp exit code: $?"
103
103
 
104
- if [ -f "${DIST_DIR}/index.js" ]; then
105
- for chunk in $(grep -oE "utils-[A-Za-z0-9]+\.js" "${DIST_DIR}/index.js" 2>/dev/null | sort -u); do
106
- if [ ! -f "${DIST_DIR}/${chunk}" ]; then
104
+ if [ -f "${DIST_DIR}/dist/index.js" ]; then
105
+ for chunk in $(grep -oE "utils-[A-Za-z0-9]+\.js" "${DIST_DIR}/dist/index.js" 2>/dev/null | sort -u); do
106
+ if [ ! -f "${DIST_DIR}/dist/${chunk}" ]; then
107
107
  echo -e "${RED}❌ 致命错误: dist 缺失关键模块 ${chunk}${NC}"
108
108
  echo -e "${YELLOW}请在源码端执行: rm -rf dist && pnpm build && npm publish${NC}"
109
109
  exit 1
@@ -111,22 +111,20 @@ if [ -d "${SOURCE_CODE}/dist" ]; then
111
111
  done
112
112
  fi
113
113
  else
114
- echo -e "${RED}❌ 错误: 母本 dist 不存在${NC}"
114
+ echo -e "${RED}❌ 错误: 母本源码目录 ${SOURCE_CODE} 不存在${NC}"
115
115
  exit 1
116
116
  fi
117
117
 
118
118
  cp "${SOURCE_CODE}/package.json" "${INSTANCE_DIR}/package.json"
119
119
  [ -f "${SOURCE_CODE}/pnpm-lock.yaml" ] && cp "${SOURCE_CODE}/pnpm-lock.yaml" "${INSTANCE_DIR}/pnpm-lock.yaml"
120
120
 
121
- # 复制 extensions 目录到实例的 .openclaw 目录(包含 page-action-cache, feishu 等)
122
- # 多实例架构:每个实例完全隔离,扩展在 ~/.openclaws/<实例>/.openclaw/extensions
123
- INSTANCE_OPENCLAW_DIR="${INSTANCE_DIR}/.openclaw"
121
+ # 复制 extensions 目录到实例目录(包含 page-action-cache, feishu 等)
122
+ # 多实例架构:每个实例完全隔离,运行自己的扩展
124
123
  if [ -d "${SOURCE_CODE}/extensions" ]; then
125
- echo -e "${YELLOW}📁 复制 extensions 目录到实例 .openclaw 目录...${NC}"
126
- mkdir -p "$INSTANCE_OPENCLAW_DIR"
127
- cp -r "${SOURCE_CODE}/extensions/" "${INSTANCE_OPENCLAW_DIR}/"
124
+ echo -e "${YELLOW}📁 复制 extensions 目录到实例目录...${NC}"
125
+ cp -r "${SOURCE_CODE}/extensions/" "${INSTANCE_DIR}/extensions"
128
126
  echo -e "${GREEN}✅ extensions 目录复制完成${NC}"
129
- echo -e "${BLUE}📂 实例扩展目录: ${INSTANCE_OPENCLAW_DIR}${NC}"
127
+ echo -e "${BLUE}📂 实例扩展目录: ${INSTANCE_DIR}/extensions${NC}"
130
128
  fi
131
129
 
132
130
  # 复制 control-ui(如果存在)
@@ -1,35 +0,0 @@
1
- import { ot as normalizeAccountId } from "./run-with-concurrency-Bt_ks0Qa.js";
2
- import { v as resolveAccountEntry, y as createAccountListHelpers } from "./accounts-DP1-L-QS.js";
3
-
4
- //#region src/imessage/accounts.ts
5
- const { listAccountIds, resolveDefaultAccountId } = createAccountListHelpers("imessage");
6
- const listIMessageAccountIds = listAccountIds;
7
- const resolveDefaultIMessageAccountId = resolveDefaultAccountId;
8
- function resolveAccountConfig(cfg, accountId) {
9
- return resolveAccountEntry(cfg.channels?.imessage?.accounts, accountId);
10
- }
11
- function mergeIMessageAccountConfig(cfg, accountId) {
12
- const { accounts: _ignored, ...base } = cfg.channels?.imessage ?? {};
13
- const account = resolveAccountConfig(cfg, accountId) ?? {};
14
- return {
15
- ...base,
16
- ...account
17
- };
18
- }
19
- function resolveIMessageAccount(params) {
20
- const accountId = normalizeAccountId(params.accountId);
21
- const baseEnabled = params.cfg.channels?.imessage?.enabled !== false;
22
- const merged = mergeIMessageAccountConfig(params.cfg, accountId);
23
- const accountEnabled = merged.enabled !== false;
24
- const configured = Boolean(merged.cliPath?.trim() || merged.dbPath?.trim() || merged.service || merged.region?.trim() || merged.allowFrom && merged.allowFrom.length > 0 || merged.groupAllowFrom && merged.groupAllowFrom.length > 0 || merged.dmPolicy || merged.groupPolicy || typeof merged.includeAttachments === "boolean" || merged.attachmentRoots && merged.attachmentRoots.length > 0 || merged.remoteAttachmentRoots && merged.remoteAttachmentRoots.length > 0 || typeof merged.mediaMaxMb === "number" || typeof merged.textChunkLimit === "number" || merged.groups && Object.keys(merged.groups).length > 0);
25
- return {
26
- accountId,
27
- enabled: baseEnabled && accountEnabled,
28
- name: merged.name?.trim() || void 0,
29
- config: merged,
30
- configured
31
- };
32
- }
33
-
34
- //#endregion
35
- export { resolveDefaultIMessageAccountId as n, resolveIMessageAccount as r, listIMessageAccountIds as t };
@@ -1,288 +0,0 @@
1
- import { at as DEFAULT_ACCOUNT_ID, ot as normalizeAccountId, st as normalizeOptionalAccountId } from "./run-with-concurrency-Bt_ks0Qa.js";
2
- import { o as resolveOAuthDir } from "./paths-MKyEVmEb.js";
3
- import { Pr as formatCliCommand } from "./config-BkEnz2Po.js";
4
- import { B as success, E as resolveUserPath, G as getChildLogger, I as info, c as defaultRuntime, x as jidToE164 } from "./logger-CZY9KIoY.js";
5
- import fs from "node:fs";
6
- import path from "node:path";
7
- import fs$1 from "node:fs/promises";
8
-
9
- //#region src/channels/plugins/account-helpers.ts
10
- function createAccountListHelpers(channelKey) {
11
- function resolveConfiguredDefaultAccountId(cfg) {
12
- const channel = cfg.channels?.[channelKey];
13
- const preferred = normalizeOptionalAccountId(typeof channel?.defaultAccount === "string" ? channel.defaultAccount : void 0);
14
- if (!preferred) return;
15
- if (listAccountIds(cfg).some((id) => normalizeAccountId(id) === preferred)) return preferred;
16
- }
17
- function listConfiguredAccountIds(cfg) {
18
- const accounts = (cfg.channels?.[channelKey])?.accounts;
19
- if (!accounts || typeof accounts !== "object") return [];
20
- return Object.keys(accounts).filter(Boolean);
21
- }
22
- function listAccountIds(cfg) {
23
- const ids = listConfiguredAccountIds(cfg);
24
- if (ids.length === 0) return [DEFAULT_ACCOUNT_ID];
25
- return ids.toSorted((a, b) => a.localeCompare(b));
26
- }
27
- function resolveDefaultAccountId(cfg) {
28
- const preferred = resolveConfiguredDefaultAccountId(cfg);
29
- if (preferred) return preferred;
30
- const ids = listAccountIds(cfg);
31
- if (ids.includes(DEFAULT_ACCOUNT_ID)) return DEFAULT_ACCOUNT_ID;
32
- return ids[0] ?? DEFAULT_ACCOUNT_ID;
33
- }
34
- return {
35
- listConfiguredAccountIds,
36
- listAccountIds,
37
- resolveDefaultAccountId
38
- };
39
- }
40
-
41
- //#endregion
42
- //#region src/routing/account-lookup.ts
43
- function resolveAccountEntry(accounts, accountId) {
44
- if (!accounts || typeof accounts !== "object") return;
45
- if (Object.hasOwn(accounts, accountId)) return accounts[accountId];
46
- const normalized = accountId.toLowerCase();
47
- const matchKey = Object.keys(accounts).find((key) => key.toLowerCase() === normalized);
48
- return matchKey ? accounts[matchKey] : void 0;
49
- }
50
-
51
- //#endregion
52
- //#region src/web/auth-store.ts
53
- function resolveDefaultWebAuthDir() {
54
- return path.join(resolveOAuthDir(), "whatsapp", DEFAULT_ACCOUNT_ID);
55
- }
56
- const WA_WEB_AUTH_DIR = resolveDefaultWebAuthDir();
57
- function resolveWebCredsPath(authDir) {
58
- return path.join(authDir, "creds.json");
59
- }
60
- function resolveWebCredsBackupPath(authDir) {
61
- return path.join(authDir, "creds.json.bak");
62
- }
63
- function hasWebCredsSync(authDir) {
64
- try {
65
- const stats = fs.statSync(resolveWebCredsPath(authDir));
66
- return stats.isFile() && stats.size > 1;
67
- } catch {
68
- return false;
69
- }
70
- }
71
- function readCredsJsonRaw(filePath) {
72
- try {
73
- if (!fs.existsSync(filePath)) return null;
74
- const stats = fs.statSync(filePath);
75
- if (!stats.isFile() || stats.size <= 1) return null;
76
- return fs.readFileSync(filePath, "utf-8");
77
- } catch {
78
- return null;
79
- }
80
- }
81
- function maybeRestoreCredsFromBackup(authDir) {
82
- const logger = getChildLogger({ module: "web-session" });
83
- try {
84
- const credsPath = resolveWebCredsPath(authDir);
85
- const backupPath = resolveWebCredsBackupPath(authDir);
86
- const raw = readCredsJsonRaw(credsPath);
87
- if (raw) {
88
- JSON.parse(raw);
89
- return;
90
- }
91
- const backupRaw = readCredsJsonRaw(backupPath);
92
- if (!backupRaw) return;
93
- JSON.parse(backupRaw);
94
- fs.copyFileSync(backupPath, credsPath);
95
- try {
96
- fs.chmodSync(credsPath, 384);
97
- } catch {}
98
- logger.warn({ credsPath }, "restored corrupted WhatsApp creds.json from backup");
99
- } catch {}
100
- }
101
- async function webAuthExists(authDir = resolveDefaultWebAuthDir()) {
102
- const resolvedAuthDir = resolveUserPath(authDir);
103
- maybeRestoreCredsFromBackup(resolvedAuthDir);
104
- const credsPath = resolveWebCredsPath(resolvedAuthDir);
105
- try {
106
- await fs$1.access(resolvedAuthDir);
107
- } catch {
108
- return false;
109
- }
110
- try {
111
- const stats = await fs$1.stat(credsPath);
112
- if (!stats.isFile() || stats.size <= 1) return false;
113
- const raw = await fs$1.readFile(credsPath, "utf-8");
114
- JSON.parse(raw);
115
- return true;
116
- } catch {
117
- return false;
118
- }
119
- }
120
- async function clearLegacyBaileysAuthState(authDir) {
121
- const entries = await fs$1.readdir(authDir, { withFileTypes: true });
122
- const shouldDelete = (name) => {
123
- if (name === "oauth.json") return false;
124
- if (name === "creds.json" || name === "creds.json.bak") return true;
125
- if (!name.endsWith(".json")) return false;
126
- return /^(app-state-sync|session|sender-key|pre-key)-/.test(name);
127
- };
128
- await Promise.all(entries.map(async (entry) => {
129
- if (!entry.isFile()) return;
130
- if (!shouldDelete(entry.name)) return;
131
- await fs$1.rm(path.join(authDir, entry.name), { force: true });
132
- }));
133
- }
134
- async function logoutWeb(params) {
135
- const runtime = params.runtime ?? defaultRuntime;
136
- const resolvedAuthDir = resolveUserPath(params.authDir ?? resolveDefaultWebAuthDir());
137
- if (!await webAuthExists(resolvedAuthDir)) {
138
- runtime.log(info("No WhatsApp Web session found; nothing to delete."));
139
- return false;
140
- }
141
- if (params.isLegacyAuthDir) await clearLegacyBaileysAuthState(resolvedAuthDir);
142
- else await fs$1.rm(resolvedAuthDir, {
143
- recursive: true,
144
- force: true
145
- });
146
- runtime.log(success("Cleared WhatsApp Web credentials."));
147
- return true;
148
- }
149
- function readWebSelfId(authDir = resolveDefaultWebAuthDir()) {
150
- try {
151
- const credsPath = resolveWebCredsPath(resolveUserPath(authDir));
152
- if (!fs.existsSync(credsPath)) return {
153
- e164: null,
154
- jid: null
155
- };
156
- const raw = fs.readFileSync(credsPath, "utf-8");
157
- const jid = JSON.parse(raw)?.me?.id ?? null;
158
- return {
159
- e164: jid ? jidToE164(jid, { authDir }) : null,
160
- jid
161
- };
162
- } catch {
163
- return {
164
- e164: null,
165
- jid: null
166
- };
167
- }
168
- }
169
- /**
170
- * Return the age (in milliseconds) of the cached WhatsApp web auth state, or null when missing.
171
- * Helpful for heartbeats/observability to spot stale credentials.
172
- */
173
- function getWebAuthAgeMs(authDir = resolveDefaultWebAuthDir()) {
174
- try {
175
- const stats = fs.statSync(resolveWebCredsPath(resolveUserPath(authDir)));
176
- return Date.now() - stats.mtimeMs;
177
- } catch {
178
- return null;
179
- }
180
- }
181
- function logWebSelfId(authDir = resolveDefaultWebAuthDir(), runtime = defaultRuntime, includeChannelPrefix = false) {
182
- const { e164, jid } = readWebSelfId(authDir);
183
- const details = e164 || jid ? `${e164 ?? "unknown"}${jid ? ` (jid ${jid})` : ""}` : "unknown";
184
- const prefix = includeChannelPrefix ? "Web Channel: " : "";
185
- runtime.log(info(`${prefix}${details}`));
186
- }
187
- async function pickWebChannel(pref, authDir = resolveDefaultWebAuthDir()) {
188
- const choice = pref === "auto" ? "web" : pref;
189
- if (!await webAuthExists(authDir)) throw new Error(`No WhatsApp Web session found. Run \`${formatCliCommand("openclaw channels login --channel whatsapp --verbose")}\` to link.`);
190
- return choice;
191
- }
192
-
193
- //#endregion
194
- //#region src/web/accounts.ts
195
- const { listConfiguredAccountIds, listAccountIds, resolveDefaultAccountId } = createAccountListHelpers("whatsapp");
196
- const listWhatsAppAccountIds = listAccountIds;
197
- const resolveDefaultWhatsAppAccountId = resolveDefaultAccountId;
198
- function listWhatsAppAuthDirs(cfg) {
199
- const oauthDir = resolveOAuthDir();
200
- const whatsappDir = path.join(oauthDir, "whatsapp");
201
- const authDirs = new Set([oauthDir, path.join(whatsappDir, DEFAULT_ACCOUNT_ID)]);
202
- const accountIds = listConfiguredAccountIds(cfg);
203
- for (const accountId of accountIds) authDirs.add(resolveWhatsAppAuthDir({
204
- cfg,
205
- accountId
206
- }).authDir);
207
- try {
208
- const entries = fs.readdirSync(whatsappDir, { withFileTypes: true });
209
- for (const entry of entries) {
210
- if (!entry.isDirectory()) continue;
211
- authDirs.add(path.join(whatsappDir, entry.name));
212
- }
213
- } catch {}
214
- return Array.from(authDirs);
215
- }
216
- function hasAnyWhatsAppAuth(cfg) {
217
- return listWhatsAppAuthDirs(cfg).some((authDir) => hasWebCredsSync(authDir));
218
- }
219
- function resolveAccountConfig(cfg, accountId) {
220
- return resolveAccountEntry(cfg.channels?.whatsapp?.accounts, accountId);
221
- }
222
- function resolveDefaultAuthDir(accountId) {
223
- return path.join(resolveOAuthDir(), "whatsapp", normalizeAccountId(accountId));
224
- }
225
- function resolveLegacyAuthDir() {
226
- return resolveOAuthDir();
227
- }
228
- function legacyAuthExists(authDir) {
229
- try {
230
- return fs.existsSync(path.join(authDir, "creds.json"));
231
- } catch {
232
- return false;
233
- }
234
- }
235
- function resolveWhatsAppAuthDir(params) {
236
- const accountId = params.accountId.trim() || DEFAULT_ACCOUNT_ID;
237
- const configured = resolveAccountConfig(params.cfg, accountId)?.authDir?.trim();
238
- if (configured) return {
239
- authDir: resolveUserPath(configured),
240
- isLegacy: false
241
- };
242
- const defaultDir = resolveDefaultAuthDir(accountId);
243
- if (accountId === DEFAULT_ACCOUNT_ID) {
244
- const legacyDir = resolveLegacyAuthDir();
245
- if (legacyAuthExists(legacyDir) && !legacyAuthExists(defaultDir)) return {
246
- authDir: legacyDir,
247
- isLegacy: true
248
- };
249
- }
250
- return {
251
- authDir: defaultDir,
252
- isLegacy: false
253
- };
254
- }
255
- function resolveWhatsAppAccount(params) {
256
- const rootCfg = params.cfg.channels?.whatsapp;
257
- const accountId = params.accountId?.trim() || resolveDefaultWhatsAppAccountId(params.cfg);
258
- const accountCfg = resolveAccountConfig(params.cfg, accountId);
259
- const enabled = accountCfg?.enabled !== false;
260
- const { authDir, isLegacy } = resolveWhatsAppAuthDir({
261
- cfg: params.cfg,
262
- accountId
263
- });
264
- return {
265
- accountId,
266
- name: accountCfg?.name?.trim() || void 0,
267
- enabled,
268
- sendReadReceipts: accountCfg?.sendReadReceipts ?? rootCfg?.sendReadReceipts ?? true,
269
- messagePrefix: accountCfg?.messagePrefix ?? rootCfg?.messagePrefix ?? params.cfg.messages?.messagePrefix,
270
- authDir,
271
- isLegacyAuthDir: isLegacy,
272
- selfChatMode: accountCfg?.selfChatMode ?? rootCfg?.selfChatMode,
273
- dmPolicy: accountCfg?.dmPolicy ?? rootCfg?.dmPolicy,
274
- allowFrom: accountCfg?.allowFrom ?? rootCfg?.allowFrom,
275
- groupAllowFrom: accountCfg?.groupAllowFrom ?? rootCfg?.groupAllowFrom,
276
- groupPolicy: accountCfg?.groupPolicy ?? rootCfg?.groupPolicy,
277
- textChunkLimit: accountCfg?.textChunkLimit ?? rootCfg?.textChunkLimit,
278
- chunkMode: accountCfg?.chunkMode ?? rootCfg?.chunkMode,
279
- mediaMaxMb: accountCfg?.mediaMaxMb ?? rootCfg?.mediaMaxMb,
280
- blockStreaming: accountCfg?.blockStreaming ?? rootCfg?.blockStreaming,
281
- ackReaction: accountCfg?.ackReaction ?? rootCfg?.ackReaction,
282
- groups: accountCfg?.groups ?? rootCfg?.groups,
283
- debounceMs: accountCfg?.debounceMs ?? rootCfg?.debounceMs
284
- };
285
- }
286
-
287
- //#endregion
288
- export { webAuthExists as _, resolveWhatsAppAuthDir as a, logWebSelfId as c, pickWebChannel as d, readCredsJsonRaw as f, resolveWebCredsPath as g, resolveWebCredsBackupPath as h, resolveWhatsAppAccount as i, logoutWeb as l, resolveDefaultWebAuthDir as m, listWhatsAppAccountIds as n, WA_WEB_AUTH_DIR as o, readWebSelfId as p, resolveDefaultWhatsAppAccountId as r, getWebAuthAgeMs as s, hasAnyWhatsAppAuth as t, maybeRestoreCredsFromBackup as u, resolveAccountEntry as v, createAccountListHelpers as y };
@@ -1,46 +0,0 @@
1
- import { ot as normalizeAccountId } from "./run-with-concurrency-Bt_ks0Qa.js";
2
- import { v as resolveAccountEntry, y as createAccountListHelpers } from "./accounts-DP1-L-QS.js";
3
-
4
- //#region src/signal/accounts.ts
5
- const { listAccountIds, resolveDefaultAccountId } = createAccountListHelpers("signal");
6
- const listSignalAccountIds = listAccountIds;
7
- const resolveDefaultSignalAccountId = resolveDefaultAccountId;
8
- function resolveAccountConfig(cfg, accountId) {
9
- return resolveAccountEntry(cfg.channels?.signal?.accounts, accountId);
10
- }
11
- function mergeSignalAccountConfig(cfg, accountId) {
12
- const { accounts: _ignored, ...base } = cfg.channels?.signal ?? {};
13
- const account = resolveAccountConfig(cfg, accountId) ?? {};
14
- return {
15
- ...base,
16
- ...account
17
- };
18
- }
19
- function resolveSignalAccount(params) {
20
- const accountId = normalizeAccountId(params.accountId);
21
- const baseEnabled = params.cfg.channels?.signal?.enabled !== false;
22
- const merged = mergeSignalAccountConfig(params.cfg, accountId);
23
- const accountEnabled = merged.enabled !== false;
24
- const enabled = baseEnabled && accountEnabled;
25
- const host = merged.httpHost?.trim() || "127.0.0.1";
26
- const port = merged.httpPort ?? 8080;
27
- const baseUrl = merged.httpUrl?.trim() || `http://${host}:${port}`;
28
- const configured = Boolean(merged.account?.trim() || merged.httpUrl?.trim() || merged.cliPath?.trim() || merged.httpHost?.trim() || typeof merged.httpPort === "number" || typeof merged.autoStart === "boolean");
29
- return {
30
- accountId,
31
- enabled,
32
- name: merged.name?.trim() || void 0,
33
- baseUrl,
34
- configured,
35
- config: merged
36
- };
37
- }
38
- function listEnabledSignalAccounts(cfg) {
39
- return listSignalAccountIds(cfg).map((accountId) => resolveSignalAccount({
40
- cfg,
41
- accountId
42
- })).filter((account) => account.enabled);
43
- }
44
-
45
- //#endregion
46
- export { resolveSignalAccount as i, listSignalAccountIds as n, resolveDefaultSignalAccountId as r, listEnabledSignalAccounts as t };
@@ -1,50 +0,0 @@
1
- import { at as DEFAULT_ACCOUNT_ID } from "./run-with-concurrency-BR1DXa8T.js";
2
- import { Tr as formatCliCommand } from "./config-CHQrpx-Q.js";
3
- import crypto from "node:crypto";
4
-
5
- //#region src/logging/redact-identifier.ts
6
- function sha256HexPrefix(value, len = 12) {
7
- const safeLen = Number.isFinite(len) ? Math.max(1, Math.floor(len)) : 12;
8
- return crypto.createHash("sha256").update(value).digest("hex").slice(0, safeLen);
9
- }
10
- function redactIdentifier(value, opts) {
11
- const trimmed = value?.trim();
12
- if (!trimmed) return "-";
13
- return `sha256:${sha256HexPrefix(trimmed, opts?.len ?? 12)}`;
14
- }
15
-
16
- //#endregion
17
- //#region src/web/active-listener.ts
18
- const listeners = /* @__PURE__ */ new Map();
19
- function resolveWebAccountId(accountId) {
20
- return (accountId ?? "").trim() || DEFAULT_ACCOUNT_ID;
21
- }
22
- function requireActiveWebListener(accountId) {
23
- const id = resolveWebAccountId(accountId);
24
- const listener = listeners.get(id) ?? null;
25
- if (!listener) throw new Error(`No active WhatsApp Web listener (account: ${id}). Start the gateway, then link WhatsApp with: ${formatCliCommand(`openclaw channels login --channel whatsapp --account ${id}`)}.`);
26
- return {
27
- accountId: id,
28
- listener
29
- };
30
- }
31
- function setActiveWebListener(accountIdOrListener, maybeListener) {
32
- const { accountId, listener } = typeof accountIdOrListener === "string" ? {
33
- accountId: accountIdOrListener,
34
- listener: maybeListener ?? null
35
- } : {
36
- accountId: DEFAULT_ACCOUNT_ID,
37
- listener: accountIdOrListener ?? null
38
- };
39
- const id = resolveWebAccountId(accountId);
40
- if (!listener) listeners.delete(id);
41
- else listeners.set(id, listener);
42
- if (id === DEFAULT_ACCOUNT_ID) {}
43
- }
44
- function getActiveWebListener(accountId) {
45
- const id = resolveWebAccountId(accountId);
46
- return listeners.get(id) ?? null;
47
- }
48
-
49
- //#endregion
50
- export { redactIdentifier as i, requireActiveWebListener as n, setActiveWebListener as r, getActiveWebListener as t };
@@ -1,181 +0,0 @@
1
- import { jn as normalizeProviderId } from "./config-BkEnz2Po.js";
2
- import { r as formatErrorMessage } from "./errors-DaiAM-yU.js";
3
-
4
- //#region src/infra/gemini-auth.ts
5
- /**
6
- * Shared Gemini authentication utilities.
7
- *
8
- * Supports both traditional API keys and OAuth JSON format.
9
- */
10
- /**
11
- * Parse Gemini API key and return appropriate auth headers.
12
- *
13
- * OAuth format: `{"token": "...", "projectId": "..."}`
14
- *
15
- * @param apiKey - Either a traditional API key string or OAuth JSON
16
- * @returns Headers object with appropriate authentication
17
- */
18
- function parseGeminiAuth(apiKey) {
19
- if (apiKey.startsWith("{")) try {
20
- const parsed = JSON.parse(apiKey);
21
- if (typeof parsed.token === "string" && parsed.token) return { headers: {
22
- Authorization: `Bearer ${parsed.token}`,
23
- "Content-Type": "application/json"
24
- } };
25
- } catch {}
26
- return { headers: {
27
- "x-goog-api-key": apiKey,
28
- "Content-Type": "application/json"
29
- } };
30
- }
31
-
32
- //#endregion
33
- //#region src/agents/live-auth-keys.ts
34
- const KEY_SPLIT_RE = /[\s,;]+/g;
35
- const GOOGLE_LIVE_SINGLE_KEY = "OPENCLAW_LIVE_GEMINI_KEY";
36
- const PROVIDER_PREFIX_OVERRIDES = {
37
- google: "GEMINI",
38
- "google-vertex": "GEMINI"
39
- };
40
- const PROVIDER_API_KEY_CONFIG = {
41
- anthropic: {
42
- liveSingle: "OPENCLAW_LIVE_ANTHROPIC_KEY",
43
- listVar: "OPENCLAW_LIVE_ANTHROPIC_KEYS",
44
- primaryVar: "ANTHROPIC_API_KEY",
45
- prefixedVar: "ANTHROPIC_API_KEY_"
46
- },
47
- google: {
48
- liveSingle: GOOGLE_LIVE_SINGLE_KEY,
49
- listVar: "GEMINI_API_KEYS",
50
- primaryVar: "GEMINI_API_KEY",
51
- prefixedVar: "GEMINI_API_KEY_"
52
- },
53
- "google-vertex": {
54
- liveSingle: GOOGLE_LIVE_SINGLE_KEY,
55
- listVar: "GEMINI_API_KEYS",
56
- primaryVar: "GEMINI_API_KEY",
57
- prefixedVar: "GEMINI_API_KEY_"
58
- },
59
- openai: {
60
- liveSingle: "OPENCLAW_LIVE_OPENAI_KEY",
61
- listVar: "OPENAI_API_KEYS",
62
- primaryVar: "OPENAI_API_KEY",
63
- prefixedVar: "OPENAI_API_KEY_"
64
- }
65
- };
66
- function parseKeyList(raw) {
67
- if (!raw) return [];
68
- return raw.split(KEY_SPLIT_RE).map((value) => value.trim()).filter(Boolean);
69
- }
70
- function collectEnvPrefixedKeys(prefix) {
71
- const keys = [];
72
- for (const [name, value] of Object.entries(process.env)) {
73
- if (!name.startsWith(prefix)) continue;
74
- const trimmed = value?.trim();
75
- if (!trimmed) continue;
76
- keys.push(trimmed);
77
- }
78
- return keys;
79
- }
80
- function resolveProviderApiKeyConfig(provider) {
81
- const normalized = normalizeProviderId(provider);
82
- const custom = PROVIDER_API_KEY_CONFIG[normalized];
83
- const base = PROVIDER_PREFIX_OVERRIDES[normalized] ?? normalized.toUpperCase().replace(/-/g, "_");
84
- const liveSingle = custom?.liveSingle ?? `OPENCLAW_LIVE_${base}_KEY`;
85
- const listVar = custom?.listVar ?? `${base}_API_KEYS`;
86
- const primaryVar = custom?.primaryVar ?? `${base}_API_KEY`;
87
- const prefixedVar = custom?.prefixedVar ?? `${base}_API_KEY_`;
88
- if (normalized === "google" || normalized === "google-vertex") return {
89
- liveSingle,
90
- listVar,
91
- primaryVar,
92
- prefixedVar,
93
- fallbackVars: ["GOOGLE_API_KEY"]
94
- };
95
- return {
96
- liveSingle,
97
- listVar,
98
- primaryVar,
99
- prefixedVar,
100
- fallbackVars: []
101
- };
102
- }
103
- function collectProviderApiKeys(provider) {
104
- const config = resolveProviderApiKeyConfig(provider);
105
- const forcedSingle = config.liveSingle ? process.env[config.liveSingle]?.trim() : void 0;
106
- if (forcedSingle) return [forcedSingle];
107
- const fromList = parseKeyList(config.listVar ? process.env[config.listVar] : void 0);
108
- const primary = config.primaryVar ? process.env[config.primaryVar]?.trim() : void 0;
109
- const fromPrefixed = config.prefixedVar ? collectEnvPrefixedKeys(config.prefixedVar) : [];
110
- const fallback = config.fallbackVars.map((envVar) => process.env[envVar]?.trim()).filter(Boolean);
111
- const seen = /* @__PURE__ */ new Set();
112
- const add = (value) => {
113
- if (!value) return;
114
- if (seen.has(value)) return;
115
- seen.add(value);
116
- };
117
- for (const value of fromList) add(value);
118
- add(primary);
119
- for (const value of fromPrefixed) add(value);
120
- for (const value of fallback) add(value);
121
- return Array.from(seen);
122
- }
123
- function isApiKeyRateLimitError(message) {
124
- const lower = message.toLowerCase();
125
- if (lower.includes("rate_limit")) return true;
126
- if (lower.includes("rate limit")) return true;
127
- if (lower.includes("429")) return true;
128
- if (lower.includes("quota exceeded") || lower.includes("quota_exceeded")) return true;
129
- if (lower.includes("resource exhausted") || lower.includes("resource_exhausted")) return true;
130
- if (lower.includes("too many requests")) return true;
131
- return false;
132
- }
133
-
134
- //#endregion
135
- //#region src/agents/api-key-rotation.ts
136
- function dedupeApiKeys(raw) {
137
- const seen = /* @__PURE__ */ new Set();
138
- const keys = [];
139
- for (const value of raw) {
140
- const apiKey = value.trim();
141
- if (!apiKey || seen.has(apiKey)) continue;
142
- seen.add(apiKey);
143
- keys.push(apiKey);
144
- }
145
- return keys;
146
- }
147
- function collectProviderApiKeysForExecution(params) {
148
- const { primaryApiKey, provider } = params;
149
- return dedupeApiKeys([primaryApiKey?.trim() ?? "", ...collectProviderApiKeys(provider)]);
150
- }
151
- async function executeWithApiKeyRotation(params) {
152
- const keys = dedupeApiKeys(params.apiKeys);
153
- if (keys.length === 0) throw new Error(`No API keys configured for provider "${params.provider}".`);
154
- let lastError;
155
- for (let attempt = 0; attempt < keys.length; attempt += 1) {
156
- const apiKey = keys[attempt];
157
- try {
158
- return await params.execute(apiKey);
159
- } catch (error) {
160
- lastError = error;
161
- const message = formatErrorMessage(error);
162
- if (!(params.shouldRetry ? params.shouldRetry({
163
- apiKey,
164
- error,
165
- attempt,
166
- message
167
- }) : isApiKeyRateLimitError(message)) || attempt + 1 >= keys.length) break;
168
- params.onRetry?.({
169
- apiKey,
170
- error,
171
- attempt,
172
- message
173
- });
174
- }
175
- }
176
- if (lastError === void 0) throw new Error(`Failed to run API request for ${params.provider}.`);
177
- throw lastError;
178
- }
179
-
180
- //#endregion
181
- export { executeWithApiKeyRotation as n, parseGeminiAuth as r, collectProviderApiKeysForExecution as t };