@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,478 @@
1
+ /**
2
+ * Strict, allocation-bounded inspection of canonical OGACO001 transactions.
3
+ *
4
+ * The Rust kernel remains the authority for applying operations. This decoder
5
+ * validates the complete envelope and every typed operation so metadata after
6
+ * the operation stream cannot be located by trusting attacker-controlled
7
+ * lengths. It intentionally does not construct an editable artifact model.
8
+ */
9
+
10
+ import { COMMITTED_TRANSACTION_PROTOCOL_VERSION } from "./editable-artifact-versions";
11
+
12
+ export { COMMITTED_TRANSACTION_PROTOCOL_VERSION } from "./editable-artifact-versions";
13
+ export const MAX_COMMITTED_TRANSACTION_BYTES = 8 * 1024 * 1024;
14
+ export const MAX_COMMITTED_TRANSACTION_OPERATIONS = 4_096;
15
+ export const MAX_COMMITTED_TRANSACTION_CAUSAL_REPLICAS = 100_000;
16
+ export const MAX_COMMITTED_TRANSACTION_CELLS = 1_000_000;
17
+
18
+ const MAGIC = new Uint8Array([0x4f, 0x47, 0x41, 0x43, 0x4f, 0x30, 0x30, 0x31]); // OGACO001
19
+ const HEADER_BYTES = 24;
20
+ const CHECKSUM_BYTES = 8;
21
+ const HASH_BYTES = 32;
22
+ const STABLE_ID_BYTES = 16;
23
+ const MAX_OPERATION_STRING_BYTES = 4 * 1024 * 1024;
24
+ const MAX_SAFE_U64_HIGH = 0x1f_ffff;
25
+ const U32_SIZE = 0x1_0000_0000;
26
+ const U32_MAX = 0xffff_ffff;
27
+ const FNV_OFFSET_LOW = 0x8422_2325;
28
+ const FNV_OFFSET_HIGH = 0xcbf2_9ce4;
29
+ const FNV_PRIME_LOW = 0x01b3;
30
+
31
+ const HEX = Array.from({ length: 256 }, (_, value) => value.toString(16).padStart(2, "0"));
32
+
33
+ export type CommittedTransactionCausalEntry = Readonly<{
34
+ replicaId: string;
35
+ counter: number;
36
+ }>;
37
+
38
+ export type CommittedTransactionSummary = Readonly<{
39
+ operationProtocolVersion: typeof COMMITTED_TRANSACTION_PROTOCOL_VERSION;
40
+ transactionId: string;
41
+ dot: CommittedTransactionCausalEntry;
42
+ resolvedCausalBase: readonly CommittedTransactionCausalEntry[];
43
+ operationIds: readonly string[];
44
+ priorStateHash: string;
45
+ resultingCausalFrontier: readonly CommittedTransactionCausalEntry[];
46
+ stateHash: string;
47
+ }>;
48
+
49
+ /**
50
+ * Decodes only the metadata of one exact canonical OGACO001 byte envelope.
51
+ *
52
+ * This function is synchronous and never mutates or retains `bytes`. The
53
+ * caller remains the owner of the exact canonical envelope.
54
+ */
55
+ export function decodeCommittedTransactionSummary(bytes: Uint8Array): CommittedTransactionSummary {
56
+ assertInput(bytes);
57
+ if (bytes.byteLength > MAX_COMMITTED_TRANSACTION_BYTES) {
58
+ throw new RangeError("OGACO001 envelope exceeds its byte limit");
59
+ }
60
+ if (bytes.byteLength < HEADER_BYTES + CHECKSUM_BYTES) {
61
+ throw new TypeError("truncated OGACO001 envelope");
62
+ }
63
+
64
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
65
+ for (let index = 0; index < MAGIC.byteLength; index += 1) {
66
+ if (bytes[index] !== MAGIC[index]) throw new TypeError("invalid OGACO001 magic");
67
+ }
68
+
69
+ const version = view.getUint16(8, true);
70
+ if (version !== COMMITTED_TRANSACTION_PROTOCOL_VERSION) {
71
+ throw new TypeError(`unsupported OGACO001 version: ${version}`);
72
+ }
73
+ if (view.getUint16(10, true) !== 0) {
74
+ throw new TypeError("reserved OGACO001 header bits are set");
75
+ }
76
+
77
+ const operationCount = view.getUint32(12, true);
78
+ if (operationCount === 0 || operationCount > MAX_COMMITTED_TRANSACTION_OPERATIONS) {
79
+ throw new RangeError("OGACO001 operation count is outside its canonical bounds");
80
+ }
81
+
82
+ const payloadLength = safeU64At(view, 16, "OGACO001 payload length", false);
83
+ const payloadEnd = checkedAdd(HEADER_BYTES, payloadLength, "OGACO001 payload length");
84
+ const expectedLength = checkedAdd(payloadEnd, CHECKSUM_BYTES, "OGACO001 envelope length");
85
+ if (bytes.byteLength !== expectedLength) {
86
+ throw new TypeError(
87
+ bytes.byteLength < expectedLength
88
+ ? "truncated OGACO001 payload"
89
+ : "trailing bytes after OGACO001 envelope",
90
+ );
91
+ }
92
+
93
+ const [checksumLow, checksumHigh] = fnv1a64(bytes, payloadEnd);
94
+ if (
95
+ view.getUint32(payloadEnd, true) !== checksumLow ||
96
+ view.getUint32(payloadEnd + 4, true) !== checksumHigh
97
+ ) {
98
+ throw new TypeError("OGACO001 checksum mismatch");
99
+ }
100
+
101
+ const reader = new Reader(bytes, HEADER_BYTES, payloadEnd);
102
+ const transactionId = reader.stableId("transaction id");
103
+ const dot = Object.freeze({
104
+ replicaId: reader.replicaId("transaction dot replica"),
105
+ counter: reader.safeU64("transaction dot counter", true),
106
+ });
107
+ const resolvedCausalBase = reader.frontier("resolved causal base");
108
+ const priorStateHash = reader.stateHash("prior state hash");
109
+
110
+ const operationIds: string[] = [];
111
+ const seenOperationIds = new Set<string>();
112
+ let totalCells = 0;
113
+ for (let index = 0; index < operationCount; index += 1) {
114
+ const operationId = reader.stableId(`operation ${index} id`);
115
+ if (seenOperationIds.has(operationId)) {
116
+ throw new TypeError("OGACO001 operation ids must be unique");
117
+ }
118
+ seenOperationIds.add(operationId);
119
+ operationIds.push(operationId);
120
+ totalCells = reader.skipCommand(totalCells);
121
+ }
122
+
123
+ const resultingCausalFrontier = reader.frontier("resulting causal frontier");
124
+ const stateHash = reader.stateHash("resulting state hash");
125
+ reader.done();
126
+
127
+ return Object.freeze({
128
+ operationProtocolVersion: COMMITTED_TRANSACTION_PROTOCOL_VERSION,
129
+ transactionId,
130
+ dot,
131
+ resolvedCausalBase,
132
+ operationIds: Object.freeze(operationIds),
133
+ priorStateHash,
134
+ resultingCausalFrontier,
135
+ stateHash,
136
+ });
137
+ }
138
+
139
+ class Reader {
140
+ readonly #bytes: Uint8Array;
141
+ readonly #view: DataView;
142
+ readonly #end: number;
143
+ #offset: number;
144
+
145
+ constructor(bytes: Uint8Array, offset: number, end: number) {
146
+ this.#bytes = bytes;
147
+ this.#view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
148
+ this.#offset = offset;
149
+ this.#end = end;
150
+ }
151
+
152
+ take(length: number, label: string): Uint8Array {
153
+ const offset = this.reserve(length, label);
154
+ return this.#bytes.subarray(offset, offset + length);
155
+ }
156
+
157
+ reserve(length: number, label: string): number {
158
+ if (!Number.isSafeInteger(length) || length < 0) {
159
+ throw new RangeError(`${label} has an invalid byte length`);
160
+ }
161
+ const offset = this.#offset;
162
+ const end = checkedAdd(offset, length, `${label} byte range`);
163
+ if (end > this.#end) throw new TypeError(`truncated ${label}`);
164
+ this.#offset = end;
165
+ return offset;
166
+ }
167
+
168
+ u8(label: string): number {
169
+ return this.#bytes[this.reserve(1, label)]!;
170
+ }
171
+
172
+ u32(label: string): number {
173
+ const offset = this.reserve(4, label);
174
+ return this.#view.getUint32(offset, true);
175
+ }
176
+
177
+ safeU64(label: string, positive: boolean): number {
178
+ const offset = this.reserve(8, label);
179
+ const value = safeU64At(this.#view, offset, label, positive);
180
+ return value;
181
+ }
182
+
183
+ replicaId(label: string): string {
184
+ const offset = this.reserve(8, label);
185
+ const low = this.#view.getUint32(offset, true);
186
+ const high = this.#view.getUint32(offset + 4, true);
187
+ if (low === 0 && high === 0) throw new TypeError(`${label} must be nonzero`);
188
+ return hexU64(high, low);
189
+ }
190
+
191
+ stableId(label: string): string {
192
+ const offset = this.reserve(STABLE_ID_BYTES, label);
193
+ const counterLow = this.#view.getUint32(offset, true);
194
+ const counterHigh = this.#view.getUint32(offset + 4, true);
195
+ const namespaceLow = this.#view.getUint32(offset + 8, true);
196
+ const namespaceHigh = this.#view.getUint32(offset + 12, true);
197
+ if (counterLow === 0 && counterHigh === 0 && namespaceLow === 0 && namespaceHigh === 0) {
198
+ throw new TypeError(`${label} reserves the all-zero value`);
199
+ }
200
+ return `${hexU64(namespaceHigh, namespaceLow)}${hexU64(counterHigh, counterLow)}`;
201
+ }
202
+
203
+ sheetObjectId(label: string): string {
204
+ const offset = this.#offset;
205
+ const id = this.stableId(label);
206
+ const counterIsZero =
207
+ this.#view.getUint32(offset, true) === 0 && this.#view.getUint32(offset + 4, true) === 0;
208
+ const namespaceIsZero =
209
+ this.#view.getUint32(offset + 8, true) === 0 && this.#view.getUint32(offset + 12, true) === 0;
210
+ if (counterIsZero || namespaceIsZero) {
211
+ throw new TypeError(`${label} requires nonzero namespace and counter`);
212
+ }
213
+ return id;
214
+ }
215
+
216
+ stateHash(label: string): string {
217
+ return `sha256:${hexBytes(this.take(HASH_BYTES, label))}`;
218
+ }
219
+
220
+ frontier(label: string): readonly CommittedTransactionCausalEntry[] {
221
+ const count = this.u32(`${label} count`);
222
+ if (count > MAX_COMMITTED_TRANSACTION_CAUSAL_REPLICAS) {
223
+ throw new RangeError(`${label} exceeds its replica limit`);
224
+ }
225
+ const entries: CommittedTransactionCausalEntry[] = [];
226
+ let previousLow = 0;
227
+ let previousHigh = 0;
228
+ let hasPrevious = false;
229
+ for (let index = 0; index < count; index += 1) {
230
+ const replicaOffset = this.#offset;
231
+ const replicaId = this.replicaId(`${label} replica ${index}`);
232
+ const replicaLow = this.#view.getUint32(replicaOffset, true);
233
+ const replicaHigh = this.#view.getUint32(replicaOffset + 4, true);
234
+ if (
235
+ hasPrevious &&
236
+ (replicaHigh < previousHigh || (replicaHigh === previousHigh && replicaLow <= previousLow))
237
+ ) {
238
+ throw new TypeError(`${label} replicas must be unique and strictly ordered`);
239
+ }
240
+ const counter = this.safeU64(`${label} counter ${index}`, true);
241
+ entries.push(Object.freeze({ replicaId, counter }));
242
+ previousLow = replicaLow;
243
+ previousHigh = replicaHigh;
244
+ hasPrevious = true;
245
+ }
246
+ return Object.freeze(entries);
247
+ }
248
+
249
+ skipCommand(totalCells: number): number {
250
+ const tag = this.u8("collaboration command tag");
251
+ switch (tag) {
252
+ case 0: {
253
+ this.sheetObjectId("created sheet id");
254
+ this.skipString("created sheet name");
255
+ const after = this.u8("created sheet predecessor flag");
256
+ if (after === 1) this.skipGeneration("created sheet predecessor");
257
+ else if (after !== 0) throw new TypeError("invalid created sheet predecessor flag");
258
+ return totalCells;
259
+ }
260
+ case 1:
261
+ this.skipGeneration("renamed sheet generation");
262
+ this.skipString("renamed sheet name");
263
+ return totalCells;
264
+ case 2:
265
+ this.skipGeneration("deleted sheet generation");
266
+ return totalCells;
267
+ case 3:
268
+ return this.skipSetCells(totalCells);
269
+ case 4: {
270
+ this.skipGeneration("cleared sheet generation");
271
+ const startRow = this.u32("clear range start row");
272
+ const startColumn = this.u32("clear range start column");
273
+ const endRow = this.u32("clear range end row");
274
+ const endColumn = this.u32("clear range end column");
275
+ if (startRow > endRow || startColumn > endColumn) {
276
+ throw new TypeError("OGACO001 clear range is not normalized");
277
+ }
278
+ return totalCells;
279
+ }
280
+ case 5:
281
+ this.stableId("selective undo target");
282
+ return totalCells;
283
+ default:
284
+ throw new TypeError(`invalid OGACO001 collaboration command tag: ${tag}`);
285
+ }
286
+ }
287
+
288
+ skipSetCells(totalCells: number): number {
289
+ this.skipGeneration("cell block sheet generation");
290
+ const anchorRow = this.u32("cell block anchor row");
291
+ const anchorColumn = this.u32("cell block anchor column");
292
+ const rows = this.u32("cell block rows");
293
+ const columns = this.u32("cell block columns");
294
+ if (rows === 0 || columns === 0) {
295
+ throw new TypeError("OGACO001 cell block dimensions must be nonzero");
296
+ }
297
+ if (anchorRow > U32_MAX - (rows - 1) || anchorColumn > U32_MAX - (columns - 1)) {
298
+ throw new RangeError("OGACO001 cell block coordinates overflow u32");
299
+ }
300
+ if (rows > Math.floor(MAX_COMMITTED_TRANSACTION_CELLS / columns)) {
301
+ throw new RangeError("OGACO001 cell block exceeds its cell limit");
302
+ }
303
+ const cellCount = rows * columns;
304
+ const nextTotal = totalCells + cellCount;
305
+ if (nextTotal > MAX_COMMITTED_TRANSACTION_CELLS) {
306
+ throw new RangeError("OGACO001 transaction exceeds its cell limit");
307
+ }
308
+ for (let index = 0; index < cellCount; index += 1) this.skipCell();
309
+ return nextTotal;
310
+ }
311
+
312
+ skipCell(): void {
313
+ const formulaTag = this.u8("cell formula tag");
314
+ if (formulaTag === 1) {
315
+ if (this.skipString("cell formula") === 0) {
316
+ throw new TypeError("OGACO001 formula must not be empty");
317
+ }
318
+ } else if (formulaTag !== 0) {
319
+ throw new TypeError(`invalid OGACO001 cell formula tag: ${formulaTag}`);
320
+ }
321
+
322
+ const valueTag = this.u8("cell value tag");
323
+ switch (valueTag) {
324
+ case 0:
325
+ case 1:
326
+ case 2:
327
+ return;
328
+ case 3:
329
+ this.skipNumber();
330
+ return;
331
+ case 4:
332
+ this.skipString("cell text");
333
+ return;
334
+ case 5:
335
+ this.skipFormulaError();
336
+ return;
337
+ default:
338
+ throw new TypeError(`invalid OGACO001 cell value tag: ${valueTag}`);
339
+ }
340
+ }
341
+
342
+ skipNumber(): void {
343
+ const offset = this.reserve(8, "cell number");
344
+ const low = this.#view.getUint32(offset, true);
345
+ const high = this.#view.getUint32(offset + 4, true);
346
+ if (low === 0 && high === 0x8000_0000) {
347
+ throw new TypeError("OGACO001 cell number uses negative zero");
348
+ }
349
+ if ((high & 0x7ff0_0000) === 0x7ff0_0000) {
350
+ throw new TypeError("OGACO001 cell numbers must be finite");
351
+ }
352
+ }
353
+
354
+ skipFormulaError(): void {
355
+ const tag = this.u8("formula error tag");
356
+ if (tag <= 8) return;
357
+ if (tag === 9) {
358
+ this.skipString("custom formula error");
359
+ return;
360
+ }
361
+ throw new TypeError(`invalid OGACO001 formula error tag: ${tag}`);
362
+ }
363
+
364
+ skipGeneration(label: string): void {
365
+ this.sheetObjectId(`${label} sheet id`);
366
+ this.stableId(`${label} creation operation id`);
367
+ }
368
+
369
+ skipString(label: string): number {
370
+ const length = this.u32(`${label} length`);
371
+ if (length > MAX_OPERATION_STRING_BYTES) {
372
+ throw new RangeError(`${label} exceeds its byte limit`);
373
+ }
374
+ const value = this.take(length, label);
375
+ assertUtf8(value, label);
376
+ return length;
377
+ }
378
+
379
+ done(): void {
380
+ if (this.#offset !== this.#end) throw new TypeError("trailing bytes in OGACO001 payload");
381
+ }
382
+ }
383
+
384
+ function assertInput(bytes: Uint8Array): void {
385
+ if (!(bytes instanceof Uint8Array)) {
386
+ throw new TypeError("OGACO001 bytes must be a Uint8Array");
387
+ }
388
+ if (typeof SharedArrayBuffer !== "undefined" && bytes.buffer instanceof SharedArrayBuffer) {
389
+ throw new TypeError("OGACO001 bytes must not use shared mutable memory");
390
+ }
391
+ }
392
+
393
+ function safeU64At(view: DataView, offset: number, label: string, positive: boolean): number {
394
+ const low = view.getUint32(offset, true);
395
+ const high = view.getUint32(offset + 4, true);
396
+ if (high > MAX_SAFE_U64_HIGH)
397
+ throw new RangeError(`${label} exceeds JavaScript safe integer range`);
398
+ const value = high * U32_SIZE + low;
399
+ if (positive && value === 0) throw new TypeError(`${label} must be nonzero`);
400
+ return value;
401
+ }
402
+
403
+ function checkedAdd(left: number, right: number, label: string): number {
404
+ const result = left + right;
405
+ if (!Number.isSafeInteger(result)) throw new RangeError(`${label} exceeds safe integer range`);
406
+ return result;
407
+ }
408
+
409
+ /** Allocation-free UTF-8 scalar validation equivalent to Rust `str::from_utf8`. */
410
+ function assertUtf8(bytes: Uint8Array, label: string): void {
411
+ for (let index = 0; index < bytes.length;) {
412
+ const first = bytes[index]!;
413
+ if (first <= 0x7f) {
414
+ index += 1;
415
+ continue;
416
+ }
417
+ const second = bytes[index + 1];
418
+ if (first >= 0xc2 && first <= 0xdf && continuation(second)) {
419
+ index += 2;
420
+ continue;
421
+ }
422
+ const third = bytes[index + 2];
423
+ if (
424
+ ((first === 0xe0 && between(second, 0xa0, 0xbf)) ||
425
+ (first >= 0xe1 && first <= 0xec && continuation(second)) ||
426
+ (first === 0xed && between(second, 0x80, 0x9f)) ||
427
+ (first >= 0xee && first <= 0xef && continuation(second))) &&
428
+ continuation(third)
429
+ ) {
430
+ index += 3;
431
+ continue;
432
+ }
433
+ const fourth = bytes[index + 3];
434
+ if (
435
+ ((first === 0xf0 && between(second, 0x90, 0xbf)) ||
436
+ (first >= 0xf1 && first <= 0xf3 && continuation(second)) ||
437
+ (first === 0xf4 && between(second, 0x80, 0x8f))) &&
438
+ continuation(third) &&
439
+ continuation(fourth)
440
+ ) {
441
+ index += 4;
442
+ continue;
443
+ }
444
+ throw new TypeError(`${label} is not canonical UTF-8`);
445
+ }
446
+ }
447
+
448
+ function continuation(value: number | undefined): boolean {
449
+ return value !== undefined && value >= 0x80 && value <= 0xbf;
450
+ }
451
+
452
+ function between(value: number | undefined, minimum: number, maximum: number): boolean {
453
+ return value !== undefined && value >= minimum && value <= maximum;
454
+ }
455
+
456
+ function hexU64(high: number, low: number): string {
457
+ return `${high.toString(16).padStart(8, "0")}${low.toString(16).padStart(8, "0")}`;
458
+ }
459
+
460
+ function hexBytes(bytes: Uint8Array): string {
461
+ let result = "";
462
+ for (const byte of bytes) result += HEX[byte];
463
+ return result;
464
+ }
465
+
466
+ /** FNV-1a-64 using exact 32-bit limbs; avoids a BigInt allocation per byte. */
467
+ function fnv1a64(bytes: Uint8Array, end: number): readonly [low: number, high: number] {
468
+ let low = FNV_OFFSET_LOW;
469
+ let high = FNV_OFFSET_HIGH;
470
+ for (let index = 0; index < end; index += 1) {
471
+ low = (low ^ bytes[index]!) >>> 0;
472
+ const lowProduct = low * FNV_PRIME_LOW;
473
+ const carry = Math.floor(lowProduct / U32_SIZE);
474
+ high = (high * FNV_PRIME_LOW + carry + low * 0x100) >>> 0;
475
+ low = lowProduct >>> 0;
476
+ }
477
+ return [low, high];
478
+ }