literally-aeo 0.2.0 → 0.2.1
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/README.md +29 -1
- package/dist/author-tools.js +479 -397
- package/dist/cli.mjs +777 -382
- package/dist/lib/access/schema.js +6 -6
- package/dist/lib/agents/author-schema.js +10 -10
- package/dist/lib/agents/author-validation.js +18 -18
- package/dist/lib/agents/copy-validation.js +22 -21
- package/dist/lib/agents/copywriter-input.js +22 -7
- package/dist/lib/agents/facts.js +21 -6
- package/dist/lib/agents/narrative-facts.js +20 -2
- package/dist/lib/agents/verifier.js +25 -24
- package/dist/lib/analysis/domain-classifier.js +19 -20
- package/dist/lib/analysis/domain-labels.js +10 -10
- package/dist/lib/analysis/progress-schema.js +2 -2
- package/dist/lib/analysis/progress.js +18 -19
- package/dist/lib/analysis/retrieval.js +20 -3
- package/dist/lib/analysis/scoring.js +20 -3
- package/dist/lib/analysis/search-analyzer.js +19 -5
- package/dist/lib/analysis/sentiment.js +16 -17
- package/dist/lib/author/examples.js +11 -11
- package/dist/lib/bundle/contracts.js +14 -12
- package/dist/lib/bundle/export.js +27 -27
- package/dist/lib/bundle/isolation.js +2 -2
- package/dist/lib/bundle/journal.js +13 -13
- package/dist/lib/bundle/project-journal.js +17 -17
- package/dist/lib/bundle/project.js +25 -25
- package/dist/lib/bundle/read.js +28 -28
- package/dist/lib/bundle/recorder.js +15 -15
- package/dist/lib/bundle/redact.js +13 -13
- package/dist/lib/bundle/trace-coverage.js +13 -13
- package/dist/lib/bundle/verify-integrity.js +15 -15
- package/dist/lib/bundle/verify-measurement.js +21 -21
- package/dist/lib/bundle/verify-report.js +29 -29
- package/dist/lib/bundle/verify.js +37 -37
- package/dist/lib/capture-manifest.js +12 -12
- package/dist/lib/checks/crawler-access.js +4 -1
- package/dist/lib/checks/renderability.js +5 -1
- package/dist/lib/checks/run-checks.js +21 -18
- package/dist/lib/chunks/{chunk-BSRKN6FU.js → chunk-2FOKEIIN.js} +1 -1
- package/dist/lib/chunks/{chunk-JXMDOAKA.js → chunk-2KH7LNK7.js} +11 -11
- package/dist/lib/chunks/{chunk-HFRAHG5C.js → chunk-3GPUCXVA.js} +14 -14
- package/dist/lib/chunks/{chunk-TJQ5OPLQ.js → chunk-3OE4UQIB.js} +7 -7
- package/dist/lib/chunks/{chunk-FOCJ7HPC.js → chunk-3OWJBGQE.js} +11 -11
- package/dist/lib/chunks/{chunk-Y4OGZ3Q5.js → chunk-46PVVQYR.js} +1 -1
- package/dist/lib/chunks/{chunk-EV4DRS5M.js → chunk-4XIAXX7K.js} +1 -1
- package/dist/lib/chunks/{chunk-IBOWGKN7.js → chunk-52F5XYOW.js} +1 -1
- package/dist/lib/chunks/{chunk-OQU5IXAJ.js → chunk-66DVMLGR.js} +10 -10
- package/dist/lib/chunks/{chunk-FFOVLI3U.js → chunk-66T7JC57.js} +12 -10
- package/dist/lib/chunks/{chunk-IE7NAL6B.js → chunk-6HMHXSCS.js} +2 -2
- package/dist/lib/chunks/{chunk-7Z27HQWL.js → chunk-6JICXLDA.js} +3 -3
- package/dist/lib/chunks/chunk-75DMLOQ7.js +127 -0
- package/dist/lib/chunks/{chunk-6G25V4CF.js → chunk-7CW6U5WJ.js} +1 -1
- package/dist/lib/chunks/{chunk-622NMXN6.js → chunk-7HM6IZ3L.js} +2 -2
- package/dist/lib/chunks/{chunk-XR44YSHT.js → chunk-7LBSNDRR.js} +10 -8
- package/dist/lib/chunks/{chunk-F4W5YHDZ.js → chunk-7WO3FFPS.js} +2 -2
- package/dist/lib/chunks/{chunk-ULRXHSJL.js → chunk-7YDXD4MD.js} +9 -6
- package/dist/lib/chunks/{chunk-NGHAP2P5.js → chunk-AAFHXNLU.js} +4 -4
- package/dist/lib/chunks/{chunk-OBXAHX3L.js → chunk-AASWJR7Q.js} +1 -5
- package/dist/lib/chunks/{chunk-VPZQGND4.js → chunk-AJKV46SM.js} +3 -3
- package/dist/lib/chunks/{chunk-NCXSNHXX.js → chunk-AJO7XVXK.js} +12 -12
- package/dist/lib/chunks/{chunk-5JPYM4MD.js → chunk-AK6YNTCV.js} +1 -1
- package/dist/lib/chunks/{chunk-MNWO7EHC.js → chunk-BFWK3TBN.js} +2 -2
- package/dist/lib/chunks/{chunk-BGOIPHJZ.js → chunk-BGAHZIL3.js} +18 -12
- package/dist/lib/chunks/{chunk-ZCOI3HE2.js → chunk-BRENK356.js} +1 -1
- package/dist/lib/chunks/{chunk-KJMU5KH4.js → chunk-BXF4OC74.js} +18 -9
- package/dist/lib/chunks/{chunk-NCLFZOZU.js → chunk-CH7OCYDL.js} +1 -1
- package/dist/lib/chunks/{chunk-FUAUPNRO.js → chunk-DDS4G4DO.js} +7 -7
- package/dist/lib/chunks/{chunk-OKL7GN2F.js → chunk-DL6YQDTE.js} +31 -5
- package/dist/lib/chunks/{chunk-PDS5KWO3.js → chunk-E2YTTB6Q.js} +56 -42
- package/dist/lib/chunks/{chunk-UEMZYHYJ.js → chunk-E3OGPTUY.js} +1 -1
- package/dist/lib/chunks/{chunk-SDWYZM64.js → chunk-EDQTINTL.js} +5 -1
- package/dist/lib/chunks/chunk-ESEMYWUH.js +257 -0
- package/dist/lib/chunks/{chunk-YHS5IEVZ.js → chunk-F2NSJ6PG.js} +12 -8
- package/dist/lib/chunks/{chunk-BLKLPUYR.js → chunk-F7DBTXKG.js} +6 -6
- package/dist/lib/chunks/{chunk-EE26FNSY.js → chunk-FDM2YNQL.js} +1 -1
- package/dist/lib/chunks/{chunk-GESHTTSA.js → chunk-FIC7JSR4.js} +2 -2
- package/dist/lib/chunks/{chunk-RJ5R6YYA.js → chunk-FJL2V6P5.js} +6 -6
- package/dist/lib/chunks/{chunk-QSJ4IKUF.js → chunk-FL6LN2K6.js} +5 -5
- package/dist/lib/chunks/{chunk-663HABKP.js → chunk-HI3PD3KR.js} +8 -8
- package/dist/lib/chunks/{chunk-EJ655TVU.js → chunk-I3UE52ZV.js} +2 -2
- package/dist/lib/chunks/{chunk-ML4W6KC6.js → chunk-J5NPHPXY.js} +5 -4
- package/dist/lib/chunks/{chunk-V7OAPKNF.js → chunk-JBOOD6MU.js} +10 -9
- package/dist/lib/chunks/{chunk-YAAUWCJ4.js → chunk-JKPBXPCW.js} +3 -3
- package/dist/lib/chunks/{chunk-5HT55QYX.js → chunk-JQDQVG3D.js} +1 -1
- package/dist/lib/chunks/{chunk-YRBIC5QH.js → chunk-JXBLGCXZ.js} +1 -1
- package/dist/lib/chunks/{chunk-D2INDP5W.js → chunk-JYFEXVWC.js} +7 -6
- package/dist/lib/chunks/{chunk-W2VGLWTS.js → chunk-K2FZFESR.js} +10 -10
- package/dist/lib/chunks/{chunk-DC6PN7QJ.js → chunk-K4Y5NT4M.js} +11 -7
- package/dist/lib/chunks/chunk-K7YFL5KB.js +182 -0
- package/dist/lib/chunks/{chunk-ZYSPTOKK.js → chunk-KQCRJIEG.js} +1 -1
- package/dist/lib/chunks/{chunk-RR46EDDR.js → chunk-KSOHZKV5.js} +22 -22
- package/dist/lib/chunks/{chunk-R6XDZWUL.js → chunk-LR27H2HZ.js} +11 -11
- package/dist/lib/chunks/{chunk-KZR25REO.js → chunk-LTI2YYU3.js} +1 -1
- package/dist/lib/chunks/{chunk-EPQHVILQ.js → chunk-MA27TFEY.js} +5 -3
- package/dist/lib/chunks/{chunk-UZJSTJFP.js → chunk-MENTBQGB.js} +6 -5
- package/dist/lib/chunks/chunk-MPJCZN4G.js +155 -0
- package/dist/lib/chunks/{chunk-QHUDJVPJ.js → chunk-MTDYBJXH.js} +7 -7
- package/dist/lib/chunks/{chunk-BE4ENGUY.js → chunk-OQFAMKLN.js} +6 -6
- package/dist/lib/chunks/{chunk-SHUMCKCS.js → chunk-PWOYEIPF.js} +4 -4
- package/dist/lib/chunks/{chunk-4PD65FRJ.js → chunk-PXB4PWJI.js} +3 -3
- package/dist/lib/chunks/{chunk-7ZOJE6BH.js → chunk-QGZ4QSUE.js} +8 -7
- package/dist/lib/chunks/{chunk-GNMFJ2OK.js → chunk-QJZTDZMB.js} +8 -8
- package/dist/lib/chunks/{chunk-HQG63ZKO.js → chunk-R2AJYV6A.js} +17 -17
- package/dist/lib/chunks/{chunk-5B3RNVZ6.js → chunk-RK57YZKM.js} +1 -1
- package/dist/lib/chunks/{chunk-EBUQPCKB.js → chunk-RPTADJXD.js} +1 -1
- package/dist/lib/chunks/{chunk-GDKGZQ3T.js → chunk-RXSHKWZJ.js} +3 -3
- package/dist/lib/chunks/{chunk-CUYVHXHI.js → chunk-SD7LR26G.js} +3 -3
- package/dist/lib/chunks/{chunk-6GHHNPFJ.js → chunk-SIJOQRRK.js} +1 -1
- package/dist/lib/chunks/{chunk-2GU6CNQI.js → chunk-SLAPBFRH.js} +5 -5
- package/dist/lib/chunks/{chunk-2ROXN2EC.js → chunk-SMPP7B7F.js} +10 -10
- package/dist/lib/chunks/{chunk-L7MEIRJB.js → chunk-SQQ56UP2.js} +15 -6
- package/dist/lib/chunks/{chunk-WVACVWBL.js → chunk-T5XQ6NXD.js} +6 -4
- package/dist/lib/chunks/{chunk-EYKINDNK.js → chunk-TAPVCSCR.js} +1 -1
- package/dist/lib/chunks/{chunk-ISN6MBNB.js → chunk-U5USH2HB.js} +7 -7
- package/dist/lib/chunks/{chunk-MRL5RUP7.js → chunk-U6BW6LGX.js} +10 -3
- package/dist/lib/chunks/{chunk-3JO5TXBA.js → chunk-UYDQXXDQ.js} +4 -4
- package/dist/lib/chunks/{chunk-LOBXOZ2R.js → chunk-V5JJEEBT.js} +1 -1
- package/dist/lib/chunks/{chunk-OU73OUX4.js → chunk-VPXYGN4I.js} +71 -6
- package/dist/lib/chunks/{chunk-Z7V63UZA.js → chunk-VXDMOB7O.js} +4 -4
- package/dist/lib/chunks/{chunk-W5DC23OP.js → chunk-WCLKIPJV.js} +1 -1
- package/dist/lib/chunks/{chunk-7XO3SQAX.js → chunk-WDT2Y7D7.js} +1 -1
- package/dist/lib/chunks/{chunk-OVUCZLH2.js → chunk-WIBMVNIH.js} +2 -2
- package/dist/lib/chunks/{chunk-5T3V6XJS.js → chunk-WNIXDMJL.js} +1 -1
- package/dist/lib/chunks/{chunk-HTOD4W4E.js → chunk-WZGI7UVM.js} +2 -2
- package/dist/lib/chunks/{chunk-D3GE3OCB.js → chunk-XAKME6NM.js} +1 -1
- package/dist/lib/chunks/{chunk-I3XGRGXE.js → chunk-XAN4CRFP.js} +33 -41
- package/dist/lib/chunks/{chunk-AYY4MYTW.js → chunk-XFUYEFQP.js} +1 -1
- package/dist/lib/chunks/{chunk-G62E525I.js → chunk-XNTFOVCE.js} +2 -2
- package/dist/lib/chunks/{chunk-D7GEQVLL.js → chunk-YKJHFD64.js} +1 -1
- package/dist/lib/chunks/{chunk-VKM6MMA4.js → chunk-YZEZRQIG.js} +33 -2
- package/dist/lib/chunks/{chunk-5ZITQDVE.js → chunk-ZQ3ER7JD.js} +12 -13
- package/dist/lib/cli/bundle-commands.js +87 -85
- package/dist/lib/cli/run-commands.js +104 -100
- package/dist/lib/cli/status-command.js +73 -71
- package/dist/lib/codex-workflow/aggregate.js +21 -22
- package/dist/lib/codex-workflow/author-search.js +4 -3
- package/dist/lib/codex-workflow/author-tools.js +17 -15
- package/dist/lib/codex-workflow/author.js +36 -33
- package/dist/lib/codex-workflow/capture.js +24 -24
- package/dist/lib/codex-workflow/checkpoint.js +13 -13
- package/dist/lib/codex-workflow/checks.js +15 -16
- package/dist/lib/codex-workflow/copy-editor.js +30 -29
- package/dist/lib/codex-workflow/copy-recovery.js +11 -11
- package/dist/lib/codex-workflow/copy.js +27 -26
- package/dist/lib/codex-workflow/finish.js +34 -34
- package/dist/lib/codex-workflow/loop.js +62 -60
- package/dist/lib/codex-workflow/quality.js +11 -11
- package/dist/lib/codex-workflow/run-inputs.js +12 -12
- package/dist/lib/codex-workflow/run-source.js +26 -23
- package/dist/lib/codex-workflow/schemas.js +11 -11
- package/dist/lib/codex-workflow/session.js +14 -14
- package/dist/lib/codex-workflow/stage.js +43 -40
- package/dist/lib/codex-workflow/workdir.js +13 -13
- package/dist/lib/engine/audit-file.js +14 -10
- package/dist/lib/engine/author.js +50 -47
- package/dist/lib/engine/cost-estimate.js +18 -16
- package/dist/lib/engine/local-run.js +72 -70
- package/dist/lib/engine/preflight.js +11 -11
- package/dist/lib/engine/rejudge.js +78 -76
- package/dist/lib/engine/run-status.js +73 -71
- package/dist/lib/engine/templates.js +15 -11
- package/dist/lib/grounding/chromium-guard.js +13 -0
- package/dist/lib/grounding/controller.js +11 -10
- package/dist/lib/grounding/extract.js +10 -9
- package/dist/lib/grounding/fetch.js +4 -7
- package/dist/lib/grounding/file-store.js +5 -5
- package/dist/lib/grounding/grounding-runtime.js +32 -31
- package/dist/lib/grounding/guarded-request.js +18 -0
- package/dist/lib/grounding/model.js +9 -8
- package/dist/lib/grounding/profile.js +4 -4
- package/dist/lib/grounding/recorded-tools.js +16 -16
- package/dist/lib/grounding/session.js +3 -3
- package/dist/lib/grounding/tools.js +4 -3
- package/dist/lib/grounding/validation.js +2 -2
- package/dist/lib/harness/report/artifacts.js +11 -11
- package/dist/lib/harness/report/capture-coverage.js +4 -4
- package/dist/lib/lib/checkpoint.js +10 -10
- package/dist/lib/lib/progress-comparison.js +2 -2
- package/dist/lib/models/batching.js +3 -3
- package/dist/lib/models/structured.js +2 -2
- package/dist/lib/pipeline.js +19 -20
- package/dist/lib/probes/agent-clis.js +10 -10
- package/dist/lib/probes/probes.js +11 -11
- package/dist/lib/probes/web-tool-guard.js +3 -3
- package/dist/lib/report/contracts.js +4 -4
- package/dist/lib/report/core/progress-comparison.js +2 -2
- package/dist/lib/report/core/progress-schema.js +2 -2
- package/dist/lib/report/core/schema.js +2 -4
- package/dist/lib/report/core/surfaces.js +1 -3
- package/dist/lib/runner.js +23 -24
- package/dist/lib/schema.js +19 -13
- package/dist/lib/section-result.js +14 -15
- package/dist/lib/stores/artifacts.js +17 -17
- package/dist/lib/stores/files.js +31 -31
- package/dist/lib/stores/local-versions.js +10 -10
- package/dist/lib/stores/memory.js +33 -33
- package/dist/lib/stores/publication.js +23 -22
- package/dist/lib/surfaces.js +1 -3
- package/dist/lib/viewer/server.js +38 -38
- package/dist/lib/workflow/schema.js +8 -8
- package/dist/types/agents/author-schema.d.ts +3 -3
- package/dist/types/analysis/scoring.d.ts +2 -2
- package/dist/types/bundle/contracts.d.ts +3 -2
- package/dist/types/checks/crawler-access.d.ts +3 -2
- package/dist/types/checks/renderability.d.ts +8 -1
- package/dist/types/codex-workflow/author-tools.d.ts +3 -3
- package/dist/types/codex-workflow/run-inputs.d.ts +3 -0
- package/dist/types/codex-workflow/schemas.d.ts +6 -6
- package/dist/types/engine/audit-file.d.ts +6 -1
- package/dist/types/engine/preflight.d.ts +2 -0
- package/dist/types/grounding/chromium-guard.d.ts +41 -0
- package/dist/types/grounding/fetch.d.ts +0 -10
- package/dist/types/grounding/guarded-request.d.ts +76 -0
- package/dist/types/harness/report/artifacts.d.ts +1 -0
- package/dist/types/lib/checkpoint.d.ts +5 -6
- package/dist/types/pipeline.d.ts +2 -1
- package/dist/types/probes/probes.d.ts +2 -1
- package/dist/types/report/contracts.d.ts +2 -0
- package/dist/types/report/core/schema.d.ts +3 -1
- package/dist/types/report/core/surfaces.d.ts +0 -1
- package/dist/types/schema.d.ts +22 -0
- package/dist/types/section-result.d.ts +1 -1
- package/package.json +1 -1
- package/resources/guide/OPERATOR.md +12 -3
- package/src/agents/author-schema.ts +13 -1
- package/src/agents/author-validation.ts +2 -5
- package/src/agents/facts.ts +8 -8
- package/src/agents/narrative-facts.ts +9 -20
- package/src/agents/verifier.ts +2 -2
- package/src/analysis/progress.ts +1 -0
- package/src/analysis/scoring.ts +9 -13
- package/src/bundle/contracts.ts +7 -2
- package/src/bundle/verify.ts +3 -3
- package/src/capture-manifest.ts +4 -0
- package/src/checks/crawler-access.ts +70 -50
- package/src/checks/renderability.ts +113 -87
- package/src/checks/run-checks.ts +16 -3
- package/src/cli/run-commands.ts +2 -0
- package/src/codex-workflow/aggregate.ts +1 -0
- package/src/codex-workflow/author-tools.ts +39 -60
- package/src/codex-workflow/capture.ts +1 -0
- package/src/codex-workflow/copy-editor.ts +3 -3
- package/src/codex-workflow/loop.ts +2 -2
- package/src/engine/audit-file.ts +89 -2
- package/src/engine/guide/OPERATOR.md +12 -3
- package/src/engine/preflight.ts +50 -0
- package/src/grounding/chromium-guard.ts +273 -0
- package/src/grounding/controller.ts +1 -1
- package/src/grounding/fetch.ts +39 -276
- package/src/grounding/guarded-request.ts +428 -0
- package/src/grounding/tools.ts +2 -1
- package/src/grounding/validation.ts +1 -1
- package/src/lib/checkpoint.ts +15 -16
- package/src/pipeline.ts +13 -7
- package/src/probes/agent-clis.ts +2 -3
- package/src/probes/probes.ts +24 -10
- package/src/report/core/schema.ts +4 -1
- package/src/report/core/surfaces.ts +4 -8
- package/src/runner.ts +1 -0
- package/src/schema.ts +68 -4
- package/src/section-result.ts +6 -5
- package/dist/lib/chunks/chunk-6EH4N3EU.js +0 -113
- package/dist/lib/chunks/chunk-SWJ7KQSL.js +0 -318
- package/dist/lib/chunks/{chunk-CO5T6WU5.js → chunk-OD36HUXA.js} +3 -3
- package/dist/lib/chunks/{chunk-XI5H46DF.js → chunk-SASE7U6E.js} +3 -3
|
@@ -7,9 +7,16 @@ import {
|
|
|
7
7
|
canonicalResearchUrl,
|
|
8
8
|
extractSourceDocument,
|
|
9
9
|
fetchGroundingSource,
|
|
10
|
+
} from '../grounding/fetch';
|
|
11
|
+
import {
|
|
12
|
+
resolvePublicAddress,
|
|
10
13
|
SourceRetrievalError,
|
|
11
14
|
validateResearchUrl,
|
|
12
|
-
} from '../grounding/
|
|
15
|
+
} from '../grounding/guarded-request';
|
|
16
|
+
import {
|
|
17
|
+
withBoundedPage,
|
|
18
|
+
withGuardedChromium,
|
|
19
|
+
} from '../grounding/chromium-guard';
|
|
13
20
|
import {
|
|
14
21
|
groundingSourceSchema,
|
|
15
22
|
type GroundingSource,
|
|
@@ -987,70 +994,42 @@ export const createAuthorTools = (options: AuthorToolsOptions): AuthorTools => {
|
|
|
987
994
|
};
|
|
988
995
|
|
|
989
996
|
/** Rendered HTML for a public page through the Chromium the image already
|
|
990
|
-
* carries for the renderability check.
|
|
991
|
-
*
|
|
992
|
-
*
|
|
997
|
+
* carries for the renderability check. Every connection the browser makes
|
|
998
|
+
* passes the guarding proxy; the page's own host is checked first so a
|
|
999
|
+
* private destination fails with its own reason, not a tunnel error. */
|
|
993
1000
|
export const renderWithChromium = async (
|
|
994
1001
|
url: URL,
|
|
995
1002
|
signal: AbortSignal,
|
|
996
1003
|
): Promise<string> => {
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
const {
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
if (
|
|
1025
|
-
target.protocol !== 'https:' ||
|
|
1026
|
-
(isIP(host) && !isPublicAddress(host)) ||
|
|
1027
|
-
host === 'localhost' ||
|
|
1028
|
-
host.endsWith('.local') ||
|
|
1029
|
-
host.endsWith('.internal')
|
|
1030
|
-
) {
|
|
1031
|
-
return route.abort();
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
return route.continue();
|
|
1035
|
-
});
|
|
1036
|
-
|
|
1037
|
-
// Closing the page ends the navigation; its own failure changes nothing.
|
|
1038
|
-
const abort = () => {
|
|
1039
|
-
void page.close().catch(() => undefined);
|
|
1040
|
-
};
|
|
1041
|
-
|
|
1042
|
-
signal.addEventListener('abort', abort, { once: true });
|
|
1043
|
-
|
|
1044
|
-
try {
|
|
1045
|
-
await page.goto(url.href, { waitUntil: 'networkidle', timeout: 45_000 });
|
|
1004
|
+
await resolvePublicAddress(url.hostname, signal);
|
|
1005
|
+
|
|
1006
|
+
const { result } = await withGuardedChromium(
|
|
1007
|
+
(context) => {
|
|
1008
|
+
return withBoundedPage(context, 60_000, async (page) => {
|
|
1009
|
+
// Closing the page ends the navigation; its own failure changes
|
|
1010
|
+
// nothing.
|
|
1011
|
+
const abort = () => {
|
|
1012
|
+
void page.close().catch(() => undefined);
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
signal.addEventListener('abort', abort, { once: true });
|
|
1016
|
+
|
|
1017
|
+
try {
|
|
1018
|
+
await page.goto(url.href, {
|
|
1019
|
+
waitUntil: 'networkidle',
|
|
1020
|
+
timeout: 45_000,
|
|
1021
|
+
});
|
|
1022
|
+
|
|
1023
|
+
return await page.content();
|
|
1024
|
+
} finally {
|
|
1025
|
+
signal.removeEventListener('abort', abort);
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
},
|
|
1029
|
+
{ userAgent: `${researchUserAgent}/1` },
|
|
1030
|
+
);
|
|
1046
1031
|
|
|
1047
|
-
|
|
1048
|
-
} finally {
|
|
1049
|
-
signal.removeEventListener('abort', abort);
|
|
1050
|
-
}
|
|
1051
|
-
} finally {
|
|
1052
|
-
await browser.close();
|
|
1053
|
-
}
|
|
1032
|
+
return result;
|
|
1054
1033
|
};
|
|
1055
1034
|
|
|
1056
1035
|
/** Every research journal entry, in order; an absent journal is empty. */
|
|
@@ -83,6 +83,7 @@ const sectionArgs = (
|
|
|
83
83
|
language: deps.config.language,
|
|
84
84
|
surfaces: deps.plan.surfaces,
|
|
85
85
|
agentProbes: deps.config.agentProbes,
|
|
86
|
+
chatProbes: deps.config.chatProbes,
|
|
86
87
|
agentCliVersions: deps.agentCliVersions,
|
|
87
88
|
runId: deps.request.runId,
|
|
88
89
|
probeStore: deps.stores.probeStore,
|
|
@@ -79,9 +79,9 @@ export const copyEditCall = (args: {
|
|
|
79
79
|
// facts, in the order it is given up when the whole does not fit the
|
|
80
80
|
// role's input limit: every previous edit carries a full draft, the
|
|
81
81
|
// review history grows a review per block per round, and the rule
|
|
82
|
-
// documents are voice, not evidence.
|
|
83
|
-
//
|
|
84
|
-
//
|
|
82
|
+
// documents are voice, not evidence. One run's copy pass refused the
|
|
83
|
+
// edit before any model call because all of it together was over the
|
|
84
|
+
// limit, and the report shipped without a narrative.
|
|
85
85
|
const trims: { name: string; apply: () => void }[] = [
|
|
86
86
|
{
|
|
87
87
|
name: 'older_edits',
|
|
@@ -775,8 +775,8 @@ export const writeReportCopy = async (
|
|
|
775
775
|
throw error;
|
|
776
776
|
}
|
|
777
777
|
|
|
778
|
-
// The verifier stayed unusable through its tries (
|
|
779
|
-
//
|
|
778
|
+
// The verifier stayed unusable through its tries (one run's six
|
|
779
|
+
// invalid reviews failed the pipeline). The report ships on its
|
|
780
780
|
// verified facts with the improvement note; the saved draft is kept.
|
|
781
781
|
ctx.log(
|
|
782
782
|
`copy verifier stayed ${error.outcome} after its tries; delivering the verified facts without the narrative`,
|
package/src/engine/audit-file.ts
CHANGED
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { readFile } from 'node:fs/promises';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
import {
|
|
4
|
+
SourceRetrievalError,
|
|
5
|
+
validateResearchUrl,
|
|
6
|
+
} from '../grounding/guarded-request';
|
|
3
7
|
import type { ModelBudgetLimits } from '../models/accounting';
|
|
4
8
|
import { localModelProfile } from '../models/local-profile';
|
|
5
9
|
import { resolveSupportedModel } from '../models/supported-models';
|
|
6
10
|
import { resolveDataForSeoLocale } from '../probes/dataforseo-locale';
|
|
7
11
|
import { probeLimitsSchema } from '../probes/limits';
|
|
12
|
+
import { urlIsOnDomain } from '../report/core/domain-match';
|
|
8
13
|
import {
|
|
9
14
|
aeoAuditConfigSchema,
|
|
10
15
|
aeoSurfaceSchema,
|
|
11
16
|
agentProbeConfigSchema,
|
|
12
17
|
allSurfaces,
|
|
13
18
|
brandSchema,
|
|
19
|
+
chatProbeConfigSchema,
|
|
14
20
|
coverageThresholdsSchema,
|
|
15
21
|
defaultMaxPlannedUnits,
|
|
16
22
|
isAgentSurface,
|
|
@@ -84,9 +90,61 @@ export const runPolicySchema = z
|
|
|
84
90
|
// Caps every paid call of the run: probes, Codex stage sessions, host
|
|
85
91
|
// model calls and searches (see BudgetPolicy).
|
|
86
92
|
budget: budgetPolicySchema.prefault({}),
|
|
93
|
+
// Hosts off the brand's site whose pages the site checks may fetch (a
|
|
94
|
+
// docs site on another domain). A permission, not a measurement input:
|
|
95
|
+
// granting one never moves a baseline.
|
|
96
|
+
checkHosts: z.array(z.string().trim().min(1)).max(20).default([]),
|
|
87
97
|
})
|
|
88
98
|
.strict();
|
|
89
99
|
|
|
100
|
+
/** Why a checkHosts entry is refused: it must be a bare public host name. */
|
|
101
|
+
const checkHostProblem = (host: string): string | undefined => {
|
|
102
|
+
try {
|
|
103
|
+
const url = validateResearchUrl(`https://${host}/`);
|
|
104
|
+
|
|
105
|
+
if (url.hostname === host.toLowerCase()) {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
} catch (err) {
|
|
109
|
+
if (!(err instanceof SourceRetrievalError)) {
|
|
110
|
+
throw err;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return `Use a bare public host name such as docs.acme.example, not ${JSON.stringify(host)}.`;
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Why a money page is refused. The site checks fetch and render it, so it
|
|
119
|
+
* must be public https on the brand's site or its subdomains, or on a host
|
|
120
|
+
* the operator named in runPolicy.checkHosts.
|
|
121
|
+
*/
|
|
122
|
+
const moneyPageProblem = (
|
|
123
|
+
page: string,
|
|
124
|
+
file: {
|
|
125
|
+
brand: { domain: string };
|
|
126
|
+
runPolicy: { checkHosts: readonly string[] };
|
|
127
|
+
},
|
|
128
|
+
): string | undefined => {
|
|
129
|
+
try {
|
|
130
|
+
validateResearchUrl(page);
|
|
131
|
+
} catch (err) {
|
|
132
|
+
if (err instanceof SourceRetrievalError) {
|
|
133
|
+
return `A money page must be a public https URL with no port or credentials: ${err.message}`;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
throw err;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const hosts = [file.brand.domain, ...file.runPolicy.checkHosts];
|
|
140
|
+
|
|
141
|
+
if (hosts.some((host) => urlIsOnDomain(page, host))) {
|
|
142
|
+
return undefined;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return `${page} is not on ${file.brand.domain} or its subdomains. Name its host in runPolicy.checkHosts to let the site checks fetch it.`;
|
|
146
|
+
};
|
|
147
|
+
|
|
90
148
|
export const auditFileSchema = z
|
|
91
149
|
.object({
|
|
92
150
|
version: z.literal(auditFileVersion),
|
|
@@ -102,10 +160,14 @@ export const auditFileSchema = z
|
|
|
102
160
|
.array(aeoSurfaceSchema)
|
|
103
161
|
.min(1)
|
|
104
162
|
.default([...allSurfaces]),
|
|
105
|
-
|
|
163
|
+
// Strict here, unlike the internal config that bundles keep: a
|
|
164
|
+
// misspelled key is refused, never dropped for the default depth.
|
|
165
|
+
agentProbes: agentProbeConfigSchema.strict().prefault({}),
|
|
166
|
+
// Absent = the standard depth (2 runs per prompt, 1 on AI Overview).
|
|
167
|
+
chatProbes: chatProbeConfigSchema.optional(),
|
|
106
168
|
geography: z.string().default('us'),
|
|
107
169
|
language: z.string().default('en'),
|
|
108
|
-
moneyPages: z.array(z.url()).default([]),
|
|
170
|
+
moneyPages: z.array(z.url()).max(20).default([]),
|
|
109
171
|
productBrief: z.string().trim().min(1),
|
|
110
172
|
// `full` researches and adjudicates the claims answers make about the
|
|
111
173
|
// product; `extraction_only` keeps the claim inventory and skips both.
|
|
@@ -126,6 +188,30 @@ export const auditFileSchema = z
|
|
|
126
188
|
});
|
|
127
189
|
}
|
|
128
190
|
|
|
191
|
+
for (const [index, host] of file.runPolicy.checkHosts.entries()) {
|
|
192
|
+
const problem = checkHostProblem(host);
|
|
193
|
+
|
|
194
|
+
if (problem !== undefined) {
|
|
195
|
+
context.addIssue({
|
|
196
|
+
code: 'custom',
|
|
197
|
+
message: problem,
|
|
198
|
+
path: ['runPolicy', 'checkHosts', index],
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
for (const [index, page] of file.moneyPages.entries()) {
|
|
204
|
+
const problem = moneyPageProblem(page, file);
|
|
205
|
+
|
|
206
|
+
if (problem !== undefined) {
|
|
207
|
+
context.addIssue({
|
|
208
|
+
code: 'custom',
|
|
209
|
+
message: problem,
|
|
210
|
+
path: ['moneyPages', index],
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
129
215
|
const keys = file.sections.map((section) => section.key);
|
|
130
216
|
|
|
131
217
|
if (new Set(keys).size !== keys.length) {
|
|
@@ -213,6 +299,7 @@ export const toAuditConfig = (file: AuditFile): AeoAuditConfig => {
|
|
|
213
299
|
}),
|
|
214
300
|
sections: file.sections,
|
|
215
301
|
agentProbes: file.agentProbes,
|
|
302
|
+
...(file.chatProbes !== undefined && { chatProbes: file.chatProbes }),
|
|
216
303
|
moneyPages: file.moneyPages,
|
|
217
304
|
productBrief: file.productBrief,
|
|
218
305
|
surfaces: {
|
|
@@ -114,9 +114,17 @@ sections, the buyer questions in each, the competitors, and the surfaces
|
|
|
114
114
|
(the assistants that will be asked). Apply the user's edits to
|
|
115
115
|
`draft/audit.json` yourself. The optional `model` field names the model
|
|
116
116
|
that judges and writes the report; leave it out to use the recommended
|
|
117
|
-
one, which `literally-aeo doctor` lists with every supported model.
|
|
117
|
+
one, which `literally-aeo doctor` lists with every supported model. If the
|
|
118
|
+
user would rather measure fewer questions more deeply, set
|
|
119
|
+
`chatProbes.runsPerPrompt` and `agentProbes.runsPerPrompt` (1 to 25 runs
|
|
120
|
+
of each question per assistant); left out, each question is asked twice
|
|
121
|
+
(once on AI Overviews). Run
|
|
118
122
|
`literally-aeo doctor --config draft/audit.json --env-file .env --json`
|
|
119
|
-
after editing.
|
|
123
|
+
after editing. Money pages must be on the company's site or its
|
|
124
|
+
subdomains; for a page on another host the user owns (a docs site, say),
|
|
125
|
+
add that host to `runPolicy.checkHosts`. With money pages, doctor also
|
|
126
|
+
checks that Chromium launches and, if not, names the command that
|
|
127
|
+
installs it.
|
|
120
128
|
|
|
121
129
|
## Checkpoint 6: approve the audit cost
|
|
122
130
|
|
|
@@ -174,7 +182,8 @@ Quote the report; do not add claims it does not make.
|
|
|
174
182
|
|
|
175
183
|
Offer `literally-aeo export run`: a `.aeo.zip` bundle with the captured
|
|
176
184
|
answers, every judgment, the metrics, the report and the journal of every
|
|
177
|
-
operation, which anyone can check offline with `literally-aeo verify
|
|
185
|
+
operation, which anyone can check offline with `literally-aeo verify` from
|
|
186
|
+
this release or a newer one.
|
|
178
187
|
Credentials found in it block the export. Tell the user the bundle shows
|
|
179
188
|
the questions and the answers, so they should share it only where those can
|
|
180
189
|
be read.
|
package/src/engine/preflight.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { mkdir, rm, writeFile } from 'node:fs/promises';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import {
|
|
4
5
|
agentAuthEnv,
|
|
@@ -109,6 +110,49 @@ const directoryCheck = async (dir: string): Promise<PreflightCheck> => {
|
|
|
109
110
|
}
|
|
110
111
|
};
|
|
111
112
|
|
|
113
|
+
/** The command that installs the Chromium this package's Playwright drives;
|
|
114
|
+
* an unversioned `npx playwright` may fetch another release's browser. */
|
|
115
|
+
const chromiumInstallCommand = (): string => {
|
|
116
|
+
const manifest: unknown = createRequire(import.meta.url)(
|
|
117
|
+
'playwright/package.json',
|
|
118
|
+
);
|
|
119
|
+
const version =
|
|
120
|
+
typeof manifest === 'object' &&
|
|
121
|
+
manifest !== null &&
|
|
122
|
+
'version' in manifest &&
|
|
123
|
+
typeof manifest.version === 'string'
|
|
124
|
+
? `@${manifest.version}`
|
|
125
|
+
: '';
|
|
126
|
+
|
|
127
|
+
return `npx playwright${version} install chromium`;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/** The renderability check renders every money page in Chromium: a
|
|
131
|
+
* missing browser stops the run here, not after the probes were paid for. */
|
|
132
|
+
const chromiumCheck = async (): Promise<PreflightCheck> => {
|
|
133
|
+
try {
|
|
134
|
+
const { chromium } = await import('playwright');
|
|
135
|
+
const browser = await chromium.launch();
|
|
136
|
+
const version = browser.version();
|
|
137
|
+
|
|
138
|
+
await browser.close();
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
name: 'chromium (money pages)',
|
|
142
|
+
ok: true,
|
|
143
|
+
detail: `Chromium ${version} launches`,
|
|
144
|
+
};
|
|
145
|
+
} catch (err) {
|
|
146
|
+
const message = err instanceof Error ? err.message.split('\n')[0] : '';
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
name: 'chromium (money pages)',
|
|
150
|
+
ok: false,
|
|
151
|
+
detail: `does not launch (${message}); run \`${chromiumInstallCommand()}\`, or remove moneyPages from audit.json`,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
|
|
112
156
|
/** The model audit.json names, or the recommended one: refused when it is
|
|
113
157
|
* not on the supported list, which the detail then prints. */
|
|
114
158
|
export const modelCheck = (model: string | undefined): PreflightCheck => {
|
|
@@ -174,6 +218,8 @@ export const runPreflight = async (args: {
|
|
|
174
218
|
model?: string;
|
|
175
219
|
/** Full grounding researches through the pinned search provider. */
|
|
176
220
|
groundingSearch?: boolean;
|
|
221
|
+
/** Money pages are rendered in Chromium by the renderability check. */
|
|
222
|
+
rendersPages?: boolean;
|
|
177
223
|
}): Promise<PreflightCheck[]> => {
|
|
178
224
|
const { surfaces, settings } = args;
|
|
179
225
|
const nodeMajor = Number(process.versions.node.split('.')[0]);
|
|
@@ -233,6 +279,10 @@ export const runPreflight = async (args: {
|
|
|
233
279
|
});
|
|
234
280
|
}
|
|
235
281
|
|
|
282
|
+
if (args.rendersPages) {
|
|
283
|
+
checks.push(await chromiumCheck());
|
|
284
|
+
}
|
|
285
|
+
|
|
236
286
|
checks.push(await directoryCheck(args.dir));
|
|
237
287
|
|
|
238
288
|
return checks;
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
import type { LookupAddress } from 'node:dns';
|
|
2
|
+
import { createServer } from 'node:http';
|
|
3
|
+
import { connect, type Socket } from 'node:net';
|
|
4
|
+
import type { Duplex } from 'node:stream';
|
|
5
|
+
import type { BrowserContext, Page, Request } from 'playwright';
|
|
6
|
+
import {
|
|
7
|
+
resolvePublicAddress,
|
|
8
|
+
validateResearchUrl,
|
|
9
|
+
type LookupAll,
|
|
10
|
+
} from './guarded-request';
|
|
11
|
+
|
|
12
|
+
// ============================================================================
|
|
13
|
+
// Chromium behind the guard (specs/aeo-checks-and-reach-spec.md §3.2). A
|
|
14
|
+
// route handler alone does not hold: it sees only the first URL of a
|
|
15
|
+
// redirect, never resolves subresource host names, and WebSockets and
|
|
16
|
+
// service workers pass beside it. So the browser's every connection goes
|
|
17
|
+
// through a forward proxy on 127.0.0.1 that applies guardedRequest's rule
|
|
18
|
+
// per connection: port 443, a public host, every DNS answer public, the
|
|
19
|
+
// socket pinned to the checked address. The proxy tunnels TLS; it never
|
|
20
|
+
// sees page content.
|
|
21
|
+
// ============================================================================
|
|
22
|
+
|
|
23
|
+
const connectTimeoutInMs = 15_000;
|
|
24
|
+
|
|
25
|
+
export type ConnectionCounts = { allowed: number; refused: number };
|
|
26
|
+
|
|
27
|
+
export type GuardingProxyOptions = {
|
|
28
|
+
/** Test seam: the DNS answers for a host. */
|
|
29
|
+
lookupHost?: LookupAll;
|
|
30
|
+
/** Test seam: where an allowed connection is dialled. */
|
|
31
|
+
dial?: (address: LookupAddress) => Socket;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export type GuardingProxy = {
|
|
35
|
+
server: string;
|
|
36
|
+
counts: () => ConnectionCounts;
|
|
37
|
+
close: () => Promise<void>;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const dialPublicAddress = (address: LookupAddress): Socket => {
|
|
41
|
+
return connect({ host: address.address, port: 443, family: address.family });
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** The CONNECT authority as a guarded https URL, or undefined if refused. */
|
|
45
|
+
const toConnectTarget = (authority: string): URL | undefined => {
|
|
46
|
+
const separator = authority.lastIndexOf(':');
|
|
47
|
+
|
|
48
|
+
if (separator < 0 || authority.slice(separator + 1) !== '443') {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
try {
|
|
53
|
+
return validateResearchUrl(`https://${authority.slice(0, separator)}/`);
|
|
54
|
+
} catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** startGuardingProxy listens on a free loopback port until closed. */
|
|
60
|
+
export const startGuardingProxy = async (
|
|
61
|
+
options: GuardingProxyOptions = {},
|
|
62
|
+
): Promise<GuardingProxy> => {
|
|
63
|
+
const { lookupHost, dial = dialPublicAddress } = options;
|
|
64
|
+
const counts: ConnectionCounts = { allowed: 0, refused: 0 };
|
|
65
|
+
const sockets = new Set<Duplex>();
|
|
66
|
+
|
|
67
|
+
const refuse = (client: Duplex) => {
|
|
68
|
+
counts.refused += 1;
|
|
69
|
+
client.end('HTTP/1.1 403 Forbidden\r\n\r\n');
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Only CONNECT tunnels are served: a plain http request is refused.
|
|
73
|
+
const server = createServer((_request, response) => {
|
|
74
|
+
counts.refused += 1;
|
|
75
|
+
response.writeHead(403).end();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const tunnel = async (authority: string, client: Duplex, head: Buffer) => {
|
|
79
|
+
const target = toConnectTarget(authority);
|
|
80
|
+
|
|
81
|
+
if (!target) {
|
|
82
|
+
refuse(client);
|
|
83
|
+
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
let address: LookupAddress;
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
address = await resolvePublicAddress(
|
|
91
|
+
target.hostname,
|
|
92
|
+
AbortSignal.timeout(connectTimeoutInMs),
|
|
93
|
+
lookupHost,
|
|
94
|
+
);
|
|
95
|
+
} catch {
|
|
96
|
+
refuse(client);
|
|
97
|
+
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
counts.allowed += 1;
|
|
102
|
+
|
|
103
|
+
const upstream = dial(address);
|
|
104
|
+
|
|
105
|
+
sockets.add(upstream);
|
|
106
|
+
upstream.setTimeout(connectTimeoutInMs, () => {
|
|
107
|
+
upstream.destroy();
|
|
108
|
+
});
|
|
109
|
+
upstream.once('connect', () => {
|
|
110
|
+
upstream.setTimeout(0);
|
|
111
|
+
client.write('HTTP/1.1 200 Connection Established\r\n\r\n');
|
|
112
|
+
upstream.write(head);
|
|
113
|
+
upstream.pipe(client);
|
|
114
|
+
client.pipe(upstream);
|
|
115
|
+
});
|
|
116
|
+
upstream.once('error', () => {
|
|
117
|
+
client.end('HTTP/1.1 502 Bad Gateway\r\n\r\n');
|
|
118
|
+
});
|
|
119
|
+
upstream.once('close', () => {
|
|
120
|
+
sockets.delete(upstream);
|
|
121
|
+
client.destroy();
|
|
122
|
+
});
|
|
123
|
+
client.once('close', () => {
|
|
124
|
+
upstream.destroy();
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
server.on('connection', (socket: Socket) => {
|
|
129
|
+
sockets.add(socket);
|
|
130
|
+
socket.once('close', () => {
|
|
131
|
+
sockets.delete(socket);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
server.on('connect', (request, client: Duplex, head: Buffer) => {
|
|
135
|
+
client.on('error', () => {
|
|
136
|
+
client.destroy();
|
|
137
|
+
});
|
|
138
|
+
void tunnel(request.url ?? '', client, head);
|
|
139
|
+
});
|
|
140
|
+
// A ws:// upgrade asked of the proxy itself, not tunnelled.
|
|
141
|
+
server.on('upgrade', (_request, client: Duplex) => {
|
|
142
|
+
refuse(client);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
await new Promise<void>((resolve, reject) => {
|
|
146
|
+
server.once('error', reject);
|
|
147
|
+
server.listen(0, '127.0.0.1', resolve);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
const address = server.address();
|
|
151
|
+
|
|
152
|
+
if (address === null || typeof address === 'string') {
|
|
153
|
+
throw new Error('The guarding proxy did not bind a TCP port.');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return {
|
|
157
|
+
server: `http://127.0.0.1:${address.port}`,
|
|
158
|
+
counts: () => ({ ...counts }),
|
|
159
|
+
close: async () => {
|
|
160
|
+
for (const socket of sockets) {
|
|
161
|
+
socket.destroy();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
await new Promise<void>((resolve) => {
|
|
165
|
+
server.close(() => {
|
|
166
|
+
resolve();
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const chromiumArgs = [
|
|
174
|
+
// Playwright proxies loopback too unless an environment variable turns
|
|
175
|
+
// that off; this flag comes last and keeps it on regardless.
|
|
176
|
+
'--proxy-bypass-list=<-loopback>',
|
|
177
|
+
// QUIC and WebRTC over UDP would leave beside an HTTP proxy.
|
|
178
|
+
'--disable-quic',
|
|
179
|
+
'--force-webrtc-ip-handling-policy=disable_non_proxied_udp',
|
|
180
|
+
];
|
|
181
|
+
|
|
182
|
+
/** What a guarded page may request at all, before the proxy decides. */
|
|
183
|
+
const isAllowedRequest = (request: Request): boolean => {
|
|
184
|
+
const url = new URL(request.url());
|
|
185
|
+
|
|
186
|
+
return (
|
|
187
|
+
url.protocol === 'https:' &&
|
|
188
|
+
url.port === '' &&
|
|
189
|
+
request.resourceType() !== 'media'
|
|
190
|
+
);
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* withBoundedPage runs `use` on a new page of the context, then closes it.
|
|
195
|
+
* A page that freezes its main thread never answers evaluate() or content(),
|
|
196
|
+
* and no Playwright timeout covers those calls; closing the page makes them
|
|
197
|
+
* fail. So past the deadline the page is closed and the render refused,
|
|
198
|
+
* instead of holding the run, and the host's turn in the pacer, forever.
|
|
199
|
+
*/
|
|
200
|
+
export const withBoundedPage = async <T>(
|
|
201
|
+
context: Pick<BrowserContext, 'newPage'>,
|
|
202
|
+
deadlineInMs: number,
|
|
203
|
+
use: (page: Page) => Promise<T>,
|
|
204
|
+
): Promise<T> => {
|
|
205
|
+
const page = await context.newPage();
|
|
206
|
+
const deadline = AbortSignal.timeout(deadlineInMs);
|
|
207
|
+
// The pending call fails with the closed page; that failure is reported.
|
|
208
|
+
const closePage = () => {
|
|
209
|
+
void page.close().catch(() => undefined);
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
deadline.addEventListener('abort', closePage, { once: true });
|
|
213
|
+
|
|
214
|
+
try {
|
|
215
|
+
return await use(page);
|
|
216
|
+
} catch (error) {
|
|
217
|
+
if (deadline.aborted) {
|
|
218
|
+
throw new Error(
|
|
219
|
+
`The page did not finish rendering within ${deadlineInMs / 1000} s.`,
|
|
220
|
+
{ cause: error },
|
|
221
|
+
);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
throw error;
|
|
225
|
+
} finally {
|
|
226
|
+
deadline.removeEventListener('abort', closePage);
|
|
227
|
+
await page.close();
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* withGuardedChromium runs `use` in a fresh browser context whose every
|
|
233
|
+
* connection passes the guarding proxy, then closes both. Downloads are
|
|
234
|
+
* refused, service workers blocked and media never loaded.
|
|
235
|
+
*/
|
|
236
|
+
export const withGuardedChromium = async <T>(
|
|
237
|
+
use: (context: BrowserContext) => Promise<T>,
|
|
238
|
+
options: { userAgent?: string; proxy?: GuardingProxyOptions } = {},
|
|
239
|
+
): Promise<{ result: T; connections: ConnectionCounts }> => {
|
|
240
|
+
const proxy = await startGuardingProxy(options.proxy);
|
|
241
|
+
|
|
242
|
+
try {
|
|
243
|
+
const { chromium } = await import('playwright');
|
|
244
|
+
const browser = await chromium.launch({
|
|
245
|
+
proxy: { server: proxy.server },
|
|
246
|
+
args: chromiumArgs,
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
try {
|
|
250
|
+
const context = await browser.newContext({
|
|
251
|
+
acceptDownloads: false,
|
|
252
|
+
serviceWorkers: 'block',
|
|
253
|
+
...(options.userAgent !== undefined && {
|
|
254
|
+
userAgent: options.userAgent,
|
|
255
|
+
}),
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
await context.route('**/*', (route) => {
|
|
259
|
+
return isAllowedRequest(route.request())
|
|
260
|
+
? route.continue()
|
|
261
|
+
: route.abort();
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
const result = await use(context);
|
|
265
|
+
|
|
266
|
+
return { result, connections: proxy.counts() };
|
|
267
|
+
} finally {
|
|
268
|
+
await browser.close();
|
|
269
|
+
}
|
|
270
|
+
} finally {
|
|
271
|
+
await proxy.close();
|
|
272
|
+
}
|
|
273
|
+
};
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
ModelBudgetError,
|
|
5
5
|
type ModelCallAccounting,
|
|
6
6
|
} from '../models/accounting';
|
|
7
|
-
import { SourceRetrievalError } from './
|
|
7
|
+
import { SourceRetrievalError } from './guarded-request';
|
|
8
8
|
import { proposedAssessmentSchema } from './model';
|
|
9
9
|
import {
|
|
10
10
|
adjudicationVersion,
|