@jam-overture/loom 0.1.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.
- package/LICENSE +21 -0
- package/README.md +743 -0
- package/dist/catalogue.d.ts +70 -0
- package/dist/catalogue.js +88 -0
- package/dist/cli/args.d.ts +17 -0
- package/dist/cli/args.js +83 -0
- package/dist/cli/filesystem.d.ts +15 -0
- package/dist/cli/filesystem.js +31 -0
- package/dist/cli/index.d.ts +12 -0
- package/dist/cli/index.js +12 -0
- package/dist/cli/main.d.ts +3 -0
- package/dist/cli/main.js +30 -0
- package/dist/cli/namespace.d.ts +40 -0
- package/dist/cli/namespace.js +40 -0
- package/dist/cli/plan.d.ts +84 -0
- package/dist/cli/plan.js +113 -0
- package/dist/cli/run.d.ts +17 -0
- package/dist/cli/run.js +75 -0
- package/dist/cli/templates.d.ts +43 -0
- package/dist/cli/templates.js +134 -0
- package/dist/closed-set.d.ts +34 -0
- package/dist/closed-set.js +34 -0
- package/dist/data/adapter.d.ts +123 -0
- package/dist/data/adapter.js +91 -0
- package/dist/data/binding.d.ts +48 -0
- package/dist/data/binding.js +39 -0
- package/dist/data/catalogue.d.ts +26 -0
- package/dist/data/catalogue.js +6 -0
- package/dist/data/index.d.ts +14 -0
- package/dist/data/index.js +14 -0
- package/dist/data/plan.d.ts +58 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +91 -0
- package/dist/data/resolution.js +96 -0
- package/dist/data/resolve.d.ts +46 -0
- package/dist/data/resolve.js +37 -0
- package/dist/data/source.d.ts +40 -0
- package/dist/data/source.js +45 -0
- package/dist/deadline.d.ts +57 -0
- package/dist/deadline.js +78 -0
- package/dist/frame/catalogue.d.ts +24 -0
- package/dist/frame/catalogue.js +5 -0
- package/dist/frame/index.d.ts +12 -0
- package/dist/frame/index.js +12 -0
- package/dist/frame/origin.d.ts +87 -0
- package/dist/frame/origin.js +114 -0
- package/dist/frame/resolution.d.ts +85 -0
- package/dist/frame/resolution.js +79 -0
- package/dist/grammar.d.ts +26 -0
- package/dist/grammar.js +28 -0
- package/dist/ids.d.ts +57 -0
- package/dist/ids.js +104 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +26 -0
- package/dist/interactivity.d.ts +50 -0
- package/dist/interactivity.js +22 -0
- package/dist/interpretation/anthropic.d.ts +22 -0
- package/dist/interpretation/anthropic.js +76 -0
- package/dist/interpretation/client.d.ts +83 -0
- package/dist/interpretation/client.js +2 -0
- package/dist/interpretation/draft.d.ts +234 -0
- package/dist/interpretation/draft.js +84 -0
- package/dist/interpretation/index.d.ts +15 -0
- package/dist/interpretation/index.js +15 -0
- package/dist/interpretation/interpreter.d.ts +62 -0
- package/dist/interpretation/interpreter.js +151 -0
- package/dist/interpretation/materialize.d.ts +42 -0
- package/dist/interpretation/materialize.js +107 -0
- package/dist/interpretation/prompt.d.ts +229 -0
- package/dist/interpretation/prompt.js +285 -0
- package/dist/interpretation/render.d.ts +76 -0
- package/dist/interpretation/render.js +272 -0
- package/dist/interpretation/schema.d.ts +49 -0
- package/dist/interpretation/schema.js +131 -0
- package/dist/json.d.ts +35 -0
- package/dist/json.js +11 -0
- package/dist/paging.d.ts +60 -0
- package/dist/paging.js +49 -0
- package/dist/primitive-type.d.ts +32 -0
- package/dist/primitive-type.js +39 -0
- package/dist/render/addressing.d.ts +59 -0
- package/dist/render/addressing.js +60 -0
- package/dist/render/anchor.d.ts +105 -0
- package/dist/render/anchor.js +84 -0
- package/dist/render/behaviour-adjust.d.ts +62 -0
- package/dist/render/behaviour-adjust.js +78 -0
- package/dist/render/behaviour-copy.d.ts +53 -0
- package/dist/render/behaviour-copy.js +75 -0
- package/dist/render/behaviour-disclose.d.ts +74 -0
- package/dist/render/behaviour-disclose.js +77 -0
- package/dist/render/behaviour-present.d.ts +123 -0
- package/dist/render/behaviour-present.js +173 -0
- package/dist/render/behaviour.d.ts +243 -0
- package/dist/render/behaviour.js +284 -0
- package/dist/render/control.d.ts +81 -0
- package/dist/render/control.js +80 -0
- package/dist/render/decorative.d.ts +62 -0
- package/dist/render/decorative.js +2 -0
- package/dist/render/diagnostics.d.ts +260 -0
- package/dist/render/diagnostics.js +61 -0
- package/dist/render/disclosed.d.ts +37 -0
- package/dist/render/disclosed.js +37 -0
- package/dist/render/editable.d.ts +34 -0
- package/dist/render/editable.js +35 -0
- package/dist/render/frame.d.ts +42 -0
- package/dist/render/frame.js +31 -0
- package/dist/render/index.d.ts +35 -0
- package/dist/render/index.js +35 -0
- package/dist/render/inline-variables.d.ts +77 -0
- package/dist/render/inline-variables.js +220 -0
- package/dist/render/presented.d.ts +82 -0
- package/dist/render/presented.js +82 -0
- package/dist/render/primitive.d.ts +228 -0
- package/dist/render/primitive.js +36 -0
- package/dist/render/props.d.ts +48 -0
- package/dist/render/props.js +2 -0
- package/dist/render/reads.d.ts +73 -0
- package/dist/render/reads.js +45 -0
- package/dist/render/render.d.ts +164 -0
- package/dist/render/render.js +571 -0
- package/dist/render/request.d.ts +111 -0
- package/dist/render/request.js +60 -0
- package/dist/render/text.d.ts +91 -0
- package/dist/render/text.js +44 -0
- package/dist/render/theme.d.ts +61 -0
- package/dist/render/theme.js +52 -0
- package/dist/reserved-props.d.ts +35 -0
- package/dist/reserved-props.js +45 -0
- package/dist/result.d.ts +27 -0
- package/dist/result.js +30 -0
- package/dist/role.d.ts +71 -0
- package/dist/role.js +22 -0
- package/dist/runtime/analysis.d.ts +149 -0
- package/dist/runtime/analysis.js +187 -0
- package/dist/runtime/assessment.d.ts +35 -0
- package/dist/runtime/assessment.js +13 -0
- package/dist/runtime/disposition.d.ts +102 -0
- package/dist/runtime/disposition.js +59 -0
- package/dist/runtime/events.d.ts +187 -0
- package/dist/runtime/events.js +7 -0
- package/dist/runtime/gate.d.ts +43 -0
- package/dist/runtime/gate.js +169 -0
- package/dist/runtime/index.d.ts +27 -0
- package/dist/runtime/index.js +27 -0
- package/dist/runtime/intent.d.ts +60 -0
- package/dist/runtime/intent.js +36 -0
- package/dist/runtime/interpreter.d.ts +117 -0
- package/dist/runtime/interpreter.js +46 -0
- package/dist/runtime/inverse-interpreter.d.ts +90 -0
- package/dist/runtime/inverse-interpreter.js +56 -0
- package/dist/runtime/inverse.d.ts +87 -0
- package/dist/runtime/inverse.js +48 -0
- package/dist/runtime/narration.d.ts +24 -0
- package/dist/runtime/narration.js +36 -0
- package/dist/runtime/nesting.d.ts +31 -0
- package/dist/runtime/nesting.js +46 -0
- package/dist/runtime/pipeline.d.ts +124 -0
- package/dist/runtime/pipeline.js +178 -0
- package/dist/runtime/policy-fingerprint.d.ts +29 -0
- package/dist/runtime/policy-fingerprint.js +119 -0
- package/dist/runtime/policy-source.d.ts +42 -0
- package/dist/runtime/policy-source.js +8 -0
- package/dist/runtime/policy.d.ts +156 -0
- package/dist/runtime/policy.js +107 -0
- package/dist/runtime/proposal.d.ts +423 -0
- package/dist/runtime/proposal.js +109 -0
- package/dist/runtime/redirection.d.ts +53 -0
- package/dist/runtime/redirection.js +38 -0
- package/dist/runtime/repointing.d.ts +71 -0
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +36 -0
- package/dist/runtime/reversibility.js +39 -0
- package/dist/runtime/stake-level.d.ts +33 -0
- package/dist/runtime/stake-level.js +58 -0
- package/dist/runtime/stakes.d.ts +47 -0
- package/dist/runtime/stakes.js +305 -0
- package/dist/runtime/vocabulary.d.ts +122 -0
- package/dist/runtime/vocabulary.js +87 -0
- package/dist/sdk/audit.d.ts +195 -0
- package/dist/sdk/audit.js +128 -0
- package/dist/sdk/catalogue.d.ts +37 -0
- package/dist/sdk/catalogue.js +16 -0
- package/dist/sdk/conformance.d.ts +342 -0
- package/dist/sdk/conformance.js +494 -0
- package/dist/sdk/copy.d.ts +105 -0
- package/dist/sdk/copy.js +90 -0
- package/dist/sdk/definition.d.ts +242 -0
- package/dist/sdk/definition.js +64 -0
- package/dist/sdk/index.d.ts +19 -0
- package/dist/sdk/index.js +19 -0
- package/dist/sdk/interactivity.d.ts +29 -0
- package/dist/sdk/interactivity.js +34 -0
- package/dist/sdk/pairings.d.ts +124 -0
- package/dist/sdk/pairings.js +81 -0
- package/dist/sdk/registry.d.ts +162 -0
- package/dist/sdk/registry.js +329 -0
- package/dist/sdk/selection.d.ts +46 -0
- package/dist/sdk/selection.js +24 -0
- package/dist/sdk/text.d.ts +100 -0
- package/dist/sdk/text.js +105 -0
- package/dist/sdk/vocabulary.d.ts +39 -0
- package/dist/sdk/vocabulary.js +36 -0
- package/dist/signals/broadcast.d.ts +134 -0
- package/dist/signals/broadcast.js +451 -0
- package/dist/signals/collect.d.ts +184 -0
- package/dist/signals/collect.js +196 -0
- package/dist/signals/deliver.d.ts +64 -0
- package/dist/signals/deliver.js +85 -0
- package/dist/signals/fold.d.ts +112 -0
- package/dist/signals/fold.js +76 -0
- package/dist/signals/index.d.ts +31 -0
- package/dist/signals/index.js +31 -0
- package/dist/signals/ingest.d.ts +51 -0
- package/dist/signals/ingest.js +70 -0
- package/dist/signals/intake.d.ts +149 -0
- package/dist/signals/intake.js +154 -0
- package/dist/signals/journal.d.ts +94 -0
- package/dist/signals/journal.js +11 -0
- package/dist/signals/kinds.d.ts +22 -0
- package/dist/signals/kinds.js +22 -0
- package/dist/signals/ledger.d.ts +46 -0
- package/dist/signals/ledger.js +81 -0
- package/dist/signals/memory.d.ts +17 -0
- package/dist/signals/memory.js +99 -0
- package/dist/signals/migrate.d.ts +27 -0
- package/dist/signals/migrate.js +78 -0
- package/dist/signals/postgres.d.ts +7 -0
- package/dist/signals/postgres.js +295 -0
- package/dist/signals/rollup.d.ts +142 -0
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +534 -0
- package/dist/signals/schema.js +92 -0
- package/dist/signals/signal.d.ts +381 -0
- package/dist/signals/signal.js +150 -0
- package/dist/signals/tally.d.ts +70 -0
- package/dist/signals/tally.js +2 -0
- package/dist/signals/view.d.ts +51 -0
- package/dist/signals/view.js +54 -0
- package/dist/store/attribution.d.ts +125 -0
- package/dist/store/attribution.js +116 -0
- package/dist/store/database.d.ts +14 -0
- package/dist/store/database.js +2 -0
- package/dist/store/driver.d.ts +29 -0
- package/dist/store/driver.js +39 -0
- package/dist/store/errors.d.ts +56 -0
- package/dist/store/errors.js +37 -0
- package/dist/store/index.d.ts +16 -0
- package/dist/store/index.js +16 -0
- package/dist/store/memory.d.ts +3 -0
- package/dist/store/memory.js +115 -0
- package/dist/store/migrate.d.ts +54 -0
- package/dist/store/migrate.js +122 -0
- package/dist/store/postgres-holds.d.ts +4 -0
- package/dist/store/postgres-holds.js +192 -0
- package/dist/store/postgres.d.ts +8 -0
- package/dist/store/postgres.js +262 -0
- package/dist/store/replay.d.ts +94 -0
- package/dist/store/replay.js +82 -0
- package/dist/store/revert.d.ts +116 -0
- package/dist/store/revert.js +243 -0
- package/dist/store/schema.d.ts +371 -0
- package/dist/store/schema.js +78 -0
- package/dist/store/source.d.ts +23 -0
- package/dist/store/source.js +37 -0
- package/dist/store/store.d.ts +231 -0
- package/dist/store/store.js +52 -0
- package/dist/store/undone.d.ts +18 -0
- package/dist/store/undone.js +89 -0
- package/dist/submit/catalogue.d.ts +20 -0
- package/dist/submit/catalogue.js +5 -0
- package/dist/submit/declaration.d.ts +39 -0
- package/dist/submit/declaration.js +30 -0
- package/dist/submit/endpoint.d.ts +131 -0
- package/dist/submit/endpoint.js +160 -0
- package/dist/submit/index.d.ts +13 -0
- package/dist/submit/index.js +13 -0
- package/dist/submit/plan.d.ts +49 -0
- package/dist/submit/plan.js +47 -0
- package/dist/submit/resolution.d.ts +61 -0
- package/dist/submit/resolution.js +64 -0
- package/dist/submit/resolve.d.ts +45 -0
- package/dist/submit/resolve.js +36 -0
- package/dist/telemetry/calibration.d.ts +132 -0
- package/dist/telemetry/calibration.js +151 -0
- package/dist/telemetry/episode.d.ts +140 -0
- package/dist/telemetry/episode.js +272 -0
- package/dist/telemetry/event.d.ts +2310 -0
- package/dist/telemetry/event.js +405 -0
- package/dist/telemetry/index.d.ts +15 -0
- package/dist/telemetry/index.js +15 -0
- package/dist/telemetry/journal.d.ts +116 -0
- package/dist/telemetry/journal.js +11 -0
- package/dist/telemetry/memory.d.ts +24 -0
- package/dist/telemetry/memory.js +75 -0
- package/dist/telemetry/migrate.d.ts +26 -0
- package/dist/telemetry/migrate.js +40 -0
- package/dist/telemetry/postgres.d.ts +6 -0
- package/dist/telemetry/postgres.js +139 -0
- package/dist/telemetry/retention.d.ts +131 -0
- package/dist/telemetry/retention.js +217 -0
- package/dist/telemetry/schema.d.ts +113 -0
- package/dist/telemetry/schema.js +33 -0
- package/dist/telemetry/sink.d.ts +42 -0
- package/dist/telemetry/sink.js +61 -0
- package/dist/testing/contracts.d.ts +34 -0
- package/dist/testing/contracts.js +34 -0
- package/dist/testing/definitions.d.ts +15 -0
- package/dist/testing/definitions.js +48 -0
- package/dist/testing/doubles.d.ts +94 -0
- package/dist/testing/doubles.js +141 -0
- package/dist/testing/episode-harness.d.ts +49 -0
- package/dist/testing/episode-harness.js +65 -0
- package/dist/testing/filesystem.d.ts +17 -0
- package/dist/testing/filesystem.js +17 -0
- package/dist/testing/fixtures.d.ts +57 -0
- package/dist/testing/fixtures.js +84 -0
- package/dist/testing/hold-contract.d.ts +19 -0
- package/dist/testing/hold-contract.js +374 -0
- package/dist/testing/index.d.ts +41 -0
- package/dist/testing/index.js +41 -0
- package/dist/testing/journal-contract.d.ts +17 -0
- package/dist/testing/journal-contract.js +353 -0
- package/dist/testing/model-replies.d.ts +34 -0
- package/dist/testing/model-replies.js +101 -0
- package/dist/testing/primitives.d.ts +7 -0
- package/dist/testing/primitives.js +29 -0
- package/dist/testing/reader-signal-contract.d.ts +38 -0
- package/dist/testing/reader-signal-contract.js +318 -0
- package/dist/testing/row-security.d.ts +17 -0
- package/dist/testing/row-security.js +21 -0
- package/dist/testing/store-contract.d.ts +25 -0
- package/dist/testing/store-contract.js +500 -0
- package/dist/theme/apply.d.ts +17 -0
- package/dist/theme/apply.js +60 -0
- package/dist/theme/contrast.d.ts +197 -0
- package/dist/theme/contrast.js +259 -0
- package/dist/theme/derive.d.ts +77 -0
- package/dist/theme/derive.js +167 -0
- package/dist/theme/faces.d.ts +73 -0
- package/dist/theme/faces.js +119 -0
- package/dist/theme/font-packs.d.ts +25 -0
- package/dist/theme/font-packs.js +257 -0
- package/dist/theme/index.d.ts +20 -0
- package/dist/theme/index.js +20 -0
- package/dist/theme/lab.d.ts +30 -0
- package/dist/theme/lab.js +46 -0
- package/dist/theme/library.d.ts +114 -0
- package/dist/theme/library.js +300 -0
- package/dist/theme/measure.d.ts +144 -0
- package/dist/theme/measure.js +145 -0
- package/dist/theme/palettes.d.ts +64 -0
- package/dist/theme/palettes.js +497 -0
- package/dist/theme/registry.d.ts +59 -0
- package/dist/theme/registry.js +60 -0
- package/dist/theme/separation.d.ts +177 -0
- package/dist/theme/separation.js +203 -0
- package/dist/theme/style-presets.d.ts +60 -0
- package/dist/theme/style-presets.js +124 -0
- package/dist/theme/theme.d.ts +253 -0
- package/dist/theme/theme.js +171 -0
- package/dist/tree/apply.d.ts +16 -0
- package/dist/tree/apply.js +104 -0
- package/dist/tree/builders.d.ts +19 -0
- package/dist/tree/builders.js +20 -0
- package/dist/tree/compare.d.ts +68 -0
- package/dist/tree/compare.js +75 -0
- package/dist/tree/configuration.d.ts +25 -0
- package/dist/tree/configuration.js +108 -0
- package/dist/tree/delta.d.ts +288 -0
- package/dist/tree/delta.js +88 -0
- package/dist/tree/errors.d.ts +69 -0
- package/dist/tree/errors.js +34 -0
- package/dist/tree/identity.d.ts +117 -0
- package/dist/tree/identity.js +145 -0
- package/dist/tree/index.d.ts +21 -0
- package/dist/tree/index.js +21 -0
- package/dist/tree/inverse.d.ts +24 -0
- package/dist/tree/inverse.js +112 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +49 -0
- package/dist/tree/naming.d.ts +4 -0
- package/dist/tree/naming.js +35 -0
- package/dist/tree/navigation.d.ts +38 -0
- package/dist/tree/navigation.js +83 -0
- package/dist/tree/node.d.ts +103 -0
- package/dist/tree/node.js +46 -0
- package/dist/tree/outline.d.ts +28 -0
- package/dist/tree/outline.js +10 -0
- package/dist/tree/tree.d.ts +83 -0
- package/dist/tree/tree.js +62 -0
- package/dist/write/commit.d.ts +124 -0
- package/dist/write/commit.js +234 -0
- package/dist/write/held.d.ts +674 -0
- package/dist/write/held.js +185 -0
- package/dist/write/index.d.ts +11 -0
- package/dist/write/index.js +11 -0
- package/dist/write/liveness.d.ts +132 -0
- package/dist/write/liveness.js +91 -0
- package/dist/write/revert.d.ts +79 -0
- package/dist/write/revert.js +134 -0
- package/package.json +160 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { JsonObject } from "../json.js";
|
|
2
|
+
/**
|
|
3
|
+
* The JSON Schema handed to the model, hand-written rather than derived from
|
|
4
|
+
* the Zod draft schema, because structured output accepts a strict subset of
|
|
5
|
+
* JSON Schema: every object must close over its properties, and recursive
|
|
6
|
+
* definitions are not allowed.
|
|
7
|
+
*
|
|
8
|
+
* Nesting is therefore unrolled to a fixed depth. That is a limit on how much
|
|
9
|
+
* structure one proposal may introduce at once, not a limit on the tree: a
|
|
10
|
+
* deeper subtree is built by a second insert against the node the first one
|
|
11
|
+
* created. `draft.ts` stays fully recursive, so a deeper reply that somehow
|
|
12
|
+
* arrives still validates.
|
|
13
|
+
*
|
|
14
|
+
* There is a second constraint, and it is the one that bites: the service
|
|
15
|
+
* compiles this schema into a grammar and refuses anything whose compiled form
|
|
16
|
+
* is too large. It is not a documented number and it is not proportional to
|
|
17
|
+
* anything obvious — it tracks the serialised size of the schema closely enough
|
|
18
|
+
* that size is the practical proxy. 0014 has the measurements.
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_DRAFT_DEPTH = 4;
|
|
21
|
+
/**
|
|
22
|
+
* The size guard, in bytes of serialised schema.
|
|
23
|
+
*
|
|
24
|
+
* Measured on 2026-07-30: every variant at or below 3681 bytes was accepted and
|
|
25
|
+
* every variant at or above 4136 was rejected. This sits below that band with
|
|
26
|
+
* room to spare, so it fails before the API does — a schema that grows past it
|
|
27
|
+
* is a change someone has to look at, not a 400 in production.
|
|
28
|
+
*
|
|
29
|
+
* It is a guard rail, not the boundary. The boundary is undocumented, belongs to
|
|
30
|
+
* the service, and can move; only `anthropic.smoke.test.ts` can tell us where it
|
|
31
|
+
* actually is today.
|
|
32
|
+
*
|
|
33
|
+
* A second reason this function takes only a depth and reads nothing else: the
|
|
34
|
+
* service compiles a schema once and caches the compilation for about a day, keyed
|
|
35
|
+
* by the schema itself. Byte-identical output across every deployment and every
|
|
36
|
+
* request means that cost is paid once; a schema that varied per deployment or per
|
|
37
|
+
* request would pay it repeatedly. It is also the second argument against 0013's
|
|
38
|
+
* rejected alternative of generating a schema per primitive.
|
|
39
|
+
*/
|
|
40
|
+
export declare const GRAMMAR_BUDGET_BYTES = 3500;
|
|
41
|
+
export declare const interpretationReplyJsonSchema: (depth?: number) => JsonObject;
|
|
42
|
+
/**
|
|
43
|
+
* The serialised size of the emitted schema, which is what the budget is
|
|
44
|
+
* asserted against offline. Bytes rather than characters: the description
|
|
45
|
+
* strings are the part most likely to grow, and the part most likely to grow
|
|
46
|
+
* a non-ASCII character.
|
|
47
|
+
*/
|
|
48
|
+
export declare const draftSchemaByteSize: (depth?: number) => number;
|
|
49
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JSON Schema handed to the model, hand-written rather than derived from
|
|
3
|
+
* the Zod draft schema, because structured output accepts a strict subset of
|
|
4
|
+
* JSON Schema: every object must close over its properties, and recursive
|
|
5
|
+
* definitions are not allowed.
|
|
6
|
+
*
|
|
7
|
+
* Nesting is therefore unrolled to a fixed depth. That is a limit on how much
|
|
8
|
+
* structure one proposal may introduce at once, not a limit on the tree: a
|
|
9
|
+
* deeper subtree is built by a second insert against the node the first one
|
|
10
|
+
* created. `draft.ts` stays fully recursive, so a deeper reply that somehow
|
|
11
|
+
* arrives still validates.
|
|
12
|
+
*
|
|
13
|
+
* There is a second constraint, and it is the one that bites: the service
|
|
14
|
+
* compiles this schema into a grammar and refuses anything whose compiled form
|
|
15
|
+
* is too large. It is not a documented number and it is not proportional to
|
|
16
|
+
* anything obvious — it tracks the serialised size of the schema closely enough
|
|
17
|
+
* that size is the practical proxy. 0014 has the measurements.
|
|
18
|
+
*/
|
|
19
|
+
export const DEFAULT_DRAFT_DEPTH = 4;
|
|
20
|
+
/**
|
|
21
|
+
* The size guard, in bytes of serialised schema.
|
|
22
|
+
*
|
|
23
|
+
* Measured on 2026-07-30: every variant at or below 3681 bytes was accepted and
|
|
24
|
+
* every variant at or above 4136 was rejected. This sits below that band with
|
|
25
|
+
* room to spare, so it fails before the API does — a schema that grows past it
|
|
26
|
+
* is a change someone has to look at, not a 400 in production.
|
|
27
|
+
*
|
|
28
|
+
* It is a guard rail, not the boundary. The boundary is undocumented, belongs to
|
|
29
|
+
* the service, and can move; only `anthropic.smoke.test.ts` can tell us where it
|
|
30
|
+
* actually is today.
|
|
31
|
+
*
|
|
32
|
+
* A second reason this function takes only a depth and reads nothing else: the
|
|
33
|
+
* service compiles a schema once and caches the compilation for about a day, keyed
|
|
34
|
+
* by the schema itself. Byte-identical output across every deployment and every
|
|
35
|
+
* request means that cost is paid once; a schema that varied per deployment or per
|
|
36
|
+
* request would pay it repeatedly. It is also the second argument against 0013's
|
|
37
|
+
* rejected alternative of generating a schema per primitive.
|
|
38
|
+
*/
|
|
39
|
+
export const GRAMMAR_BUDGET_BYTES = 3500;
|
|
40
|
+
const closedObject = (properties) => ({
|
|
41
|
+
type: "object",
|
|
42
|
+
properties,
|
|
43
|
+
required: Object.keys(properties),
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
});
|
|
46
|
+
const constant = (value) => ({ type: "string", const: value });
|
|
47
|
+
/**
|
|
48
|
+
* Descriptions are kept terse on purpose. Every one of them is repeated at every
|
|
49
|
+
* level of the unrolled schema, so a helpful sentence here costs a multiple of
|
|
50
|
+
* itself in budget — and the system prompt already explains ids, indices, and the
|
|
51
|
+
* prop encoding at length, to the same model, in the same request.
|
|
52
|
+
*/
|
|
53
|
+
/** Ids are copied from the rendered tree; the regex lives in `nodeIdSchema`. */
|
|
54
|
+
const nodeIdProperty = { type: "string", description: "id copied from the tree" };
|
|
55
|
+
const indexProperty = { type: "integer", description: "0-based" };
|
|
56
|
+
/**
|
|
57
|
+
* One string, not a structure. A typed prop union repeats at every element at
|
|
58
|
+
* every level of the unrolled schema, and that repetition — not the depth — is
|
|
59
|
+
* what put the old schema four times over the grammar budget (0014).
|
|
60
|
+
*/
|
|
61
|
+
const propsProperty = { type: "string" };
|
|
62
|
+
const textNodeSchema = closedObject({
|
|
63
|
+
kind: constant("text"),
|
|
64
|
+
value: { type: "string" },
|
|
65
|
+
});
|
|
66
|
+
/** Depth 1 is a leaf: the only node kind that cannot hold children. */
|
|
67
|
+
const nodeSchema = (depth) => {
|
|
68
|
+
if (depth <= 1)
|
|
69
|
+
return textNodeSchema;
|
|
70
|
+
const children = { type: "array", items: nodeSchema(depth - 1) };
|
|
71
|
+
return {
|
|
72
|
+
anyOf: [
|
|
73
|
+
closedObject({
|
|
74
|
+
kind: constant("element"),
|
|
75
|
+
type: { type: "string", description: "e.g. loom.card" },
|
|
76
|
+
props: propsProperty,
|
|
77
|
+
children,
|
|
78
|
+
}),
|
|
79
|
+
textNodeSchema,
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
const operationSchema = (depth) => ({
|
|
84
|
+
anyOf: [
|
|
85
|
+
closedObject({
|
|
86
|
+
op: constant("insert"),
|
|
87
|
+
parentId: nodeIdProperty,
|
|
88
|
+
index: indexProperty,
|
|
89
|
+
node: nodeSchema(depth),
|
|
90
|
+
}),
|
|
91
|
+
closedObject({ op: constant("remove"), nodeId: nodeIdProperty }),
|
|
92
|
+
closedObject({
|
|
93
|
+
op: constant("move"),
|
|
94
|
+
nodeId: nodeIdProperty,
|
|
95
|
+
parentId: nodeIdProperty,
|
|
96
|
+
index: indexProperty,
|
|
97
|
+
}),
|
|
98
|
+
closedObject({
|
|
99
|
+
op: constant("configure"),
|
|
100
|
+
nodeId: nodeIdProperty,
|
|
101
|
+
set: propsProperty,
|
|
102
|
+
unset: { type: "array", items: { type: "string" } },
|
|
103
|
+
}),
|
|
104
|
+
],
|
|
105
|
+
});
|
|
106
|
+
export const interpretationReplyJsonSchema = (depth = DEFAULT_DRAFT_DEPTH) => ({
|
|
107
|
+
anyOf: [
|
|
108
|
+
closedObject({
|
|
109
|
+
outcome: constant("change"),
|
|
110
|
+
rationale: { type: "string", description: "why these operations satisfy the intent" },
|
|
111
|
+
confidence: { type: "number", description: "0 to 1" },
|
|
112
|
+
operations: { type: "array", items: operationSchema(depth) },
|
|
113
|
+
}),
|
|
114
|
+
closedObject({
|
|
115
|
+
outcome: constant("no-change"),
|
|
116
|
+
rationale: { type: "string", description: "why the tree already satisfies it" },
|
|
117
|
+
}),
|
|
118
|
+
closedObject({
|
|
119
|
+
outcome: constant("not-understood"),
|
|
120
|
+
rationale: { type: "string", description: "what was ambiguous or unsupported" },
|
|
121
|
+
}),
|
|
122
|
+
],
|
|
123
|
+
});
|
|
124
|
+
/**
|
|
125
|
+
* The serialised size of the emitted schema, which is what the budget is
|
|
126
|
+
* asserted against offline. Bytes rather than characters: the description
|
|
127
|
+
* strings are the part most likely to grow, and the part most likely to grow
|
|
128
|
+
* a non-ASCII character.
|
|
129
|
+
*/
|
|
130
|
+
export const draftSchemaByteSize = (depth = DEFAULT_DRAFT_DEPTH) => new TextEncoder().encode(JSON.stringify(interpretationReplyJsonSchema(depth))).length;
|
|
131
|
+
//# sourceMappingURL=schema.js.map
|
package/dist/json.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The JSON floor the rest of the runtime stands on.
|
|
4
|
+
*
|
|
5
|
+
* A tree is written by a model, stored in a database, sent over a wire and read
|
|
6
|
+
* back, so the values it carries have to survive all four. This module says what
|
|
7
|
+
* those values may be and gives the schema that checks it.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Everything that crosses a Loom boundary — the tree, deltas, telemetry — must
|
|
11
|
+
* round-trip through JSON without loss. Props are therefore restricted to JSON
|
|
12
|
+
* values: no functions, no Dates, no undefined, no class instances.
|
|
13
|
+
*/
|
|
14
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
15
|
+
[key: string]: JsonValue;
|
|
16
|
+
};
|
|
17
|
+
export declare const jsonValueSchema: z.ZodType<JsonValue>;
|
|
18
|
+
export type JsonObject = {
|
|
19
|
+
[key: string]: JsonValue;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A narrower view of a `JsonObject` — what a schema declares it needs, rather
|
|
23
|
+
* than everything a stored object may hold. Optional members are allowed to be
|
|
24
|
+
* `undefined` because an absent key in a `JsonObject` reads that way; the value
|
|
25
|
+
* space itself is unchanged, since `undefined` never survives serialisation and
|
|
26
|
+
* so can never be a stored prop.
|
|
27
|
+
*
|
|
28
|
+
* Every `JsonObject` is a `JsonObjectView`; the reverse is what validation at a
|
|
29
|
+
* boundary establishes.
|
|
30
|
+
*/
|
|
31
|
+
export type JsonObjectView = {
|
|
32
|
+
[key: string]: JsonValue | undefined;
|
|
33
|
+
};
|
|
34
|
+
export declare const jsonObjectSchema: z.ZodType<JsonObject>;
|
|
35
|
+
//# sourceMappingURL=json.d.ts.map
|
package/dist/json.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const jsonValueSchema = z.lazy(() => z.union([
|
|
3
|
+
z.string(),
|
|
4
|
+
z.number().finite(),
|
|
5
|
+
z.boolean(),
|
|
6
|
+
z.null(),
|
|
7
|
+
z.array(jsonValueSchema),
|
|
8
|
+
z.record(z.string(), jsonValueSchema),
|
|
9
|
+
]));
|
|
10
|
+
export const jsonObjectSchema = z.record(z.string(), jsonValueSchema);
|
|
11
|
+
//# sourceMappingURL=json.js.map
|
package/dist/paging.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyset paging, as a rule rather than a convention.
|
|
3
|
+
*
|
|
4
|
+
* Every listing in Loom is a page with an opaque cursor, and every one of them
|
|
5
|
+
* clamps the limit it was asked for — otherwise a caller can ask a store for
|
|
6
|
+
* everything it holds by omitting the limit or naming a large one. The bounds
|
|
7
|
+
* differ by what is being listed; the clamping rule does not, so it is written
|
|
8
|
+
* once here and the bounds are what each caller supplies.
|
|
9
|
+
*/
|
|
10
|
+
export type LimitBounds = {
|
|
11
|
+
/** Used when the caller named no limit, or named one that is not a number. */
|
|
12
|
+
readonly fallback: number;
|
|
13
|
+
readonly max: number;
|
|
14
|
+
};
|
|
15
|
+
export declare const clampLimit: (limit: number | undefined, bounds: LimitBounds) => number;
|
|
16
|
+
/**
|
|
17
|
+
* Which end of an append-only sequence a page is taken from.
|
|
18
|
+
*
|
|
19
|
+
* A log only grows, so the question asked of one most often is "what happened
|
|
20
|
+
* recently" — and forward-only paging answers that by reading everything that
|
|
21
|
+
* ever happened first. `older` starts at the newest position and walks back,
|
|
22
|
+
* which is one index seek rather than a walk from the beginning.
|
|
23
|
+
*/
|
|
24
|
+
export type PageDirection = "newer" | "older";
|
|
25
|
+
/**
|
|
26
|
+
* The two ends a page names: cursors to resume from in either direction, `null`
|
|
27
|
+
* when the page already reaches that end.
|
|
28
|
+
*
|
|
29
|
+
* `newer: null` is a weaker claim than `older: null`. The oldest position in a
|
|
30
|
+
* log is a fact; the newest is only true at the time of the read, because the
|
|
31
|
+
* log is still being appended to.
|
|
32
|
+
*/
|
|
33
|
+
export type PageEnds = {
|
|
34
|
+
readonly older: string | null;
|
|
35
|
+
readonly newer: string | null;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The ends a page reports, given the positions it holds and what the read
|
|
39
|
+
* already knows.
|
|
40
|
+
*
|
|
41
|
+
* Shared by every implementation of every paged log, because "which ends does
|
|
42
|
+
* this page name" is a property of keyset paging rather than of a backend or of
|
|
43
|
+
* what is being paged. `beyond` is what the limit+1 probe found on the side
|
|
44
|
+
* being paged toward; the far side is bounded by the cursor the caller passed,
|
|
45
|
+
* since a position it named is a position records exist at.
|
|
46
|
+
*
|
|
47
|
+
* `positions` is in the page's own ascending order, whichever end it came from.
|
|
48
|
+
*/
|
|
49
|
+
export declare const pageEnds: (positions: readonly number[], direction: PageDirection, { beyond, resumed }: {
|
|
50
|
+
readonly beyond: boolean;
|
|
51
|
+
readonly resumed: boolean;
|
|
52
|
+
}) => PageEnds;
|
|
53
|
+
/**
|
|
54
|
+
* Reads a cursor back into the position it names. A cursor is opaque to the
|
|
55
|
+
* caller, so one that is absent or unreadable means the same thing to every
|
|
56
|
+
* implementation — start at the end the direction begins from — rather than one
|
|
57
|
+
* refusing what another silently accepts.
|
|
58
|
+
*/
|
|
59
|
+
export declare const cursorPosition: (cursor: string | undefined) => number | undefined;
|
|
60
|
+
//# sourceMappingURL=paging.d.ts.map
|
package/dist/paging.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keyset paging, as a rule rather than a convention.
|
|
3
|
+
*
|
|
4
|
+
* Every listing in Loom is a page with an opaque cursor, and every one of them
|
|
5
|
+
* clamps the limit it was asked for — otherwise a caller can ask a store for
|
|
6
|
+
* everything it holds by omitting the limit or naming a large one. The bounds
|
|
7
|
+
* differ by what is being listed; the clamping rule does not, so it is written
|
|
8
|
+
* once here and the bounds are what each caller supplies.
|
|
9
|
+
*/
|
|
10
|
+
export const clampLimit = (limit, bounds) => {
|
|
11
|
+
if (limit === undefined || !Number.isFinite(limit))
|
|
12
|
+
return bounds.fallback;
|
|
13
|
+
return Math.min(bounds.max, Math.max(1, Math.floor(limit)));
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* The ends a page reports, given the positions it holds and what the read
|
|
17
|
+
* already knows.
|
|
18
|
+
*
|
|
19
|
+
* Shared by every implementation of every paged log, because "which ends does
|
|
20
|
+
* this page name" is a property of keyset paging rather than of a backend or of
|
|
21
|
+
* what is being paged. `beyond` is what the limit+1 probe found on the side
|
|
22
|
+
* being paged toward; the far side is bounded by the cursor the caller passed,
|
|
23
|
+
* since a position it named is a position records exist at.
|
|
24
|
+
*
|
|
25
|
+
* `positions` is in the page's own ascending order, whichever end it came from.
|
|
26
|
+
*/
|
|
27
|
+
export const pageEnds = (positions, direction, { beyond, resumed }) => {
|
|
28
|
+
const first = positions.at(0);
|
|
29
|
+
const last = positions.at(-1);
|
|
30
|
+
if (first === undefined || last === undefined)
|
|
31
|
+
return { older: null, newer: null };
|
|
32
|
+
return direction === "older"
|
|
33
|
+
? { older: beyond ? String(first) : null, newer: resumed ? String(last) : null }
|
|
34
|
+
: { older: resumed ? String(first) : null, newer: beyond ? String(last) : null };
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Reads a cursor back into the position it names. A cursor is opaque to the
|
|
38
|
+
* caller, so one that is absent or unreadable means the same thing to every
|
|
39
|
+
* implementation — start at the end the direction begins from — rather than one
|
|
40
|
+
* refusing what another silently accepts.
|
|
41
|
+
*/
|
|
42
|
+
export const cursorPosition = (cursor) => {
|
|
43
|
+
/** `Number("")` is 0, and an empty cursor is an absent one rather than the start. */
|
|
44
|
+
if (cursor === undefined || cursor.trim() === "")
|
|
45
|
+
return undefined;
|
|
46
|
+
const position = Number(cursor);
|
|
47
|
+
return Number.isFinite(position) ? position : undefined;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=paging.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* The names a tree uses to reach what a deployment registered.
|
|
4
|
+
*
|
|
5
|
+
* One grammar serves every registry — primitives, data sources, submission
|
|
6
|
+
* endpoints — so that naming a capability looks the same wherever a tree does
|
|
7
|
+
* it.
|
|
8
|
+
*/
|
|
9
|
+
export { NAMESPACED_ID_PATTERN } from "./grammar.js";
|
|
10
|
+
/**
|
|
11
|
+
* The identifier of a registered primitive — the contract between an element
|
|
12
|
+
* node and whatever renders it. The tree schema only cares about the shape of
|
|
13
|
+
* the identifier; resolving it to an implementation is the registry's job, which
|
|
14
|
+
* keeps the AST independent of any particular primitive library.
|
|
15
|
+
*/
|
|
16
|
+
export declare const primitiveTypeSchema: z.ZodBranded<z.ZodString, "PrimitiveType">;
|
|
17
|
+
export type PrimitiveType = z.infer<typeof primitiveTypeSchema>;
|
|
18
|
+
/**
|
|
19
|
+
* A named region inside a primitive that accepts projected children.
|
|
20
|
+
* camelCase, mirroring prop naming.
|
|
21
|
+
*/
|
|
22
|
+
export declare const slotNameSchema: z.ZodBranded<z.ZodString, "SlotName">;
|
|
23
|
+
export type SlotName = z.infer<typeof slotNameSchema>;
|
|
24
|
+
/**
|
|
25
|
+
* A key naming one of the strings a primitive owns. camelCase, mirroring slot
|
|
26
|
+
* and prop naming — and, load-bearing, never containing a dot: a dictionary
|
|
27
|
+
* addresses a string as `${type}.${key}`, and a key with a dot in it would make
|
|
28
|
+
* that address ambiguous between two primitives.
|
|
29
|
+
*/
|
|
30
|
+
export declare const textKeySchema: z.ZodBranded<z.ZodString, "TextKey">;
|
|
31
|
+
export type TextKey = z.infer<typeof textKeySchema>;
|
|
32
|
+
//# sourceMappingURL=primitive-type.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { NAMESPACED_ID_PATTERN } from "./grammar.js";
|
|
3
|
+
/**
|
|
4
|
+
* The names a tree uses to reach what a deployment registered.
|
|
5
|
+
*
|
|
6
|
+
* One grammar serves every registry — primitives, data sources, submission
|
|
7
|
+
* endpoints — so that naming a capability looks the same wherever a tree does
|
|
8
|
+
* it.
|
|
9
|
+
*/
|
|
10
|
+
export { NAMESPACED_ID_PATTERN } from "./grammar.js";
|
|
11
|
+
/**
|
|
12
|
+
* The identifier of a registered primitive — the contract between an element
|
|
13
|
+
* node and whatever renders it. The tree schema only cares about the shape of
|
|
14
|
+
* the identifier; resolving it to an implementation is the registry's job, which
|
|
15
|
+
* keeps the AST independent of any particular primitive library.
|
|
16
|
+
*/
|
|
17
|
+
export const primitiveTypeSchema = z
|
|
18
|
+
.string()
|
|
19
|
+
.regex(NAMESPACED_ID_PATTERN)
|
|
20
|
+
.brand();
|
|
21
|
+
/**
|
|
22
|
+
* A named region inside a primitive that accepts projected children.
|
|
23
|
+
* camelCase, mirroring prop naming.
|
|
24
|
+
*/
|
|
25
|
+
export const slotNameSchema = z
|
|
26
|
+
.string()
|
|
27
|
+
.regex(/^[a-z][a-zA-Z0-9]*$/)
|
|
28
|
+
.brand();
|
|
29
|
+
/**
|
|
30
|
+
* A key naming one of the strings a primitive owns. camelCase, mirroring slot
|
|
31
|
+
* and prop naming — and, load-bearing, never containing a dot: a dictionary
|
|
32
|
+
* addresses a string as `${type}.${key}`, and a key with a dot in it would make
|
|
33
|
+
* that address ambiguous between two primitives.
|
|
34
|
+
*/
|
|
35
|
+
export const textKeySchema = z
|
|
36
|
+
.string()
|
|
37
|
+
.regex(/^[a-z][a-zA-Z0-9]*$/)
|
|
38
|
+
.brand();
|
|
39
|
+
//# sourceMappingURL=primitive-type.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { NodeId } from "../ids.js";
|
|
2
|
+
import type { PrimitiveType } from "../primitive-type.js";
|
|
3
|
+
import type { LoomNode } from "../tree/node.js";
|
|
4
|
+
/**
|
|
5
|
+
* Which node in the tree a click in the browser can actually land on.
|
|
6
|
+
*
|
|
7
|
+
* Edit mode decorates elements and nothing else (0010): a text node renders as a
|
|
8
|
+
* bare string and a slot renders as a Fragment, so neither leaves anything in the
|
|
9
|
+
* DOM to carry `data-loom-node`. On top of that, 0012 made conformance reported
|
|
10
|
+
* rather than enforced, so a registered primitive is allowed to ignore
|
|
11
|
+
* `loom.editable` — it renders correctly and is invisible to a portal.
|
|
12
|
+
*
|
|
13
|
+
* The consequence is that *the tree a user sees in an outline is not the same set
|
|
14
|
+
* of nodes the DOM can address*, and something has to reconcile the two. 0019
|
|
15
|
+
* fixed what that something must do: fall back to the nearest decorated ancestor,
|
|
16
|
+
* and say so. Wrapping an undecorated primitive to force a handle would restructure
|
|
17
|
+
* the DOM, which 0010 forbids for good reason.
|
|
18
|
+
*
|
|
19
|
+
* This module is the reconciliation, as a pure function. It takes a predicate
|
|
20
|
+
* rather than a registry so it depends on nothing: what makes a type decorated is
|
|
21
|
+
* the host's business (`decorationFromAudit` in the SDK answers it from a
|
|
22
|
+
* conformance audit), and a caller with better knowledge — a recorded probe, an
|
|
23
|
+
* allowlist — can answer it differently without this module changing.
|
|
24
|
+
*/
|
|
25
|
+
/** Whether elements of this type reach the DOM carrying their decoration. */
|
|
26
|
+
export type DecorationLookup = (type: PrimitiveType) => boolean;
|
|
27
|
+
export type UnaddressableReason =
|
|
28
|
+
/** Text and slot nodes render without an element of their own. */
|
|
29
|
+
"not-an-element"
|
|
30
|
+
/** A registered primitive that ignores `loom.editable`, or one that is not registered at all. */
|
|
31
|
+
| "undecorated-primitive"
|
|
32
|
+
/** Not in this tree. */
|
|
33
|
+
| "absent";
|
|
34
|
+
export type Addressing = {
|
|
35
|
+
readonly outcome: "addressable";
|
|
36
|
+
readonly nodeId: NodeId;
|
|
37
|
+
}
|
|
38
|
+
/** The request is answerable, but by an ancestor rather than by the node asked for. */
|
|
39
|
+
| {
|
|
40
|
+
readonly outcome: "delegated";
|
|
41
|
+
readonly nodeId: NodeId;
|
|
42
|
+
readonly requested: NodeId;
|
|
43
|
+
readonly reason: UnaddressableReason;
|
|
44
|
+
}
|
|
45
|
+
/** Nothing on the path to the root is addressable, so there is nowhere to point. */
|
|
46
|
+
| {
|
|
47
|
+
readonly outcome: "unaddressable";
|
|
48
|
+
readonly requested: NodeId;
|
|
49
|
+
readonly reason: UnaddressableReason;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* The node a click can land on when the user meant `nodeId`: itself when it is
|
|
53
|
+
* decorated, otherwise its nearest decorated ancestor, otherwise nothing.
|
|
54
|
+
*/
|
|
55
|
+
export declare const addressNode: (root: LoomNode, nodeId: NodeId, decorates: DecorationLookup) => Addressing;
|
|
56
|
+
/** The id a caller should look for in the DOM, or null when there is none. */
|
|
57
|
+
export declare const addressedNodeId: (addressing: Addressing) => NodeId | null;
|
|
58
|
+
export declare const describeAddressing: (addressing: Addressing) => string;
|
|
59
|
+
//# sourceMappingURL=addressing.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { nodePath } from "../tree/navigation.js";
|
|
2
|
+
const reasonFor = (node, decorates) => {
|
|
3
|
+
if (node.kind !== "element")
|
|
4
|
+
return "not-an-element";
|
|
5
|
+
return decorates(node.type) ? null : "undecorated-primitive";
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* The node a click can land on when the user meant `nodeId`: itself when it is
|
|
9
|
+
* decorated, otherwise its nearest decorated ancestor, otherwise nothing.
|
|
10
|
+
*/
|
|
11
|
+
export const addressNode = (root, nodeId, decorates) => {
|
|
12
|
+
const path = nodePath(root, nodeId);
|
|
13
|
+
if (!path)
|
|
14
|
+
return { outcome: "unaddressable", requested: nodeId, reason: "absent" };
|
|
15
|
+
const requested = path.at(-1);
|
|
16
|
+
/** Unreachable: `nodePath` ends at the node it found. */
|
|
17
|
+
if (!requested)
|
|
18
|
+
return { outcome: "unaddressable", requested: nodeId, reason: "absent" };
|
|
19
|
+
const reason = reasonFor(requested, decorates);
|
|
20
|
+
if (!reason)
|
|
21
|
+
return { outcome: "addressable", nodeId };
|
|
22
|
+
const ancestors = path.slice(0, -1).reverse();
|
|
23
|
+
for (const ancestor of ancestors) {
|
|
24
|
+
if (!reasonFor(ancestor, decorates)) {
|
|
25
|
+
return { outcome: "delegated", nodeId: ancestor.id, requested: nodeId, reason };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return { outcome: "unaddressable", requested: nodeId, reason };
|
|
29
|
+
};
|
|
30
|
+
/** The id a caller should look for in the DOM, or null when there is none. */
|
|
31
|
+
export const addressedNodeId = (addressing) => {
|
|
32
|
+
switch (addressing.outcome) {
|
|
33
|
+
case "addressable":
|
|
34
|
+
case "delegated":
|
|
35
|
+
return addressing.nodeId;
|
|
36
|
+
case "unaddressable":
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
export const describeAddressing = (addressing) => {
|
|
41
|
+
switch (addressing.outcome) {
|
|
42
|
+
case "addressable":
|
|
43
|
+
return "addressable";
|
|
44
|
+
case "delegated":
|
|
45
|
+
return `${describeReason(addressing.reason)}, so selection falls back to ${addressing.nodeId}`;
|
|
46
|
+
case "unaddressable":
|
|
47
|
+
return `${describeReason(addressing.reason)}, and no ancestor is addressable either`;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const describeReason = (reason) => {
|
|
51
|
+
switch (reason) {
|
|
52
|
+
case "not-an-element":
|
|
53
|
+
return "this node renders without an element of its own";
|
|
54
|
+
case "undecorated-primitive":
|
|
55
|
+
return "this primitive does not spread loom.editable";
|
|
56
|
+
case "absent":
|
|
57
|
+
return "this node is not in the tree";
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=addressing.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { NodeId } from "../ids.js";
|
|
2
|
+
import type { JsonValue } from "../json.js";
|
|
3
|
+
/**
|
|
4
|
+
* A band the page's own links can point at.
|
|
5
|
+
*
|
|
6
|
+
* A Loom page could hold a link to any document on the web except itself. The
|
|
7
|
+
* address half has always worked — a URL carrying a fragment parses and passes
|
|
8
|
+
* every check the library makes — and the target half did not exist, because no
|
|
9
|
+
* primitive renders an `id` and nothing in the runtime gave it one. A page whose
|
|
10
|
+
* answer sits twelve hundred pixels below the claim had no way to say *here it
|
|
11
|
+
* is*.
|
|
12
|
+
*
|
|
13
|
+
* This is the target half. A node the tree gives an anchor receives an `id` to
|
|
14
|
+
* spread, the same way it receives the attributes that make it editable and the
|
|
15
|
+
* variables that make the root themed — on its own root element, never on a
|
|
16
|
+
* wrapper the renderer emitted, for the reason `editable.ts` gives.
|
|
17
|
+
*
|
|
18
|
+
* Three things happen here that could not happen in a prop schema, and they are
|
|
19
|
+
* the reason this is a reserved key read by the runtime rather than a prop each
|
|
20
|
+
* band primitive declares for itself. An anchor is checked against a grammar
|
|
21
|
+
* narrow enough that what the tree wrote is what a browser matches. It is held
|
|
22
|
+
* against every other anchor in the same render, because two elements sharing an
|
|
23
|
+
* `id` is a document that is wrong rather than a node that is wrong, and a
|
|
24
|
+
* schema sees one node at a time. And it is withheld from a decorative copy,
|
|
25
|
+
* because a copy carries no identity and an anchor is identity (0093).
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* What a primitive spreads to become a fragment target.
|
|
29
|
+
*
|
|
30
|
+
* One attribute, and shaped as a bundle rather than a bare string so that the
|
|
31
|
+
* spread at the call site reads the same as the one beside it — `{...loom.anchor}`
|
|
32
|
+
* next to `{...loom.editable}` — and so that adding to it later is not a change
|
|
33
|
+
* to every primitive that placed it.
|
|
34
|
+
*/
|
|
35
|
+
export type AnchorAttributes = {
|
|
36
|
+
readonly id: string;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* What the renderer learned about a node's declared anchor.
|
|
40
|
+
*
|
|
41
|
+
* Three states rather than the two the framing seam has, because the two ways an
|
|
42
|
+
* anchor fails are different faults with different fixes: a slug nobody can use
|
|
43
|
+
* is the tree's own mistake, and a slug already taken is a collision between two
|
|
44
|
+
* nodes that are each fine alone. A caller that flattened them would report the
|
|
45
|
+
* second as the first and send whoever reads it looking at the wrong node.
|
|
46
|
+
*
|
|
47
|
+
* A primitive is never handed any of this. It receives the attributes or it does
|
|
48
|
+
* not, because unlike a refused frame — which a primitive renders differently,
|
|
49
|
+
* and visibly — there is nothing for a primitive to do about an anchor it did
|
|
50
|
+
* not get. What is left is a diagnostic, which is where a fault with no
|
|
51
|
+
* behaviour belongs.
|
|
52
|
+
*/
|
|
53
|
+
export type AnchorReading = {
|
|
54
|
+
readonly status: "anchored";
|
|
55
|
+
readonly attributes: AnchorAttributes;
|
|
56
|
+
} | {
|
|
57
|
+
readonly status: "unusable";
|
|
58
|
+
readonly detail: string;
|
|
59
|
+
} | {
|
|
60
|
+
readonly status: "claimed";
|
|
61
|
+
readonly anchor: string;
|
|
62
|
+
readonly holder: NodeId;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* The longest anchor a tree may name.
|
|
66
|
+
*
|
|
67
|
+
* A bound rather than a judgement about slugs: this is markup a model writes
|
|
68
|
+
* into the document, and every other place a proposal writes a string has one.
|
|
69
|
+
* Nothing legible reaches it — the longest anchor in this repository's own
|
|
70
|
+
* writing is a third of it.
|
|
71
|
+
*/
|
|
72
|
+
export declare const ANCHOR_MAX_LENGTH = 64;
|
|
73
|
+
/**
|
|
74
|
+
* Who holds each anchor in one render.
|
|
75
|
+
*
|
|
76
|
+
* Lives for exactly one walk. Two renders of the same tree must not be able to
|
|
77
|
+
* disagree about which node holds a slug because one of them ran first, which is
|
|
78
|
+
* the same reason the text seam keeps its merge cache in a closure rather than
|
|
79
|
+
* at module scope.
|
|
80
|
+
*/
|
|
81
|
+
export type AnchorLedger = {
|
|
82
|
+
/**
|
|
83
|
+
* Records this node as the holder, or answers with the node that got there
|
|
84
|
+
* first. First claim in document order wins: the walk reaches a node before
|
|
85
|
+
* its descendants and reads siblings in tree order, so the winner is a fact
|
|
86
|
+
* about the tree rather than about the order the renderer happened to visit.
|
|
87
|
+
*/
|
|
88
|
+
readonly claim: (anchor: string, nodeId: NodeId) => NodeId | undefined;
|
|
89
|
+
};
|
|
90
|
+
export declare const createAnchorLedger: () => AnchorLedger;
|
|
91
|
+
/**
|
|
92
|
+
* The whole check, as a function of a declared value and what is already taken.
|
|
93
|
+
*
|
|
94
|
+
* Total, like every other reading of something a model wrote: a number where a
|
|
95
|
+
* slug goes, a slug with a space in it, or a slug another node already holds all
|
|
96
|
+
* come back as a reading rather than as a thrown error. A page is not lost
|
|
97
|
+
* because a proposal named a bad anchor; it renders with one band that cannot be
|
|
98
|
+
* linked to, and says so.
|
|
99
|
+
*
|
|
100
|
+
* Claiming happens here rather than in the caller so that the check and the
|
|
101
|
+
* record of it cannot come apart — there is no order of operations in which a
|
|
102
|
+
* node is told it is anchored and the ledger does not know.
|
|
103
|
+
*/
|
|
104
|
+
export declare const resolveAnchor: (declared: JsonValue | undefined, nodeId: NodeId, ledger: AnchorLedger) => AnchorReading;
|
|
105
|
+
//# sourceMappingURL=anchor.d.ts.map
|