@opengeni/contracts 0.40.0 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/dist/atlassian.d.ts +278 -0
  2. package/dist/atlassian.js +57 -0
  3. package/dist/atlassian.js.map +1 -0
  4. package/dist/canonical-human-identities.d.ts +157 -0
  5. package/dist/canonical-human-identities.js +23 -0
  6. package/dist/canonical-human-identities.js.map +1 -0
  7. package/dist/{chunk-7JZMI22I.js → chunk-5UDNP7AO.js} +34 -2
  8. package/dist/chunk-5UDNP7AO.js.map +1 -0
  9. package/dist/chunk-BVGIYW7D.js +11 -0
  10. package/dist/chunk-BVGIYW7D.js.map +1 -0
  11. package/dist/chunk-CADSX6UN.js +1145 -0
  12. package/dist/chunk-CADSX6UN.js.map +1 -0
  13. package/dist/chunk-CM6BMECR.js +24 -0
  14. package/dist/chunk-CM6BMECR.js.map +1 -0
  15. package/dist/chunk-D2HKF2EF.js +1460 -0
  16. package/dist/chunk-D2HKF2EF.js.map +1 -0
  17. package/dist/chunk-JBCIY7QD.js +194 -0
  18. package/dist/chunk-JBCIY7QD.js.map +1 -0
  19. package/dist/chunk-JUFK3T4Q.js +80 -0
  20. package/dist/chunk-JUFK3T4Q.js.map +1 -0
  21. package/dist/chunk-LSB7GRLG.js +779 -0
  22. package/dist/chunk-LSB7GRLG.js.map +1 -0
  23. package/dist/chunk-LW7OH6CS.js +382 -0
  24. package/dist/chunk-LW7OH6CS.js.map +1 -0
  25. package/dist/chunk-M5ZGRVIQ.js +719 -0
  26. package/dist/chunk-M5ZGRVIQ.js.map +1 -0
  27. package/dist/chunk-MYBZRDTY.js +340 -0
  28. package/dist/chunk-MYBZRDTY.js.map +1 -0
  29. package/dist/chunk-Q6A7XT2N.js +16734 -0
  30. package/dist/chunk-Q6A7XT2N.js.map +1 -0
  31. package/dist/chunk-RIY7GYQS.js +1204 -0
  32. package/dist/chunk-RIY7GYQS.js.map +1 -0
  33. package/dist/chunk-TZ6YEYN4.js +386 -0
  34. package/dist/chunk-TZ6YEYN4.js.map +1 -0
  35. package/dist/chunk-Y3MLSLB4.js +392 -0
  36. package/dist/chunk-Y3MLSLB4.js.map +1 -0
  37. package/dist/chunk-YRKRZ6OF.js +134 -0
  38. package/dist/chunk-YRKRZ6OF.js.map +1 -0
  39. package/dist/codex-provider-account-authority.d.ts +23 -0
  40. package/dist/codex-provider-account-authority.js +23 -0
  41. package/dist/codex-provider-account-authority.js.map +1 -0
  42. package/dist/company-profile.d.ts +629 -0
  43. package/dist/document-artifact-commands.d.ts +282 -0
  44. package/dist/document-artifact-commands.js +54 -0
  45. package/dist/document-artifact-commands.js.map +1 -0
  46. package/dist/document-artifact-query.d.ts +2 -0
  47. package/dist/document-artifact-query.js +54 -0
  48. package/dist/document-artifact-query.js.map +1 -0
  49. package/dist/editable-artifact-binary.d.ts +56 -0
  50. package/dist/editable-artifact-causal-frontier.d.ts +12 -0
  51. package/dist/editable-artifact-causal-frontier.js +18 -0
  52. package/dist/editable-artifact-causal-frontier.js.map +1 -0
  53. package/dist/editable-artifact-codec-registry.d.ts +48 -0
  54. package/dist/editable-artifact-codec-registry.js +20 -0
  55. package/dist/editable-artifact-codec-registry.js.map +1 -0
  56. package/dist/editable-artifact-committed-transaction.d.ts +35 -0
  57. package/dist/editable-artifact-committed-transaction.js +19 -0
  58. package/dist/editable-artifact-committed-transaction.js.map +1 -0
  59. package/dist/editable-artifact-live.d.ts +276 -0
  60. package/dist/editable-artifact-live.js +907 -0
  61. package/dist/editable-artifact-live.js.map +1 -0
  62. package/dist/editable-artifact-serialized-commit.d.ts +53 -0
  63. package/dist/editable-artifact-serialized-commit.js +26 -0
  64. package/dist/editable-artifact-serialized-commit.js.map +1 -0
  65. package/dist/editable-artifact-versions.d.ts +6 -0
  66. package/dist/editable-artifact-versions.js +11 -0
  67. package/dist/editable-artifact-versions.js.map +1 -0
  68. package/dist/editable-artifacts.d.ts +46 -0
  69. package/dist/editable-artifacts.js +236 -0
  70. package/dist/editable-artifacts.js.map +1 -0
  71. package/dist/event-preview.d.ts +1 -1
  72. package/dist/google-drive.d.ts +114 -2
  73. package/dist/google-drive.js +72 -14
  74. package/dist/google-drive.js.map +1 -1
  75. package/dist/image-generation.d.ts +70 -0
  76. package/dist/index.d.ts +5661 -166
  77. package/dist/index.js +1438 -21
  78. package/dist/interaction.d.ts +8290 -0
  79. package/dist/knowledge.d.ts +543 -0
  80. package/dist/memory-slack-delivery.d.ts +397 -0
  81. package/dist/presentation-artifact-commands.d.ts +349 -0
  82. package/dist/presentation-artifact-commands.js +66 -0
  83. package/dist/presentation-artifact-commands.js.map +1 -0
  84. package/dist/presentation-artifact-query.d.ts +2 -0
  85. package/dist/presentation-artifact-query.js +66 -0
  86. package/dist/presentation-artifact-query.js.map +1 -0
  87. package/dist/retained-output.d.ts +24 -0
  88. package/dist/sandbox-snapshots.d.ts +9 -0
  89. package/dist/scoped-knowledge.d.ts +14 -13
  90. package/dist/slack-bot-scopes.d.ts +4 -0
  91. package/dist/slack-bot-scopes.js +3 -1
  92. package/dist/slack-task-policy.d.ts +294 -0
  93. package/dist/spreadsheet-artifact-commands.d.ts +101 -0
  94. package/dist/spreadsheet-artifact-commands.js +27 -0
  95. package/dist/spreadsheet-artifact-commands.js.map +1 -0
  96. package/dist/spreadsheet-artifact-date.d.ts +4 -0
  97. package/dist/spreadsheet-artifact-query.d.ts +120 -0
  98. package/dist/spreadsheet-artifact-query.js +48 -0
  99. package/dist/spreadsheet-artifact-query.js.map +1 -0
  100. package/dist/task-notes.d.ts +128 -0
  101. package/dist/tool-catalog.d.ts +576 -0
  102. package/dist/video-generation.d.ts +580 -0
  103. package/dist/video-generation.js +59 -0
  104. package/dist/video-generation.js.map +1 -0
  105. package/dist/workspace-learning-policy.d.ts +208 -0
  106. package/dist/xai-provider-account-authority.d.ts +23 -0
  107. package/dist/xai-provider-account-authority.js +9 -0
  108. package/dist/xai-provider-account-authority.js.map +1 -0
  109. package/package.json +73 -1
  110. package/src/artifacts.ts +1 -1
  111. package/src/atlassian.ts +160 -0
  112. package/src/canonical-human-identities.ts +93 -0
  113. package/src/codex-provider-account-authority.ts +37 -0
  114. package/src/company-profile.ts +306 -0
  115. package/src/document-artifact-commands.ts +1709 -0
  116. package/src/document-artifact-query.ts +2 -0
  117. package/src/editable-artifact-binary.ts +396 -0
  118. package/src/editable-artifact-causal-frontier.ts +154 -0
  119. package/src/editable-artifact-codec-registry.ts +261 -0
  120. package/src/editable-artifact-committed-transaction.ts +478 -0
  121. package/src/editable-artifact-live.ts +1379 -0
  122. package/src/editable-artifact-serialized-commit.ts +494 -0
  123. package/src/editable-artifact-versions.ts +8 -0
  124. package/src/editable-artifacts.ts +473 -0
  125. package/src/google-drive.ts +68 -15
  126. package/src/image-generation.ts +106 -0
  127. package/src/index.ts +2920 -326
  128. package/src/interaction.ts +3173 -0
  129. package/src/knowledge.ts +207 -0
  130. package/src/memory-slack-delivery.ts +183 -0
  131. package/src/presentation-artifact-commands.ts +2035 -0
  132. package/src/presentation-artifact-query.ts +2 -0
  133. package/src/retained-output.ts +149 -2
  134. package/src/sandbox-snapshots.ts +28 -1
  135. package/src/scoped-knowledge.ts +18 -4
  136. package/src/slack-bot-scopes.ts +34 -1
  137. package/src/slack-task-policy.ts +215 -0
  138. package/src/spreadsheet-artifact-commands.ts +999 -0
  139. package/src/spreadsheet-artifact-date.ts +21 -0
  140. package/src/spreadsheet-artifact-query.ts +1411 -0
  141. package/src/task-notes.ts +92 -0
  142. package/src/tool-catalog.ts +334 -0
  143. package/src/video-generation.ts +431 -0
  144. package/src/workspace-learning-policy.ts +233 -0
  145. package/src/xai-provider-account-authority.ts +37 -0
  146. package/dist/chunk-5HR2GPSC.js +0 -11031
  147. package/dist/chunk-5HR2GPSC.js.map +0 -1
  148. package/dist/chunk-7JZMI22I.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/spreadsheet-artifact-date.ts","../src/spreadsheet-artifact-commands.ts"],"sourcesContent":["const ECMASCRIPT_DATE_MAX_MILLISECONDS = 8_640_000_000_000_000n;\n\n/** Parses only the exact string form emitted by `Date.prototype.toISOString`. */\nexport function canonicalSpreadsheetDateMilliseconds(value: unknown): number {\n const milliseconds = typeof value === \"string\" ? Date.parse(value) : Number.NaN;\n if (!Number.isFinite(milliseconds) || new Date(milliseconds).toISOString() !== value) {\n throw new TypeError(\"date must be canonical ISO\");\n }\n return milliseconds;\n}\n\n/** Converts a signed wire integer to a canonical ISO instant without lossy coercion. */\nexport function canonicalSpreadsheetDateFromMilliseconds(milliseconds: bigint): string {\n if (\n milliseconds < -ECMASCRIPT_DATE_MAX_MILLISECONDS ||\n milliseconds > ECMASCRIPT_DATE_MAX_MILLISECONDS\n ) {\n throw new RangeError(\"date outside supported range\");\n }\n return new Date(Number(milliseconds)).toISOString();\n}\n","import {\n canonicalSpreadsheetDateFromMilliseconds,\n canonicalSpreadsheetDateMilliseconds,\n} from \"./spreadsheet-artifact-date\";\n\n/**\n * Canonical, identity-free spreadsheet mutation commands nested inside\n * `OGATX001`. Artifact, actor, transaction, delivery, and causal identity must\n * never be added here: the outer authored-intent envelope is their sole wire\n * authority.\n */\n\nexport const SPREADSHEET_ARTIFACT_COMMAND_VERSION = 1 as const;\nexport const SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES = 4 * 1024 * 1024;\nexport const SPREADSHEET_ARTIFACT_COMMAND_MAX_COMMANDS = 4_096;\nexport const SPREADSHEET_ARTIFACT_COMMAND_MAX_CELLS = 1_000_000;\nexport const SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES = 1 * 1024 * 1024;\nexport const SPREADSHEET_ARTIFACT_SHEET_NAME_MAX_UTF16_UNITS = 31;\n\nconst MAGIC = new TextEncoder().encode(\"OGASC001\");\nconst HEADER_BYTES = 8 + 2 + 2 + 4 + 8;\nconst CHECKSUM_BYTES = 8;\nconst textEncoder = new TextEncoder();\nconst textDecoder = new TextDecoder(\"utf-8\", { fatal: true });\nconst LOWER_HEX_ID = /^[0-9a-f]{32}$/u;\nconst UINT64_HEX_ZERO = \"0\".repeat(16);\nconst UINT32_MAX = 0xffff_ffff;\nconst FNV_OFFSET = 0xcbf29ce484222325n;\nconst FNV_PRIME = 0x100000001b3n;\n\ndeclare const stableIdBrand: unique symbol;\n\n/** Fixed-width lowercase hexadecimal 128-bit id. Runtime helpers enforce use. */\nexport type EditableArtifactStableId = string & {\n readonly [stableIdBrand]: \"EditableArtifactStableId\";\n};\n\n/**\n * A concrete sheet generation. The object id follows the offline allocator\n * invariant (both 64-bit halves nonzero); a derived operation id reserves only\n * the all-zero 128-bit value.\n */\nexport type SpreadsheetSheetGeneration = Readonly<{\n kind: \"generation\";\n sheetId: EditableArtifactStableId;\n creationOperationId: EditableArtifactStableId;\n}>;\n\n/**\n * Reference to a sheet created by an earlier command in this same batch.\n * This avoids recursively embedding the creation operation id, which is\n * derived from the hash of the complete outer intent.\n */\nexport type SpreadsheetPriorCreatePrecondition = Readonly<{\n kind: \"created-in-batch\";\n sheetId: EditableArtifactStableId;\n createCommandIndex: number;\n}>;\n\nexport type SpreadsheetSheetPrecondition =\n | SpreadsheetSheetGeneration\n | SpreadsheetPriorCreatePrecondition;\n\nexport type SpreadsheetCellPoint = Readonly<{ row: number; column: number }>;\nexport type SpreadsheetCellRange = Readonly<{\n start: SpreadsheetCellPoint;\n end: SpreadsheetCellPoint;\n}>;\n\nexport type SpreadsheetFormulaError = Readonly<{ error: string }>;\nexport type SpreadsheetDateValue = Readonly<{ date: string }>;\nexport type SpreadsheetCellScalar =\n | null\n | boolean\n | number\n | string\n | SpreadsheetDateValue\n | SpreadsheetFormulaError;\nexport type SpreadsheetFormulaCell = Readonly<{\n formula: string;\n cached: SpreadsheetCellScalar;\n}>;\nexport type SpreadsheetCellInput = SpreadsheetCellScalar | SpreadsheetFormulaCell;\n\nexport type SpreadsheetCreateSheetCommand = Readonly<{\n kind: \"sheet.create\";\n sheetId: EditableArtifactStableId;\n name: string;\n after: SpreadsheetSheetPrecondition | null;\n}>;\n\nexport type SpreadsheetRenameSheetCommand = Readonly<{\n kind: \"sheet.rename\";\n sheet: SpreadsheetSheetPrecondition;\n name: string;\n}>;\n\nexport type SpreadsheetDeleteSheetCommand = Readonly<{\n kind: \"sheet.delete\";\n sheet: SpreadsheetSheetPrecondition;\n}>;\n\n/** Row-major rectangular write; `cells.length === rows * columns`. */\nexport type SpreadsheetSetCellsCommand = Readonly<{\n kind: \"cells.set\";\n sheet: SpreadsheetSheetPrecondition;\n anchor: SpreadsheetCellPoint;\n rows: number;\n columns: number;\n cells: readonly SpreadsheetCellInput[];\n}>;\n\nexport type SpreadsheetClearRangeCommand = Readonly<{\n kind: \"range.clear\";\n sheet: SpreadsheetSheetPrecondition;\n range: SpreadsheetCellRange;\n}>;\n\nexport type SpreadsheetArtifactCommand =\n | SpreadsheetCreateSheetCommand\n | SpreadsheetRenameSheetCommand\n | SpreadsheetDeleteSheetCommand\n | SpreadsheetSetCellsCommand\n | SpreadsheetClearRangeCommand;\n\nexport type SpreadsheetArtifactCommandBatch = Readonly<{\n version: typeof SPREADSHEET_ARTIFACT_COMMAND_VERSION;\n commands: readonly SpreadsheetArtifactCommand[];\n}>;\n\n/** Validates a generic nonzero 128-bit id and returns its nominal type. */\nexport function editableArtifactStableId(value: string): EditableArtifactStableId {\n return genericStableId(value, \"stable id\");\n}\n\n/** Validates a sheet object id with nonzero allocator namespace and counter. */\nexport function spreadsheetSheetId(value: string): EditableArtifactStableId {\n return sheetObjectId(value, \"sheet id\");\n}\n\nexport function encodeSpreadsheetArtifactCommandBatch(\n input: SpreadsheetArtifactCommandBatch,\n): Uint8Array {\n const batch = batchRecord(input);\n const payload = new BinaryWriter(\n SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES - HEADER_BYTES - CHECKSUM_BYTES,\n );\n const context = new CommandContext();\n for (let index = 0; index < batch.commands.length; index += 1) {\n const command = ownArrayElement(batch.commands, index, \"commands\");\n encodeCommand(payload, command, index, context);\n }\n\n const payloadBytes = payload.finish();\n const output = new BinaryWriter(SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES);\n output.bytes(MAGIC);\n output.u16(SPREADSHEET_ARTIFACT_COMMAND_VERSION);\n output.u16(0);\n output.u32(batch.commands.length);\n output.u64(BigInt(payloadBytes.byteLength));\n output.bytes(payloadBytes);\n output.u64(fnv1a64(output.view()));\n return output.finish();\n}\n\nexport function decodeSpreadsheetArtifactCommandBatch(\n bytes: Uint8Array,\n): SpreadsheetArtifactCommandBatch {\n if (!(bytes instanceof Uint8Array)) {\n throw new TypeError(\"spreadsheet command bytes must be a Uint8Array\");\n }\n if (bytes.byteLength > SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES) {\n throw new RangeError(\"spreadsheet command envelope exceeds its byte limit\");\n }\n if (bytes.byteLength < HEADER_BYTES + CHECKSUM_BYTES) {\n throw new TypeError(\"truncated spreadsheet command envelope\");\n }\n const header = new BinaryReader(bytes);\n if (!equalBytes(header.bytes(MAGIC.byteLength), MAGIC)) {\n throw new TypeError(\"invalid spreadsheet command magic\");\n }\n const version = header.u16();\n if (version !== SPREADSHEET_ARTIFACT_COMMAND_VERSION) {\n throw new TypeError(`unsupported spreadsheet command version: ${version}`);\n }\n if (header.u16() !== 0) {\n throw new TypeError(\"spreadsheet command reserved flags must be zero\");\n }\n const commandCount = header.u32();\n if (commandCount < 1 || commandCount > SPREADSHEET_ARTIFACT_COMMAND_MAX_COMMANDS) {\n throw new RangeError(\"spreadsheet command count is outside its limit\");\n }\n const payloadLength = safeLength(header.u64(), \"spreadsheet command payload\");\n const expectedLength = HEADER_BYTES + payloadLength + CHECKSUM_BYTES;\n if (bytes.byteLength < expectedLength) {\n throw new TypeError(\"truncated spreadsheet command envelope\");\n }\n if (bytes.byteLength > expectedLength) {\n throw new TypeError(\"spreadsheet command envelope contains trailing bytes\");\n }\n const advertisedChecksum = readU64At(bytes, expectedLength - CHECKSUM_BYTES);\n const actualChecksum = fnv1a64(bytes.subarray(0, expectedLength - CHECKSUM_BYTES));\n if (advertisedChecksum !== actualChecksum) {\n throw new TypeError(\"spreadsheet command checksum does not match\");\n }\n\n const payload = new BinaryReader(bytes.subarray(HEADER_BYTES, HEADER_BYTES + payloadLength));\n const context = new CommandContext();\n const commands: SpreadsheetArtifactCommand[] = [];\n for (let index = 0; index < commandCount; index += 1) {\n commands.push(decodeCommand(payload, index, context));\n }\n payload.done(\"spreadsheet command payload contains trailing bytes\");\n return Object.freeze({\n version: SPREADSHEET_ARTIFACT_COMMAND_VERSION,\n commands: Object.freeze(commands),\n });\n}\n\n/** Decodes, re-encodes, and proves byte-for-byte canonicality. */\nexport function assertCanonicalSpreadsheetArtifactCommandBytes(bytes: Uint8Array): Uint8Array {\n const canonical = encodeSpreadsheetArtifactCommandBatch(\n decodeSpreadsheetArtifactCommandBatch(bytes),\n );\n if (!equalBytes(bytes, canonical)) {\n throw new TypeError(\"spreadsheet command envelope is not canonical\");\n }\n return bytes;\n}\n\nclass CommandContext {\n readonly createdByIndex = new Map<number, string>();\n readonly createdSheetIds = new Set<string>();\n totalCells = 0;\n\n registerCreate(index: number, sheetId: string): void {\n if (this.createdSheetIds.has(sheetId)) {\n throw commandError(index, \"sheet id is created more than once in the batch\");\n }\n this.createdByIndex.set(index, sheetId);\n this.createdSheetIds.add(sheetId);\n }\n\n addCells(index: number, rows: number, columns: number): number {\n const count = rows * columns;\n if (!Number.isSafeInteger(count) || count < 1) {\n throw commandError(index, \"cell block dimensions are invalid\");\n }\n const next = this.totalCells + count;\n if (!Number.isSafeInteger(next) || next > SPREADSHEET_ARTIFACT_COMMAND_MAX_CELLS) {\n throw commandError(index, \"cell count exceeds its transaction limit\");\n }\n this.totalCells = next;\n return count;\n }\n}\n\nfunction encodeCommand(\n writer: BinaryWriter,\n value: unknown,\n index: number,\n context: CommandContext,\n): void {\n const command = plainRecord(value, `spreadsheet command ${index}`);\n switch (command.kind) {\n case \"sheet.create\": {\n exactKeys(command, [\"after\", \"kind\", \"name\", \"sheetId\"], `spreadsheet command ${index}`);\n const sheetId = sheetObjectId(command.sheetId, `spreadsheet command ${index} sheetId`);\n const name = sheetName(command.name, index);\n writer.u8(0);\n writer.stableId(sheetId);\n writer.string(name, SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);\n if (command.after === null) {\n writer.u8(0);\n } else {\n writer.u8(1);\n encodeSheetPrecondition(writer, command.after, index, context);\n }\n context.registerCreate(index, sheetId);\n break;\n }\n case \"sheet.rename\": {\n exactKeys(command, [\"kind\", \"name\", \"sheet\"], `spreadsheet command ${index}`);\n writer.u8(1);\n encodeSheetPrecondition(writer, command.sheet, index, context);\n writer.string(sheetName(command.name, index), SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);\n break;\n }\n case \"sheet.delete\": {\n exactKeys(command, [\"kind\", \"sheet\"], `spreadsheet command ${index}`);\n writer.u8(2);\n encodeSheetPrecondition(writer, command.sheet, index, context);\n break;\n }\n case \"cells.set\": {\n exactKeys(\n command,\n [\"anchor\", \"cells\", \"columns\", \"kind\", \"rows\", \"sheet\"],\n `spreadsheet command ${index}`,\n );\n const anchor = point(command.anchor, `spreadsheet command ${index} anchor`);\n const rows = positiveU32(command.rows, `spreadsheet command ${index} rows`);\n const columns = positiveU32(command.columns, `spreadsheet command ${index} columns`);\n assertExtent(anchor.row, rows, \"row\", index);\n assertExtent(anchor.column, columns, \"column\", index);\n const count = context.addCells(index, rows, columns);\n if (!Array.isArray(command.cells) || command.cells.length !== count) {\n throw commandError(index, `cells must contain exactly ${count} row-major values`);\n }\n writer.u8(3);\n encodeSheetPrecondition(writer, command.sheet, index, context);\n writer.u32(anchor.row);\n writer.u32(anchor.column);\n writer.u32(rows);\n writer.u32(columns);\n for (let cellIndex = 0; cellIndex < count; cellIndex += 1) {\n writer.cell(\n ownArrayElement(command.cells, cellIndex, `spreadsheet command ${index} cells`),\n );\n }\n break;\n }\n case \"range.clear\": {\n exactKeys(command, [\"kind\", \"range\", \"sheet\"], `spreadsheet command ${index}`);\n const range = cellRange(command.range, index);\n writer.u8(4);\n encodeSheetPrecondition(writer, command.sheet, index, context);\n writer.u32(range.start.row);\n writer.u32(range.start.column);\n writer.u32(range.end.row);\n writer.u32(range.end.column);\n break;\n }\n default:\n throw commandError(index, \"unknown command kind\");\n }\n}\n\nfunction decodeCommand(\n reader: BinaryReader,\n index: number,\n context: CommandContext,\n): SpreadsheetArtifactCommand {\n switch (reader.u8()) {\n case 0: {\n const sheetId = reader.sheetObjectId();\n const name = decodedSheetName(\n reader.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES),\n index,\n );\n const afterFlag = reader.u8();\n if (afterFlag > 1) throw commandError(index, \"after presence flag is invalid\");\n const after = afterFlag === 1 ? decodeSheetPrecondition(reader, index, context) : null;\n context.registerCreate(index, sheetId);\n return Object.freeze({ kind: \"sheet.create\", sheetId, name, after });\n }\n case 1:\n return Object.freeze({\n kind: \"sheet.rename\",\n sheet: decodeSheetPrecondition(reader, index, context),\n name: decodedSheetName(reader.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES), index),\n });\n case 2:\n return Object.freeze({\n kind: \"sheet.delete\",\n sheet: decodeSheetPrecondition(reader, index, context),\n });\n case 3: {\n const sheet = decodeSheetPrecondition(reader, index, context);\n const anchor = frozenPoint(reader.u32(), reader.u32());\n const rows = reader.u32();\n const columns = reader.u32();\n if (rows === 0 || columns === 0) {\n throw commandError(index, \"cell block dimensions must be nonzero\");\n }\n assertExtent(anchor.row, rows, \"row\", index);\n assertExtent(anchor.column, columns, \"column\", index);\n const count = context.addCells(index, rows, columns);\n const cells: SpreadsheetCellInput[] = [];\n for (let cellIndex = 0; cellIndex < count; cellIndex += 1) cells.push(reader.cell());\n return Object.freeze({\n kind: \"cells.set\",\n sheet,\n anchor,\n rows,\n columns,\n cells: Object.freeze(cells),\n });\n }\n case 4: {\n const sheet = decodeSheetPrecondition(reader, index, context);\n const start = frozenPoint(reader.u32(), reader.u32());\n const end = frozenPoint(reader.u32(), reader.u32());\n if (start.row > end.row || start.column > end.column) {\n throw commandError(index, \"clear range endpoints are not ordered\");\n }\n return Object.freeze({\n kind: \"range.clear\",\n sheet,\n range: Object.freeze({ start, end }),\n });\n }\n default:\n throw commandError(index, \"unknown binary command tag\");\n }\n}\n\nfunction encodeSheetPrecondition(\n writer: BinaryWriter,\n value: unknown,\n commandIndex: number,\n context: CommandContext,\n): void {\n const input = plainRecord(value, `spreadsheet command ${commandIndex} sheet precondition`);\n if (input.kind === \"generation\") {\n exactKeys(\n input,\n [\"creationOperationId\", \"kind\", \"sheetId\"],\n `spreadsheet command ${commandIndex} sheet generation`,\n );\n writer.u8(0);\n writer.stableId(sheetObjectId(input.sheetId, \"sheet generation sheetId\"));\n writer.stableId(genericStableId(input.creationOperationId, \"sheet creation operation id\"));\n return;\n }\n if (input.kind === \"created-in-batch\") {\n exactKeys(\n input,\n [\"createCommandIndex\", \"kind\", \"sheetId\"],\n `spreadsheet command ${commandIndex} prior-create precondition`,\n );\n const sheetId = sheetObjectId(input.sheetId, \"prior-create sheetId\");\n const createCommandIndex = nonnegativeU32(\n input.createCommandIndex,\n \"prior-create command index\",\n );\n assertPriorCreate(context, commandIndex, createCommandIndex, sheetId);\n writer.u8(1);\n writer.stableId(sheetId);\n writer.u32(createCommandIndex);\n return;\n }\n throw commandError(commandIndex, \"unknown sheet precondition kind\");\n}\n\nfunction decodeSheetPrecondition(\n reader: BinaryReader,\n commandIndex: number,\n context: CommandContext,\n): SpreadsheetSheetPrecondition {\n switch (reader.u8()) {\n case 0:\n return Object.freeze({\n kind: \"generation\",\n sheetId: reader.sheetObjectId(),\n creationOperationId: reader.genericStableId(),\n });\n case 1: {\n const sheetId = reader.sheetObjectId();\n const createCommandIndex = reader.u32();\n assertPriorCreate(context, commandIndex, createCommandIndex, sheetId);\n return Object.freeze({\n kind: \"created-in-batch\",\n sheetId,\n createCommandIndex,\n });\n }\n default:\n throw commandError(commandIndex, \"unknown sheet precondition tag\");\n }\n}\n\nfunction assertPriorCreate(\n context: CommandContext,\n commandIndex: number,\n createCommandIndex: number,\n sheetId: string,\n): void {\n if (createCommandIndex >= commandIndex) {\n throw commandError(commandIndex, \"prior-create reference must point to an earlier command\");\n }\n if (context.createdByIndex.get(createCommandIndex) !== sheetId) {\n throw commandError(\n commandIndex,\n \"prior-create reference must match the referenced create command and sheet id\",\n );\n }\n}\n\nfunction batchRecord(input: unknown): SpreadsheetArtifactCommandBatch {\n const batch = plainRecord(input, \"spreadsheet command batch\");\n exactKeys(batch, [\"commands\", \"version\"], \"spreadsheet command batch\");\n if (batch.version !== SPREADSHEET_ARTIFACT_COMMAND_VERSION) {\n throw new TypeError(\"spreadsheet command batch version must be 1\");\n }\n if (!Array.isArray(batch.commands)) throw new TypeError(\"commands must be an array\");\n if (\n batch.commands.length < 1 ||\n batch.commands.length > SPREADSHEET_ARTIFACT_COMMAND_MAX_COMMANDS\n ) {\n throw new RangeError(\"spreadsheet command count is outside its limit\");\n }\n return input as SpreadsheetArtifactCommandBatch;\n}\n\nfunction cellRange(value: unknown, index: number): SpreadsheetCellRange {\n const range = plainRecord(value, `spreadsheet command ${index} range`);\n exactKeys(range, [\"end\", \"start\"], `spreadsheet command ${index} range`);\n const start = point(range.start, `spreadsheet command ${index} range start`);\n const end = point(range.end, `spreadsheet command ${index} range end`);\n if (start.row > end.row || start.column > end.column) {\n throw commandError(index, \"clear range endpoints are not ordered\");\n }\n return { start, end };\n}\n\nfunction point(value: unknown, label: string): SpreadsheetCellPoint {\n const input = plainRecord(value, label);\n exactKeys(input, [\"column\", \"row\"], label);\n return {\n row: nonnegativeU32(input.row, `${label} row`),\n column: nonnegativeU32(input.column, `${label} column`),\n };\n}\n\nfunction frozenPoint(row: number, column: number): SpreadsheetCellPoint {\n return Object.freeze({ row, column });\n}\n\nfunction sheetName(value: unknown, index: number): string {\n if (typeof value !== \"string\") throw commandError(index, \"sheet name must be a string\");\n return decodedSheetName(value, index);\n}\n\nfunction decodedSheetName(value: string, index: number): string {\n const bytes = strictUtf8(value, \"sheet name\");\n const forbidden = /[\\\\/?*[\\]:\\0]/u.test(value);\n if (\n bytes.byteLength === 0 ||\n value.trim() !== value ||\n value.length > SPREADSHEET_ARTIFACT_SHEET_NAME_MAX_UTF16_UNITS ||\n forbidden\n ) {\n throw commandError(index, \"sheet name does not match the public spreadsheet model\");\n }\n return value;\n}\n\nfunction genericStableId(value: unknown, label: string): EditableArtifactStableId {\n if (typeof value !== \"string\" || !LOWER_HEX_ID.test(value) || /^0+$/u.test(value)) {\n throw new TypeError(`${label} must be nonzero fixed-width lowercase hexadecimal text`);\n }\n return value as EditableArtifactStableId;\n}\n\nfunction sheetObjectId(value: unknown, label: string): EditableArtifactStableId {\n const id = genericStableId(value, label);\n if (id.slice(0, 16) === UINT64_HEX_ZERO || id.slice(16) === UINT64_HEX_ZERO) {\n throw new TypeError(`${label} must have a nonzero namespace and counter`);\n }\n return id;\n}\n\nfunction positiveU32(value: unknown, label: string): number {\n const output = nonnegativeU32(value, label);\n if (output === 0) throw new TypeError(`${label} must be positive`);\n return output;\n}\n\nfunction nonnegativeU32(value: unknown, label: string): number {\n if (!Number.isInteger(value) || (value as number) < 0 || (value as number) > UINT32_MAX) {\n throw new TypeError(`${label} must be a uint32`);\n }\n return value as number;\n}\n\nfunction assertExtent(start: number, length: number, axis: string, index: number): void {\n if (length - 1 > UINT32_MAX - start) {\n throw commandError(index, `${axis} extent exceeds uint32 coordinates`);\n }\n}\n\nfunction safeLength(value: bigint, label: string): number {\n if (value > BigInt(Number.MAX_SAFE_INTEGER)) throw new RangeError(`${label} length is unsafe`);\n const length = Number(value);\n if (length > SPREADSHEET_ARTIFACT_COMMAND_MAX_BYTES - HEADER_BYTES - CHECKSUM_BYTES) {\n throw new RangeError(`${label} exceeds its byte limit`);\n }\n return length;\n}\n\nfunction plainRecord(value: unknown, label: string): Record<string, unknown> {\n if (\n typeof value !== \"object\" ||\n value === null ||\n Array.isArray(value) ||\n Object.getPrototypeOf(value) !== Object.prototype\n ) {\n throw new TypeError(`${label} must be a plain record`);\n }\n return value as Record<string, unknown>;\n}\n\nfunction exactKeys(\n value: Record<string, unknown>,\n expected: readonly string[],\n label: string,\n): void {\n const keys = Reflect.ownKeys(value);\n if (keys.some((key) => typeof key !== \"string\")) {\n throw new TypeError(`${label} contains unsupported symbol fields`);\n }\n const actual = (keys as string[]).sort(compareCodeUnits);\n if (actual.length !== expected.length || actual.some((key, index) => key !== expected[index])) {\n throw new TypeError(`${label} fields must be exactly: ${expected.join(\", \")}`);\n }\n for (const key of actual) {\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (!descriptor || !(\"value\" in descriptor) || !descriptor.enumerable) {\n throw new TypeError(`${label} fields must be enumerable data properties`);\n }\n }\n}\n\nfunction ownArrayElement(value: readonly unknown[], index: number, label: string): unknown {\n if (!Object.hasOwn(value, index)) throw new TypeError(`${label} must be dense`);\n return value[index];\n}\n\nfunction commandError(index: number, message: string): TypeError {\n return new TypeError(`spreadsheet command ${index}: ${message}`);\n}\n\nfunction strictUtf8(value: string, label: string): Uint8Array {\n for (let index = 0; index < value.length; index += 1) {\n const code = value.charCodeAt(index);\n if (code >= 0xd800 && code <= 0xdbff) {\n const next = value.charCodeAt(index + 1);\n if (!(next >= 0xdc00 && next <= 0xdfff)) {\n throw new TypeError(`${label} contains an unpaired surrogate`);\n }\n index += 1;\n } else if (code >= 0xdc00 && code <= 0xdfff) {\n throw new TypeError(`${label} contains an unpaired surrogate`);\n }\n }\n return textEncoder.encode(value);\n}\n\nfunction compareCodeUnits(left: string, right: string): number {\n return left < right ? -1 : left > right ? 1 : 0;\n}\n\nfunction fnv1a64(bytes: Uint8Array): bigint {\n let hash = FNV_OFFSET;\n for (const byte of bytes) {\n hash ^= BigInt(byte);\n hash = BigInt.asUintN(64, hash * FNV_PRIME);\n }\n return hash;\n}\n\nfunction equalBytes(left: Uint8Array, right: Uint8Array): boolean {\n return (\n left.byteLength === right.byteLength && left.every((value, index) => value === right[index])\n );\n}\n\nfunction readU64At(bytes: Uint8Array, offset: number): bigint {\n let value = 0n;\n for (let index = 0; index < 8; index += 1) {\n value |= BigInt(bytes[offset + index]!) << BigInt(index * 8);\n }\n return value;\n}\n\nconst STANDARD_ERROR_TAGS = Object.freeze({\n \"#NULL!\": 0,\n \"#DIV/0!\": 1,\n \"#VALUE!\": 2,\n \"#REF!\": 3,\n \"#NAME?\": 4,\n \"#NUM!\": 5,\n \"#N/A\": 6,\n \"#SPILL!\": 7,\n \"#CALC!\": 8,\n} satisfies Record<string, number>);\n\nconst STANDARD_ERRORS = Object.freeze([\n \"#NULL!\",\n \"#DIV/0!\",\n \"#VALUE!\",\n \"#REF!\",\n \"#NAME?\",\n \"#NUM!\",\n \"#N/A\",\n \"#SPILL!\",\n \"#CALC!\",\n] as const);\n\nclass BinaryWriter {\n private buffer: Uint8Array;\n private viewBuffer: DataView;\n private length = 0;\n\n constructor(private readonly maximum: number) {\n this.buffer = new Uint8Array(Math.min(1_024, maximum));\n this.viewBuffer = new DataView(this.buffer.buffer);\n }\n\n view(): Uint8Array {\n return this.buffer.subarray(0, this.length);\n }\n\n finish(): Uint8Array {\n return this.buffer.slice(0, this.length);\n }\n\n u8(value: number): void {\n this.reserve(1);\n this.viewBuffer.setUint8(this.length, value);\n this.length += 1;\n }\n\n u16(value: number): void {\n this.reserve(2);\n this.viewBuffer.setUint16(this.length, value, true);\n this.length += 2;\n }\n\n u32(value: number): void {\n this.reserve(4);\n this.viewBuffer.setUint32(this.length, value, true);\n this.length += 4;\n }\n\n u64(value: bigint): void {\n this.reserve(8);\n this.viewBuffer.setBigUint64(this.length, value, true);\n this.length += 8;\n }\n\n i64(value: bigint): void {\n this.reserve(8);\n this.viewBuffer.setBigInt64(this.length, value, true);\n this.length += 8;\n }\n\n f64(value: number): void {\n this.reserve(8);\n this.viewBuffer.setFloat64(this.length, value === 0 ? 0 : value, true);\n this.length += 8;\n }\n\n stableId(value: EditableArtifactStableId): void {\n // Text is namespace || counter; canonical model bytes are counter LE then\n // namespace LE, matching Rust `StableId::to_le_bytes`.\n this.u64(BigInt(`0x${value.slice(16)}`));\n this.u64(BigInt(`0x${value.slice(0, 16)}`));\n }\n\n string(value: string, maximum: number): void {\n const bytes = strictUtf8(value, \"spreadsheet string\");\n if (bytes.byteLength > maximum)\n throw new RangeError(\"spreadsheet string exceeds its byte limit\");\n this.u32(bytes.byteLength);\n this.bytes(bytes);\n }\n\n cell(value: unknown): void {\n if (isFormulaCell(value)) {\n const cell = plainRecord(value, \"formula cell\");\n exactKeys(cell, [\"cached\", \"formula\"], \"formula cell\");\n if (typeof cell.formula !== \"string\" || cell.formula.length === 0) {\n throw new TypeError(\"formula source must be a nonempty string\");\n }\n this.u8(1);\n this.string(cell.formula, SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);\n this.scalar(cell.cached);\n return;\n }\n this.u8(0);\n this.scalar(value);\n }\n\n private scalar(value: unknown): void {\n if (value === null) {\n this.u8(0);\n } else if (value === false) {\n this.u8(1);\n } else if (value === true) {\n this.u8(2);\n } else if (typeof value === \"number\") {\n if (!Number.isFinite(value)) throw new TypeError(\"spreadsheet numbers must be finite\");\n this.u8(3);\n this.f64(value);\n } else if (typeof value === \"string\") {\n this.u8(4);\n this.string(value, SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);\n } else if (isDateValue(value)) {\n const date = plainRecord(value, \"date cell\");\n exactKeys(date, [\"date\"], \"date cell\");\n this.u8(6);\n this.i64(BigInt(canonicalDateMilliseconds(date.date)));\n } else if (isFormulaError(value)) {\n const error = plainRecord(value, \"formula error\");\n exactKeys(error, [\"error\"], \"formula error\");\n this.u8(5);\n const tag = STANDARD_ERROR_TAGS[error.error as keyof typeof STANDARD_ERROR_TAGS];\n if (tag !== undefined) {\n this.u8(tag);\n } else {\n this.u8(9);\n this.string(error.error as string, SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);\n }\n } else {\n throw new TypeError(\"spreadsheet cell has an unsupported value shape\");\n }\n }\n\n bytes(value: Uint8Array): void {\n this.reserve(value.byteLength);\n this.buffer.set(value, this.length);\n this.length += value.byteLength;\n }\n\n private reserve(additional: number): void {\n const needed = this.length + additional;\n if (!Number.isSafeInteger(needed) || needed > this.maximum) {\n throw new RangeError(\"spreadsheet command envelope exceeds its byte limit\");\n }\n if (needed <= this.buffer.byteLength) return;\n let size = Math.max(1, this.buffer.byteLength);\n while (size < needed) size = Math.min(this.maximum, size * 2);\n const next = new Uint8Array(size);\n next.set(this.buffer.subarray(0, this.length));\n this.buffer = next;\n this.viewBuffer = new DataView(next.buffer);\n }\n}\n\nclass BinaryReader {\n private offset = 0;\n\n constructor(private readonly input: Uint8Array) {}\n\n u8(): number {\n return this.bytes(1)[0]!;\n }\n\n u16(): number {\n const bytes = this.bytes(2);\n return bytes[0]! | (bytes[1]! << 8);\n }\n\n u32(): number {\n const bytes = this.bytes(4);\n return bytes[0]! + bytes[1]! * 2 ** 8 + bytes[2]! * 2 ** 16 + bytes[3]! * 2 ** 24;\n }\n\n u64(): bigint {\n const bytes = this.bytes(8);\n let value = 0n;\n for (let index = 0; index < 8; index += 1) {\n value |= BigInt(bytes[index]!) << BigInt(index * 8);\n }\n return value;\n }\n\n i64(): bigint {\n const bytes = this.bytes(8);\n return new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getBigInt64(0, true);\n }\n\n f64(): number {\n const bytes = this.bytes(8);\n const value = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength).getFloat64(\n 0,\n true,\n );\n if (!Number.isFinite(value)) throw new TypeError(\"spreadsheet numbers must be finite\");\n if (Object.is(value, -0)) {\n throw new TypeError(\"spreadsheet numbers must encode zero with a positive sign\");\n }\n return value;\n }\n\n sheetObjectId(): EditableArtifactStableId {\n return sheetObjectId(this.stableIdText(), \"sheet id\");\n }\n\n genericStableId(): EditableArtifactStableId {\n return genericStableId(this.stableIdText(), \"stable id\");\n }\n\n string(maximum: number): string {\n const length = this.u32();\n if (length > maximum) throw new RangeError(\"spreadsheet string exceeds its byte limit\");\n return textDecoder.decode(this.bytes(length));\n }\n\n cell(): SpreadsheetCellInput {\n const formulaTag = this.u8();\n if (formulaTag > 1) throw new TypeError(\"spreadsheet formula presence tag is invalid\");\n const formula =\n formulaTag === 1\n ? this.nonemptyFormula(this.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES))\n : null;\n const cached = this.scalar();\n return formula === null ? cached : Object.freeze({ formula, cached });\n }\n\n done(message: string): void {\n if (this.offset !== this.input.byteLength) throw new TypeError(message);\n }\n\n bytes(length: number): Uint8Array {\n const end = this.offset + length;\n if (!Number.isSafeInteger(length) || length < 0 || end > this.input.byteLength) {\n throw new TypeError(\"truncated spreadsheet command envelope\");\n }\n const result = this.input.subarray(this.offset, end);\n this.offset = end;\n return result;\n }\n\n private stableIdText(): string {\n const counter = this.u64().toString(16).padStart(16, \"0\");\n const namespace = this.u64().toString(16).padStart(16, \"0\");\n return `${namespace}${counter}`;\n }\n\n private nonemptyFormula(value: string): string {\n if (value.length === 0) throw new TypeError(\"formula source must not be empty\");\n return value;\n }\n\n private scalar(): SpreadsheetCellScalar {\n switch (this.u8()) {\n case 0:\n return null;\n case 1:\n return false;\n case 2:\n return true;\n case 3:\n return this.f64();\n case 4:\n return this.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES);\n case 5: {\n const tag = this.u8();\n if (tag <= 8) return Object.freeze({ error: STANDARD_ERRORS[tag]! });\n if (tag === 9) {\n return Object.freeze({\n error: this.string(SPREADSHEET_ARTIFACT_COMMAND_MAX_STRING_BYTES),\n });\n }\n throw new TypeError(\"spreadsheet formula error tag is invalid\");\n }\n case 6:\n return Object.freeze({\n date: canonicalSpreadsheetDateFromMilliseconds(this.i64()),\n });\n default:\n throw new TypeError(\"spreadsheet scalar tag is invalid\");\n }\n }\n}\n\nfunction isFormulaCell(value: unknown): value is SpreadsheetFormulaCell {\n return (\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n Object.hasOwn(value, \"formula\")\n );\n}\n\nfunction isFormulaError(value: unknown): value is SpreadsheetFormulaError {\n return (\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n typeof (value as Record<string, unknown>).error === \"string\"\n );\n}\n\nfunction isDateValue(value: unknown): value is SpreadsheetDateValue {\n return (\n typeof value === \"object\" &&\n value !== null &&\n !Array.isArray(value) &&\n Object.hasOwn(value, \"date\")\n );\n}\n\nfunction canonicalDateMilliseconds(value: unknown): number {\n return canonicalSpreadsheetDateMilliseconds(value);\n}\n"],"mappings":";AAAA,IAAM,mCAAmC;AAGlC,SAAS,qCAAqC,OAAwB;AAC3E,QAAM,eAAe,OAAO,UAAU,WAAW,KAAK,MAAM,KAAK,IAAI,OAAO;AAC5E,MAAI,CAAC,OAAO,SAAS,YAAY,KAAK,IAAI,KAAK,YAAY,EAAE,YAAY,MAAM,OAAO;AACpF,UAAM,IAAI,UAAU,4BAA4B;AAAA,EAClD;AACA,SAAO;AACT;AAGO,SAAS,yCAAyC,cAA8B;AACrF,MACE,eAAe,CAAC,oCAChB,eAAe,kCACf;AACA,UAAM,IAAI,WAAW,8BAA8B;AAAA,EACrD;AACA,SAAO,IAAI,KAAK,OAAO,YAAY,CAAC,EAAE,YAAY;AACpD;;;ACRO,IAAM,uCAAuC;AAC7C,IAAM,yCAAyC,IAAI,OAAO;AAC1D,IAAM,4CAA4C;AAClD,IAAM,yCAAyC;AAC/C,IAAM,gDAAgD,IAAI,OAAO;AACjE,IAAM,kDAAkD;AAE/D,IAAM,QAAQ,IAAI,YAAY,EAAE,OAAO,UAAU;AACjD,IAAM,eAAe,IAAI,IAAI,IAAI,IAAI;AACrC,IAAM,iBAAiB;AACvB,IAAM,cAAc,IAAI,YAAY;AACpC,IAAM,cAAc,IAAI,YAAY,SAAS,EAAE,OAAO,KAAK,CAAC;AAC5D,IAAM,eAAe;AACrB,IAAM,kBAAkB,IAAI,OAAO,EAAE;AACrC,IAAM,aAAa;AACnB,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O,OAAO,OAAO,SAAS;AAElC;AAEA,SAAS,eAAe,OAAkD;AACxE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,QAAQ,KAAK,KACpB,OAAQ,MAAkC,UAAU;AAExD;AAEA,SAAS,YAAY,OAA+C;AAClE,SACE,OAAO,UAAU,YACjB,UAAU,QACV,CAAC,MAAM,QAAQ,KAAK,KACpB,OAAO,OAAO,OAAO,MAAM;AAE/B;AAEA,SAAS,0BAA0B,OAAwB;AACzD,SAAO,qCAAqC,KAAK;AACnD;","names":[]}
