@jam-overture/loom 0.1.0 → 0.3.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/README.md +3 -1
- package/dist/application/application.d.ts +109 -0
- package/dist/application/application.js +97 -0
- package/dist/application/memory.d.ts +20 -0
- package/dist/application/memory.js +79 -0
- package/dist/application/store.d.ts +101 -0
- package/dist/application/store.js +25 -0
- package/dist/audience/audience.d.ts +36 -0
- package/dist/audience/audience.js +41 -0
- package/dist/audience/compose.d.ts +112 -0
- package/dist/audience/compose.js +134 -0
- package/dist/audience/memory.d.ts +14 -0
- package/dist/audience/memory.js +71 -0
- package/dist/audience/overlay-store.d.ts +343 -0
- package/dist/audience/overlay-store.js +217 -0
- package/dist/audience/rule.d.ts +121 -0
- package/dist/audience/rule.js +78 -0
- package/dist/cli/index.d.ts +3 -4
- package/dist/cli/index.js +3 -4
- package/dist/cli/templates.js +19 -0
- package/dist/data/adapter.d.ts +9 -1
- package/dist/data/adapter.js +2 -0
- package/dist/data/plan.js +0 -0
- package/dist/data/resolution.d.ts +23 -1
- package/dist/data/resolve.d.ts +31 -4
- package/dist/data/resolve.js +11 -3
- package/dist/ids.d.ts +10 -0
- package/dist/ids.js +11 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interpretation/anthropic.d.ts +1 -1
- package/dist/interpretation/anthropic.js +2 -22
- package/dist/interpretation/client.d.ts +1 -1
- package/dist/interpretation/materialize.js +67 -22
- package/dist/interpretation/openai-compatible.d.ts +36 -0
- package/dist/interpretation/openai-compatible.js +79 -0
- package/dist/interpretation/status.d.ts +19 -0
- package/dist/interpretation/status.js +26 -0
- package/dist/live/index.d.ts +73 -0
- package/dist/live/index.js +73 -0
- package/dist/live/pages.d.ts +187 -0
- package/dist/live/pages.js +161 -0
- package/dist/live/pull.d.ts +147 -0
- package/dist/live/pull.js +398 -0
- package/dist/live/pulling.d.ts +79 -0
- package/dist/live/pulling.js +117 -0
- package/dist/live/window.d.ts +129 -0
- package/dist/live/window.js +132 -0
- package/dist/patch.d.ts +54 -0
- package/dist/patch.js +44 -0
- package/dist/project/closing.d.ts +51 -0
- package/dist/project/closing.js +53 -0
- package/dist/project/memory.d.ts +20 -0
- package/dist/project/memory.js +97 -0
- package/dist/project/project.d.ts +90 -0
- package/dist/project/project.js +91 -0
- package/dist/project/store.d.ts +135 -0
- package/dist/project/store.js +41 -0
- package/dist/registered.d.ts +64 -0
- package/dist/registered.js +118 -0
- package/dist/render/addressed.d.ts +35 -0
- package/dist/render/addressed.js +79 -0
- package/dist/render/behaviour-adjust.d.ts +11 -19
- package/dist/render/behaviour-adjust.js +75 -21
- package/dist/render/behaviour-present.d.ts +8 -0
- package/dist/render/behaviour-present.js +57 -6
- package/dist/render/behaviour.d.ts +98 -17
- package/dist/render/behaviour.js +91 -26
- package/dist/render/control-name.d.ts +68 -0
- package/dist/render/control-name.js +37 -0
- package/dist/render/diagnostics.d.ts +72 -0
- package/dist/render/diagnostics.js +7 -0
- package/dist/render/document-theme.d.ts +70 -0
- package/dist/render/document-theme.js +139 -0
- package/dist/render/editable.d.ts +15 -1
- package/dist/render/editable.js +13 -1
- package/dist/render/expected.d.ts +98 -0
- package/dist/render/expected.js +88 -0
- package/dist/render/index.d.ts +4 -0
- package/dist/render/index.js +4 -0
- package/dist/render/reads.d.ts +11 -0
- package/dist/render/reads.js +12 -1
- package/dist/render/render.d.ts +11 -0
- package/dist/render/render.js +294 -53
- package/dist/render/request.d.ts +8 -1
- package/dist/render/request.js +1 -0
- package/dist/render/slots.d.ts +52 -0
- package/dist/render/slots.js +24 -0
- package/dist/render/theme.d.ts +54 -1
- package/dist/render/theme.js +23 -1
- package/dist/render/unshown.d.ts +152 -0
- package/dist/render/unshown.js +80 -0
- package/dist/runtime/analysis.d.ts +94 -9
- package/dist/runtime/analysis.js +54 -9
- package/dist/runtime/assessment.d.ts +36 -2
- package/dist/runtime/assessment.js +27 -2
- package/dist/runtime/auto-apply-ceiling.d.ts +54 -0
- package/dist/runtime/auto-apply-ceiling.js +66 -0
- package/dist/runtime/checks.d.ts +148 -0
- package/dist/runtime/checks.js +112 -0
- package/dist/runtime/disposition.d.ts +96 -0
- package/dist/runtime/disposition.js +46 -0
- package/dist/runtime/gate.js +91 -10
- package/dist/runtime/index.d.ts +4 -0
- package/dist/runtime/index.js +4 -0
- package/dist/runtime/irreversibility.d.ts +64 -0
- package/dist/runtime/irreversibility.js +45 -0
- package/dist/runtime/nesting.d.ts +13 -1
- package/dist/runtime/nesting.js +41 -24
- package/dist/runtime/pipeline.d.ts +43 -0
- package/dist/runtime/pipeline.js +10 -2
- package/dist/runtime/policy-change.d.ts +93 -0
- package/dist/runtime/policy-change.js +305 -0
- package/dist/runtime/policy-log.d.ts +406 -0
- package/dist/runtime/policy-log.js +285 -0
- package/dist/runtime/policy.d.ts +8 -6
- package/dist/runtime/policy.js +5 -2
- package/dist/runtime/repointing.js +0 -0
- package/dist/runtime/reversibility.d.ts +11 -9
- package/dist/runtime/stakes.d.ts +129 -1
- package/dist/runtime/stakes.js +240 -26
- package/dist/runtime/vocabulary.d.ts +164 -7
- package/dist/runtime/vocabulary.js +181 -8
- package/dist/sdk/audit.d.ts +174 -3
- package/dist/sdk/audit.js +176 -17
- package/dist/sdk/catalogue.d.ts +9 -1
- package/dist/sdk/conformance.d.ts +37 -3
- package/dist/sdk/conformance.js +25 -4
- package/dist/sdk/definition.d.ts +129 -5
- package/dist/sdk/definition.js +66 -0
- package/dist/sdk/registry.d.ts +45 -2
- package/dist/sdk/registry.js +102 -1
- package/dist/signals/acted.contract.d.ts +21 -0
- package/dist/signals/acted.contract.js +236 -0
- package/dist/signals/acted.d.ts +359 -0
- package/dist/signals/acted.js +135 -0
- package/dist/signals/action-change.d.ts +507 -0
- package/dist/signals/action-change.js +265 -0
- package/dist/signals/action.d.ts +331 -0
- package/dist/signals/action.js +182 -0
- package/dist/signals/agenda.d.ts +585 -0
- package/dist/signals/agenda.js +295 -0
- package/dist/signals/applied-window.contract.d.ts +23 -0
- package/dist/signals/applied-window.contract.js +160 -0
- package/dist/signals/arrivals.contract.d.ts +21 -0
- package/dist/signals/arrivals.contract.js +180 -0
- package/dist/signals/arrivals.d.ts +375 -0
- package/dist/signals/arrivals.js +254 -0
- package/dist/signals/arriving.d.ts +210 -0
- package/dist/signals/arriving.js +133 -0
- package/dist/signals/audiences.d.ts +528 -0
- package/dist/signals/audiences.js +255 -0
- package/dist/signals/broadcast.d.ts +33 -17
- package/dist/signals/broadcast.js +255 -32
- package/dist/signals/change.d.ts +378 -0
- package/dist/signals/change.js +327 -0
- package/dist/signals/collect.d.ts +169 -34
- package/dist/signals/collect.js +186 -38
- package/dist/signals/conversion.d.ts +348 -0
- package/dist/signals/conversion.js +235 -0
- package/dist/signals/copy-change.d.ts +553 -0
- package/dist/signals/copy-change.js +377 -0
- package/dist/signals/copy.d.ts +337 -0
- package/dist/signals/copy.js +211 -0
- package/dist/signals/correlated.contract.d.ts +24 -0
- package/dist/signals/correlated.contract.js +94 -0
- package/dist/signals/counters.d.ts +97 -0
- package/dist/signals/counters.js +160 -0
- package/dist/signals/deliver.d.ts +23 -4
- package/dist/signals/deliver.js +34 -6
- package/dist/signals/deployment-change.d.ts +395 -0
- package/dist/signals/deployment-change.js +309 -0
- package/dist/signals/deployment.d.ts +278 -0
- package/dist/signals/deployment.js +178 -0
- package/dist/signals/door.d.ts +114 -0
- package/dist/signals/door.js +77 -0
- package/dist/signals/expire.d.ts +192 -0
- package/dist/signals/expire.js +213 -0
- package/dist/signals/fold.d.ts +10 -0
- package/dist/signals/fold.js +5 -1
- package/dist/signals/form-action.d.ts +302 -0
- package/dist/signals/form-action.js +169 -0
- package/dist/signals/form-copy.d.ts +523 -0
- package/dist/signals/form-copy.js +346 -0
- package/dist/signals/forms.d.ts +247 -0
- package/dist/signals/forms.js +147 -0
- package/dist/signals/frontier.d.ts +268 -0
- package/dist/signals/frontier.js +145 -0
- package/dist/signals/funnel-change.d.ts +548 -0
- package/dist/signals/funnel-change.js +361 -0
- package/dist/signals/funnel-hours.contract.d.ts +21 -0
- package/dist/signals/funnel-hours.contract.js +221 -0
- package/dist/signals/funnel-hours.d.ts +293 -0
- package/dist/signals/funnel-hours.js +99 -0
- package/dist/signals/funnel.d.ts +592 -0
- package/dist/signals/funnel.js +231 -0
- package/dist/signals/health.d.ts +694 -0
- package/dist/signals/health.js +573 -0
- package/dist/signals/index.d.ts +60 -0
- package/dist/signals/index.js +60 -0
- package/dist/signals/ingest.d.ts +56 -1
- package/dist/signals/ingest.js +91 -1
- package/dist/signals/inside.d.ts +190 -0
- package/dist/signals/inside.js +263 -0
- package/dist/signals/join.d.ts +56 -0
- package/dist/signals/join.js +60 -0
- package/dist/signals/journal.d.ts +123 -9
- package/dist/signals/kept.contract.d.ts +22 -0
- package/dist/signals/kept.contract.js +111 -0
- package/dist/signals/kinds.d.ts +8 -6
- package/dist/signals/kinds.js +14 -6
- package/dist/signals/library-action.d.ts +430 -0
- package/dist/signals/library-action.js +336 -0
- package/dist/signals/library-agenda-change.d.ts +324 -0
- package/dist/signals/library-agenda-change.js +199 -0
- package/dist/signals/library-agenda.d.ts +258 -0
- package/dist/signals/library-agenda.js +167 -0
- package/dist/signals/library-change.d.ts +477 -0
- package/dist/signals/library-change.js +335 -0
- package/dist/signals/library-copy-change.d.ts +498 -0
- package/dist/signals/library-copy-change.js +476 -0
- package/dist/signals/library-pace.d.ts +319 -0
- package/dist/signals/library-pace.js +305 -0
- package/dist/signals/library-reach-change.d.ts +646 -0
- package/dist/signals/library-reach-change.js +542 -0
- package/dist/signals/library-reach.d.ts +377 -0
- package/dist/signals/library-reach.js +227 -0
- package/dist/signals/library-senders-change.d.ts +457 -0
- package/dist/signals/library-senders-change.js +367 -0
- package/dist/signals/library-senders-reach-change.d.ts +486 -0
- package/dist/signals/library-senders-reach-change.js +538 -0
- package/dist/signals/library-senders-reach.d.ts +340 -0
- package/dist/signals/library-senders-reach.js +252 -0
- package/dist/signals/library-senders.d.ts +271 -0
- package/dist/signals/library-senders.js +180 -0
- package/dist/signals/library-word-reach-change.d.ts +567 -0
- package/dist/signals/library-word-reach-change.js +564 -0
- package/dist/signals/library.d.ts +306 -0
- package/dist/signals/library.js +178 -0
- package/dist/signals/memory.d.ts +9 -0
- package/dist/signals/memory.js +246 -14
- package/dist/signals/migrate.d.ts +20 -4
- package/dist/signals/migrate.js +269 -8
- package/dist/signals/notice.d.ts +389 -0
- package/dist/signals/notice.js +250 -0
- package/dist/signals/pace-change.d.ts +501 -0
- package/dist/signals/pace-change.js +310 -0
- package/dist/signals/pace.d.ts +296 -0
- package/dist/signals/pace.js +291 -0
- package/dist/signals/page-views.d.ts +365 -0
- package/dist/signals/page-views.js +218 -0
- package/dist/signals/part-pace.d.ts +378 -0
- package/dist/signals/part-pace.js +333 -0
- package/dist/signals/parts.d.ts +354 -0
- package/dist/signals/parts.js +232 -0
- package/dist/signals/postgres.d.ts +16 -2
- package/dist/signals/postgres.js +753 -76
- package/dist/signals/progress.d.ts +212 -0
- package/dist/signals/progress.js +150 -0
- package/dist/signals/ratios.d.ts +108 -0
- package/dist/signals/ratios.js +40 -0
- package/dist/signals/reach.d.ts +309 -0
- package/dist/signals/reach.js +93 -0
- package/dist/signals/readable.d.ts +34 -0
- package/dist/signals/readable.js +34 -0
- package/dist/signals/readership.d.ts +381 -0
- package/dist/signals/readership.js +308 -0
- package/dist/signals/region-pages.d.ts +173 -0
- package/dist/signals/region-pages.js +62 -0
- package/dist/signals/region.d.ts +287 -0
- package/dist/signals/region.js +198 -0
- package/dist/signals/retention.d.ts +163 -0
- package/dist/signals/retention.js +75 -0
- package/dist/signals/rhythm.d.ts +302 -0
- package/dist/signals/rhythm.js +262 -0
- package/dist/signals/rollup.d.ts +194 -4
- package/dist/signals/rollup.js +0 -0
- package/dist/signals/schema.d.ts +1069 -1
- package/dist/signals/schema.js +393 -3
- package/dist/signals/signal.d.ts +237 -11
- package/dist/signals/signal.js +70 -10
- package/dist/signals/silence-census.d.ts +205 -0
- package/dist/signals/silence-census.js +87 -0
- package/dist/signals/silences.d.ts +1147 -0
- package/dist/signals/silences.js +996 -0
- package/dist/signals/subtrees.d.ts +123 -0
- package/dist/signals/subtrees.js +102 -0
- package/dist/signals/tally.d.ts +262 -12
- package/dist/signals/unread.d.ts +292 -0
- package/dist/signals/unread.js +137 -0
- package/dist/signals/window-agenda.d.ts +276 -0
- package/dist/signals/window-agenda.js +83 -0
- package/dist/signals/window-figures.d.ts +148 -0
- package/dist/signals/window-figures.js +42 -0
- package/dist/signals/window-funnels.d.ts +88 -0
- package/dist/signals/window-funnels.js +47 -0
- package/dist/signals/window.d.ts +866 -0
- package/dist/signals/window.js +693 -0
- package/dist/signals/words.d.ts +24 -0
- package/dist/signals/words.js +24 -0
- package/dist/store/cache.d.ts +101 -0
- package/dist/store/cache.js +149 -0
- package/dist/store/history.d.ts +82 -0
- package/dist/store/history.js +36 -0
- package/dist/store/index.d.ts +30 -0
- package/dist/store/index.js +30 -0
- package/dist/store/memory.d.ts +2 -1
- package/dist/store/memory.js +48 -12
- package/dist/store/migrate.d.ts +106 -0
- package/dist/store/migrate.js +323 -7
- package/dist/store/postgres-applications.d.ts +4 -0
- package/dist/store/postgres-applications.js +197 -0
- package/dist/store/postgres-audience.d.ts +14 -0
- package/dist/store/postgres-audience.js +272 -0
- package/dist/store/postgres-holds.d.ts +10 -1
- package/dist/store/postgres-holds.js +116 -101
- package/dist/store/postgres-policy-log.d.ts +14 -0
- package/dist/store/postgres-policy-log.js +240 -0
- package/dist/store/postgres-projects.d.ts +4 -0
- package/dist/store/postgres-projects.js +217 -0
- package/dist/store/postgres.d.ts +17 -1
- package/dist/store/postgres.js +60 -9
- package/dist/store/replay.d.ts +102 -1
- package/dist/store/replay.js +190 -19
- package/dist/store/reseed.d.ts +238 -0
- package/dist/store/reseed.js +308 -0
- package/dist/store/schema.d.ts +762 -2
- package/dist/store/schema.js +218 -5
- package/dist/store/source.d.ts +57 -1
- package/dist/store/source.js +65 -1
- package/dist/store/store.d.ts +29 -6
- package/dist/submit/resolve.d.ts +1 -1
- package/dist/submit/resolve.js +2 -1
- package/dist/telemetry/calibration.d.ts +25 -0
- package/dist/telemetry/calibration.js +27 -1
- package/dist/telemetry/event.d.ts +391 -33
- package/dist/telemetry/event.js +84 -20
- package/dist/telemetry/index.d.ts +2 -0
- package/dist/telemetry/index.js +2 -0
- package/dist/telemetry/journal.d.ts +104 -3
- package/dist/telemetry/journal.js +9 -0
- package/dist/telemetry/lookup.d.ts +27 -0
- package/dist/telemetry/lookup.js +18 -0
- package/dist/telemetry/memory.js +33 -1
- package/dist/telemetry/migrate.js +22 -1
- package/dist/telemetry/postgres.d.ts +10 -1
- package/dist/telemetry/postgres.js +188 -90
- package/dist/telemetry/remeasure.d.ts +78 -0
- package/dist/telemetry/remeasure.js +83 -0
- package/dist/telemetry/retention.d.ts +2 -2
- package/dist/telemetry/schema.d.ts +17 -0
- package/dist/telemetry/schema.js +27 -1
- package/dist/telemetry/sink.d.ts +2 -2
- package/dist/telemetry/window.d.ts +135 -0
- package/dist/telemetry/window.js +101 -0
- package/dist/testing/application-contract.d.ts +14 -0
- package/dist/testing/application-contract.js +270 -0
- package/dist/testing/audience-overlay-contract.d.ts +31 -0
- package/dist/testing/audience-overlay-contract.js +354 -0
- package/dist/testing/contracts.d.ts +13 -7
- package/dist/testing/contracts.js +13 -7
- package/dist/testing/definitions.d.ts +78 -0
- package/dist/testing/definitions.js +134 -9
- package/dist/testing/doubles.d.ts +103 -0
- package/dist/testing/doubles.js +143 -0
- package/dist/testing/index.d.ts +2 -2
- package/dist/testing/index.js +2 -2
- package/dist/testing/journal-contract.js +297 -6
- package/dist/testing/model-contract.d.ts +110 -0
- package/dist/testing/model-contract.js +150 -0
- package/dist/testing/policy-log-contract.d.ts +26 -0
- package/dist/testing/policy-log-contract.js +344 -0
- package/dist/testing/project-contract.d.ts +14 -0
- package/dist/testing/project-contract.js +266 -0
- package/dist/testing/reader-signal-contract.d.ts +27 -2
- package/dist/testing/reader-signal-contract.js +475 -5
- package/dist/testing/store-contract.d.ts +7 -1
- package/dist/testing/store-contract.js +84 -3
- package/dist/theme/apply.d.ts +20 -1
- package/dist/theme/apply.js +5 -3
- package/dist/theme/contrast.d.ts +19 -14
- package/dist/theme/contrast.js +181 -17
- package/dist/theme/derive.d.ts +22 -0
- package/dist/theme/derive.js +54 -1
- package/dist/theme/library.js +1 -1
- package/dist/theme/measure.d.ts +34 -0
- package/dist/theme/measure.js +30 -1
- package/dist/theme/palettes.js +7 -7
- package/dist/theme/ramp.d.ts +64 -0
- package/dist/theme/ramp.js +114 -0
- package/dist/theme/registry.d.ts +9 -0
- package/dist/theme/registry.js +11 -1
- package/dist/theme/separation.d.ts +97 -3
- package/dist/theme/separation.js +75 -0
- package/dist/tree/apply.js +13 -0
- package/dist/tree/compare.d.ts +9 -0
- package/dist/tree/compare.js +18 -0
- package/dist/tree/mutation.d.ts +18 -0
- package/dist/tree/mutation.js +24 -12
- package/dist/tree/navigation.d.ts +5 -0
- package/dist/tree/navigation.js +32 -10
- package/dist/tree/outline.d.ts +7 -0
- package/dist/tree/outline.js +9 -5
- package/dist/write/computed.d.ts +60 -0
- package/dist/write/computed.js +61 -0
- package/dist/write/held.d.ts +59 -0
- package/dist/write/index.d.ts +5 -2
- package/dist/write/index.js +5 -2
- package/dist/write/reseed.d.ts +151 -0
- package/dist/write/reseed.js +184 -0
- package/dist/write/revert.js +2 -16
- package/package.json +25 -3
- package/dist/runtime/inverse-interpreter.d.ts +0 -90
- package/dist/runtime/inverse-interpreter.js +0 -56
package/dist/ids.js
CHANGED
|
@@ -40,11 +40,21 @@ export const proposalIdSchema = z
|
|
|
40
40
|
.brand();
|
|
41
41
|
const RANDOM_ID_LENGTH = 20;
|
|
42
42
|
const BASE36_ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";
|
|
43
|
-
|
|
43
|
+
/**
|
|
44
|
+
* The body of a random id, which is the part after the prefix.
|
|
45
|
+
*
|
|
46
|
+
* Exported because an application id and a project id are minted outside this
|
|
47
|
+
* module — by the control plane when somebody registers, rather than by an
|
|
48
|
+
* `IdFactory` during a render — and the alternative was either widening that
|
|
49
|
+
* interface with two members no renderer calls, or a second copy of this that
|
|
50
|
+
* drifts.
|
|
51
|
+
*/
|
|
52
|
+
export const randomIdBody = () => {
|
|
44
53
|
const bytes = new Uint8Array(RANDOM_ID_LENGTH);
|
|
45
54
|
globalThis.crypto.getRandomValues(bytes);
|
|
46
55
|
return Array.from(bytes, (byte) => BASE36_ALPHABET[byte % BASE36_ALPHABET.length] ?? "0").join("");
|
|
47
56
|
};
|
|
57
|
+
const randomBody = randomIdBody;
|
|
48
58
|
export const randomIdFactory = {
|
|
49
59
|
nodeId: () => nodeIdSchema.parse(`n_${randomBody()}`),
|
|
50
60
|
treeId: () => treeIdSchema.parse(`t_${randomBody()}`),
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./interactivity.js";
|
|
|
15
15
|
export * from "./interpretation/index.js";
|
|
16
16
|
export * from "./json.js";
|
|
17
17
|
export * from "./paging.js";
|
|
18
|
+
export * from "./patch.js";
|
|
18
19
|
export * from "./primitive-type.js";
|
|
19
20
|
export * from "./reserved-props.js";
|
|
20
21
|
export * from "./result.js";
|
package/dist/index.js
CHANGED
|
@@ -15,6 +15,7 @@ export * from "./interactivity.js";
|
|
|
15
15
|
export * from "./interpretation/index.js";
|
|
16
16
|
export * from "./json.js";
|
|
17
17
|
export * from "./paging.js";
|
|
18
|
+
export * from "./patch.js";
|
|
18
19
|
export * from "./primitive-type.js";
|
|
19
20
|
export * from "./reserved-props.js";
|
|
20
21
|
export * from "./result.js";
|
|
@@ -15,7 +15,7 @@ import type { ModelClient } from "./client.js";
|
|
|
15
15
|
*/
|
|
16
16
|
export type AnthropicMessages = {
|
|
17
17
|
readonly create: (params: Anthropic.MessageCreateParamsNonStreaming, options?: {
|
|
18
|
-
readonly signal?: AbortSignal;
|
|
18
|
+
readonly signal?: AbortSignal | undefined;
|
|
19
19
|
}) => Promise<Anthropic.Message>;
|
|
20
20
|
};
|
|
21
21
|
export declare const anthropicModelClient: (messages: AnthropicMessages) => ModelClient;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { err, ok } from "../result.js";
|
|
2
|
+
import { classifyStatus } from "./status.js";
|
|
2
3
|
const firstTextBlock = (message) => message.content.find((block) => block.type === "text")?.text;
|
|
3
4
|
const errorDetail = (cause) => cause instanceof Error ? cause.message : "unknown transport failure";
|
|
4
5
|
/**
|
|
@@ -12,27 +13,6 @@ const statusOf = (cause) => {
|
|
|
12
13
|
const { status } = cause;
|
|
13
14
|
return typeof status === "number" ? status : undefined;
|
|
14
15
|
};
|
|
15
|
-
/**
|
|
16
|
-
* Which of the three "could not answer" codes a thrown error is.
|
|
17
|
-
*
|
|
18
|
-
* Only a status we positively recognise as this side's fault becomes `rejected`
|
|
19
|
-
* or `misconfigured`; everything else — including a transport failure that
|
|
20
|
-
* never got a response — stays `unavailable`. Guessing wrong in that direction
|
|
21
|
-
* costs a retry that fails, where guessing wrong the other way tells a host to
|
|
22
|
-
* stop trying something that would have worked.
|
|
23
|
-
*
|
|
24
|
-
* 408, 409 and 429 are the 4xx statuses that mean "later", and the SDK has
|
|
25
|
-
* already retried them twice by the time one reaches here, so a 429 that
|
|
26
|
-
* escapes is a rate limit that outlasted the client's own backoff.
|
|
27
|
-
*/
|
|
28
|
-
const classifyThrown = (status) => {
|
|
29
|
-
if (status === undefined)
|
|
30
|
-
return "unavailable";
|
|
31
|
-
if (status === 401 || status === 402 || status === 403)
|
|
32
|
-
return "misconfigured";
|
|
33
|
-
const asksAgainLater = status === 408 || status === 409 || status === 429;
|
|
34
|
-
return status >= 400 && status < 500 && !asksAgainLater ? "rejected" : "unavailable";
|
|
35
|
-
};
|
|
36
16
|
const toCompletion = (message) => {
|
|
37
17
|
if (message.stop_reason === "refusal") {
|
|
38
18
|
return err({ code: "refused", detail: message.stop_details?.category ?? "unspecified" });
|
|
@@ -69,7 +49,7 @@ export const anthropicModelClient = (messages) => ({
|
|
|
69
49
|
return toCompletion(message);
|
|
70
50
|
}
|
|
71
51
|
catch (cause) {
|
|
72
|
-
return err({ code:
|
|
52
|
+
return err({ code: classifyStatus(statusOf(cause)), detail: errorDetail(cause) });
|
|
73
53
|
}
|
|
74
54
|
},
|
|
75
55
|
});
|
|
@@ -28,7 +28,7 @@ export type ModelRequest = {
|
|
|
28
28
|
* ignoring it is the connection it is holding, which nobody is going to read.
|
|
29
29
|
*/
|
|
30
30
|
export type ModelCallOptions = {
|
|
31
|
-
readonly signal?: AbortSignal;
|
|
31
|
+
readonly signal?: AbortSignal | undefined;
|
|
32
32
|
};
|
|
33
33
|
export type ModelCompletion = {
|
|
34
34
|
/** The reply body, expected to be JSON matching `outputSchema`. */
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { jsonObjectSchema } from "../json.js";
|
|
2
|
-
import { assertNever, err, ok
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { assertNever, err, ok } from "../result.js";
|
|
3
|
+
/**
|
|
4
|
+
* Every item mapped, in order, stopping at the first failure.
|
|
5
|
+
*
|
|
6
|
+
* It appends to one array rather than spreading the accumulated values per item
|
|
7
|
+
* (0380). The spread made this the product of the list's length and itself, on
|
|
8
|
+
* both lists it is used for. Children of one parent: 8,000 cost 70 ms, 16,000
|
|
9
|
+
* cost 690 and 32,000 cost 4,704. Operations in one reply: 8,000 cost 61 ms and
|
|
10
|
+
* 16,000 cost 783. **How long either list is, is the model's choice.**
|
|
11
|
+
*/
|
|
12
|
+
const collectResults = (items, map) => {
|
|
13
|
+
const collected = [];
|
|
14
|
+
for (const item of items) {
|
|
15
|
+
const mapped = map(item);
|
|
16
|
+
if (!mapped.ok)
|
|
17
|
+
return mapped;
|
|
18
|
+
collected.push(mapped.value);
|
|
19
|
+
}
|
|
20
|
+
return ok(collected);
|
|
21
|
+
};
|
|
7
22
|
const parseJson = (text) => {
|
|
8
23
|
try {
|
|
9
24
|
return ok(JSON.parse(text));
|
|
@@ -41,28 +56,58 @@ export const decodeProps = (encoded) => {
|
|
|
41
56
|
const validated = jsonObjectSchema.safeParse(parsed.value);
|
|
42
57
|
return validated.success ? ok(validated.data) : err("props contain a value that is not JSON");
|
|
43
58
|
};
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
/**
|
|
60
|
+
* A draft becomes a tree without a call frame per level (0380).
|
|
61
|
+
*
|
|
62
|
+
* **The order two things happen in is observable, and both are preserved.**
|
|
63
|
+
* Props are decoded on the way down, so an element with an unreadable bag is
|
|
64
|
+
* refused before anything below it is looked at and its message is the one the
|
|
65
|
+
* caller gets. Ids are minted on the way *up* — every child before its parent,
|
|
66
|
+
* in document order — because that is the order the recursion minted them in
|
|
67
|
+
* and a node's id is in the delta the proposer gets back.
|
|
68
|
+
*
|
|
69
|
+
* The depth of a reply is the model's choice. This answered `RangeError` at two
|
|
70
|
+
* thousand deep — second-shallowest in the framework, behind the render walk's
|
|
71
|
+
* thousand, and both outlived 0372 and 0373 by sitting outside `src/tree/`.
|
|
72
|
+
*/
|
|
73
|
+
const materializeNode = (root, idFactory) => {
|
|
74
|
+
const work = [{ step: "read", node: root }];
|
|
75
|
+
const finished = [];
|
|
76
|
+
for (let next = work.pop(); next !== undefined; next = work.pop()) {
|
|
77
|
+
if (next.step === "build") {
|
|
78
|
+
finished.push({
|
|
56
79
|
kind: "element",
|
|
57
80
|
id: idFactory.nodeId(),
|
|
58
|
-
type: node.type,
|
|
59
|
-
props: props
|
|
60
|
-
children: children.
|
|
81
|
+
type: next.node.type,
|
|
82
|
+
props: next.props,
|
|
83
|
+
children: finished.splice(finished.length - next.children, next.children),
|
|
61
84
|
});
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const node = next.node;
|
|
88
|
+
switch (node.kind) {
|
|
89
|
+
case "text":
|
|
90
|
+
finished.push({ kind: "text", id: idFactory.nodeId(), value: node.value });
|
|
91
|
+
break;
|
|
92
|
+
case "element": {
|
|
93
|
+
const props = decodeProps(node.props);
|
|
94
|
+
if (!props.ok)
|
|
95
|
+
return props;
|
|
96
|
+
work.push({ step: "build", node, props: props.value, children: node.children.length });
|
|
97
|
+
for (let index = node.children.length - 1; index >= 0; index -= 1) {
|
|
98
|
+
const child = node.children[index];
|
|
99
|
+
if (child)
|
|
100
|
+
work.push({ step: "read", node: child });
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
default:
|
|
105
|
+
return assertNever(node, "materializeNode");
|
|
62
106
|
}
|
|
63
|
-
default:
|
|
64
|
-
return assertNever(node, "materializeNode");
|
|
65
107
|
}
|
|
108
|
+
const built = finished[0];
|
|
109
|
+
/** Unreachable: one node in, one node out, and a failure returned above. */
|
|
110
|
+
return built ? ok(built) : err("a draft node materialized to nothing");
|
|
66
111
|
};
|
|
67
112
|
const materializeOperation = (operation, idFactory) => {
|
|
68
113
|
switch (operation.op) {
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ModelClient } from "./client.js";
|
|
2
|
+
/**
|
|
3
|
+
* The adapter for any server that speaks the OpenAI-compatible chat API with
|
|
4
|
+
* JSON-schema replies: vLLM, llama.cpp's server, Ollama, and the hosted
|
|
5
|
+
* services that serve open models the same way. Like `anthropic.ts` it is an
|
|
6
|
+
* entry point of its own, not exported from the package root (0005), and its
|
|
7
|
+
* whole job is translation.
|
|
8
|
+
*
|
|
9
|
+
* It takes `fetch` rather than a vendor SDK, so it adds no dependency, and so
|
|
10
|
+
* a host decides what the network may reach: the portal hands it a `fetch`
|
|
11
|
+
* that refuses private addresses (0421 clause 6).
|
|
12
|
+
*
|
|
13
|
+
* `effort` has no counterpart in this API that every such server honours, so
|
|
14
|
+
* it is not sent. A server that cannot hold to the schema answers with text
|
|
15
|
+
* the interpreter cannot parse, which it already reports as a malformed reply.
|
|
16
|
+
*/
|
|
17
|
+
/** The part of `fetch` this adapter uses, so a host can hand it a guarded one and a test a stub. */
|
|
18
|
+
export type CompatibleFetch = (url: string, init: {
|
|
19
|
+
readonly method: "POST";
|
|
20
|
+
readonly headers: Readonly<Record<string, string>>;
|
|
21
|
+
readonly body: string;
|
|
22
|
+
readonly redirect: "error";
|
|
23
|
+
readonly signal?: AbortSignal | undefined;
|
|
24
|
+
}) => Promise<{
|
|
25
|
+
readonly status: number;
|
|
26
|
+
readonly json: () => Promise<unknown>;
|
|
27
|
+
}>;
|
|
28
|
+
export type OpenAiCompatibleConfig = {
|
|
29
|
+
/** The server's API root, such as `https://models.example.com/v1`; `/chat/completions` is added. */
|
|
30
|
+
readonly endpoint: string;
|
|
31
|
+
/** Sent as a bearer token where the server asks for one. */
|
|
32
|
+
readonly apiKey?: string | undefined;
|
|
33
|
+
readonly fetch: CompatibleFetch;
|
|
34
|
+
};
|
|
35
|
+
export declare const openAiCompatibleModelClient: (config: OpenAiCompatibleConfig) => ModelClient;
|
|
36
|
+
//# sourceMappingURL=openai-compatible.d.ts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { err, ok } from "../result.js";
|
|
3
|
+
import { classifyStatus } from "./status.js";
|
|
4
|
+
const replySchema = z.object({
|
|
5
|
+
model: z.string().optional(),
|
|
6
|
+
choices: z
|
|
7
|
+
.array(z.object({
|
|
8
|
+
finish_reason: z.string().nullable().optional(),
|
|
9
|
+
message: z.object({
|
|
10
|
+
content: z.string().nullable().optional(),
|
|
11
|
+
refusal: z.string().nullable().optional(),
|
|
12
|
+
}),
|
|
13
|
+
}))
|
|
14
|
+
.min(1),
|
|
15
|
+
});
|
|
16
|
+
/** What a reply the server finished says, as a completion or the reason it is not one. Pure. */
|
|
17
|
+
const completionOf = (reply, asked) => {
|
|
18
|
+
const [choice] = reply.choices;
|
|
19
|
+
if (choice === undefined)
|
|
20
|
+
return err({ code: "incomplete", detail: "reply had no choices" });
|
|
21
|
+
const refusal = choice.message.refusal ?? undefined;
|
|
22
|
+
if (refusal !== undefined || choice.finish_reason === "content_filter") {
|
|
23
|
+
return err({ code: "refused", detail: refusal ?? "content_filter" });
|
|
24
|
+
}
|
|
25
|
+
if (choice.finish_reason === "length") {
|
|
26
|
+
return err({ code: "incomplete", detail: "hit the output token ceiling" });
|
|
27
|
+
}
|
|
28
|
+
const text = choice.message.content ?? undefined;
|
|
29
|
+
if (text === undefined || text === "") {
|
|
30
|
+
return err({ code: "incomplete", detail: "reply contained no text" });
|
|
31
|
+
}
|
|
32
|
+
return ok({ text, servedBy: reply.model ?? asked });
|
|
33
|
+
};
|
|
34
|
+
/** The request body, as the chat API spells it. Pure. */
|
|
35
|
+
const bodyOf = (request) => JSON.stringify({
|
|
36
|
+
model: request.model,
|
|
37
|
+
max_tokens: request.maxTokens,
|
|
38
|
+
messages: [
|
|
39
|
+
{ role: "system", content: request.system },
|
|
40
|
+
{ role: "user", content: request.userMessage },
|
|
41
|
+
],
|
|
42
|
+
response_format: {
|
|
43
|
+
type: "json_schema",
|
|
44
|
+
json_schema: { name: "loom_reply", schema: request.outputSchema, strict: true },
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
const errorDetail = (cause) => cause instanceof Error ? cause.message : "unknown transport failure";
|
|
48
|
+
export const openAiCompatibleModelClient = (config) => {
|
|
49
|
+
const url = `${config.endpoint.replace(/\/+$/u, "")}/chat/completions`;
|
|
50
|
+
const headers = {
|
|
51
|
+
"content-type": "application/json",
|
|
52
|
+
...(config.apiKey === undefined ? {} : { authorization: `Bearer ${config.apiKey}` }),
|
|
53
|
+
};
|
|
54
|
+
return {
|
|
55
|
+
complete: async (request, options) => {
|
|
56
|
+
try {
|
|
57
|
+
const response = await config.fetch(url, {
|
|
58
|
+
method: "POST",
|
|
59
|
+
headers,
|
|
60
|
+
body: bodyOf(request),
|
|
61
|
+
/** A server that redirects is answered as one that refused, never followed (0421). */
|
|
62
|
+
redirect: "error",
|
|
63
|
+
signal: options?.signal,
|
|
64
|
+
});
|
|
65
|
+
if (response.status < 200 || response.status >= 300) {
|
|
66
|
+
return err({ code: classifyStatus(response.status), detail: `status ${response.status}` });
|
|
67
|
+
}
|
|
68
|
+
const reply = replySchema.safeParse(await response.json());
|
|
69
|
+
return reply.success
|
|
70
|
+
? completionOf(reply.data, request.model)
|
|
71
|
+
: err({ code: "incomplete", detail: "reply was not a chat completion" });
|
|
72
|
+
}
|
|
73
|
+
catch (cause) {
|
|
74
|
+
return err({ code: "unavailable", detail: errorDetail(cause) });
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=openai-compatible.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an HTTP status from a model's service means for the caller, shared by
|
|
3
|
+
* every adapter so that a 429 means the same thing whichever vendor sent it.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Which of the three "could not answer" codes a failed call is, by its status.
|
|
7
|
+
*
|
|
8
|
+
* Only a status we positively recognise as this side's fault becomes `rejected`
|
|
9
|
+
* or `misconfigured`; everything else — including a transport failure that
|
|
10
|
+
* never got a response — stays `unavailable`. Guessing wrong in that direction
|
|
11
|
+
* costs a retry that fails, where guessing wrong the other way tells a host to
|
|
12
|
+
* stop trying something that would have worked.
|
|
13
|
+
*
|
|
14
|
+
* 408, 409 and 429 are the 4xx statuses that mean "later". The Anthropic SDK
|
|
15
|
+
* has already retried them twice by the time one reaches here, so a 429 that
|
|
16
|
+
* escapes it is a rate limit that outlasted the client's own backoff.
|
|
17
|
+
*/
|
|
18
|
+
export declare const classifyStatus: (status: number | undefined) => "unavailable" | "rejected" | "misconfigured";
|
|
19
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an HTTP status from a model's service means for the caller, shared by
|
|
3
|
+
* every adapter so that a 429 means the same thing whichever vendor sent it.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Which of the three "could not answer" codes a failed call is, by its status.
|
|
7
|
+
*
|
|
8
|
+
* Only a status we positively recognise as this side's fault becomes `rejected`
|
|
9
|
+
* or `misconfigured`; everything else — including a transport failure that
|
|
10
|
+
* never got a response — stays `unavailable`. Guessing wrong in that direction
|
|
11
|
+
* costs a retry that fails, where guessing wrong the other way tells a host to
|
|
12
|
+
* stop trying something that would have worked.
|
|
13
|
+
*
|
|
14
|
+
* 408, 409 and 429 are the 4xx statuses that mean "later". The Anthropic SDK
|
|
15
|
+
* has already retried them twice by the time one reaches here, so a 429 that
|
|
16
|
+
* escapes it is a rate limit that outlasted the client's own backoff.
|
|
17
|
+
*/
|
|
18
|
+
export const classifyStatus = (status) => {
|
|
19
|
+
if (status === undefined)
|
|
20
|
+
return "unavailable";
|
|
21
|
+
if (status === 401 || status === 402 || status === 403)
|
|
22
|
+
return "misconfigured";
|
|
23
|
+
const asksAgainLater = status === 408 || status === 409 || status === 429;
|
|
24
|
+
return status >= 400 && status < 500 && !asksAgainLater ? "rejected" : "unavailable";
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The half of going live that runs in the customer's server.
|
|
3
|
+
*
|
|
4
|
+
* A change accepted in the portal is live as soon as the site next pulls
|
|
5
|
+
* (0358): there is no pull request, no merge and no deploy between somebody
|
|
6
|
+
* accepting a change and a reader seeing it. What makes that true is this —
|
|
7
|
+
* a loop that fetches the project's live pages from Loom on a short interval,
|
|
8
|
+
* keeps them in the process, and hands one to the render path by page id.
|
|
9
|
+
*
|
|
10
|
+
* Three properties hold by construction rather than by care, and each has a
|
|
11
|
+
* test that would fail if it stopped:
|
|
12
|
+
*
|
|
13
|
+
* - **Loom is in the render path once per server, and only until it answers**
|
|
14
|
+
* (0262, 0364). The first reader on a new server waits for the first pull,
|
|
15
|
+
* so they get the live page rather than one that changes on their next
|
|
16
|
+
* request; a failed pull ends the wait at once and a silent Loom ends it after
|
|
17
|
+
* `DEFAULT_FIRST_WAIT_MS`. Every pull after that runs beside requests, on a
|
|
18
|
+
* timer, and no reader waits on it.
|
|
19
|
+
* - **Loom never learns who a reader is.** The request carries the project's
|
|
20
|
+
* key and the tag of what is held, and nothing else. The door answers every
|
|
21
|
+
* page's segment rules and segment forms beside the pages (0371), and both
|
|
22
|
+
* sorting a reader into a segment and composing the page they get happen
|
|
23
|
+
* afterwards, here, against rules and deltas already held: `pageForReader`
|
|
24
|
+
* reads the context the host's server built and answers a tree and a
|
|
25
|
+
* segment's name, and nothing about the reader leaves the process.
|
|
26
|
+
* - **A failed pull costs freshness, never the page** (0358 clause 4). Every
|
|
27
|
+
* way a pull can fail leaves the last pages whole, and a server with none
|
|
28
|
+
* renders every page as it was built.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* const live = startPullingLivePages({
|
|
32
|
+
* deployment: process.env.LOOM_URL ?? "",
|
|
33
|
+
* key: process.env.LOOM_PROJECT_KEY ?? "",
|
|
34
|
+
* onOutcome: (outcome) => {
|
|
35
|
+
* if (outcome.kind === "failed") log.warn(describeSitePullFailure(outcome.failure))
|
|
36
|
+
* },
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* // wherever a page is rendered, with the tree the site was built with, and
|
|
40
|
+
* // what this server knows about the request in the keys the rules read
|
|
41
|
+
* const held = await live.ready()
|
|
42
|
+
* const pin = pinIn(request.headers.get("cookie"))
|
|
43
|
+
* const served = pageForReader(held, builtTree, { device: "phone", returning: true }, pin)
|
|
44
|
+
* const keep = pinCookieFor(held, pin)
|
|
45
|
+
*
|
|
46
|
+
* if (served.refusal !== undefined) log.warn(describeComposeError(served.refusal))
|
|
47
|
+
* if (keep !== undefined) response.headers.set("set-cookie", keep)
|
|
48
|
+
*
|
|
49
|
+
* renderLoomTree(served.tree, { resolver, addressed: true, audience: served.audience })
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* The last two of those are what a project with a reader window costs a host
|
|
53
|
+
* (0383): a reader keeps the pages they first saw for as long as the project
|
|
54
|
+
* set, and a project with no window — which is every project until somebody
|
|
55
|
+
* chooses one — needs neither line. Both are pure, both read only what the last
|
|
56
|
+
* pull brought, and nothing about the reader leaves the process.
|
|
57
|
+
*
|
|
58
|
+
* The page's signals are filed under the segment it was rendered for (0284):
|
|
59
|
+
* the root carries it, and the broadcaster reads it from there.
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* The refusal a composition hands back, and the sentence for it, re-exported
|
|
63
|
+
* here because the place a host meets one is the render path. A site's server
|
|
64
|
+
* imports `/live` and `/react`; making it import the control plane's door to
|
|
65
|
+
* say why a page was served as the base would be the wrong dependency for the
|
|
66
|
+
* one line of logging this costs.
|
|
67
|
+
*/
|
|
68
|
+
export { describeComposeError, type AudienceForm, type ComposeError } from "../audience/compose.js";
|
|
69
|
+
export { isPulling, livePageOf, livePagesHeld, NO_LIVE_PAGES, pageForReader, segmentOf, type LivePages, type ServedPage, } from "./pages.js";
|
|
70
|
+
export { PIN_COOKIE, pinCookieFor, pinIn, WINDOW_OFF, type HeldVersion, type LiveWindow, } from "./window.js";
|
|
71
|
+
export { describeSitePullFailure, DEFAULT_PULL_CEILING_MS, LIVE_PAGES_PATH, livePagesUrlOf, pullLivePages, withPullOutcome, type LivePageForms, type LivePageRules, type PullFetch, type PullLivePagesOptions, type SitePullFailure, type SitePullOutcome, } from "./pull.js";
|
|
72
|
+
export { DEFAULT_FIRST_WAIT_MS, DEFAULT_PULL_INTERVAL_MS, startPullingLivePages, type LivePullLoop, type PullSchedule, type StartPullingOptions, } from "./pulling.js";
|
|
73
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The half of going live that runs in the customer's server.
|
|
3
|
+
*
|
|
4
|
+
* A change accepted in the portal is live as soon as the site next pulls
|
|
5
|
+
* (0358): there is no pull request, no merge and no deploy between somebody
|
|
6
|
+
* accepting a change and a reader seeing it. What makes that true is this —
|
|
7
|
+
* a loop that fetches the project's live pages from Loom on a short interval,
|
|
8
|
+
* keeps them in the process, and hands one to the render path by page id.
|
|
9
|
+
*
|
|
10
|
+
* Three properties hold by construction rather than by care, and each has a
|
|
11
|
+
* test that would fail if it stopped:
|
|
12
|
+
*
|
|
13
|
+
* - **Loom is in the render path once per server, and only until it answers**
|
|
14
|
+
* (0262, 0364). The first reader on a new server waits for the first pull,
|
|
15
|
+
* so they get the live page rather than one that changes on their next
|
|
16
|
+
* request; a failed pull ends the wait at once and a silent Loom ends it after
|
|
17
|
+
* `DEFAULT_FIRST_WAIT_MS`. Every pull after that runs beside requests, on a
|
|
18
|
+
* timer, and no reader waits on it.
|
|
19
|
+
* - **Loom never learns who a reader is.** The request carries the project's
|
|
20
|
+
* key and the tag of what is held, and nothing else. The door answers every
|
|
21
|
+
* page's segment rules and segment forms beside the pages (0371), and both
|
|
22
|
+
* sorting a reader into a segment and composing the page they get happen
|
|
23
|
+
* afterwards, here, against rules and deltas already held: `pageForReader`
|
|
24
|
+
* reads the context the host's server built and answers a tree and a
|
|
25
|
+
* segment's name, and nothing about the reader leaves the process.
|
|
26
|
+
* - **A failed pull costs freshness, never the page** (0358 clause 4). Every
|
|
27
|
+
* way a pull can fail leaves the last pages whole, and a server with none
|
|
28
|
+
* renders every page as it was built.
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* const live = startPullingLivePages({
|
|
32
|
+
* deployment: process.env.LOOM_URL ?? "",
|
|
33
|
+
* key: process.env.LOOM_PROJECT_KEY ?? "",
|
|
34
|
+
* onOutcome: (outcome) => {
|
|
35
|
+
* if (outcome.kind === "failed") log.warn(describeSitePullFailure(outcome.failure))
|
|
36
|
+
* },
|
|
37
|
+
* })
|
|
38
|
+
*
|
|
39
|
+
* // wherever a page is rendered, with the tree the site was built with, and
|
|
40
|
+
* // what this server knows about the request in the keys the rules read
|
|
41
|
+
* const held = await live.ready()
|
|
42
|
+
* const pin = pinIn(request.headers.get("cookie"))
|
|
43
|
+
* const served = pageForReader(held, builtTree, { device: "phone", returning: true }, pin)
|
|
44
|
+
* const keep = pinCookieFor(held, pin)
|
|
45
|
+
*
|
|
46
|
+
* if (served.refusal !== undefined) log.warn(describeComposeError(served.refusal))
|
|
47
|
+
* if (keep !== undefined) response.headers.set("set-cookie", keep)
|
|
48
|
+
*
|
|
49
|
+
* renderLoomTree(served.tree, { resolver, addressed: true, audience: served.audience })
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* The last two of those are what a project with a reader window costs a host
|
|
53
|
+
* (0383): a reader keeps the pages they first saw for as long as the project
|
|
54
|
+
* set, and a project with no window — which is every project until somebody
|
|
55
|
+
* chooses one — needs neither line. Both are pure, both read only what the last
|
|
56
|
+
* pull brought, and nothing about the reader leaves the process.
|
|
57
|
+
*
|
|
58
|
+
* The page's signals are filed under the segment it was rendered for (0284):
|
|
59
|
+
* the root carries it, and the broadcaster reads it from there.
|
|
60
|
+
*/
|
|
61
|
+
/**
|
|
62
|
+
* The refusal a composition hands back, and the sentence for it, re-exported
|
|
63
|
+
* here because the place a host meets one is the render path. A site's server
|
|
64
|
+
* imports `/live` and `/react`; making it import the control plane's door to
|
|
65
|
+
* say why a page was served as the base would be the wrong dependency for the
|
|
66
|
+
* one line of logging this costs.
|
|
67
|
+
*/
|
|
68
|
+
export { describeComposeError } from "../audience/compose.js";
|
|
69
|
+
export { isPulling, livePageOf, livePagesHeld, NO_LIVE_PAGES, pageForReader, segmentOf, } from "./pages.js";
|
|
70
|
+
export { PIN_COOKIE, pinCookieFor, pinIn, WINDOW_OFF, } from "./window.js";
|
|
71
|
+
export { describeSitePullFailure, DEFAULT_PULL_CEILING_MS, LIVE_PAGES_PATH, livePagesUrlOf, pullLivePages, withPullOutcome, } from "./pull.js";
|
|
72
|
+
export { DEFAULT_FIRST_WAIT_MS, DEFAULT_PULL_INTERVAL_MS, startPullingLivePages, } from "./pulling.js";
|
|
73
|
+
//# sourceMappingURL=index.js.map
|