@opengeni/artifact-tool 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +104 -0
  3. package/dist/bounded-zip.d.ts +28 -0
  4. package/dist/chunk-4BSENMAE.js +39 -0
  5. package/dist/chunk-4BSENMAE.js.map +1 -0
  6. package/dist/chunk-4FRFNNBM.js +276 -0
  7. package/dist/chunk-4FRFNNBM.js.map +1 -0
  8. package/dist/chunk-5XIA6KHZ.js +49 -0
  9. package/dist/chunk-5XIA6KHZ.js.map +1 -0
  10. package/dist/chunk-66CT2ZRP.js +2229 -0
  11. package/dist/chunk-66CT2ZRP.js.map +1 -0
  12. package/dist/chunk-72SYDU4O.js +319 -0
  13. package/dist/chunk-72SYDU4O.js.map +1 -0
  14. package/dist/chunk-B2ZJRZDA.js +279 -0
  15. package/dist/chunk-B2ZJRZDA.js.map +1 -0
  16. package/dist/chunk-DCTLTNPW.js +2458 -0
  17. package/dist/chunk-DCTLTNPW.js.map +1 -0
  18. package/dist/chunk-FGZM4FQ6.js +473 -0
  19. package/dist/chunk-FGZM4FQ6.js.map +1 -0
  20. package/dist/chunk-HTJBLBDE.js +591 -0
  21. package/dist/chunk-HTJBLBDE.js.map +1 -0
  22. package/dist/chunk-IYFXZQ34.js +5306 -0
  23. package/dist/chunk-IYFXZQ34.js.map +1 -0
  24. package/dist/chunk-J6N7IR44.js +172 -0
  25. package/dist/chunk-J6N7IR44.js.map +1 -0
  26. package/dist/chunk-N2IHNWBS.js +1002 -0
  27. package/dist/chunk-N2IHNWBS.js.map +1 -0
  28. package/dist/chunk-NAG44K67.js +549 -0
  29. package/dist/chunk-NAG44K67.js.map +1 -0
  30. package/dist/chunk-O24KTEGP.js +33 -0
  31. package/dist/chunk-O24KTEGP.js.map +1 -0
  32. package/dist/chunk-PI2AZVGK.js +2074 -0
  33. package/dist/chunk-PI2AZVGK.js.map +1 -0
  34. package/dist/chunk-Q2FFHEY7.js +40 -0
  35. package/dist/chunk-Q2FFHEY7.js.map +1 -0
  36. package/dist/chunk-RBGQADXA.js +57 -0
  37. package/dist/chunk-RBGQADXA.js.map +1 -0
  38. package/dist/chunk-U5G2BKM2.js +613 -0
  39. package/dist/chunk-U5G2BKM2.js.map +1 -0
  40. package/dist/chunk-VOJHMSM3.js +39 -0
  41. package/dist/chunk-VOJHMSM3.js.map +1 -0
  42. package/dist/chunk-VUNV25KB.js +16 -0
  43. package/dist/chunk-VUNV25KB.js.map +1 -0
  44. package/dist/chunk-XIFUNVBO.js +101 -0
  45. package/dist/chunk-XIFUNVBO.js.map +1 -0
  46. package/dist/chunk-ZCJYRJGB.js +489 -0
  47. package/dist/chunk-ZCJYRJGB.js.map +1 -0
  48. package/dist/chunk-ZZXPEE4S.js +2260 -0
  49. package/dist/chunk-ZZXPEE4S.js.map +1 -0
  50. package/dist/document-docx-api.d.ts +49 -0
  51. package/dist/document-docx-codec.d.ts +9 -0
  52. package/dist/document-docx-codec.js +4765 -0
  53. package/dist/document-docx-codec.js.map +1 -0
  54. package/dist/document-docx-import.d.ts +261 -0
  55. package/dist/document-docx-packer.d.ts +18 -0
  56. package/dist/document-docx-state.d.ts +12 -0
  57. package/dist/document-render.d.ts +3 -0
  58. package/dist/document-render.js +492 -0
  59. package/dist/document-render.js.map +1 -0
  60. package/dist/document.d.ts +432 -0
  61. package/dist/document.js +37 -0
  62. package/dist/document.js.map +1 -0
  63. package/dist/errors.d.ts +23 -0
  64. package/dist/file-blob.d.ts +11 -0
  65. package/dist/index.d.ts +4 -0
  66. package/dist/index.js +186 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/inspection.d.ts +12 -0
  69. package/dist/kernel.d.ts +101 -0
  70. package/dist/lib-GQLPACFK.js +9746 -0
  71. package/dist/lib-GQLPACFK.js.map +1 -0
  72. package/dist/materializer-cli-entry.d.ts +2 -0
  73. package/dist/materializer-cli-entry.js +29 -0
  74. package/dist/materializer-cli-entry.js.map +1 -0
  75. package/dist/materializer-cli.d.ts +24 -0
  76. package/dist/materializer-cli.js +24 -0
  77. package/dist/materializer-cli.js.map +1 -0
  78. package/dist/native-raster.d.ts +10 -0
  79. package/dist/native.d.ts +129 -0
  80. package/dist/native.js +31 -0
  81. package/dist/native.js.map +1 -0
  82. package/dist/office-import.d.ts +48 -0
  83. package/dist/office-import.js +154 -0
  84. package/dist/office-import.js.map +1 -0
  85. package/dist/presentation-pptx-api.d.ts +60 -0
  86. package/dist/presentation-pptx-import.d.ts +5 -0
  87. package/dist/presentation-pptx-state-digest-765CZZED.js +10 -0
  88. package/dist/presentation-pptx-state-digest-765CZZED.js.map +1 -0
  89. package/dist/presentation-pptx-state-digest.d.ts +3 -0
  90. package/dist/presentation-pptx-state.d.ts +4 -0
  91. package/dist/presentation-pptx-xml.d.ts +29 -0
  92. package/dist/presentation-pptx.d.ts +5 -0
  93. package/dist/presentation-pptx.js +2365 -0
  94. package/dist/presentation-pptx.js.map +1 -0
  95. package/dist/presentation-render.d.ts +29 -0
  96. package/dist/presentation-render.js +375 -0
  97. package/dist/presentation-render.js.map +1 -0
  98. package/dist/presentation.d.ts +565 -0
  99. package/dist/presentation.js +71 -0
  100. package/dist/presentation.js.map +1 -0
  101. package/dist/production-composite.d.ts +68 -0
  102. package/dist/production-document.d.ts +2 -0
  103. package/dist/production-document.js +176 -0
  104. package/dist/production-document.js.map +1 -0
  105. package/dist/production-native-codecs.d.ts +94 -0
  106. package/dist/production-presentation.d.ts +2 -0
  107. package/dist/production-presentation.js +176 -0
  108. package/dist/production-presentation.js.map +1 -0
  109. package/dist/production-sha256.d.ts +2 -0
  110. package/dist/production-spreadsheet-native.d.ts +12 -0
  111. package/dist/production-spreadsheet.d.ts +2 -0
  112. package/dist/production-spreadsheet.js +176 -0
  113. package/dist/production-spreadsheet.js.map +1 -0
  114. package/dist/production.d.ts +96 -0
  115. package/dist/raster-image.d.ts +34 -0
  116. package/dist/reference.d.ts +17 -0
  117. package/dist/reference.js +574 -0
  118. package/dist/reference.js.map +1 -0
  119. package/dist/runtime-cli-entry.d.ts +2 -0
  120. package/dist/runtime-cli-entry.js +21 -0
  121. package/dist/runtime-cli-entry.js.map +1 -0
  122. package/dist/runtime-cli.d.ts +76 -0
  123. package/dist/runtime-cli.js +26 -0
  124. package/dist/runtime-cli.js.map +1 -0
  125. package/dist/runtime-development.d.ts +73 -0
  126. package/dist/runtime-development.js +30 -0
  127. package/dist/runtime-development.js.map +1 -0
  128. package/dist/runtime-receipt.d.ts +19 -0
  129. package/dist/runtime.d.ts +355 -0
  130. package/dist/runtime.js +42 -0
  131. package/dist/runtime.js.map +1 -0
  132. package/dist/snapshot.d.ts +26 -0
  133. package/dist/snapshot.js +61 -0
  134. package/dist/snapshot.js.map +1 -0
  135. package/dist/spreadsheet-address.d.ts +18 -0
  136. package/dist/spreadsheet-file.d.ts +17 -0
  137. package/dist/spreadsheet-formula.d.ts +67 -0
  138. package/dist/spreadsheet-image.d.ts +17 -0
  139. package/dist/spreadsheet-render.d.ts +5 -0
  140. package/dist/spreadsheet-render.js +752 -0
  141. package/dist/spreadsheet-render.js.map +1 -0
  142. package/dist/spreadsheet-types.d.ts +155 -0
  143. package/dist/spreadsheet-xlsx-api.d.ts +88 -0
  144. package/dist/spreadsheet-xlsx-codec.d.ts +16 -0
  145. package/dist/spreadsheet-xlsx-codec.js +16 -0
  146. package/dist/spreadsheet-xlsx-codec.js.map +1 -0
  147. package/dist/spreadsheet-xlsx-state.d.ts +16 -0
  148. package/dist/spreadsheet.d.ts +724 -0
  149. package/dist/spreadsheet.js +67 -0
  150. package/dist/spreadsheet.js.map +1 -0
  151. package/package.json +129 -0
  152. package/src/bounded-zip.ts +450 -0
  153. package/src/document-docx-api.ts +64 -0
  154. package/src/document-docx-codec.ts +2253 -0
  155. package/src/document-docx-import.ts +3814 -0
  156. package/src/document-docx-packer.ts +72 -0
  157. package/src/document-docx-state.ts +59 -0
  158. package/src/document-render.ts +615 -0
  159. package/src/document.ts +2800 -0
  160. package/src/errors.ts +45 -0
  161. package/src/file-blob.ts +43 -0
  162. package/src/index.ts +4 -0
  163. package/src/inspection.ts +50 -0
  164. package/src/kernel.ts +525 -0
  165. package/src/materializer-cli-entry.ts +11 -0
  166. package/src/materializer-cli.ts +743 -0
  167. package/src/native-raster.ts +141 -0
  168. package/src/native.ts +390 -0
  169. package/src/office-import.ts +243 -0
  170. package/src/presentation-pptx-api.ts +107 -0
  171. package/src/presentation-pptx-import.ts +2065 -0
  172. package/src/presentation-pptx-state-digest.ts +46 -0
  173. package/src/presentation-pptx-state.ts +18 -0
  174. package/src/presentation-pptx-xml.ts +473 -0
  175. package/src/presentation-pptx.ts +447 -0
  176. package/src/presentation-render.ts +532 -0
  177. package/src/presentation.ts +2599 -0
  178. package/src/production-composite.ts +805 -0
  179. package/src/production-document.ts +2 -0
  180. package/src/production-native-codecs.ts +1141 -0
  181. package/src/production-presentation.ts +2 -0
  182. package/src/production-sha256.ts +150 -0
  183. package/src/production-spreadsheet-native.ts +686 -0
  184. package/src/production-spreadsheet.ts +2 -0
  185. package/src/production.ts +1022 -0
  186. package/src/raster-image.ts +586 -0
  187. package/src/reference.ts +17 -0
  188. package/src/runtime-cli-entry.ts +13 -0
  189. package/src/runtime-cli.ts +670 -0
  190. package/src/runtime-development.ts +689 -0
  191. package/src/runtime-receipt.ts +169 -0
  192. package/src/runtime.ts +1463 -0
  193. package/src/snapshot.ts +88 -0
  194. package/src/spreadsheet-address.ts +90 -0
  195. package/src/spreadsheet-file.ts +71 -0
  196. package/src/spreadsheet-formula.ts +1212 -0
  197. package/src/spreadsheet-image.ts +242 -0
  198. package/src/spreadsheet-render.ts +985 -0
  199. package/src/spreadsheet-types.ts +171 -0
  200. package/src/spreadsheet-xlsx-api.ts +123 -0
  201. package/src/spreadsheet-xlsx-codec.ts +3063 -0
  202. package/src/spreadsheet-xlsx-state.ts +191 -0
  203. package/src/spreadsheet.ts +5195 -0
