fengming 0.3.7 → 0.3.9

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 (1264) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/abort-CCR8oZyg.js +277 -0
  3. package/dist/abort.runtime-eqx84NZa.js +2 -0
  4. package/dist/abort.runtime.js +1 -1
  5. package/dist/acp-spawn-BcDyvaXh.js +2 -0
  6. package/dist/acp-spawn-CCtSel-_.js +1286 -0
  7. package/dist/acp-stateful-target-driver-B3pCvuOV.js +89 -0
  8. package/dist/active-tool-schema-warnings-Cf-5q5WU.js +105 -0
  9. package/dist/active-tool-schema-warnings-Dzt3XE-y.js +2 -0
  10. package/dist/agent-1M2dVE2G.js +2 -0
  11. package/dist/agent-DLDIbUT4.js +1825 -0
  12. package/dist/agent-DZi6j3o6.js +3 -0
  13. package/dist/agent-command-ppfDBwET.js +1435 -0
  14. package/dist/agent-harness-runtime-C0bo62eY.d.ts +913 -0
  15. package/dist/agent-harness-runtime-RkTGiliR.js +207 -0
  16. package/dist/agent-runner-utils-B4YeVAO_.js +267 -0
  17. package/dist/agent-runner.runtime-T_3tlZN1.js +3784 -0
  18. package/dist/agent-runner.runtime.js +1 -1
  19. package/dist/agent-runtime-CloshyK-.d.ts +207 -0
  20. package/dist/agent-runtime-DZsmp1xr.js +199 -0
  21. package/dist/agent-tools-CET9usCz.js +2506 -0
  22. package/dist/agent-via-gateway-CZ0X0YkM.js +486 -0
  23. package/dist/agent-wait-dedupe-I81_F2tr.js +180 -0
  24. package/dist/agents/embedded-agent-runner/run/runtime-context-prompt.d.ts +1 -1
  25. package/dist/agents/embedded-agent-runner/tool-split.d.ts +1 -1
  26. package/dist/agents/model-catalog.runtime.d.ts +1 -1
  27. package/dist/api-BDB5xHYj.js +3 -0
  28. package/dist/api-BH7bfI5d.js +6 -0
  29. package/dist/api-BxJNXitd.js +2 -0
  30. package/dist/approval-client-helpers-CfQA9Jzh.d.ts +78 -0
  31. package/dist/approval-native-helpers-B2zyhxWc.d.ts +241 -0
  32. package/dist/approval-renderers-CMqSXyvm.d.ts +39 -0
  33. package/dist/assistant-Cu_Mzzgu.js +291 -0
  34. package/dist/attachment-normalize-Bb3v5iCC.js +213 -0
  35. package/dist/attempt-execution-BskbAq5I.js +584 -0
  36. package/dist/attempt-execution.runtime-BuT1wpNS.js +3 -0
  37. package/dist/attempt-execution.runtime.js +1 -1
  38. package/dist/attempt.prompt-helpers-ByKj-vQ7.js +543 -0
  39. package/dist/auto-reply/reply/commands-crestodian.d.ts +1 -1
  40. package/dist/binding-routing-EGRNvRC4.js +113 -0
  41. package/dist/binding-targets-B9vYS8n6.js +121 -0
  42. package/dist/bridge-server-DG9YtKQe.js +113 -0
  43. package/dist/browser-cli-B0Ou-Nbm.js +2 -0
  44. package/dist/browser-cli-GF25gL6M.js +230 -0
  45. package/dist/browser-cli-actions-input-CuER6RVe.js +522 -0
  46. package/dist/browser-cli-actions-observe-Dq-Zz_FA.js +81 -0
  47. package/dist/browser-cli-debug-7hvb49S1.js +137 -0
  48. package/dist/browser-cli-inspect-WU5KeWOK.js +117 -0
  49. package/dist/browser-cli-manage-B9D9BvSe.js +446 -0
  50. package/dist/browser-cli-resize-BUOusOPb.js +32 -0
  51. package/dist/browser-cli-shared-DmpSN-Qi.js +69 -0
  52. package/dist/browser-cli-state-D_YxTqRw.js +371 -0
  53. package/dist/browser-control-auth-Cqd1n9FA.js +2 -0
  54. package/dist/browser-profiles-9tQ05wYh.js +2 -0
  55. package/dist/browser-runtime-Bbzumoha.js +389 -0
  56. package/dist/build-CBXuT2K1.js +261 -0
  57. package/dist/build-info.json +3 -3
  58. package/dist/bundled/boot-md/handler.js +2 -2
  59. package/dist/bundled/session-memory/handler.js +1 -1
  60. package/dist/bundled-channel-config-schema-DpdKMATU.d.ts +3168 -0
  61. package/dist/canvas-host/a2ui/.bundle.hash +1 -1
  62. package/dist/capability-cli-CiVGX7ut.js +1809 -0
  63. package/dist/channel-BIVwHq7P.js +2309 -0
  64. package/dist/channel-CiA2FVdL.d.ts +427 -0
  65. package/dist/channel-core-Cj9JTqeu.js +5 -0
  66. package/dist/channel-core-DjVpcH1C.d.ts +6 -0
  67. package/dist/channel-entry-contract-Bs_54m1D.d.ts +114 -0
  68. package/dist/channel-inbound-CdUdeQRa.js +121 -0
  69. package/dist/channel-inbound-iGiqx6CS.d.ts +97 -0
  70. package/dist/channel-message-C3QPaDUk.js +12 -0
  71. package/dist/channel-message-CXDjxb2U.d.ts +9 -0
  72. package/dist/channel-outbound-ofvvmMSK.d.ts +325 -0
  73. package/dist/channel-pairing-DKscOV1K.d.ts +58 -0
  74. package/dist/channel.runtime-VW6PW_ez.js +697 -0
  75. package/dist/channel.runtime.js +1 -1
  76. package/dist/chat-CFkQepUQ.js +3 -0
  77. package/dist/chat-Czh_tXM0.js +2940 -0
  78. package/dist/chrome-B2cq8YyH.js +1517 -0
  79. package/dist/cli/run-main.js +5 -5
  80. package/dist/cli-compaction-Dxv4nt7R.js +363 -0
  81. package/dist/cli-runner-CimXSTVs.js +2 -0
  82. package/dist/cli-runner-orCzE1Sr.js +597 -0
  83. package/dist/cli-runner.runtime-CsW0dXJW.js +3 -0
  84. package/dist/cli-runner.runtime-DgPrc1do.js +4 -0
  85. package/dist/cli-runner.runtime.js +1 -1
  86. package/dist/cli-startup-metadata.json +10 -12
  87. package/dist/command-registry-C5ooX6PF.js +4 -0
  88. package/dist/command-registry-DMB-HKIk.js +9 -0
  89. package/dist/command-registry-core-B2w_XWvn.js +114 -0
  90. package/dist/command-status.runtime-Bdy3Dkar.js +90 -0
  91. package/dist/command-status.runtime.js +1 -1
  92. package/dist/commands-compact.runtime-Bk2jTQo6.js +10 -0
  93. package/dist/commands-compact.runtime.js +1 -1
  94. package/dist/commands-handlers.runtime-Csw1og0U.js +6327 -0
  95. package/dist/commands-handlers.runtime.js +1 -1
  96. package/dist/commands-mRqmLIVz.d.ts +117 -0
  97. package/dist/commands-status-Dgrj_ubK.js +3 -0
  98. package/dist/commands-status-s32HJOpD.js +16 -0
  99. package/dist/commands-status.runtime-Dgrj_ubK.js +3 -0
  100. package/dist/commands-status.runtime.js +1 -1
  101. package/dist/commands-subagents-control.runtime-C_hnOO9l.js +2 -0
  102. package/dist/commands-subagents-control.runtime.js +1 -1
  103. package/dist/commands-system-prompt-CQV742Cc.js +2 -0
  104. package/dist/commands-system-prompt-DTfsKwK1.js +161 -0
  105. package/dist/commands-types-MXHhrssO.d.ts +132 -0
  106. package/dist/commands.runtime-akiVK67l.js +175 -0
  107. package/dist/commands.runtime.js +1 -1
  108. package/dist/commitments/runtime.js +1 -1
  109. package/dist/compact-U6ZhvPtD.js +1165 -0
  110. package/dist/compact.runtime-36E5vKsC.js +12 -0
  111. package/dist/compact.runtime.js +1 -1
  112. package/dist/completion-cli-Bf4mEw2W.js +393 -0
  113. package/dist/config-BJJhHN9E.js +374 -0
  114. package/dist/config-mutations-swLu-j_p.js +161 -0
  115. package/dist/config-schema-Tjner6bM.d.ts +20 -0
  116. package/dist/context-engine-host-compat-6fkn_daV.js +280 -0
  117. package/dist/context-engine-host-compat-DtAZC1bS.js +2 -0
  118. package/dist/context-engine-lifecycle-R__Idxi1.js +627 -0
  119. package/dist/control-auth-DnkI94_D.js +114 -0
  120. package/dist/control-service-BBsamNjq.js +40 -0
  121. package/dist/control-service-BGpHj7RL.js +3 -0
  122. package/dist/control-ui/assets/activity-B2W-IeAT.js +124 -0
  123. package/dist/control-ui/assets/agents-mRUyNVCz.js +1030 -0
  124. package/dist/control-ui/assets/channels-8QHOqBnt.js +120 -0
  125. package/dist/control-ui/assets/cron-H3unP_mO.js +1016 -0
  126. package/dist/control-ui/assets/debug-CxLsQ9vH.js +97 -0
  127. package/dist/control-ui/assets/index-jtIYT0Eh.js +7214 -0
  128. package/dist/control-ui/assets/instances-B1JQeCRb.js +57 -0
  129. package/dist/control-ui/assets/nodes-RGOmq_1l.js +444 -0
  130. package/dist/control-ui/assets/sessions-C2O-Jgpg.js +425 -0
  131. package/dist/control-ui/assets/skills-jyJOYA4I.js +362 -0
  132. package/dist/control-ui/assets/workboard-uM_kK8cQ.js +402 -0
  133. package/dist/control-ui/index.html +1 -1
  134. package/dist/control-ui/sw.js +1 -1
  135. package/dist/conversation-runtime-DDekWU-U.js +31 -0
  136. package/dist/core-Bpk-qSJH.js +284 -0
  137. package/dist/core-Chrz4oRB.d.ts +223 -0
  138. package/dist/core-api-DSpUKNVW.js +2 -0
  139. package/dist/core-api-hLsW03Wo.js +5 -0
  140. package/dist/crestodian/crestodian.js +1 -1
  141. package/dist/crestodian/rescue-message.d.ts +1 -1
  142. package/dist/crestodian/rescue-message.js +1 -1
  143. package/dist/crestodian-C0x7JjF-.js +55 -0
  144. package/dist/delegate-BArFIZ4B.d.ts +30 -0
  145. package/dist/deliver-BnVp3VbL.d.ts +111 -0
  146. package/dist/delivery-queue-BFOASdf5.d.ts +161 -0
  147. package/dist/delivery-queue-runtime-BFfc8AEs.d.ts +9 -0
  148. package/dist/dialogue-No0NvYX7.js +37 -0
  149. package/dist/direct-dm-C-h88JJH.d.ts +79 -0
  150. package/dist/directive-handling.fast-lane-DTyDKhZb.js +70 -0
  151. package/dist/directive-handling.impl-DMReM6tu.js +2 -0
  152. package/dist/directive-handling.impl-DzPouhV-.js +823 -0
  153. package/dist/directive-handling.model-selection-BjwTBAZJ.js +122 -0
  154. package/dist/directive-handling.persist.runtime-D_O1okkR.js +274 -0
  155. package/dist/directive-handling.persist.runtime.js +1 -1
  156. package/dist/dispatch-Dtl-oRuN.js +2057 -0
  157. package/dist/dispatch-acp-transcript.runtime-M4y0Dq74.js +40 -0
  158. package/dist/dispatch-acp-transcript.runtime.js +1 -1
  159. package/dist/dispatch-acp.runtime-B8uCIKZS.js +18 -0
  160. package/dist/dispatch-acp.runtime.js +1 -1
  161. package/dist/dispatcher-DslvaRcj.js +106 -0
  162. package/dist/doctor-config-flow-LU2C94af.js +1819 -0
  163. package/dist/doctor-core-checks-BqcjExIZ.js +666 -0
  164. package/dist/doctor-core-checks-Diuk8l0N.js +2 -0
  165. package/dist/doctor-core-checks.runtime-DbS-kMZN.js +278 -0
  166. package/dist/doctor-core-checks.runtime.js +1 -1
  167. package/dist/doctor-health-BdqHwfYE.js +65 -0
  168. package/dist/doctor-health-contributions-DLLTVnll.js +874 -0
  169. package/dist/doctor-lint-PZqkVMWf.js +95 -0
  170. package/dist/doctor-mRfJMSb5.js +6 -0
  171. package/dist/doctor-state-integrity-Cdlm-peH.js +1257 -0
  172. package/dist/draft-stream-controls-B7uLonbw.d.ts +159 -0
  173. package/dist/embedded-agent-CEpOPW6X.js +4 -0
  174. package/dist/embedded-agent-CNINO_M-.d.ts +5 -0
  175. package/dist/embedded-agent-DxwzoZkp.js +4074 -0
  176. package/dist/embedded-agent.runtime-DDbhA85-.js +4 -0
  177. package/dist/embedded-agent.runtime.js +1 -1
  178. package/dist/embedded-backend-ChaKCepC.js +1581 -0
  179. package/dist/embedded-gateway-stub.runtime-e_ZxGhcW.js +12 -0
  180. package/dist/embedded-gateway-stub.runtime.js +1 -1
  181. package/dist/entry.d.ts +1 -1
  182. package/dist/extensionAPI.d.ts +2 -2
  183. package/dist/extensionAPI.js +1 -1
  184. package/dist/extensions/active-memory/index.d.ts +1 -1
  185. package/dist/extensions/active-memory/index.js +1 -1
  186. package/dist/extensions/admin-http-rpc/index.d.ts +1 -1
  187. package/dist/extensions/admin-http-rpc/index.js +1 -1
  188. package/dist/extensions/bonjour/index.d.ts +1 -1
  189. package/dist/extensions/browser/browser-bridge.js +1 -1
  190. package/dist/extensions/browser/browser-config.js +4 -4
  191. package/dist/extensions/browser/browser-control-auth.js +2 -2
  192. package/dist/extensions/browser/browser-doctor.js +2 -2
  193. package/dist/extensions/browser/browser-maintenance.js +1 -1
  194. package/dist/extensions/browser/browser-profiles.js +2 -2
  195. package/dist/extensions/browser/browser-runtime-api.js +12 -12
  196. package/dist/extensions/browser/cli-metadata.d.ts +1 -1
  197. package/dist/extensions/browser/cli-metadata.js +1 -1
  198. package/dist/extensions/browser/index.d.ts +1 -1
  199. package/dist/extensions/browser/index.js +1 -1
  200. package/dist/extensions/browser/plugin-registration.d.ts +1 -1
  201. package/dist/extensions/browser/plugin-registration.js +1 -1
  202. package/dist/extensions/browser/register.runtime.d.ts +2 -2
  203. package/dist/extensions/browser/register.runtime.js +4 -4
  204. package/dist/extensions/browser/runtime-api.d.ts +3 -3
  205. package/dist/extensions/browser/runtime-api.js +14 -14
  206. package/dist/extensions/browser/setup-api.d.ts +1 -1
  207. package/dist/extensions/canvas/cli-metadata.d.ts +1 -1
  208. package/dist/extensions/canvas/index.d.ts +1 -1
  209. package/dist/extensions/canvas/index.js +1 -1
  210. package/dist/extensions/canvas/setup-api.d.ts +1 -1
  211. package/dist/extensions/deepseek/api.d.ts +1 -1
  212. package/dist/extensions/deepseek/index.d.ts +1 -1
  213. package/dist/extensions/deepseek/provider-discovery.d.ts +1 -1
  214. package/dist/extensions/deepseek/stream.d.ts +1 -1
  215. package/dist/extensions/device-pair/api.d.ts +4 -4
  216. package/dist/extensions/device-pair/api.js +1 -1
  217. package/dist/extensions/device-pair/index.d.ts +1 -1
  218. package/dist/extensions/device-pair/notify.d.ts +1 -1
  219. package/dist/extensions/device-pair/pair-command-approve.js +1 -1
  220. package/dist/extensions/device-pair/qr-image.d.ts +1 -1
  221. package/dist/extensions/memory-core/api.d.ts +1 -1
  222. package/dist/extensions/memory-core/cli-metadata.d.ts +1 -1
  223. package/dist/extensions/memory-core/cli-metadata.js +1 -1
  224. package/dist/extensions/memory-core/index.d.ts +1 -1
  225. package/dist/extensions/memory-core/manager-runtime.d.ts +1 -1
  226. package/dist/extensions/memory-core/runtime-api.d.ts +3 -3
  227. package/dist/extensions/skill-workshop/api.d.ts +2 -2
  228. package/dist/extensions/skill-workshop/api.js +1 -1
  229. package/dist/extensions/skill-workshop/index.d.ts +1 -1
  230. package/dist/extensions/skill-workshop/index.js +2 -2
  231. package/dist/extensions/tavily/index.d.ts +1 -1
  232. package/dist/extensions/tavily/web-search-contract-api.d.ts +1 -1
  233. package/dist/extensions/tavily/web-search-provider.d.ts +1 -1
  234. package/dist/extensions/thread-ownership/api.d.ts +2 -2
  235. package/dist/extensions/thread-ownership/index.d.ts +1 -1
  236. package/dist/extensions/webhooks/api.d.ts +2 -2
  237. package/dist/extensions/webhooks/api.js +1 -1
  238. package/dist/extensions/webhooks/index.d.ts +1 -1
  239. package/dist/extensions/webhooks/index.js +1 -1
  240. package/dist/extensions/webhooks/runtime-api.d.ts +1 -1
  241. package/dist/extensions/workboard/api.d.ts +2 -2
  242. package/dist/extensions/workboard/index.d.ts +1 -1
  243. package/dist/extensions/workboard/index.js +1 -1
  244. package/dist/extensions/workboard/runtime-api.d.ts +1 -1
  245. package/dist/fengming-runtime-CtRd5677.d.ts +153 -0
  246. package/dist/fengming-tools-DBLsJfsf.js +12221 -0
  247. package/dist/gateway/protocol/index.d.ts +1 -1
  248. package/dist/gateway-cli-BgDV2HF9.js +443 -0
  249. package/dist/gateway-method-runtime-d9oN_XO9.js +21 -0
  250. package/dist/get-reply-CEMtvaTJ.js +5198 -0
  251. package/dist/get-reply-from-config.runtime-CE8zmX7o.js +2 -0
  252. package/dist/get-reply-from-config.runtime.js +1 -1
  253. package/dist/heartbeat-runner-H8SmaKmJ.js +5 -0
  254. package/dist/heartbeat-runner.runtime-6hUaxEbl.js +3 -0
  255. package/dist/heartbeat-runner.runtime.js +1 -1
  256. package/dist/hooks-DkEvkwzS.js +536 -0
  257. package/dist/host-compat-DeAq3dnI.d.ts +21 -0
  258. package/dist/http-registry-BDoApjTY.d.ts +23 -0
  259. package/dist/inbound-reply-dispatch-CIYP2OPo.d.ts +156 -0
  260. package/dist/inbound-reply-dispatch-geHu6oUK.js +147 -0
  261. package/dist/inbound-reply-dispatch-vwW5Hl-_.js +2 -0
  262. package/dist/index-DhOQs6M_.d.ts +1497 -0
  263. package/dist/index.js +1 -1
  264. package/dist/init-DpE_6dG4.js +59 -0
  265. package/dist/interactive-Cb_1f91G.d.ts +26 -0
  266. package/dist/isolated-agent-B_upYOOM.js +2 -0
  267. package/dist/isolated-agent-KH9uwWhw.js +1097 -0
  268. package/dist/kernel-BHnBXnm2.d.ts +241 -0
  269. package/dist/lifecycle-BmZwopzF.js +570 -0
  270. package/dist/list.probe-5kzWm9Jk.js +451 -0
  271. package/dist/list.probe-9zBcGGQ4.js +2 -0
  272. package/dist/list.status-command-DY2ifqp1.js +815 -0
  273. package/dist/llm-slug-generator-Bmx0I84M.js +78 -0
  274. package/dist/llm-slug-generator.js +1 -1
  275. package/dist/loader-BVz75gSb.d.ts +142 -0
  276. package/dist/local-dispatch.runtime-CX3IOY1E.js +10 -0
  277. package/dist/local-dispatch.runtime.js +1 -1
  278. package/dist/manager-BXGg8bfG.d.ts +409 -0
  279. package/dist/mcp-http-B1lnh67s.js +2 -0
  280. package/dist/mcp-http-CamghE-W.js +583 -0
  281. package/dist/media-runtime-DpykroJR.d.ts +261 -0
  282. package/dist/memory-core-host-engine-embeddings-N2dX5P40.d.ts +324 -0
  283. package/dist/memory-core-host-engine-storage-WQfkQMer.d.ts +54 -0
  284. package/dist/message-handler-Ca_pqGVS.js +1806 -0
  285. package/dist/model-catalog-BBMLIjhq.d.ts +88 -0
  286. package/dist/model-selection-Cq82FXLy.js +352 -0
  287. package/dist/models-cli-Dm_393dw.js +257 -0
  288. package/dist/monitor-d0eyE2k0.js +60 -0
  289. package/dist/monitor.account-vLQ3bKHu.js +5382 -0
  290. package/dist/nodes-Bunvrb33.js +1483 -0
  291. package/dist/nodes-edNlxb2I.js +3 -0
  292. package/dist/nodes-pending-DEIwVh9v.js +211 -0
  293. package/dist/openai-compat-errors-CvWEoG98.js +136 -0
  294. package/dist/openai-http-Bskdv4Tv.js +836 -0
  295. package/dist/openresponses-http-DxdgCxFU.js +1175 -0
  296. package/dist/operations-Z85LFqsT.js +805 -0
  297. package/dist/outbound.types-DVkbsxo8.d.ts +291 -0
  298. package/dist/plugin-enabled-fvhTpvYS.js +232 -0
  299. package/dist/plugin-entry-CunlVUw6.d.ts +47 -0
  300. package/dist/plugin-registration-9ovnK_Tk.js +97 -0
  301. package/dist/plugin-runtime-DH2ZM9P5.d.ts +117 -0
  302. package/dist/plugin-sdk/.boundary-entry-shims.stamp +1 -1
  303. package/dist/plugin-sdk/acp-runtime-backend.js +1 -1
  304. package/dist/plugin-sdk/acp-runtime.js +1 -1
  305. package/dist/plugin-sdk/agent-harness-runtime.js +5 -5
  306. package/dist/plugin-sdk/agent-harness-task-runtime.js +1 -1
  307. package/dist/plugin-sdk/agent-harness.js +6 -6
  308. package/dist/plugin-sdk/agent-runtime.js +2 -2
  309. package/dist/plugin-sdk/bundled-channel-config-schema-Dfn3b8sF.d.ts +3169 -0
  310. package/dist/plugin-sdk/bundled-channel-config-schema.d.ts +1 -1
  311. package/dist/plugin-sdk/channel-config-schema-legacy.d.ts +1 -1
  312. package/dist/plugin-sdk/channel-core.js +2 -2
  313. package/dist/plugin-sdk/channel-envelope.js +1 -1
  314. package/dist/plugin-sdk/channel-inbound-roots.js +1 -1
  315. package/dist/plugin-sdk/channel-inbound.js +2 -2
  316. package/dist/plugin-sdk/channel-location.js +1 -1
  317. package/dist/plugin-sdk/channel-message-runtime.js +3 -3
  318. package/dist/plugin-sdk/channel-message.js +2 -2
  319. package/dist/plugin-sdk/channel-runtime.js +0 -1
  320. package/dist/plugin-sdk/command-status-runtime.js +1 -1
  321. package/dist/plugin-sdk/compat.js +1 -1
  322. package/dist/plugin-sdk/conversation-binding-runtime.js +1 -1
  323. package/dist/plugin-sdk/conversation-runtime.js +3 -3
  324. package/dist/plugin-sdk/core.js +2 -2
  325. package/dist/plugin-sdk/discord.d.ts +1 -1
  326. package/dist/plugin-sdk/gateway-method-runtime.js +1 -1
  327. package/dist/plugin-sdk/health.js +1 -1
  328. package/dist/plugin-sdk/hook-runtime.js +0 -1
  329. package/dist/plugin-sdk/inbound-reply-dispatch.js +2 -2
  330. package/dist/plugin-sdk/index.js +1 -1
  331. package/dist/plugin-sdk/infra-runtime.js +3 -1
  332. package/dist/plugin-sdk/provider-auth-api-key.js +0 -1
  333. package/dist/plugin-sdk/provider-stream-family.js +0 -1
  334. package/dist/plugin-sdk/provider-usage.js +649 -1
  335. package/dist/plugin-sdk/reply-runtime.js +4 -4
  336. package/dist/plugin-sdk/scripts/lib/plugin-sdk-doc-metadata.d.ts +122 -0
  337. package/dist/plugin-sdk/video-generation.js +206 -1
  338. package/dist/plugin-service-BdZxoKBZ.js +1249 -0
  339. package/dist/plugin-service-quTl5hT0.d.ts +24 -0
  340. package/dist/plugins/build-smoke-entry.d.ts +2 -2
  341. package/dist/plugins/loader.d.ts +1 -1
  342. package/dist/plugins/provider-discovery.runtime.d.ts +1 -1
  343. package/dist/plugins/provider-runtime.runtime.d.ts +1 -1
  344. package/dist/plugins/runtime/index.d.ts +1 -1
  345. package/dist/plugins/runtime/index.js +4 -4
  346. package/dist/plugins/tools.d.ts +1 -1
  347. package/dist/prepare.runtime-DFvkUqBZ.js +798 -0
  348. package/dist/prepare.runtime.js +1 -1
  349. package/dist/preview-warnings-CGzc8ccG.js +618 -0
  350. package/dist/program-D19g2jaa.js +131 -0
  351. package/dist/provider-api-key-auth-B8GgTfo8.d.ts +27 -0
  352. package/dist/provider-auth-result-Diw-woMA.d.ts +21 -0
  353. package/dist/provider-catalog-shared-hMvzzDgL.d.ts +62 -0
  354. package/dist/provider-dispatcher-DCTc4lG_.js +22 -0
  355. package/dist/provider-dispatcher.runtime.js +1 -1
  356. package/dist/provider-model-shared-BUCh3uCL.d.ts +143 -0
  357. package/dist/provider-registry-BIokPlxa.d.ts +8 -0
  358. package/dist/provider-registry-CyUOXHG-.d.ts +8 -0
  359. package/dist/provider-registry-i--H79Ao.d.ts +29 -0
  360. package/dist/provider-self-hosted-setup-BF8UR8wg.d.ts +74 -0
  361. package/dist/provider-stream-NF0XJnar.d.ts +139 -0
  362. package/dist/provider-stream-shared-DLwDaYed.d.ts +132 -0
  363. package/dist/provider-web-search-contract-fields-D61Vl5Kl.d.ts +25 -0
  364. package/dist/pw-ai-DYR-D7xR.js +3064 -0
  365. package/dist/register.agent-DwW0mQPk.js +152 -0
  366. package/dist/register.crestodian-BhIukKDA.js +24 -0
  367. package/dist/register.maintenance-DWHlvztJ.js +85 -0
  368. package/dist/register.subclis-Bsvdh8RI.js +3 -0
  369. package/dist/register.subclis-DVk0HU4k.js +31 -0
  370. package/dist/register.subclis-core-BK7nVvl6.js +278 -0
  371. package/dist/registry-hscEPAcC.d.ts +8 -0
  372. package/dist/registry-types-Ce-n1tuw.d.ts +392 -0
  373. package/dist/repair-sequencing-0-qGNSUO.js +652 -0
  374. package/dist/reply-payload-mCw4ZND6.d.ts +200 -0
  375. package/dist/reply-turn-admission-DMWNadoS.js +2056 -0
  376. package/dist/reply.runtime-CE8zmX7o.js +2 -0
  377. package/dist/reply.runtime.js +1 -1
  378. package/dist/result-fallback-classifier-BZmv2ACy.js +98 -0
  379. package/dist/route-qQ-jYpFa.js +475 -0
  380. package/dist/routes-dTCmw98g.js +2 -0
  381. package/dist/routes-r8DRKa83.js +3701 -0
  382. package/dist/run-BgH7EPGH.js +1162 -0
  383. package/dist/run-command-DCsM-BVh.js +23 -0
  384. package/dist/run-command-I2ib4dwS.js +2 -0
  385. package/dist/run-context-CWaKUKKJ.js +66 -0
  386. package/dist/run-embedded.runtime-CBnDBWN0.js +4 -0
  387. package/dist/run-embedded.runtime.js +1 -1
  388. package/dist/run-execution-cli.runtime-DlYXI-lw.js +4 -0
  389. package/dist/run-execution-cli.runtime.js +1 -1
  390. package/dist/run-executor.runtime-DwepGrmB.js +330 -0
  391. package/dist/run-executor.runtime.js +1 -1
  392. package/dist/run-subagent-registry.runtime-CeVpoIhj.js +2 -0
  393. package/dist/run-subagent-registry.runtime.js +1 -1
  394. package/dist/runtime-D2ee-rNh.js +436 -0
  395. package/dist/runtime-api-B99ZlkNt.d.ts +5 -0
  396. package/dist/runtime-api-Cta2L_Yo.js +12 -0
  397. package/dist/runtime-channel-LKOkML3M.js +2 -0
  398. package/dist/runtime-channel-UtWvrTZ5.js +148 -0
  399. package/dist/runtime-embedded-agent.runtime-9O2Idzyb.js +2 -0
  400. package/dist/runtime-embedded-agent.runtime.js +1 -1
  401. package/dist/runtime-forwarders-DjI8RFL5.d.ts +39 -0
  402. package/dist/sdk-setup-tools-B-X04pa6.js +8 -0
  403. package/dist/selection-B02h8Old.js +3 -0
  404. package/dist/selection-DEPvzrW2.js +18365 -0
  405. package/dist/server-CMYi8gDo.js +24 -0
  406. package/dist/server-Cx07rsiY.js +72 -0
  407. package/dist/server-close.runtime.js +1 -1
  408. package/dist/server-context-BIemGRt4.js +2 -0
  409. package/dist/server-context-CB_an9iy.js +955 -0
  410. package/dist/server-cron-BeyuBUjb.js +3173 -0
  411. package/dist/server-cron-CV7KkVeB.js +2 -0
  412. package/dist/server-methods-C7EnpOhB.js +497 -0
  413. package/dist/server-node-events-DMMzZciN.js +597 -0
  414. package/dist/server-plugin-bootstrap-O6MzvzL8.js +71 -0
  415. package/dist/server-plugins-Dwnaz9kX.js +435 -0
  416. package/dist/server-reload-handlers-C-6TyPvI.js +719 -0
  417. package/dist/server-restart-sentinel-Dc35eYgk.js +700 -0
  418. package/dist/server-runtime-services-DCs-gqh_.js +3 -0
  419. package/dist/server-runtime-services-DF2fzzVd.js +147 -0
  420. package/dist/server-startup-plugins-t-YeYibm.js +127 -0
  421. package/dist/server-startup-post-attach-CiEki-DC.js +793 -0
  422. package/dist/server-ws-runtime-uaUpI-e8.js +374 -0
  423. package/dist/server.impl-MoHjSMr5.js +2622 -0
  424. package/dist/session-kill-http-CYCiQpt2.js +121 -0
  425. package/dist/session-reset-service-BYbADY57.js +651 -0
  426. package/dist/session-status.runtime-8NASbeO4.js +2 -0
  427. package/dist/session-status.runtime.js +1 -1
  428. package/dist/session-subagent-reactivation.runtime-DGeNY2Rb.js +2 -0
  429. package/dist/session-subagent-reactivation.runtime.js +1 -1
  430. package/dist/session-tab-registry-C2eElZrt.js +551 -0
  431. package/dist/sessions-DXAdVXIx.js +1917 -0
  432. package/dist/sessions-history-http-BwK7b8OH.js +432 -0
  433. package/dist/sessions-patch-BYC5gvY1.js +401 -0
  434. package/dist/sessions-resolve-C3ORcdmo.js +180 -0
  435. package/dist/sessions.runtime-BijldeSY.js +2 -0
  436. package/dist/sessions.runtime.js +1 -1
  437. package/dist/snapshot-urls-C5CfP3Co.js +317 -0
  438. package/dist/speech-core-wWkTZPpQ.d.ts +49 -0
  439. package/dist/standalone-CHrieUsw.js +42 -0
  440. package/dist/startup-context-CZfmG8-g.js +314 -0
  441. package/dist/status-subagents.runtime-D2XMebiS.js +32 -0
  442. package/dist/status-subagents.runtime.js +1 -1
  443. package/dist/status-text-JR7IPyzZ.js +301 -0
  444. package/dist/stream-BJgTkLEI.d.ts +5 -0
  445. package/dist/subagent-announce-B9cfs_KZ.js +353 -0
  446. package/dist/subagent-announce-delivery-CtmEvLTS.js +1369 -0
  447. package/dist/subagent-control-DVqLHi9O.js +492 -0
  448. package/dist/subagent-hooks-D251uSvy.js +230 -0
  449. package/dist/subagent-hooks-api-DvdMKxsC.js +23 -0
  450. package/dist/subagent-hooks-uLORYChc.js +2 -0
  451. package/dist/subagent-registry-BW2l_oYu.js +3 -0
  452. package/dist/subagent-registry-BxEMHuiN.js +2627 -0
  453. package/dist/subagent-registry.runtime.d.ts +1 -1
  454. package/dist/subagent-registry.runtime.js +1 -1
  455. package/dist/subagent-session-cleanup-BC5wV2qQ.js +390 -0
  456. package/dist/system-fvgHsr2x.js +111 -0
  457. package/dist/talk-DU0Sod_K.js +2454 -0
  458. package/dist/target-id-BR2xJIkd.js +107 -0
  459. package/dist/task-registry-control.runtime.js +1 -1
  460. package/dist/thread-bindings-8XNu5U2p.js +228 -0
  461. package/dist/tool-Boeg0N5g.js +143 -0
  462. package/dist/tool-dispatch-BhLLaL2g.js +155 -0
  463. package/dist/tool-resolution-CzsLs-87.js +153 -0
  464. package/dist/tool-split-Bedy42Ms.d.ts +19 -0
  465. package/dist/tools-B6egHpE3.d.ts +38 -0
  466. package/dist/tools-effective-NXscxK8n.js +442 -0
  467. package/dist/tools-effective-inventory-NsGMUVo-.js +379 -0
  468. package/dist/tools-invoke-_sSu96Kq.js +51 -0
  469. package/dist/tools-invoke-http-BDhlRl-G.js +68 -0
  470. package/dist/tools-invoke-shared-BH-T9Bcg.js +200 -0
  471. package/dist/tts-runtime-C1wu3o15.d.ts +230 -0
  472. package/dist/tui-C733Qov0.js +2 -0
  473. package/dist/tui-DqbscVN5.js +3 -0
  474. package/dist/tui-backend-_Pn3Byj-.js +257 -0
  475. package/dist/tui-cli-CAiC39zd.js +40 -0
  476. package/dist/tui-ink-run-ChXEGj1h.js +7414 -0
  477. package/dist/tui-ink-run-D4mSfLHj.js +2 -0
  478. package/dist/types-BQw1qXGl.d.ts +7034 -0
  479. package/dist/types-BzMoU6-C.d.ts +111 -0
  480. package/dist/types-DltHmoCX.d.ts +393 -0
  481. package/dist/types.public-C_bVIMBl.d.ts +70 -0
  482. package/dist/web-fetch/runtime.d.ts +1 -1
  483. package/dist/webhook-targets-DW2jhddP.d.ts +99 -0
  484. package/dist/zod-schema.core-Cuz0lz6m.d.ts +166 -0
  485. package/npm-shrinkwrap.json +12861 -11889
  486. package/package.json +1 -1
  487. package/skills/batch/SKILL.md +118 -0
  488. package/skills/code-review/SKILL.md +107 -0
  489. package/skills/debug/SKILL.md +83 -0
  490. package/skills/loop/SKILL.md +118 -0
  491. package/skills/run/SKILL.md +79 -0
  492. package/skills/run-skill-generator/SKILL.md +179 -0
  493. package/skills/verify/SKILL.md +103 -0
  494. package/dist/abort-DGskei2p.js +0 -277
  495. package/dist/abort.runtime-Buq9IZxn.js +0 -2
  496. package/dist/acp-spawn-DC6IyYaB.js +0 -1286
  497. package/dist/acp-spawn-Diqb3nel.js +0 -2
  498. package/dist/acp-stateful-target-driver-Clhe_L8v.js +0 -89
  499. package/dist/active-tool-schema-warnings-BRhKkyvt.js +0 -2
  500. package/dist/active-tool-schema-warnings-C6N0-ce6.js +0 -105
  501. package/dist/agent-C5lhsEZJ.js +0 -2
  502. package/dist/agent-WEb757bl.js +0 -1825
  503. package/dist/agent-command-iLD_nsVY.js +0 -1435
  504. package/dist/agent-core-BeDN8Ns5.d.ts +0 -13
  505. package/dist/agent-harness-runtime-C89_Q-bW.d.ts +0 -913
  506. package/dist/agent-harness-runtime-Dfn5rik2.js +0 -207
  507. package/dist/agent-runner-utils-DNiuuo43.js +0 -267
  508. package/dist/agent-runner.runtime-CFF_qJ5V.js +0 -3784
  509. package/dist/agent-runtime-BkMtWXxn.js +0 -199
  510. package/dist/agent-runtime-HufMO_YR.d.ts +0 -207
  511. package/dist/agent-tools-HmaDv4ot.js +0 -2506
  512. package/dist/agent-via-gateway-CZQG8RYL.js +0 -486
  513. package/dist/agent-wait-dedupe-C3xQk2Ww.js +0 -180
  514. package/dist/agent-z1cs3c7n.js +0 -3
  515. package/dist/api-B4IMKjSe.js +0 -3
  516. package/dist/api-BwSbBWI8.js +0 -3
  517. package/dist/api-CE9In9m4.js +0 -5
  518. package/dist/api-ClPvYNGa.js +0 -32
  519. package/dist/api-CntBCaZf.js +0 -3
  520. package/dist/api-DBZBwTsn.js +0 -6
  521. package/dist/api-OCPwGOvK.js +0 -2
  522. package/dist/api-yYhEo7gK.js +0 -4
  523. package/dist/approval-client-helpers-CfdQ3-vv.d.ts +0 -78
  524. package/dist/approval-native-helpers-DSHPksK4.d.ts +0 -241
  525. package/dist/approval-renderers-BfEfwk44.d.ts +0 -39
  526. package/dist/assistant-v5fdOYu7.js +0 -291
  527. package/dist/attachment-normalize-BHAbLiL2.js +0 -213
  528. package/dist/attempt-execution-5w9WYbaJ.js +0 -584
  529. package/dist/attempt-execution.runtime-DnhOWGzr.js +0 -3
  530. package/dist/attempt.prompt-helpers-C4M4erF7.js +0 -543
  531. package/dist/binding-routing-Dpes-QF1.js +0 -113
  532. package/dist/binding-targets-B6H5Pd-A.js +0 -121
  533. package/dist/bridge-server-BCpxCRm_.js +0 -113
  534. package/dist/browser-cli-DMhXHopl.js +0 -230
  535. package/dist/browser-cli-Dy_VugK0.js +0 -2
  536. package/dist/browser-cli-actions-input-WMP7_lm6.js +0 -522
  537. package/dist/browser-cli-actions-observe-DQWAWhwU.js +0 -81
  538. package/dist/browser-cli-debug-CaT2ZKAx.js +0 -137
  539. package/dist/browser-cli-inspect-DU-LUXq1.js +0 -117
  540. package/dist/browser-cli-manage-DAuogqIh.js +0 -446
  541. package/dist/browser-cli-resize-Cz5uO_aR.js +0 -32
  542. package/dist/browser-cli-shared-CjPZcG3j.js +0 -69
  543. package/dist/browser-cli-state-CC3l77-K.js +0 -371
  544. package/dist/browser-control-auth-ELccIUZy.js +0 -2
  545. package/dist/browser-profiles-Cuy4ia6_.js +0 -2
  546. package/dist/browser-runtime-De-iUfME.js +0 -389
  547. package/dist/build-DEF8Per9.js +0 -261
  548. package/dist/bundled-channel-config-schema-Bte--ZlY.d.ts +0 -3168
  549. package/dist/capability-cli-Bydel4E7.js +0 -1809
  550. package/dist/channel-6SGL4R5P.js +0 -2309
  551. package/dist/channel-D3Q3b8J-.d.ts +0 -427
  552. package/dist/channel-core-Bj71kAB5.d.ts +0 -6
  553. package/dist/channel-core-DMvyWnHg.js +0 -5
  554. package/dist/channel-entry-contract-zYxRmEdf.d.ts +0 -114
  555. package/dist/channel-inbound-DVJzBcJ8.d.ts +0 -97
  556. package/dist/channel-inbound-DlCa7eJe.js +0 -121
  557. package/dist/channel-message-CyPGMMFB.js +0 -12
  558. package/dist/channel-message-Czl4cdoA.d.ts +0 -9
  559. package/dist/channel-outbound-BNbhmruA.d.ts +0 -325
  560. package/dist/channel-pairing-BiS-tSvl.d.ts +0 -58
  561. package/dist/channel-runtime-D8hntg7H.js +0 -7
  562. package/dist/channel.runtime-DxErReJR.js +0 -697
  563. package/dist/chat-BLA8ORQI.js +0 -3
  564. package/dist/chat-DWRXkuvU.js +0 -2940
  565. package/dist/chrome-DPwFYi-g.js +0 -1517
  566. package/dist/cli-compaction-YZpssARf.js +0 -363
  567. package/dist/cli-runner-D2OAqxu3.js +0 -597
  568. package/dist/cli-runner-DO4SORQf.js +0 -2
  569. package/dist/cli-runner.runtime-CNSIpbeT.js +0 -4
  570. package/dist/cli-runner.runtime-DAOYvpVQ.js +0 -3
  571. package/dist/command-registry-DpD0fb8D.js +0 -4
  572. package/dist/command-registry-core-Cl3tLG8G.js +0 -114
  573. package/dist/command-registry-nbP7c8RT.js +0 -9
  574. package/dist/command-status.runtime-BBuXTkq0.js +0 -90
  575. package/dist/commands-CR8MVvlD.d.ts +0 -117
  576. package/dist/commands-compact.runtime-BoafIjjg.js +0 -10
  577. package/dist/commands-handlers.runtime-D9jViG_x.js +0 -6327
  578. package/dist/commands-status-BqqJ7PVq.js +0 -16
  579. package/dist/commands-status-CMd41Vxf.js +0 -3
  580. package/dist/commands-status.runtime-CMd41Vxf.js +0 -3
  581. package/dist/commands-subagents-control.runtime-CU4I3A_n.js +0 -2
  582. package/dist/commands-system-prompt-CTtu1D3-.js +0 -2
  583. package/dist/commands-system-prompt-xswhORdM.js +0 -161
  584. package/dist/commands-types-B67CsqXf.d.ts +0 -132
  585. package/dist/commands.runtime-BUFhkrjQ.js +0 -175
  586. package/dist/compact-Dz_WvRkQ.js +0 -1165
  587. package/dist/compact.runtime-n-AKErni.js +0 -12
  588. package/dist/completion-cli-DJYs_L4_.js +0 -393
  589. package/dist/config-CFMbHJb0.js +0 -374
  590. package/dist/config-mutations-DCAloTKR.js +0 -161
  591. package/dist/config-schema-Drw1zrnG.d.ts +0 -20
  592. package/dist/context-engine-host-compat-4mNm1HCE.js +0 -2
  593. package/dist/context-engine-host-compat-BzJ7fUIn.js +0 -280
  594. package/dist/context-engine-lifecycle-V4PNQp6k.js +0 -627
  595. package/dist/control-auth-DG_cw-aN.js +0 -114
  596. package/dist/control-service-CurYipgK.js +0 -3
  597. package/dist/control-service-VyncoV7j.js +0 -40
  598. package/dist/control-ui/assets/activity-BvGWC_j9.js +0 -124
  599. package/dist/control-ui/assets/agents-XOPBFHre.js +0 -1030
  600. package/dist/control-ui/assets/channels-B3E6Zw4-.js +0 -120
  601. package/dist/control-ui/assets/cron-r1sJdAbI.js +0 -1016
  602. package/dist/control-ui/assets/debug-EJlC-Qxz.js +0 -97
  603. package/dist/control-ui/assets/index-DBWFWpqU.js +0 -7214
  604. package/dist/control-ui/assets/instances-DqYhTGuq.js +0 -57
  605. package/dist/control-ui/assets/nodes-CPozuEst.js +0 -444
  606. package/dist/control-ui/assets/sessions-vJlr6aBb.js +0 -425
  607. package/dist/control-ui/assets/skills-wNA5l4y0.js +0 -362
  608. package/dist/control-ui/assets/workboard-BwoP_UJU.js +0 -402
  609. package/dist/conversation-runtime-DgaABwHh.js +0 -31
  610. package/dist/core-BeBXdneV.js +0 -284
  611. package/dist/core-Chqb7X6l.d.ts +0 -223
  612. package/dist/core-api-BlK0FgBM.js +0 -2
  613. package/dist/core-api-pAvYk716.js +0 -5
  614. package/dist/crestodian-FeGTBqO1.js +0 -55
  615. package/dist/delegate-BjIjSU_E.d.ts +0 -30
  616. package/dist/deliver-CvtWN4Ey.d.ts +0 -111
  617. package/dist/delivery-queue-CQ-cj3KG.d.ts +0 -161
  618. package/dist/delivery-queue-runtime-ut7MG04m.d.ts +0 -9
  619. package/dist/detect-BjXPyrwn.js +0 -115
  620. package/dist/detect-C1xeIemQ.d.ts +0 -16
  621. package/dist/dialogue-BowVYhEC.js +0 -37
  622. package/dist/direct-dm-DoZZHpA0.d.ts +0 -79
  623. package/dist/directive-handling.fast-lane-hnmQ_CvD.js +0 -70
  624. package/dist/directive-handling.impl-Cai-CFS1.js +0 -2
  625. package/dist/directive-handling.impl-DY84qIfU.js +0 -823
  626. package/dist/directive-handling.model-selection-DASssLFQ.js +0 -122
  627. package/dist/directive-handling.persist.runtime-BY7tJUs2.js +0 -274
  628. package/dist/dispatch-D5iG5A8j.js +0 -2057
  629. package/dist/dispatch-acp-transcript.runtime-D3r16hbD.js +0 -40
  630. package/dist/dispatch-acp.runtime-CAIau5qX.js +0 -18
  631. package/dist/dispatcher-7-d2gw3J.js +0 -106
  632. package/dist/doctor-DD5YEMmf.js +0 -6
  633. package/dist/doctor-config-flow-CdlLHJmX.js +0 -1819
  634. package/dist/doctor-core-checks-6MP99TQG.js +0 -666
  635. package/dist/doctor-core-checks-Dm_o576z.js +0 -2
  636. package/dist/doctor-core-checks.runtime-B2qbKATd.js +0 -278
  637. package/dist/doctor-health-BKrhOv1v.js +0 -65
  638. package/dist/doctor-health-contributions-bIBLmw69.js +0 -874
  639. package/dist/doctor-lint-aOLOWli4.js +0 -95
  640. package/dist/doctor-state-integrity-23NQNNuo.js +0 -1257
  641. package/dist/draft-stream-controls-Bk1GVJ1l.d.ts +0 -159
  642. package/dist/embedded-agent-BeK8FhZr.d.ts +0 -5
  643. package/dist/embedded-agent-CNp_y7jW.js +0 -4074
  644. package/dist/embedded-agent-NEmNlXDR.js +0 -4
  645. package/dist/embedded-agent.runtime-hEby8P2s.js +0 -4
  646. package/dist/embedded-backend-BdbgfpBP.js +0 -1581
  647. package/dist/embedded-gateway-stub.runtime-ySZUA3Gy.js +0 -12
  648. package/dist/extensions/alibaba/fengming.plugin.json +0 -47
  649. package/dist/extensions/alibaba/index.d.ts +0 -12
  650. package/dist/extensions/alibaba/index.js +0 -13
  651. package/dist/extensions/alibaba/package.json +0 -15
  652. package/dist/extensions/alibaba/video-generation-provider.d.ts +0 -6
  653. package/dist/extensions/alibaba/video-generation-provider.js +0 -2
  654. package/dist/extensions/baichuan/fengming.plugin.json +0 -69
  655. package/dist/extensions/baichuan/index.d.ts +0 -11
  656. package/dist/extensions/baichuan/index.js +0 -45
  657. package/dist/extensions/baichuan/models.d.ts +0 -7
  658. package/dist/extensions/baichuan/models.js +0 -2
  659. package/dist/extensions/baichuan/onboard.d.ts +0 -5
  660. package/dist/extensions/baichuan/onboard.js +0 -2
  661. package/dist/extensions/baichuan/package.json +0 -15
  662. package/dist/extensions/baichuan/provider-catalog.d.ts +0 -2
  663. package/dist/extensions/baichuan/provider-catalog.js +0 -2
  664. package/dist/extensions/baichuan/provider-discovery.d.ts +0 -2
  665. package/dist/extensions/baichuan/provider-discovery.js +0 -5
  666. package/dist/extensions/byteplus/api.d.ts +0 -3
  667. package/dist/extensions/byteplus/api.js +0 -3
  668. package/dist/extensions/byteplus/fengming.plugin.json +0 -196
  669. package/dist/extensions/byteplus/index.d.ts +0 -12
  670. package/dist/extensions/byteplus/index.js +0 -85
  671. package/dist/extensions/byteplus/models.d.ts +0 -2
  672. package/dist/extensions/byteplus/models.js +0 -2
  673. package/dist/extensions/byteplus/package.json +0 -15
  674. package/dist/extensions/byteplus/provider-catalog.d.ts +0 -2
  675. package/dist/extensions/byteplus/provider-catalog.js +0 -2
  676. package/dist/extensions/byteplus/provider-discovery.d.ts +0 -5
  677. package/dist/extensions/byteplus/provider-discovery.js +0 -23
  678. package/dist/extensions/byteplus/video-generation-provider.d.ts +0 -6
  679. package/dist/extensions/byteplus/video-generation-provider.js +0 -2
  680. package/dist/extensions/longcat/fengming.plugin.json +0 -84
  681. package/dist/extensions/longcat/index.d.ts +0 -11
  682. package/dist/extensions/longcat/index.js +0 -45
  683. package/dist/extensions/longcat/models.d.ts +0 -7
  684. package/dist/extensions/longcat/models.js +0 -2
  685. package/dist/extensions/longcat/onboard.d.ts +0 -5
  686. package/dist/extensions/longcat/onboard.js +0 -2
  687. package/dist/extensions/longcat/package.json +0 -15
  688. package/dist/extensions/longcat/provider-catalog.d.ts +0 -2
  689. package/dist/extensions/longcat/provider-catalog.js +0 -2
  690. package/dist/extensions/longcat/provider-discovery.d.ts +0 -2
  691. package/dist/extensions/longcat/provider-discovery.js +0 -5
  692. package/dist/extensions/minimax/api.d.ts +0 -5
  693. package/dist/extensions/minimax/api.js +0 -6
  694. package/dist/extensions/minimax/fengming.plugin.json +0 -206
  695. package/dist/extensions/minimax/image-generation-provider.d.ts +0 -6
  696. package/dist/extensions/minimax/image-generation-provider.js +0 -2
  697. package/dist/extensions/minimax/index.d.ts +0 -12
  698. package/dist/extensions/minimax/index.js +0 -29
  699. package/dist/extensions/minimax/media-understanding-provider.d.ts +0 -6
  700. package/dist/extensions/minimax/media-understanding-provider.js +0 -2
  701. package/dist/extensions/minimax/model-definitions.d.ts +0 -2
  702. package/dist/extensions/minimax/model-definitions.js +0 -2
  703. package/dist/extensions/minimax/music-generation-provider.d.ts +0 -6
  704. package/dist/extensions/minimax/music-generation-provider.js +0 -2
  705. package/dist/extensions/minimax/oauth.d.ts +0 -2
  706. package/dist/extensions/minimax/oauth.js +0 -2
  707. package/dist/extensions/minimax/oauth.runtime.d.ts +0 -2
  708. package/dist/extensions/minimax/oauth.runtime.js +0 -2
  709. package/dist/extensions/minimax/onboard.d.ts +0 -2
  710. package/dist/extensions/minimax/onboard.js +0 -2
  711. package/dist/extensions/minimax/package.json +0 -15
  712. package/dist/extensions/minimax/provider-catalog.d.ts +0 -2
  713. package/dist/extensions/minimax/provider-catalog.js +0 -2
  714. package/dist/extensions/minimax/provider-contract-api.d.ts +0 -6
  715. package/dist/extensions/minimax/provider-contract-api.js +0 -77
  716. package/dist/extensions/minimax/provider-discovery.d.ts +0 -5
  717. package/dist/extensions/minimax/provider-discovery.js +0 -23
  718. package/dist/extensions/minimax/provider-models.d.ts +0 -2
  719. package/dist/extensions/minimax/provider-models.js +0 -2
  720. package/dist/extensions/minimax/provider-registration.d.ts +0 -7
  721. package/dist/extensions/minimax/provider-registration.js +0 -2
  722. package/dist/extensions/minimax/speech-provider.d.ts +0 -5
  723. package/dist/extensions/minimax/speech-provider.js +0 -2
  724. package/dist/extensions/minimax/tts.d.ts +0 -20
  725. package/dist/extensions/minimax/tts.js +0 -2
  726. package/dist/extensions/minimax/video-generation-provider.d.ts +0 -7
  727. package/dist/extensions/minimax/video-generation-provider.js +0 -2
  728. package/dist/extensions/minimax/web-search-contract-api.d.ts +0 -5
  729. package/dist/extensions/minimax/web-search-contract-api.js +0 -31
  730. package/dist/extensions/minimax/web-search-provider.d.ts +0 -5
  731. package/dist/extensions/minimax/web-search-provider.js +0 -2
  732. package/dist/extensions/moonshot/api.d.ts +0 -3
  733. package/dist/extensions/moonshot/api.js +0 -4
  734. package/dist/extensions/moonshot/fengming.plugin.json +0 -250
  735. package/dist/extensions/moonshot/index.d.ts +0 -11
  736. package/dist/extensions/moonshot/index.js +0 -70
  737. package/dist/extensions/moonshot/media-understanding-provider.d.ts +0 -6
  738. package/dist/extensions/moonshot/media-understanding-provider.js +0 -2
  739. package/dist/extensions/moonshot/onboard.d.ts +0 -2
  740. package/dist/extensions/moonshot/onboard.js +0 -2
  741. package/dist/extensions/moonshot/package.json +0 -15
  742. package/dist/extensions/moonshot/provider-catalog.d.ts +0 -2
  743. package/dist/extensions/moonshot/provider-catalog.js +0 -2
  744. package/dist/extensions/moonshot/provider-contract-api.d.ts +0 -5
  745. package/dist/extensions/moonshot/provider-contract-api.js +0 -27
  746. package/dist/extensions/moonshot/provider-discovery.d.ts +0 -5
  747. package/dist/extensions/moonshot/provider-discovery.js +0 -15
  748. package/dist/extensions/moonshot/web-search-contract-api.d.ts +0 -5
  749. package/dist/extensions/moonshot/web-search-contract-api.js +0 -29
  750. package/dist/extensions/moonshot/web-search-provider.d.ts +0 -5
  751. package/dist/extensions/moonshot/web-search-provider.js +0 -2
  752. package/dist/extensions/qianfan/api.d.ts +0 -3
  753. package/dist/extensions/qianfan/api.js +0 -3
  754. package/dist/extensions/qianfan/fengming.plugin.json +0 -89
  755. package/dist/extensions/qianfan/index.d.ts +0 -11
  756. package/dist/extensions/qianfan/index.js +0 -26
  757. package/dist/extensions/qianfan/onboard.d.ts +0 -2
  758. package/dist/extensions/qianfan/onboard.js +0 -2
  759. package/dist/extensions/qianfan/package.json +0 -15
  760. package/dist/extensions/qianfan/provider-catalog.d.ts +0 -2
  761. package/dist/extensions/qianfan/provider-catalog.js +0 -2
  762. package/dist/extensions/qwen/api.d.ts +0 -4
  763. package/dist/extensions/qwen/api.js +0 -5
  764. package/dist/extensions/qwen/fengming.plugin.json +0 -389
  765. package/dist/extensions/qwen/index.d.ts +0 -11
  766. package/dist/extensions/qwen/index.js +0 -202
  767. package/dist/extensions/qwen/media-understanding-provider.d.ts +0 -6
  768. package/dist/extensions/qwen/media-understanding-provider.js +0 -2
  769. package/dist/extensions/qwen/model-definitions.d.ts +0 -2
  770. package/dist/extensions/qwen/model-definitions.js +0 -2
  771. package/dist/extensions/qwen/models.d.ts +0 -2
  772. package/dist/extensions/qwen/models.js +0 -2
  773. package/dist/extensions/qwen/onboard.d.ts +0 -21
  774. package/dist/extensions/qwen/onboard.js +0 -2
  775. package/dist/extensions/qwen/package.json +0 -15
  776. package/dist/extensions/qwen/provider-catalog.d.ts +0 -2
  777. package/dist/extensions/qwen/provider-catalog.js +0 -2
  778. package/dist/extensions/qwen/stream.d.ts +0 -2
  779. package/dist/extensions/qwen/stream.js +0 -2
  780. package/dist/extensions/qwen/video-generation-provider.d.ts +0 -6
  781. package/dist/extensions/qwen/video-generation-provider.js +0 -2
  782. package/dist/extensions/sensenova/fengming.plugin.json +0 -69
  783. package/dist/extensions/sensenova/index.d.ts +0 -11
  784. package/dist/extensions/sensenova/index.js +0 -45
  785. package/dist/extensions/sensenova/models.d.ts +0 -7
  786. package/dist/extensions/sensenova/models.js +0 -2
  787. package/dist/extensions/sensenova/onboard.d.ts +0 -5
  788. package/dist/extensions/sensenova/onboard.js +0 -2
  789. package/dist/extensions/sensenova/package.json +0 -15
  790. package/dist/extensions/sensenova/provider-catalog.d.ts +0 -2
  791. package/dist/extensions/sensenova/provider-catalog.js +0 -2
  792. package/dist/extensions/sensenova/provider-discovery.d.ts +0 -2
  793. package/dist/extensions/sensenova/provider-discovery.js +0 -5
  794. package/dist/extensions/stepfun/fengming.plugin.json +0 -162
  795. package/dist/extensions/stepfun/index.d.ts +0 -12
  796. package/dist/extensions/stepfun/index.js +0 -165
  797. package/dist/extensions/stepfun/onboard.d.ts +0 -7
  798. package/dist/extensions/stepfun/onboard.js +0 -2
  799. package/dist/extensions/stepfun/package.json +0 -15
  800. package/dist/extensions/stepfun/provider-catalog.d.ts +0 -14
  801. package/dist/extensions/stepfun/provider-catalog.js +0 -2
  802. package/dist/extensions/tencent/api.d.ts +0 -3
  803. package/dist/extensions/tencent/api.js +0 -4
  804. package/dist/extensions/tencent/fengming.plugin.json +0 -105
  805. package/dist/extensions/tencent/index.d.ts +0 -12
  806. package/dist/extensions/tencent/index.js +0 -62
  807. package/dist/extensions/tencent/models.d.ts +0 -2
  808. package/dist/extensions/tencent/models.js +0 -2
  809. package/dist/extensions/tencent/onboard.d.ts +0 -6
  810. package/dist/extensions/tencent/onboard.js +0 -2
  811. package/dist/extensions/tencent/package.json +0 -15
  812. package/dist/extensions/tencent/provider-catalog.d.ts +0 -2
  813. package/dist/extensions/tencent/provider-catalog.js +0 -2
  814. package/dist/extensions/tencent/provider-discovery.d.ts +0 -5
  815. package/dist/extensions/tencent/provider-discovery.js +0 -14
  816. package/dist/extensions/tiangong/fengming.plugin.json +0 -69
  817. package/dist/extensions/tiangong/index.d.ts +0 -11
  818. package/dist/extensions/tiangong/index.js +0 -45
  819. package/dist/extensions/tiangong/models.d.ts +0 -7
  820. package/dist/extensions/tiangong/models.js +0 -2
  821. package/dist/extensions/tiangong/onboard.d.ts +0 -5
  822. package/dist/extensions/tiangong/onboard.js +0 -2
  823. package/dist/extensions/tiangong/package.json +0 -15
  824. package/dist/extensions/tiangong/provider-catalog.d.ts +0 -2
  825. package/dist/extensions/tiangong/provider-catalog.js +0 -2
  826. package/dist/extensions/tiangong/provider-discovery.d.ts +0 -2
  827. package/dist/extensions/tiangong/provider-discovery.js +0 -5
  828. package/dist/extensions/volcengine/api.d.ts +0 -12
  829. package/dist/extensions/volcengine/api.js +0 -4
  830. package/dist/extensions/volcengine/fengming.plugin.json +0 -263
  831. package/dist/extensions/volcengine/index.d.ts +0 -12
  832. package/dist/extensions/volcengine/index.js +0 -88
  833. package/dist/extensions/volcengine/models.d.ts +0 -2
  834. package/dist/extensions/volcengine/models.js +0 -2
  835. package/dist/extensions/volcengine/package.json +0 -15
  836. package/dist/extensions/volcengine/provider-catalog.d.ts +0 -2
  837. package/dist/extensions/volcengine/provider-catalog.js +0 -2
  838. package/dist/extensions/volcengine/provider-discovery.d.ts +0 -5
  839. package/dist/extensions/volcengine/provider-discovery.js +0 -23
  840. package/dist/extensions/volcengine/speech-provider.d.ts +0 -5
  841. package/dist/extensions/volcengine/speech-provider.js +0 -2
  842. package/dist/extensions/volcengine/tts.d.ts +0 -22
  843. package/dist/extensions/volcengine/tts.js +0 -2
  844. package/dist/extensions/weixin/fengming.plugin.json +0 -22
  845. package/dist/extensions/weixin/index.d.ts +0 -26
  846. package/dist/extensions/weixin/index.js +0 -862
  847. package/dist/extensions/weixin/package.json +0 -45
  848. package/dist/extensions/xiaomi/api.d.ts +0 -3
  849. package/dist/extensions/xiaomi/api.js +0 -3
  850. package/dist/extensions/xiaomi/fengming.plugin.json +0 -260
  851. package/dist/extensions/xiaomi/index.d.ts +0 -12
  852. package/dist/extensions/xiaomi/index.js +0 -284
  853. package/dist/extensions/xiaomi/onboard.d.ts +0 -2
  854. package/dist/extensions/xiaomi/onboard.js +0 -2
  855. package/dist/extensions/xiaomi/package.json +0 -15
  856. package/dist/extensions/xiaomi/provider-catalog.d.ts +0 -2
  857. package/dist/extensions/xiaomi/provider-catalog.js +0 -2
  858. package/dist/extensions/xiaomi/speech-provider.d.ts +0 -5
  859. package/dist/extensions/xiaomi/speech-provider.js +0 -2
  860. package/dist/extensions/xiaomi/stream.d.ts +0 -5
  861. package/dist/extensions/xiaomi/stream.js +0 -2
  862. package/dist/extensions/xiaomi/thinking.d.ts +0 -11
  863. package/dist/extensions/xiaomi/thinking.js +0 -2
  864. package/dist/extensions/xingchen/fengming.plugin.json +0 -69
  865. package/dist/extensions/xingchen/index.d.ts +0 -11
  866. package/dist/extensions/xingchen/index.js +0 -45
  867. package/dist/extensions/xingchen/models.d.ts +0 -7
  868. package/dist/extensions/xingchen/models.js +0 -2
  869. package/dist/extensions/xingchen/onboard.d.ts +0 -5
  870. package/dist/extensions/xingchen/onboard.js +0 -2
  871. package/dist/extensions/xingchen/package.json +0 -15
  872. package/dist/extensions/xingchen/provider-catalog.d.ts +0 -2
  873. package/dist/extensions/xingchen/provider-catalog.js +0 -2
  874. package/dist/extensions/xingchen/provider-discovery.d.ts +0 -2
  875. package/dist/extensions/xingchen/provider-discovery.js +0 -5
  876. package/dist/extensions/yi/fengming.plugin.json +0 -84
  877. package/dist/extensions/yi/index.d.ts +0 -11
  878. package/dist/extensions/yi/index.js +0 -45
  879. package/dist/extensions/yi/models.d.ts +0 -7
  880. package/dist/extensions/yi/models.js +0 -2
  881. package/dist/extensions/yi/onboard.d.ts +0 -5
  882. package/dist/extensions/yi/onboard.js +0 -2
  883. package/dist/extensions/yi/package.json +0 -15
  884. package/dist/extensions/yi/provider-catalog.d.ts +0 -2
  885. package/dist/extensions/yi/provider-catalog.js +0 -2
  886. package/dist/extensions/yi/provider-discovery.d.ts +0 -2
  887. package/dist/extensions/yi/provider-discovery.js +0 -5
  888. package/dist/extensions/zai/api.d.ts +0 -4
  889. package/dist/extensions/zai/api.js +0 -4
  890. package/dist/extensions/zai/detect.d.ts +0 -2
  891. package/dist/extensions/zai/detect.js +0 -2
  892. package/dist/extensions/zai/fengming.plugin.json +0 -377
  893. package/dist/extensions/zai/index.d.ts +0 -12
  894. package/dist/extensions/zai/index.js +0 -297
  895. package/dist/extensions/zai/media-understanding-provider.d.ts +0 -5
  896. package/dist/extensions/zai/media-understanding-provider.js +0 -2
  897. package/dist/extensions/zai/model-definitions.d.ts +0 -2
  898. package/dist/extensions/zai/model-definitions.js +0 -2
  899. package/dist/extensions/zai/onboard.d.ts +0 -2
  900. package/dist/extensions/zai/onboard.js +0 -2
  901. package/dist/extensions/zai/package.json +0 -15
  902. package/dist/extensions/zai/runtime-api.d.ts +0 -2
  903. package/dist/extensions/zai/runtime-api.js +0 -2
  904. package/dist/extensions/zhinao/fengming.plugin.json +0 -69
  905. package/dist/extensions/zhinao/index.d.ts +0 -11
  906. package/dist/extensions/zhinao/index.js +0 -45
  907. package/dist/extensions/zhinao/models.d.ts +0 -7
  908. package/dist/extensions/zhinao/models.js +0 -2
  909. package/dist/extensions/zhinao/onboard.d.ts +0 -5
  910. package/dist/extensions/zhinao/onboard.js +0 -2
  911. package/dist/extensions/zhinao/package.json +0 -15
  912. package/dist/extensions/zhinao/provider-catalog.d.ts +0 -2
  913. package/dist/extensions/zhinao/provider-catalog.js +0 -2
  914. package/dist/extensions/zhinao/provider-discovery.d.ts +0 -2
  915. package/dist/extensions/zhinao/provider-discovery.js +0 -5
  916. package/dist/fengming-runtime-0jdu_329.d.ts +0 -153
  917. package/dist/fengming-tools-gQkwsWYz.js +0 -12221
  918. package/dist/fengming.plugin-C-Kdi1_5.js +0 -130
  919. package/dist/fengming.plugin-CRPqMj85.js +0 -166
  920. package/dist/gateway-cli-BV1V43-D.js +0 -443
  921. package/dist/gateway-method-runtime-J2OPP_oH.js +0 -21
  922. package/dist/get-reply-BE8ZGJos.js +0 -5198
  923. package/dist/get-reply-from-config.runtime-C5wfxVI_.js +0 -2
  924. package/dist/heartbeat-runner-_0HlObMb.js +0 -5
  925. package/dist/heartbeat-runner.runtime-DvYz_4Z3.js +0 -3
  926. package/dist/hook-runtime-BH9moP5T.js +0 -4
  927. package/dist/hooks-icCwsmrQ.js +0 -536
  928. package/dist/host-compat-dfJvEfe7.d.ts +0 -21
  929. package/dist/http-registry-Buj7R-F_.d.ts +0 -23
  930. package/dist/image-generation-provider-hrRXkkGc.js +0 -152
  931. package/dist/inbound-reply-dispatch-5AYt56Yt.js +0 -147
  932. package/dist/inbound-reply-dispatch-B5weFW8i.js +0 -2
  933. package/dist/inbound-reply-dispatch-cJh4H31y.d.ts +0 -156
  934. package/dist/index-DbpfOFUf.d.ts +0 -1497
  935. package/dist/infra-runtime-3_0R8nmO.js +0 -32
  936. package/dist/init-BnfkYG_k.js +0 -59
  937. package/dist/interactive-V8NfYsTW.d.ts +0 -26
  938. package/dist/isolated-agent-CgH7dfOj.js +0 -1097
  939. package/dist/isolated-agent-dBWkiw0a.js +0 -2
  940. package/dist/kernel-Ds2aqAJF.d.ts +0 -241
  941. package/dist/kimi-web-search-provider-QJT3Ftj3.js +0 -80
  942. package/dist/kimi-web-search-provider.runtime-Dj3SS4T5.js +0 -307
  943. package/dist/kimi-web-search-provider.runtime.js +0 -1
  944. package/dist/lib-Dg4yjNFQ.js +0 -871
  945. package/dist/lifecycle-B9k7QGsS.js +0 -570
  946. package/dist/list.probe-CbVHFNwf.js +0 -2
  947. package/dist/list.probe-CxiEBmyW.js +0 -451
  948. package/dist/list.status-command-DE-edGgB.js +0 -815
  949. package/dist/llm-slug-generator-DJgq9eFd.js +0 -78
  950. package/dist/loader-5AqYM9PC.d.ts +0 -142
  951. package/dist/local-dispatch.runtime-D3F4v51B.js +0 -10
  952. package/dist/manager-BWf1ks-Z.d.ts +0 -409
  953. package/dist/mcp-http-DU7Nsg4P.js +0 -583
  954. package/dist/mcp-http-iZCW6Cet.js +0 -2
  955. package/dist/media-runtime-DZ5RpQN7.d.ts +0 -261
  956. package/dist/media-understanding-DEdEyoQB.d.ts +0 -46
  957. package/dist/media-understanding-provider-4JHrQOUE.js +0 -70
  958. package/dist/media-understanding-provider-BV7O82XV.js +0 -29
  959. package/dist/media-understanding-provider-BlPRhYkx.js +0 -69
  960. package/dist/media-understanding-provider-BuX8eQLj.js +0 -13
  961. package/dist/memory-core-host-engine-embeddings-BDu5fx8E.d.ts +0 -324
  962. package/dist/memory-core-host-engine-storage-CdCuH-E2.d.ts +0 -54
  963. package/dist/message-handler-L6QLWNVP.js +0 -1806
  964. package/dist/minimax-web-search-provider-_gxeEOy8.js +0 -58
  965. package/dist/minimax-web-search-provider.runtime-BF4mGi6U.js +0 -148
  966. package/dist/minimax-web-search-provider.runtime.js +0 -1
  967. package/dist/model-catalog-DCnRkX8f.d.ts +0 -88
  968. package/dist/model-definitions-B2gY43hI.d.ts +0 -34
  969. package/dist/model-definitions-BLOyeH5h.js +0 -73
  970. package/dist/model-definitions-CoByf5mT.js +0 -243
  971. package/dist/model-definitions-WP3OmzbS.d.ts +0 -57
  972. package/dist/model-selection-DhTE6GZD.js +0 -352
  973. package/dist/models--iAR9QkZ.js +0 -175
  974. package/dist/models-8ImVEkvh.js +0 -36
  975. package/dist/models-BIDM8htk.js +0 -48
  976. package/dist/models-BRgRfrcS.js +0 -36
  977. package/dist/models-Bib5-APc.js +0 -67
  978. package/dist/models-Bl67zOoe.js +0 -36
  979. package/dist/models-BqDDYFE3.d.ts +0 -65
  980. package/dist/models-BtRQoRIu.js +0 -36
  981. package/dist/models-BvXmOXik.js +0 -48
  982. package/dist/models-C-sJciOD.d.ts +0 -9
  983. package/dist/models-COnXPdlL.js +0 -24
  984. package/dist/models-CXTmk-Da.d.ts +0 -8
  985. package/dist/models-Cz0C_8re.js +0 -36
  986. package/dist/models-DbwEIt-m.d.ts +0 -15
  987. package/dist/models-DgXkSADi.js +0 -30
  988. package/dist/models-cli-Bv3y3JgQ.js +0 -257
  989. package/dist/monitor-BiVOsbbN.js +0 -1024
  990. package/dist/monitor-BumfRp1t.js +0 -60
  991. package/dist/monitor.account-Cd6EwtuZ.js +0 -5382
  992. package/dist/music-generation-provider-ZdDMiC-c.js +0 -308
  993. package/dist/nodes-C0f8XgD5.js +0 -1483
  994. package/dist/nodes-Dk4vOgg9.js +0 -3
  995. package/dist/nodes-pending-Cjg09MXz.js +0 -211
  996. package/dist/oauth-BIO69Qw0.d.ts +0 -25
  997. package/dist/oauth-CnO10TN2.js +0 -207
  998. package/dist/onboard-B3BYT5k7.js +0 -34
  999. package/dist/onboard-BDMNV6RE.js +0 -23
  1000. package/dist/onboard-B_WNNy5F.d.ts +0 -6
  1001. package/dist/onboard-BbyMaErU.js +0 -69
  1002. package/dist/onboard-BuYPNE6j2.js +0 -23
  1003. package/dist/onboard-C394zMnM.d.ts +0 -11
  1004. package/dist/onboard-CHn4oVbY.js +0 -24
  1005. package/dist/onboard-CPpVbb0O.js +0 -73
  1006. package/dist/onboard-CWDx7Crt.js +0 -23
  1007. package/dist/onboard-CbzkwBzu.d.ts +0 -12
  1008. package/dist/onboard-D099qUd0.js +0 -23
  1009. package/dist/onboard-D7dbzfHc.js +0 -23
  1010. package/dist/onboard-DB-x0nHF.js +0 -30
  1011. package/dist/onboard-DFVrRnxJ.js +0 -23
  1012. package/dist/onboard-DFiqoOc2.d.ts +0 -7
  1013. package/dist/onboard-DJaMK3rr.d.ts +0 -6
  1014. package/dist/onboard-DMdK8D_h.js +0 -67
  1015. package/dist/onboard-J-KL-I6m.js +0 -48
  1016. package/dist/onboard-MIBU-Rmv.js +0 -39
  1017. package/dist/onboard-vmGylfFe.js +0 -23
  1018. package/dist/openai-compat-errors-Dcr5Y8bF.js +0 -136
  1019. package/dist/openai-http-CcqspzU6.js +0 -836
  1020. package/dist/openresponses-http-BnyYYvUF.js +0 -1175
  1021. package/dist/operations-H2Oq0KYz.js +0 -805
  1022. package/dist/outbound.types-BhRehecY.d.ts +0 -291
  1023. package/dist/plugin-enabled-CEIKWKrq.js +0 -232
  1024. package/dist/plugin-entry-CTVRRaaA.d.ts +0 -47
  1025. package/dist/plugin-registration-BTyO5Fwt.js +0 -97
  1026. package/dist/plugin-runtime-_XF2N_UQ.d.ts +0 -117
  1027. package/dist/plugin-sdk/bundled-channel-config-schema-BsOWCrJT.d.ts +0 -3169
  1028. package/dist/plugin-service-B91jVlmZ.d.ts +0 -24
  1029. package/dist/plugin-service-CtGwVz8V.js +0 -1249
  1030. package/dist/postinstall-inventory.json +0 -5410
  1031. package/dist/prepare.runtime-9dlboph7.js +0 -798
  1032. package/dist/preview-warnings-DJx4KJpC.js +0 -618
  1033. package/dist/program-CWC-NBBB.js +0 -131
  1034. package/dist/provider-api-key-auth-BmNcYRMl.d.ts +0 -27
  1035. package/dist/provider-auth-api-key-CCaFiqY3.js +0 -5
  1036. package/dist/provider-auth-result-D_E9dcVc.d.ts +0 -21
  1037. package/dist/provider-catalog-5KZLmrDO.js +0 -11
  1038. package/dist/provider-catalog-7P6AvDzS.js +0 -11
  1039. package/dist/provider-catalog-B2gyTjTU.js +0 -88
  1040. package/dist/provider-catalog-B3YBhe77.js +0 -17
  1041. package/dist/provider-catalog-B7XEeuUm.js +0 -11
  1042. package/dist/provider-catalog-BFGPRd9v.js +0 -17
  1043. package/dist/provider-catalog-BLvkIMSk.d.ts +0 -6
  1044. package/dist/provider-catalog-BPBL9mJf.d.ts +0 -5
  1045. package/dist/provider-catalog-BRkZ6-HD.d.ts +0 -5
  1046. package/dist/provider-catalog-Bfl_AoTZ.js +0 -142
  1047. package/dist/provider-catalog-BpiHWHu1.js +0 -11
  1048. package/dist/provider-catalog-C1qDLekT.d.ts +0 -5
  1049. package/dist/provider-catalog-CKWNCfry.js +0 -11
  1050. package/dist/provider-catalog-CUHB2pSt.d.ts +0 -7
  1051. package/dist/provider-catalog-CWqN2j6J.d.ts +0 -5
  1052. package/dist/provider-catalog-CZ8oYbx3.js +0 -11
  1053. package/dist/provider-catalog-CcQ5-4ZW.d.ts +0 -6
  1054. package/dist/provider-catalog-Cd16uZ0U.js +0 -20
  1055. package/dist/provider-catalog-CpF2D0VK.js +0 -61
  1056. package/dist/provider-catalog-CvXq36zW.d.ts +0 -5
  1057. package/dist/provider-catalog-D2pgEME3.js +0 -48
  1058. package/dist/provider-catalog-DPzcupEl.d.ts +0 -5
  1059. package/dist/provider-catalog-DaeI606G.d.ts +0 -9
  1060. package/dist/provider-catalog-DrOCtTb-.js +0 -11
  1061. package/dist/provider-catalog-DwZ1J2Al.d.ts +0 -6
  1062. package/dist/provider-catalog-Dy7IcHmS.js +0 -107
  1063. package/dist/provider-catalog-TsZS52nq.d.ts +0 -10
  1064. package/dist/provider-catalog-YqIFRCND.d.ts +0 -5
  1065. package/dist/provider-catalog-Ywb5jRwG.d.ts +0 -5
  1066. package/dist/provider-catalog-evknl1oN.js +0 -11
  1067. package/dist/provider-catalog-l0hFpFO2.d.ts +0 -17
  1068. package/dist/provider-catalog-shared-DsRBv0Tp.d.ts +0 -62
  1069. package/dist/provider-dispatcher-BMy9mBJ1.js +0 -22
  1070. package/dist/provider-model-shared-CPAfQBNs.d.ts +0 -143
  1071. package/dist/provider-models-Diu65OcG.d.ts +0 -18
  1072. package/dist/provider-models-LE7PlLYY.js +0 -22
  1073. package/dist/provider-onboard-CpvXEmvz.d.ts +0 -91
  1074. package/dist/provider-registration-DF-LkmNE.js +0 -235
  1075. package/dist/provider-registry-D9cTPW1F.d.ts +0 -8
  1076. package/dist/provider-registry-DI7gMKUP.d.ts +0 -8
  1077. package/dist/provider-registry-DZtgZDkl.d.ts +0 -29
  1078. package/dist/provider-self-hosted-setup-CoHvoyKm.d.ts +0 -74
  1079. package/dist/provider-stream-BpXJr5Ap.d.ts +0 -139
  1080. package/dist/provider-stream-family-Bj5aBD8w.js +0 -2
  1081. package/dist/provider-stream-shared-BaUkhUHj.d.ts +0 -132
  1082. package/dist/provider-usage-DFUhW2do.js +0 -651
  1083. package/dist/provider-web-search-contract-fields-CkXzSsWu.d.ts +0 -25
  1084. package/dist/pw-ai-9Q_dIq4B.js +0 -3064
  1085. package/dist/register.agent-CbfrlzXB.js +0 -152
  1086. package/dist/register.crestodian-CEg0rPfK.js +0 -24
  1087. package/dist/register.maintenance-k9N8I4Wg.js +0 -85
  1088. package/dist/register.subclis-CrXOeaS3.js +0 -3
  1089. package/dist/register.subclis-DfKlni8N.js +0 -31
  1090. package/dist/register.subclis-core-Bg4wbDsO.js +0 -278
  1091. package/dist/registry-Bh3-P2HL.d.ts +0 -8
  1092. package/dist/registry-types-BmEUS4d3.d.ts +0 -392
  1093. package/dist/repair-sequencing-E4yViXG9.js +0 -652
  1094. package/dist/reply-payload-S2mrc_Mh.d.ts +0 -200
  1095. package/dist/reply-turn-admission-BBoPjmGB.js +0 -2056
  1096. package/dist/reply.runtime-C5wfxVI_.js +0 -2
  1097. package/dist/result-fallback-classifier-CX4iLD1G.js +0 -98
  1098. package/dist/route-CifxcQZ1.js +0 -475
  1099. package/dist/routes-B3XAOeWo.js +0 -2
  1100. package/dist/routes-H185h3U-.js +0 -3701
  1101. package/dist/run-CTJFbwbB.js +0 -1162
  1102. package/dist/run-command-B7B53tYk.js +0 -23
  1103. package/dist/run-command-BFuxRDxS.js +0 -2
  1104. package/dist/run-context-C7im9ICg.js +0 -66
  1105. package/dist/run-embedded.runtime-TljBTbzh.js +0 -4
  1106. package/dist/run-execution-cli.runtime-Bt5zwx1W.js +0 -4
  1107. package/dist/run-executor.runtime-hmbWX2Ct.js +0 -330
  1108. package/dist/run-subagent-registry.runtime-B70X80nS.js +0 -2
  1109. package/dist/runtime-DoKE0o7v.js +0 -436
  1110. package/dist/runtime-api-Ca4Llbgf.js +0 -12
  1111. package/dist/runtime-api-pa8xcEmg.d.ts +0 -5
  1112. package/dist/runtime-channel-CFQ59svm.js +0 -148
  1113. package/dist/runtime-channel-DRwCWGUx.js +0 -2
  1114. package/dist/runtime-embedded-agent.runtime-DwmqKUVp.js +0 -2
  1115. package/dist/runtime-forwarders-BMThPHg_.d.ts +0 -39
  1116. package/dist/sdk-setup-tools-Cg_Tabrf.js +0 -8
  1117. package/dist/selection-COhr7g82.js +0 -18365
  1118. package/dist/selection-_G44EVqd.js +0 -3
  1119. package/dist/send-media-BNc67G7I.js +0 -2072
  1120. package/dist/server-5rR0RCpI.js +0 -24
  1121. package/dist/server-context-BhiPROPA.js +0 -955
  1122. package/dist/server-context-OShBAJZQ.js +0 -2
  1123. package/dist/server-cron-Bkzb9edh.js +0 -3173
  1124. package/dist/server-cron-DdR-ugiU.js +0 -2
  1125. package/dist/server-lwtC1vaS.js +0 -72
  1126. package/dist/server-methods-BY_ZqDFJ.js +0 -497
  1127. package/dist/server-node-events-CLvE94AS.js +0 -597
  1128. package/dist/server-plugin-bootstrap-cKOAH5GL.js +0 -71
  1129. package/dist/server-plugins-CPpUykw5.js +0 -435
  1130. package/dist/server-reload-handlers-uzt4VDZ-.js +0 -719
  1131. package/dist/server-restart-sentinel-CpvV0t4O.js +0 -700
  1132. package/dist/server-runtime-services-BhOHoerM.js +0 -147
  1133. package/dist/server-runtime-services-D3Ig68nC.js +0 -3
  1134. package/dist/server-startup-plugins-DslzKVHK.js +0 -127
  1135. package/dist/server-startup-post-attach-DPFBTQez.js +0 -793
  1136. package/dist/server-ws-runtime-D0zoWoiz.js +0 -374
  1137. package/dist/server.impl-CzqLQ3qt.js +0 -2622
  1138. package/dist/session-kill-http-D8JhwZVS.js +0 -121
  1139. package/dist/session-reset-service-uoi7E4Xp.js +0 -651
  1140. package/dist/session-status.runtime-CZK5IU8w.js +0 -2
  1141. package/dist/session-subagent-reactivation.runtime-BSO00-FY.js +0 -2
  1142. package/dist/session-tab-registry-DM9U7e3o.js +0 -551
  1143. package/dist/sessions-B-SkIoaa.js +0 -1917
  1144. package/dist/sessions-history-http-DCiOG4FK.js +0 -432
  1145. package/dist/sessions-patch-DlAAvQvB.js +0 -401
  1146. package/dist/sessions-resolve-DfMXookg.js +0 -180
  1147. package/dist/sessions.runtime-0V2YxKxB.js +0 -2
  1148. package/dist/snapshot-urls-Ble1-NEW.js +0 -317
  1149. package/dist/speech-core-Bk60ZS_y.d.ts +0 -49
  1150. package/dist/speech-provider-DQO9eZd0.js +0 -233
  1151. package/dist/speech-provider-DnBCla4V.js +0 -171
  1152. package/dist/speech-provider-DyYHFxT5.js +0 -227
  1153. package/dist/standalone-9EWfcxeO.js +0 -42
  1154. package/dist/startup-context-nti4X0_w.js +0 -314
  1155. package/dist/status-subagents.runtime-CPZb1EF1.js +0 -32
  1156. package/dist/status-text-C1Hf37lF.js +0 -301
  1157. package/dist/stream-9VBt1MDs.js +0 -26
  1158. package/dist/stream-B_3P7v7P.js +0 -86
  1159. package/dist/stream-CXsue2-v.d.ts +0 -9
  1160. package/dist/stream-oNBFxfKt.d.ts +0 -5
  1161. package/dist/subagent-announce-CPjQQLy8.js +0 -353
  1162. package/dist/subagent-announce-delivery-B6iBOicL.js +0 -1369
  1163. package/dist/subagent-control-DP72sk-l.js +0 -492
  1164. package/dist/subagent-hooks-B1oUIYH3.js +0 -2
  1165. package/dist/subagent-hooks-BkGj4_xI.js +0 -230
  1166. package/dist/subagent-hooks-api-D2mulK3S.js +0 -23
  1167. package/dist/subagent-registry-CEKAUB5h.js +0 -3
  1168. package/dist/subagent-registry-OUVucPAn.js +0 -2627
  1169. package/dist/subagent-session-cleanup-Bx8d3kw0.js +0 -390
  1170. package/dist/system-CelaP2zI.js +0 -111
  1171. package/dist/talk-DGOI3Lu3.js +0 -2454
  1172. package/dist/target-id-BXRG7x9x.js +0 -107
  1173. package/dist/thinking-B8V29FhB.js +0 -35
  1174. package/dist/thread-bindings-DpVdEPZ0.js +0 -228
  1175. package/dist/tool-DHzDpxE4.js +0 -143
  1176. package/dist/tool-dispatch-ClP3Rc7g.js +0 -155
  1177. package/dist/tool-resolution-CZcLod1d.js +0 -153
  1178. package/dist/tool-split-BhiQ8676.d.ts +0 -19
  1179. package/dist/tools-ZvSvbsCW.d.ts +0 -38
  1180. package/dist/tools-effective-C2mHZT-A.js +0 -442
  1181. package/dist/tools-effective-inventory-ctnM7hc6.js +0 -379
  1182. package/dist/tools-invoke-Ci6Rux2s.js +0 -51
  1183. package/dist/tools-invoke-http-CJflXcJk.js +0 -68
  1184. package/dist/tools-invoke-shared-BLu_mJEX.js +0 -200
  1185. package/dist/tts-B2rPJPij.js +0 -83
  1186. package/dist/tts-Gp9FI3_n.js +0 -163
  1187. package/dist/tts-runtime-DNi1HXPF.d.ts +0 -230
  1188. package/dist/tui-BUhfQ9vD.js +0 -3
  1189. package/dist/tui-BhH5mvLf.js +0 -2
  1190. package/dist/tui-backend-C_4ajTHI.js +0 -257
  1191. package/dist/tui-cli-BhWJ-QoB.js +0 -40
  1192. package/dist/tui-ink-run-BTWbUQGb.js +0 -7414
  1193. package/dist/tui-ink-run-DfTdivkh.js +0 -2
  1194. package/dist/types-B4fW3r5y.d.ts +0 -111
  1195. package/dist/types-DI62NfFe.d.ts +0 -7034
  1196. package/dist/types-sAih_uQb.d.ts +0 -393
  1197. package/dist/types.public-B3MKhuo2.d.ts +0 -70
  1198. package/dist/video-generation-B9c6a5cw.js +0 -207
  1199. package/dist/video-generation-BgJp7UIA.d.ts +0 -224
  1200. package/dist/video-generation-provider-BjiVjf40.js +0 -325
  1201. package/dist/video-generation-provider-CsnQJg_h.js +0 -297
  1202. package/dist/video-generation-provider-DtU-ZPqP.js +0 -64
  1203. package/dist/video-generation-provider-wZ0bzv0e.js +0 -77
  1204. package/dist/webhook-targets-Cy8e7y3g.d.ts +0 -99
  1205. package/dist/zod-schema.core-BGLctDlK.d.ts +0 -166
  1206. package/skills/canvas/SKILL.md +0 -78
  1207. package/skills/clawhub/SKILL.md +0 -77
  1208. package/skills/coding-agent/SKILL.md +0 -143
  1209. package/skills/diagram-maker/SKILL.md +0 -53
  1210. package/skills/diagram-maker/references/excalidraw-patterns.md +0 -85
  1211. package/skills/diagram-maker/references/svg-template.md +0 -112
  1212. package/skills/gemini/SKILL.md +0 -47
  1213. package/skills/gh-issues/SKILL.md +0 -213
  1214. package/skills/gifgrep/SKILL.md +0 -85
  1215. package/skills/github/SKILL.md +0 -84
  1216. package/skills/healthcheck/SKILL.md +0 -105
  1217. package/skills/mcporter/SKILL.md +0 -61
  1218. package/skills/meme-maker/SKILL.md +0 -42
  1219. package/skills/meme-maker/references/templates.json +0 -358
  1220. package/skills/meme-maker/scripts/meme.mjs +0 -398
  1221. package/skills/model-usage/SKILL.md +0 -71
  1222. package/skills/model-usage/references/codexbar-cli.md +0 -33
  1223. package/skills/model-usage/scripts/model_usage.py +0 -319
  1224. package/skills/model-usage/scripts/test_model_usage.py +0 -40
  1225. package/skills/nano-pdf/SKILL.md +0 -38
  1226. package/skills/node-connect/SKILL.md +0 -143
  1227. package/skills/node-inspect-debugger/SKILL.md +0 -85
  1228. package/skills/openai-whisper/SKILL.md +0 -38
  1229. package/skills/openai-whisper-api/SKILL.md +0 -71
  1230. package/skills/openai-whisper-api/scripts/transcribe.sh +0 -154
  1231. package/skills/oracle/SKILL.md +0 -126
  1232. package/skills/pyproject.toml +0 -10
  1233. package/skills/python-debugpy/SKILL.md +0 -73
  1234. package/skills/sag/SKILL.md +0 -87
  1235. package/skills/session-logs/SKILL.md +0 -151
  1236. package/skills/sherpa-onnx-tts/SKILL.md +0 -109
  1237. package/skills/sherpa-onnx-tts/bin/sherpa-onnx-tts +0 -178
  1238. package/skills/skill-creator/SKILL.md +0 -78
  1239. package/skills/skill-creator/license.txt +0 -202
  1240. package/skills/skill-creator/scripts/init_skill.py +0 -378
  1241. package/skills/skill-creator/scripts/package_skill.py +0 -139
  1242. package/skills/skill-creator/scripts/quick_validate.py +0 -169
  1243. package/skills/skill-creator/scripts/test_package_skill.py +0 -161
  1244. package/skills/skill-creator/scripts/test_quick_validate.py +0 -116
  1245. package/skills/spike/SKILL.md +0 -51
  1246. package/skills/summarize/SKILL.md +0 -87
  1247. package/skills/taskflow/SKILL.md +0 -149
  1248. package/skills/taskflow/examples/inbox-triage.lobster +0 -33
  1249. package/skills/taskflow/examples/pr-intake.lobster +0 -32
  1250. package/skills/taskflow-inbox-triage/SKILL.md +0 -119
  1251. package/skills/video-frames/SKILL.md +0 -46
  1252. package/skills/video-frames/scripts/frame.sh +0 -81
  1253. package/skills/voice-call/SKILL.md +0 -45
  1254. package/skills/weather/SKILL.md +0 -64
  1255. /package/dist/{acp-runtime-backend-DbchQ02o.js → acp-runtime-backend-DZ1Lnt7f.js} +0 -0
  1256. /package/dist/{delegate-k1aptKei.js → delegate-CwhxUdeb.js} +0 -0
  1257. /package/dist/{dispatch-acp-CD4YxPpf.js → dispatch-acp-BP4I5ZQf.js} +0 -0
  1258. /package/dist/{exec-approvals-ByWUCFQM.js → exec-approvals-ByWUCFQM2.js} +0 -0
  1259. /package/dist/{heartbeat-runner-CM0UZxa_.js → heartbeat-runner-CL3alQ8-.js} +0 -0
  1260. /package/dist/{index-B0VJdRJQ.d.ts → index-B0VJdRJQ2.d.ts} +0 -0
  1261. /package/dist/{library-CQ71yATP.js → library-CiTr_aqC.js} +0 -0
  1262. /package/dist/{run-session-state-DbDeH-q6.js → run-session-state-BOMUtBKZ.js} +0 -0
  1263. /package/dist/{session-subagent-reactivation-Bj91A2ms.js → session-subagent-reactivation-CH0C2I6Y.js} +0 -0
  1264. /package/dist/{types-C4HgagiY2.d.ts → types-C4HgagiY.d.ts} +0 -0
