literally-aeo 0.2.2 → 0.3.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 (304) hide show
  1. package/dist/cli.mjs +6031 -5158
  2. package/dist/lib/agents/author-schema.js +5 -5
  3. package/dist/lib/agents/author-validation.js +7 -7
  4. package/dist/lib/agents/copy-validation.js +9 -9
  5. package/dist/lib/agents/copywriter-input.js +8 -8
  6. package/dist/lib/agents/facts.js +7 -7
  7. package/dist/lib/agents/narrative-facts.js +6 -6
  8. package/dist/lib/agents/verifier.js +13 -12
  9. package/dist/lib/analysis/domain-classifier.js +12 -10
  10. package/dist/lib/analysis/domain-labels.js +4 -4
  11. package/dist/lib/analysis/outreach.js +2 -2
  12. package/dist/lib/analysis/progress.js +8 -8
  13. package/dist/lib/analysis/retrieval.js +5 -5
  14. package/dist/lib/analysis/scoring.js +5 -5
  15. package/dist/lib/analysis/search-analyzer.js +6 -6
  16. package/dist/lib/analysis/sentiment.js +12 -10
  17. package/dist/lib/analysis/source-mix.js +2 -2
  18. package/dist/lib/author/examples.js +6 -6
  19. package/dist/lib/bundle/contracts.js +6 -6
  20. package/dist/lib/bundle/export.js +18 -18
  21. package/dist/lib/bundle/journal.js +7 -7
  22. package/dist/lib/bundle/project-journal.js +10 -10
  23. package/dist/lib/bundle/project.js +16 -16
  24. package/dist/lib/bundle/read.js +19 -19
  25. package/dist/lib/bundle/recorder.js +8 -8
  26. package/dist/lib/bundle/redact.js +7 -7
  27. package/dist/lib/bundle/trace-coverage.js +7 -7
  28. package/dist/lib/bundle/verify-integrity.js +9 -9
  29. package/dist/lib/bundle/verify-measurement.js +22 -13
  30. package/dist/lib/bundle/verify-report.js +23 -15
  31. package/dist/lib/bundle/verify.js +31 -23
  32. package/dist/lib/capture-manifest.js +6 -6
  33. package/dist/lib/checks/crawler-access.js +2 -2
  34. package/dist/lib/checks/renderability.js +2 -2
  35. package/dist/lib/checks/run-checks.js +12 -12
  36. package/dist/lib/chunks/{chunk-3CMPR6ZZ.js → chunk-2C723CW7.js} +1 -1
  37. package/dist/lib/chunks/chunk-2FDSOZ6Q.js +287 -0
  38. package/dist/lib/chunks/{chunk-PWOYEIPF.js → chunk-2U5QSA6Q.js} +7 -7
  39. package/dist/lib/chunks/{chunk-6EI4CVRW.js → chunk-3ESH5NDR.js} +5 -1
  40. package/dist/lib/chunks/{chunk-VHKHYAC5.js → chunk-3S2FAVRE.js} +2 -2
  41. package/dist/lib/chunks/{chunk-LR27H2HZ.js → chunk-44NSZBCP.js} +6 -6
  42. package/dist/lib/chunks/{chunk-JBOOD6MU.js → chunk-4AWFF53U.js} +12 -4
  43. package/dist/lib/chunks/{chunk-MENTBQGB.js → chunk-4HPMLJKC.js} +4 -4
  44. package/dist/lib/chunks/{chunk-S6QOXJAL.js → chunk-4Q2WFZ5J.js} +11 -4
  45. package/dist/lib/chunks/{chunk-7DNLRXEY.js → chunk-5JU2Y2I6.js} +2 -2
  46. package/dist/lib/chunks/{chunk-KFAT65P7.js → chunk-64JFN2Q5.js} +1 -1
  47. package/dist/lib/chunks/chunk-66UE4TT2.js +245 -0
  48. package/dist/lib/chunks/chunk-6N3C6E3D.js +105 -0
  49. package/dist/lib/chunks/{chunk-F2NSJ6PG.js → chunk-6RED3G6K.js} +7 -3
  50. package/dist/lib/chunks/{chunk-HCUJ2J7P.js → chunk-7KLTOVIY.js} +9 -9
  51. package/dist/lib/chunks/{chunk-EOO5RBUW.js → chunk-7ZR3WDF2.js} +38 -5
  52. package/dist/lib/chunks/chunk-A5PF7UE2.js +86 -0
  53. package/dist/lib/chunks/{chunk-PKNODC6Y.js → chunk-AB7DUTX5.js} +1 -1
  54. package/dist/lib/chunks/{chunk-WDT2Y7D7.js → chunk-AQCWKHTE.js} +11 -7
  55. package/dist/lib/chunks/{chunk-UNCUG2YS.js → chunk-ASHFEFCU.js} +3 -3
  56. package/dist/lib/chunks/{chunk-BYHXNFWN.js → chunk-ASIFUJG2.js} +1 -1
  57. package/dist/lib/chunks/{chunk-ZSEY7AHQ.js → chunk-BBK54RVK.js} +14 -11
  58. package/dist/lib/chunks/chunk-BQMUZLHO.js +17 -0
  59. package/dist/lib/chunks/{chunk-QD3JXA3Y.js → chunk-CQNIPZH3.js} +18 -18
  60. package/dist/lib/chunks/{chunk-7HM6IZ3L.js → chunk-CVEXMYPW.js} +2 -2
  61. package/dist/lib/chunks/chunk-CXZIHHLJ.js +95 -0
  62. package/dist/lib/chunks/{chunk-75DMLOQ7.js → chunk-CYJNBVQB.js} +1 -1
  63. package/dist/lib/chunks/{chunk-FAUFE7MI.js → chunk-D7N5OLYL.js} +1 -1
  64. package/dist/lib/chunks/{chunk-E2YTTB6Q.js → chunk-DSK3PM4Z.js} +1 -1
  65. package/dist/lib/chunks/{chunk-TNL2GWYR.js → chunk-EUXNCXCR.js} +22 -0
  66. package/dist/lib/chunks/{chunk-FJL2V6P5.js → chunk-F4EQULFR.js} +6 -6
  67. package/dist/lib/chunks/{chunk-QGZ4QSUE.js → chunk-FHV4PBYG.js} +1 -1
  68. package/dist/lib/chunks/{chunk-K2FZFESR.js → chunk-FONFW67K.js} +4 -4
  69. package/dist/lib/chunks/{chunk-PIFTG6YW.js → chunk-FPPHYGIO.js} +2 -2
  70. package/dist/lib/chunks/{chunk-VXYQWE45.js → chunk-FYE4R5TY.js} +2 -2
  71. package/dist/lib/chunks/{chunk-JYCVBFH5.js → chunk-H2DOBJZC.js} +2 -2
  72. package/dist/lib/chunks/{chunk-XA27KAUV.js → chunk-HEWHNSDP.js} +68 -36
  73. package/dist/lib/chunks/{chunk-RXSHKWZJ.js → chunk-HLC6OHGO.js} +2 -2
  74. package/dist/lib/chunks/{chunk-6HMHXSCS.js → chunk-HXXFRZTJ.js} +2 -2
  75. package/dist/lib/chunks/{chunk-R5UPOEWE.js → chunk-HYMWNGOK.js} +10 -3
  76. package/dist/lib/chunks/chunk-IH67TEGY.js +73 -0
  77. package/dist/lib/chunks/{chunk-JKPBXPCW.js → chunk-IMADI2YP.js} +1 -1
  78. package/dist/lib/chunks/{chunk-AT3XMGES.js → chunk-JBGQFPTY.js} +4 -4
  79. package/dist/lib/chunks/{chunk-JQDQVG3D.js → chunk-JDU3ZCKO.js} +1 -1
  80. package/dist/lib/chunks/{chunk-2KH7LNK7.js → chunk-JGIX427K.js} +7 -7
  81. package/dist/lib/chunks/{chunk-7CW6U5WJ.js → chunk-JIE2ANVD.js} +1 -1
  82. package/dist/lib/chunks/{chunk-YEUCAPKP.js → chunk-JJFOILZK.js} +2 -2
  83. package/dist/lib/chunks/{chunk-F7DBTXKG.js → chunk-JMIK2QN3.js} +4 -3
  84. package/dist/lib/chunks/chunk-JW7DTYSI.js +116 -0
  85. package/dist/lib/chunks/{chunk-BFWK3TBN.js → chunk-JXLCKACO.js} +2 -2
  86. package/dist/lib/chunks/{chunk-7WO3FFPS.js → chunk-K5NQDJLE.js} +1 -1
  87. package/dist/lib/chunks/{chunk-BXF4OC74.js → chunk-KI2FB4Y3.js} +30 -16
  88. package/dist/lib/chunks/{chunk-Y2CZ6FZY.js → chunk-KRWDELRS.js} +30 -7
  89. package/dist/lib/chunks/{chunk-SIJOQRRK.js → chunk-KRXOJJR7.js} +1 -1
  90. package/dist/lib/chunks/chunk-KSUI4DAY.js +15 -0
  91. package/dist/lib/chunks/chunk-KXFZ3CH3.js +98 -0
  92. package/dist/lib/chunks/{chunk-XSER7WEB.js → chunk-LJCWZ5SZ.js} +14 -14
  93. package/dist/lib/chunks/{chunk-HGGRPOSA.js → chunk-LNYQMWJO.js} +3 -3
  94. package/dist/lib/chunks/{chunk-DL6YQDTE.js → chunk-LOIAGEKN.js} +2 -2
  95. package/dist/lib/chunks/{chunk-I3UE52ZV.js → chunk-LPOIMPJK.js} +2 -2
  96. package/dist/lib/chunks/{chunk-66T7JC57.js → chunk-LUKP64NX.js} +2 -2
  97. package/dist/lib/chunks/chunk-MNG5TZRW.js +208 -0
  98. package/dist/lib/chunks/{chunk-HGGOGCPX.js → chunk-MPQXB7HN.js} +7 -7
  99. package/dist/lib/chunks/{chunk-YGLWQFKL.js → chunk-MZ2KN3IH.js} +3 -3
  100. package/dist/lib/chunks/chunk-N62G4EWT.js +91 -0
  101. package/dist/lib/chunks/{chunk-7YDXD4MD.js → chunk-ODIXZHHX.js} +1 -1
  102. package/dist/lib/chunks/{chunk-GLUGYZQO.js → chunk-OTVHGRCO.js} +8 -8
  103. package/dist/lib/chunks/{chunk-RIJERFGU.js → chunk-OVF27NAO.js} +69 -17
  104. package/dist/lib/chunks/chunk-P6LHGBYU.js +90 -0
  105. package/dist/lib/chunks/{chunk-U5USH2HB.js → chunk-PAL5SXIP.js} +1 -1
  106. package/dist/lib/chunks/{chunk-W5XYW6ZM.js → chunk-PT6PK2MJ.js} +26 -19
  107. package/dist/lib/chunks/{chunk-OD36HUXA.js → chunk-Q22FCF4A.js} +6 -7
  108. package/dist/lib/chunks/chunk-QKTKQSPS.js +292 -0
  109. package/dist/lib/chunks/{chunk-K4Y5NT4M.js → chunk-QO5TPMWS.js} +2 -2
  110. package/dist/lib/chunks/{chunk-4GLW3ZRO.js → chunk-QUZYFAGP.js} +4 -4
  111. package/dist/lib/chunks/{chunk-T6XZQOXS.js → chunk-QVMPTT7R.js} +5 -5
  112. package/dist/lib/chunks/{chunk-OOLWU667.js → chunk-RGZY6YUQ.js} +5 -5
  113. package/dist/lib/chunks/{chunk-U6BW6LGX.js → chunk-RM2VVR7Y.js} +1 -1
  114. package/dist/lib/chunks/{chunk-AJO7XVXK.js → chunk-RMSH7RUG.js} +6 -6
  115. package/dist/lib/chunks/{chunk-V5B6UZ3E.js → chunk-RQGEPR6V.js} +1 -0
  116. package/dist/lib/chunks/{chunk-V5JJEEBT.js → chunk-RYB77E7O.js} +6 -5
  117. package/dist/lib/chunks/chunk-S24JGY7B.js +97 -0
  118. package/dist/lib/chunks/{chunk-6GKKALCI.js → chunk-SF4UJ2AY.js} +1 -1
  119. package/dist/lib/chunks/chunk-SJCUR4QX.js +94 -0
  120. package/dist/lib/chunks/{chunk-XAN4CRFP.js → chunk-SQ55KGHO.js} +1 -1
  121. package/dist/lib/chunks/{chunk-ZOGIJGU3.js → chunk-TKOQMB6A.js} +7 -7
  122. package/dist/lib/chunks/{chunk-UYDQXXDQ.js → chunk-TWK6IA4P.js} +1 -1
  123. package/dist/lib/chunks/{chunk-DVFFYY5G.js → chunk-U42I3SBR.js} +13 -9
  124. package/dist/lib/chunks/{chunk-PIF3GL62.js → chunk-UECQONVZ.js} +5 -5
  125. package/dist/lib/chunks/{chunk-FDM2YNQL.js → chunk-VTY53IFN.js} +1 -1
  126. package/dist/lib/chunks/chunk-VYUC772A.js +338 -0
  127. package/dist/lib/chunks/{chunk-WCLKIPJV.js → chunk-WPCBE2NZ.js} +1 -1
  128. package/dist/lib/chunks/{chunk-3OE4UQIB.js → chunk-WRHGLRUK.js} +5 -5
  129. package/dist/lib/chunks/{chunk-J7QKT5E7.js → chunk-WUIY7BXR.js} +34 -17
  130. package/dist/lib/chunks/{chunk-7YYDUHJG.js → chunk-WZA4H4TG.js} +39 -13
  131. package/dist/lib/chunks/{chunk-NH4QGBJV.js → chunk-XBSA7MNJ.js} +7 -2
  132. package/dist/lib/chunks/chunk-XTBCXEH7.js +243 -0
  133. package/dist/lib/chunks/{chunk-ZQ3ER7JD.js → chunk-YPVJAXPP.js} +1 -1
  134. package/dist/lib/chunks/{chunk-SASE7U6E.js → chunk-YQD5ITKI.js} +1 -1
  135. package/dist/lib/chunks/{chunk-LTCDLURT.js → chunk-YY4BH5XM.js} +6 -6
  136. package/dist/lib/chunks/{chunk-J5NPHPXY.js → chunk-Z3BZRBQF.js} +36 -2
  137. package/dist/lib/chunks/{chunk-XFUYEFQP.js → chunk-ZBQU2VU3.js} +1 -1
  138. package/dist/lib/chunks/{chunk-7YZPEX3T.js → chunk-ZHGABG7L.js} +2 -2
  139. package/dist/lib/chunks/chunk-ZZCRYG36.js +31 -0
  140. package/dist/lib/cli/bundle-commands.js +89 -73
  141. package/dist/lib/cli/run-commands.js +136 -92
  142. package/dist/lib/cli/status-command.js +75 -59
  143. package/dist/lib/codex-workflow/aggregate.js +20 -12
  144. package/dist/lib/codex-workflow/author-tools.js +7 -7
  145. package/dist/lib/codex-workflow/author.js +23 -22
  146. package/dist/lib/codex-workflow/capture.js +38 -17
  147. package/dist/lib/codex-workflow/checkpoint.js +7 -7
  148. package/dist/lib/codex-workflow/checks.js +9 -9
  149. package/dist/lib/codex-workflow/copy-editor.js +19 -18
  150. package/dist/lib/codex-workflow/copy-recovery.js +4 -4
  151. package/dist/lib/codex-workflow/copy.js +16 -15
  152. package/dist/lib/codex-workflow/finish.js +28 -24
  153. package/dist/lib/codex-workflow/host-models.js +2 -2
  154. package/dist/lib/codex-workflow/loop.js +51 -46
  155. package/dist/lib/codex-workflow/quality.js +4 -4
  156. package/dist/lib/codex-workflow/run-inputs.js +6 -6
  157. package/dist/lib/codex-workflow/run-source.js +16 -16
  158. package/dist/lib/codex-workflow/schemas.js +6 -6
  159. package/dist/lib/codex-workflow/session.js +8 -8
  160. package/dist/lib/codex-workflow/stage.js +30 -28
  161. package/dist/lib/codex-workflow/workdir.js +18 -11
  162. package/dist/lib/engine/audit-file.js +7 -7
  163. package/dist/lib/engine/author.js +38 -36
  164. package/dist/lib/engine/cost-estimate.js +37 -9
  165. package/dist/lib/engine/local-run.js +74 -58
  166. package/dist/lib/engine/preflight.js +37 -9
  167. package/dist/lib/engine/rejudge.js +80 -64
  168. package/dist/lib/engine/run-bindings.js +62 -0
  169. package/dist/lib/engine/run-status.js +75 -59
  170. package/dist/lib/engine/templates.js +8 -8
  171. package/dist/lib/grounding/controller.js +8 -7
  172. package/dist/lib/grounding/extract.js +8 -6
  173. package/dist/lib/grounding/grounding-runtime.js +22 -21
  174. package/dist/lib/grounding/model-usage.js +2 -2
  175. package/dist/lib/grounding/model.js +7 -5
  176. package/dist/lib/grounding/recorded-tools.js +9 -9
  177. package/dist/lib/harness/report/artifacts.js +5 -5
  178. package/dist/lib/lib/checkpoint.js +5 -5
  179. package/dist/lib/lib/log.js +1 -1
  180. package/dist/lib/models/accounting.js +1 -1
  181. package/dist/lib/models/batching.js +6 -4
  182. package/dist/lib/models/budget-protection.js +1 -1
  183. package/dist/lib/models/cost-coefficients.js +2 -1
  184. package/dist/lib/models/gateway-cost.js +7 -0
  185. package/dist/lib/models/structured.js +5 -3
  186. package/dist/lib/models/supported-models.js +1 -1
  187. package/dist/lib/pipeline.js +36 -17
  188. package/dist/lib/probes/adapter.js +6 -0
  189. package/dist/lib/probes/adapters/cli-agents.js +44 -0
  190. package/dist/lib/probes/adapters/cli-claude-code.js +21 -0
  191. package/dist/lib/probes/adapters/cli-codex.js +23 -0
  192. package/dist/lib/probes/adapters/cli-cursor.js +21 -0
  193. package/dist/lib/probes/adapters/cli-process.js +34 -0
  194. package/dist/lib/probes/adapters/dataforseo-ai-overview.js +20 -0
  195. package/dist/lib/probes/adapters/gateway-chat.js +30 -0
  196. package/dist/lib/probes/adapters/gateway-perplexity.js +19 -0
  197. package/dist/lib/probes/agent-cli-parsers.js +2 -2
  198. package/dist/lib/probes/agent-clis.js +26 -11
  199. package/dist/lib/probes/answer-text.js +21 -0
  200. package/dist/lib/probes/attempt.js +28 -0
  201. package/dist/lib/probes/bindings.js +69 -0
  202. package/dist/lib/probes/charged-trace.js +47 -3
  203. package/dist/lib/probes/dataforseo-locale.js +1 -1
  204. package/dist/lib/probes/dataforseo.js +8 -5
  205. package/dist/lib/probes/grounding-urls.js +6 -4
  206. package/dist/lib/probes/legacy-bindings.js +7 -0
  207. package/dist/lib/probes/limits.js +1 -1
  208. package/dist/lib/probes/probes.js +33 -12
  209. package/dist/lib/runner.js +17 -14
  210. package/dist/lib/schema.js +4 -4
  211. package/dist/lib/section-result.js +6 -6
  212. package/dist/lib/stores/artifacts.js +7 -7
  213. package/dist/lib/stores/files.js +19 -17
  214. package/dist/lib/stores/local-versions.js +5 -5
  215. package/dist/lib/stores/memory.js +19 -14
  216. package/dist/lib/stores/publication.js +10 -10
  217. package/dist/lib/stores/unit-record.js +28 -0
  218. package/dist/lib/viewer/server.js +32 -24
  219. package/dist/lib/workflow/schema.js +3 -3
  220. package/dist/types/bundle/contracts.d.ts +1 -1
  221. package/dist/types/capture-manifest.d.ts +1 -0
  222. package/dist/types/codex-workflow/capture.d.ts +13 -0
  223. package/dist/types/codex-workflow/workdir.d.ts +0 -1
  224. package/dist/types/engine/cost-estimate.d.ts +5 -1
  225. package/dist/types/engine/preflight.d.ts +6 -1
  226. package/dist/types/engine/run-bindings.d.ts +25 -0
  227. package/dist/types/models/accounting.d.ts +7 -0
  228. package/dist/types/models/cost-coefficients.d.ts +5 -5
  229. package/dist/types/models/gateway-cost.d.ts +3 -0
  230. package/dist/types/pipeline.d.ts +2 -0
  231. package/dist/types/probes/adapter.d.ts +112 -0
  232. package/dist/types/probes/adapters/cli-agents.d.ts +19 -0
  233. package/dist/types/probes/adapters/cli-claude-code.d.ts +4 -0
  234. package/dist/types/probes/adapters/cli-codex.d.ts +10 -0
  235. package/dist/types/probes/adapters/cli-cursor.d.ts +4 -0
  236. package/dist/types/probes/adapters/cli-process.d.ts +86 -0
  237. package/dist/types/probes/adapters/dataforseo-ai-overview.d.ts +12 -0
  238. package/dist/types/probes/adapters/gateway-chat.d.ts +32 -0
  239. package/dist/types/probes/adapters/gateway-perplexity.d.ts +10 -0
  240. package/dist/types/probes/agent-clis.d.ts +7 -49
  241. package/dist/types/probes/answer-text.d.ts +20 -0
  242. package/dist/types/probes/attempt.d.ts +113 -0
  243. package/dist/types/probes/bindings.d.ts +79 -0
  244. package/dist/types/probes/charged-trace.d.ts +2 -1
  245. package/dist/types/probes/dataforseo.d.ts +24 -1
  246. package/dist/types/probes/grounding-urls.d.ts +18 -5
  247. package/dist/types/probes/legacy-bindings.d.ts +36 -0
  248. package/dist/types/probes/limits.d.ts +12 -6
  249. package/dist/types/probes/probe-trace.d.ts +10 -0
  250. package/dist/types/probes/probes.d.ts +5 -3
  251. package/dist/types/stores/ports.d.ts +1 -0
  252. package/dist/types/stores/unit-record.d.ts +11 -0
  253. package/package.json +6 -6
  254. package/src/analysis/progress.ts +10 -1
  255. package/src/bundle/contracts.ts +1 -1
  256. package/src/bundle/recorder.ts +47 -1
  257. package/src/capture-manifest.ts +6 -0
  258. package/src/cli/run-commands.ts +37 -1
  259. package/src/codex-workflow/capture.ts +60 -0
  260. package/src/codex-workflow/workdir.ts +3 -4
  261. package/src/engine/cost-estimate.ts +10 -4
  262. package/src/engine/local-run.ts +21 -2
  263. package/src/engine/preflight.ts +113 -17
  264. package/src/engine/rejudge.ts +5 -0
  265. package/src/engine/run-bindings.ts +142 -0
  266. package/src/grounding/extract.ts +1 -0
  267. package/src/grounding/model-usage.ts +4 -0
  268. package/src/lib/log.ts +17 -15
  269. package/src/models/accounting.ts +34 -0
  270. package/src/models/budget-protection.ts +1 -0
  271. package/src/models/cost-coefficients.ts +17 -13
  272. package/src/models/gateway-cost.ts +32 -0
  273. package/src/models/structured.ts +2 -10
  274. package/src/models/supported-models.ts +2 -2
  275. package/src/pipeline.ts +36 -17
  276. package/src/probes/adapter.ts +122 -0
  277. package/src/probes/adapters/cli-agents.ts +123 -0
  278. package/src/probes/adapters/cli-claude-code.ts +119 -0
  279. package/src/probes/adapters/cli-codex.ts +145 -0
  280. package/src/probes/adapters/cli-cursor.ts +95 -0
  281. package/src/probes/adapters/cli-process.ts +522 -0
  282. package/src/probes/adapters/dataforseo-ai-overview.ts +106 -0
  283. package/src/probes/adapters/gateway-chat.ts +339 -0
  284. package/src/probes/adapters/gateway-perplexity.ts +104 -0
  285. package/src/probes/agent-clis.ts +151 -1088
  286. package/src/probes/answer-text.ts +153 -0
  287. package/src/probes/attempt.ts +462 -0
  288. package/src/probes/bindings.ts +344 -0
  289. package/src/probes/charged-trace.ts +54 -13
  290. package/src/probes/dataforseo-locale.ts +13 -2
  291. package/src/probes/dataforseo.ts +265 -188
  292. package/src/probes/grounding-urls.ts +68 -19
  293. package/src/probes/legacy-bindings.ts +40 -0
  294. package/src/probes/limits.ts +31 -18
  295. package/src/probes/probe-trace.ts +10 -0
  296. package/src/probes/probes.ts +64 -736
  297. package/src/runner.ts +13 -0
  298. package/src/stores/files.ts +78 -54
  299. package/src/stores/memory.ts +4 -1
  300. package/src/stores/ports.ts +3 -0
  301. package/src/stores/unit-record.ts +151 -0
  302. package/dist/lib/chunks/chunk-BGAHZIL3.js +0 -563
  303. package/dist/lib/chunks/chunk-IB6RROHE.js +0 -204
  304. package/dist/lib/chunks/chunk-WZGI7UVM.js +0 -937
