@enhance-eng/sdk 0.1.161 → 0.1.166

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.
@@ -1,10 +1,10 @@
1
1
  import { z } from "zod";
2
2
  import { z as z$1 } from "zod/mini";
3
- import { link, mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
3
+ import { createReadStream } from "node:fs";
4
4
  import nodePath from "node:path";
5
+ import { link, mkdir, open, readFile, rename, rm, stat, writeFile } from "node:fs/promises";
5
6
  import { createHash } from "node:crypto";
6
7
  import { channel } from "node:diagnostics_channel";
7
- import { createReadStream } from "node:fs";
8
8
  import { pipeline } from "node:stream/promises";
9
9
  const CAPTURE_METADATA_LENGTH = 200;
10
10
  const CAPTURE_FAILURE_LENGTH = 1e3;
@@ -821,9 +821,24 @@ const writeCaptureJson = async (path, value) => {
821
821
  await writeFile(temporary, JSON.stringify(value), { mode: 384 });
822
822
  await rename(temporary, path);
823
823
  };
824
+ const manifestJson = (path, content) => {
825
+ try {
826
+ return JSON.parse(content);
827
+ } catch (error) {
828
+ throw captureError("artifact", `The capture manifest ${path} is not JSON: ${error instanceof Error ? error.message : "it could not be parsed"}.`);
829
+ }
830
+ };
831
+ /**
832
+ * The manifest at `path`. One that is not JSON, or not a capture manifest, throws an artifact
833
+ * error naming the file and the first problem in it, which a caller can report as bad input.
834
+ */
824
835
  const readCaptureManifest = async (path) => {
825
- const raw = JSON.parse(await readFile(path, "utf8"));
826
- return lenientCaptureManifestSchema.parse(raw);
836
+ const content = await readFile(path, "utf8");
837
+ const parsed = lenientCaptureManifestSchema.safeParse(manifestJson(path, content));
838
+ if (parsed.success) return parsed.data;
839
+ const [problem] = parsed.error.issues;
840
+ const field = problem?.path.join(".") ?? "";
841
+ throw captureError("artifact", `The capture manifest ${path} is not valid: ${field === "" ? "" : `${field}: `}${problem?.message ?? "it is not a capture manifest"}`);
827
842
  };
828
843
  //#endregion
829
844
  //#region ../canvas-format/src/canvas-format.consts.ts
@@ -863,8 +878,10 @@ const LEGACY_CANVAS_ADAPTATIONS = {
863
878
  };
864
879
  //#endregion
865
880
  //#region ../canvas-format/src/canvas-edit-support.lib.ts
866
- /** Why the API refused an operation, as a fixed value. Never the words of the refusal. */
881
+ /** Why the API refused a request or one of its operations, as a fixed value. Never its words. */
867
882
  const CANVAS_REFUSAL_CODES = [
883
+ "input-invalid",
884
+ "request-too-large",
868
885
  "appearance-unsupported-component",
869
886
  "styles-unsupported-component",
870
887
  "text-shadow-blend-unsupported",
@@ -1173,6 +1190,96 @@ const adaptCanvasDocumentFormat = (document) => {
1173
1190
  if (document["version"] === LEGACY_CANVAS_FORMATS.v13 || document["version"] === LEGACY_CANVAS_FORMATS.v14) return adapted;
1174
1191
  return withoutTextShadowBlends(document["version"] === LEGACY_CANVAS_FORMATS.v12 ? adapted : adaptCanvasCss(adapted));
1175
1192
  };
1193
+ const isSafeInteger = (value) => Number.isSafeInteger(value);
1194
+ /** A format below 1 names no adaptation, so the walk below refuses it. */
1195
+ const canvasWriterFormat = (version) => {
1196
+ if (!isSafeInteger(version)) return "refused";
1197
+ if (version > 15) return "ahead";
1198
+ if (version === 15) return "current";
1199
+ const adaptations = new Map(Object.entries(LEGACY_CANVAS_ADAPTATIONS).map(([format, kind]) => [Number(format), kind]));
1200
+ for (let format = version; format < 15; format += 1) if (adaptations.get(format) !== "format-number") return "refused";
1201
+ return "number-only";
1202
+ };
1203
+ const objectPictureSizeSchema = z.enum(["quarter", "sixteenth"]);
1204
+ /** One stored picture of one top layer. */
1205
+ const canvasObjectPictureSchema = z.strictObject({
1206
+ objectId: z.string().min(1),
1207
+ size: objectPictureSizeSchema,
1208
+ /** Where the picture's bytes are; what it answers with never changes. */
1209
+ url: z.string().min(1),
1210
+ width: z.number().int().positive(),
1211
+ height: z.number().int().positive(),
1212
+ /** The canvas version the picture was drawn at. */
1213
+ drawnVersion: z.number().int().nonnegative(),
1214
+ /** Whether the top layer is unchanged since the picture was drawn. */
1215
+ isCurrent: z.boolean(),
1216
+ /**
1217
+ * The font size, in pixels, that set the most characters of the top layer's texts when it was
1218
+ * drawn; left out where it held no text, or for a picture drawn before sizes were kept.
1219
+ */
1220
+ textSize: z.number().positive().optional()
1221
+ });
1222
+ z.strictObject({
1223
+ canvasId: z.uuid(),
1224
+ /** Only pictures drawn after this version; every picture when left out. */
1225
+ sinceVersion: z.number().int().nonnegative().optional()
1226
+ });
1227
+ z.object({ pictures: z.array(canvasObjectPictureSchema) });
1228
+ z.strictObject({
1229
+ canvasId: z.uuid(),
1230
+ objectIds: z.array(z.string().min(1)).min(1).max(200)
1231
+ });
1232
+ z.object({ scheduled: z.number().int().nonnegative() });
1233
+ const MAX_PICTURE_STORAGE_KEY_LENGTH = 500;
1234
+ const MAX_PICTURE_FAILURE_LENGTH = 500;
1235
+ /** One top layer a picture job is to draw, with when it was last put on the list. */
1236
+ const objectPictureWorkObjectSchema = z.object({
1237
+ objectId: z.string().min(1),
1238
+ wantedAt: z.iso.datetime()
1239
+ });
1240
+ /** One picture a job drew and uploaded, in pixels of the stored picture. */
1241
+ const drawnObjectPictureSchema = z.object({
1242
+ size: objectPictureSizeSchema,
1243
+ width: z.number().int().positive(),
1244
+ height: z.number().int().positive(),
1245
+ bytes: z.number().int().positive(),
1246
+ storageKey: z.string().min(1).max(MAX_PICTURE_STORAGE_KEY_LENGTH),
1247
+ /** The text size of the top layer the page drew, as the list of pictures gives it. */
1248
+ textSize: z.number().positive().optional()
1249
+ });
1250
+ z.object({
1251
+ jobId: z.uuid(),
1252
+ loadedVersion: z.number().int().positive(),
1253
+ drawn: z.array(objectPictureWorkObjectSchema.extend({ pictures: z.array(drawnObjectPictureSchema).length(2) })).max(20),
1254
+ failed: z.array(z.object({
1255
+ objectId: z.string().min(1),
1256
+ message: z.string().min(1).max(MAX_PICTURE_FAILURE_LENGTH)
1257
+ })).max(20)
1258
+ });
1259
+ const coordinate$1 = z.number();
1260
+ const extent = z.number().nonnegative();
1261
+ /** A box in page coordinates. */
1262
+ const canvasOutlineBoxSchema = z.strictObject({
1263
+ x: coordinate$1,
1264
+ y: coordinate$1,
1265
+ width: extent,
1266
+ height: extent
1267
+ });
1268
+ /** What a browser measured of one top layer: its own box, and how far its descendants paint. */
1269
+ const canvasOutlineMeasurementSchema = z.strictObject({
1270
+ objectId: z.string().min(1),
1271
+ box: canvasOutlineBoxSchema,
1272
+ reach: canvasOutlineBoxSchema
1273
+ });
1274
+ z.strictObject({
1275
+ canvasId: z.uuid(),
1276
+ /** The revision of the document the browser had laid out when it measured. */
1277
+ version: z.number().int().positive(),
1278
+ measurements: z.array(canvasOutlineMeasurementSchema).min(1).max(200)
1279
+ });
1280
+ z.object({ stored: z.number().int().nonnegative() });
1281
+ z.strictObject({ canvasId: z.uuid() });
1282
+ z.object({ measurements: z.array(canvasOutlineMeasurementSchema.extend({ measuredVersion: z.number().int().nonnegative() })) });
1176
1283
  z.strictObject({});
1177
1284
  z.object({ firstAgentWorkAt: z.iso.datetime().nullable() });
1178
1285
  /** Cursor pagination, defined once so no endpoint invents its own page shape. */
@@ -1281,13 +1388,18 @@ const canvasSchema = z.object({
1281
1388
  createdAt: z.iso.datetime(),
1282
1389
  lastActivityAt: z.iso.datetime()
1283
1390
  });
1391
+ /**
1392
+ * A canvas with its full web address, which only the API can write: it is built from the web
1393
+ * address of the API's own environment, so a reader never joins an id to a host.
1394
+ */
1395
+ const linkedCanvasSchema = canvasSchema.extend({ url: z.url() });
1284
1396
  z.object({
1285
1397
  title: z.string().trim().min(1),
1286
1398
  /** The team to file it under, or null for the maker's own. Refused for one you are not on. */
1287
1399
  organisationId: z.uuid().nullable().default(null),
1288
1400
  sourceUrl: z.string().nullable().default(null)
1289
1401
  });
1290
- canvasSchema.extend({ version: z.number().int().positive() });
1402
+ linkedCanvasSchema.extend({ version: z.number().int().positive() });
1291
1403
  z.object({ canvasId: z.uuid() });
1292
1404
  /**
1293
1405
  * Which collection to draw: your own, a team's by id, or everything you can reach. One field
@@ -1311,7 +1423,7 @@ z.object({
1311
1423
  ]).default("all"),
1312
1424
  hasUnresolved: z.boolean().default(false)
1313
1425
  });
1314
- const canvasCardBaseSchema = canvasSchema.extend({
1426
+ const canvasCardBaseSchema = linkedCanvasSchema.extend({
1315
1427
  screenCount: z.number().int().min(0),
1316
1428
  hasRecording: z.boolean(),
1317
1429
  /** When the person listing last opened it in the web app; `null` if they never have. */
@@ -1751,6 +1863,11 @@ const canvasNodeLayoutSchema = z.object({
1751
1863
  clipContent: z.boolean().optional(),
1752
1864
  baselineSource: canvasBaselineSourceSchema.optional(),
1753
1865
  scrollbarGutter: canvasScrollbarGutterSchema.optional(),
1866
+ /**
1867
+ * The frame holds an embedded document. Chromium sizes that document's viewport in whole
1868
+ * pixels, rounding the frame's content box up, so what the frame holds resolves against that.
1869
+ */
1870
+ embeddedDocument: z.literal(true).optional(),
1754
1871
  container: canvasFlexLayoutSchema.partial().extend({ padding: canvasFlexPaddingSchema.partial().optional() }).optional()
1755
1872
  }).strict();
1756
1873
  //#endregion
@@ -1821,7 +1938,9 @@ const canvasOutlineSchema = z.object({
1821
1938
  ]),
1822
1939
  paints: z.array(canvasPaintSchema),
1823
1940
  dashPattern: canvasDashPatternSchema.optional(),
1824
- dashCap: canvasDashCapSchema.optional()
1941
+ dashCap: canvasDashCapSchema.optional(),
1942
+ /** Captured CSS dashes, which the browser draws, as for a border. */
1943
+ dashOrigin: z.literal("css").optional()
1825
1944
  });