@@ -0,0 +1,2622 @@
1
+ import { c as normalizeOptionalString } from "./string-coerce-DKw2K5wM.js";
2
+ import { n as isVitestRuntimeEnv, r as logAcceptedEnvOption, t as isTruthyEnvValue } from "./env-CuDPoYuT.js";
3
+ import { S as resolveIntegerOption, _ as parseStrictPositiveInteger } from "./number-coercion-D1aDmIZp.js";
4
+ import { a as normalizeStateDirEnv, i as isNixMode } from "./paths-9MqJt9oL.js";
5
+ import { _ as uniqueStrings } from "./string-normalization-B8G0vlWE.js";
6
+ import { _ as sleep } from "./utils-v5zGdVpj.js";
7
+ import { E as runWithDiagnosticTraceContext, _ as createDiagnosticTraceContext, c as isDiagnosticsEnabled, m as setDiagnosticsEnabledForProcess } from "./diagnostic-events-Bwqd0ZOT.js";
8
+ import { r as runtimeForLogger, t as createSubsystemLogger } from "./subsystem-B7U-DPv3.js";
9
+ import { o as setCurrentPluginMetadataSnapshot } from "./current-plugin-metadata-snapshot-98AlXutr.js";
10
+ import { t as clearPluginMetadataLifecycleCaches } from "./plugin-metadata-lifecycle-BqWfg4Sp.js";
11
+ import { o as emitDiagnosticsTimelineEvent, s as isDiagnosticsTimelineEnabled } from "./plugin-metadata-snapshot-CHymO30I.js";
12
+ import { t as loadBundledPluginPublicArtifactModuleSync } from "./public-surface-loader-BxZUDpzM.js";
13
+ import { t as isContainerEnvironment } from "./container-environment-CNsJSTpY.js";
14
+ import { _ as resolveRequestClientIp, i as isLoopbackHost, m as resolveGatewayListenHosts } from "./net-DAt4-3lj.js";
15
+ import { a as createAuthRateLimiter } from "./auth-rate-limit-BvIq8WVd.js";
16
+ import { n as resolveGatewayAuth } from "./auth-resolve-DQPFGhog.js";
17
+ import { o as isLocalDirectRequest, r as authorizeHttpGatewayConnect } from "./auth-CLEZzwsq.js";
18
+ import { c as promoteConfigSnapshotToLastKnownGood, i as getRuntimeConfig, j as applyConfigOverrides, u as readConfigFileSnapshot, v as registerConfigWriteListener } from "./io-T1CV3Z1L.js";
19
+ import { v as setRuntimeConfigSnapshot } from "./runtime-snapshot-D93_HOsR.js";
20
+ import { n as isRestartEnabled } from "./commands.flags-BRADB-MQ.js";
21
+ import { t as loadGatewayTlsRuntime$1 } from "./gateway-CFSMSlU7.js";
22
+ import { n as createCoreGatewayMethodDescriptors, r as isCoreGatewayMethodClassified, s as listCoreGatewayMethodNames, t as STARTUP_UNAVAILABLE_GATEWAY_METHODS } from "./core-descriptors-B9yUgJ17.js";
23
+ import { i as READ_SCOPE, n as APPROVALS_SCOPE, o as WRITE_SCOPE, r as PAIRING_SCOPE, t as ADMIN_SCOPE } from "./operator-scopes-DGvgHuOd.js";
24
+ import "./method-scopes-CTk-6mpm.js";
25
+ import { h as setPreRestartDeferralCheck, m as setGatewaySigusr1RestartPolicy } from "./restart-CgwRFO_y.js";
26
+ import { n as readGatewayRestartHandoffSync } from "./restart-handoff-BUoVWhMZ.js";
27
+ import { d as pinActivePluginChannelRegistry, f as pinActivePluginHttpRouteRegistry, h as releasePinnedPluginHttpRouteRegistry, m as releasePinnedPluginChannelRegistry } from "./runtime-CQgf-ok4.js";
28
+ import { i as createPluginGatewayMethodDescriptors, n as createGatewayMethodRegistry, t as createGatewayMethodDescriptorsFromHandlers } from "./registry-BQNtQhdh.js";
29
+ import { i as resolveMainSessionKey } from "./main-session-BxJmPEXx.js";
30
+ import { n as getLoadedChannelPluginEntryById, r as listLoadedChannelPlugins } from "./registry-loaded-CP4VA-bv.js";
31
+ import "./sessions-CtMqsEs2.js";
32
+ import { a as enqueueSystemEvent } from "./system-events-DviB_CZO.js";
33
+ import { b as startDiagnosticHeartbeat, x as stopDiagnosticHeartbeat } from "./diagnostic-B66j5Hib.js";
34
+ import { i as withDiagnosticPhase } from "./diagnostic-phase-ewqU1V1-.js";
35
+ import { u as getActiveEmbeddedRunCount } from "./run-state-CU3dnr0T.js";
36
+ import { l as getTotalQueueSize } from "./command-queue-BdFPuMNt.js";
37
+ import { o as resolveCronStorePath } from "./store-DvIbNKvA.js";
38
+ import { n as clearSecretsRuntimeSnapshot, o as getActiveSecretsRuntimeSnapshot } from "./runtime-state-DdDHn4Yo.js";
39
+ import { o as setFallbackGatewayContextResolver } from "./server-plugins-Dwnaz9kX.js";
40
+ import { t as getTotalPendingReplies } from "./dispatcher-registry-CaTZukRA.js";
41
+ import { c as recordGatewayRestartTraceDetail, d as resumeGatewayRestartTraceFromHandoff, i as finishGatewayRestartTrace, l as recordGatewayRestartTraceSpan, n as collectGatewayProcessMemoryUsageMb, u as resumeGatewayRestartTraceFromEnv } from "./restart-trace-DqNfUyLD.js";
42
+ import { t as ensureFengMingCliOnPath } from "./path-env-DhfNx6TA.js";
43
+ import { n as logRejectedLargePayload } from "./diagnostic-payload-BP1TpHgP.js";
44
+ import { i as MAX_BUFFERED_BYTES, o as MAX_PREAUTH_PAYLOAD_BYTES } from "./server-constants-BGwLM6XN.js";
45
+ import { s as normalizePluginNodeCapabilityScopedUrl } from "./plugin-node-capability-DH-ae5Gb.js";
46
+ import { i as summarizeAgentEventForWsLog, n as logWs, r as shouldLogWs } from "./ws-log-BzGc41ZC.js";
47
+ import { t as createDefaultDeps } from "./deps-BExyLYPP.js";
48
+ import { c as setDefaultSecurityHeaders, r as sendGatewayAuthFailure } from "./http-common-Bwxkslgi.js";
49
+ import { t as GatewayLockError } from "./gateway-lock-DwP3jzVd.js";
50
+ import { n as DEFAULT_CHANNEL_STALE_EVENT_THRESHOLD_MS, r as evaluateChannelHealth, t as DEFAULT_CHANNEL_CONNECT_GRACE_MS } from "./channel-health-policy-D_eDwUBm.js";
51
+ import { c as resolveControlUiRootSync, n as isPackageProvenControlUiRootSync, s as resolveControlUiRootOverrideSync, t as ensureControlUiAssetsBuilt } from "./control-ui-assets-B-mD-U6l.js";
52
+ import { n as ensureControlUiAllowedOriginsForNonLoopbackBind } from "./gateway-control-ui-origins-Cr3qDWBG.js";
53
+ import { n as resolveAssistantIdentity } from "./assistant-identity-Q4krpxtt.js";
54
+ import { t as resolveSharedGatewaySessionGeneration } from "./ws-shared-generation-Bp5l7wzu.js";
55
+ import { i as getRequiredSharedGatewaySessionGeneration, r as enforceSharedGatewaySessionGenerationForConfigWrite } from "./server-shared-auth-generation-Csm1h6QK.js";
56
+ import { a as createToolEventRecipientRegistry, n as createChatRunState } from "./server-chat-state-B4ta4USz.js";
57
+ import { a as incrementPresenceVersion, i as getPresenceVersion, n as getHealthCache, o as refreshGatewayHealthSnapshot, r as getHealthVersion } from "./health-state-R9QouhXJ.js";
58
+ import { t as resolveGatewayPluginConfig } from "./runtime-plugin-config-CDc8wzhi.js";
59
+ import { n as applyGatewayLaneConcurrency, t as resolveHookClientIpConfig } from "./hook-client-ip-config-DEsjG7a7.js";
60
+ import { t as GATEWAY_EVENTS } from "./server-methods-list-D8PJ5m-Q.js";
61
+ import { n as isProtectedPluginRoutePathFromContext, r as resolvePluginRoutePathContext } from "./route-match-DdHHDhWl.js";
62
+ import { n as shouldEnforceGatewayAuthForPluginPath } from "./route-auth-2fSSQYKc.js";
63
+ import { t as findMatchingPluginNodeCapabilityRoute } from "./route-capability-DZXc1U_r.js";
64
+ import path from "node:path";
65
+ import { monitorEventLoopDelay, performance } from "node:perf_hooks";
66
+ import { WebSocketServer } from "ws";
67
+ import { createServer } from "node:http";
68
+ import { createServer as createServer$1 } from "node:https";
69
+ //#region src/gateway/plugin-channel-reload-targets.ts
70
+ function addNormalizedTarget(targets, value) {
71
+ const normalized = normalizeOptionalString(value);
72
+ if (normalized) targets.add(normalized);
73
+ }
74
+ function listChannelPluginConfigTargetIds(target) {
75
+ const targets = /* @__PURE__ */ new Set();
76
+ addNormalizedTarget(targets, target.channelId);
77
+ addNormalizedTarget(targets, target.pluginId);
78
+ for (const alias of target.aliases ?? []) addNormalizedTarget(targets, alias);
79
+ return targets;
80
+ }
81
+ function pluginConfigTargetsChanged(targetIds, changedPaths) {
82
+ const prefixes = Array.from(targetIds, (id) => [`plugins.entries.${id}`, `plugins.installs.${id}`]).flat();
83
+ return changedPaths.some((path) => prefixes.some((prefix) => path === prefix || path.startsWith(`${prefix}.`)));
84
+ }
85
+ //#endregion
86
+ //#region src/gateway/server-control-ui-root.ts
87
+ async function resolveGatewayControlUiRootState(params) {
88
+ if (params.controlUiRootOverride) {
89
+ const resolvedOverride = resolveControlUiRootOverrideSync(params.controlUiRootOverride);
90
+ const resolvedOverridePath = path.resolve(params.controlUiRootOverride);
91
+ if (!resolvedOverride) params.log.warn(`gateway: controlUi.root not found at ${resolvedOverridePath}`);
92
+ return resolvedOverride ? {
93
+ kind: "resolved",
94
+ path: resolvedOverride
95
+ } : {
96
+ kind: "invalid",
97
+ path: resolvedOverridePath
98
+ };
99
+ }
100
+ if (!params.controlUiEnabled) return;
101
+ const resolveRoot = () => resolveControlUiRootSync({
102
+ moduleUrl: import.meta.url,
103
+ argv1: process.argv[1],
104
+ cwd: process.cwd()
105
+ });
106
+ let resolvedRoot = resolveRoot();
107
+ if (!resolvedRoot) {
108
+ const ensureResult = await ensureControlUiAssetsBuilt(params.gatewayRuntime);
109
+ if (!ensureResult.ok && ensureResult.message) params.log.warn(`gateway: ${ensureResult.message}`);
110
+ resolvedRoot = resolveRoot();
111
+ }
112
+ if (!resolvedRoot) return { kind: "missing" };
113
+ return {
114
+ kind: isPackageProvenControlUiRootSync(resolvedRoot, {
115
+ moduleUrl: import.meta.url,
116
+ argv1: process.argv[1],
117
+ cwd: process.cwd()
118
+ }) ? "bundled" : "resolved",
119
+ path: resolvedRoot
120
+ };
121
+ }
122
+ //#endregion
123
+ //#region src/gateway/server-cron-lazy.ts
124
+ function createLazyGatewayCronState(params) {
125
+ const storePath = resolveCronStorePath(params.cfg.cron?.store);
126
+ const cronEnabled = process.env.FENGMING_SKIP_CRON !== "1" && params.cfg.cron?.enabled !== false;
127
+ let loaded = null;
128
+ let loading = null;
129
+ let stopped = false;
130
+ const load = async () => {
131
+ if (loaded) return loaded;
132
+ loading ??= import("./server-cron-CV7KkVeB.js").then(({ buildGatewayCronService }) => {
133
+ loaded = {
134
+ state: buildGatewayCronService(params),
135
+ started: false
136
+ };
137
+ return loaded;
138
+ });
139
+ return await loading;
140
+ };
141
+ return {
142
+ cron: {
143
+ async start() {
144
+ stopped = false;
145
+ const resolved = await load();
146
+ if (stopped) return;
147
+ if (resolved.started) return;
148
+ resolved.started = true;
149
+ await resolved.state.cron.start();
150
+ if (stopped && resolved.started) {
151
+ resolved.started = false;
152
+ resolved.state.cron.stop();
153
+ }
154
+ },
155
+ stop() {
156
+ stopped = true;
157
+ if (loaded) {
158
+ loaded.started = false;
159
+ loaded.state.cron.stop();
160
+ return;
161
+ }
162
+ if (loading) loading.then((resolved) => {
163
+ if (!stopped) return;
164
+ resolved.started = false;
165
+ resolved.state.cron.stop();
166
+ }).catch(() => {});
167
+ },
168
+ async status() {
169
+ return await (await load()).state.cron.status();
170
+ },
171
+ async list(opts) {
172
+ return await (await load()).state.cron.list(opts);
173
+ },
174
+ async listPage(opts) {
175
+ return await (await load()).state.cron.listPage(opts);
176
+ },
177
+ async add(input) {
178
+ return await (await load()).state.cron.add(input);
179
+ },
180
+ async update(id, patch) {
181
+ return await (await load()).state.cron.update(id, patch);
182
+ },
183
+ async remove(id) {
184
+ return await (await load()).state.cron.remove(id);
185
+ },
186
+ async run(id, mode) {
187
+ return await (await load()).state.cron.run(id, mode);
188
+ },
189
+ async enqueueRun(id, mode) {
190
+ return await (await load()).state.cron.enqueueRun(id, mode);
191
+ },
192
+ getJob(id) {
193
+ if (!loaded) return;
194
+ return loaded.state.cron.getJob(id);
195
+ },
196
+ async readJob(id) {
197
+ return await (await load()).state.cron.readJob(id);
198
+ },
199
+ getDefaultAgentId() {
200
+ if (!loaded) return;
201
+ return loaded.state.cron.getDefaultAgentId();
202
+ },
203
+ wake(opts) {
204
+ if (!loaded) {
205
+ load();
206
+ return { ok: false };
207
+ }
208
+ return loaded.state.cron.wake(opts);
209
+ }
210
+ },
211
+ storePath,
212
+ cronEnabled
213
+ };
214
+ }
215
+ //#endregion
216
+ //#region src/gateway/server-runtime-handles.ts
217
+ function createGatewayServerMutableState() {
218
+ const noopInterval = () => {
219
+ const timer = setInterval(() => {}, 1 << 30);
220
+ timer.unref?.();
221
+ return timer;
222
+ };
223
+ return {
224
+ bonjourStop: null,
225
+ tickInterval: noopInterval(),
226
+ healthInterval: noopInterval(),
227
+ dedupeCleanup: noopInterval(),
228
+ mediaCleanup: null,
229
+ heartbeatRunner: {
230
+ stop: () => {},
231
+ updateConfig: (_cfg) => {}
232
+ },
233
+ stopGatewayUpdateCheck: () => {},
234
+ tailscaleCleanup: null,
235
+ postReadySidecars: [],
236
+ gatewayLifetimeSidecars: [],
237
+ skillsRefreshTimer: null,
238
+ skillsRefreshDelayMs: 3e4,
239
+ skillsChangeUnsub: () => {},
240
+ channelHealthMonitor: null,
241
+ stopModelPricingRefresh: () => {},
242
+ mcpServer: void 0,
243
+ configReloader: { stop: async () => {} },
244
+ agentUnsub: null,
245
+ heartbeatUnsub: null,
246
+ transcriptUnsub: null,
247
+ lifecycleUnsub: null
248
+ };
249
+ }
250
+ //#endregion
251
+ //#region src/gateway/server-live-state.ts
252
+ function createGatewayServerLiveState(params) {
253
+ return {
254
+ ...createGatewayServerMutableState(),
255
+ hooksConfig: params.hooksConfig,
256
+ hookClientIpConfig: params.hookClientIpConfig,
257
+ cronState: params.cronState,
258
+ pluginServices: null,
259
+ gatewayMethods: params.gatewayMethods
260
+ };
261
+ }
262
+ //#endregion
263
+ //#region src/gateway/server-broadcast.ts
264
+ const EVENT_SCOPE_GUARDS = {
265
+ agent: [READ_SCOPE],
266
+ chat: [READ_SCOPE],
267
+ "chat.side_result": [READ_SCOPE],
268
+ cron: [READ_SCOPE],
269
+ health: [],
270
+ "exec.approval.requested": [APPROVALS_SCOPE],
271
+ "exec.approval.resolved": [APPROVALS_SCOPE],
272
+ heartbeat: [],
273
+ "plugin.approval.requested": [APPROVALS_SCOPE],
274
+ "plugin.approval.resolved": [APPROVALS_SCOPE],
275
+ presence: [],
276
+ shutdown: [],
277
+ tick: [],
278
+ "talk.event": [READ_SCOPE],
279
+ "talk.mode": [WRITE_SCOPE],
280
+ "update.available": [],
281
+ "voicewake.changed": [READ_SCOPE],
282
+ "voicewake.routing.changed": [READ_SCOPE],
283
+ "device.pair.requested": [PAIRING_SCOPE],
284
+ "device.pair.resolved": [PAIRING_SCOPE],
285
+ "node.pair.requested": [PAIRING_SCOPE],
286
+ "node.pair.resolved": [PAIRING_SCOPE],
287
+ "sessions.changed": [READ_SCOPE],
288
+ "session.message": [READ_SCOPE],
289
+ "session.operation": [READ_SCOPE],
290
+ "session.tool": [READ_SCOPE]
291
+ };
292
+ const NODE_ALLOWED_EVENTS = new Set(["voicewake.changed", "voicewake.routing.changed"]);
293
+ function serializeFrameField(name, value) {
294
+ const fieldJSON = JSON.stringify({ [name]: value });
295
+ const keyJSON = JSON.stringify(name);
296
+ const prefix = `{${keyJSON}:`;
297
+ return fieldJSON.startsWith(prefix) ? `,${keyJSON}:${fieldJSON.slice(prefix.length, -1)}` : "";
298
+ }
299
+ function hasEventScope(client, event) {
300
+ const required = EVENT_SCOPE_GUARDS[event];
301
+ if (!required && event.startsWith("plugin.")) {
302
+ if ((client.connect.role ?? "operator") !== "operator") return false;
303
+ const scopes = Array.isArray(client.connect.scopes) ? client.connect.scopes : [];
304
+ return scopes.includes("operator.write") || scopes.includes("operator.admin");
305
+ }
306
+ if (!required) return false;
307
+ if (required.length === 0) return true;
308
+ const role = client.connect.role ?? "operator";
309
+ if (role !== "operator") return role === "node" && NODE_ALLOWED_EVENTS.has(event);
310
+ const scopes = Array.isArray(client.connect.scopes) ? client.connect.scopes : [];
311
+ if (scopes.includes("operator.admin")) return true;
312
+ if (required.includes("operator.read")) return scopes.includes("operator.read") || scopes.includes("operator.write");
313
+ return required.some((scope) => scopes.includes(scope));
314
+ }
315
+ function createGatewayBroadcaster(params) {
316
+ const clientSeq = /* @__PURE__ */ new WeakMap();
317
+ const reportedSlowPayloadClients = /* @__PURE__ */ new WeakSet();
318
+ const broadcastInternal = (event, payload, opts, targetConnIds) => {
319
+ if (params.clients.size === 0) return;
320
+ const isTargeted = Boolean(targetConnIds);
321
+ if (shouldLogWs()) {
322
+ const logMeta = {
323
+ event,
324
+ seq: isTargeted ? "targeted" : "per-client",
325
+ clients: params.clients.size,
326
+ targets: targetConnIds ? targetConnIds.size : void 0,
327
+ dropIfSlow: opts?.dropIfSlow,
328
+ presenceVersion: opts?.stateVersion?.presence,
329
+ healthVersion: opts?.stateVersion?.health
330
+ };
331
+ if (event === "agent") Object.assign(logMeta, summarizeAgentEventForWsLog(payload));
332
+ logWs("out", "event", logMeta);
333
+ }
334
+ let frameBase;
335
+ const getFrameBase = () => {
336
+ if (!frameBase) frameBase = {
337
+ eventJSON: JSON.stringify(event),
338
+ payloadFragment: serializeFrameField("payload", payload),
339
+ stateVersionFragment: opts?.stateVersion === void 0 ? "" : serializeFrameField("stateVersion", opts.stateVersion)
340
+ };
341
+ return frameBase;
342
+ };
343
+ for (const c of params.clients) {
344
+ if (targetConnIds && !targetConnIds.has(c.connId)) continue;
345
+ if (!hasEventScope(c, event)) continue;
346
+ const nextSeq = (clientSeq.get(c) ?? 0) + 1;
347
+ const slow = c.socket.bufferedAmount > MAX_BUFFERED_BYTES;
348
+ if (!slow) reportedSlowPayloadClients.delete(c);
349
+ else if (!reportedSlowPayloadClients.has(c)) {
350
+ reportedSlowPayloadClients.add(c);
351
+ logRejectedLargePayload({
352
+ surface: "gateway.ws.outbound_buffer",
353
+ bytes: c.socket.bufferedAmount,
354
+ limitBytes: MAX_BUFFERED_BYTES,
355
+ reason: opts?.dropIfSlow ? "ws_send_buffer_drop" : "ws_send_buffer_close"
356
+ });
357
+ }
358
+ if (slow && opts?.dropIfSlow) {
359
+ if (!isTargeted) clientSeq.set(c, nextSeq);
360
+ continue;
361
+ }
362
+ if (slow) {
363
+ try {
364
+ c.socket.close(1008, "slow consumer");
365
+ } catch {}
366
+ continue;
367
+ }
368
+ try {
369
+ const eventSeq = isTargeted ? void 0 : nextSeq;
370
+ if (!isTargeted) clientSeq.set(c, nextSeq);
371
+ const base = getFrameBase();
372
+ const seqFragment = eventSeq === void 0 ? "" : `,"seq":${eventSeq}`;
373
+ const frame = `{"type":"event","event":${base.eventJSON}${base.payloadFragment}${seqFragment}${base.stateVersionFragment}}`;
374
+ c.socket.send(frame);
375
+ } catch {}
376
+ }
377
+ };
378
+ const broadcast = (event, payload, opts) => broadcastInternal(event, payload, opts);
379
+ const broadcastToConnIds = (event, payload, connIds, opts) => {
380
+ if (connIds.size === 0) return;
381
+ broadcastInternal(event, payload, opts, connIds);
382
+ };
383
+ return {
384
+ broadcast,
385
+ broadcastToConnIds
386
+ };
387
+ }
388
+ //#endregion
389
+ //#region src/channels/plugins/gateway-auth-bypass.ts
390
+ const GATEWAY_AUTH_API_ARTIFACT_BASENAME = "gateway-auth-api.js";
391
+ const MISSING_PUBLIC_SURFACE_PREFIX = "Unable to resolve bundled plugin public surface ";
392
+ function loadBundledChannelGatewayAuthApi(channelId) {
393
+ try {
394
+ return loadBundledPluginPublicArtifactModuleSync({
395
+ dirName: channelId,
396
+ artifactBasename: GATEWAY_AUTH_API_ARTIFACT_BASENAME
397
+ });
398
+ } catch (error) {
399
+ if (error instanceof Error && error.message.startsWith(MISSING_PUBLIC_SURFACE_PREFIX)) return;
400
+ throw error;
401
+ }
402
+ }
403
+ function resolveBundledChannelGatewayAuthBypassPaths(params) {
404
+ return (loadBundledChannelGatewayAuthApi(params.channelId)?.resolveGatewayAuthBypassPaths?.({ cfg: params.cfg }) ?? []).flatMap((path) => typeof path === "string" && path.trim() ? [path.trim()] : []);
405
+ }
406
+ //#endregion
407
+ //#region src/gateway/server-http.ts
408
+ let identityAvatarModulePromise;
409
+ let controlUiModulePromise;
410
+ let embeddingsHttpModulePromise;
411
+ let managedImageAttachmentsModulePromise;
412
+ let modelsHttpModulePromise;
413
+ let openAiHttpModulePromise;
414
+ let openResponsesHttpModulePromise;
415
+ let sessionHistoryHttpModulePromise;
416
+ let sessionKillHttpModulePromise;
417
+ let toolsInvokeHttpModulePromise;
418
+ let pluginNodeCapabilityAuthModulePromise;
419
+ let httpAuthUtilsModulePromise;
420
+ let pluginRouteRuntimeScopesModulePromise;
421
+ function getIdentityAvatarModule() {
422
+ identityAvatarModulePromise ??= import("./identity-avatar-D4I8zUIf.js");
423
+ return identityAvatarModulePromise;
424
+ }
425
+ function getControlUiModule() {
426
+ controlUiModulePromise ??= import("./control-ui-pZyQwpk6.js");
427
+ return controlUiModulePromise;
428
+ }
429
+ function getEmbeddingsHttpModule() {
430
+ embeddingsHttpModulePromise ??= import("./embeddings-http-ChhP3KGJ.js");
431
+ return embeddingsHttpModulePromise;
432
+ }
433
+ function getManagedImageAttachmentsModule() {
434
+ managedImageAttachmentsModulePromise ??= import("./managed-image-attachments-DrKU4E5v.js");
435
+ return managedImageAttachmentsModulePromise;
436
+ }
437
+ function getModelsHttpModule() {
438
+ modelsHttpModulePromise ??= import("./models-http-BQp9tJtS.js");
439
+ return modelsHttpModulePromise;
440
+ }
441
+ function getOpenAiHttpModule() {
442
+ openAiHttpModulePromise ??= import("./openai-http-Bskdv4Tv.js");
443
+ return openAiHttpModulePromise;
444
+ }
445
+ function getOpenResponsesHttpModule() {
446
+ openResponsesHttpModulePromise ??= import("./openresponses-http-DxdgCxFU.js");
447
+ return openResponsesHttpModulePromise;
448
+ }
449
+ function getSessionHistoryHttpModule() {
450
+ sessionHistoryHttpModulePromise ??= import("./sessions-history-http-BwK7b8OH.js");
451
+ return sessionHistoryHttpModulePromise;
452
+ }
453
+ function getSessionKillHttpModule() {
454
+ sessionKillHttpModulePromise ??= import("./session-kill-http-CYCiQpt2.js");
455
+ return sessionKillHttpModulePromise;
456
+ }
457
+ function getToolsInvokeHttpModule() {
458
+ toolsInvokeHttpModulePromise ??= import("./tools-invoke-http-BDhlRl-G.js");
459
+ return toolsInvokeHttpModulePromise;
460
+ }
461
+ function getPluginNodeCapabilityAuthModule() {
462
+ pluginNodeCapabilityAuthModulePromise ??= import("./plugin-node-capability-auth-C5AH9lpt.js");
463
+ return pluginNodeCapabilityAuthModulePromise;
464
+ }
465
+ function getHttpAuthUtilsModule() {
466
+ httpAuthUtilsModulePromise ??= import("./http-auth-utils-DWlNKteu.js");
467
+ return httpAuthUtilsModulePromise;
468
+ }
469
+ function getPluginRouteRuntimeScopesModule() {
470
+ pluginRouteRuntimeScopesModulePromise ??= import("./plugin-route-runtime-scopes-DleJGK2H.js");
471
+ return pluginRouteRuntimeScopesModulePromise;
472
+ }
473
+ const GATEWAY_PROBE_STATUS_BY_PATH = new Map([
474
+ ["/health", "live"],
475
+ ["/healthz", "live"],
476
+ ["/ready", "ready"],
477
+ ["/readyz", "ready"]
478
+ ]);
479
+ const pluginGatewayAuthBypassPathsCache = /* @__PURE__ */ new WeakMap();
480
+ async function resolvePluginGatewayAuthBypassPaths(configSnapshot) {
481
+ const paths = /* @__PURE__ */ new Set();
482
+ const configuredChannels = configSnapshot.channels;
483
+ if (!configuredChannels || Object.keys(configuredChannels).length === 0) return paths;
484
+ for (const channelId of Object.keys(configuredChannels)) for (const path of resolveBundledChannelGatewayAuthBypassPaths({
485
+ channelId,
486
+ cfg: configSnapshot
487
+ })) paths.add(path);
488
+ return paths;
489
+ }
490
+ function getCachedPluginGatewayAuthBypassPaths(configSnapshot) {
491
+ const cached = pluginGatewayAuthBypassPathsCache.get(configSnapshot);
492
+ if (cached) return cached;
493
+ const resolved = resolvePluginGatewayAuthBypassPaths(configSnapshot).catch((error) => {
494
+ pluginGatewayAuthBypassPathsCache.delete(configSnapshot);
495
+ throw error;
496
+ });
497
+ pluginGatewayAuthBypassPathsCache.set(configSnapshot, resolved);
498
+ return resolved;
499
+ }
500
+ function isOpenAiModelsPath(pathname) {
501
+ return pathname === "/v1/models" || pathname.startsWith("/v1/models/");
502
+ }
503
+ function isEmbeddingsPath(pathname) {
504
+ return pathname === "/v1/embeddings";
505
+ }
506
+ function isOpenAiChatCompletionsPath(pathname) {
507
+ return pathname === "/v1/chat/completions";
508
+ }
509
+ function isOpenResponsesPath(pathname) {
510
+ return pathname === "/v1/responses";
511
+ }
512
+ function isToolsInvokePath(pathname) {
513
+ return pathname === "/tools/invoke";
514
+ }
515
+ function isManagedOutgoingImagePath(pathname) {
516
+ return pathname.startsWith("/api/chat/media/outgoing/");
517
+ }
518
+ function isSessionKillPath(pathname) {
519
+ return /^\/sessions\/[^/]+\/kill$/.test(pathname);
520
+ }
521
+ function isSessionHistoryPath(pathname) {
522
+ return /^\/sessions\/[^/]+\/history$/.test(pathname);
523
+ }
524
+ function shouldEnforceDefaultPluginGatewayAuth(pathContext) {
525
+ return pathContext.malformedEncoding || pathContext.decodePassLimitReached || isProtectedPluginRoutePathFromContext(pathContext);
526
+ }
527
+ async function canRevealReadinessDetails(params) {
528
+ if (isLocalDirectRequest(params.req, params.trustedProxies, params.allowRealIpFallback)) return true;
529
+ if (params.resolvedAuth.mode === "none") return false;
530
+ const { getBearerToken, resolveHttpBrowserOriginPolicy } = await getHttpAuthUtilsModule();
531
+ const bearerToken = getBearerToken(params.req);
532
+ return (await authorizeHttpGatewayConnect({
533
+ auth: params.resolvedAuth,
534
+ connectAuth: bearerToken ? {
535
+ token: bearerToken,
536
+ password: bearerToken
537
+ } : null,
538
+ req: params.req,
539
+ trustedProxies: params.trustedProxies,
540
+ allowRealIpFallback: params.allowRealIpFallback,
541
+ browserOriginPolicy: resolveHttpBrowserOriginPolicy(params.req)
542
+ })).ok;
543
+ }
544
+ async function handleGatewayProbeRequest(req, res, requestPath, resolvedAuth, trustedProxies, allowRealIpFallback, getReadiness) {
545
+ const status = GATEWAY_PROBE_STATUS_BY_PATH.get(requestPath);
546
+ if (!status) return false;
547
+ const method = (req.method ?? "GET").toUpperCase();
548
+ if (method !== "GET" && method !== "HEAD") {
549
+ res.statusCode = 405;
550
+ res.setHeader("Allow", "GET, HEAD");
551
+ res.setHeader("Content-Type", "text/plain; charset=utf-8");
552
+ res.end("Method Not Allowed");
553
+ return true;
554
+ }
555
+ res.setHeader("Content-Type", "application/json; charset=utf-8");
556
+ res.setHeader("Cache-Control", "no-store");
557
+ let statusCode;
558
+ let body;
559
+ if (status === "ready" && getReadiness) {
560
+ const includeDetails = await canRevealReadinessDetails({
561
+ req,
562
+ resolvedAuth,
563
+ trustedProxies,
564
+ allowRealIpFallback
565
+ });
566
+ try {
567
+ const result = getReadiness();
568
+ statusCode = result.ready ? 200 : 503;
569
+ body = JSON.stringify(includeDetails ? result : { ready: result.ready });
570
+ } catch {
571
+ statusCode = 503;
572
+ body = JSON.stringify(includeDetails ? {
573
+ ready: false,
574
+ failing: ["internal"],
575
+ uptimeMs: 0
576
+ } : { ready: false });
577
+ }
578
+ } else {
579
+ statusCode = 200;
580
+ body = JSON.stringify({
581
+ ok: true,
582
+ status
583
+ });
584
+ }
585
+ res.statusCode = statusCode;
586
+ res.end(method === "HEAD" ? void 0 : body);
587
+ return true;
588
+ }
589
+ function writeUpgradeAuthFailure(socket, auth) {
590
+ if (auth.rateLimited) {
591
+ const retryAfterSeconds = auth.retryAfterMs && auth.retryAfterMs > 0 ? Math.ceil(auth.retryAfterMs / 1e3) : void 0;
592
+ socket.write([
593
+ "HTTP/1.1 429 Too Many Requests",
594
+ retryAfterSeconds ? `Retry-After: ${retryAfterSeconds}` : void 0,
595
+ "Content-Type: application/json; charset=utf-8",
596
+ "Connection: close",
597
+ "",
598
+ JSON.stringify({ error: {
599
+ message: "Too many failed authentication attempts. Please try again later.",
600
+ type: "rate_limited"
601
+ } })
602
+ ].filter(Boolean).join("\r\n"));
603
+ return;
604
+ }
605
+ socket.write("HTTP/1.1 401 Unauthorized\r\nConnection: close\r\n\r\n");
606
+ }
607
+ function writeUpgradeServiceUnavailable(socket, body) {
608
+ socket.write(`HTTP/1.1 503 Service Unavailable\r
609
+ Connection: close\r
610
+ Content-Type: text/plain; charset=utf-8\r
611
+ Content-Length: ${Buffer.byteLength(body, "utf8")}\r\n\r
612
+ ` + body);
613
+ }
614
+ function parseGatewayRequestPath(rawUrl) {
615
+ try {
616
+ return new URL(rawUrl ?? "/", "http://localhost").pathname;
617
+ } catch {
618
+ return;
619
+ }
620
+ }
621
+ async function runGatewayHttpRequestStages(stages) {
622
+ for (const stage of stages) try {
623
+ if (await stage.run()) return true;
624
+ } catch (err) {
625
+ if (!stage.continueOnError) throw err;
626
+ console.error(`[gateway-http] stage "${stage.name}" threw — skipping:`, err);
627
+ }
628
+ return false;
629
+ }
630
+ function buildPluginRequestStages(params) {
631
+ if (!params.handlePluginRequest) return [];
632
+ let pluginGatewayAuthSatisfied = false;
633
+ let pluginGatewayRequestAuth;
634
+ let pluginRequestOperatorScopes;
635
+ return [{
636
+ name: "plugin-auth",
637
+ run: async () => {
638
+ const pathContext = params.pluginPathContext ?? resolvePluginRoutePathContext(params.requestPath);
639
+ if (!(params.shouldEnforcePluginGatewayAuth ?? shouldEnforceDefaultPluginGatewayAuth)(pathContext)) return false;
640
+ if ((await params.getGatewayAuthBypassPaths()).has(params.requestPath)) return false;
641
+ const { authorizeGatewayHttpRequestOrReply } = await getHttpAuthUtilsModule();
642
+ const requestAuth = await authorizeGatewayHttpRequestOrReply({
643
+ req: params.req,
644
+ res: params.res,
645
+ auth: params.resolvedAuth,
646
+ trustedProxies: params.trustedProxies,
647
+ allowRealIpFallback: params.allowRealIpFallback,
648
+ rateLimiter: params.rateLimiter
649
+ });
650
+ if (!requestAuth) return true;
651
+ pluginGatewayAuthSatisfied = true;
652
+ pluginGatewayRequestAuth = requestAuth;
653
+ const { resolvePluginRouteRuntimeOperatorScopes } = await getPluginRouteRuntimeScopesModule();
654
+ pluginRequestOperatorScopes = resolvePluginRouteRuntimeOperatorScopes(params.req, requestAuth);
655
+ return false;
656
+ }
657
+ }, {
658
+ name: "plugin-http",
659
+ continueOnError: true,
660
+ run: () => {
661
+ const pathContext = params.pluginPathContext ?? resolvePluginRoutePathContext(params.requestPath);
662
+ return params.handlePluginRequest?.(params.req, params.res, pathContext, {
663
+ gatewayAuthSatisfied: pluginGatewayAuthSatisfied,
664
+ gatewayRequestAuth: pluginGatewayRequestAuth,
665
+ gatewayRequestOperatorScopes: pluginRequestOperatorScopes
666
+ }) ?? false;
667
+ }
668
+ }];
669
+ }
670
+ function createGatewayHttpServer(opts) {
671
+ const { clients, controlUiEnabled, controlUiBasePath, controlUiRoot, openAiChatCompletionsEnabled, openAiChatCompletionsConfig, openResponsesEnabled, openResponsesConfig, strictTransportSecurityHeader, handleHooksRequest, handlePluginRequest, shouldEnforcePluginGatewayAuth, resolvePluginNodeCapabilityRoute, resolvedAuth, rateLimiter, getReadiness } = opts;
672
+ const getResolvedAuth = opts.getResolvedAuth ?? (() => resolvedAuth);
673
+ const loadGatewayConfig = opts.getRuntimeConfig ?? getRuntimeConfig;
674
+ const openAiCompatEnabled = openAiChatCompletionsEnabled || openResponsesEnabled;
675
+ const httpServer = opts.tlsOptions ? createServer$1(opts.tlsOptions, (req, res) => {
676
+ handleRequestWithTrace(req, res);
677
+ }) : createServer((req, res) => {
678
+ handleRequestWithTrace(req, res);
679
+ });
680
+ function handleRequestWithTrace(req, res) {
681
+ return runWithDiagnosticTraceContext(createDiagnosticTraceContext(), () => handleRequest(req, res));
682
+ }
683
+ async function handleRequest(req, res) {
684
+ setDefaultSecurityHeaders(res, { strictTransportSecurity: strictTransportSecurityHeader });
685
+ if ((req.headers.upgrade ?? "").toLowerCase() === "websocket") return;
686
+ try {
687
+ const requestPath = parseGatewayRequestPath(req.url);
688
+ if (requestPath === void 0) {
689
+ sendGatewayAuthFailure(res, {
690
+ ok: false,
691
+ reason: "unauthorized"
692
+ });
693
+ return;
694
+ }
695
+ if (GATEWAY_PROBE_STATUS_BY_PATH.get(requestPath) === "live") {
696
+ await handleGatewayProbeRequest(req, res, requestPath, getResolvedAuth(), [], false, getReadiness);
697
+ return;
698
+ }
699
+ const configSnapshot = loadGatewayConfig();
700
+ const trustedProxies = configSnapshot.gateway?.trustedProxies ?? [];
701
+ const allowRealIpFallback = configSnapshot.gateway?.allowRealIpFallback === true;
702
+ const scopedNodeCapability = normalizePluginNodeCapabilityScopedUrl(req.url ?? "/");
703
+ if (scopedNodeCapability.malformedScopedPath) {
704
+ sendGatewayAuthFailure(res, {
705
+ ok: false,
706
+ reason: "unauthorized"
707
+ });
708
+ return;
709
+ }
710
+ if (scopedNodeCapability.rewrittenUrl) req.url = scopedNodeCapability.rewrittenUrl;
711
+ const scopedRequestPath = scopedNodeCapability.pathname;
712
+ const pluginPathContext = handlePluginRequest ? resolvePluginRoutePathContext(scopedRequestPath) : null;
713
+ const resolvedAuth = getResolvedAuth();
714
+ const requestStages = [{
715
+ name: "gateway-probes",
716
+ run: () => handleGatewayProbeRequest(req, res, scopedRequestPath, resolvedAuth, trustedProxies, allowRealIpFallback, getReadiness)
717
+ }, {
718
+ name: "hooks",
719
+ run: () => handleHooksRequest(req, res)
720
+ }];
721
+ if (openAiCompatEnabled && isOpenAiModelsPath(scopedRequestPath)) requestStages.push({
722
+ name: "models",
723
+ run: async () => (await getModelsHttpModule()).handleOpenAiModelsHttpRequest(req, res, {
724
+ auth: resolvedAuth,
725
+ trustedProxies,
726
+ allowRealIpFallback,
727
+ rateLimiter
728
+ })
729
+ });
730
+ if (openAiCompatEnabled && isEmbeddingsPath(scopedRequestPath)) requestStages.push({
731
+ name: "embeddings",
732
+ run: async () => (await getEmbeddingsHttpModule()).handleOpenAiEmbeddingsHttpRequest(req, res, {
733
+ auth: resolvedAuth,
734
+ trustedProxies,
735
+ allowRealIpFallback,
736
+ rateLimiter
737
+ })
738
+ });
739
+ if (isToolsInvokePath(scopedRequestPath)) requestStages.push({
740
+ name: "tools-invoke",
741
+ run: async () => (await getToolsInvokeHttpModule()).handleToolsInvokeHttpRequest(req, res, {
742
+ auth: resolvedAuth,
743
+ trustedProxies,
744
+ allowRealIpFallback,
745
+ rateLimiter
746
+ })
747
+ });
748
+ if (isSessionKillPath(scopedRequestPath)) requestStages.push({
749
+ name: "sessions-kill",
750
+ run: async () => (await getSessionKillHttpModule()).handleSessionKillHttpRequest(req, res, {
751
+ auth: resolvedAuth,
752
+ trustedProxies,
753
+ allowRealIpFallback,
754
+ rateLimiter
755
+ })
756
+ });
757
+ if (isSessionHistoryPath(scopedRequestPath)) requestStages.push({
758
+ name: "sessions-history",
759
+ run: async () => (await getSessionHistoryHttpModule()).handleSessionHistoryHttpRequest(req, res, {
760
+ auth: resolvedAuth,
761
+ getResolvedAuth,
762
+ trustedProxies,
763
+ allowRealIpFallback,
764
+ rateLimiter
765
+ })
766
+ });
767
+ if (openResponsesEnabled && isOpenResponsesPath(scopedRequestPath)) requestStages.push({
768
+ name: "openresponses",
769
+ run: async () => (await getOpenResponsesHttpModule()).handleOpenResponsesHttpRequest(req, res, {
770
+ auth: resolvedAuth,
771
+ config: openResponsesConfig,
772
+ trustedProxies,
773
+ allowRealIpFallback,
774
+ rateLimiter
775
+ })
776
+ });
777
+ if (openAiChatCompletionsEnabled && isOpenAiChatCompletionsPath(scopedRequestPath)) requestStages.push({
778
+ name: "openai",
779
+ run: async () => (await getOpenAiHttpModule()).handleOpenAiHttpRequest(req, res, {
780
+ auth: resolvedAuth,
781
+ config: openAiChatCompletionsConfig,
782
+ trustedProxies,
783
+ allowRealIpFallback,
784
+ rateLimiter
785
+ })
786
+ });
787
+ if (handlePluginRequest && pluginPathContext && resolvePluginNodeCapabilityRoute?.(pluginPathContext)) {
788
+ const nodeCapability = resolvePluginNodeCapabilityRoute(pluginPathContext);
789
+ requestStages.push({
790
+ name: "plugin-node-capability-auth",
791
+ run: async () => {
792
+ if (!nodeCapability) return false;
793
+ const { authorizePluginNodeCapabilityRequest } = await getPluginNodeCapabilityAuthModule();
794
+ const ok = await authorizePluginNodeCapabilityRequest({
795
+ req,
796
+ auth: resolvedAuth,
797
+ trustedProxies,
798
+ allowRealIpFallback,
799
+ clients,
800
+ nodeCapability,
801
+ capability: scopedNodeCapability.capability,
802
+ malformedScopedPath: scopedNodeCapability.malformedScopedPath,
803
+ rateLimiter
804
+ });
805
+ if (!ok.ok) {
806
+ sendGatewayAuthFailure(res, ok);
807
+ return true;
808
+ }
809
+ return false;
810
+ }
811
+ });
812
+ }
813
+ requestStages.push(...buildPluginRequestStages({
814
+ req,
815
+ res,
816
+ requestPath: scopedRequestPath,
817
+ getGatewayAuthBypassPaths: () => getCachedPluginGatewayAuthBypassPaths(configSnapshot),
818
+ pluginPathContext,
819
+ handlePluginRequest,
820
+ shouldEnforcePluginGatewayAuth,
821
+ resolvedAuth,
822
+ trustedProxies,
823
+ allowRealIpFallback,
824
+ rateLimiter
825
+ }));
826
+ if (isManagedOutgoingImagePath(scopedRequestPath)) requestStages.push({
827
+ name: "chat-managed-image-media",
828
+ run: async () => (await getManagedImageAttachmentsModule()).handleManagedOutgoingImageHttpRequest(req, res, {
829
+ auth: resolvedAuth,
830
+ trustedProxies,
831
+ allowRealIpFallback,
832
+ rateLimiter
833
+ })
834
+ });
835
+ if (controlUiEnabled) {
836
+ requestStages.push({
837
+ name: "control-ui-assistant-media",
838
+ run: async () => (await getControlUiModule()).handleControlUiAssistantMediaRequest(req, res, {
839
+ basePath: controlUiBasePath,
840
+ config: configSnapshot,
841
+ agentId: resolveAssistantIdentity({ cfg: configSnapshot }).agentId,
842
+ auth: resolvedAuth,
843
+ trustedProxies,
844
+ allowRealIpFallback,
845
+ rateLimiter
846
+ })
847
+ });
848
+ requestStages.push({
849
+ name: "control-ui-avatar",
850
+ run: async () => {
851
+ const { handleControlUiAvatarRequest } = await getControlUiModule();
852
+ const { resolveAgentAvatar } = await getIdentityAvatarModule();
853
+ return handleControlUiAvatarRequest(req, res, {
854
+ basePath: controlUiBasePath,
855
+ auth: resolvedAuth,
856
+ trustedProxies,
857
+ allowRealIpFallback,
858
+ rateLimiter,
859
+ resolveAvatar: (agentId) => resolveAgentAvatar(configSnapshot, agentId, { includeUiOverride: true })
860
+ });
861
+ }
862
+ });
863
+ requestStages.push({
864
+ name: "control-ui-http",
865
+ run: async () => (await getControlUiModule()).handleControlUiHttpRequest(req, res, {
866
+ basePath: controlUiBasePath,
867
+ config: configSnapshot,
868
+ agentId: resolveAssistantIdentity({ cfg: configSnapshot }).agentId,
869
+ root: controlUiRoot,
870
+ auth: resolvedAuth,
871
+ trustedProxies,
872
+ allowRealIpFallback,
873
+ rateLimiter
874
+ })
875
+ });
876
+ }
877
+ if (await runGatewayHttpRequestStages(requestStages)) return;
878
+ res.statusCode = 404;
879
+ res.setHeader("Content-Type", "text/plain; charset=utf-8");
880
+ res.end("Not Found");
881
+ } catch (err) {
882
+ console.error("[gateway-http] unhandled error in request handler:", err);
883
+ res.statusCode = 500;
884
+ res.setHeader("Content-Type", "text/plain; charset=utf-8");
885
+ res.end("Internal Server Error");
886
+ }
887
+ }
888
+ return httpServer;
889
+ }
890
+ function attachGatewayUpgradeHandler(opts) {
891
+ const { httpServer, wss, handlePluginUpgrade, shouldEnforcePluginGatewayAuth, resolvePluginNodeCapabilityRoute, clients, preauthConnectionBudget, resolvedAuth, rateLimiter, log } = opts;
892
+ const getResolvedAuth = opts.getResolvedAuth ?? (() => resolvedAuth);
893
+ httpServer.on("upgrade", (req, socket, head) => {
894
+ runWithDiagnosticTraceContext(createDiagnosticTraceContext(), async () => {
895
+ const configSnapshot = getRuntimeConfig();
896
+ const trustedProxies = configSnapshot.gateway?.trustedProxies ?? [];
897
+ const allowRealIpFallback = configSnapshot.gateway?.allowRealIpFallback === true;
898
+ const scopedNodeCapability = normalizePluginNodeCapabilityScopedUrl(req.url ?? "/");
899
+ if (scopedNodeCapability.malformedScopedPath) {
900
+ writeUpgradeAuthFailure(socket, {
901
+ ok: false,
902
+ reason: "unauthorized"
903
+ });
904
+ socket.destroy();
905
+ return;
906
+ }
907
+ if (scopedNodeCapability.rewrittenUrl) req.url = scopedNodeCapability.rewrittenUrl;
908
+ const resolvedAuth = getResolvedAuth();
909
+ const requestPath = scopedNodeCapability.pathname;
910
+ const pathContext = resolvePluginRoutePathContext(requestPath);
911
+ const nodeCapability = resolvePluginNodeCapabilityRoute?.(pathContext);
912
+ if (nodeCapability) {
913
+ const { authorizePluginNodeCapabilityRequest } = await getPluginNodeCapabilityAuthModule();
914
+ const ok = await authorizePluginNodeCapabilityRequest({
915
+ req,
916
+ auth: resolvedAuth,
917
+ trustedProxies,
918
+ allowRealIpFallback,
919
+ clients,
920
+ nodeCapability,
921
+ capability: scopedNodeCapability.capability,
922
+ malformedScopedPath: scopedNodeCapability.malformedScopedPath,
923
+ rateLimiter
924
+ });
925
+ if (!ok.ok) {
926
+ writeUpgradeAuthFailure(socket, ok);
927
+ socket.destroy();
928
+ return;
929
+ }
930
+ }
931
+ if (handlePluginUpgrade) {
932
+ let pluginGatewayAuthSatisfied = false;
933
+ let pluginGatewayRequestAuth;
934
+ let pluginGatewayRequestOperatorScopes;
935
+ if ((shouldEnforcePluginGatewayAuth ?? shouldEnforceDefaultPluginGatewayAuth)(pathContext) && !(await getCachedPluginGatewayAuthBypassPaths(configSnapshot)).has(requestPath)) {
936
+ const { checkGatewayHttpRequestAuth } = await getHttpAuthUtilsModule();
937
+ const authCheck = await checkGatewayHttpRequestAuth({
938
+ req,
939
+ auth: resolvedAuth,
940
+ trustedProxies,
941
+ allowRealIpFallback,
942
+ rateLimiter,
943
+ cfg: configSnapshot
944
+ });
945
+ if (!authCheck.ok) {
946
+ writeUpgradeAuthFailure(socket, authCheck.authResult);
947
+ socket.destroy();
948
+ return;
949
+ }
950
+ pluginGatewayAuthSatisfied = true;
951
+ pluginGatewayRequestAuth = authCheck.requestAuth;
952
+ const { resolvePluginRouteRuntimeOperatorScopes } = await getPluginRouteRuntimeScopesModule();
953
+ pluginGatewayRequestOperatorScopes = resolvePluginRouteRuntimeOperatorScopes(req, authCheck.requestAuth);
954
+ }
955
+ if (await handlePluginUpgrade(req, socket, head, pathContext, {
956
+ gatewayAuthSatisfied: pluginGatewayAuthSatisfied,
957
+ gatewayRequestAuth: pluginGatewayRequestAuth,
958
+ gatewayRequestOperatorScopes: pluginGatewayRequestOperatorScopes
959
+ })) return;
960
+ }
961
+ const preauthBudgetKey = resolveRequestClientIp(req, trustedProxies, allowRealIpFallback);
962
+ if (wss.listenerCount("connection") === 0) {
963
+ writeUpgradeServiceUnavailable(socket, "Gateway websocket handlers unavailable");
964
+ socket.destroy();
965
+ return;
966
+ }
967
+ if (!preauthConnectionBudget.acquire(preauthBudgetKey)) {
968
+ writeUpgradeServiceUnavailable(socket, "Too many unauthenticated sockets");
969
+ socket.destroy();
970
+ return;
971
+ }
972
+ let budgetTransferred = false;
973
+ const releaseUpgradeBudget = () => {
974
+ if (budgetTransferred) return;
975
+ budgetTransferred = true;
976
+ preauthConnectionBudget.release(preauthBudgetKey);
977
+ };
978
+ socket.once("close", releaseUpgradeBudget);
979
+ try {
980
+ wss.handleUpgrade(req, socket, head, (ws) => {
981
+ ws["__fengmingPreauthBudgetKey"] = preauthBudgetKey;
982
+ wss.emit("connection", ws, req);
983
+ if (Boolean(ws["__fengmingPreauthBudgetClaimed"])) {
984
+ budgetTransferred = true;
985
+ socket.off("close", releaseUpgradeBudget);
986
+ }
987
+ });
988
+ } catch {
989
+ socket.off("close", releaseUpgradeBudget);
990
+ releaseUpgradeBudget();
991
+ throw new Error("网关 WebSocket 升级失败");
992
+ }
993
+ }).catch((err) => {
994
+ const remoteAddress = socket.remoteAddress ?? "unknown";
995
+ const errorMessage = err instanceof Error ? err.message : String(err);
996
+ log?.warn(`ws upgrade error from ${remoteAddress}: ${errorMessage}`);
997
+ socket.destroy();
998
+ });
999
+ });
1000
+ }
1001
+ //#endregion
1002
+ //#region src/gateway/server/http-listen.ts
1003
+ const EADDRINUSE_MAX_RETRIES = 20;
1004
+ const EADDRINUSE_RETRY_INTERVAL_MS = 500;
1005
+ async function closeServerQuietly(httpServer) {
1006
+ await new Promise((resolve) => {
1007
+ try {
1008
+ httpServer.close(() => resolve());
1009
+ } catch {
1010
+ resolve();
1011
+ }
1012
+ });
1013
+ }
1014
+ async function listenGatewayHttpServer(params) {
1015
+ const { httpServer, bindHost, port } = params;
1016
+ for (let attempt = 0;; attempt++) try {
1017
+ await new Promise((resolve, reject) => {
1018
+ const onError = (err) => {
1019
+ httpServer.off("listening", onListening);
1020
+ reject(err);
1021
+ };
1022
+ const onListening = () => {
1023
+ httpServer.off("error", onError);
1024
+ resolve();
1025
+ };
1026
+ httpServer.once("error", onError);
1027
+ httpServer.once("listening", onListening);
1028
+ httpServer.listen(port, bindHost);
1029
+ });
1030
+ return;
1031
+ } catch (err) {
1032
+ const code = err.code;
1033
+ if (code === "EADDRINUSE" && attempt < EADDRINUSE_MAX_RETRIES) {
1034
+ await closeServerQuietly(httpServer);
1035
+ await sleep(EADDRINUSE_RETRY_INTERVAL_MS);
1036
+ continue;
1037
+ }
1038
+ if (code === "EADDRINUSE") throw new GatewayLockError(`another gateway instance is already listening on ws://${bindHost}:${port}`, err);
1039
+ throw new GatewayLockError(`failed to bind gateway socket on ws://${bindHost}:${port}: ${String(err)}`, err);
1040
+ }
1041
+ }
1042
+ //#endregion
1043
+ //#region src/gateway/server/preauth-connection-budget.ts
1044
+ const DEFAULT_MAX_PREAUTH_CONNECTIONS_PER_IP = 32;
1045
+ const UNKNOWN_CLIENT_IP_BUDGET_KEY = "__fengming_unknown_client_ip__";
1046
+ function getMaxPreauthConnectionsPerIpFromEnv(env = process.env) {
1047
+ const configured = env.FENGMING_MAX_PREAUTH_CONNECTIONS_PER_IP || env.VITEST && env.FENGMING_TEST_MAX_PREAUTH_CONNECTIONS_PER_IP;
1048
+ if (!configured) return DEFAULT_MAX_PREAUTH_CONNECTIONS_PER_IP;
1049
+ const parsed = parseStrictPositiveInteger(configured);
1050
+ if (parsed === void 0) return DEFAULT_MAX_PREAUTH_CONNECTIONS_PER_IP;
1051
+ return parsed;
1052
+ }
1053
+ function createPreauthConnectionBudget(limit = getMaxPreauthConnectionsPerIpFromEnv()) {
1054
+ const maxConnectionsPerIp = resolveIntegerOption(limit, getMaxPreauthConnectionsPerIpFromEnv(), { min: 1 });
1055
+ const counts = /* @__PURE__ */ new Map();
1056
+ const normalizeBudgetKey = (clientIp) => {
1057
+ return clientIp?.trim() || UNKNOWN_CLIENT_IP_BUDGET_KEY;
1058
+ };
1059
+ return {
1060
+ acquire(clientIp) {
1061
+ const ip = normalizeBudgetKey(clientIp);
1062
+ const next = (counts.get(ip) ?? 0) + 1;
1063
+ if (next > maxConnectionsPerIp) return false;
1064
+ counts.set(ip, next);
1065
+ return true;
1066
+ },
1067
+ release(clientIp) {
1068
+ const ip = normalizeBudgetKey(clientIp);
1069
+ const current = counts.get(ip);
1070
+ if (current === void 0) return;
1071
+ if (current <= 1) {
1072
+ counts.delete(ip);
1073
+ return;
1074
+ }
1075
+ counts.set(ip, current - 1);
1076
+ }
1077
+ };
1078
+ }
1079
+ //#endregion
1080
+ //#region src/gateway/server-runtime-state.ts
1081
+ async function createGatewayRuntimeState(params) {
1082
+ pinActivePluginHttpRouteRegistry(params.pluginRegistry);
1083
+ if (params.pinChannelRegistry !== false) pinActivePluginChannelRegistry(params.pluginRegistry);
1084
+ else releasePinnedPluginChannelRegistry();
1085
+ try {
1086
+ const resolvePluginRouteRegistry = () => params.getPluginRouteRegistry?.() ?? params.pluginRegistry;
1087
+ const clients = /* @__PURE__ */ new Set();
1088
+ const { broadcast, broadcastToConnIds } = createGatewayBroadcaster({ clients });
1089
+ let loadedHooksRequestHandler = null;
1090
+ const handleHooksRequest = async (req, res) => {
1091
+ const hooksConfig = params.hooksConfig();
1092
+ if (!hooksConfig) return false;
1093
+ const url = new URL(req.url ?? "/", "http://localhost");
1094
+ const basePath = hooksConfig.basePath;
1095
+ if (url.pathname !== basePath && !url.pathname.startsWith(`${basePath}/`)) return false;
1096
+ if (!loadedHooksRequestHandler) {
1097
+ const { createGatewayHooksRequestHandler } = await import("./hooks-DkEvkwzS.js");
1098
+ loadedHooksRequestHandler = createGatewayHooksRequestHandler({
1099
+ deps: params.deps,
1100
+ getHooksConfig: params.hooksConfig,
1101
+ getClientIpConfig: params.getHookClientIpConfig,
1102
+ bindHost: params.bindHost,
1103
+ port: params.port,
1104
+ logHooks: params.logHooks
1105
+ });
1106
+ }
1107
+ return await loadedHooksRequestHandler(req, res);
1108
+ };
1109
+ let loadedPluginRequestHandler = null;
1110
+ let loadedPluginUpgradeHandler = null;
1111
+ const handlePluginRequest = async (req, res, pathContext, dispatchContext) => {
1112
+ if ((resolvePluginRouteRegistry().httpRoutes ?? []).length === 0) return false;
1113
+ if (!loadedPluginRequestHandler) {
1114
+ const { createGatewayPluginRequestHandler } = await import("./plugins-http-C4vPyldG.js");
1115
+ loadedPluginRequestHandler = createGatewayPluginRequestHandler({
1116
+ registry: params.pluginRegistry,
1117
+ getRouteRegistry: resolvePluginRouteRegistry,
1118
+ log: params.logPlugins,
1119
+ getGatewayRequestContext: params.getGatewayRequestContext
1120
+ });
1121
+ }
1122
+ return await loadedPluginRequestHandler(req, res, pathContext, dispatchContext);
1123
+ };
1124
+ const handlePluginUpgrade = async (req, socket, head, pathContext, dispatchContext) => {
1125
+ if ((resolvePluginRouteRegistry().httpRoutes ?? []).length === 0) return false;
1126
+ if (!loadedPluginUpgradeHandler) {
1127
+ const { createGatewayPluginUpgradeHandler } = await import("./plugins-http-C4vPyldG.js");
1128
+ loadedPluginUpgradeHandler = createGatewayPluginUpgradeHandler({
1129
+ registry: params.pluginRegistry,
1130
+ getRouteRegistry: resolvePluginRouteRegistry,
1131
+ log: params.logPlugins,
1132
+ getGatewayRequestContext: params.getGatewayRequestContext
1133
+ });
1134
+ }
1135
+ return await loadedPluginUpgradeHandler(req, socket, head, pathContext, dispatchContext);
1136
+ };
1137
+ const shouldEnforcePluginGatewayAuth = (pathContext) => {
1138
+ return shouldEnforceGatewayAuthForPluginPath(resolvePluginRouteRegistry(), pathContext);
1139
+ };
1140
+ const resolvePluginNodeCapabilityRoute = (pathContext) => findMatchingPluginNodeCapabilityRoute(resolvePluginRouteRegistry(), pathContext)?.nodeCapability;
1141
+ const bindHosts = await resolveGatewayListenHosts(params.bindHost);
1142
+ if (!isLoopbackHost(params.bindHost)) params.log.warn("⚠️ Gateway is binding to a non-loopback address. Ensure authentication is configured before exposing to public networks.");
1143
+ if (params.cfg.gateway?.controlUi?.dangerouslyAllowHostHeaderOriginFallback === true) params.log.warn("⚠️ gateway.controlUi.dangerouslyAllowHostHeaderOriginFallback=true is enabled. Host-header origin fallback weakens origin checks and should only be used as break-glass.");
1144
+ const wss = new WebSocketServer({
1145
+ noServer: true,
1146
+ maxPayload: MAX_PREAUTH_PAYLOAD_BYTES
1147
+ });
1148
+ const preauthConnectionBudget = createPreauthConnectionBudget();
1149
+ const httpServers = [];
1150
+ const httpBindHosts = [];
1151
+ for (const _ of bindHosts) {
1152
+ const httpServer = createGatewayHttpServer({
1153
+ clients,
1154
+ controlUiEnabled: params.controlUiEnabled,
1155
+ controlUiBasePath: params.controlUiBasePath,
1156
+ controlUiRoot: params.controlUiRoot,
1157
+ openAiChatCompletionsEnabled: params.openAiChatCompletionsEnabled,
1158
+ openAiChatCompletionsConfig: params.openAiChatCompletionsConfig,
1159
+ openResponsesEnabled: params.openResponsesEnabled,
1160
+ openResponsesConfig: params.openResponsesConfig,
1161
+ strictTransportSecurityHeader: params.strictTransportSecurityHeader,
1162
+ handleHooksRequest,
1163
+ handlePluginRequest,
1164
+ shouldEnforcePluginGatewayAuth,
1165
+ resolvePluginNodeCapabilityRoute,
1166
+ resolvedAuth: params.resolvedAuth,
1167
+ getResolvedAuth: params.getResolvedAuth,
1168
+ rateLimiter: params.rateLimiter,
1169
+ getReadiness: params.getReadiness,
1170
+ tlsOptions: params.gatewayTls?.enabled ? params.gatewayTls.tlsOptions : void 0
1171
+ });
1172
+ attachGatewayUpgradeHandler({
1173
+ httpServer,
1174
+ wss,
1175
+ handlePluginUpgrade,
1176
+ shouldEnforcePluginGatewayAuth,
1177
+ resolvePluginNodeCapabilityRoute,
1178
+ clients,
1179
+ preauthConnectionBudget,
1180
+ resolvedAuth: params.resolvedAuth,
1181
+ getResolvedAuth: params.getResolvedAuth,
1182
+ rateLimiter: params.rateLimiter,
1183
+ log: params.log
1184
+ });
1185
+ httpServers.push(httpServer);
1186
+ }
1187
+ const httpServer = httpServers[0];
1188
+ if (!httpServer) throw new Error("网关 HTTP 服务启动失败");
1189
+ let startListeningPromise = null;
1190
+ const startListening = async () => {
1191
+ if (startListeningPromise) {
1192
+ await startListeningPromise;
1193
+ return;
1194
+ }
1195
+ startListeningPromise = (async () => {
1196
+ for (const [index, host] of bindHosts.entries()) {
1197
+ const server = httpServers[index];
1198
+ if (!server) throw new Error(`Missing gateway HTTP server for bind host ${host}`);
1199
+ try {
1200
+ await listenGatewayHttpServer({
1201
+ httpServer: server,
1202
+ bindHost: host,
1203
+ port: params.port
1204
+ });
1205
+ httpBindHosts.push(host);
1206
+ } catch (err) {
1207
+ if (host === bindHosts[0]) throw err;
1208
+ params.log.warn(`gateway: failed to bind loopback alias ${host}:${params.port} (${String(err)})`);
1209
+ }
1210
+ }
1211
+ if (httpBindHosts.length === 0) throw new Error("网关 HTTP 服务启动失败");
1212
+ })();
1213
+ try {
1214
+ await startListeningPromise;
1215
+ } catch (err) {
1216
+ startListeningPromise = null;
1217
+ throw err;
1218
+ }
1219
+ };
1220
+ const agentRunSeq = /* @__PURE__ */ new Map();
1221
+ const dedupe = /* @__PURE__ */ new Map();
1222
+ const chatRunState = createChatRunState();
1223
+ const chatRunRegistry = chatRunState.registry;
1224
+ return {
1225
+ releasePluginRouteRegistry: () => {
1226
+ releasePinnedPluginHttpRouteRegistry();
1227
+ releasePinnedPluginChannelRegistry();
1228
+ },
1229
+ httpServer,
1230
+ httpServers,
1231
+ httpBindHosts,
1232
+ startListening,
1233
+ wss,
1234
+ preauthConnectionBudget,
1235
+ clients,
1236
+ broadcast,
1237
+ broadcastToConnIds,
1238
+ agentRunSeq,
1239
+ dedupe,
1240
+ chatRunState,
1241
+ chatRunBuffers: chatRunState.buffers,
1242
+ chatDeltaSentAt: chatRunState.deltaSentAt,
1243
+ chatDeltaLastBroadcastLen: chatRunState.deltaLastBroadcastLen,
1244
+ addChatRun: chatRunRegistry.add,
1245
+ removeChatRun: chatRunRegistry.remove,
1246
+ chatAbortControllers: /* @__PURE__ */ new Map(),
1247
+ toolEventRecipients: createToolEventRecipientRegistry()
1248
+ };
1249
+ } catch (err) {
1250
+ releasePinnedPluginHttpRouteRegistry();
1251
+ releasePinnedPluginChannelRegistry();
1252
+ throw err;
1253
+ }
1254
+ }
1255
+ //#endregion
1256
+ //#region src/gateway/server-wizard-sessions.ts
1257
+ function createWizardSessionTracker() {
1258
+ const wizardSessions = /* @__PURE__ */ new Map();
1259
+ const findRunningWizard = () => {
1260
+ for (const [id, session] of wizardSessions) if (session.getStatus() === "running") return id;
1261
+ return null;
1262
+ };
1263
+ const purgeWizardSession = (id) => {
1264
+ const session = wizardSessions.get(id);
1265
+ if (!session) return;
1266
+ if (session.getStatus() === "running") return;
1267
+ wizardSessions.delete(id);
1268
+ };
1269
+ return {
1270
+ wizardSessions,
1271
+ findRunningWizard,
1272
+ purgeWizardSession
1273
+ };
1274
+ }
1275
+ //#endregion
1276
+ //#region src/gateway/server/event-loop-health.ts
1277
+ const EVENT_LOOP_MONITOR_RESOLUTION_MS = 20;
1278
+ const EVENT_LOOP_DELAY_WARN_MS = 1e3;
1279
+ const EVENT_LOOP_UTILIZATION_WARN = .95;
1280
+ const CPU_CORE_RATIO_WARN = .9;
1281
+ const LOAD_DEGRADATION_DELAY_COEVIDENCE_MS = 25;
1282
+ const SUSTAINED_LOAD_SAMPLE_MIN_INTERVAL_MS = 1e3;
1283
+ function roundMetric(value, digits = 3) {
1284
+ if (!Number.isFinite(value)) return 0;
1285
+ const factor = 10 ** digits;
1286
+ return Math.round(value * factor) / factor;
1287
+ }
1288
+ function nanosecondsToMilliseconds(value) {
1289
+ return roundMetric(value / 1e6, 1);
1290
+ }
1291
+ function classifyGatewayEventLoopHealthReasons(metrics) {
1292
+ const reasons = [];
1293
+ if (metrics.delayP99Ms >= EVENT_LOOP_DELAY_WARN_MS || metrics.delayMaxMs >= EVENT_LOOP_DELAY_WARN_MS) reasons.push("event_loop_delay");
1294
+ if (metrics.intervalMs < SUSTAINED_LOAD_SAMPLE_MIN_INTERVAL_MS) return reasons;
1295
+ if (!(metrics.delayP99Ms >= LOAD_DEGRADATION_DELAY_COEVIDENCE_MS || metrics.delayMaxMs >= LOAD_DEGRADATION_DELAY_COEVIDENCE_MS)) return reasons;
1296
+ if (metrics.utilization >= EVENT_LOOP_UTILIZATION_WARN) reasons.push("event_loop_utilization");
1297
+ if (metrics.cpuCoreRatio >= CPU_CORE_RATIO_WARN) reasons.push("cpu");
1298
+ return reasons;
1299
+ }
1300
+ function createGatewayEventLoopHealthMonitor(deps = {}) {
1301
+ const nowMs = deps.now ?? Date.now;
1302
+ const readCpuUsage = deps.cpuUsage ?? process.cpuUsage.bind(process);
1303
+ const readEventLoopUtilization = deps.eventLoopUtilization ?? performance.eventLoopUtilization.bind(performance);
1304
+ const createDelayMonitor = deps.createDelayMonitor ?? ((resolutionMs) => monitorEventLoopDelay({ resolution: resolutionMs }));
1305
+ let monitor = null;
1306
+ let lastWallAt = nowMs();
1307
+ let lastCpuUsage = readCpuUsage();
1308
+ let lastEventLoopUtilization = readEventLoopUtilization();
1309
+ let lastSnapshot;
1310
+ try {
1311
+ monitor = createDelayMonitor(EVENT_LOOP_MONITOR_RESOLUTION_MS);
1312
+ monitor.enable();
1313
+ monitor.reset();
1314
+ } catch {
1315
+ monitor = null;
1316
+ }
1317
+ return {
1318
+ snapshot: () => {
1319
+ if (!monitor || !lastCpuUsage || !lastEventLoopUtilization || lastWallAt <= 0) return;
1320
+ const now = nowMs();
1321
+ const intervalMs = Math.max(1, now - lastWallAt);
1322
+ const delayP99Ms = nanosecondsToMilliseconds(monitor.percentile(99));
1323
+ const delayMaxMs = nanosecondsToMilliseconds(monitor.max);
1324
+ if (!(delayP99Ms >= EVENT_LOOP_DELAY_WARN_MS || delayMaxMs >= EVENT_LOOP_DELAY_WARN_MS) && intervalMs < SUSTAINED_LOAD_SAMPLE_MIN_INTERVAL_MS) return lastSnapshot;
1325
+ const cpuUsage = readCpuUsage(lastCpuUsage);
1326
+ const currentEventLoopUtilization = readEventLoopUtilization();
1327
+ const utilization = roundMetric(readEventLoopUtilization(currentEventLoopUtilization, lastEventLoopUtilization).utilization);
1328
+ const cpuCoreRatio = roundMetric(roundMetric((cpuUsage.user + cpuUsage.system) / 1e3, 1) / intervalMs);
1329
+ const reasons = classifyGatewayEventLoopHealthReasons({
1330
+ intervalMs,
1331
+ delayP99Ms,
1332
+ delayMaxMs,
1333
+ utilization,
1334
+ cpuCoreRatio
1335
+ });
1336
+ const snapshot = {
1337
+ degraded: reasons.length > 0,
1338
+ reasons,
1339
+ intervalMs,
1340
+ delayP99Ms,
1341
+ delayMaxMs,
1342
+ utilization,
1343
+ cpuCoreRatio
1344
+ };
1345
+ monitor.reset();
1346
+ lastWallAt = now;
1347
+ lastCpuUsage = readCpuUsage();
1348
+ lastEventLoopUtilization = currentEventLoopUtilization;
1349
+ lastSnapshot = snapshot;
1350
+ return snapshot;
1351
+ },
1352
+ stop: () => {
1353
+ monitor?.disable();
1354
+ monitor = null;
1355
+ lastWallAt = 0;
1356
+ lastCpuUsage = null;
1357
+ lastEventLoopUtilization = null;
1358
+ lastSnapshot = void 0;
1359
+ }
1360
+ };
1361
+ }
1362
+ //#endregion
1363
+ //#region src/gateway/server/readiness.ts
1364
+ const DEFAULT_READINESS_CACHE_TTL_MS = 1e3;
1365
+ function shouldIgnoreReadinessFailure(accountSnapshot, health) {
1366
+ if (health.reason === "unmanaged" || health.reason === "stale-socket") return true;
1367
+ return health.reason === "not-running" && accountSnapshot.restartPending === true;
1368
+ }
1369
+ function createReadinessChecker(deps) {
1370
+ const { channelManager, startedAt } = deps;
1371
+ const cacheTtlMs = Math.max(0, deps.cacheTtlMs ?? DEFAULT_READINESS_CACHE_TTL_MS);
1372
+ let cachedAt = 0;
1373
+ let cachedState = null;
1374
+ return () => {
1375
+ const now = Date.now();
1376
+ const uptimeMs = now - startedAt;
1377
+ if (deps.getStartupPending?.()) return withEventLoopHealth({
1378
+ ready: false,
1379
+ failing: [deps.getStartupPendingReason?.() ?? "startup-sidecars"],
1380
+ uptimeMs
1381
+ }, deps.getEventLoopHealth);
1382
+ if (deps.shouldSkipChannelReadiness?.()) return withEventLoopHealth({
1383
+ ready: true,
1384
+ failing: [],
1385
+ uptimeMs
1386
+ }, deps.getEventLoopHealth);
1387
+ if (cachedState && now - cachedAt < cacheTtlMs) return withEventLoopHealth({
1388
+ ...cachedState,
1389
+ uptimeMs
1390
+ }, deps.getEventLoopHealth);
1391
+ const snapshot = channelManager.getRuntimeSnapshot();
1392
+ const failing = [];
1393
+ for (const [channelId, accounts] of Object.entries(snapshot.channelAccounts)) {
1394
+ if (!accounts) continue;
1395
+ for (const accountSnapshot of Object.values(accounts)) {
1396
+ if (!accountSnapshot) continue;
1397
+ const health = evaluateChannelHealth(accountSnapshot, {
1398
+ now,
1399
+ staleEventThresholdMs: DEFAULT_CHANNEL_STALE_EVENT_THRESHOLD_MS,
1400
+ channelConnectGraceMs: DEFAULT_CHANNEL_CONNECT_GRACE_MS,
1401
+ channelId
1402
+ });
1403
+ if (!health.healthy && !shouldIgnoreReadinessFailure(accountSnapshot, health)) {
1404
+ failing.push(channelId);
1405
+ break;
1406
+ }
1407
+ }
1408
+ }
1409
+ cachedAt = now;
1410
+ cachedState = {
1411
+ ready: failing.length === 0,
1412
+ failing
1413
+ };
1414
+ return withEventLoopHealth({
1415
+ ...cachedState,
1416
+ uptimeMs
1417
+ }, deps.getEventLoopHealth);
1418
+ };
1419
+ }
1420
+ function withEventLoopHealth(result, getEventLoopHealth) {
1421
+ const eventLoop = getEventLoopHealth?.();
1422
+ return eventLoop ? {
1423
+ ...result,
1424
+ eventLoop
1425
+ } : result;
1426
+ }
1427
+ //#endregion
1428
+ //#region src/gateway/server/tls.ts
1429
+ async function loadGatewayTlsRuntime(cfg, log) {
1430
+ return await loadGatewayTlsRuntime$1(cfg, log);
1431
+ }
1432
+ //#endregion
1433
+ //#region src/gateway/startup-control-ui-origins.ts
1434
+ async function maybeSeedControlUiAllowedOriginsAtStartup(params) {
1435
+ const seeded = ensureControlUiAllowedOriginsForNonLoopbackBind(params.config, {
1436
+ isContainerEnvironment,
1437
+ runtimeBind: params.runtimeBind,
1438
+ runtimePort: params.runtimePort
1439
+ });
1440
+ if (!seeded.seededOrigins || !seeded.bind) return {
1441
+ config: params.config,
1442
+ seededAllowedOrigins: false
1443
+ };
1444
+ params.log.info(buildSeededOriginsInfoLog(seeded.seededOrigins, seeded.bind));
1445
+ return {
1446
+ config: seeded.config,
1447
+ seededAllowedOrigins: true
1448
+ };
1449
+ }
1450
+ function buildSeededOriginsInfoLog(origins, bind) {
1451
+ return `gateway: seeded gateway.controlUi.allowedOrigins ${JSON.stringify(origins)} for bind=${bind} (required since v2026.2.26; see issue #29385). Applied for this runtime without writing config; add other origins to gateway.controlUi.allowedOrigins if needed.`;
1452
+ }
1453
+ //#endregion
1454
+ //#region src/gateway/server.impl.ts
1455
+ async function resetModelCatalogCacheForTest() {
1456
+ const { resetModelCatalogCacheForTest } = await import("./server-model-catalog-CWpK65W9.js");
1457
+ await resetModelCatalogCacheForTest();
1458
+ }
1459
+ ensureFengMingCliOnPath();
1460
+ const MAX_MEDIA_TTL_HOURS = 168;
1461
+ const POST_READY_MAINTENANCE_DELAY_MS = 250;
1462
+ let gatewayStartupEarlyModulePromise = null;
1463
+ let gatewayStartupPostAttachModulePromise = null;
1464
+ function loadGatewayStartupEarlyModule() {
1465
+ gatewayStartupEarlyModulePromise ??= import("./server-startup-early-Cn8EE_6N.js");
1466
+ return gatewayStartupEarlyModulePromise;
1467
+ }
1468
+ function loadGatewayStartupPostAttachModule() {
1469
+ gatewayStartupPostAttachModulePromise ??= import("./server-startup-post-attach-CiEki-DC.js");
1470
+ return gatewayStartupPostAttachModulePromise;
1471
+ }
1472
+ function listGatewayStartupChannelPlugins() {
1473
+ return listLoadedChannelPlugins();
1474
+ }
1475
+ function resolveMediaCleanupTtlMs(ttlHoursRaw) {
1476
+ const ttlMs = Math.min(Math.max(ttlHoursRaw, 1), MAX_MEDIA_TTL_HOURS) * 60 * 6e4;
1477
+ if (!Number.isFinite(ttlMs) || !Number.isSafeInteger(ttlMs)) throw new Error(`Invalid media.ttlHours: ${String(ttlHoursRaw)}`);
1478
+ return ttlMs;
1479
+ }
1480
+ const log = createSubsystemLogger("gateway");
1481
+ const logDiscovery = log.child("discovery");
1482
+ const logTailscale = log.child("tailscale");
1483
+ const logChannels = log.child("channels");
1484
+ let cachedChannelRuntimePromise = null;
1485
+ let cachedStartupChannelRuntimePromise = null;
1486
+ function getChannelRuntime() {
1487
+ cachedChannelRuntimePromise ??= import("./runtime-channel-LKOkML3M.js").then(({ createRuntimeChannel }) => createRuntimeChannel());
1488
+ return cachedChannelRuntimePromise;
1489
+ }
1490
+ function getStartupChannelRuntime() {
1491
+ cachedStartupChannelRuntimePromise ??= import("./channel-runtime-contexts--ErfKjrx.js").then(({ createChannelRuntimeContextRegistry }) => ({ runtimeContexts: createChannelRuntimeContextRegistry() }));
1492
+ return cachedStartupChannelRuntimePromise;
1493
+ }
1494
+ async function closeMcpLoopbackServerOnDemand() {
1495
+ const { closeMcpLoopbackServer } = await import("./mcp-http-B1lnh67s.js");
1496
+ await closeMcpLoopbackServer();
1497
+ }
1498
+ let gatewayCloseModulePromise = null;
1499
+ function loadGatewayCloseModule() {
1500
+ gatewayCloseModulePromise ??= import("./server-close.runtime.js");
1501
+ return gatewayCloseModulePromise;
1502
+ }
1503
+ let gatewayModelCatalogModulePromise = null;
1504
+ const loadGatewayModelCatalog = async (...args) => {
1505
+ gatewayModelCatalogModulePromise ??= import("./server-model-catalog-CWpK65W9.js");
1506
+ return (await gatewayModelCatalogModulePromise).loadGatewayModelCatalog(...args);
1507
+ };
1508
+ const logHealth = log.child("health");
1509
+ const logCron = log.child("cron");
1510
+ const logReload = log.child("reload");
1511
+ const logHooks = log.child("hooks");
1512
+ const logPlugins = log.child("plugins");
1513
+ const logWsControl = log.child("ws");
1514
+ const logSecrets = log.child("secrets");
1515
+ const gatewayRuntime = runtimeForLogger(log);
1516
+ function createGatewayStartupTrace() {
1517
+ const logEnabled = isTruthyEnvValue(process.env.FENGMING_GATEWAY_STARTUP_TRACE);
1518
+ let timelineConfig;
1519
+ let eventLoopDelay;
1520
+ const timelineOptions = () => ({
1521
+ ...timelineConfig ? { config: timelineConfig } : {},
1522
+ env: process.env
1523
+ });
1524
+ const eventLoopTimelineEnabled = () => isDiagnosticsTimelineEnabled(timelineOptions()) && isTruthyEnvValue(process.env.FENGMING_DIAGNOSTICS_EVENT_LOOP);
1525
+ const ensureEventLoopDelay = () => {
1526
+ if (eventLoopDelay || !logEnabled && !eventLoopTimelineEnabled()) return;
1527
+ eventLoopDelay = monitorEventLoopDelay({ resolution: 10 });
1528
+ eventLoopDelay.enable();
1529
+ };
1530
+ ensureEventLoopDelay();
1531
+ const started = performance.now();
1532
+ let last = started;
1533
+ let spanSequence = 0;
1534
+ const formatMetric = (key, value) => `${key}=${typeof value === "number" ? value.toFixed(1) : value}`;
1535
+ const mapTimelineName = (name) => {
1536
+ switch (name) {
1537
+ case "config.snapshot": return "config.load";
1538
+ case "config.auth":
1539
+ case "config.final-snapshot":
1540
+ case "runtime.config": return "config.normalize";
1541
+ case "plugins.bootstrap": return "plugins.load";
1542
+ case "runtime.post-attach":
1543
+ case "ready": return "gateway.ready";
1544
+ default: return name;
1545
+ }
1546
+ };
1547
+ const takeEventLoopSample = () => {
1548
+ if (!eventLoopDelay) return;
1549
+ const sample = {
1550
+ p50Ms: eventLoopDelay.percentile(50) / 1e6,
1551
+ p95Ms: eventLoopDelay.percentile(95) / 1e6,
1552
+ p99Ms: eventLoopDelay.percentile(99) / 1e6,
1553
+ maxMs: eventLoopDelay.max / 1e6
1554
+ };
1555
+ eventLoopDelay.reset();
1556
+ return sample;
1557
+ };
1558
+ const emitEventLoopTimelineSample = (activeSpanName, sample) => {
1559
+ if (!eventLoopTimelineEnabled()) return;
1560
+ if (!sample) return;
1561
+ emitDiagnosticsTimelineEvent({
1562
+ type: "eventLoop.sample",
1563
+ name: "eventLoop",
1564
+ phase: "startup",
1565
+ activeSpanName: mapTimelineName(activeSpanName),
1566
+ attributes: activeSpanName === mapTimelineName(activeSpanName) ? void 0 : { traceName: activeSpanName },
1567
+ ...sample
1568
+ }, timelineOptions());
1569
+ };
1570
+ const emit = (name, durationMs, totalMs, eventLoopSample, extras = []) => {
1571
+ const metrics = [["eventLoopMax", `${(eventLoopSample?.maxMs ?? 0).toFixed(1)}ms`], ...extras];
1572
+ recordGatewayRestartTraceSpan(`restart.ready.${name}`, durationMs, totalMs, metrics);
1573
+ if (logEnabled) log.info(`startup trace: ${name} ${durationMs.toFixed(1)}ms total=${totalMs.toFixed(1)}ms ${metrics.map(([key, value]) => formatMetric(key, value)).join(" ")}`);
1574
+ };
1575
+ return {
1576
+ setConfig(config) {
1577
+ timelineConfig = config;
1578
+ ensureEventLoopDelay();
1579
+ },
1580
+ mark(name) {
1581
+ const now = performance.now();
1582
+ const eventLoopSample = takeEventLoopSample();
1583
+ emit(name, now - last, now - started, eventLoopSample);
1584
+ emitDiagnosticsTimelineEvent({
1585
+ type: "mark",
1586
+ name: mapTimelineName(name),
1587
+ phase: "startup",
1588
+ durationMs: now - started,
1589
+ attributes: name === mapTimelineName(name) ? void 0 : { traceName: name }
1590
+ }, timelineOptions());
1591
+ emitEventLoopTimelineSample(name, eventLoopSample);
1592
+ last = now;
1593
+ if (name === "ready") eventLoopDelay?.disable();
1594
+ },
1595
+ detail(name, metrics) {
1596
+ const attributes = Object.fromEntries(metrics);
1597
+ recordGatewayRestartTraceDetail(`restart.ready.${name}`, metrics);
1598
+ if (logEnabled) log.info(`startup trace: ${name} ${metrics.map(([key, value]) => formatMetric(key, value)).join(" ")}`);
1599
+ emitDiagnosticsTimelineEvent({
1600
+ type: "mark",
1601
+ name: mapTimelineName(name),
1602
+ phase: "startup",
1603
+ attributes: {
1604
+ traceName: name,
1605
+ ...attributes
1606
+ }
1607
+ }, timelineOptions());
1608
+ },
1609
+ async measure(name, run, options = {}) {
1610
+ const before = performance.now();
1611
+ const spanId = `gateway-startup-${++spanSequence}`;
1612
+ emitDiagnosticsTimelineEvent({
1613
+ type: "span.start",
1614
+ name: mapTimelineName(name),
1615
+ phase: "startup",
1616
+ spanId,
1617
+ attributes: name === mapTimelineName(name) ? void 0 : { traceName: name }
1618
+ }, timelineOptions());
1619
+ try {
1620
+ const result = await withDiagnosticPhase(mapTimelineName(name), run, { traceName: name });
1621
+ const now = performance.now();
1622
+ emitDiagnosticsTimelineEvent({
1623
+ type: "span.end",
1624
+ name: mapTimelineName(name),
1625
+ phase: "startup",
1626
+ spanId,
1627
+ durationMs: now - before,
1628
+ attributes: name === mapTimelineName(name) ? void 0 : { traceName: name }
1629
+ }, timelineOptions());
1630
+ return result;
1631
+ } catch (error) {
1632
+ const now = performance.now();
1633
+ emitDiagnosticsTimelineEvent({
1634
+ type: "span.error",
1635
+ name: mapTimelineName(name),
1636
+ phase: "startup",
1637
+ spanId,
1638
+ durationMs: now - before,
1639
+ attributes: name === mapTimelineName(name) ? void 0 : { traceName: name },
1640
+ errorName: error instanceof Error ? error.name : typeof error,
1641
+ ...options.omitErrorMessage ? {} : { errorMessage: error instanceof Error ? error.message : String(error) }
1642
+ }, timelineOptions());
1643
+ throw error;
1644
+ } finally {
1645
+ const now = performance.now();
1646
+ const eventLoopSample = takeEventLoopSample();
1647
+ emit(name, now - before, now - started, eventLoopSample);
1648
+ emitEventLoopTimelineSample(name, eventLoopSample);
1649
+ last = now;
1650
+ }
1651
+ }
1652
+ };
1653
+ }
1654
+ function formatRuntimeGatewayAuthTokenWarning() {
1655
+ const base = "Gateway auth token was missing. Generated a runtime token for this startup without changing config; restart will generate a different token.";
1656
+ if (!isNixMode) return `${base} Persist one with \`fengming config set gateway.auth.mode token\` and \`fengming config set gateway.auth.token <token>\`.`;
1657
+ return [
1658
+ base,
1659
+ "In Nix mode, set gateway.auth.token in your Nix-managed FengMing config and rebuild.",
1660
+ "For the first-party Nix flow, see https://github.com/fengming/nix-fengming#quick-start and https://docs.fengming.ai/install/nix."
1661
+ ].join(" ");
1662
+ }
1663
+ async function stopTaskRegistryMaintenanceOnDemand() {
1664
+ const { stopTaskRegistryMaintenance } = await import("./task-registry.maintenance-CJoV6m7Z.js");
1665
+ stopTaskRegistryMaintenance();
1666
+ }
1667
+ function createGatewayAuthRateLimiters(rateLimitConfig) {
1668
+ return {
1669
+ rateLimiter: createAuthRateLimiter(rateLimitConfig ?? {}),
1670
+ browserRateLimiter: createAuthRateLimiter({
1671
+ ...rateLimitConfig,
1672
+ exemptLoopback: false
1673
+ })
1674
+ };
1675
+ }
1676
+ const runDefaultSetupWizard = async (...args) => {
1677
+ const { runSetupWizard } = await import("./setup-Dx56i-oI.js");
1678
+ return runSetupWizard(...args);
1679
+ };
1680
+ async function startGatewayServer(port = 18789, opts = {}) {
1681
+ normalizeStateDirEnv(process.env);
1682
+ const { bootstrapGatewayNetworkRuntime } = await import("./server-network-runtime-hruywBSn.js");
1683
+ bootstrapGatewayNetworkRuntime();
1684
+ const minimalTestGateway = isVitestRuntimeEnv() && process.env.FENGMING_TEST_MINIMAL_GATEWAY === "1";
1685
+ process.env.FENGMING_GATEWAY_PORT = String(port);
1686
+ logAcceptedEnvOption({
1687
+ key: "FENGMING_RAW_STREAM",
1688
+ description: "raw stream logging enabled"
1689
+ });
1690
+ logAcceptedEnvOption({
1691
+ key: "FENGMING_RAW_STREAM_PATH",
1692
+ description: "raw stream log path override"
1693
+ });
1694
+ if (!resumeGatewayRestartTraceFromEnv(process.env, [["source", "env"]])) {
1695
+ const restartHandoff = readGatewayRestartHandoffSync();
1696
+ resumeGatewayRestartTraceFromHandoff(restartHandoff?.restartTrace, [
1697
+ ["source", restartHandoff?.source],
1698
+ ["restartKind", restartHandoff?.restartKind],
1699
+ ["supervisorMode", restartHandoff?.supervisorMode]
1700
+ ]);
1701
+ }
1702
+ const startupTrace = createGatewayStartupTrace();
1703
+ const startupConfigModulePromise = import("./server-startup-config-DB4QEDFT.js");
1704
+ let startupPluginsModulePromise = null;
1705
+ const loadStartupPluginsModule = () => {
1706
+ startupPluginsModulePromise ??= import("./server-startup-plugins-t-YeYibm.js");
1707
+ return startupPluginsModulePromise;
1708
+ };
1709
+ const { loadGatewayStartupConfigSnapshot } = await startupConfigModulePromise;
1710
+ const startupConfigLoad = await startupTrace.measure("config.snapshot", () => loadGatewayStartupConfigSnapshot({
1711
+ minimalTestGateway,
1712
+ log,
1713
+ measure: (name, run) => startupTrace.measure(name, run),
1714
+ ...opts.startupConfigSnapshotRead ? { initialSnapshotRead: opts.startupConfigSnapshotRead } : {}
1715
+ }));
1716
+ const configSnapshot = startupConfigLoad.snapshot;
1717
+ const emitSecretsStateEvent = (code, message, cfg) => {
1718
+ enqueueSystemEvent(`[${code}] ${message}`, {
1719
+ sessionKey: resolveMainSessionKey(cfg),
1720
+ contextKey: code
1721
+ });
1722
+ };
1723
+ const { createRuntimeSecretsActivator } = await startupConfigModulePromise;
1724
+ const activateRuntimeSecrets = createRuntimeSecretsActivator({
1725
+ logSecrets,
1726
+ emitStateEvent: emitSecretsStateEvent,
1727
+ ...startupConfigLoad.pluginMetadataSnapshot ? { pluginMetadataSnapshot: startupConfigLoad.pluginMetadataSnapshot } : {}
1728
+ });
1729
+ let cfgAtStart;
1730
+ let startupInternalWriteHash = null;
1731
+ let startupLastGoodSnapshot = configSnapshot;
1732
+ const startupActivationSourceConfig = configSnapshot.sourceConfig;
1733
+ const startupRuntimeConfig = applyConfigOverrides(configSnapshot.config);
1734
+ startupTrace.setConfig(startupRuntimeConfig);
1735
+ const { prepareGatewayStartupConfig } = await startupConfigModulePromise;
1736
+ const authBootstrap = await startupTrace.measure("config.auth", () => prepareGatewayStartupConfig({
1737
+ configSnapshot,
1738
+ authOverride: opts.auth,
1739
+ tailscaleOverride: opts.tailscale,
1740
+ activateRuntimeSecrets,
1741
+ measure: (name, run, measureOptions) => startupTrace.measure(name, run, measureOptions)
1742
+ }), { omitErrorMessage: true });
1743
+ cfgAtStart = authBootstrap.cfg;
1744
+ startupTrace.setConfig(cfgAtStart);
1745
+ if (authBootstrap.generatedToken) log.warn(formatRuntimeGatewayAuthTokenWarning());
1746
+ const diagnosticsEnabled = isDiagnosticsEnabled(cfgAtStart);
1747
+ setDiagnosticsEnabledForProcess(diagnosticsEnabled);
1748
+ if (diagnosticsEnabled) startDiagnosticHeartbeat(void 0, {
1749
+ getConfig: getRuntimeConfig,
1750
+ startupGraceMs: 6e4
1751
+ });
1752
+ setGatewaySigusr1RestartPolicy({ allowExternal: isRestartEnabled(cfgAtStart) });
1753
+ let getActiveTaskCount = () => 0;
1754
+ setPreRestartDeferralCheck(() => getTotalQueueSize() + getTotalPendingReplies() + getActiveEmbeddedRunCount() + getActiveTaskCount());
1755
+ cfgAtStart = (minimalTestGateway ? {
1756
+ config: cfgAtStart,
1757
+ seededAllowedOrigins: false
1758
+ } : await startupTrace.measure("control-ui.seed", () => maybeSeedControlUiAllowedOriginsAtStartup({
1759
+ config: cfgAtStart,
1760
+ log,
1761
+ runtimeBind: opts.bind,
1762
+ runtimePort: port
1763
+ }))).config;
1764
+ if (startupConfigLoad.wroteConfig || authBootstrap.persistedGeneratedToken) {
1765
+ const startupSnapshot = await startupTrace.measure("config.final-snapshot", () => readConfigFileSnapshot());
1766
+ startupInternalWriteHash = startupSnapshot.hash ?? null;
1767
+ startupLastGoodSnapshot = startupSnapshot;
1768
+ }
1769
+ setRuntimeConfigSnapshot(cfgAtStart, startupLastGoodSnapshot.sourceConfig);
1770
+ const { prepareGatewayPluginBootstrap } = await loadStartupPluginsModule();
1771
+ const pluginBootstrap = await startupTrace.measure("plugins.bootstrap", () => prepareGatewayPluginBootstrap({
1772
+ cfgAtStart,
1773
+ activationSourceConfig: startupActivationSourceConfig,
1774
+ startupRuntimeConfig,
1775
+ pluginMetadataSnapshot: startupConfigLoad.pluginMetadataSnapshot,
1776
+ minimalTestGateway,
1777
+ log,
1778
+ loadRuntimePlugins: false,
1779
+ loadSetupRuntimePlugins: true
1780
+ }));
1781
+ const { gatewayPluginConfigAtStart, defaultWorkspaceDir, deferredConfiguredChannelPluginIds, startupPluginIds, pluginLookUpTable, baseMethods, runtimePluginsLoaded } = pluginBootstrap;
1782
+ const coreGatewayMethodNames = listCoreGatewayMethodNames();
1783
+ setCurrentPluginMetadataSnapshot(pluginLookUpTable, {
1784
+ config: startupActivationSourceConfig,
1785
+ compatibleConfigs: [
1786
+ startupRuntimeConfig,
1787
+ cfgAtStart,
1788
+ gatewayPluginConfigAtStart
1789
+ ],
1790
+ env: process.env,
1791
+ workspaceDir: defaultWorkspaceDir
1792
+ });
1793
+ if (pluginLookUpTable) {
1794
+ const metrics = pluginLookUpTable.metrics;
1795
+ startupTrace.detail("plugins.lookup-table", [
1796
+ ["registrySnapshotMs", metrics.registrySnapshotMs],
1797
+ ["manifestRegistryMs", metrics.manifestRegistryMs],
1798
+ ["startupPlanMs", metrics.startupPlanMs],
1799
+ ["ownerMapsMs", metrics.ownerMapsMs],
1800
+ ["totalMs", metrics.totalMs],
1801
+ ["indexPlugins", String(metrics.indexPluginCount)],
1802
+ ["indexPluginCount", metrics.indexPluginCount],
1803
+ ["manifestPlugins", String(metrics.manifestPluginCount)],
1804
+ ["manifestPluginCount", metrics.manifestPluginCount],
1805
+ ["startupPlugins", String(metrics.startupPluginCount)],
1806
+ ["startupPluginCount", metrics.startupPluginCount],
1807
+ ["deferredChannelPlugins", String(metrics.deferredChannelPluginCount)],
1808
+ ["deferredChannelPluginCount", metrics.deferredChannelPluginCount]
1809
+ ]);
1810
+ }
1811
+ let { pluginRegistry, baseGatewayMethods } = pluginBootstrap;
1812
+ const channelLogs = Object.fromEntries(listGatewayStartupChannelPlugins().map((plugin) => [plugin.id, logChannels.child(plugin.id)]));
1813
+ const channelRuntimeEnvs = Object.fromEntries(Object.entries(channelLogs).map(([id, logger]) => [id, runtimeForLogger(logger)]));
1814
+ const listStartupChannelGatewayMethods = () => {
1815
+ const methods = [];
1816
+ for (const plugin of listGatewayStartupChannelPlugins()) {
1817
+ methods.push(...plugin.gatewayMethods ?? []);
1818
+ for (const descriptor of plugin.gatewayMethodDescriptors ?? []) methods.push(descriptor.name);
1819
+ }
1820
+ return methods;
1821
+ };
1822
+ const listActiveGatewayMethods = (nextBaseGatewayMethods) => uniqueStrings([...nextBaseGatewayMethods, ...listStartupChannelGatewayMethods()]);
1823
+ const runtimeConfig = await startupTrace.measure("runtime.config", async () => {
1824
+ const { resolveGatewayRuntimeConfig } = await import("./server-runtime-config-DNQUMRPi.js");
1825
+ return resolveGatewayRuntimeConfig({
1826
+ cfg: cfgAtStart,
1827
+ port,
1828
+ bind: opts.bind,
1829
+ host: opts.host,
1830
+ controlUiEnabled: opts.controlUiEnabled,
1831
+ openAiChatCompletionsEnabled: opts.openAiChatCompletionsEnabled,
1832
+ openResponsesEnabled: opts.openResponsesEnabled,
1833
+ auth: opts.auth,
1834
+ tailscale: opts.tailscale
1835
+ });
1836
+ });
1837
+ const { bindHost, controlUiEnabled, openAiChatCompletionsEnabled, openAiChatCompletionsConfig, openResponsesEnabled, openResponsesConfig, strictTransportSecurityHeader, controlUiBasePath, controlUiRoot: controlUiRootOverride, resolvedAuth, tailscaleConfig, tailscaleMode } = runtimeConfig;
1838
+ const getResolvedAuth = () => resolveGatewayAuth({
1839
+ authConfig: getActiveSecretsRuntimeSnapshot()?.config.gateway?.auth ?? getRuntimeConfig().gateway?.auth,
1840
+ authOverride: opts.auth,
1841
+ env: process.env,
1842
+ tailscaleMode
1843
+ });
1844
+ const resolveSharedGatewaySessionGenerationForConfig = (config) => resolveSharedGatewaySessionGeneration(resolveGatewayAuth({
1845
+ authConfig: config.gateway?.auth,
1846
+ authOverride: opts.auth,
1847
+ env: process.env,
1848
+ tailscaleMode
1849
+ }), config.gateway?.trustedProxies);
1850
+ const resolveCurrentSharedGatewaySessionGeneration = () => resolveSharedGatewaySessionGeneration(getResolvedAuth(), getRuntimeConfig().gateway?.trustedProxies);
1851
+ const resolveSharedGatewaySessionGenerationForRuntimeSnapshot = () => resolveSharedGatewaySessionGeneration(resolveGatewayAuth({
1852
+ authConfig: getRuntimeConfig().gateway?.auth,
1853
+ authOverride: opts.auth,
1854
+ env: process.env,
1855
+ tailscaleMode
1856
+ }), getRuntimeConfig().gateway?.trustedProxies);
1857
+ const sharedGatewaySessionGenerationState = {
1858
+ current: resolveCurrentSharedGatewaySessionGeneration(),
1859
+ required: null
1860
+ };
1861
+ const preauthHandshakeTimeoutMs = cfgAtStart.gateway?.handshakeTimeoutMs ?? getRuntimeConfig().gateway?.handshakeTimeoutMs;
1862
+ const initialHooksConfig = runtimeConfig.hooksConfig;
1863
+ const initialHookClientIpConfig = resolveHookClientIpConfig(cfgAtStart);
1864
+ const rateLimitConfig = cfgAtStart.gateway?.auth?.rateLimit;
1865
+ const { rateLimiter: authRateLimiter, browserRateLimiter: browserAuthRateLimiter } = createGatewayAuthRateLimiters(rateLimitConfig);
1866
+ const controlUiRootState = await startupTrace.measure("control-ui.root", () => resolveGatewayControlUiRootState({
1867
+ controlUiRootOverride,
1868
+ controlUiEnabled,
1869
+ gatewayRuntime,
1870
+ log
1871
+ }));
1872
+ const wizardRunner = opts.wizardRunner ?? runDefaultSetupWizard;
1873
+ const { wizardSessions, findRunningWizard, purgeWizardSession } = createWizardSessionTracker();
1874
+ const deps = createDefaultDeps();
1875
+ let runtimeState = null;
1876
+ let gatewayCronStartHandled = false;
1877
+ const gatewayTls = await startupTrace.measure("tls.runtime", () => loadGatewayTlsRuntime(cfgAtStart.gateway?.tls, log.child("tls")));
1878
+ if (cfgAtStart.gateway?.tls?.enabled && !gatewayTls.enabled) throw new Error(gatewayTls.error ?? "gateway tls: failed to enable");
1879
+ const serverStartedAt = Date.now();
1880
+ const readinessEventLoopHealth = createGatewayEventLoopHealthMonitor();
1881
+ let startupSidecarsReady = minimalTestGateway;
1882
+ let startupPendingReason = "startup-sidecars";
1883
+ let releaseStartupAccountStarts = () => {};
1884
+ const startupAccountStartsReady = new Promise((resolve) => {
1885
+ releaseStartupAccountStarts = resolve;
1886
+ });
1887
+ const { createChannelManager } = await import("./server-channels-D0Ir52nV.js");
1888
+ const channelManager = createChannelManager({
1889
+ getRuntimeConfig: () => {
1890
+ return resolveGatewayPluginConfig({ config: getRuntimeConfig() });
1891
+ },
1892
+ channelLogs,
1893
+ channelRuntimeEnvs,
1894
+ resolveChannelRuntime: getChannelRuntime,
1895
+ resolveStartupChannelRuntime: getStartupChannelRuntime,
1896
+ getPluginHttpRouteRegistry: () => pluginRegistry,
1897
+ startupTrace,
1898
+ deferStartupAccountStartsUntil: startupAccountStartsReady
1899
+ });
1900
+ const deferStartupSidecars = opts.deferStartupSidecars === true;
1901
+ const isGatewayStartupPending = () => !startupSidecarsReady && !deferStartupSidecars;
1902
+ const getReadiness = createReadinessChecker({
1903
+ channelManager,
1904
+ startedAt: serverStartedAt,
1905
+ getStartupPending: isGatewayStartupPending,
1906
+ getStartupPendingReason: () => startupPendingReason,
1907
+ getEventLoopHealth: readinessEventLoopHealth.snapshot,
1908
+ shouldSkipChannelReadiness: () => isTruthyEnvValue(process.env.FENGMING_SKIP_CHANNELS) || isTruthyEnvValue(process.env.FENGMING_SKIP_PROVIDERS)
1909
+ });
1910
+ log.info("starting HTTP server...");
1911
+ let currentPluginRegistryGatewayContext;
1912
+ const { releasePluginRouteRegistry, httpServer, httpServers, httpBindHosts, startListening, wss, preauthConnectionBudget, clients, broadcast, broadcastToConnIds, agentRunSeq, dedupe, chatRunState, chatRunBuffers, chatDeltaSentAt, chatDeltaLastBroadcastLen, addChatRun, removeChatRun, chatAbortControllers, toolEventRecipients } = await startupTrace.measure("runtime.state", () => createGatewayRuntimeState({
1913
+ cfg: cfgAtStart,
1914
+ bindHost,
1915
+ port,
1916
+ controlUiEnabled,
1917
+ controlUiBasePath,
1918
+ controlUiRoot: controlUiRootState,
1919
+ openAiChatCompletionsEnabled,
1920
+ openAiChatCompletionsConfig,
1921
+ openResponsesEnabled,
1922
+ openResponsesConfig,
1923
+ strictTransportSecurityHeader,
1924
+ resolvedAuth,
1925
+ rateLimiter: authRateLimiter,
1926
+ gatewayTls,
1927
+ getResolvedAuth,
1928
+ hooksConfig: () => runtimeState?.hooksConfig ?? initialHooksConfig,
1929
+ getHookClientIpConfig: () => runtimeState?.hookClientIpConfig ?? initialHookClientIpConfig,
1930
+ pluginRegistry,
1931
+ getPluginRouteRegistry: () => pluginRegistry,
1932
+ getGatewayRequestContext: () => currentPluginRegistryGatewayContext,
1933
+ pinChannelRegistry: !minimalTestGateway,
1934
+ deps,
1935
+ log,
1936
+ logHooks,
1937
+ logPlugins,
1938
+ getReadiness
1939
+ }));
1940
+ const { createGatewayNodeSessionRuntime } = await import("./server-node-session-runtime-BOl2B_ak.js");
1941
+ const { nodeRegistry, nodePresenceTimers, sessionEventSubscribers, sessionMessageSubscribers, nodeSendToSession, nodeSendToAllSubscribed, nodeSubscribe, nodeUnsubscribe, nodeUnsubscribeAll, broadcastVoiceWakeChanged, hasTalkNodeConnected } = createGatewayNodeSessionRuntime({ broadcast });
1942
+ applyGatewayLaneConcurrency(cfgAtStart);
1943
+ runtimeState = createGatewayServerLiveState({
1944
+ hooksConfig: initialHooksConfig,
1945
+ hookClientIpConfig: initialHookClientIpConfig,
1946
+ cronState: createLazyGatewayCronState({
1947
+ cfg: cfgAtStart,
1948
+ deps,
1949
+ broadcast
1950
+ }),
1951
+ gatewayMethods: listActiveGatewayMethods(baseGatewayMethods)
1952
+ });
1953
+ deps.cron = runtimeState.cronState.cron;
1954
+ const pluginHostServices = { get cron() {
1955
+ return runtimeState.cronState.cron;
1956
+ } };
1957
+ let closePreludeStarted = false;
1958
+ let postReadyMaintenanceTimer = null;
1959
+ const clearPostReadyMaintenanceTimer = () => {
1960
+ if (!postReadyMaintenanceTimer) return;
1961
+ clearTimeout(postReadyMaintenanceTimer);
1962
+ postReadyMaintenanceTimer = null;
1963
+ };
1964
+ const markClosePreludeStarted = () => {
1965
+ closePreludeStarted = true;
1966
+ clearPostReadyMaintenanceTimer();
1967
+ };
1968
+ const runClosePrelude = async () => {
1969
+ markClosePreludeStarted();
1970
+ clearPluginMetadataLifecycleCaches();
1971
+ const { runGatewayClosePrelude } = await loadGatewayCloseModule();
1972
+ await runGatewayClosePrelude({
1973
+ ...diagnosticsEnabled ? { stopDiagnostics: stopDiagnosticHeartbeat } : {},
1974
+ clearSkillsRefreshTimer: () => {
1975
+ if (!runtimeState?.skillsRefreshTimer) return;
1976
+ clearTimeout(runtimeState.skillsRefreshTimer);
1977
+ runtimeState.skillsRefreshTimer = null;
1978
+ },
1979
+ skillsChangeUnsub: runtimeState.skillsChangeUnsub,
1980
+ disposeAuthRateLimiter: () => authRateLimiter.dispose(),
1981
+ disposeBrowserAuthRateLimiter: () => browserAuthRateLimiter.dispose(),
1982
+ stopModelPricingRefresh: runtimeState.stopModelPricingRefresh,
1983
+ stopChannelHealthMonitor: () => runtimeState?.channelHealthMonitor?.stop(),
1984
+ stopReadinessEventLoopHealth: readinessEventLoopHealth.stop,
1985
+ clearSecretsRuntimeSnapshot,
1986
+ closeMcpServer: closeMcpLoopbackServerOnDemand
1987
+ });
1988
+ };
1989
+ const { getRuntimeSnapshot, startChannels, startChannel, stopChannel, markChannelLoggedOut } = channelManager;
1990
+ const refreshGatewayHealthSnapshotWithRuntime = (opts) => refreshGatewayHealthSnapshot({
1991
+ ...opts,
1992
+ getRuntimeSnapshot,
1993
+ getEventLoopHealth: readinessEventLoopHealth.snapshot
1994
+ });
1995
+ const stopRegisteredPostReadySidecars = async () => {
1996
+ const postReadySidecars = runtimeState.postReadySidecars;
1997
+ runtimeState.postReadySidecars = [];
1998
+ for (const postReadySidecar of postReadySidecars) await postReadySidecar.stop();
1999
+ };
2000
+ const stopRegisteredGatewayLifetimeSidecars = async () => {
2001
+ const gatewayLifetimeSidecars = runtimeState.gatewayLifetimeSidecars;
2002
+ runtimeState.gatewayLifetimeSidecars = [];
2003
+ for (const gatewayLifetimeSidecar of gatewayLifetimeSidecars) await gatewayLifetimeSidecar.stop();
2004
+ };
2005
+ const createCloseHandler = () => async (opts) => {
2006
+ const channelIds = listLoadedChannelPlugins().map((plugin) => plugin.id);
2007
+ const { createGatewayCloseHandler, drainActiveSessionsForShutdown } = await loadGatewayCloseModule();
2008
+ await createGatewayCloseHandler({
2009
+ bonjourStop: runtimeState.bonjourStop,
2010
+ tailscaleCleanup: runtimeState.tailscaleCleanup,
2011
+ releasePluginRouteRegistry,
2012
+ channelIds,
2013
+ stopChannel,
2014
+ pluginServices: runtimeState.pluginServices,
2015
+ postReadySidecars: runtimeState.postReadySidecars,
2016
+ cron: runtimeState.cronState.cron,
2017
+ heartbeatRunner: runtimeState.heartbeatRunner,
2018
+ updateCheckStop: runtimeState.stopGatewayUpdateCheck,
2019
+ stopTaskRegistryMaintenance: stopTaskRegistryMaintenanceOnDemand,
2020
+ nodePresenceTimers,
2021
+ broadcast,
2022
+ tickInterval: runtimeState.tickInterval,
2023
+ healthInterval: runtimeState.healthInterval,
2024
+ dedupeCleanup: runtimeState.dedupeCleanup,
2025
+ mediaCleanup: runtimeState.mediaCleanup,
2026
+ agentUnsub: runtimeState.agentUnsub,
2027
+ heartbeatUnsub: runtimeState.heartbeatUnsub,
2028
+ transcriptUnsub: runtimeState.transcriptUnsub,
2029
+ lifecycleUnsub: runtimeState.lifecycleUnsub,
2030
+ chatRunState,
2031
+ chatAbortControllers,
2032
+ removeChatRun,
2033
+ agentRunSeq,
2034
+ nodeSendToSession,
2035
+ getPendingReplyCount: getTotalPendingReplies,
2036
+ clients,
2037
+ configReloader: runtimeState.configReloader,
2038
+ wss,
2039
+ httpServer,
2040
+ httpServers,
2041
+ drainActiveSessionsForShutdown
2042
+ })(opts);
2043
+ };
2044
+ let clearFallbackGatewayContextForServer = () => {};
2045
+ const closeOnStartupFailure = async () => {
2046
+ try {
2047
+ await stopRegisteredGatewayLifetimeSidecars();
2048
+ await stopRegisteredPostReadySidecars();
2049
+ await runClosePrelude();
2050
+ await createCloseHandler()({ reason: "gateway startup failed" });
2051
+ } finally {
2052
+ clearFallbackGatewayContextForServer();
2053
+ }
2054
+ };
2055
+ const broadcastVoiceWakeRoutingChanged = (config) => {
2056
+ broadcast("voicewake.routing.changed", { config }, { dropIfSlow: true });
2057
+ };
2058
+ try {
2059
+ const earlyRuntime = await startupTrace.measure("runtime.early", () => loadGatewayStartupEarlyModule().then(({ startGatewayEarlyRuntime }) => startGatewayEarlyRuntime({
2060
+ minimalTestGateway,
2061
+ cfgAtStart,
2062
+ port,
2063
+ gatewayTls,
2064
+ gatewayDirectReachable: !isLoopbackHost(bindHost),
2065
+ tailscaleMode,
2066
+ log,
2067
+ logDiscovery,
2068
+ nodeRegistry,
2069
+ pluginRegistry,
2070
+ broadcast,
2071
+ nodeSendToAllSubscribed,
2072
+ getPresenceVersion,
2073
+ getHealthVersion,
2074
+ refreshGatewayHealthSnapshot: refreshGatewayHealthSnapshotWithRuntime,
2075
+ logHealth,
2076
+ dedupe,
2077
+ chatAbortControllers,
2078
+ chatRunState,
2079
+ chatRunBuffers,
2080
+ chatDeltaSentAt,
2081
+ chatDeltaLastBroadcastLen,
2082
+ removeChatRun,
2083
+ agentRunSeq,
2084
+ nodeSendToSession,
2085
+ ...typeof cfgAtStart.media?.ttlHours === "number" ? { mediaCleanupTtlMs: resolveMediaCleanupTtlMs(cfgAtStart.media.ttlHours) } : {},
2086
+ skillsRefreshDelayMs: runtimeState.skillsRefreshDelayMs,
2087
+ getSkillsRefreshTimer: () => runtimeState.skillsRefreshTimer,
2088
+ setSkillsRefreshTimer: (timer) => {
2089
+ runtimeState.skillsRefreshTimer = timer;
2090
+ },
2091
+ getRuntimeConfig,
2092
+ startupTrace
2093
+ })));
2094
+ runtimeState.bonjourStop = earlyRuntime.bonjourStop;
2095
+ getActiveTaskCount = earlyRuntime.getActiveTaskCount;
2096
+ runtimeState.skillsChangeUnsub = earlyRuntime.skillsChangeUnsub;
2097
+ const [{ startGatewayEventSubscriptions }, { startGatewayRuntimeServices }] = await startupTrace.measure("runtime.post-early-imports", () => Promise.all([import("./server-runtime-subscriptions-Do2o5_WH.js"), import("./server-runtime-startup-services-Dbg0rmkG.js")]));
2098
+ const runtimeSubscriptions = await startupTrace.measure("runtime.subscriptions", () => startGatewayEventSubscriptions({
2099
+ broadcast,
2100
+ broadcastToConnIds,
2101
+ nodeSendToSession,
2102
+ agentRunSeq,
2103
+ chatRunState,
2104
+ toolEventRecipients,
2105
+ sessionEventSubscribers,
2106
+ sessionMessageSubscribers,
2107
+ chatAbortControllers
2108
+ }));
2109
+ Object.assign(runtimeState, runtimeSubscriptions);
2110
+ const runtimeServices = await startupTrace.measure("runtime.services", () => startGatewayRuntimeServices({
2111
+ minimalTestGateway,
2112
+ cfgAtStart,
2113
+ channelManager,
2114
+ log
2115
+ }));
2116
+ Object.assign(runtimeState, runtimeServices);
2117
+ const { execApprovalManager, pluginApprovalManager, extraHandlers, coreGatewayHandlers } = await startupTrace.measure("gateway.handlers", async () => {
2118
+ const [{ createGatewayAuxHandlers }, { coreGatewayHandlers }] = await Promise.all([import("./server-aux-handlers-CXhDTocn.js"), import("./server-methods-C7EnpOhB.js")]);
2119
+ return {
2120
+ ...createGatewayAuxHandlers({
2121
+ log,
2122
+ activateRuntimeSecrets,
2123
+ sharedGatewaySessionGenerationState,
2124
+ resolveSharedGatewaySessionGenerationForConfig,
2125
+ clients,
2126
+ startChannel,
2127
+ stopChannel,
2128
+ logChannels
2129
+ }),
2130
+ coreGatewayHandlers
2131
+ };
2132
+ });
2133
+ const attachedGatewayExtraHandlers = {
2134
+ ...pluginRegistry.gatewayHandlers,
2135
+ ...extraHandlers
2136
+ };
2137
+ let attachedPluginGatewayHandlerKeys = new Set(Object.keys(pluginRegistry.gatewayHandlers));
2138
+ const buildAttachedGatewayMethodRegistry = (nextPluginRegistry) => {
2139
+ const coreDescriptorHandlers = { ...coreGatewayHandlers };
2140
+ const auxHandlers = {};
2141
+ for (const [method, handler] of Object.entries(extraHandlers)) if (isCoreGatewayMethodClassified(method)) coreDescriptorHandlers[method] = handler;
2142
+ else auxHandlers[method] = handler;
2143
+ return createGatewayMethodRegistry([
2144
+ ...createCoreGatewayMethodDescriptors(coreDescriptorHandlers),
2145
+ ...createPluginGatewayMethodDescriptors(nextPluginRegistry),
2146
+ ...createGatewayMethodDescriptorsFromHandlers({
2147
+ handlers: auxHandlers,
2148
+ owner: {
2149
+ kind: "aux",
2150
+ area: "gateway-extra"
2151
+ },
2152
+ defaultScope: ADMIN_SCOPE
2153
+ })
2154
+ ]);
2155
+ };
2156
+ let attachedGatewayMethodRegistry = buildAttachedGatewayMethodRegistry(pluginRegistry);
2157
+ const listAttachedGatewayMethods = () => {
2158
+ const methods = attachedGatewayMethodRegistry.listAdvertisedMethods();
2159
+ methods.push(...listStartupChannelGatewayMethods());
2160
+ return uniqueStrings(methods);
2161
+ };
2162
+ runtimeState.gatewayMethods.splice(0, runtimeState.gatewayMethods.length, ...listAttachedGatewayMethods());
2163
+ const replaceAttachedPluginRuntime = (loaded) => {
2164
+ pluginRegistry = loaded.pluginRegistry;
2165
+ baseGatewayMethods = loaded.gatewayMethods;
2166
+ for (const key of attachedPluginGatewayHandlerKeys) delete attachedGatewayExtraHandlers[key];
2167
+ Object.assign(attachedGatewayExtraHandlers, pluginRegistry.gatewayHandlers);
2168
+ attachedPluginGatewayHandlerKeys = new Set(Object.keys(pluginRegistry.gatewayHandlers));
2169
+ attachedGatewayMethodRegistry = buildAttachedGatewayMethodRegistry(pluginRegistry);
2170
+ runtimeState.gatewayMethods.splice(0, runtimeState.gatewayMethods.length, ...listAttachedGatewayMethods());
2171
+ pinActivePluginHttpRouteRegistry(pluginRegistry);
2172
+ pinActivePluginChannelRegistry(pluginRegistry);
2173
+ };
2174
+ const refreshAttachedGatewayDiscovery = async (nextPluginRegistry) => {
2175
+ if (minimalTestGateway) return;
2176
+ try {
2177
+ const stopPreviousDiscovery = runtimeState.bonjourStop;
2178
+ runtimeState.bonjourStop = null;
2179
+ if (stopPreviousDiscovery) try {
2180
+ await stopPreviousDiscovery();
2181
+ } catch (err) {
2182
+ logDiscovery.warn(`gateway discovery stop failed before plugin refresh: ${String(err)}`);
2183
+ }
2184
+ const { startGatewayPluginDiscovery } = await loadGatewayStartupEarlyModule();
2185
+ runtimeState.bonjourStop = await startGatewayPluginDiscovery({
2186
+ minimalTestGateway,
2187
+ cfgAtStart,
2188
+ port,
2189
+ gatewayTls,
2190
+ gatewayDirectReachable: !isLoopbackHost(bindHost),
2191
+ tailscaleMode,
2192
+ logDiscovery,
2193
+ pluginRegistry: nextPluginRegistry
2194
+ });
2195
+ } catch (err) {
2196
+ logDiscovery.warn(`gateway discovery refresh failed after plugin load: ${String(err)}`);
2197
+ }
2198
+ };
2199
+ const listAttachedChannelConfigTargets = () => new Map(listGatewayStartupChannelPlugins().map((plugin) => [plugin.id, listChannelPluginConfigTargetIds({
2200
+ channelId: plugin.id,
2201
+ pluginId: getLoadedChannelPluginEntryById(plugin.id)?.pluginId,
2202
+ aliases: plugin.meta.aliases
2203
+ })]));
2204
+ const reloadAttachedGatewayPlugins = async (params) => {
2205
+ const beforeChannelTargets = listAttachedChannelConfigTargets();
2206
+ const beforeChannelIds = new Set(beforeChannelTargets.keys());
2207
+ const [{ loadPluginLookUpTable }, { prepareGatewayPluginLoad }, { startPluginServices }] = await Promise.all([
2208
+ import("./plugin-lookup-table-DstCupLB.js"),
2209
+ import("./server-plugin-bootstrap-O6MzvzL8.js"),
2210
+ import("./services-CRSHR0oH.js")
2211
+ ]);
2212
+ const nextPluginLookUpTable = loadPluginLookUpTable({
2213
+ config: params.nextConfig,
2214
+ workspaceDir: defaultWorkspaceDir,
2215
+ env: process.env,
2216
+ activationSourceConfig: params.nextConfig
2217
+ });
2218
+ const nextStartupPluginIds = new Set(nextPluginLookUpTable.startup.pluginIds);
2219
+ const nextStartupChannelIds = /* @__PURE__ */ new Set();
2220
+ for (const plugin of nextPluginLookUpTable.manifestRegistry.plugins) {
2221
+ if (!nextStartupPluginIds.has(plugin.id)) continue;
2222
+ if (plugin.channels.length === 0) {
2223
+ nextStartupChannelIds.add(plugin.id);
2224
+ continue;
2225
+ }
2226
+ for (const channelId of plugin.channels) nextStartupChannelIds.add(channelId);
2227
+ }
2228
+ const channelsToStopBeforeReplace = /* @__PURE__ */ new Set();
2229
+ for (const channelId of beforeChannelIds) {
2230
+ const targetIds = beforeChannelTargets.get(channelId) ?? new Set([channelId]);
2231
+ if (!nextStartupChannelIds.has(channelId) || pluginConfigTargetsChanged(targetIds, params.changedPaths)) channelsToStopBeforeReplace.add(channelId);
2232
+ }
2233
+ await params.beforeReplace(channelsToStopBeforeReplace);
2234
+ setCurrentPluginMetadataSnapshot(nextPluginLookUpTable, {
2235
+ config: params.nextConfig,
2236
+ env: process.env,
2237
+ workspaceDir: defaultWorkspaceDir
2238
+ });
2239
+ const loaded = prepareGatewayPluginLoad({
2240
+ cfg: params.nextConfig,
2241
+ workspaceDir: defaultWorkspaceDir,
2242
+ log,
2243
+ coreGatewayMethodNames,
2244
+ hostServices: pluginHostServices,
2245
+ baseMethods,
2246
+ pluginLookUpTable: nextPluginLookUpTable
2247
+ });
2248
+ const previousPluginServices = runtimeState.pluginServices;
2249
+ runtimeState.pluginServices = null;
2250
+ if (previousPluginServices) await previousPluginServices.stop().catch((err) => {
2251
+ log.warn(`plugin services stop failed during reload: ${String(err)}`);
2252
+ });
2253
+ replaceAttachedPluginRuntime(loaded);
2254
+ await refreshAttachedGatewayDiscovery(loaded.pluginRegistry);
2255
+ try {
2256
+ runtimeState.pluginServices = await startPluginServices({
2257
+ registry: loaded.pluginRegistry,
2258
+ config: params.nextConfig,
2259
+ workspaceDir: defaultWorkspaceDir
2260
+ });
2261
+ } catch (err) {
2262
+ log.warn(`plugin services failed to start after reload: ${String(err)}`);
2263
+ }
2264
+ const afterChannelTargets = listAttachedChannelConfigTargets();
2265
+ const afterChannelIds = new Set(afterChannelTargets.keys());
2266
+ const restartChannels = /* @__PURE__ */ new Set();
2267
+ for (const channelId of new Set([...beforeChannelIds, ...afterChannelIds])) {
2268
+ const targetIds = afterChannelTargets.get(channelId) ?? beforeChannelTargets.get(channelId) ?? new Set([channelId]);
2269
+ if (afterChannelIds.has(channelId) && (beforeChannelIds.has(channelId) !== afterChannelIds.has(channelId) || pluginConfigTargetsChanged(targetIds, params.changedPaths))) restartChannels.add(channelId);
2270
+ }
2271
+ return {
2272
+ restartChannels,
2273
+ activeChannels: afterChannelIds
2274
+ };
2275
+ };
2276
+ const unavailableGatewayMethods = new Set(minimalTestGateway ? [] : STARTUP_UNAVAILABLE_GATEWAY_METHODS);
2277
+ const gatewayRequestContext = await startupTrace.measure("gateway.request-context", async () => {
2278
+ const { createGatewayRequestContext } = await import("./server-request-context-DrlcKs-I.js");
2279
+ return createGatewayRequestContext({
2280
+ deps,
2281
+ runtimeState,
2282
+ getRuntimeConfig,
2283
+ execApprovalManager,
2284
+ pluginApprovalManager,
2285
+ loadGatewayModelCatalog,
2286
+ getHealthCache,
2287
+ refreshHealthSnapshot: refreshGatewayHealthSnapshotWithRuntime,
2288
+ logHealth,
2289
+ logGateway: log,
2290
+ incrementPresenceVersion,
2291
+ getHealthVersion,
2292
+ broadcast,
2293
+ broadcastToConnIds,
2294
+ nodeSendToSession,
2295
+ nodeSendToAllSubscribed,
2296
+ nodeSubscribe,
2297
+ nodeUnsubscribe,
2298
+ nodeUnsubscribeAll,
2299
+ hasConnectedTalkNode: hasTalkNodeConnected,
2300
+ clients,
2301
+ enforceSharedGatewayAuthGenerationForConfigWrite: (nextConfig) => {
2302
+ enforceSharedGatewaySessionGenerationForConfigWrite({
2303
+ state: sharedGatewaySessionGenerationState,
2304
+ nextConfig,
2305
+ resolveRuntimeSnapshotGeneration: resolveSharedGatewaySessionGenerationForRuntimeSnapshot,
2306
+ clients
2307
+ });
2308
+ },
2309
+ nodeRegistry,
2310
+ agentRunSeq,
2311
+ chatAbortControllers,
2312
+ chatAbortedRuns: chatRunState.abortedRuns,
2313
+ chatRunBuffers: chatRunState.buffers,
2314
+ chatDeltaSentAt: chatRunState.deltaSentAt,
2315
+ chatDeltaLastBroadcastLen: chatRunState.deltaLastBroadcastLen,
2316
+ chatDeltaLastBroadcastText: chatRunState.deltaLastBroadcastText,
2317
+ agentDeltaSentAt: chatRunState.agentDeltaSentAt,
2318
+ bufferedAgentEvents: chatRunState.bufferedAgentEvents,
2319
+ clearChatRunState: chatRunState.clearRun,
2320
+ addChatRun,
2321
+ removeChatRun,
2322
+ subscribeSessionEvents: sessionEventSubscribers.subscribe,
2323
+ unsubscribeSessionEvents: sessionEventSubscribers.unsubscribe,
2324
+ subscribeSessionMessageEvents: sessionMessageSubscribers.subscribe,
2325
+ unsubscribeSessionMessageEvents: sessionMessageSubscribers.unsubscribe,
2326
+ unsubscribeAllSessionEvents: (connId) => {
2327
+ sessionEventSubscribers.unsubscribe(connId);
2328
+ sessionMessageSubscribers.unsubscribeAll(connId);
2329
+ },
2330
+ getSessionEventSubscriberConnIds: sessionEventSubscribers.getAll,
2331
+ registerToolEventRecipient: toolEventRecipients.add,
2332
+ dedupe,
2333
+ wizardSessions,
2334
+ findRunningWizard,
2335
+ purgeWizardSession,
2336
+ getRuntimeSnapshot,
2337
+ getEventLoopHealth: readinessEventLoopHealth.snapshot,
2338
+ startChannel,
2339
+ stopChannel,
2340
+ markChannelLoggedOut,
2341
+ wizardRunner,
2342
+ broadcastVoiceWakeChanged,
2343
+ unavailableGatewayMethods,
2344
+ broadcastVoiceWakeRoutingChanged
2345
+ });
2346
+ });
2347
+ currentPluginRegistryGatewayContext = gatewayRequestContext;
2348
+ const fallbackGatewayContextCleanup = setFallbackGatewayContextResolver(() => gatewayRequestContext);
2349
+ clearFallbackGatewayContextForServer = typeof fallbackGatewayContextCleanup === "function" ? () => {
2350
+ fallbackGatewayContextCleanup();
2351
+ } : () => {};
2352
+ if (!minimalTestGateway) {
2353
+ if (runtimePluginsLoaded && deferredConfiguredChannelPluginIds.length > 0) {
2354
+ const { reloadDeferredGatewayPlugins } = await import("./server-plugin-bootstrap-O6MzvzL8.js");
2355
+ const loaded = await startupTrace.measure("gateway.deferred-plugins", () => reloadDeferredGatewayPlugins({
2356
+ cfg: gatewayPluginConfigAtStart,
2357
+ activationSourceConfig: startupActivationSourceConfig,
2358
+ workspaceDir: defaultWorkspaceDir,
2359
+ log,
2360
+ coreGatewayMethodNames,
2361
+ hostServices: pluginHostServices,
2362
+ baseMethods,
2363
+ pluginIds: startupPluginIds,
2364
+ pluginLookUpTable,
2365
+ logDiagnostics: false
2366
+ }));
2367
+ replaceAttachedPluginRuntime(loaded);
2368
+ await refreshAttachedGatewayDiscovery(loaded.pluginRegistry);
2369
+ }
2370
+ }
2371
+ const [{ attachGatewayWsHandlers }, { listPluginNodeCapabilities }] = await startupTrace.measure("gateway.ws-imports", () => Promise.all([import("./server-ws-runtime-uaUpI-e8.js"), import("./route-capability-aTQ4px-E.js")]));
2372
+ const pluginSurfaceScheme = gatewayTls.enabled ? "https" : "http";
2373
+ await startupTrace.measure("gateway.ws-attach", () => attachGatewayWsHandlers({
2374
+ wss,
2375
+ clients,
2376
+ preauthConnectionBudget,
2377
+ port,
2378
+ gatewayHost: bindHost ?? void 0,
2379
+ pluginSurfaceScheme,
2380
+ getPluginNodeCapabilities: () => listPluginNodeCapabilities(pluginRegistry),
2381
+ resolvedAuth,
2382
+ getResolvedAuth,
2383
+ getRequiredSharedGatewaySessionGeneration: () => getRequiredSharedGatewaySessionGeneration(sharedGatewaySessionGenerationState),
2384
+ rateLimiter: authRateLimiter,
2385
+ browserRateLimiter: browserAuthRateLimiter,
2386
+ preauthHandshakeTimeoutMs,
2387
+ isStartupPending: isGatewayStartupPending,
2388
+ gatewayMethods: runtimeState.gatewayMethods,
2389
+ events: GATEWAY_EVENTS,
2390
+ logGateway: log,
2391
+ logHealth,
2392
+ logWsControl,
2393
+ extraHandlers: attachedGatewayExtraHandlers,
2394
+ getMethodRegistry: () => attachedGatewayMethodRegistry,
2395
+ broadcast,
2396
+ context: gatewayRequestContext
2397
+ }));
2398
+ await startupTrace.measure("http.listen", () => startListening());
2399
+ startupTrace.mark("http.bound");
2400
+ const sessionDeliveryRecoveryMaxEnqueuedAt = Date.now();
2401
+ let postAttachRuntimeReturned = false;
2402
+ let scheduledServicesActivated = false;
2403
+ let scheduledServicesModulePromise = null;
2404
+ const loadScheduledServicesModule = () => {
2405
+ scheduledServicesModulePromise ??= import("./server-runtime-services-DCs-gqh_.js");
2406
+ return scheduledServicesModulePromise;
2407
+ };
2408
+ const activateScheduledServicesWhenReady = () => {
2409
+ if (closePreludeStarted || !postAttachRuntimeReturned || !startupSidecarsReady || scheduledServicesActivated) return;
2410
+ scheduledServicesActivated = true;
2411
+ loadScheduledServicesModule().then((gatewayRuntimeServices) => {
2412
+ if (closePreludeStarted) return;
2413
+ const activated = gatewayRuntimeServices.activateGatewayScheduledServices({
2414
+ minimalTestGateway,
2415
+ cfgAtStart,
2416
+ deps,
2417
+ sessionDeliveryRecoveryMaxEnqueuedAt,
2418
+ cron: runtimeState.cronState.cron,
2419
+ startCron: false,
2420
+ logCron,
2421
+ log,
2422
+ pluginLookUpTable
2423
+ });
2424
+ runtimeState.heartbeatRunner = activated.heartbeatRunner;
2425
+ runtimeState.stopModelPricingRefresh = activated.stopModelPricingRefresh;
2426
+ });
2427
+ };
2428
+ ({stopGatewayUpdateCheck: runtimeState.stopGatewayUpdateCheck, tailscaleCleanup: runtimeState.tailscaleCleanup, pluginServices: runtimeState.pluginServices} = await startupTrace.measure("runtime.post-attach", () => loadGatewayStartupPostAttachModule().then(({ startGatewayPostAttachRuntime, stopPostReadySidecarsAfterCloseStarted }) => startGatewayPostAttachRuntime({
2429
+ minimalTestGateway,
2430
+ cfgAtStart,
2431
+ bindHost,
2432
+ bindHosts: httpBindHosts,
2433
+ port,
2434
+ tlsEnabled: gatewayTls.enabled,
2435
+ log,
2436
+ isNixMode,
2437
+ startupStartedAt: opts.startupStartedAt,
2438
+ broadcast,
2439
+ tailscaleMode,
2440
+ resetOnExit: tailscaleConfig.resetOnExit ?? false,
2441
+ preserveFunnel: tailscaleConfig.preserveFunnel ?? false,
2442
+ controlUiBasePath,
2443
+ logTailscale,
2444
+ gatewayPluginConfigAtStart,
2445
+ pluginRegistry,
2446
+ defaultWorkspaceDir,
2447
+ deps,
2448
+ startChannels,
2449
+ logHooks,
2450
+ logChannels,
2451
+ unavailableGatewayMethods,
2452
+ loadStartupPlugins: runtimePluginsLoaded ? void 0 : async () => {
2453
+ const { loadGatewayStartupPluginRuntime } = await loadStartupPluginsModule();
2454
+ return loadGatewayStartupPluginRuntime({
2455
+ cfg: gatewayPluginConfigAtStart,
2456
+ activationSourceConfig: startupActivationSourceConfig,
2457
+ workspaceDir: defaultWorkspaceDir,
2458
+ log,
2459
+ baseMethods,
2460
+ coreGatewayMethodNames,
2461
+ hostServices: pluginHostServices,
2462
+ startupPluginIds,
2463
+ pluginLookUpTable,
2464
+ startupTrace
2465
+ });
2466
+ },
2467
+ onStartupPluginsLoading: () => {
2468
+ startupPendingReason = "startup-sidecars";
2469
+ },
2470
+ onStartupPluginsLoaded: async (loaded) => {
2471
+ replaceAttachedPluginRuntime(loaded);
2472
+ startupPendingReason = "startup-sidecars";
2473
+ await refreshAttachedGatewayDiscovery(loaded.pluginRegistry);
2474
+ },
2475
+ getCronService: () => runtimeState?.cronState.cron,
2476
+ onChannelsStarted: () => {
2477
+ releaseStartupAccountStarts();
2478
+ },
2479
+ onPluginServices: (pluginServices) => {
2480
+ runtimeState.pluginServices = pluginServices;
2481
+ },
2482
+ onPostReadySidecars: (postReadySidecars) => {
2483
+ runtimeState.postReadySidecars = postReadySidecars;
2484
+ stopPostReadySidecarsAfterCloseStarted({
2485
+ postReadySidecars,
2486
+ closeStarted: closePreludeStarted
2487
+ });
2488
+ if (closePreludeStarted) runtimeState.postReadySidecars = [];
2489
+ },
2490
+ onGatewayLifetimeSidecars: (gatewayLifetimeSidecars) => {
2491
+ runtimeState.gatewayLifetimeSidecars = gatewayLifetimeSidecars;
2492
+ stopPostReadySidecarsAfterCloseStarted({
2493
+ postReadySidecars: gatewayLifetimeSidecars,
2494
+ closeStarted: closePreludeStarted
2495
+ });
2496
+ if (closePreludeStarted) runtimeState.gatewayLifetimeSidecars = [];
2497
+ },
2498
+ onSidecarsReady: () => {
2499
+ startupSidecarsReady = true;
2500
+ activateScheduledServicesWhenReady();
2501
+ },
2502
+ isClosing: () => closePreludeStarted,
2503
+ startupTrace,
2504
+ deferSidecars: deferStartupSidecars,
2505
+ logReadyOnSidecars: !deferStartupSidecars,
2506
+ providerAuthPrewarm: { getConfig: getRuntimeConfig }
2507
+ }))));
2508
+ startupTrace.detail("memory.ready", collectGatewayProcessMemoryUsageMb());
2509
+ startupTrace.mark("ready");
2510
+ if (deferStartupSidecars) log.info("gateway ready");
2511
+ finishGatewayRestartTrace("restart.ready", collectGatewayProcessMemoryUsageMb());
2512
+ postAttachRuntimeReturned = true;
2513
+ activateScheduledServicesWhenReady();
2514
+ const { startManagedGatewayConfigReloader } = await import("./server-reload-handlers-C-6TyPvI.js");
2515
+ runtimeState.configReloader = startManagedGatewayConfigReloader({
2516
+ minimalTestGateway,
2517
+ initialConfig: cfgAtStart,
2518
+ initialCompareConfig: startupLastGoodSnapshot.sourceConfig,
2519
+ initialInternalWriteHash: startupInternalWriteHash,
2520
+ watchPath: configSnapshot.path,
2521
+ readSnapshot: readConfigFileSnapshot,
2522
+ promoteSnapshot: promoteConfigSnapshotToLastKnownGood,
2523
+ subscribeToWrites: registerConfigWriteListener,
2524
+ deps,
2525
+ broadcast,
2526
+ getState: () => ({
2527
+ hooksConfig: runtimeState.hooksConfig,
2528
+ hookClientIpConfig: runtimeState.hookClientIpConfig,
2529
+ heartbeatRunner: runtimeState.heartbeatRunner,
2530
+ cronState: runtimeState.cronState,
2531
+ channelHealthMonitor: runtimeState.channelHealthMonitor
2532
+ }),
2533
+ setState: (nextState) => {
2534
+ const cronStateChanged = nextState.cronState !== runtimeState.cronState;
2535
+ runtimeState.hooksConfig = nextState.hooksConfig;
2536
+ runtimeState.hookClientIpConfig = nextState.hookClientIpConfig;
2537
+ runtimeState.heartbeatRunner = nextState.heartbeatRunner;
2538
+ runtimeState.cronState = nextState.cronState;
2539
+ deps.cron = runtimeState.cronState.cron;
2540
+ runtimeState.channelHealthMonitor = nextState.channelHealthMonitor;
2541
+ if (cronStateChanged) gatewayCronStartHandled = true;
2542
+ },
2543
+ startChannel,
2544
+ stopChannel,
2545
+ stopPostReadySidecars: stopRegisteredPostReadySidecars,
2546
+ reloadPlugins: reloadAttachedGatewayPlugins,
2547
+ logHooks,
2548
+ logChannels,
2549
+ logCron,
2550
+ logReload,
2551
+ onCronRestart: () => {
2552
+ gatewayCronStartHandled = true;
2553
+ },
2554
+ channelManager,
2555
+ activateRuntimeSecrets,
2556
+ resolveSharedGatewaySessionGenerationForConfig,
2557
+ sharedGatewaySessionGenerationState,
2558
+ clients
2559
+ });
2560
+ await promoteConfigSnapshotToLastKnownGood(startupLastGoodSnapshot).catch((err) => {
2561
+ log.warn(`gateway: failed to promote config last-known-good backup: ${String(err)}`);
2562
+ });
2563
+ if (!minimalTestGateway) postReadyMaintenanceTimer = (await loadScheduledServicesModule()).scheduleGatewayPostReadyMaintenance({
2564
+ delayMs: POST_READY_MAINTENANCE_DELAY_MS,
2565
+ isClosing: () => closePreludeStarted,
2566
+ onStarted: () => {
2567
+ postReadyMaintenanceTimer = null;
2568
+ },
2569
+ startMaintenance: async () => {
2570
+ if (closePreludeStarted) return null;
2571
+ return earlyRuntime.startMaintenance();
2572
+ },
2573
+ applyMaintenance: (maintenance) => {
2574
+ if (closePreludeStarted) {
2575
+ clearInterval(maintenance.tickInterval);
2576
+ clearInterval(maintenance.healthInterval);
2577
+ clearInterval(maintenance.dedupeCleanup);
2578
+ if (maintenance.mediaCleanup) clearInterval(maintenance.mediaCleanup);
2579
+ return;
2580
+ }
2581
+ runtimeState.tickInterval = maintenance.tickInterval;
2582
+ runtimeState.healthInterval = maintenance.healthInterval;
2583
+ runtimeState.dedupeCleanup = maintenance.dedupeCleanup;
2584
+ runtimeState.mediaCleanup = maintenance.mediaCleanup;
2585
+ },
2586
+ shouldStartCron: () => !closePreludeStarted && !gatewayCronStartHandled,
2587
+ markCronStartHandled: () => {
2588
+ gatewayCronStartHandled = true;
2589
+ },
2590
+ cron: runtimeState.cronState.cron,
2591
+ logCron,
2592
+ log,
2593
+ recordPostReadyMemory: () => {
2594
+ startupTrace.detail("memory.post-ready", collectGatewayProcessMemoryUsageMb());
2595
+ }
2596
+ });
2597
+ else startupTrace.detail("memory.post-ready", collectGatewayProcessMemoryUsageMb());
2598
+ } catch (err) {
2599
+ await closeOnStartupFailure();
2600
+ throw err;
2601
+ }
2602
+ const close = createCloseHandler();
2603
+ return { close: async (opts) => {
2604
+ try {
2605
+ markClosePreludeStarted();
2606
+ await stopRegisteredGatewayLifetimeSidecars();
2607
+ await stopRegisteredPostReadySidecars();
2608
+ const { runGlobalGatewayStopSafely } = await import("./plugins/hook-runner-global.js");
2609
+ await runGlobalGatewayStopSafely({
2610
+ event: { reason: opts?.reason ?? "gateway stopping" },
2611
+ ctx: { port },
2612
+ onError: (err) => log.warn(`gateway_stop hook failed: ${String(err)}`)
2613
+ });
2614
+ await runClosePrelude();
2615
+ await close(opts);
2616
+ } finally {
2617
+ clearFallbackGatewayContextForServer();
2618
+ }
2619
+ } };
2620
+ }
2621
+ //#endregion
2622
+ export { resetModelCatalogCacheForTest, startGatewayServer };