refactor(web): share retained text artifact metadata
This commit is contained in:
1 parent
27dc9735e4
commit
c0eb612780
2 files changed
+15
-14
No files matched your search
@@ -9,7 +9,10 @@ import {
|
||||
} from "./browserDeadline.js";
|
||||
import { emptyArraySchema } from "./emptyArraySchema.js";
|
||||
import { inspectWebPageWithSourceInputSchema } from "./browserObservation.js";
|
||||
import { webTextArtifactSchema } from "./webContentArtifact.js";
|
||||
import {
|
||||
webTextArtifactMetadataSchema,
|
||||
webTextArtifactSchema,
|
||||
} from "./webContentArtifact.js";
|
||||
|
||||
/** Isolated analyzer heap used when max_heap_mb is omitted. */
|
||||
export const DEFAULT_WEB_BUNDLE_HEAP_MB = 1024;
|
||||
@@ -298,11 +301,7 @@ const sourceMapSchema = z.union([
|
||||
}),
|
||||
]);
|
||||
|
||||
const webTextArtifactSummarySchema = z.object({
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
bytes: z.number().int().min(0),
|
||||
media_type: z.string().min(1),
|
||||
charset: z.literal("utf-8"),
|
||||
const webTextArtifactSummarySchema = webTextArtifactMetadataSchema.extend({
|
||||
text_available: z.literal(true),
|
||||
});
|
||||
|
||||
|
||||
@@ -2,15 +2,17 @@ import { createHash } from "node:crypto";
|
||||
|
||||
import { z } from "zod";
|
||||
|
||||
/** Metadata shared by complete and summarized retained web text artifacts. */
|
||||
export const webTextArtifactMetadataSchema = z.object({
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
bytes: z.number().int().min(0),
|
||||
media_type: z.string().min(1),
|
||||
charset: z.literal("utf-8"),
|
||||
});
|
||||
|
||||
/** Self-verifying text artifact used by web-source analysis boundaries. */
|
||||
export const webTextArtifactSchema = z
|
||||
.object({
|
||||
sha256: z.string().regex(/^[a-f0-9]{64}$/u),
|
||||
bytes: z.number().int().min(0),
|
||||
media_type: z.string().min(1),
|
||||
charset: z.literal("utf-8"),
|
||||
text: z.string(),
|
||||
})
|
||||
export const webTextArtifactSchema = webTextArtifactMetadataSchema
|
||||
.extend({ text: z.string() })
|
||||
.superRefine((artifact, context) => {
|
||||
const bytes = Buffer.byteLength(artifact.text);
|
||||
const digest = createHash("sha256").update(artifact.text).digest("hex");
|
||||
|
||||
Reference in new issue
Block a user