@@ -0,0 +1,1002 @@
1
+ // src/runtime.ts
2
+ var ARTIFACT_RUNTIME_ENVIRONMENT = {
3
+ manifest: "OPENGENI_ARTIFACT_RUNTIME_MANIFEST",
4
+ toolEntrypoint: "OPENGENI_ARTIFACT_TOOL_ENTRY"
5
+ };
6
+ var ARTIFACT_RUNTIME_TARGETS = [
7
+ "darwin-x64",
8
+ "darwin-arm64",
9
+ "linux-x64-gnu",
10
+ "linux-arm64-gnu",
11
+ "linux-x64-musl",
12
+ "linux-arm64-musl",
13
+ "win32-x64-msvc",
14
+ "wasm-web"
15
+ ];
16
+ var ARTIFACT_RUNTIME_MATRIX = [
17
+ descriptor("darwin-x64", "native", "darwin", "x64"),
18
+ descriptor("darwin-arm64", "native", "darwin", "arm64"),
19
+ descriptor("linux-x64-gnu", "native", "linux", "x64", "gnu"),
20
+ descriptor("linux-arm64-gnu", "native", "linux", "arm64", "gnu"),
21
+ descriptor("linux-x64-musl", "native", "linux", "x64", "musl"),
22
+ descriptor("linux-arm64-musl", "native", "linux", "arm64", "musl"),
23
+ descriptor("win32-x64-msvc", "native", "win32", "x64"),
24
+ descriptor("wasm-web", "wasm", "browser", "wasm32")
25
+ ];
26
+ var ArtifactRuntimeError = class extends Error {
27
+ code;
28
+ constructor(code, message, options) {
29
+ super(`[${code}] ${message}`, options);
30
+ this.name = "ArtifactRuntimeError";
31
+ this.code = code;
32
+ }
33
+ };
34
+ function resolveArtifactRuntimeTarget(input) {
35
+ const match = ARTIFACT_RUNTIME_MATRIX.find(
36
+ (entry) => entry.platform === input.platform && entry.arch === input.arch && (entry.platform !== "linux" || entry.libc === input.libc)
37
+ );
38
+ if (match) return match;
39
+ const libc = input.platform === "linux" ? `/${input.libc ?? "unknown-libc"}` : "";
40
+ throw new ArtifactRuntimeError(
41
+ "ARTIFACT_RUNTIME_UNSUPPORTED_TARGET",
42
+ `No artifact kernel is published for ${input.platform}/${input.arch}${libc}`
43
+ );
44
+ }
45
+ function artifactRuntimeTarget(target) {
46
+ const match = ARTIFACT_RUNTIME_MATRIX.find((entry) => entry.target === target);
47
+ if (!match) {
48
+ throw new ArtifactRuntimeError(
49
+ "ARTIFACT_RUNTIME_UNSUPPORTED_TARGET",
50
+ `Unknown artifact runtime target: ${String(target)}`
51
+ );
52
+ }
53
+ return match;
54
+ }
55
+ function validateArtifactKernelPackageManifest(value, expectedTarget) {
56
+ const record = exactRecord(
57
+ value,
58
+ [
59
+ "schemaVersion",
60
+ "target",
61
+ "kind",
62
+ "packageName",
63
+ "packageVersion",
64
+ "artifactToolVersion",
65
+ "buildIdentity",
66
+ "entrypoint",
67
+ "asset",
68
+ "supportFiles"
69
+ ],
70
+ "kernel package manifest"
71
+ );
72
+ if (record.schemaVersion !== 1) invalid("kernel package manifest schemaVersion must be 1");
73
+ if (!isArtifactRuntimeTarget(record.target)) invalid("kernel package manifest target is invalid");
74
+ const target = artifactRuntimeTarget(record.target);
75
+ if (expectedTarget !== void 0 && target.target !== expectedTarget) {
76
+ invalid(`kernel package target ${target.target} does not match ${expectedTarget}`);
77
+ }
78
+ if (record.kind !== target.kind) invalid("kernel package kind does not match its target");
79
+ if (record.packageName !== target.packageName) {
80
+ invalid("kernel package name does not match its target");
81
+ }
82
+ const packageVersion = exactStableVersion(record.packageVersion, "kernel package version");
83
+ const artifactToolVersion = exactStableVersion(
84
+ record.artifactToolVersion,
85
+ "artifact-tool compatibility version"
86
+ );
87
+ if (packageVersion !== artifactToolVersion) {
88
+ invalid("kernel and artifact-tool versions must be identical");
89
+ }
90
+ const buildIdentity = boundedString(record.buildIdentity, "kernel build identity", 512);
91
+ const entrypoint = exactRecord(
92
+ record.entrypoint,
93
+ ["path", "bytes", "sha256"],
94
+ "kernel entrypoint"
95
+ );
96
+ const asset = exactRecord(record.asset, ["path", "bytes", "sha256"], "kernel asset");
97
+ if (!Array.isArray(record.supportFiles) || record.supportFiles.length > 32) {
98
+ invalid("kernel supportFiles must be an array with at most 32 entries");
99
+ }
100
+ const supportFiles = record.supportFiles.map((supportFile, index) => {
101
+ const file = exactRecord(
102
+ supportFile,
103
+ ["path", "bytes", "sha256"],
104
+ `kernel support file ${index}`
105
+ );
106
+ return {
107
+ path: safeRelativePath(file.path, `kernel support file ${index} path`),
108
+ bytes: positiveSafeInteger(file.bytes, `kernel support file ${index} bytes`),
109
+ sha256: sha256(file.sha256, `kernel support file ${index} sha256`)
110
+ };
111
+ });
112
+ const runtimePaths = [entrypoint.path, asset.path, ...supportFiles.map((file) => file.path)];
113
+ if (new Set(runtimePaths).size !== runtimePaths.length) {
114
+ invalid("kernel runtime file paths must be unique");
115
+ }
116
+ if (!supportFiles.every((file, index) => index === 0 || supportFiles[index - 1].path < file.path)) {
117
+ invalid("kernel supportFiles must be strictly sorted by path");
118
+ }
119
+ return {
120
+ schemaVersion: 1,
121
+ target: target.target,
122
+ kind: target.kind,
123
+ packageName: target.packageName,
124
+ packageVersion,
125
+ artifactToolVersion,
126
+ buildIdentity,
127
+ entrypoint: {
128
+ path: safeRelativePath(entrypoint.path, "kernel entrypoint path"),
129
+ bytes: positiveSafeInteger(entrypoint.bytes, "kernel entrypoint bytes"),
130
+ sha256: sha256(entrypoint.sha256, "kernel entrypoint sha256")
131
+ },
132
+ asset: {
133
+ path: safeRelativePath(asset.path, "kernel asset path"),
134
+ bytes: positiveSafeInteger(asset.bytes, "kernel asset bytes"),
135
+ sha256: sha256(asset.sha256, "kernel asset sha256")
136
+ },
137
+ supportFiles
138
+ };
139
+ }
140
+ function validateArtifactKernelPackageIdentity(value, expectedTarget) {
141
+ const record = exactRecord(
142
+ value,
143
+ [
144
+ "schemaVersion",
145
+ "target",
146
+ "kind",
147
+ "packageName",
148
+ "packageVersion",
149
+ "artifactToolVersion",
150
+ "buildIdentity"
151
+ ],
152
+ "kernel package identity"
153
+ );
154
+ if (record.schemaVersion !== 1) invalid("kernel package identity schemaVersion must be 1");
155
+ if (!isArtifactRuntimeTarget(record.target)) invalid("kernel package identity target is invalid");
156
+ const target = artifactRuntimeTarget(record.target);
157
+ if (expectedTarget !== void 0 && target.target !== expectedTarget) {
158
+ invalid(`kernel package identity target ${target.target} does not match ${expectedTarget}`);
159
+ }
160
+ if (record.kind !== target.kind)
161
+ invalid("kernel package identity kind does not match its target");
162
+ if (record.packageName !== target.packageName) {
163
+ invalid("kernel package identity name does not match its target");
164
+ }
165
+ const packageVersion = exactStableVersion(
166
+ record.packageVersion,
167
+ "kernel package identity version"
168
+ );
169
+ const artifactToolVersion = exactStableVersion(
170
+ record.artifactToolVersion,
171
+ "kernel package identity artifact-tool version"
172
+ );
173
+ if (packageVersion !== artifactToolVersion) {
174
+ invalid("kernel package identity versions must be identical");
175
+ }
176
+ return {
177
+ schemaVersion: 1,
178
+ target: target.target,
179
+ kind: target.kind,
180
+ packageName: target.packageName,
181
+ packageVersion,
182
+ artifactToolVersion,
183
+ buildIdentity: boundedString(
184
+ record.buildIdentity,
185
+ "kernel package identity build identity",
186
+ 512
187
+ )
188
+ };
189
+ }
190
+ function validateArtifactRuntimeInstallationManifest(value, expectedTarget) {
191
+ const candidate = requiredRecord(value, "artifact runtime installation manifest");
192
+ const record = exactRecord(
193
+ candidate,
194
+ [
195
+ "schemaVersion",
196
+ "target",
197
+ "releaseManifest",
198
+ "artifactTool",
199
+ ...Object.hasOwn(candidate, "artifactToolArchive") ? ["artifactToolArchive"] : [],
200
+ "skillFacadeEntrypoint",
201
+ ...Object.hasOwn(candidate, "skillFacadeSupportFiles") ? ["skillFacadeSupportFiles"] : [],
202
+ "kernelPackageRoot",
203
+ "kernel"
204
+ ],
205
+ "artifact runtime installation manifest"
206
+ );
207
+ if (record.schemaVersion !== 1) invalid("installation manifest schemaVersion must be 1");
208
+ if (!isArtifactRuntimeTarget(record.target)) invalid("installation manifest target is invalid");
209
+ if (expectedTarget !== void 0 && record.target !== expectedTarget) {
210
+ invalid(`installation target ${record.target} does not match ${expectedTarget}`);
211
+ }
212
+ const releaseManifest = exactRecord(
213
+ record.releaseManifest,
214
+ ["path", "bytes", "sha256"],
215
+ "release manifest file"
216
+ );
217
+ const artifactTool = exactRecord(
218
+ record.artifactTool,
219
+ ["packageName", "packageVersion", "integrity"],
220
+ "artifact-tool installation"
221
+ );
222
+ if (artifactTool.packageName !== "@opengeni/artifact-tool") {
223
+ invalid("artifact-tool package name is invalid");
224
+ }
225
+ const packageVersion = exactStableVersion(artifactTool.packageVersion, "artifact-tool version");
226
+ const integrity = sha512Integrity(artifactTool.integrity, "artifact-tool integrity");
227
+ const artifactToolArchive = Object.hasOwn(candidate, "artifactToolArchive") ? exactRecord(record.artifactToolArchive, ["path", "bytes", "sha256"], "artifact-tool archive") : void 0;
228
+ const skillFacadeEntrypoint = exactRecord(
229
+ record.skillFacadeEntrypoint,
230
+ ["path", "bytes", "sha256"],
231
+ "skill facade entrypoint"
232
+ );
233
+ const rawSkillFacadeSupportFiles = record.skillFacadeSupportFiles ?? [];
234
+ if (!Array.isArray(rawSkillFacadeSupportFiles) || rawSkillFacadeSupportFiles.length > 256) {
235
+ invalid("skill facade supportFiles must be an array with at most 256 entries");
236
+ }
237
+ const skillFacadeSupportFiles = rawSkillFacadeSupportFiles.map((supportFile, index) => {
238
+ const file = exactRecord(
239
+ supportFile,
240
+ ["path", "bytes", "sha256"],
241
+ `skill facade support file ${index}`
242
+ );
243
+ return {
244
+ path: safeRelativePath(file.path, `skill facade support file ${index} path`),
245
+ bytes: positiveSafeInteger(file.bytes, `skill facade support file ${index} bytes`),
246
+ sha256: sha256(file.sha256, `skill facade support file ${index} sha256`)
247
+ };
248
+ });
249
+ if (!skillFacadeSupportFiles.every(
250
+ (file, index) => index === 0 || skillFacadeSupportFiles[index - 1].path < file.path
251
+ )) {
252
+ invalid("skill facade supportFiles must be strictly sorted by path");
253
+ }
254
+ const facadeRuntimePaths = [
255
+ ...artifactToolArchive ? [safeRelativePath(artifactToolArchive.path, "artifact-tool archive path")] : [],
256
+ safeRelativePath(releaseManifest.path, "release manifest path"),
257
+ safeRelativePath(skillFacadeEntrypoint.path, "skill facade entrypoint path"),
258
+ ...skillFacadeSupportFiles.map((file) => file.path)
259
+ ];
260
+ const skillFacadeSupportBytes = skillFacadeSupportFiles.reduce(
261
+ (total, file) => total + file.bytes,
262
+ 0
263
+ );
264
+ if (!Number.isSafeInteger(skillFacadeSupportBytes) || skillFacadeSupportBytes > 256 * 1024 * 1024) {
265
+ invalid("skill facade supportFiles exceed the 256 MiB installation limit");
266
+ }
267
+ const kernel = validateArtifactKernelPackageManifest(record.kernel, record.target);
268
+ if (kernel.artifactToolVersion !== packageVersion) {
269
+ invalid("installed artifact-tool and kernel versions must be identical");
270
+ }
271
+ const kernelPackageRoot = safeRelativePath(record.kernelPackageRoot, "kernel package root");
272
+ const installationFilePaths = [
273
+ ...facadeRuntimePaths,
274
+ `${kernelPackageRoot}/${kernel.entrypoint.path}`,
275
+ `${kernelPackageRoot}/${kernel.asset.path}`,
276
+ ...kernel.supportFiles.map((file) => `${kernelPackageRoot}/${file.path}`)
277
+ ].sort();
278
+ if (installationFilePaths.some(
279
+ (path, index) => index > 0 && (path === installationFilePaths[index - 1] || path.startsWith(`${installationFilePaths[index - 1]}/`))
280
+ )) {
281
+ invalid("installation runtime file paths must be collision-free");
282
+ }
283
+ return {
284
+ schemaVersion: 1,
285
+ target: record.target,
286
+ releaseManifest: {
287
+ path: safeRelativePath(releaseManifest.path, "release manifest path"),
288
+ bytes: positiveSafeInteger(releaseManifest.bytes, "release manifest bytes"),
289
+ sha256: sha256(releaseManifest.sha256, "release manifest sha256")
290
+ },
291
+ artifactTool: {
292
+ packageName: "@opengeni/artifact-tool",
293
+ packageVersion,
294
+ integrity
295
+ },
296
+ ...artifactToolArchive ? {
297
+ artifactToolArchive: {
298
+ path: safeRelativePath(artifactToolArchive.path, "artifact-tool archive path"),
299
+ bytes: positiveSafeInteger(artifactToolArchive.bytes, "artifact-tool archive bytes"),
300
+ sha256: sha256(artifactToolArchive.sha256, "artifact-tool archive sha256")
301
+ }
302
+ } : {},
303
+ skillFacadeEntrypoint: {
304
+ path: safeRelativePath(skillFacadeEntrypoint.path, "skill facade entrypoint path"),
305
+ bytes: positiveSafeInteger(skillFacadeEntrypoint.bytes, "skill facade entrypoint bytes"),
306
+ sha256: sha256(skillFacadeEntrypoint.sha256, "skill facade entrypoint sha256")
307
+ },
308
+ ...Object.hasOwn(candidate, "skillFacadeSupportFiles") ? { skillFacadeSupportFiles } : {},
309
+ kernelPackageRoot,
310
+ kernel: {
311
+ ...kernel
312
+ }
313
+ };
314
+ }
315
+ function validateCompleteArtifactRuntimeReleaseManifest(value) {
316
+ const record = exactRecord(
317
+ value,
318
+ ["schemaVersion", "artifactTool", "targets"],
319
+ "release manifest"
320
+ );
321
+ if (record.schemaVersion !== 1) invalid("release manifest schemaVersion must be 1");
322
+ const artifactTool = exactRecord(
323
+ record.artifactTool,
324
+ ["packageName", "packageVersion", "integrity"],
325
+ "release artifact-tool"
326
+ );
327
+ if (artifactTool.packageName !== "@opengeni/artifact-tool") {
328
+ invalid("release artifact-tool package name is invalid");
329
+ }
330
+ const packageVersion = exactStableVersion(
331
+ artifactTool.packageVersion,
332
+ "release artifact-tool version"
333
+ );
334
+ const integrity = sha512Integrity(artifactTool.integrity, "release artifact-tool integrity");
335
+ if (!Array.isArray(record.targets)) invalid("release targets must be an array");
336
+ if (record.targets.length !== ARTIFACT_RUNTIME_MATRIX.length) {
337
+ invalid(`release manifest must contain exactly ${ARTIFACT_RUNTIME_MATRIX.length} targets`);
338
+ }
339
+ const targets = record.targets.map((entry, index) => {
340
+ const expected = ARTIFACT_RUNTIME_MATRIX[index];
341
+ const target = validateArtifactKernelPackageManifest(entry, expected.target);
342
+ if (target.artifactToolVersion !== packageVersion) {
343
+ invalid(`target ${target.target} does not match artifact-tool ${packageVersion}`);
344
+ }
345
+ return target;
346
+ });
347
+ const buildIdentities = new Set(targets.map((target) => target.buildIdentity));
348
+ if (buildIdentities.size !== 1) invalid("all target packages must carry one build identity");
349
+ return {
350
+ schemaVersion: 1,
351
+ artifactTool: {
352
+ packageName: "@opengeni/artifact-tool",
353
+ packageVersion,
354
+ integrity
355
+ },
356
+ targets
357
+ };
358
+ }
359
+ function locateArtifactRuntimeDependencies(value, manifestUrl, expectedTarget) {
360
+ if (manifestUrl.protocol !== "file:") {
361
+ throw new ArtifactRuntimeError(
362
+ "ARTIFACT_RUNTIME_MANIFEST_INVALID",
363
+ "Installed runtime manifest must be a local file URL"
364
+ );
365
+ }
366
+ const manifest = validateArtifactRuntimeInstallationManifest(value, expectedTarget);
367
+ const root = new URL("./", manifestUrl);
368
+ const kernelRoot = confinedUrl(root, `${manifest.kernelPackageRoot}/`);
369
+ return {
370
+ target: artifactRuntimeTarget(manifest.target),
371
+ manifestUrl,
372
+ releaseManifestUrl: confinedUrl(root, manifest.releaseManifest.path),
373
+ ...manifest.artifactToolArchive ? { artifactToolArchiveUrl: confinedUrl(root, manifest.artifactToolArchive.path) } : {},
374
+ skillFacadeEntrypoint: confinedUrl(root, manifest.skillFacadeEntrypoint.path),
375
+ skillFacadeSupportFiles: (manifest.skillFacadeSupportFiles ?? []).map(
376
+ (file) => confinedUrl(root, file.path)
377
+ ),
378
+ kernelEntrypoint: confinedUrl(kernelRoot, manifest.kernel.entrypoint.path),
379
+ kernelAsset: confinedUrl(kernelRoot, manifest.kernel.asset.path),
380
+ kernelSupportFiles: manifest.kernel.supportFiles.map(
381
+ (file) => confinedUrl(kernelRoot, file.path)
382
+ ),
383
+ manifest
384
+ };
385
+ }
386
+ async function loadArtifactKernelRuntime(dependencies, importer = defaultModuleImporter) {
387
+ let imported;
388
+ try {
389
+ imported = await importer(dependencies.kernelEntrypoint.href);
390
+ } catch (cause) {
391
+ throw new ArtifactRuntimeError(
392
+ "ARTIFACT_RUNTIME_UNAVAILABLE",
393
+ `Could not load exact kernel package ${dependencies.manifest.kernel.packageName}`,
394
+ { cause }
395
+ );
396
+ }
397
+ const module = requiredRecord(imported, "kernel package module");
398
+ const packagedIdentity = validateArtifactKernelPackageIdentity(
399
+ module.artifactKernelPackageIdentity,
400
+ dependencies.target.target
401
+ );
402
+ assertSameKernelPackageIdentity(packagedIdentity, dependencies.manifest.kernel);
403
+ if (typeof module.loadArtifactKernelBinding !== "function") {
404
+ incompatible("kernel package does not export loadArtifactKernelBinding()");
405
+ }
406
+ const candidate = await module.loadArtifactKernelBinding();
407
+ return new ArtifactKernelRuntime(
408
+ dependencies.target.kind,
409
+ candidate,
410
+ dependencies.manifest.kernel
411
+ );
412
+ }
413
+ var ArtifactKernelRuntime = class {
414
+ kind;
415
+ target;
416
+ capabilities;
417
+ buildIdentity;
418
+ #binding;
419
+ constructor(kind, candidate, packageManifest) {
420
+ const manifest = validateArtifactKernelPackageManifest(packageManifest);
421
+ if (kind !== manifest.kind) incompatible("binding kind does not match package manifest");
422
+ this.kind = kind;
423
+ this.target = manifest.target;
424
+ this.#binding = validateRawBinding(candidate);
425
+ this.capabilities = parseCapabilities(this.#binding.capabilities());
426
+ this.buildIdentity = decodeBuildIdentity(this.#binding.buildIdentity());
427
+ if (this.buildIdentity !== manifest.buildIdentity) {
428
+ throw new ArtifactRuntimeError(
429
+ "ARTIFACT_RUNTIME_INTEGRITY",
430
+ "Loaded kernel build identity does not match its package manifest"
431
+ );
432
+ }
433
+ }
434
+ canonicalizeCollaborationSnapshot(snapshot) {
435
+ return bytes(
436
+ this.#binding.canonicalizeCollaborationSnapshot(snapshot),
437
+ "canonicalizeCollaborationSnapshot"
438
+ );
439
+ }
440
+ createDocument(namespace) {
441
+ return bytes(
442
+ this.#binding.createDocument(encodeArtifactReplicaNamespace(namespace)),
443
+ "createDocument"
444
+ );
445
+ }
446
+ applyDocumentCommands(snapshot, commands) {
447
+ return bytes(this.#binding.applyDocumentCommands(snapshot, commands), "applyDocumentCommands");
448
+ }
449
+ queryDocument(snapshot, query) {
450
+ return bytes(this.#binding.queryDocument(snapshot, query), "queryDocument");
451
+ }
452
+ canonicalizeDocumentSnapshot(snapshot) {
453
+ return bytes(
454
+ this.#binding.canonicalizeDocumentSnapshot(snapshot),
455
+ "canonicalizeDocumentSnapshot"
456
+ );
457
+ }
458
+ createPresentation(namespace) {
459
+ return bytes(
460
+ this.#binding.createPresentation(encodeArtifactReplicaNamespace(namespace)),
461
+ "createPresentation"
462
+ );
463
+ }
464
+ applyPresentationCommands(snapshot, commands) {
465
+ return bytes(
466
+ this.#binding.applyPresentationCommands(snapshot, commands),
467
+ "applyPresentationCommands"
468
+ );
469
+ }
470
+ queryPresentation(snapshot, query) {
471
+ return bytes(this.#binding.queryPresentation(snapshot, query), "queryPresentation");
472
+ }
473
+ canonicalizePresentationSnapshot(snapshot) {
474
+ return bytes(
475
+ this.#binding.canonicalizePresentationSnapshot(snapshot),
476
+ "canonicalizePresentationSnapshot"
477
+ );
478
+ }
479
+ layoutText(fontBundle, request) {
480
+ return bytes(this.#binding.layoutText(fontBundle, request), "layoutText");
481
+ }
482
+ canonicalizeRenderTile(value) {
483
+ return bytes(this.#binding.canonicalizeRenderTile(value), "canonicalizeRenderTile");
484
+ }
485
+ canonicalizeRenderPatch(value) {
486
+ return bytes(this.#binding.canonicalizeRenderPatch(value), "canonicalizeRenderPatch");
487
+ }
488
+ createCollaborationSession(namespace) {
489
+ return new ArtifactCollaborationSession(
490
+ this.#binding.ArtifactCollaborationSession.create(encodeArtifactReplicaNamespace(namespace))
491
+ );
492
+ }
493
+ openCollaborationSession(snapshot) {
494
+ return new ArtifactCollaborationSession(
495
+ this.#binding.ArtifactCollaborationSession.open(snapshot)
496
+ );
497
+ }
498
+ createDocumentSession(namespace) {
499
+ return new ArtifactDocumentSession(
500
+ this.#binding.ArtifactDocumentSession.create(encodeArtifactReplicaNamespace(namespace))
501
+ );
502
+ }
503
+ openDocumentSession(snapshot) {
504
+ return new ArtifactDocumentSession(this.#binding.ArtifactDocumentSession.open(snapshot));
505
+ }
506
+ createPresentationSession(namespace) {
507
+ return new ArtifactPresentationSession(
508
+ this.#binding.ArtifactPresentationSession.create(encodeArtifactReplicaNamespace(namespace))
509
+ );
510
+ }
511
+ openPresentationSession(snapshot) {
512
+ return new ArtifactPresentationSession(
513
+ this.#binding.ArtifactPresentationSession.open(snapshot)
514
+ );
515
+ }
516
+ openTextLayoutSession(fontBundle) {
517
+ return new ArtifactTextLayoutSession(this.#binding.ArtifactTextLayoutSession.open(fontBundle));
518
+ }
519
+ };
520
+ var ArtifactCollaborationSession = class _ArtifactCollaborationSession {
521
+ #session;
522
+ #disposed = false;
523
+ constructor(session) {
524
+ validateRawCollaborationSession(session);
525
+ this.#session = session;
526
+ }
527
+ authorTransaction(intent, resolvedBase) {
528
+ this.assertLive();
529
+ return bytes(this.#session.authorTransaction(intent, resolvedBase), "authorTransaction");
530
+ }
531
+ applyCommitted(operation) {
532
+ this.assertLive();
533
+ this.#session.applyCommitted(operation);
534
+ }
535
+ queryViewport(request) {
536
+ return this.query(request);
537
+ }
538
+ query(request) {
539
+ this.assertLive();
540
+ return bytes(this.#session.query(request), "query");
541
+ }
542
+ snapshot() {
543
+ this.assertLive();
544
+ return bytes(this.#session.snapshot(), "snapshot");
545
+ }
546
+ frontier() {
547
+ this.assertLive();
548
+ return bytes(this.#session.frontier(), "frontier");
549
+ }
550
+ stateHash() {
551
+ this.assertLive();
552
+ const returnedStateHash = this.#session.stateHash();
553
+ if (!/^sha256:[0-9a-f]{64}$/u.test(returnedStateHash))
554
+ incompatible("kernel returned invalid state hash");
555
+ return returnedStateHash;
556
+ }
557
+ revision() {
558
+ this.assertLive();
559
+ const revision = this.#session.revision();
560
+ if (typeof revision === "bigint") {
561
+ if (revision < 0n) incompatible("kernel returned a negative revision");
562
+ return revision;
563
+ }
564
+ if (!Number.isSafeInteger(revision) || revision < 0) {
565
+ incompatible("kernel returned an unsafe revision");
566
+ }
567
+ return BigInt(revision);
568
+ }
569
+ fork() {
570
+ this.assertLive();
571
+ return new _ArtifactCollaborationSession(this.#session.fork());
572
+ }
573
+ isClosed() {
574
+ return this.#disposed || (typeof this.#session.isClosed === "function" ? this.#session.isClosed() : this.#session.closed === true);
575
+ }
576
+ dispose() {
577
+ if (this.#disposed) return;
578
+ try {
579
+ if (!this.isClosed()) {
580
+ if (typeof this.#session.dispose === "function") this.#session.dispose();
581
+ else this.#session.close?.();
582
+ }
583
+ } finally {
584
+ this.#session.free?.();
585
+ this.#disposed = true;
586
+ }
587
+ }
588
+ assertLive() {
589
+ if (this.isClosed()) incompatible("artifact collaboration session is closed");
590
+ }
591
+ };
592
+ var ArtifactModalitySession = class {
593
+ #session;
594
+ #disposed = false;
595
+ constructor(session) {
596
+ validateRawModalitySession(session);
597
+ this.#session = session;
598
+ }
599
+ applyCommands(commands) {
600
+ this.assertLive();
601
+ return bytes(this.#session.applyCommands(commands), "modality session applyCommands");
602
+ }
603
+ query(request) {
604
+ this.assertLive();
605
+ return bytes(this.#session.query(request), "modality session query");
606
+ }
607
+ snapshot() {
608
+ this.assertLive();
609
+ return bytes(this.#session.snapshot(), "modality session snapshot");
610
+ }
611
+ revision() {
612
+ this.assertLive();
613
+ return safeRevision(this.#session.revision());
614
+ }
615
+ stateHash() {
616
+ this.assertLive();
617
+ return stateHash(this.#session.stateHash());
618
+ }
619
+ isClosed() {
620
+ return rawSessionClosed(this.#disposed, this.#session);
621
+ }
622
+ dispose() {
623
+ if (this.#disposed) return;
624
+ try {
625
+ if (!this.isClosed()) {
626
+ if (typeof this.#session.dispose === "function") this.#session.dispose();
627
+ else this.#session.close?.();
628
+ }
629
+ } finally {
630
+ this.#session.free?.();
631
+ this.#disposed = true;
632
+ }
633
+ }
634
+ forkRaw() {
635
+ this.assertLive();
636
+ return this.#session.fork();
637
+ }
638
+ assertLive() {
639
+ if (this.isClosed()) incompatible("artifact modality session is closed");
640
+ }
641
+ };
642
+ var ArtifactDocumentSession = class _ArtifactDocumentSession extends ArtifactModalitySession {
643
+ fork() {
644
+ return new _ArtifactDocumentSession(this.forkRaw());
645
+ }
646
+ };
647
+ var ArtifactPresentationSession = class _ArtifactPresentationSession extends ArtifactModalitySession {
648
+ fork() {
649
+ return new _ArtifactPresentationSession(this.forkRaw());
650
+ }
651
+ };
652
+ var ArtifactTextLayoutSession = class {
653
+ #session;
654
+ #disposed = false;
655
+ constructor(session) {
656
+ validateRawTextLayoutSession(session);
657
+ this.#session = session;
658
+ }
659
+ layout(request) {
660
+ if (this.isClosed()) incompatible("artifact text-layout session is closed");
661
+ return bytes(this.#session.layout(request), "text-layout session layout");
662
+ }
663
+ isClosed() {
664
+ return rawSessionClosed(this.#disposed, this.#session);
665
+ }
666
+ dispose() {
667
+ if (this.#disposed) return;
668
+ try {
669
+ if (!this.isClosed()) {
670
+ if (typeof this.#session.dispose === "function") this.#session.dispose();
671
+ else this.#session.close?.();
672
+ }
673
+ } finally {
674
+ this.#session.free?.();
675
+ this.#disposed = true;
676
+ }
677
+ }
678
+ };
679
+ function descriptor(target, kind, platform, arch, libc) {
680
+ return {
681
+ target,
682
+ kind,
683
+ packageName: `@opengeni/artifact-kernel-${target}`,
684
+ platform,
685
+ arch,
686
+ ...libc ? { libc } : {}
687
+ };
688
+ }
689
+ function defaultModuleImporter(specifier) {
690
+ return import(
691
+ /* @vite-ignore */
692
+ specifier
693
+ );
694
+ }
695
+ function validateRawBinding(value) {
696
+ const binding = bindingRecord(value, "artifact kernel binding");
697
+ for (const name of [
698
+ "capabilities",
699
+ "buildIdentity",
700
+ "canonicalizeCollaborationSnapshot",
701
+ "createDocument",
702
+ "applyDocumentCommands",
703
+ "queryDocument",
704
+ "canonicalizeDocumentSnapshot",
705
+ "createPresentation",
706
+ "applyPresentationCommands",
707
+ "queryPresentation",
708
+ "canonicalizePresentationSnapshot",
709
+ "layoutText",
710
+ "canonicalizeRenderTile",
711
+ "canonicalizeRenderPatch"
712
+ ]) {
713
+ if (typeof binding[name] !== "function") incompatible(`kernel binding is missing ${name}()`);
714
+ }
715
+ const session = bindingRecord(
716
+ binding.ArtifactCollaborationSession,
717
+ "ArtifactCollaborationSession"
718
+ );
719
+ if (typeof session.create !== "function" || typeof session.open !== "function") {
720
+ incompatible("ArtifactCollaborationSession is missing create/open factories");
721
+ }
722
+ for (const name of ["ArtifactDocumentSession", "ArtifactPresentationSession"]) {
723
+ const constructor = bindingRecord(binding[name], name);
724
+ if (typeof constructor.create !== "function" || typeof constructor.open !== "function") {
725
+ incompatible(`${name} is missing create/open factories`);
726
+ }
727
+ }
728
+ const textLayout = bindingRecord(binding.ArtifactTextLayoutSession, "ArtifactTextLayoutSession");
729
+ if (typeof textLayout.open !== "function") {
730
+ incompatible("ArtifactTextLayoutSession is missing open() factory");
731
+ }
732
+ return value;
733
+ }
734
+ function validateRawCollaborationSession(value) {
735
+ const session = bindingRecord(value, "artifact collaboration session");
736
+ for (const name of [
737
+ "authorTransaction",
738
+ "applyCommitted",
739
+ "query",
740
+ "snapshot",
741
+ "frontier",
742
+ "stateHash",
743
+ "revision",
744
+ "fork"
745
+ ]) {
746
+ if (typeof session[name] !== "function")
747
+ incompatible(`collaboration session is missing ${name}()`);
748
+ }
749
+ }
750
+ function validateRawModalitySession(value) {
751
+ const session = bindingRecord(value, "artifact modality session");
752
+ for (const name of [
753
+ "applyCommands",
754
+ "query",
755
+ "snapshot",
756
+ "stateHash",
757
+ "revision",
758
+ "fork"
759
+ ]) {
760
+ if (typeof session[name] !== "function") {
761
+ incompatible(`artifact modality session is missing ${name}()`);
762
+ }
763
+ }
764
+ }
765
+ function validateRawTextLayoutSession(value) {
766
+ const session = bindingRecord(value, "artifact text-layout session");
767
+ if (typeof session.layout !== "function") {
768
+ incompatible("artifact text-layout session is missing layout()");
769
+ }
770
+ }
771
+ function parseCapabilities(value) {
772
+ const decoded = JSON.parse(
773
+ new TextDecoder("utf-8", { fatal: true }).decode(bytes(value, "capabilities"))
774
+ );
775
+ const capabilities = requiredRecord(decoded, "artifact kernel capabilities");
776
+ const required = {
777
+ abiVersion: 1,
778
+ buildIdentityFormat: "utf8",
779
+ commandSchemaVersion: 1,
780
+ spreadsheetCommandVersion: 1,
781
+ kernelSnapshotVersion: 1,
782
+ receiptSchemaVersion: 1,
783
+ collaborationSnapshotVersion: 1,
784
+ editableArtifactIntentVersion: 1,
785
+ committedTransactionVersion: 1,
786
+ queryVersion: 1,
787
+ queryResponseVersion: 1,
788
+ collaboration: true,
789
+ document: true,
790
+ documentCommandVersion: 1,
791
+ documentQueryResponseVersion: 1,
792
+ documentQueryVersion: 1,
793
+ documentReceiptVersion: 1,
794
+ documentSnapshotVersion: 1,
795
+ documentStatefulSessions: true,
796
+ presentation: true,
797
+ presentationCommandVersion: 1,
798
+ presentationQueryResponseVersion: 1,
799
+ presentationQueryVersion: 1,
800
+ presentationSnapshotVersion: 1,
801
+ presentationStatefulSessions: true,
802
+ textLayout: true,
803
+ textLayoutFontBundleVersion: 1,
804
+ textLayoutRequestVersion: 1,
805
+ textLayoutResponseVersion: 1,
806
+ textLayoutStatefulSessions: true,
807
+ retainedRenderPatchVersion: 1,
808
+ retainedRenderTileVersion: 1,
809
+ workbookMetadataQueries: true,
810
+ canonicalStateHash: "sha256:canonical-snapshot",
811
+ safeRust: true,
812
+ sessionForks: true,
813
+ statefulSessions: true,
814
+ transport: "bounded-uint8array"
815
+ };
816
+ for (const [name, expected] of Object.entries(required)) {
817
+ if (capabilities[name] !== expected) incompatible(`kernel capability ${name} is incompatible`);
818
+ }
819
+ for (const name of [
820
+ "maxCellsPerBatch",
821
+ "maxCommandBytes",
822
+ "maxCommands",
823
+ "maxCommittedTransactionBytes",
824
+ "maxDocumentCommandBytes",
825
+ "maxDocumentCommands",
826
+ "maxDocumentQueryBytes",
827
+ "maxDocumentQueryResponseBytes",
828
+ "maxDocumentSnapshotBytes",
829
+ "maxIntentBytes",
830
+ "maxMetadataScannedCells",
831
+ "maxMetadataSheets",
832
+ "maxPresentationCommandBytes",
833
+ "maxPresentationQueryBytes",
834
+ "maxPresentationResponseBytes",
835
+ "maxPresentationSnapshotBytes",
836
+ "maxQueryBytes",
837
+ "maxQueryResponseBytes",
838
+ "maxSnapshotBytes",
839
+ "maxSpreadsheetCommandBytes",
840
+ "maxTextLayoutFontBundleBytes",
841
+ "maxTextLayoutRequestBytes",
842
+ "maxTextLayoutResponseBytes",
843
+ "maxViewportArea",
844
+ "maxViewportCells"
845
+ ]) {
846
+ positiveSafeInteger(capabilities[name], `kernel capability ${name}`);
847
+ }
848
+ return capabilities;
849
+ }
850
+ function decodeBuildIdentity(value) {
851
+ const identity = new TextDecoder("utf-8", { fatal: true }).decode(bytes(value, "buildIdentity"));
852
+ return boundedString(identity, "kernel build identity", 512);
853
+ }
854
+ function safeRevision(value) {
855
+ if (typeof value === "bigint") {
856
+ if (value < 0n) incompatible("kernel returned a negative revision");
857
+ return value;
858
+ }
859
+ if (!Number.isSafeInteger(value) || value < 0) {
860
+ incompatible("kernel returned an unsafe revision");
861
+ }
862
+ return BigInt(value);
863
+ }
864
+ function stateHash(value) {
865
+ if (!/^sha256:[0-9a-f]{64}$/u.test(value)) incompatible("kernel returned invalid state hash");
866
+ return value;
867
+ }
868
+ function rawSessionClosed(disposed, session) {
869
+ return disposed || (typeof session.isClosed === "function" ? session.isClosed() : session.closed === true);
870
+ }
871
+ function encodeArtifactReplicaNamespace(namespace) {
872
+ if (namespace <= 0n || namespace > 0xffffffffffffffffn) {
873
+ incompatible("artifact replica namespace must be a nonzero u64");
874
+ }
875
+ const envelope = new Uint8Array(28);
876
+ envelope.set(new TextEncoder().encode("OGAKN001"));
877
+ const view = new DataView(envelope.buffer);
878
+ view.setUint16(8, 1, true);
879
+ view.setBigUint64(12, namespace, true);
880
+ view.setBigUint64(20, fnv64(envelope.subarray(0, 20)), true);
881
+ return envelope;
882
+ }
883
+ function fnv64(value) {
884
+ let hash = 0xcbf29ce484222325n;
885
+ for (const byte of value) {
886
+ hash ^= BigInt(byte);
887
+ hash = BigInt.asUintN(64, hash * 0x100000001b3n);
888
+ }
889
+ return hash;
890
+ }
891
+ function assertSameKernelPackageIdentity(actual, expected) {
892
+ if (JSON.stringify(actual) !== JSON.stringify({
893
+ schemaVersion: expected.schemaVersion,
894
+ target: expected.target,
895
+ kind: expected.kind,
896
+ packageName: expected.packageName,
897
+ packageVersion: expected.packageVersion,
898
+ artifactToolVersion: expected.artifactToolVersion,
899
+ buildIdentity: expected.buildIdentity
900
+ })) {
901
+ throw new ArtifactRuntimeError(
902
+ "ARTIFACT_RUNTIME_INTEGRITY",
903
+ "Loaded kernel package identity differs from the installation manifest"
904
+ );
905
+ }
906
+ }
907
+ function confinedUrl(root, relativePath) {
908
+ const candidate = new URL(relativePath, root);
909
+ if (candidate.protocol !== "file:" || !candidate.href.startsWith(root.href)) {
910
+ invalid("runtime dependency escapes the installation root");
911
+ }
912
+ return candidate;
913
+ }
914
+ function safeRelativePath(value, name) {
915
+ const path = boundedString(value, name, 1024);
916
+ if (path.startsWith("/") || path.startsWith("\\") || path.includes("\\") || path.split("/").some((part) => part === "" || part === "." || part === "..") || /[%?#\0]/u.test(path)) {
917
+ invalid(`${name} must be a normalized relative POSIX path`);
918
+ }
919
+ return path;
920
+ }
921
+ function exactStableVersion(value, name) {
922
+ if (typeof value !== "string" || !/^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$/u.test(value)) {
923
+ invalid(`${name} must be an exact stable semantic version`);
924
+ }
925
+ return value;
926
+ }
927
+ function sha256(value, name) {
928
+ if (typeof value !== "string" || !/^sha256:[0-9a-f]{64}$/u.test(value)) {
929
+ invalid(`${name} must be a lowercase SHA-256 digest`);
930
+ }
931
+ return value;
932
+ }
933
+ function sha512Integrity(value, name) {
934
+ if (typeof value !== "string" || !/^sha512-[A-Za-z0-9+/]+={0,2}$/u.test(value)) {
935
+ invalid(`${name} is invalid`);
936
+ }
937
+ return value;
938
+ }
939
+ function positiveSafeInteger(value, name) {
940
+ if (!Number.isSafeInteger(value) || value <= 0) invalid(`${name} must be positive`);
941
+ return value;
942
+ }
943
+ function boundedString(value, name, maximum) {
944
+ if (typeof value !== "string" || value.length === 0 || value.length > maximum) {
945
+ invalid(`${name} is invalid`);
946
+ }
947
+ return value;
948
+ }
949
+ function isArtifactRuntimeTarget(value) {
950
+ return typeof value === "string" && ARTIFACT_RUNTIME_TARGETS.includes(value);
951
+ }
952
+ function exactRecord(value, keys, name) {
953
+ const record = requiredRecord(value, name);
954
+ const actualKeys = Object.keys(record).sort();
955
+ const expectedKeys = [...keys].sort();
956
+ if (JSON.stringify(actualKeys) !== JSON.stringify(expectedKeys))
957
+ invalid(`${name} has unexpected fields`);
958
+ return record;
959
+ }
960
+ function requiredRecord(value, name) {
961
+ if (typeof value !== "object" || value === null || Array.isArray(value))
962
+ invalid(`${name} is invalid`);
963
+ return value;
964
+ }
965
+ function bindingRecord(value, name) {
966
+ if (typeof value !== "object" && typeof value !== "function" || value === null) {
967
+ incompatible(`${name} is invalid`);
968
+ }
969
+ return value;
970
+ }
971
+ function bytes(value, name) {
972
+ if (!(value instanceof Uint8Array)) incompatible(`kernel ${name} did not return Uint8Array`);
973
+ return value;
974
+ }
975
+ function invalid(message) {
976
+ throw new ArtifactRuntimeError("ARTIFACT_RUNTIME_MANIFEST_INVALID", message);
977
+ }
978
+ function incompatible(message) {
979
+ throw new ArtifactRuntimeError("ARTIFACT_RUNTIME_INCOMPATIBLE", message);
980
+ }
981
+
982
+ export {
983
+ ARTIFACT_RUNTIME_ENVIRONMENT,
984
+ ARTIFACT_RUNTIME_TARGETS,
985
+ ARTIFACT_RUNTIME_MATRIX,
986
+ ArtifactRuntimeError,
987
+ resolveArtifactRuntimeTarget,
988
+ artifactRuntimeTarget,
989
+ validateArtifactKernelPackageManifest,
990
+ validateArtifactKernelPackageIdentity,
991
+ validateArtifactRuntimeInstallationManifest,
992
+ validateCompleteArtifactRuntimeReleaseManifest,
993
+ locateArtifactRuntimeDependencies,
994
+ loadArtifactKernelRuntime,
995
+ ArtifactKernelRuntime,
996
+ ArtifactCollaborationSession,
997
+ ArtifactDocumentSession,
998
+ ArtifactPresentationSession,
999
+ ArtifactTextLayoutSession,
1000
+ encodeArtifactReplicaNamespace
1001
+ };
1002
+ //# sourceMappingURL=chunk-N2IHNWBS.js.map