literally-aeo 0.2.2 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (483) hide show
  1. package/README.md +183 -14
  2. package/dist/author-tools.js +386 -283
  3. package/dist/cli.mjs +19943 -16532
  4. package/dist/lib/access/schema.js +6 -6
  5. package/dist/lib/agents/author-schema.js +12 -12
  6. package/dist/lib/agents/author-validation.js +15 -15
  7. package/dist/lib/agents/copy-validation.js +18 -17
  8. package/dist/lib/agents/copywriter-input.js +16 -15
  9. package/dist/lib/agents/credentials.js +1 -1
  10. package/dist/lib/agents/facts.js +15 -14
  11. package/dist/lib/agents/methodology.js +56 -0
  12. package/dist/lib/agents/narrative-facts.js +13 -13
  13. package/dist/lib/agents/verifier.js +22 -20
  14. package/dist/lib/analysis/domain-classifier.js +21 -19
  15. package/dist/lib/analysis/domain-labels.js +12 -12
  16. package/dist/lib/analysis/outreach.js +2 -2
  17. package/dist/lib/analysis/progress-schema.js +6 -2
  18. package/dist/lib/analysis/progress.js +17 -16
  19. package/dist/lib/analysis/rate-evidence.js +6 -0
  20. package/dist/lib/analysis/retrieval.js +12 -12
  21. package/dist/lib/analysis/scoring.js +12 -12
  22. package/dist/lib/analysis/search-analyzer.js +13 -13
  23. package/dist/lib/analysis/sentiment.js +20 -18
  24. package/dist/lib/analysis/source-mix.js +2 -2
  25. package/dist/lib/author/examples.js +13 -13
  26. package/dist/lib/bundle/contracts.js +19 -13
  27. package/dist/lib/bundle/export.js +86 -31
  28. package/dist/lib/bundle/isolation.js +2 -2
  29. package/dist/lib/bundle/journal.js +14 -14
  30. package/dist/lib/bundle/project-journal.js +18 -18
  31. package/dist/lib/bundle/project.js +87 -30
  32. package/dist/lib/bundle/read.js +87 -32
  33. package/dist/lib/bundle/recorder.js +16 -16
  34. package/dist/lib/bundle/redact.js +14 -14
  35. package/dist/lib/bundle/trace-coverage.js +14 -14
  36. package/dist/lib/bundle/verify-integrity.js +17 -17
  37. package/dist/lib/bundle/verify-measurement.js +31 -22
  38. package/dist/lib/bundle/verify-report.js +36 -26
  39. package/dist/lib/bundle/verify.js +45 -35
  40. package/dist/lib/capture-manifest.js +13 -13
  41. package/dist/lib/checks/crawler-access.js +2 -2
  42. package/dist/lib/checks/renderability.js +2 -2
  43. package/dist/lib/checks/run-checks.js +20 -20
  44. package/dist/lib/chunks/{chunk-4XIAXX7K.js → chunk-2A327DMI.js} +1 -1
  45. package/dist/lib/chunks/{chunk-7WO3FFPS.js → chunk-2FK6QVU6.js} +3 -3
  46. package/dist/lib/chunks/{chunk-F2NSJ6PG.js → chunk-2WS6RC35.js} +8 -4
  47. package/dist/lib/chunks/{chunk-6EI4CVRW.js → chunk-3ESH5NDR.js} +5 -1
  48. package/dist/lib/chunks/{chunk-WIBMVNIH.js → chunk-3F5ZP2EO.js} +4 -4
  49. package/dist/lib/chunks/{chunk-ZXQPD4OC.js → chunk-3TF4JGQA.js} +126 -5
  50. package/dist/lib/chunks/{chunk-BFWK3TBN.js → chunk-3YPAIXFG.js} +8 -8
  51. package/dist/lib/chunks/{chunk-PIFTG6YW.js → chunk-4332MUTU.js} +4 -4
  52. package/dist/lib/chunks/{chunk-K2FZFESR.js → chunk-4MOZ3DVS.js} +8 -7
  53. package/dist/lib/chunks/{chunk-KFAT65P7.js → chunk-4SCPKDJV.js} +1 -1
  54. package/dist/lib/chunks/{chunk-6HMHXSCS.js → chunk-4ZR2LPUD.js} +3 -3
  55. package/dist/lib/chunks/{chunk-QGZ4QSUE.js → chunk-55KFAM4X.js} +36 -5
  56. package/dist/lib/chunks/{chunk-FJL2V6P5.js → chunk-66OL2XA6.js} +13 -8
  57. package/dist/lib/chunks/{chunk-4QQJXCD2.js → chunk-6FRZN5SA.js} +13 -28
  58. package/dist/lib/chunks/{chunk-3OE4UQIB.js → chunk-6FXNXXY7.js} +116 -7
  59. package/dist/lib/chunks/chunk-6TJXJZUL.js +97 -0
  60. package/dist/lib/chunks/{chunk-YKJHFD64.js → chunk-72ZLXWD4.js} +21 -4
  61. package/dist/lib/chunks/{chunk-2FOKEIIN.js → chunk-744YWRX7.js} +1 -1
  62. package/dist/lib/chunks/{chunk-I3UE52ZV.js → chunk-77EQ3RT6.js} +4 -4
  63. package/dist/lib/chunks/{chunk-AJO7XVXK.js → chunk-7GHR6MOG.js} +12 -12
  64. package/dist/lib/chunks/{chunk-JYCVBFH5.js → chunk-7GJTWUI4.js} +2 -2
  65. package/dist/lib/chunks/{chunk-UNCUG2YS.js → chunk-7NQOQNE7.js} +3 -3
  66. package/dist/lib/chunks/chunk-7Y3S7LD5.js +160 -0
  67. package/dist/lib/chunks/{chunk-U64NCRRR.js → chunk-7ZQAAEOK.js} +7 -6
  68. package/dist/lib/chunks/{chunk-MENTBQGB.js → chunk-A4QTI7FN.js} +78 -19
  69. package/dist/lib/chunks/{chunk-Y2CZ6FZY.js → chunk-ADNYALFZ.js} +36 -7
  70. package/dist/lib/chunks/{chunk-CH7OCYDL.js → chunk-B5ZAFK6T.js} +1 -1
  71. package/dist/lib/chunks/{chunk-WDT2Y7D7.js → chunk-B6YKBZXD.js} +20 -11
  72. package/dist/lib/chunks/{chunk-ZSEY7AHQ.js → chunk-BBK54RVK.js} +14 -11
  73. package/dist/lib/chunks/{chunk-YGLWQFKL.js → chunk-BE7EDOJY.js} +3 -3
  74. package/dist/lib/chunks/{chunk-OD36HUXA.js → chunk-BECSPYFC.js} +7 -8
  75. package/dist/lib/chunks/{chunk-HGGOGCPX.js → chunk-BNKNZTYH.js} +17 -14
  76. package/dist/lib/chunks/{chunk-2KH7LNK7.js → chunk-BOLZJBPS.js} +56 -15
  77. package/dist/lib/chunks/chunk-BQMUZLHO.js +17 -0
  78. package/dist/lib/chunks/chunk-C22Q3TKU.js +90 -0
  79. package/dist/lib/chunks/chunk-C3AZMWQJ.js +109 -0
  80. package/dist/lib/chunks/{chunk-T6XZQOXS.js → chunk-CCSF7LP5.js} +7 -7
  81. package/dist/lib/chunks/{chunk-JBOOD6MU.js → chunk-CHDK5EQK.js} +57 -16
  82. package/dist/lib/chunks/{chunk-NZFMOQHU.js → chunk-CWEVVIZI.js} +11 -1
  83. package/dist/lib/chunks/{chunk-75DMLOQ7.js → chunk-CYJNBVQB.js} +1 -1
  84. package/dist/lib/chunks/{chunk-66T7JC57.js → chunk-CZRHH5HF.js} +85 -5
  85. package/dist/lib/chunks/{chunk-FAUFE7MI.js → chunk-D7N5OLYL.js} +1 -1
  86. package/dist/lib/chunks/chunk-DBQ3HVPX.js +73 -0
  87. package/dist/lib/chunks/{chunk-PKNODC6Y.js → chunk-DC6CS6GC.js} +1 -1
  88. package/dist/lib/chunks/{chunk-7YDXD4MD.js → chunk-DHQKAIOP.js} +2 -2
  89. package/dist/lib/chunks/{chunk-LTCDLURT.js → chunk-DIR4UIRF.js} +73 -24
  90. package/dist/lib/chunks/{chunk-E2YTTB6Q.js → chunk-DSK3PM4Z.js} +1 -1
  91. package/dist/lib/chunks/chunk-DWOTAT7R.js +312 -0
  92. package/dist/lib/chunks/chunk-E2JICEL3.js +446 -0
  93. package/dist/lib/chunks/{chunk-HXHFMFQU.js → chunk-E5COBP7A.js} +13 -2
  94. package/dist/lib/chunks/{chunk-XAN4CRFP.js → chunk-EUHVUF7I.js} +1 -1
  95. package/dist/lib/chunks/{chunk-TNL2GWYR.js → chunk-EUXNCXCR.js} +22 -0
  96. package/dist/lib/chunks/chunk-F3MHGDZG.js +97 -0
  97. package/dist/lib/chunks/chunk-F7LCGM6W.js +120 -0
  98. package/dist/lib/chunks/chunk-FJAZEGU6.js +354 -0
  99. package/dist/lib/chunks/chunk-FOJVAGAD.js +91 -0
  100. package/dist/lib/chunks/chunk-FXR6P7HY.js +14 -0
  101. package/dist/lib/chunks/chunk-GC4XJYQW.js +145 -0
  102. package/dist/lib/chunks/chunk-GQZHZSAQ.js +108 -0
  103. package/dist/lib/chunks/{chunk-BRENK356.js → chunk-GZC3ASNL.js} +1 -1
  104. package/dist/lib/chunks/{chunk-3CMPR6ZZ.js → chunk-H2JJCIZW.js} +1 -1
  105. package/dist/lib/chunks/{chunk-XSER7WEB.js → chunk-H33MFLSH.js} +12 -12
  106. package/dist/lib/chunks/chunk-H4IE2JE6.js +118 -0
  107. package/dist/lib/chunks/chunk-H4LZ3U26.js +31 -0
  108. package/dist/lib/chunks/{chunk-XFUYEFQP.js → chunk-HHGLGVOZ.js} +1 -1
  109. package/dist/lib/chunks/{chunk-52F5XYOW.js → chunk-I2KRWXXO.js} +15 -7
  110. package/dist/lib/chunks/chunk-IDNT2WBK.js +27 -0
  111. package/dist/lib/chunks/{chunk-R5UPOEWE.js → chunk-IUQ6C4Y6.js} +14 -4
  112. package/dist/lib/chunks/chunk-IXYVHA7C.js +101 -0
  113. package/dist/lib/chunks/{chunk-FDM2YNQL.js → chunk-J3BZ3WPV.js} +1 -1
  114. package/dist/lib/chunks/{chunk-U6BW6LGX.js → chunk-J63WQUKR.js} +10 -3
  115. package/dist/lib/chunks/{chunk-OOLWU667.js → chunk-JBEKIT7Z.js} +10 -10
  116. package/dist/lib/chunks/chunk-JEAZREDN.js +94 -0
  117. package/dist/lib/chunks/{chunk-2B5QF6UQ.js → chunk-JFUWSJZT.js} +46 -5
  118. package/dist/lib/chunks/{chunk-SIJOQRRK.js → chunk-JHOLYLI4.js} +4 -2
  119. package/dist/lib/chunks/chunk-JOLIDHZV.js +39 -0
  120. package/dist/lib/chunks/{chunk-HCUJ2J7P.js → chunk-JWH33YCK.js} +17 -16
  121. package/dist/lib/chunks/{chunk-HGGRPOSA.js → chunk-K5K27WBZ.js} +10 -9
  122. package/dist/lib/chunks/{chunk-7HM6IZ3L.js → chunk-KU53HTUY.js} +2 -2
  123. package/dist/lib/chunks/{chunk-PIF3GL62.js → chunk-LJTFZ52Y.js} +24 -12
  124. package/dist/lib/chunks/chunk-LMUTZ6O2.js +335 -0
  125. package/dist/lib/chunks/chunk-LTPLZSXI.js +86 -0
  126. package/dist/lib/chunks/{chunk-RXSHKWZJ.js → chunk-M3WZCV65.js} +3 -3
  127. package/dist/lib/chunks/{chunk-ZOGIJGU3.js → chunk-MN3YGXJH.js} +17 -17
  128. package/dist/lib/chunks/{chunk-ZQ3ER7JD.js → chunk-MSEGYN6W.js} +32 -14
  129. package/dist/lib/chunks/{chunk-JQDQVG3D.js → chunk-MWZIVYMK.js} +1 -1
  130. package/dist/lib/chunks/{chunk-WCLKIPJV.js → chunk-MX6YA6YH.js} +1 -1
  131. package/dist/lib/chunks/{chunk-GEFKDW7X.js → chunk-N4PQ6RPQ.js} +14 -2
  132. package/dist/lib/chunks/{chunk-EDQTINTL.js → chunk-N5IAPSLM.js} +52 -6
  133. package/dist/lib/chunks/{chunk-V5JJEEBT.js → chunk-NAPYHYA5.js} +6 -5
  134. package/dist/lib/chunks/{chunk-LR27H2HZ.js → chunk-NWUZJUJX.js} +8 -8
  135. package/dist/lib/chunks/{chunk-U5USH2HB.js → chunk-NZTOOSLX.js} +3 -3
  136. package/dist/lib/chunks/{chunk-S6QOXJAL.js → chunk-OQVEYTVV.js} +16 -7
  137. package/dist/lib/chunks/{chunk-GLUGYZQO.js → chunk-OXPPUUIO.js} +48 -60
  138. package/dist/lib/chunks/chunk-PPTUCXWS.js +95 -0
  139. package/dist/lib/chunks/{chunk-W5XYW6ZM.js → chunk-PT6PK2MJ.js} +26 -19
  140. package/dist/lib/chunks/{chunk-7DNLRXEY.js → chunk-PUZBLM7E.js} +9 -6
  141. package/dist/lib/chunks/{chunk-7YZPEX3T.js → chunk-PVW5W2MX.js} +9 -4
  142. package/dist/lib/chunks/{chunk-YEUCAPKP.js → chunk-QFIJSLAR.js} +26 -6
  143. package/dist/lib/chunks/{chunk-J5NPHPXY.js → chunk-QTUWCZ3X.js} +43 -8
  144. package/dist/lib/chunks/{chunk-6GKKALCI.js → chunk-R4BFYHLK.js} +2 -2
  145. package/dist/lib/chunks/chunk-R75F4MKU.js +162 -0
  146. package/dist/lib/chunks/{chunk-V5B6UZ3E.js → chunk-RQGEPR6V.js} +1 -0
  147. package/dist/lib/chunks/{chunk-TAPVCSCR.js → chunk-SCZ7PA4T.js} +1 -1
  148. package/dist/lib/chunks/{chunk-K4Y5NT4M.js → chunk-SFPPZGTA.js} +112 -26
  149. package/dist/lib/chunks/chunk-SN3DKEOY.js +11 -0
  150. package/dist/lib/chunks/{chunk-UYDQXXDQ.js → chunk-ST6IVXHT.js} +1 -1
  151. package/dist/lib/chunks/chunk-SXCTAL6V.js +116 -0
  152. package/dist/lib/chunks/chunk-SXVKFPC4.js +288 -0
  153. package/dist/lib/chunks/chunk-T4Z3GAEH.js +292 -0
  154. package/dist/lib/chunks/{chunk-RK57YZKM.js → chunk-T7DNKNMG.js} +81 -26
  155. package/dist/lib/chunks/{chunk-DL6YQDTE.js → chunk-TPPBTN3E.js} +50 -21
  156. package/dist/lib/chunks/{chunk-J7QKT5E7.js → chunk-UBH2P5IR.js} +91 -32
  157. package/dist/lib/chunks/{chunk-BYHXNFWN.js → chunk-UIXTXI7P.js} +9 -7
  158. package/dist/lib/chunks/chunk-UWXR24TV.js +38 -0
  159. package/dist/lib/chunks/chunk-V57HW7T4.js +86 -0
  160. package/dist/lib/chunks/{chunk-XA27KAUV.js → chunk-VCFLUGLQ.js} +80 -48
  161. package/dist/lib/chunks/{chunk-VL253W5C.js → chunk-VMDGYDZW.js} +3 -1
  162. package/dist/lib/chunks/{chunk-RIJERFGU.js → chunk-W6TGEP5C.js} +96 -26
  163. package/dist/lib/chunks/chunk-WB4ZBRF6.js +338 -0
  164. package/dist/lib/chunks/{chunk-F7DBTXKG.js → chunk-WQTDLVKV.js} +4 -3
  165. package/dist/lib/chunks/{chunk-VXYQWE45.js → chunk-WRH4CIFQ.js} +3 -3
  166. package/dist/lib/chunks/{chunk-JKPBXPCW.js → chunk-WSFXGX7S.js} +3 -3
  167. package/dist/lib/chunks/{chunk-BXF4OC74.js → chunk-WSWQCHSW.js} +32 -17
  168. package/dist/lib/chunks/{chunk-EOO5RBUW.js → chunk-WTAIFAQV.js} +42 -6
  169. package/dist/lib/chunks/{chunk-7YYDUHJG.js → chunk-WZA4H4TG.js} +39 -13
  170. package/dist/lib/chunks/{chunk-RYCRL3YA.js → chunk-X3HRV5CF.js} +12 -4
  171. package/dist/lib/chunks/{chunk-S2SFHTJD.js → chunk-XPUCJQIB.js} +39 -1
  172. package/dist/lib/chunks/{chunk-PWOYEIPF.js → chunk-Y2NZTYKV.js} +8 -8
  173. package/dist/lib/chunks/chunk-YLS4XX7B.js +105 -0
  174. package/dist/lib/chunks/{chunk-7CW6U5WJ.js → chunk-YPMRZX4U.js} +1 -1
  175. package/dist/lib/chunks/{chunk-SASE7U6E.js → chunk-YQD5ITKI.js} +1 -1
  176. package/dist/lib/chunks/{chunk-LTI2YYU3.js → chunk-YTEUQEJE.js} +1 -1
  177. package/dist/lib/chunks/{chunk-4GLW3ZRO.js → chunk-YYP547FI.js} +146 -22
  178. package/dist/lib/chunks/{chunk-QD3JXA3Y.js → chunk-ZDCKZEDJ.js} +56 -36
  179. package/dist/lib/chunks/{chunk-AT3XMGES.js → chunk-ZWTNELCS.js} +12 -6
  180. package/dist/lib/chunks/{chunk-VHKHYAC5.js → chunk-ZWWIXFCV.js} +3 -3
  181. package/dist/lib/chunks/{chunk-MA27TFEY.js → chunk-ZXL6FZX4.js} +8 -1
  182. package/dist/lib/cli/bundle-commands.js +137 -111
  183. package/dist/lib/cli/guide-command.js +1 -1
  184. package/dist/lib/cli/io.js +1 -1
  185. package/dist/lib/cli/run-commands.js +349 -168
  186. package/dist/lib/cli/status-command.js +114 -87
  187. package/dist/lib/codex-workflow/aggregate.js +41 -24
  188. package/dist/lib/codex-workflow/author-search.js +1 -1
  189. package/dist/lib/codex-workflow/author-tools.js +14 -14
  190. package/dist/lib/codex-workflow/author.js +35 -32
  191. package/dist/lib/codex-workflow/capture.js +53 -28
  192. package/dist/lib/codex-workflow/checkpoint.js +14 -14
  193. package/dist/lib/codex-workflow/checks.js +16 -16
  194. package/dist/lib/codex-workflow/copy-editor.js +29 -26
  195. package/dist/lib/codex-workflow/copy-recovery.js +13 -13
  196. package/dist/lib/codex-workflow/copy.js +32 -23
  197. package/dist/lib/codex-workflow/finish.js +67 -37
  198. package/dist/lib/codex-workflow/host-models.js +2 -2
  199. package/dist/lib/codex-workflow/loop.js +96 -72
  200. package/dist/lib/codex-workflow/prompts.js +1 -1
  201. package/dist/lib/codex-workflow/quality.js +13 -13
  202. package/dist/lib/codex-workflow/run-inputs.js +13 -13
  203. package/dist/lib/codex-workflow/run-source.js +24 -24
  204. package/dist/lib/codex-workflow/schemas.js +13 -13
  205. package/dist/lib/codex-workflow/session.js +15 -15
  206. package/dist/lib/codex-workflow/stage.js +49 -46
  207. package/dist/lib/codex-workflow/workdir.js +25 -18
  208. package/dist/lib/engine/audit-file.js +50 -16
  209. package/dist/lib/engine/author.js +77 -57
  210. package/dist/lib/engine/budget.js +3 -1
  211. package/dist/lib/engine/cost-estimate.js +46 -16
  212. package/dist/lib/engine/local-run.js +113 -85
  213. package/dist/lib/engine/preflight.js +47 -17
  214. package/dist/lib/engine/rejudge.js +121 -92
  215. package/dist/lib/engine/run-bindings.js +66 -0
  216. package/dist/lib/engine/run-configuration.js +3 -1
  217. package/dist/lib/engine/run-method.js +67 -0
  218. package/dist/lib/engine/run-models.js +48 -0
  219. package/dist/lib/engine/run-status.js +112 -85
  220. package/dist/lib/engine/templates.js +47 -17
  221. package/dist/lib/grounding/controller.js +10 -9
  222. package/dist/lib/grounding/extract.js +10 -8
  223. package/dist/lib/grounding/grounding-runtime.js +32 -31
  224. package/dist/lib/grounding/model-usage.js +2 -2
  225. package/dist/lib/grounding/model.js +9 -7
  226. package/dist/lib/grounding/recorded-tools.js +17 -17
  227. package/dist/lib/grounding/tools.js +5 -1
  228. package/dist/lib/harness/report/artifacts.js +12 -12
  229. package/dist/lib/harness/report/capture-coverage.js +4 -4
  230. package/dist/lib/lib/checkpoint.js +12 -12
  231. package/dist/lib/lib/compare.js +6 -0
  232. package/dist/lib/lib/log.js +1 -1
  233. package/dist/lib/lib/progress-comparison.js +3 -2
  234. package/dist/lib/models/accounting.js +1 -1
  235. package/dist/lib/models/batching.js +7 -5
  236. package/dist/lib/models/budget-protection.js +1 -1
  237. package/dist/lib/models/catalog.js +16 -0
  238. package/dist/lib/models/cost-coefficients.js +12 -1
  239. package/dist/lib/models/gateway-cost.js +7 -0
  240. package/dist/lib/models/local-profile.js +2 -2
  241. package/dist/lib/models/open-model.js +7 -0
  242. package/dist/lib/models/profiles.js +3 -1
  243. package/dist/lib/models/structured.js +6 -4
  244. package/dist/lib/models/supported-models.js +2 -2
  245. package/dist/lib/pipeline.js +50 -27
  246. package/dist/lib/probes/adapter.js +6 -0
  247. package/dist/lib/probes/adapters/cli-agents.js +44 -0
  248. package/dist/lib/probes/adapters/cli-claude-code.js +22 -0
  249. package/dist/lib/probes/adapters/cli-codex.js +24 -0
  250. package/dist/lib/probes/adapters/cli-cursor.js +22 -0
  251. package/dist/lib/probes/adapters/cli-process.js +35 -0
  252. package/dist/lib/probes/adapters/dataforseo-ai-mode.js +24 -0
  253. package/dist/lib/probes/adapters/dataforseo-ai-overview.js +21 -0
  254. package/dist/lib/probes/adapters/dataforseo-chatgpt-app.js +22 -0
  255. package/dist/lib/probes/adapters/gateway-chat.js +33 -0
  256. package/dist/lib/probes/adapters/gateway-perplexity.js +20 -0
  257. package/dist/lib/probes/agent-cli-parsers.js +4 -3
  258. package/dist/lib/probes/agent-clis.js +34 -19
  259. package/dist/lib/probes/answer-text.js +22 -0
  260. package/dist/lib/probes/attempt.js +29 -0
  261. package/dist/lib/probes/bindings.js +101 -0
  262. package/dist/lib/probes/charged-trace.js +49 -3
  263. package/dist/lib/probes/chat-retrieval.js +7 -2
  264. package/dist/lib/probes/dataforseo-locale.js +9 -3
  265. package/dist/lib/probes/dataforseo.js +16 -5
  266. package/dist/lib/probes/grounding-urls.js +6 -4
  267. package/dist/lib/probes/legacy-bindings.js +7 -0
  268. package/dist/lib/probes/limits.js +1 -1
  269. package/dist/lib/probes/probes.js +42 -19
  270. package/dist/lib/probes/web-tool-guard.js +3 -3
  271. package/dist/lib/report/contracts.js +7 -7
  272. package/dist/lib/report/core/progress-comparison.js +3 -2
  273. package/dist/lib/report/core/progress-schema.js +6 -2
  274. package/dist/lib/report/core/progress-statistics.js +8 -0
  275. package/dist/lib/report/core/rate-interval.js +6 -0
  276. package/dist/lib/report/core/retrieval.js +4 -1
  277. package/dist/lib/report/core/schema.js +23 -3
  278. package/dist/lib/report/core/surfaces.js +23 -1
  279. package/dist/lib/retrieval.js +4 -1
  280. package/dist/lib/runner.js +28 -25
  281. package/dist/lib/schema.js +37 -13
  282. package/dist/lib/section-result.js +15 -13
  283. package/dist/lib/stores/artifacts.js +15 -15
  284. package/dist/lib/stores/files.js +31 -27
  285. package/dist/lib/stores/local-versions.js +12 -12
  286. package/dist/lib/stores/memory.js +33 -27
  287. package/dist/lib/stores/publication.js +19 -18
  288. package/dist/lib/stores/unit-record.js +28 -0
  289. package/dist/lib/surfaces.js +23 -1
  290. package/dist/lib/viewer/page.js +1 -1
  291. package/dist/lib/viewer/server.js +47 -37
  292. package/dist/lib/workflow/schema.js +10 -10
  293. package/dist/types/agents/author-schema.d.ts +10 -10
  294. package/dist/types/agents/facts.d.ts +1 -1
  295. package/dist/types/agents/methodology.d.ts +26 -0
  296. package/dist/types/agents/verifier.d.ts +1 -1
  297. package/dist/types/analysis/domain-labels.d.ts +1 -1
  298. package/dist/types/analysis/rate-evidence.d.ts +11 -0
  299. package/dist/types/analysis/scoring.d.ts +17 -0
  300. package/dist/types/analysis/sentiment.d.ts +8 -4
  301. package/dist/types/bundle/contracts.d.ts +42 -20
  302. package/dist/types/bundle/project.d.ts +6 -0
  303. package/dist/types/bundle/recorder.d.ts +1 -1
  304. package/dist/types/bundle/trace-coverage.d.ts +4 -2
  305. package/dist/types/capture-manifest.d.ts +9 -4
  306. package/dist/types/codex-workflow/aggregate.d.ts +90 -12
  307. package/dist/types/codex-workflow/capture.d.ts +13 -0
  308. package/dist/types/codex-workflow/copy-editor.d.ts +40 -1
  309. package/dist/types/codex-workflow/copy.d.ts +136 -1
  310. package/dist/types/codex-workflow/run-inputs.d.ts +138 -32
  311. package/dist/types/codex-workflow/schemas.d.ts +20 -20
  312. package/dist/types/codex-workflow/stage.d.ts +7 -1
  313. package/dist/types/codex-workflow/workdir.d.ts +0 -1
  314. package/dist/types/engine/audit-file.d.ts +96 -6
  315. package/dist/types/engine/budget.d.ts +19 -6
  316. package/dist/types/engine/cost-estimate.d.ts +15 -2
  317. package/dist/types/engine/local-run.d.ts +12 -2
  318. package/dist/types/engine/preflight.d.ts +27 -6
  319. package/dist/types/engine/run-bindings.d.ts +52 -0
  320. package/dist/types/engine/run-configuration.d.ts +15 -3
  321. package/dist/types/engine/run-method.d.ts +58 -0
  322. package/dist/types/engine/run-models.d.ts +89 -0
  323. package/dist/types/engine/templates.d.ts +3 -1
  324. package/dist/types/grounding/tools.d.ts +10 -0
  325. package/dist/types/harness/report/artifacts.d.ts +48 -24
  326. package/dist/types/lib/compare.d.ts +3 -0
  327. package/dist/types/models/accounting.d.ts +7 -0
  328. package/dist/types/models/catalog.d.ts +52 -0
  329. package/dist/types/models/cost-coefficients.d.ts +77 -24
  330. package/dist/types/models/gateway-cost.d.ts +3 -0
  331. package/dist/types/models/local-profile.d.ts +5 -1
  332. package/dist/types/models/open-model.d.ts +10 -0
  333. package/dist/types/models/profiles.d.ts +113 -14
  334. package/dist/types/models/supported-models.d.ts +13 -3
  335. package/dist/types/pipeline.d.ts +2 -0
  336. package/dist/types/probes/adapter.d.ts +121 -0
  337. package/dist/types/probes/adapters/cli-agents.d.ts +19 -0
  338. package/dist/types/probes/adapters/cli-claude-code.d.ts +4 -0
  339. package/dist/types/probes/adapters/cli-codex.d.ts +10 -0
  340. package/dist/types/probes/adapters/cli-cursor.d.ts +4 -0
  341. package/dist/types/probes/adapters/cli-process.d.ts +86 -0
  342. package/dist/types/probes/adapters/dataforseo-ai-mode.d.ts +16 -0
  343. package/dist/types/probes/adapters/dataforseo-ai-overview.d.ts +12 -0
  344. package/dist/types/probes/adapters/dataforseo-chatgpt-app.d.ts +12 -0
  345. package/dist/types/probes/adapters/gateway-chat.d.ts +61 -0
  346. package/dist/types/probes/adapters/gateway-perplexity.d.ts +10 -0
  347. package/dist/types/probes/agent-clis.d.ts +7 -49
  348. package/dist/types/probes/answer-text.d.ts +20 -0
  349. package/dist/types/probes/attempt.d.ts +113 -0
  350. package/dist/types/probes/bindings.d.ts +168 -0
  351. package/dist/types/probes/charged-trace.d.ts +8 -1
  352. package/dist/types/probes/chat-retrieval.d.ts +2 -0
  353. package/dist/types/probes/dataforseo-locale.d.ts +16 -0
  354. package/dist/types/probes/dataforseo.d.ts +66 -1
  355. package/dist/types/probes/grounding-urls.d.ts +18 -5
  356. package/dist/types/probes/legacy-bindings.d.ts +36 -0
  357. package/dist/types/probes/limits.d.ts +12 -6
  358. package/dist/types/probes/probe-trace.d.ts +13 -0
  359. package/dist/types/probes/probes.d.ts +7 -5
  360. package/dist/types/report/contracts.d.ts +184 -30
  361. package/dist/types/report/core/progress-comparison.d.ts +19 -2
  362. package/dist/types/report/core/progress-schema.d.ts +13 -5
  363. package/dist/types/report/core/progress-statistics.d.ts +28 -0
  364. package/dist/types/report/core/rate-interval.d.ts +10 -0
  365. package/dist/types/report/core/retrieval.d.ts +5 -2
  366. package/dist/types/report/core/schema.d.ts +190 -30
  367. package/dist/types/report/core/surfaces.d.ts +38 -4
  368. package/dist/types/runner.d.ts +5 -0
  369. package/dist/types/schema.d.ts +126 -21
  370. package/dist/types/section-result.d.ts +7 -2
  371. package/dist/types/stores/ports.d.ts +1 -0
  372. package/dist/types/stores/unit-record.d.ts +11 -0
  373. package/dist/types/workflow/schema.d.ts +121 -41
  374. package/package.json +6 -6
  375. package/resources/guide/OPERATOR.md +35 -7
  376. package/src/agents/author-schema.ts +7 -0
  377. package/src/agents/credentials.ts +18 -3
  378. package/src/agents/facts.ts +116 -3
  379. package/src/agents/methodology.ts +168 -0
  380. package/src/agents/narrative-facts.ts +50 -13
  381. package/src/agents/verifier.ts +2 -1
  382. package/src/analysis/progress.ts +14 -2
  383. package/src/analysis/rate-evidence.ts +74 -0
  384. package/src/analysis/scoring.ts +53 -10
  385. package/src/bundle/contracts.ts +42 -5
  386. package/src/bundle/export.ts +24 -4
  387. package/src/bundle/project-journal.ts +7 -1
  388. package/src/bundle/project.ts +76 -7
  389. package/src/bundle/recorder.ts +50 -1
  390. package/src/bundle/trace-coverage.ts +13 -6
  391. package/src/bundle/verify-integrity.ts +1 -0
  392. package/src/bundle/verify-report.ts +9 -3
  393. package/src/capture-manifest.ts +6 -0
  394. package/src/cli/io.ts +2 -0
  395. package/src/cli/literally-aeo.ts +10 -6
  396. package/src/cli/run-commands.ts +268 -39
  397. package/src/codex-workflow/aggregate.ts +108 -15
  398. package/src/codex-workflow/capture.ts +62 -5
  399. package/src/codex-workflow/copy-editor.ts +13 -2
  400. package/src/codex-workflow/copy.ts +171 -2
  401. package/src/codex-workflow/finish.ts +39 -0
  402. package/src/codex-workflow/loop.ts +23 -2
  403. package/src/codex-workflow/prompts.ts +32 -42
  404. package/src/codex-workflow/schemas.ts +3 -1
  405. package/src/codex-workflow/stage.ts +40 -45
  406. package/src/codex-workflow/workdir.ts +3 -4
  407. package/src/engine/audit-file.ts +186 -13
  408. package/src/engine/author.ts +5 -2
  409. package/src/engine/budget.ts +70 -10
  410. package/src/engine/cost-estimate.ts +39 -9
  411. package/src/engine/guide/OPERATOR.md +35 -7
  412. package/src/engine/local-run.ts +109 -13
  413. package/src/engine/preflight.ts +170 -30
  414. package/src/engine/rejudge.ts +8 -2
  415. package/src/engine/run-bindings.ts +189 -0
  416. package/src/engine/run-configuration.ts +36 -6
  417. package/src/engine/run-method.ts +230 -0
  418. package/src/engine/run-models.ts +276 -0
  419. package/src/engine/run-status.ts +9 -4
  420. package/src/engine/templates.ts +7 -2
  421. package/src/grounding/controller.ts +2 -1
  422. package/src/grounding/extract.ts +1 -0
  423. package/src/grounding/model-usage.ts +4 -0
  424. package/src/grounding/tools.ts +18 -1
  425. package/src/lib/compare.ts +9 -0
  426. package/src/lib/log.ts +17 -15
  427. package/src/models/accounting.ts +34 -0
  428. package/src/models/budget-protection.ts +1 -0
  429. package/src/models/catalog.ts +500 -0
  430. package/src/models/cost-coefficients.ts +116 -27
  431. package/src/models/gateway-cost.ts +32 -0
  432. package/src/models/local-profile.ts +14 -8
  433. package/src/models/open-model.ts +70 -0
  434. package/src/models/profiles.ts +17 -4
  435. package/src/models/structured.ts +2 -10
  436. package/src/models/supported-models.ts +7 -5
  437. package/src/pipeline.ts +45 -19
  438. package/src/probes/adapter.ts +138 -0
  439. package/src/probes/adapters/cli-agents.ts +123 -0
  440. package/src/probes/adapters/cli-claude-code.ts +119 -0
  441. package/src/probes/adapters/cli-codex.ts +145 -0
  442. package/src/probes/adapters/cli-cursor.ts +95 -0
  443. package/src/probes/adapters/cli-process.ts +522 -0
  444. package/src/probes/adapters/dataforseo-ai-mode.ts +146 -0
  445. package/src/probes/adapters/dataforseo-ai-overview.ts +106 -0
  446. package/src/probes/adapters/dataforseo-chatgpt-app.ts +115 -0
  447. package/src/probes/adapters/gateway-chat.ts +453 -0
  448. package/src/probes/adapters/gateway-perplexity.ts +104 -0
  449. package/src/probes/agent-clis.ts +151 -1088
  450. package/src/probes/answer-text.ts +153 -0
  451. package/src/probes/attempt.ts +463 -0
  452. package/src/probes/bindings.ts +761 -0
  453. package/src/probes/charged-trace.ts +69 -13
  454. package/src/probes/chat-retrieval.ts +67 -0
  455. package/src/probes/dataforseo-locale.ts +153 -22
  456. package/src/probes/dataforseo.ts +474 -178
  457. package/src/probes/grounding-urls.ts +68 -19
  458. package/src/probes/legacy-bindings.ts +41 -0
  459. package/src/probes/limits.ts +31 -18
  460. package/src/probes/probe-trace.ts +13 -0
  461. package/src/probes/probes.ts +76 -738
  462. package/src/probes/web-tool-guard.ts +18 -8
  463. package/src/report/core/progress-comparison.ts +158 -44
  464. package/src/report/core/progress-schema.ts +25 -3
  465. package/src/report/core/progress-statistics.ts +194 -0
  466. package/src/report/core/rate-interval.ts +24 -0
  467. package/src/report/core/retrieval.ts +18 -4
  468. package/src/report/core/schema.ts +79 -4
  469. package/src/report/core/surfaces.ts +100 -9
  470. package/src/runner.ts +72 -4
  471. package/src/schema.ts +78 -17
  472. package/src/section-result.ts +141 -23
  473. package/src/stores/files.ts +78 -54
  474. package/src/stores/memory.ts +4 -1
  475. package/src/stores/ports.ts +3 -0
  476. package/src/stores/unit-record.ts +151 -0
  477. package/src/viewer/page.ts +126 -5
  478. package/dist/lib/chunks/chunk-AASWJR7Q.js +0 -42
  479. package/dist/lib/chunks/chunk-BGAHZIL3.js +0 -563
  480. package/dist/lib/chunks/chunk-DVFFYY5G.js +0 -74
  481. package/dist/lib/chunks/chunk-IB6RROHE.js +0 -204
  482. package/dist/lib/chunks/chunk-NH4QGBJV.js +0 -61
  483. package/dist/lib/chunks/chunk-WZGI7UVM.js +0 -937
