@robota-sdk/agent-core 3.0.0-beta.8 → 3.0.0-beta.81

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 (557) hide show
  1. package/CHANGELOG.md +844 -0
  2. package/LICENSE +661 -21
  3. package/README.md +153 -26
  4. package/dist/browser/bounded-output-DpjpS98g.js +2 -0
  5. package/dist/browser/bounded-output-DpjpS98g.js.map +1 -0
  6. package/dist/browser/command-executor-cI7XJ374.js +2 -0
  7. package/dist/browser/command-executor-cI7XJ374.js.map +1 -0
  8. package/dist/browser/http-executor-CHy6UeBU.js +2 -0
  9. package/dist/browser/http-executor-CHy6UeBU.js.map +1 -0
  10. package/dist/browser/index.d.ts +6381 -3394
  11. package/dist/browser/index.d.ts.map +1 -0
  12. package/dist/browser/index.js +13 -5
  13. package/dist/browser/index.js.map +1 -0
  14. package/dist/browser/verdict-decoder-Dk_w2NG9.js +2 -0
  15. package/dist/browser/verdict-decoder-Dk_w2NG9.js.map +1 -0
  16. package/dist/node/bounded-output-DpjpS98g.js +2 -0
  17. package/dist/node/bounded-output-DpjpS98g.js.map +1 -0
  18. package/dist/node/command-executor-Aat_q7P2.cjs +1 -0
  19. package/dist/node/command-executor-DV-H2oD6.js +2 -0
  20. package/dist/node/command-executor-DV-H2oD6.js.map +1 -0
  21. package/dist/node/http-executor-71JiIdFP.cjs +1 -0
  22. package/dist/node/http-executor-cWzI2svn.js +2 -0
  23. package/dist/node/http-executor-cWzI2svn.js.map +1 -0
  24. package/dist/node/index-CiFlpr7-.d.cts +6893 -0
  25. package/dist/node/index-CiFlpr7-.d.cts.map +1 -0
  26. package/dist/node/index-DFlMw376.d.ts +6893 -0
  27. package/dist/node/index-DFlMw376.d.ts.map +1 -0
  28. package/dist/node/index.cjs +12 -5
  29. package/dist/node/index.d.cts +3 -4238
  30. package/dist/node/index.d.ts +3 -4238
  31. package/dist/node/index.js +13 -5
  32. package/dist/node/index.js.map +1 -0
  33. package/dist/node/node.cjs +1 -0
  34. package/dist/node/node.d.cts +236 -0
  35. package/dist/node/node.d.cts.map +1 -0
  36. package/dist/node/node.d.ts +236 -0
  37. package/dist/node/node.d.ts.map +1 -0
  38. package/dist/node/node.js +2 -0
  39. package/dist/node/node.js.map +1 -0
  40. package/dist/node/project-tool-schema-DrDjGKnH.cjs +1 -0
  41. package/dist/node/project-tool-schema-_UKfY7yO.js +2 -0
  42. package/dist/node/project-tool-schema-_UKfY7yO.js.map +1 -0
  43. package/dist/node/rolldown-runtime-DK3Fl9T5.js +1 -0
  44. package/dist/node/rolldown-runtime-DWNI8pZO.cjs +1 -0
  45. package/dist/node/testing/index.cjs +1 -0
  46. package/dist/node/testing/index.d.cts +96 -0
  47. package/dist/node/testing/index.d.cts.map +1 -0
  48. package/dist/node/testing/index.d.ts +96 -0
  49. package/dist/node/testing/index.d.ts.map +1 -0
  50. package/dist/node/testing/index.js +2 -0
  51. package/dist/node/testing/index.js.map +1 -0
  52. package/dist/node/types-gNrckgFE.d.cts +335 -0
  53. package/dist/node/types-gNrckgFE.d.cts.map +1 -0
  54. package/dist/node/types-gNrckgFE.d.ts +335 -0
  55. package/dist/node/types-gNrckgFE.d.ts.map +1 -0
  56. package/dist/node/verdict-decoder-Dk_w2NG9.js +2 -0
  57. package/dist/node/verdict-decoder-Dk_w2NG9.js.map +1 -0
  58. package/dist/node/verdict-decoder-Estx9MtY.cjs +1 -0
  59. package/package.json +89 -23
  60. package/dist/abstracts/abstract-agent.d.ts +0 -56
  61. package/dist/abstracts/abstract-agent.d.ts.map +0 -1
  62. package/dist/abstracts/abstract-agent.js +0 -55
  63. package/dist/abstracts/abstract-agent.js.map +0 -1
  64. package/dist/abstracts/abstract-ai-provider.d.ts +0 -187
  65. package/dist/abstracts/abstract-ai-provider.d.ts.map +0 -1
  66. package/dist/abstracts/abstract-ai-provider.js +0 -252
  67. package/dist/abstracts/abstract-ai-provider.js.map +0 -1
  68. package/dist/abstracts/abstract-executor.d.ts +0 -110
  69. package/dist/abstracts/abstract-executor.d.ts.map +0 -1
  70. package/dist/abstracts/abstract-executor.js +0 -156
  71. package/dist/abstracts/abstract-executor.js.map +0 -1
  72. package/dist/abstracts/abstract-manager.d.ts +0 -42
  73. package/dist/abstracts/abstract-manager.d.ts.map +0 -1
  74. package/dist/abstracts/abstract-manager.js +0 -49
  75. package/dist/abstracts/abstract-manager.js.map +0 -1
  76. package/dist/abstracts/abstract-module.d.ts +0 -365
  77. package/dist/abstracts/abstract-module.d.ts.map +0 -1
  78. package/dist/abstracts/abstract-module.js +0 -474
  79. package/dist/abstracts/abstract-module.js.map +0 -1
  80. package/dist/abstracts/abstract-plugin.d.ts +0 -369
  81. package/dist/abstracts/abstract-plugin.d.ts.map +0 -1
  82. package/dist/abstracts/abstract-plugin.js +0 -258
  83. package/dist/abstracts/abstract-plugin.js.map +0 -1
  84. package/dist/abstracts/abstract-tool.d.ts +0 -175
  85. package/dist/abstracts/abstract-tool.d.ts.map +0 -1
  86. package/dist/abstracts/abstract-tool.js +0 -140
  87. package/dist/abstracts/abstract-tool.js.map +0 -1
  88. package/dist/abstracts/abstract-workflow-converter.d.ts +0 -136
  89. package/dist/abstracts/abstract-workflow-converter.d.ts.map +0 -1
  90. package/dist/abstracts/abstract-workflow-converter.js +0 -252
  91. package/dist/abstracts/abstract-workflow-converter.js.map +0 -1
  92. package/dist/abstracts/abstract-workflow-validator.d.ts +0 -203
  93. package/dist/abstracts/abstract-workflow-validator.d.ts.map +0 -1
  94. package/dist/abstracts/abstract-workflow-validator.js +0 -447
  95. package/dist/abstracts/abstract-workflow-validator.js.map +0 -1
  96. package/dist/abstracts/index.d.ts +0 -6
  97. package/dist/abstracts/index.d.ts.map +0 -1
  98. package/dist/abstracts/index.js +0 -9
  99. package/dist/abstracts/index.js.map +0 -1
  100. package/dist/agents/constants.d.ts +0 -23
  101. package/dist/agents/constants.d.ts.map +0 -1
  102. package/dist/agents/constants.js +0 -22
  103. package/dist/agents/constants.js.map +0 -1
  104. package/dist/agents/index.d.ts +0 -1
  105. package/dist/agents/index.d.ts.map +0 -1
  106. package/dist/agents/index.js +0 -4
  107. package/dist/agents/index.js.map +0 -1
  108. package/dist/agents/robota.test.d.ts +0 -2
  109. package/dist/agents/robota.test.d.ts.map +0 -1
  110. package/dist/agents/robota.test.js +0 -416
  111. package/dist/agents/robota.test.js.map +0 -1
  112. package/dist/browser/builtin-templates.json +0 -107
  113. package/dist/core/robota.d.ts +0 -694
  114. package/dist/core/robota.d.ts.map +0 -1
  115. package/dist/core/robota.js +0 -1277
  116. package/dist/core/robota.js.map +0 -1
  117. package/dist/executors/local-executor.d.ts +0 -96
  118. package/dist/executors/local-executor.d.ts.map +0 -1
  119. package/dist/executors/local-executor.js +0 -197
  120. package/dist/executors/local-executor.js.map +0 -1
  121. package/dist/executors/local-executor.test.d.ts +0 -2
  122. package/dist/executors/local-executor.test.d.ts.map +0 -1
  123. package/dist/executors/local-executor.test.js +0 -192
  124. package/dist/executors/local-executor.test.js.map +0 -1
  125. package/dist/index.d.ts +0 -274
  126. package/dist/index.d.ts.map +0 -1
  127. package/dist/index.js +0 -235
  128. package/dist/index.js.map +0 -1
  129. package/dist/interfaces/agent.d.ts +0 -198
  130. package/dist/interfaces/agent.d.ts.map +0 -1
  131. package/dist/interfaces/agent.js +0 -2
  132. package/dist/interfaces/agent.js.map +0 -1
  133. package/dist/interfaces/event-service.d.ts +0 -79
  134. package/dist/interfaces/event-service.d.ts.map +0 -1
  135. package/dist/interfaces/event-service.js +0 -2
  136. package/dist/interfaces/event-service.js.map +0 -1
  137. package/dist/interfaces/executor.d.ts +0 -128
  138. package/dist/interfaces/executor.d.ts.map +0 -1
  139. package/dist/interfaces/executor.js +0 -2
  140. package/dist/interfaces/executor.js.map +0 -1
  141. package/dist/interfaces/history-module.d.ts +0 -19
  142. package/dist/interfaces/history-module.d.ts.map +0 -1
  143. package/dist/interfaces/history-module.js +0 -2
  144. package/dist/interfaces/history-module.js.map +0 -1
  145. package/dist/interfaces/index.d.ts +0 -13
  146. package/dist/interfaces/index.d.ts.map +0 -1
  147. package/dist/interfaces/index.js +0 -4
  148. package/dist/interfaces/index.js.map +0 -1
  149. package/dist/interfaces/manager.d.ts +0 -142
  150. package/dist/interfaces/manager.d.ts.map +0 -1
  151. package/dist/interfaces/manager.js +0 -2
  152. package/dist/interfaces/manager.js.map +0 -1
  153. package/dist/interfaces/messages.d.ts +0 -75
  154. package/dist/interfaces/messages.d.ts.map +0 -1
  155. package/dist/interfaces/messages.js +0 -29
  156. package/dist/interfaces/messages.js.map +0 -1
  157. package/dist/interfaces/progress-reporting.d.ts +0 -86
  158. package/dist/interfaces/progress-reporting.d.ts.map +0 -1
  159. package/dist/interfaces/progress-reporting.js +0 -37
  160. package/dist/interfaces/progress-reporting.js.map +0 -1
  161. package/dist/interfaces/provider.d.ts +0 -217
  162. package/dist/interfaces/provider.d.ts.map +0 -1
  163. package/dist/interfaces/provider.js +0 -2
  164. package/dist/interfaces/provider.js.map +0 -1
  165. package/dist/interfaces/service.d.ts +0 -205
  166. package/dist/interfaces/service.d.ts.map +0 -1
  167. package/dist/interfaces/service.js +0 -6
  168. package/dist/interfaces/service.js.map +0 -1
  169. package/dist/interfaces/tool.d.ts +0 -248
  170. package/dist/interfaces/tool.d.ts.map +0 -1
  171. package/dist/interfaces/tool.js +0 -2
  172. package/dist/interfaces/tool.js.map +0 -1
  173. package/dist/interfaces/types.d.ts +0 -71
  174. package/dist/interfaces/types.d.ts.map +0 -1
  175. package/dist/interfaces/types.js +0 -33
  176. package/dist/interfaces/types.js.map +0 -1
  177. package/dist/interfaces/workflow-converter.d.ts +0 -193
  178. package/dist/interfaces/workflow-converter.d.ts.map +0 -1
  179. package/dist/interfaces/workflow-converter.js +0 -11
  180. package/dist/interfaces/workflow-converter.js.map +0 -1
  181. package/dist/interfaces/workflow-validator.d.ts +0 -209
  182. package/dist/interfaces/workflow-validator.d.ts.map +0 -1
  183. package/dist/interfaces/workflow-validator.js +0 -16
  184. package/dist/interfaces/workflow-validator.js.map +0 -1
  185. package/dist/managers/agent-factory.d.ts +0 -132
  186. package/dist/managers/agent-factory.d.ts.map +0 -1
  187. package/dist/managers/agent-factory.js +0 -284
  188. package/dist/managers/agent-factory.js.map +0 -1
  189. package/dist/managers/agent-factory.test.d.ts +0 -2
  190. package/dist/managers/agent-factory.test.d.ts.map +0 -1
  191. package/dist/managers/agent-factory.test.js +0 -249
  192. package/dist/managers/agent-factory.test.js.map +0 -1
  193. package/dist/managers/agent-templates.d.ts +0 -84
  194. package/dist/managers/agent-templates.d.ts.map +0 -1
  195. package/dist/managers/agent-templates.js +0 -159
  196. package/dist/managers/agent-templates.js.map +0 -1
  197. package/dist/managers/ai-provider-manager.d.ts +0 -80
  198. package/dist/managers/ai-provider-manager.d.ts.map +0 -1
  199. package/dist/managers/ai-provider-manager.js +0 -226
  200. package/dist/managers/ai-provider-manager.js.map +0 -1
  201. package/dist/managers/conversation-history-manager.d.ts +0 -455
  202. package/dist/managers/conversation-history-manager.d.ts.map +0 -1
  203. package/dist/managers/conversation-history-manager.js +0 -578
  204. package/dist/managers/conversation-history-manager.js.map +0 -1
  205. package/dist/managers/conversation-history-manager.test.d.ts +0 -2
  206. package/dist/managers/conversation-history-manager.test.d.ts.map +0 -1
  207. package/dist/managers/conversation-history-manager.test.js +0 -374
  208. package/dist/managers/conversation-history-manager.test.js.map +0 -1
  209. package/dist/managers/index.d.ts +0 -8
  210. package/dist/managers/index.d.ts.map +0 -1
  211. package/dist/managers/index.js +0 -8
  212. package/dist/managers/index.js.map +0 -1
  213. package/dist/managers/module-registry.d.ts +0 -161
  214. package/dist/managers/module-registry.d.ts.map +0 -1
  215. package/dist/managers/module-registry.js +0 -519
  216. package/dist/managers/module-registry.js.map +0 -1
  217. package/dist/managers/module-type-registry.d.ts +0 -113
  218. package/dist/managers/module-type-registry.d.ts.map +0 -1
  219. package/dist/managers/module-type-registry.js +0 -439
  220. package/dist/managers/module-type-registry.js.map +0 -1
  221. package/dist/managers/plugins.d.ts +0 -166
  222. package/dist/managers/plugins.d.ts.map +0 -1
  223. package/dist/managers/plugins.js +0 -339
  224. package/dist/managers/plugins.js.map +0 -1
  225. package/dist/managers/tool-manager.d.ts +0 -70
  226. package/dist/managers/tool-manager.d.ts.map +0 -1
  227. package/dist/managers/tool-manager.js +0 -138
  228. package/dist/managers/tool-manager.js.map +0 -1
  229. package/dist/managers/tool-manager.test.d.ts +0 -2
  230. package/dist/managers/tool-manager.test.d.ts.map +0 -1
  231. package/dist/managers/tool-manager.test.js +0 -186
  232. package/dist/managers/tool-manager.test.js.map +0 -1
  233. package/dist/node/builtin-templates.json +0 -107
  234. package/dist/plugins/conversation-history/conversation-history-plugin.d.ts +0 -67
  235. package/dist/plugins/conversation-history/conversation-history-plugin.d.ts.map +0 -1
  236. package/dist/plugins/conversation-history/conversation-history-plugin.js +0 -270
  237. package/dist/plugins/conversation-history/conversation-history-plugin.js.map +0 -1
  238. package/dist/plugins/conversation-history/index.d.ts +0 -3
  239. package/dist/plugins/conversation-history/index.d.ts.map +0 -1
  240. package/dist/plugins/conversation-history/index.js +0 -2
  241. package/dist/plugins/conversation-history/index.js.map +0 -1
  242. package/dist/plugins/conversation-history/storages/database-storage.d.ts +0 -19
  243. package/dist/plugins/conversation-history/storages/database-storage.d.ts.map +0 -1
  244. package/dist/plugins/conversation-history/storages/database-storage.js +0 -94
  245. package/dist/plugins/conversation-history/storages/database-storage.js.map +0 -1
  246. package/dist/plugins/conversation-history/storages/file-storage.d.ts +0 -15
  247. package/dist/plugins/conversation-history/storages/file-storage.d.ts.map +0 -1
  248. package/dist/plugins/conversation-history/storages/file-storage.js +0 -94
  249. package/dist/plugins/conversation-history/storages/file-storage.js.map +0 -1
  250. package/dist/plugins/conversation-history/storages/index.d.ts +0 -4
  251. package/dist/plugins/conversation-history/storages/index.d.ts.map +0 -1
  252. package/dist/plugins/conversation-history/storages/index.js +0 -4
  253. package/dist/plugins/conversation-history/storages/index.js.map +0 -1
  254. package/dist/plugins/conversation-history/storages/memory-storage.d.ts +0 -15
  255. package/dist/plugins/conversation-history/storages/memory-storage.d.ts.map +0 -1
  256. package/dist/plugins/conversation-history/storages/memory-storage.js +0 -33
  257. package/dist/plugins/conversation-history/storages/memory-storage.js.map +0 -1
  258. package/dist/plugins/conversation-history/types.d.ts +0 -61
  259. package/dist/plugins/conversation-history/types.d.ts.map +0 -1
  260. package/dist/plugins/conversation-history/types.js +0 -2
  261. package/dist/plugins/conversation-history/types.js.map +0 -1
  262. package/dist/plugins/error-handling/context-adapter.d.ts +0 -30
  263. package/dist/plugins/error-handling/context-adapter.d.ts.map +0 -1
  264. package/dist/plugins/error-handling/context-adapter.js +0 -41
  265. package/dist/plugins/error-handling/context-adapter.js.map +0 -1
  266. package/dist/plugins/error-handling/error-handling-plugin.d.ts +0 -49
  267. package/dist/plugins/error-handling/error-handling-plugin.d.ts.map +0 -1
  268. package/dist/plugins/error-handling/error-handling-plugin.js +0 -229
  269. package/dist/plugins/error-handling/error-handling-plugin.js.map +0 -1
  270. package/dist/plugins/error-handling/index.d.ts +0 -10
  271. package/dist/plugins/error-handling/index.d.ts.map +0 -1
  272. package/dist/plugins/error-handling/index.js +0 -10
  273. package/dist/plugins/error-handling/index.js.map +0 -1
  274. package/dist/plugins/error-handling/types.d.ts +0 -73
  275. package/dist/plugins/error-handling/types.d.ts.map +0 -1
  276. package/dist/plugins/error-handling/types.js +0 -14
  277. package/dist/plugins/error-handling/types.js.map +0 -1
  278. package/dist/plugins/event-emitter/metrics.d.ts +0 -17
  279. package/dist/plugins/event-emitter/metrics.d.ts.map +0 -1
  280. package/dist/plugins/event-emitter/metrics.js +0 -17
  281. package/dist/plugins/event-emitter/metrics.js.map +0 -1
  282. package/dist/plugins/event-emitter/types.d.ts +0 -112
  283. package/dist/plugins/event-emitter/types.d.ts.map +0 -1
  284. package/dist/plugins/event-emitter/types.js +0 -65
  285. package/dist/plugins/event-emitter/types.js.map +0 -1
  286. package/dist/plugins/event-emitter-plugin.d.ts +0 -222
  287. package/dist/plugins/event-emitter-plugin.d.ts.map +0 -1
  288. package/dist/plugins/event-emitter-plugin.js +0 -432
  289. package/dist/plugins/event-emitter-plugin.js.map +0 -1
  290. package/dist/plugins/event-emitter-plugin.test.d.ts +0 -2
  291. package/dist/plugins/event-emitter-plugin.test.d.ts.map +0 -1
  292. package/dist/plugins/event-emitter-plugin.test.js +0 -94
  293. package/dist/plugins/event-emitter-plugin.test.js.map +0 -1
  294. package/dist/plugins/execution/execution-analytics-plugin.d.ts +0 -129
  295. package/dist/plugins/execution/execution-analytics-plugin.d.ts.map +0 -1
  296. package/dist/plugins/execution/execution-analytics-plugin.js +0 -517
  297. package/dist/plugins/execution/execution-analytics-plugin.js.map +0 -1
  298. package/dist/plugins/execution/index.d.ts +0 -3
  299. package/dist/plugins/execution/index.d.ts.map +0 -1
  300. package/dist/plugins/execution/index.js +0 -2
  301. package/dist/plugins/execution/index.js.map +0 -1
  302. package/dist/plugins/execution/types.d.ts +0 -90
  303. package/dist/plugins/execution/types.d.ts.map +0 -1
  304. package/dist/plugins/execution/types.js +0 -2
  305. package/dist/plugins/execution/types.js.map +0 -1
  306. package/dist/plugins/index.d.ts +0 -10
  307. package/dist/plugins/index.d.ts.map +0 -1
  308. package/dist/plugins/index.js +0 -11
  309. package/dist/plugins/index.js.map +0 -1
  310. package/dist/plugins/limits/types.d.ts +0 -61
  311. package/dist/plugins/limits/types.d.ts.map +0 -1
  312. package/dist/plugins/limits/types.js +0 -2
  313. package/dist/plugins/limits/types.js.map +0 -1
  314. package/dist/plugins/limits-plugin.d.ts +0 -113
  315. package/dist/plugins/limits-plugin.d.ts.map +0 -1
  316. package/dist/plugins/limits-plugin.js +0 -380
  317. package/dist/plugins/limits-plugin.js.map +0 -1
  318. package/dist/plugins/logging/formatters.d.ts +0 -14
  319. package/dist/plugins/logging/formatters.d.ts.map +0 -1
  320. package/dist/plugins/logging/formatters.js +0 -24
  321. package/dist/plugins/logging/formatters.js.map +0 -1
  322. package/dist/plugins/logging/index.d.ts +0 -3
  323. package/dist/plugins/logging/index.d.ts.map +0 -1
  324. package/dist/plugins/logging/index.js +0 -2
  325. package/dist/plugins/logging/index.js.map +0 -1
  326. package/dist/plugins/logging/logging-plugin.d.ts +0 -91
  327. package/dist/plugins/logging/logging-plugin.d.ts.map +0 -1
  328. package/dist/plugins/logging/logging-plugin.js +0 -335
  329. package/dist/plugins/logging/logging-plugin.js.map +0 -1
  330. package/dist/plugins/logging/storages/console-storage.d.ts +0 -14
  331. package/dist/plugins/logging/storages/console-storage.d.ts.map +0 -1
  332. package/dist/plugins/logging/storages/console-storage.js +0 -38
  333. package/dist/plugins/logging/storages/console-storage.js.map +0 -1
  334. package/dist/plugins/logging/storages/file-storage.d.ts +0 -14
  335. package/dist/plugins/logging/storages/file-storage.d.ts.map +0 -1
  336. package/dist/plugins/logging/storages/file-storage.js +0 -41
  337. package/dist/plugins/logging/storages/file-storage.js.map +0 -1
  338. package/dist/plugins/logging/storages/index.d.ts +0 -5
  339. package/dist/plugins/logging/storages/index.d.ts.map +0 -1
  340. package/dist/plugins/logging/storages/index.js +0 -5
  341. package/dist/plugins/logging/storages/index.js.map +0 -1
  342. package/dist/plugins/logging/storages/remote-storage.d.ts +0 -20
  343. package/dist/plugins/logging/storages/remote-storage.d.ts.map +0 -1
  344. package/dist/plugins/logging/storages/remote-storage.js +0 -61
  345. package/dist/plugins/logging/storages/remote-storage.js.map +0 -1
  346. package/dist/plugins/logging/storages/silent-storage.d.ts +0 -10
  347. package/dist/plugins/logging/storages/silent-storage.d.ts.map +0 -1
  348. package/dist/plugins/logging/storages/silent-storage.js +0 -15
  349. package/dist/plugins/logging/storages/silent-storage.js.map +0 -1
  350. package/dist/plugins/logging/types.d.ts +0 -84
  351. package/dist/plugins/logging/types.d.ts.map +0 -1
  352. package/dist/plugins/logging/types.js +0 -2
  353. package/dist/plugins/logging/types.js.map +0 -1
  354. package/dist/plugins/performance/collectors/system-metrics-collector.d.ts +0 -12
  355. package/dist/plugins/performance/collectors/system-metrics-collector.d.ts.map +0 -1
  356. package/dist/plugins/performance/collectors/system-metrics-collector.js +0 -65
  357. package/dist/plugins/performance/collectors/system-metrics-collector.js.map +0 -1
  358. package/dist/plugins/performance/index.d.ts +0 -5
  359. package/dist/plugins/performance/index.d.ts.map +0 -1
  360. package/dist/plugins/performance/index.js +0 -4
  361. package/dist/plugins/performance/index.js.map +0 -1
  362. package/dist/plugins/performance/performance-plugin.d.ts +0 -49
  363. package/dist/plugins/performance/performance-plugin.d.ts.map +0 -1
  364. package/dist/plugins/performance/performance-plugin.js +0 -293
  365. package/dist/plugins/performance/performance-plugin.js.map +0 -1
  366. package/dist/plugins/performance/storages/index.d.ts +0 -2
  367. package/dist/plugins/performance/storages/index.d.ts.map +0 -1
  368. package/dist/plugins/performance/storages/index.js +0 -4
  369. package/dist/plugins/performance/storages/index.js.map +0 -1
  370. package/dist/plugins/performance/storages/memory-storage.d.ts +0 -19
  371. package/dist/plugins/performance/storages/memory-storage.d.ts.map +0 -1
  372. package/dist/plugins/performance/storages/memory-storage.js +0 -69
  373. package/dist/plugins/performance/storages/memory-storage.js.map +0 -1
  374. package/dist/plugins/performance/types.d.ts +0 -154
  375. package/dist/plugins/performance/types.d.ts.map +0 -1
  376. package/dist/plugins/performance/types.js +0 -2
  377. package/dist/plugins/performance/types.js.map +0 -1
  378. package/dist/plugins/usage/aggregate-usage-stats.d.ts +0 -12
  379. package/dist/plugins/usage/aggregate-usage-stats.d.ts.map +0 -1
  380. package/dist/plugins/usage/aggregate-usage-stats.js +0 -115
  381. package/dist/plugins/usage/aggregate-usage-stats.js.map +0 -1
  382. package/dist/plugins/usage/index.d.ts +0 -5
  383. package/dist/plugins/usage/index.d.ts.map +0 -1
  384. package/dist/plugins/usage/index.js +0 -4
  385. package/dist/plugins/usage/index.js.map +0 -1
  386. package/dist/plugins/usage/storages/file-storage.d.ts +0 -22
  387. package/dist/plugins/usage/storages/file-storage.d.ts.map +0 -1
  388. package/dist/plugins/usage/storages/file-storage.js +0 -111
  389. package/dist/plugins/usage/storages/file-storage.js.map +0 -1
  390. package/dist/plugins/usage/storages/index.d.ts +0 -5
  391. package/dist/plugins/usage/storages/index.d.ts.map +0 -1
  392. package/dist/plugins/usage/storages/index.js +0 -5
  393. package/dist/plugins/usage/storages/index.js.map +0 -1
  394. package/dist/plugins/usage/storages/memory-storage.d.ts +0 -22
  395. package/dist/plugins/usage/storages/memory-storage.d.ts.map +0 -1
  396. package/dist/plugins/usage/storages/memory-storage.js +0 -42
  397. package/dist/plugins/usage/storages/memory-storage.js.map +0 -1
  398. package/dist/plugins/usage/storages/remote-storage.d.ts +0 -26
  399. package/dist/plugins/usage/storages/remote-storage.d.ts.map +0 -1
  400. package/dist/plugins/usage/storages/remote-storage.js +0 -115
  401. package/dist/plugins/usage/storages/remote-storage.js.map +0 -1
  402. package/dist/plugins/usage/storages/silent-storage.d.ts +0 -19
  403. package/dist/plugins/usage/storages/silent-storage.d.ts.map +0 -1
  404. package/dist/plugins/usage/storages/silent-storage.js +0 -26
  405. package/dist/plugins/usage/storages/silent-storage.js.map +0 -1
  406. package/dist/plugins/usage/types.d.ts +0 -127
  407. package/dist/plugins/usage/types.d.ts.map +0 -1
  408. package/dist/plugins/usage/types.js +0 -2
  409. package/dist/plugins/usage/types.js.map +0 -1
  410. package/dist/plugins/usage/usage-plugin.d.ts +0 -67
  411. package/dist/plugins/usage/usage-plugin.d.ts.map +0 -1
  412. package/dist/plugins/usage/usage-plugin.js +0 -309
  413. package/dist/plugins/usage/usage-plugin.js.map +0 -1
  414. package/dist/plugins/webhook/http-client.d.ts +0 -30
  415. package/dist/plugins/webhook/http-client.d.ts.map +0 -1
  416. package/dist/plugins/webhook/http-client.js +0 -110
  417. package/dist/plugins/webhook/http-client.js.map +0 -1
  418. package/dist/plugins/webhook/index.d.ts +0 -9
  419. package/dist/plugins/webhook/index.d.ts.map +0 -1
  420. package/dist/plugins/webhook/index.js +0 -9
  421. package/dist/plugins/webhook/index.js.map +0 -1
  422. package/dist/plugins/webhook/transformer.d.ts +0 -63
  423. package/dist/plugins/webhook/transformer.d.ts.map +0 -1
  424. package/dist/plugins/webhook/transformer.js +0 -157
  425. package/dist/plugins/webhook/transformer.js.map +0 -1
  426. package/dist/plugins/webhook/types.d.ts +0 -183
  427. package/dist/plugins/webhook/types.d.ts.map +0 -1
  428. package/dist/plugins/webhook/types.js +0 -2
  429. package/dist/plugins/webhook/types.js.map +0 -1
  430. package/dist/plugins/webhook/webhook-plugin.d.ts +0 -92
  431. package/dist/plugins/webhook/webhook-plugin.d.ts.map +0 -1
  432. package/dist/plugins/webhook/webhook-plugin.js +0 -328
  433. package/dist/plugins/webhook/webhook-plugin.js.map +0 -1
  434. package/dist/schemas/agent-template-schema.d.ts +0 -137
  435. package/dist/schemas/agent-template-schema.d.ts.map +0 -1
  436. package/dist/schemas/agent-template-schema.js +0 -87
  437. package/dist/schemas/agent-template-schema.js.map +0 -1
  438. package/dist/services/conversation-service/index.d.ts +0 -88
  439. package/dist/services/conversation-service/index.d.ts.map +0 -1
  440. package/dist/services/conversation-service/index.js +0 -441
  441. package/dist/services/conversation-service/index.js.map +0 -1
  442. package/dist/services/conversation-service/types.d.ts +0 -32
  443. package/dist/services/conversation-service/types.d.ts.map +0 -1
  444. package/dist/services/conversation-service/types.js +0 -8
  445. package/dist/services/conversation-service/types.js.map +0 -1
  446. package/dist/services/event-service.d.ts +0 -61
  447. package/dist/services/event-service.d.ts.map +0 -1
  448. package/dist/services/event-service.js +0 -110
  449. package/dist/services/event-service.js.map +0 -1
  450. package/dist/services/event-service.test.d.ts +0 -2
  451. package/dist/services/event-service.test.d.ts.map +0 -1
  452. package/dist/services/event-service.test.js +0 -86
  453. package/dist/services/event-service.test.js.map +0 -1
  454. package/dist/services/execution-service.d.ts +0 -151
  455. package/dist/services/execution-service.d.ts.map +0 -1
  456. package/dist/services/execution-service.js +0 -1262
  457. package/dist/services/execution-service.js.map +0 -1
  458. package/dist/services/execution-service.test.d.ts +0 -2
  459. package/dist/services/execution-service.test.d.ts.map +0 -1
  460. package/dist/services/execution-service.test.js +0 -338
  461. package/dist/services/execution-service.test.js.map +0 -1
  462. package/dist/services/history-module.d.ts +0 -15
  463. package/dist/services/history-module.d.ts.map +0 -1
  464. package/dist/services/history-module.js +0 -42
  465. package/dist/services/history-module.js.map +0 -1
  466. package/dist/services/in-memory-history-store.d.ts +0 -12
  467. package/dist/services/in-memory-history-store.d.ts.map +0 -1
  468. package/dist/services/in-memory-history-store.js +0 -41
  469. package/dist/services/in-memory-history-store.js.map +0 -1
  470. package/dist/services/index.d.ts +0 -7
  471. package/dist/services/index.d.ts.map +0 -1
  472. package/dist/services/index.js +0 -13
  473. package/dist/services/index.js.map +0 -1
  474. package/dist/services/task-events.d.ts +0 -6
  475. package/dist/services/task-events.d.ts.map +0 -1
  476. package/dist/services/task-events.js +0 -6
  477. package/dist/services/task-events.js.map +0 -1
  478. package/dist/services/tool-execution-service.d.ts +0 -74
  479. package/dist/services/tool-execution-service.d.ts.map +0 -1
  480. package/dist/services/tool-execution-service.js +0 -189
  481. package/dist/services/tool-execution-service.js.map +0 -1
  482. package/dist/services/user-events.d.ts +0 -7
  483. package/dist/services/user-events.d.ts.map +0 -1
  484. package/dist/services/user-events.js +0 -6
  485. package/dist/services/user-events.js.map +0 -1
  486. package/dist/tools/implementations/function-tool/index.d.ts +0 -9
  487. package/dist/tools/implementations/function-tool/index.d.ts.map +0 -1
  488. package/dist/tools/implementations/function-tool/index.js +0 -13
  489. package/dist/tools/implementations/function-tool/index.js.map +0 -1
  490. package/dist/tools/implementations/function-tool/schema-converter.d.ts +0 -32
  491. package/dist/tools/implementations/function-tool/schema-converter.d.ts.map +0 -1
  492. package/dist/tools/implementations/function-tool/schema-converter.js +0 -164
  493. package/dist/tools/implementations/function-tool/schema-converter.js.map +0 -1
  494. package/dist/tools/implementations/function-tool/types.d.ts +0 -72
  495. package/dist/tools/implementations/function-tool/types.d.ts.map +0 -1
  496. package/dist/tools/implementations/function-tool/types.js +0 -14
  497. package/dist/tools/implementations/function-tool/types.js.map +0 -1
  498. package/dist/tools/implementations/function-tool.d.ts +0 -49
  499. package/dist/tools/implementations/function-tool.d.ts.map +0 -1
  500. package/dist/tools/implementations/function-tool.js +0 -223
  501. package/dist/tools/implementations/function-tool.js.map +0 -1
  502. package/dist/tools/implementations/index.d.ts +0 -4
  503. package/dist/tools/implementations/index.d.ts.map +0 -1
  504. package/dist/tools/implementations/index.js +0 -5
  505. package/dist/tools/implementations/index.js.map +0 -1
  506. package/dist/tools/implementations/mcp-tool.d.ts +0 -72
  507. package/dist/tools/implementations/mcp-tool.d.ts.map +0 -1
  508. package/dist/tools/implementations/mcp-tool.js +0 -246
  509. package/dist/tools/implementations/mcp-tool.js.map +0 -1
  510. package/dist/tools/implementations/openapi-tool.d.ts +0 -56
  511. package/dist/tools/implementations/openapi-tool.d.ts.map +0 -1
  512. package/dist/tools/implementations/openapi-tool.js +0 -324
  513. package/dist/tools/implementations/openapi-tool.js.map +0 -1
  514. package/dist/tools/implementations/relay-mcp-tool.d.ts +0 -38
  515. package/dist/tools/implementations/relay-mcp-tool.d.ts.map +0 -1
  516. package/dist/tools/implementations/relay-mcp-tool.js +0 -46
  517. package/dist/tools/implementations/relay-mcp-tool.js.map +0 -1
  518. package/dist/tools/index.d.ts +0 -3
  519. package/dist/tools/index.d.ts.map +0 -1
  520. package/dist/tools/index.js +0 -4
  521. package/dist/tools/index.js.map +0 -1
  522. package/dist/tools/registry/index.d.ts +0 -2
  523. package/dist/tools/registry/index.d.ts.map +0 -1
  524. package/dist/tools/registry/index.js +0 -3
  525. package/dist/tools/registry/index.js.map +0 -1
  526. package/dist/tools/registry/tool-registry.d.ts +0 -54
  527. package/dist/tools/registry/tool-registry.d.ts.map +0 -1
  528. package/dist/tools/registry/tool-registry.js +0 -146
  529. package/dist/tools/registry/tool-registry.js.map +0 -1
  530. package/dist/utils/errors.d.ts +0 -155
  531. package/dist/utils/errors.d.ts.map +0 -1
  532. package/dist/utils/errors.js +0 -203
  533. package/dist/utils/errors.js.map +0 -1
  534. package/dist/utils/execution-proxy.d.ts +0 -75
  535. package/dist/utils/execution-proxy.d.ts.map +0 -1
  536. package/dist/utils/execution-proxy.js +0 -230
  537. package/dist/utils/execution-proxy.js.map +0 -1
  538. package/dist/utils/index.d.ts +0 -11
  539. package/dist/utils/index.d.ts.map +0 -1
  540. package/dist/utils/index.js +0 -7
  541. package/dist/utils/index.js.map +0 -1
  542. package/dist/utils/logger.d.ts +0 -74
  543. package/dist/utils/logger.d.ts.map +0 -1
  544. package/dist/utils/logger.js +0 -143
  545. package/dist/utils/logger.js.map +0 -1
  546. package/dist/utils/message-converter.d.ts +0 -68
  547. package/dist/utils/message-converter.d.ts.map +0 -1
  548. package/dist/utils/message-converter.js +0 -87
  549. package/dist/utils/message-converter.js.map +0 -1
  550. package/dist/utils/periodic-task.d.ts +0 -14
  551. package/dist/utils/periodic-task.d.ts.map +0 -1
  552. package/dist/utils/periodic-task.js +0 -26
  553. package/dist/utils/periodic-task.js.map +0 -1
  554. package/dist/utils/validation.d.ts +0 -40
  555. package/dist/utils/validation.d.ts.map +0 -1
  556. package/dist/utils/validation.js +0 -162
  557. package/dist/utils/validation.js.map +0 -1
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./command-executor-Aat_q7P2.cjs"),t=require("./http-executor-71JiIdFP.cjs");let n=require("node:fs"),r=require("node:path"),i=require("node:dns/promises"),a=require("node:net");function o(e){if(typeof e!=`string`)throw TypeError(`executionRoot must be a string`);if(e.trim().length===0)throw TypeError(`executionRoot must be a non-empty string`);if(!(0,r.isAbsolute)(e))throw TypeError(`executionRoot must be an absolute path`);let t;try{t=(0,n.realpathSync)(e)}catch{throw TypeError(`executionRoot must name an existing accessible directory`)}if(!(0,n.statSync)(t).isDirectory())throw TypeError(`executionRoot must name a directory`);try{(0,n.accessSync)(t,n.constants.R_OK|n.constants.X_OK)}catch{throw TypeError(`executionRoot directory must be readable and traversable`)}return t}function s(e){let t=[],i=(0,r.resolve)(e);for(;;)try{return(0,r.join)((0,n.realpathSync)(i),...t)}catch{let n=(0,r.dirname)(i);if(n===i)return(0,r.resolve)(e);t.unshift((0,r.basename)(i)),i=n}}function c(e,t){let n=s(e),i=s(t);return i===n||i.startsWith(n+r.sep)}var l=class extends Error{constructor(e){super(e),this.name=`OwnerOnlyModeError`}};function u(e=process.platform){return e===`win32`?`windows-acl`:`posix-mode`}function d(e,t){let n=(0,r.relative)(e,t);if(n.startsWith(`..`)||(0,r.isAbsolute)(n))throw new l(`withinRoot ${e} is not an ancestor of ${t}, so this call cannot own the path between them.`);let i=n.split(r.sep).filter(e=>e.length>0),a=[e],o=e;for(let e of i)o=(0,r.join)(o,e),a.push(o);return a}function f(e,t,r={}){if(u()!==`posix-mode`)return;let i=(r.readMode??(e=>(0,n.statSync)(e).mode&4095))(e);if(i&63)throw new l(`${t} ${e} is mode 0${i.toString(8)} after being set owner-only; group or other permissions survived, so its contents are readable by another account.`)}function p(e,t={}){let r=t.makeDirectory??((e,t)=>{(0,n.mkdirSync)(e,{recursive:!0,mode:t})}),i=t.setMode??((e,t)=>(0,n.chmodSync)(e,t));r(e,448);let a=t.withinRoot===void 0?[e]:d(t.withinRoot,e);for(let e of a)u()===`posix-mode`&&i(e,448),f(e,`directory`,t)}function m(e,t){p((0,r.dirname)(e));let i=`${e}.${process.pid}.tmp`;(0,n.rmSync)(i,{force:!0}),(0,n.writeFileSync)(i,t,{encoding:`utf8`,mode:384,flag:`wx`});try{f(i,`file`),(0,n.renameSync)(i,e)}catch(e){try{(0,n.unlinkSync)(i)}catch{}throw e}f(e,`file`)}function h(e){if(u()!==`posix-mode`)return;let t;try{t=(0,n.statSync)(e).mode&4095}catch{return}t&63&&((0,n.chmodSync)(e,384),f(e,`file`))}function g(e){let t=(0,a.isIP)(e);return t===4?_(e.split(`.`).map(Number)):t!==6||v(e)}function _(e){let[t=0,n=0,r=0]=e;return t===0||t===10||t===127||t===100&&n>=64&&n<=127||t===169&&n===254||t===172&&n>=16&&n<=31||t===192&&n===0&&r===0||t===192&&n===168||t===198&&(n===18||n===19)||t>=224}function v(e){let t=b(e);if(t===void 0)return!0;let[n=0,r=0,i=0,a=0,o=0,s=0,c=0,l=0]=t;return n===0&&r===0&&i===0&&a===0&&o===0&&s===65535||n===100&&r===65435&&i===0&&a===0&&o===0&&s===0?_([c>>8,c&255,l>>8,l&255]):n===0&&r===0&&i===0&&a===0&&o===0&&s===0||(n&65024)==64512||(n&65472)==65152||(n&65472)==65216||(n&65280)==65280}function y(e){let t=e.lastIndexOf(`:`),n=e.slice(t+1);if(!n.includes(`.`))return e;if(t<0||(0,a.isIP)(n)!==4)return;let[r=0,i=0,o=0,s=0]=n.split(`.`).map(Number),c=(r<<8|i).toString(16),l=(o<<8|s).toString(16);return`${e.slice(0,t+1)}${c}:${l}`}function b(e){let t=y(e.split(`%`)[0]??e);if(t===void 0)return;let n=t.split(`::`);if(n.length>2)return;let r=e=>e.length===0?[]:e.split(`:`).map(e=>Number.parseInt(e,16)),i=r(n[0]??``),a=n.length===2?r(n[1]??``):[],o=8-i.length-a.length;if(o<0||n.length===1&&o!==0)return;let s=[...i,...Array(o).fill(0),...a];return s.some(e=>Number.isNaN(e)||e<0||e>65535)?void 0:s}const x=3e4,S=5e6,C=new Set([301,302,303,307,308]),w=new Set([`localhost`,`metadata`,`metadata.google.internal`,`metadata.goog`,`instance-data`,`instance-data.ec2.internal`]),T=async e=>(await(0,i.lookup)(e,{all:!0,verbatim:!0})).map(e=>e.address);async function E(e,t={},n=T){let r=e.href;if(e.protocol!==`http:`&&e.protocol!==`https:`)return{reason:`unsupported_scheme`,url:r,message:`Only http(s) URLs may be fetched.`};if(t.allowPrivateAddresses===!0)return;let i=e.hostname.replace(/^\[|\]$/g,``).toLowerCase();if(t.allowedHosts?.includes(i))return;if(w.has(i)||i.endsWith(`.localhost`))return{reason:`metadata_host`,url:r,message:`Destination "${i}" is a loopback or cloud-metadata host and is not reachable from tools.`};let o=(0,a.isIP)(i)?[i]:await D(i,n);if(o===void 0||o.length===0)return{reason:`unresolvable`,url:r,message:`Destination "${i}" did not resolve.`};let s=o.find(g);if(s!==void 0)return{reason:`private_destination`,url:r,message:`Destination "${i}" resolves to ${s}, a private, loopback or link-local address, and is not reachable from tools.`}}async function D(e,t){try{return await t(e)}catch{return}}async function O(e,t={},n={},r={}){let i=r.fetch??((e,t)=>globalThis.fetch(e,t)),a=r.lookup??T,o=t.maxResponseBytes??S,s=n.maxRedirects??5,c=AbortSignal.timeout(t.timeoutMs??x),l=t.signal?AbortSignal.any([c,t.signal]):c,u=new URL(e),d={...t.headers??{}};for(let e=0;;e+=1){let t=await E(u,n,a);if(t!==void 0)return{ok:!1,rejection:t};let r=await i(u.href,{headers:d,signal:l,redirect:`manual`});if(!C.has(r.status))return j(r,u.href,o,l);let c=r.headers.get(`location`);if(c===null)return{ok:!1,rejection:{reason:`redirect_without_location`,url:u.href,message:`HTTP ${r.status} without a Location header.`}};if(e>=s)return{ok:!1,rejection:{reason:`redirect_limit`,url:u.href,message:`More than ${s} redirects.`}};let f=new URL(c,u);f.origin!==u.origin&&(d=A(d)),u=f}}async function k(e,t,n={},r={}){let i=r.fetch??((e,t)=>globalThis.fetch(e,t)),a=t.maxResponseBytes??S,o=AbortSignal.timeout(t.timeoutMs??x),s=t.signal?AbortSignal.any([o,t.signal]):o,c=new URL(e),l=await E(c,n,r.lookup??T);if(l!==void 0)return{ok:!1,rejection:l};let u=await i(c.href,{method:`POST`,headers:{...t.headers??{}},body:t.body,signal:s,redirect:`manual`});return u.status>=300&&u.status<400?(await u.body?.cancel().catch(()=>void 0),{ok:!1,rejection:{reason:`redirect_refused`,url:c.href,message:`HTTP ${u.status}: a POST is never redirected.`}}):j(u,c.href,a,s)}function A(e){let t={};for(let[n,r]of Object.entries(e))n.toLowerCase()===`user-agent`&&(t[n]=r);return t}async function j(e,t,n,r){let i=e=>({ok:!1,rejection:{reason:`response_too_large`,url:t,message:`Response exceeds ${n} bytes (${e} seen).`}}),a=Number(e.headers.get(`content-length`));if(Number.isFinite(a)&&a>n)return await e.body?.cancel(),i(a);let o=[],s=0;if(!e.body&&typeof e.arrayBuffer==`function`){let t=new Uint8Array(await e.arrayBuffer());if(t.byteLength>n)return i(t.byteLength);o.push(t),s=t.byteLength}else if(e.body){let t=e.body.getReader();for(;;){r.throwIfAborted();let{done:e,value:a}=await t.read();if(e)break;if(s+=a.byteLength,s>n)return await t.cancel(),i(s);o.push(a)}}let c=new Uint8Array(s),l=0;for(let e of o)c.set(e,l),l+=e.byteLength;return{ok:!0,status:e.status,statusText:e.statusText,headers:e.headers,body:c,finalUrl:t}}exports.BLOCKED_HOSTNAMES=w,exports.CommandExecutor=e.t,exports.HttpExecutor=t.t,exports.OWNER_ONLY_DIRECTORY_MODE=448,exports.OWNER_ONLY_FILE_MODE=384,exports.OwnerOnlyModeError=l,exports.canonicalizePath=s,exports.ensureOwnerOnlyDirectory=p,exports.fetchWithEgressPolicy=O,exports.isPathInside=c,exports.isPrivateAddress=g,exports.ownerOnlyGuarantee=u,exports.postWithEgressPolicy=k,exports.rejectDestination=E,exports.resolveTrustedExecutionRoot=o,exports.tightenExistingFile=h,exports.writeOwnerOnlyFile=m;
@@ -0,0 +1,236 @@
1
+ import { c as IHookTypeExecutor, l as IHttpHookDefinition, m as THookOutcome, n as ICommandHookDefinition, s as IHookInput, y as ISubprocessTraceEnv } from "./types-gNrckgFE.cjs";
2
+ //#region src/utils/path-containment.d.ts
3
+ /**
4
+ * Validate an authority root more strictly than candidate-path canonicalization.
5
+ *
6
+ * Candidate write paths may have a missing tail, but an authority root must already exist and be a
7
+ * traversable directory. Keeping the contracts separate prevents a typo in a root from degrading to
8
+ * a lexical boundary that the caller did not actually select.
9
+ */
10
+ declare function resolveTrustedExecutionRoot(input: unknown): string;
11
+ /**
12
+ * Resolve `p` to its canonical form, following symlinks, tolerating a path that does not exist yet.
13
+ *
14
+ * `realpathSync` throws on a missing path, but callers legitimately ask about files they are about to
15
+ * CREATE (a write or an edit). So we walk up to the deepest ancestor that does exist, canonicalize
16
+ * that, and re-attach the remaining segments — the re-attached tail cannot itself be a symlink,
17
+ * because it does not exist.
18
+ */
19
+ declare function canonicalizePath(p: string): string;
20
+ /**
21
+ * Whether `candidate` is `root` itself or lies beneath it, decided on the CANONICAL form of both.
22
+ *
23
+ * Canonicalizing the root as well as the candidate matters: a root that is itself reached through a
24
+ * symlink (macOS `/tmp` -> `/private/tmp`, or a workspace under a symlinked home) would otherwise
25
+ * spuriously reject every path inside it.
26
+ */
27
+ declare function isPathInside(root: string, candidate: string): boolean;
28
+ //#endregion
29
+ //#region src/utils/owner-only-store.d.ts
30
+ /**
31
+ * SEC-020 (issue #2021) — creating a host directory or file that only its owner can read.
32
+ *
33
+ * A host application persists session records, logs, settings and device credentials under a directory
34
+ * of its own choosing. They carry prompts, model output, tool results and, in the settings case,
35
+ * provider credentials. On a shared workstation or a CI host, every other local account reads them
36
+ * unless the mode says otherwise.
37
+ *
38
+ * WHERE that directory is belongs to the host, not here — this module knows only what has to be true
39
+ * of whatever path it is handed, which is what lets it be tested without a filesystem layout.
40
+ *
41
+ * ## Why this is one module and not a constant each caller repeats
42
+ *
43
+ * `0o600` and `0o700` were already spelled out in five separate files before this existed, and the
44
+ * repository had already learned — in `guarded-directory.ts`, for a pairing rendezvous — that the
45
+ * constants are the easy half. The load-bearing part is that **`mkdirSync(path, { mode })` does not
46
+ * set the mode of a directory that already exists.** `recursive: true` returns successfully and
47
+ * silently adopts whatever mode is there. A directory left at 0777 by an earlier version, by a
48
+ * shared CI checkout, or by another local user who pre-created it, becomes ours with no signal.
49
+ *
50
+ * Measured under umask 022 before this module existed: a session log directory pre-created at 0777
51
+ * stayed 0777 through `mkdirSync(dir, { recursive: true, mode: 0o700 })`, and its 0600 records were
52
+ * then removable and replaceable by any local account.
53
+ *
54
+ * The same holds for files. `writeFileSync(path, data, { mode })` applies the mode only when the
55
+ * file is CREATED; an existing 0644 record keeps 0644 forever, so a store written by an older
56
+ * version is never repaired by a newer one.
57
+ *
58
+ * So: create, then set the mode unconditionally, then VERIFY — and verification is what makes the
59
+ * first two checkable rather than hopeful. It is also the only step that catches an owner we did not
60
+ * expect, which `mkdir` and `chmod` between them cannot.
61
+ *
62
+ * ## Windows
63
+ *
64
+ * `chmodSync` on win32 toggles the read-only attribute and cannot express "owner only"; NTFS ACL
65
+ * inheritance governs instead, and a user's profile directory is not readable by other unprivileged
66
+ * accounts by default. The POSIX assertion is therefore not made there, and `ownerOnlyGuarantee()` reports which
67
+ * guarantee is in force so a caller — and a test — can state the platform's actual claim rather than
68
+ * assume the POSIX one everywhere. A store directory placed inside a world-writable parent on
69
+ * Windows is NOT protected by this module, and that is recorded rather than papered over.
70
+ */
71
+ /** Owner read/write. Nothing for group, nothing for other. */
72
+ declare const OWNER_ONLY_FILE_MODE = 384;
73
+ /** Owner read/write/traverse. The traverse bit is what keeps another account out of the directory. */
74
+ declare const OWNER_ONLY_DIRECTORY_MODE = 448;
75
+ /** Raised when a path cannot be made owner-only. Never swallowed into a weaker mode. */
76
+ declare class OwnerOnlyModeError extends Error {
77
+ constructor(message: string);
78
+ }
79
+ /**
80
+ * Which guarantee this platform can actually make.
81
+ *
82
+ * `posix-mode` — the mode bits are asserted after every create and every write.
83
+ * `windows-acl` — inherited NTFS ACLs govern; the POSIX assertion is not made and not claimed.
84
+ */
85
+ declare function ownerOnlyGuarantee(platform?: string): 'posix-mode' | 'windows-acl';
86
+ /**
87
+ * Seams for the failure paths, injected for the reason `guarded-directory.ts` states: a filesystem
88
+ * that silently ignores `chmod` is a real condition — some network and FAT mounts do exactly that —
89
+ * and it is the ONLY condition the verification step catches that create-then-chmod does not. Without
90
+ * a seam that case is unreachable from a test, and a guard no test can reach is a guard nobody knows
91
+ * is there. Measured: with these absent, deleting the verification entirely changed no test result.
92
+ */
93
+ interface IOwnerOnlyIo {
94
+ readonly makeDirectory?: (target: string, mode: number) => void;
95
+ readonly setMode?: (target: string, mode: number) => void;
96
+ readonly readMode?: (target: string) => number;
97
+ }
98
+ interface IEnsureOwnerOnlyOptions extends IOwnerOnlyIo {
99
+ /**
100
+ * An ANCESTOR of `directory` that the caller also owns, tightened along with every segment between
101
+ * them.
102
+ *
103
+ * Needed because `mkdirSync(path, { recursive: true, mode })` applies the mode only to the
104
+ * directories it CREATES. A store root an older version already made sits at whatever mode it was
105
+ * given and this call would leave it there — which is the module's own headline defect surviving
106
+ * one level up, on the very path it exists to protect. Found in review of PR #2224.
107
+ *
108
+ * It is a parameter rather than a walk up to some inferred boundary because WHICH ancestors belong
109
+ * to the caller is the caller's knowledge. This module must not guess that a parent is ours; it
110
+ * would eventually chmod someone's home directory.
111
+ */
112
+ readonly withinRoot?: string;
113
+ }
114
+ /**
115
+ * Ensure `directory` exists and only its owner can enter it.
116
+ *
117
+ * The `chmod` is unconditional because `mkdir` does not touch an existing directory's mode, and the
118
+ * `stat` afterwards is what turns two hopeful calls into a checked one.
119
+ */
120
+ declare function ensureOwnerOnlyDirectory(directory: string, options?: IEnsureOwnerOnlyOptions): void;
121
+ /**
122
+ * Replace `filePath` atomically with content only its owner can read.
123
+ *
124
+ * The temp file carries the mode from the moment it is created — writing it at the umask's default
125
+ * and tightening afterwards leaves a window in which the full content is world-readable on disk, and
126
+ * `rename` preserves whatever mode the temp file had. The `chmod` after the write is for the case
127
+ * where the temp path already existed at a wider mode.
128
+ */
129
+ declare function writeOwnerOnlyFile(filePath: string, content: string): void;
130
+ /**
131
+ * Tighten a file that already exists — the repair path for a record an older version left at 0644.
132
+ *
133
+ * A no-op on a path that does not exist, because "there is nothing to tighten" and "we tightened it"
134
+ * are the same outcome for the caller, and throwing would make every writer branch on existence.
135
+ */
136
+ declare function tightenExistingFile(filePath: string): void;
137
+ //#endregion
138
+ //#region src/hooks/executors/command-executor.d.ts
139
+ declare class CommandExecutor implements IHookTypeExecutor {
140
+ private readonly shellExecutable?;
141
+ readonly type: "command";
142
+ constructor(shellExecutable?: string | undefined);
143
+ /**
144
+ * `traceEnv` is the prompt's trace for this child, handed separately so it never reaches the
145
+ * stdin JSON. The child sees `process.env`, then Robota's value, then the hook's own `env`; a hook
146
+ * that sets its own `TRACEPARENT` wins and gets the ambient environment unchanged.
147
+ */
148
+ execute(definition: ICommandHookDefinition, input: IHookInput, traceEnv?: ISubprocessTraceEnv): Promise<THookOutcome>;
149
+ }
150
+ //#endregion
151
+ //#region src/hooks/executors/http-executor.d.ts
152
+ declare class HttpExecutor implements IHookTypeExecutor {
153
+ readonly type: "http";
154
+ execute(definition: IHttpHookDefinition, input: IHookInput): Promise<THookOutcome>;
155
+ }
156
+ //#endregion
157
+ //#region src/utils/ip-address.d.ts
158
+ /**
159
+ * Address classification for the egress boundary (#2026) — the "is this address public unicast?"
160
+ * half of `egress-policy.ts`, split out so each module holds one job: that one owns the FETCH
161
+ * (scheme, redirects, headers, deadline, byte cap), this one owns the ARITHMETIC of an address.
162
+ *
163
+ * The awkward part lives here on purpose. A literal destination reaches the policy already
164
+ * normalized by `URL` (`2130706433`, `0x7f.1` and `[::ffff:7f00:1]` all collapse to one hostname),
165
+ * but a RESOLVED one does not: `dns.lookup` renders an IPv4-mapped AAAA answer through `inet_ntop`,
166
+ * which prints the dotted spelling `::ffff:127.0.0.1`. So the expansion below accepts BOTH
167
+ * spellings rather than trusting any normalizer to have run — on the resolution path an attacker
168
+ * controls the record. Every "cannot parse" answer is `undefined`/`true`, i.e. NOT public: an
169
+ * address this module cannot read is never treated as reachable.
170
+ *
171
+ * Node-only (`node:net`): reached through `egress-policy.ts`, never the browser barrel.
172
+ */
173
+ /** True when `ip` (v4 or v6 text) is not a public unicast address. */
174
+ declare function isPrivateAddress(ip: string): boolean;
175
+ //#endregion
176
+ //#region src/utils/egress-policy.d.ts
177
+ type TEgressLookup = (hostname: string) => Promise<readonly string[]>;
178
+ interface IEgressPolicy {
179
+ /** Exact lowercase hostnames that may be reached even when they resolve to a private address. */
180
+ readonly allowedHosts?: readonly string[];
181
+ /** Explicit enterprise opt-out from private/loopback/metadata blocking. Default `false`. */
182
+ readonly allowPrivateAddresses?: boolean;
183
+ /** Redirect hops followed before refusing. Default 5. */
184
+ readonly maxRedirects?: number;
185
+ }
186
+ interface IEgressFetchOptions {
187
+ readonly headers?: Readonly<Record<string, string>>;
188
+ readonly signal?: AbortSignal;
189
+ /** Deadline for the WHOLE exchange, redirects and body included. Default 30 000 ms. */
190
+ readonly timeoutMs?: number;
191
+ /** Byte cap enforced on `Content-Length` and again while streaming. Default 5 000 000. */
192
+ readonly maxResponseBytes?: number;
193
+ }
194
+ interface IEgressDeps {
195
+ readonly fetch?: typeof globalThis.fetch;
196
+ readonly lookup?: TEgressLookup;
197
+ }
198
+ type TEgressRejectionReason = 'unsupported_scheme' | 'private_destination' | 'metadata_host' | 'unresolvable' | 'redirect_limit' | 'redirect_without_location' | 'redirect_refused' | 'response_too_large';
199
+ interface IEgressRejection {
200
+ readonly reason: TEgressRejectionReason;
201
+ readonly url: string;
202
+ readonly message: string;
203
+ }
204
+ type TEgressFetchResult = {
205
+ ok: true;
206
+ status: number;
207
+ statusText: string;
208
+ headers: Headers;
209
+ body: Uint8Array;
210
+ finalUrl: string;
211
+ } | {
212
+ ok: false;
213
+ rejection: IEgressRejection;
214
+ };
215
+ /** Hostnames that are metadata services or loopback by convention, whatever they resolve to. */
216
+ declare const BLOCKED_HOSTNAMES: ReadonlySet<string>;
217
+ /** Validate ONE destination URL against the policy. `undefined` means it may be reached. */
218
+ declare function rejectDestination(url: URL, policy?: IEgressPolicy, lookup?: TEgressLookup): Promise<IEgressRejection | undefined>;
219
+ /**
220
+ * Fetch `url` under the egress policy. Policy outcomes are RETURNED (`ok: false`); transport errors
221
+ * (DNS failure at connect, refused connection, TLS, abort) are THROWN, as `fetch` throws them, so the
222
+ * caller's own error classification keeps working.
223
+ */
224
+ declare function fetchWithEgressPolicy(url: string, options?: IEgressFetchOptions, policy?: IEgressPolicy, deps?: IEgressDeps): Promise<TEgressFetchResult>;
225
+ interface IEgressPostOptions extends IEgressFetchOptions {
226
+ /** Sent as-is; a `URLSearchParams` or JSON string, never a stream, so it is never re-sent. */
227
+ readonly body: string | URLSearchParams;
228
+ }
229
+ /**
230
+ * POST `url` under the egress policy. The destination is validated as for a GET, but a redirect is
231
+ * REFUSED (`redirect_refused`), never followed: the body is the caller's to send to this URL alone.
232
+ */
233
+ declare function postWithEgressPolicy(url: string, options: IEgressPostOptions, policy?: IEgressPolicy, deps?: IEgressDeps): Promise<TEgressFetchResult>;
234
+ //#endregion
235
+ export { BLOCKED_HOSTNAMES, CommandExecutor, HttpExecutor, type IEgressDeps, type IEgressFetchOptions, type IEgressPolicy, type IEgressPostOptions, type IEgressRejection, type IOwnerOnlyIo, OWNER_ONLY_DIRECTORY_MODE, OWNER_ONLY_FILE_MODE, OwnerOnlyModeError, type TEgressFetchResult, type TEgressLookup, type TEgressRejectionReason, canonicalizePath, ensureOwnerOnlyDirectory, fetchWithEgressPolicy, isPathInside, isPrivateAddress, ownerOnlyGuarantee, postWithEgressPolicy, rejectDestination, resolveTrustedExecutionRoot, tightenExistingFile, writeOwnerOnlyFile };
236
+ //# sourceMappingURL=node.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.cts","names":[],"sources":["../../src/utils/path-containment.ts","../../src/utils/owner-only-store.ts","../../src/hooks/executors/command-executor.ts","../../src/hooks/executors/http-executor.ts","../../src/utils/ip-address.ts","../../src/utils/egress-policy.ts"],"mappings":";;;;;;;;;iBA2BgB,4BAA4B;;;;;;;;;iBAoC5B,iBAAiB;;;;;;;;iBAwBjB,aAAa,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCjC9B;;cAEA;;cAMA,2BAA2B;EAC1B,YAAA;;;;;;;;iBAYE,mBACd;;;;;;;;UAYe;WACN,iBAAiB,gBAAgB;WACjC,WAAW,gBAAgB;WAC3B,YAAY;;UAGN,gCAAgC;;;;;;;;;;;;;;WActC;;;;;;;;iBAsCK,yBACd,mBACA,UAAS;;;;;;;;;iBA8BK,mBAAmB,kBAAkB;;;;;;;iBA2CrC,oBAAoB;;;cCnIvB,2BAA2B;mBAGT;WAFpB;EAEoB,YAAA;;;;;;EAO7B,QACE,YAAY,wBACZ,OAAO,YACP,WAAW,sBACV,QAAQ;;;;cC1EA,wBAAwB;WAC1B;EAEH,QAAQ,YAAY,qBAAqB,OAAO,aAAa,QAAQ;;;;;;;;;;;;;;;;;;;;iBCP7D,iBAAiB;;;KCSrB,iBAAiB,qBAAqB;UAEjC;;WAEN;;WAEA;;WAEA;;UAGM;WACN,UAAU,SAAS;WACnB,SAAS;;WAET;;WAEA;;UAGM;WACN,eAAe,WAAW;WAC1B,SAAS;;KAGR;UAUK;WACN,QAAQ;WACR;WACA;;KAGC;EAEN;EACA;EACA;EACA,SAAS;EACT,MAAM;EACN;;EAEA;EAAW,WAAW;;;cAWf,mBAAmB;;iBAaV,kBACpB,KAAK,KACL,SAAQ,eACR,SAAQ,gBACP,QAAQ;;;;;;iBAwDW,sBACpB,aACA,UAAS,qBACT,SAAQ,eACR,OAAM,cACL,QAAQ;UA6CM,2BAA2B;;WAEjC,eAAe;;;;;;iBAOJ,qBACpB,aACA,SAAS,oBACT,SAAQ,eACR,OAAM,cACL,QAAQ"}
@@ -0,0 +1,236 @@
1
+ import { c as IHookTypeExecutor, l as IHttpHookDefinition, m as THookOutcome, n as ICommandHookDefinition, s as IHookInput, y as ISubprocessTraceEnv } from "./types-gNrckgFE.js";
2
+ //#region src/utils/path-containment.d.ts
3
+ /**
4
+ * Validate an authority root more strictly than candidate-path canonicalization.
5
+ *
6
+ * Candidate write paths may have a missing tail, but an authority root must already exist and be a
7
+ * traversable directory. Keeping the contracts separate prevents a typo in a root from degrading to
8
+ * a lexical boundary that the caller did not actually select.
9
+ */
10
+ declare function resolveTrustedExecutionRoot(input: unknown): string;
11
+ /**
12
+ * Resolve `p` to its canonical form, following symlinks, tolerating a path that does not exist yet.
13
+ *
14
+ * `realpathSync` throws on a missing path, but callers legitimately ask about files they are about to
15
+ * CREATE (a write or an edit). So we walk up to the deepest ancestor that does exist, canonicalize
16
+ * that, and re-attach the remaining segments — the re-attached tail cannot itself be a symlink,
17
+ * because it does not exist.
18
+ */
19
+ declare function canonicalizePath(p: string): string;
20
+ /**
21
+ * Whether `candidate` is `root` itself or lies beneath it, decided on the CANONICAL form of both.
22
+ *
23
+ * Canonicalizing the root as well as the candidate matters: a root that is itself reached through a
24
+ * symlink (macOS `/tmp` -> `/private/tmp`, or a workspace under a symlinked home) would otherwise
25
+ * spuriously reject every path inside it.
26
+ */
27
+ declare function isPathInside(root: string, candidate: string): boolean;
28
+ //#endregion
29
+ //#region src/utils/owner-only-store.d.ts
30
+ /**
31
+ * SEC-020 (issue #2021) — creating a host directory or file that only its owner can read.
32
+ *
33
+ * A host application persists session records, logs, settings and device credentials under a directory
34
+ * of its own choosing. They carry prompts, model output, tool results and, in the settings case,
35
+ * provider credentials. On a shared workstation or a CI host, every other local account reads them
36
+ * unless the mode says otherwise.
37
+ *
38
+ * WHERE that directory is belongs to the host, not here — this module knows only what has to be true
39
+ * of whatever path it is handed, which is what lets it be tested without a filesystem layout.
40
+ *
41
+ * ## Why this is one module and not a constant each caller repeats
42
+ *
43
+ * `0o600` and `0o700` were already spelled out in five separate files before this existed, and the
44
+ * repository had already learned — in `guarded-directory.ts`, for a pairing rendezvous — that the
45
+ * constants are the easy half. The load-bearing part is that **`mkdirSync(path, { mode })` does not
46
+ * set the mode of a directory that already exists.** `recursive: true` returns successfully and
47
+ * silently adopts whatever mode is there. A directory left at 0777 by an earlier version, by a
48
+ * shared CI checkout, or by another local user who pre-created it, becomes ours with no signal.
49
+ *
50
+ * Measured under umask 022 before this module existed: a session log directory pre-created at 0777
51
+ * stayed 0777 through `mkdirSync(dir, { recursive: true, mode: 0o700 })`, and its 0600 records were
52
+ * then removable and replaceable by any local account.
53
+ *
54
+ * The same holds for files. `writeFileSync(path, data, { mode })` applies the mode only when the
55
+ * file is CREATED; an existing 0644 record keeps 0644 forever, so a store written by an older
56
+ * version is never repaired by a newer one.
57
+ *
58
+ * So: create, then set the mode unconditionally, then VERIFY — and verification is what makes the
59
+ * first two checkable rather than hopeful. It is also the only step that catches an owner we did not
60
+ * expect, which `mkdir` and `chmod` between them cannot.
61
+ *
62
+ * ## Windows
63
+ *
64
+ * `chmodSync` on win32 toggles the read-only attribute and cannot express "owner only"; NTFS ACL
65
+ * inheritance governs instead, and a user's profile directory is not readable by other unprivileged
66
+ * accounts by default. The POSIX assertion is therefore not made there, and `ownerOnlyGuarantee()` reports which
67
+ * guarantee is in force so a caller — and a test — can state the platform's actual claim rather than
68
+ * assume the POSIX one everywhere. A store directory placed inside a world-writable parent on
69
+ * Windows is NOT protected by this module, and that is recorded rather than papered over.
70
+ */
71
+ /** Owner read/write. Nothing for group, nothing for other. */
72
+ declare const OWNER_ONLY_FILE_MODE = 384;
73
+ /** Owner read/write/traverse. The traverse bit is what keeps another account out of the directory. */
74
+ declare const OWNER_ONLY_DIRECTORY_MODE = 448;
75
+ /** Raised when a path cannot be made owner-only. Never swallowed into a weaker mode. */
76
+ declare class OwnerOnlyModeError extends Error {
77
+ constructor(message: string);
78
+ }
79
+ /**
80
+ * Which guarantee this platform can actually make.
81
+ *
82
+ * `posix-mode` — the mode bits are asserted after every create and every write.
83
+ * `windows-acl` — inherited NTFS ACLs govern; the POSIX assertion is not made and not claimed.
84
+ */
85
+ declare function ownerOnlyGuarantee(platform?: string): 'posix-mode' | 'windows-acl';
86
+ /**
87
+ * Seams for the failure paths, injected for the reason `guarded-directory.ts` states: a filesystem
88
+ * that silently ignores `chmod` is a real condition — some network and FAT mounts do exactly that —
89
+ * and it is the ONLY condition the verification step catches that create-then-chmod does not. Without
90
+ * a seam that case is unreachable from a test, and a guard no test can reach is a guard nobody knows
91
+ * is there. Measured: with these absent, deleting the verification entirely changed no test result.
92
+ */
93
+ interface IOwnerOnlyIo {
94
+ readonly makeDirectory?: (target: string, mode: number) => void;
95
+ readonly setMode?: (target: string, mode: number) => void;
96
+ readonly readMode?: (target: string) => number;
97
+ }
98
+ interface IEnsureOwnerOnlyOptions extends IOwnerOnlyIo {
99
+ /**
100
+ * An ANCESTOR of `directory` that the caller also owns, tightened along with every segment between
101
+ * them.
102
+ *
103
+ * Needed because `mkdirSync(path, { recursive: true, mode })` applies the mode only to the
104
+ * directories it CREATES. A store root an older version already made sits at whatever mode it was
105
+ * given and this call would leave it there — which is the module's own headline defect surviving
106
+ * one level up, on the very path it exists to protect. Found in review of PR #2224.
107
+ *
108
+ * It is a parameter rather than a walk up to some inferred boundary because WHICH ancestors belong
109
+ * to the caller is the caller's knowledge. This module must not guess that a parent is ours; it
110
+ * would eventually chmod someone's home directory.
111
+ */
112
+ readonly withinRoot?: string;
113
+ }
114
+ /**
115
+ * Ensure `directory` exists and only its owner can enter it.
116
+ *
117
+ * The `chmod` is unconditional because `mkdir` does not touch an existing directory's mode, and the
118
+ * `stat` afterwards is what turns two hopeful calls into a checked one.
119
+ */
120
+ declare function ensureOwnerOnlyDirectory(directory: string, options?: IEnsureOwnerOnlyOptions): void;
121
+ /**
122
+ * Replace `filePath` atomically with content only its owner can read.
123
+ *
124
+ * The temp file carries the mode from the moment it is created — writing it at the umask's default
125
+ * and tightening afterwards leaves a window in which the full content is world-readable on disk, and
126
+ * `rename` preserves whatever mode the temp file had. The `chmod` after the write is for the case
127
+ * where the temp path already existed at a wider mode.
128
+ */
129
+ declare function writeOwnerOnlyFile(filePath: string, content: string): void;
130
+ /**
131
+ * Tighten a file that already exists — the repair path for a record an older version left at 0644.
132
+ *
133
+ * A no-op on a path that does not exist, because "there is nothing to tighten" and "we tightened it"
134
+ * are the same outcome for the caller, and throwing would make every writer branch on existence.
135
+ */
136
+ declare function tightenExistingFile(filePath: string): void;
137
+ //#endregion
138
+ //#region src/hooks/executors/command-executor.d.ts
139
+ declare class CommandExecutor implements IHookTypeExecutor {
140
+ private readonly shellExecutable?;
141
+ readonly type: "command";
142
+ constructor(shellExecutable?: string | undefined);
143
+ /**
144
+ * `traceEnv` is the prompt's trace for this child, handed separately so it never reaches the
145
+ * stdin JSON. The child sees `process.env`, then Robota's value, then the hook's own `env`; a hook
146
+ * that sets its own `TRACEPARENT` wins and gets the ambient environment unchanged.
147
+ */
148
+ execute(definition: ICommandHookDefinition, input: IHookInput, traceEnv?: ISubprocessTraceEnv): Promise<THookOutcome>;
149
+ }
150
+ //#endregion
151
+ //#region src/hooks/executors/http-executor.d.ts
152
+ declare class HttpExecutor implements IHookTypeExecutor {
153
+ readonly type: "http";
154
+ execute(definition: IHttpHookDefinition, input: IHookInput): Promise<THookOutcome>;
155
+ }
156
+ //#endregion
157
+ //#region src/utils/ip-address.d.ts
158
+ /**
159
+ * Address classification for the egress boundary (#2026) — the "is this address public unicast?"
160
+ * half of `egress-policy.ts`, split out so each module holds one job: that one owns the FETCH
161
+ * (scheme, redirects, headers, deadline, byte cap), this one owns the ARITHMETIC of an address.
162
+ *
163
+ * The awkward part lives here on purpose. A literal destination reaches the policy already
164
+ * normalized by `URL` (`2130706433`, `0x7f.1` and `[::ffff:7f00:1]` all collapse to one hostname),
165
+ * but a RESOLVED one does not: `dns.lookup` renders an IPv4-mapped AAAA answer through `inet_ntop`,
166
+ * which prints the dotted spelling `::ffff:127.0.0.1`. So the expansion below accepts BOTH
167
+ * spellings rather than trusting any normalizer to have run — on the resolution path an attacker
168
+ * controls the record. Every "cannot parse" answer is `undefined`/`true`, i.e. NOT public: an
169
+ * address this module cannot read is never treated as reachable.
170
+ *
171
+ * Node-only (`node:net`): reached through `egress-policy.ts`, never the browser barrel.
172
+ */
173
+ /** True when `ip` (v4 or v6 text) is not a public unicast address. */
174
+ declare function isPrivateAddress(ip: string): boolean;
175
+ //#endregion
176
+ //#region src/utils/egress-policy.d.ts
177
+ type TEgressLookup = (hostname: string) => Promise<readonly string[]>;
178
+ interface IEgressPolicy {
179
+ /** Exact lowercase hostnames that may be reached even when they resolve to a private address. */
180
+ readonly allowedHosts?: readonly string[];
181
+ /** Explicit enterprise opt-out from private/loopback/metadata blocking. Default `false`. */
182
+ readonly allowPrivateAddresses?: boolean;
183
+ /** Redirect hops followed before refusing. Default 5. */
184
+ readonly maxRedirects?: number;
185
+ }
186
+ interface IEgressFetchOptions {
187
+ readonly headers?: Readonly<Record<string, string>>;
188
+ readonly signal?: AbortSignal;
189
+ /** Deadline for the WHOLE exchange, redirects and body included. Default 30 000 ms. */
190
+ readonly timeoutMs?: number;
191
+ /** Byte cap enforced on `Content-Length` and again while streaming. Default 5 000 000. */
192
+ readonly maxResponseBytes?: number;
193
+ }
194
+ interface IEgressDeps {
195
+ readonly fetch?: typeof globalThis.fetch;
196
+ readonly lookup?: TEgressLookup;
197
+ }
198
+ type TEgressRejectionReason = 'unsupported_scheme' | 'private_destination' | 'metadata_host' | 'unresolvable' | 'redirect_limit' | 'redirect_without_location' | 'redirect_refused' | 'response_too_large';
199
+ interface IEgressRejection {
200
+ readonly reason: TEgressRejectionReason;
201
+ readonly url: string;
202
+ readonly message: string;
203
+ }
204
+ type TEgressFetchResult = {
205
+ ok: true;
206
+ status: number;
207
+ statusText: string;
208
+ headers: Headers;
209
+ body: Uint8Array;
210
+ finalUrl: string;
211
+ } | {
212
+ ok: false;
213
+ rejection: IEgressRejection;
214
+ };
215
+ /** Hostnames that are metadata services or loopback by convention, whatever they resolve to. */
216
+ declare const BLOCKED_HOSTNAMES: ReadonlySet<string>;
217
+ /** Validate ONE destination URL against the policy. `undefined` means it may be reached. */
218
+ declare function rejectDestination(url: URL, policy?: IEgressPolicy, lookup?: TEgressLookup): Promise<IEgressRejection | undefined>;
219
+ /**
220
+ * Fetch `url` under the egress policy. Policy outcomes are RETURNED (`ok: false`); transport errors
221
+ * (DNS failure at connect, refused connection, TLS, abort) are THROWN, as `fetch` throws them, so the
222
+ * caller's own error classification keeps working.
223
+ */
224
+ declare function fetchWithEgressPolicy(url: string, options?: IEgressFetchOptions, policy?: IEgressPolicy, deps?: IEgressDeps): Promise<TEgressFetchResult>;
225
+ interface IEgressPostOptions extends IEgressFetchOptions {
226
+ /** Sent as-is; a `URLSearchParams` or JSON string, never a stream, so it is never re-sent. */
227
+ readonly body: string | URLSearchParams;
228
+ }
229
+ /**
230
+ * POST `url` under the egress policy. The destination is validated as for a GET, but a redirect is
231
+ * REFUSED (`redirect_refused`), never followed: the body is the caller's to send to this URL alone.
232
+ */
233
+ declare function postWithEgressPolicy(url: string, options: IEgressPostOptions, policy?: IEgressPolicy, deps?: IEgressDeps): Promise<TEgressFetchResult>;
234
+ //#endregion
235
+ export { BLOCKED_HOSTNAMES, CommandExecutor, HttpExecutor, type IEgressDeps, type IEgressFetchOptions, type IEgressPolicy, type IEgressPostOptions, type IEgressRejection, type IOwnerOnlyIo, OWNER_ONLY_DIRECTORY_MODE, OWNER_ONLY_FILE_MODE, OwnerOnlyModeError, type TEgressFetchResult, type TEgressLookup, type TEgressRejectionReason, canonicalizePath, ensureOwnerOnlyDirectory, fetchWithEgressPolicy, isPathInside, isPrivateAddress, ownerOnlyGuarantee, postWithEgressPolicy, rejectDestination, resolveTrustedExecutionRoot, tightenExistingFile, writeOwnerOnlyFile };
236
+ //# sourceMappingURL=node.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.d.ts","names":[],"sources":["../../src/utils/path-containment.ts","../../src/utils/owner-only-store.ts","../../src/hooks/executors/command-executor.ts","../../src/hooks/executors/http-executor.ts","../../src/utils/ip-address.ts","../../src/utils/egress-policy.ts"],"mappings":";;;;;;;;;iBA2BgB,4BAA4B;;;;;;;;;iBAoC5B,iBAAiB;;;;;;;;iBAwBjB,aAAa,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cCjC9B;;cAEA;;cAMA,2BAA2B;EAC1B,YAAA;;;;;;;;iBAYE,mBACd;;;;;;;;UAYe;WACN,iBAAiB,gBAAgB;WACjC,WAAW,gBAAgB;WAC3B,YAAY;;UAGN,gCAAgC;;;;;;;;;;;;;;WActC;;;;;;;;iBAsCK,yBACd,mBACA,UAAS;;;;;;;;;iBA8BK,mBAAmB,kBAAkB;;;;;;;iBA2CrC,oBAAoB;;;cCnIvB,2BAA2B;mBAGT;WAFpB;EAEoB,YAAA;;;;;;EAO7B,QACE,YAAY,wBACZ,OAAO,YACP,WAAW,sBACV,QAAQ;;;;cC1EA,wBAAwB;WAC1B;EAEH,QAAQ,YAAY,qBAAqB,OAAO,aAAa,QAAQ;;;;;;;;;;;;;;;;;;;;iBCP7D,iBAAiB;;;KCSrB,iBAAiB,qBAAqB;UAEjC;;WAEN;;WAEA;;WAEA;;UAGM;WACN,UAAU,SAAS;WACnB,SAAS;;WAET;;WAEA;;UAGM;WACN,eAAe,WAAW;WAC1B,SAAS;;KAGR;UAUK;WACN,QAAQ;WACR;WACA;;KAGC;EAEN;EACA;EACA;EACA,SAAS;EACT,MAAM;EACN;;EAEA;EAAW,WAAW;;;cAWf,mBAAmB;;iBAaV,kBACpB,KAAK,KACL,SAAQ,eACR,SAAQ,gBACP,QAAQ;;;;;;iBAwDW,sBACpB,aACA,UAAS,qBACT,SAAQ,eACR,OAAM,cACL,QAAQ;UA6CM,2BAA2B;;WAEjC,eAAe;;;;;;iBAOJ,qBACpB,aACA,SAAS,oBACT,SAAQ,eACR,OAAM,cACL,QAAQ"}
@@ -0,0 +1,2 @@
1
+ import{t as e}from"./command-executor-DV-H2oD6.js";import{t}from"./http-executor-cWzI2svn.js";import{accessSync as n,chmodSync as r,constants as i,mkdirSync as a,realpathSync as o,renameSync as s,rmSync as c,statSync as l,unlinkSync as u,writeFileSync as d}from"node:fs";import{basename as f,dirname as p,isAbsolute as m,join as h,relative as g,resolve as _,sep as v}from"node:path";import{lookup as y}from"node:dns/promises";import{isIP as b}from"node:net";function x(e){if(typeof e!=`string`)throw TypeError(`executionRoot must be a string`);if(e.trim().length===0)throw TypeError(`executionRoot must be a non-empty string`);if(!m(e))throw TypeError(`executionRoot must be an absolute path`);let t;try{t=o(e)}catch{throw TypeError(`executionRoot must name an existing accessible directory`)}if(!l(t).isDirectory())throw TypeError(`executionRoot must name a directory`);try{n(t,i.R_OK|i.X_OK)}catch{throw TypeError(`executionRoot directory must be readable and traversable`)}return t}function S(e){let t=[],n=_(e);for(;;)try{return h(o(n),...t)}catch{let r=p(n);if(r===n)return _(e);t.unshift(f(n)),n=r}}function C(e,t){let n=S(e),r=S(t);return r===n||r.startsWith(n+v)}const w=384,T=448;var E=class extends Error{constructor(e){super(e),this.name=`OwnerOnlyModeError`}};function D(e=process.platform){return e===`win32`?`windows-acl`:`posix-mode`}function O(e,t){let n=g(e,t);if(n.startsWith(`..`)||m(n))throw new E(`withinRoot ${e} is not an ancestor of ${t}, so this call cannot own the path between them.`);let r=n.split(v).filter(e=>e.length>0),i=[e],a=e;for(let e of r)a=h(a,e),i.push(a);return i}function k(e,t,n={}){if(D()!==`posix-mode`)return;let r=(n.readMode??(e=>l(e).mode&4095))(e);if(r&63)throw new E(`${t} ${e} is mode 0${r.toString(8)} after being set owner-only; group or other permissions survived, so its contents are readable by another account.`)}function A(e,t={}){let n=t.makeDirectory??((e,t)=>{a(e,{recursive:!0,mode:t})}),i=t.setMode??((e,t)=>r(e,t));n(e,448);let o=t.withinRoot===void 0?[e]:O(t.withinRoot,e);for(let e of o)D()===`posix-mode`&&i(e,448),k(e,`directory`,t)}function j(e,t){A(p(e));let n=`${e}.${process.pid}.tmp`;c(n,{force:!0}),d(n,t,{encoding:`utf8`,mode:384,flag:`wx`});try{k(n,`file`),s(n,e)}catch(e){try{u(n)}catch{}throw e}k(e,`file`)}function M(e){if(D()!==`posix-mode`)return;let t;try{t=l(e).mode&4095}catch{return}t&63&&(r(e,384),k(e,`file`))}function N(e){let t=b(e);return t===4?P(e.split(`.`).map(Number)):t!==6||F(e)}function P(e){let[t=0,n=0,r=0]=e;return t===0||t===10||t===127||t===100&&n>=64&&n<=127||t===169&&n===254||t===172&&n>=16&&n<=31||t===192&&n===0&&r===0||t===192&&n===168||t===198&&(n===18||n===19)||t>=224}function F(e){let t=L(e);if(t===void 0)return!0;let[n=0,r=0,i=0,a=0,o=0,s=0,c=0,l=0]=t;return n===0&&r===0&&i===0&&a===0&&o===0&&s===65535||n===100&&r===65435&&i===0&&a===0&&o===0&&s===0?P([c>>8,c&255,l>>8,l&255]):n===0&&r===0&&i===0&&a===0&&o===0&&s===0||(n&65024)==64512||(n&65472)==65152||(n&65472)==65216||(n&65280)==65280}function I(e){let t=e.lastIndexOf(`:`),n=e.slice(t+1);if(!n.includes(`.`))return e;if(t<0||b(n)!==4)return;let[r=0,i=0,a=0,o=0]=n.split(`.`).map(Number),s=(r<<8|i).toString(16),c=(a<<8|o).toString(16);return`${e.slice(0,t+1)}${s}:${c}`}function L(e){let t=I(e.split(`%`)[0]??e);if(t===void 0)return;let n=t.split(`::`);if(n.length>2)return;let r=e=>e.length===0?[]:e.split(`:`).map(e=>Number.parseInt(e,16)),i=r(n[0]??``),a=n.length===2?r(n[1]??``):[],o=8-i.length-a.length;if(o<0||n.length===1&&o!==0)return;let s=[...i,...Array(o).fill(0),...a];return s.some(e=>Number.isNaN(e)||e<0||e>65535)?void 0:s}const R=3e4,z=5e6,B=new Set([301,302,303,307,308]),V=new Set([`localhost`,`metadata`,`metadata.google.internal`,`metadata.goog`,`instance-data`,`instance-data.ec2.internal`]),H=async e=>(await y(e,{all:!0,verbatim:!0})).map(e=>e.address);async function U(e,t={},n=H){let r=e.href;if(e.protocol!==`http:`&&e.protocol!==`https:`)return{reason:`unsupported_scheme`,url:r,message:`Only http(s) URLs may be fetched.`};if(t.allowPrivateAddresses===!0)return;let i=e.hostname.replace(/^\[|\]$/g,``).toLowerCase();if(t.allowedHosts?.includes(i))return;if(V.has(i)||i.endsWith(`.localhost`))return{reason:`metadata_host`,url:r,message:`Destination "${i}" is a loopback or cloud-metadata host and is not reachable from tools.`};let a=b(i)?[i]:await W(i,n);if(a===void 0||a.length===0)return{reason:`unresolvable`,url:r,message:`Destination "${i}" did not resolve.`};let o=a.find(N);if(o!==void 0)return{reason:`private_destination`,url:r,message:`Destination "${i}" resolves to ${o}, a private, loopback or link-local address, and is not reachable from tools.`}}async function W(e,t){try{return await t(e)}catch{return}}async function G(e,t={},n={},r={}){let i=r.fetch??((e,t)=>globalThis.fetch(e,t)),a=r.lookup??H,o=t.maxResponseBytes??z,s=n.maxRedirects??5,c=AbortSignal.timeout(t.timeoutMs??R),l=t.signal?AbortSignal.any([c,t.signal]):c,u=new URL(e),d={...t.headers??{}};for(let e=0;;e+=1){let t=await U(u,n,a);if(t!==void 0)return{ok:!1,rejection:t};let r=await i(u.href,{headers:d,signal:l,redirect:`manual`});if(!B.has(r.status))return J(r,u.href,o,l);let c=r.headers.get(`location`);if(c===null)return{ok:!1,rejection:{reason:`redirect_without_location`,url:u.href,message:`HTTP ${r.status} without a Location header.`}};if(e>=s)return{ok:!1,rejection:{reason:`redirect_limit`,url:u.href,message:`More than ${s} redirects.`}};let f=new URL(c,u);f.origin!==u.origin&&(d=q(d)),u=f}}async function K(e,t,n={},r={}){let i=r.fetch??((e,t)=>globalThis.fetch(e,t)),a=t.maxResponseBytes??z,o=AbortSignal.timeout(t.timeoutMs??R),s=t.signal?AbortSignal.any([o,t.signal]):o,c=new URL(e),l=await U(c,n,r.lookup??H);if(l!==void 0)return{ok:!1,rejection:l};let u=await i(c.href,{method:`POST`,headers:{...t.headers??{}},body:t.body,signal:s,redirect:`manual`});return u.status>=300&&u.status<400?(await u.body?.cancel().catch(()=>void 0),{ok:!1,rejection:{reason:`redirect_refused`,url:c.href,message:`HTTP ${u.status}: a POST is never redirected.`}}):J(u,c.href,a,s)}function q(e){let t={};for(let[n,r]of Object.entries(e))n.toLowerCase()===`user-agent`&&(t[n]=r);return t}async function J(e,t,n,r){let i=e=>({ok:!1,rejection:{reason:`response_too_large`,url:t,message:`Response exceeds ${n} bytes (${e} seen).`}}),a=Number(e.headers.get(`content-length`));if(Number.isFinite(a)&&a>n)return await e.body?.cancel(),i(a);let o=[],s=0;if(!e.body&&typeof e.arrayBuffer==`function`){let t=new Uint8Array(await e.arrayBuffer());if(t.byteLength>n)return i(t.byteLength);o.push(t),s=t.byteLength}else if(e.body){let t=e.body.getReader();for(;;){r.throwIfAborted();let{done:e,value:a}=await t.read();if(e)break;if(s+=a.byteLength,s>n)return await t.cancel(),i(s);o.push(a)}}let c=new Uint8Array(s),l=0;for(let e of o)c.set(e,l),l+=e.byteLength;return{ok:!0,status:e.status,statusText:e.statusText,headers:e.headers,body:c,finalUrl:t}}export{V as BLOCKED_HOSTNAMES,e as CommandExecutor,t as HttpExecutor,T as OWNER_ONLY_DIRECTORY_MODE,w as OWNER_ONLY_FILE_MODE,E as OwnerOnlyModeError,S as canonicalizePath,A as ensureOwnerOnlyDirectory,G as fetchWithEgressPolicy,C as isPathInside,N as isPrivateAddress,D as ownerOnlyGuarantee,K as postWithEgressPolicy,U as rejectDestination,x as resolveTrustedExecutionRoot,M as tightenExistingFile,j as writeOwnerOnlyFile};
2
+ //# sourceMappingURL=node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node.js","names":["relative","relativePath","dnsLookup","resolve"],"sources":["../../src/utils/path-containment.ts","../../src/utils/owner-only-store.ts","../../src/utils/ip-address.ts","../../src/utils/egress-policy.ts"],"sourcesContent":["/**\n * SEC-006 — the SSOT for \"is this path inside that root?\" when the answer is a SECURITY decision.\n *\n * `path.resolve` and `path.normalize` are purely lexical: they collapse `.` and `..` textually but do\n * not consult the filesystem, so they cannot see a symlink. A link sitting INSIDE the root and\n * pointing outside it therefore satisfies a `startsWith(root + sep)` check while the syscall that\n * follows — `open`, `readFile`, `writeFile` — follows the link straight out of the boundary.\n *\n * Symlinks are ordinary committed git content and ordinary build-output artifacts, so this is not a\n * theoretical hole: it was exploitable in both the file-tool sandbox and the CLI's monitor asset\n * server. Both now decide containment here, because two containment checks that can disagree are\n * their own defect.\n *\n * Every security-boundary containment check in the repo routes through here — the `agent-*` family\n * and the `dag-*` family alike. The DAG side is not a cross-family exception: `dag-framework`\n * declares `@robota-sdk/agent-core` in its runtime dependencies.\n */\nimport { accessSync, constants, realpathSync, statSync } from 'node:fs';\nimport { basename, dirname, isAbsolute, join, resolve, sep } from 'node:path';\n\n/**\n * Validate an authority root more strictly than candidate-path canonicalization.\n *\n * Candidate write paths may have a missing tail, but an authority root must already exist and be a\n * traversable directory. Keeping the contracts separate prevents a typo in a root from degrading to\n * a lexical boundary that the caller did not actually select.\n */\nexport function resolveTrustedExecutionRoot(input: unknown): string {\n if (typeof input !== 'string') {\n throw new TypeError('executionRoot must be a string');\n }\n if (input.trim().length === 0) {\n throw new TypeError('executionRoot must be a non-empty string');\n }\n if (!isAbsolute(input)) {\n throw new TypeError('executionRoot must be an absolute path');\n }\n\n let canonicalRoot: string;\n try {\n canonicalRoot = realpathSync(input);\n } catch {\n throw new TypeError('executionRoot must name an existing accessible directory');\n }\n if (!statSync(canonicalRoot).isDirectory()) {\n throw new TypeError('executionRoot must name a directory');\n }\n try {\n accessSync(canonicalRoot, constants.R_OK | constants.X_OK);\n } catch {\n throw new TypeError('executionRoot directory must be readable and traversable');\n }\n return canonicalRoot;\n}\n\n/**\n * Resolve `p` to its canonical form, following symlinks, tolerating a path that does not exist yet.\n *\n * `realpathSync` throws on a missing path, but callers legitimately ask about files they are about to\n * CREATE (a write or an edit). So we walk up to the deepest ancestor that does exist, canonicalize\n * that, and re-attach the remaining segments — the re-attached tail cannot itself be a symlink,\n * because it does not exist.\n */\nexport function canonicalizePath(p: string): string {\n const tail: string[] = [];\n let current = resolve(p);\n for (;;) {\n try {\n return join(realpathSync(current), ...tail);\n } catch {\n const parent = dirname(current);\n // allow-fallback: nothing along the chain exists or is readable — fall back to the lexical\n // path, which `resolve()` has already fully normalized and which is therefore safe to compare.\n if (parent === current) return resolve(p);\n tail.unshift(basename(current));\n current = parent;\n }\n }\n}\n\n/**\n * Whether `candidate` is `root` itself or lies beneath it, decided on the CANONICAL form of both.\n *\n * Canonicalizing the root as well as the candidate matters: a root that is itself reached through a\n * symlink (macOS `/tmp` -> `/private/tmp`, or a workspace under a symlinked home) would otherwise\n * spuriously reject every path inside it.\n */\nexport function isPathInside(root: string, candidate: string): boolean {\n const canonicalRoot = canonicalizePath(root);\n const canonicalCandidate = canonicalizePath(candidate);\n return canonicalCandidate === canonicalRoot || canonicalCandidate.startsWith(canonicalRoot + sep);\n}\n","/**\n * SEC-020 (issue #2021) — creating a host directory or file that only its owner can read.\n *\n * A host application persists session records, logs, settings and device credentials under a directory\n * of its own choosing. They carry prompts, model output, tool results and, in the settings case,\n * provider credentials. On a shared workstation or a CI host, every other local account reads them\n * unless the mode says otherwise.\n *\n * WHERE that directory is belongs to the host, not here — this module knows only what has to be true\n * of whatever path it is handed, which is what lets it be tested without a filesystem layout.\n *\n * ## Why this is one module and not a constant each caller repeats\n *\n * `0o600` and `0o700` were already spelled out in five separate files before this existed, and the\n * repository had already learned — in `guarded-directory.ts`, for a pairing rendezvous — that the\n * constants are the easy half. The load-bearing part is that **`mkdirSync(path, { mode })` does not\n * set the mode of a directory that already exists.** `recursive: true` returns successfully and\n * silently adopts whatever mode is there. A directory left at 0777 by an earlier version, by a\n * shared CI checkout, or by another local user who pre-created it, becomes ours with no signal.\n *\n * Measured under umask 022 before this module existed: a session log directory pre-created at 0777\n * stayed 0777 through `mkdirSync(dir, { recursive: true, mode: 0o700 })`, and its 0600 records were\n * then removable and replaceable by any local account.\n *\n * The same holds for files. `writeFileSync(path, data, { mode })` applies the mode only when the\n * file is CREATED; an existing 0644 record keeps 0644 forever, so a store written by an older\n * version is never repaired by a newer one.\n *\n * So: create, then set the mode unconditionally, then VERIFY — and verification is what makes the\n * first two checkable rather than hopeful. It is also the only step that catches an owner we did not\n * expect, which `mkdir` and `chmod` between them cannot.\n *\n * ## Windows\n *\n * `chmodSync` on win32 toggles the read-only attribute and cannot express \"owner only\"; NTFS ACL\n * inheritance governs instead, and a user's profile directory is not readable by other unprivileged\n * accounts by default. The POSIX assertion is therefore not made there, and `ownerOnlyGuarantee()` reports which\n * guarantee is in force so a caller — and a test — can state the platform's actual claim rather than\n * assume the POSIX one everywhere. A store directory placed inside a world-writable parent on\n * Windows is NOT protected by this module, and that is recorded rather than papered over.\n */\n\nimport {\n chmodSync,\n mkdirSync,\n renameSync,\n rmSync,\n statSync,\n unlinkSync,\n writeFileSync,\n} from 'node:fs';\nimport { dirname, isAbsolute, join, relative as relativePath, sep } from 'node:path';\n\n/** Owner read/write. Nothing for group, nothing for other. */\nexport const OWNER_ONLY_FILE_MODE = 0o600;\n/** Owner read/write/traverse. The traverse bit is what keeps another account out of the directory. */\nexport const OWNER_ONLY_DIRECTORY_MODE = 0o700;\n\n/** The bits that must be clear for the guarantee to hold: every group and other permission. */\nconst FORBIDDEN_BITS = 0o077;\n\n/** Raised when a path cannot be made owner-only. Never swallowed into a weaker mode. */\nexport class OwnerOnlyModeError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'OwnerOnlyModeError';\n }\n}\n\n/**\n * Which guarantee this platform can actually make.\n *\n * `posix-mode` — the mode bits are asserted after every create and every write.\n * `windows-acl` — inherited NTFS ACLs govern; the POSIX assertion is not made and not claimed.\n */\nexport function ownerOnlyGuarantee(\n platform: string = process.platform,\n): 'posix-mode' | 'windows-acl' {\n return platform === 'win32' ? 'windows-acl' : 'posix-mode';\n}\n\n/**\n * Seams for the failure paths, injected for the reason `guarded-directory.ts` states: a filesystem\n * that silently ignores `chmod` is a real condition — some network and FAT mounts do exactly that —\n * and it is the ONLY condition the verification step catches that create-then-chmod does not. Without\n * a seam that case is unreachable from a test, and a guard no test can reach is a guard nobody knows\n * is there. Measured: with these absent, deleting the verification entirely changed no test result.\n */\nexport interface IOwnerOnlyIo {\n readonly makeDirectory?: (target: string, mode: number) => void;\n readonly setMode?: (target: string, mode: number) => void;\n readonly readMode?: (target: string) => number;\n}\n\nexport interface IEnsureOwnerOnlyOptions extends IOwnerOnlyIo {\n /**\n * An ANCESTOR of `directory` that the caller also owns, tightened along with every segment between\n * them.\n *\n * Needed because `mkdirSync(path, { recursive: true, mode })` applies the mode only to the\n * directories it CREATES. A store root an older version already made sits at whatever mode it was\n * given and this call would leave it there — which is the module's own headline defect surviving\n * one level up, on the very path it exists to protect. Found in review of PR #2224.\n *\n * It is a parameter rather than a walk up to some inferred boundary because WHICH ancestors belong\n * to the caller is the caller's knowledge. This module must not guess that a parent is ours; it\n * would eventually chmod someone's home directory.\n */\n readonly withinRoot?: string;\n}\n\n/** Every directory from `root` down to `target`, outermost first. `root` must be an ancestor. */\nfunction segmentsFromRoot(root: string, target: string): string[] {\n const relative = relativePath(root, target);\n if (relative.startsWith('..') || isAbsolute(relative)) {\n throw new OwnerOnlyModeError(\n `withinRoot ${root} is not an ancestor of ${target}, so this call cannot own the path between them.`,\n );\n }\n const parts = relative.split(sep).filter((part) => part.length > 0);\n const chain: string[] = [root];\n let current = root;\n for (const part of parts) {\n current = join(current, part);\n chain.push(current);\n }\n return chain;\n}\n\nfunction assertOwnerOnly(target: string, kind: 'directory' | 'file', io: IOwnerOnlyIo = {}): void {\n if (ownerOnlyGuarantee() !== 'posix-mode') return;\n const mode = (io.readMode ?? ((path: string) => statSync(path).mode & 0o7777))(target);\n if ((mode & FORBIDDEN_BITS) !== 0) {\n throw new OwnerOnlyModeError(\n `${kind} ${target} is mode 0${mode.toString(8)} after being set owner-only; ` +\n 'group or other permissions survived, so its contents are readable by another account.',\n );\n }\n}\n\n/**\n * Ensure `directory` exists and only its owner can enter it.\n *\n * The `chmod` is unconditional because `mkdir` does not touch an existing directory's mode, and the\n * `stat` afterwards is what turns two hopeful calls into a checked one.\n */\nexport function ensureOwnerOnlyDirectory(\n directory: string,\n options: IEnsureOwnerOnlyOptions = {},\n): void {\n const makeDirectory =\n options.makeDirectory ??\n ((target: string, mode: number): void => {\n mkdirSync(target, { recursive: true, mode });\n });\n const setMode =\n options.setMode ?? ((target: string, mode: number): void => chmodSync(target, mode));\n makeDirectory(directory, OWNER_ONLY_DIRECTORY_MODE);\n // Every directory the caller declared it owns, not only the leaf. `mkdir` set the mode on what it\n // CREATED; a root an older version left at 0755 was created by nobody here and would keep it.\n const owned =\n options.withinRoot === undefined\n ? [directory]\n : segmentsFromRoot(options.withinRoot, directory);\n for (const target of owned) {\n if (ownerOnlyGuarantee() === 'posix-mode') setMode(target, OWNER_ONLY_DIRECTORY_MODE);\n assertOwnerOnly(target, 'directory', options);\n }\n}\n\n/**\n * Replace `filePath` atomically with content only its owner can read.\n *\n * The temp file carries the mode from the moment it is created — writing it at the umask's default\n * and tightening afterwards leaves a window in which the full content is world-readable on disk, and\n * `rename` preserves whatever mode the temp file had. The `chmod` after the write is for the case\n * where the temp path already existed at a wider mode.\n */\nexport function writeOwnerOnlyFile(filePath: string, content: string): void {\n ensureOwnerOnlyDirectory(dirname(filePath));\n const temporaryPath = `${filePath}.${process.pid}.tmp`;\n // A stale temp file is REMOVED rather than reused. It can only come from a process that died\n // mid-write, its contents are meaningless, and — the part that matters here — `writeFileSync` does\n // not apply `mode` to a file that already exists, so reusing one at 0666 would put the whole\n // record on disk world-readable before the rename.\n //\n // Removed with `force` rather than `if (exists) unlink`: checking and then acting on a path is a\n // race, and the race is exploitable here — another process can create the path between the two\n // calls, and the `wx` write below would then fail on a file this call believed it had cleared.\n // CodeQL flagged the check-then-act form on PR #2224 and it was right to.\n rmSync(temporaryPath, { force: true });\n // `wx` guarantees this call CREATES the file, which is the only condition under which `mode` is\n // applied. There is deliberately no `chmod` after it: tightening a file that was created wide\n // leaves a window in which the full record is readable, and a `chmod` here would make the mode\n // above redundant — so a mutation that removed it would change nothing and the window would be\n // untested. The assertion below is what proves the mode actually took.\n writeFileSync(temporaryPath, content, {\n encoding: 'utf8',\n mode: OWNER_ONLY_FILE_MODE,\n flag: 'wx',\n });\n try {\n assertOwnerOnly(temporaryPath, 'file');\n renameSync(temporaryPath, filePath);\n } catch (error) {\n try {\n unlinkSync(temporaryPath);\n } catch {\n // allow-fallback: the temp file may already be gone; the original error is the one to report.\n }\n throw error;\n }\n assertOwnerOnly(filePath, 'file');\n}\n\n/**\n * Tighten a file that already exists — the repair path for a record an older version left at 0644.\n *\n * A no-op on a path that does not exist, because \"there is nothing to tighten\" and \"we tightened it\"\n * are the same outcome for the caller, and throwing would make every writer branch on existence.\n */\nexport function tightenExistingFile(filePath: string): void {\n if (ownerOnlyGuarantee() !== 'posix-mode') return;\n let mode: number;\n try {\n mode = statSync(filePath).mode & 0o7777;\n } catch {\n return; // allow-fallback: nothing to tighten\n }\n if ((mode & FORBIDDEN_BITS) === 0) return;\n chmodSync(filePath, OWNER_ONLY_FILE_MODE);\n assertOwnerOnly(filePath, 'file');\n}\n","/**\n * Address classification for the egress boundary (#2026) — the \"is this address public unicast?\"\n * half of `egress-policy.ts`, split out so each module holds one job: that one owns the FETCH\n * (scheme, redirects, headers, deadline, byte cap), this one owns the ARITHMETIC of an address.\n *\n * The awkward part lives here on purpose. A literal destination reaches the policy already\n * normalized by `URL` (`2130706433`, `0x7f.1` and `[::ffff:7f00:1]` all collapse to one hostname),\n * but a RESOLVED one does not: `dns.lookup` renders an IPv4-mapped AAAA answer through `inet_ntop`,\n * which prints the dotted spelling `::ffff:127.0.0.1`. So the expansion below accepts BOTH\n * spellings rather than trusting any normalizer to have run — on the resolution path an attacker\n * controls the record. Every \"cannot parse\" answer is `undefined`/`true`, i.e. NOT public: an\n * address this module cannot read is never treated as reachable.\n *\n * Node-only (`node:net`): reached through `egress-policy.ts`, never the browser barrel.\n */\n\nimport { isIP } from 'node:net';\n\n/** What `isIP` answers: 4 for an IPv4 literal, 6 for an IPv6 one, 0 for text that is neither. */\nconst IP_VERSION_V4 = 4;\nconst IP_VERSION_V6 = 6;\n/** An IPv6 group is two octets wide, and is written in hex once a dotted quad is folded into one. */\nconst OCTET_BITS = 8;\nconst HEX_RADIX = 16;\n\n/** True when `ip` (v4 or v6 text) is not a public unicast address. */\nexport function isPrivateAddress(ip: string): boolean {\n const version = isIP(ip);\n if (version === IP_VERSION_V4) return isPrivateIpv4(ip.split('.').map(Number));\n if (version === IP_VERSION_V6) return isPrivateIpv6(ip);\n return true; // not an address at all: never treat it as public\n}\n\nfunction isPrivateIpv4(o: readonly number[]): boolean {\n const [a = 0, b = 0, c = 0] = o;\n return (\n a === 0 || // \"this\" network\n a === 10 ||\n a === 127 ||\n (a === 100 && b >= 64 && b <= 127) || // CGNAT\n (a === 169 && b === 254) || // link-local, incl. 169.254.169.254\n (a === 172 && b >= 16 && b <= 31) ||\n (a === 192 && b === 0 && c === 0) ||\n (a === 192 && b === 168) ||\n (a === 198 && (b === 18 || b === 19)) ||\n a >= 224 // multicast + reserved + broadcast\n );\n}\n\nfunction isPrivateIpv6(ip: string): boolean {\n const groups = expandIpv6(ip);\n if (groups === undefined) return true;\n const [g0 = 0, g1 = 0, g2 = 0, g3 = 0, g4 = 0, g5 = 0, g6 = 0, g7 = 0] = groups;\n const isMapped = g0 === 0 && g1 === 0 && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0xffff;\n const isNat64 = g0 === 0x64 && g1 === 0xff9b && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0;\n if (isMapped || isNat64) {\n return isPrivateIpv4([g6 >> 8, g6 & 0xff, g7 >> 8, g7 & 0xff]);\n }\n // ::/96 in one rule: the unspecified address `::`, loopback `::1`, and the DEPRECATED\n // IPv4-compatible form (`::127.0.0.1`, which `URL` renders as `::7f00:1`) — which embeds an IPv4\n // address just as a mapped one does. None of that range is public unicast.\n if (g0 === 0 && g1 === 0 && g2 === 0 && g3 === 0 && g4 === 0 && g5 === 0) return true;\n if ((g0 & 0xfe00) === 0xfc00) return true; // fc00::/7 unique local\n if ((g0 & 0xffc0) === 0xfe80) return true; // fe80::/10 link-local\n if ((g0 & 0xffc0) === 0xfec0) return true; // fec0::/10 site-local (deprecated, still routable)\n if ((g0 & 0xff00) === 0xff00) return true; // ff00::/8 multicast\n return false;\n}\n\n/**\n * Rewrite a trailing dotted-quad (`::ffff:127.0.0.1`) into the two hex groups it stands for, so the\n * rest of the expansion only ever sees colon groups. `undefined` when the tail is not a valid IPv4\n * address — a refusal, never a guess, because {@link isPrivateIpv6} reads `undefined` as private.\n *\n * This form is not exotic: `URL` normalizes a literal to `[::ffff:7f00:1]`, but `dns.lookup` renders\n * an IPv4-mapped AAAA answer through `inet_ntop`, which prints the dotted form — so it is exactly\n * what arrives on the RESOLUTION path, where an attacker controls the record.\n */\nfunction withoutDottedQuadTail(ip: string): string | undefined {\n const lastColon = ip.lastIndexOf(':');\n const tail = ip.slice(lastColon + 1);\n if (!tail.includes('.')) return ip;\n if (lastColon < 0 || isIP(tail) !== IP_VERSION_V4) return undefined;\n const [a = 0, b = 0, c = 0, d = 0] = tail.split('.').map(Number);\n const high = ((a << OCTET_BITS) | b).toString(HEX_RADIX);\n const low = ((c << OCTET_BITS) | d).toString(HEX_RADIX);\n return `${ip.slice(0, lastColon + 1)}${high}:${low}`;\n}\n\n/** Expand an IPv6 literal (as `URL` or a resolver renders it, brackets removed) into 8 16-bit groups. */\nfunction expandIpv6(ip: string): number[] | undefined {\n const zoneless = ip.split('%')[0] ?? ip;\n const withoutZone = withoutDottedQuadTail(zoneless);\n if (withoutZone === undefined) return undefined;\n const halves = withoutZone.split('::');\n if (halves.length > 2) return undefined;\n const parse = (part: string): number[] =>\n part.length === 0 ? [] : part.split(':').map((g) => Number.parseInt(g, 16));\n const head = parse(halves[0] ?? '');\n const tail = halves.length === 2 ? parse(halves[1] ?? '') : [];\n const missing = 8 - head.length - tail.length;\n if (missing < 0 || (halves.length === 1 && missing !== 0)) return undefined;\n const groups = [...head, ...new Array<number>(missing).fill(0), ...tail];\n return groups.some((g) => Number.isNaN(g) || g < 0 || g > 0xffff) ? undefined : groups;\n}\n","/**\n * The shared outbound-network (egress) boundary (#2026).\n *\n * Every built-in, provider helper and node runtime that fetches a caller- or model-supplied URL goes\n * through {@link fetchWithEgressPolicy}. It owns, in one place:\n *\n * - DESTINATION safety: only `http:`/`https:`; literal and RESOLVED addresses are refused when they are\n * loopback, private, link-local, multicast, unspecified or reserved — for IPv4, IPv6, and IPv4-mapped /\n * IPv4-compatible / NAT64-embedded forms — plus the well-known cloud metadata hostnames. `URL`\n * normalization is what collapses alternate encodings (`2130706433`, `0x7f.1`, `[::ffff:7f00:1]`)\n * into one hostname on the LITERAL path; the RESOLVED path has no such normalizer, and an embedded\n * IPv4 arrives from `dns.lookup` in the dotted spelling `inet_ntop` prints (`::ffff:127.0.0.1`), so\n * the classifier accepts both spellings rather than trusting `URL` to have canonicalised anything.\n * - REDIRECTS: followed manually, every hop re-validated, and caller-supplied plus credential-bearing\n * headers dropped on a cross-origin hop. A POST ({@link postWithEgressPolicy}) never follows one:\n * its body can carry a credential — an authorization code, a client secret, a refresh token — and\n * a redirect would hand it to a destination the caller never chose.\n * - RESOURCE policy: the caller's `AbortSignal` composed with an explicit deadline, and the response\n * byte cap enforced WHILE STREAMING (and from `Content-Length` first), never after a whole-body\n * allocation.\n * - ESCAPE HATCHES: `allowedHosts` (exact hostnames that may resolve privately) and\n * `allowPrivateAddresses` (an explicit enterprise opt-out), both declared by the composition root.\n *\n * What it does NOT yet do: pin the connection to the validated address (Node's global `fetch` exposes\n * no connect-time lookup hook without the `undici` package). Resolve-then-validate on every hop narrows\n * the DNS-rebinding window; it does not close it, and this comment is the record of that gap.\n *\n * Node-only (`node:dns`, `node:net`): exported from `@robota-sdk/agent-core/node`, never the browser barrel.\n */\n\nimport { lookup as dnsLookup } from 'node:dns/promises';\nimport { isIP } from 'node:net';\n\nimport { isPrivateAddress } from './ip-address.js';\n\nexport type TEgressLookup = (hostname: string) => Promise<readonly string[]>;\n\nexport interface IEgressPolicy {\n /** Exact lowercase hostnames that may be reached even when they resolve to a private address. */\n readonly allowedHosts?: readonly string[];\n /** Explicit enterprise opt-out from private/loopback/metadata blocking. Default `false`. */\n readonly allowPrivateAddresses?: boolean;\n /** Redirect hops followed before refusing. Default 5. */\n readonly maxRedirects?: number;\n}\n\nexport interface IEgressFetchOptions {\n readonly headers?: Readonly<Record<string, string>>;\n readonly signal?: AbortSignal;\n /** Deadline for the WHOLE exchange, redirects and body included. Default 30 000 ms. */\n readonly timeoutMs?: number;\n /** Byte cap enforced on `Content-Length` and again while streaming. Default 5 000 000. */\n readonly maxResponseBytes?: number;\n}\n\nexport interface IEgressDeps {\n readonly fetch?: typeof globalThis.fetch;\n readonly lookup?: TEgressLookup;\n}\n\nexport type TEgressRejectionReason =\n | 'unsupported_scheme'\n | 'private_destination'\n | 'metadata_host'\n | 'unresolvable'\n | 'redirect_limit'\n | 'redirect_without_location'\n | 'redirect_refused'\n | 'response_too_large';\n\nexport interface IEgressRejection {\n readonly reason: TEgressRejectionReason;\n readonly url: string;\n readonly message: string;\n}\n\nexport type TEgressFetchResult =\n | {\n ok: true;\n status: number;\n statusText: string;\n headers: Headers;\n body: Uint8Array;\n finalUrl: string;\n }\n | { ok: false; rejection: IEgressRejection };\n\nconst DEFAULT_TIMEOUT_MS = 30_000;\nconst DEFAULT_MAX_RESPONSE_BYTES = 5_000_000;\nconst DEFAULT_MAX_REDIRECTS = 5;\nconst REDIRECT_STATUSES = new Set([301, 302, 303, 307, 308]);\n\n/** The address classifier, re-exported so the egress boundary stays one import for callers. */\nexport { isPrivateAddress };\n\n/** Hostnames that are metadata services or loopback by convention, whatever they resolve to. */\nexport const BLOCKED_HOSTNAMES: ReadonlySet<string> = new Set([\n 'localhost',\n 'metadata',\n 'metadata.google.internal',\n 'metadata.goog',\n 'instance-data',\n 'instance-data.ec2.internal',\n]);\n\nconst defaultLookup: TEgressLookup = async (hostname) =>\n (await dnsLookup(hostname, { all: true, verbatim: true })).map((entry) => entry.address);\n\n/** Validate ONE destination URL against the policy. `undefined` means it may be reached. */\nexport async function rejectDestination(\n url: URL,\n policy: IEgressPolicy = {},\n lookup: TEgressLookup = defaultLookup,\n): Promise<IEgressRejection | undefined> {\n const href = url.href;\n if (url.protocol !== 'http:' && url.protocol !== 'https:') {\n return {\n reason: 'unsupported_scheme',\n url: href,\n message: `Only http(s) URLs may be fetched.`,\n };\n }\n if (policy.allowPrivateAddresses === true) return undefined;\n const hostname = url.hostname.replace(/^\\[|\\]$/g, '').toLowerCase();\n if (policy.allowedHosts?.includes(hostname)) return undefined;\n if (BLOCKED_HOSTNAMES.has(hostname) || hostname.endsWith('.localhost')) {\n return {\n reason: 'metadata_host',\n url: href,\n message: `Destination \"${hostname}\" is a loopback or cloud-metadata host and is not reachable from tools.`,\n };\n }\n const addresses = isIP(hostname) ? [hostname] : await resolve(hostname, lookup);\n if (addresses === undefined || addresses.length === 0) {\n return {\n reason: 'unresolvable',\n url: href,\n message: `Destination \"${hostname}\" did not resolve.`,\n };\n }\n const blocked = addresses.find(isPrivateAddress);\n if (blocked !== undefined) {\n return {\n reason: 'private_destination',\n url: href,\n message: `Destination \"${hostname}\" resolves to ${blocked}, a private, loopback or link-local address, and is not reachable from tools.`,\n };\n }\n return undefined;\n}\n\nasync function resolve(\n hostname: string,\n lookup: TEgressLookup,\n): Promise<readonly string[] | undefined> {\n try {\n return await lookup(hostname);\n } catch {\n // allow-fallback: an unresolvable host is a POLICY outcome (\"unresolvable\"), reported to the\n // caller as a rejection with its reason — not a hidden success.\n return undefined;\n }\n}\n\n/**\n * Fetch `url` under the egress policy. Policy outcomes are RETURNED (`ok: false`); transport errors\n * (DNS failure at connect, refused connection, TLS, abort) are THROWN, as `fetch` throws them, so the\n * caller's own error classification keeps working.\n */\nexport async function fetchWithEgressPolicy(\n url: string,\n options: IEgressFetchOptions = {},\n policy: IEgressPolicy = {},\n deps: IEgressDeps = {},\n): Promise<TEgressFetchResult> {\n const doFetch = deps.fetch ?? ((input, init) => globalThis.fetch(input, init));\n const lookup = deps.lookup ?? defaultLookup;\n const maxBytes = options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES;\n const maxRedirects = policy.maxRedirects ?? DEFAULT_MAX_REDIRECTS;\n const deadline = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);\n const signal = options.signal ? AbortSignal.any([deadline, options.signal]) : deadline;\n\n let current = new URL(url);\n let headers: Record<string, string> = { ...(options.headers ?? {}) };\n for (let hop = 0; ; hop += 1) {\n const rejection = await rejectDestination(current, policy, lookup);\n if (rejection !== undefined) return { ok: false, rejection };\n\n const response = await doFetch(current.href, { headers, signal, redirect: 'manual' });\n if (!REDIRECT_STATUSES.has(response.status)) {\n return readUnderCap(response, current.href, maxBytes, signal);\n }\n const location = response.headers.get('location');\n if (location === null) {\n return {\n ok: false,\n rejection: {\n reason: 'redirect_without_location',\n url: current.href,\n message: `HTTP ${response.status} without a Location header.`,\n },\n };\n }\n if (hop >= maxRedirects) {\n return {\n ok: false,\n rejection: {\n reason: 'redirect_limit',\n url: current.href,\n message: `More than ${maxRedirects} redirects.`,\n },\n };\n }\n const next = new URL(location, current);\n if (next.origin !== current.origin) headers = stripSensitiveHeaders(headers);\n current = next;\n }\n}\n\nexport interface IEgressPostOptions extends IEgressFetchOptions {\n /** Sent as-is; a `URLSearchParams` or JSON string, never a stream, so it is never re-sent. */\n readonly body: string | URLSearchParams;\n}\n\n/**\n * POST `url` under the egress policy. The destination is validated as for a GET, but a redirect is\n * REFUSED (`redirect_refused`), never followed: the body is the caller's to send to this URL alone.\n */\nexport async function postWithEgressPolicy(\n url: string,\n options: IEgressPostOptions,\n policy: IEgressPolicy = {},\n deps: IEgressDeps = {},\n): Promise<TEgressFetchResult> {\n const doFetch = deps.fetch ?? ((input, init) => globalThis.fetch(input, init));\n const maxBytes = options.maxResponseBytes ?? DEFAULT_MAX_RESPONSE_BYTES;\n const deadline = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);\n const signal = options.signal ? AbortSignal.any([deadline, options.signal]) : deadline;\n const target = new URL(url);\n const rejection = await rejectDestination(target, policy, deps.lookup ?? defaultLookup);\n if (rejection !== undefined) return { ok: false, rejection };\n const response = await doFetch(target.href, {\n method: 'POST',\n headers: { ...(options.headers ?? {}) },\n body: options.body,\n signal,\n redirect: 'manual',\n });\n if (response.status >= 300 && response.status < 400) {\n await response.body?.cancel().catch(() => undefined);\n return {\n ok: false,\n rejection: {\n reason: 'redirect_refused',\n url: target.href,\n message: `HTTP ${response.status}: a POST is never redirected.`,\n },\n };\n }\n return readUnderCap(response, target.href, maxBytes, signal);\n}\n\n/** On a cross-origin hop nothing the caller supplied travels on — only the identifying User-Agent. */\nfunction stripSensitiveHeaders(headers: Record<string, string>): Record<string, string> {\n const kept: Record<string, string> = {};\n for (const [name, value] of Object.entries(headers)) {\n if (name.toLowerCase() === 'user-agent') kept[name] = value;\n }\n return kept;\n}\n\nasync function readUnderCap(\n response: Response,\n finalUrl: string,\n maxBytes: number,\n signal: AbortSignal,\n): Promise<TEgressFetchResult> {\n const tooLarge = (seen: number): TEgressFetchResult => ({\n ok: false,\n rejection: {\n reason: 'response_too_large',\n url: finalUrl,\n message: `Response exceeds ${maxBytes} bytes (${seen} seen).`,\n },\n });\n const declared = Number(response.headers.get('content-length'));\n if (Number.isFinite(declared) && declared > maxBytes) {\n await response.body?.cancel();\n return tooLarge(declared);\n }\n const chunks: Uint8Array[] = [];\n let total = 0;\n if (!response.body && typeof response.arrayBuffer === 'function') {\n // A carrier with no readable stream (a body-less Response, or a non-streaming fetch\n // implementation) can only be read whole; the cap is then checked on what it handed over.\n const whole = new Uint8Array(await response.arrayBuffer());\n if (whole.byteLength > maxBytes) return tooLarge(whole.byteLength);\n chunks.push(whole);\n total = whole.byteLength;\n } else if (response.body) {\n const reader = response.body.getReader();\n for (;;) {\n signal.throwIfAborted();\n const { done, value } = await reader.read();\n if (done) break;\n total += value.byteLength;\n if (total > maxBytes) {\n await reader.cancel();\n return tooLarge(total);\n }\n chunks.push(value);\n }\n }\n const body = new Uint8Array(total);\n let offset = 0;\n for (const chunk of chunks) {\n body.set(chunk, offset);\n offset += chunk.byteLength;\n }\n return {\n ok: true,\n status: response.status,\n statusText: response.statusText,\n headers: response.headers,\n body,\n finalUrl,\n };\n}\n"],"mappings":"0cA2BA,SAAgB,EAA4B,EAAwB,CAClE,GAAI,OAAO,GAAU,SACnB,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