@vercel/factory 0.0.14 → 0.0.16

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 (510) hide show
  1. package/CHANGELOG.md +356 -0
  2. package/README.md +96 -2
  3. package/dist/agent-routes.d.mts +113 -0
  4. package/dist/agent-routes.mjs +91 -0
  5. package/dist/agent-routes.mjs.map +1 -0
  6. package/dist/api-contracts.d.mts +1768 -0
  7. package/dist/api-contracts.mjs +119 -0
  8. package/dist/api-contracts.mjs.map +1 -0
  9. package/dist/api-images.d.mts +30 -0
  10. package/dist/api-images.mjs +28 -0
  11. package/dist/api-images.mjs.map +1 -0
  12. package/dist/api-task-graph.mjs +57 -0
  13. package/dist/api-task-graph.mjs.map +1 -0
  14. package/dist/api.d.mts +111 -216
  15. package/dist/api.mjs +1063 -99
  16. package/dist/api.mjs.map +1 -1
  17. package/dist/approval-access.d.mts +39 -0
  18. package/dist/approval-access.mjs +62 -0
  19. package/dist/approval-access.mjs.map +1 -0
  20. package/dist/approval-contracts.d.mts +698 -0
  21. package/dist/approval-contracts.mjs +27 -0
  22. package/dist/approval-contracts.mjs.map +1 -0
  23. package/dist/approval.d.mts +49 -0
  24. package/dist/approval.mjs +39 -0
  25. package/dist/approval.mjs.map +1 -0
  26. package/dist/blob/artifacts.d.mts +37 -0
  27. package/dist/blob/artifacts.mjs +45 -0
  28. package/dist/blob/artifacts.mjs.map +1 -0
  29. package/dist/blob/index.d.mts +84 -12
  30. package/dist/blob/index.mjs +179 -45
  31. package/dist/blob/index.mjs.map +1 -1
  32. package/dist/budget.d.mts +115 -0
  33. package/dist/budget.mjs +147 -0
  34. package/dist/budget.mjs.map +1 -0
  35. package/dist/budgets.d.mts +4 -0
  36. package/dist/budgets.mjs +4 -0
  37. package/dist/build-factory.d.mts +7 -4
  38. package/dist/build-factory.mjs +2 -1
  39. package/dist/build-factory.mjs.map +1 -1
  40. package/dist/change-verification/brief.d.mts +9 -0
  41. package/dist/change-verification/brief.mjs +13 -0
  42. package/dist/change-verification/brief.mjs.map +1 -0
  43. package/dist/change-verification/dispatch.d.mts +37 -0
  44. package/dist/change-verification/dispatch.mjs +83 -0
  45. package/dist/change-verification/dispatch.mjs.map +1 -0
  46. package/dist/change-verification/eve-tool.d.mts +61 -0
  47. package/dist/change-verification/eve-tool.mjs +89 -0
  48. package/dist/change-verification/eve-tool.mjs.map +1 -0
  49. package/dist/change-verification/result.mjs +130 -0
  50. package/dist/change-verification/result.mjs.map +1 -0
  51. package/dist/changes/eve-record-change.d.mts +56 -0
  52. package/dist/changes/eve-record-change.mjs +131 -0
  53. package/dist/changes/eve-record-change.mjs.map +1 -0
  54. package/dist/changes/presentation.d.mts +14 -0
  55. package/dist/changes.d.mts +24 -0
  56. package/dist/changes.mjs +29 -0
  57. package/dist/changes.mjs.map +1 -0
  58. package/dist/client-events.d.mts +25 -0
  59. package/dist/client-events.mjs +45 -0
  60. package/dist/client-events.mjs.map +1 -0
  61. package/dist/client-stream.d.mts +28 -0
  62. package/dist/client-stream.mjs +210 -0
  63. package/dist/client-stream.mjs.map +1 -0
  64. package/dist/client-transcript.d.mts +41 -0
  65. package/dist/client-transcript.mjs +233 -0
  66. package/dist/client-transcript.mjs.map +1 -0
  67. package/dist/client.d.mts +343 -0
  68. package/dist/client.mjs +366 -0
  69. package/dist/client.mjs.map +1 -0
  70. package/dist/code-review/contracts.d.mts +27 -0
  71. package/dist/code-review/eve-post-review.d.mts +70 -0
  72. package/dist/code-review/eve-post-review.mjs +195 -0
  73. package/dist/code-review/eve-post-review.mjs.map +1 -0
  74. package/dist/code-review/eve-review-comments.d.mts +75 -0
  75. package/dist/code-review/eve-review-comments.mjs +193 -0
  76. package/dist/code-review/eve-review-comments.mjs.map +1 -0
  77. package/dist/code-review/github-contracts.d.mts +10 -0
  78. package/dist/code-review/github-reporter.d.mts +46 -0
  79. package/dist/code-review/github-reporter.mjs +262 -0
  80. package/dist/code-review/github-reporter.mjs.map +1 -0
  81. package/dist/code-review/preparation.d.mts +34 -0
  82. package/dist/code-review/preparation.mjs +23 -0
  83. package/dist/code-review/preparation.mjs.map +1 -0
  84. package/dist/code-review/stall.d.mts +17 -0
  85. package/dist/code-review/stall.mjs +30 -0
  86. package/dist/code-review/stall.mjs.map +1 -0
  87. package/dist/code-review.d.mts +7 -0
  88. package/dist/code-review.mjs +5 -0
  89. package/dist/communication.d.mts +9 -0
  90. package/dist/communication.mjs +9 -0
  91. package/dist/connectors/github.d.mts +26 -0
  92. package/dist/connectors/github.mjs +55 -0
  93. package/dist/connectors/github.mjs.map +1 -0
  94. package/dist/connectors/index.d.mts +35 -3
  95. package/dist/connectors/index.mjs +3 -52
  96. package/dist/connectors/index.mjs.map +1 -1
  97. package/dist/connectors/outbox.d.mts +34 -0
  98. package/dist/connectors/outbox.mjs +50 -0
  99. package/dist/connectors/outbox.mjs.map +1 -0
  100. package/dist/connectors/slack-approval-blocks.mjs +136 -0
  101. package/dist/connectors/slack-approval-blocks.mjs.map +1 -0
  102. package/dist/connectors/slack-approvals.d.mts +29 -0
  103. package/dist/connectors/slack-approvals.mjs +346 -0
  104. package/dist/connectors/slack-approvals.mjs.map +1 -0
  105. package/dist/connectors/slack.d.mts +35 -52
  106. package/dist/connectors/slack.mjs +13 -85
  107. package/dist/connectors/slack.mjs.map +1 -1
  108. package/dist/deepsec/eve-tool.d.mts +110 -0
  109. package/dist/deepsec/eve-tool.mjs +166 -0
  110. package/dist/deepsec/eve-tool.mjs.map +1 -0
  111. package/dist/deepsec/finding.d.mts +84 -0
  112. package/dist/deepsec/finding.mjs +56 -0
  113. package/dist/deepsec/finding.mjs.map +1 -0
  114. package/dist/deepsec.d.mts +3 -0
  115. package/dist/delivery-metrics/metrics.d.mts +93 -0
  116. package/dist/delivery-metrics/metrics.mjs +200 -0
  117. package/dist/delivery-metrics/metrics.mjs.map +1 -0
  118. package/dist/delivery-metrics.d.mts +2 -0
  119. package/dist/delivery-metrics.mjs +2 -0
  120. package/dist/dispatch.d.mts +152 -0
  121. package/dist/dispatch.mjs +199 -0
  122. package/dist/dispatch.mjs.map +1 -0
  123. package/dist/errors.d.mts +15 -0
  124. package/dist/errors.mjs +38 -0
  125. package/dist/errors.mjs.map +1 -0
  126. package/dist/eve/index.d.mts +209 -1277
  127. package/dist/eve/index.mjs +312 -1073
  128. package/dist/eve/index.mjs.map +1 -1
  129. package/dist/eve/invoke.d.mts +144 -0
  130. package/dist/eve/invoke.mjs +254 -0
  131. package/dist/eve/invoke.mjs.map +1 -0
  132. package/dist/eve/session-client.d.mts +186 -0
  133. package/dist/eve/session-client.mjs +245 -0
  134. package/dist/eve/session-client.mjs.map +1 -0
  135. package/dist/eve/task-execution.d.mts +380 -0
  136. package/dist/eve/task-execution.mjs +73 -0
  137. package/dist/eve/task-execution.mjs.map +1 -0
  138. package/dist/eve/task-session.d.mts +129 -0
  139. package/dist/eve/task-session.mjs +245 -0
  140. package/dist/eve/task-session.mjs.map +1 -0
  141. package/dist/eve/transcript.d.mts +37 -0
  142. package/dist/eve/transcript.mjs +69 -0
  143. package/dist/eve/transcript.mjs.map +1 -0
  144. package/dist/execution-public.d.mts +8 -0
  145. package/dist/execution-public.mjs +7 -0
  146. package/dist/execution.d.mts +183 -0
  147. package/dist/execution.mjs +223 -0
  148. package/dist/execution.mjs.map +1 -0
  149. package/dist/finding-remediation/admission.d.mts +53 -0
  150. package/dist/finding-remediation/admission.mjs +90 -0
  151. package/dist/finding-remediation/admission.mjs.map +1 -0
  152. package/dist/finding-remediation/brief.d.mts +14 -0
  153. package/dist/finding-remediation/brief.mjs +25 -0
  154. package/dist/finding-remediation/brief.mjs.map +1 -0
  155. package/dist/finding-remediation/eve-tool.d.mts +29 -0
  156. package/dist/finding-remediation/eve-tool.mjs +34 -0
  157. package/dist/finding-remediation/eve-tool.mjs.map +1 -0
  158. package/dist/findings/fingerprint.d.mts +14 -0
  159. package/dist/findings/fingerprint.mjs +28 -0
  160. package/dist/findings/fingerprint.mjs.map +1 -0
  161. package/dist/findings.d.mts +7 -0
  162. package/dist/findings.mjs +6 -0
  163. package/dist/github-app.d.mts +54 -0
  164. package/dist/github-app.mjs +121 -0
  165. package/dist/github-app.mjs.map +1 -0
  166. package/dist/github-publication.d.mts +199 -0
  167. package/dist/github-publication.mjs +442 -0
  168. package/dist/github-publication.mjs.map +1 -0
  169. package/dist/github-transfer.d.mts +81 -0
  170. package/dist/github-transfer.mjs +273 -0
  171. package/dist/github-transfer.mjs.map +1 -0
  172. package/dist/github.d.mts +446 -2
  173. package/dist/github.mjs +357 -56
  174. package/dist/github.mjs.map +1 -1
  175. package/dist/image-input.d.mts +51 -0
  176. package/dist/image-input.mjs +63 -0
  177. package/dist/image-input.mjs.map +1 -0
  178. package/dist/inbox-activity.d.mts +53 -0
  179. package/dist/inbox-activity.mjs +41 -0
  180. package/dist/inbox-activity.mjs.map +1 -0
  181. package/dist/index.d.mts +16 -484
  182. package/dist/index.mjs +15 -522
  183. package/dist/intake-contracts.d.mts +55 -0
  184. package/dist/intake-contracts.mjs +33 -0
  185. package/dist/intake-contracts.mjs.map +1 -0
  186. package/dist/integrations/deepsec.d.mts +5 -0
  187. package/dist/integrations/deepsec.mjs +3 -0
  188. package/dist/integrations/github.d.mts +11 -0
  189. package/dist/integrations/github.mjs +9 -0
  190. package/dist/integrations/slack.d.mts +5 -0
  191. package/dist/integrations/slack.mjs +5 -0
  192. package/dist/integrations/vercel.d.mts +5 -0
  193. package/dist/integrations/vercel.mjs +4 -0
  194. package/dist/merge-resolution/contracts.d.mts +17 -0
  195. package/dist/merge-resolution/contracts.mjs +19 -0
  196. package/dist/merge-resolution/contracts.mjs.map +1 -0
  197. package/dist/merge-resolution/eve-tools.d.mts +47 -0
  198. package/dist/merge-resolution/eve-tools.mjs +122 -0
  199. package/dist/merge-resolution/eve-tools.mjs.map +1 -0
  200. package/dist/model-settings.d.mts +41 -0
  201. package/dist/model-settings.mjs +35 -0
  202. package/dist/model-settings.mjs.map +1 -0
  203. package/dist/multi-repository-changes/coordination.d.mts +49 -0
  204. package/dist/multi-repository-changes/coordination.mjs +115 -0
  205. package/dist/multi-repository-changes/coordination.mjs.map +1 -0
  206. package/dist/planning/cancellation.mjs +82 -0
  207. package/dist/planning/cancellation.mjs.map +1 -0
  208. package/dist/planning/configuration.d.mts +23 -0
  209. package/dist/planning/configuration.mjs +56 -0
  210. package/dist/planning/configuration.mjs.map +1 -0
  211. package/dist/planning/contracts.d.mts +136 -0
  212. package/dist/planning/contracts.mjs +42 -0
  213. package/dist/planning/contracts.mjs.map +1 -0
  214. package/dist/planning/dependencies.mjs +44 -0
  215. package/dist/planning/dependencies.mjs.map +1 -0
  216. package/dist/planning/effects.mjs +122 -0
  217. package/dist/planning/effects.mjs.map +1 -0
  218. package/dist/planning/reconcile.mjs +279 -0
  219. package/dist/planning/reconcile.mjs.map +1 -0
  220. package/dist/planning/runtime.d.mts +27 -0
  221. package/dist/planning/runtime.mjs +25 -0
  222. package/dist/planning/runtime.mjs.map +1 -0
  223. package/dist/planning/state.mjs +92 -0
  224. package/dist/planning/state.mjs.map +1 -0
  225. package/dist/planning/turns.mjs +262 -0
  226. package/dist/planning/turns.mjs.map +1 -0
  227. package/dist/planning/validation.mjs +106 -0
  228. package/dist/planning/validation.mjs.map +1 -0
  229. package/dist/postgres/index.d.mts +48 -1
  230. package/dist/postgres/index.mjs +45 -3
  231. package/dist/postgres/index.mjs.map +1 -1
  232. package/dist/presets/software-development/approval.d.mts +14 -0
  233. package/dist/presets/software-development/approval.mjs +21 -0
  234. package/dist/presets/software-development/approval.mjs.map +1 -0
  235. package/dist/presets/software-development/deepsec-brief.d.mts +8 -0
  236. package/dist/presets/software-development/deepsec-brief.mjs +14 -0
  237. package/dist/presets/software-development/deepsec-brief.mjs.map +1 -0
  238. package/dist/presets/software-development/dispatch.d.mts +56 -0
  239. package/dist/presets/software-development/dispatch.mjs +67 -0
  240. package/dist/presets/software-development/dispatch.mjs.map +1 -0
  241. package/dist/presets/software-development/eve-delegation-policy.d.mts +7 -0
  242. package/dist/presets/software-development/eve-delegation-policy.mjs +34 -0
  243. package/dist/presets/software-development/eve-delegation-policy.mjs.map +1 -0
  244. package/dist/presets/software-development/eve.d.mts +18 -0
  245. package/dist/presets/software-development/eve.mjs +19 -0
  246. package/dist/presets/software-development/eve.mjs.map +1 -0
  247. package/dist/presets/software-development/finish-task-policy.d.mts +7 -0
  248. package/dist/presets/software-development/finish-task-policy.mjs +9 -0
  249. package/dist/presets/software-development/finish-task-policy.mjs.map +1 -0
  250. package/dist/presets/software-development/recovery.d.mts +32 -0
  251. package/dist/presets/software-development/recovery.mjs +120 -0
  252. package/dist/presets/software-development/recovery.mjs.map +1 -0
  253. package/dist/presets/software-development/task-communication.d.mts +24 -0
  254. package/dist/presets/software-development/task-communication.mjs +157 -0
  255. package/dist/presets/software-development/task-communication.mjs.map +1 -0
  256. package/dist/presets/software-development.d.mts +10 -0
  257. package/dist/presets/software-development.mjs +9 -0
  258. package/dist/pull-requests/contracts.d.mts +72 -0
  259. package/dist/pull-requests/eve-fetch.d.mts +57 -0
  260. package/dist/pull-requests/eve-fetch.mjs +151 -0
  261. package/dist/pull-requests/eve-fetch.mjs.map +1 -0
  262. package/dist/pull-requests/github-label-manager.d.mts +27 -0
  263. package/dist/pull-requests/github-label-manager.mjs +40 -0
  264. package/dist/pull-requests/github-label-manager.mjs.map +1 -0
  265. package/dist/pull-requests/github-publisher.d.mts +67 -0
  266. package/dist/pull-requests/github-publisher.mjs +405 -0
  267. package/dist/pull-requests/github-publisher.mjs.map +1 -0
  268. package/dist/pull-requests.d.mts +6 -0
  269. package/dist/pull-requests.mjs +4 -0
  270. package/dist/receipts.d.mts +4 -0
  271. package/dist/receipts.mjs +3 -0
  272. package/dist/repositories.d.mts +18 -0
  273. package/dist/repositories.mjs +33 -0
  274. package/dist/repositories.mjs.map +1 -0
  275. package/dist/sandbox/command.d.mts +18 -0
  276. package/dist/sandbox/execution-abort.d.mts +16 -0
  277. package/dist/sandbox/execution-abort.mjs +49 -0
  278. package/dist/sandbox/execution-abort.mjs.map +1 -0
  279. package/dist/sandbox/execution-environment.d.mts +25 -0
  280. package/dist/sandbox/execution-run-ledger.d.mts +115 -0
  281. package/dist/sandbox/execution-run-ledger.mjs +209 -0
  282. package/dist/sandbox/execution-run-ledger.mjs.map +1 -0
  283. package/dist/sandbox/execution.d.mts +54 -0
  284. package/dist/sandbox/execution.mjs +228 -0
  285. package/dist/sandbox/execution.mjs.map +1 -0
  286. package/dist/sandbox/harness-runner.d.mts +79 -0
  287. package/dist/sandbox/harness-runner.mjs +162 -0
  288. package/dist/sandbox/harness-runner.mjs.map +1 -0
  289. package/dist/sandbox/index.d.mts +10 -0
  290. package/dist/sandbox/index.mjs +7 -0
  291. package/dist/sandbox/task-environment.d.mts +50 -0
  292. package/dist/sandbox/task-environment.mjs +140 -0
  293. package/dist/sandbox/task-environment.mjs.map +1 -0
  294. package/dist/sandbox/workspace.d.mts +29 -0
  295. package/dist/sandbox/workspace.mjs +28 -0
  296. package/dist/sandbox/workspace.mjs.map +1 -0
  297. package/dist/schema/agent-route.d.mts +40 -0
  298. package/dist/schema/agent-route.mjs +33 -0
  299. package/dist/schema/agent-route.mjs.map +1 -0
  300. package/dist/schema/answer.d.mts +23 -0
  301. package/dist/schema/answer.mjs +21 -0
  302. package/dist/schema/answer.mjs.map +1 -0
  303. package/dist/schema/budget.d.mts +38 -0
  304. package/dist/schema/budget.mjs +30 -0
  305. package/dist/schema/budget.mjs.map +1 -0
  306. package/dist/schema/catalog.mjs +72 -0
  307. package/dist/schema/catalog.mjs.map +1 -0
  308. package/dist/schema/change.d.mts +117 -0
  309. package/dist/schema/change.mjs +68 -0
  310. package/dist/schema/change.mjs.map +1 -0
  311. package/dist/schema/common.d.mts +33 -0
  312. package/dist/{id-BLIkCVue.mjs → schema/common.mjs} +7 -16
  313. package/dist/schema/common.mjs.map +1 -0
  314. package/dist/schema/communication.d.mts +52 -0
  315. package/dist/{communication-Kd9nU5RP.mjs → schema/communication.mjs} +8 -3
  316. package/dist/schema/communication.mjs.map +1 -0
  317. package/dist/schema/execution.d.mts +101 -0
  318. package/dist/schema/execution.mjs +86 -0
  319. package/dist/schema/execution.mjs.map +1 -0
  320. package/dist/schema/factory-config.d.mts +122 -0
  321. package/dist/schema/factory-config.mjs +90 -0
  322. package/dist/schema/factory-config.mjs.map +1 -0
  323. package/dist/schema/finding.d.mts +125 -0
  324. package/dist/schema/finding.mjs +67 -0
  325. package/dist/schema/finding.mjs.map +1 -0
  326. package/dist/schema/id.d.mts +43 -0
  327. package/dist/schema/id.mjs +32 -0
  328. package/dist/schema/id.mjs.map +1 -0
  329. package/dist/schema/outbox.d.mts +240 -0
  330. package/dist/schema/outbox.mjs +53 -0
  331. package/dist/schema/outbox.mjs.map +1 -0
  332. package/dist/schema/question-route.mjs +16 -0
  333. package/dist/schema/question-route.mjs.map +1 -0
  334. package/dist/schema/receipt.d.mts +81 -0
  335. package/dist/schema/receipt.mjs +94 -0
  336. package/dist/schema/receipt.mjs.map +1 -0
  337. package/dist/schema/repository.d.mts +30 -0
  338. package/dist/schema/repository.mjs +29 -0
  339. package/dist/schema/repository.mjs.map +1 -0
  340. package/dist/schema/session.d.mts +136 -0
  341. package/dist/schema/session.mjs +54 -0
  342. package/dist/schema/session.mjs.map +1 -0
  343. package/dist/schema/signal.d.mts +105 -0
  344. package/dist/schema/signal.mjs +81 -0
  345. package/dist/schema/signal.mjs.map +1 -0
  346. package/dist/schema/slack-pr-notifications.d.mts +12 -0
  347. package/dist/schema/slack-pr-notifications.mjs +11 -0
  348. package/dist/schema/slack-pr-notifications.mjs.map +1 -0
  349. package/dist/schema/stored-session.mjs +10 -0
  350. package/dist/schema/stored-session.mjs.map +1 -0
  351. package/dist/schema/stored-task.mjs +20 -0
  352. package/dist/schema/stored-task.mjs.map +1 -0
  353. package/dist/schema/task-effect.d.mts +39 -0
  354. package/dist/schema/task-effect.mjs +29 -0
  355. package/dist/schema/task-effect.mjs.map +1 -0
  356. package/dist/schema/task-graph.d.mts +3173 -0
  357. package/dist/schema/task-graph.mjs +97 -0
  358. package/dist/schema/task-graph.mjs.map +1 -0
  359. package/dist/schema/task-message.d.mts +254 -0
  360. package/dist/schema/task-message.mjs +189 -0
  361. package/dist/schema/task-message.mjs.map +1 -0
  362. package/dist/schema/task.d.mts +273 -0
  363. package/dist/schema/task.mjs +200 -0
  364. package/dist/schema/task.mjs.map +1 -0
  365. package/dist/schema/transcript.d.mts +176 -0
  366. package/dist/schema/transcript.mjs +87 -0
  367. package/dist/schema/transcript.mjs.map +1 -0
  368. package/dist/schema/transitions.d.mts +50 -0
  369. package/dist/schema/transitions.mjs +303 -0
  370. package/dist/schema/transitions.mjs.map +1 -0
  371. package/dist/schema/work.d.mts +150 -0
  372. package/dist/schema/work.mjs +102 -0
  373. package/dist/schema/work.mjs.map +1 -0
  374. package/dist/session-previews.d.mts +76 -0
  375. package/dist/session-previews.mjs +55 -0
  376. package/dist/session-previews.mjs.map +1 -0
  377. package/dist/session-review.d.mts +120 -0
  378. package/dist/session-review.mjs +79 -0
  379. package/dist/session-review.mjs.map +1 -0
  380. package/dist/signal-triage.d.mts +20 -0
  381. package/dist/signal-triage.mjs +85 -0
  382. package/dist/signal-triage.mjs.map +1 -0
  383. package/dist/signals.d.mts +20 -0
  384. package/dist/signals.mjs +19 -0
  385. package/dist/signals.mjs.map +1 -0
  386. package/dist/stall.d.mts +41 -0
  387. package/dist/stall.mjs +83 -0
  388. package/dist/stall.mjs.map +1 -0
  389. package/dist/storage.d.mts +4 -0
  390. package/dist/storage.mjs +4 -0
  391. package/dist/store/driver.d.mts +65 -0
  392. package/dist/store/driver.mjs +42 -0
  393. package/dist/store/driver.mjs.map +1 -0
  394. package/dist/store/engine.d.mts +683 -0
  395. package/dist/store/engine.mjs +2309 -0
  396. package/dist/store/engine.mjs.map +1 -0
  397. package/dist/store/memory.d.mts +24 -0
  398. package/dist/store/memory.mjs +69 -0
  399. package/dist/store/memory.mjs.map +1 -0
  400. package/dist/store/slack-pr-notifications.d.mts +44 -0
  401. package/dist/store/slack-pr-notifications.mjs +121 -0
  402. package/dist/store/slack-pr-notifications.mjs.map +1 -0
  403. package/dist/store/task-effects.d.mts +38 -0
  404. package/dist/store/task-effects.mjs +118 -0
  405. package/dist/store/task-effects.mjs.map +1 -0
  406. package/dist/store/task-graphs.d.mts +60 -0
  407. package/dist/store/task-graphs.mjs +212 -0
  408. package/dist/store/task-graphs.mjs.map +1 -0
  409. package/dist/store/task-messages.d.mts +136 -0
  410. package/dist/store/task-messages.mjs +475 -0
  411. package/dist/store/task-messages.mjs.map +1 -0
  412. package/dist/store/task-work.d.mts +180 -0
  413. package/dist/store/task-work.mjs +137 -0
  414. package/dist/store/task-work.mjs.map +1 -0
  415. package/dist/store/work-notifications.d.mts +19 -0
  416. package/dist/store/work-notifications.mjs +48 -0
  417. package/dist/store/work-notifications.mjs.map +1 -0
  418. package/dist/sweep.d.mts +79 -0
  419. package/dist/sweep.mjs +171 -0
  420. package/dist/sweep.mjs.map +1 -0
  421. package/dist/task-communication.d.mts +35 -0
  422. package/dist/task-communication.mjs +47 -0
  423. package/dist/task-communication.mjs.map +1 -0
  424. package/dist/task-graph-view.d.mts +267 -0
  425. package/dist/task-graph-view.mjs +17 -0
  426. package/dist/task-graph-view.mjs.map +1 -0
  427. package/dist/task-message-processing.d.mts +60 -0
  428. package/dist/task-message-processing.mjs +200 -0
  429. package/dist/task-message-processing.mjs.map +1 -0
  430. package/dist/task-protocols.d.mts +80 -0
  431. package/dist/task-protocols.mjs +47 -0
  432. package/dist/task-protocols.mjs.map +1 -0
  433. package/dist/tasks.d.mts +17 -0
  434. package/dist/tasks.mjs +17 -0
  435. package/dist/vercel-git.d.mts +53 -0
  436. package/dist/vercel-git.mjs +344 -0
  437. package/dist/vercel-git.mjs.map +1 -0
  438. package/dist/vercel-github-api.d.mts +103 -0
  439. package/dist/vercel-github-api.mjs +363 -0
  440. package/dist/vercel-github-api.mjs.map +1 -0
  441. package/dist/vercel.d.mts +34 -2
  442. package/dist/vercel.mjs +49 -3
  443. package/dist/vercel.mjs.map +1 -1
  444. package/dist/work-triage/eve-tool.d.mts +29 -0
  445. package/dist/work-triage/eve-tool.mjs +32 -0
  446. package/dist/work-triage/eve-tool.mjs.map +1 -0
  447. package/dist/work-triage/find-existing-work.d.mts +32 -0
  448. package/dist/work-triage/find-existing-work.mjs +31 -0
  449. package/dist/work-triage/find-existing-work.mjs.map +1 -0
  450. package/dist/work-triage/github.d.mts +15 -0
  451. package/dist/work-triage/github.mjs +14 -0
  452. package/dist/work-triage/github.mjs.map +1 -0
  453. package/dist/work-triage.d.mts +4 -0
  454. package/dist/work-triage.mjs +3 -0
  455. package/dist/workflows.d.mts +146 -0
  456. package/dist/workflows.mjs +139 -0
  457. package/dist/workflows.mjs.map +1 -0
  458. package/dist/workspace-diff-assembly.d.mts +33 -0
  459. package/dist/workspace-diff-assembly.mjs +95 -0
  460. package/dist/workspace-diff-assembly.mjs.map +1 -0
  461. package/dist/workspace-diff.d.mts +90 -0
  462. package/dist/workspace-diff.mjs +61 -0
  463. package/dist/workspace-diff.mjs.map +1 -0
  464. package/dist/workspace-files-git.d.mts +15 -0
  465. package/dist/workspace-files-git.mjs +61 -0
  466. package/dist/workspace-files-git.mjs.map +1 -0
  467. package/dist/workspace-files.d.mts +107 -0
  468. package/dist/workspace-files.mjs +74 -0
  469. package/dist/workspace-files.mjs.map +1 -0
  470. package/dist/workspace-snapshot.d.mts +26 -0
  471. package/dist/workspace-snapshot.mjs +80 -0
  472. package/dist/workspace-snapshot.mjs.map +1 -0
  473. package/docs/getting-started.md +104 -0
  474. package/docs/index.md +100 -0
  475. package/docs/recipes/cancellation.md +215 -0
  476. package/docs/recipes/custom-workflow.md +153 -0
  477. package/docs/recipes/dependent-tasks.md +207 -0
  478. package/docs/recipes/eve-agent.md +277 -0
  479. package/docs/recipes/human-input.md +204 -0
  480. package/docs/recipes/persistence-recovery.md +268 -0
  481. package/docs/recipes/retry-recovery.md +241 -0
  482. package/docs/recipes/task-messaging.md +215 -0
  483. package/docs/recipes/typed-eve-result.md +161 -0
  484. package/docs/runtime-integration.md +137 -0
  485. package/package.json +142 -46
  486. package/dist/approval-JX2Px9IC.mjs +0 -132
  487. package/dist/approval-JX2Px9IC.mjs.map +0 -1
  488. package/dist/budget-DzSiIA4t.mjs +0 -42
  489. package/dist/budget-DzSiIA4t.mjs.map +0 -1
  490. package/dist/change-D2U6v7Ek.mjs +0 -554
  491. package/dist/change-D2U6v7Ek.mjs.map +0 -1
  492. package/dist/communication-Kd9nU5RP.mjs.map +0 -1
  493. package/dist/coordination-Cq08hb1l.mjs +0 -76
  494. package/dist/coordination-Cq08hb1l.mjs.map +0 -1
  495. package/dist/dispatch-BaZS3PT8.d.mts +0 -76
  496. package/dist/driver-BC0Mt5KG.d.mts +0 -34
  497. package/dist/driver-Bbd25rNM.mjs +0 -23
  498. package/dist/driver-Bbd25rNM.mjs.map +0 -1
  499. package/dist/engine-DFHU2Pe-.d.mts +0 -781
  500. package/dist/engine-WaUM2cGA.mjs +0 -1068
  501. package/dist/engine-WaUM2cGA.mjs.map +0 -1
  502. package/dist/factory-config-BoRXOw43.mjs +0 -50
  503. package/dist/factory-config-BoRXOw43.mjs.map +0 -1
  504. package/dist/factory-config-D2yU3G0c.d.mts +0 -58
  505. package/dist/github-C5HNBN6p.d.mts +0 -279
  506. package/dist/id-BLIkCVue.mjs.map +0 -1
  507. package/dist/index-Bw6hggoH.d.mts +0 -40
  508. package/dist/index.mjs.map +0 -1
  509. package/dist/task-CcOyOJ3k.mjs +0 -154
  510. package/dist/task-CcOyOJ3k.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"github.mjs","names":[],"sources":["../src/github.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport { z } from \"zod\";\nimport type { NormalizedSignal, WebhookEvent } from \"./connectors/index\";\n\nconst gitHubApiUrl = \"https://api.github.com\";\nconst repositorySlugPattern = /^[^/\\s]+\\/[^/\\s]+$/;\n\nexport interface GitHubRepositoryRequest {\n repository: string;\n token: string;\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface CreatePullRequestInput extends GitHubRepositoryRequest {\n title: string;\n head: string;\n base: string;\n body?: string;\n draft?: boolean;\n}\n\nexport interface CreatedPullRequest {\n prNumber: number;\n prUrl: string;\n}\n\nexport type ReviewCommentAuthorPolicy = \"write\" | \"any\";\n\ninterface ReviewCommentTrustInput {\n /** Defaults to `write`. Use `any` only when untrusted review text is handled as data. */\n authorPolicy?: ReviewCommentAuthorPolicy;\n}\n\nexport interface ReadReviewCommentInput extends GitHubRepositoryRequest, ReviewCommentTrustInput {\n commentId: number;\n}\n\nexport interface GitHubReviewComment {\n id: number;\n body: string;\n url: string;\n author: string;\n inReplyToId: number | null;\n}\n\nexport interface AnswerReviewCommentInput\n extends GitHubRepositoryRequest,\n ReviewCommentTrustInput {\n pullRequestNumber: number;\n commentId: number;\n body: string;\n}\n\nexport interface ReadPullRequestHeadInput extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n}\n\nexport interface GitHubPullRequestHead {\n branch: string;\n sha: string;\n repository: string;\n}\n\nexport interface GitHubPullRequest {\n number: number;\n url: string;\n author: string;\n state: \"open\" | \"closed\";\n}\n\nexport type PullRequestReviewEvent = \"APPROVE\" | \"REQUEST_CHANGES\" | \"COMMENT\";\n\nexport interface PullRequestReviewComment {\n path: string;\n line: number;\n body: string;\n}\n\nexport interface SubmitPullRequestReviewInput extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n commitId: string;\n event: PullRequestReviewEvent;\n body: string;\n comments?: readonly PullRequestReviewComment[];\n}\n\nexport interface SubmittedPullRequestReview {\n id: number;\n url: string;\n state: string;\n}\n\nexport interface GitHubIssueComment {\n id: number;\n body: string;\n url: string;\n author: string;\n authorType: \"Bot\" | \"User\" | \"Organization\";\n}\n\nexport interface ListPullRequestCommentsInput extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n}\n\nexport interface CreatePullRequestCommentInput extends ListPullRequestCommentsInput {\n body: string;\n}\n\nexport interface UpdatePullRequestCommentInput extends GitHubRepositoryRequest {\n commentId: number;\n body: string;\n}\n\nexport interface PullRequestLabelInput extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n label: string;\n}\n\nexport interface ConflictedPullRequest {\n prNumber: number;\n prUrl: string;\n headBranch: string;\n headSha: string;\n baseBranch: string;\n baseSha: string;\n}\n\nexport type ListConflictedPullRequestsInput = GitHubRepositoryRequest;\n\nexport type CheckRunStatus = \"queued\" | \"in_progress\" | \"completed\";\nexport type GitHubCheckRunStatus = CheckRunStatus | \"waiting\" | \"requested\" | \"pending\";\nexport type CheckRunConclusion =\n | \"action_required\"\n | \"cancelled\"\n | \"failure\"\n | \"neutral\"\n | \"skipped\"\n | \"success\"\n | \"timed_out\";\nexport type CheckRunAnnotationLevel = \"notice\" | \"warning\" | \"failure\";\n\nexport interface CheckRunAnnotation {\n path: string;\n startLine: number;\n endLine?: number;\n startColumn?: number;\n endColumn?: number;\n annotationLevel: CheckRunAnnotationLevel;\n message: string;\n title?: string;\n rawDetails?: string;\n}\n\nexport interface CheckRunOutput {\n title: string;\n summary: string;\n text?: string;\n annotations?: readonly CheckRunAnnotation[];\n}\n\ninterface CheckRunFields {\n status?: CheckRunStatus;\n conclusion?: CheckRunConclusion;\n detailsUrl?: string;\n externalId?: string;\n startedAt?: string;\n completedAt?: string;\n output?: CheckRunOutput;\n}\n\nexport interface CreateCheckRunInput extends GitHubRepositoryRequest, CheckRunFields {\n name: string;\n headSha: string;\n}\n\nexport interface UpdateCheckRunInput extends GitHubRepositoryRequest, CheckRunFields {\n checkRunId: number;\n name?: string;\n}\n\nexport interface ListCheckRunsForRefInput extends GitHubRepositoryRequest {\n ref: string;\n checkName?: string;\n}\n\nexport interface GitHubCheckRun {\n id: number;\n name: string;\n headSha: string;\n status: GitHubCheckRunStatus;\n conclusion: CheckRunConclusion | \"stale\" | \"startup_failure\" | null;\n url: string | null;\n detailsUrl: string | null;\n externalId: string | null;\n startedAt: string | null;\n completedAt: string | null;\n}\n\nconst pullRequestSchema = z.object({\n number: z.number().int().positive(),\n html_url: z.url(),\n});\n\nconst readablePullRequestSchema = pullRequestSchema.extend({\n state: z.enum([\"open\", \"closed\"]),\n user: z.object({ login: z.string().min(1) }),\n});\n\nconst pullRequestHeadSchema = z.object({\n head: z.object({\n ref: z\n .string()\n .regex(/^[A-Za-z0-9][A-Za-z0-9._/-]*$/)\n .refine((value) => !value.includes(\"..\")),\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n repo: z.object({ full_name: z.string().min(1) }),\n }),\n});\n\nconst reviewCommentSchema = z.object({\n id: z.number().int().positive(),\n body: z.string(),\n html_url: z.url(),\n user: z.object({ login: z.string().min(1) }),\n in_reply_to_id: z.number().int().positive().nullish(),\n});\n\nconst submittedReviewSchema = z.object({\n id: z.number().int().positive(),\n html_url: z.url(),\n state: z.string().min(1),\n});\n\nconst issueCommentSchema = z.object({\n id: z.number().int().positive(),\n body: z.string(),\n html_url: z.url(),\n user: z.object({\n login: z.string().min(1),\n type: z.enum([\"Bot\", \"User\", \"Organization\"]),\n }),\n});\n\nconst checkRunSchema = z.object({\n id: z.number().int().positive(),\n name: z.string().min(1),\n head_sha: z.string().regex(/^[0-9a-f]{40}$/),\n status: z.enum([\"queued\", \"in_progress\", \"completed\", \"waiting\", \"requested\", \"pending\"]),\n conclusion: z\n .enum([\n \"action_required\",\n \"cancelled\",\n \"failure\",\n \"neutral\",\n \"skipped\",\n \"success\",\n \"timed_out\",\n \"stale\",\n \"startup_failure\",\n ])\n .nullable(),\n html_url: z.url().nullable(),\n details_url: z.url().nullable(),\n external_id: z.string().nullable(),\n started_at: z.string().nullable(),\n completed_at: z.string().nullable(),\n});\n\nconst checkRunsSchema = z.object({ check_runs: z.array(checkRunSchema) });\nconst labelsSchema = z.array(z.object({ name: z.string().min(1) }));\nconst pullRequestCandidateSchema = z.object({\n number: z.number().int().positive(),\n user: z.object({ type: z.string().min(1) }),\n head: z.object({ ref: z.string().min(1), repo: z.object({ full_name: z.string().min(1) }) }),\n});\nconst openPullRequestsSchema = z.array(pullRequestCandidateSchema);\nconst pullRequestDetailSchema = pullRequestCandidateSchema.extend({\n html_url: z.url(),\n mergeable: z.boolean().nullable(),\n mergeable_state: z.string().min(1),\n head: pullRequestCandidateSchema.shape.head.extend({ sha: z.string().min(1) }),\n base: z.object({ ref: z.string().min(1), sha: z.string().min(1) }),\n});\nconst collaboratorPermissionSchema = z.object({\n permission: z.enum([\"admin\", \"maintain\", \"write\", \"triage\", \"read\", \"none\"]),\n});\nconst writePermissions = new Set([\"admin\", \"maintain\", \"write\"]);\n\nexport class GitHubReviewCommentAuthorError extends Error {\n readonly author: string;\n\n constructor(author: string) {\n super(`GitHub user ${author} does not have write access to the repository`);\n this.name = \"GitHubReviewCommentAuthorError\";\n this.author = author;\n }\n}\n\n/** Create a pull request from an existing head branch. */\nexport async function createPullRequest(input: CreatePullRequestInput): Promise<CreatedPullRequest> {\n const pull = pullRequestSchema.parse(\n await gitHubRequest(input, \"/pulls\", {\n method: \"POST\",\n body: JSON.stringify({\n title: input.title,\n head: input.head,\n base: input.base,\n ...(input.body === undefined ? {} : { body: input.body }),\n ...(input.draft === undefined ? {} : { draft: input.draft }),\n }),\n }),\n );\n return { prNumber: pull.number, prUrl: pull.html_url };\n}\n\n/** Create a check run for one commit. Requires a GitHub App token with checks:write. */\nexport async function createCheckRun(input: CreateCheckRunInput): Promise<GitHubCheckRun> {\n if (input.status === \"completed\" && input.conclusion === undefined) {\n throw new Error(\"completed check runs require a conclusion\");\n }\n if (input.status !== \"completed\" && input.conclusion !== undefined) {\n throw new Error(\"creating a check run with a conclusion requires completed status\");\n }\n return parseCheckRun(\n await gitHubRequest(input, \"/check-runs\", {\n method: \"POST\",\n body: JSON.stringify({\n name: input.name,\n head_sha: commitSha(input.headSha),\n ...checkRunFields(input),\n }),\n }),\n );\n}\n\n/** Update a check run previously created by the authenticated GitHub App. */\nexport async function updateCheckRun(input: UpdateCheckRunInput): Promise<GitHubCheckRun> {\n if (input.status !== undefined && input.status !== \"completed\" && input.conclusion !== undefined) {\n throw new Error(\"a check run conclusion conflicts with an incomplete status\");\n }\n return parseCheckRun(\n await gitHubRequest(input, `/check-runs/${positiveInteger(input.checkRunId, \"checkRunId\")}`, {\n method: \"PATCH\",\n body: JSON.stringify({\n ...(input.name === undefined ? {} : { name: input.name }),\n ...checkRunFields(input),\n }),\n }),\n );\n}\n\n/** List check runs reported for a commit, branch, or tag. */\nexport async function listCheckRunsForRef(input: ListCheckRunsForRefInput): Promise<GitHubCheckRun[]> {\n const query = new URLSearchParams({ per_page: \"100\" });\n if (input.checkName !== undefined) query.set(\"check_name\", input.checkName);\n const response = checkRunsSchema.parse(\n await gitHubRequest(input, `/commits/${encodeURIComponent(input.ref)}/check-runs?${query.toString()}`),\n );\n return response.check_runs.map(parseCheckRun);\n}\n\n/** List every issue-style comment in a pull request conversation. */\nexport async function listPullRequestComments(\n input: ListPullRequestCommentsInput,\n): Promise<GitHubIssueComment[]> {\n const comments: GitHubIssueComment[] = [];\n for (let page = 1; ; page += 1) {\n const response = z.array(issueCommentSchema).parse(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/comments?per_page=100&page=${page}`,\n ),\n );\n comments.push(...response.map(parseIssueComment));\n if (response.length < 100) return comments;\n }\n}\n\n/** Add one issue-style comment to a pull request conversation. */\nexport async function createPullRequestComment(\n input: CreatePullRequestCommentInput,\n): Promise<GitHubIssueComment> {\n return parseIssueComment(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/comments`,\n { method: \"POST\", body: JSON.stringify({ body: input.body }) },\n ),\n );\n}\n\n/** Edit one issue-style pull request comment. */\nexport async function updatePullRequestComment(\n input: UpdatePullRequestCommentInput,\n): Promise<GitHubIssueComment> {\n return parseIssueComment(\n await gitHubRequest(input, `/issues/comments/${positiveInteger(input.commentId, \"commentId\")}`, {\n method: \"PATCH\",\n body: JSON.stringify({ body: input.body }),\n }),\n );\n}\n\n/** Read one inline review comment after applying the author policy, which requires write access by default. */\nexport async function readReviewComment(\n input: ReadReviewCommentInput,\n): Promise<GitHubReviewComment> {\n const comment = parseReviewComment(\n await gitHubRequest(input, `/pulls/comments/${positiveInteger(input.commentId, \"commentId\")}`),\n );\n await assertReviewCommentAuthor(input, comment.author);\n return comment;\n}\n\n/** Reply to an inline review comment after applying the author policy, which requires write access by default. */\nexport async function answerReviewComment(\n input: AnswerReviewCommentInput,\n): Promise<GitHubReviewComment> {\n await readReviewComment(input);\n return parseReviewComment(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/comments/${positiveInteger(input.commentId, \"commentId\")}/replies`,\n { method: \"POST\", body: JSON.stringify({ body: input.body }) },\n ),\n );\n}\n\n/** Submit a summary and optional inline comments against a reviewed pull request commit. */\nexport async function submitPullRequestReview(\n input: SubmitPullRequestReviewInput,\n): Promise<SubmittedPullRequestReview> {\n const commitId = z.string().regex(/^[0-9a-f]{40}$/).parse(input.commitId);\n const head = await readPullRequestHead(input);\n if (head.sha !== commitId) {\n throw new Error(`pull request changed after review: expected ${commitId}, found ${head.sha}`);\n }\n const review = submittedReviewSchema.parse(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/reviews`,\n {\n method: \"POST\",\n body: JSON.stringify({\n commit_id: commitId,\n event: input.event,\n body: input.body,\n comments: (input.comments ?? []).map((comment) => ({\n path: comment.path,\n line: positiveInteger(comment.line, \"comment line\"),\n side: \"RIGHT\",\n body: comment.body,\n })),\n }),\n },\n ),\n );\n return { id: review.id, url: review.html_url, state: review.state };\n}\n\n/** Read the current head branch and commit of a pull request. */\nexport async function readPullRequestHead(\n input: ReadPullRequestHeadInput,\n): Promise<GitHubPullRequestHead> {\n const pull = pullRequestHeadSchema.parse(\n await gitHubRequest(input, `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}`),\n );\n return {\n branch: pull.head.ref,\n sha: pull.head.sha,\n repository: pull.head.repo.full_name.toLowerCase(),\n };\n}\n\n/** Read the provider-owned identity and lifecycle of one pull request. */\nexport async function readPullRequest(\n input: ReadPullRequestHeadInput,\n): Promise<GitHubPullRequest> {\n const pull = readablePullRequestSchema.parse(\n await gitHubRequest(input, `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}`),\n );\n return { number: pull.number, url: pull.html_url, author: pull.user.login, state: pull.state };\n}\n\n/** List open, same-repository pull requests by one author that GitHub reports as conflicting. */\nexport async function listConflictedPullRequests(\n input: ListConflictedPullRequestsInput,\n): Promise<ConflictedPullRequest[]> {\n const pulls = openPullRequestsSchema.parse(\n await gitHubRequest(input, `/pulls?state=open&per_page=100`),\n );\n const candidates = pulls.filter(\n (pull) =>\n pull.user.type === \"Bot\" &&\n pull.head.ref.startsWith(\"factory/\") &&\n pull.head.repo.full_name.toLowerCase() === input.repository.toLowerCase(),\n );\n const conflicted: ConflictedPullRequest[] = [];\n for (const candidate of candidates) {\n const pull = pullRequestDetailSchema.parse(\n await gitHubRequest(input, `/pulls/${candidate.number}`),\n );\n if (pull.mergeable === false || pull.mergeable_state === \"dirty\") {\n conflicted.push({\n prNumber: pull.number,\n prUrl: pull.html_url,\n headBranch: pull.head.ref,\n headSha: pull.head.sha,\n baseBranch: pull.base.ref,\n baseSha: pull.base.sha,\n });\n }\n }\n return conflicted;\n}\n\n/** Add one label to a pull request. */\nexport async function addLabel(input: PullRequestLabelInput): Promise<string[]> {\n return parseLabels(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/labels`,\n { method: \"POST\", body: JSON.stringify({ labels: [input.label] }) },\n ),\n );\n}\n\n/** Remove one label from a pull request. */\nexport async function removeLabel(input: PullRequestLabelInput): Promise<string[]> {\n return parseLabels(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/labels/${encodeURIComponent(input.label)}`,\n { method: \"DELETE\" },\n ),\n );\n}\n\nasync function gitHubRequest(\n input: GitHubRepositoryRequest,\n path: string,\n init: RequestInit = {},\n): Promise<unknown> {\n if (!repositorySlugPattern.test(input.repository)) {\n throw new Error(`invalid GitHub repository slug: ${input.repository}`);\n }\n const response = await (input.fetch ?? globalThis.fetch)(\n `${gitHubApiUrl}/repos/${input.repository}${path}`,\n {\n ...init,\n headers: {\n Accept: \"application/vnd.github+json\",\n Authorization: `Bearer ${input.token}`,\n \"Content-Type\": \"application/json\",\n \"X-GitHub-Api-Version\": \"2022-11-28\",\n ...init.headers,\n },\n },\n );\n const body: unknown = await response.json();\n if (!response.ok) {\n const message = z.object({ message: z.string() }).safeParse(body);\n throw new Error(\n `GitHub API request failed (${response.status}): ${message.success ? message.data.message : response.statusText}`,\n );\n }\n return body;\n}\n\nfunction parseReviewComment(value: unknown): GitHubReviewComment {\n const comment = reviewCommentSchema.parse(value);\n return {\n id: comment.id,\n body: comment.body,\n url: comment.html_url,\n author: comment.user.login,\n inReplyToId: comment.in_reply_to_id ?? null,\n };\n}\n\nfunction parseIssueComment(value: unknown): GitHubIssueComment {\n const comment = issueCommentSchema.parse(value);\n return {\n id: comment.id,\n body: comment.body,\n url: comment.html_url,\n author: comment.user.login,\n authorType: comment.user.type,\n };\n}\n\nfunction parseLabels(value: unknown): string[] {\n return labelsSchema.parse(value).map(({ name }) => name);\n}\n\nfunction parseCheckRun(value: unknown): GitHubCheckRun {\n const checkRun = checkRunSchema.parse(value);\n return {\n id: checkRun.id,\n name: checkRun.name,\n headSha: checkRun.head_sha,\n status: checkRun.status,\n conclusion: checkRun.conclusion,\n url: checkRun.html_url,\n detailsUrl: checkRun.details_url,\n externalId: checkRun.external_id,\n startedAt: checkRun.started_at,\n completedAt: checkRun.completed_at,\n };\n}\n\nfunction checkRunFields(input: CheckRunFields): Record<string, unknown> {\n return {\n ...(input.status === undefined ? {} : { status: input.status }),\n ...(input.conclusion === undefined ? {} : { conclusion: input.conclusion }),\n ...(input.detailsUrl === undefined ? {} : { details_url: input.detailsUrl }),\n ...(input.externalId === undefined ? {} : { external_id: input.externalId }),\n ...(input.startedAt === undefined ? {} : { started_at: input.startedAt }),\n ...(input.completedAt === undefined ? {} : { completed_at: input.completedAt }),\n ...(input.output === undefined ? {} : { output: checkRunOutput(input.output) }),\n };\n}\n\nfunction checkRunOutput(output: CheckRunOutput): Record<string, unknown> {\n return {\n title: output.title,\n summary: output.summary,\n ...(output.text === undefined ? {} : { text: output.text }),\n ...(output.annotations === undefined\n ? {}\n : {\n annotations: output.annotations.map((annotation) => ({\n path: annotation.path,\n start_line: positiveInteger(annotation.startLine, \"annotation startLine\"),\n end_line: positiveInteger(annotation.endLine ?? annotation.startLine, \"annotation endLine\"),\n ...(annotation.startColumn === undefined\n ? {}\n : { start_column: positiveInteger(annotation.startColumn, \"annotation startColumn\") }),\n ...(annotation.endColumn === undefined\n ? {}\n : { end_column: positiveInteger(annotation.endColumn, \"annotation endColumn\") }),\n annotation_level: annotation.annotationLevel,\n message: annotation.message,\n ...(annotation.title === undefined ? {} : { title: annotation.title }),\n ...(annotation.rawDetails === undefined ? {} : { raw_details: annotation.rawDetails }),\n })),\n }),\n };\n}\n\nasync function assertReviewCommentAuthor(\n input: GitHubRepositoryRequest & ReviewCommentTrustInput,\n author: string,\n): Promise<void> {\n if (input.authorPolicy === \"any\") {\n return;\n }\n const { permission } = collaboratorPermissionSchema.parse(\n await gitHubRequest(input, `/collaborators/${encodeURIComponent(author)}/permission`),\n );\n if (!writePermissions.has(permission)) {\n throw new GitHubReviewCommentAuthorError(author);\n }\n}\n\nfunction positiveInteger(value: number, name: string): number {\n if (!Number.isInteger(value) || value < 1) {\n throw new Error(`${name} must be a positive integer`);\n }\n return value;\n}\n\nfunction commitSha(value: string): string {\n return z.string().regex(/^[0-9a-f]{40}$/).parse(value);\n}\n\n/**\n * Verify a GitHub webhook HMAC signature (the x-hub-signature-256 header)\n * against the raw request body. Returns false for missing or malformed\n * signatures instead of throwing.\n */\nexport function verifyGitHubSignature(options: {\n secret: string;\n payload: string;\n signature: string | null;\n}): boolean {\n const { secret, payload, signature } = options;\n if (signature === null || !signature.startsWith(\"sha256=\")) {\n return false;\n }\n const expected = createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n const provided = signature.slice(\"sha256=\".length);\n if (provided.length !== expected.length) {\n return false;\n }\n return timingSafeEqual(Buffer.from(provided, \"hex\"), Buffer.from(expected, \"hex\"));\n}\n\nconst pushEventSchema = z.looseObject({\n ref: z.string().min(1),\n repository: z.looseObject({\n default_branch: z.string().min(1),\n full_name: z.string().min(1),\n }),\n});\n\nexport interface GitHubDefaultBranchPush {\n source: \"github_default_branch_push\";\n deliveryId: string;\n repositorySlug: string;\n defaultBranch: string;\n}\n\n/** Normalize a push to a repository's default branch for deterministic reconciliation. */\nexport function normalizeGitHubDefaultBranchPush(options: {\n deliveryId: string;\n event: string;\n payload: unknown;\n}): GitHubDefaultBranchPush | null {\n if (options.event !== \"push\") return null;\n const parsed = pushEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.ref !== `refs/heads/${parsed.data.repository.default_branch}`) {\n return null;\n }\n return {\n source: \"github_default_branch_push\",\n deliveryId: options.deliveryId,\n repositorySlug: parsed.data.repository.full_name.toLowerCase(),\n defaultBranch: parsed.data.repository.default_branch,\n };\n}\n\nconst pullRequestEventSchema = z.looseObject({\n action: z.string(),\n number: z.number().int().positive(),\n pull_request: z.looseObject({\n html_url: z.url(),\n draft: z.boolean(),\n user: z.looseObject({ login: z.string().min(1) }),\n head: z.looseObject({\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n ref: z.string().min(1),\n repo: z.looseObject({ full_name: z.string().min(1) }),\n }),\n base: z.looseObject({\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n ref: z.string().min(1),\n }),\n }),\n repository: z.looseObject({ full_name: z.string().min(1) }),\n sender: z.looseObject({ login: z.string().min(1) }),\n});\n\nconst reviewablePullRequestActions = new Set([\"opened\", \"reopened\", \"ready_for_review\", \"synchronize\"]);\n\nexport interface GitHubPullRequestSignal extends NormalizedSignal<\"github_pr\"> {\n repositorySlug: string;\n pullRequest: {\n number: number;\n url: string;\n author: string;\n draft: boolean;\n headSha: string;\n headBranch: string;\n headRepositorySlug: string;\n baseSha: string;\n baseBranch: string;\n sender: string;\n };\n}\n\n/** Normalize a newly reviewable or updated pull request into a factory signal. */\nexport function normalizeGitHubPullRequest(options: WebhookEvent): GitHubPullRequestSignal | null {\n if (options.event !== \"pull_request\") return null;\n const parsed = pullRequestEventSchema.safeParse(options.payload);\n if (!parsed.success || !reviewablePullRequestActions.has(parsed.data.action)) return null;\n if (parsed.data.pull_request.draft && parsed.data.action !== \"ready_for_review\") return null;\n\n const slug = parsed.data.repository.full_name.toLowerCase();\n const pull = parsed.data.pull_request;\n return {\n source: \"github_pr\",\n deliveryId: options.deliveryId,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}/pull/${parsed.data.number}` },\n pullRequest: {\n number: parsed.data.number,\n url: pull.html_url,\n author: pull.user.login,\n draft: pull.draft,\n headSha: pull.head.sha,\n headBranch: pull.head.ref,\n headRepositorySlug: pull.head.repo.full_name.toLowerCase(),\n baseSha: pull.base.sha,\n baseBranch: pull.base.ref,\n sender: parsed.data.sender.login,\n },\n payload: options.payload,\n };\n}\n\nconst issueEventSchema = z.looseObject({\n action: z.string(),\n issue: z.looseObject({\n number: z.number().int().min(1),\n title: z.string(),\n body: z.string().nullable(),\n }),\n repository: z.looseObject({\n full_name: z.string().min(1),\n }),\n});\n\nexport interface GitHubIssueSignal extends NormalizedSignal<\"github_issue\"> {\n repositorySlug: string;\n issue: { number: number; title: string; body: string | null };\n}\n\nconst failedWorkflowConclusions = new Set([\n \"action_required\",\n \"failure\",\n \"stale\",\n \"startup_failure\",\n \"timed_out\",\n]);\n\nconst workflowRunEventSchema = z.looseObject({\n action: z.string(),\n repository: z.looseObject({\n default_branch: z.string().min(1),\n full_name: z.string().min(1),\n }),\n workflow_run: z.looseObject({\n id: z.number().int().min(1),\n name: z.string().min(1),\n event: z.string().min(1),\n head_branch: z.string().min(1).nullable(),\n head_repository: z\n .looseObject({\n full_name: z.string().min(1),\n })\n .nullable(),\n head_sha: z.string().min(1),\n html_url: z.url(),\n conclusion: z.string().nullable(),\n run_attempt: z.number().int().min(1),\n }),\n});\n\nexport interface GitHubCIFailureSignal extends NormalizedSignal<\"github_ci_failure\"> {\n repositoryDefaultBranch: string;\n repositorySlug: string;\n workflowRun: {\n id: number;\n name: string;\n trigger: string;\n branch: string | null;\n headRepositorySlug: string | null;\n headSha: string;\n url: string;\n conclusion: string;\n attempt: number;\n };\n}\n\n/**\n * Normalize a GitHub issues webhook into the factory's signal shape. Returns\n * null for payloads that are not an opened issue. The caller supplies the\n * repository id; the payload stays untrusted data.\n */\nexport function normalizeGitHubIssueOpened(options: WebhookEvent): GitHubIssueSignal | null {\n if (options.event !== \"issues\") {\n return null;\n }\n const parsed = issueEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"opened\") {\n return null;\n }\n const slug = parsed.data.repository.full_name.toLowerCase();\n const { number, title, body } = parsed.data.issue;\n return {\n source: \"github_issue\",\n deliveryId: options.deliveryId,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}#${number}` },\n issue: { number, title, body },\n payload: options.payload,\n };\n}\n\nconst pullRequestClosedSchema = z.looseObject({\n action: z.string(),\n pull_request: z.looseObject({\n number: z.number().int().min(1),\n html_url: z.url(),\n merged: z.boolean(),\n merged_by: z.looseObject({ login: z.string().min(1) }).nullable().optional(),\n merge_commit_sha: z\n .string()\n .regex(/^[0-9a-f]{40}$/)\n .nullable()\n .optional(),\n }),\n repository: z.looseObject({\n full_name: z.string().min(1),\n }),\n sender: z.looseObject({ login: z.string().min(1) }),\n});\n\nexport interface GitHubPullRequestClosed {\n source: \"github_pull_request_closed\";\n deliveryId: string;\n repositorySlug: string;\n prNumber: number;\n prUrl: string;\n merged: boolean;\n /** The merge commit on the base branch; null when closed without merging. */\n mergeCommitSha: string | null;\n /** The GitHub login that merged the pull request, or closed it without merging. */\n decidedBy: string;\n}\n\n/**\n * Normalize a closed pull_request webhook so the factory can observe what\n * happened to its change: merged records merged_by (the sender when GitHub\n * omits it), a close without merge records the sender.\n */\nexport function normalizeGitHubPullRequestClosed(\n options: WebhookEvent,\n): GitHubPullRequestClosed | null {\n if (options.event !== \"pull_request\") {\n return null;\n }\n const parsed = pullRequestClosedSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"closed\") {\n return null;\n }\n const pr = parsed.data.pull_request;\n const sender = parsed.data.sender.login;\n return {\n source: \"github_pull_request_closed\",\n deliveryId: options.deliveryId,\n repositorySlug: parsed.data.repository.full_name.toLowerCase(),\n prNumber: pr.number,\n prUrl: pr.html_url,\n merged: pr.merged,\n mergeCommitSha: pr.merged ? (pr.merge_commit_sha ?? null) : null,\n decidedBy: pr.merged ? (pr.merged_by?.login ?? sender) : sender,\n };\n}\n\n/** Normalize a completed, unsuccessful GitHub Actions run into a CI failure signal. */\nexport function normalizeGitHubWorkflowRunFailure(\n options: WebhookEvent,\n): GitHubCIFailureSignal | null {\n if (options.event !== \"workflow_run\") {\n return null;\n }\n const parsed = workflowRunEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"completed\") {\n return null;\n }\n\n const run = parsed.data.workflow_run;\n const conclusion = run.conclusion;\n if (conclusion === null || !failedWorkflowConclusions.has(conclusion)) {\n return null;\n }\n const slug = parsed.data.repository.full_name.toLowerCase();\n return {\n source: \"github_ci_failure\",\n deliveryId: options.deliveryId,\n repositoryDefaultBranch: parsed.data.repository.default_branch,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}/actions/runs/${run.id}` },\n workflowRun: {\n id: run.id,\n name: run.name,\n trigger: run.event,\n branch: run.head_branch,\n headRepositorySlug: run.head_repository?.full_name.toLowerCase() ?? null,\n headSha: run.head_sha,\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AS,IAAI;GACb,QAAQ,IAAI;GACZ,oBAAoB,IAAI,iBAAiB,UAAU,YAAY,KAAK;GACpE,SAAS,IAAI;GACb,KAAK,IAAI;GACT;GACA,SAAS,IAAI;EACf;EACA,SAAS,QAAQ;CACnB;AACF"}