@@ -0,0 +1,339 @@
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 { createLog } from '../../lib/log';
6
+ import { isRecord } from '../../lib/type-guards';
7
+ import { gatewayCostUsd } from '../../models/gateway-cost';
8
+ import { probeUsd } from '../../models/cost-coefficients';
9
+ import type { RetrievalLog } from '../../schema';
10
+ import type { AeoChatSurface } from '../../surfaces';
11
+ import {
12
+ ProbeAdapterId,
13
+ type ChatModelProvider,
14
+ type ProbeAdapter,
15
+ type ProbeAdapterProfile,
16
+ type ProbeAnswer,
17
+ type ProbeFailureClass,
18
+ type ProbeRequest,
19
+ } from '../adapter';
20
+ import {
21
+ extractAnthropicRetrieval,
22
+ extractGeminiRetrieval,
23
+ extractOpenAiRetrieval,
24
+ type RetrievalStep,
25
+ } from '../chat-retrieval';
26
+ import { classifyGatewayError, errorMessage, ProbeFailure } from '../failure';
27
+
28
+ // ============================================================================
29
+ // Chat surfaces through the Vercel AI Gateway with the provider's own web
30
+ // search tool (gateway.openai, gateway.google, gateway.anthropic): one
31
+ // search-required call and, when it returns no prose, one synthesis
32
+ // follow-up over its results. The request is the method: the prompt
33
+ // prefix, the tool, the token cap and the tool choice.
34
+ // ============================================================================
35
+
36
+ const log = createLog('AISearchProbes');
37
+
38
+ export const probeMaxOutputTokens = 2000;
39
+ // A search-required call plus a synthesis follow-up: bounded by the runner
40
+ // (hardening spec §4.5), never by undici's defaults plus SDK retries.
41
+ export const chatProbeTimeoutMs = 180_000;
42
+
43
+ export const searchPromptPrefix =
44
+ 'Search the web for current information to answer the following question. Return a complete answer, not just search results.\n\n';
45
+
46
+ /** reportedCostOf sums the reported costs of a probe's calls; absent unless
47
+ * every call reported one. */
48
+ export const reportedCostOf = (
49
+ costs: readonly (number | undefined)[],
50
+ ): { reportedCostUsd?: number } => {
51
+ if (costs.some((cost) => cost === undefined)) {
52
+ return {};
53
+ }
54
+
55
+ return {
56
+ reportedCostUsd: costs.reduce<number>((sum, cost) => sum + (cost ?? 0), 0),
57
+ };
58
+ };
59
+
60
+ /** classifyGatewayFailure keeps the error's kind and its message. */
61
+ export const classifyGatewayFailure = (error: unknown): ProbeFailureClass => {
62
+ return { kind: classifyGatewayError(error), message: errorMessage(error) };
63
+ };
64
+
65
+ /**
66
+ * toProviderToolSet hands provider-defined tools to `streamText`.
67
+ */
68
+ const toProviderToolSet = (tools: Record<string, unknown>): ToolSet => {
69
+ // eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- The provider packages declare their tools against a different Tool type than the `ai` package.
70
+ return tools as ToolSet;
71
+ };
72
+
73
+ // The slice of a model result the retrieval extractors read.
74
+ type SearchProbeResult = {
75
+ steps: ReadonlyArray<RetrievalStep>;
76
+ providerMetadata: unknown;
77
+ };
78
+
79
+ /** describeTools names each provider tool a request carries, with its
80
+ * arguments: the tool is part of the method. */
81
+ export const describeTools = (tools: Record<string, unknown>) => {
82
+ return Object.entries(tools).map(([name, tool]) => ({
83
+ name,
84
+ id: isRecord(tool) ? tool.id : undefined,
85
+ args: isRecord(tool) ? tool.args : undefined,
86
+ }));
87
+ };
88
+
89
+ type GatewayChatMethod = {
90
+ profile: ProbeAdapterProfile;
91
+ /** Built per call, as the request carries it. */
92
+ tools: () => Record<string, unknown>;
93
+ extractRetrieval: (result: SearchProbeResult) => RetrievalLog;
94
+ };
95
+
96
+ const searchRequest = (
97
+ model: string,
98
+ promptText: string,
99
+ tools: Record<string, unknown>,
100
+ ): ProbeRequest => {
101
+ return {
102
+ prompt: `${searchPromptPrefix}${promptText}`,
103
+ parameters: {
104
+ model,
105
+ maxOutputTokens: probeMaxOutputTokens,
106
+ toolChoice: 'required',
107
+ tools: describeTools(tools),
108
+ },
109
+ };
110
+ };
111
+
112
+ const searchProbe = async ({
113
+ surface,
114
+ gateway,
115
+ model,
116
+ promptText,
117
+ method,
118
+ }: {
119
+ surface: AeoChatSurface;
120
+ gateway: ChatModelProvider;
121
+ model: string;
122
+ promptText: string;
123
+ method: GatewayChatMethod;
124
+ }): Promise<ProbeAnswer> => {
125
+ const tools = method.tools();
126
+ const { prompt } = searchRequest(model, promptText, tools);
127
+ // Streamed like every other non-trivial response: the gateway abandons a
128
+ // non-streaming request at 340 seconds whatever the caller's own timeout.
129
+ // Without an `onError` the SDK prints a provider failure with
130
+ // `console.error`, which includes the full prompt, and then hands the
131
+ // caller a causeless error the retry classifier cannot read.
132
+ let streamFailure: unknown;
133
+ const streamed = streamText({
134
+ onError: ({ error }) => {
135
+ streamFailure ??= error;
136
+ },
137
+ model: gateway(model),
138
+ prompt,
139
+ maxOutputTokens: probeMaxOutputTokens,
140
+ tools: toProviderToolSet(tools),
141
+ toolChoice: 'required',
142
+ maxRetries: 0,
143
+ abortSignal: AbortSignal.timeout(chatProbeTimeoutMs),
144
+ });
145
+
146
+ // Drain the stream once; every field below resolves from that one pass,
147
+ // and every one of them is read behind the same unwrapping, so a provider
148
+ // failure is never seen as the SDK's stand-in error.
149
+ const [
150
+ steps,
151
+ text,
152
+ sources,
153
+ finishReason,
154
+ toolCalls,
155
+ response,
156
+ providerMetadata,
157
+ ] = await Promise.all([
158
+ streamed.steps,
159
+ streamed.text,
160
+ streamed.sources,
161
+ streamed.finishReason,
162
+ streamed.toolCalls,
163
+ streamed.response,
164
+ streamed.providerMetadata,
165
+ ]).catch((error: unknown) => {
166
+ throw streamFailure ?? error;
167
+ });
168
+
169
+ // The retrieval log comes from this first, search-required call only; the
170
+ // synthesis follow-up below runs with toolChoice: 'none' and contributes
171
+ // nothing. An empty log after a required tool call is an extractor miss
172
+ // (§7), not a from-memory answer: log it and store no retrieval, so the
173
+ // row renders "not captured" rather than "no searches".
174
+ let retrieval: RetrievalLog | null = method.extractRetrieval({
175
+ steps,
176
+ providerMetadata,
177
+ });
178
+
179
+ if (retrieval.calls.length === 0) {
180
+ log.warn('Search-required probe yielded no retrieval calls; not stored', {
181
+ model: surface,
182
+ stepCount: steps.length,
183
+ partTypes: [
184
+ ...new Set(steps.flatMap((step) => step.content.map((p) => p.type))),
185
+ ],
186
+ });
187
+
188
+ retrieval = null;
189
+ }
190
+
191
+ const firstCost = gatewayCostUsd(providerMetadata);
192
+
193
+ if (text.trim().length > 0) {
194
+ return {
195
+ answerText: text,
196
+ sources: { format: 'search', sources },
197
+ retrieval,
198
+ servedModel: response.modelId,
199
+ ...reportedCostOf([firstCost]),
200
+ };
201
+ }
202
+
203
+ log.warn('Search probe returned no answer text; synthesizing from search', {
204
+ model: surface,
205
+ finishReason,
206
+ toolCallCount: toolCalls.length,
207
+ sourceCount: sources.length,
208
+ });
209
+
210
+ // The follow-up is its own stream with its own failure: a 429 here is
211
+ // capacity, to be retried as such, and must not be read through the
212
+ // first stream's error or mistaken for a parser slip.
213
+ let followupFailure: unknown;
214
+ const followupStream = streamText({
215
+ onError: ({ error }) => {
216
+ followupFailure ??= error;
217
+ },
218
+ model: gateway(model),
219
+ messages: [
220
+ { role: 'user', content: prompt },
221
+ ...response.messages,
222
+ {
223
+ role: 'user',
224
+ content:
225
+ '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.',
226
+ },
227
+ ],
228
+ maxOutputTokens: probeMaxOutputTokens,
229
+ tools: toProviderToolSet(method.tools()),
230
+ toolChoice: 'none',
231
+ maxRetries: 0,
232
+ abortSignal: AbortSignal.timeout(chatProbeTimeoutMs),
233
+ });
234
+
235
+ const [followupText, followupSources, followupMetadata] = await Promise.all([
236
+ followupStream.text,
237
+ followupStream.sources,
238
+ followupStream.providerMetadata,
239
+ ]).catch((error: unknown) => {
240
+ throw followupFailure ?? error;
241
+ });
242
+
243
+ if (followupText.trim().length > 0) {
244
+ return {
245
+ answerText: followupText,
246
+ sources: {
247
+ format: 'search',
248
+ sources: sources.length > 0 ? sources : followupSources,
249
+ },
250
+ retrieval,
251
+ servedModel: response.modelId,
252
+ ...reportedCostOf([firstCost, gatewayCostUsd(followupMetadata)]),
253
+ };
254
+ }
255
+
256
+ // No answer after the search and the synthesis follow-up: a failed unit
257
+ // (hardening spec §2.4), retried like a transient failure — never banked
258
+ // as a measured absence.
259
+ throw new ProbeFailure(
260
+ 'empty_answer',
261
+ `${surface} completed a required web search but returned no answer text (tool calls: ${toolCalls.length}, sources: ${sources.length})`,
262
+ );
263
+ };
264
+
265
+ const gatewayChatProfile = (
266
+ id: ProbeAdapterProfile['id'],
267
+ retrieval: ProbeAdapterProfile['observes']['retrieval'],
268
+ ): ProbeAdapterProfile => {
269
+ return {
270
+ id,
271
+ observes: { retrieval, servedModel: 'compare_to_requested' },
272
+ settings: [{ name: 'AI_GATEWAY_API_KEY', secret: true }],
273
+ pool: 'gateway',
274
+ retry: 'chat',
275
+ estimateUsd: probeUsd[id],
276
+ billing: 'metered',
277
+ resolvesRedirects: true,
278
+ };
279
+ };
280
+
281
+ export type GatewayChatAdapterId =
282
+ | typeof ProbeAdapterId.GATEWAY_OPENAI
283
+ | typeof ProbeAdapterId.GATEWAY_GOOGLE
284
+ | typeof ProbeAdapterId.GATEWAY_ANTHROPIC;
285
+
286
+ const gatewayChatMethods: Record<GatewayChatAdapterId, GatewayChatMethod> = {
287
+ [ProbeAdapterId.GATEWAY_OPENAI]: {
288
+ profile: gatewayChatProfile(ProbeAdapterId.GATEWAY_OPENAI, 'full'),
289
+ tools: () => ({ web_search: openai.tools.webSearch({}) }),
290
+ extractRetrieval: (result) => extractOpenAiRetrieval(result.steps),
291
+ },
292
+ [ProbeAdapterId.GATEWAY_GOOGLE]: {
293
+ profile: gatewayChatProfile(ProbeAdapterId.GATEWAY_GOOGLE, 'partial'),
294
+ tools: () => ({ google_search: google.tools.googleSearch({}) }),
295
+ extractRetrieval: (result) =>
296
+ extractGeminiRetrieval(result.providerMetadata),
297
+ },
298
+ [ProbeAdapterId.GATEWAY_ANTHROPIC]: {
299
+ profile: gatewayChatProfile(ProbeAdapterId.GATEWAY_ANTHROPIC, 'full'),
300
+ tools: () => ({
301
+ web_search: anthropic.tools.webSearch_20250305({ maxUses: 5 }),
302
+ }),
303
+ extractRetrieval: (result) => extractAnthropicRetrieval(result.steps),
304
+ },
305
+ };
306
+
307
+ export const gatewayChatProfiles = {
308
+ [ProbeAdapterId.GATEWAY_OPENAI]:
309
+ gatewayChatMethods[ProbeAdapterId.GATEWAY_OPENAI].profile,
310
+ [ProbeAdapterId.GATEWAY_GOOGLE]:
311
+ gatewayChatMethods[ProbeAdapterId.GATEWAY_GOOGLE].profile,
312
+ [ProbeAdapterId.GATEWAY_ANTHROPIC]:
313
+ gatewayChatMethods[ProbeAdapterId.GATEWAY_ANTHROPIC].profile,
314
+ } satisfies Record<GatewayChatAdapterId, ProbeAdapterProfile>;
315
+
316
+ /** createGatewayChatAdapter is one search-required chat adapter, asking
317
+ * `model` on `surface` through the run's `gateway`. */
318
+ export const createGatewayChatAdapter = (
319
+ id: GatewayChatAdapterId,
320
+ {
321
+ surface,
322
+ gateway,
323
+ model,
324
+ }: { surface: AeoChatSurface; gateway: ChatModelProvider; model: string },
325
+ ): ProbeAdapter => {
326
+ const method: GatewayChatMethod = gatewayChatMethods[id];
327
+
328
+ const adapter: ProbeAdapter = {
329
+ ...method.profile,
330
+ surface,
331
+ model,
332
+ request: (promptText) => searchRequest(model, promptText, method.tools()),
333
+ probe: (promptText) =>
334
+ searchProbe({ surface, gateway, model, promptText, method }),
335
+ classifyError: classifyGatewayFailure,
336
+ };
337
+
338
+ return adapter;
339
+ };
@@ -0,0 +1,104 @@
1
+ import { streamText } from 'ai';
2
+ import { gatewayCostUsd } from '../../models/gateway-cost';
3
+ import { probeUsd } from '../../models/cost-coefficients';
4
+ import type { AeoChatSurface } from '../../surfaces';
5
+ import {
6
+ ProbeAdapterId,
7
+ type ChatModelProvider,
8
+ type ProbeAdapter,
9
+ type ProbeAdapterProfile,
10
+ } from '../adapter';
11
+ import { ProbeFailure } from '../failure';
12
+ import {
13
+ chatProbeTimeoutMs,
14
+ classifyGatewayFailure,
15
+ probeMaxOutputTokens,
16
+ reportedCostOf,
17
+ searchPromptPrefix,
18
+ } from './gateway-chat';
19
+
20
+ // ============================================================================
21
+ // Perplexity through the Vercel AI Gateway (gateway.perplexity): the model
22
+ // searches on its own, with no tool to require, and exposes no queries.
23
+ // It cites with bare numeric markers ([1], [2]) and returns the URLs behind
24
+ // them out of band in `sources`, rendered like the other search surfaces so
25
+ // citation extraction sees them.
26
+ // ============================================================================
27
+
28
+ export const gatewayPerplexityProfile: ProbeAdapterProfile = {
29
+ id: ProbeAdapterId.GATEWAY_PERPLEXITY,
30
+ observes: { retrieval: 'none', servedModel: 'compare_to_requested' },
31
+ settings: [{ name: 'AI_GATEWAY_API_KEY', secret: true }],
32
+ pool: 'gateway',
33
+ retry: 'chat',
34
+ estimateUsd: probeUsd[ProbeAdapterId.GATEWAY_PERPLEXITY],
35
+ billing: 'metered',
36
+ resolvesRedirects: true,
37
+ };
38
+
39
+ /** createGatewayPerplexityAdapter asks `model` on `surface` through the
40
+ * run's `gateway`. */
41
+ export const createGatewayPerplexityAdapter = ({
42
+ surface,
43
+ gateway,
44
+ model,
45
+ }: {
46
+ surface: AeoChatSurface;
47
+ gateway: ChatModelProvider;
48
+ model: string;
49
+ }): ProbeAdapter => {
50
+ const adapter: ProbeAdapter = {
51
+ ...gatewayPerplexityProfile,
52
+ surface,
53
+ model,
54
+ request: (promptText) => ({
55
+ prompt: `${searchPromptPrefix}${promptText}`,
56
+ parameters: { model, maxOutputTokens: probeMaxOutputTokens },
57
+ }),
58
+ probe: async (promptText) => {
59
+ let streamFailure: unknown;
60
+ const stream = streamText({
61
+ onError: ({ error }) => {
62
+ streamFailure ??= error;
63
+ },
64
+ model: gateway(model),
65
+ prompt: `${searchPromptPrefix}${promptText}`,
66
+ maxOutputTokens: probeMaxOutputTokens,
67
+ maxRetries: 0,
68
+ abortSignal: AbortSignal.timeout(chatProbeTimeoutMs),
69
+ });
70
+
71
+ const [text, sources, response, providerMetadata] = await Promise.all([
72
+ stream.text,
73
+ stream.sources,
74
+ stream.response,
75
+ stream.providerMetadata,
76
+ ]).catch((error: unknown) => {
77
+ throw streamFailure ?? error;
78
+ });
79
+
80
+ // Checked before the sources are rendered: sources alone are no
81
+ // answer.
82
+ if (text.trim().length === 0) {
83
+ throw new ProbeFailure(
84
+ 'empty_answer',
85
+ 'perplexity returned no answer text',
86
+ );
87
+ }
88
+
89
+ return {
90
+ answerText: text,
91
+ sources: { format: 'search', sources },
92
+ retrieval: {
93
+ exposure: gatewayPerplexityProfile.observes.retrieval,
94
+ calls: [],
95
+ },
96
+ servedModel: response.modelId,
97
+ ...reportedCostOf([gatewayCostUsd(providerMetadata)]),
98
+ };
99
+ },
100
+ classifyError: classifyGatewayFailure,
101
+ };
102
+
103
+ return adapter;
104
+ };