@halonicjs/testing 0.0.0 → 0.1.1

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 (438) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +5 -0
  3. package/README.md +41 -1
  4. package/dist/adapters/http-kit/src/address-checking.d.ts +19 -0
  5. package/dist/adapters/http-kit/src/address-checking.js +1 -0
  6. package/dist/adapters/http-kit/src/address-class.d.ts +34 -0
  7. package/dist/adapters/http-kit/src/address-class.js +109 -0
  8. package/dist/adapters/http-kit/src/index.d.ts +3 -0
  9. package/dist/adapters/http-kit/src/index.js +2 -0
  10. package/dist/adapters/http-kit/src/ip-address.d.ts +23 -0
  11. package/dist/adapters/http-kit/src/ip-address.js +89 -0
  12. package/dist/adapters/integration-kit/src/auth-placement.d.ts +40 -0
  13. package/dist/adapters/integration-kit/src/auth-placement.js +102 -0
  14. package/dist/adapters/integration-kit/src/current-secret-forms.d.ts +28 -0
  15. package/dist/adapters/integration-kit/src/current-secret-forms.js +60 -0
  16. package/dist/adapters/integration-kit/src/declaration.d.ts +15 -0
  17. package/dist/adapters/integration-kit/src/declaration.js +78 -0
  18. package/dist/adapters/integration-kit/src/host.d.ts +34 -0
  19. package/dist/adapters/integration-kit/src/host.js +31 -0
  20. package/dist/adapters/integration-kit/src/index.d.ts +16 -0
  21. package/dist/adapters/integration-kit/src/index.js +22 -0
  22. package/dist/adapters/integration-kit/src/leak-attempt.d.ts +16 -0
  23. package/dist/adapters/integration-kit/src/leak-attempt.js +19 -0
  24. package/dist/adapters/integration-kit/src/limited-http.d.ts +55 -0
  25. package/dist/adapters/integration-kit/src/limited-http.js +225 -0
  26. package/dist/adapters/integration-kit/src/load-problem.d.ts +20 -0
  27. package/dist/adapters/integration-kit/src/load-problem.js +1 -0
  28. package/dist/adapters/integration-kit/src/loader.d.ts +131 -0
  29. package/dist/adapters/integration-kit/src/loader.js +251 -0
  30. package/dist/adapters/integration-kit/src/local-address.d.ts +15 -0
  31. package/dist/adapters/integration-kit/src/local-address.js +25 -0
  32. package/dist/adapters/integration-kit/src/own-request.d.ts +33 -0
  33. package/dist/adapters/integration-kit/src/own-request.js +36 -0
  34. package/dist/adapters/integration-kit/src/plugin-load.d.ts +14 -0
  35. package/dist/adapters/integration-kit/src/plugin-load.js +58 -0
  36. package/dist/adapters/integration-kit/src/policy.d.ts +83 -0
  37. package/dist/adapters/integration-kit/src/policy.js +37 -0
  38. package/dist/adapters/integration-kit/src/request-body.d.ts +38 -0
  39. package/dist/adapters/integration-kit/src/request-body.js +68 -0
  40. package/dist/adapters/integration-kit/src/request-log.d.ts +25 -0
  41. package/dist/adapters/integration-kit/src/request-log.js +17 -0
  42. package/dist/adapters/integration-kit/src/response-body.d.ts +27 -0
  43. package/dist/adapters/integration-kit/src/response-body.js +117 -0
  44. package/dist/adapters/integration-kit/src/scoped-tokens.d.ts +14 -0
  45. package/dist/adapters/integration-kit/src/scoped-tokens.js +27 -0
  46. package/dist/adapters/integration-kit/src/secret-filter.d.ts +84 -0
  47. package/dist/adapters/integration-kit/src/secret-filter.js +220 -0
  48. package/dist/adapters/integration-kit/src/secret-in-request.d.ts +62 -0
  49. package/dist/adapters/integration-kit/src/secret-in-request.js +139 -0
  50. package/dist/adapters/integration-kit/src/secret-placement.d.ts +46 -0
  51. package/dist/adapters/integration-kit/src/secret-placement.js +160 -0
  52. package/dist/adapters/integration-kit/src/sign-in-placement.d.ts +29 -0
  53. package/dist/adapters/integration-kit/src/sign-in-placement.js +92 -0
  54. package/dist/adapters/integration-kit/src/wait.d.ts +16 -0
  55. package/dist/adapters/integration-kit/src/wait.js +35 -0
  56. package/dist/core/events/src/add-usage.d.ts +10 -0
  57. package/dist/core/events/src/add-usage.js +27 -0
  58. package/dist/core/events/src/agent-resume.d.ts +24 -0
  59. package/dist/core/events/src/agent-resume.js +1 -0
  60. package/dist/core/events/src/blocked-sites.d.ts +57 -0
  61. package/dist/core/events/src/blocked-sites.js +89 -0
  62. package/dist/core/events/src/home-path.d.ts +13 -0
  63. package/dist/core/events/src/home-path.js +26 -0
  64. package/dist/core/events/src/index.d.ts +17 -0
  65. package/dist/core/events/src/index.js +10 -0
  66. package/dist/core/events/src/run-basics.d.ts +228 -0
  67. package/dist/core/events/src/run-basics.js +1 -0
  68. package/dist/core/events/src/run-event.d.ts +478 -0
  69. package/dist/core/events/src/run-event.js +1 -0
  70. package/dist/core/events/src/run-reads.d.ts +25 -0
  71. package/dist/core/events/src/run-reads.js +44 -0
  72. package/dist/core/events/src/run-sends.d.ts +47 -0
  73. package/dist/core/events/src/run-sends.js +68 -0
  74. package/dist/core/events/src/run-summary.d.ts +108 -0
  75. package/dist/core/events/src/run-summary.js +1 -0
  76. package/dist/core/events/src/sandbox-blocked.d.ts +42 -0
  77. package/dist/core/events/src/sandbox-blocked.js +26 -0
  78. package/dist/core/events/src/sandbox-opened-read.d.ts +17 -0
  79. package/dist/core/events/src/sandbox-opened-read.js +63 -0
  80. package/dist/core/events/src/sandbox-opened.d.ts +94 -0
  81. package/dist/core/events/src/sandbox-opened.js +52 -0
  82. package/dist/core/events/src/summarize.d.ts +14 -0
  83. package/dist/core/events/src/summarize.js +192 -0
  84. package/dist/core/events/src/timeline-entry.d.ts +21 -0
  85. package/dist/core/events/src/timeline-entry.js +106 -0
  86. package/dist/core/events/src/upgrade.d.ts +23 -0
  87. package/dist/core/events/src/upgrade.js +49 -0
  88. package/dist/core/format/src/compact.d.ts +30 -0
  89. package/dist/core/format/src/compact.js +72 -0
  90. package/dist/core/format/src/index.d.ts +39 -0
  91. package/dist/core/format/src/index.js +25 -0
  92. package/dist/core/format/src/integration/index.d.ts +7 -0
  93. package/dist/core/format/src/integration/index.js +10 -0
  94. package/dist/core/format/src/json-schema.d.ts +26 -0
  95. package/dist/core/format/src/json-schema.js +48 -0
  96. package/dist/core/format/src/kind.d.ts +65 -0
  97. package/dist/core/format/src/kind.js +1 -0
  98. package/dist/core/format/src/kinds/agent/kind.d.ts +4 -0
  99. package/dist/core/format/src/kinds/agent/kind.js +10 -0
  100. package/dist/core/format/src/kinds/agent/sandbox-fields.d.ts +99 -0
  101. package/dist/core/format/src/kinds/agent/sandbox-fields.js +216 -0
  102. package/dist/core/format/src/kinds/agent/schema.d.ts +147 -0
  103. package/dist/core/format/src/kinds/agent/schema.js +107 -0
  104. package/dist/core/format/src/kinds/agent/working-folder-start.d.ts +74 -0
  105. package/dist/core/format/src/kinds/agent/working-folder-start.js +312 -0
  106. package/dist/core/format/src/kinds/collection/kind.d.ts +8 -0
  107. package/dist/core/format/src/kinds/collection/kind.js +14 -0
  108. package/dist/core/format/src/kinds/collection/schema.d.ts +89 -0
  109. package/dist/core/format/src/kinds/collection/schema.js +90 -0
  110. package/dist/core/format/src/kinds/connector/is-local.d.ts +10 -0
  111. package/dist/core/format/src/kinds/connector/is-local.js +43 -0
  112. package/dist/core/format/src/kinds/connector/kind.d.ts +4 -0
  113. package/dist/core/format/src/kinds/connector/kind.js +218 -0
  114. package/dist/core/format/src/kinds/connector/schema.d.ts +74 -0
  115. package/dist/core/format/src/kinds/connector/schema.js +143 -0
  116. package/dist/core/format/src/kinds/deployments/kind.d.ts +4 -0
  117. package/dist/core/format/src/kinds/deployments/kind.js +49 -0
  118. package/dist/core/format/src/kinds/deployments/schema.d.ts +77 -0
  119. package/dist/core/format/src/kinds/deployments/schema.js +94 -0
  120. package/dist/core/format/src/kinds/hub/kind.d.ts +4 -0
  121. package/dist/core/format/src/kinds/hub/kind.js +10 -0
  122. package/dist/core/format/src/kinds/hub/schema.d.ts +54 -0
  123. package/dist/core/format/src/kinds/hub/schema.js +34 -0
  124. package/dist/core/format/src/kinds/integration/approved-sign-ins.d.ts +62 -0
  125. package/dist/core/format/src/kinds/integration/approved-sign-ins.js +125 -0
  126. package/dist/core/format/src/kinds/integration/host-key.d.ts +7 -0
  127. package/dist/core/format/src/kinds/integration/host-key.js +8 -0
  128. package/dist/core/format/src/kinds/integration/kind.d.ts +18 -0
  129. package/dist/core/format/src/kinds/integration/kind.js +175 -0
  130. package/dist/core/format/src/kinds/integration/parse-sheet.d.ts +19 -0
  131. package/dist/core/format/src/kinds/integration/parse-sheet.js +24 -0
  132. package/dist/core/format/src/kinds/integration/policy.d.ts +112 -0
  133. package/dist/core/format/src/kinds/integration/policy.js +327 -0
  134. package/dist/core/format/src/kinds/integration/schema.d.ts +410 -0
  135. package/dist/core/format/src/kinds/integration/schema.js +359 -0
  136. package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +13 -0
  137. package/dist/core/format/src/kinds/integration/sign-in-checks.js +120 -0
  138. package/dist/core/format/src/kinds/integration/sign-in-urls.d.ts +19 -0
  139. package/dist/core/format/src/kinds/integration/sign-in-urls.js +47 -0
  140. package/dist/core/format/src/kinds/knowledge/kind.d.ts +4 -0
  141. package/dist/core/format/src/kinds/knowledge/kind.js +13 -0
  142. package/dist/core/format/src/kinds/knowledge/schema.d.ts +18 -0
  143. package/dist/core/format/src/kinds/knowledge/schema.js +25 -0
  144. package/dist/core/format/src/kinds/models/kind.d.ts +4 -0
  145. package/dist/core/format/src/kinds/models/kind.js +10 -0
  146. package/dist/core/format/src/kinds/models/schema.d.ts +92 -0
  147. package/dist/core/format/src/kinds/models/schema.js +38 -0
  148. package/dist/core/format/src/kinds/plugin/backend.d.ts +22 -0
  149. package/dist/core/format/src/kinds/plugin/backend.js +31 -0
  150. package/dist/core/format/src/kinds/plugin/checks.d.ts +13 -0
  151. package/dist/core/format/src/kinds/plugin/checks.js +137 -0
  152. package/dist/core/format/src/kinds/plugin/kind.d.ts +8 -0
  153. package/dist/core/format/src/kinds/plugin/kind.js +16 -0
  154. package/dist/core/format/src/kinds/plugin/problems.d.ts +24 -0
  155. package/dist/core/format/src/kinds/plugin/problems.js +65 -0
  156. package/dist/core/format/src/kinds/plugin/schema.d.ts +672 -0
  157. package/dist/core/format/src/kinds/plugin/schema.js +261 -0
  158. package/dist/core/format/src/kinds/plugin/setting-values.d.ts +17 -0
  159. package/dist/core/format/src/kinds/plugin/setting-values.js +38 -0
  160. package/dist/core/format/src/kinds/plugin/ui-checks.d.ts +8 -0
  161. package/dist/core/format/src/kinds/plugin/ui-checks.js +85 -0
  162. package/dist/core/format/src/kinds/provider/kind.d.ts +4 -0
  163. package/dist/core/format/src/kinds/provider/kind.js +24 -0
  164. package/dist/core/format/src/kinds/provider/schema.d.ts +17 -0
  165. package/dist/core/format/src/kinds/provider/schema.js +22 -0
  166. package/dist/core/format/src/kinds/routine/kind.d.ts +8 -0
  167. package/dist/core/format/src/kinds/routine/kind.js +62 -0
  168. package/dist/core/format/src/kinds/routine/schema.d.ts +94 -0
  169. package/dist/core/format/src/kinds/routine/schema.js +115 -0
  170. package/dist/core/format/src/kinds/routine/webhook-headers.d.ts +9 -0
  171. package/dist/core/format/src/kinds/routine/webhook-headers.js +26 -0
  172. package/dist/core/format/src/kinds/runtime/kind.d.ts +4 -0
  173. package/dist/core/format/src/kinds/runtime/kind.js +13 -0
  174. package/dist/core/format/src/kinds/runtime/schema.d.ts +10 -0
  175. package/dist/core/format/src/kinds/runtime/schema.js +12 -0
  176. package/dist/core/format/src/kinds/skill/kind.d.ts +4 -0
  177. package/dist/core/format/src/kinds/skill/kind.js +10 -0
  178. package/dist/core/format/src/kinds/skill/schema.d.ts +17 -0
  179. package/dist/core/format/src/kinds/skill/schema.js +17 -0
  180. package/dist/core/format/src/kinds/skill/scripts-folder.d.ts +27 -0
  181. package/dist/core/format/src/kinds/skill/scripts-folder.js +37 -0
  182. package/dist/core/format/src/kinds/workflow/kind.d.ts +8 -0
  183. package/dist/core/format/src/kinds/workflow/kind.js +14 -0
  184. package/dist/core/format/src/kinds/workflow/schema.d.ts +162 -0
  185. package/dist/core/format/src/kinds/workflow/schema.js +106 -0
  186. package/dist/core/format/src/kinds/workflow-test/kind.d.ts +4 -0
  187. package/dist/core/format/src/kinds/workflow-test/kind.js +14 -0
  188. package/dist/core/format/src/kinds/workflow-test/schema.d.ts +67 -0
  189. package/dist/core/format/src/kinds/workflow-test/schema.js +59 -0
  190. package/dist/core/format/src/kinds/workspace/kind.d.ts +4 -0
  191. package/dist/core/format/src/kinds/workspace/kind.js +10 -0
  192. package/dist/core/format/src/kinds/workspace/schema.d.ts +72 -0
  193. package/dist/core/format/src/kinds/workspace/schema.js +66 -0
  194. package/dist/core/format/src/parse-file.d.ts +69 -0
  195. package/dist/core/format/src/parse-file.js +105 -0
  196. package/dist/core/format/src/recording/format.d.ts +81 -0
  197. package/dist/core/format/src/recording/format.js +102 -0
  198. package/dist/core/format/src/recording/index.d.ts +1 -0
  199. package/dist/core/format/src/recording/index.js +3 -0
  200. package/dist/core/format/src/registry.d.ts +64 -0
  201. package/dist/core/format/src/registry.js +61 -0
  202. package/dist/core/format/src/reserved.d.ts +20 -0
  203. package/dist/core/format/src/reserved.js +30 -0
  204. package/dist/core/format/src/shared/fields.d.ts +34 -0
  205. package/dist/core/format/src/shared/fields.js +74 -0
  206. package/dist/core/format/src/shared/guard.d.ts +32 -0
  207. package/dist/core/format/src/shared/guard.js +16 -0
  208. package/dist/core/format/src/shared/key-in-value.d.ts +28 -0
  209. package/dist/core/format/src/shared/key-in-value.js +82 -0
  210. package/dist/core/format/src/shared/legacy-keys.d.ts +8 -0
  211. package/dist/core/format/src/shared/legacy-keys.js +17 -0
  212. package/dist/core/format/src/shared/program-start.d.ts +60 -0
  213. package/dist/core/format/src/shared/program-start.js +99 -0
  214. package/dist/core/format/src/shared/relative-path.d.ts +29 -0
  215. package/dist/core/format/src/shared/relative-path.js +50 -0
  216. package/dist/core/format/src/shared/secret-name.d.ts +24 -0
  217. package/dist/core/format/src/shared/secret-name.js +107 -0
  218. package/dist/core/format/src/source.d.ts +16 -0
  219. package/dist/core/format/src/source.js +73 -0
  220. package/dist/core/ports/src/agent-placement-store.d.ts +74 -0
  221. package/dist/core/ports/src/agent-placement-store.js +27 -0
  222. package/dist/core/ports/src/agent-runs-not-available.d.ts +21 -0
  223. package/dist/core/ports/src/agent-runs-not-available.js +25 -0
  224. package/dist/core/ports/src/blob-store.d.ts +45 -0
  225. package/dist/core/ports/src/blob-store.js +24 -0
  226. package/dist/core/ports/src/cant-try-error.d.ts +35 -0
  227. package/dist/core/ports/src/cant-try-error.js +44 -0
  228. package/dist/core/ports/src/chat.d.ts +127 -0
  229. package/dist/core/ports/src/chat.js +1 -0
  230. package/dist/core/ports/src/clock.d.ts +7 -0
  231. package/dist/core/ports/src/clock.js +2 -0
  232. package/dist/core/ports/src/connection-settings-store.d.ts +57 -0
  233. package/dist/core/ports/src/connection-settings-store.js +2 -0
  234. package/dist/core/ports/src/connector-client.d.ts +303 -0
  235. package/dist/core/ports/src/connector-client.js +19 -0
  236. package/dist/core/ports/src/coordination.d.ts +84 -0
  237. package/dist/core/ports/src/coordination.js +2 -0
  238. package/dist/core/ports/src/definition-store.d.ts +229 -0
  239. package/dist/core/ports/src/definition-store.js +122 -0
  240. package/dist/core/ports/src/digest.d.ts +14 -0
  241. package/dist/core/ports/src/digest.js +2 -0
  242. package/dist/core/ports/src/folder-reader.d.ts +89 -0
  243. package/dist/core/ports/src/folder-reader.js +2 -0
  244. package/dist/core/ports/src/harness-bridge-server.d.ts +198 -0
  245. package/dist/core/ports/src/harness-bridge-server.js +37 -0
  246. package/dist/core/ports/src/harness-sign-in-command.d.ts +27 -0
  247. package/dist/core/ports/src/harness-sign-in-command.js +31 -0
  248. package/dist/core/ports/src/harness.d.ts +283 -0
  249. package/dist/core/ports/src/harness.js +45 -0
  250. package/dist/core/ports/src/host-settings-store.d.ts +116 -0
  251. package/dist/core/ports/src/host-settings-store.js +106 -0
  252. package/dist/core/ports/src/http-client.d.ts +27 -0
  253. package/dist/core/ports/src/http-client.js +2 -0
  254. package/dist/core/ports/src/id-generator.d.ts +14 -0
  255. package/dist/core/ports/src/id-generator.js +2 -0
  256. package/dist/core/ports/src/index.d.ts +45 -0
  257. package/dist/core/ports/src/index.js +44 -0
  258. package/dist/core/ports/src/instruction-trust-store.d.ts +81 -0
  259. package/dist/core/ports/src/instruction-trust-store.js +43 -0
  260. package/dist/core/ports/src/integration.d.ts +242 -0
  261. package/dist/core/ports/src/integration.js +31 -0
  262. package/dist/core/ports/src/knowledge-provider.d.ts +65 -0
  263. package/dist/core/ports/src/knowledge-provider.js +2 -0
  264. package/dist/core/ports/src/llm-cache.d.ts +13 -0
  265. package/dist/core/ports/src/llm-cache.js +2 -0
  266. package/dist/core/ports/src/llm-provider.d.ts +186 -0
  267. package/dist/core/ports/src/llm-provider.js +139 -0
  268. package/dist/core/ports/src/model-price.d.ts +34 -0
  269. package/dist/core/ports/src/model-price.js +25 -0
  270. package/dist/core/ports/src/password-hasher.d.ts +63 -0
  271. package/dist/core/ports/src/password-hasher.js +2 -0
  272. package/dist/core/ports/src/plugin-folder-writer.d.ts +104 -0
  273. package/dist/core/ports/src/plugin-folder-writer.js +95 -0
  274. package/dist/core/ports/src/port-versions.d.ts +47 -0
  275. package/dist/core/ports/src/port-versions.js +80 -0
  276. package/dist/core/ports/src/program-probe.d.ts +69 -0
  277. package/dist/core/ports/src/program-probe.js +2 -0
  278. package/dist/core/ports/src/provider-default-base-url.d.ts +10 -0
  279. package/dist/core/ports/src/provider-default-base-url.js +18 -0
  280. package/dist/core/ports/src/record-store.d.ts +79 -0
  281. package/dist/core/ports/src/record-store.js +108 -0
  282. package/dist/core/ports/src/resource-probe.d.ts +59 -0
  283. package/dist/core/ports/src/resource-probe.js +2 -0
  284. package/dist/core/ports/src/run-executor.d.ts +303 -0
  285. package/dist/core/ports/src/run-executor.js +2 -0
  286. package/dist/core/ports/src/run-failure-error.d.ts +49 -0
  287. package/dist/core/ports/src/run-failure-error.js +47 -0
  288. package/dist/core/ports/src/run-store.d.ts +194 -0
  289. package/dist/core/ports/src/run-store.js +131 -0
  290. package/dist/core/ports/src/run-target-not-found.d.ts +34 -0
  291. package/dist/core/ports/src/run-target-not-found.js +41 -0
  292. package/dist/core/ports/src/sandbox-setting-store.d.ts +68 -0
  293. package/dist/core/ports/src/sandbox-setting-store.js +33 -0
  294. package/dist/core/ports/src/sandbox.d.ts +364 -0
  295. package/dist/core/ports/src/sandbox.js +70 -0
  296. package/dist/core/ports/src/scheduler.d.ts +85 -0
  297. package/dist/core/ports/src/scheduler.js +2 -0
  298. package/dist/core/ports/src/secrets.d.ts +201 -0
  299. package/dist/core/ports/src/secrets.js +200 -0
  300. package/dist/core/ports/src/token-store.d.ts +19 -0
  301. package/dist/core/ports/src/token-store.js +2 -0
  302. package/dist/core/ports/src/tool-approval-store.d.ts +253 -0
  303. package/dist/core/ports/src/tool-approval-store.js +116 -0
  304. package/dist/core/ports/src/trust-store.d.ts +72 -0
  305. package/dist/core/ports/src/trust-store.js +2 -0
  306. package/dist/core/ports/src/unfenced-run-consent-store.d.ts +43 -0
  307. package/dist/core/ports/src/unfenced-run-consent-store.js +2 -0
  308. package/dist/core/ports/src/vcs-status.d.ts +8 -0
  309. package/dist/core/ports/src/vcs-status.js +90 -0
  310. package/dist/core/ports/src/vcs.d.ts +394 -0
  311. package/dist/core/ports/src/vcs.js +48 -0
  312. package/dist/core/schema-kit/src/builders.d.ts +50 -0
  313. package/dist/core/schema-kit/src/builders.js +72 -0
  314. package/dist/core/schema-kit/src/depth.d.ts +15 -0
  315. package/dist/core/schema-kit/src/depth.js +37 -0
  316. package/dist/core/schema-kit/src/index.d.ts +6 -0
  317. package/dist/core/schema-kit/src/index.js +6 -0
  318. package/dist/core/schema-kit/src/issue.d.ts +22 -0
  319. package/dist/core/schema-kit/src/issue.js +23 -0
  320. package/dist/core/schema-kit/src/json-schema.d.ts +23 -0
  321. package/dist/core/schema-kit/src/json-schema.js +22 -0
  322. package/dist/core/schema-kit/src/parse.d.ts +17 -0
  323. package/dist/core/schema-kit/src/parse.js +25 -0
  324. package/dist/core/schema-kit/src/schema.d.ts +12 -0
  325. package/dist/core/schema-kit/src/schema.js +1 -0
  326. package/dist/core/std/src/amount.d.ts +13 -0
  327. package/dist/core/std/src/amount.js +22 -0
  328. package/dist/core/std/src/ascii-host.d.ts +18 -0
  329. package/dist/core/std/src/ascii-host.js +110 -0
  330. package/dist/core/std/src/assert.d.ts +39 -0
  331. package/dist/core/std/src/assert.js +59 -0
  332. package/dist/core/std/src/base64url.d.ts +23 -0
  333. package/dist/core/std/src/base64url.js +65 -0
  334. package/dist/core/std/src/canonical-json.d.ts +18 -0
  335. package/dist/core/std/src/canonical-json.js +56 -0
  336. package/dist/core/std/src/clock.d.ts +27 -0
  337. package/dist/core/std/src/clock.js +33 -0
  338. package/dist/core/std/src/constant-time.d.ts +16 -0
  339. package/dist/core/std/src/constant-time.js +26 -0
  340. package/dist/core/std/src/content-digest.d.ts +24 -0
  341. package/dist/core/std/src/content-digest.js +28 -0
  342. package/dist/core/std/src/deep-clone.d.ts +15 -0
  343. package/dist/core/std/src/deep-clone.js +59 -0
  344. package/dist/core/std/src/deep-equal.d.ts +23 -0
  345. package/dist/core/std/src/deep-equal.js +64 -0
  346. package/dist/core/std/src/emitter.d.ts +42 -0
  347. package/dist/core/std/src/emitter.js +74 -0
  348. package/dist/core/std/src/error-kind.d.ts +88 -0
  349. package/dist/core/std/src/error-kind.js +98 -0
  350. package/dist/core/std/src/hex.d.ts +10 -0
  351. package/dist/core/std/src/hex.js +16 -0
  352. package/dist/core/std/src/hidden-characters.d.ts +19 -0
  353. package/dist/core/std/src/hidden-characters.js +54 -0
  354. package/dist/core/std/src/ids.d.ts +45 -0
  355. package/dist/core/std/src/ids.js +49 -0
  356. package/dist/core/std/src/index.d.ts +30 -0
  357. package/dist/core/std/src/index.js +31 -0
  358. package/dist/core/std/src/keyed-queue.d.ts +18 -0
  359. package/dist/core/std/src/keyed-queue.js +32 -0
  360. package/dist/core/std/src/line-diff.d.ts +83 -0
  361. package/dist/core/std/src/line-diff.js +179 -0
  362. package/dist/core/std/src/line-merge.d.ts +63 -0
  363. package/dist/core/std/src/line-merge.js +138 -0
  364. package/dist/core/std/src/plain-data.d.ts +32 -0
  365. package/dist/core/std/src/plain-data.js +57 -0
  366. package/dist/core/std/src/posix-path.d.ts +61 -0
  367. package/dist/core/std/src/posix-path.js +121 -0
  368. package/dist/core/std/src/public-suffixes.generated.d.ts +9 -0
  369. package/dist/core/std/src/public-suffixes.generated.js +10429 -0
  370. package/dist/core/std/src/registrable-domain.d.ts +10 -0
  371. package/dist/core/std/src/registrable-domain.js +62 -0
  372. package/dist/core/std/src/result.d.ts +55 -0
  373. package/dist/core/std/src/result.js +52 -0
  374. package/dist/core/std/src/secret-scrubber.d.ts +54 -0
  375. package/dist/core/std/src/secret-scrubber.js +124 -0
  376. package/dist/core/std/src/secret-shape.d.ts +20 -0
  377. package/dist/core/std/src/secret-shape.js +53 -0
  378. package/dist/core/std/src/secret-variable-name.d.ts +12 -0
  379. package/dist/core/std/src/secret-variable-name.js +34 -0
  380. package/dist/core/std/src/site-name.d.ts +35 -0
  381. package/dist/core/std/src/site-name.js +111 -0
  382. package/dist/core/std/src/stop-signal.d.ts +44 -0
  383. package/dist/core/std/src/stop-signal.js +77 -0
  384. package/dist/core/std/src/text.d.ts +28 -0
  385. package/dist/core/std/src/text.js +54 -0
  386. package/dist/core/std/src/url-host.d.ts +35 -0
  387. package/dist/core/std/src/url-host.js +170 -0
  388. package/dist/core/std/src/utf8.d.ts +23 -0
  389. package/dist/core/std/src/utf8.js +110 -0
  390. package/dist/core/std/src/version.d.ts +48 -0
  391. package/dist/core/std/src/version.js +103 -0
  392. package/dist/core/yaml/src/depth.d.ts +14 -0
  393. package/dist/core/yaml/src/depth.js +140 -0
  394. package/dist/core/yaml/src/edit-data.d.ts +47 -0
  395. package/dist/core/yaml/src/edit-data.js +286 -0
  396. package/dist/core/yaml/src/edit-text.d.ts +92 -0
  397. package/dist/core/yaml/src/edit-text.js +267 -0
  398. package/dist/core/yaml/src/edit.d.ts +47 -0
  399. package/dist/core/yaml/src/edit.js +198 -0
  400. package/dist/core/yaml/src/index.d.ts +5 -0
  401. package/dist/core/yaml/src/index.js +4 -0
  402. package/dist/core/yaml/src/problem.d.ts +20 -0
  403. package/dist/core/yaml/src/problem.js +1 -0
  404. package/dist/core/yaml/src/read.d.ts +47 -0
  405. package/dist/core/yaml/src/read.js +130 -0
  406. package/dist/core/yaml/src/splice-node.d.ts +47 -0
  407. package/dist/core/yaml/src/splice-node.js +333 -0
  408. package/dist/core/yaml/src/splice.d.ts +13 -0
  409. package/dist/core/yaml/src/splice.js +174 -0
  410. package/dist/core/yaml/src/unsupported.d.ts +26 -0
  411. package/dist/core/yaml/src/unsupported.js +70 -0
  412. package/dist/core/yaml/src/write.d.ts +35 -0
  413. package/dist/core/yaml/src/write.js +44 -0
  414. package/dist/testing/integration/src/canaries.d.ts +14 -0
  415. package/dist/testing/integration/src/canaries.js +17 -0
  416. package/dist/testing/integration/src/checks.d.ts +37 -0
  417. package/dist/testing/integration/src/checks.js +195 -0
  418. package/dist/testing/integration/src/describe.d.ts +35 -0
  419. package/dist/testing/integration/src/describe.js +74 -0
  420. package/dist/testing/integration/src/failure.d.ts +6 -0
  421. package/dist/testing/integration/src/failure.js +8 -0
  422. package/dist/testing/integration/src/fake-wait.d.ts +18 -0
  423. package/dist/testing/integration/src/fake-wait.js +21 -0
  424. package/dist/testing/integration/src/index.d.ts +10 -0
  425. package/dist/testing/integration/src/index.js +11 -0
  426. package/dist/testing/integration/src/load.d.ts +14 -0
  427. package/dist/testing/integration/src/load.js +47 -0
  428. package/dist/testing/integration/src/plugin-folder.d.ts +23 -0
  429. package/dist/testing/integration/src/plugin-folder.js +59 -0
  430. package/dist/testing/integration/src/plugin.d.ts +32 -0
  431. package/dist/testing/integration/src/plugin.js +57 -0
  432. package/dist/testing/integration/src/recording.d.ts +84 -0
  433. package/dist/testing/integration/src/recording.js +164 -0
  434. package/dist/testing/integration/src/run.d.ts +60 -0
  435. package/dist/testing/integration/src/run.js +81 -0
  436. package/dist/testing/integration/src/source-scan.d.ts +16 -0
  437. package/dist/testing/integration/src/source-scan.js +40 -0
  438. package/package.json +34 -3