@@ -0,0 +1,106 @@
1
+ import { probeUsd } from '../../models/cost-coefficients';
2
+ import type { AeoApiSurface } from '../../surfaces';
3
+ import {
4
+ ProbeAdapterId,
5
+ type ProbeAdapter,
6
+ type ProbeAdapterProfile,
7
+ } from '../adapter';
8
+ import {
9
+ aiOverviewEndpoint,
10
+ aiOverviewTask,
11
+ type DataForSeoLocale,
12
+ type DataForSeoProbeClient,
13
+ } from '../dataforseo';
14
+ import { ProbeFailure } from '../failure';
15
+ import { classifyGatewayFailure } from './gateway-chat';
16
+
17
+ // ============================================================================
18
+ // Google AI Overview through DataForSEO's live SERP
19
+ // (dataforseo.ai_overview): a SERP feature, so there is no model to ask
20
+ // for and no retrieval to expose. A SERP without an AI Overview is an honest
21
+ // absence (`noOverview`), never a failure.
22
+ // ============================================================================
23
+
24
+ export const dataForSeoAiOverviewProfile: ProbeAdapterProfile = {
25
+ id: ProbeAdapterId.DATAFORSEO_AI_OVERVIEW,
26
+ observes: { retrieval: 'none', servedModel: 'none' },
27
+ settings: [
28
+ { name: 'DATAFORSEO_LOGIN', secret: false },
29
+ { name: 'DATAFORSEO_PASSWORD', secret: true },
30
+ ],
31
+ pool: 'dataforseo',
32
+ retry: 'chat',
33
+ estimateUsd: probeUsd[ProbeAdapterId.DATAFORSEO_AI_OVERVIEW],
34
+ billing: 'metered',
35
+ resolvesRedirects: true,
36
+ };
37
+
38
+ /** createDataForSeoAiOverviewAdapter asks through the run's client, in the
39
+ * run's market. Without a client (no credentials) every probe fails as
40
+ * an auth failure, as an unauthenticated request would. */
41
+ export const createDataForSeoAiOverviewAdapter = ({
42
+ surface,
43
+ client,
44
+ locale,
45
+ }: {
46
+ surface: AeoApiSurface;
47
+ client: DataForSeoProbeClient | undefined;
48
+ locale: DataForSeoLocale;
49
+ }): ProbeAdapter => {
50
+ const retrieval = () => {
51
+ return {
52
+ exposure: dataForSeoAiOverviewProfile.observes.retrieval,
53
+ calls: [],
54
+ };
55
+ };
56
+
57
+ const adapter: ProbeAdapter = {
58
+ ...dataForSeoAiOverviewProfile,
59
+ surface,
60
+ request: (promptText) => {
61
+ const { keyword, ...parameters } = aiOverviewTask(promptText, locale);
62
+
63
+ return {
64
+ prompt: keyword,
65
+ parameters: { endpoint: aiOverviewEndpoint, ...parameters },
66
+ };
67
+ },
68
+ probe: async (promptText) => {
69
+ if (!client) {
70
+ throw new ProbeFailure('auth', 'DataForSEO credentials not configured');
71
+ }
72
+
73
+ const result = await client.getGoogleAIOverview(promptText, locale);
74
+
75
+ if (result.status === 'no_overview') {
76
+ return {
77
+ answerText: '',
78
+ sources: { format: 'none' },
79
+ retrieval: retrieval(),
80
+ noOverview: true,
81
+ };
82
+ }
83
+
84
+ // The rendered text is empty only when both the markdown and the
85
+ // references are.
86
+ if (
87
+ result.markdown.trim().length === 0 &&
88
+ result.references.length === 0
89
+ ) {
90
+ throw new ProbeFailure(
91
+ 'empty_answer',
92
+ 'google_ai_overview returned an AI Overview with no text',
93
+ );
94
+ }
95
+
96
+ return {
97
+ answerText: result.markdown,
98
+ sources: { format: 'ai_overview', references: result.references },
99
+ retrieval: retrieval(),
100
+ };
101
+ },
102
+ classifyError: classifyGatewayFailure,
103
+ };
104
+
105
+ return adapter;
106
+ };
@@ -0,0 +1,115 @@
1
+ import { probeUsd } from '../../models/cost-coefficients';
2
+ import type { AeoApiSurface } from '../../surfaces';
3
+ import {
4
+ ProbeAdapterId,
5
+ type ProbeAdapter,
6
+ type ProbeAdapterProfile,
7
+ } from '../adapter';
8
+ import {
9
+ chatGptEndpoint,
10
+ chatGptTask,
11
+ type DataForSeoLocale,
12
+ type DataForSeoProbeClient,
13
+ } from '../dataforseo';
14
+ import { ProbeFailure } from '../failure';
15
+ import { dataForSeoAiOverviewProfile } from './dataforseo-ai-overview';
16
+ import { classifyGatewayFailure } from './gateway-chat';
17
+
18
+ // ============================================================================
19
+ // ChatGPT's web interface through DataForSEO's live scrape
20
+ // (dataforseo.chatgpt_app, method release spec §5): the consumer product,
21
+ // not the API, with its search forced on.
22
+ //
23
+ // - The answer is the page's prose and tables (dataforseo.ts).
24
+ // - The sources are the ones the vendor describes as "cited or relied on";
25
+ // the methodology section says that "relied on" is included.
26
+ // - The model is whatever the scraper read off the page. Nothing pins it,
27
+ // so it is recorded as reported and never compared with a requested one.
28
+ // - Retrieval is `partial`: the answer's searches as a flat list, with no
29
+ // result set tied to any of them. A response that reports no list at
30
+ // all has no log (`null`), never an empty one: every request forces the
31
+ // search on, so "no list" is not "searched nothing". The results the
32
+ // page showed and did not cite are not kept: the retrieval log has no
33
+ // place for results that belong to no query.
34
+ // ============================================================================
35
+
36
+ export const dataForSeoChatGptAppProfile: ProbeAdapterProfile = {
37
+ id: ProbeAdapterId.DATAFORSEO_CHATGPT_APP,
38
+ observes: { retrieval: 'partial', servedModel: 'raw' },
39
+ settings: dataForSeoAiOverviewProfile.settings,
40
+ pool: 'dataforseo',
41
+ retry: 'chat',
42
+ estimateUsd: probeUsd[ProbeAdapterId.DATAFORSEO_CHATGPT_APP],
43
+ billing: 'metered',
44
+ resolvesRedirects: false,
45
+ };
46
+
47
+ /** createDataForSeoChatGptAppAdapter asks through the run's client, in the
48
+ * run's market. Without a client (no credentials) every probe fails as an
49
+ * auth failure, as an unauthenticated request would. */
50
+ export const createDataForSeoChatGptAppAdapter = ({
51
+ surface,
52
+ client,
53
+ locale,
54
+ }: {
55
+ surface: AeoApiSurface;
56
+ client: DataForSeoProbeClient | undefined;
57
+ locale: DataForSeoLocale;
58
+ }): ProbeAdapter => {
59
+ const adapter: ProbeAdapter = {
60
+ ...dataForSeoChatGptAppProfile,
61
+ surface,
62
+ request: (promptText) => {
63
+ const { keyword, ...parameters } = chatGptTask(promptText, locale);
64
+
65
+ return {
66
+ prompt: keyword,
67
+ parameters: { endpoint: chatGptEndpoint, ...parameters },
68
+ };
69
+ },
70
+ probe: async (promptText) => {
71
+ if (!client) {
72
+ throw new ProbeFailure('auth', 'DataForSEO credentials not configured');
73
+ }
74
+
75
+ const answer = await client.getChatGptAnswer(promptText, locale);
76
+
77
+ if (answer.markdown.length === 0) {
78
+ throw new ProbeFailure(
79
+ 'empty_answer',
80
+ `${surface} returned an answer with no text`,
81
+ );
82
+ }
83
+
84
+ return {
85
+ answerText: answer.markdown,
86
+ sources: {
87
+ format: 'search',
88
+ sources: answer.sources.map(({ url, title }) => ({
89
+ sourceType: 'url',
90
+ url,
91
+ ...(title !== '' && { title }),
92
+ })),
93
+ },
94
+ retrieval:
95
+ answer.fanOutQueries === null
96
+ ? null
97
+ : {
98
+ exposure: dataForSeoChatGptAppProfile.observes.retrieval,
99
+ calls: answer.fanOutQueries.map((query) => ({
100
+ kind: 'search' as const,
101
+ query,
102
+ url: null,
103
+ resultUrls: null,
104
+ resultsComplete: true,
105
+ })),
106
+ },
107
+ ...(answer.model !== null && { servedModel: answer.model }),
108
+ ...(answer.costUsd !== null && { reportedCostUsd: answer.costUsd }),
109
+ };
110
+ },
111
+ classifyError: classifyGatewayFailure,
112
+ };
113
+
114
+ return adapter;
115
+ };
@@ -0,0 +1,453 @@
1
+ import { streamText, type ToolSet } from 'ai';
2
+ import { openai } from '@ai-sdk/openai';
3
+ import { google } from '@ai-sdk/google';
4
+ import { anthropic } from '@ai-sdk/anthropic';
5
+ import { gateway as gatewaySdk } from '@ai-sdk/gateway';
6
+ import { createLog } from '../../lib/log';
7
+ import { isRecord } from '../../lib/type-guards';
8
+ import { gatewayCostUsd } from '../../models/gateway-cost';
9
+ import { probeUsd } from '../../models/cost-coefficients';
10
+ import type { RetrievalLog } from '../../schema';
11
+ import type { AeoApiSurface } from '../../surfaces';
12
+ import {
13
+ ProbeAdapterId,
14
+ type ChatModelProvider,
15
+ type ProbeAdapter,
16
+ type ProbeAdapterProfile,
17
+ type ProbeAnswer,
18
+ type ProbeFailureClass,
19
+ type ProbeRequest,
20
+ } from '../adapter';
21
+ import {
22
+ extractAnthropicRetrieval,
23
+ extractGatewaySearchRetrieval,
24
+ extractGeminiRetrieval,
25
+ gatewaySearchToolName,
26
+ extractOpenAiRetrieval,
27
+ type RetrievalStep,
28
+ } from '../chat-retrieval';
29
+ import { classifyGatewayError, errorMessage, ProbeFailure } from '../failure';
30
+
31
+ // ============================================================================
32
+ // Chat surfaces through the Vercel AI Gateway with the provider's own web
33
+ // search tool (gateway.openai, gateway.google, gateway.anthropic): one
34
+ // search-required call and, when it returns no prose, one synthesis
35
+ // follow-up over its results. The request is the method: the prompt
36
+ // prefix, the tool, the token cap and the tool choice.
37
+ // ============================================================================
38
+
39
+ const log = createLog('AISearchProbes');
40
+
41
+ export const probeMaxOutputTokens = 2000;
42
+
43
+ /**
44
+ * The output allowance of gateway.openai@2, gateway.anthropic@2 and
45
+ * gateway.search@1: room for the models of 2026 to finish an answer to a
46
+ * buyer question. Measured on six such questions (2026-11-11, method
47
+ * release spec §4.4), under the released 2,000 tokens:
48
+ *
49
+ * - openai/gpt-6-luna bills its thinking and its tool calls as output, and
50
+ * ran out while it was still searching. The search call ended on its
51
+ * token limit with no text, the follow-up, which searches nothing, wrote
52
+ * the answer, and 6 of 12 answers carried no source at all. The same
53
+ * questions on the earlier model gave none without a source in 38.
54
+ * - anthropic/claude-sonnet-5 was cut off mid-sentence in 4 of 6 answers.
55
+ *
56
+ * With this allowance both finished all six answers, each whole and with
57
+ * its sources: the first in at most 2,918 output tokens, the second in at
58
+ * most 3,422, at the cost they had before. The other two default models
59
+ * finished inside 2,000 (1,027 at most), and keep it.
60
+ */
61
+ export const roomyProbeMaxOutputTokens = 16_000;
62
+ // A search-required call plus a synthesis follow-up: bounded by the runner
63
+ // (hardening spec §4.5), never by undici's defaults plus SDK retries.
64
+ export const chatProbeTimeoutMs = 180_000;
65
+
66
+ export const searchPromptPrefix =
67
+ 'Search the web for current information to answer the following question. Return a complete answer, not just search results.\n\n';
68
+
69
+ /** reportedCostOf sums the reported costs of a probe's calls; absent unless
70
+ * every call reported one. */
71
+ export const reportedCostOf = (
72
+ costs: readonly (number | undefined)[],
73
+ ): { reportedCostUsd?: number } => {
74
+ if (costs.some((cost) => cost === undefined)) {
75
+ return {};
76
+ }
77
+
78
+ return {
79
+ reportedCostUsd: costs.reduce<number>((sum, cost) => sum + (cost ?? 0), 0),
80
+ };
81
+ };
82
+
83
+ /** classifyGatewayFailure keeps the error's kind and its message. */
84
+ export const classifyGatewayFailure = (error: unknown): ProbeFailureClass => {
85
+ return { kind: classifyGatewayError(error), message: errorMessage(error) };
86
+ };
87
+
88
+ /**
89
+ * toProviderToolSet hands provider-defined tools to `streamText`.
90
+ */
91
+ const toProviderToolSet = (tools: Record<string, unknown>): ToolSet => {
92
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- The provider packages declare their tools against a different Tool type than the `ai` package.
93
+ return tools as ToolSet;
94
+ };
95
+
96
+ // The slice of a model result the retrieval extractors read.
97
+ type SearchProbeResult = {
98
+ steps: ReadonlyArray<RetrievalStep>;
99
+ providerMetadata: unknown;
100
+ };
101
+
102
+ /** describeTools names each provider tool a request carries, with its
103
+ * arguments: the tool is part of the method. */
104
+ export const describeTools = (tools: Record<string, unknown>) => {
105
+ return Object.entries(tools).map(([name, tool]) => ({
106
+ name,
107
+ id: isRecord(tool) ? tool.id : undefined,
108
+ args: isRecord(tool) ? tool.args : undefined,
109
+ }));
110
+ };
111
+
112
+ /** The market an adapter's search tool is asked to search, when the tool
113
+ * takes one. The providers' own tools take none. */
114
+ export type SearchMarket = { geography: string; language: string };
115
+
116
+ type GatewayChatMethod = {
117
+ profile: ProbeAdapterProfile;
118
+ /** The output tokens one call may use: the follow-up gets the same. */
119
+ maxOutputTokens: number;
120
+ /** Built per call, as the request carries it. */
121
+ tools: (market: SearchMarket | undefined) => Record<string, unknown>;
122
+ extractRetrieval: (result: SearchProbeResult) => RetrievalLog;
123
+ };
124
+
125
+ const searchRequest = ({
126
+ model,
127
+ promptText,
128
+ maxOutputTokens,
129
+ tools,
130
+ }: {
131
+ model: string;
132
+ promptText: string;
133
+ maxOutputTokens: number;
134
+ tools: Record<string, unknown>;
135
+ }): ProbeRequest => {
136
+ return {
137
+ prompt: `${searchPromptPrefix}${promptText}`,
138
+ parameters: {
139
+ model,
140
+ maxOutputTokens,
141
+ toolChoice: 'required',
142
+ tools: describeTools(tools),
143
+ },
144
+ };
145
+ };
146
+
147
+ const searchProbe = async ({
148
+ surface,
149
+ gateway,
150
+ model,
151
+ promptText,
152
+ method,
153
+ tools: toolsOf,
154
+ }: {
155
+ surface: AeoApiSurface;
156
+ gateway: ChatModelProvider;
157
+ model: string;
158
+ promptText: string;
159
+ method: GatewayChatMethod;
160
+ /** The method's tools, in the adapter's market. */
161
+ tools: () => Record<string, unknown>;
162
+ }): Promise<ProbeAnswer> => {
163
+ const tools = toolsOf();
164
+ const { maxOutputTokens } = method;
165
+ const { prompt } = searchRequest({
166
+ model,
167
+ promptText,
168
+ maxOutputTokens,
169
+ tools,
170
+ });
171
+ // Streamed like every other non-trivial response: the gateway abandons a
172
+ // non-streaming request at 340 seconds whatever the caller's own timeout.
173
+ // Without an `onError` the SDK prints a provider failure with
174
+ // `console.error`, which includes the full prompt, and then hands the
175
+ // caller a causeless error the retry classifier cannot read.
176
+ let streamFailure: unknown;
177
+ const streamed = streamText({
178
+ onError: ({ error }) => {
179
+ streamFailure ??= error;
180
+ },
181
+ model: gateway(model),
182
+ prompt,
183
+ maxOutputTokens,
184
+ tools: toProviderToolSet(tools),
185
+ toolChoice: 'required',
186
+ maxRetries: 0,
187
+ abortSignal: AbortSignal.timeout(chatProbeTimeoutMs),
188
+ });
189
+
190
+ // Drain the stream once; every field below resolves from that one pass,
191
+ // and every one of them is read behind the same unwrapping, so a provider
192
+ // failure is never seen as the SDK's stand-in error.
193
+ const [
194
+ steps,
195
+ text,
196
+ sources,
197
+ finishReason,
198
+ toolCalls,
199
+ response,
200
+ providerMetadata,
201
+ ] = await Promise.all([
202
+ streamed.steps,
203
+ streamed.text,
204
+ streamed.sources,
205
+ streamed.finishReason,
206
+ streamed.toolCalls,
207
+ streamed.response,
208
+ streamed.providerMetadata,
209
+ ]).catch((error: unknown) => {
210
+ throw streamFailure ?? error;
211
+ });
212
+
213
+ // The retrieval log comes from this first, search-required call only; the
214
+ // synthesis follow-up below runs with toolChoice: 'none' and contributes
215
+ // nothing. An empty log after a required tool call is an extractor miss
216
+ // (§7), not a from-memory answer: log it and store no retrieval, so the
217
+ // row renders "not captured" rather than "no searches".
218
+ let retrieval: RetrievalLog | null = method.extractRetrieval({
219
+ steps,
220
+ providerMetadata,
221
+ });
222
+
223
+ if (retrieval.calls.length === 0) {
224
+ log.warn('Search-required probe yielded no retrieval calls; not stored', {
225
+ model: surface,
226
+ stepCount: steps.length,
227
+ partTypes: [
228
+ ...new Set(steps.flatMap((step) => step.content.map((p) => p.type))),
229
+ ],
230
+ });
231
+
232
+ retrieval = null;
233
+ }
234
+
235
+ const firstCost = gatewayCostUsd(providerMetadata);
236
+
237
+ if (text.trim().length > 0) {
238
+ return {
239
+ answerText: text,
240
+ sources: { format: 'search', sources },
241
+ retrieval,
242
+ servedModel: response.modelId,
243
+ ...reportedCostOf([firstCost]),
244
+ };
245
+ }
246
+
247
+ log.warn('Search probe returned no answer text; synthesizing from search', {
248
+ model: surface,
249
+ finishReason,
250
+ toolCallCount: toolCalls.length,
251
+ sourceCount: sources.length,
252
+ });
253
+
254
+ // The follow-up is its own stream with its own failure: a 429 here is
255
+ // capacity, to be retried as such, and must not be read through the
256
+ // first stream's error or mistaken for a parser slip.
257
+ let followupFailure: unknown;
258
+ const followupStream = streamText({
259
+ onError: ({ error }) => {
260
+ followupFailure ??= error;
261
+ },
262
+ model: gateway(model),
263
+ messages: [
264
+ { role: 'user', content: prompt },
265
+ ...response.messages,
266
+ {
267
+ role: 'user',
268
+ content:
269
+ 'Using the web search results from the previous turn, answer the original question in a complete, readable response. Do not perform another search. If the search results were insufficient, say what was missing.',
270
+ },
271
+ ],
272
+ maxOutputTokens,
273
+ tools: toProviderToolSet(toolsOf()),
274
+ toolChoice: 'none',
275
+ maxRetries: 0,
276
+ abortSignal: AbortSignal.timeout(chatProbeTimeoutMs),
277
+ });
278
+
279
+ const [followupText, followupSources, followupMetadata] = await Promise.all([
280
+ followupStream.text,
281
+ followupStream.sources,
282
+ followupStream.providerMetadata,
283
+ ]).catch((error: unknown) => {
284
+ throw followupFailure ?? error;
285
+ });
286
+
287
+ if (followupText.trim().length > 0) {
288
+ return {
289
+ answerText: followupText,
290
+ sources: {
291
+ format: 'search',
292
+ sources: sources.length > 0 ? sources : followupSources,
293
+ },
294
+ retrieval,
295
+ servedModel: response.modelId,
296
+ ...reportedCostOf([firstCost, gatewayCostUsd(followupMetadata)]),
297
+ fromFollowUp: true,
298
+ };
299
+ }
300
+
301
+ // No answer after the search and the synthesis follow-up: a failed unit
302
+ // (hardening spec §2.4), retried like a transient failure — never banked
303
+ // as a measured absence.
304
+ throw new ProbeFailure(
305
+ 'empty_answer',
306
+ `${surface} completed a required web search but returned no answer text (tool calls: ${toolCalls.length}, sources: ${sources.length})`,
307
+ );
308
+ };
309
+
310
+ const gatewayChatProfile = (
311
+ id: ProbeAdapterProfile['id'],
312
+ retrieval: ProbeAdapterProfile['observes']['retrieval'],
313
+ ): ProbeAdapterProfile => {
314
+ return {
315
+ id,
316
+ observes: { retrieval, servedModel: 'compare_to_requested' },
317
+ settings: [{ name: 'AI_GATEWAY_API_KEY', secret: true }],
318
+ pool: 'gateway',
319
+ retry: 'chat',
320
+ estimateUsd: probeUsd[id],
321
+ billing: 'metered',
322
+ resolvesRedirects: true,
323
+ };
324
+ };
325
+
326
+ export type GatewayChatAdapterId =
327
+ | typeof ProbeAdapterId.GATEWAY_OPENAI
328
+ | typeof ProbeAdapterId.GATEWAY_OPENAI_2
329
+ | typeof ProbeAdapterId.GATEWAY_GOOGLE
330
+ | typeof ProbeAdapterId.GATEWAY_ANTHROPIC
331
+ | typeof ProbeAdapterId.GATEWAY_ANTHROPIC_2
332
+ | typeof ProbeAdapterId.GATEWAY_SEARCH;
333
+
334
+ // A two-letter language, alone or with its region ("pt", "pt-BR").
335
+ const languageOfMarket = /^([a-z]{2})(?:-[a-z]{2})?$/;
336
+
337
+ // The gateway's search tool, in the audit's market: results for the
338
+ // country, in the language. Both are two-letter codes there. A regional
339
+ // variant is searched by its language; anything else is left out, never
340
+ // guessed.
341
+ const gatewaySearchTool = (market: SearchMarket | undefined) => {
342
+ const country = market?.geography.toUpperCase();
343
+ const language = languageOfMarket.exec(
344
+ market?.language.toLowerCase() ?? '',
345
+ )?.[1];
346
+
347
+ return gatewaySdk.tools.perplexitySearch({
348
+ ...(country !== undefined && /^[A-Z]{2}$/.test(country) && { country }),
349
+ ...(language !== undefined && { searchLanguageFilter: [language] }),
350
+ });
351
+ };
352
+
353
+ const gatewayChatMethods: Record<GatewayChatAdapterId, GatewayChatMethod> = {
354
+ // Kept as released: a run directory that froze it resumes on it.
355
+ [ProbeAdapterId.GATEWAY_OPENAI]: {
356
+ profile: gatewayChatProfile(ProbeAdapterId.GATEWAY_OPENAI, 'full'),
357
+ maxOutputTokens: probeMaxOutputTokens,
358
+ tools: () => ({ web_search: openai.tools.webSearch({}) }),
359
+ extractRetrieval: (result) => extractOpenAiRetrieval(result.steps),
360
+ },
361
+ [ProbeAdapterId.GATEWAY_OPENAI_2]: {
362
+ profile: gatewayChatProfile(ProbeAdapterId.GATEWAY_OPENAI_2, 'full'),
363
+ maxOutputTokens: roomyProbeMaxOutputTokens,
364
+ tools: () => ({ web_search: openai.tools.webSearch({}) }),
365
+ extractRetrieval: (result) => extractOpenAiRetrieval(result.steps),
366
+ },
367
+ [ProbeAdapterId.GATEWAY_GOOGLE]: {
368
+ profile: gatewayChatProfile(ProbeAdapterId.GATEWAY_GOOGLE, 'partial'),
369
+ maxOutputTokens: probeMaxOutputTokens,
370
+ tools: () => ({ google_search: google.tools.googleSearch({}) }),
371
+ extractRetrieval: (result) =>
372
+ extractGeminiRetrieval(result.providerMetadata),
373
+ },
374
+ // Kept as released, like gateway.openai@1.
375
+ [ProbeAdapterId.GATEWAY_ANTHROPIC]: {
376
+ profile: gatewayChatProfile(ProbeAdapterId.GATEWAY_ANTHROPIC, 'full'),
377
+ maxOutputTokens: probeMaxOutputTokens,
378
+ tools: () => ({
379
+ web_search: anthropic.tools.webSearch_20250305({ maxUses: 5 }),
380
+ }),
381
+ extractRetrieval: (result) => extractAnthropicRetrieval(result.steps),
382
+ },
383
+ [ProbeAdapterId.GATEWAY_ANTHROPIC_2]: {
384
+ profile: gatewayChatProfile(ProbeAdapterId.GATEWAY_ANTHROPIC_2, 'full'),
385
+ maxOutputTokens: roomyProbeMaxOutputTokens,
386
+ tools: () => ({
387
+ web_search: anthropic.tools.webSearch_20250305({ maxUses: 5 }),
388
+ }),
389
+ extractRetrieval: (result) => extractAnthropicRetrieval(result.steps),
390
+ },
391
+ // Any gateway model (open models spec §5.2): the search is the gateway's
392
+ // own tool, so it does not depend on the model's provider. Any model may
393
+ // reason, so it has the room from its first release.
394
+ [ProbeAdapterId.GATEWAY_SEARCH]: {
395
+ profile: gatewayChatProfile(ProbeAdapterId.GATEWAY_SEARCH, 'full'),
396
+ maxOutputTokens: roomyProbeMaxOutputTokens,
397
+ tools: (market) => ({ [gatewaySearchToolName]: gatewaySearchTool(market) }),
398
+ extractRetrieval: (result) => extractGatewaySearchRetrieval(result.steps),
399
+ },
400
+ };
401
+
402
+ export const gatewayChatProfiles = {
403
+ [ProbeAdapterId.GATEWAY_OPENAI]:
404
+ gatewayChatMethods[ProbeAdapterId.GATEWAY_OPENAI].profile,
405
+ [ProbeAdapterId.GATEWAY_OPENAI_2]:
406
+ gatewayChatMethods[ProbeAdapterId.GATEWAY_OPENAI_2].profile,
407
+ [ProbeAdapterId.GATEWAY_GOOGLE]:
408
+ gatewayChatMethods[ProbeAdapterId.GATEWAY_GOOGLE].profile,
409
+ [ProbeAdapterId.GATEWAY_ANTHROPIC]:
410
+ gatewayChatMethods[ProbeAdapterId.GATEWAY_ANTHROPIC].profile,
411
+ [ProbeAdapterId.GATEWAY_ANTHROPIC_2]:
412
+ gatewayChatMethods[ProbeAdapterId.GATEWAY_ANTHROPIC_2].profile,
413
+ [ProbeAdapterId.GATEWAY_SEARCH]:
414
+ gatewayChatMethods[ProbeAdapterId.GATEWAY_SEARCH].profile,
415
+ } satisfies Record<GatewayChatAdapterId, ProbeAdapterProfile>;
416
+
417
+ /** createGatewayChatAdapter is one search-required chat adapter, asking
418
+ * `model` on `surface` through the run's `gateway`. */
419
+ export const createGatewayChatAdapter = (
420
+ id: GatewayChatAdapterId,
421
+ {
422
+ surface,
423
+ gateway,
424
+ model,
425
+ market,
426
+ }: {
427
+ surface: AeoApiSurface;
428
+ gateway: ChatModelProvider;
429
+ model: string;
430
+ market?: SearchMarket;
431
+ },
432
+ ): ProbeAdapter => {
433
+ const method: GatewayChatMethod = gatewayChatMethods[id];
434
+ const tools = () => method.tools(market);
435
+
436
+ const adapter: ProbeAdapter = {
437
+ ...method.profile,
438
+ surface,
439
+ model,
440
+ request: (promptText) =>
441
+ searchRequest({
442
+ model,
443
+ promptText,
444
+ maxOutputTokens: method.maxOutputTokens,
445
+ tools: tools(),
446
+ }),
447
+ probe: (promptText) =>
448
+ searchProbe({ surface, gateway, model, promptText, method, tools }),
449
+ classifyError: classifyGatewayFailure,
450
+ };
451
+
452
+ return adapter;
453
+ };