1
+ {"version":3,"file":"github.mjs","names":[],"sources":["../src/github.ts"],"sourcesContent":["import { createHmac, timingSafeEqual } from \"node:crypto\";\nimport { z } from \"zod\";\nimport type { NormalizedSignal, WebhookEvent } from \"./connectors/index\";\nimport type { OpenPullRequest } from \"./pull-requests/contracts\";\nimport { repositorySlugSchema, type RepositorySlug } from \"./schema/repository\";\n\nexport {\n mintGitHubAppInstallationToken,\n type GitHubAppFactoryInput,\n type GitHubAppInstallationToken,\n type GitHubAppLike,\n type GitHubAppPermissions,\n type MintGitHubAppInstallationTokenInput,\n} from \"./github-app\";\nexport {\n checkoutGitHubRepository,\n createGitHubPublicationClient,\n factorySessionBranch,\n factoryTaskBranch,\n GitHubCheckoutConflictError,\n GitHubPublicationApiError,\n isSafeGitRef,\n readCommittedGitChange,\n runSandboxGit,\n type CheckoutGitHubRepositoryInput,\n type CommittedGitChange,\n type CreatedGitHubPublicationPullRequest,\n type CreateGitHubBranchInput,\n type CreateGitHubCommitInput,\n type CreateGitHubPublicationPullRequestInput,\n type CreateGitHubTreeInput,\n type GitHubCommit,\n type GitHubPublicationClient,\n type GitHubPublicationClientOptions,\n type GitHubPublicationLimits,\n type GitHubPublicationPullRequest,\n type GitHubTreeDeletion,\n type GitHubTreeEntry,\n type GitHubTreeUpsert,\n type MarkGitHubPullRequestReadyInput,\n type ListGitHubPublicationPullRequestsInput,\n type ReadCommittedGitChangeInput,\n type ReadGitHubBranchHeadInput,\n type ReadGitHubCommitInput,\n type ReadGitHubPullRequestInput,\n type RunSandboxGitInput,\n type SandboxGit,\n type SandboxGitCommandInput,\n type SandboxGitCommandResult,\n type UpdateGitHubBranchInput,\n} from \"./github-publication\";\n\nexport type {\n FetchGitHubBundleInput,\n FetchGitHubRefsInput,\n GitHubGitTransport,\n GitHubRefMapping,\n GitHubRepositoryBundle,\n GitTransferSandbox,\n ReadGitTransferFileInput,\n PushGitHubBundleInput,\n PushGitHubHeadInput,\n WithSandboxGitBundleInput,\n WriteGitTransferFileInput,\n} from \"./github-transfer\";\n\nconst gitHubApiUrl = \"https://api.github.com\";\nconst gitHubRepositorySlugSchema = z\n .string()\n .min(1)\n .transform((value) => value.toLowerCase())\n .pipe(repositorySlugSchema);\n\nconst factoryReviewCommentEventSchema = z.looseObject({\n action: z.literal(\"created\"),\n comment: z.looseObject({\n id: z.number().int().positive(),\n body: z.string(),\n html_url: z.url(),\n in_reply_to_id: z.number().int().positive().nullish(),\n }),\n pull_request: z.looseObject({\n number: z.number().int().positive(),\n html_url: z.url(),\n user: z.looseObject({ login: z.string().min(1) }),\n }),\n repository: z.looseObject({ full_name: gitHubRepositorySlugSchema }),\n});\n\nconst factoryQuestionReplyEventSchema = z.looseObject({\n action: z.literal(\"created\"),\n comment: z.looseObject({\n body: z.string(),\n html_url: z.url(),\n id: z.number().int().positive(),\n }),\n issue: z.looseObject({\n number: z.number().int().positive(),\n pull_request: z.unknown().optional(),\n }),\n repository: z.looseObject({ full_name: gitHubRepositorySlugSchema }),\n sender: z.looseObject({ login: z.string().min(1), type: z.string().min(1) }),\n});\n\nconst defaultReviewMentions = [\"factory\"] as const;\nconst defaultQuestionMentions = [\"agent-factory\", \"agent-factory[bot]\", \"factory\"] as const;\n\n/** Custom mention names accepted by Factory's GitHub comment normalizers. */\nexport interface FactoryMentionOptions {\n mentions?: readonly string[];\n}\n\n/** Provider event and optional mentions accepted by Factory comment normalizers. */\nexport interface NormalizeFactoryCommentInput extends FactoryMentionOptions {\n event: string;\n payload: unknown;\n}\n\n/** Select addressed comments and optionally reply candidates whose ownership the caller must verify. */\nexport interface NormalizeFactoryReviewCommentInput extends NormalizeFactoryCommentInput {\n includeReplies?: boolean;\n}\n\n/** Configured repositories and provider observations used to select one trusted repository. */\nexport interface ConfiguredEventRepositoryInput {\n configuredSlugs: readonly RepositorySlug[];\n eventSlugs: readonly (RepositorySlug | null)[];\n}\n\nfunction stripMention(body: string, mentions: readonly string[]): string | null {\n const trimmed = body.trimStart();\n for (const mention of mentions) {\n const prefix = `@${mention.trim()}`;\n if (prefix === \"@\" || trimmed.slice(0, prefix.length).toLowerCase() !== prefix.toLowerCase()) {\n continue;\n }\n const remainder = trimmed.slice(prefix.length);\n if (!/^[\\s,:-]/u.test(remainder)) continue;\n return remainder.replace(/^[\\s,:-]*/u, \"\").trim();\n }\n return null;\n}\n\n/** Routing metadata extracted from an addressed inline comment or an opt-in reply candidate. */\nexport interface FactoryReviewComment {\n repositorySlug: RepositorySlug;\n pullRequestNumber: number;\n pullRequestUrl: string;\n pullRequestAuthor: string;\n commentId: number;\n commentUrl: string;\n}\n\n/** Human answer extracted from a mentioned GitHub issue comment. */\nexport interface FactoryQuestionReply {\n repositorySlug: RepositorySlug;\n replyAddress: string;\n author: string;\n answer: string;\n commentId: number;\n issueNumber: number;\n commentUrl: string;\n}\n\n/** Select the one configured repository consistently identified by a provider delivery. */\nexport function configuredEventRepositorySlug(\n input: ConfiguredEventRepositoryInput,\n): RepositorySlug | null {\n const { configuredSlugs, eventSlugs } = input;\n const distinctEventSlugs = [\n ...new Set(eventSlugs.filter((slug): slug is RepositorySlug => slug !== null)),\n ];\n const eventSlug = distinctEventSlugs[0];\n return distinctEventSlugs.length === 1 &&\n eventSlug !== undefined &&\n configuredSlugs.includes(eventSlug)\n ? eventSlug\n : null;\n}\n\n/** Normalize addressed inline comments or opt-in reply candidates; callers must authenticate them. */\nexport function normalizeFactoryReviewComment(\n input: NormalizeFactoryReviewCommentInput,\n): FactoryReviewComment | null {\n if (input.event !== \"pull_request_review_comment\") return null;\n const parsed = factoryReviewCommentEventSchema.safeParse(input.payload);\n if (\n !parsed.success ||\n (stripMention(parsed.data.comment.body, input.mentions ?? defaultReviewMentions) === null &&\n !(input.includeReplies && parsed.data.comment.in_reply_to_id != null))\n ) {\n return null;\n }\n return {\n repositorySlug: parsed.data.repository.full_name,\n pullRequestNumber: parsed.data.pull_request.number,\n pullRequestUrl: parsed.data.pull_request.html_url,\n pullRequestAuthor: parsed.data.pull_request.user.login,\n commentId: parsed.data.comment.id,\n commentUrl: parsed.data.comment.html_url,\n };\n}\n\n/**\n * Strip the Factory mention from an issue comment body, returning null when the\n * comment does not address Factory. Exported so a caller reconciling a delivery\n * against GitHub's own copy of the comment applies the same rule the normalizer\n * applied to the payload.\n */\nexport function stripFactoryQuestionMention(\n body: string,\n options: FactoryMentionOptions = {},\n): string | null {\n return stripMention(body, options.mentions ?? defaultQuestionMentions);\n}\n\n/** Normalize a mentioned issue comment that can answer a persisted Factory QuestionTask. */\nexport function normalizeFactoryQuestionReply(\n input: NormalizeFactoryCommentInput,\n): FactoryQuestionReply | null {\n if (input.event !== \"issue_comment\") return null;\n const parsed = factoryQuestionReplyEventSchema.safeParse(input.payload);\n if (!parsed.success || parsed.data.sender.type.toLowerCase() === \"bot\") return null;\n const answer = stripMention(parsed.data.comment.body, input.mentions ?? defaultQuestionMentions);\n if (answer === null || answer === \"\") return null;\n if (parsed.data.issue.pull_request !== undefined) return null;\n const repositorySlug = parsed.data.repository.full_name;\n return {\n repositorySlug,\n replyAddress: `${repositorySlug}#${parsed.data.issue.number}`,\n author: parsed.data.sender.login,\n answer,\n commentId: parsed.data.comment.id,\n issueNumber: parsed.data.issue.number,\n commentUrl: parsed.data.comment.html_url,\n };\n}\n\n/** Credentials and transport for a repository-scoped GitHub REST request. */\nexport interface GitHubRepositoryRequest {\n repository: RepositorySlug;\n token: string;\n fetch?: typeof globalThis.fetch;\n}\n\n/** Repository-scoped identity of one pull request accepted by GitHub operations. */\nexport interface GitHubPullRequestTarget extends GitHubRepositoryRequest {\n pullRequestNumber: number;\n}\n\n/** Provider-owned number and URL that identify one GitHub pull request. */\nexport interface GitHubPullRequestReference {\n pullRequestNumber: number;\n pullRequestUrl: string;\n}\n\n/** Repository request that identifies the GitHub actor whose access must be checked. */\nexport interface GitHubRepositoryAuthorRequest extends GitHubRepositoryRequest {\n author: string;\n}\n\n/** Repository-scoped fields required to open a pull request from an existing branch. */\nexport interface CreatePullRequestInput extends GitHubRepositoryRequest {\n title: string;\n head: string;\n base: string;\n body?: string;\n draft?: boolean;\n}\n\n/** Provider identity returned after GitHub creates a pull request. */\nexport type CreatedGitHubPullRequest = GitHubPullRequestReference;\n\n/** Trust threshold applied before Factory consumes an inline review comment. */\nexport type ReviewCommentAuthorPolicy = \"write\" | \"any\";\n\ninterface ReviewCommentTrustInput {\n /** Defaults to `write`. Use `any` only when untrusted review text is handled as data. */\n authorPolicy?: ReviewCommentAuthorPolicy;\n}\n\n/** Pull request, comment identity, and author policy used to read an inline review comment. */\nexport interface ReadReviewCommentInput extends GitHubPullRequestTarget, ReviewCommentTrustInput {\n commentId: number;\n}\n\n/** Normalized inline review comment, with a null author when GitHub no longer exposes it. */\nexport interface GitHubReviewComment {\n id: number;\n pullRequestNumber: number;\n body: string;\n url: string;\n author: string | null;\n /** GitHub account type when available, used to distinguish human requests from bot activity. */\n authorType: string | null;\n inReplyToId: number | null;\n reviewId: number | null;\n}\n\n/** Trusted inline comment and reply content used to post a threaded answer. */\nexport interface AnswerReviewCommentInput extends GitHubPullRequestTarget, ReviewCommentTrustInput {\n commentId: number;\n body: string;\n}\n\n/** Current branch, commit, and source repository of a pull request head. */\nexport interface GitHubPullRequestHead {\n branch: string;\n sha: string;\n repository: RepositorySlug;\n}\n\n/** Provider-owned identity, author, and lifecycle state of a pull request. */\nexport interface GitHubPullRequest extends GitHubPullRequestReference {\n author: string;\n /** GitHub account type of the author, e.g. \"User\" or \"Bot\", when reported. */\n authorType?: string;\n state: \"open\" | \"closed\";\n}\n\n/** GitHub review action submitted with a pull-request review. */\nexport type PullRequestReviewEvent = \"APPROVE\" | \"REQUEST_CHANGES\" | \"COMMENT\";\n\n/** One inline finding attached to a submitted pull-request review. */\nexport interface PullRequestReviewComment {\n path: string;\n startLine?: number;\n line: number;\n body: string;\n}\n\n/** Commit-fenced summary and inline findings submitted as one review. */\nexport interface SubmitPullRequestReviewInput extends GitHubPullRequestTarget {\n commitId: string;\n event: PullRequestReviewEvent;\n body: string;\n comments?: readonly PullRequestReviewComment[];\n}\n\n/** Provider identity and state returned for a submitted pull-request review. */\nexport interface SubmittedPullRequestReview {\n id: number;\n url: string;\n state: string;\n}\n\n/** Issue-style PR comment, with null author metadata when GitHub no longer exposes it. */\nexport interface GitHubIssueComment {\n id: number;\n body: string;\n url: string;\n author: string | null;\n authorType: \"Bot\" | \"User\" | \"Organization\" | null;\n}\n\n/** Inline discussion entry with its review and source location, including replies. */\nexport interface GitHubPullRequestDiscussionComment extends GitHubReviewComment {\n path: string;\n line: number | null;\n}\n\n/** Existing PR verdict, retaining null author or commit metadata when unavailable on GitHub. */\nexport interface GitHubPullRequestDiscussionReview extends SubmittedPullRequestReview {\n author: string | null;\n body: string;\n commitId: string | null;\n}\n\n/** One bounded page of untrusted PR conversation, inline comments, and prior verdicts. */\nexport interface GitHubPullRequestDiscussionPage {\n comments: readonly GitHubIssueComment[];\n reviewComments: readonly GitHubPullRequestDiscussionComment[];\n reviews: readonly GitHubPullRequestDiscussionReview[];\n nextPage: number | null;\n}\n\n/** Pull request and one-based discussion page to read; each collection returns up to 50 entries. */\nexport interface ListPullRequestDiscussionInput extends GitHubPullRequestTarget {\n page?: number;\n}\n\n/** Repository and pull request whose issue-style comments should be listed. */\nexport type ListPullRequestCommentsInput = GitHubPullRequestTarget;\n\n/** Pull-request conversation and body for a new issue-style comment. */\nexport interface CreatePullRequestCommentInput extends ListPullRequestCommentsInput {\n body: string;\n}\n\n/** Existing issue-style comment and replacement body to persist. */\nexport interface UpdatePullRequestCommentInput extends GitHubRepositoryRequest {\n commentId: number;\n body: string;\n}\n\n/** Pull request and label targeted by a metadata-only label operation. */\nexport interface PullRequestLabelInput extends GitHubPullRequestTarget {\n label: string;\n}\n\n/** Repository label to create when absent, retaining any existing color and description. */\nexport interface EnsureGitHubLabelInput extends GitHubRepositoryRequest {\n name: string;\n color: string;\n description: string;\n}\n\n/** Open Factory-authored pull request GitHub currently reports as conflicted. */\nexport interface ConflictedGitHubPullRequest extends GitHubPullRequestReference {\n headBranch: string;\n headSha: string;\n baseBranch: string;\n baseSha: string;\n}\n\n/** Repository scope used to discover conflicted Factory-authored pull requests. */\nexport type ListConflictedPullRequestsInput = GitHubRepositoryRequest;\n\n/** Repository scope used to enumerate open pull requests. */\nexport type ListOpenPullRequestsInput = GitHubRepositoryRequest;\n\n/** Nonterminal lifecycle states Factory may write to a GitHub check run. */\nexport type CheckRunProgressStatus = \"queued\" | \"in_progress\";\n/** Lifecycle states GitHub may report when observing a check run. */\nexport type ObservedCheckRunStatus =\n | CheckRunProgressStatus\n | \"completed\"\n | \"waiting\"\n | \"requested\"\n | \"pending\";\n/** Terminal result GitHub records for a completed check run. */\nexport type CheckRunConclusion =\n | \"action_required\"\n | \"cancelled\"\n | \"failure\"\n | \"neutral\"\n | \"skipped\"\n | \"success\"\n | \"timed_out\";\n/** Severity GitHub displays for a check-run annotation. */\nexport type CheckRunAnnotationLevel = \"notice\" | \"warning\" | \"failure\";\n\n/** One source location and message rendered in a check run. */\nexport interface CheckRunAnnotation {\n path: string;\n startLine: number;\n endLine?: number;\n startColumn?: number;\n endColumn?: number;\n annotationLevel: CheckRunAnnotationLevel;\n message: string;\n title?: string;\n rawDetails?: string;\n}\n\n/** Human-readable summary and optional annotations attached to a check run. */\nexport interface CheckRunOutput {\n title: string;\n summary: string;\n text?: string;\n annotations?: readonly CheckRunAnnotation[];\n}\n\ninterface CheckRunPresentationFields {\n detailsUrl?: string;\n externalId?: string;\n startedAt?: string;\n output?: CheckRunOutput;\n}\n\n/** Writable fields for a queued, running, or presentation-only check-run update. */\nexport interface IncompleteCheckRunFields extends CheckRunPresentationFields {\n status?: CheckRunProgressStatus;\n conclusion?: never;\n completedAt?: never;\n}\n\n/** Writable fields for a terminal check run, which always requires its conclusion. */\nexport interface CompletedCheckRunFields extends CheckRunPresentationFields {\n status: \"completed\";\n conclusion: CheckRunConclusion;\n completedAt?: string;\n}\n\n/** Lifecycle-correlated fields accepted when creating or updating a check run. */\nexport type CheckRunFields = IncompleteCheckRunFields | CompletedCheckRunFields;\n\n/** Commit identity and presentation fields for a new check run. */\nexport type CreateCheckRunInput = GitHubRepositoryRequest &\n CheckRunFields & {\n name: string;\n headSha: string;\n };\n\n/** Check-run identity and fields to update on GitHub. */\nexport type UpdateCheckRunInput = GitHubRepositoryRequest &\n CheckRunFields & {\n checkRunId: number;\n name?: string;\n };\n\n/** Git reference and optional name filter used to discover existing check runs. */\nexport interface ListCheckRunsForRefInput extends GitHubRepositoryRequest {\n ref: string;\n checkName?: string;\n}\n\n/** Normalized identity, lifecycle, and links for a GitHub check run. */\nexport interface GitHubCheckRun {\n id: number;\n name: string;\n headSha: string;\n status: ObservedCheckRunStatus;\n conclusion: CheckRunConclusion | \"stale\" | \"startup_failure\" | null;\n url: string | null;\n detailsUrl: string | null;\n externalId: string | null;\n startedAt: string | null;\n completedAt: string | null;\n}\n\nconst pullRequestSchema = z.object({\n number: z.number().int().positive(),\n html_url: z.url(),\n});\n\nconst readablePullRequestSchema = pullRequestSchema.extend({\n state: z.enum([\"open\", \"closed\"]),\n user: z.object({ login: z.string().min(1), type: z.string().optional() }),\n});\n\nconst pullRequestHeadSchema = z.object({\n head: z.object({\n ref: z\n .string()\n .regex(/^[A-Za-z0-9][A-Za-z0-9._/-]*$/)\n .refine((value) => !value.includes(\"..\")),\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n repo: z.object({ full_name: gitHubRepositorySlugSchema }),\n }),\n});\n\nconst reviewCommentSchema = z.object({\n id: z.number().int().positive(),\n body: z.string(),\n html_url: z.url(),\n pull_request_url: z.url(),\n user: z.object({ login: z.string().min(1), type: z.string().optional() }).nullable(),\n in_reply_to_id: z.number().int().positive().nullish(),\n pull_request_review_id: z.number().int().positive().nullish(),\n});\n\nconst submittedReviewSchema = z.object({\n id: z.number().int().positive(),\n html_url: z.url(),\n state: z.string().min(1),\n});\n\nconst issueCommentSchema = z.object({\n id: z.number().int().positive(),\n body: z.string(),\n html_url: z.url(),\n user: z\n .object({\n login: z.string().min(1),\n type: z.enum([\"Bot\", \"User\", \"Organization\"]),\n })\n .nullable(),\n});\n\nconst checkRunSchema = z.object({\n id: z.number().int().positive(),\n name: z.string().min(1),\n head_sha: z.string().regex(/^[0-9a-f]{40}$/),\n status: z.enum([\"queued\", \"in_progress\", \"completed\", \"waiting\", \"requested\", \"pending\"]),\n conclusion: z\n .enum([\n \"action_required\",\n \"cancelled\",\n \"failure\",\n \"neutral\",\n \"skipped\",\n \"success\",\n \"timed_out\",\n \"stale\",\n \"startup_failure\",\n ])\n .nullable(),\n html_url: z.url().nullable(),\n details_url: z.url().nullable(),\n external_id: z.string().nullable(),\n started_at: z.string().nullable(),\n completed_at: z.string().nullable(),\n});\n\nconst checkRunsSchema = z.object({ check_runs: z.array(checkRunSchema) });\nconst labelsSchema = z.array(z.object({ name: z.string().min(1) }));\nconst pullRequestCandidateSchema = z.object({\n number: z.number().int().positive(),\n user: z.object({ type: z.string().min(1) }),\n head: z.object({\n ref: z.string().min(1),\n repo: z.object({ full_name: gitHubRepositorySlugSchema }),\n }),\n});\nconst openPullRequestsSchema = z.array(pullRequestCandidateSchema);\nconst pullRequestDetailSchema = pullRequestCandidateSchema.extend({\n html_url: z.url(),\n mergeable: z.boolean().nullable(),\n mergeable_state: z.string().min(1),\n head: pullRequestCandidateSchema.shape.head.extend({ sha: z.string().min(1) }),\n base: z.object({ ref: z.string().min(1), sha: z.string().min(1) }),\n});\nconst openPullRequestSummarySchema = z.object({\n number: z.number().int().positive(),\n html_url: z.url(),\n title: z.string().min(1),\n user: z.object({ login: z.string().min(1) }),\n head: z.object({ ref: z.string().min(1) }),\n draft: z.boolean(),\n});\nconst collaboratorPermissionSchema = z.object({\n permission: z.enum([\"admin\", \"maintain\", \"write\", \"triage\", \"read\", \"none\"]),\n});\nconst writePermissions = new Set([\"admin\", \"maintain\", \"write\"]);\n\n/** Refusal raised when an inline review-comment author lacks repository write access. */\nexport class GitHubReviewCommentAuthorError extends Error {\n readonly author: string | null;\n\n constructor(author: string | null) {\n super(\n author === null\n ? \"GitHub review comment has no author to verify for repository write access\"\n : `GitHub user ${author} does not have write access to the repository`,\n );\n this.name = \"GitHubReviewCommentAuthorError\";\n this.author = author;\n }\n}\n\n/**\n * The pull request advanced past the commit a review or fix was prepared\n * against. Callers that reviewed a task keyed to a specific commit (for\n * example `record_post_review`) can use `expectedSha`/`actualSha` to resolve\n * the task as superseded instead of leaving it running for the stall\n * watchdog to eventually -- and misleadingly -- report as \"stalled\".\n */\nexport class StalePullRequestHeadError extends Error {\n readonly expectedSha: string;\n readonly actualSha: string;\n\n constructor(expectedSha: string, actualSha: string) {\n super(`pull request changed after review: expected ${expectedSha}, found ${actualSha}`);\n this.name = \"StalePullRequestHeadError\";\n this.expectedSha = expectedSha;\n this.actualSha = actualSha;\n }\n}\n\n/** Whether a GitHub user may make repository-scoped Factory decisions. */\nexport async function hasGitHubRepositoryWriteAccess(\n input: GitHubRepositoryAuthorRequest,\n): Promise<boolean> {\n const { permission } = collaboratorPermissionSchema.parse(\n await gitHubRequest(input, `/collaborators/${encodeURIComponent(input.author)}/permission`),\n );\n return writePermissions.has(permission);\n}\n\n/** Create a pull request from an existing head branch. */\nexport async function createPullRequest(\n input: CreatePullRequestInput,\n): Promise<CreatedGitHubPullRequest> {\n const pull = pullRequestSchema.parse(\n await gitHubRequest(input, \"/pulls\", {\n method: \"POST\",\n body: JSON.stringify({\n title: input.title,\n head: input.head,\n base: input.base,\n ...(input.body === undefined ? {} : { body: input.body }),\n ...(input.draft === undefined ? {} : { draft: input.draft }),\n }),\n }),\n );\n return { pullRequestNumber: pull.number, pullRequestUrl: pull.html_url };\n}\n\n/** Create a check run for one commit. Requires a GitHub App token with checks:write. */\nexport async function createCheckRun(input: CreateCheckRunInput): Promise<GitHubCheckRun> {\n assertCheckRunFields(input);\n return parseCheckRun(\n await gitHubRequest(input, \"/check-runs\", {\n method: \"POST\",\n body: JSON.stringify({\n name: input.name,\n head_sha: commitSha(input.headSha),\n ...checkRunFields(input),\n }),\n }),\n );\n}\n\n/** Update a check run previously created by the authenticated GitHub App. */\nexport async function updateCheckRun(input: UpdateCheckRunInput): Promise<GitHubCheckRun> {\n assertCheckRunFields(input);\n return parseCheckRun(\n await gitHubRequest(input, `/check-runs/${positiveInteger(input.checkRunId, \"checkRunId\")}`, {\n method: \"PATCH\",\n body: JSON.stringify({\n ...(input.name === undefined ? {} : { name: input.name }),\n ...checkRunFields(input),\n }),\n }),\n );\n}\n\n/** List check runs reported for a commit, branch, or tag. */\nexport async function listCheckRunsForRef(\n input: ListCheckRunsForRefInput,\n): Promise<readonly GitHubCheckRun[]> {\n const query = new URLSearchParams({ per_page: \"100\" });\n if (input.checkName !== undefined) query.set(\"check_name\", input.checkName);\n const response = checkRunsSchema.parse(\n await gitHubRequest(\n input,\n `/commits/${encodeURIComponent(input.ref)}/check-runs?${query.toString()}`,\n ),\n );\n return response.check_runs.map(parseCheckRun);\n}\n\n/** List every issue-style comment in a pull request conversation. */\nexport async function listPullRequestComments(\n input: ListPullRequestCommentsInput,\n): Promise<readonly GitHubIssueComment[]> {\n const comments: GitHubIssueComment[] = [];\n for (let page = 1; ; page += 1) {\n const response = z\n .array(issueCommentSchema)\n .parse(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/comments?per_page=100&page=${page}`,\n ),\n );\n comments.push(...response.map(parseIssueComment));\n if (response.length < 100) return comments;\n }\n}\n\n/** Read a page of all PR discussion types without treating any author's text as authorization. */\nexport async function listPullRequestDiscussion(\n input: ListPullRequestDiscussionInput,\n): Promise<GitHubPullRequestDiscussionPage> {\n const page = z\n .number()\n .int()\n .positive()\n .parse(input.page ?? 1);\n const number = positiveInteger(input.pullRequestNumber, \"pullRequestNumber\");\n const query = `per_page=50&page=${page}`;\n const [comments, reviewComments, reviews] = await Promise.all([\n gitHubRequest(input, `/issues/${number}/comments?${query}`).then((value) =>\n z.array(issueCommentSchema).max(50).parse(value).map(parseIssueComment),\n ),\n gitHubRequest(input, `/pulls/${number}/comments?${query}`).then((value) =>\n z\n .array(\n reviewCommentSchema.extend({\n pull_request_review_id: z.number().int().positive().nullable(),\n path: z.string().min(1),\n line: z.number().int().positive().nullish(),\n }),\n )\n .max(50)\n .parse(value)\n .map((entry) => {\n const comment = parseReviewComment(entry);\n assertReviewCommentPullRequest(input, comment);\n return {\n ...comment,\n reviewId: entry.pull_request_review_id,\n path: entry.path,\n line: entry.line ?? null,\n };\n }),\n ),\n gitHubRequest(input, `/pulls/${number}/reviews?${query}`).then((value) =>\n z\n .array(\n submittedReviewSchema.extend({\n user: z.object({ login: z.string().min(1) }).nullable(),\n body: z.string(),\n commit_id: z\n .string()\n .regex(/^[0-9a-f]{40}$/)\n .nullable(),\n }),\n )\n .max(50)\n .parse(value)\n .map((review) => ({\n id: review.id,\n url: review.html_url,\n state: review.state,\n author: review.user?.login ?? null,\n body: review.body,\n commitId: review.commit_id,\n })),\n ),\n ]);\n return {\n comments,\n reviewComments,\n reviews,\n nextPage: [comments, reviewComments, reviews].some((entries) => entries.length === 50)\n ? page + 1\n : null,\n };\n}\n\n/** Add one issue-style comment to a pull request conversation. */\nexport async function createPullRequestComment(\n input: CreatePullRequestCommentInput,\n): Promise<GitHubIssueComment> {\n return parseIssueComment(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/comments`,\n { method: \"POST\", body: JSON.stringify({ body: input.body }) },\n ),\n );\n}\n\n/** Edit one issue-style pull request comment. */\nexport async function updatePullRequestComment(\n input: UpdatePullRequestCommentInput,\n): Promise<GitHubIssueComment> {\n return parseIssueComment(\n await gitHubRequest(\n input,\n `/issues/comments/${positiveInteger(input.commentId, \"commentId\")}`,\n {\n method: \"PATCH\",\n body: JSON.stringify({ body: input.body }),\n },\n ),\n );\n}\n\nconst readIssueCommentSchema = issueCommentSchema.extend({\n issue_url: z.string().min(1),\n});\n\n/** One issue comment as GitHub reports it, with the issue it belongs to. */\nexport interface GitHubIssueCommentRecord extends GitHubIssueComment {\n issueNumber: number;\n}\n\n/**\n * Read one issue comment from GitHub. A delivery authenticated as a workload\n * rather than by body signature can name any author and any text, so the\n * comment it refers to has to be read back before either is believed.\n */\nexport async function readIssueComment(\n input: GitHubRepositoryRequest & { commentId: number },\n): Promise<GitHubIssueCommentRecord> {\n const comment = readIssueCommentSchema.parse(\n await gitHubRequest(input, `/issues/comments/${positiveInteger(input.commentId, \"commentId\")}`),\n );\n const issueNumber = Number(comment.issue_url.split(\"/\").pop());\n if (!Number.isSafeInteger(issueNumber) || issueNumber < 1) {\n throw new Error(\"GitHub returned an issue comment without a usable issue reference.\");\n }\n return {\n id: comment.id,\n url: comment.html_url,\n author: comment.user?.login ?? null,\n authorType: comment.user?.type ?? null,\n body: comment.body,\n issueNumber,\n };\n}\n\n/** Read one inline review comment after applying the author policy, which requires write access by default. */\nexport async function readReviewComment(\n input: ReadReviewCommentInput,\n): Promise<GitHubReviewComment> {\n const comment = parseReviewComment(\n await gitHubRequest(input, `/pulls/comments/${positiveInteger(input.commentId, \"commentId\")}`),\n );\n assertReviewCommentPullRequest(input, comment);\n await assertReviewCommentAuthor(input, comment.author);\n return comment;\n}\n\n/** Reply to an inline review comment after applying the author policy, which requires write access by default. */\nexport async function answerReviewComment(\n input: AnswerReviewCommentInput,\n): Promise<GitHubReviewComment> {\n const comment = await readReviewComment(input);\n const rootId = comment.inReplyToId ?? comment.id;\n if (rootId !== comment.id) {\n await readReviewComment({ ...input, commentId: rootId, authorPolicy: \"any\" });\n }\n const reply = parseReviewComment(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/comments/${positiveInteger(rootId, \"commentId\")}/replies`,\n { method: \"POST\", body: JSON.stringify({ body: input.body }) },\n ),\n );\n assertReviewCommentPullRequest(input, reply);\n return reply;\n}\n\n/** Submit a summary and optional inline comments against a reviewed pull request commit. */\nexport async function submitPullRequestReview(\n input: SubmitPullRequestReviewInput,\n): Promise<SubmittedPullRequestReview> {\n const commitId = z\n .string()\n .regex(/^[0-9a-f]{40}$/)\n .parse(input.commitId);\n const comments = (input.comments ?? []).map((comment) => {\n const line = positiveInteger(comment.line, \"comment line\");\n const startLine =\n comment.startLine === undefined\n ? undefined\n : positiveInteger(comment.startLine, \"comment startLine\");\n if (startLine !== undefined && startLine >= line) {\n throw new Error(\"comment startLine must precede line; omit it for a single-line finding\");\n }\n return {\n path: comment.path,\n line,\n side: \"RIGHT\",\n ...(startLine === undefined ? {} : { start_line: startLine, start_side: \"RIGHT\" }),\n body: comment.body,\n };\n });\n const head = await readPullRequestHead(input);\n if (head.sha !== commitId) {\n throw new StalePullRequestHeadError(commitId, head.sha);\n }\n const review = submittedReviewSchema.parse(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/reviews`,\n {\n method: \"POST\",\n body: JSON.stringify({\n commit_id: commitId,\n event: input.event,\n body: input.body,\n comments,\n }),\n },\n ),\n );\n return { id: review.id, url: review.html_url, state: review.state };\n}\n\n/** Read the current head branch and commit of a pull request. */\nexport async function readPullRequestHead(\n input: GitHubPullRequestTarget,\n): Promise<GitHubPullRequestHead> {\n const pull = pullRequestHeadSchema.parse(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}`,\n ),\n );\n return {\n branch: pull.head.ref,\n sha: pull.head.sha,\n repository: pull.head.repo.full_name,\n };\n}\n\n/** Read the provider-owned identity and lifecycle of one pull request. */\nexport async function readPullRequest(input: GitHubPullRequestTarget): Promise<GitHubPullRequest> {\n const pull = readablePullRequestSchema.parse(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}`,\n ),\n );\n return {\n pullRequestNumber: pull.number,\n pullRequestUrl: pull.html_url,\n author: pull.user.login,\n authorType: pull.user.type,\n state: pull.state,\n };\n}\n\n/** Close an open pull request without merging it. */\nexport async function closePullRequest(input: GitHubPullRequestTarget): Promise<GitHubPullRequest> {\n const pull = readablePullRequestSchema.parse(\n await gitHubRequest(\n input,\n `/pulls/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}`,\n { method: \"PATCH\", body: JSON.stringify({ state: \"closed\" }) },\n ),\n );\n return {\n pullRequestNumber: pull.number,\n pullRequestUrl: pull.html_url,\n author: pull.user.login,\n authorType: pull.user.type,\n state: pull.state,\n };\n}\n\n/** List open, same-repository pull requests by one author that GitHub reports as conflicting. */\nexport async function listConflictedPullRequests(\n input: ListConflictedPullRequestsInput,\n): Promise<readonly ConflictedGitHubPullRequest[]> {\n const pulls = openPullRequestsSchema.parse(\n await gitHubRequest(input, `/pulls?state=open&per_page=100`),\n );\n const candidates = pulls.filter(\n (pull) =>\n pull.user.type === \"Bot\" &&\n pull.head.ref.startsWith(\"factory/\") &&\n pull.head.repo.full_name.toLowerCase() === input.repository.toLowerCase(),\n );\n const conflicted: ConflictedGitHubPullRequest[] = [];\n for (const candidate of candidates) {\n const pull = pullRequestDetailSchema.parse(\n await gitHubRequest(input, `/pulls/${candidate.number}`),\n );\n if (pull.mergeable === false || pull.mergeable_state === \"dirty\") {\n conflicted.push({\n pullRequestNumber: pull.number,\n pullRequestUrl: pull.html_url,\n headBranch: pull.head.ref,\n headSha: pull.head.sha,\n baseBranch: pull.base.ref,\n baseSha: pull.base.sha,\n });\n }\n }\n return conflicted;\n}\n\n/** List open pull requests in a repository, newest first, to check for existing work before triage. */\nexport async function listOpenPullRequests(\n input: ListOpenPullRequestsInput,\n): Promise<readonly OpenPullRequest[]> {\n const pulls = z\n .array(openPullRequestSummarySchema)\n .parse(\n await gitHubRequest(input, `/pulls?state=open&per_page=100&sort=created&direction=desc`),\n );\n return pulls.map((pull) => ({\n prNumber: pull.number,\n prUrl: pull.html_url,\n title: pull.title,\n author: pull.user.login,\n headBranch: pull.head.ref,\n draft: pull.draft,\n }));\n}\n\n/** Ensure a repository label exists, including when another publisher creates it concurrently. */\nexport async function ensureGitHubLabel(input: EnsureGitHubLabelInput): Promise<void> {\n const label = z\n .object({\n name: z.string().trim().min(1).max(50),\n color: z.string().regex(/^[a-fA-F0-9]{6}$/u),\n description: z.string().max(100),\n })\n .parse(input);\n const path = `/labels/${encodeURIComponent(label.name)}`;\n const read = async () => {\n const existing = z.object({ name: z.string() }).parse(await gitHubRequest(input, path));\n if (existing.name.toLowerCase() !== label.name.toLowerCase())\n throw new Error(\"GitHub returned a different repository label\");\n };\n try {\n await read();\n return;\n } catch (error) {\n if (!(error instanceof GitHubRequestError) || error.status !== 404) throw error;\n }\n try {\n await gitHubRequest(input, \"/labels\", { method: \"POST\", body: JSON.stringify(label) });\n } catch (error) {\n if (!(error instanceof GitHubRequestError) || error.status !== 422) throw error;\n // GitHub uses 422 for both a concurrent creation and unrelated validation failures.\n await read();\n }\n}\n\n/** Add one label to a pull request. */\nexport async function addLabel(input: PullRequestLabelInput): Promise<readonly string[]> {\n return parseLabels(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/labels`,\n { method: \"POST\", body: JSON.stringify({ labels: [input.label] }) },\n ),\n );\n}\n\n/** Remove one label from a pull request. */\nexport async function removeLabel(input: PullRequestLabelInput): Promise<readonly string[]> {\n return parseLabels(\n await gitHubRequest(\n input,\n `/issues/${positiveInteger(input.pullRequestNumber, \"pullRequestNumber\")}/labels/${encodeURIComponent(input.label)}`,\n { method: \"DELETE\" },\n ),\n );\n}\n\nclass GitHubRequestError extends Error {\n constructor(\n readonly status: number,\n message: string,\n ) {\n super(`GitHub API request failed (${status}): ${message}`);\n }\n}\n\nasync function gitHubRequest(\n input: GitHubRepositoryRequest,\n path: string,\n init: RequestInit = {},\n): Promise<unknown> {\n const repository = repositorySlugSchema.parse(input.repository);\n const response = await (input.fetch ?? globalThis.fetch)(\n `${gitHubApiUrl}/repos/${repository}${path}`,\n {\n ...init,\n headers: {\n Accept: \"application/vnd.github+json\",\n Authorization: `Bearer ${input.token}`,\n \"Content-Type\": \"application/json\",\n \"X-GitHub-Api-Version\": \"2022-11-28\",\n ...init.headers,\n },\n },\n );\n const body: unknown = await response.json();\n if (!response.ok) {\n const message = z.object({ message: z.string() }).safeParse(body);\n throw new GitHubRequestError(\n response.status,\n message.success ? message.data.message : response.statusText,\n );\n }\n return body;\n}\n\nfunction parseReviewComment(value: unknown): GitHubReviewComment {\n const comment = reviewCommentSchema.parse(value);\n const pullRequestMatch = /\\/pulls\\/([1-9]\\d*)\\/?$/.exec(\n new URL(comment.pull_request_url).pathname,\n );\n if (pullRequestMatch?.[1] === undefined) {\n throw new Error(\"GitHub review comment has an invalid pull request URL\");\n }\n return {\n id: comment.id,\n pullRequestNumber: positiveInteger(Number(pullRequestMatch[1]), \"pullRequestNumber\"),\n body: comment.body,\n url: comment.html_url,\n author: comment.user?.login ?? null,\n authorType: comment.user?.type ?? null,\n inReplyToId: comment.in_reply_to_id ?? null,\n reviewId: comment.pull_request_review_id ?? null,\n };\n}\n\nfunction assertReviewCommentPullRequest(\n input: GitHubPullRequestTarget,\n comment: GitHubReviewComment,\n): void {\n const expected = positiveInteger(input.pullRequestNumber, \"pullRequestNumber\");\n if (comment.pullRequestNumber !== expected) {\n throw new Error(\n `GitHub review comment ${comment.id} does not belong to pull request ${expected}`,\n );\n }\n}\n\nfunction parseIssueComment(value: unknown): GitHubIssueComment {\n const comment = issueCommentSchema.parse(value);\n return {\n id: comment.id,\n body: comment.body,\n url: comment.html_url,\n author: comment.user?.login ?? null,\n authorType: comment.user?.type ?? null,\n };\n}\n\nfunction parseLabels(value: unknown): string[] {\n return labelsSchema.parse(value).map(({ name }) => name);\n}\n\nfunction parseCheckRun(value: unknown): GitHubCheckRun {\n const checkRun = checkRunSchema.parse(value);\n return {\n id: checkRun.id,\n name: checkRun.name,\n headSha: checkRun.head_sha,\n status: checkRun.status,\n conclusion: checkRun.conclusion,\n url: checkRun.html_url,\n detailsUrl: checkRun.details_url,\n externalId: checkRun.external_id,\n startedAt: checkRun.started_at,\n completedAt: checkRun.completed_at,\n };\n}\n\nfunction checkRunFields(input: CheckRunFields): Record<string, unknown> {\n return {\n ...(input.status === undefined ? {} : { status: input.status }),\n ...(input.conclusion === undefined ? {} : { conclusion: input.conclusion }),\n ...(input.detailsUrl === undefined ? {} : { details_url: input.detailsUrl }),\n ...(input.externalId === undefined ? {} : { external_id: input.externalId }),\n ...(input.startedAt === undefined ? {} : { started_at: input.startedAt }),\n ...(input.completedAt === undefined ? {} : { completed_at: input.completedAt }),\n ...(input.output === undefined ? {} : { output: checkRunOutput(input.output) }),\n };\n}\n\nfunction assertCheckRunFields(input: CheckRunFields): void {\n if (input.status === \"completed\") {\n if (input.conclusion === undefined) {\n throw new Error(\"completed check runs require a conclusion\");\n }\n return;\n }\n if (input.conclusion !== undefined) {\n throw new Error(\"a check run conclusion requires completed status\");\n }\n if (input.completedAt !== undefined) {\n throw new Error(\"a check run completion time requires completed status\");\n }\n}\n\nfunction checkRunOutput(output: CheckRunOutput): Record<string, unknown> {\n return {\n title: output.title,\n summary: output.summary,\n ...(output.text === undefined ? {} : { text: output.text }),\n ...(output.annotations === undefined\n ? {}\n : {\n annotations: output.annotations.map((annotation) => ({\n path: annotation.path,\n start_line: positiveInteger(annotation.startLine, \"annotation startLine\"),\n end_line: positiveInteger(\n annotation.endLine ?? annotation.startLine,\n \"annotation endLine\",\n ),\n ...(annotation.startColumn === undefined\n ? {}\n : {\n start_column: positiveInteger(annotation.startColumn, \"annotation startColumn\"),\n }),\n ...(annotation.endColumn === undefined\n ? {}\n : { end_column: positiveInteger(annotation.endColumn, \"annotation endColumn\") }),\n annotation_level: annotation.annotationLevel,\n message: annotation.message,\n ...(annotation.title === undefined ? {} : { title: annotation.title }),\n ...(annotation.rawDetails === undefined ? {} : { raw_details: annotation.rawDetails }),\n })),\n }),\n };\n}\n\nasync function assertReviewCommentAuthor(\n input: GitHubRepositoryRequest & ReviewCommentTrustInput,\n author: string | null,\n): Promise<void> {\n if (input.authorPolicy === \"any\") {\n return;\n }\n if (author === null || !(await hasGitHubRepositoryWriteAccess({ ...input, author }))) {\n throw new GitHubReviewCommentAuthorError(author);\n }\n}\n\nfunction positiveInteger(value: number, name: string): number {\n if (!Number.isInteger(value) || value < 1) {\n throw new Error(`${name} must be a positive integer`);\n }\n return value;\n}\n\nfunction commitSha(value: string): string {\n return z\n .string()\n .regex(/^[0-9a-f]{40}$/)\n .parse(value);\n}\n\n/** Raw payload, shared secret, and provider signature used for webhook verification. */\nexport interface VerifyGitHubSignatureInput {\n secret: string;\n payload: string;\n signature: string | null;\n}\n\n/**\n * Verify a GitHub webhook HMAC signature (the x-hub-signature-256 header)\n * against the raw request body. Returns false for missing or malformed\n * signatures instead of throwing.\n */\nexport function verifyGitHubSignature(options: VerifyGitHubSignatureInput): boolean {\n const { secret, payload, signature } = options;\n if (signature === null || !signature.startsWith(\"sha256=\")) {\n return false;\n }\n const expected = createHmac(\"sha256\", secret).update(payload).digest(\"hex\");\n const provided = signature.slice(\"sha256=\".length);\n if (provided.length !== expected.length) {\n return false;\n }\n return timingSafeEqual(Buffer.from(provided, \"hex\"), Buffer.from(expected, \"hex\"));\n}\n\nconst pushEventSchema = z.looseObject({\n ref: z.string().min(1),\n repository: z.looseObject({\n default_branch: z.string().min(1),\n full_name: gitHubRepositorySlugSchema,\n }),\n});\n\n/** Normalized observation that a repository's configured default branch advanced. */\nexport interface GitHubDefaultBranchPush {\n source: \"github_default_branch_push\";\n deliveryId: string;\n repositorySlug: RepositorySlug;\n defaultBranch: string;\n}\n\n/** Normalize a push to a repository's default branch for deterministic reconciliation. */\nexport function normalizeGitHubDefaultBranchPush(\n options: WebhookEvent,\n): GitHubDefaultBranchPush | null {\n if (options.event !== \"push\") return null;\n const parsed = pushEventSchema.safeParse(options.payload);\n if (\n !parsed.success ||\n parsed.data.ref !== `refs/heads/${parsed.data.repository.default_branch}`\n ) {\n return null;\n }\n return {\n source: \"github_default_branch_push\",\n deliveryId: options.deliveryId,\n repositorySlug: parsed.data.repository.full_name,\n defaultBranch: parsed.data.repository.default_branch,\n };\n}\n\nconst pullRequestEventSchema = z.looseObject({\n action: z.string(),\n number: z.number().int().positive(),\n pull_request: z.looseObject({\n html_url: z.url(),\n draft: z.boolean(),\n user: z.looseObject({ login: z.string().min(1) }),\n head: z.looseObject({\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n ref: z.string().min(1),\n repo: z.looseObject({ full_name: gitHubRepositorySlugSchema }),\n }),\n base: z.looseObject({\n sha: z.string().regex(/^[0-9a-f]{40}$/),\n ref: z.string().min(1),\n }),\n }),\n repository: z.looseObject({ full_name: gitHubRepositorySlugSchema }),\n sender: z.looseObject({ login: z.string().min(1) }),\n});\n\nconst reviewablePullRequestActions = new Set([\n \"opened\",\n \"reopened\",\n \"ready_for_review\",\n \"synchronize\",\n]);\n\n/** Reviewable pull-request webhook normalized for Factory intake. */\nexport interface GitHubPullRequestSignal extends NormalizedSignal<\"github_pr\"> {\n repositorySlug: RepositorySlug;\n pullRequest: {\n pullRequestNumber: number;\n pullRequestUrl: string;\n author: string;\n draft: boolean;\n headSha: string;\n headBranch: string;\n headRepositorySlug: RepositorySlug;\n baseSha: string;\n baseBranch: string;\n sender: string;\n };\n}\n\n/** Normalize a newly reviewable or updated pull request into a factory signal. */\nexport function normalizeGitHubPullRequest(options: WebhookEvent): GitHubPullRequestSignal | null {\n if (options.event !== \"pull_request\") return null;\n const parsed = pullRequestEventSchema.safeParse(options.payload);\n if (!parsed.success || !reviewablePullRequestActions.has(parsed.data.action)) return null;\n if (parsed.data.pull_request.draft && parsed.data.action !== \"ready_for_review\") return null;\n\n const slug = parsed.data.repository.full_name;\n const pull = parsed.data.pull_request;\n return {\n source: \"github_pr\",\n deliveryId: options.deliveryId,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}/pull/${parsed.data.number}` },\n pullRequest: {\n pullRequestNumber: parsed.data.number,\n pullRequestUrl: pull.html_url,\n author: pull.user.login,\n draft: pull.draft,\n headSha: pull.head.sha,\n headBranch: pull.head.ref,\n headRepositorySlug: pull.head.repo.full_name,\n baseSha: pull.base.sha,\n baseBranch: pull.base.ref,\n sender: parsed.data.sender.login,\n },\n payload: options.payload,\n };\n}\n\nconst issueEventSchema = z.looseObject({\n action: z.string(),\n issue: z.looseObject({\n number: z.number().int().min(1),\n title: z.string(),\n body: z.string().nullable(),\n }),\n repository: z.looseObject({\n full_name: gitHubRepositorySlugSchema,\n }),\n});\n\n/** Opened GitHub issue normalized for Factory intake. */\nexport interface GitHubIssueSignal extends NormalizedSignal<\"github_issue\"> {\n repositorySlug: RepositorySlug;\n issue: { number: number; title: string; body: string | null };\n}\n\nconst failedWorkflowConclusions = new Set([\n \"action_required\",\n \"failure\",\n \"stale\",\n \"startup_failure\",\n \"timed_out\",\n]);\n\nconst workflowRunEventSchema = z.looseObject({\n action: z.string(),\n repository: z.looseObject({\n default_branch: z.string().min(1),\n full_name: gitHubRepositorySlugSchema,\n }),\n workflow_run: z.looseObject({\n id: z.number().int().min(1),\n name: z.string().min(1),\n event: z.string().min(1),\n head_branch: z.string().min(1).nullable(),\n head_repository: z\n .looseObject({\n full_name: gitHubRepositorySlugSchema,\n })\n .nullable(),\n head_sha: z.string().min(1),\n html_url: z.url(),\n conclusion: z.string().nullable(),\n run_attempt: z.number().int().min(1),\n }),\n});\n\n/** Unsuccessful GitHub Actions run normalized for Factory intake. */\nexport interface GitHubCiFailureSignal extends NormalizedSignal<\"github_ci_failure\"> {\n repositoryDefaultBranch: string;\n repositorySlug: RepositorySlug;\n workflowRun: {\n id: number;\n name: string;\n trigger: string;\n branch: string | null;\n headRepositorySlug: RepositorySlug | null;\n headSha: string;\n url: string;\n conclusion: string;\n attempt: number;\n };\n}\n\n/**\n * Normalize a GitHub issues webhook into the factory's signal shape. Returns\n * null for payloads that are not an opened issue. The caller supplies the\n * repository id; the payload stays untrusted data.\n */\nexport function normalizeGitHubIssueOpened(options: WebhookEvent): GitHubIssueSignal | null {\n if (options.event !== \"issues\") {\n return null;\n }\n const parsed = issueEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"opened\") {\n return null;\n }\n const slug = parsed.data.repository.full_name;\n const { number, title, body } = parsed.data.issue;\n return {\n source: \"github_issue\",\n deliveryId: options.deliveryId,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}#${number}` },\n issue: { number, title, body },\n payload: options.payload,\n };\n}\n\nconst pullRequestClosedSchema = z.looseObject({\n action: z.string(),\n pull_request: z.looseObject({\n number: z.number().int().min(1),\n html_url: z.url(),\n merged: z.boolean(),\n merged_by: z\n .looseObject({ login: z.string().min(1) })\n .nullable()\n .optional(),\n merge_commit_sha: z\n .string()\n .regex(/^[0-9a-f]{40}$/)\n .nullable()\n .optional(),\n }),\n repository: z.looseObject({\n full_name: gitHubRepositorySlugSchema,\n }),\n sender: z.looseObject({ login: z.string().min(1) }),\n});\n\n/** Normalized provider observation that a pull request was merged or closed. */\nexport interface GitHubPullRequestClosed extends GitHubPullRequestReference {\n source: \"github_pull_request_closed\";\n deliveryId: string;\n repositorySlug: RepositorySlug;\n merged: boolean;\n /** The merge commit on the base branch; null when closed without merging. */\n mergeCommitSha: string | null;\n /** The GitHub login that merged the pull request, or closed it without merging. */\n decidedBy: string;\n}\n\n/**\n * Normalize a closed pull_request webhook so the factory can observe what\n * happened to its change: merged records merged_by (the sender when GitHub\n * omits it), a close without merge records the sender.\n */\nexport function normalizeGitHubPullRequestClosed(\n options: WebhookEvent,\n): GitHubPullRequestClosed | null {\n if (options.event !== \"pull_request\") {\n return null;\n }\n const parsed = pullRequestClosedSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"closed\") {\n return null;\n }\n const pr = parsed.data.pull_request;\n const sender = parsed.data.sender.login;\n return {\n source: \"github_pull_request_closed\",\n deliveryId: options.deliveryId,\n repositorySlug: parsed.data.repository.full_name,\n pullRequestNumber: pr.number,\n pullRequestUrl: pr.html_url,\n merged: pr.merged,\n mergeCommitSha: pr.merged ? (pr.merge_commit_sha ?? null) : null,\n decidedBy: pr.merged ? (pr.merged_by?.login ?? sender) : sender,\n };\n}\n\n/** Normalize a completed, unsuccessful GitHub Actions run into a CI failure signal. */\nexport function normalizeGitHubWorkflowRunFailure(\n options: WebhookEvent,\n): GitHubCiFailureSignal | null {\n if (options.event !== \"workflow_run\") {\n return null;\n }\n const parsed = workflowRunEventSchema.safeParse(options.payload);\n if (!parsed.success || parsed.data.action !== \"completed\") {\n return null;\n }\n\n const run = parsed.data.workflow_run;\n const conclusion = run.conclusion;\n if (conclusion === null || !failedWorkflowConclusions.has(conclusion)) {\n return null;\n }\n const slug = parsed.data.repository.full_name;\n return {\n source: \"github_ci_failure\",\n deliveryId: options.deliveryId,\n repositoryDefaultBranch: parsed.data.repository.default_branch,\n repositorySlug: slug,\n replyTo: { channel: \"github\", address: `${slug}/actions/runs/${run.id}` },\n workflowRun: {\n id: run.id,\n name: run.name,\n trigger: run.event,\n branch: run.head_branch,\n headRepositorySlug: run.head_repository?.full_name ?? null,\n headSha: run.head_sha,\n url: run.html_url,\n conclusion,\n attempt: run.run_attempt,\n },\n payload: options.payload,\n };\n}\n"],"mappings":";;;;;;AAkEA,MAAM,eAAe;AACrB,MAAM,6BAA6B,EAChC,OAAO,CAAC,CACR,IAAI,CAAC,CAAC,CACN,WAAW,UAAU,MAAM,YAAY,CAAC,CAAC,CACzC,KAAK,oBAAoB;AAE5B,MAAM,kCAAkC,EAAE,YAAY;CACpD,QAAQ,EAAE,QAAQ,SAAS;CAC3B,SAAS,EAAE,YAAY;EACrB,IAAI,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS;EAC9B,MAAM,EAAE,OAAO;EACf,UAAU,EAAE,IAAI;EAChB,gBAAgB,EAAE,OAAO,CAAC,CAAC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,OAAO;CAC/D,IAAI,CAAC,OAAO,WAAW,OAAO,KAAK,WAAW,aAC5C,OAAO;CAGT,MAAM,MAAM,OAAO,KAAK;CACxB,MAAM,aAAa,IAAI;CACvB,IAAI,eAAe,QAAQ,CAAC,0BAA0B,IAAI,UAAU,GAClE,OAAO;CAET,MAAM,OAAO,OAAO,KAAK,WAAW;CACpC,OAAO;EACL,QAAQ;EACR,YAAY,QAAQ;EACpB,yBAAyB,OAAO,KAAK,WAAW;EAChD,gBAAgB;EAChB,SAAS;GAAE,SAAS;GAAU,SAAS,GAAG,KAAK,gBAAgB,IAAI;EAAK;EACxE,aAAa;GACX,IAAI,IAAI;GACR,MAAM,IAAI;GACV,SAAS,IAAI;GACb,QAAQ,IAAI;GACZ,oBAAoB,IAAI,iBAAiB,aAAa;GACtD,SAAS,IAAI;GACb,KAAK,IAAI;GACT;GACA,SAAS,IAAI;EACf;EACA,SAAS,QAAQ;CACnB;AACF"}
@@ -0,0 +1,51 @@
1
+ import { z } from "zod";
2
+ //#region src/image-input.d.ts
3
+ /** Maximum decoded byte size of all images attached to one message. */
4
+ declare const MAX_IMAGE_BYTES: number;
5
+ /** Maximum number of images attached to one message. */
6
+ declare const MAX_IMAGES = 4;
7
+ /** Validates an immutable owner-scoped image identifier. */
8
+ declare const imageIdSchema: z.ZodType<`img_${string}`, string>;
9
+ /** Immutable owner-scoped identifier for one uploaded image. */
10
+ type ImageId = z.infer<typeof imageIdSchema>;
11
+ /** Validates metadata referencing one previously uploaded image. */
12
+ declare const imageAttachmentSchema: z.ZodObject<{
13
+ id: z.ZodType<`img_${string}`, string, z.core.$ZodTypeInternals<`img_${string}`, string>>;
14
+ filename: z.ZodString;
15
+ mediaType: z.ZodEnum<{
16
+ "image/png": "image/png";
17
+ "image/jpeg": "image/jpeg";
18
+ "image/webp": "image/webp";
19
+ }>;
20
+ size: z.ZodNumber;
21
+ }, z.core.$strict>;
22
+ /** Metadata that safely references an immutable uploaded image. */
23
+ type ImageAttachment = Readonly<z.infer<typeof imageAttachmentSchema>>;
24
+ /** Validates the count, total size, and unique identity of message image attachments. */
25
+ declare const imageAttachmentsSchema: z.ZodReadonly<z.ZodArray<z.ZodObject<{
26
+ id: z.ZodType<`img_${string}`, string, z.core.$ZodTypeInternals<`img_${string}`, string>>;
27
+ filename: z.ZodString;
28
+ mediaType: z.ZodEnum<{
29
+ "image/png": "image/png";
30
+ "image/jpeg": "image/jpeg";
31
+ "image/webp": "image/webp";
32
+ }>;
33
+ size: z.ZodNumber;
34
+ }, z.core.$strict>>>;
35
+ /** Validates a supported image filename, media type, and bounded base64 payload. */
36
+ declare const imageUploadSchema: z.ZodObject<{
37
+ filename: z.ZodString;
38
+ mediaType: z.ZodEnum<{
39
+ "image/png": "image/png";
40
+ "image/jpeg": "image/jpeg";
41
+ "image/webp": "image/webp";
42
+ }>;
43
+ base64: z.ZodString;
44
+ }, z.core.$strict>;
45
+ /** Supported filename, media type, and bounded base64 payload for one image upload. */
46
+ type ImageUploadInput = Readonly<z.input<typeof imageUploadSchema>>;
47
+ /** Encodes an image ID into a sanitized provider file-part name. */
48
+ declare function imagePartFilename(image: ImageAttachment): string;
49
+ //#endregion
50
+ export { ImageAttachment, ImageId, ImageUploadInput, MAX_IMAGES, MAX_IMAGE_BYTES, imageAttachmentSchema, imageAttachmentsSchema, imageIdSchema, imagePartFilename, imageUploadSchema };
51
+ //# sourceMappingURL=image-input.d.mts.map
@@ -0,0 +1,63 @@
1
+ import { z } from "zod";
2
+ //#region src/image-input.ts
3
+ /** Maximum decoded byte size of all images attached to one message. */
4
+ const MAX_IMAGE_BYTES = 3145728;
5
+ /** Maximum number of images attached to one message. */
6
+ const MAX_IMAGES = 4;
7
+ /** Validates an immutable owner-scoped image identifier. */
8
+ const imageIdSchema = z.string().regex(/^img_[a-f0-9]{64}$/u).describe("Immutable, owner-scoped image identifier.");
9
+ const imageMediaTypeSchema = z.enum([
10
+ "image/png",
11
+ "image/jpeg",
12
+ "image/webp"
13
+ ]).describe("Supported raster image format.");
14
+ /** Validates metadata referencing one previously uploaded image. */
15
+ const imageAttachmentSchema = z.strictObject({
16
+ id: imageIdSchema,
17
+ filename: z.string().min(1).max(160).describe("Display filename of the uploaded image."),
18
+ mediaType: imageMediaTypeSchema,
19
+ size: z.number().int().positive().max(MAX_IMAGE_BYTES).describe("Decoded image size in bytes.")
20
+ });
21
+ /** Validates the count, total size, and unique identity of message image attachments. */
22
+ const imageAttachmentsSchema = z.array(imageAttachmentSchema).max(4).refine((images) => images.reduce((sum, image) => sum + image.size, 0) <= MAX_IMAGE_BYTES, "Images must total at most 3 MiB").refine((images) => new Set(images.map((image) => image.id)).size === images.length, "Do not attach the same image twice").describe("Up to four images, totaling at most 3 MiB.").readonly();
23
+ /** Validates a supported image filename, media type, and bounded base64 payload. */
24
+ const imageUploadSchema = z.strictObject({
25
+ filename: imageAttachmentSchema.shape.filename,
26
+ mediaType: imageMediaTypeSchema,
27
+ base64: z.string().min(4).max(4 * Math.ceil(MAX_IMAGE_BYTES / 3)).regex(/^[A-Za-z0-9+/]*={0,2}$/u).refine((value) => value.length % 4 === 0, "Invalid base64 image").describe("Base64-encoded image bytes, without a data URL prefix.")
28
+ });
29
+ /** Reports whether a message contains non-whitespace text or at least one image. */
30
+ function hasMessageContent(input) {
31
+ return input.message.trim().length > 0 || (input.attachments?.length ?? 0) > 0;
32
+ }
33
+ /** Encodes an image ID into a sanitized provider file-part name. */
34
+ function imagePartFilename(image) {
35
+ return `${image.id}__${image.filename.replace(/[^\w.-]/gu, "_")}`;
36
+ }
37
+ /** Recovers valid image attachment metadata from provider file parts. */
38
+ function receivedImages(parts) {
39
+ if (!Array.isArray(parts)) return [];
40
+ return parts.flatMap((part) => {
41
+ const file = z.object({
42
+ type: z.literal("file"),
43
+ filename: z.string(),
44
+ mediaType: imageMediaTypeSchema,
45
+ size: z.number().optional()
46
+ }).safeParse(part);
47
+ if (!file.success) return [];
48
+ const filename = file.data.filename.split("/").at(-1) ?? "";
49
+ const match = /^(img_[a-f0-9]{64})__(.+)$/u.exec(filename);
50
+ if (!match) return [];
51
+ const image = imageAttachmentSchema.safeParse({
52
+ id: match[1],
53
+ filename: match[2],
54
+ mediaType: file.data.mediaType,
55
+ size: file.data.size ?? 1
56
+ });
57
+ return image.success ? [image.data] : [];
58
+ });
59
+ }
60
+ //#endregion
61
+ export { MAX_IMAGES, MAX_IMAGE_BYTES, hasMessageContent, imageAttachmentSchema, imageAttachmentsSchema, imageIdSchema, imagePartFilename, imageUploadSchema, receivedImages };
62
+
63
+ //# sourceMappingURL=image-input.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image-input.mjs","names":[],"sources":["../src/image-input.ts"],"sourcesContent":["import { z } from \"zod\";\n\n/** Maximum decoded byte size of all images attached to one message. */\nexport const MAX_IMAGE_BYTES = 3 * 1024 * 1024;\n/** Maximum number of images attached to one message. */\nexport const MAX_IMAGES = 4;\n/** Validates an immutable owner-scoped image identifier. */\nexport const imageIdSchema = z\n .string()\n .regex(/^img_[a-f0-9]{64}$/u)\n .describe(\"Immutable, owner-scoped image identifier.\") as z.ZodType<`img_${string}`, string>;\n/** Immutable owner-scoped identifier for one uploaded image. */\nexport type ImageId = z.infer<typeof imageIdSchema>;\nconst imageMediaTypeSchema = z\n .enum([\"image/png\", \"image/jpeg\", \"image/webp\"])\n .describe(\"Supported raster image format.\");\n/** Validates metadata referencing one previously uploaded image. */\nexport const imageAttachmentSchema = z.strictObject({\n id: imageIdSchema,\n filename: z.string().min(1).max(160).describe(\"Display filename of the uploaded image.\"),\n mediaType: imageMediaTypeSchema,\n size: z.number().int().positive().max(MAX_IMAGE_BYTES).describe(\"Decoded image size in bytes.\"),\n});\n/** Metadata that safely references an immutable uploaded image. */\nexport type ImageAttachment = Readonly<z.infer<typeof imageAttachmentSchema>>;\n/** Validates the count, total size, and unique identity of message image attachments. */\nexport const imageAttachmentsSchema = z\n .array(imageAttachmentSchema)\n .max(MAX_IMAGES)\n .refine(\n (images) => images.reduce((sum, image) => sum + image.size, 0) <= MAX_IMAGE_BYTES,\n \"Images must total at most 3 MiB\",\n )\n .refine(\n (images) => new Set(images.map((image) => image.id)).size === images.length,\n \"Do not attach the same image twice\",\n )\n .describe(\"Up to four images, totaling at most 3 MiB.\")\n .readonly();\n/** Validates a supported image filename, media type, and bounded base64 payload. */\nexport const imageUploadSchema = z.strictObject({\n filename: imageAttachmentSchema.shape.filename,\n mediaType: imageMediaTypeSchema,\n base64: z\n .string()\n .min(4)\n .max(4 * Math.ceil(MAX_IMAGE_BYTES / 3))\n .regex(/^[A-Za-z0-9+/]*={0,2}$/u)\n .refine((value) => value.length % 4 === 0, \"Invalid base64 image\")\n .describe(\"Base64-encoded image bytes, without a data URL prefix.\"),\n});\n/** Supported filename, media type, and bounded base64 payload for one image upload. */\nexport type ImageUploadInput = Readonly<z.input<typeof imageUploadSchema>>;\n\n/** Reports whether a message contains non-whitespace text or at least one image. */\nexport function hasMessageContent(input: {\n readonly message: string;\n readonly attachments?: readonly ImageAttachment[];\n}): boolean {\n return input.message.trim().length > 0 || (input.attachments?.length ?? 0) > 0;\n}\n\n/** Encodes an image ID into a sanitized provider file-part name. */\nexport function imagePartFilename(image: ImageAttachment): string {\n return `${image.id}__${image.filename.replace(/[^\\w.-]/gu, \"_\")}`;\n}\n\n/** Recovers valid image attachment metadata from provider file parts. */\nexport function receivedImages(parts: unknown): ImageAttachment[] {\n if (!Array.isArray(parts)) return [];\n return parts.flatMap((part: unknown) => {\n const file = z\n .object({\n type: z.literal(\"file\"),\n filename: z.string(),\n mediaType: imageMediaTypeSchema,\n size: z.number().optional(),\n })\n .safeParse(part);\n if (!file.success) return [];\n const filename = file.data.filename.split(\"/\").at(-1) ?? \"\";\n const match = /^(img_[a-f0-9]{64})__(.+)$/u.exec(filename);\n if (!match) return [];\n const image = imageAttachmentSchema.safeParse({\n id: match[1],\n filename: match[2],\n mediaType: file.data.mediaType,\n size: file.data.size ?? 1,\n });\n return image.success ? [image.data] : [];\n });\n}\n"],"mappings":";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AAgB,kBAAkB,OAAgC;CAChE,OAAO,GAAG,MAAM,GAAG,IAAI,MAAM,SAAS,QAAQ,aAAa,GAAG;AAChE;;AAGA,SAAgB,eAAe,OAAmC;CAChE,IAAI,CAAC,MAAM,QAAQ,KAAK,GAAG,OAAO,CAAC;CACnC,OAAO,MAAM,SAAS,SAAkB;EACtC,MAAM,OAAO,EACV,OAAO;GACN,MAAM,EAAE,QAAQ,MAAM;GACtB,UAAU,EAAE,OAAO;GACnB,WAAW;GACX,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS;EAC5B,CAAC,CAAC,CACD,UAAU,IAAI;EACjB,IAAI,CAAC,KAAK,SAAS,OAAO,CAAC;EAC3B,MAAM,WAAW,KAAK,KAAK,SAAS,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,KAAK;EACzD,MAAM,QAAQ,8BAA8B,KAAK,QAAQ;EACzD,IAAI,CAAC,OAAO,OAAO,CAAC;EACpB,MAAM,QAAQ,sBAAsB,UAAU;GAC5C,IAAI,MAAM;GACV,UAAU,MAAM;GAChB,WAAW,KAAK,KAAK;GACrB,MAAM,KAAK,KAAK,QAAQ;EAC1B,CAAC;EACD,OAAO,MAAM,UAAU,CAAC,MAAM,IAAI,IAAI,CAAC;CACzC,CAAC;AACH"}
@@ -0,0 +1,53 @@
1
+ import { z } from "zod";
2
+ //#region src/inbox-activity.d.ts
3
+ /** Validates one application-owned attention item, independent of a Factory session. */
4
+ declare const inboxActivityItemSchema: z.ZodObject<{
5
+ id: z.ZodString;
6
+ repository: z.ZodType<`${string}/${string}`, string, z.core.$ZodTypeInternals<`${string}/${string}`, string>>;
7
+ source: z.ZodString;
8
+ title: z.ZodString;
9
+ category: z.ZodString;
10
+ label: z.ZodString;
11
+ summary: z.ZodString;
12
+ url: z.ZodURL;
13
+ updatedAt: z.ZodISODateTime;
14
+ revision: z.ZodNullable<z.ZodString>;
15
+ details: z.ZodReadonly<z.ZodArray<z.ZodObject<{
16
+ text: z.ZodString;
17
+ url: z.ZodOptional<z.ZodURL>;
18
+ }, z.core.$strict>>>;
19
+ }, z.core.$strict>;
20
+ /** Validates an optional, bounded external attention projection. */
21
+ declare const inboxActivitySchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
22
+ state: z.ZodLiteral<"ready">;
23
+ capturedAt: z.ZodISODateTime;
24
+ items: z.ZodReadonly<z.ZodArray<z.ZodObject<{
25
+ id: z.ZodString;
26
+ repository: z.ZodType<`${string}/${string}`, string, z.core.$ZodTypeInternals<`${string}/${string}`, string>>;
27
+ source: z.ZodString;
28
+ title: z.ZodString;
29
+ category: z.ZodString;
30
+ label: z.ZodString;
31
+ summary: z.ZodString;
32
+ url: z.ZodURL;
33
+ updatedAt: z.ZodISODateTime;
34
+ revision: z.ZodNullable<z.ZodString>;
35
+ details: z.ZodReadonly<z.ZodArray<z.ZodObject<{
36
+ text: z.ZodString;
37
+ url: z.ZodOptional<z.ZodURL>;
38
+ }, z.core.$strict>>>;
39
+ }, z.core.$strict>>>;
40
+ limitations: z.ZodReadonly<z.ZodArray<z.ZodString>>;
41
+ truncated: z.ZodBoolean;
42
+ }, z.core.$strict>, z.ZodObject<{
43
+ state: z.ZodLiteral<"unavailable">;
44
+ capturedAt: z.ZodISODateTime;
45
+ reason: z.ZodString;
46
+ }, z.core.$strict>], "state">;
47
+ /** One application-owned attention item and its evidence. */
48
+ type InboxActivityItem = z.infer<typeof inboxActivityItemSchema>;
49
+ /** Read-only activity supplied by an optional application reader. */
50
+ type InboxActivity = z.infer<typeof inboxActivitySchema>;
51
+ //#endregion
52
+ export { InboxActivity, InboxActivityItem, inboxActivityItemSchema, inboxActivitySchema };
53
+ //# sourceMappingURL=inbox-activity.d.mts.map
@@ -0,0 +1,41 @@
1
+ import { repositorySlugSchema } from "./schema/repository.mjs";
2
+ import { z } from "zod";
3
+ //#region src/inbox-activity.ts
4
+ const text = z.string().trim().min(1);
5
+ const link = z.url().refine((value) => {
6
+ const url = new URL(value);
7
+ return ["https:", "http:"].includes(url.protocol) && !url.username && !url.password;
8
+ }, "Use an HTTP(S) URL without credentials");
9
+ /** Validates one application-owned attention item, independent of a Factory session. */
10
+ const inboxActivityItemSchema = z.strictObject({
11
+ id: text.describe("Stable identity, unique across this reader's sources."),
12
+ repository: repositorySlugSchema.describe("Configured repository owning this item."),
13
+ source: text.describe("Name of the external activity source."),
14
+ title: text.describe("Work requiring operator attention."),
15
+ category: text.describe("Application-owned grouping key."),
16
+ label: text.describe("Human-readable attention category."),
17
+ summary: text.describe("Why this item needs attention."),
18
+ url: link.describe("Source page where the operator can inspect or act."),
19
+ updatedAt: z.iso.datetime().describe("Last update reported by the source."),
20
+ revision: text.nullable().describe("Exact code revision, or null when unknown."),
21
+ details: z.array(z.strictObject({
22
+ text: text.describe("Check, reviewer, or feedback detail."),
23
+ url: link.optional().describe("Optional source link for this detail.")
24
+ })).readonly().describe("Bounded details supplied by the source.")
25
+ });
26
+ /** Validates an optional, bounded external attention projection. */
27
+ const inboxActivitySchema = z.discriminatedUnion("state", [z.strictObject({
28
+ state: z.literal("ready").describe("The reader completed, possibly with partial results."),
29
+ capturedAt: z.iso.datetime().describe("When the source was read; caches preserve this time."),
30
+ items: z.array(inboxActivityItemSchema).readonly().describe("Items requiring attention."),
31
+ limitations: z.array(text).readonly().describe("Unavailable sources or incomplete evidence."),
32
+ truncated: z.boolean().describe("Whether configured limits or failures omitted information.")
33
+ }), z.strictObject({
34
+ state: z.literal("unavailable").describe("No external activity projection is available."),
35
+ capturedAt: z.iso.datetime().describe("When availability was checked."),
36
+ reason: text.describe("Why the activity could not be read.")
37
+ })]);
38
+ //#endregion
39
+ export { inboxActivityItemSchema, inboxActivitySchema };
40
+
41
+ //# sourceMappingURL=inbox-activity.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inbox-activity.mjs","names":[],"sources":["../src/inbox-activity.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { repositorySlugSchema } from \"./schema/repository\";\n\nconst text = z.string().trim().min(1);\nconst link = z.url().refine((value) => {\n const url = new URL(value);\n return [\"https:\", \"http:\"].includes(url.protocol) && !url.username && !url.password;\n}, \"Use an HTTP(S) URL without credentials\");\n\n/** Validates one application-owned attention item, independent of a Factory session. */\nexport const inboxActivityItemSchema = z.strictObject({\n id: text.describe(\"Stable identity, unique across this reader's sources.\"),\n repository: repositorySlugSchema.describe(\"Configured repository owning this item.\"),\n source: text.describe(\"Name of the external activity source.\"),\n title: text.describe(\"Work requiring operator attention.\"),\n category: text.describe(\"Application-owned grouping key.\"),\n label: text.describe(\"Human-readable attention category.\"),\n summary: text.describe(\"Why this item needs attention.\"),\n url: link.describe(\"Source page where the operator can inspect or act.\"),\n updatedAt: z.iso.datetime().describe(\"Last update reported by the source.\"),\n revision: text.nullable().describe(\"Exact code revision, or null when unknown.\"),\n details: z\n .array(\n z.strictObject({\n text: text.describe(\"Check, reviewer, or feedback detail.\"),\n url: link.optional().describe(\"Optional source link for this detail.\"),\n }),\n )\n .readonly()\n .describe(\"Bounded details supplied by the source.\"),\n});\n\n/** Validates an optional, bounded external attention projection. */\nexport const inboxActivitySchema = z.discriminatedUnion(\"state\", [\n z.strictObject({\n state: z.literal(\"ready\").describe(\"The reader completed, possibly with partial results.\"),\n capturedAt: z.iso.datetime().describe(\"When the source was read; caches preserve this time.\"),\n items: z.array(inboxActivityItemSchema).readonly().describe(\"Items requiring attention.\"),\n limitations: z.array(text).readonly().describe(\"Unavailable sources or incomplete evidence.\"),\n truncated: z.boolean().describe(\"Whether configured limits or failures omitted information.\"),\n }),\n z.strictObject({\n state: z.literal(\"unavailable\").describe(\"No external activity projection is available.\"),\n capturedAt: z.iso.datetime().describe(\"When availability was checked.\"),\n reason: text.describe(\"Why the activity could not be read.\"),\n }),\n]);\n\n/** One application-owned attention item and its evidence. */\nexport type InboxActivityItem = z.infer<typeof inboxActivityItemSchema>;\n/** Read-only activity supplied by an optional application reader. */\nexport type InboxActivity = z.infer<typeof inboxActivitySchema>;\n"],"mappings":";;;AAGA,MAAM,OAAO,E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