clinkx 0.3.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (555) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/LICENSE +10 -0
  3. package/README.md +82 -26
  4. package/clinkx-workflows/dist/allowed-roots.d.ts +1 -0
  5. package/clinkx-workflows/dist/allowed-roots.js +5 -0
  6. package/clinkx-workflows/dist/allowed-roots.js.map +1 -0
  7. package/clinkx-workflows/dist/artifacts.d.ts +20 -1
  8. package/clinkx-workflows/dist/artifacts.js +38 -9
  9. package/clinkx-workflows/dist/artifacts.js.map +1 -1
  10. package/clinkx-workflows/dist/backend.d.ts +4 -0
  11. package/clinkx-workflows/dist/citation-check.d.ts +40 -0
  12. package/clinkx-workflows/dist/citation-check.js +348 -0
  13. package/clinkx-workflows/dist/citation-check.js.map +1 -0
  14. package/clinkx-workflows/dist/clink-client.d.ts +2 -1
  15. package/clinkx-workflows/dist/clink-client.js +17 -4
  16. package/clinkx-workflows/dist/clink-client.js.map +1 -1
  17. package/clinkx-workflows/dist/config.d.ts +145 -16
  18. package/clinkx-workflows/dist/config.js +384 -26
  19. package/clinkx-workflows/dist/config.js.map +1 -1
  20. package/clinkx-workflows/dist/contained-file.d.ts +172 -0
  21. package/clinkx-workflows/dist/contained-file.js +483 -0
  22. package/clinkx-workflows/dist/contained-file.js.map +1 -0
  23. package/clinkx-workflows/dist/context-builder-lifecycle-contract.d.ts +416 -0
  24. package/clinkx-workflows/dist/context-builder-lifecycle-contract.js +328 -0
  25. package/clinkx-workflows/dist/context-builder-lifecycle-contract.js.map +1 -0
  26. package/clinkx-workflows/dist/context-builder-lifecycle-router.d.ts +24 -0
  27. package/clinkx-workflows/dist/context-builder-lifecycle-router.js +39 -0
  28. package/clinkx-workflows/dist/context-builder-lifecycle-router.js.map +1 -0
  29. package/clinkx-workflows/dist/context-cache-key.d.ts +53 -0
  30. package/clinkx-workflows/dist/context-cache-key.js +91 -0
  31. package/clinkx-workflows/dist/context-cache-key.js.map +1 -0
  32. package/clinkx-workflows/dist/context-mode-resolver.d.ts +27 -0
  33. package/clinkx-workflows/dist/context-mode-resolver.js +126 -0
  34. package/clinkx-workflows/dist/context-mode-resolver.js.map +1 -0
  35. package/clinkx-workflows/dist/context-preflight.d.ts +184 -0
  36. package/clinkx-workflows/dist/context-preflight.js +91 -0
  37. package/clinkx-workflows/dist/context-preflight.js.map +1 -0
  38. package/clinkx-workflows/dist/council-expander.d.ts +1 -1
  39. package/clinkx-workflows/dist/council-expander.js +2 -1
  40. package/clinkx-workflows/dist/council-expander.js.map +1 -1
  41. package/clinkx-workflows/dist/dashboard/activity-contract.d.ts +165 -0
  42. package/clinkx-workflows/dist/dashboard/activity-contract.js +105 -0
  43. package/clinkx-workflows/dist/dashboard/activity-contract.js.map +1 -0
  44. package/clinkx-workflows/dist/dashboard/activity-lease.d.ts +25 -0
  45. package/clinkx-workflows/dist/dashboard/activity-lease.js +34 -0
  46. package/clinkx-workflows/dist/dashboard/activity-lease.js.map +1 -0
  47. package/clinkx-workflows/dist/dashboard/activity-reader.d.ts +86 -0
  48. package/clinkx-workflows/dist/dashboard/activity-reader.js +480 -0
  49. package/clinkx-workflows/dist/dashboard/activity-reader.js.map +1 -0
  50. package/clinkx-workflows/dist/dashboard/api-routes.d.ts +36 -0
  51. package/clinkx-workflows/dist/dashboard/api-routes.js +1047 -0
  52. package/clinkx-workflows/dist/dashboard/api-routes.js.map +1 -0
  53. package/clinkx-workflows/dist/dashboard/artifact-index.d.ts +37 -0
  54. package/clinkx-workflows/dist/dashboard/artifact-index.js +145 -0
  55. package/clinkx-workflows/dist/dashboard/artifact-index.js.map +1 -0
  56. package/clinkx-workflows/dist/dashboard/auth/challenge-store.d.ts +31 -0
  57. package/clinkx-workflows/dist/dashboard/auth/challenge-store.js +65 -0
  58. package/clinkx-workflows/dist/dashboard/auth/challenge-store.js.map +1 -0
  59. package/clinkx-workflows/dist/dashboard/auth/controller.d.ts +26 -0
  60. package/clinkx-workflows/dist/dashboard/auth/controller.js +596 -0
  61. package/clinkx-workflows/dist/dashboard/auth/controller.js.map +1 -0
  62. package/clinkx-workflows/dist/dashboard/auth/credential-store.d.ts +60 -0
  63. package/clinkx-workflows/dist/dashboard/auth/credential-store.js +776 -0
  64. package/clinkx-workflows/dist/dashboard/auth/credential-store.js.map +1 -0
  65. package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.d.ts +9 -0
  66. package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.js +44 -0
  67. package/clinkx-workflows/dist/dashboard/auth/enrollment-gate.js.map +1 -0
  68. package/clinkx-workflows/dist/dashboard/auth/session-store.d.ts +17 -0
  69. package/clinkx-workflows/dist/dashboard/auth/session-store.js +77 -0
  70. package/clinkx-workflows/dist/dashboard/auth/session-store.js.map +1 -0
  71. package/clinkx-workflows/dist/dashboard/auth/webauthn-service.d.ts +25 -0
  72. package/clinkx-workflows/dist/dashboard/auth/webauthn-service.js +71 -0
  73. package/clinkx-workflows/dist/dashboard/auth/webauthn-service.js.map +1 -0
  74. package/clinkx-workflows/dist/dashboard/context-run-liveness.d.ts +37 -0
  75. package/clinkx-workflows/dist/dashboard/context-run-liveness.js +49 -0
  76. package/clinkx-workflows/dist/dashboard/context-run-liveness.js.map +1 -0
  77. package/clinkx-workflows/dist/dashboard/context-run-reader.d.ts +222 -0
  78. package/clinkx-workflows/dist/dashboard/context-run-reader.js +1178 -0
  79. package/clinkx-workflows/dist/dashboard/context-run-reader.js.map +1 -0
  80. package/clinkx-workflows/dist/dashboard/contracts.d.ts +8936 -0
  81. package/clinkx-workflows/dist/dashboard/contracts.js +1157 -0
  82. package/clinkx-workflows/dist/dashboard/contracts.js.map +1 -0
  83. package/clinkx-workflows/dist/dashboard/generation.d.ts +14 -0
  84. package/clinkx-workflows/dist/dashboard/generation.js +41 -0
  85. package/clinkx-workflows/dist/dashboard/generation.js.map +1 -0
  86. package/clinkx-workflows/dist/dashboard/index.d.ts +28 -0
  87. package/clinkx-workflows/dist/dashboard/index.js +16 -0
  88. package/clinkx-workflows/dist/dashboard/index.js.map +1 -0
  89. package/clinkx-workflows/dist/dashboard/lazy-content.d.ts +101 -0
  90. package/clinkx-workflows/dist/dashboard/lazy-content.js +748 -0
  91. package/clinkx-workflows/dist/dashboard/lazy-content.js.map +1 -0
  92. package/clinkx-workflows/dist/dashboard/progress-report-contract.d.ts +303 -0
  93. package/clinkx-workflows/dist/dashboard/progress-report-contract.js +221 -0
  94. package/clinkx-workflows/dist/dashboard/progress-report-contract.js.map +1 -0
  95. package/clinkx-workflows/dist/dashboard/progress-report-reader.d.ts +50 -0
  96. package/clinkx-workflows/dist/dashboard/progress-report-reader.js +581 -0
  97. package/clinkx-workflows/dist/dashboard/progress-report-reader.js.map +1 -0
  98. package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.d.ts +89 -0
  99. package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.js +71 -0
  100. package/clinkx-workflows/dist/dashboard/progress-report-status-overlay.js.map +1 -0
  101. package/clinkx-workflows/dist/dashboard/progress-report-status-store.d.ts +28 -0
  102. package/clinkx-workflows/dist/dashboard/progress-report-status-store.js +110 -0
  103. package/clinkx-workflows/dist/dashboard/progress-report-status-store.js.map +1 -0
  104. package/clinkx-workflows/dist/dashboard/read-model.d.ts +86 -0
  105. package/clinkx-workflows/dist/dashboard/read-model.js +440 -0
  106. package/clinkx-workflows/dist/dashboard/read-model.js.map +1 -0
  107. package/clinkx-workflows/dist/dashboard/request-admission.d.ts +31 -0
  108. package/clinkx-workflows/dist/dashboard/request-admission.js +126 -0
  109. package/clinkx-workflows/dist/dashboard/request-admission.js.map +1 -0
  110. package/clinkx-workflows/dist/dashboard/scanner.d.ts +75 -0
  111. package/clinkx-workflows/dist/dashboard/scanner.js +1110 -0
  112. package/clinkx-workflows/dist/dashboard/scanner.js.map +1 -0
  113. package/clinkx-workflows/dist/dashboard/server-factory.d.ts +50 -0
  114. package/clinkx-workflows/dist/dashboard/server-factory.js +431 -0
  115. package/clinkx-workflows/dist/dashboard/server-factory.js.map +1 -0
  116. package/clinkx-workflows/dist/dashboard/session-log-contract.d.ts +2611 -0
  117. package/clinkx-workflows/dist/dashboard/session-log-contract.js +480 -0
  118. package/clinkx-workflows/dist/dashboard/session-log-contract.js.map +1 -0
  119. package/clinkx-workflows/dist/dashboard/session-log-identity.d.ts +21 -0
  120. package/clinkx-workflows/dist/dashboard/session-log-identity.js +101 -0
  121. package/clinkx-workflows/dist/dashboard/session-log-identity.js.map +1 -0
  122. package/clinkx-workflows/dist/dashboard/session-log-journal.d.ts +43 -0
  123. package/clinkx-workflows/dist/dashboard/session-log-journal.js +522 -0
  124. package/clinkx-workflows/dist/dashboard/session-log-journal.js.map +1 -0
  125. package/clinkx-workflows/dist/dashboard/session-log-reader.d.ts +61 -0
  126. package/clinkx-workflows/dist/dashboard/session-log-reader.js +378 -0
  127. package/clinkx-workflows/dist/dashboard/session-log-reader.js.map +1 -0
  128. package/clinkx-workflows/dist/dashboard/session-log-redaction.d.ts +6 -0
  129. package/clinkx-workflows/dist/dashboard/session-log-redaction.js +367 -0
  130. package/clinkx-workflows/dist/dashboard/session-log-redaction.js.map +1 -0
  131. package/clinkx-workflows/dist/dashboard/session-log-retention.d.ts +23 -0
  132. package/clinkx-workflows/dist/dashboard/session-log-retention.js +212 -0
  133. package/clinkx-workflows/dist/dashboard/session-log-retention.js.map +1 -0
  134. package/clinkx-workflows/dist/dashboard/static-responses.d.ts +10 -0
  135. package/clinkx-workflows/dist/dashboard/static-responses.js +94 -0
  136. package/clinkx-workflows/dist/dashboard/static-responses.js.map +1 -0
  137. package/clinkx-workflows/dist/dashboard/worker-lock-observer.d.ts +28 -0
  138. package/clinkx-workflows/dist/dashboard/worker-lock-observer.js +241 -0
  139. package/clinkx-workflows/dist/dashboard/worker-lock-observer.js.map +1 -0
  140. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-400-normal-CvHOgSBP.woff +0 -0
  141. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-400-normal-DMJ8VG8y.woff2 +0 -0
  142. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-500-normal-CB9ihrfo.woff +0 -0
  143. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-mono-latin-500-normal-DSY6xOcd.woff2 +0 -0
  144. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-400-normal-CDDApCn2.woff2 +0 -0
  145. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-400-normal-CYLoc0-x.woff +0 -0
  146. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-500-normal-6ng42L7E.woff2 +0 -0
  147. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-500-normal-BgVn5rGT.woff +0 -0
  148. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-600-normal-Cu4Hd6ag.woff +0 -0
  149. package/clinkx-workflows/dist/dashboard-ui/assets/ibm-plex-sans-latin-600-normal-CuJfVYMP.woff2 +0 -0
  150. package/clinkx-workflows/dist/dashboard-ui/assets/index-DOkMXTfB.js +25 -0
  151. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
  152. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
  153. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
  154. package/clinkx-workflows/dist/dashboard-ui/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
  155. package/clinkx-workflows/dist/dashboard-ui/assets/style-ChJsn0KD.css +1 -0
  156. package/clinkx-workflows/dist/dashboard-ui/contracts/council-plan-review-input-v1.json +158 -0
  157. package/clinkx-workflows/dist/dashboard-ui/index.html +15 -0
  158. package/clinkx-workflows/dist/dashboard-ui/licenses/IBM-Plex-Mono-OFL.txt +93 -0
  159. package/clinkx-workflows/dist/dashboard-ui/licenses/IBM-Plex-Sans-OFL.txt +93 -0
  160. package/clinkx-workflows/dist/dashboard-ui/licenses/JetBrains-Mono-OFL.txt +93 -0
  161. package/clinkx-workflows/dist/dashboard-ui/licenses/NOTICE.md +32 -0
  162. package/clinkx-workflows/dist/dashboard-ui/theme-init.js +8 -0
  163. package/clinkx-workflows/dist/definition-normalizer.d.ts +19 -0
  164. package/clinkx-workflows/dist/definition-normalizer.js.map +1 -1
  165. package/clinkx-workflows/dist/delegate-validate.d.ts +78 -0
  166. package/clinkx-workflows/dist/delegate-validate.js +97 -0
  167. package/clinkx-workflows/dist/delegate-validate.js.map +1 -0
  168. package/clinkx-workflows/dist/engine.d.ts +141 -0
  169. package/clinkx-workflows/dist/engine.js +882 -28
  170. package/clinkx-workflows/dist/engine.js.map +1 -1
  171. package/clinkx-workflows/dist/errors.d.ts +2 -0
  172. package/clinkx-workflows/dist/errors.js.map +1 -1
  173. package/clinkx-workflows/dist/fingerprint.d.ts +1 -1
  174. package/clinkx-workflows/dist/fingerprint.js +1 -1
  175. package/clinkx-workflows/dist/index.d.ts +19 -0
  176. package/clinkx-workflows/dist/index.js +15 -0
  177. package/clinkx-workflows/dist/index.js.map +1 -1
  178. package/clinkx-workflows/dist/loader.d.ts +9 -3
  179. package/clinkx-workflows/dist/loader.js +92 -21
  180. package/clinkx-workflows/dist/loader.js.map +1 -1
  181. package/clinkx-workflows/dist/plan-review/admission.d.ts +160 -0
  182. package/clinkx-workflows/dist/plan-review/admission.js +290 -0
  183. package/clinkx-workflows/dist/plan-review/admission.js.map +1 -0
  184. package/clinkx-workflows/dist/plan-review/context-policy.d.ts +55 -0
  185. package/clinkx-workflows/dist/plan-review/context-policy.js +146 -0
  186. package/clinkx-workflows/dist/plan-review/context-policy.js.map +1 -0
  187. package/clinkx-workflows/dist/plan-review/contract.d.ts +763 -0
  188. package/clinkx-workflows/dist/plan-review/contract.js +289 -0
  189. package/clinkx-workflows/dist/plan-review/contract.js.map +1 -0
  190. package/clinkx-workflows/dist/plan-review/digest.d.ts +68 -0
  191. package/clinkx-workflows/dist/plan-review/digest.js +241 -0
  192. package/clinkx-workflows/dist/plan-review/digest.js.map +1 -0
  193. package/clinkx-workflows/dist/plan-review/discovery.d.ts +45 -0
  194. package/clinkx-workflows/dist/plan-review/discovery.js +36 -0
  195. package/clinkx-workflows/dist/plan-review/discovery.js.map +1 -0
  196. package/clinkx-workflows/dist/plan-review/execution-contract.d.ts +298 -0
  197. package/clinkx-workflows/dist/plan-review/execution-contract.js +194 -0
  198. package/clinkx-workflows/dist/plan-review/execution-contract.js.map +1 -0
  199. package/clinkx-workflows/dist/plan-review/expander.d.ts +48 -0
  200. package/clinkx-workflows/dist/plan-review/expander.js +243 -0
  201. package/clinkx-workflows/dist/plan-review/expander.js.map +1 -0
  202. package/clinkx-workflows/dist/plan-review/projector.d.ts +126 -0
  203. package/clinkx-workflows/dist/plan-review/projector.js +437 -0
  204. package/clinkx-workflows/dist/plan-review/projector.js.map +1 -0
  205. package/clinkx-workflows/dist/plan-review/publication.d.ts +95 -0
  206. package/clinkx-workflows/dist/plan-review/publication.js +182 -0
  207. package/clinkx-workflows/dist/plan-review/publication.js.map +1 -0
  208. package/clinkx-workflows/dist/plan-review/ranking-reducer.d.ts +34 -0
  209. package/clinkx-workflows/dist/plan-review/ranking-reducer.js +139 -0
  210. package/clinkx-workflows/dist/plan-review/ranking-reducer.js.map +1 -0
  211. package/clinkx-workflows/dist/plan-review/resume.d.ts +38 -0
  212. package/clinkx-workflows/dist/plan-review/resume.js +122 -0
  213. package/clinkx-workflows/dist/plan-review/resume.js.map +1 -0
  214. package/clinkx-workflows/dist/plan-review/rubric.d.ts +7 -0
  215. package/clinkx-workflows/dist/plan-review/rubric.js +24 -0
  216. package/clinkx-workflows/dist/plan-review/rubric.js.map +1 -0
  217. package/clinkx-workflows/dist/plan-review/run-state.d.ts +398 -0
  218. package/clinkx-workflows/dist/plan-review/run-state.js +183 -0
  219. package/clinkx-workflows/dist/plan-review/run-state.js.map +1 -0
  220. package/clinkx-workflows/dist/plan-review/runtime-policy.d.ts +74 -0
  221. package/clinkx-workflows/dist/plan-review/runtime-policy.js +186 -0
  222. package/clinkx-workflows/dist/plan-review/runtime-policy.js.map +1 -0
  223. package/clinkx-workflows/dist/plan-review/snapshot.d.ts +81 -0
  224. package/clinkx-workflows/dist/plan-review/snapshot.js +170 -0
  225. package/clinkx-workflows/dist/plan-review/snapshot.js.map +1 -0
  226. package/clinkx-workflows/dist/plan-review/stage-error.d.ts +19 -0
  227. package/clinkx-workflows/dist/plan-review/stage-error.js +20 -0
  228. package/clinkx-workflows/dist/plan-review/stage-error.js.map +1 -0
  229. package/clinkx-workflows/dist/post-processors/index.d.ts +20 -0
  230. package/clinkx-workflows/dist/post-processors/index.js +21 -0
  231. package/clinkx-workflows/dist/post-processors/index.js.map +1 -0
  232. package/clinkx-workflows/dist/prompt-budget.d.ts +7 -0
  233. package/clinkx-workflows/dist/prompt-budget.js +7 -1
  234. package/clinkx-workflows/dist/prompt-budget.js.map +1 -1
  235. package/clinkx-workflows/dist/reducers/index.js +2 -0
  236. package/clinkx-workflows/dist/reducers/index.js.map +1 -1
  237. package/clinkx-workflows/dist/run-lock-heartbeat.d.ts +2 -0
  238. package/clinkx-workflows/dist/run-lock-heartbeat.js +3 -0
  239. package/clinkx-workflows/dist/run-lock-heartbeat.js.map +1 -0
  240. package/clinkx-workflows/dist/run-summary/cards/council-plan-review.d.ts +34 -0
  241. package/clinkx-workflows/dist/run-summary/cards/council-plan-review.js +74 -0
  242. package/clinkx-workflows/dist/run-summary/cards/council-plan-review.js.map +1 -0
  243. package/clinkx-workflows/dist/run-summary/cards/index.js +5 -0
  244. package/clinkx-workflows/dist/run-summary/cards/index.js.map +1 -1
  245. package/clinkx-workflows/dist/run-summary.d.ts +13 -0
  246. package/clinkx-workflows/dist/run-summary.js +29 -1
  247. package/clinkx-workflows/dist/run-summary.js.map +1 -1
  248. package/clinkx-workflows/dist/schema.d.ts +76 -21
  249. package/clinkx-workflows/dist/schema.js +10 -1
  250. package/clinkx-workflows/dist/schema.js.map +1 -1
  251. package/clinkx-workflows/dist/seed-terms.d.ts +30 -0
  252. package/clinkx-workflows/dist/seed-terms.js +176 -0
  253. package/clinkx-workflows/dist/seed-terms.js.map +1 -0
  254. package/clinkx-workflows/dist/server.d.ts +5 -2
  255. package/clinkx-workflows/dist/server.js +82 -52
  256. package/clinkx-workflows/dist/server.js.map +1 -1
  257. package/clinkx-workflows/dist/shutdown.d.ts +18 -20
  258. package/clinkx-workflows/dist/shutdown.js +43 -61
  259. package/clinkx-workflows/dist/shutdown.js.map +1 -1
  260. package/clinkx-workflows/dist/state-schema.d.ts +38 -0
  261. package/clinkx-workflows/dist/state.d.ts +170 -3
  262. package/clinkx-workflows/dist/state.js +1275 -28
  263. package/clinkx-workflows/dist/state.js.map +1 -1
  264. package/clinkx-workflows/dist/transport.d.ts +15 -0
  265. package/clinkx-workflows/dist/transport.js +19 -10
  266. package/clinkx-workflows/dist/transport.js.map +1 -1
  267. package/clinkx-workflows/dist/types.d.ts +14 -2
  268. package/clinkx-workflows/dist/validators/council.d.ts +318 -85
  269. package/clinkx-workflows/dist/validators/council.js +52 -13
  270. package/clinkx-workflows/dist/validators/council.js.map +1 -1
  271. package/clinkx-workflows/dist/validators/index.d.ts +1 -0
  272. package/clinkx-workflows/dist/validators/index.js +3 -0
  273. package/clinkx-workflows/dist/validators/index.js.map +1 -1
  274. package/clinkx-workflows/dist/validators/plan-review.d.ts +398 -0
  275. package/clinkx-workflows/dist/validators/plan-review.js +316 -0
  276. package/clinkx-workflows/dist/validators/plan-review.js.map +1 -0
  277. package/clinkx-workflows/dist/workflow-receipt.js +188 -4
  278. package/clinkx-workflows/dist/workflow-receipt.js.map +1 -1
  279. package/clinkx-workflows/dist/workflow-tools.d.ts +48 -3
  280. package/clinkx-workflows/dist/workflow-tools.js +1402 -59
  281. package/clinkx-workflows/dist/workflow-tools.js.map +1 -1
  282. package/clinkx-workflows/dist/workspace-signature.d.ts +16 -0
  283. package/clinkx-workflows/dist/workspace-signature.js +388 -0
  284. package/clinkx-workflows/dist/workspace-signature.js.map +1 -0
  285. package/clinkx-workflows/templates/council/answer-specialist.txt +2 -1
  286. package/clinkx-workflows/templates/council/code-review-chairman.txt +13 -0
  287. package/clinkx-workflows/templates/council/code-review-cross-reviewer.txt +4 -1
  288. package/clinkx-workflows/templates/council/code-review-reviewer.txt +19 -3
  289. package/clinkx-workflows/templates/council/debug-debugger.txt +2 -1
  290. package/clinkx-workflows/templates/council/discover-analyst.txt +2 -1
  291. package/clinkx-workflows/templates/council/member.txt +2 -1
  292. package/clinkx-workflows/templates/council/plan-review-chairman.txt +68 -0
  293. package/clinkx-workflows/templates/council/plan-review-cross-reviewer.txt +51 -0
  294. package/clinkx-workflows/templates/council/plan-review-reviewer.txt +60 -0
  295. package/clinkx-workflows/templates/plan-review/chairman.txt +48 -0
  296. package/clinkx-workflows/templates/plan-review/cross-review.txt +52 -0
  297. package/clinkx-workflows/templates/plan-review/ranking.txt +16 -0
  298. package/clinkx-workflows/templates/plan-review/reviewer.txt +57 -0
  299. package/clinkx-workflows/workflows/council-answer.yaml +97 -8
  300. package/clinkx-workflows/workflows/council-code-review.yaml +103 -8
  301. package/clinkx-workflows/workflows/council-debug.yaml +97 -8
  302. package/clinkx-workflows/workflows/council-default.yaml +97 -8
  303. package/clinkx-workflows/workflows/council-discover.yaml +97 -8
  304. package/clinkx-workflows/workflows/council-plan-review.yaml +250 -0
  305. package/clinkx-workflows/workflows/plan-review-receipts.yaml +230 -0
  306. package/conf/adapters/agy.json +49 -0
  307. package/conf/adapters/claude.json +5 -0
  308. package/conf/adapters/codex-app-server.json +44 -0
  309. package/conf/adapters/codex.json +7 -2
  310. package/conf/adapters/glm.json +5 -0
  311. package/conf/adapters/grok.json +60 -0
  312. package/conf/adapters/hapi/agy.json +52 -0
  313. package/conf/adapters/hapi/claude.json +5 -0
  314. package/conf/adapters/hapi/codex.json +7 -2
  315. package/conf/adapters/hapi/glm.json +5 -0
  316. package/dist/activity-journal.d.ts +42 -0
  317. package/dist/activity-journal.js +381 -0
  318. package/dist/activity-journal.js.map +1 -0
  319. package/dist/allowed-roots.d.ts +41 -0
  320. package/dist/allowed-roots.js +125 -3
  321. package/dist/allowed-roots.js.map +1 -1
  322. package/dist/codex/activity-session-log.d.ts +14 -0
  323. package/dist/codex/activity-session-log.js +206 -0
  324. package/dist/codex/activity-session-log.js.map +1 -0
  325. package/dist/codex/agent-tools.d.ts +23 -0
  326. package/dist/codex/agent-tools.js +1270 -0
  327. package/dist/codex/agent-tools.js.map +1 -0
  328. package/dist/codex/app-server-client.d.ts +76 -0
  329. package/dist/codex/app-server-client.js +582 -0
  330. package/dist/codex/app-server-client.js.map +1 -0
  331. package/dist/codex/app-server-registry.d.ts +389 -0
  332. package/dist/codex/app-server-registry.js +1407 -0
  333. package/dist/codex/app-server-registry.js.map +1 -0
  334. package/dist/codex/client-types.d.ts +109 -0
  335. package/dist/codex/client-types.js +2 -0
  336. package/dist/codex/client-types.js.map +1 -0
  337. package/dist/codex/protocol.d.ts +5375 -0
  338. package/dist/codex/protocol.js +614 -0
  339. package/dist/codex/protocol.js.map +1 -0
  340. package/dist/codex/session.d.ts +263 -0
  341. package/dist/codex/session.js +466 -0
  342. package/dist/codex/session.js.map +1 -0
  343. package/dist/config.d.ts +185 -19
  344. package/dist/config.js +82 -16
  345. package/dist/config.js.map +1 -1
  346. package/dist/context-builder/anchors.d.ts +1 -0
  347. package/dist/context-builder/anchors.js +3 -0
  348. package/dist/context-builder/anchors.js.map +1 -1
  349. package/dist/context-builder/bundle.d.ts +35 -2
  350. package/dist/context-builder/bundle.js +342 -2417
  351. package/dist/context-builder/bundle.js.map +1 -1
  352. package/dist/context-builder/codemap.d.ts +5 -0
  353. package/dist/context-builder/codemap.js +387 -13
  354. package/dist/context-builder/codemap.js.map +1 -1
  355. package/dist/context-builder/config.d.ts +1 -0
  356. package/dist/context-builder/config.js +12 -0
  357. package/dist/context-builder/config.js.map +1 -1
  358. package/dist/context-builder/context-run-catalog.d.ts +17 -0
  359. package/dist/context-builder/context-run-catalog.js +99 -0
  360. package/dist/context-builder/context-run-catalog.js.map +1 -0
  361. package/dist/context-builder/delegate-packet.d.ts +37 -0
  362. package/dist/context-builder/delegate-packet.js +359 -67
  363. package/dist/context-builder/delegate-packet.js.map +1 -1
  364. package/dist/context-builder/delegate-validation.d.ts +10 -1
  365. package/dist/context-builder/delegate-validation.js +153 -41
  366. package/dist/context-builder/delegate-validation.js.map +1 -1
  367. package/dist/context-builder/delegate.d.ts +2 -0
  368. package/dist/context-builder/delegate.js +1 -0
  369. package/dist/context-builder/delegate.js.map +1 -1
  370. package/dist/context-builder/diagnostics.d.ts +11 -2
  371. package/dist/context-builder/diagnostics.js +39 -6
  372. package/dist/context-builder/diagnostics.js.map +1 -1
  373. package/dist/context-builder/discovery.d.ts +29 -1
  374. package/dist/context-builder/discovery.js +475 -175
  375. package/dist/context-builder/discovery.js.map +1 -1
  376. package/dist/context-builder/globs.js +10 -10
  377. package/dist/context-builder/globs.js.map +1 -1
  378. package/dist/context-builder/handler.d.ts +26 -2
  379. package/dist/context-builder/handler.js +1158 -2416
  380. package/dist/context-builder/handler.js.map +1 -1
  381. package/dist/context-builder/lifecycle-contract.d.ts +424 -0
  382. package/dist/context-builder/lifecycle-contract.js +523 -0
  383. package/dist/context-builder/lifecycle-contract.js.map +1 -0
  384. package/dist/context-builder/lifecycle-journal.d.ts +62 -0
  385. package/dist/context-builder/lifecycle-journal.js +88 -0
  386. package/dist/context-builder/lifecycle-journal.js.map +1 -0
  387. package/dist/context-builder/lifecycle-observer.d.ts +102 -0
  388. package/dist/context-builder/lifecycle-observer.js +258 -0
  389. package/dist/context-builder/lifecycle-observer.js.map +1 -0
  390. package/dist/context-builder/lifecycle-reconcile.d.ts +32 -0
  391. package/dist/context-builder/lifecycle-reconcile.js +191 -0
  392. package/dist/context-builder/lifecycle-reconcile.js.map +1 -0
  393. package/dist/context-builder/lifecycle-recovery.d.ts +2 -0
  394. package/dist/context-builder/lifecycle-recovery.js +14 -0
  395. package/dist/context-builder/lifecycle-recovery.js.map +1 -0
  396. package/dist/context-builder/path-signals.js +9 -5
  397. package/dist/context-builder/path-signals.js.map +1 -1
  398. package/dist/context-builder/progress.d.ts +3 -1
  399. package/dist/context-builder/progress.js +23 -0
  400. package/dist/context-builder/progress.js.map +1 -1
  401. package/dist/context-builder/receipt.d.ts +6 -4
  402. package/dist/context-builder/receipt.js +12 -1
  403. package/dist/context-builder/receipt.js.map +1 -1
  404. package/dist/context-builder/refine-handler.d.ts +14 -0
  405. package/dist/context-builder/refine-handler.js +790 -0
  406. package/dist/context-builder/refine-handler.js.map +1 -0
  407. package/dist/context-builder/review-coverage.d.ts +84 -0
  408. package/dist/context-builder/review-coverage.js +437 -0
  409. package/dist/context-builder/review-coverage.js.map +1 -0
  410. package/dist/context-builder/schema.d.ts +239 -1
  411. package/dist/context-builder/schema.js +112 -6
  412. package/dist/context-builder/schema.js.map +1 -1
  413. package/dist/context-builder/secrets.d.ts +28 -0
  414. package/dist/context-builder/secrets.js +1473 -44
  415. package/dist/context-builder/secrets.js.map +1 -1
  416. package/dist/context-builder/selection.d.ts +7 -3
  417. package/dist/context-builder/selection.js +200 -738
  418. package/dist/context-builder/selection.js.map +1 -1
  419. package/dist/context-builder/session-log-identity.d.ts +1 -0
  420. package/dist/context-builder/session-log-identity.js +66 -0
  421. package/dist/context-builder/session-log-identity.js.map +1 -0
  422. package/dist/context-builder/slice-range-math.d.ts +16 -0
  423. package/dist/context-builder/slice-range-math.js +137 -0
  424. package/dist/context-builder/slice-range-math.js.map +1 -0
  425. package/dist/context-builder/status.d.ts +22 -1
  426. package/dist/context-builder/status.js +59 -4
  427. package/dist/context-builder/status.js.map +1 -1
  428. package/dist/context-builder/storage.d.ts +35 -2
  429. package/dist/context-builder/storage.js +271 -14
  430. package/dist/context-builder/storage.js.map +1 -1
  431. package/dist/context-builder/token-estimate.d.ts +13 -2
  432. package/dist/context-builder/token-estimate.js +77 -4
  433. package/dist/context-builder/token-estimate.js.map +1 -1
  434. package/dist/context-builder/versions.d.ts +29 -0
  435. package/dist/context-builder/versions.js +30 -0
  436. package/dist/context-builder/versions.js.map +1 -0
  437. package/dist/context-builder/workflow-runner.d.ts +69 -0
  438. package/dist/context-builder/workflow-runner.js +1051 -0
  439. package/dist/context-builder/workflow-runner.js.map +1 -0
  440. package/dist/context-builder/write-watchdog.d.ts +14 -0
  441. package/dist/context-builder/write-watchdog.js +38 -0
  442. package/dist/context-builder/write-watchdog.js.map +1 -0
  443. package/dist/dashboard-adapter-catalog.d.ts +9 -0
  444. package/dist/dashboard-adapter-catalog.js +46 -0
  445. package/dist/dashboard-adapter-catalog.js.map +1 -0
  446. package/dist/dashboard-cli.d.ts +79 -0
  447. package/dist/dashboard-cli.js +585 -0
  448. package/dist/dashboard-cli.js.map +1 -0
  449. package/dist/dashboard-companion/client.d.ts +36 -0
  450. package/dist/dashboard-companion/client.js +210 -0
  451. package/dist/dashboard-companion/client.js.map +1 -0
  452. package/dist/dashboard-companion/config.d.ts +8 -0
  453. package/dist/dashboard-companion/config.js +52 -0
  454. package/dist/dashboard-companion/config.js.map +1 -0
  455. package/dist/dashboard-companion/http-proxy.d.ts +10 -0
  456. package/dist/dashboard-companion/http-proxy.js +234 -0
  457. package/dist/dashboard-companion/http-proxy.js.map +1 -0
  458. package/dist/dashboard-companion/protocol.d.ts +80 -0
  459. package/dist/dashboard-companion/protocol.js +455 -0
  460. package/dist/dashboard-companion/protocol.js.map +1 -0
  461. package/dist/dashboard-companion/standalone-assets.d.ts +12 -0
  462. package/dist/dashboard-companion/standalone-assets.js +72 -0
  463. package/dist/dashboard-companion/standalone-assets.js.map +1 -0
  464. package/dist/dashboard-companion/standalone-entry.d.ts +1 -0
  465. package/dist/dashboard-companion/standalone-entry.js +17 -0
  466. package/dist/dashboard-companion/standalone-entry.js.map +1 -0
  467. package/dist/dashboard-gateway/config.d.ts +9 -0
  468. package/dist/dashboard-gateway/config.js +44 -0
  469. package/dist/dashboard-gateway/config.js.map +1 -0
  470. package/dist/dashboard-gateway/index.d.ts +11 -0
  471. package/dist/dashboard-gateway/index.js +755 -0
  472. package/dist/dashboard-gateway/index.js.map +1 -0
  473. package/dist/dashboard-gateway/main.d.ts +1 -0
  474. package/dist/dashboard-gateway/main.js +25 -0
  475. package/dist/dashboard-gateway/main.js.map +1 -0
  476. package/dist/dashboard-pairing-token.d.ts +1 -0
  477. package/dist/dashboard-pairing-token.js +5 -0
  478. package/dist/dashboard-pairing-token.js.map +1 -0
  479. package/dist/elaris/client.d.ts +73 -0
  480. package/dist/elaris/client.js +825 -0
  481. package/dist/elaris/client.js.map +1 -0
  482. package/dist/elaris/config.d.ts +18 -0
  483. package/dist/elaris/config.js +75 -0
  484. package/dist/elaris/config.js.map +1 -0
  485. package/dist/elaris/errors.d.ts +41 -0
  486. package/dist/elaris/errors.js +205 -0
  487. package/dist/elaris/errors.js.map +1 -0
  488. package/dist/elaris/github-repo.d.ts +18 -0
  489. package/dist/elaris/github-repo.js +89 -0
  490. package/dist/elaris/github-repo.js.map +1 -0
  491. package/dist/elaris/index.d.ts +10 -0
  492. package/dist/elaris/index.js +11 -0
  493. package/dist/elaris/index.js.map +1 -0
  494. package/dist/elaris/redact.d.ts +89 -0
  495. package/dist/elaris/redact.js +423 -0
  496. package/dist/elaris/redact.js.map +1 -0
  497. package/dist/elaris/run-id.d.ts +5 -0
  498. package/dist/elaris/run-id.js +20 -0
  499. package/dist/elaris/run-id.js.map +1 -0
  500. package/dist/elaris/status.d.ts +45 -0
  501. package/dist/elaris/status.js +122 -0
  502. package/dist/elaris/status.js.map +1 -0
  503. package/dist/elaris/tool-schemas.d.ts +314 -0
  504. package/dist/elaris/tool-schemas.js +208 -0
  505. package/dist/elaris/tool-schemas.js.map +1 -0
  506. package/dist/elaris/tools.d.ts +73 -0
  507. package/dist/elaris/tools.js +1065 -0
  508. package/dist/elaris/tools.js.map +1 -0
  509. package/dist/elaris/types.d.ts +1541 -0
  510. package/dist/elaris/types.js +252 -0
  511. package/dist/elaris/types.js.map +1 -0
  512. package/dist/errors.d.ts +16 -0
  513. package/dist/errors.js +19 -0
  514. package/dist/errors.js.map +1 -1
  515. package/dist/handler.d.ts +4 -0
  516. package/dist/handler.js +10 -1
  517. package/dist/handler.js.map +1 -1
  518. package/dist/index.d.ts +2 -1
  519. package/dist/index.js +13 -3
  520. package/dist/index.js.map +1 -1
  521. package/dist/local-clink-backend.d.ts +3 -0
  522. package/dist/local-clink-backend.js +4 -0
  523. package/dist/local-clink-backend.js.map +1 -1
  524. package/dist/package-info.d.ts +2 -0
  525. package/dist/package-info.js +18 -0
  526. package/dist/package-info.js.map +1 -0
  527. package/dist/parsers/codex-jsonl.js +48 -3
  528. package/dist/parsers/codex-jsonl.js.map +1 -1
  529. package/dist/parsers/extract.d.ts +10 -1
  530. package/dist/parsers/extract.js +11 -3
  531. package/dist/parsers/extract.js.map +1 -1
  532. package/dist/pipeline.d.ts +4 -0
  533. package/dist/pipeline.js +129 -8
  534. package/dist/pipeline.js.map +1 -1
  535. package/dist/run-dir.d.ts +24 -0
  536. package/dist/run-dir.js +201 -2
  537. package/dist/run-dir.js.map +1 -1
  538. package/dist/runner.d.ts +13 -0
  539. package/dist/runner.js +184 -15
  540. package/dist/runner.js.map +1 -1
  541. package/dist/safety.d.ts +4 -4
  542. package/dist/safety.js +4 -4
  543. package/dist/schema.d.ts +7 -7
  544. package/dist/server.d.ts +1 -0
  545. package/dist/server.js +359 -17
  546. package/dist/server.js.map +1 -1
  547. package/dist/session-log-stream.d.ts +18 -0
  548. package/dist/session-log-stream.js +319 -0
  549. package/dist/session-log-stream.js.map +1 -0
  550. package/package.json +46 -5
  551. package/conf/adapters/gemini.json +0 -44
  552. package/conf/adapters/hapi/gemini.json +0 -47
  553. package/dist/parsers/gemini-json.d.ts +0 -2
  554. package/dist/parsers/gemini-json.js +0 -72
  555. package/dist/parsers/gemini-json.js.map +0 -1
