@docs-sdk-dev/reader 0.0.0-stage → 0.4.0-next.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 (108) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -2
  3. package/dist/annotation-projection.d.ts +35 -0
  4. package/dist/annotation-projection.js +78 -0
  5. package/dist/annotation-projection.js.map +1 -0
  6. package/dist/artifacts.d.ts +19 -0
  7. package/dist/artifacts.js +33 -0
  8. package/dist/artifacts.js.map +1 -0
  9. package/dist/ask.d.ts +41 -0
  10. package/dist/ask.js +89 -0
  11. package/dist/ask.js.map +1 -0
  12. package/dist/collection-view.d.ts +190 -0
  13. package/dist/collection-view.js +170 -0
  14. package/dist/collection-view.js.map +1 -0
  15. package/dist/composition.d.ts +199 -0
  16. package/dist/composition.js +473 -0
  17. package/dist/composition.js.map +1 -0
  18. package/dist/condition.d.ts +17 -0
  19. package/dist/condition.js +61 -0
  20. package/dist/condition.js.map +1 -0
  21. package/dist/content-schema.d.ts +182 -0
  22. package/dist/content-schema.js +288 -0
  23. package/dist/content-schema.js.map +1 -0
  24. package/dist/context-search.d.ts +168 -0
  25. package/dist/context-search.js +73 -0
  26. package/dist/context-search.js.map +1 -0
  27. package/dist/context-store.d.ts +93 -0
  28. package/dist/context-store.js +438 -0
  29. package/dist/context-store.js.map +1 -0
  30. package/dist/dimension-runtime.d.ts +203 -0
  31. package/dist/dimension-runtime.js +737 -0
  32. package/dist/dimension-runtime.js.map +1 -0
  33. package/dist/dimensions.d.ts +84 -0
  34. package/dist/dimensions.js +136 -0
  35. package/dist/dimensions.js.map +1 -0
  36. package/dist/directory-navigation.d.ts +60 -0
  37. package/dist/directory-navigation.js +41 -0
  38. package/dist/directory-navigation.js.map +1 -0
  39. package/dist/directory-sections.d.ts +9 -0
  40. package/dist/directory-sections.js +76 -0
  41. package/dist/directory-sections.js.map +1 -0
  42. package/dist/document-reader.d.ts +1017 -0
  43. package/dist/document-reader.js +396 -0
  44. package/dist/document-reader.js.map +1 -0
  45. package/dist/document-selection.d.ts +412 -0
  46. package/dist/document-selection.js +45 -0
  47. package/dist/document-selection.js.map +1 -0
  48. package/dist/evidence.d.ts +102 -0
  49. package/dist/evidence.js +104 -0
  50. package/dist/evidence.js.map +1 -0
  51. package/dist/index.d.ts +19 -0
  52. package/dist/index.js +23 -0
  53. package/dist/model.d.ts +89 -0
  54. package/dist/model.js +31 -0
  55. package/dist/model.js.map +1 -0
  56. package/dist/module.d.ts +657 -0
  57. package/dist/module.js +199 -0
  58. package/dist/module.js.map +1 -0
  59. package/dist/navigation-view.d.ts +33 -0
  60. package/dist/navigation-view.js +68 -0
  61. package/dist/navigation-view.js.map +1 -0
  62. package/dist/node.d.ts +2004 -0
  63. package/dist/node.js +210 -0
  64. package/dist/node.js.map +1 -0
  65. package/dist/open-docs.d.ts +1396 -0
  66. package/dist/open-docs.js +198 -0
  67. package/dist/open-docs.js.map +1 -0
  68. package/dist/outline.d.ts +97 -0
  69. package/dist/outline.js +171 -0
  70. package/dist/outline.js.map +1 -0
  71. package/dist/persistence.d.ts +82 -0
  72. package/dist/persistence.js +377 -0
  73. package/dist/persistence.js.map +1 -0
  74. package/dist/projection-catalog.d.ts +23 -0
  75. package/dist/projection-catalog.js +45 -0
  76. package/dist/projection-catalog.js.map +1 -0
  77. package/dist/publication.d.ts +59 -0
  78. package/dist/publication.js +11 -0
  79. package/dist/publication.js.map +1 -0
  80. package/dist/reader.d.ts +236 -0
  81. package/dist/reader.js +400 -0
  82. package/dist/reader.js.map +1 -0
  83. package/dist/references.d.ts +54 -0
  84. package/dist/references.js +70 -0
  85. package/dist/references.js.map +1 -0
  86. package/dist/retrieval.d.ts +82 -0
  87. package/dist/retrieval.js +135 -0
  88. package/dist/retrieval.js.map +1 -0
  89. package/dist/search-view.d.ts +11 -0
  90. package/dist/search-view.js +30 -0
  91. package/dist/search-view.js.map +1 -0
  92. package/dist/search.d.ts +95 -0
  93. package/dist/search.js +234 -0
  94. package/dist/search.js.map +1 -0
  95. package/dist/semantic.d.ts +177 -0
  96. package/dist/semantic.js +104 -0
  97. package/dist/semantic.js.map +1 -0
  98. package/dist/skills.d.ts +21 -0
  99. package/dist/skills.js +42 -0
  100. package/dist/skills.js.map +1 -0
  101. package/docs/index.md +10 -0
  102. package/docs/sdk/composition.md +72 -0
  103. package/docs/sdk/reader-storage.md +70 -0
  104. package/docs/sdk/reader.md +99 -0
  105. package/docs/zh-CN/sdk/composition.md +72 -0
  106. package/docs/zh-CN/sdk/reader-storage.md +70 -0
  107. package/docs/zh-CN/sdk/reader.md +99 -0
  108. package/package.json +69 -4
