literally-aeo 0.0.0-stage → 0.1.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.
- package/LICENSE +21 -0
- package/README.md +73 -2
- package/dist/author-tools.js +3031 -0
- package/dist/cli.mjs +25536 -0
- package/dist/lib/access/schema.js +24 -0
- package/dist/lib/agents/author-schema.js +28 -0
- package/dist/lib/agents/author-validation.js +46 -0
- package/dist/lib/agents/copy-schema.js +30 -0
- package/dist/lib/agents/copy-validation.js +62 -0
- package/dist/lib/agents/copywriter-input.js +31 -0
- package/dist/lib/agents/credentials.js +6 -0
- package/dist/lib/agents/facts.js +31 -0
- package/dist/lib/agents/narrative-facts.js +12 -0
- package/dist/lib/agents/verifier.js +62 -0
- package/dist/lib/analysis/answer-text.js +19 -0
- package/dist/lib/analysis/competitor-classifier.js +6 -0
- package/dist/lib/analysis/domain-classifier.js +73 -0
- package/dist/lib/analysis/domain-labels.js +32 -0
- package/dist/lib/analysis/domain-match.js +12 -0
- package/dist/lib/analysis/name-forms.js +12 -0
- package/dist/lib/analysis/outreach.js +17 -0
- package/dist/lib/analysis/progress-schema.js +13 -0
- package/dist/lib/analysis/progress.js +39 -0
- package/dist/lib/analysis/qualified-competitors.js +7 -0
- package/dist/lib/analysis/retrieval.js +16 -0
- package/dist/lib/analysis/scoring.js +12 -0
- package/dist/lib/analysis/search-analyzer.js +17 -0
- package/dist/lib/analysis/sentiment.js +61 -0
- package/dist/lib/analysis/source-classifier.js +22 -0
- package/dist/lib/analysis/source-mix.js +16 -0
- package/dist/lib/analysis/verbatim.js +6 -0
- package/dist/lib/api/errors.js +10 -0
- package/dist/lib/author/examples.js +34 -0
- package/dist/lib/bundle/checks.js +16 -0
- package/dist/lib/bundle/contracts.js +66 -0
- package/dist/lib/bundle/export.js +69 -0
- package/dist/lib/bundle/journal.js +41 -0
- package/dist/lib/bundle/json.js +13 -0
- package/dist/lib/bundle/lineage.js +13 -0
- package/dist/lib/bundle/paths.js +6 -0
- package/dist/lib/bundle/project-journal.js +36 -0
- package/dist/lib/bundle/project.js +55 -0
- package/dist/lib/bundle/read.js +60 -0
- package/dist/lib/bundle/recorder.js +46 -0
- package/dist/lib/bundle/redact.js +35 -0
- package/dist/lib/bundle/trace-coverage.js +33 -0
- package/dist/lib/bundle/verify-integrity.js +41 -0
- package/dist/lib/bundle/verify-measurement.js +49 -0
- package/dist/lib/bundle/verify-report.js +62 -0
- package/dist/lib/bundle/verify.js +71 -0
- package/dist/lib/bundle/writer-lock.js +11 -0
- package/dist/lib/bundle/zip.js +13 -0
- package/dist/lib/capture-manifest.js +42 -0
- package/dist/lib/checks/crawler-access.js +16 -0
- package/dist/lib/checks/renderability.js +8 -0
- package/dist/lib/checks/run-checks.js +38 -0
- package/dist/lib/chunks/chunk-2KJZ326K.js +253 -0
- package/dist/lib/chunks/chunk-2MGARWKY.js +138 -0
- package/dist/lib/chunks/chunk-2NJEWPCV.js +94 -0
- package/dist/lib/chunks/chunk-2PAO43CH.js +43 -0
- package/dist/lib/chunks/chunk-2QLAFBCG.js +8 -0
- package/dist/lib/chunks/chunk-2ROSV4HD.js +64 -0
- package/dist/lib/chunks/chunk-2URYGUMH.js +27 -0
- package/dist/lib/chunks/chunk-3BFCI7LI.js +34 -0
- package/dist/lib/chunks/chunk-3BJWRD4O.js +0 -0
- package/dist/lib/chunks/chunk-3EBWDHPK.js +133 -0
- package/dist/lib/chunks/chunk-3UFZ2XPE.js +73 -0
- package/dist/lib/chunks/chunk-4E4NDGOZ.js +47 -0
- package/dist/lib/chunks/chunk-4QQJXCD2.js +113 -0
- package/dist/lib/chunks/chunk-4US3OBKJ.js +136 -0
- package/dist/lib/chunks/chunk-4ZY6P5SO.js +303 -0
- package/dist/lib/chunks/chunk-55U7PRRM.js +26 -0
- package/dist/lib/chunks/chunk-565CYND6.js +93 -0
- package/dist/lib/chunks/chunk-56VOFZ7T.js +1486 -0
- package/dist/lib/chunks/chunk-5B3RNVZ6.js +193 -0
- package/dist/lib/chunks/chunk-5EX5DKMA.js +812 -0
- package/dist/lib/chunks/chunk-5GZVDGTX.js +316 -0
- package/dist/lib/chunks/chunk-5H3SNUQT.js +101 -0
- package/dist/lib/chunks/chunk-5HT55QYX.js +53 -0
- package/dist/lib/chunks/chunk-5KKLUM7M.js +105 -0
- package/dist/lib/chunks/chunk-5SOTF3XD.js +56 -0
- package/dist/lib/chunks/chunk-5T3V6XJS.js +41 -0
- package/dist/lib/chunks/chunk-5VNYUCLL.js +352 -0
- package/dist/lib/chunks/chunk-5ZITQDVE.js +149 -0
- package/dist/lib/chunks/chunk-6AUEDSTU.js +52 -0
- package/dist/lib/chunks/chunk-6EH4N3EU.js +113 -0
- package/dist/lib/chunks/chunk-6EI4CVRW.js +33 -0
- package/dist/lib/chunks/chunk-6GKKALCI.js +538 -0
- package/dist/lib/chunks/chunk-6GSQKCKF.js +48 -0
- package/dist/lib/chunks/chunk-6KHQ7DXP.js +100 -0
- package/dist/lib/chunks/chunk-6KO7HGCQ.js +229 -0
- package/dist/lib/chunks/chunk-6RAKXYSR.js +226 -0
- package/dist/lib/chunks/chunk-72P6NOKD.js +190 -0
- package/dist/lib/chunks/chunk-74UNVGWB.js +0 -0
- package/dist/lib/chunks/chunk-7GXRDAUY.js +554 -0
- package/dist/lib/chunks/chunk-7MR6IJ7I.js +0 -0
- package/dist/lib/chunks/chunk-7O3M6I2X.js +123 -0
- package/dist/lib/chunks/chunk-7PLK6VGC.js +12 -0
- package/dist/lib/chunks/chunk-7QYZSP7Q.js +190 -0
- package/dist/lib/chunks/chunk-7YYDUHJG.js +113 -0
- package/dist/lib/chunks/chunk-7ZOJE6BH.js +73 -0
- package/dist/lib/chunks/chunk-AKKFERA4.js +99 -0
- package/dist/lib/chunks/chunk-AP5DLF36.js +150 -0
- package/dist/lib/chunks/chunk-AUB5THIS.js +341 -0
- package/dist/lib/chunks/chunk-AWOJWMPN.js +213 -0
- package/dist/lib/chunks/chunk-B5L2KMTU.js +108 -0
- package/dist/lib/chunks/chunk-BEQLSAVX.js +202 -0
- package/dist/lib/chunks/chunk-C6CMSW5J.js +13 -0
- package/dist/lib/chunks/chunk-CFFPOTP4.js +356 -0
- package/dist/lib/chunks/chunk-CJ5YD3CU.js +237 -0
- package/dist/lib/chunks/chunk-CPT2GKKW.js +188 -0
- package/dist/lib/chunks/chunk-CQ62GN7P.js +30 -0
- package/dist/lib/chunks/chunk-CRVCWDH6.js +0 -0
- package/dist/lib/chunks/chunk-CS24IL3K.js +115 -0
- package/dist/lib/chunks/chunk-D2INDP5W.js +240 -0
- package/dist/lib/chunks/chunk-D2LPQO6Y.js +39 -0
- package/dist/lib/chunks/chunk-D5B4ZOW6.js +61 -0
- package/dist/lib/chunks/chunk-D7GEQVLL.js +115 -0
- package/dist/lib/chunks/chunk-DC6PN7QJ.js +193 -0
- package/dist/lib/chunks/chunk-DYJVVQHD.js +60 -0
- package/dist/lib/chunks/chunk-E3CDKC5B.js +45 -0
- package/dist/lib/chunks/chunk-E4HADK7C.js +18 -0
- package/dist/lib/chunks/chunk-E6NQQU6V.js +111 -0
- package/dist/lib/chunks/chunk-EBXOHAMQ.js +131 -0
- package/dist/lib/chunks/chunk-EPQHVILQ.js +348 -0
- package/dist/lib/chunks/chunk-EV4DRS5M.js +61 -0
- package/dist/lib/chunks/chunk-EYKINDNK.js +29 -0
- package/dist/lib/chunks/chunk-EZD2C7QS.js +10 -0
- package/dist/lib/chunks/chunk-FBFZBLTY.js +752 -0
- package/dist/lib/chunks/chunk-FFOVLI3U.js +235 -0
- package/dist/lib/chunks/chunk-FKLNEB2P.js +529 -0
- package/dist/lib/chunks/chunk-FT5NSQYX.js +0 -0
- package/dist/lib/chunks/chunk-FWBVTM7F.js +11 -0
- package/dist/lib/chunks/chunk-GLXY73MK.js +165 -0
- package/dist/lib/chunks/chunk-GMGKKE5N.js +11 -0
- package/dist/lib/chunks/chunk-GVC4LH2N.js +130 -0
- package/dist/lib/chunks/chunk-GVOF5ZUG.js +44 -0
- package/dist/lib/chunks/chunk-H2KDLDK6.js +13 -0
- package/dist/lib/chunks/chunk-H3G3VTT7.js +259 -0
- package/dist/lib/chunks/chunk-H56DDRKE.js +85 -0
- package/dist/lib/chunks/chunk-HOJXKHPX.js +34 -0
- package/dist/lib/chunks/chunk-HSZ3DM74.js +55 -0
- package/dist/lib/chunks/chunk-HXHFMFQU.js +29 -0
- package/dist/lib/chunks/chunk-I7VNIW6Q.js +196 -0
- package/dist/lib/chunks/chunk-IAR6XGEW.js +184 -0
- package/dist/lib/chunks/chunk-IB6RROHE.js +204 -0
- package/dist/lib/chunks/chunk-IBOWGKN7.js +98 -0
- package/dist/lib/chunks/chunk-IEVAFDW7.js +513 -0
- package/dist/lib/chunks/chunk-IPNK7FYT.js +70 -0
- package/dist/lib/chunks/chunk-IRPKBDB7.js +13 -0
- package/dist/lib/chunks/chunk-ISN6MBNB.js +70 -0
- package/dist/lib/chunks/chunk-J46W3EMQ.js +237 -0
- package/dist/lib/chunks/chunk-J6IJGYP5.js +147 -0
- package/dist/lib/chunks/chunk-JQ3P552S.js +0 -0
- package/dist/lib/chunks/chunk-JS3GBU3R.js +46 -0
- package/dist/lib/chunks/chunk-KMRQSIZW.js +90 -0
- package/dist/lib/chunks/chunk-KRFHQQS7.js +323 -0
- package/dist/lib/chunks/chunk-KZR25REO.js +95 -0
- package/dist/lib/chunks/chunk-LIZX4N3H.js +110 -0
- package/dist/lib/chunks/chunk-M2OD74GP.js +93 -0
- package/dist/lib/chunks/chunk-MHAKYFDF.js +741 -0
- package/dist/lib/chunks/chunk-MIF5IYNR.js +139 -0
- package/dist/lib/chunks/chunk-MRRWMAPA.js +0 -0
- package/dist/lib/chunks/chunk-MX6Y4RD2.js +22 -0
- package/dist/lib/chunks/chunk-N2XIGMJ6.js +0 -0
- package/dist/lib/chunks/chunk-N2ZZ6JRF.js +188 -0
- package/dist/lib/chunks/chunk-NANJGMEJ.js +108 -0
- package/dist/lib/chunks/chunk-NCLFZOZU.js +74 -0
- package/dist/lib/chunks/chunk-NH4QGBJV.js +61 -0
- package/dist/lib/chunks/chunk-NL2LDKXX.js +125 -0
- package/dist/lib/chunks/chunk-NZFMOQHU.js +32 -0
- package/dist/lib/chunks/chunk-O2DKE2RO.js +77 -0
- package/dist/lib/chunks/chunk-O7M2OY3H.js +35 -0
- package/dist/lib/chunks/chunk-OBXAHX3L.js +46 -0
- package/dist/lib/chunks/chunk-OL746E4T.js +350 -0
- package/dist/lib/chunks/chunk-OORO55OM.js +922 -0
- package/dist/lib/chunks/chunk-OVUCZLH2.js +114 -0
- package/dist/lib/chunks/chunk-OX656HYK.js +46 -0
- package/dist/lib/chunks/chunk-OYKV5NDM.js +28 -0
- package/dist/lib/chunks/chunk-P4K6BP3L.js +104 -0
- package/dist/lib/chunks/chunk-PCYNBDZ7.js +386 -0
- package/dist/lib/chunks/chunk-PDS5KWO3.js +256 -0
- package/dist/lib/chunks/chunk-PKB6JRJM.js +53 -0
- package/dist/lib/chunks/chunk-PO2J5OQ3.js +46 -0
- package/dist/lib/chunks/chunk-PYLJISDZ.js +206 -0
- package/dist/lib/chunks/chunk-Q2PWES4B.js +822 -0
- package/dist/lib/chunks/chunk-QBD24WTZ.js +37 -0
- package/dist/lib/chunks/chunk-QFVRCSJ2.js +54 -0
- package/dist/lib/chunks/chunk-QTXOW5XC.js +14 -0
- package/dist/lib/chunks/chunk-RBOO4NDG.js +33 -0
- package/dist/lib/chunks/chunk-RMFT4KKK.js +281 -0
- package/dist/lib/chunks/chunk-S2AM76LT.js +90 -0
- package/dist/lib/chunks/chunk-S2SFHTJD.js +152 -0
- package/dist/lib/chunks/chunk-S42BCLHP.js +0 -0
- package/dist/lib/chunks/chunk-S7KJZIUR.js +241 -0
- package/dist/lib/chunks/chunk-SBAZBOPI.js +33 -0
- package/dist/lib/chunks/chunk-SBQ4TWGJ.js +33 -0
- package/dist/lib/chunks/chunk-SDWYZM64.js +371 -0
- package/dist/lib/chunks/chunk-SREGO3PU.js +25 -0
- package/dist/lib/chunks/chunk-SWJ7KQSL.js +318 -0
- package/dist/lib/chunks/chunk-SZ2UBZKG.js +13 -0
- package/dist/lib/chunks/chunk-TCOH3FGE.js +66 -0
- package/dist/lib/chunks/chunk-TGTM5ZFR.js +82 -0
- package/dist/lib/chunks/chunk-TNL2GWYR.js +345 -0
- package/dist/lib/chunks/chunk-UGCT46PC.js +20 -0
- package/dist/lib/chunks/chunk-ULRXHSJL.js +85 -0
- package/dist/lib/chunks/chunk-URUODEVG.js +0 -0
- package/dist/lib/chunks/chunk-V5B6UZ3E.js +47 -0
- package/dist/lib/chunks/chunk-VHDVKEWO.js +102 -0
- package/dist/lib/chunks/chunk-W46Y7KBR.js +29 -0
- package/dist/lib/chunks/chunk-W5XYW6ZM.js +133 -0
- package/dist/lib/chunks/chunk-WDSCJEDG.js +371 -0
- package/dist/lib/chunks/chunk-WE2WPNG2.js +104 -0
- package/dist/lib/chunks/chunk-WJUHRJVW.js +55 -0
- package/dist/lib/chunks/chunk-WKH6BJAZ.js +167 -0
- package/dist/lib/chunks/chunk-WTQWU522.js +343 -0
- package/dist/lib/chunks/chunk-WUELMJ22.js +345 -0
- package/dist/lib/chunks/chunk-X2Y2ZNG3.js +776 -0
- package/dist/lib/chunks/chunk-X6E44EGV.js +261 -0
- package/dist/lib/chunks/chunk-XHWRSGX3.js +95 -0
- package/dist/lib/chunks/chunk-XI5H46DF.js +47 -0
- package/dist/lib/chunks/chunk-XJVXASDD.js +281 -0
- package/dist/lib/chunks/chunk-XU6WQ5UL.js +257 -0
- package/dist/lib/chunks/chunk-Y4OGZ3Q5.js +365 -0
- package/dist/lib/chunks/chunk-Y6D6IVOM.js +299 -0
- package/dist/lib/chunks/chunk-YHS5IEVZ.js +252 -0
- package/dist/lib/chunks/chunk-YIEAIIND.js +6 -0
- package/dist/lib/chunks/chunk-YOZNLFSB.js +297 -0
- package/dist/lib/chunks/chunk-YR67JG2V.js +65 -0
- package/dist/lib/chunks/chunk-YWJPJI3W.js +51 -0
- package/dist/lib/chunks/chunk-Z4LMDKBU.js +369 -0
- package/dist/lib/chunks/chunk-Z7V63UZA.js +108 -0
- package/dist/lib/chunks/chunk-ZCOI3HE2.js +45 -0
- package/dist/lib/chunks/chunk-ZLOOC46D.js +142 -0
- package/dist/lib/chunks/chunk-ZSEY7AHQ.js +123 -0
- package/dist/lib/chunks/chunk-ZVAKKRRD.js +11 -0
- package/dist/lib/chunks/chunk-ZXQPD4OC.js +202 -0
- package/dist/lib/chunks/chunk-ZYSPTOKK.js +302 -0
- package/dist/lib/cli/bundle-commands.js +371 -0
- package/dist/lib/cli/io.js +12 -0
- package/dist/lib/cli/run-commands.js +614 -0
- package/dist/lib/codex-workflow/aggregate.js +56 -0
- package/dist/lib/codex-workflow/author-search.js +48 -0
- package/dist/lib/codex-workflow/author-tools.js +63 -0
- package/dist/lib/codex-workflow/author.js +99 -0
- package/dist/lib/codex-workflow/batch-input.js +7 -0
- package/dist/lib/codex-workflow/batch-layout.js +8 -0
- package/dist/lib/codex-workflow/capture.js +62 -0
- package/dist/lib/codex-workflow/checkpoint.js +39 -0
- package/dist/lib/codex-workflow/checks.js +44 -0
- package/dist/lib/codex-workflow/codex-home.js +17 -0
- package/dist/lib/codex-workflow/copy-editor.js +66 -0
- package/dist/lib/codex-workflow/copy-recovery.js +32 -0
- package/dist/lib/codex-workflow/copy.js +66 -0
- package/dist/lib/codex-workflow/finish.js +84 -0
- package/dist/lib/codex-workflow/host-models.js +15 -0
- package/dist/lib/codex-workflow/loop.js +140 -0
- package/dist/lib/codex-workflow/pending.js +8 -0
- package/dist/lib/codex-workflow/prompts.js +8 -0
- package/dist/lib/codex-workflow/quality.js +31 -0
- package/dist/lib/codex-workflow/run-inputs.js +38 -0
- package/dist/lib/codex-workflow/run-source.js +55 -0
- package/dist/lib/codex-workflow/schemas.js +58 -0
- package/dist/lib/codex-workflow/session.js +40 -0
- package/dist/lib/codex-workflow/stage.js +98 -0
- package/dist/lib/codex-workflow/workdir.js +42 -0
- package/dist/lib/configs/literally-2026-q3.js +6 -0
- package/dist/lib/container/protocol.js +20 -0
- package/dist/lib/coverage-schema.js +6 -0
- package/dist/lib/engine/audit-file.js +46 -0
- package/dist/lib/engine/author.js +97 -0
- package/dist/lib/engine/budget.js +16 -0
- package/dist/lib/engine/env-file.js +8 -0
- package/dist/lib/engine/local-run.js +149 -0
- package/dist/lib/engine/package-root.js +8 -0
- package/dist/lib/engine/preflight.js +43 -0
- package/dist/lib/engine/rejudge.js +151 -0
- package/dist/lib/engine/resources.js +7 -0
- package/dist/lib/engine/run-configuration.js +15 -0
- package/dist/lib/engine/templates.js +33 -0
- package/dist/lib/grounding/controller.js +31 -0
- package/dist/lib/grounding/extract.js +38 -0
- package/dist/lib/grounding/fetch.js +23 -0
- package/dist/lib/grounding/file-store.js +17 -0
- package/dist/lib/grounding/grounding-runtime.js +62 -0
- package/dist/lib/grounding/model-usage.js +9 -0
- package/dist/lib/grounding/model.js +30 -0
- package/dist/lib/grounding/profile.js +15 -0
- package/dist/lib/grounding/recorded-tools.js +35 -0
- package/dist/lib/grounding/schema.js +42 -0
- package/dist/lib/grounding/session.js +30 -0
- package/dist/lib/grounding/tools.js +25 -0
- package/dist/lib/grounding/validation.js +28 -0
- package/dist/lib/grounding.js +13 -0
- package/dist/lib/harness/checkpoint.js +17 -0
- package/dist/lib/harness/contracts.js +30 -0
- package/dist/lib/harness/criteria.js +14 -0
- package/dist/lib/harness/policy.js +25 -0
- package/dist/lib/harness/report/artifacts.js +36 -0
- package/dist/lib/harness/report/capture-coverage.js +11 -0
- package/dist/lib/harness/store.js +46 -0
- package/dist/lib/lib/analysis-checkpoint.js +10 -0
- package/dist/lib/lib/canonical-json.js +8 -0
- package/dist/lib/lib/checkpoint.js +34 -0
- package/dist/lib/lib/env.js +14 -0
- package/dist/lib/lib/log.js +7 -0
- package/dist/lib/lib/paths.js +8 -0
- package/dist/lib/lib/progress-comparison.js +16 -0
- package/dist/lib/lib/report-presentation.js +13 -0
- package/dist/lib/lib/run-id.js +8 -0
- package/dist/lib/lib/type-guards.js +8 -0
- package/dist/lib/models/accounting.js +22 -0
- package/dist/lib/models/batching.js +18 -0
- package/dist/lib/models/budget-protection.js +6 -0
- package/dist/lib/models/context.js +0 -0
- package/dist/lib/models/coverage-rounds.js +6 -0
- package/dist/lib/models/errors.js +8 -0
- package/dist/lib/models/failure-diagnostics.js +6 -0
- package/dist/lib/models/profiles.js +30 -0
- package/dist/lib/models/served-model.js +6 -0
- package/dist/lib/models/structured-images.js +10 -0
- package/dist/lib/models/structured.js +25 -0
- package/dist/lib/models/wire-schema.js +6 -0
- package/dist/lib/pipeline.js +57 -0
- package/dist/lib/probes/agent-cli-parsers.js +23 -0
- package/dist/lib/probes/agent-clis.js +64 -0
- package/dist/lib/probes/chat-retrieval.js +17 -0
- package/dist/lib/probes/child-process.js +13 -0
- package/dist/lib/probes/dataforseo-locale.js +10 -0
- package/dist/lib/probes/dataforseo.js +10 -0
- package/dist/lib/probes/failure.js +26 -0
- package/dist/lib/probes/grounding-urls.js +19 -0
- package/dist/lib/probes/limits.js +12 -0
- package/dist/lib/probes/outcomes.js +13 -0
- package/dist/lib/probes/probe-trace.js +12 -0
- package/dist/lib/probes/probes.js +40 -0
- package/dist/lib/probes/web-tool-guard.js +18 -0
- package/dist/lib/report/contracts.js +34 -0
- package/dist/lib/report/core/answer-text.js +18 -0
- package/dist/lib/report/core/copy-schema.js +10 -0
- package/dist/lib/report/core/domain-match.js +11 -0
- package/dist/lib/report/core/grounding.js +12 -0
- package/dist/lib/report/core/normalize-domain.js +6 -0
- package/dist/lib/report/core/progress-comparison.js +15 -0
- package/dist/lib/report/core/progress-question-sets.js +16 -0
- package/dist/lib/report/core/progress-schema.js +12 -0
- package/dist/lib/report/core/progress-slot-key.js +6 -0
- package/dist/lib/report/core/qualified-competitors.js +6 -0
- package/dist/lib/report/core/report-presentation.js +12 -0
- package/dist/lib/report/core/retrieval.js +10 -0
- package/dist/lib/report/core/schema.js +70 -0
- package/dist/lib/report/core/source-classifier.js +21 -0
- package/dist/lib/report/core/surfaces.js +18 -0
- package/dist/lib/retrieval.js +11 -0
- package/dist/lib/runner.js +71 -0
- package/dist/lib/schema.js +110 -0
- package/dist/lib/section-result.js +34 -0
- package/dist/lib/stores/artifacts.js +35 -0
- package/dist/lib/stores/content-hash.js +10 -0
- package/dist/lib/stores/file-publication.js +20 -0
- package/dist/lib/stores/files.js +76 -0
- package/dist/lib/stores/fs-errors.js +6 -0
- package/dist/lib/stores/local-versions.js +40 -0
- package/dist/lib/stores/memory.js +312 -0
- package/dist/lib/stores/ports.js +6 -0
- package/dist/lib/stores/publication-history.js +10 -0
- package/dist/lib/stores/publication.js +50 -0
- package/dist/lib/stores/run-lifecycle.js +12 -0
- package/dist/lib/stores/versions.js +6 -0
- package/dist/lib/surfaces.js +19 -0
- package/dist/lib/viewer/page.js +6 -0
- package/dist/lib/viewer/server.js +71 -0
- package/dist/lib/workflow/callbacks.js +15 -0
- package/dist/lib/workflow/lineage.js +8 -0
- package/dist/lib/workflow/schema.js +52 -0
- package/dist/types/access/schema.d.ts +75 -0
- package/dist/types/agents/author-schema.d.ts +76 -0
- package/dist/types/agents/author-validation.d.ts +73 -0
- package/dist/types/agents/copy-schema.d.ts +345 -0
- package/dist/types/agents/copy-validation.d.ts +158 -0
- package/dist/types/agents/copywriter-input.d.ts +46 -0
- package/dist/types/agents/credentials.d.ts +10 -0
- package/dist/types/agents/facts.d.ts +69 -0
- package/dist/types/agents/narrative-facts.d.ts +8 -0
- package/dist/types/agents/verifier.d.ts +167 -0
- package/dist/types/analysis/answer-text.d.ts +1 -0
- package/dist/types/analysis/competitor-classifier.d.ts +1 -0
- package/dist/types/analysis/domain-classifier.d.ts +105 -0
- package/dist/types/analysis/domain-labels.d.ts +30 -0
- package/dist/types/analysis/domain-match.d.ts +1 -0
- package/dist/types/analysis/name-forms.d.ts +25 -0
- package/dist/types/analysis/outreach.d.ts +6 -0
- package/dist/types/analysis/progress-schema.d.ts +1 -0
- package/dist/types/analysis/progress.d.ts +15 -0
- package/dist/types/analysis/qualified-competitors.d.ts +1 -0
- package/dist/types/analysis/retrieval.d.ts +22 -0
- package/dist/types/analysis/scoring.d.ts +55 -0
- package/dist/types/analysis/search-analyzer.d.ts +23 -0
- package/dist/types/analysis/sentiment.d.ts +99 -0
- package/dist/types/analysis/source-classifier.d.ts +1 -0
- package/dist/types/analysis/source-mix.d.ts +6 -0
- package/dist/types/analysis/verbatim.d.ts +1 -0
- package/dist/types/api/errors.d.ts +30 -0
- package/dist/types/author/examples.d.ts +31 -0
- package/dist/types/bundle/checks.d.ts +45 -0
- package/dist/types/bundle/contracts.d.ts +354 -0
- package/dist/types/bundle/export.d.ts +46 -0
- package/dist/types/bundle/journal.d.ts +39 -0
- package/dist/types/bundle/json.d.ts +8 -0
- package/dist/types/bundle/lineage.d.ts +13 -0
- package/dist/types/bundle/paths.d.ts +2 -0
- package/dist/types/bundle/project-journal.d.ts +31 -0
- package/dist/types/bundle/project.d.ts +30 -0
- package/dist/types/bundle/read.d.ts +9 -0
- package/dist/types/bundle/recorder.d.ts +89 -0
- package/dist/types/bundle/redact.d.ts +17 -0
- package/dist/types/bundle/trace-coverage.d.ts +36 -0
- package/dist/types/bundle/verify-integrity.d.ts +11 -0
- package/dist/types/bundle/verify-measurement.d.ts +26 -0
- package/dist/types/bundle/verify-report.d.ts +16 -0
- package/dist/types/bundle/verify.d.ts +31 -0
- package/dist/types/bundle/writer-lock.d.ts +23 -0
- package/dist/types/bundle/zip.d.ts +24 -0
- package/dist/types/capture-manifest.d.ts +122 -0
- package/dist/types/checks/crawler-access.d.ts +25 -0
- package/dist/types/checks/renderability.d.ts +4 -0
- package/dist/types/checks/run-checks.d.ts +8 -0
- package/dist/types/cli/bundle-commands.d.ts +5 -0
- package/dist/types/cli/io.d.ts +10 -0
- package/dist/types/cli/literally-aeo.d.ts +1 -0
- package/dist/types/cli/run-commands.d.ts +14 -0
- package/dist/types/codex-workflow/aggregate.d.ts +76 -0
- package/dist/types/codex-workflow/author-search.d.ts +26 -0
- package/dist/types/codex-workflow/author-tools-server.d.ts +1 -0
- package/dist/types/codex-workflow/author-tools.d.ts +145 -0
- package/dist/types/codex-workflow/author.d.ts +101 -0
- package/dist/types/codex-workflow/batch-input.d.ts +12 -0
- package/dist/types/codex-workflow/batch-layout.d.ts +16 -0
- package/dist/types/codex-workflow/capture.d.ts +37 -0
- package/dist/types/codex-workflow/checkpoint.d.ts +18 -0
- package/dist/types/codex-workflow/checks.d.ts +53 -0
- package/dist/types/codex-workflow/codex-home.d.ts +47 -0
- package/dist/types/codex-workflow/copy-editor.d.ts +164 -0
- package/dist/types/codex-workflow/copy-recovery.d.ts +30 -0
- package/dist/types/codex-workflow/copy.d.ts +62 -0
- package/dist/types/codex-workflow/finish.d.ts +53 -0
- package/dist/types/codex-workflow/host-models.d.ts +5 -0
- package/dist/types/codex-workflow/loop.d.ts +177 -0
- package/dist/types/codex-workflow/pending.d.ts +6 -0
- package/dist/types/codex-workflow/prompts.d.ts +14 -0
- package/dist/types/codex-workflow/quality.d.ts +25 -0
- package/dist/types/codex-workflow/run-inputs.d.ts +951 -0
- package/dist/types/codex-workflow/run-source.d.ts +34 -0
- package/dist/types/codex-workflow/schemas.d.ts +493 -0
- package/dist/types/codex-workflow/session.d.ts +13 -0
- package/dist/types/codex-workflow/stage.d.ts +136 -0
- package/dist/types/codex-workflow/workdir.d.ts +40 -0
- package/dist/types/configs/literally-2026-q3.d.ts +2 -0
- package/dist/types/container/protocol.d.ts +72 -0
- package/dist/types/coverage-schema.d.ts +6 -0
- package/dist/types/engine/audit-file.d.ts +126 -0
- package/dist/types/engine/author.d.ts +52 -0
- package/dist/types/engine/budget.d.ts +68 -0
- package/dist/types/engine/env-file.d.ts +13 -0
- package/dist/types/engine/local-run.d.ts +62 -0
- package/dist/types/engine/package-root.d.ts +8 -0
- package/dist/types/engine/preflight.d.ts +27 -0
- package/dist/types/engine/rejudge.d.ts +14 -0
- package/dist/types/engine/resources.d.ts +8 -0
- package/dist/types/engine/run-configuration.d.ts +36 -0
- package/dist/types/engine/templates.d.ts +38 -0
- package/dist/types/grounding/controller.d.ts +110 -0
- package/dist/types/grounding/extract.d.ts +103 -0
- package/dist/types/grounding/fetch.d.ts +53 -0
- package/dist/types/grounding/file-store.d.ts +2 -0
- package/dist/types/grounding/grounding-runtime.d.ts +43 -0
- package/dist/types/grounding/model-usage.d.ts +13 -0
- package/dist/types/grounding/model.d.ts +51 -0
- package/dist/types/grounding/profile.d.ts +15 -0
- package/dist/types/grounding/recorded-tools.d.ts +12 -0
- package/dist/types/grounding/schema.d.ts +521 -0
- package/dist/types/grounding/session.d.ts +143 -0
- package/dist/types/grounding/tools.d.ts +135 -0
- package/dist/types/grounding/validation.d.ts +35 -0
- package/dist/types/grounding.d.ts +1 -0
- package/dist/types/harness/checkpoint.d.ts +29 -0
- package/dist/types/harness/contracts.d.ts +141 -0
- package/dist/types/harness/criteria.d.ts +34 -0
- package/dist/types/harness/policy.d.ts +9 -0
- package/dist/types/harness/report/artifacts.d.ts +287 -0
- package/dist/types/harness/report/capture-coverage.d.ts +11 -0
- package/dist/types/harness/store.d.ts +116 -0
- package/dist/types/lib/analysis-checkpoint.d.ts +20 -0
- package/dist/types/lib/canonical-json.d.ts +11 -0
- package/dist/types/lib/checkpoint.d.ts +33 -0
- package/dist/types/lib/env.d.ts +31 -0
- package/dist/types/lib/log.d.ts +11 -0
- package/dist/types/lib/paths.d.ts +2 -0
- package/dist/types/lib/progress-comparison.d.ts +1 -0
- package/dist/types/lib/report-presentation.d.ts +1 -0
- package/dist/types/lib/run-id.d.ts +2 -0
- package/dist/types/lib/type-guards.d.ts +9 -0
- package/dist/types/models/accounting.d.ts +147 -0
- package/dist/types/models/batching.d.ts +17 -0
- package/dist/types/models/budget-protection.d.ts +10 -0
- package/dist/types/models/context.d.ts +8 -0
- package/dist/types/models/coverage-rounds.d.ts +47 -0
- package/dist/types/models/errors.d.ts +12 -0
- package/dist/types/models/failure-diagnostics.d.ts +8 -0
- package/dist/types/models/profiles.d.ts +551 -0
- package/dist/types/models/served-model.d.ts +11 -0
- package/dist/types/models/structured-images.d.ts +9 -0
- package/dist/types/models/structured.d.ts +111 -0
- package/dist/types/models/wire-schema.d.ts +27 -0
- package/dist/types/pipeline.d.ts +117 -0
- package/dist/types/probes/agent-cli-parsers.d.ts +46 -0
- package/dist/types/probes/agent-clis.d.ts +132 -0
- package/dist/types/probes/chat-retrieval.d.ts +14 -0
- package/dist/types/probes/child-process.d.ts +28 -0
- package/dist/types/probes/dataforseo-locale.d.ts +8 -0
- package/dist/types/probes/dataforseo.d.ts +15 -0
- package/dist/types/probes/failure.d.ts +30 -0
- package/dist/types/probes/grounding-urls.d.ts +18 -0
- package/dist/types/probes/limits.d.ts +30 -0
- package/dist/types/probes/outcomes.d.ts +20 -0
- package/dist/types/probes/probe-trace.d.ts +51 -0
- package/dist/types/probes/probes.d.ts +47 -0
- package/dist/types/probes/web-tool-guard.d.ts +59 -0
- package/dist/types/report/contracts.d.ts +973 -0
- package/dist/types/report/core/answer-text.d.ts +24 -0
- package/dist/types/report/core/copy-schema.d.ts +47 -0
- package/dist/types/report/core/domain-match.d.ts +9 -0
- package/dist/types/report/core/grounding.d.ts +4 -0
- package/dist/types/report/core/normalize-domain.d.ts +2 -0
- package/dist/types/report/core/progress-comparison.d.ts +52 -0
- package/dist/types/report/core/progress-question-sets.d.ts +16 -0
- package/dist/types/report/core/progress-schema.d.ts +101 -0
- package/dist/types/report/core/progress-slot-key.d.ts +9 -0
- package/dist/types/report/core/qualified-competitors.d.ts +6 -0
- package/dist/types/report/core/report-presentation.d.ts +10 -0
- package/dist/types/report/core/retrieval.d.ts +6 -0
- package/dist/types/report/core/schema.d.ts +745 -0
- package/dist/types/report/core/source-classifier.d.ts +21 -0
- package/dist/types/report/core/surfaces.d.ts +11 -0
- package/dist/types/retrieval.d.ts +1 -0
- package/dist/types/runner.d.ts +96 -0
- package/dist/types/schema.d.ts +858 -0
- package/dist/types/section-result.d.ts +4 -0
- package/dist/types/stores/artifacts.d.ts +2 -0
- package/dist/types/stores/content-hash.d.ts +2 -0
- package/dist/types/stores/file-publication.d.ts +31 -0
- package/dist/types/stores/files.d.ts +87 -0
- package/dist/types/stores/fs-errors.d.ts +5 -0
- package/dist/types/stores/local-versions.d.ts +54 -0
- package/dist/types/stores/memory.d.ts +76 -0
- package/dist/types/stores/ports.d.ts +150 -0
- package/dist/types/stores/publication-history.d.ts +27 -0
- package/dist/types/stores/publication.d.ts +53 -0
- package/dist/types/stores/run-lifecycle.d.ts +7 -0
- package/dist/types/stores/versions.d.ts +71 -0
- package/dist/types/surfaces.d.ts +1 -0
- package/dist/types/viewer/page.d.ts +2 -0
- package/dist/types/viewer/server.d.ts +14 -0
- package/dist/types/workflow/callbacks.d.ts +22 -0
- package/dist/types/workflow/lineage.d.ts +20 -0
- package/dist/types/workflow/schema.d.ts +1572 -0
- package/package.json +95 -3
- package/resources/author/COPY_RULES.md +95 -0
- package/resources/author/RULES.md +104 -0
- package/resources/author/banlist.json +38 -0
- package/resources/editorial/COMPANY.md +11 -0
- package/resources/editorial/positioning.md +8 -0
- package/resources/editorial/services.md +4 -0
- package/src/access/schema.ts +96 -0
- package/src/agents/author-schema.ts +49 -0
- package/src/agents/author-validation.ts +409 -0
- package/src/agents/copy-schema.ts +214 -0
- package/src/agents/copy-validation.ts +1170 -0
- package/src/agents/copywriter-input.ts +90 -0
- package/src/agents/credentials.ts +60 -0
- package/src/agents/facts.ts +343 -0
- package/src/agents/narrative-facts.ts +174 -0
- package/src/agents/verifier.ts +603 -0
- package/src/analysis/answer-text.ts +1 -0
- package/src/analysis/competitor-classifier.ts +15 -0
- package/src/analysis/domain-classifier.ts +804 -0
- package/src/analysis/domain-labels.ts +67 -0
- package/src/analysis/domain-match.ts +1 -0
- package/src/analysis/name-forms.ts +59 -0
- package/src/analysis/outreach.ts +107 -0
- package/src/analysis/progress-schema.ts +1 -0
- package/src/analysis/progress.ts +346 -0
- package/src/analysis/qualified-competitors.ts +1 -0
- package/src/analysis/retrieval.ts +105 -0
- package/src/analysis/scoring.ts +167 -0
- package/src/analysis/search-analyzer.ts +83 -0
- package/src/analysis/sentiment.ts +558 -0
- package/src/analysis/source-classifier.ts +1 -0
- package/src/analysis/source-mix.ts +56 -0
- package/src/analysis/verbatim.ts +107 -0
- package/src/api/errors.ts +50 -0
- package/src/author/COPY_RULES.md +95 -0
- package/src/author/RULES.md +104 -0
- package/src/author/banlist.json +38 -0
- package/src/author/examples.ts +79 -0
- package/src/bundle/checks.ts +146 -0
- package/src/bundle/contracts.ts +289 -0
- package/src/bundle/export.ts +448 -0
- package/src/bundle/journal.ts +270 -0
- package/src/bundle/json.ts +157 -0
- package/src/bundle/lineage.ts +45 -0
- package/src/bundle/paths.ts +36 -0
- package/src/bundle/project-journal.ts +179 -0
- package/src/bundle/project.ts +434 -0
- package/src/bundle/read.ts +154 -0
- package/src/bundle/recorder.ts +497 -0
- package/src/bundle/redact.ts +134 -0
- package/src/bundle/trace-coverage.ts +168 -0
- package/src/bundle/verify-integrity.ts +322 -0
- package/src/bundle/verify-measurement.ts +384 -0
- package/src/bundle/verify-report.ts +260 -0
- package/src/bundle/verify.ts +400 -0
- package/src/bundle/writer-lock.ts +133 -0
- package/src/bundle/zip.ts +281 -0
- package/src/capture-manifest.ts +348 -0
- package/src/checks/crawler-access.ts +373 -0
- package/src/checks/renderability.ts +164 -0
- package/src/checks/run-checks.ts +74 -0
- package/src/cli/bundle-commands.ts +249 -0
- package/src/cli/io.ts +63 -0
- package/src/cli/literally-aeo.ts +121 -0
- package/src/cli/run-commands.ts +535 -0
- package/src/codex-workflow/aggregate.ts +336 -0
- package/src/codex-workflow/author-search.ts +76 -0
- package/src/codex-workflow/author-tools-server.ts +208 -0
- package/src/codex-workflow/author-tools.ts +1202 -0
- package/src/codex-workflow/author.ts +512 -0
- package/src/codex-workflow/batch-input.ts +145 -0
- package/src/codex-workflow/batch-layout.ts +47 -0
- package/src/codex-workflow/capture.ts +255 -0
- package/src/codex-workflow/checkpoint.ts +127 -0
- package/src/codex-workflow/checks.ts +510 -0
- package/src/codex-workflow/codex-home.ts +187 -0
- package/src/codex-workflow/copy-editor.ts +322 -0
- package/src/codex-workflow/copy-recovery.ts +134 -0
- package/src/codex-workflow/copy.ts +195 -0
- package/src/codex-workflow/finish.ts +433 -0
- package/src/codex-workflow/host-models.ts +35 -0
- package/src/codex-workflow/loop.ts +1159 -0
- package/src/codex-workflow/pending.ts +24 -0
- package/src/codex-workflow/prompts.ts +153 -0
- package/src/codex-workflow/quality.ts +97 -0
- package/src/codex-workflow/run-inputs.ts +117 -0
- package/src/codex-workflow/run-source.ts +149 -0
- package/src/codex-workflow/schemas.ts +222 -0
- package/src/codex-workflow/session.ts +70 -0
- package/src/codex-workflow/stage.ts +2344 -0
- package/src/codex-workflow/workdir.ts +242 -0
- package/src/configs/literally-2026-q3.ts +199 -0
- package/src/container/protocol.ts +152 -0
- package/src/coverage-schema.ts +7 -0
- package/src/engine/audit-file.ts +254 -0
- package/src/engine/author.ts +279 -0
- package/src/engine/budget.ts +164 -0
- package/src/engine/editorial/COMPANY.md +11 -0
- package/src/engine/editorial/positioning.md +8 -0
- package/src/engine/editorial/services.md +4 -0
- package/src/engine/env-file.ts +87 -0
- package/src/engine/local-run.ts +323 -0
- package/src/engine/package-root.ts +47 -0
- package/src/engine/preflight.ts +156 -0
- package/src/engine/rejudge.ts +118 -0
- package/src/engine/resources.ts +45 -0
- package/src/engine/run-configuration.ts +70 -0
- package/src/engine/templates.ts +66 -0
- package/src/grounding/controller.ts +1211 -0
- package/src/grounding/extract.ts +830 -0
- package/src/grounding/fetch.ts +448 -0
- package/src/grounding/file-store.ts +131 -0
- package/src/grounding/grounding-runtime.ts +318 -0
- package/src/grounding/model-usage.ts +48 -0
- package/src/grounding/model.ts +508 -0
- package/src/grounding/profile.ts +63 -0
- package/src/grounding/recorded-tools.ts +40 -0
- package/src/grounding/schema.ts +262 -0
- package/src/grounding/session.ts +681 -0
- package/src/grounding/tools.ts +500 -0
- package/src/grounding/validation.ts +435 -0
- package/src/grounding.ts +1 -0
- package/src/harness/checkpoint.ts +53 -0
- package/src/harness/contracts.ts +169 -0
- package/src/harness/criteria.ts +166 -0
- package/src/harness/policy.ts +28 -0
- package/src/harness/report/artifacts.ts +130 -0
- package/src/harness/report/capture-coverage.ts +40 -0
- package/src/harness/store.ts +167 -0
- package/src/lib/analysis-checkpoint.ts +94 -0
- package/src/lib/canonical-json.ts +90 -0
- package/src/lib/checkpoint.ts +140 -0
- package/src/lib/env.ts +80 -0
- package/src/lib/log.ts +192 -0
- package/src/lib/paths.ts +14 -0
- package/src/lib/progress-comparison.ts +1 -0
- package/src/lib/report-presentation.ts +1 -0
- package/src/lib/run-id.ts +39 -0
- package/src/lib/type-guards.ts +14 -0
- package/src/models/accounting.ts +656 -0
- package/src/models/batching.ts +68 -0
- package/src/models/budget-protection.ts +68 -0
- package/src/models/context.ts +9 -0
- package/src/models/coverage-rounds.ts +125 -0
- package/src/models/errors.ts +39 -0
- package/src/models/failure-diagnostics.ts +157 -0
- package/src/models/profiles.ts +511 -0
- package/src/models/served-model.ts +20 -0
- package/src/models/structured-images.ts +95 -0
- package/src/models/structured.ts +634 -0
- package/src/models/wire-schema.ts +453 -0
- package/src/pipeline.ts +496 -0
- package/src/probes/agent-cli-parsers.ts +835 -0
- package/src/probes/agent-clis.ts +1482 -0
- package/src/probes/chat-retrieval.ts +238 -0
- package/src/probes/child-process.ts +280 -0
- package/src/probes/dataforseo-locale.ts +71 -0
- package/src/probes/dataforseo.ts +286 -0
- package/src/probes/failure.ts +182 -0
- package/src/probes/grounding-urls.ts +182 -0
- package/src/probes/limits.ts +181 -0
- package/src/probes/outcomes.ts +40 -0
- package/src/probes/probe-trace.ts +109 -0
- package/src/probes/probes.ts +789 -0
- package/src/probes/web-tool-guard.ts +195 -0
- package/src/report/contracts.ts +161 -0
- package/src/report/core/answer-text.ts +144 -0
- package/src/report/core/copy-schema.ts +75 -0
- package/src/report/core/domain-match.ts +52 -0
- package/src/report/core/grounding.ts +32 -0
- package/src/report/core/normalize-domain.ts +16 -0
- package/src/report/core/progress-comparison.ts +362 -0
- package/src/report/core/progress-question-sets.ts +93 -0
- package/src/report/core/progress-schema.ts +150 -0
- package/src/report/core/progress-slot-key.ts +20 -0
- package/src/report/core/qualified-competitors.ts +15 -0
- package/src/report/core/report-presentation.ts +112 -0
- package/src/report/core/retrieval.ts +49 -0
- package/src/report/core/schema.ts +489 -0
- package/src/report/core/source-classifier.ts +239 -0
- package/src/report/core/surfaces.ts +64 -0
- package/src/retrieval.ts +1 -0
- package/src/runner.ts +461 -0
- package/src/schema.ts +181 -0
- package/src/section-result.ts +315 -0
- package/src/stores/artifacts.ts +74 -0
- package/src/stores/content-hash.ts +8 -0
- package/src/stores/file-publication.ts +194 -0
- package/src/stores/files.ts +1069 -0
- package/src/stores/fs-errors.ts +12 -0
- package/src/stores/local-versions.ts +412 -0
- package/src/stores/memory.ts +432 -0
- package/src/stores/ports.ts +231 -0
- package/src/stores/publication-history.ts +48 -0
- package/src/stores/publication.ts +221 -0
- package/src/stores/run-lifecycle.ts +72 -0
- package/src/stores/versions.ts +113 -0
- package/src/surfaces.ts +1 -0
- package/src/viewer/page.ts +208 -0
- package/src/viewer/server.ts +215 -0
- package/src/workflow/callbacks.ts +201 -0
- package/src/workflow/lineage.ts +36 -0
- package/src/workflow/schema.ts +256 -0
|
@@ -0,0 +1,634 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { createGateway, GatewayInternalServerError } from '@ai-sdk/gateway';
|
|
3
|
+
import { Agent, fetch as undiciFetch } from 'undici';
|
|
4
|
+
import { NoObjectGeneratedError, Output, streamText } from 'ai';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { createLog } from '../lib/log';
|
|
7
|
+
import { readEnv } from '../lib/env';
|
|
8
|
+
import {
|
|
9
|
+
structuredWireSchema,
|
|
10
|
+
type StructuredSchemaIssue,
|
|
11
|
+
} from './wire-schema';
|
|
12
|
+
import { structuredFailureDiagnostic } from './failure-diagnostics';
|
|
13
|
+
import { ModelBudgetError, type ModelCallAccounting } from './accounting';
|
|
14
|
+
import { assertModelCallActive } from './errors';
|
|
15
|
+
import {
|
|
16
|
+
structuredImageMessages,
|
|
17
|
+
structuredImageTokens,
|
|
18
|
+
type StructuredImage,
|
|
19
|
+
} from './structured-images';
|
|
20
|
+
import {
|
|
21
|
+
internalModelRoleSchema,
|
|
22
|
+
internalModelRoleDigest,
|
|
23
|
+
type InternalModelRoleConfig,
|
|
24
|
+
} from './profiles';
|
|
25
|
+
import { servedModelOf } from './served-model';
|
|
26
|
+
|
|
27
|
+
export type StructuredCallUsage = {
|
|
28
|
+
callId: string;
|
|
29
|
+
requestedModel: string;
|
|
30
|
+
resolvedModel?: string;
|
|
31
|
+
reasoningEffort?: string;
|
|
32
|
+
durationMs: number;
|
|
33
|
+
inputTokens?: number;
|
|
34
|
+
outputTokens?: number;
|
|
35
|
+
cachedInputTokens?: number;
|
|
36
|
+
reasoningTokens?: number;
|
|
37
|
+
costUsd?: number;
|
|
38
|
+
requestId?: string;
|
|
39
|
+
finishReason?: string;
|
|
40
|
+
/** False when the provider billed the call without a usable answer. */
|
|
41
|
+
valid?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** The bounded provider response, retained durably before application
|
|
44
|
+
* parsing or settlement (orchestrator spec §4.4). A parse failure or a lost
|
|
45
|
+
* process after this point replays from the observation, never regenerates. */
|
|
46
|
+
export type StructuredCallObservation = {
|
|
47
|
+
callId: string;
|
|
48
|
+
/** The provider's structured payload when it produced one. */
|
|
49
|
+
payload: unknown;
|
|
50
|
+
/** The raw response text when the transport exposes it. */
|
|
51
|
+
text: string | null;
|
|
52
|
+
valid: boolean;
|
|
53
|
+
usage: StructuredCallUsage;
|
|
54
|
+
};
|
|
55
|
+
export type StructuredCallJournal = {
|
|
56
|
+
observe(observation: StructuredCallObservation): Promise<void>;
|
|
57
|
+
};
|
|
58
|
+
type ReportedUsage = Omit<
|
|
59
|
+
StructuredCallUsage,
|
|
60
|
+
'callId' | 'requestedModel' | 'reasoningEffort' | 'durationMs'
|
|
61
|
+
>;
|
|
62
|
+
|
|
63
|
+
type StructuredOutputMiss = {
|
|
64
|
+
text: string | null;
|
|
65
|
+
usage: ReportedUsage;
|
|
66
|
+
/** Why it was refused, so a caller can ask for a repair. */
|
|
67
|
+
issues: readonly StructuredSchemaIssue[];
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* StructuredOutputMissingError means the provider answered and billed, but
|
|
72
|
+
* produced no value matching the response schema. The retained text and
|
|
73
|
+
* reported usage travel with the error so the attempt is journaled and settled
|
|
74
|
+
* instead of being lost.
|
|
75
|
+
*/
|
|
76
|
+
export class StructuredOutputMissingError extends Error {
|
|
77
|
+
readonly text: string | null;
|
|
78
|
+
readonly usage: ReportedUsage;
|
|
79
|
+
readonly issues: readonly StructuredSchemaIssue[];
|
|
80
|
+
|
|
81
|
+
constructor(
|
|
82
|
+
{ text, usage, issues }: StructuredOutputMiss,
|
|
83
|
+
{ cause }: { cause: unknown },
|
|
84
|
+
) {
|
|
85
|
+
super('Model produced no value matching the response schema', { cause });
|
|
86
|
+
|
|
87
|
+
this.text = text;
|
|
88
|
+
this.usage = usage;
|
|
89
|
+
this.issues = issues;
|
|
90
|
+
this.name = 'StructuredOutputMissingError';
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* StructuredJournalError means a response was received but could not be
|
|
96
|
+
* journaled. The retained bytes travel with the error so the caller retries
|
|
97
|
+
* persistence, not generation.
|
|
98
|
+
*/
|
|
99
|
+
export class StructuredJournalError extends Error {
|
|
100
|
+
readonly observation: StructuredCallObservation;
|
|
101
|
+
|
|
102
|
+
constructor(observation: StructuredCallObservation, cause: unknown) {
|
|
103
|
+
super('Model response could not be journaled', { cause });
|
|
104
|
+
|
|
105
|
+
this.observation = observation;
|
|
106
|
+
this.name = 'StructuredJournalError';
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type StructuredCallInput<T> = {
|
|
111
|
+
roleName: string;
|
|
112
|
+
role: InternalModelRoleConfig;
|
|
113
|
+
schema: z.ZodType<T>;
|
|
114
|
+
prompt: string;
|
|
115
|
+
images?: readonly StructuredImage[];
|
|
116
|
+
system?: string;
|
|
117
|
+
signal?: AbortSignal;
|
|
118
|
+
accounting: ModelCallAccounting;
|
|
119
|
+
/** Host-issued durable call ID; legacy callers get a fresh UUID. */
|
|
120
|
+
callId?: string;
|
|
121
|
+
journal?: StructuredCallJournal;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** Injection is a single no-tools network step, never an opaque agent loop. */
|
|
125
|
+
export type StructuredTransport = {
|
|
126
|
+
<T>(
|
|
127
|
+
input: Omit<StructuredCallInput<T>, 'accounting' | 'journal'> & {
|
|
128
|
+
signal: AbortSignal;
|
|
129
|
+
},
|
|
130
|
+
): Promise<{
|
|
131
|
+
output: T;
|
|
132
|
+
text?: string;
|
|
133
|
+
usage: ReportedUsage;
|
|
134
|
+
}>;
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
const reportedNumber = (value: unknown): number | undefined => {
|
|
138
|
+
const number =
|
|
139
|
+
typeof value === 'string' && value.trim() ? Number(value) : value;
|
|
140
|
+
|
|
141
|
+
return typeof number === 'number' && Number.isFinite(number) && number >= 0
|
|
142
|
+
? number
|
|
143
|
+
: undefined;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const isGatewayCreditRefusal = (error: unknown): boolean => {
|
|
147
|
+
// Gateway requires a positive balance before routing even BYOK requests:
|
|
148
|
+
// https://vercel.com/docs/ai-gateway/authentication-and-byok/byok
|
|
149
|
+
// Only its explicit credit precheck proves zero usage. Other 402 responses,
|
|
150
|
+
// provider errors and timeouts can have unknown spend and stay reserved.
|
|
151
|
+
return (
|
|
152
|
+
GatewayInternalServerError.isInstance(error) &&
|
|
153
|
+
error.statusCode === 402 &&
|
|
154
|
+
error.message.startsWith(
|
|
155
|
+
'A positive credit balance is required for all requests, including BYOK, so fallback providers remain available. Add credits at https://vercel.com/',
|
|
156
|
+
)
|
|
157
|
+
);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
// Two ceilings sit above every model call, and neither is the role deadline.
|
|
161
|
+
// Node's HTTP client abandons a request after five minutes by default, and
|
|
162
|
+
// the gateway abandons a NON-STREAMING request at 340 seconds (measured five
|
|
163
|
+
// times on 2026-09-11, always within 16ms, across three roles; a streaming
|
|
164
|
+
// request runs several times longer). So the transport streams, and its own
|
|
165
|
+
// client timeout is set above the largest role deadline. Every call already
|
|
166
|
+
// carries an AbortSignal built from that deadline and the remaining budget,
|
|
167
|
+
// so the transport never becomes the thing that decides when to give up.
|
|
168
|
+
const transportTimeoutMs = 960_000;
|
|
169
|
+
|
|
170
|
+
const dispatcher = new Agent({
|
|
171
|
+
headersTimeout: transportTimeoutMs,
|
|
172
|
+
bodyTimeout: transportTimeoutMs,
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
// Undici's fetch accepts the dispatcher; the global one does not expose it.
|
|
176
|
+
const fetchWithDispatcher = (
|
|
177
|
+
request: string | URL,
|
|
178
|
+
init?: Parameters<typeof undiciFetch>[1],
|
|
179
|
+
) => {
|
|
180
|
+
return undiciFetch(request, { ...init, dispatcher });
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const gateway = createGateway({
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Undici's fetch types differ from the DOM fetch type the SDK declares, though both are compatible at runtime.
|
|
185
|
+
fetch: fetchWithDispatcher as unknown as typeof globalThis.fetch,
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* dispatchProviderOptions returns the provider options a call dispatches with.
|
|
190
|
+
* A pinned profile names the gateway routes a family may use (`gateway.only`);
|
|
191
|
+
* `AEO_GATEWAY_ROUTE_DENYLIST` (comma-separated route names) removes routes from
|
|
192
|
+
* that list at call time without touching the pin, because route health is
|
|
193
|
+
* operational, not part of what was admitted. Measured 2026-09-12: DeepInfra
|
|
194
|
+
* passed a one-object probe and then refused the evidence reviewer's request
|
|
195
|
+
* with no output, three times, on an execution whose pin already named it. A
|
|
196
|
+
* denylist that would empty the allowlist is ignored rather than dispatching
|
|
197
|
+
* with none.
|
|
198
|
+
*/
|
|
199
|
+
export const dispatchProviderOptions = (
|
|
200
|
+
providerOptions: InternalModelRoleConfig['providerOptions'],
|
|
201
|
+
denylist = readEnv('AEO_GATEWAY_ROUTE_DENYLIST') ?? '',
|
|
202
|
+
): InternalModelRoleConfig['providerOptions'] => {
|
|
203
|
+
const denied = denylist
|
|
204
|
+
.split(',')
|
|
205
|
+
.map((route) => route.trim())
|
|
206
|
+
.filter(Boolean);
|
|
207
|
+
const gatewayOptions = providerOptions.gateway;
|
|
208
|
+
const only = gatewayOptions?.only;
|
|
209
|
+
|
|
210
|
+
if (denied.length === 0 || !gatewayOptions || !only) {
|
|
211
|
+
return providerOptions;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const allowed = only.filter((route) => !denied.includes(route));
|
|
215
|
+
|
|
216
|
+
if (allowed.length === 0 || allowed.length === only.length) {
|
|
217
|
+
return providerOptions;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return { ...providerOptions, gateway: { ...gatewayOptions, only: allowed } };
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const gatewayTransport: StructuredTransport = async (input) => {
|
|
224
|
+
const wire = structuredWireSchema(input.schema);
|
|
225
|
+
// A streamed request reports a provider failure as an error part, not a
|
|
226
|
+
// thrown error: without an `onError` the SDK's default prints it with
|
|
227
|
+
// `console.error`, which serialises an APICallError's own properties —
|
|
228
|
+
// including `requestBodyValues`, the entire prompt. It then synthesises a
|
|
229
|
+
// causeless NoOutputGeneratedError, so the caller cannot tell a 402 from a
|
|
230
|
+
// schema miss. Capturing it keeps the prompt out of stderr and restores
|
|
231
|
+
// the error identity every classifier downstream is written against.
|
|
232
|
+
let streamFailure: unknown;
|
|
233
|
+
const result = streamText({
|
|
234
|
+
onError: ({ error }) => {
|
|
235
|
+
streamFailure ??= error;
|
|
236
|
+
},
|
|
237
|
+
model: gateway(input.role.model),
|
|
238
|
+
output: Output.object({ schema: wire.sdkSchema }),
|
|
239
|
+
providerOptions: dispatchProviderOptions(input.role.providerOptions),
|
|
240
|
+
maxOutputTokens: input.role.maxOutputTokens,
|
|
241
|
+
maxRetries: 0,
|
|
242
|
+
abortSignal: input.signal,
|
|
243
|
+
system: [
|
|
244
|
+
input.system,
|
|
245
|
+
wire.wrapped
|
|
246
|
+
? 'Return the requested result inside the top-level result property required by the response schema.'
|
|
247
|
+
: undefined,
|
|
248
|
+
]
|
|
249
|
+
.filter(Boolean)
|
|
250
|
+
.join('\n'),
|
|
251
|
+
...(input.images?.length
|
|
252
|
+
? { messages: structuredImageMessages(input.prompt, input.images) }
|
|
253
|
+
: { prompt: input.prompt }),
|
|
254
|
+
});
|
|
255
|
+
// Drain the stream once and read the reported usage before the output: the
|
|
256
|
+
// output accessor rejects when nothing matched the schema, and that
|
|
257
|
+
// generation was still billed. Every accessor resolves from this one pass.
|
|
258
|
+
let drained: [
|
|
259
|
+
Awaited<typeof result.usage>,
|
|
260
|
+
Awaited<typeof result.response>,
|
|
261
|
+
Awaited<typeof result.finishReason>,
|
|
262
|
+
Awaited<typeof result.providerMetadata>,
|
|
263
|
+
string,
|
|
264
|
+
Awaited<typeof result.toolCalls>,
|
|
265
|
+
];
|
|
266
|
+
|
|
267
|
+
try {
|
|
268
|
+
drained = await Promise.all([
|
|
269
|
+
result.usage,
|
|
270
|
+
result.response,
|
|
271
|
+
result.finishReason,
|
|
272
|
+
result.providerMetadata,
|
|
273
|
+
result.text,
|
|
274
|
+
result.toolCalls,
|
|
275
|
+
]);
|
|
276
|
+
} catch (error) {
|
|
277
|
+
// The provider's own error, not the SDK's stand-in for "no steps".
|
|
278
|
+
throw streamFailure ?? error;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
const [
|
|
282
|
+
reported,
|
|
283
|
+
response,
|
|
284
|
+
finishReason,
|
|
285
|
+
providerMetadata,
|
|
286
|
+
answered,
|
|
287
|
+
toolCalls,
|
|
288
|
+
] = drained;
|
|
289
|
+
// An answer given as a tool call has no text; the call itself is what was
|
|
290
|
+
// said, and it is retained so a schema miss of that shape can be read
|
|
291
|
+
// (Opus 5 through the gateway, repair planner, 2026-09-12).
|
|
292
|
+
const text =
|
|
293
|
+
answered === '' && toolCalls.length > 0
|
|
294
|
+
? JSON.stringify(
|
|
295
|
+
toolCalls.map((call) => {
|
|
296
|
+
const callInput: unknown = call.input;
|
|
297
|
+
|
|
298
|
+
return { tool: call.toolName, input: callInput };
|
|
299
|
+
}),
|
|
300
|
+
)
|
|
301
|
+
: answered;
|
|
302
|
+
const usage = {
|
|
303
|
+
resolvedModel: servedModelOf(input.role.model, response.modelId),
|
|
304
|
+
requestId: response.id,
|
|
305
|
+
finishReason,
|
|
306
|
+
inputTokens: reported.inputTokens,
|
|
307
|
+
outputTokens: reported.outputTokens,
|
|
308
|
+
cachedInputTokens: reported.inputTokenDetails.cacheReadTokens,
|
|
309
|
+
reasoningTokens: reported.outputTokenDetails.reasoningTokens,
|
|
310
|
+
costUsd: reportedNumber(providerMetadata?.gateway?.cost),
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
try {
|
|
314
|
+
return { output: await result.output, text, usage };
|
|
315
|
+
} catch (error) {
|
|
316
|
+
// Streaming reports "answered but matched no schema" as a rejected
|
|
317
|
+
// output promise carrying NoObjectGeneratedError. Catching the wrong
|
|
318
|
+
// class here dropped the billed cost, the refusal reason, and the copy
|
|
319
|
+
// writer's repair loop, because the retained text never reached it.
|
|
320
|
+
if (!NoObjectGeneratedError.isInstance(error)) {
|
|
321
|
+
throw streamFailure ?? error;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
// A lone native tool call naming one of the schema's own actions is that
|
|
325
|
+
// action: Opus 5 through the gateway answered a planner turn with
|
|
326
|
+
// `inspect_dependencies({nodeKey})` instead of the JSON envelope, three
|
|
327
|
+
// times in a row (2026-09-13). The schema still decides: a call it does
|
|
328
|
+
// not admit fails below exactly as before.
|
|
329
|
+
const [toolCall] = toolCalls;
|
|
330
|
+
|
|
331
|
+
if (answered === '' && toolCalls.length === 1 && toolCall) {
|
|
332
|
+
const callInput: unknown = toolCall.input;
|
|
333
|
+
|
|
334
|
+
for (const action of [`tool:${toolCall.toolName}`, toolCall.toolName]) {
|
|
335
|
+
const candidate = { action, input: callInput };
|
|
336
|
+
|
|
337
|
+
try {
|
|
338
|
+
return {
|
|
339
|
+
output: wire.decode(
|
|
340
|
+
wire.wrapped ? { result: candidate } : candidate,
|
|
341
|
+
),
|
|
342
|
+
text,
|
|
343
|
+
usage,
|
|
344
|
+
};
|
|
345
|
+
} catch {
|
|
346
|
+
// Not this shape; try the next, then report the miss.
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// The locally read usage carries the cost; the SDK's own copy on the
|
|
352
|
+
// error does not, and dropping it left the reservation charged at its
|
|
353
|
+
// estimate for the rest of the run.
|
|
354
|
+
throw new StructuredOutputMissingError(
|
|
355
|
+
{ text, usage, issues: wire.lastFailure() },
|
|
356
|
+
{ cause: error },
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
export const structuredCallReservation = <T>(
|
|
362
|
+
input: Pick<
|
|
363
|
+
StructuredCallInput<T>,
|
|
364
|
+
'role' | 'schema' | 'system' | 'prompt' | 'images'
|
|
365
|
+
>,
|
|
366
|
+
) => {
|
|
367
|
+
const role = internalModelRoleSchema.parse(input.role);
|
|
368
|
+
const imageTokens = structuredImageTokens(input.images, role.model);
|
|
369
|
+
// UTF-8 bytes bound text token count conservatively; include the JSON schema
|
|
370
|
+
// and framing overhead. Keeping this below 100k avoids long-context tiers.
|
|
371
|
+
const inputTokens =
|
|
372
|
+
Buffer.byteLength(
|
|
373
|
+
JSON.stringify({
|
|
374
|
+
system: input.system,
|
|
375
|
+
prompt: input.prompt,
|
|
376
|
+
schema: structuredWireSchema(input.schema).wire,
|
|
377
|
+
...(input.images?.length
|
|
378
|
+
? { imageIds: input.images.map(({ id }) => id) }
|
|
379
|
+
: {}),
|
|
380
|
+
}),
|
|
381
|
+
) +
|
|
382
|
+
2048 +
|
|
383
|
+
imageTokens;
|
|
384
|
+
|
|
385
|
+
if (inputTokens > role.maxInputTokens) {
|
|
386
|
+
throw new Error('model_input_limit');
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
return {
|
|
390
|
+
inputTokens,
|
|
391
|
+
maxOutputTokens: role.maxOutputTokens,
|
|
392
|
+
// Cache creation can cost more than uncached input; reserve that ceiling.
|
|
393
|
+
reservedUsd:
|
|
394
|
+
(inputTokens * role.pricingUsdPerMillion.input * 1.25 +
|
|
395
|
+
role.maxOutputTokens * role.pricingUsdPerMillion.output) /
|
|
396
|
+
1_000_000,
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* billedInvalidAnswer reads the two shapes of "the provider answered, billed,
|
|
402
|
+
* and nothing matched the schema": the SDK's own NoObjectGeneratedError from a
|
|
403
|
+
* non-streaming transport, and the streaming transport's
|
|
404
|
+
* StructuredOutputMissingError, which carries the usage it read itself. Either
|
|
405
|
+
* way the retained text and the reported usage are journaled and settled
|
|
406
|
+
* before the error travels on.
|
|
407
|
+
*/
|
|
408
|
+
const billedInvalidAnswer = (
|
|
409
|
+
error: unknown,
|
|
410
|
+
requestedModel: string,
|
|
411
|
+
): { text: string | null; usage: ReportedUsage } | null => {
|
|
412
|
+
if (NoObjectGeneratedError.isInstance(error)) {
|
|
413
|
+
return {
|
|
414
|
+
text: typeof error.text === 'string' ? error.text : null,
|
|
415
|
+
usage: {
|
|
416
|
+
resolvedModel: servedModelOf(requestedModel, error.response?.modelId),
|
|
417
|
+
requestId: error.response?.id,
|
|
418
|
+
finishReason: error.finishReason,
|
|
419
|
+
inputTokens: error.usage?.inputTokens,
|
|
420
|
+
outputTokens: error.usage?.outputTokens,
|
|
421
|
+
cachedInputTokens: error.usage?.inputTokenDetails.cacheReadTokens,
|
|
422
|
+
reasoningTokens: error.usage?.outputTokenDetails.reasoningTokens,
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (error instanceof StructuredOutputMissingError) {
|
|
428
|
+
return { text: error.text, usage: error.usage };
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return null;
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const journal = async (
|
|
435
|
+
sink: StructuredCallJournal | undefined,
|
|
436
|
+
observation: StructuredCallObservation,
|
|
437
|
+
): Promise<void> => {
|
|
438
|
+
if (!sink) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
try {
|
|
443
|
+
await sink.observe(observation);
|
|
444
|
+
} catch (error) {
|
|
445
|
+
throw new StructuredJournalError(observation, error);
|
|
446
|
+
}
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
/** The output schema as the provider receives it, for the run journal;
|
|
450
|
+
* null for a schema JSON Schema cannot express (a custom refinement). */
|
|
451
|
+
const outputJsonSchema = (schema: z.ZodType): unknown => {
|
|
452
|
+
try {
|
|
453
|
+
return z.toJSONSchema(schema);
|
|
454
|
+
} catch {
|
|
455
|
+
// The schema still validates the answer; only its description is lost.
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
export const generateStructured = async <T>(
|
|
461
|
+
input: StructuredCallInput<T>,
|
|
462
|
+
transport: StructuredTransport = gatewayTransport,
|
|
463
|
+
): Promise<{ output: T; usage: StructuredCallUsage }> => {
|
|
464
|
+
input.signal?.throwIfAborted();
|
|
465
|
+
const reservation = structuredCallReservation(input);
|
|
466
|
+
const callId = input.callId ?? randomUUID();
|
|
467
|
+
// Observed before the reservation, which a recording accounting turns into
|
|
468
|
+
// the operation's start: the request is durable before it is dispatched.
|
|
469
|
+
await input.accounting.observe?.(callId, {
|
|
470
|
+
kind: 'request',
|
|
471
|
+
system: input.system ?? null,
|
|
472
|
+
prompt: input.prompt,
|
|
473
|
+
schema: outputJsonSchema(input.schema),
|
|
474
|
+
role: input.role,
|
|
475
|
+
images: input.images ?? [],
|
|
476
|
+
});
|
|
477
|
+
await input.accounting.reserve({
|
|
478
|
+
callId,
|
|
479
|
+
role: input.roleName,
|
|
480
|
+
requestedModel: input.role.model,
|
|
481
|
+
reasoningEffort: input.role.providerOptions.openai?.reasoningEffort,
|
|
482
|
+
profileDigest: internalModelRoleDigest(input.role),
|
|
483
|
+
...reservation,
|
|
484
|
+
});
|
|
485
|
+
await input.accounting.assertOwned();
|
|
486
|
+
const remainingMs = input.accounting.deadlineAt
|
|
487
|
+
? Date.parse(input.accounting.deadlineAt) - Date.now()
|
|
488
|
+
: input.role.deadlineMs;
|
|
489
|
+
|
|
490
|
+
if (!Number.isFinite(remainingMs) || remainingMs <= 0) {
|
|
491
|
+
throw new ModelBudgetError('Model budget deadline reached before dispatch');
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const signal = AbortSignal.any([
|
|
495
|
+
...(input.signal ? [input.signal] : []),
|
|
496
|
+
AbortSignal.timeout(Math.min(input.role.deadlineMs, remainingMs)),
|
|
497
|
+
]);
|
|
498
|
+
assertModelCallActive(signal);
|
|
499
|
+
const start = Date.now();
|
|
500
|
+
const log = createLog('InternalModel');
|
|
501
|
+
const heartbeat = setInterval(
|
|
502
|
+
() =>
|
|
503
|
+
log.info('Model request in progress', {
|
|
504
|
+
callId,
|
|
505
|
+
role: input.roleName,
|
|
506
|
+
model: input.role.model,
|
|
507
|
+
elapsedMs: Date.now() - start,
|
|
508
|
+
}),
|
|
509
|
+
30_000,
|
|
510
|
+
);
|
|
511
|
+
heartbeat.unref();
|
|
512
|
+
// Unknown failures retain their reservation: a timeout does not prove that
|
|
513
|
+
// the provider did no billable work. The caller owns any repair attempt.
|
|
514
|
+
let result: Awaited<ReturnType<StructuredTransport>>;
|
|
515
|
+
|
|
516
|
+
try {
|
|
517
|
+
result = await transport({ ...input, signal });
|
|
518
|
+
} catch (error) {
|
|
519
|
+
log.warn('Model request failed', {
|
|
520
|
+
callId,
|
|
521
|
+
role: input.roleName,
|
|
522
|
+
model: input.role.model,
|
|
523
|
+
durationMs: Date.now() - start,
|
|
524
|
+
...structuredFailureDiagnostic(error, signal),
|
|
525
|
+
// Which upstream route answered, and how it ended: a route that
|
|
526
|
+
// rejects a request looks identical to a schema miss without this.
|
|
527
|
+
...(error instanceof StructuredOutputMissingError
|
|
528
|
+
? {
|
|
529
|
+
resolvedModel: error.usage.resolvedModel,
|
|
530
|
+
finishReason: error.usage.finishReason,
|
|
531
|
+
outputTokens: error.usage.outputTokens,
|
|
532
|
+
// What was said and why it was refused, when the operator asked
|
|
533
|
+
// for it: a schema miss with neither is undiagnosable from a log.
|
|
534
|
+
...(readEnv('AEO_HARNESS_DEBUG_ERRORS') === '1'
|
|
535
|
+
? {
|
|
536
|
+
issues: error.issues.slice(0, 3),
|
|
537
|
+
text: error.text?.slice(0, 600) ?? null,
|
|
538
|
+
}
|
|
539
|
+
: {}),
|
|
540
|
+
}
|
|
541
|
+
: {}),
|
|
542
|
+
});
|
|
543
|
+
|
|
544
|
+
if (isGatewayCreditRefusal(error)) {
|
|
545
|
+
await input.accounting.assertOwned();
|
|
546
|
+
assertModelCallActive(signal, error);
|
|
547
|
+
await input.accounting.settle(callId, {
|
|
548
|
+
requestedModel: input.role.model,
|
|
549
|
+
reasoningEffort: input.role.providerOptions.openai?.reasoningEffort,
|
|
550
|
+
durationMs: Date.now() - start,
|
|
551
|
+
costUsd: 0,
|
|
552
|
+
inputTokens: 0,
|
|
553
|
+
outputTokens: 0,
|
|
554
|
+
finishReason: 'gateway_credit_refused',
|
|
555
|
+
valid: false,
|
|
556
|
+
});
|
|
557
|
+
} else {
|
|
558
|
+
const billed = billedInvalidAnswer(error, input.role.model);
|
|
559
|
+
|
|
560
|
+
if (billed) {
|
|
561
|
+
await input.accounting.assertOwned();
|
|
562
|
+
const invalidUsage: StructuredCallUsage = {
|
|
563
|
+
...billed.usage,
|
|
564
|
+
callId,
|
|
565
|
+
requestedModel: input.role.model,
|
|
566
|
+
reasoningEffort: input.role.providerOptions.openai?.reasoningEffort,
|
|
567
|
+
durationMs: Date.now() - start,
|
|
568
|
+
valid: false,
|
|
569
|
+
};
|
|
570
|
+
// The provider answered and billed; retain that answer before
|
|
571
|
+
// settling.
|
|
572
|
+
await journal(input.journal, {
|
|
573
|
+
callId,
|
|
574
|
+
payload: null,
|
|
575
|
+
text: billed.text,
|
|
576
|
+
valid: false,
|
|
577
|
+
usage: invalidUsage,
|
|
578
|
+
});
|
|
579
|
+
await input.accounting.observe?.(callId, {
|
|
580
|
+
kind: 'response',
|
|
581
|
+
payload: null,
|
|
582
|
+
text: billed.text,
|
|
583
|
+
valid: false,
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
const { callId: _invalidCallId, ...recordedInvalidUsage } =
|
|
587
|
+
invalidUsage;
|
|
588
|
+
await input.accounting.settle(callId, recordedInvalidUsage);
|
|
589
|
+
|
|
590
|
+
if (invalidUsage.finishReason === 'length') {
|
|
591
|
+
// eslint-disable-next-line preserve-caught-error -- The output-limit code must classify on its own; a cause would change its failure diagnostic.
|
|
592
|
+
throw new Error('model_output_limit');
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
assertModelCallActive(signal, error);
|
|
598
|
+
throw error;
|
|
599
|
+
} finally {
|
|
600
|
+
clearInterval(heartbeat);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
await input.accounting.assertOwned();
|
|
604
|
+
assertModelCallActive(signal);
|
|
605
|
+
const usage: StructuredCallUsage = {
|
|
606
|
+
...result.usage,
|
|
607
|
+
callId,
|
|
608
|
+
requestedModel: input.role.model,
|
|
609
|
+
reasoningEffort: input.role.providerOptions.openai?.reasoningEffort,
|
|
610
|
+
durationMs: Date.now() - start,
|
|
611
|
+
};
|
|
612
|
+
await journal(input.journal, {
|
|
613
|
+
callId,
|
|
614
|
+
payload: result.output,
|
|
615
|
+
text: result.text ?? null,
|
|
616
|
+
valid: true,
|
|
617
|
+
usage,
|
|
618
|
+
});
|
|
619
|
+
await input.accounting.observe?.(callId, {
|
|
620
|
+
kind: 'response',
|
|
621
|
+
payload: result.output,
|
|
622
|
+
text: result.text ?? null,
|
|
623
|
+
valid: true,
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
const { callId: _callId, ...recordedUsage } = usage;
|
|
627
|
+
await input.accounting.settle(callId, recordedUsage);
|
|
628
|
+
|
|
629
|
+
if (usage.finishReason === 'length') {
|
|
630
|
+
throw new Error('model_output_limit');
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
return { output: input.schema.parse(result.output), usage };
|
|
634
|
+
};
|