@@ -0,0 +1,825 @@
1
+ import { AgentSessionArtifactsPageSchema, AgentSessionCancelResponseSchema, AgentSessionCleanupResponseSchema, AgentSessionLogsPageSchema, AgentSessionMessageResponseSchema, AgentSessionRawArtifactMetadataSchema, AgentSessionResultContentSchema, AgentSessionResultMetadataSchema, AgentSessionStatusResponseSchema, AgentSessionURLResponseSchema, } from "./types.js";
2
+ import { CancellationError, InvalidParamsError } from "../errors.js";
3
+ import { MAX_AGGREGATE_BYTES, MAX_PAGES, MAX_RESPONSE_BYTES, MAX_TEXT_CHARS, MAX_TOTAL_ITEMS, PAGE_LIMIT, POLL_MAX_MS, POLL_MIN_MS, } from "./config.js";
4
+ import { detectCredentials, redact, redactPreservingLocators, redactPreservingLocatorsWithMetadata, redactWithMetadata, scrubOwnCredentials, } from "./redact.js";
5
+ const AGENT_SESSIONS_PATH = "/api/v1/agent-sessions";
6
+ const MAX_RAW_BODY_BYTES_FOR_BASE64 = Math.floor((MAX_RESPONSE_BYTES - 4096) * 3 / 4);
7
+ export class ElarisHttpError extends Error {
8
+ status;
9
+ payload;
10
+ rawPayload;
11
+ retryAfterMs;
12
+ retryClass;
13
+ constructor(status, payload, rawPayload, retryAfterMs, retryClass) {
14
+ super(`Elaris HTTP request failed with status ${status}`);
15
+ this.status = status;
16
+ this.payload = payload;
17
+ this.rawPayload = rawPayload;
18
+ this.retryAfterMs = retryAfterMs;
19
+ this.retryClass = retryClass;
20
+ this.name = "ElarisHttpError";
21
+ }
22
+ }
23
+ export function isElarisHttpError(err) {
24
+ return err instanceof ElarisHttpError;
25
+ }
26
+ export class ElarisClient {
27
+ options;
28
+ constructor(options) {
29
+ this.options = options;
30
+ }
31
+ async createSession(request, options = {}) {
32
+ return this.requestJson(AgentSessionURLResponseSchema, {
33
+ method: "POST",
34
+ path: AGENT_SESSIONS_PATH,
35
+ body: request,
36
+ signal: options.signal,
37
+ expectedStatus: 202,
38
+ }, true);
39
+ }
40
+ async postMessage(sessionId, request, options = {}) {
41
+ return this.requestJson(AgentSessionMessageResponseSchema, {
42
+ method: "POST",
43
+ path: `${AGENT_SESSIONS_PATH}/${encodePathSegment(sessionId)}/messages`,
44
+ body: request,
45
+ signal: options.signal,
46
+ expectedStatus: 202,
47
+ }, true);
48
+ }
49
+ async getStatusBySessionId(sessionId, options = {}) {
50
+ return this.requestJson(AgentSessionStatusResponseSchema, {
51
+ method: "GET",
52
+ path: `${AGENT_SESSIONS_PATH}/${encodePathSegment(sessionId)}`,
53
+ signal: options.signal,
54
+ expectedStatus: 200,
55
+ }, true);
56
+ }
57
+ async getStatusByHandle(statusUrl, options = {}) {
58
+ const resolved = resolveHandle(this.options.baseUrl, statusUrl);
59
+ return this.requestJson(AgentSessionStatusResponseSchema, {
60
+ method: "GET",
61
+ path: resolved.path,
62
+ signal: options.signal,
63
+ expectedStatus: 200,
64
+ }, true);
65
+ }
66
+ async getResult(sessionId, options = {}) {
67
+ const value = await this.requestJsonRecord({
68
+ method: "GET",
69
+ path: `${AGENT_SESSIONS_PATH}/${encodePathSegment(sessionId)}/result`,
70
+ signal: options.signal,
71
+ expectedStatus: 200,
72
+ });
73
+ return parseRedactedDeepCounted(AgentSessionResultMetadataSchema, value);
74
+ }
75
+ async getResultContent(sessionId, options = {}) {
76
+ const response = await this.fetchRaw({
77
+ method: "GET",
78
+ path: `${AGENT_SESSIONS_PATH}/${encodePathSegment(sessionId)}/result/content`,
79
+ signal: options.signal,
80
+ expectedStatus: 200,
81
+ responseCapBytes: MAX_RESPONSE_BYTES,
82
+ });
83
+ const text = decodeUtf8Lossy(response.body.bytes);
84
+ const { value: redacted, redaction_count } = redactWithMetadata({
85
+ text,
86
+ content_type: response.response.headers.get("content-type"),
87
+ bytes_returned: response.body.bytes.length,
88
+ result_bytes: parseNullablePositiveInt(response.response.headers.get("content-length")),
89
+ truncated: response.body.tooLarge,
90
+ local_response_too_large: response.body.tooLarge ? response.body.tooLargeReason : undefined,
91
+ });
92
+ return AgentSessionResultContentSchema.parse(attachRedactionCount(redacted, redaction_count));
93
+ }
94
+ async getLogsPage(sessionId, options = {}) {
95
+ const page = await this.requestJsonRecord({
96
+ method: "GET",
97
+ path: withQuery(`${AGENT_SESSIONS_PATH}/${encodePathSegment(sessionId)}/logs`, {
98
+ cursor: options.cursor ?? "0",
99
+ limit: String(normalizePageLimit(options.limit)),
100
+ }),
101
+ signal: options.signal,
102
+ expectedStatus: 200,
103
+ });
104
+ const normalized = normalizeLogsPage(page);
105
+ return parseRedactedDeepCounted(AgentSessionLogsPageSchema, normalized);
106
+ }
107
+ async getAllLogs(sessionId, options = {}) {
108
+ return this.collectPages({
109
+ firstCursor: "0",
110
+ fetchPage: (cursor) => this.getLogsPage(sessionId, { ...options, cursor, limit: normalizePageLimit(options.limit) }),
111
+ getItems: (page) => readItems(page),
112
+ getNextCursor: (page) => readNextCursor(page),
113
+ getRedactionCount: (page) => readPageRedactionCount(page),
114
+ makePage: (items, lastPage, metadata, redactionTotal) => parseAggregatedRedactedPage(AgentSessionLogsPageSchema, {
115
+ ...lastPage,
116
+ items,
117
+ next_cursor: metadata.resume_cursor,
118
+ ...metadata,
119
+ }, redactionTotal),
120
+ });
121
+ }
122
+ async getArtifactsPage(sessionId, options = {}) {
123
+ const value = await this.requestJsonRecord({
124
+ method: "GET",
125
+ path: withQuery(`${AGENT_SESSIONS_PATH}/${encodePathSegment(sessionId)}/artifacts`, {
126
+ cursor: options.cursor ?? "0",
127
+ limit: String(normalizePageLimit(options.limit)),
128
+ }),
129
+ signal: options.signal,
130
+ expectedStatus: 200,
131
+ });
132
+ return parseRedactedDeepCounted(AgentSessionArtifactsPageSchema, value);
133
+ }
134
+ async getAllArtifacts(sessionId, options = {}) {
135
+ return this.collectPages({
136
+ firstCursor: "0",
137
+ fetchPage: (cursor) => this.getArtifactsPage(sessionId, { ...options, cursor, limit: normalizePageLimit(options.limit) }),
138
+ getItems: (page) => readItems(page),
139
+ getNextCursor: (page) => readNextCursor(page),
140
+ getRedactionCount: (page) => readPageRedactionCount(page),
141
+ makePage: (items, lastPage, metadata, redactionTotal) => parseAggregatedRedactedPage(AgentSessionArtifactsPageSchema, {
142
+ ...lastPage,
143
+ items,
144
+ next_cursor: metadata.resume_cursor,
145
+ ...metadata,
146
+ }, redactionTotal),
147
+ });
148
+ }
149
+ async getArtifactRaw(sessionId, filePath, options = {}) {
150
+ const artifactPath = buildArtifactRawPath(sessionId, filePath);
151
+ const headers = {};
152
+ if (options.range)
153
+ headers["Range"] = formatRange(options.range);
154
+ const response = await this.fetchRaw({
155
+ method: "GET",
156
+ path: artifactPath,
157
+ signal: options.signal,
158
+ headers,
159
+ expectedStatus: [200, 206],
160
+ responseCapBytes: MAX_RESPONSE_BYTES,
161
+ });
162
+ const contentType = response.response.headers.get("content-type");
163
+ const base = {
164
+ status_code: response.response.status,
165
+ content_type: contentType,
166
+ content_length: parseNullablePositiveInt(response.response.headers.get("content-length")),
167
+ content_range: response.response.headers.get("content-range"),
168
+ accept_ranges: response.response.headers.get("accept-ranges"),
169
+ bytes_returned: response.body.bytes.length,
170
+ truncated: response.body.tooLarge,
171
+ local_response_too_large: response.body.tooLarge ? response.body.tooLargeReason : undefined,
172
+ range_guidance: response.body.tooLarge ? "Retry with a smaller Range header." : undefined,
173
+ };
174
+ const serialized = serializeRawArtifact(base, response.body.bytes);
175
+ return AgentSessionRawArtifactMetadataSchema.parse(scrubRawArtifactFields(serialized));
176
+ }
177
+ async cancel(sessionId, options = {}) {
178
+ return this.requestJson(AgentSessionCancelResponseSchema, {
179
+ method: "POST",
180
+ path: `${AGENT_SESSIONS_PATH}/${encodePathSegment(sessionId)}/cancel`,
181
+ signal: options.signal,
182
+ expectedStatus: 200,
183
+ }, true);
184
+ }
185
+ async cleanup(sessionId, options = {}) {
186
+ return this.requestJson(AgentSessionCleanupResponseSchema, {
187
+ method: "DELETE",
188
+ path: `${AGENT_SESSIONS_PATH}/${encodePathSegment(sessionId)}`,
189
+ signal: options.signal,
190
+ expectedStatus: 200,
191
+ }, true);
192
+ }
193
+ async healthProbe(options = {}) {
194
+ if (!this.options.apiKey.trim()) {
195
+ return {
196
+ ok: false,
197
+ key_present: false,
198
+ router: "not_checked",
199
+ detail: "Elaris API key is not configured.",
200
+ };
201
+ }
202
+ try {
203
+ const probeId = "00000000-0000-0000-0000-000000000000";
204
+ const probe = await this.fetchRaw({
205
+ method: "GET",
206
+ path: `${AGENT_SESSIONS_PATH}/${probeId}`,
207
+ signal: options.signal,
208
+ expectedStatus: [200, 401, 403, 404],
209
+ responseCapBytes: MAX_RESPONSE_BYTES,
210
+ });
211
+ const status = probe.response.status;
212
+ if (status === 401) {
213
+ return redact({
214
+ ok: false,
215
+ key_present: true,
216
+ router: "auth_failed",
217
+ detail: "Elaris rejected the API key (HTTP 401).",
218
+ });
219
+ }
220
+ if (status === 403) {
221
+ return redact({
222
+ ok: false,
223
+ key_present: true,
224
+ router: "insufficient_scope",
225
+ detail: "Elaris API key lacks the required scope (HTTP 403).",
226
+ });
227
+ }
228
+ // 200 or a nil-UUID 404 both mean the router is reachable and the key authenticates.
229
+ return { ok: true, key_present: true, router: "reachable", status_code: status };
230
+ }
231
+ catch (err) {
232
+ const retry = err instanceof ElarisHttpError ? {
233
+ retry_after_ms: err.retryAfterMs,
234
+ retry_class: err.retryClass,
235
+ } : {};
236
+ return redact({
237
+ ok: false,
238
+ key_present: true,
239
+ router: "indeterminate",
240
+ detail: err instanceof Error ? err.message : "Unknown Elaris health probe failure",
241
+ ...retry,
242
+ });
243
+ }
244
+ }
245
+ async requestJson(schema, config, deep = false) {
246
+ const value = await this.requestJsonRecord(config);
247
+ return deep ? parseRedactedDeep(schema, value) : parseRedacted(schema, value);
248
+ }
249
+ async requestJsonRecord(config) {
250
+ const response = await this.fetchRaw({
251
+ ...config,
252
+ responseCapBytes: config.responseCapBytes ?? MAX_RESPONSE_BYTES,
253
+ });
254
+ if (response.body.tooLarge) {
255
+ const localMarker = {
256
+ error: "local_response_too_large",
257
+ detail: response.body.tooLargeReason,
258
+ };
259
+ throw new ElarisHttpError(response.response.status, localMarker, localMarker);
260
+ }
261
+ const text = decodeUtf8Lossy(response.body.bytes);
262
+ try {
263
+ const parsed = text ? JSON.parse(text) : {};
264
+ if (typeof parsed === "object" && parsed !== null && !Array.isArray(parsed)) {
265
+ return parsed;
266
+ }
267
+ }
268
+ catch (err) {
269
+ throw new Error("Elaris returned invalid JSON");
270
+ }
271
+ throw new Error("Elaris returned a non-object JSON response");
272
+ }
273
+ async fetchRaw(config) {
274
+ const url = new URL(config.path, this.options.baseUrl);
275
+ const controller = new AbortController();
276
+ const signals = [controller.signal, AbortSignal.timeout(this.options.requestTimeoutMs)];
277
+ if (config.signal)
278
+ signals.push(config.signal);
279
+ const signal = AbortSignal.any(signals);
280
+ const headers = this.buildHeaders(config.headers, config.body !== undefined, config.includeAuth ?? true);
281
+ const init = {
282
+ method: config.method,
283
+ headers,
284
+ signal,
285
+ };
286
+ if (config.body !== undefined)
287
+ init.body = JSON.stringify(config.body);
288
+ const response = await this.options.fetch(url, init);
289
+ const expected = Array.isArray(config.expectedStatus)
290
+ ? config.expectedStatus
291
+ : [config.expectedStatus ?? 200];
292
+ const body = await readBoundedBody(response, config.responseCapBytes ?? MAX_RESPONSE_BYTES, () => controller.abort());
293
+ if (!expected.includes(response.status)) {
294
+ const retry = parseRetryAfter(response.headers.get("retry-after"));
295
+ const parsedError = parseErrorPayload(body);
296
+ throw new ElarisHttpError(response.status, parsedError.payload, parsedError.rawPayload, retry?.retry_after_ms, retry?.retry_class);
297
+ }
298
+ return { response, body };
299
+ }
300
+ buildHeaders(extra, hasBody, includeAuth) {
301
+ const headers = new Headers(extra);
302
+ headers.set("Accept", "application/json");
303
+ if (hasBody)
304
+ headers.set("Content-Type", "application/json");
305
+ if (includeAuth && this.options.apiKey.trim()) {
306
+ headers.set("Authorization", `Bearer ${this.options.apiKey}`);
307
+ }
308
+ return headers;
309
+ }
310
+ async collectPages(options) {
311
+ const items = [];
312
+ const seenCursors = new Set();
313
+ let cursor = options.firstCursor;
314
+ let lastPage = null;
315
+ let bytesReturned = 0;
316
+ let pagesFetched = 0;
317
+ // Authoritative aggregate: sum each fetched page's OWN per-page redaction_count.
318
+ // Re-redacting already-scrubbed assembled items finds ~0, so this running total
319
+ // is the true count that overrides the near-zero recomputation in makePage.
320
+ let redactionTotal = 0;
321
+ while (cursor !== null) {
322
+ if (seenCursors.has(cursor)) {
323
+ return options.makePage(items, lastPage ?? emptyPage(), {
324
+ truncated: true,
325
+ truncation_reason: "repeated_cursor",
326
+ resume_cursor: cursor,
327
+ items_returned: items.length,
328
+ bytes_returned: bytesReturned,
329
+ pages_fetched: pagesFetched,
330
+ }, redactionTotal);
331
+ }
332
+ if (pagesFetched >= MAX_PAGES) {
333
+ return options.makePage(items, lastPage ?? emptyPage(), {
334
+ truncated: true,
335
+ truncation_reason: "max_pages",
336
+ resume_cursor: cursor,
337
+ items_returned: items.length,
338
+ bytes_returned: bytesReturned,
339
+ pages_fetched: pagesFetched,
340
+ }, redactionTotal);
341
+ }
342
+ seenCursors.add(cursor);
343
+ let page;
344
+ try {
345
+ page = await options.fetchPage(cursor);
346
+ }
347
+ catch (err) {
348
+ if (err instanceof ElarisHttpError && err.status === 410 && items.length > 0) {
349
+ return options.makePage(items, lastPage ?? emptyPage(), {
350
+ truncated: true,
351
+ truncation_reason: "resource_gone_partial",
352
+ resume_cursor: cursor,
353
+ items_returned: items.length,
354
+ bytes_returned: bytesReturned,
355
+ pages_fetched: pagesFetched,
356
+ }, redactionTotal);
357
+ }
358
+ throw err;
359
+ }
360
+ lastPage = page;
361
+ pagesFetched += 1;
362
+ redactionTotal += options.getRedactionCount(page);
363
+ for (const item of options.getItems(page)) {
364
+ const itemBytes = JSON.stringify(item).length;
365
+ if (items.length + 1 > MAX_TOTAL_ITEMS) {
366
+ return options.makePage(items, page, capMetadata("max_total_items", cursor, items.length, bytesReturned, pagesFetched), redactionTotal);
367
+ }
368
+ if (bytesReturned + itemBytes > MAX_AGGREGATE_BYTES) {
369
+ return options.makePage(items, page, capMetadata("max_aggregate_bytes", cursor, items.length, bytesReturned, pagesFetched), redactionTotal);
370
+ }
371
+ items.push(item);
372
+ bytesReturned += itemBytes;
373
+ }
374
+ const next = options.getNextCursor(page);
375
+ if (next === cursor) {
376
+ return options.makePage(items, page, capMetadata("non_advancing_cursor", next, items.length, bytesReturned, pagesFetched), redactionTotal);
377
+ }
378
+ cursor = next;
379
+ }
380
+ return options.makePage(items, lastPage ?? emptyPage(), {
381
+ truncated: false,
382
+ resume_cursor: null,
383
+ items_returned: items.length,
384
+ bytes_returned: bytesReturned,
385
+ pages_fetched: pagesFetched,
386
+ }, redactionTotal);
387
+ }
388
+ }
389
+ export async function waitForNextElarisPoll(options) {
390
+ const now = options.nowMs ?? (() => Date.now());
391
+ const random = options.random ?? Math.random;
392
+ const sleep = options.sleep ?? defaultSleep;
393
+ const base = clamp(options.pollIntervalMs ?? POLL_MIN_MS, POLL_MIN_MS, POLL_MAX_MS);
394
+ const jittered = Math.floor(base * (0.8 + random() * 0.4));
395
+ const requested = options.retryAfterMs !== undefined && options.retryAfterMs > POLL_MAX_MS
396
+ ? options.retryAfterMs
397
+ : Math.max(jittered, Math.min(options.retryAfterMs ?? 0, POLL_MAX_MS));
398
+ const delayMs = clamp(requested, POLL_MIN_MS, Math.max(POLL_MAX_MS, requested));
399
+ if (now() + delayMs > options.deadlineMs)
400
+ return false;
401
+ await sleep(delayMs, options.signal);
402
+ return true;
403
+ }
404
+ export function resolveHandle(baseUrl, rawPath) {
405
+ if (!rawPath || rawPath.includes("\0")) {
406
+ throw new InvalidParamsError("Elaris handle path must be non-empty");
407
+ }
408
+ if (rawPath.includes("?") || rawPath.includes("#")) {
409
+ throw new InvalidParamsError("Elaris handle path must not include a query or fragment");
410
+ }
411
+ if (/^[a-z][a-z0-9+.-]*:\/\//i.test(rawPath) || rawPath.startsWith("//")) {
412
+ throw new InvalidParamsError("Elaris handle path must not be an absolute URL");
413
+ }
414
+ const path = rawPath.startsWith("/") ? rawPath : `/${rawPath}`;
415
+ if (!path.startsWith(`${AGENT_SESSIONS_PATH}/`)) {
416
+ throw new InvalidParamsError("Elaris handle path must be rooted under /api/v1/agent-sessions/");
417
+ }
418
+ for (const segment of path.split("/")) {
419
+ const decoded = safeDecodeURIComponent(segment);
420
+ if (decoded === "..") {
421
+ throw new InvalidParamsError("Elaris handle path must not contain traversal");
422
+ }
423
+ }
424
+ return { path: rawPath, url: new URL(path, baseUrl) };
425
+ }
426
+ function parseRedacted(schema, value) {
427
+ const parsed = schema.parse(value);
428
+ if (typeof parsed === "object" && parsed !== null && "raw" in parsed) {
429
+ const withRaw = parsed;
430
+ if (withRaw.raw !== undefined)
431
+ withRaw.raw = redact(withRaw.raw);
432
+ }
433
+ return parsed;
434
+ }
435
+ /**
436
+ * Uniform success-path redaction for ALL JSON responses — both read responses
437
+ * (result metadata, log/artifact pages including their `items`) and
438
+ * control-plane responses (create/status/message/cancel/cleanup, whose
439
+ * schema-typed free-text fields like `status_reason` and nested `error.detail`
440
+ * the provider may echo secrets into). The WHOLE payload is deep-redacted BEFORE
441
+ * schema parsing — like getResultContent — so provider-echoed secrets are
442
+ * scrubbed, while control-plane locators (cursors, URLs, ids, ranges) pass
443
+ * through verbatim.
444
+ */
445
+ function parseRedactedDeep(schema, value) {
446
+ return schema.parse(redactPreservingLocators(value));
447
+ }
448
+ /**
449
+ * Reserved envelope control keys that are OWNED by ClinkX, never legitimate
450
+ * provider payload. A provider MUST NOT be able to inject either — see
451
+ * {@link stripReservedRedactionKeys}.
452
+ */
453
+ const RESERVED_REDACTION_KEYS = new Set(["redaction_count", "redacted"]);
454
+ /**
455
+ * Deep-strip the reserved envelope control keys (`redaction_count`, `redacted`)
456
+ * from a PROVIDER-ORIGINATED value at EVERY depth (walking objects and arrays).
457
+ * These fields are stamped locally by ClinkX and are never legitimate provider
458
+ * data, so removing them anywhere is safe.
459
+ *
460
+ * This MUST run BEFORE the redaction/count pass on the read paths. Doing so
461
+ * closes two spoofs:
462
+ * A) A provider-supplied credential-SHAPED `redaction_count` string (e.g.
463
+ * `"Authorization: Bearer …"`) can no longer be matched by the redaction
464
+ * walk and inflate the locally-computed count (which also feeds the
465
+ * `fetch_all` aggregate via {@link readPageRedactionCount}).
466
+ * B) No nested provider `redaction_count`/`redacted` (in `items[*]`, `extra`,
467
+ * etc.) survives into the parsed result — including values that would
468
+ * otherwise land in a schema `.raw` bucket, because the strip happens
469
+ * before `withRaw` buckets unknown keys.
470
+ */
471
+ function stripReservedRedactionKeys(value) {
472
+ if (Array.isArray(value)) {
473
+ return value.map((entry) => stripReservedRedactionKeys(entry));
474
+ }
475
+ if (typeof value === "object" && value !== null) {
476
+ const out = {};
477
+ for (const [key, entry] of Object.entries(value)) {
478
+ if (RESERVED_REDACTION_KEYS.has(key))
479
+ continue;
480
+ out[key] = stripReservedRedactionKeys(entry);
481
+ }
482
+ return out;
483
+ }
484
+ return value;
485
+ }
486
+ /**
487
+ * Read-path variant of {@link parseRedactedDeep}: deep-redacts (preserving
488
+ * locators) AND surfaces how many redactions fired as a first-class
489
+ * `redaction_count` field so it can bubble to the tool envelope. Counting rides
490
+ * the single existing walk. A zero count is omitted to keep clean responses
491
+ * byte-identical to before. Used only for read responses (result metadata, log
492
+ * and artifact pages); control-plane responses keep {@link parseRedactedDeep}.
493
+ *
494
+ * Reserved control keys are deep-stripped from the provider value FIRST, so a
495
+ * spoofed/nested `redaction_count`/`redacted` can neither inflate the local
496
+ * count nor survive into the parsed result.
497
+ */
498
+ function parseRedactedDeepCounted(schema, value) {
499
+ const sanitized = stripReservedRedactionKeys(value);
500
+ const { value: redacted, redaction_count } = redactPreservingLocatorsWithMetadata(sanitized);
501
+ return schema.parse(attachRedactionCount(redacted, redaction_count));
502
+ }
503
+ /**
504
+ * fetch_all aggregate variant: deep-redacts the ASSEMBLED page (defensively —
505
+ * the per-page items are already scrubbed) but takes `redactionTotal` (the sum of
506
+ * every fetched page's own per-page `redaction_count`) as the AUTHORITATIVE count.
507
+ * Re-scanning already-redacted items would find ~0 and lose the earlier pages'
508
+ * real redactions, so we do NOT recount here; {@link attachRedactionCount} strips
509
+ * any carried-over per-page/provider count and stamps the aggregate (omitted at 0).
510
+ * Reserved control keys are deep-stripped from the assembled value FIRST (covering
511
+ * the `...lastPage`/`...metadata` spread) so no nested provider `redaction_count`/
512
+ * `redacted` survives, and the authoritative aggregate is the only stamped count.
513
+ */
514
+ function parseAggregatedRedactedPage(schema, value, redactionTotal) {
515
+ const sanitized = stripReservedRedactionKeys(value);
516
+ return schema.parse(attachRedactionCount(redactPreservingLocators(sanitized), redactionTotal));
517
+ }
518
+ /**
519
+ * Attach the LOCALLY-COMPUTED `redaction_count` to a plain object before schema
520
+ * parsing, authoritatively. Any incoming `redaction_count` (e.g. a provider-echoed
521
+ * value) is ALWAYS stripped first so a malicious or buggy upstream cannot spoof
522
+ * `redacted:true` or an arbitrary count; the local `count` is then attached only
523
+ * when it is > 0 (omitted at 0 so clean responses stay byte-identical). A
524
+ * non-object/array/null value is returned untouched.
525
+ */
526
+ function attachRedactionCount(value, count) {
527
+ if (typeof value !== "object" || value === null || Array.isArray(value))
528
+ return value;
529
+ const rest = {};
530
+ for (const [key, entry] of Object.entries(value)) {
531
+ if (key === "redaction_count")
532
+ continue;
533
+ rest[key] = entry;
534
+ }
535
+ if (count > 0)
536
+ rest["redaction_count"] = count;
537
+ return rest;
538
+ }
539
+ /**
540
+ * Per-field scrub for the explicit raw-inspection path (`artifact_raw`).
541
+ *
542
+ * FAIL-CLOSED: the shared high-confidence detector runs over the emitted inline
543
+ * `text` AND over the DECODED `data_base64` bytes. If ANY credential is detected
544
+ * the payload body is WITHHELD entirely — `text`/`data_base64` are dropped and a
545
+ * `withheld: "credential_detected"` marker plus `redaction_count` is surfaced
546
+ * (both are now FIRST-CLASS fields declared on
547
+ * `AgentSessionRawArtifactMetadataSchema` in `types.ts`, not `.raw` passthrough),
548
+ * while all metadata (status, ranges, encoding label, bytes_returned) is
549
+ * preserved so the caller can re-request a narrower Range. We do NOT inline-scrub a detected body: a
550
+ * caller-requested raw blob mixing a credential with legitimate token-shaped
551
+ * content cannot be safely partially-redacted, so we fail closed.
552
+ *
553
+ * When CLEAN, behavior is byte-identical to the prior scrub: own credentials are
554
+ * removed from string metadata fields, `data_base64` passes through verbatim,
555
+ * and numeric/boolean metadata is untouched.
556
+ */
557
+ function scrubRawArtifactFields(record) {
558
+ let count = 0;
559
+ const text = record["text"];
560
+ if (typeof text === "string")
561
+ count += detectCredentials(text).count;
562
+ const dataBase64 = record["data_base64"];
563
+ if (typeof dataBase64 === "string") {
564
+ const decoded = decodeUtf8Lossy(Buffer.from(dataBase64, "base64"));
565
+ count += detectCredentials(decoded).count;
566
+ }
567
+ if (count > 0) {
568
+ const withheld = {};
569
+ for (const [key, value] of Object.entries(record)) {
570
+ if (key === "text" || key === "data_base64")
571
+ continue;
572
+ withheld[key] = typeof value === "string" ? scrubOwnCredentials(value) : value;
573
+ }
574
+ withheld["withheld"] = "credential_detected";
575
+ withheld["redaction_count"] = count;
576
+ return withheld;
577
+ }
578
+ const out = {};
579
+ for (const [key, value] of Object.entries(record)) {
580
+ if (key === "data_base64") {
581
+ out[key] = value;
582
+ }
583
+ else if (typeof value === "string") {
584
+ out[key] = scrubOwnCredentials(value);
585
+ }
586
+ else {
587
+ out[key] = value;
588
+ }
589
+ }
590
+ return out;
591
+ }
592
+ async function readBoundedBody(response, capBytes, abortFetch) {
593
+ const contentLength = parseNullablePositiveInt(response.headers.get("content-length"));
594
+ if (contentLength !== null && contentLength > capBytes) {
595
+ abortFetch();
596
+ return {
597
+ bytes: new Uint8Array(),
598
+ bytesRead: 0,
599
+ tooLarge: true,
600
+ tooLargeReason: "content_length_exceeded",
601
+ };
602
+ }
603
+ if (!response.body) {
604
+ return { bytes: new Uint8Array(), bytesRead: 0, tooLarge: false };
605
+ }
606
+ const reader = response.body.getReader();
607
+ const chunks = [];
608
+ let bytesRead = 0;
609
+ try {
610
+ while (true) {
611
+ const { done, value } = await reader.read();
612
+ if (done)
613
+ break;
614
+ if (!value)
615
+ continue;
616
+ bytesRead += value.byteLength;
617
+ if (bytesRead > capBytes) {
618
+ const remaining = Math.max(0, capBytes - chunks.reduce((sum, chunk) => sum + chunk.byteLength, 0));
619
+ if (remaining > 0)
620
+ chunks.push(value.slice(0, remaining));
621
+ await reader.cancel().catch(() => undefined);
622
+ abortFetch();
623
+ return {
624
+ bytes: concatChunks(chunks, capBytes),
625
+ bytesRead,
626
+ tooLarge: true,
627
+ tooLargeReason: "stream_cap_exceeded",
628
+ };
629
+ }
630
+ chunks.push(value);
631
+ }
632
+ }
633
+ finally {
634
+ reader.releaseLock();
635
+ }
636
+ return { bytes: concatChunks(chunks, bytesRead), bytesRead, tooLarge: false };
637
+ }
638
+ function concatChunks(chunks, totalBytes) {
639
+ const out = new Uint8Array(totalBytes);
640
+ let offset = 0;
641
+ for (const chunk of chunks) {
642
+ out.set(chunk, offset);
643
+ offset += chunk.byteLength;
644
+ }
645
+ return out;
646
+ }
647
+ function parseErrorPayload(body) {
648
+ if (body.tooLarge) {
649
+ const marker = { error: "local_response_too_large", detail: body.tooLargeReason };
650
+ return { payload: marker, rawPayload: marker };
651
+ }
652
+ const text = decodeUtf8Lossy(body.bytes);
653
+ if (!text)
654
+ return { payload: {}, rawPayload: {} };
655
+ try {
656
+ const rawPayload = JSON.parse(text);
657
+ return { payload: redact(rawPayload), rawPayload };
658
+ }
659
+ catch {
660
+ const rawPayload = { detail: text };
661
+ return { payload: redact(rawPayload), rawPayload };
662
+ }
663
+ }
664
+ function normalizeLogsPage(page) {
665
+ if (!Array.isArray(page["items"]) && Array.isArray(page["entries"])) {
666
+ return { ...page, items: page["entries"] };
667
+ }
668
+ return page;
669
+ }
670
+ function serializeRawArtifact(base, body) {
671
+ if (base["truncated"] === true) {
672
+ return { ...base, bytes_returned: body.length, encoding: "base64" };
673
+ }
674
+ const decoded = decodeUtf8Strict(body);
675
+ if (decoded !== null && decoded.length <= MAX_TEXT_CHARS) {
676
+ const candidate = { ...base, bytes_returned: body.length, encoding: "text", text: decoded };
677
+ if (JSON.stringify(candidate).length <= MAX_RESPONSE_BYTES)
678
+ return candidate;
679
+ }
680
+ if (body.length <= MAX_RAW_BODY_BYTES_FOR_BASE64) {
681
+ const candidate = { ...base, bytes_returned: body.length, encoding: "base64", data_base64: Buffer.from(body).toString("base64") };
682
+ if (JSON.stringify(candidate).length <= MAX_RESPONSE_BYTES)
683
+ return candidate;
684
+ }
685
+ return {
686
+ ...base,
687
+ bytes_returned: body.length,
688
+ truncated: true,
689
+ encoding: "base64",
690
+ local_response_too_large: "serialized_json_cap_exceeded",
691
+ range_guidance: "Retry with a smaller Range header.",
692
+ };
693
+ }
694
+ function buildArtifactRawPath(sessionId, filePath) {
695
+ if (!filePath || filePath.includes("\0") || filePath.startsWith("/") || filePath.startsWith("\\") || /^[a-z][a-z0-9+.-]*:/i.test(filePath)) {
696
+ throw new InvalidParamsError("Artifact file_path must be a relative path");
697
+ }
698
+ const encoded = filePath.split("/").map((segment) => {
699
+ const decoded = safeDecodeURIComponent(segment);
700
+ if (!segment || decoded === "." || decoded === "..") {
701
+ throw new InvalidParamsError("Artifact file_path must not contain empty, current, or parent path segments");
702
+ }
703
+ return encodeURIComponent(decoded);
704
+ }).join("/");
705
+ return `${AGENT_SESSIONS_PATH}/${encodePathSegment(sessionId)}/artifacts/raw/${encoded}`;
706
+ }
707
+ function formatRange(range) {
708
+ if (!Number.isInteger(range.start) || range.start < 0) {
709
+ throw new InvalidParamsError("Artifact range.start must be a non-negative integer");
710
+ }
711
+ if (range.end !== undefined && (!Number.isInteger(range.end) || range.end < range.start)) {
712
+ throw new InvalidParamsError("Artifact range.end must be an integer greater than or equal to range.start");
713
+ }
714
+ return `bytes=${range.start}-${range.end ?? ""}`;
715
+ }
716
+ function withQuery(path, params) {
717
+ const query = new URLSearchParams(params);
718
+ return `${path}?${query.toString()}`;
719
+ }
720
+ function normalizePageLimit(limit) {
721
+ if (limit === undefined)
722
+ return PAGE_LIMIT;
723
+ if (!Number.isInteger(limit) || limit < 1)
724
+ throw new InvalidParamsError("Elaris page limit must be a positive integer");
725
+ return Math.min(limit, PAGE_LIMIT);
726
+ }
727
+ function capMetadata(reason, resumeCursor, itemsReturned, bytesReturned, pagesFetched) {
728
+ return {
729
+ truncated: true,
730
+ truncation_reason: reason,
731
+ resume_cursor: resumeCursor,
732
+ items_returned: itemsReturned,
733
+ bytes_returned: bytesReturned,
734
+ pages_fetched: pagesFetched,
735
+ };
736
+ }
737
+ function emptyPage() {
738
+ return { items: [], next_cursor: null };
739
+ }
740
+ function readItems(page) {
741
+ if (typeof page === "object" && page !== null && "items" in page) {
742
+ const value = page.items;
743
+ if (Array.isArray(value))
744
+ return value;
745
+ }
746
+ return [];
747
+ }
748
+ function readNextCursor(page) {
749
+ if (typeof page === "object" && page !== null && "next_cursor" in page) {
750
+ const value = page.next_cursor;
751
+ return typeof value === "string" ? value : null;
752
+ }
753
+ return null;
754
+ }
755
+ function readPageRedactionCount(page) {
756
+ if (typeof page === "object" && page !== null && "redaction_count" in page) {
757
+ const value = page.redaction_count;
758
+ if (typeof value === "number" && Number.isFinite(value) && value > 0)
759
+ return value;
760
+ }
761
+ return 0;
762
+ }
763
+ function parseNullablePositiveInt(value) {
764
+ if (!value)
765
+ return null;
766
+ const parsed = Number(value);
767
+ return Number.isInteger(parsed) && parsed >= 0 ? parsed : null;
768
+ }
769
+ function decodeUtf8Lossy(bytes) {
770
+ return new TextDecoder("utf-8").decode(bytes);
771
+ }
772
+ function decodeUtf8Strict(bytes) {
773
+ try {
774
+ return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
775
+ }
776
+ catch {
777
+ return null;
778
+ }
779
+ }
780
+ function encodePathSegment(segment) {
781
+ if (!segment || segment.includes("/") || segment.includes("\0")) {
782
+ throw new InvalidParamsError("Elaris path segment must be non-empty and must not contain slashes");
783
+ }
784
+ return encodeURIComponent(segment);
785
+ }
786
+ function safeDecodeURIComponent(value) {
787
+ try {
788
+ return decodeURIComponent(value);
789
+ }
790
+ catch {
791
+ throw new InvalidParamsError("Elaris path contains invalid percent encoding");
792
+ }
793
+ }
794
+ function parseRetryAfter(value) {
795
+ if (!value)
796
+ return null;
797
+ const trimmed = value.trim();
798
+ if (/^\d+$/.test(trimmed)) {
799
+ return { retry_after_ms: Number(trimmed) * 1000, retry_class: "retry_after_delta" };
800
+ }
801
+ const dateMs = Date.parse(trimmed);
802
+ if (Number.isFinite(dateMs)) {
803
+ return { retry_after_ms: Math.max(0, dateMs - Date.now()), retry_class: "retry_after_date" };
804
+ }
805
+ return null;
806
+ }
807
+ function clamp(value, min, max) {
808
+ return Math.min(max, Math.max(min, value));
809
+ }
810
+ function defaultSleep(ms, signal) {
811
+ if (signal?.aborted)
812
+ return Promise.reject(new CancellationError());
813
+ return new Promise((resolve, reject) => {
814
+ const onAbort = () => {
815
+ clearTimeout(timeout);
816
+ reject(new CancellationError());
817
+ };
818
+ const timeout = setTimeout(() => {
819
+ signal?.removeEventListener("abort", onAbort);
820
+ resolve();
821
+ }, ms);
822
+ signal?.addEventListener("abort", onAbort, { once: true });
823
+ });
824
+ }
825
+ //# sourceMappingURL=client.js.map