@@ -0,0 +1,396 @@
1
+ import { selectContextProjection } from "./condition.js";
2
+ import { dimensionValueIds, localeDimension } from "./dimensions.js";
3
+ import { DocsError } from "./model.js";
4
+ import { decodeArtifactInventory } from "./artifacts.js";
5
+ import { localizedTitles } from "./directory-navigation.js";
6
+ import { indexDirectory, selectDirectory } from "./directory-sections.js";
7
+ import { filterNavigationView, navigationPath, selectNavigationView } from "./navigation-view.js";
8
+ import { outlineViews, publishedOutline } from "./outline.js";
9
+ import { createDimensionInspector, inspectPinnedDimensions, resolveDocumentContext } from "./dimension-runtime.js";
10
+
11
+ // src/document-reader.ts
12
+ function projectReadingChoices(declarations) {
13
+ return Object.fromEntries((declarations ?? []).filter(({ owner }) => owner.kind === "project").flatMap(({ definitions }) => Object.entries(definitions).flatMap(([name, axis]) => axis.kind === "preference" && axis.values ? [[name, {
14
+ values: dimensionValueIds(axis.values),
15
+ default: axis.default
16
+ }]] : [])));
17
+ }
18
+ function readingContext(policy = {}, requested = {}, edition = {}) {
19
+ const values = {
20
+ ...requested,
21
+ ...edition
22
+ };
23
+ for (const [name, choice] of Object.entries(policy)) {
24
+ if (Object.hasOwn(edition, name)) continue;
25
+ if (Object.hasOwn(requested, name) && !choice.values.includes(requested[name])) throw new DocsError("DOCS_CONTEXT_UNAVAILABLE", "Unsupported " + name + " choice: " + requested[name], { field: name });
26
+ if (!Object.hasOwn(requested, name) && choice.default !== void 0) Object.defineProperty(values, name, {
27
+ value: choice.default,
28
+ enumerable: true,
29
+ writable: true,
30
+ configurable: true
31
+ });
32
+ }
33
+ return values;
34
+ }
35
+ /** Canonical route dimensions own the edition. The public pm preference selects installation examples on other pages. */
36
+ function sharedPageContext(dimensions, manager, parameters, policy) {
37
+ const inherited = [];
38
+ for (const [key, value] of parameters ?? []) if (/^ctx\.[a-zA-Z][a-zA-Z0-9._-]*$/.test(key) && value && key !== "ctx.packageManager") inherited.push([key.slice(4), value]);
39
+ const context = Object.fromEntries(inherited);
40
+ if (manager && (policy && Object.hasOwn(policy, "packageManager") || [
41
+ "npm",
42
+ "pnpm",
43
+ "yarn",
44
+ "bun"
45
+ ].includes(manager))) context.packageManager = manager;
46
+ return readingContext(policy, context, dimensions);
47
+ }
48
+ function documentKey(identity) {
49
+ return JSON.stringify([
50
+ identity.scope,
51
+ identity.id,
52
+ Object.entries(identity.dimensions ?? {}).sort(([left], [right]) => left < right ? -1 : left > right ? 1 : 0)
53
+ ]);
54
+ }
55
+ function createReader(manifest, readText) {
56
+ return buildReader(manifest, readText, createDimensionInspector);
57
+ }
58
+ /** Use the applicable Dimension Context for a semantic entity request. */
59
+ function factContext(reader, id, requested = {}) {
60
+ if (id.includes("@")) return requested;
61
+ const subject = /^(?:document|section):([^#]+)/.exec(id)?.[1] ?? "";
62
+ const boundary = subject.lastIndexOf("/");
63
+ const identity = {
64
+ scope: subject.slice(0, Math.max(0, boundary)),
65
+ id: subject.slice(boundary + 1)
66
+ };
67
+ const { definitions, effective } = reader.context(identity, { requested });
68
+ if (!definitions.some((axis) => axis.when || axis.defaults || axis.valueConditions)) return requested;
69
+ const selection = {
70
+ ...requested,
71
+ ...effective
72
+ };
73
+ for (const { name } of definitions) if (!Object.hasOwn(effective, name)) delete selection[name];
74
+ return selection;
75
+ }
76
+ function buildReader(manifest, readText, inspectDimensions) {
77
+ const documents = new Map(manifest.documents.map((document) => [document.key, document]));
78
+ const routes = new Map(manifest.documents.map((document) => [document.route, document]));
79
+ const redirects = new Map(manifest.redirects?.map((redirect) => [redirect.from, redirect.to]));
80
+ const localeKey = localeDimension(manifest.dimensionPolicy);
81
+ let dimensions;
82
+ const runtime = () => dimensions ??= inspectDimensions(manifest);
83
+ let directory;
84
+ function automaticView(page) {
85
+ directory ??= indexDirectory(manifest.documents);
86
+ const context = page.identity.dimensions;
87
+ const labels = localizedTitles(manifest.navigationTitles, context[localeKey], manifest.dimensionPolicy?.defaultLocale);
88
+ function group(node) {
89
+ return {
90
+ id: "scope:" + node.scope,
91
+ title: node.label,
92
+ kind: "group",
93
+ children: [...node.items.map(({ entity, route, title }) => {
94
+ const { key, availability } = routes.get(route);
95
+ return {
96
+ id: entity,
97
+ title,
98
+ route,
99
+ kind: "document",
100
+ document: key,
101
+ ...availability && { availability }
102
+ };
103
+ }), ...node.children.map(group)]
104
+ };
105
+ }
106
+ return {
107
+ name: "sidebar",
108
+ context,
109
+ nodes: selectDirectory(directory, page, labels).sections.map(group),
110
+ reads: []
111
+ };
112
+ }
113
+ const lookup = (identity) => documents.get(documentKey(identity)) ?? null;
114
+ function projection(identity, requested) {
115
+ if (requested === void 0) return lookup(identity);
116
+ const { document, effective, reasons } = runtime().inspect(identity, {
117
+ requested,
118
+ edition: identity.dimensions
119
+ });
120
+ if (!document || reasons.some(({ key, reason }) => reason === "value" && Object.hasOwn(requested, key) && (Object.hasOwn(document.contextDefaults ?? {}, key) || document.contextVariants?.some(({ context }) => Object.hasOwn(context, key))))) return null;
121
+ const alternate = selectContextProjection(document.contextVariants ?? [], effective, document.contextDefaults);
122
+ if (alternate) return {
123
+ ...document,
124
+ ...alternate
125
+ };
126
+ return document;
127
+ }
128
+ const resolveCompatible = (identity) => resolveDocumentContext(runtime().registry.editions(identity), identity.dimensions ?? {});
129
+ function resolveEdition(identity) {
130
+ if (!manifest.dimensionDeclarations?.length && !manifest.dimensionPolicy) return resolveCompatible(identity);
131
+ const state = runtime().inspect(identity, { requested: identity.dimensions });
132
+ const { status, requested, effective, resolved, reasons } = state;
133
+ const resolution = {
134
+ status,
135
+ requested,
136
+ effective,
137
+ resolved,
138
+ reasons
139
+ };
140
+ if (state.document) return {
141
+ status: "exact",
142
+ value: state.document,
143
+ resolution
144
+ };
145
+ if (status === "ambiguous") return {
146
+ status,
147
+ candidates: [...state.candidates],
148
+ resolution
149
+ };
150
+ if (status === "not-found") return {
151
+ status,
152
+ resolution
153
+ };
154
+ return {
155
+ status: "unsupported-context",
156
+ available: state.availability.map((page) => page.dimensions),
157
+ resolution
158
+ };
159
+ }
160
+ function resolve(identity) {
161
+ const exact = lookup(identity);
162
+ if (exact) return {
163
+ status: "exact",
164
+ value: exact
165
+ };
166
+ const available = runtime().registry.editions(identity);
167
+ return available.length ? {
168
+ status: "unsupported-context",
169
+ available: available.map((item) => item.identity.dimensions)
170
+ } : { status: "not-found" };
171
+ }
172
+ return {
173
+ lookup,
174
+ /** Select a portable projection for an explicit reading Context, or open an exact edition. */
175
+ projection,
176
+ resolveCompatible,
177
+ resolveEdition,
178
+ resolve,
179
+ context(identity, request = {}) {
180
+ return runtime().inspect(identity, request);
181
+ },
182
+ navigation(identity, view = "sidebar", placement, requested) {
183
+ const page = lookup(identity);
184
+ if (!page) return null;
185
+ const model = selectNavigationView(manifest.navigationViews ?? [], view, page.identity.dimensions) ?? (view === "sidebar" ? automaticView(page) : void 0);
186
+ if (!model) return;
187
+ const selected = filterNavigationView(model, runtime().inspect(identity, {
188
+ edition: page.identity.dimensions,
189
+ requested
190
+ }).effective, (node) => {
191
+ const target = node.route && routes.get(node.route.split("#")[0]);
192
+ return !target || runtime().includesEdition(target, requested ?? page.identity.dimensions);
193
+ });
194
+ return {
195
+ view: selected,
196
+ ...navigationPath(selected, page.key, placement)
197
+ };
198
+ },
199
+ outline(identity, view, requested) {
200
+ const page = projection(identity, requested);
201
+ if (!page) return null;
202
+ const policies = manifest.outlineViews;
203
+ if (typeof view === "string") {
204
+ const named = view === "compact" || view === "full" ? outlineViews[view] : policies && Object.hasOwn(policies, view) ? policies[view] : void 0;
205
+ return named ? publishedOutline(page, named) : null;
206
+ }
207
+ return publishedOutline(page, view ?? (page.outlineView === void 0 ? manifest.outlineView : page.outlineView) ?? void 0);
208
+ },
209
+ /** Resolve an HTTP pathname using the publication's canonical routes and declared aliases. */
210
+ route(pathname) {
211
+ const prefix = manifest.basePath ?? "";
212
+ if (prefix && pathname === prefix) return {
213
+ status: "redirect",
214
+ to: prefix + "/"
215
+ };
216
+ if (!pathname.startsWith(prefix + "/")) return { status: "not-found" };
217
+ const local = pathname.slice(prefix.length);
218
+ const path = local.endsWith("/") ? local : local + "/";
219
+ const document = routes.get(path);
220
+ if (document) return local === path ? {
221
+ status: "document",
222
+ document
223
+ } : {
224
+ status: "redirect",
225
+ to: prefix + path
226
+ };
227
+ const to = redirects.get(path);
228
+ if (to === void 0) return { status: "not-found" };
229
+ return {
230
+ status: "redirect",
231
+ to: to.startsWith("/") ? prefix + to : to
232
+ };
233
+ },
234
+ /**
235
+ * Read a document edition, section or rendered anchor. A heading reads its subsection and an independent
236
+ * semantic anchor reads its projected block.
237
+ */
238
+ async read(identity, sectionId, headingId, requested) {
239
+ const document = projection(identity, requested);
240
+ const target = sectionId === void 0 ? document : document?.sections.find((section) => section.id === sectionId);
241
+ if (!target) return null;
242
+ if (headingId === void 0 || "id" in target && headingId === target.id) return {
243
+ ...target,
244
+ markdown: await readText(target.markdown)
245
+ };
246
+ if (!("id" in target)) return null;
247
+ const semantic = target.outline?.find((item) => item.position && item.anchor === headingId);
248
+ const semanticRange = semantic && target.outlineRanges?.[semantic.anchor];
249
+ const index = target.headings?.findIndex((heading) => heading.id === headingId) ?? -1;
250
+ if (index === -1 && !semanticRange) return null;
251
+ const heading = index === -1 ? {
252
+ id: semantic.anchor,
253
+ text: semantic.text,
254
+ depth: semantic.position.level
255
+ } : target.headings[index];
256
+ const chunk = target.headingFiles?.[index];
257
+ if (chunk) return {
258
+ ...target,
259
+ heading,
260
+ markdown: await readText(chunk)
261
+ };
262
+ if (!semanticRange && !target.headingRanges) throw new DocsError("DOCS_HEADING_INDEX_MISSING", "Rebuild the publication to index headings.", { source: target.markdown });
263
+ const markdown = await readText(target.markdown);
264
+ const range = semanticRange ?? target.headingRanges?.[index];
265
+ if (!range || !Number.isSafeInteger(range[0]) || !Number.isSafeInteger(range[1]) || range[0] < 0 || range[0] >= range[1] || range[1] > markdown.length) return null;
266
+ const text = markdown.slice(range[0], range[1]).trim() + "\n";
267
+ return {
268
+ ...target,
269
+ heading,
270
+ markdown: text
271
+ };
272
+ }
273
+ };
274
+ }
275
+ async function pinnedArtifacts(inventoryRevision, host) {
276
+ const invalid = (source, message) => new DocsError("DOCS_ARTIFACT_INTEGRITY", message, { source });
277
+ const bytes = await host.readBytes("artifacts.json");
278
+ if (await host.sha256(bytes) !== inventoryRevision) throw invalid("artifacts.json", "Inventory revision differs from the expected SHA-256.");
279
+ const inventory = decodeArtifactInventory(bytes);
280
+ function artifact(path) {
281
+ if (!Object.hasOwn(inventory.files, path)) throw invalid(path, "Artifact is absent from the pinned publication.");
282
+ return { ...inventory.files[path] };
283
+ }
284
+ async function readBytes(path) {
285
+ const expected = artifact(path);
286
+ const content = await host.readBytes(path);
287
+ if (content.byteLength !== expected.bytes || await host.sha256(content) !== expected.sha256) throw invalid(path, "Artifact bytes differ from the pinned publication.");
288
+ return content;
289
+ }
290
+ return {
291
+ files: inventory.files,
292
+ inventoryBytes: bytes,
293
+ buildRevision: inventory.buildRevision,
294
+ readBytes,
295
+ artifact
296
+ };
297
+ }
298
+ /** Yield the manifest, the remaining verified files, then the exact inventory bytes as a receipt for the complete copy. */
299
+ async function* readPublicationArtifacts(inventoryRevision, host) {
300
+ const artifacts = await pinnedArtifacts(inventoryRevision, host);
301
+ const manifest = await artifacts.readBytes("manifest.json");
302
+ pinnedManifest(manifest, artifacts.buildRevision);
303
+ yield {
304
+ path: "manifest.json",
305
+ bytes: manifest
306
+ };
307
+ for (const path of Object.keys(artifacts.files)) if (path !== "manifest.json") yield {
308
+ path,
309
+ bytes: await artifacts.readBytes(path)
310
+ };
311
+ yield {
312
+ path: "artifacts.json",
313
+ bytes: artifacts.inventoryBytes
314
+ };
315
+ }
316
+ const decodeText = (bytes) => new TextDecoder("utf-8", { fatal: true }).decode(bytes);
317
+ function pinnedManifest(bytes, buildRevision) {
318
+ const manifest = JSON.parse(decodeText(bytes));
319
+ if (manifest?.buildRevision !== buildRevision) throw new DocsError("DOCS_ARTIFACT_INTEGRITY", "Manifest and inventory name different builds.", { source: "manifest.json" });
320
+ return manifest;
321
+ }
322
+ /** Open a publication by its externally retained SHA-256, verifying only the files a caller reads. */
323
+ async function openPinnedReader(inventoryRevision, host) {
324
+ const { readBytes, buildRevision, artifact, files } = await pinnedArtifacts(inventoryRevision, host);
325
+ const pendingText = /* @__PURE__ */ new Map();
326
+ function readText(path) {
327
+ const pending = pendingText.get(path);
328
+ if (pending) return pending;
329
+ const read = readBytes(path).then(decodeText).finally(() => pendingText.delete(path));
330
+ pendingText.set(path, read);
331
+ return read;
332
+ }
333
+ const manifest = pinnedManifest(await readBytes("manifest.json"), buildRevision);
334
+ const catalog = manifest.projections;
335
+ if (catalog) {
336
+ const invalid = () => new DocsError("DOCS_ARTIFACT_INTEGRITY", "Projection catalog refers to unavailable capabilities or files.", { source: "manifest.json" });
337
+ if (catalog.schemaVersion !== 1 || !Array.isArray(catalog.targets)) throw invalid();
338
+ const targets = /* @__PURE__ */ new Set();
339
+ for (const entry of catalog.targets) {
340
+ if (!entry || typeof entry.target !== "string" || targets.has(entry.target) || !Array.isArray(entry.requiredManifestFields)) throw invalid();
341
+ targets.add(entry.target);
342
+ for (const field of entry.requiredManifestFields) if (typeof field !== "string" || !Object.hasOwn(manifest, field)) throw invalid();
343
+ }
344
+ if (targets.has("search") && (!manifest.search || !Object.hasOwn(files, manifest.search.path))) throw invalid();
345
+ if (catalog.deliveries !== void 0 && !Array.isArray(catalog.deliveries)) throw invalid();
346
+ for (const delivery of catalog.deliveries ?? []) {
347
+ if (!delivery || typeof delivery.id !== "string" || typeof delivery.version !== "string" || !Array.isArray(delivery.files)) throw invalid();
348
+ for (const path of delivery.files) if (typeof path !== "string" || !path.startsWith("delivery/" + delivery.id + "/") || !Object.hasOwn(files, path)) throw invalid();
349
+ if (delivery.requires !== void 0 && !Array.isArray(delivery.requires)) throw invalid();
350
+ for (const target of delivery.requires ?? []) if (!targets.has(target)) throw invalid();
351
+ }
352
+ }
353
+ const reader = buildReader(manifest, readText, inspectPinnedDimensions);
354
+ return {
355
+ buildRevision,
356
+ manifest,
357
+ reader,
358
+ readBytes,
359
+ readText,
360
+ artifact,
361
+ projectionCatalog() {
362
+ return {
363
+ buildRevision,
364
+ inventoryRevision,
365
+ catalog: catalog ? structuredClone(catalog) : null
366
+ };
367
+ },
368
+ /** Discover the emitted projections of an exact edition from the verified inventory. */
369
+ documentProjections(identity) {
370
+ const document = reader.lookup(identity);
371
+ if (!document) return null;
372
+ const targets = [{
373
+ target: "web",
374
+ path: document.route.slice(1) + "index.html",
375
+ href: (manifest.basePath ?? "") + document.route
376
+ }, {
377
+ target: "markdown",
378
+ path: document.markdown
379
+ }].filter((item) => Object.hasOwn(files, item.path)).map((item) => ({
380
+ ...item,
381
+ ...artifact(item.path),
382
+ losses: (document.losses ?? []).filter((loss) => loss.target === item.target).map((loss) => ({ ...loss }))
383
+ }));
384
+ return {
385
+ identity: document.identity,
386
+ buildRevision,
387
+ inventoryRevision,
388
+ provenance: document.provenance,
389
+ targets
390
+ };
391
+ }
392
+ };
393
+ }
394
+
395
+ export { createReader, documentKey, factContext, openPinnedReader, projectReadingChoices, readPublicationArtifacts, readingContext, resolveDocumentContext, sharedPageContext };
396
+ //# sourceMappingURL=document-reader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document-reader.js","names":[],"sources":["../src/document-reader.ts"],"sourcesContent":["import { selectContextProjection } from \"./condition.js\"\nimport { localeDimension } from \"./dimensions.js\"\nimport {\n DocsError,\n type Identity,\n type MarkdownHeadingIndexes,\n type ProjectionLoss,\n type Provenance,\n} from \"./model.js\"\nimport type { JsonValue } from \"./content-schema.js\"\nimport type { PublicationProjectionCatalog } from \"./projection-catalog.js\"\nimport { decodeArtifactInventory } from \"./artifacts.js\"\nimport type { SourceRole, SourceReceipt } from \"./publication.js\"\nimport { type Context, type Resolution, type SemanticPointer } from \"./semantic.js\"\n\nimport { localizedTitles, type LocalizedText, type NavigationNode } from \"./directory-navigation.js\"\nimport { indexDirectory, selectDirectory } from \"./directory-sections.js\"\nimport {\n navigationPath,\n selectNavigationView,\n filterNavigationView,\n type PublishedNavigation,\n type NavigationPlacement,\n} from \"./navigation-view.js\"\nimport {\n publishedOutline,\n outlineViews,\n type OutlineContribution,\n type OutlineProjection,\n type OutlineView,\n} from \"./outline.js\"\n\nimport {\n dimensionValueIds,\n type DimensionDefinitions,\n type PreferenceChoices,\n} from \"./dimensions.js\"\nexport { type PreferenceChoices } from \"./dimensions.js\"\n\nexport function projectReadingChoices(\n declarations: Manifest[\"dimensionDeclarations\"],\n): PreferenceChoices {\n return Object.fromEntries(\n (declarations ?? [])\n .filter(({ owner }) => owner.kind === \"project\")\n .flatMap(({ definitions }) =>\n Object.entries(definitions).flatMap(([name, axis]) =>\n axis.kind === \"preference\" && axis.values\n ? [[name, { values: dimensionValueIds(axis.values), default: axis.default }]]\n : [],\n ),\n ),\n )\n}\n\nexport function readingContext(\n policy: PreferenceChoices = {},\n requested: Context = {},\n edition: Context = {},\n): Context {\n const values = { ...requested, ...edition }\n for (const [name, choice] of Object.entries(policy)) {\n if (Object.hasOwn(edition, name)) continue\n if (Object.hasOwn(requested, name) && !choice.values.includes(requested[name]!))\n throw new DocsError(\n \"DOCS_CONTEXT_UNAVAILABLE\",\n \"Unsupported \" + name + \" choice: \" + requested[name],\n { field: name },\n )\n if (!Object.hasOwn(requested, name) && choice.default !== undefined)\n Object.defineProperty(values, name, {\n value: choice.default,\n enumerable: true,\n writable: true,\n configurable: true,\n })\n }\n return values\n}\n\n/** Canonical route dimensions own the edition. The public pm preference selects installation examples on other pages. */\nexport function sharedPageContext(\n dimensions: Context,\n manager: string | null,\n parameters?: Iterable<readonly [string, string]>,\n policy?: PreferenceChoices,\n): Context {\n const inherited: [string, string][] = []\n for (const [key, value] of parameters ?? []) {\n if (/^ctx\\.[a-zA-Z][a-zA-Z0-9._-]*$/.test(key) && value && key !== \"ctx.packageManager\")\n inherited.push([key.slice(4), value])\n }\n const context: Context = Object.fromEntries(inherited)\n if (\n manager &&\n ((policy && Object.hasOwn(policy, \"packageManager\")) ||\n [\"npm\", \"pnpm\", \"yarn\", \"bun\"].includes(manager))\n )\n context.packageManager = manager\n return readingContext(policy, context, dimensions)\n}\n\nimport {\n createDimensionInspector,\n inspectPinnedDimensions,\n resolveDocumentContext,\n type DimensionDeclaration,\n type PublishedDimensionPolicy,\n type DimensionRequest,\n type DimensionInspection,\n} from \"./dimension-runtime.js\"\nexport { resolveDocumentContext } from \"./dimension-runtime.js\"\ntype ManifestSection = {\n id: string\n title?: string\n /** UTF-16 offset of this section in the complete published Markdown. */\n documentOffset?: number\n markdown: string\n provenance: Provenance[]\n /** Added in M6. Headings inside the section with their anchors, for outlines and links. */\n outline?: OutlineContribution[]\n headings?: { id: string; text: string; depth: number }[]\n /** Half-open UTF-16 offsets into this section’s published Markdown, in rendered-heading order. */\n headingRanges?: readonly (readonly [number, number])[]\n /** Exact Markdown ranges for independent semantic outline anchors. */\n outlineRanges?: Record<string, readonly [number, number]>\n /** A separately inventoried artifact for a short heading in a large section. */\n headingFiles?: Record<number, string>\n /** Present when the Markdown heading order differs from the rendered anchors. */\n headingIndexes?: MarkdownHeadingIndexes\n}\n\nexport interface Manifest {\n /** Discovery artifacts for the public documentation interface. */\n agent?: { indexes: readonly string[] }\n /** Stable project namespace for preference records, independent of publication URLs. */\n persistenceId?: string\n /** Confirms that this host owns the unqualified Context storage keys on its origin. */\n dimensionDeclarations?: readonly DimensionDeclaration[]\n dimensionPolicy?: PublishedDimensionPolicy\n dimensionPlacements?: Readonly<Record<string, Context>>\n dimensionGraph?: readonly import(\"./dimension-runtime.js\").RegisteredDimension[]\n navigationTitles?: Record<string, LocalizedText>\n navigationViews?: PublishedNavigation[]\n outlineView?: OutlineView\n outlineViews?: Readonly<Record<string, OutlineView>>\n extensions?: readonly {\n id: string\n version: string\n dependencies: readonly string[]\n requires?: Readonly<Record<string, string>>\n components?: readonly string[]\n hooks?: readonly string[]\n contentTypes: readonly {\n id: string\n name: string\n version: number\n kind: string\n mdx?: string\n schema?: unknown\n outputSchema?: unknown\n }[]\n entityTypes: readonly {\n name: string\n version: number\n schema?: unknown\n outputSchema?: unknown\n }[]\n relations: readonly {\n name: string\n from: string\n to: string\n context: string\n impact: string\n cardinality?: string\n ordered?: boolean\n }[]\n dimensions?: DimensionDefinitions\n operations?: readonly { id: string; version: number; effect: string }[]\n collections: readonly string[]\n templates: readonly string[]\n outlines?: readonly string[]\n contracts: readonly string[]\n }[]\n /** Deployment URL prefix. Artifact paths and document routes remain local to this publication. */\n basePath?: string\n schemaVersion: 1\n buildRevision: string\n /** Declared by newer static publishers. Older publications have no delivery catalog. */\n projections?: PublicationProjectionCatalog\n documents: {\n key: string\n identity: Identity & { dimensions: Record<string, string> }\n route: string\n title: string\n availability?: Context\n navigationHidden?: boolean\n outlineView?: OutlineView | null\n description?: string\n /** Validated user-defined metadata for structured consumers. */\n meta?: Record<string, JsonValue>\n /** Author-selected custom metadata fields for the article header. */\n showMetadata?: readonly string[]\n /** Layout instructions consumed by Web hosts independently of custom metadata. */\n presentation?: {\n layout?: string | false\n actions?: readonly { text: string; href: string }[]\n rendererProfile?: string\n }\n origin?: {\n kind: \"generated\" | \"overlay\" | \"authored\"\n collection: string\n source: string\n upstreamRevision: string\n authored?: string\n }\n mode: \"template\" | \"replacement\" | \"markdown\"\n template?: { id: string; revision: string }\n provenance: Provenance[]\n markdown: string\n contextDefaults?: Context\n contextVariants?: { context: Context; markdown: string; sections: ManifestSection[] }[]\n sections: ManifestSection[]\n\n /** Added in M5. What each target could not express, per section. Absent when every target is complete. */\n losses?: (ProjectionLoss & { section: string })[]\n }[]\n sources?: readonly SourceReceipt[]\n /** Added in M2. Absent in older builds; readers that ignore it keep working. */\n semantic?: SemanticPointer\n /**\n * Added in M3. The project snapshot the build was made from. `toolchain` is the lockfile revision; `roles` names\n * files whose change is attributed to the whole build rather than to entities.\n */\n snapshot?: {\n schemaVersion: 1\n revision: string\n sourceMapRevision?: string\n environmentRevision?: string\n presentationRevision?: string\n projectionInputs?: Record<string, string | null>\n toolchain?: string\n lockfiles?: Record<string, string>\n roles: Record<string, SourceRole>\n }\n /** Added in M3. Source path → dependent entity variants, for impact analysis. */\n dependencies?: { path: string; revision: string }\n /** Added in M4. Section-edition search index, ranked with BM25 by `createSearch`. */\n search?: { path: string; revision: string; entries: number }\n /** Added in M8. Old URLs and where they now live; each `from` has a static redirect page. */\n redirects?: { from: string; to: string }[]\n /** Added in M3. Documentation contract results for this build. */\n contracts?: {\n path: string\n configRevision?: string\n status: \"pass\" | \"fail\"\n errors: number\n warnings: number\n waived: number\n }\n}\n\ntype PublishedSection = Manifest[\"documents\"][number][\"sections\"][number]\n\n/** Published entry or section metadata with its resolved Markdown and optional heading excerpt. */\nexport type PublishedMarkdownRead =\n | Manifest[\"documents\"][number]\n | PublishedSection\n | (PublishedSection & { heading: NonNullable<PublishedSection[\"headings\"]>[number] })\n\nexport function documentKey(identity: Identity) {\n return JSON.stringify([\n identity.scope,\n identity.id,\n Object.entries(identity.dimensions ?? {}).sort(([left], [right]) =>\n left < right ? -1 : left > right ? 1 : 0,\n ),\n ])\n}\n\nexport function createReader(manifest: Manifest, readText: (path: string) => Promise<string>) {\n return buildReader(manifest, readText, createDimensionInspector)\n}\n\n/** Use the applicable Dimension Context for a semantic entity request. */\nexport function factContext(\n reader: Pick<ReturnType<typeof createReader>, \"context\">,\n id: string,\n requested: Context = {},\n): Context {\n if (id.includes(\"@\")) return requested\n const subject = /^(?:document|section):([^#]+)/.exec(id)?.[1] ?? \"\"\n const boundary = subject.lastIndexOf(\"/\")\n const identity = {\n scope: subject.slice(0, Math.max(0, boundary)),\n id: subject.slice(boundary + 1),\n }\n const { definitions, effective } = reader.context(identity, { requested })\n if (!definitions.some((axis) => axis.when || axis.defaults || axis.valueConditions))\n return requested\n const selection = { ...requested, ...effective }\n for (const { name } of definitions) if (!Object.hasOwn(effective, name)) delete selection[name]\n return selection\n}\n\nfunction buildReader(\n manifest: Manifest,\n readText: (path: string) => Promise<string>,\n inspectDimensions: typeof inspectPinnedDimensions,\n) {\n const documents = new Map(manifest.documents.map((document) => [document.key, document]))\n const routes = new Map(manifest.documents.map((document) => [document.route, document]))\n const redirects = new Map(manifest.redirects?.map((redirect) => [redirect.from, redirect.to]))\n const localeKey = localeDimension(manifest.dimensionPolicy)\n let dimensions:\n ReturnType<typeof inspectPinnedDimensions<Manifest[\"documents\"][number]>> | undefined\n const runtime = () => (dimensions ??= inspectDimensions(manifest))\n let directory: ReturnType<typeof indexDirectory<Manifest[\"documents\"][number]>> | undefined\n function automaticView(page: Manifest[\"documents\"][number]): PublishedNavigation {\n directory ??= indexDirectory(manifest.documents)\n const context = page.identity.dimensions\n const labels = localizedTitles(\n manifest.navigationTitles,\n context[localeKey],\n manifest.dimensionPolicy?.defaultLocale,\n )\n function group(node: NavigationNode): NavigationPlacement {\n return {\n id: \"scope:\" + node.scope,\n title: node.label,\n kind: \"group\",\n children: [\n ...node.items.map(({ entity, route, title }) => {\n const { key, availability } = routes.get(route)!\n return {\n id: entity,\n title,\n route,\n kind: \"document\",\n document: key,\n ...(availability && { availability }),\n }\n }),\n ...node.children.map(group),\n ],\n }\n }\n return {\n name: \"sidebar\",\n context,\n nodes: selectDirectory(directory, page, labels).sections.map(group),\n reads: [],\n }\n }\n const lookup = (identity: Identity) => documents.get(documentKey(identity)) ?? null\n function projection(identity: Identity, requested?: Context) {\n if (requested === undefined) return lookup(identity)\n const { document, effective, reasons } = runtime().inspect(identity, {\n requested,\n edition: identity.dimensions,\n })\n if (\n !document ||\n reasons.some(\n ({ key, reason }) =>\n reason === \"value\" &&\n Object.hasOwn(requested, key) &&\n (Object.hasOwn(document.contextDefaults ?? {}, key) ||\n document.contextVariants?.some(({ context }) => Object.hasOwn(context, key))),\n )\n )\n return null\n const alternate = selectContextProjection(\n document.contextVariants ?? [],\n effective,\n document.contextDefaults,\n )\n if (alternate) return { ...document, ...alternate }\n return document\n }\n const resolveCompatible = (identity: Identity) =>\n resolveDocumentContext(runtime().registry.editions(identity), identity.dimensions ?? {})\n type Page = Manifest[\"documents\"][number]\n type Explanation = Pick<\n DimensionInspection<Page>,\n \"status\" | \"requested\" | \"effective\" | \"resolved\" | \"reasons\"\n >\n function resolveEdition(identity: Identity): Resolution<Page> & { resolution?: Explanation } {\n if (!manifest.dimensionDeclarations?.length && !manifest.dimensionPolicy)\n return resolveCompatible(identity)\n const state = runtime().inspect(identity, { requested: identity.dimensions })\n const { status, requested, effective, resolved, reasons } = state\n const resolution = { status, requested, effective, resolved, reasons }\n if (state.document) return { status: \"exact\", value: state.document, resolution }\n if (status === \"ambiguous\") return { status, candidates: [...state.candidates!], resolution }\n if (status === \"not-found\") return { status, resolution }\n return {\n status: \"unsupported-context\",\n available: state.availability.map((page) => page.dimensions),\n resolution,\n }\n }\n function resolve(identity: Identity): Resolution<Manifest[\"documents\"][number]> {\n const exact = lookup(identity)\n if (exact) return { status: \"exact\", value: exact }\n const available = runtime().registry.editions(identity)\n return available.length\n ? {\n status: \"unsupported-context\",\n available: available.map((item) => item.identity.dimensions),\n }\n : { status: \"not-found\" }\n }\n return {\n lookup,\n /** Select a portable projection for an explicit reading Context, or open an exact edition. */\n projection,\n resolveCompatible,\n resolveEdition,\n resolve,\n context(identity: Identity, request: DimensionRequest = {}) {\n return runtime().inspect(identity, request)\n },\n navigation(identity: Identity, view = \"sidebar\", placement?: string, requested?: Context) {\n const page = lookup(identity)\n if (!page) return null\n const model =\n selectNavigationView(manifest.navigationViews ?? [], view, page.identity.dimensions) ??\n (view === \"sidebar\" ? automaticView(page) : undefined)\n if (!model) return\n const selected = filterNavigationView(\n model,\n runtime().inspect(identity, { edition: page.identity.dimensions, requested }).effective,\n (node) => {\n const target = node.route && routes.get(node.route.split(\"#\")[0]!)\n return !target || runtime().includesEdition(target, requested ?? page.identity.dimensions)\n },\n )\n return { view: selected, ...navigationPath(selected, page.key, placement) }\n },\n outline(identity: Identity, view?: OutlineProjection | string, requested?: Context) {\n const page = projection(identity, requested)\n if (!page) return null\n const policies = manifest.outlineViews\n if (typeof view === \"string\") {\n const named =\n view === \"compact\" || view === \"full\"\n ? outlineViews[view]\n : policies && Object.hasOwn(policies, view)\n ? policies[view]\n : undefined\n return named ? publishedOutline(page, named) : null\n }\n return publishedOutline(\n page,\n view ??\n (page.outlineView === undefined ? manifest.outlineView : page.outlineView) ??\n undefined,\n )\n },\n /** Resolve an HTTP pathname using the publication's canonical routes and declared aliases. */\n route(pathname: string) {\n const prefix = manifest.basePath ?? \"\"\n if (prefix && pathname === prefix) return { status: \"redirect\" as const, to: prefix + \"/\" }\n if (!pathname.startsWith(prefix + \"/\")) return { status: \"not-found\" as const }\n const local = pathname.slice(prefix.length)\n const path = local.endsWith(\"/\") ? local : local + \"/\"\n const document = routes.get(path)\n if (document)\n return local === path\n ? { status: \"document\" as const, document }\n : { status: \"redirect\" as const, to: prefix + path }\n const to = redirects.get(path)\n if (to === undefined) return { status: \"not-found\" as const }\n return { status: \"redirect\" as const, to: to.startsWith(\"/\") ? prefix + to : to }\n },\n /**\n * Read a document edition, section or rendered anchor. A heading reads its subsection and an independent\n * semantic anchor reads its projected block.\n */\n async read(\n identity: Identity,\n sectionId?: string,\n headingId?: string,\n requested?: Context,\n ): Promise<PublishedMarkdownRead | null> {\n const document = projection(identity, requested)\n const target =\n sectionId === undefined\n ? document\n : document?.sections.find((section) => section.id === sectionId)\n if (!target) return null\n if (headingId === undefined || (\"id\" in target && headingId === target.id))\n return { ...target, markdown: await readText(target.markdown) }\n if (!(\"id\" in target)) return null\n const semantic = target.outline?.find((item) => item.position && item.anchor === headingId)\n const semanticRange = semantic && target.outlineRanges?.[semantic.anchor]\n const index = target.headings?.findIndex((heading) => heading.id === headingId) ?? -1\n if (index === -1 && !semanticRange) return null\n const heading =\n index === -1\n ? { id: semantic!.anchor, text: semantic!.text!, depth: semantic!.position!.level }\n : target.headings![index]!\n const chunk = target.headingFiles?.[index]\n if (chunk) return { ...target, heading, markdown: await readText(chunk) }\n if (!semanticRange && !target.headingRanges)\n throw new DocsError(\n \"DOCS_HEADING_INDEX_MISSING\",\n \"Rebuild the publication to index headings.\",\n { source: target.markdown },\n )\n const markdown = await readText(target.markdown)\n const range = semanticRange ?? target.headingRanges?.[index]\n if (\n !range ||\n !Number.isSafeInteger(range[0]) ||\n !Number.isSafeInteger(range[1]) ||\n range[0] < 0 ||\n range[0] >= range[1] ||\n range[1] > markdown.length\n )\n return null\n const text = markdown.slice(range[0], range[1]).trim() + \"\\n\"\n return { ...target, heading, markdown: text }\n },\n }\n}\n\nexport interface PublicationHost {\n readBytes(path: string): Promise<Uint8Array>\n sha256(bytes: Uint8Array): string | Promise<string>\n}\nasync function pinnedArtifacts(inventoryRevision: string, host: PublicationHost) {\n const invalid = (source: string, message: string) =>\n new DocsError(\"DOCS_ARTIFACT_INTEGRITY\", message, { source })\n const bytes = await host.readBytes(\"artifacts.json\")\n if ((await host.sha256(bytes)) !== inventoryRevision)\n throw invalid(\"artifacts.json\", \"Inventory revision differs from the expected SHA-256.\")\n const inventory = decodeArtifactInventory(bytes)\n function artifact(path: string) {\n if (!Object.hasOwn(inventory.files, path))\n throw invalid(path, \"Artifact is absent from the pinned publication.\")\n return { ...inventory.files[path]! }\n }\n async function readBytes(path: string) {\n const expected = artifact(path)\n const content = await host.readBytes(path)\n if (content.byteLength !== expected.bytes || (await host.sha256(content)) !== expected.sha256)\n throw invalid(path, \"Artifact bytes differ from the pinned publication.\")\n return content\n }\n return {\n files: inventory.files,\n inventoryBytes: bytes,\n buildRevision: inventory.buildRevision,\n readBytes,\n artifact,\n }\n}\n\n/** Yield the manifest, the remaining verified files, then the exact inventory bytes as a receipt for the complete copy. */\nexport async function* readPublicationArtifacts(inventoryRevision: string, host: PublicationHost) {\n const artifacts = await pinnedArtifacts(inventoryRevision, host)\n const manifest = await artifacts.readBytes(\"manifest.json\")\n pinnedManifest(manifest, artifacts.buildRevision)\n yield { path: \"manifest.json\", bytes: manifest }\n for (const path of Object.keys(artifacts.files)) {\n if (path !== \"manifest.json\") yield { path, bytes: await artifacts.readBytes(path) }\n }\n yield { path: \"artifacts.json\", bytes: artifacts.inventoryBytes }\n}\n\nconst decodeText = (bytes: Uint8Array) => new TextDecoder(\"utf-8\", { fatal: true }).decode(bytes)\n\nfunction pinnedManifest(bytes: Uint8Array, buildRevision: string): Manifest {\n const manifest = JSON.parse(decodeText(bytes))\n if (manifest?.buildRevision !== buildRevision)\n throw new DocsError(\n \"DOCS_ARTIFACT_INTEGRITY\",\n \"Manifest and inventory name different builds.\",\n { source: \"manifest.json\" },\n )\n return manifest\n}\n\n/** Open a publication by its externally retained SHA-256, verifying only the files a caller reads. */\nexport async function openPinnedReader(inventoryRevision: string, host: PublicationHost) {\n const { readBytes, buildRevision, artifact, files } = await pinnedArtifacts(\n inventoryRevision,\n host,\n )\n const pendingText = new Map<string, Promise<string>>()\n function readText(path: string) {\n const pending = pendingText.get(path)\n if (pending) return pending\n const read = readBytes(path)\n .then(decodeText)\n .finally(() => pendingText.delete(path))\n pendingText.set(path, read)\n return read\n }\n const manifest = pinnedManifest(await readBytes(\"manifest.json\"), buildRevision)\n const catalog: PublicationProjectionCatalog | undefined = manifest.projections\n if (catalog) {\n const invalid = () =>\n new DocsError(\n \"DOCS_ARTIFACT_INTEGRITY\",\n \"Projection catalog refers to unavailable capabilities or files.\",\n { source: \"manifest.json\" },\n )\n if (catalog.schemaVersion !== 1 || !Array.isArray(catalog.targets)) throw invalid()\n const targets = new Set<string>()\n for (const entry of catalog.targets) {\n if (\n !entry ||\n typeof entry.target !== \"string\" ||\n targets.has(entry.target) ||\n !Array.isArray(entry.requiredManifestFields)\n )\n throw invalid()\n targets.add(entry.target)\n for (const field of entry.requiredManifestFields)\n if (typeof field !== \"string\" || !Object.hasOwn(manifest, field)) throw invalid()\n }\n if (targets.has(\"search\") && (!manifest.search || !Object.hasOwn(files, manifest.search.path)))\n throw invalid()\n if (catalog.deliveries !== undefined && !Array.isArray(catalog.deliveries)) throw invalid()\n for (const delivery of catalog.deliveries ?? []) {\n if (\n !delivery ||\n typeof delivery.id !== \"string\" ||\n typeof delivery.version !== \"string\" ||\n !Array.isArray(delivery.files)\n )\n throw invalid()\n for (const path of delivery.files)\n if (\n typeof path !== \"string\" ||\n !path.startsWith(\"delivery/\" + delivery.id + \"/\") ||\n !Object.hasOwn(files, path)\n )\n throw invalid()\n if (delivery.requires !== undefined && !Array.isArray(delivery.requires)) throw invalid()\n for (const target of delivery.requires ?? []) if (!targets.has(target)) throw invalid()\n }\n }\n const reader = buildReader(manifest, readText, inspectPinnedDimensions)\n return {\n buildRevision,\n manifest,\n reader,\n readBytes,\n readText,\n artifact,\n projectionCatalog() {\n return {\n buildRevision,\n inventoryRevision,\n catalog: catalog ? structuredClone(catalog) : null,\n }\n },\n /** Discover the emitted projections of an exact edition from the verified inventory. */\n documentProjections(identity: Identity) {\n const document = reader.lookup(identity)\n if (!document) return null\n const candidates: { target: ProjectionLoss[\"target\"]; path: string; href?: string }[] = [\n {\n target: \"web\",\n path: document.route.slice(1) + \"index.html\",\n href: (manifest.basePath ?? \"\") + document.route,\n },\n { target: \"markdown\", path: document.markdown },\n ]\n const targets = candidates\n .filter((item) => Object.hasOwn(files, item.path))\n .map((item) => ({\n ...item,\n ...artifact(item.path),\n losses: (document.losses ?? [])\n .filter((loss) => loss.target === item.target)\n .map((loss) => ({ ...loss })),\n }))\n return {\n identity: document.identity,\n buildRevision,\n inventoryRevision,\n provenance: document.provenance,\n targets,\n }\n },\n }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