literally-aeo 0.2.0 → 0.2.2
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 +808 -386
- package/dist/lib/access/schema.js +6 -6
- package/dist/lib/agents/author-schema.js +10 -10
- package/dist/lib/agents/author-validation.js +20 -18
- package/dist/lib/agents/copy-validation.js +22 -21
- package/dist/lib/agents/copywriter-input.js +23 -8
- package/dist/lib/agents/facts.js +22 -7
- 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/money-pages.js +13 -0
- 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-D3GE3OCB.js → chunk-3CMPR6ZZ.js} +1 -1
- package/dist/lib/chunks/{chunk-TJQ5OPLQ.js → chunk-3OE4UQIB.js} +7 -7
- package/dist/lib/chunks/{chunk-Y4OGZ3Q5.js → chunk-46PVVQYR.js} +1 -1
- package/dist/lib/chunks/{chunk-OU73OUX4.js → chunk-4GLW3ZRO.js} +67 -7
- 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-FFOVLI3U.js → chunk-66T7JC57.js} +12 -10
- package/dist/lib/chunks/{chunk-IE7NAL6B.js → chunk-6HMHXSCS.js} +2 -2
- 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-CUYVHXHI.js → chunk-7DNLRXEY.js} +3 -3
- package/dist/lib/chunks/{chunk-622NMXN6.js → chunk-7HM6IZ3L.js} +2 -2
- 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-UEMZYHYJ.js → chunk-7YZPEX3T.js} +2 -2
- package/dist/lib/chunks/{chunk-OBXAHX3L.js → chunk-AASWJR7Q.js} +1 -5
- package/dist/lib/chunks/{chunk-NCXSNHXX.js → chunk-AJO7XVXK.js} +12 -12
- package/dist/lib/chunks/{chunk-2GU6CNQI.js → chunk-AT3XMGES.js} +5 -5
- 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-5JPYM4MD.js → chunk-BYHXNFWN.js} +1 -1
- package/dist/lib/chunks/{chunk-NCLFZOZU.js → chunk-CH7OCYDL.js} +1 -1
- 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-SDWYZM64.js → chunk-EDQTINTL.js} +5 -1
- package/dist/lib/chunks/{chunk-4PD65FRJ.js → chunk-EOO5RBUW.js} +3 -3
- 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-RJ5R6YYA.js → chunk-FJL2V6P5.js} +6 -6
- package/dist/lib/chunks/chunk-FK2JQHAX.js +30 -0
- package/dist/lib/chunks/{chunk-QHUDJVPJ.js → chunk-GLUGYZQO.js} +7 -7
- package/dist/lib/chunks/{chunk-GNMFJ2OK.js → chunk-HCUJ2J7P.js} +8 -8
- package/dist/lib/chunks/{chunk-2ROXN2EC.js → chunk-HGGOGCPX.js} +10 -10
- package/dist/lib/chunks/{chunk-VPZQGND4.js → chunk-HGGRPOSA.js} +3 -3
- 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-HFRAHG5C.js → chunk-J7QKT5E7.js} +17 -17
- 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-GESHTTSA.js → chunk-JYCVBFH5.js} +2 -2
- 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-EBUQPCKB.js → chunk-KFAT65P7.js} +1 -1
- package/dist/lib/chunks/{chunk-ZYSPTOKK.js → chunk-KQCRJIEG.js} +1 -1
- package/dist/lib/chunks/{chunk-R6XDZWUL.js → chunk-LR27H2HZ.js} +11 -11
- package/dist/lib/chunks/{chunk-FUAUPNRO.js → chunk-LTCDLURT.js} +7 -7
- 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-BE4ENGUY.js → chunk-OOLWU667.js} +6 -6
- package/dist/lib/chunks/{chunk-QSJ4IKUF.js → chunk-PIF3GL62.js} +5 -5
- package/dist/lib/chunks/{chunk-W5X7WJYL.js → chunk-PIFTG6YW.js} +3 -3
- package/dist/lib/chunks/{chunk-YRBIC5QH.js → chunk-PKNODC6Y.js} +1 -1
- package/dist/lib/chunks/{chunk-SHUMCKCS.js → chunk-PWOYEIPF.js} +4 -4
- package/dist/lib/chunks/{chunk-RR46EDDR.js → chunk-QD3JXA3Y.js} +25 -25
- package/dist/lib/chunks/{chunk-7ZOJE6BH.js → chunk-QGZ4QSUE.js} +8 -7
- package/dist/lib/chunks/{chunk-D2INDP5W.js → chunk-R5UPOEWE.js} +9 -8
- package/dist/lib/chunks/{chunk-VKM6MMA4.js → chunk-RIJERFGU.js} +34 -3
- package/dist/lib/chunks/{chunk-5B3RNVZ6.js → chunk-RK57YZKM.js} +1 -1
- package/dist/lib/chunks/{chunk-GDKGZQ3T.js → chunk-RXSHKWZJ.js} +3 -3
- package/dist/lib/chunks/{chunk-NGHAP2P5.js → chunk-S6QOXJAL.js} +4 -4
- package/dist/lib/chunks/{chunk-6GHHNPFJ.js → chunk-SIJOQRRK.js} +1 -1
- package/dist/lib/chunks/{chunk-663HABKP.js → chunk-T6XZQOXS.js} +8 -8
- 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-L7MEIRJB.js → chunk-UNCUG2YS.js} +15 -6
- 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-XR44YSHT.js → chunk-VHKHYAC5.js} +30 -9
- package/dist/lib/chunks/{chunk-Z7V63UZA.js → chunk-VXDMOB7O.js} +4 -4
- package/dist/lib/chunks/{chunk-G62E525I.js → chunk-VXYQWE45.js} +2 -2
- 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-HQG63ZKO.js → chunk-XA27KAUV.js} +17 -17
- 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-FOCJ7HPC.js → chunk-XSER7WEB.js} +11 -11
- package/dist/lib/chunks/{chunk-WVACVWBL.js → chunk-YEUCAPKP.js} +6 -4
- package/dist/lib/chunks/{chunk-7Z27HQWL.js → chunk-YGLWQFKL.js} +3 -3
- package/dist/lib/chunks/{chunk-D7GEQVLL.js → chunk-YKJHFD64.js} +1 -1
- package/dist/lib/chunks/{chunk-OQU5IXAJ.js → chunk-ZOGIJGU3.js} +10 -10
- package/dist/lib/chunks/{chunk-5ZITQDVE.js → chunk-ZQ3ER7JD.js} +12 -13
- package/dist/lib/cli/bundle-commands.js +91 -88
- package/dist/lib/cli/run-commands.js +110 -105
- package/dist/lib/cli/status-command.js +77 -74
- 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 +38 -34
- package/dist/lib/codex-workflow/capture.js +25 -25
- 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 +31 -30
- package/dist/lib/codex-workflow/copy-recovery.js +11 -11
- package/dist/lib/codex-workflow/copy.js +28 -27
- package/dist/lib/codex-workflow/finish.js +34 -34
- package/dist/lib/codex-workflow/loop.js +65 -62
- 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 +45 -41
- package/dist/lib/codex-workflow/workdir.js +13 -13
- package/dist/lib/engine/audit-file.js +16 -11
- package/dist/lib/engine/author.js +53 -49
- package/dist/lib/engine/cost-estimate.js +18 -16
- package/dist/lib/engine/local-run.js +76 -73
- package/dist/lib/engine/preflight.js +12 -12
- package/dist/lib/engine/rejudge.js +82 -79
- package/dist/lib/engine/run-status.js +77 -74
- package/dist/lib/engine/templates.js +17 -12
- 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/models/supported-models.js +1 -1
- package/dist/lib/pipeline.js +20 -21
- package/dist/lib/probes/agent-clis.js +10 -10
- package/dist/lib/probes/probes.js +12 -12
- 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/money-pages.d.ts +19 -0
- 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 +24 -6
- 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/money-pages.ts +48 -0
- 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 +79 -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/models/supported-models.ts +3 -3
- 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
package/dist/author-tools.js
CHANGED
|
@@ -1,166 +1,5 @@
|
|
|
1
1
|
import { createRequire as __createRequire } from "node:module";
|
|
2
2
|
const require = __createRequire(import.meta.url);
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __esm = (fn, res, err) => function __init() {
|
|
6
|
-
if (err) throw err[0];
|
|
7
|
-
try {
|
|
8
|
-
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
9
|
-
} catch (e) {
|
|
10
|
-
throw err = [e], e;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
var __export = (target, all) => {
|
|
14
|
-
for (var name in all)
|
|
15
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// src/api/errors.ts
|
|
19
|
-
var ApiError;
|
|
20
|
-
var init_errors = __esm({
|
|
21
|
-
"src/api/errors.ts"() {
|
|
22
|
-
"use strict";
|
|
23
|
-
ApiError = class extends Error {
|
|
24
|
-
code;
|
|
25
|
-
details;
|
|
26
|
-
constructor(code, message, { details } = {}) {
|
|
27
|
-
super(message);
|
|
28
|
-
this.code = code;
|
|
29
|
-
this.details = details;
|
|
30
|
-
this.name = "ApiError";
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// src/workflow/callbacks.ts
|
|
37
|
-
var callbacks_exports = {};
|
|
38
|
-
__export(callbacks_exports, {
|
|
39
|
-
deliverCallback: () => deliverCallback,
|
|
40
|
-
isPublicAddress: () => isPublicAddress,
|
|
41
|
-
signCallback: () => signCallback,
|
|
42
|
-
validateCallbackUrl: () => validateCallbackUrl,
|
|
43
|
-
verifyCallback: () => verifyCallback
|
|
44
|
-
});
|
|
45
|
-
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
46
|
-
import { lookup } from "node:dns/promises";
|
|
47
|
-
import { isIP } from "node:net";
|
|
48
|
-
import { request as httpsRequest } from "node:https";
|
|
49
|
-
var signatureToleranceSeconds, deliveryTimeoutMs, signCallback, verifyCallback, isPublicAddress, validateCallbackUrl, deliverCallback;
|
|
50
|
-
var init_callbacks = __esm({
|
|
51
|
-
"src/workflow/callbacks.ts"() {
|
|
52
|
-
"use strict";
|
|
53
|
-
init_errors();
|
|
54
|
-
signatureToleranceSeconds = 300;
|
|
55
|
-
deliveryTimeoutMs = 5e3;
|
|
56
|
-
signCallback = (rawBody, secret, {
|
|
57
|
-
timestampInSeconds = Math.floor(Date.now() / 1e3)
|
|
58
|
-
} = {}) => {
|
|
59
|
-
const digest2 = createHmac("sha256", secret).update(`${timestampInSeconds}.${rawBody}`).digest("hex");
|
|
60
|
-
return `t=${timestampInSeconds},v1=${digest2}`;
|
|
61
|
-
};
|
|
62
|
-
verifyCallback = (rawBody, { signature, secret, nowMs = Date.now() }) => {
|
|
63
|
-
const match = /^t=(\d{1,12}),v1=([a-f0-9]{64})$/.exec(signature ?? "");
|
|
64
|
-
if (!match || !secret) {
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
const [, timestampText, digestHex] = match;
|
|
68
|
-
if (timestampText === void 0 || digestHex === void 0) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
const ageInSeconds = Math.abs(nowMs / 1e3 - Number(timestampText));
|
|
72
|
-
if (ageInSeconds > signatureToleranceSeconds) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
const expected = createHmac("sha256", secret).update(`${timestampText}.${rawBody}`).digest();
|
|
76
|
-
return timingSafeEqual(expected, Buffer.from(digestHex, "hex"));
|
|
77
|
-
};
|
|
78
|
-
isPublicAddress = (address) => {
|
|
79
|
-
if (isIP(address) === 4) {
|
|
80
|
-
const [a, b] = address.split(".").map(Number);
|
|
81
|
-
if (a === void 0 || b === void 0) {
|
|
82
|
-
return false;
|
|
83
|
-
}
|
|
84
|
-
return !(a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && (b === 168 || b === 0) || a === 198 && (b === 18 || b === 19) || a >= 224);
|
|
85
|
-
}
|
|
86
|
-
return isIP(address) === 6 && /^[23][0-9a-f]{3}:/i.test(address) && !address.toLowerCase().startsWith("2001:db8:");
|
|
87
|
-
};
|
|
88
|
-
validateCallbackUrl = (value, hosts) => {
|
|
89
|
-
const url = new URL(value);
|
|
90
|
-
if (url.protocol !== "https:" || url.username || url.password || url.port || url.hash || !hosts.includes(url.hostname) || isIP(url.hostname)) {
|
|
91
|
-
throw new ApiError(
|
|
92
|
-
"invalid_request",
|
|
93
|
-
"Callback URL must use an approved HTTPS host and default port"
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
return url;
|
|
97
|
-
};
|
|
98
|
-
deliverCallback = async (url, { rawBody, signature }) => {
|
|
99
|
-
const controller = new AbortController();
|
|
100
|
-
const deadline = new Promise((_resolve, reject) => {
|
|
101
|
-
controller.signal.addEventListener(
|
|
102
|
-
"abort",
|
|
103
|
-
() => {
|
|
104
|
-
reject(new Error(`Callback delivery timed out for ${url.hostname}.`));
|
|
105
|
-
},
|
|
106
|
-
{ once: true }
|
|
107
|
-
);
|
|
108
|
-
});
|
|
109
|
-
const timeout = setTimeout(() => {
|
|
110
|
-
controller.abort();
|
|
111
|
-
}, deliveryTimeoutMs);
|
|
112
|
-
try {
|
|
113
|
-
const addresses = await Promise.race([
|
|
114
|
-
lookup(url.hostname, { all: true }),
|
|
115
|
-
deadline
|
|
116
|
-
]);
|
|
117
|
-
const [pinned] = addresses;
|
|
118
|
-
if (!pinned || addresses.some(({ address }) => !isPublicAddress(address))) {
|
|
119
|
-
throw new Error(
|
|
120
|
-
`Callback DNS must resolve only to public addresses: ${url.hostname}.`
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
await new Promise((resolve, reject) => {
|
|
124
|
-
const req = httpsRequest(
|
|
125
|
-
url,
|
|
126
|
-
{
|
|
127
|
-
method: "POST",
|
|
128
|
-
headers: {
|
|
129
|
-
"content-type": "application/json",
|
|
130
|
-
"content-length": Buffer.byteLength(rawBody),
|
|
131
|
-
"x-aeo-signature": signature
|
|
132
|
-
},
|
|
133
|
-
lookup: (_host, options, callback) => {
|
|
134
|
-
if (options.all) {
|
|
135
|
-
callback(null, [pinned]);
|
|
136
|
-
} else {
|
|
137
|
-
callback(null, pinned.address, pinned.family);
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
signal: controller.signal
|
|
141
|
-
},
|
|
142
|
-
(res) => {
|
|
143
|
-
res.resume();
|
|
144
|
-
if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
|
|
145
|
-
resolve();
|
|
146
|
-
} else {
|
|
147
|
-
reject(
|
|
148
|
-
new Error(
|
|
149
|
-
`Callback delivery returned HTTP ${res.statusCode ?? "without a status"}.`
|
|
150
|
-
)
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
);
|
|
155
|
-
req.once("error", reject);
|
|
156
|
-
req.end(rawBody);
|
|
157
|
-
});
|
|
158
|
-
} finally {
|
|
159
|
-
clearTimeout(timeout);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
3
|
|
|
165
4
|
// src/codex-workflow/author-tools-server.ts
|
|
166
5
|
import { appendFile as appendFile2, mkdir as mkdir3 } from "node:fs/promises";
|
|
@@ -205,11 +44,242 @@ var contentHash = (value) => {
|
|
|
205
44
|
};
|
|
206
45
|
|
|
207
46
|
// src/grounding/fetch.ts
|
|
208
|
-
import { lookup as lookup2 } from "node:dns/promises";
|
|
209
|
-
import { isIP as isIP2 } from "node:net";
|
|
210
|
-
import { request } from "node:https";
|
|
211
47
|
import { load } from "cheerio";
|
|
212
|
-
|
|
48
|
+
|
|
49
|
+
// src/grounding/guarded-request.ts
|
|
50
|
+
import { lookup } from "node:dns/promises";
|
|
51
|
+
import { request } from "node:https";
|
|
52
|
+
import { isIP as isIP2 } from "node:net";
|
|
53
|
+
|
|
54
|
+
// src/workflow/callbacks.ts
|
|
55
|
+
import { isIP } from "node:net";
|
|
56
|
+
var isPublicAddress = (address) => {
|
|
57
|
+
if (isIP(address) === 4) {
|
|
58
|
+
const [a, b] = address.split(".").map(Number);
|
|
59
|
+
if (a === void 0 || b === void 0) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
return !(a === 0 || a === 10 || a === 127 || a === 100 && b >= 64 && b <= 127 || a === 169 && b === 254 || a === 172 && b >= 16 && b <= 31 || a === 192 && (b === 168 || b === 0) || a === 198 && (b === 18 || b === 19) || a >= 224);
|
|
63
|
+
}
|
|
64
|
+
return isIP(address) === 6 && /^[23][0-9a-f]{3}:/i.test(address) && !address.toLowerCase().startsWith("2001:db8:");
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// src/grounding/guarded-request.ts
|
|
68
|
+
var SourceRetrievalError = class extends Error {
|
|
69
|
+
reason;
|
|
70
|
+
status;
|
|
71
|
+
constructor(reason, message, { status, cause } = {}) {
|
|
72
|
+
super(message, cause === void 0 ? void 0 : { cause });
|
|
73
|
+
this.name = "SourceRetrievalError";
|
|
74
|
+
this.reason = reason;
|
|
75
|
+
this.status = status;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
var validateResearchUrl = (value) => {
|
|
79
|
+
let url;
|
|
80
|
+
try {
|
|
81
|
+
url = new URL(value);
|
|
82
|
+
} catch {
|
|
83
|
+
throw new SourceRetrievalError(
|
|
84
|
+
"unsafe_destination",
|
|
85
|
+
`Invalid source URL: ${value}.`
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
if (url.protocol !== "https:" || url.username || url.password || url.port || url.hostname === "localhost" || url.hostname.endsWith(".localhost") || url.hostname.endsWith(".local") || url.hostname.endsWith(".internal") || url.hostname === "metadata.google.internal") {
|
|
89
|
+
throw new SourceRetrievalError(
|
|
90
|
+
"unsafe_destination",
|
|
91
|
+
`Source must use public HTTPS with no credentials: ${url.hostname}.`
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
95
|
+
if (isIP2(host) && !isPublicAddress(host)) {
|
|
96
|
+
throw new SourceRetrievalError(
|
|
97
|
+
"unsafe_destination",
|
|
98
|
+
`Private source destination: ${host}.`
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
url.hash = "";
|
|
102
|
+
return url;
|
|
103
|
+
};
|
|
104
|
+
var withAbort = (promise, signal) => {
|
|
105
|
+
signal.throwIfAborted();
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
const aborted = () => {
|
|
108
|
+
reject(signal.reason);
|
|
109
|
+
};
|
|
110
|
+
signal.addEventListener("abort", aborted, { once: true });
|
|
111
|
+
promise.then(resolve, reject).finally(() => {
|
|
112
|
+
signal.removeEventListener("abort", aborted);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
var lookupAll = (host) => {
|
|
117
|
+
return lookup(host, { all: true });
|
|
118
|
+
};
|
|
119
|
+
var resolvePublicAddress = async (hostname, signal, lookupHost = lookupAll) => {
|
|
120
|
+
const host = hostname.replace(/^\[|\]$/g, "");
|
|
121
|
+
const addresses = await withAbort(lookupHost(host), signal);
|
|
122
|
+
if (addresses.length === 0 || addresses.some(({ address }) => !isPublicAddress(address))) {
|
|
123
|
+
throw new SourceRetrievalError(
|
|
124
|
+
"unsafe_destination",
|
|
125
|
+
`Source DNS must resolve exclusively to public addresses: ${host}.`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
const [firstAddress] = addresses;
|
|
129
|
+
if (!firstAddress) {
|
|
130
|
+
throw new SourceRetrievalError(
|
|
131
|
+
"unsafe_destination",
|
|
132
|
+
`Source DNS returned no address: ${host}.`
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
return firstAddress;
|
|
136
|
+
};
|
|
137
|
+
var isRedirect = (status) => {
|
|
138
|
+
return status >= 300 && status < 400;
|
|
139
|
+
};
|
|
140
|
+
var isSuccess = (status) => {
|
|
141
|
+
return status >= 200 && status < 300;
|
|
142
|
+
};
|
|
143
|
+
var requestHop = async (url, options, signal) => {
|
|
144
|
+
const address = await resolvePublicAddress(url.hostname, signal);
|
|
145
|
+
signal.throwIfAborted();
|
|
146
|
+
return new Promise((resolve, reject) => {
|
|
147
|
+
const req = request(
|
|
148
|
+
url,
|
|
149
|
+
{
|
|
150
|
+
method: "GET",
|
|
151
|
+
signal,
|
|
152
|
+
headers: {
|
|
153
|
+
"accept": options.accept,
|
|
154
|
+
// Never a compressed body: nothing to decompress, so no bomb to
|
|
155
|
+
// bound. An encoded body despite this is refused below.
|
|
156
|
+
"accept-encoding": "identity",
|
|
157
|
+
"user-agent": options.userAgent
|
|
158
|
+
},
|
|
159
|
+
lookup: (_host, lookupOptions, callback) => {
|
|
160
|
+
if (lookupOptions.all) {
|
|
161
|
+
callback(null, [address]);
|
|
162
|
+
} else {
|
|
163
|
+
callback(null, address.address, address.family);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
(response) => {
|
|
168
|
+
const status = response.statusCode ?? 0;
|
|
169
|
+
const contentType = response.headers["content-type"] ?? "";
|
|
170
|
+
const encoding = response.headers["content-encoding"];
|
|
171
|
+
const policy = options.body;
|
|
172
|
+
const settle = (body, isTruncated) => {
|
|
173
|
+
resolve({
|
|
174
|
+
status,
|
|
175
|
+
location: response.headers.location,
|
|
176
|
+
contentType,
|
|
177
|
+
body,
|
|
178
|
+
isTruncated
|
|
179
|
+
});
|
|
180
|
+
};
|
|
181
|
+
if (!policy || !isSuccess(status)) {
|
|
182
|
+
response.destroy();
|
|
183
|
+
settle(void 0, false);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (policy.contentTypes !== "any" && !policy.contentTypes.test(contentType) || encoding && encoding !== "identity") {
|
|
187
|
+
response.destroy();
|
|
188
|
+
reject(
|
|
189
|
+
new SourceRetrievalError(
|
|
190
|
+
"unsupported_content",
|
|
191
|
+
`Unsupported source content: ${contentType}.`
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const chunks = [];
|
|
197
|
+
let bytes = 0;
|
|
198
|
+
response.on("data", (chunk) => {
|
|
199
|
+
bytes += chunk.length;
|
|
200
|
+
if (bytes <= policy.maxBytes) {
|
|
201
|
+
chunks.push(chunk);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
response.destroy();
|
|
205
|
+
if (policy.oversize === "refuse") {
|
|
206
|
+
reject(
|
|
207
|
+
new SourceRetrievalError(
|
|
208
|
+
"too_large",
|
|
209
|
+
`Source response exceeds byte limit: ${bytes} bytes.`
|
|
210
|
+
)
|
|
211
|
+
);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
const kept = Buffer.concat(chunks);
|
|
215
|
+
settle(
|
|
216
|
+
Buffer.concat([
|
|
217
|
+
kept,
|
|
218
|
+
chunk.subarray(0, policy.maxBytes - kept.length)
|
|
219
|
+
]),
|
|
220
|
+
true
|
|
221
|
+
);
|
|
222
|
+
});
|
|
223
|
+
response.once("error", reject);
|
|
224
|
+
response.once("end", () => {
|
|
225
|
+
settle(Buffer.concat(chunks), false);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
req.once("error", reject);
|
|
230
|
+
req.end();
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
var guardedRequest = async (options) => {
|
|
234
|
+
const pace = options.pace ?? ((_url, send2) => send2());
|
|
235
|
+
const hops = [];
|
|
236
|
+
let url = validateResearchUrl(options.url);
|
|
237
|
+
let hopSignal;
|
|
238
|
+
try {
|
|
239
|
+
for (let redirects = 0; ; redirects += 1) {
|
|
240
|
+
const target = url;
|
|
241
|
+
const response = await pace(target, () => {
|
|
242
|
+
options.signal?.throwIfAborted();
|
|
243
|
+
const signal = AbortSignal.any([
|
|
244
|
+
AbortSignal.timeout(options.timeoutInMs),
|
|
245
|
+
...options.signal ? [options.signal] : []
|
|
246
|
+
]);
|
|
247
|
+
hopSignal = signal;
|
|
248
|
+
return requestHop(target, options, signal);
|
|
249
|
+
});
|
|
250
|
+
hops.push({ url: target.href, status: response.status });
|
|
251
|
+
if (!isRedirect(response.status)) {
|
|
252
|
+
const { location: _location, ...final } = response;
|
|
253
|
+
return { ...final, url: target.href, hops };
|
|
254
|
+
}
|
|
255
|
+
if (!response.location) {
|
|
256
|
+
throw new SourceRetrievalError(
|
|
257
|
+
"http_error",
|
|
258
|
+
`Source redirect without a location: ${target.href}.`
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
if (redirects === options.redirects) {
|
|
262
|
+
throw new SourceRetrievalError(
|
|
263
|
+
"http_error",
|
|
264
|
+
`Source redirect limit exceeded: ${target.href}.`
|
|
265
|
+
);
|
|
266
|
+
}
|
|
267
|
+
url = validateResearchUrl(new URL(response.location, target).href);
|
|
268
|
+
}
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (options.signal?.aborted) {
|
|
271
|
+
throw options.signal.reason;
|
|
272
|
+
}
|
|
273
|
+
if (error instanceof SourceRetrievalError) {
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
throw new SourceRetrievalError(
|
|
277
|
+
hopSignal?.aborted ? "timeout" : "network_error",
|
|
278
|
+
`Source retrieval failed: ${url.href}.`,
|
|
279
|
+
{ cause: error }
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
};
|
|
213
283
|
|
|
214
284
|
// src/grounding/schema.ts
|
|
215
285
|
import { z } from "zod";
|
|
@@ -423,42 +493,6 @@ var sourceLimits = {
|
|
|
423
493
|
retainedBytes: 16384,
|
|
424
494
|
redirects: 3
|
|
425
495
|
};
|
|
426
|
-
var SourceRetrievalError = class extends Error {
|
|
427
|
-
reason;
|
|
428
|
-
status;
|
|
429
|
-
constructor(reason, message, { status, cause } = {}) {
|
|
430
|
-
super(message, cause === void 0 ? void 0 : { cause });
|
|
431
|
-
this.name = "SourceRetrievalError";
|
|
432
|
-
this.reason = reason;
|
|
433
|
-
this.status = status;
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
var validateResearchUrl = (value) => {
|
|
437
|
-
let url;
|
|
438
|
-
try {
|
|
439
|
-
url = new URL(value);
|
|
440
|
-
} catch {
|
|
441
|
-
throw new SourceRetrievalError(
|
|
442
|
-
"unsafe_destination",
|
|
443
|
-
`Invalid source URL: ${value}.`
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
|
-
if (url.protocol !== "https:" || url.username || url.password || url.port || url.hostname === "localhost" || url.hostname.endsWith(".localhost") || url.hostname.endsWith(".local") || url.hostname.endsWith(".internal") || url.hostname === "metadata.google.internal") {
|
|
447
|
-
throw new SourceRetrievalError(
|
|
448
|
-
"unsafe_destination",
|
|
449
|
-
`Source must use public HTTPS with no credentials: ${url.hostname}.`
|
|
450
|
-
);
|
|
451
|
-
}
|
|
452
|
-
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
453
|
-
if (isIP2(host) && !isPublicAddress(host)) {
|
|
454
|
-
throw new SourceRetrievalError(
|
|
455
|
-
"unsafe_destination",
|
|
456
|
-
`Private source destination: ${host}.`
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
url.hash = "";
|
|
460
|
-
return url;
|
|
461
|
-
};
|
|
462
496
|
var canonicalResearchUrl = (value) => {
|
|
463
497
|
const url = new URL(value);
|
|
464
498
|
url.hash = "";
|
|
@@ -468,118 +502,6 @@ var canonicalResearchUrl = (value) => {
|
|
|
468
502
|
}
|
|
469
503
|
return url.href;
|
|
470
504
|
};
|
|
471
|
-
var withAbort = (promise, signal) => {
|
|
472
|
-
signal.throwIfAborted();
|
|
473
|
-
return new Promise((resolve, reject) => {
|
|
474
|
-
const aborted = () => {
|
|
475
|
-
reject(signal.reason);
|
|
476
|
-
};
|
|
477
|
-
signal.addEventListener("abort", aborted, { once: true });
|
|
478
|
-
promise.then(resolve, reject).finally(() => {
|
|
479
|
-
signal.removeEventListener("abort", aborted);
|
|
480
|
-
});
|
|
481
|
-
});
|
|
482
|
-
};
|
|
483
|
-
var requestDocument = async (url, signal) => {
|
|
484
|
-
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
485
|
-
const addresses = await withAbort(lookup2(host, { all: true }), signal);
|
|
486
|
-
if (addresses.length === 0 || addresses.some(({ address }) => !isPublicAddress(address))) {
|
|
487
|
-
throw new SourceRetrievalError(
|
|
488
|
-
"unsafe_destination",
|
|
489
|
-
`Source DNS must resolve exclusively to public addresses: ${host}.`
|
|
490
|
-
);
|
|
491
|
-
}
|
|
492
|
-
const [firstAddress] = addresses;
|
|
493
|
-
if (!firstAddress) {
|
|
494
|
-
throw new SourceRetrievalError(
|
|
495
|
-
"unsafe_destination",
|
|
496
|
-
`Source DNS returned no address: ${host}.`
|
|
497
|
-
);
|
|
498
|
-
}
|
|
499
|
-
signal.throwIfAborted();
|
|
500
|
-
return new Promise((resolve, reject) => {
|
|
501
|
-
const req = request(
|
|
502
|
-
url,
|
|
503
|
-
{
|
|
504
|
-
method: "GET",
|
|
505
|
-
signal,
|
|
506
|
-
headers: {
|
|
507
|
-
"accept": "text/html,text/plain",
|
|
508
|
-
"accept-encoding": "identity",
|
|
509
|
-
"user-agent": "Literally-AEO-Research/1"
|
|
510
|
-
},
|
|
511
|
-
lookup: (_host, options, callback) => {
|
|
512
|
-
if (options.all) {
|
|
513
|
-
callback(null, [firstAddress]);
|
|
514
|
-
} else {
|
|
515
|
-
callback(null, firstAddress.address, firstAddress.family);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
},
|
|
519
|
-
(response) => {
|
|
520
|
-
const status = response.statusCode ?? 0;
|
|
521
|
-
const contentType = response.headers["content-type"] ?? "";
|
|
522
|
-
if (status >= 300 && status < 400) {
|
|
523
|
-
response.destroy();
|
|
524
|
-
resolve({
|
|
525
|
-
status,
|
|
526
|
-
location: response.headers.location,
|
|
527
|
-
contentType,
|
|
528
|
-
body: ""
|
|
529
|
-
});
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
if (status < 200 || status >= 300) {
|
|
533
|
-
response.destroy();
|
|
534
|
-
reject(
|
|
535
|
-
new SourceRetrievalError("http_error", `Source HTTP ${status}.`, {
|
|
536
|
-
status
|
|
537
|
-
})
|
|
538
|
-
);
|
|
539
|
-
return;
|
|
540
|
-
}
|
|
541
|
-
if (!/^(text\/html|text\/plain|application\/xhtml\+xml)(;|$)/i.test(
|
|
542
|
-
contentType
|
|
543
|
-
) || response.headers["content-encoding"] && response.headers["content-encoding"] !== "identity") {
|
|
544
|
-
response.destroy();
|
|
545
|
-
reject(
|
|
546
|
-
new SourceRetrievalError(
|
|
547
|
-
"unsupported_content",
|
|
548
|
-
`Unsupported source content: ${contentType}.`
|
|
549
|
-
)
|
|
550
|
-
);
|
|
551
|
-
return;
|
|
552
|
-
}
|
|
553
|
-
const chunks = [];
|
|
554
|
-
let bytes = 0;
|
|
555
|
-
response.on("data", (chunk) => {
|
|
556
|
-
bytes += chunk.length;
|
|
557
|
-
if (bytes > sourceLimits.receivedBytes) {
|
|
558
|
-
response.destroy();
|
|
559
|
-
reject(
|
|
560
|
-
new SourceRetrievalError(
|
|
561
|
-
"too_large",
|
|
562
|
-
`Source response exceeds byte limit: ${bytes} bytes.`
|
|
563
|
-
)
|
|
564
|
-
);
|
|
565
|
-
return;
|
|
566
|
-
}
|
|
567
|
-
chunks.push(chunk);
|
|
568
|
-
});
|
|
569
|
-
response.once("error", reject);
|
|
570
|
-
response.once("end", () => {
|
|
571
|
-
resolve({
|
|
572
|
-
status,
|
|
573
|
-
contentType,
|
|
574
|
-
body: Buffer.concat(chunks).toString("utf8")
|
|
575
|
-
});
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
);
|
|
579
|
-
req.once("error", reject);
|
|
580
|
-
req.end();
|
|
581
|
-
});
|
|
582
|
-
};
|
|
583
505
|
var boundedUtf8 = (text, bytes) => {
|
|
584
506
|
return Buffer.from(text).subarray(0, bytes).toString("utf8").replace(/\uFFFD$/, "");
|
|
585
507
|
};
|
|
@@ -659,56 +581,44 @@ var extractSourceDocument = (args) => {
|
|
|
659
581
|
};
|
|
660
582
|
};
|
|
661
583
|
var fetchGroundingSource = async (args) => {
|
|
662
|
-
const
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
584
|
+
const response = await guardedRequest({
|
|
585
|
+
url: args.url,
|
|
586
|
+
timeoutInMs: sourceLimits.timeoutMs,
|
|
587
|
+
signal: args.signal,
|
|
588
|
+
userAgent: "Literally-AEO-Research/1",
|
|
589
|
+
accept: "text/html,text/plain",
|
|
590
|
+
redirects: sourceLimits.redirects,
|
|
591
|
+
body: {
|
|
592
|
+
contentTypes: /^(text\/html|text\/plain|application\/xhtml\+xml)(;|$)/i,
|
|
593
|
+
maxBytes: sourceLimits.receivedBytes,
|
|
594
|
+
oversize: "refuse"
|
|
595
|
+
},
|
|
596
|
+
pace: async (_url, send2) => {
|
|
669
597
|
await args.beforeRequest?.();
|
|
670
|
-
|
|
671
|
-
const response = await requestDocument(url, signal);
|
|
672
|
-
if (response.status >= 300 && response.status < 400) {
|
|
673
|
-
if (!response.location || redirects === sourceLimits.redirects) {
|
|
674
|
-
throw new SourceRetrievalError(
|
|
675
|
-
"http_error",
|
|
676
|
-
`Source redirect limit exceeded: ${url.href}.`
|
|
677
|
-
);
|
|
678
|
-
}
|
|
679
|
-
url = validateResearchUrl(new URL(response.location, url).href);
|
|
680
|
-
continue;
|
|
681
|
-
}
|
|
682
|
-
return {
|
|
683
|
-
...extractSourceDocument({
|
|
684
|
-
requestedUrl: args.url,
|
|
685
|
-
finalUrl: url.href,
|
|
686
|
-
body: response.body,
|
|
687
|
-
contentType: response.contentType,
|
|
688
|
-
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
689
|
-
firstPartyHosts: args.firstPartyHosts
|
|
690
|
-
}),
|
|
691
|
-
requestCount: redirects + 1,
|
|
692
|
-
bytes: Buffer.byteLength(response.body)
|
|
693
|
-
};
|
|
598
|
+
return send2();
|
|
694
599
|
}
|
|
600
|
+
});
|
|
601
|
+
if (response.status < 200 || response.status >= 300) {
|
|
695
602
|
throw new SourceRetrievalError(
|
|
696
603
|
"http_error",
|
|
697
|
-
`Source
|
|
698
|
-
|
|
699
|
-
} catch (error) {
|
|
700
|
-
if (args.signal?.aborted) {
|
|
701
|
-
throw args.signal.reason;
|
|
702
|
-
}
|
|
703
|
-
if (error instanceof SourceRetrievalError) {
|
|
704
|
-
throw error;
|
|
705
|
-
}
|
|
706
|
-
throw new SourceRetrievalError(
|
|
707
|
-
signal.aborted ? "timeout" : "network_error",
|
|
708
|
-
`Source retrieval failed: ${url.href}.`,
|
|
709
|
-
{ cause: error }
|
|
604
|
+
`Source HTTP ${response.status}.`,
|
|
605
|
+
{ status: response.status }
|
|
710
606
|
);
|
|
711
607
|
}
|
|
608
|
+
const body = response.body?.toString("utf8") ?? "";
|
|
609
|
+
const document = extractSourceDocument({
|
|
610
|
+
requestedUrl: args.url,
|
|
611
|
+
finalUrl: response.url,
|
|
612
|
+
body,
|
|
613
|
+
contentType: response.contentType,
|
|
614
|
+
fetchedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
615
|
+
firstPartyHosts: args.firstPartyHosts
|
|
616
|
+
});
|
|
617
|
+
return {
|
|
618
|
+
...document,
|
|
619
|
+
requestCount: response.hops.length,
|
|
620
|
+
bytes: Buffer.byteLength(body)
|
|
621
|
+
};
|
|
712
622
|
};
|
|
713
623
|
|
|
714
624
|
// src/grounding/tools.ts
|
|
@@ -947,6 +857,178 @@ import path2 from "node:path";
|
|
|
947
857
|
import { setTimeout as delay } from "node:timers/promises";
|
|
948
858
|
import { z as z17 } from "zod";
|
|
949
859
|
|
|
860
|
+
// src/grounding/chromium-guard.ts
|
|
861
|
+
import { createServer } from "node:http";
|
|
862
|
+
import { connect } from "node:net";
|
|
863
|
+
var connectTimeoutInMs = 15e3;
|
|
864
|
+
var dialPublicAddress = (address) => {
|
|
865
|
+
return connect({ host: address.address, port: 443, family: address.family });
|
|
866
|
+
};
|
|
867
|
+
var toConnectTarget = (authority) => {
|
|
868
|
+
const separator = authority.lastIndexOf(":");
|
|
869
|
+
if (separator < 0 || authority.slice(separator + 1) !== "443") {
|
|
870
|
+
return void 0;
|
|
871
|
+
}
|
|
872
|
+
try {
|
|
873
|
+
return validateResearchUrl(`https://${authority.slice(0, separator)}/`);
|
|
874
|
+
} catch {
|
|
875
|
+
return void 0;
|
|
876
|
+
}
|
|
877
|
+
};
|
|
878
|
+
var startGuardingProxy = async (options = {}) => {
|
|
879
|
+
const { lookupHost, dial = dialPublicAddress } = options;
|
|
880
|
+
const counts = { allowed: 0, refused: 0 };
|
|
881
|
+
const sockets = /* @__PURE__ */ new Set();
|
|
882
|
+
const refuse = (client) => {
|
|
883
|
+
counts.refused += 1;
|
|
884
|
+
client.end("HTTP/1.1 403 Forbidden\r\n\r\n");
|
|
885
|
+
};
|
|
886
|
+
const server = createServer((_request, response) => {
|
|
887
|
+
counts.refused += 1;
|
|
888
|
+
response.writeHead(403).end();
|
|
889
|
+
});
|
|
890
|
+
const tunnel = async (authority, client, head) => {
|
|
891
|
+
const target = toConnectTarget(authority);
|
|
892
|
+
if (!target) {
|
|
893
|
+
refuse(client);
|
|
894
|
+
return;
|
|
895
|
+
}
|
|
896
|
+
let address2;
|
|
897
|
+
try {
|
|
898
|
+
address2 = await resolvePublicAddress(
|
|
899
|
+
target.hostname,
|
|
900
|
+
AbortSignal.timeout(connectTimeoutInMs),
|
|
901
|
+
lookupHost
|
|
902
|
+
);
|
|
903
|
+
} catch {
|
|
904
|
+
refuse(client);
|
|
905
|
+
return;
|
|
906
|
+
}
|
|
907
|
+
counts.allowed += 1;
|
|
908
|
+
const upstream = dial(address2);
|
|
909
|
+
sockets.add(upstream);
|
|
910
|
+
upstream.setTimeout(connectTimeoutInMs, () => {
|
|
911
|
+
upstream.destroy();
|
|
912
|
+
});
|
|
913
|
+
upstream.once("connect", () => {
|
|
914
|
+
upstream.setTimeout(0);
|
|
915
|
+
client.write("HTTP/1.1 200 Connection Established\r\n\r\n");
|
|
916
|
+
upstream.write(head);
|
|
917
|
+
upstream.pipe(client);
|
|
918
|
+
client.pipe(upstream);
|
|
919
|
+
});
|
|
920
|
+
upstream.once("error", () => {
|
|
921
|
+
client.end("HTTP/1.1 502 Bad Gateway\r\n\r\n");
|
|
922
|
+
});
|
|
923
|
+
upstream.once("close", () => {
|
|
924
|
+
sockets.delete(upstream);
|
|
925
|
+
client.destroy();
|
|
926
|
+
});
|
|
927
|
+
client.once("close", () => {
|
|
928
|
+
upstream.destroy();
|
|
929
|
+
});
|
|
930
|
+
};
|
|
931
|
+
server.on("connection", (socket) => {
|
|
932
|
+
sockets.add(socket);
|
|
933
|
+
socket.once("close", () => {
|
|
934
|
+
sockets.delete(socket);
|
|
935
|
+
});
|
|
936
|
+
});
|
|
937
|
+
server.on("connect", (request2, client, head) => {
|
|
938
|
+
client.on("error", () => {
|
|
939
|
+
client.destroy();
|
|
940
|
+
});
|
|
941
|
+
void tunnel(request2.url ?? "", client, head);
|
|
942
|
+
});
|
|
943
|
+
server.on("upgrade", (_request, client) => {
|
|
944
|
+
refuse(client);
|
|
945
|
+
});
|
|
946
|
+
await new Promise((resolve, reject) => {
|
|
947
|
+
server.once("error", reject);
|
|
948
|
+
server.listen(0, "127.0.0.1", resolve);
|
|
949
|
+
});
|
|
950
|
+
const address = server.address();
|
|
951
|
+
if (address === null || typeof address === "string") {
|
|
952
|
+
throw new Error("The guarding proxy did not bind a TCP port.");
|
|
953
|
+
}
|
|
954
|
+
return {
|
|
955
|
+
server: `http://127.0.0.1:${address.port}`,
|
|
956
|
+
counts: () => ({ ...counts }),
|
|
957
|
+
close: async () => {
|
|
958
|
+
for (const socket of sockets) {
|
|
959
|
+
socket.destroy();
|
|
960
|
+
}
|
|
961
|
+
await new Promise((resolve) => {
|
|
962
|
+
server.close(() => {
|
|
963
|
+
resolve();
|
|
964
|
+
});
|
|
965
|
+
});
|
|
966
|
+
}
|
|
967
|
+
};
|
|
968
|
+
};
|
|
969
|
+
var chromiumArgs = [
|
|
970
|
+
// Playwright proxies loopback too unless an environment variable turns
|
|
971
|
+
// that off; this flag comes last and keeps it on regardless.
|
|
972
|
+
"--proxy-bypass-list=<-loopback>",
|
|
973
|
+
// QUIC and WebRTC over UDP would leave beside an HTTP proxy.
|
|
974
|
+
"--disable-quic",
|
|
975
|
+
"--force-webrtc-ip-handling-policy=disable_non_proxied_udp"
|
|
976
|
+
];
|
|
977
|
+
var isAllowedRequest = (request2) => {
|
|
978
|
+
const url = new URL(request2.url());
|
|
979
|
+
return url.protocol === "https:" && url.port === "" && request2.resourceType() !== "media";
|
|
980
|
+
};
|
|
981
|
+
var withBoundedPage = async (context, deadlineInMs, use) => {
|
|
982
|
+
const page = await context.newPage();
|
|
983
|
+
const deadline = AbortSignal.timeout(deadlineInMs);
|
|
984
|
+
const closePage = () => {
|
|
985
|
+
void page.close().catch(() => void 0);
|
|
986
|
+
};
|
|
987
|
+
deadline.addEventListener("abort", closePage, { once: true });
|
|
988
|
+
try {
|
|
989
|
+
return await use(page);
|
|
990
|
+
} catch (error) {
|
|
991
|
+
if (deadline.aborted) {
|
|
992
|
+
throw new Error(
|
|
993
|
+
`The page did not finish rendering within ${deadlineInMs / 1e3} s.`,
|
|
994
|
+
{ cause: error }
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
throw error;
|
|
998
|
+
} finally {
|
|
999
|
+
deadline.removeEventListener("abort", closePage);
|
|
1000
|
+
await page.close();
|
|
1001
|
+
}
|
|
1002
|
+
};
|
|
1003
|
+
var withGuardedChromium = async (use, options = {}) => {
|
|
1004
|
+
const proxy = await startGuardingProxy(options.proxy);
|
|
1005
|
+
try {
|
|
1006
|
+
const { chromium } = await import("playwright");
|
|
1007
|
+
const browser = await chromium.launch({
|
|
1008
|
+
proxy: { server: proxy.server },
|
|
1009
|
+
args: chromiumArgs
|
|
1010
|
+
});
|
|
1011
|
+
try {
|
|
1012
|
+
const context = await browser.newContext({
|
|
1013
|
+
acceptDownloads: false,
|
|
1014
|
+
serviceWorkers: "block",
|
|
1015
|
+
...options.userAgent !== void 0 && {
|
|
1016
|
+
userAgent: options.userAgent
|
|
1017
|
+
}
|
|
1018
|
+
});
|
|
1019
|
+
await context.route("**/*", (route) => {
|
|
1020
|
+
return isAllowedRequest(route.request()) ? route.continue() : route.abort();
|
|
1021
|
+
});
|
|
1022
|
+
const result = await use(context);
|
|
1023
|
+
return { result, connections: proxy.counts() };
|
|
1024
|
+
} finally {
|
|
1025
|
+
await browser.close();
|
|
1026
|
+
}
|
|
1027
|
+
} finally {
|
|
1028
|
+
await proxy.close();
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
|
|
950
1032
|
// src/codex-workflow/pending.ts
|
|
951
1033
|
import { randomUUID } from "node:crypto";
|
|
952
1034
|
import { mkdir, rename, rm, writeFile } from "node:fs/promises";
|
|
@@ -1435,6 +1517,10 @@ var aeoTechnicalChecksSchema = z6.object({
|
|
|
1435
1517
|
robotsUrl: z6.string(),
|
|
1436
1518
|
fetchedAt: z6.string(),
|
|
1437
1519
|
robotsFetchError: z6.string().nullable(),
|
|
1520
|
+
// True when robots.txt ran past the 500 KiB RFC 9309 asks a reader to
|
|
1521
|
+
// parse: the verdicts rest on that prefix. Absent on snapshots written
|
|
1522
|
+
// before the bound existed.
|
|
1523
|
+
robotsTruncated: z6.boolean().optional(),
|
|
1438
1524
|
bots: z6.array(
|
|
1439
1525
|
z6.object({
|
|
1440
1526
|
bot: z6.string(),
|
|
@@ -1799,7 +1885,6 @@ var clientReportBundleSchema = z11.discriminatedUnion("state", [
|
|
|
1799
1885
|
|
|
1800
1886
|
// src/access/schema.ts
|
|
1801
1887
|
import { z as z12 } from "zod";
|
|
1802
|
-
init_errors();
|
|
1803
1888
|
var identity = z12.string().min(1).max(128).regex(/^[a-zA-Z0-9_-]+$/);
|
|
1804
1889
|
var reportAudienceSchema = z12.enum([
|
|
1805
1890
|
"client_private",
|
|
@@ -1961,14 +2046,17 @@ var aeoSectionConfigSchema = z14.object({
|
|
|
1961
2046
|
// markets. Omitted → the report-level set (the union shown on the page).
|
|
1962
2047
|
competitors: z14.array(brandSchema).optional()
|
|
1963
2048
|
});
|
|
2049
|
+
var maxRunsPerPrompt = 25;
|
|
2050
|
+
var runsPerPromptSchema = z14.number().int().min(1).max(maxRunsPerPrompt);
|
|
1964
2051
|
var agentProbeConfigSchema = z14.object({
|
|
1965
2052
|
// Runs per prompt per agent surface.
|
|
1966
|
-
runsPerPrompt:
|
|
2053
|
+
runsPerPrompt: runsPerPromptSchema.default(2),
|
|
1967
2054
|
// Cap on how many of each section's prompts get agent probes — the FIRST N
|
|
1968
2055
|
// prompts in config order, so the subset is stable across runs. Omitted =
|
|
1969
2056
|
// all prompts.
|
|
1970
2057
|
maxPromptsPerSection: z14.number().int().min(1).optional()
|
|
1971
2058
|
});
|
|
2059
|
+
var chatProbeConfigSchema = z14.object({ runsPerPrompt: runsPerPromptSchema }).strict();
|
|
1972
2060
|
var ownedCompetitorDomainSchema = z14.string().trim().regex(
|
|
1973
2061
|
/^(?=.{1,253}$)(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)+[A-Za-z](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.?$/,
|
|
1974
2062
|
"Expected a domain name without a URL, path or port"
|
|
@@ -1991,6 +2079,9 @@ var aeoAuditConfigSchema = z14.object({
|
|
|
1991
2079
|
// the schema — consumers read config.agentProbes directly, no fallbacks.
|
|
1992
2080
|
// prefault({}) runs {} through the inner schema so its own defaults fill.
|
|
1993
2081
|
agentProbes: agentProbeConfigSchema.prefault({}),
|
|
2082
|
+
// Read through runsPerPromptOn or chatRunsPerPrompt, which own the
|
|
2083
|
+
// fallback to the canonical counts.
|
|
2084
|
+
chatProbes: chatProbeConfigSchema.optional(),
|
|
1994
2085
|
// Renderability targets — docs, pricing, comparison pages (§7.4).
|
|
1995
2086
|
moneyPages: z14.array(z14.string().url()),
|
|
1996
2087
|
// Grounds accuracy flagging (§7.2): claims contradicting this brief are
|
|
@@ -2066,8 +2157,14 @@ var authorOutputSchema = aeoAuditConfigSchema.omit({
|
|
|
2066
2157
|
agentReadiness: true,
|
|
2067
2158
|
sourceOverrides: true,
|
|
2068
2159
|
productGrounding: true,
|
|
2069
|
-
competitorQualification: true
|
|
2160
|
+
competitorQualification: true,
|
|
2161
|
+
// Depth decides what a run costs, so the operator sets it in audit.json
|
|
2162
|
+
// with the estimate in front of them, never the author.
|
|
2163
|
+
chatProbes: true
|
|
2070
2164
|
}).extend({
|
|
2165
|
+
// The agent batch the author could always propose: 1 or 2 runs per
|
|
2166
|
+
// prompt. A deeper one is the operator's call, as chat depth is.
|
|
2167
|
+
agentProbes: agentProbeConfigSchema.extend({ runsPerPrompt: z15.number().int().min(1).max(2).default(2) }).prefault({}),
|
|
2071
2168
|
sections: z15.array(
|
|
2072
2169
|
aeoSectionConfigSchema.extend({
|
|
2073
2170
|
key: z15.string().regex(
|
|
@@ -2825,43 +2922,28 @@ var createAuthorTools = (options) => {
|
|
|
2825
2922
|
};
|
|
2826
2923
|
};
|
|
2827
2924
|
var renderWithChromium = async (url, signal) => {
|
|
2828
|
-
|
|
2829
|
-
const {
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2844
|
-
|
|
2845
|
-
|
|
2846
|
-
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
|
|
2850
|
-
return route.continue();
|
|
2851
|
-
});
|
|
2852
|
-
const abort = () => {
|
|
2853
|
-
void page.close().catch(() => void 0);
|
|
2854
|
-
};
|
|
2855
|
-
signal.addEventListener("abort", abort, { once: true });
|
|
2856
|
-
try {
|
|
2857
|
-
await page.goto(url.href, { waitUntil: "networkidle", timeout: 45e3 });
|
|
2858
|
-
return await page.content();
|
|
2859
|
-
} finally {
|
|
2860
|
-
signal.removeEventListener("abort", abort);
|
|
2861
|
-
}
|
|
2862
|
-
} finally {
|
|
2863
|
-
await browser.close();
|
|
2864
|
-
}
|
|
2925
|
+
await resolvePublicAddress(url.hostname, signal);
|
|
2926
|
+
const { result } = await withGuardedChromium(
|
|
2927
|
+
(context) => {
|
|
2928
|
+
return withBoundedPage(context, 6e4, async (page) => {
|
|
2929
|
+
const abort = () => {
|
|
2930
|
+
void page.close().catch(() => void 0);
|
|
2931
|
+
};
|
|
2932
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
2933
|
+
try {
|
|
2934
|
+
await page.goto(url.href, {
|
|
2935
|
+
waitUntil: "networkidle",
|
|
2936
|
+
timeout: 45e3
|
|
2937
|
+
});
|
|
2938
|
+
return await page.content();
|
|
2939
|
+
} finally {
|
|
2940
|
+
signal.removeEventListener("abort", abort);
|
|
2941
|
+
}
|
|
2942
|
+
});
|
|
2943
|
+
},
|
|
2944
|
+
{ userAgent: `${researchUserAgent}/1` }
|
|
2945
|
+
);
|
|
2946
|
+
return result;
|
|
2865
2947
|
};
|
|
2866
2948
|
|
|
2867
2949
|
// src/codex-workflow/author-tools-server.ts
|