@@ -0,0 +1,160 @@
1
+ import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
2
+ import { isLoopback } from "./local-address.js";
3
+ import { hostIn, } from "./policy.js";
4
+ /** Checks that the secret is declared, isn't a client secret, and is placed as the sheet says. */
5
+ export function checkSecretPlacement(policy, placement) {
6
+ const declared = declaredSecret(policy, placement.secret);
7
+ if (declared === undefined) {
8
+ if (isClientSecret(policy, placement.secret)) {
9
+ throw new IntegrationRefusedError("secret-sign-in-only", `${policy.name}: the secret ${quoted(placement.secret)} is the client secret of a sign-in, which only Halonic's sign-in code sends`);
10
+ }
11
+ throw new IntegrationRefusedError("secret-not-declared", `${policy.name}: the secret ${quoted(placement.secret)} is not in its permission sheet`);
12
+ }
13
+ if (!matchesSheet(placement, declared.placement)) {
14
+ throw new IntegrationRefusedError("placement-not-in-sheet", `${policy.name}: the secret ${quoted(placement.secret)} goes ${describe(declared.placement)} in its permission sheet, not ${describe(placement)}`);
15
+ }
16
+ }
17
+ /** Whether a sign-in names the secret as its client secret, by own key only. */
18
+ function isClientSecret(policy, secret) {
19
+ return Object.values(policy.signIns).some((signIn) => signIn.clientSecret?.name === secret);
20
+ }
21
+ /** Checks that the secret may go to this host, over this scheme. */
22
+ export function checkSecretHost(policy, placement, url) {
23
+ const declared = declaredSecret(policy, placement.secret);
24
+ if (declared === undefined || !hostIn(declared.hosts, url)) {
25
+ throw new IntegrationRefusedError("secret-not-allowed-for-host", `${policy.name}: the secret ${quoted(placement.secret)} may not go to ${url.host}`);
26
+ }
27
+ if (!mayCarrySecret(url)) {
28
+ throw new IntegrationRefusedError("secret-over-plain-http", `${policy.name}: the secret ${quoted(placement.secret)} may not go over plain http to another machine (${url.host})`);
29
+ }
30
+ }
31
+ /** The sheet's entry for a secret, looked up by own key only, so `toString` is never a secret. */
32
+ function declaredSecret(policy, secret) {
33
+ return Object.hasOwn(policy.secrets, secret) ? policy.secrets[secret] : undefined;
34
+ }
35
+ /**
36
+ * Whether the code places the secret the way the sheet says. Otherwise it
37
+ * could put a key in a field the service stores, such as a note title,
38
+ * where the integration could read it back. Header names match ignoring
39
+ * ASCII case, as HTTP does; a missing prefix and `""` send the same bytes;
40
+ * form field names are case-sensitive. The placement comes from the
41
+ * integration's code, so nothing in it is trusted to have the right type.
42
+ */
43
+ export function matchesSheet(placement, sheet) {
44
+ switch (sheet.as) {
45
+ case "bearer":
46
+ return placement.as === "bearer";
47
+ case "header":
48
+ return (placement.as === "header" &&
49
+ typeof placement.header === "string" &&
50
+ asciiLowerCase(placement.header) === asciiLowerCase(sheet.header) &&
51
+ (placement.prefix ?? "") === (sheet.prefix ?? ""));
52
+ case "form":
53
+ return placement.as === "form" && placement.field === sheet.field;
54
+ }
55
+ }
56
+ /**
57
+ * Lower-cases `A` to `Z` only. `toLowerCase` would also turn the Kelvin
58
+ * sign into `k`, so a header no service reads would pass as `x-api-key`.
59
+ */
60
+ function asciiLowerCase(text) {
61
+ return text.replace(/[A-Z]/g, (letter) => letter.toLowerCase());
62
+ }
63
+ /** A placement in words, for a refusal message. It never holds a value. */
64
+ export function describe(placement) {
65
+ switch (placement.as) {
66
+ case "bearer":
67
+ return "as a bearer token";
68
+ case "header": {
69
+ const prefix = placement.prefix ?? "";
70
+ return prefix === ""
71
+ ? `in the header ${quoted(placement.header)}`
72
+ : `in the header ${quoted(placement.header)} after ${quoted(prefix)}`;
73
+ }
74
+ case "form":
75
+ return `in the form field ${quoted(placement.field)}`;
76
+ default:
77
+ return `as ${quoted(placement.as)}`;
78
+ }
79
+ }
80
+ /**
81
+ * Text from the integration's code, cut short and quoted, so it can't break
82
+ * the message. It is cut by characters before quoting, so the cut never
83
+ * falls inside an escape or a surrogate pair.
84
+ */
85
+ export function quoted(text) {
86
+ const characters = Array.from(String(text));
87
+ const shown = characters.length <= 50 ? characters.join("") : `${characters.slice(0, 50).join("")}…`;
88
+ return JSON.stringify(shown);
89
+ }
90
+ /** A secret goes over `https`, or over plain `http` only to this machine. */
91
+ function mayCarrySecret(url) {
92
+ return url.protocol === "https:" || isLoopback(url.hostname);
93
+ }
94
+ /**
95
+ * Reads each secret's value once. The values never leave the kit. An
96
+ * optional secret without a value gets no entry, so `place` leaves it out.
97
+ */
98
+ export async function readSecrets(policy, secrets, placements) {
99
+ const values = new Map();
100
+ for (const { secret } of placements.filter((placement) => "secret" in placement)) {
101
+ if (values.has(secret))
102
+ continue;
103
+ const value = await secrets.get(secret);
104
+ if (value === null || value === "") {
105
+ // `checkPlacements` ran first, so the secret is declared.
106
+ if (policy.secrets[secret]?.optional === true)
107
+ continue;
108
+ throw new IntegrationRefusedError("secret-not-configured", `${policy.name}: the secret ${quoted(secret)} is not configured`);
109
+ }
110
+ checkSecretLength(policy.name, secret, value);
111
+ values.set(secret, value);
112
+ }
113
+ return values;
114
+ }
115
+ /**
116
+ * The fewest UTF-8 bytes a secret value may have. The filter replaces every
117
+ * copy of a value in what the integration sees, so a shorter one would
118
+ * remove ordinary text, and where it was removed would give the value away.
119
+ */
120
+ export const minSecretBytes = 8;
121
+ /**
122
+ * @throws {IntegrationRefusedError} `secret-too-short` when `value` has fewer than {@link minSecretBytes} bytes
123
+ */
124
+ export function checkSecretLength(integration, secret, value) {
125
+ if (new TextEncoder().encode(value).length >= minSecretBytes)
126
+ return;
127
+ throw new IntegrationRefusedError("secret-too-short", `${integration}: the secret ${quoted(secret)} is shorter than ${minSecretBytes} bytes, too short to keep out of what the integration sees`);
128
+ }
129
+ /**
130
+ * Puts one secret into the headers or the form body, when it may go to this
131
+ * hop's host. A secret that may not go to this hop is left out, which happens
132
+ * after a redirect to another declared host.
133
+ *
134
+ * @returns the form body to send, which a `form` placement writes into
135
+ */
136
+ export function placeSecret(policy, placement, value, url, headers, form) {
137
+ const declared = policy.secrets[placement.secret];
138
+ if (declared === undefined ||
139
+ value === undefined ||
140
+ !hostIn(declared.hosts, url) ||
141
+ !mayCarrySecret(url)) {
142
+ return form;
143
+ }
144
+ switch (placement.as) {
145
+ case "bearer":
146
+ headers.set("authorization", `Bearer ${value}`);
147
+ return form;
148
+ case "header":
149
+ headers.set(placement.header, `${placement.prefix ?? ""}${value}`);
150
+ return form;
151
+ case "form": {
152
+ if (form === undefined) {
153
+ throw new IntegrationRefusedError("secret-needs-form-body", `${policy.name}: the secret ${quoted(placement.secret)} goes in a form field, so the body must be a form`);
154
+ }
155
+ const written = new URLSearchParams(form);
156
+ written.set(placement.field, value);
157
+ return written;
158
+ }
159
+ }
160
+ }
@@ -0,0 +1,29 @@
1
+ import { type SignInPlacement, type SignInTokens } from "../../../core/ports/src/index.js";
2
+ import { type IntegrationPolicy } from "./policy.js";
3
+ /**
4
+ * Checks that the sign-in is declared and that the code places its token the
5
+ * way the sheet's `access` block says, with the same check as a secret's
6
+ * placement (`placement-not-in-sheet`). Runs before any token is asked for.
7
+ */
8
+ export declare function checkSignInPlacement(policy: IntegrationPolicy, placement: SignInPlacement): void;
9
+ /**
10
+ * Checks that the token may go to the request's first host. Unlike a
11
+ * secret, a token never goes over plain `http`, not even to this machine.
12
+ */
13
+ export declare function checkSignInPlacementHost(policy: IntegrationPolicy, placement: SignInPlacement, url: URL): void;
14
+ /**
15
+ * The access tokens this hop will carry, one per sign-in whose token may go
16
+ * to the hop's host. A sign-in that may not go there is not asked for, so a
17
+ * redirect to another declared host neither refreshes nor places its token.
18
+ *
19
+ * @throws {IntegrationRefusedError} `sign-in-needed` when the user has to sign in (again), or when no sign-ins are set up at all
20
+ */
21
+ export declare function readTokens(policy: IntegrationPolicy, tokens: SignInTokens | undefined, placements: readonly SignInPlacement[], url: URL, signal: AbortSignal): Promise<Map<string, string>>;
22
+ /** Puts the token into the headers, when this hop was asked for it. */
23
+ export declare function placeToken(placement: SignInPlacement, value: string | undefined, headers: Headers): void;
24
+ /**
25
+ * Tells the sign-in the server answered 401 to the tokens this hop placed.
26
+ * It counts a value only while it is the sign-in's current token and decides
27
+ * about refreshing; the kit never resends the request.
28
+ */
29
+ export declare function reportRejected(tokens: SignInTokens | undefined, placed: ReadonlyMap<string, string>): void;
@@ -0,0 +1,92 @@
1
+ import { SignInNeededError } from "../../../core/ports/src/index.js";
2
+ import { IntegrationRefusedError } from "@halonicjs/adapters/integration-kit";
3
+ import { hostIn } from "./policy.js";
4
+ import { checkSecretLength, describe, matchesSheet, quoted } from "./secret-placement.js";
5
+ /** The sheet's entry for a sign-in, looked up by own key only, so `toString` is never a sign-in. */
6
+ function declaredSignIn(policy, signIn) {
7
+ return Object.hasOwn(policy.signIns, signIn) ? policy.signIns[signIn] : undefined;
8
+ }
9
+ /**
10
+ * Checks that the sign-in is declared and that the code places its token the
11
+ * way the sheet's `access` block says, with the same check as a secret's
12
+ * placement (`placement-not-in-sheet`). Runs before any token is asked for.
13
+ */
14
+ export function checkSignInPlacement(policy, placement) {
15
+ const declared = declaredSignIn(policy, placement.signIn);
16
+ if (declared === undefined) {
17
+ throw new IntegrationRefusedError("sign-in-not-declared", `${policy.name}: the sign-in ${quoted(placement.signIn)} is not in its permission sheet`);
18
+ }
19
+ if (!matchesSheet(placement, declared)) {
20
+ throw new IntegrationRefusedError("placement-not-in-sheet", `${policy.name}: the token of the sign-in ${quoted(placement.signIn)} goes ${describe(declared)} in its permission sheet, not ${describe(placement)}`);
21
+ }
22
+ }
23
+ /**
24
+ * Checks that the token may go to the request's first host. Unlike a
25
+ * secret, a token never goes over plain `http`, not even to this machine.
26
+ */
27
+ export function checkSignInPlacementHost(policy, placement, url) {
28
+ const declared = declaredSignIn(policy, placement.signIn);
29
+ if (declared === undefined || !hostIn(declared.hosts, url)) {
30
+ throw new IntegrationRefusedError("token-not-allowed-for-host", `${policy.name}: the token of the sign-in ${quoted(placement.signIn)} may not go to ${url.host}`);
31
+ }
32
+ if (!mayCarryToken(url)) {
33
+ throw new IntegrationRefusedError("token-over-plain-http", `${policy.name}: the token of the sign-in ${quoted(placement.signIn)} may not go over plain http (${url.host})`);
34
+ }
35
+ }
36
+ /** A token goes over `https` only. */
37
+ function mayCarryToken(url) {
38
+ return url.protocol === "https:";
39
+ }
40
+ /** Whether this hop may carry the token of the sign-in. */
41
+ function mayGoTo(policy, signIn, url) {
42
+ const declared = declaredSignIn(policy, signIn);
43
+ return declared !== undefined && hostIn(declared.hosts, url) && mayCarryToken(url);
44
+ }
45
+ /**
46
+ * The access tokens this hop will carry, one per sign-in whose token may go
47
+ * to the hop's host. A sign-in that may not go there is not asked for, so a
48
+ * redirect to another declared host neither refreshes nor places its token.
49
+ *
50
+ * @throws {IntegrationRefusedError} `sign-in-needed` when the user has to sign in (again), or when no sign-ins are set up at all
51
+ */
52
+ export async function readTokens(policy, tokens, placements, url, signal) {
53
+ const values = new Map();
54
+ for (const { signIn } of placements) {
55
+ if (values.has(signIn) || !mayGoTo(policy, signIn, url))
56
+ continue;
57
+ const value = await accessToken(policy, tokens, signIn, signal);
58
+ checkSecretLength(policy.name, `sign-in ${signIn}`, value);
59
+ values.set(signIn, value);
60
+ }
61
+ return values;
62
+ }
63
+ async function accessToken(policy, tokens, signIn, signal) {
64
+ try {
65
+ if (tokens === undefined)
66
+ throw new SignInNeededError(signIn);
67
+ return await tokens.access(signIn, signal);
68
+ }
69
+ catch (error) {
70
+ if (!(error instanceof SignInNeededError))
71
+ throw error;
72
+ throw new IntegrationRefusedError("sign-in-needed", `${policy.name}: the sign-in ${quoted(signIn)} needs you to sign in again`);
73
+ }
74
+ }
75
+ /** Puts the token into the headers, when this hop was asked for it. */
76
+ export function placeToken(placement, value, headers) {
77
+ if (value === undefined)
78
+ return;
79
+ if (placement.as === "bearer")
80
+ headers.set("authorization", `Bearer ${value}`);
81
+ else
82
+ headers.set(placement.header, `${placement.prefix ?? ""}${value}`);
83
+ }
84
+ /**
85
+ * Tells the sign-in the server answered 401 to the tokens this hop placed.
86
+ * It counts a value only while it is the sign-in's current token and decides
87
+ * about refreshing; the kit never resends the request.
88
+ */
89
+ export function reportRejected(tokens, placed) {
90
+ for (const [signIn, value] of placed)
91
+ tokens?.rejected(signIn, value);
92
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * The milliseconds the host really waits for `ms`: `NaN` and negative values
3
+ * wait 0, anything above {@link maxIntegrationWaitMs} (`Infinity` too) waits
4
+ * the maximum.
5
+ */
6
+ export declare function clampWaitMs(ms: number): number;
7
+ /**
8
+ * `IntegrationHost.wait`: waits the clamped `ms`, and rejects with
9
+ * `signal.reason` as soon as `signal` aborts, or straight away when it
10
+ * already has. The timer and the abort listener are always cleared, so a
11
+ * wait never outlives its call.
12
+ *
13
+ * @example
14
+ * await integrationWait(retryMs, signal);
15
+ */
16
+ export declare function integrationWait(ms: number, signal?: AbortSignal): Promise<void>;
@@ -0,0 +1,35 @@
1
+ import { maxIntegrationWaitMs } from "../../../core/ports/src/index.js";
2
+ /**
3
+ * The milliseconds the host really waits for `ms`: `NaN` and negative values
4
+ * wait 0, anything above {@link maxIntegrationWaitMs} (`Infinity` too) waits
5
+ * the maximum.
6
+ */
7
+ export function clampWaitMs(ms) {
8
+ if (Number.isNaN(ms) || ms <= 0)
9
+ return 0;
10
+ return Math.min(ms, maxIntegrationWaitMs);
11
+ }
12
+ /**
13
+ * `IntegrationHost.wait`: waits the clamped `ms`, and rejects with
14
+ * `signal.reason` as soon as `signal` aborts, or straight away when it
15
+ * already has. The timer and the abort listener are always cleared, so a
16
+ * wait never outlives its call.
17
+ *
18
+ * @example
19
+ * await integrationWait(retryMs, signal);
20
+ */
21
+ export function integrationWait(ms, signal) {
22
+ if (signal?.aborted)
23
+ return Promise.reject(signal.reason);
24
+ return new Promise((resolve, reject) => {
25
+ const onAbort = () => {
26
+ clearTimeout(timer);
27
+ reject(signal?.reason);
28
+ };
29
+ const timer = setTimeout(() => {
30
+ signal?.removeEventListener("abort", onAbort);
31
+ resolve();
32
+ }, clampWaitMs(ms));
33
+ signal?.addEventListener("abort", onAbort, { once: true });
34
+ });
35
+ }
@@ -0,0 +1,10 @@
1
+ import type { Usage } from "./run-basics.js";
2
+ /**
3
+ * The tokens of two model calls together. A cache count is in the sum only
4
+ * when one of them has it, so calls without a prompt cache keep their old shape.
5
+ *
6
+ * @example
7
+ * addUsage({ inputTokens: 10, outputTokens: 5 }, { inputTokens: 2, outputTokens: 1, cacheReadTokens: 900 });
8
+ * // { inputTokens: 12, outputTokens: 6, cacheReadTokens: 900 }
9
+ */
10
+ export declare function addUsage(total: Usage, more: Usage): Usage;
@@ -0,0 +1,27 @@
1
+ /** The optional token counts of a call that used a prompt cache. */
2
+ const cacheCounts = ["cacheReadTokens", "cacheWriteTokens", "cacheWrite1hTokens"];
3
+ /**
4
+ * The tokens of two model calls together. A cache count is in the sum only
5
+ * when one of them has it, so calls without a prompt cache keep their old shape.
6
+ *
7
+ * @example
8
+ * addUsage({ inputTokens: 10, outputTokens: 5 }, { inputTokens: 2, outputTokens: 1, cacheReadTokens: 900 });
9
+ * // { inputTokens: 12, outputTokens: 6, cacheReadTokens: 900 }
10
+ */
11
+ export function addUsage(total, more) {
12
+ const sum = {
13
+ inputTokens: total.inputTokens + more.inputTokens,
14
+ outputTokens: total.outputTokens + more.outputTokens,
15
+ };
16
+ for (const count of cacheCounts) {
17
+ const added = addOptional(total[count], more[count]);
18
+ if (added !== undefined)
19
+ sum[count] = added;
20
+ }
21
+ return sum;
22
+ }
23
+ function addOptional(left, right) {
24
+ if (left === undefined && right === undefined)
25
+ return undefined;
26
+ return (left ?? 0) + (right ?? 0);
27
+ }
@@ -0,0 +1,24 @@
1
+ /** A model tool call as stored in the log. */
2
+ export interface LoggedToolCall {
3
+ id: string;
4
+ name: string;
5
+ arguments: Record<string, unknown>;
6
+ }
7
+ /** Where an agent stopped to wait for an approval, so it can continue after a restart. */
8
+ export interface AgentResume {
9
+ /** The conversation so far (chat messages, including the assistant's tool calls). */
10
+ messages: unknown[];
11
+ /** Tool calls of the current model reply still to handle, the one waiting for approval first. */
12
+ calls: LoggedToolCall[];
13
+ /** Model step the agent was on. */
14
+ step: number;
15
+ /**
16
+ * Set when `calls[0]` is a `delegate_*` call whose subagent stopped: the
17
+ * subagent, and where its own turn goes on from, nested at most 3 deep
18
+ * (requirement `events.agent-resume-inner`). Absent in older logs.
19
+ */
20
+ inner?: {
21
+ agent: string;
22
+ resume: AgentResume;
23
+ };
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,57 @@
1
+ import type { RunEvent } from "./run-event.js";
2
+ /** One site a step's sandbox refused, with how many times it was tried. */
3
+ export interface BlockedSite {
4
+ /** The host, `A`–`Z` lowercased and without a trailing dot. Show it with `siteName` from std. */
5
+ readonly host: string;
6
+ /** The refused connections to it in the step, all ports together. */
7
+ readonly tries: number;
8
+ }
9
+ /** The blocked sites of one visit of a step. */
10
+ export interface StepBlockedSites {
11
+ readonly state: string;
12
+ readonly agent: string;
13
+ /** Set for a step in one branch of a parallel state. */
14
+ readonly branch?: string;
15
+ /** Set for a step in one item of a for-each state. */
16
+ readonly item?: number;
17
+ /** The `seq` of the step's first blocked site: where the run log view shows the line. */
18
+ readonly firstSeq: number;
19
+ /** The sites to show, most tries first, then A to Z, at most the `limit` asked for. */
20
+ readonly sites: readonly BlockedSite[];
21
+ /** How many more sites were blocked than `sites` shows. */
22
+ readonly moreSites: number;
23
+ /** The tries of those further sites together. */
24
+ readonly moreTries: number;
25
+ /**
26
+ * Refused accesses past the targets the log names (`others`), files and
27
+ * sites together, which the log doesn't tell apart. 0 when there are none.
28
+ */
29
+ readonly otherBlocks: number;
30
+ }
31
+ /** How many sites {@link blockedSites} lists per step. */
32
+ export interface BlockedSitesOptions {
33
+ /**
34
+ * 5 for a step's entry on the run page, 20 for the run log view
35
+ * (sandbox-screens 2.2). A whole number, 0 or more.
36
+ */
37
+ readonly limit: number;
38
+ }
39
+ /**
40
+ * Names each site a step's sandbox refused once, with its tries
41
+ * (requirement `events.blocked-sites`). A step is one visit of a state: a
42
+ * new `state.entered` starts a new one. A `sandbox.blocked` event's `count`
43
+ * is a running total, so the latest one for a site and port counts, and
44
+ * the ports of one site add up. Blocked files aren't sites and are left
45
+ * out; a step with no blocked site isn't listed.
46
+ *
47
+ * @param events - one run's log, in `seq` order
48
+ * @param options - how many sites to list per step
49
+ * @returns the steps with blocked sites, in the order of their first one
50
+ * @throws RangeError when `limit` isn't a whole number, 0 or more
51
+ *
52
+ * @example
53
+ * blockedSites(events, { limit: 5 });
54
+ * // => [{ state: "install", agent: "writer", firstSeq: 12, sites: [{ host: "registry.npmjs.org", tries: 12 }],
55
+ * // moreSites: 0, moreTries: 0, otherBlocks: 0 }]
56
+ */
57
+ export declare function blockedSites(events: readonly RunEvent[], options: BlockedSitesOptions): StepBlockedSites[];
@@ -0,0 +1,89 @@
1
+ // The sites each step's sandbox refused, worked out from a run's
2
+ // `sandbox.blocked` events, so the run page and the run log view can name
3
+ // each site once with its tries (HAL-1708), not once per retry. Data only:
4
+ // the words come from the message catalogue.
5
+ /**
6
+ * Names each site a step's sandbox refused once, with its tries
7
+ * (requirement `events.blocked-sites`). A step is one visit of a state: a
8
+ * new `state.entered` starts a new one. A `sandbox.blocked` event's `count`
9
+ * is a running total, so the latest one for a site and port counts, and
10
+ * the ports of one site add up. Blocked files aren't sites and are left
11
+ * out; a step with no blocked site isn't listed.
12
+ *
13
+ * @param events - one run's log, in `seq` order
14
+ * @param options - how many sites to list per step
15
+ * @returns the steps with blocked sites, in the order of their first one
16
+ * @throws RangeError when `limit` isn't a whole number, 0 or more
17
+ *
18
+ * @example
19
+ * blockedSites(events, { limit: 5 });
20
+ * // => [{ state: "install", agent: "writer", firstSeq: 12, sites: [{ host: "registry.npmjs.org", tries: 12 }],
21
+ * // moreSites: 0, moreTries: 0, otherBlocks: 0 }]
22
+ */
23
+ export function blockedSites(events, options) {
24
+ if (!Number.isInteger(options.limit) || options.limit < 0) {
25
+ throw new RangeError(`blockedSites: limit must be a whole number, 0 or more, not ${options.limit}`);
26
+ }
27
+ const visits = new Map();
28
+ const tallies = new Map();
29
+ const others = new Map();
30
+ for (const event of events) {
31
+ if (event.type === "state.entered")
32
+ visits.set(event.state, event.seq);
33
+ if (event.type !== "sandbox.blocked" || event.block.kind === "file")
34
+ continue;
35
+ const key = JSON.stringify([event.state, event.branch, event.item, visits.get(event.state)]);
36
+ if (event.block.kind === "others") {
37
+ others.set(key, event.count);
38
+ continue;
39
+ }
40
+ const tally = tallies.get(key) ?? newTally(event);
41
+ tallies.set(key, tally);
42
+ const host = plainHost(event.block.host);
43
+ tally.counts.set(JSON.stringify([host, event.block.port]), { host, count: event.count });
44
+ }
45
+ return [...tallies].map(([key, tally]) => summary(tally, others.get(key) ?? 0, options.limit));
46
+ }
47
+ function newTally(event) {
48
+ const step = {
49
+ state: event.state,
50
+ agent: event.agent,
51
+ ...(event.branch === undefined ? {} : { branch: event.branch }),
52
+ ...(event.item === undefined ? {} : { item: event.item }),
53
+ firstSeq: event.seq,
54
+ };
55
+ return { step, counts: new Map() };
56
+ }
57
+ /**
58
+ * One host however the sandbox wrote it: `API.Example.com.` is
59
+ * `api.example.com`. Only `A`–`Z` are lowercased, as `siteName` does:
60
+ * Unicode lowercasing turns the Kelvin sign (U+212A) into a plain `k`, so a
61
+ * look-alike would pass for the real name.
62
+ */
63
+ function plainHost(host) {
64
+ const lower = host.replace(/[A-Z]/g, (letter) => letter.toLowerCase());
65
+ return lower.endsWith(".") ? lower.slice(0, -1) : lower;
66
+ }
67
+ function summary(tally, otherBlocks, limit) {
68
+ const triesByHost = new Map();
69
+ for (const { host, count } of tally.counts.values()) {
70
+ triesByHost.set(host, (triesByHost.get(host) ?? 0) + count);
71
+ }
72
+ const sites = [...triesByHost].map(([host, tries]) => ({ host, tries })).sort(mostTriesFirst);
73
+ const more = sites.slice(limit);
74
+ return {
75
+ ...tally.step,
76
+ sites: sites.slice(0, limit),
77
+ moreSites: more.length,
78
+ moreTries: more.reduce((total, site) => total + site.tries, 0),
79
+ otherBlocks,
80
+ };
81
+ }
82
+ /** Most tries first, then A to Z by code point, the same on every computer. */
83
+ function mostTriesFirst(first, second) {
84
+ if (first.tries !== second.tries)
85
+ return second.tries - first.tries;
86
+ if (first.host === second.host)
87
+ return 0;
88
+ return first.host < second.host ? -1 : 1;
89
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * `path` with the person's home folder written as `~`, or `path` as it is
3
+ * when it is outside the home folder or the home folder is unknown. A folder
4
+ * next to the home folder whose name starts the same stays as it is.
5
+ *
6
+ * @param path - an absolute path
7
+ * @param home - the person's home folder, or `null` when it is unknown
8
+ * @returns the path to log
9
+ *
10
+ * @example
11
+ * shortenHome("<home>/work", "<home>"); // => "~/work"
12
+ */
13
+ export declare function shortenHome(path: string, home: string | null): string;
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `path` with the person's home folder written as `~`, or `path` as it is
3
+ * when it is outside the home folder or the home folder is unknown. A folder
4
+ * next to the home folder whose name starts the same stays as it is.
5
+ *
6
+ * @param path - an absolute path
7
+ * @param home - the person's home folder, or `null` when it is unknown
8
+ * @returns the path to log
9
+ *
10
+ * @example
11
+ * shortenHome("<home>/work", "<home>"); // => "~/work"
12
+ */
13
+ export function shortenHome(path, home) {
14
+ if (home === null)
15
+ return path;
16
+ const root = home.replace(/[/\\]+$/, "");
17
+ if (root === "")
18
+ return path;
19
+ if (path === root)
20
+ return "~";
21
+ const separator = path.charAt(root.length);
22
+ if (path.startsWith(root) && (separator === "/" || separator === "\\")) {
23
+ return `~${path.slice(root.length)}`;
24
+ }
25
+ return path;
26
+ }
@@ -0,0 +1,17 @@
1
+ export { addUsage } from "./add-usage.js";
2
+ export type { AgentResume, LoggedToolCall } from "./agent-resume.js";
3
+ export { type BlockedSite, type BlockedSitesOptions, blockedSites, type StepBlockedSites, } from "./blocked-sites.js";
4
+ export type { ApprovalResolver, CantTryReason, CantTryStep, LeftOutReason, ModelSkipReason, ProviderText, RunCatchUp, RunFailureReason, RunKind, RunParent, RunStatus, RunTrigger, RunVersion, StoredBlob, ToolNoun, ToolOutcome, ToolRefusalReason, ToolRisk, ToolUnaskedReason, ToolVerb, Usage, } from "./run-basics.js";
5
+ export type { RunEvent, RunEventBase, RunEventBody, RunEventType } from "./run-event.js";
6
+ export { draftsOf, readsOf } from "./run-reads.js";
7
+ export type { RunSends, SendCount, SendGroup } from "./run-sends.js";
8
+ export { sendsOf } from "./run-sends.js";
9
+ export type { PendingApproval, RunSummary, SentSignal } from "./run-summary.js";
10
+ export type { LoggedSandboxBlock, SandboxBlock } from "./sandbox-blocked.js";
11
+ export { maxBlockedTargetsPerStep, sandboxBlockedView } from "./sandbox-blocked.js";
12
+ export type { DeniedPathGroup, DeniedPathGroupCode, SandboxOpenedOptions, SandboxOpenedView, SandboxStrength, ShownSandboxProfile, } from "./sandbox-opened.js";
13
+ export { deniedPathGroupCodes, sandboxOpenedView } from "./sandbox-opened.js";
14
+ export { readSandboxOpened } from "./sandbox-opened-read.js";
15
+ export { summarize } from "./summarize.js";
16
+ export { entryOf } from "./timeline-entry.js";
17
+ export { parseEventLine, upgradeEvent } from "./upgrade.js";
@@ -0,0 +1,10 @@
1
+ export { addUsage } from "./add-usage.js";
2
+ export { blockedSites, } from "./blocked-sites.js";
3
+ export { draftsOf, readsOf } from "./run-reads.js";
4
+ export { sendsOf } from "./run-sends.js";
5
+ export { maxBlockedTargetsPerStep, sandboxBlockedView } from "./sandbox-blocked.js";
6
+ export { deniedPathGroupCodes, sandboxOpenedView } from "./sandbox-opened.js";
7
+ export { readSandboxOpened } from "./sandbox-opened-read.js";
8
+ export { summarize } from "./summarize.js";
9
+ export { entryOf } from "./timeline-entry.js";
10
+ export { parseEventLine, upgradeEvent } from "./upgrade.js";