@@ -0,0 +1,382 @@
1
+ import {
2
+ EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
3
+ decodeEditableArtifactMutationIntent,
4
+ encodeEditableArtifactMutationIntent,
5
+ hashEditableArtifactMutationIntentBytes
6
+ } from "./chunk-TZ6YEYN4.js";
7
+ import {
8
+ editableArtifactCodecFor
9
+ } from "./chunk-JBCIY7QD.js";
10
+ import {
11
+ DOCUMENT_ARTIFACT_COMMAND_MAX_COMMANDS,
12
+ DOCUMENT_ARTIFACT_MAX_STRUCTURAL_COUNTER
13
+ } from "./chunk-RIY7GYQS.js";
14
+ import {
15
+ ArtifactBinaryReader,
16
+ ArtifactBinaryWriter,
17
+ EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES,
18
+ EDITABLE_ARTIFACT_BINARY_HEADER_BYTES,
19
+ decodeCountedEnvelope,
20
+ equalBytes,
21
+ fnv1a64,
22
+ strictUtf8
23
+ } from "./chunk-MYBZRDTY.js";
24
+
25
+ // src/editable-artifact-serialized-commit.ts
26
+ import { bytesToHex } from "@noble/hashes/utils";
27
+ var EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION = 1;
28
+ var EDITABLE_ARTIFACT_SERIALIZED_COMMIT_MAX_BYTES = 8 * 1024 * 1024;
29
+ var EDITABLE_ARTIFACT_NATIVE_RECEIPT_MAX_BYTES = 512 * 1024;
30
+ var MAGIC = strictUtf8("OGAST001", "serialized commit magic");
31
+ var SHA256_TEXT = /^sha256:[0-9a-f]{64}$/u;
32
+ var STABLE_ID = /^[0-9a-f]{32}$/u;
33
+ var DOCUMENT_RECEIPT_MAGIC = "OGADR001";
34
+ var PRESENTATION_RECEIPT_MAGIC = strictUtf8("OGAPR001", "presentation receipt magic");
35
+ var DOCUMENT_RECEIPT_VERSION = 1;
36
+ var PRESENTATION_RECEIPT_VERSION = 1;
37
+ var DOCUMENT_CREATED_IDS_PER_COMMAND = 7;
38
+ var DOCUMENT_ID_BYTES = 17;
39
+ var PRESENTATION_RECEIPT_BYTES = 32;
40
+ var MODALITY_TAG = Object.freeze({ document: 1, presentation: 2 });
41
+ function encodeEditableArtifactSerializedCommit(input) {
42
+ const normalized = normalizeSerializedCommit(input);
43
+ const payload = new ArtifactBinaryWriter(
44
+ EDITABLE_ARTIFACT_SERIALIZED_COMMIT_MAX_BYTES - EDITABLE_ARTIFACT_BINARY_HEADER_BYTES - EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES
45
+ );
46
+ payload.stableId(normalized.transactionId, "serialized transaction id");
47
+ payload.u64(normalized.parentHeadSequence);
48
+ payload.u64(normalized.resultHeadSequence);
49
+ payload.u64(normalized.priorNativeRevision);
50
+ payload.bytes(hashBytes(normalized.priorStateHash));
51
+ payload.bytes(hashBytes(normalized.stateHash));
52
+ payload.u32(normalized.intentBytes.byteLength);
53
+ payload.u32(normalized.nativeReceiptBytes.byteLength);
54
+ payload.bytes(normalized.intentBytes);
55
+ payload.bytes(normalized.nativeReceiptBytes);
56
+ const payloadBytes = payload.finish();
57
+ const output = new ArtifactBinaryWriter(EDITABLE_ARTIFACT_SERIALIZED_COMMIT_MAX_BYTES);
58
+ output.bytes(MAGIC);
59
+ output.u16(EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION);
60
+ output.u16(0);
61
+ output.u32(MODALITY_TAG[normalized.modality]);
62
+ output.u64(payloadBytes.byteLength);
63
+ output.bytes(payloadBytes);
64
+ output.u64(fnv1a64(output.view()));
65
+ return output.finish();
66
+ }
67
+ function decodeEditableArtifactSerializedCommit(bytes, durableModality) {
68
+ assertUnsharedBytes(bytes, "serialized commit");
69
+ const modality = serializedModality(durableModality);
70
+ if (bytes.byteLength > EDITABLE_ARTIFACT_SERIALIZED_COMMIT_MAX_BYTES) {
71
+ throw new RangeError("serialized commit exceeds its byte limit");
72
+ }
73
+ if (bytes.byteLength < EDITABLE_ARTIFACT_BINARY_HEADER_BYTES + EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES) {
74
+ throw new TypeError("truncated serialized commit envelope");
75
+ }
76
+ const header = new ArtifactBinaryReader(bytes);
77
+ if (!equalBytes(header.bytes(8), MAGIC)) {
78
+ throw new TypeError("invalid serialized commit magic");
79
+ }
80
+ if (header.u16() !== EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION) {
81
+ throw new TypeError("unsupported serialized commit version");
82
+ }
83
+ if (header.u16() !== 0) {
84
+ throw new TypeError("reserved serialized commit flags must be zero");
85
+ }
86
+ if (header.u32() !== MODALITY_TAG[modality]) {
87
+ throw new TypeError("serialized commit modality disagrees with durable artifact");
88
+ }
89
+ const payloadLength = header.u64Safe("serialized commit payload length");
90
+ const expectedLength = EDITABLE_ARTIFACT_BINARY_HEADER_BYTES + payloadLength + EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES;
91
+ if (bytes.byteLength < expectedLength) {
92
+ throw new TypeError("truncated serialized commit payload");
93
+ }
94
+ if (bytes.byteLength > expectedLength) {
95
+ throw new TypeError("serialized commit contains trailing bytes");
96
+ }
97
+ const payloadBytes = header.bytes(payloadLength);
98
+ const checksum = header.u64BigInt();
99
+ header.done();
100
+ if (checksum !== fnv1a64(bytes.subarray(0, bytes.byteLength - EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES))) {
101
+ throw new TypeError("serialized commit checksum does not match");
102
+ }
103
+ const payload = new ArtifactBinaryReader(payloadBytes);
104
+ const transactionId = payload.stableId("serialized transaction id");
105
+ const parentHeadSequence = payload.u64Safe("serialized parent head sequence");
106
+ const resultHeadSequence = payload.u64Safe("serialized result head sequence");
107
+ const priorNativeRevision = payload.u64Safe("serialized prior native revision");
108
+ const priorStateHash = stateHashText(payload.bytes(32));
109
+ const stateHash = stateHashText(payload.bytes(32));
110
+ const intentLength = payload.count(
111
+ EDITABLE_ARTIFACT_INTENT_MAX_BYTES,
112
+ "serialized intent bytes",
113
+ 1
114
+ );
115
+ const receiptLength = payload.count(
116
+ EDITABLE_ARTIFACT_NATIVE_RECEIPT_MAX_BYTES,
117
+ "serialized native receipt bytes",
118
+ 1
119
+ );
120
+ if (payload.remaining !== intentLength + receiptLength) {
121
+ throw new TypeError("serialized commit nested byte lengths are inconsistent");
122
+ }
123
+ const intentBytes = payload.bytes(intentLength).slice();
124
+ const nativeReceiptBytes = payload.bytes(receiptLength).slice();
125
+ payload.done();
126
+ const normalized = normalizeSerializedCommit({
127
+ modality,
128
+ transactionId,
129
+ parentHeadSequence,
130
+ resultHeadSequence,
131
+ priorNativeRevision,
132
+ priorStateHash,
133
+ stateHash,
134
+ intentBytes,
135
+ nativeReceiptBytes
136
+ });
137
+ const canonical = encodeEditableArtifactSerializedCommit(normalized);
138
+ if (!equalBytes(bytes, canonical)) {
139
+ throw new TypeError("serialized commit is not canonically encoded");
140
+ }
141
+ return Object.freeze({
142
+ commitProtocolVersion: EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION,
143
+ modality,
144
+ transactionId,
145
+ parentHeadSequence,
146
+ resultHeadSequence,
147
+ priorNativeRevision,
148
+ priorStateHash,
149
+ stateHash,
150
+ requestHash: normalized.requestHash,
151
+ intent: normalized.intent,
152
+ intentBytes,
153
+ nativeReceiptBytes,
154
+ nativeReceipt: normalized.nativeReceipt
155
+ });
156
+ }
157
+ function assertCanonicalEditableArtifactSerializedCommit(bytes, durableModality) {
158
+ decodeEditableArtifactSerializedCommit(bytes, durableModality);
159
+ }
160
+ function normalizeSerializedCommit(input) {
161
+ const modality = serializedModality(input.modality);
162
+ const transactionId = canonicalStableId(input.transactionId, "serialized transaction id");
163
+ const parentHeadSequence = safeSequence(
164
+ input.parentHeadSequence,
165
+ "serialized parent head sequence"
166
+ );
167
+ const resultHeadSequence = safeSequence(
168
+ input.resultHeadSequence,
169
+ "serialized result head sequence"
170
+ );
171
+ if (resultHeadSequence !== parentHeadSequence + 1) {
172
+ throw new TypeError("serialized commit must advance the durable head exactly once");
173
+ }
174
+ const priorNativeRevision = safeSequence(
175
+ input.priorNativeRevision,
176
+ "serialized prior native revision"
177
+ );
178
+ const priorStateHash = canonicalSha256(input.priorStateHash, "serialized prior state hash");
179
+ const stateHash = canonicalSha256(input.stateHash, "serialized resulting state hash");
180
+ assertUnsharedBytes(input.intentBytes, "serialized intent");
181
+ assertUnsharedBytes(input.nativeReceiptBytes, "serialized native receipt");
182
+ if (input.intentBytes.byteLength < 1 || input.intentBytes.byteLength > EDITABLE_ARTIFACT_INTENT_MAX_BYTES) {
183
+ throw new RangeError("serialized intent bytes exceed their limit");
184
+ }
185
+ if (input.nativeReceiptBytes.byteLength < 1 || input.nativeReceiptBytes.byteLength > EDITABLE_ARTIFACT_NATIVE_RECEIPT_MAX_BYTES) {
186
+ throw new RangeError("serialized native receipt bytes exceed their limit");
187
+ }
188
+ const intentBytes = input.intentBytes.slice();
189
+ const decodedIntent = decodeEditableArtifactMutationIntent(intentBytes);
190
+ if (!equalBytes(intentBytes, encodeEditableArtifactMutationIntent(decodedIntent))) {
191
+ throw new TypeError("nested serialized intent is not canonical OGATX001");
192
+ }
193
+ if (decodedIntent.causalBase.length !== 0 || decodedIntent.selectiveUndoOperationIds.length !== 0) {
194
+ throw new TypeError("serialized commits cannot carry CRDT causality or selective undo");
195
+ }
196
+ if (decodedIntent.observedHeadSequence !== parentHeadSequence) {
197
+ throw new TypeError("serialized intent observed head does not match its parent");
198
+ }
199
+ const descriptor = editableArtifactCodecFor({
200
+ durableModality: modality,
201
+ modelSchemaVersion: decodedIntent.modelSchemaVersion,
202
+ commandProtocolVersion: decodedIntent.commandProtocolVersion
203
+ });
204
+ descriptor.command.assertCanonical(decodedIntent.commandBytes);
205
+ const commandCount = decodedCommandCount(descriptor.command.decode(decodedIntent.commandBytes));
206
+ if (commandCount < 1) {
207
+ throw new TypeError("serialized commits require a non-empty command batch");
208
+ }
209
+ const nativeReceiptBytes = input.nativeReceiptBytes.slice();
210
+ const nativeReceipt = decodeNativeReceipt(modality, nativeReceiptBytes, commandCount);
211
+ if (modality === "presentation") {
212
+ if (nativeReceipt.revision !== priorNativeRevision + 1) {
213
+ throw new TypeError(
214
+ "presentation receipt must advance its prior native revision exactly once"
215
+ );
216
+ }
217
+ if (stateHash === priorStateHash) {
218
+ throw new TypeError("presentation commit must change its canonical state hash");
219
+ }
220
+ } else if (nativeReceipt.revision === priorNativeRevision) {
221
+ if (stateHash !== priorStateHash) {
222
+ throw new TypeError("document no-op receipt cannot change the canonical state hash");
223
+ }
224
+ } else {
225
+ if (nativeReceipt.revision !== priorNativeRevision + 1) {
226
+ throw new TypeError(
227
+ "document receipt must preserve or advance its prior native revision once"
228
+ );
229
+ }
230
+ if (stateHash === priorStateHash) {
231
+ throw new TypeError("document revision advance must change the canonical state hash");
232
+ }
233
+ }
234
+ const requestHash = hashEditableArtifactMutationIntentBytes(intentBytes);
235
+ return Object.freeze({
236
+ modality,
237
+ transactionId,
238
+ parentHeadSequence,
239
+ resultHeadSequence,
240
+ priorNativeRevision,
241
+ priorStateHash,
242
+ stateHash,
243
+ intentBytes,
244
+ nativeReceiptBytes,
245
+ requestHash,
246
+ intent: decodedIntent,
247
+ nativeReceipt
248
+ });
249
+ }
250
+ function decodeNativeReceipt(modality, bytes, expectedCommandCount) {
251
+ return modality === "document" ? decodeDocumentReceipt(bytes, expectedCommandCount) : decodePresentationReceipt(bytes, expectedCommandCount);
252
+ }
253
+ function decodeDocumentReceipt(bytes, expectedCommandCount) {
254
+ const envelope = decodeCountedEnvelope(
255
+ bytes,
256
+ DOCUMENT_RECEIPT_MAGIC,
257
+ DOCUMENT_RECEIPT_VERSION,
258
+ EDITABLE_ARTIFACT_NATIVE_RECEIPT_MAX_BYTES,
259
+ DOCUMENT_ARTIFACT_COMMAND_MAX_COMMANDS
260
+ );
261
+ const payload = new ArtifactBinaryReader(envelope.payload);
262
+ const revision = payload.u64Safe("document receipt revision");
263
+ const commandCount = payload.u32();
264
+ if (commandCount !== envelope.count || commandCount !== expectedCommandCount) {
265
+ throw new TypeError("document receipt command count does not match its intent");
266
+ }
267
+ const maximumCreatedIds = commandCount * DOCUMENT_CREATED_IDS_PER_COMMAND;
268
+ const createdIdCount = payload.count(
269
+ maximumCreatedIds,
270
+ "document receipt created ids",
271
+ DOCUMENT_ID_BYTES
272
+ );
273
+ for (let index = 0; index < createdIdCount; index += 1) {
274
+ const tag = payload.u8();
275
+ if (tag < 1 || tag > 8) {
276
+ throw new TypeError("document receipt contains an invalid id kind");
277
+ }
278
+ payload.u64BigInt();
279
+ const counter = payload.u64BigInt();
280
+ if (counter === 0n || counter > BigInt(DOCUMENT_ARTIFACT_MAX_STRUCTURAL_COUNTER)) {
281
+ throw new TypeError("document receipt contains an invalid id counter");
282
+ }
283
+ }
284
+ payload.done("document receipt contains trailing bytes");
285
+ return Object.freeze({
286
+ modality: "document",
287
+ revision,
288
+ commandCount,
289
+ createdIdCount
290
+ });
291
+ }
292
+ function decodePresentationReceipt(bytes, expectedCommandCount) {
293
+ if (bytes.byteLength !== PRESENTATION_RECEIPT_BYTES) {
294
+ throw new TypeError(
295
+ bytes.byteLength < PRESENTATION_RECEIPT_BYTES ? "truncated presentation receipt" : "presentation receipt contains trailing bytes"
296
+ );
297
+ }
298
+ const reader = new ArtifactBinaryReader(bytes);
299
+ if (!equalBytes(reader.bytes(8), PRESENTATION_RECEIPT_MAGIC)) {
300
+ throw new TypeError("invalid presentation receipt magic");
301
+ }
302
+ if (reader.u16() !== PRESENTATION_RECEIPT_VERSION) {
303
+ throw new TypeError("unsupported presentation receipt version");
304
+ }
305
+ if (reader.u16() !== 0) {
306
+ throw new TypeError("reserved presentation receipt flags must be zero");
307
+ }
308
+ const revision = reader.u64Safe("presentation receipt revision");
309
+ const commandCount = reader.u32();
310
+ if (commandCount !== expectedCommandCount) {
311
+ throw new TypeError("presentation receipt command count does not match its intent");
312
+ }
313
+ const checksum = reader.u64BigInt();
314
+ reader.done();
315
+ if (checksum !== fnv1a64(bytes.subarray(0, bytes.byteLength - EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES))) {
316
+ throw new TypeError("presentation receipt checksum does not match");
317
+ }
318
+ return Object.freeze({ modality: "presentation", revision, commandCount });
319
+ }
320
+ function decodedCommandCount(value) {
321
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
322
+ throw new TypeError("serialized command decoder returned an invalid batch");
323
+ }
324
+ const descriptor = Object.getOwnPropertyDescriptor(value, "commands");
325
+ if (!descriptor || !("value" in descriptor) || !Array.isArray(descriptor.value)) {
326
+ throw new TypeError("serialized command decoder returned an invalid batch");
327
+ }
328
+ return descriptor.value.length;
329
+ }
330
+ function serializedModality(value) {
331
+ if (value !== "document" && value !== "presentation") {
332
+ throw new TypeError("serialized commit modality is invalid");
333
+ }
334
+ return value;
335
+ }
336
+ function canonicalStableId(value, label) {
337
+ if (typeof value !== "string" || !STABLE_ID.test(value) || /^0+$/u.test(value)) {
338
+ throw new TypeError(`${label} must be a nonzero lowercase 128-bit hexadecimal id`);
339
+ }
340
+ return value;
341
+ }
342
+ function canonicalSha256(value, label) {
343
+ if (typeof value !== "string" || !SHA256_TEXT.test(value)) {
344
+ throw new TypeError(`${label} must be canonical sha256 text`);
345
+ }
346
+ return value;
347
+ }
348
+ function safeSequence(value, label) {
349
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0) {
350
+ throw new TypeError(`${label} must be a nonnegative safe integer`);
351
+ }
352
+ return value;
353
+ }
354
+ function hashBytes(value) {
355
+ const hex = value.slice("sha256:".length);
356
+ const bytes = new Uint8Array(32);
357
+ for (let index = 0; index < bytes.byteLength; index += 1) {
358
+ bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);
359
+ }
360
+ return bytes;
361
+ }
362
+ function stateHashText(value) {
363
+ return `sha256:${bytesToHex(value)}`;
364
+ }
365
+ function assertUnsharedBytes(value, label) {
366
+ if (!(value instanceof Uint8Array)) {
367
+ throw new TypeError(`${label} bytes must be a Uint8Array`);
368
+ }
369
+ if (typeof SharedArrayBuffer !== "undefined" && value.buffer instanceof SharedArrayBuffer) {
370
+ throw new TypeError(`${label} bytes must not use shared mutable memory`);
371
+ }
372
+ }
373
+
374
+ export {
375
+ EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION,
376
+ EDITABLE_ARTIFACT_SERIALIZED_COMMIT_MAX_BYTES,
377
+ EDITABLE_ARTIFACT_NATIVE_RECEIPT_MAX_BYTES,
378
+ encodeEditableArtifactSerializedCommit,
379
+ decodeEditableArtifactSerializedCommit,
380
+ assertCanonicalEditableArtifactSerializedCommit
381
+ };
382
+ //# sourceMappingURL=chunk-LW7OH6CS.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/editable-artifact-serialized-commit.ts"],"sourcesContent":["import { bytesToHex } from \"@noble/hashes/utils\";\n\nimport {\n ArtifactBinaryReader,\n ArtifactBinaryWriter,\n EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES,\n EDITABLE_ARTIFACT_BINARY_HEADER_BYTES,\n decodeCountedEnvelope,\n equalBytes,\n fnv1a64,\n strictUtf8,\n} from \"./editable-artifact-binary\";\nimport {\n DOCUMENT_ARTIFACT_COMMAND_MAX_COMMANDS,\n DOCUMENT_ARTIFACT_MAX_STRUCTURAL_COUNTER,\n} from \"./document-artifact-commands\";\nimport {\n EDITABLE_ARTIFACT_INTENT_MAX_BYTES,\n decodeEditableArtifactMutationIntent,\n encodeEditableArtifactMutationIntent,\n hashEditableArtifactMutationIntentBytes,\n type EditableArtifactMutationIntent,\n} from \"./editable-artifacts\";\nimport { editableArtifactCodecFor } from \"./editable-artifact-codec-registry\";\n\nexport const EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION = 1 as const;\nexport const EDITABLE_ARTIFACT_SERIALIZED_COMMIT_MAX_BYTES = 8 * 1024 * 1024;\nexport const EDITABLE_ARTIFACT_NATIVE_RECEIPT_MAX_BYTES = 512 * 1024;\n\nconst MAGIC = strictUtf8(\"OGAST001\", \"serialized commit magic\");\nconst SHA256_TEXT = /^sha256:[0-9a-f]{64}$/u;\nconst STABLE_ID = /^[0-9a-f]{32}$/u;\nconst DOCUMENT_RECEIPT_MAGIC = \"OGADR001\";\nconst PRESENTATION_RECEIPT_MAGIC = strictUtf8(\"OGAPR001\", \"presentation receipt magic\");\nconst DOCUMENT_RECEIPT_VERSION = 1;\nconst PRESENTATION_RECEIPT_VERSION = 1;\nconst DOCUMENT_CREATED_IDS_PER_COMMAND = 7;\nconst DOCUMENT_ID_BYTES = 17;\nconst PRESENTATION_RECEIPT_BYTES = 32;\nconst MODALITY_TAG = Object.freeze({ document: 1, presentation: 2 } as const);\n\nexport type EditableArtifactSerializedModality = \"document\" | \"presentation\";\n\nexport type EditableArtifactNativeReceiptSummary =\n | Readonly<{\n modality: \"document\";\n revision: number;\n commandCount: number;\n createdIdCount: number;\n }>\n | Readonly<{\n modality: \"presentation\";\n revision: number;\n commandCount: number;\n }>;\n\nexport type EditableArtifactSerializedCommitInput = Readonly<{\n modality: EditableArtifactSerializedModality;\n transactionId: string;\n parentHeadSequence: number;\n resultHeadSequence: number;\n /** Native model revision before applying this non-empty command batch. */\n priorNativeRevision: number;\n priorStateHash: string;\n stateHash: string;\n /** Exact canonical OGATX001 bytes accepted by the server. */\n intentBytes: Uint8Array;\n /** Exact canonical OGADR001 or OGAPR001 bytes returned by the native kernel. */\n nativeReceiptBytes: Uint8Array;\n}>;\n\nexport type EditableArtifactSerializedCommitSummary = Readonly<{\n commitProtocolVersion: typeof EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION;\n modality: EditableArtifactSerializedModality;\n transactionId: string;\n parentHeadSequence: number;\n resultHeadSequence: number;\n priorNativeRevision: number;\n priorStateHash: string;\n stateHash: string;\n requestHash: string;\n /** Canonical client intent nested in this authoritative commit. */\n intent: EditableArtifactMutationIntent;\n intentBytes: Uint8Array;\n nativeReceiptBytes: Uint8Array;\n nativeReceipt: EditableArtifactNativeReceiptSummary;\n}>;\n\n/**\n * Server-only encoder for one authoritative, strictly serialized commit.\n * Client identity remains solely in the exact nested OGATX envelope.\n */\nexport function encodeEditableArtifactSerializedCommit(\n input: EditableArtifactSerializedCommitInput,\n): Uint8Array {\n const normalized = normalizeSerializedCommit(input);\n const payload = new ArtifactBinaryWriter(\n EDITABLE_ARTIFACT_SERIALIZED_COMMIT_MAX_BYTES -\n EDITABLE_ARTIFACT_BINARY_HEADER_BYTES -\n EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES,\n );\n payload.stableId(normalized.transactionId, \"serialized transaction id\");\n payload.u64(normalized.parentHeadSequence);\n payload.u64(normalized.resultHeadSequence);\n payload.u64(normalized.priorNativeRevision);\n payload.bytes(hashBytes(normalized.priorStateHash));\n payload.bytes(hashBytes(normalized.stateHash));\n payload.u32(normalized.intentBytes.byteLength);\n payload.u32(normalized.nativeReceiptBytes.byteLength);\n payload.bytes(normalized.intentBytes);\n payload.bytes(normalized.nativeReceiptBytes);\n\n const payloadBytes = payload.finish();\n const output = new ArtifactBinaryWriter(EDITABLE_ARTIFACT_SERIALIZED_COMMIT_MAX_BYTES);\n output.bytes(MAGIC);\n output.u16(EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION);\n output.u16(0);\n output.u32(MODALITY_TAG[normalized.modality]);\n output.u64(payloadBytes.byteLength);\n output.bytes(payloadBytes);\n output.u64(fnv1a64(output.view()));\n return output.finish();\n}\n\n/** Durable modality must be selected before any nested receipt/command decode. */\nexport function decodeEditableArtifactSerializedCommit(\n bytes: Uint8Array,\n durableModality: EditableArtifactSerializedModality,\n): EditableArtifactSerializedCommitSummary {\n assertUnsharedBytes(bytes, \"serialized commit\");\n const modality = serializedModality(durableModality);\n if (bytes.byteLength > EDITABLE_ARTIFACT_SERIALIZED_COMMIT_MAX_BYTES) {\n throw new RangeError(\"serialized commit exceeds its byte limit\");\n }\n if (\n bytes.byteLength <\n EDITABLE_ARTIFACT_BINARY_HEADER_BYTES + EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES\n ) {\n throw new TypeError(\"truncated serialized commit envelope\");\n }\n const header = new ArtifactBinaryReader(bytes);\n if (!equalBytes(header.bytes(8), MAGIC)) {\n throw new TypeError(\"invalid serialized commit magic\");\n }\n if (header.u16() !== EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION) {\n throw new TypeError(\"unsupported serialized commit version\");\n }\n if (header.u16() !== 0) {\n throw new TypeError(\"reserved serialized commit flags must be zero\");\n }\n if (header.u32() !== MODALITY_TAG[modality]) {\n throw new TypeError(\"serialized commit modality disagrees with durable artifact\");\n }\n const payloadLength = header.u64Safe(\"serialized commit payload length\");\n const expectedLength =\n EDITABLE_ARTIFACT_BINARY_HEADER_BYTES + payloadLength + EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES;\n if (bytes.byteLength < expectedLength) {\n throw new TypeError(\"truncated serialized commit payload\");\n }\n if (bytes.byteLength > expectedLength) {\n throw new TypeError(\"serialized commit contains trailing bytes\");\n }\n const payloadBytes = header.bytes(payloadLength);\n const checksum = header.u64BigInt();\n header.done();\n if (\n checksum !==\n fnv1a64(bytes.subarray(0, bytes.byteLength - EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES))\n ) {\n throw new TypeError(\"serialized commit checksum does not match\");\n }\n\n const payload = new ArtifactBinaryReader(payloadBytes);\n const transactionId = payload.stableId(\"serialized transaction id\");\n const parentHeadSequence = payload.u64Safe(\"serialized parent head sequence\");\n const resultHeadSequence = payload.u64Safe(\"serialized result head sequence\");\n const priorNativeRevision = payload.u64Safe(\"serialized prior native revision\");\n const priorStateHash = stateHashText(payload.bytes(32));\n const stateHash = stateHashText(payload.bytes(32));\n const intentLength = payload.count(\n EDITABLE_ARTIFACT_INTENT_MAX_BYTES,\n \"serialized intent bytes\",\n 1,\n );\n const receiptLength = payload.count(\n EDITABLE_ARTIFACT_NATIVE_RECEIPT_MAX_BYTES,\n \"serialized native receipt bytes\",\n 1,\n );\n if (payload.remaining !== intentLength + receiptLength) {\n throw new TypeError(\"serialized commit nested byte lengths are inconsistent\");\n }\n const intentBytes = payload.bytes(intentLength).slice();\n const nativeReceiptBytes = payload.bytes(receiptLength).slice();\n payload.done();\n\n const normalized = normalizeSerializedCommit({\n modality,\n transactionId,\n parentHeadSequence,\n resultHeadSequence,\n priorNativeRevision,\n priorStateHash,\n stateHash,\n intentBytes,\n nativeReceiptBytes,\n });\n const canonical = encodeEditableArtifactSerializedCommit(normalized);\n if (!equalBytes(bytes, canonical)) {\n throw new TypeError(\"serialized commit is not canonically encoded\");\n }\n return Object.freeze({\n commitProtocolVersion: EDITABLE_ARTIFACT_SERIALIZED_COMMIT_VERSION,\n modality,\n transactionId,\n parentHeadSequence,\n resultHeadSequence,\n priorNativeRevision,\n priorStateHash,\n stateHash,\n requestHash: normalized.requestHash,\n intent: normalized.intent,\n intentBytes,\n nativeReceiptBytes,\n nativeReceipt: normalized.nativeReceipt,\n });\n}\n\nexport function assertCanonicalEditableArtifactSerializedCommit(\n bytes: Uint8Array,\n durableModality: EditableArtifactSerializedModality,\n): void {\n decodeEditableArtifactSerializedCommit(bytes, durableModality);\n}\n\ntype NormalizedSerializedCommit = EditableArtifactSerializedCommitInput &\n Readonly<{\n requestHash: string;\n intent: EditableArtifactMutationIntent;\n nativeReceipt: EditableArtifactNativeReceiptSummary;\n }>;\n\nfunction normalizeSerializedCommit(\n input: EditableArtifactSerializedCommitInput,\n): NormalizedSerializedCommit {\n const modality = serializedModality(input.modality);\n const transactionId = canonicalStableId(input.transactionId, \"serialized transaction id\");\n const parentHeadSequence = safeSequence(\n input.parentHeadSequence,\n \"serialized parent head sequence\",\n );\n const resultHeadSequence = safeSequence(\n input.resultHeadSequence,\n \"serialized result head sequence\",\n );\n if (resultHeadSequence !== parentHeadSequence + 1) {\n throw new TypeError(\"serialized commit must advance the durable head exactly once\");\n }\n const priorNativeRevision = safeSequence(\n input.priorNativeRevision,\n \"serialized prior native revision\",\n );\n const priorStateHash = canonicalSha256(input.priorStateHash, \"serialized prior state hash\");\n const stateHash = canonicalSha256(input.stateHash, \"serialized resulting state hash\");\n assertUnsharedBytes(input.intentBytes, \"serialized intent\");\n assertUnsharedBytes(input.nativeReceiptBytes, \"serialized native receipt\");\n if (\n input.intentBytes.byteLength < 1 ||\n input.intentBytes.byteLength > EDITABLE_ARTIFACT_INTENT_MAX_BYTES\n ) {\n throw new RangeError(\"serialized intent bytes exceed their limit\");\n }\n if (\n input.nativeReceiptBytes.byteLength < 1 ||\n input.nativeReceiptBytes.byteLength > EDITABLE_ARTIFACT_NATIVE_RECEIPT_MAX_BYTES\n ) {\n throw new RangeError(\"serialized native receipt bytes exceed their limit\");\n }\n const intentBytes = input.intentBytes.slice();\n const decodedIntent = decodeEditableArtifactMutationIntent(intentBytes);\n if (!equalBytes(intentBytes, encodeEditableArtifactMutationIntent(decodedIntent))) {\n throw new TypeError(\"nested serialized intent is not canonical OGATX001\");\n }\n if (\n decodedIntent.causalBase.length !== 0 ||\n decodedIntent.selectiveUndoOperationIds.length !== 0\n ) {\n throw new TypeError(\"serialized commits cannot carry CRDT causality or selective undo\");\n }\n if (decodedIntent.observedHeadSequence !== parentHeadSequence) {\n throw new TypeError(\"serialized intent observed head does not match its parent\");\n }\n const descriptor = editableArtifactCodecFor({\n durableModality: modality,\n modelSchemaVersion: decodedIntent.modelSchemaVersion,\n commandProtocolVersion: decodedIntent.commandProtocolVersion,\n });\n descriptor.command.assertCanonical(decodedIntent.commandBytes);\n const commandCount = decodedCommandCount(descriptor.command.decode(decodedIntent.commandBytes));\n if (commandCount < 1) {\n throw new TypeError(\"serialized commits require a non-empty command batch\");\n }\n const nativeReceiptBytes = input.nativeReceiptBytes.slice();\n const nativeReceipt = decodeNativeReceipt(modality, nativeReceiptBytes, commandCount);\n if (modality === \"presentation\") {\n if (nativeReceipt.revision !== priorNativeRevision + 1) {\n throw new TypeError(\n \"presentation receipt must advance its prior native revision exactly once\",\n );\n }\n if (stateHash === priorStateHash) {\n throw new TypeError(\"presentation commit must change its canonical state hash\");\n }\n } else if (nativeReceipt.revision === priorNativeRevision) {\n if (stateHash !== priorStateHash) {\n throw new TypeError(\"document no-op receipt cannot change the canonical state hash\");\n }\n } else {\n if (nativeReceipt.revision !== priorNativeRevision + 1) {\n throw new TypeError(\n \"document receipt must preserve or advance its prior native revision once\",\n );\n }\n if (stateHash === priorStateHash) {\n throw new TypeError(\"document revision advance must change the canonical state hash\");\n }\n }\n const requestHash = hashEditableArtifactMutationIntentBytes(intentBytes);\n return Object.freeze({\n modality,\n transactionId,\n parentHeadSequence,\n resultHeadSequence,\n priorNativeRevision,\n priorStateHash,\n stateHash,\n intentBytes,\n nativeReceiptBytes,\n requestHash,\n intent: decodedIntent,\n nativeReceipt,\n });\n}\n\nfunction decodeNativeReceipt(\n modality: EditableArtifactSerializedModality,\n bytes: Uint8Array,\n expectedCommandCount: number,\n): EditableArtifactNativeReceiptSummary {\n return modality === \"document\"\n ? decodeDocumentReceipt(bytes, expectedCommandCount)\n : decodePresentationReceipt(bytes, expectedCommandCount);\n}\n\nfunction decodeDocumentReceipt(\n bytes: Uint8Array,\n expectedCommandCount: number,\n): Extract<EditableArtifactNativeReceiptSummary, { modality: \"document\" }> {\n const envelope = decodeCountedEnvelope(\n bytes,\n DOCUMENT_RECEIPT_MAGIC,\n DOCUMENT_RECEIPT_VERSION,\n EDITABLE_ARTIFACT_NATIVE_RECEIPT_MAX_BYTES,\n DOCUMENT_ARTIFACT_COMMAND_MAX_COMMANDS,\n );\n const payload = new ArtifactBinaryReader(envelope.payload);\n const revision = payload.u64Safe(\"document receipt revision\");\n const commandCount = payload.u32();\n if (commandCount !== envelope.count || commandCount !== expectedCommandCount) {\n throw new TypeError(\"document receipt command count does not match its intent\");\n }\n const maximumCreatedIds = commandCount * DOCUMENT_CREATED_IDS_PER_COMMAND;\n const createdIdCount = payload.count(\n maximumCreatedIds,\n \"document receipt created ids\",\n DOCUMENT_ID_BYTES,\n );\n for (let index = 0; index < createdIdCount; index += 1) {\n const tag = payload.u8();\n if (tag < 1 || tag > 8) {\n throw new TypeError(\"document receipt contains an invalid id kind\");\n }\n payload.u64BigInt();\n const counter = payload.u64BigInt();\n if (counter === 0n || counter > BigInt(DOCUMENT_ARTIFACT_MAX_STRUCTURAL_COUNTER)) {\n throw new TypeError(\"document receipt contains an invalid id counter\");\n }\n }\n payload.done(\"document receipt contains trailing bytes\");\n return Object.freeze({\n modality: \"document\",\n revision,\n commandCount,\n createdIdCount,\n });\n}\n\nfunction decodePresentationReceipt(\n bytes: Uint8Array,\n expectedCommandCount: number,\n): Extract<EditableArtifactNativeReceiptSummary, { modality: \"presentation\" }> {\n if (bytes.byteLength !== PRESENTATION_RECEIPT_BYTES) {\n throw new TypeError(\n bytes.byteLength < PRESENTATION_RECEIPT_BYTES\n ? \"truncated presentation receipt\"\n : \"presentation receipt contains trailing bytes\",\n );\n }\n const reader = new ArtifactBinaryReader(bytes);\n if (!equalBytes(reader.bytes(8), PRESENTATION_RECEIPT_MAGIC)) {\n throw new TypeError(\"invalid presentation receipt magic\");\n }\n if (reader.u16() !== PRESENTATION_RECEIPT_VERSION) {\n throw new TypeError(\"unsupported presentation receipt version\");\n }\n if (reader.u16() !== 0) {\n throw new TypeError(\"reserved presentation receipt flags must be zero\");\n }\n const revision = reader.u64Safe(\"presentation receipt revision\");\n const commandCount = reader.u32();\n if (commandCount !== expectedCommandCount) {\n throw new TypeError(\"presentation receipt command count does not match its intent\");\n }\n const checksum = reader.u64BigInt();\n reader.done();\n if (\n checksum !==\n fnv1a64(bytes.subarray(0, bytes.byteLength - EDITABLE_ARTIFACT_BINARY_CHECKSUM_BYTES))\n ) {\n throw new TypeError(\"presentation receipt checksum does not match\");\n }\n return Object.freeze({ modality: \"presentation\", revision, commandCount });\n}\n\nfunction decodedCommandCount(value: unknown): number {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(\"serialized command decoder returned an invalid batch\");\n }\n const descriptor = Object.getOwnPropertyDescriptor(value, \"commands\");\n if (!descriptor || !(\"value\" in descriptor) || !Array.isArray(descriptor.value)) {\n throw new TypeError(\"serialized command decoder returned an invalid batch\");\n }\n return descriptor.value.length;\n}\n\nfunction serializedModality(value: unknown): EditableArtifactSerializedModality {\n if (value !== \"document\" && value !== \"presentation\") {\n throw new TypeError(\"serialized commit modality is invalid\");\n }\n return value;\n}\n\nfunction canonicalStableId(value: unknown, label: string): string {\n if (typeof value !== \"string\" || !STABLE_ID.test(value) || /^0+$/u.test(value)) {\n throw new TypeError(`${label} must be a nonzero lowercase 128-bit hexadecimal id`);\n }\n return value;\n}\n\nfunction canonicalSha256(value: unknown, label: string): string {\n if (typeof value !== \"string\" || !SHA256_TEXT.test(value)) {\n throw new TypeError(`${label} must be canonical sha256 text`);\n }\n return value;\n}\n\nfunction safeSequence(value: unknown, label: string): number {\n if (typeof value !== \"number\" || !Number.isSafeInteger(value) || value < 0) {\n throw new TypeError(`${label} must be a nonnegative safe integer`);\n }\n return value;\n}\n\nfunction hashBytes(value: string): Uint8Array {\n const hex = value.slice(\"sha256:\".length);\n const bytes = new Uint8Array(32);\n for (let index = 0; index < bytes.byteLength; index += 1) {\n bytes[index] = Number.parseInt(hex.slice(index * 2, index * 2 + 2), 16);\n }\n return bytes;\n}\n\nfunction stateHashText(value: Uint8Array): string {\n return `sha256:${bytesToHex(value)}`;\n}\n\nfunction assertUnsharedBytes(value: unknown, label: string): asserts value is Uint8Array {\n if (!(value instanceof Uint8Array)) {\n throw new TypeError(`${label} bytes must be a Uint8Array`);\n }\n if (typeof SharedArrayBuffer !== \"undefined\" && value.buffer instanceof SharedArrayBuffer) {\n throw new Typ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