1826
1945
  const canvasShadowSchema = z.object({
1827
1946
  id: itemId,
@@ -2298,13 +2417,13 @@ z.strictObject({
2298
2417
  }).refine((asset) => asset.state === "ready" === (asset.metadata !== null), "Readiness must match verified metadata.").refine((asset) => asset.metadata === null || asset.metadata.kind === asset.kind, "Metadata must describe the reserved asset kind.").refine((asset) => isStoredContentType(asset.kind, asset.contentType), "Content type must match the asset kind.").refine((asset) => asset.path === (asset.kind === "image" ? canvasImageAssetPath(asset.canvasId, asset.assetId) : canvasFontAssetPath(asset.canvasId, asset.sha256)), "The resource path must match its native identity.").safeExtend({ upload: signedUploadSchema.nullable() }).refine((asset) => asset.state === "awaiting_upload" === (asset.upload !== null), "Only pending uploads receive upload access.");
2299
2418
  //#endregion
2300
2419
  //#region ../contract/src/canvas/canvas-css-values.lib.ts
2301
- const SIDES = [
2420
+ const SIDES$1 = [
2302
2421
  "top",
2303
2422
  "right",
2304
2423
  "bottom",
2305
2424
  "left"
2306
2425
  ];
2307
- SIDES.map((side) => `padding-${side}`), SIDES.map((side) => `margin-${side}`);
2426
+ SIDES$1.map((side) => `padding-${side}`), SIDES$1.map((side) => `margin-${side}`);
2308
2427
  //#endregion
2309
2428
  //#region ../contract/src/canvas/canvas-export-settings.schema.ts
2310
2429
  const format = z.enum(["png", "jpeg"]);
@@ -2383,7 +2502,34 @@ const canvasGeometrySchema = z.discriminatedUnion("kind", [
2383
2502
  //#endregion
2384
2503
  //#region ../contract/src/canvas/canvas-scene.schema.ts
2385
2504
  const CANVAS_COMPOSITING_RETIRED = "Update Enhance: compositing is no longer supported. Use the isolation style or a mask group.";
2386
- const canvasDocumentFormatSchema = z.literal(15, { error: "This editor uses an unsupported document format. Update the editor before changing this canvas." });
2505
+ const CANVAS_FORMAT_UPDATE_REQUIRED = "This change needs a newer version of Enhance. Refresh the editor, or update the Enhance plugin or command-line tool, then try again.";
2506
+ const CANVAS_FORMAT_SERVER_UPDATING = "Enhance is being updated. Try again in a minute.";
2507
+ /** Marks an issue whose message was written for whoever sent the request, so the API keeps it. */
2508
+ const FOR_CALLER = { forCaller: true };
2509
+ /**
2510
+ * The format a writer was built for, as a plain whole number so tool schemas can describe it. Which
2511
+ * writes that format may make is `refuseUnsafeWriterFormat`'s call.
2512
+ */
2513
+ const canvasDocumentFormatSchema = z.number({ error: CANVAS_FORMAT_UPDATE_REQUIRED }).int({ error: CANVAS_FORMAT_UPDATE_REQUIRED }).positive({ error: CANVAS_FORMAT_UPDATE_REQUIRED }).meta({
2514
+ description: `The document format this client writes. The current format is ${String(15)}.`,
2515
+ examples: [15]
2516
+ });
2517
+ /**
2518
+ * Refuses a write its client's format could get wrong. A client whose format differs from the
2519
+ * current one only in its number may still name changes, but a whole value it sends may lack
2520
+ * fields added since, so that needs the current format.
2521
+ */
2522
+ const refuseUnsafeWriterFormat = (documentFormatVersion, writes, context) => {
2523
+ const writer = canvasWriterFormat(documentFormatVersion);
2524
+ if (writer === "current" || writer === "number-only" && writes === "names") return;
2525
+ context.addIssue({
2526
+ code: "custom",
2527
+ path: ["documentFormatVersion"],
2528
+ message: writer === "ahead" ? CANVAS_FORMAT_SERVER_UPDATING : CANVAS_FORMAT_UPDATE_REQUIRED,
2529
+ params: FOR_CALLER,
2530
+ input: documentFormatVersion
2531
+ });
2532
+ };
2387
2533
  z.object({
2388
2534
  signature: z.string().regex(/^[a-f0-9]{16}$/u),
2389
2535
  /** The captured picture of the page's text, inline as written or as its canvas image store path. */
@@ -2433,13 +2579,14 @@ const canvasSceneNodeSchema = z.looseObject({
2433
2579
  props: z.record(z.string(), z.unknown()).optional(),
2434
2580
  box: canvasSceneBoxSchema.optional()
2435
2581
  });
2582
+ const canvasSceneRelationshipSchema = z.object({
2583
+ parentId: z.string().min(1),
2584
+ sortKey: z.string().min(1)
2585
+ });
2436
2586
  const canvasSceneDocumentSchema = z.object({
2437
2587
  version: z.literal(15),
2438
2588
  nodes: z.record(z.string(), canvasSceneNodeSchema),
2439
- relationships: z.record(z.string(), z.object({
2440
- parentId: z.string().min(1),
2441
- sortKey: z.string().min(1)
2442
- })),
2589
+ relationships: z.record(z.string(), canvasSceneRelationshipSchema),
2443
2590
  tombstones: z.record(z.string(), z.literal(true)).default({})
2444
2591
  });
2445
2592
  const legacyRecordSchema = z.record(z.string(), z.unknown());
@@ -2463,6 +2610,10 @@ const emptyCanvasSceneDocument = () => ({
2463
2610
  relationships: {},
2464
2611
  tombstones: {}
2465
2612
  });
2613
+ canvasSceneDocumentSchema.extend({
2614
+ nodes: z.record(z.string(), z.unknown()),
2615
+ relationships: z.record(z.string(), z.unknown())
2616
+ });
2466
2617
  //#endregion
2467
2618
  //#region ../contract/src/canvas/canvas-conversion-draft.schema.ts
2468
2619
  const temporaryIdSchema = z.string().min(1);
@@ -2500,7 +2651,8 @@ const canvasUnsupportedFeatureSchema = z.enum([
2500
2651
  "image-shadows",
2501
2652
  "effect-noise",
2502
2653
  "effect-texture",
2503
- "effect-glass"
2654
+ "effect-glass",
2655
+ "mask-source"
2504
2656
  ]);
2505
2657
  const canvasConversionReportSchema = z.object({
2506
2658
  nodeCount: z.number().int().positive(),
@@ -2545,7 +2697,8 @@ const canvasSubtreeDraftSchema = z.object({
2545
2697
  /** A capture that lands as a new editable frame on a page, with no screen layer. */
2546
2698
  const editableFrameCaptureSchema = z.object({
2547
2699
  screenId: z.string().min(1),
2548
- pageId: z.string().min(1)
2700
+ pageId: z.string().min(1),
2701
+ pictureNodeId: z.string().min(1).optional().describe("The capture's picture, which the frame replaces in place and whose id it keeps. Refused as capture-already-landed once the picture is a frame.")
2549
2702
  });
2550
2703
  const editableFrameInputBase = {
2551
2704
  canvasId: z.uuid(),
@@ -2560,7 +2713,9 @@ z.union([z.strictObject({
2560
2713
  }), z.strictObject({
2561
2714
  ...editableFrameInputBase,
2562
2715
  capture: editableFrameCaptureSchema.describe("The stored page a new capture lands from, and the page its frame goes on.")
2563
- })]);
2716
+ })]).superRefine((input, context) => {
2717
+ refuseUnsafeWriterFormat(input.documentFormatVersion, "whole", context);
2718
+ });
2564
2719
  const createEditableFrameResultSchema = z.object({
2565
2720
  canvasId: z.uuid(),
2566
2721
  mutationId: z.uuid(),
@@ -2623,7 +2778,8 @@ const RENDER_WARNING_CODES = [
2623
2778
  "LOCAL_FONT_FALLBACK",
2624
2779
  "SOURCE_FALLBACK",
2625
2780
  "SCALE_REDUCED",
2626
- "LAYOUT_FALLBACK"
2781
+ "LAYOUT_FALLBACK",
2782
+ "DRAWN_APPROXIMATELY"
2627
2783
  ];
2628
2784
  //#endregion
2629
2785
  //#region ../contract/src/canvas/canvas-render.schema.ts
@@ -2866,7 +3022,12 @@ const canvasConversionDestinationSchema = z.discriminatedUnion("kind", [
2866
3022
  }),
2867
3023
  z.object({
2868
3024
  kind: z.literal("replace"),
2869
- targetNodeId: z.string().min(1)
3025
+ targetNodeId: z.string().min(1),
3026
+ /**
3027
+ * A capture's swap: the target must still be the capture's picture. When another browser has
3028
+ * already made it editable, the swap is refused as `capture-already-landed`.
3029
+ */
3030
+ onlyPicture: z.literal(true).optional()
2870
3031
  })
2871
3032
  ]);
2872
3033
  const canvasConversionSourceSchema = z.discriminatedUnion("kind", [z.object({
@@ -3601,7 +3762,7 @@ const currentCanvasOperationSchema = z.discriminatedUnion("op", [
3601
3762
  removedText: z.record(nodeIdSchema$3, canvasSceneNodeSchema.pick({ props: true })).optional()
3602
3763
  })
3603
3764
  ]);
3604
- /** An older client's compositing write is refused with the CSS that replaces it. */
3765
+ currentCanvasOperationSchema.options;
3605
3766
  /** Each operation's name, for records that may state which kind failed and nothing else. */
3606
3767
  const CANVAS_OPERATION_NAMES = currentCanvasOperationSchema.options.map((option) => option.shape.op.value);
3607
3768
  const canvasOperationSchema = z.preprocess((value, context) => {
@@ -3662,6 +3823,8 @@ const canvasMutationRevisionSchema = z.object({
3662
3823
  operations: z.array(canvasOperationSchema)
3663
3824
  });
3664
3825
  z.object({
3826
+ /** The canvas's web address. An API older than the field answers without it. */
3827
+ url: z.url().optional(),
3665
3828
  mutations: z.array(canvasMutationRevisionSchema).optional(),
3666
3829
  version: z.number().int().min(1),
3667
3830
  /**
@@ -3694,6 +3857,123 @@ z.discriminatedUnion("outcome", [z.object({
3694
3857
  document: canvasDocumentBlobSchema
3695
3858
  })]);
3696
3859
  //#endregion
3860
+ //#region ../contract/src/canvas/canvas-document-parts.schema.ts
3861
+ /** One answer stops taking top layers once it holds this many layers, unless it is asked for more. */
3862
+ const CANVAS_PART_LAYER_LIMIT = 5e3;
3863
+ /** The most layers a read of parts may ask one answer to hold before it stops. */
3864
+ const CANVAS_PART_LAYER_LIMIT_MAX = 1e5;
3865
+ /** The most identifiers one read of parts may name in each list. */
3866
+ const CANVAS_PART_NAMED_LIMIT = 2e3;
3867
+ z.strictObject({ canvasId: z.uuid() });
3868
+ /** The font files a layer inside a top layer declares, without the rest of the layer. */
3869
+ const canvasFontDeclarationSchema = z.object({
3870
+ layerId: z.string(),
3871
+ /** The child of the root that holds the layer. */
3872
+ topLayerId: z.string(),
3873
+ fontFaces: z.array(z.unknown())
3874
+ });
3875
+ z.object({
3876
+ version: z.number().int().min(1),
3877
+ restoreFenceVersion: z.number().int().positive().optional(),
3878
+ /** The root and each child of the root, pages among them, and every removed-layer id. */
3879
+ document: canvasDocumentBlobSchema,
3880
+ screens: z.array(documentScreenSchema),
3881
+ /** Whether the canvas holds more than `LARGE_PAGE_LAYERS` layers, every page counted. */
3882
+ isLarge: z.boolean(),
3883
+ fontDeclarations: z.array(canvasFontDeclarationSchema)
3884
+ });
3885
+ const namedIds = z.array(z.string().min(1)).max(CANVAS_PART_NAMED_LIMIT);
3886
+ z.strictObject({
3887
+ canvasId: z.uuid(),
3888
+ /** Children of the root, answered in this order. */
3889
+ topLayerIds: namedIds.optional(),
3890
+ /** Layers anywhere; each is answered with the whole top layer that holds it. */
3891
+ layerIds: namedIds.optional(),
3892
+ /**
3893
+ * The layers after which the answer takes no further top layer. An editor raises it on a very
3894
+ * large canvas, so the whole canvas arrives in a bounded number of answers.
3895
+ */
3896
+ maxLayers: z.number().int().min(CANVAS_PART_LAYER_LIMIT).max(CANVAS_PART_LAYER_LIMIT_MAX).default(CANVAS_PART_LAYER_LIMIT)
3897
+ }).refine(({ topLayerIds = [], layerIds = [] }) => topLayerIds.length + layerIds.length > 0, "A read of parts names at least one layer.");
3898
+ z.object({
3899
+ /** The revision every layer of the answer was read at. */
3900
+ version: z.number().int().min(1),
3901
+ /** Each answered top layer's own record and every layer inside it: no root, no removed ids. */
3902
+ document: canvasDocumentBlobSchema,
3903
+ /** The top layers answered, in the order asked. */
3904
+ read: z.array(z.string()),
3905
+ /** The top layers left out because the answer was full, in the order asked. */
3906
+ notReached: z.array(z.string()),
3907
+ /** The named identifiers that are no top layer of the canvas, or are inside none. */
3908
+ absent: z.array(z.string())
3909
+ });
3910
+ //#endregion
3911
+ //#region ../contract/src/canvas/canvas-first-letter.lib.ts
3912
+ /** Custom CSS on a text layer that styles its first letter, one declaration per property. */
3913
+ const CANVAS_FIRST_LETTER_PREFIX = "--canvas-first-letter-";
3914
+ const SIDES = [
3915
+ "top",
3916
+ "right",
3917
+ "bottom",
3918
+ "left"
3919
+ ];
3920
+ /**
3921
+ * The properties a first letter takes (CSS Pseudo-Elements 4, `::first-letter`), each with the
3922
+ * value it has when a layer does not declare it: its block's for a property that inherits, the
3923
+ * initial value for one that does not.
3924
+ */
3925
+ const CANVAS_FIRST_LETTER_PROPERTIES = {
3926
+ ...Object.fromEntries([
3927
+ "color",
3928
+ "font-family",
3929
+ "font-size",
3930
+ "font-stretch",
3931
+ "font-style",
3932
+ "font-weight",
3933
+ "font-variant-caps",
3934
+ "font-variant-ligatures",
3935
+ "font-variant-numeric",
3936
+ "font-feature-settings",
3937
+ "font-variation-settings",
3938
+ "font-kerning",
3939
+ "letter-spacing",
3940
+ "line-height",
3941
+ "text-shadow",
3942
+ "text-transform",
3943
+ "word-spacing",
3944
+ "-webkit-text-fill-color",
3945
+ "-webkit-text-stroke-color",
3946
+ "-webkit-text-stroke-width"
3947
+ ].map((property) => [property, "inherit"])),
3948
+ ...Object.fromEntries([
3949
+ "float",
3950
+ "vertical-align",
3951
+ "initial-letter",
3952
+ "opacity",
3953
+ "background-color",
3954
+ "background-image",
3955
+ "box-shadow",
3956
+ "text-decoration-line",
3957
+ "text-decoration-style",
3958
+ "text-decoration-color",
3959
+ "text-decoration-thickness",
3960
+ ...SIDES.flatMap((side) => [
3961
+ `margin-${side}`,
3962
+ `padding-${side}`,
3963
+ `border-${side}-style`,
3964
+ `border-${side}-width`,
3965
+ `border-${side}-color`
3966
+ ]),
3967
+ ...[
3968
+ "top-left",
3969
+ "top-right",
3970
+ "bottom-right",
3971
+ "bottom-left"
3972
+ ].map((corner) => `border-${corner}-radius`)
3973
+ ].map((property) => [property, "initial"]))
3974
+ };
3975
+ `${Object.entries(CANVAS_FIRST_LETTER_PROPERTIES).map(([property, fallback]) => `${property}:var(${CANVAS_FIRST_LETTER_PREFIX}${property},${fallback})`).join(";")}`;
3976
+ //#endregion
3697
3977
  //#region ../contract/src/canvas/canvas-text-content.lib.ts
3698
3978
  const textLinkSchema = z.object({
3699
3979
  start: z.number().int().nonnegative(),
@@ -3725,13 +4005,30 @@ const canvasPropertySectionSchema = z.enum([
3725
4005
  "export",
3726
4006
  "source"
3727
4007
  ]);
4008
+ //#endregion
4009
+ //#region ../contract/src/canvas/canvas-inspection.schema.ts
4010
+ const MAX_RENDER_MESSAGE_LENGTH = 500;
4011
+ const MAX_RENDER_KIND_LENGTH = 100;
4012
+ /**
4013
+ * What a layer's box is: `placed` where the canvas draws the layer, `placed-before-transform` where
4014
+ * it draws the layer before the layer's own transform, `recorded` a size kept from when the layer
4015
+ * was made, for a layer the browser lays out.
4016
+ */
4017
+ const canvasBoxSourceSchema = z.enum([
4018
+ "placed",
4019
+ "placed-before-transform",
4020
+ "recorded"
4021
+ ]);
4022
+ /** Present only on a read that holds a `recorded` box. */
4023
+ const boxNoteSchema = z.string().min(1).optional();
3728
4024
  const canvasInspectNodeSummarySchema = z.object({
3729
4025
  id: z.string().min(1),
3730
- label: z.string().max(500),
3731
- kind: z.string().min(1).max(100),
4026
+ label: z.string().max(MAX_RENDER_MESSAGE_LENGTH),
4027
+ kind: z.string().min(1).max(MAX_RENDER_KIND_LENGTH),
3732
4028
  parentId: z.string().min(1).nullable(),
3733
4029
  childCount: z.number().int().min(0),
3734
4030
  box: canvasSceneBoxSchema.nullable(),
4031
+ boxSource: canvasBoxSourceSchema.optional(),
3735
4032
  propertySections: z.array(canvasPropertySectionSchema)
3736
4033
  });
3737
4034
  z.object({ canvasId: z.uuid() });
@@ -3744,13 +4041,15 @@ z.object({
3744
4041
  rootChildCount: z.number().int().min(0),
3745
4042
  bounds: canvasSceneBoxSchema.nullable(),
3746
4043
  kinds: z.record(z.string(), z.number().int().min(0)),
4044
+ boxNote: boxNoteSchema,
3747
4045
  next: z.array(z.string().min(1))
3748
4046
  });
3749
4047
  z.object({ canvasId: z.uuid() });
3750
4048
  z.object({
3751
4049
  canvasId: z.uuid(),
3752
4050
  version: z.number().int().positive(),
3753
- nodes: z.array(canvasInspectNodeSummarySchema)
4051
+ nodes: z.array(canvasInspectNodeSummarySchema),
4052
+ boxNote: boxNoteSchema
3754
4053
  });
3755
4054
  z.object({
3756
4055
  canvasId: z.uuid(),
@@ -3769,9 +4068,49 @@ z.object({
3769
4068
  props: z.record(z.string(), z.unknown()),
3770
4069
  children: z.array(z.string().min(1))
3771
4070
  }),
4071
+ boxNote: boxNoteSchema,
3772
4072
  next: z.array(z.string().min(1))
3773
4073
  });
3774
4074
  //#endregion
4075
+ //#region ../contract/src/canvas/canvas-operation-writes.schema.ts
4076
+ /**
4077
+ * What each operation writes. `names` sets one plain value, places, removes, or merges a patch, so
4078
+ * values its client never knew stay as stored. `whole` brings a whole layer or replaces a whole
4079
+ * group of values, which a client that read the canvas in an older format may have stripped.
4080
+ */
4081
+ const CANVAS_OPERATION_WRITES = {
4082
+ insertConvertedSubtree: "whole",
4083
+ insertNode: "whole",
4084
+ insertText: "names",
4085
+ insertPrototype: "names",
4086
+ setPrototypeDeployment: "names",
4087
+ editText: "names",
4088
+ setText: "names",
4089
+ setBox: "names",
4090
+ setLabel: "names",
4091
+ setContainerKind: "names",
4092
+ setVisibility: "names",
4093
+ setLocked: "names",
4094
+ setConstraints: "names",
4095
+ setStyles: "names",
4096
+ patchExportSettings: "names",
4097
+ setAppearance: "names",
4098
+ setLayout: "whole",
4099
+ patchTypography: "names",
4100
+ setTypography: "whole",
4101
+ patchAdditionalStyles: "names",
4102
+ setAdditionalStyles: "whole",
4103
+ setArtworkColor: "whole",
4104
+ setTextStyleLibrary: "whole",
4105
+ patchFontLibrary: "names",
4106
+ setTextStyle: "whole",
4107
+ setGeometry: "whole",
4108
+ setProps: "whole",
4109
+ setParentage: "names",
4110
+ move: "names",
4111
+ remove: "names"
4112
+ };
4113
+ //#endregion
3775
4114
  //#region ../contract/src/canvas/canvas-mutation.schema.ts
3776
4115
  const nodeIdSchema$2 = canvasSceneNodeSchema.shape.id;
3777
4116
  const writableBoxSchema = canvasSceneBoxSchema.extend({
@@ -3779,6 +4118,8 @@ const writableBoxSchema = canvasSceneBoxSchema.extend({
3779
4118
  height: z.number().positive()
3780
4119
  });
3781
4120
  const copiedNodeIdsSchema = z.record(nodeIdSchema$2, nodeIdSchema$2);
4121
+ /** A receipt stored before boxes said what they are holds none, so the source stays optional. */
4122
+ const canvasReceiptBoxSchema = canvasSceneBoxSchema.extend({ boxSource: canvasBoxSourceSchema.optional() });
3782
4123
  const canvasMutationRequestContextSchema = z.strictObject({
3783
4124
  fingerprint: z.string().regex(/^[a-f0-9]{64}$/u),
3784
4125
  revisionPolicy: z.enum(["strict", "rebase"]),
@@ -3792,6 +4133,8 @@ z.object({
3792
4133
  operations: z.array(canvasOperationSchema).min(1),
3793
4134
  requestContext: canvasMutationRequestContextSchema.optional(),
3794
4135
  writeScope: canvasWriteScopeSchema.optional()
4136
+ }).superRefine((input, context) => {
4137
+ refuseUnsafeWriterFormat(input.documentFormatVersion, input.operations.every((operation) => CANVAS_OPERATION_WRITES[operation.op] === "names") ? "names" : "whole", context);
3795
4138
  });
3796
4139
  const applyCanvasOperationsOutputSchema = z.object({
3797
4140
  canvasId: z.uuid(),
@@ -3802,7 +4145,7 @@ const applyCanvasOperationsOutputSchema = z.object({
3802
4145
  insertedNodeIds: z.array(nodeIdSchema$2),
3803
4146
  changedNodeIds: z.array(nodeIdSchema$2),
3804
4147
  removedNodeIds: z.array(nodeIdSchema$2),
3805
- boxes: z.record(nodeIdSchema$2, canvasSceneBoxSchema),
4148
+ boxes: z.record(nodeIdSchema$2, canvasReceiptBoxSchema),
3806
4149
  affectedBounds: writableBoxSchema.nullable(),
3807
4150
  copiedNodeIds: copiedNodeIdsSchema.optional(),
3808
4151
  next: z.array(z.string().min(1))
@@ -3814,7 +4157,8 @@ z.strictObject({
3814
4157
  });
3815
4158
  z.discriminatedUnion("state", [z.strictObject({ state: z.literal("not-found") }), z.strictObject({
3816
4159
  state: z.literal("committed"),
3817
- result: applyCanvasOperationsOutputSchema
4160
+ /** `url` is the canvas's web address. An API older than the field answers without it. */
4161
+ result: applyCanvasOperationsOutputSchema.extend({ url: z.url().optional() })
3818
4162
  })]);
3819
4163
  //#endregion
3820
4164
  //#region ../contract/src/canvas/canvas-mutation-review.schema.ts
@@ -4217,8 +4561,10 @@ const canvasPreparationRequestSchema = z.discriminatedUnion("kind", [
4217
4561
  sources: z.array(z.strictObject({
4218
4562
  screenId: z.uuid(),
4219
4563
  captureId: z.uuid(),
4220
- label: z.string().min(1)
4221
- })).min(1)
4564
+ /** What the frame is called. Absent, the frame takes the stored page's own title. */
4565
+ label: z.string().min(1).optional()
4566
+ })).min(1),
4567
+ landing: z.literal("editable-frame").optional().describe("Lands the page as an ordinary editable frame. Without it, the layers belong to a capture run.")
4222
4568
  }),
4223
4569
  canvasArrangePreparationSchema,
4224
4570
  canvasDuplicatePreparationSchema,
@@ -4299,7 +4645,11 @@ const canvasPreparationJobSchema = z.discriminatedUnion("state", [
4299
4645
  job.extend({
4300
4646
  state: z.literal("succeeded"),
4301
4647
  phase: z.literal("complete"),
4302
- result: canvasPreparationPlanSchema.extend({ loadedVersion: z.number().int().positive() }),
4648
+ result: canvasPreparationPlanSchema.extend({
4649
+ loadedVersion: z.number().int().positive(),
4650
+ /** Where a screen compile fell back, such as a font it replaced; absent when it had none. */
4651
+ warnings: z.array(canvasRenderWarningSchema).optional()
4652
+ }),
4303
4653
  failure: z.null()
4304
4654
  }),
4305
4655
  job.extend({
@@ -4692,7 +5042,8 @@ z.discriminatedUnion("purpose", [
4692
5042
  "inspection",
4693
5043
  "snapshot",
4694
5044
  "thumbnail",
4695
- "export"
5045
+ "export",
5046
+ "object-pictures"
4696
5047
  ]),
4697
5048
  scale: z.number().positive(),
4698
5049
  maxOutputPixels: canvasRenderPixelLimitSchema.optional(),
@@ -4763,6 +5114,16 @@ z.discriminatedUnion("purpose", [
4763
5114
  sourceState: z.undefined().optional(),
4764
5115
  conversion: canvasConversionRequestSchema,
4765
5116
  scale: z.literal(1)
5117
+ }),
5118
+ claimRenderWorkBaseSchema.extend({
5119
+ purpose: z.literal("object-pictures"),
5120
+ target: canvasRenderTargetSchema,
5121
+ sourceState: z.undefined().optional(),
5122
+ scale: z.number().positive(),
5123
+ maxOutputPixels: canvasRenderPixelLimitSchema.optional(),
5124
+ /** The top layers to draw, in order; each picture is stored under the prefix. */
5125
+ objects: z.array(objectPictureWorkObjectSchema).max(20),
5126
+ outputPrefix: z.string().min(1).max(MAX_STORAGE_KEY_LENGTH)
4766
5127
  })
4767
5128
  ]);
4768
5129
  z.object({
@@ -4909,6 +5270,7 @@ z.object({
4909
5270
  nodes: z.array(canvasInspectNodeSummarySchema),
4910
5271
  contextRootId: nodeIdSchema.nullable(),
4911
5272
  visibleWorldBox: canvasWorldBoundsSchema.nullable(),
5273
+ boxNote: z.string().min(1).optional(),
4912
5274
  next: z.array(z.string().min(1)).max(MAX_SELECTION_COMMANDS)
4913
5275
  });
4914
5276
  //#endregion
@@ -4917,6 +5279,17 @@ const canvasCaptureProvenanceSchema = z.discriminatedUnion("kind", [z.object({
4917
5279
  kind: z.literal("recording"),
4918
5280
  recordingId: z.string()
4919
5281
  })]);
5282
+ /**
5283
+ * The mark on a captured page's picture while it becomes editable. Every capture lands as this
5284
+ * picture first; whoever converts it replaces the same layer with the editable frame, through the
5285
+ * one swap (`insertConvertedSubtree` with destination `replace` and `onlyPicture`). A conversion
5286
+ * that fails writes `failed` with a short reason, so every viewer sees the failure rather than a
5287
+ * spinner that never ends; Try again writes `converting` again.
5288
+ */
5289
+ const captureLandingSchema = z.discriminatedUnion("state", [z.object({ state: z.literal("converting") }), z.object({
5290
+ state: z.literal("failed"),
5291
+ reason: z.string().min(1).max(200)
5292
+ })]);
4920
5293
  z.object({
4921
5294
  html: z.string().optional(),
4922
5295
  viewport: z.object({
@@ -4926,7 +5299,8 @@ z.object({
4926
5299
  atMs: z.number(),
4927
5300
  screenId: z.string().nullable().default(null),
4928
5301
  sourceNodeId: z.string().optional(),
4929
- provenance: canvasCaptureProvenanceSchema.optional()
5302
+ provenance: canvasCaptureProvenanceSchema.optional(),
5303
+ landing: captureLandingSchema.optional()
4930
5304
  });
4931
5305
  z.object({
4932
5306
  provenance: canvasCaptureProvenanceSchema.optional(),
@@ -5056,12 +5430,16 @@ z.object({
5056
5430
  versionId: z.uuid()
5057
5431
  });
5058
5432
  z.object({ entry: canvasVersionEntrySchema });
5433
+ /** A restore or a duplicate copies a version the API holds, so it only names what to change. */
5434
+ const refuseUnsafeVersionCopy = (input, context) => {
5435
+ refuseUnsafeWriterFormat(input.documentFormatVersion, "names", context);
5436
+ };
5059
5437
  z.object({
5060
5438
  canvasId: z.uuid(),
5061
5439
  documentFormatVersion: canvasDocumentFormatSchema,
5062
5440
  versionId: z.uuid(),
5063
5441
  expectedVersion: z.number().int().positive()
5064
- });
5442
+ }).superRefine(refuseUnsafeVersionCopy);
5065
5443
  z.object({
5066
5444
  canvasId: z.uuid(),
5067
5445
  version: z.number().int().positive(),
@@ -5075,7 +5453,7 @@ z.object({
5075
5453
  versionId: z.uuid(),
5076
5454
  organisationId: z.union([z.uuid(), z.literal("personal")]),
5077
5455
  title: z.string().trim().min(1).optional()
5078
- });
5456
+ }).superRefine(refuseUnsafeVersionCopy);
5079
5457
  z.object({
5080
5458
  canvasId: z.uuid(),
5081
5459
  title: z.string().min(1),
@@ -5264,6 +5642,16 @@ const setReviewStateInputSchema = z.object({
5264
5642
  ])
5265
5643
  });
5266
5644
  z.object({ reviewState: setReviewStateInputSchema.shape.reviewState.nullable() });
5645
+ z.object({ canvasId: z.uuid() });
5646
+ z.object({
5647
+ /** The only credential a page receives: it stores captures and does nothing else. */
5648
+ pass: z.string().min(1),
5649
+ expiresAt: z.iso.datetime(),
5650
+ /** Where the capture script is published, for the snippet to load. */
5651
+ scriptUrl: z.url(),
5652
+ /** Where the page stores its capture: the API as the page reaches it. */
5653
+ apiUrl: z.url()
5654
+ });
5267
5655
  //#endregion
5268
5656
  //#region ../contract/src/comment/comment.schema.ts
5269
5657
  /** How many replies a thread hands back in one go before `hasMoreMessages` takes over. */
@@ -6565,6 +6953,12 @@ z.object({
6565
6953
  version: z.number().int().positive()
6566
6954
  })]).optional()
6567
6955
  });
6956
+ z.object({ bytes: z.number().int().positive().max(Number.MAX_SAFE_INTEGER) });
6957
+ z.object({
6958
+ id: z.uuid(),
6959
+ upload: signedUploadSchema
6960
+ });
6961
+ z.object({ id: z.uuid() });
6568
6962
  const MAX_PROTOTYPE_CONTENT_TYPE_LENGTH = 200;
6569
6963
  const prototypePathSchema = z.string().min(1).refine((value) => !value.startsWith("/") && !value.endsWith("/") && !value.includes("\\") && !value.includes("\0") && value.split("/").every((part) => part !== "" && part !== "." && part !== ".."), { message: "prototype paths must be portable relative file paths" });
6570
6964
  const prototypeFileSchema = z.object({
@@ -7000,6 +7394,24 @@ const missingReplayAssetSourceIn = (url) => {
7000
7394
  }
7001
7395
  };
7002
7396
  //#endregion
7397
+ //#region ../contract/src/recording/unsupported-surface-style.lib.ts
7398
+ const CROSS_LINE = "transparent calc(50% - 2px), rgba(255, 255, 255, 0.85) calc(50% - 1px), #a8a8b0 50%, rgba(255, 255, 255, 0.85) calc(50% + 1px), transparent calc(50% + 2px)";
7399
+ [`[data-enhance-unsupported]:not([data-enhance-unsupported-hidden]):not([style*="display: none"]) {
7400
+ align-items: center !important;
7401
+ background-color: transparent !important;
7402
+ background-image: ${`linear-gradient(to top right, ${CROSS_LINE}), linear-gradient(to bottom right, ${CROSS_LINE})`} !important;
7403
+ border: 1px solid #c7c7cc !important;
7404
+ box-sizing: border-box !important;
7405
+ color: #4f4f55 !important;
7406
+ display: flex !important;
7407
+ font: 500 14px/1.4 Inter, ui-sans-serif, system-ui, sans-serif !important;
7408
+ justify-content: center !important;
7409
+ overflow: hidden !important;
7410
+ text-align: center !important;
7411
+ }`, `[data-enhance-unsupported-hidden], [data-enhance-unsupported][style*="display: none"] {
7412
+ display: none !important;
7413
+ }`].join("\n");
7414
+ //#endregion
7003
7415
  //#region ../contract/src/recording/page-asset-references.lib.ts
7004
7416
  /**
7005
7417
  * `url(...)`, however the page chose to quote it. Three arms rather than one optional-quote
@@ -7321,21 +7733,6 @@ z.object({
7321
7733
  /** Screens survive with their provenance nulled. That is what makes iteration safe. */
7322
7734
  detachedScreenCount: z.number().int().min(0)
7323
7735
  });
7324
- [`[data-enhance-unsupported]:not([data-enhance-unsupported-hidden]):not([style*="display: none"]) {
7325
- align-items: center !important;
7326
- background-color: #f7f7f8 !important;
7327
- background-image: linear-gradient(to top right, transparent calc(50% - 1px), #a8a8b0 50%, transparent calc(50% + 1px)), linear-gradient(to bottom right, transparent calc(50% - 1px), #a8a8b0 50%, transparent calc(50% + 1px)) !important;
7328
- border: 1px solid #c7c7cc !important;
7329
- box-sizing: border-box !important;
7330
- color: #4f4f55 !important;
7331
- display: flex !important;
7332
- font: 500 14px/1.4 Inter, ui-sans-serif, system-ui, sans-serif !important;
7333
- justify-content: center !important;
7334
- overflow: hidden !important;
7335
- text-align: center !important;
7336
- }`, `[data-enhance-unsupported-hidden], [data-enhance-unsupported][style*="display: none"] {
7337
- display: none !important;
7338
- }`].join("\n");
7339
7736
  z.object({
7340
7737
  /**
7341
7738
  * Client-minted, once per capture attempt. A retry is the same screen; a re-capture at the
@@ -7435,6 +7832,21 @@ const MAX_DURATION_MS$1 = 18e5;
7435
7832
  const MAX_COUNT$1 = 1e6;
7436
7833
  const MAX_BYTES = 1073741824;
7437
7834
  const MAX_PROTOTYPE_OPEN_ATTEMPTS = 16;
7835
+ const MAX_SCRIPT_POSITION = 1e8;
7836
+ /** What the person was doing when a long frame ended; `idle` is nothing at all. */
7837
+ const longFrameActionSchema = z.enum([
7838
+ "pan",
7839
+ "zoom",
7840
+ "drag",
7841
+ "typing",
7842
+ "paste",
7843
+ "undo",
7844
+ "redo",
7845
+ "edit",
7846
+ "opening",
7847
+ "loading",
7848
+ "idle"
7849
+ ]);
7438
7850
  /** How the read of a canvas's unsaved browser copy ended when the canvas opened. */
7439
7851
  const browserCopyCheckSchema = z.enum([
7440
7852
  "answered",
@@ -7449,6 +7861,12 @@ const base$1 = {
7449
7861
  releaseIdentity: z.string().min(1).max(100),
7450
7862
  capabilityVersion: z.number().int().min(1).max(MAX_CAPABILITY_VERSION$1)
7451
7863
  };
7864
+ const scriptSourceSchema = z.enum([
7865
+ "app",
7866
+ "extension",
7867
+ "third-party",
7868
+ "unknown"
7869
+ ]);
7452
7870
  const mainThreadWork = {
7453
7871
  longTaskCount: countSchema,
7454
7872
  longTaskTotalMs: durationSchema$1,
@@ -7458,12 +7876,7 @@ const mainThreadWork = {
7458
7876
  loafLongestBlockingMs: durationSchema$1,
7459
7877
  loafStyleAndLayoutMs: durationSchema$1,
7460
7878
  loafTopScriptMs: durationSchema$1,
7461
- loafTopScriptSource: z.enum([
7462
- "app",
7463
- "extension",
7464
- "third-party",
7465
- "unknown"
7466
- ])
7879
+ loafTopScriptSource: scriptSourceSchema
7467
7880
  };
7468
7881
  z.discriminatedUnion("name", [
7469
7882
  z.object({
@@ -7524,10 +7937,42 @@ z.discriminatedUnion("name", [
7524
7937
  durationMs: durationSchema$1,
7525
7938
  frameCount: countSchema,
7526
7939
  slowFrameCount: countSchema,
7940
+ over16FrameCount: countSchema.optional(),
7941
+ over33FrameCount: countSchema.optional(),
7527
7942
  worstFrameMs: durationSchema$1,
7528
7943
  nodeCount: countSchema,
7529
7944
  replayCount: countSchema
7530
7945
  }),
7946
+ z.object({
7947
+ ...base$1,
7948
+ name: z.literal("canvas_long_frame"),
7949
+ source: z.enum(["long-animation-frame", "longtask"]),
7950
+ action: longFrameActionSchema,
7951
+ durationMs: durationSchema$1,
7952
+ blockingMs: durationSchema$1,
7953
+ styleAndLayoutMs: durationSchema$1,
7954
+ topScriptMs: durationSchema$1,
7955
+ topScriptSource: scriptSourceSchema,
7956
+ topScriptInvoker: z.enum([
7957
+ "event-listener",
7958
+ "user-callback",
7959
+ "resolve-promise",
7960
+ "reject-promise",
7961
+ "classic-script",
7962
+ "module-script",
7963
+ "none"
7964
+ ]),
7965
+ topScriptEvent: z.string().regex(/^[a-z]{1,32}$/u).optional(),
7966
+ topScriptFile: z.string().regex(/^[\w-][\w.-]{0,124}\.js$/u).optional(),
7967
+ topScriptFunction: z.string().regex(/^[\w$.]{1,80}$/u).optional(),
7968
+ topScriptPosition: z.number().int().min(0).max(MAX_SCRIPT_POSITION).optional(),
7969
+ layerCount: countSchema,
7970
+ topLayerCount: countSchema,
7971
+ builtLayerCount: countSchema,
7972
+ zoomPercent: countSchema,
7973
+ frameNumber: countSchema,
7974
+ skippedCount: countSchema
7975
+ }),
7531
7976
  z.object({
7532
7977
  ...base$1,
7533
7978
  name: z.literal("canvas_measurement"),
@@ -7647,6 +8092,7 @@ const clientRenderFailureDetailsSchema = z.strictObject({
7647
8092
  "clipboard-unavailable",
7648
8093
  "clipboard-image-pending",
7649
8094
  "clipboard-image-unavailable",
8095
+ "paste-content-refused",
7650
8096
  "edit-target-unsupported",
7651
8097
  "edit-result-invalid",
7652
8098
  "react-hook-order",
@@ -7684,6 +8130,7 @@ const clientRenderFailureDetailsSchema = z.strictObject({
7684
8130
  subsystem: z.enum([
7685
8131
  "menu",
7686
8132
  "menu-picture",
8133
+ "arrival-cue",
7687
8134
  "unknown"
7688
8135
  ]).optional(),
7689
8136
  repeats: count$1.optional(),
@@ -7758,7 +8205,18 @@ const CANVAS_SYNC_REPORTS = [
7758
8205
  "whole-value-text",
7759
8206
  "retrying",
7760
8207
  "recovery",
7761
- "trace"
8208
+ "trace",
8209
+ "update-required"
8210
+ ];
8211
+ /** How a failed document read was answered, on the report of one worth a look. */
8212
+ const CANVAS_SYNC_READ_OUTCOMES = [
8213
+ "transient",
8214
+ "no-edit-access",
8215
+ "restored",
8216
+ "replan",
8217
+ "refused",
8218
+ "update-required",
8219
+ "fault"
7762
8220
  ];
7763
8221
  const CANVAS_SYNC_DETAILS = [
7764
8222
  ...CLIENT_SAVE_ISSUES,
@@ -7795,7 +8253,8 @@ const CANVAS_SYNC_REPORT_STATUSES = [
7795
8253
  "view-only",
7796
8254
  "sign-in",
7797
8255
  "gone",
7798
- "restored"
8256
+ "restored",
8257
+ "update-required"
7799
8258
  ];
7800
8259
  /** Whether a recovery state began in this visit or was reopened from the browser copy. */
7801
8260
  const CANVAS_SYNC_EPISODES = ["new", "reopened"];
@@ -7837,6 +8296,7 @@ const CANVAS_SAVE_NOTICE_CAUSES = [
7837
8296
  "refused",
7838
8297
  "copy-refused",
7839
8298
  "copy-preview",
8299
+ "update-required",
7840
8300
  "unknown"
7841
8301
  ];
7842
8302
  const CANVAS_SAVE_SEVERITIES = [
@@ -7860,7 +8320,8 @@ const CANVAS_SAVE_ACTIONS = [
7860
8320
  "retry-upload",
7861
8321
  "choose-file",
7862
8322
  "remove-screen",
7863
- "go-to-canvases"
8323
+ "go-to-canvases",
8324
+ "reload"
7864
8325
  ];
7865
8326
  const CANVAS_SAVE_OUTCOMES = [
7866
8327
  "saved",
@@ -7954,6 +8415,7 @@ z.strictObject({
7954
8415
  durationMs: z.number().int().nonnegative(),
7955
8416
  pendingChanges: z.number().int().nonnegative(),
7956
8417
  reason: z.enum(CANVAS_SYNC_DETAILS).optional(),
8418
+ readOutcome: z.enum(CANVAS_SYNC_READ_OUTCOMES).optional(),
7957
8419
  status: z.enum(CANVAS_SYNC_REPORT_STATUSES).optional(),
7958
8420
  episode: z.enum(CANVAS_SYNC_EPISODES).optional(),
7959
8421
  trace: canvasSaveTraceSchema.optional()
@@ -8185,8 +8647,8 @@ var StorageRequestError = class extends Error {
8185
8647
  //#region ../contract/src/shared/request-outcome.lib.ts
8186
8648
  const listed = (allowed, value) => typeof value === "string" && allowed.includes(value) ? value : null;
8187
8649
  const refusalOf = (error) => {
8188
- const { refusalCode, operation, component } = error.fields ?? {};
8189
- if (refusalCode === void 0 && operation === void 0 && component === void 0) return void 0;
8650
+ const { refusalCode, operation, component, operationIndex } = error.fields ?? {};
8651
+ if (refusalCode === void 0 && operation === void 0 && component === void 0 && operationIndex === void 0) return void 0;
8190
8652
  const code = CANVAS_SAVE_REFUSAL_CODES.find((value) => value === refusalCode);
8191
8653
  return {
8192
8654
  refusalCode: refusalCode === void 0 ? "unclassified" : code ?? "unknown",
@@ -8198,6 +8660,15 @@ const refusalOf = (error) => {
8198
8660
  const MUTATION_ID_REUSED = "mutation-id-reused";
8199
8661
  /** `fields.reason` on a 413, whether the server's envelope or a proxy's bare status says so. */
8200
8662
  const REQUEST_TOO_LARGE = "request-too-large";
8663
+ const tooLarge = {
8664
+ kind: "refused",
8665
+ reason: REQUEST_TOO_LARGE,
8666
+ refusal: {
8667
+ refusalCode: REQUEST_TOO_LARGE,
8668
+ operation: "unknown",
8669
+ component: "unknown"
8670
+ }
8671
+ };
8201
8672
  const HTTP_UNAUTHORIZED = 401;
8202
8673
  const HTTP_FORBIDDEN = 403;
8203
8674
  const HTTP_NOT_FOUND = 404;
@@ -8232,17 +8703,15 @@ const conflictOutcome = (error) => {
8232
8703
  reason: error.message
8233
8704
  };
8234
8705
  };
8235
- /** The server names the two refusals a client must tell apart; any other is the message. */
8706
+ /** The server names the refusals a client must tell apart; any other is the message. */
8236
8707
  const badRequestOutcome = (error) => {
8237
8708
  const reason = error.fields?.["reason"];
8238
8709
  if (reason === "mutation-id-reused") return {
8239
8710
  kind: "fault",
8240
8711
  detail: MUTATION_ID_REUSED
8241
8712
  };
8242
- if (reason === "request-too-large") return {
8243
- kind: "refused",
8244
- reason: REQUEST_TOO_LARGE
8245
- };
8713
+ if (reason === "request-too-large") return tooLarge;
8714
+ if (error.fields?.["documentFormatVersion"] === "This change needs a newer version of Enhance. Refresh the editor, or update the Enhance plugin or command-line tool, then try again.") return { kind: "update-required" };
8246
8715
  const refusal = refusalOf(error);
8247
8716
  return {
8248
8717
  kind: "refused",
@@ -8274,10 +8743,7 @@ const statusOutcome = (status, retryAfterMs) => {
8274
8743
  };
8275
8744
  if (status === HTTP_FORBIDDEN) return { kind: "no-edit-access" };
8276
8745
  if (status === HTTP_NOT_FOUND) return { kind: "gone" };
8277
- if (status === HTTP_TOO_LARGE) return {
8278
- kind: "refused",
8279
- reason: REQUEST_TOO_LARGE
8280
- };
8746
+ if (status === HTTP_TOO_LARGE) return tooLarge;
8281
8747
  if (status === HTTP_TIMEOUT || status === HTTP_TOO_MANY_REQUESTS || status === HTTP_CLIENT_CLOSED || status >= HTTP_SERVER_ERROR) return {
8282
8748
  kind: "transient",
8283
8749
  retryAfterMs