@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,151 @@
|
|
|
1
|
+
import { ceilingOf, describeCeiling, withCeiling } from "../deadline.js";
|
|
2
|
+
import { assertNever, err, ok } from "../result.js";
|
|
3
|
+
import { parseDelta } from "../tree/delta.js";
|
|
4
|
+
import { interpretationReplySchema } from "./draft.js";
|
|
5
|
+
import { materializeDelta } from "./materialize.js";
|
|
6
|
+
import { buildRepairMessage, buildUserMessage, hashPrompt, INTERPRETER_SYSTEM_PROMPT, } from "./prompt.js";
|
|
7
|
+
import { DEFAULT_DRAFT_DEPTH, interpretationReplyJsonSchema } from "./schema.js";
|
|
8
|
+
/**
|
|
9
|
+
* A ChangeInterpreter backed by a model.
|
|
10
|
+
*
|
|
11
|
+
* Every step except the call itself is pure: assemble the prompt, hand it to
|
|
12
|
+
* the client seam, parse what comes back, project it onto a TreeDelta. The
|
|
13
|
+
* distinction the pipeline depends on is preserved here — a reply this module
|
|
14
|
+
* cannot make sense of is an `InterpretationError`, never a proposal the Gate
|
|
15
|
+
* gets to refuse, and never a thrown exception.
|
|
16
|
+
*
|
|
17
|
+
* The delta is authored against the revision the *intent* named, not the tree
|
|
18
|
+
* as it stands now. An intent raised against a tree that has since moved on
|
|
19
|
+
* therefore produces a proposal that fails to apply, which the pipeline reports
|
|
20
|
+
* as `not-applicable` — rather than being quietly re-targeted at a tree the
|
|
21
|
+
* asker never saw.
|
|
22
|
+
*/
|
|
23
|
+
export const DEFAULT_INTERPRETER_MODEL = "claude-opus-5";
|
|
24
|
+
export const DEFAULT_MAX_TOKENS = 16000;
|
|
25
|
+
export const DEFAULT_EFFORT = "high";
|
|
26
|
+
/**
|
|
27
|
+
* Three minutes, which is long enough that no interpretation this repository has
|
|
28
|
+
* measured comes near it and short enough that a request nobody is ever going to
|
|
29
|
+
* answer is reported while somebody is still looking at the screen.
|
|
30
|
+
*
|
|
31
|
+
* It is a default rather than a constant because the right number is a property
|
|
32
|
+
* of the deployment: a portal with a reader waiting wants less, a batch job
|
|
33
|
+
* rewriting a hundred pages can afford more. What is not a property of the
|
|
34
|
+
* deployment is whether to have one (0140).
|
|
35
|
+
*/
|
|
36
|
+
export const DEFAULT_INTERPRETER_CEILING_MS = 180_000;
|
|
37
|
+
const fromClientError = (error) => {
|
|
38
|
+
switch (error.code) {
|
|
39
|
+
case "unavailable":
|
|
40
|
+
return { code: "interpreter-unavailable", detail: error.detail };
|
|
41
|
+
case "rejected":
|
|
42
|
+
return { code: "interpreter-request-rejected", detail: error.detail };
|
|
43
|
+
case "misconfigured":
|
|
44
|
+
return { code: "interpreter-misconfigured", detail: error.detail };
|
|
45
|
+
case "refused":
|
|
46
|
+
return { code: "refused", detail: `model declined to answer: ${error.detail}` };
|
|
47
|
+
case "incomplete":
|
|
48
|
+
return { code: "malformed-proposal", detail: `reply was cut off: ${error.detail}` };
|
|
49
|
+
default:
|
|
50
|
+
return assertNever(error, "fromClientError");
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const parseReply = (text) => {
|
|
54
|
+
const decoded = (() => {
|
|
55
|
+
try {
|
|
56
|
+
return ok(JSON.parse(text));
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return err({ code: "malformed-proposal", detail: "reply was not valid JSON" });
|
|
60
|
+
}
|
|
61
|
+
})();
|
|
62
|
+
if (!decoded.ok)
|
|
63
|
+
return decoded;
|
|
64
|
+
const validated = interpretationReplySchema.safeParse(decoded.value);
|
|
65
|
+
if (!validated.success) {
|
|
66
|
+
const [issue] = validated.error.issues;
|
|
67
|
+
return err({
|
|
68
|
+
code: "malformed-proposal",
|
|
69
|
+
detail: issue ? `${issue.path.join(".") || "reply"}: ${issue.message}` : "reply did not match the schema",
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return ok(validated.data);
|
|
73
|
+
};
|
|
74
|
+
const buildDelta = (reply, intent, config) => {
|
|
75
|
+
const materialized = materializeDelta(reply.operations, {
|
|
76
|
+
treeId: intent.treeId,
|
|
77
|
+
baseRevision: intent.baseRevision,
|
|
78
|
+
deltaId: config.idFactory.deltaId(),
|
|
79
|
+
idFactory: config.idFactory,
|
|
80
|
+
});
|
|
81
|
+
if (!materialized.ok) {
|
|
82
|
+
return err({ code: "malformed-proposal", detail: materialized.error });
|
|
83
|
+
}
|
|
84
|
+
const parsed = parseDelta(materialized.value);
|
|
85
|
+
return parsed.ok
|
|
86
|
+
? ok(parsed.value)
|
|
87
|
+
: err({ code: "malformed-proposal", detail: `${parsed.error.code}: ${JSON.stringify(parsed.error)}` });
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* The one call path. Interpreting an utterance and revising a refused proposal
|
|
91
|
+
* differ only in the user message, so they share everything else — the same
|
|
92
|
+
* system prompt (which keeps the cacheable prefix identical), the same output
|
|
93
|
+
* schema, the same parsing, and the same rules about what a bad answer means.
|
|
94
|
+
*/
|
|
95
|
+
const propose = async (config, intent, userMessage) => {
|
|
96
|
+
const ceiling = ceilingOf(config.ceilingMs, DEFAULT_INTERPRETER_CEILING_MS);
|
|
97
|
+
/**
|
|
98
|
+
* The ceiling is enforced here rather than in the Anthropic adapter, because
|
|
99
|
+
* the seam's promise is to a caller of the interpreter and not to a vendor: a
|
|
100
|
+
* host that brings its own `ModelClient` gets the same bound without having
|
|
101
|
+
* written one (0140).
|
|
102
|
+
*/
|
|
103
|
+
const completion = await withCeiling(ceiling, () => err({ code: "unavailable", detail: `no reply in ${describeCeiling(ceiling)}` }), (signal) => config.client.complete({
|
|
104
|
+
model: config.model ?? DEFAULT_INTERPRETER_MODEL,
|
|
105
|
+
maxTokens: config.maxTokens ?? DEFAULT_MAX_TOKENS,
|
|
106
|
+
effort: config.effort ?? DEFAULT_EFFORT,
|
|
107
|
+
system: INTERPRETER_SYSTEM_PROMPT,
|
|
108
|
+
userMessage,
|
|
109
|
+
outputSchema: interpretationReplyJsonSchema(config.draftDepth ?? DEFAULT_DRAFT_DEPTH),
|
|
110
|
+
}, { signal }));
|
|
111
|
+
if (!completion.ok)
|
|
112
|
+
return err(fromClientError(completion.error));
|
|
113
|
+
const reply = parseReply(completion.value.text);
|
|
114
|
+
if (!reply.ok)
|
|
115
|
+
return reply;
|
|
116
|
+
if (reply.value.outcome === "no-change") {
|
|
117
|
+
return err({ code: "no-change-needed", detail: reply.value.rationale });
|
|
118
|
+
}
|
|
119
|
+
if (reply.value.outcome === "not-understood") {
|
|
120
|
+
return err({ code: "not-understood", detail: reply.value.rationale });
|
|
121
|
+
}
|
|
122
|
+
const delta = buildDelta(reply.value, intent, config);
|
|
123
|
+
if (!delta.ok)
|
|
124
|
+
return delta;
|
|
125
|
+
return ok({
|
|
126
|
+
proposalId: config.idFactory.proposalId(),
|
|
127
|
+
intentId: intent.intentId,
|
|
128
|
+
delta: delta.value,
|
|
129
|
+
rationale: reply.value.rationale,
|
|
130
|
+
provenance: {
|
|
131
|
+
origin: intent.origin,
|
|
132
|
+
/** Copied from the ask, never inferred from the reply: the model does not name who asked. */
|
|
133
|
+
...(intent.actor === undefined ? {} : { actor: intent.actor }),
|
|
134
|
+
interpreter: completion.value.servedBy,
|
|
135
|
+
authoredBy: "model",
|
|
136
|
+
promptHash: await hashPrompt(INTERPRETER_SYSTEM_PROMPT, userMessage),
|
|
137
|
+
confidence: reply.value.confidence,
|
|
138
|
+
interpretedAt: config.clock.now(),
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* Implements both seams. Whether a deployment actually repairs is decided by
|
|
144
|
+
* whether this object is also wired in as the runtime's `repairer` — the
|
|
145
|
+
* capability is offered here, but never assumed.
|
|
146
|
+
*/
|
|
147
|
+
export const modelInterpreter = (config) => ({
|
|
148
|
+
interpret: (intent, tree) => propose(config, intent, buildUserMessage(intent, tree, config)),
|
|
149
|
+
repair: (request, tree) => propose(config, request.intent, buildRepairMessage(request, tree, config)),
|
|
150
|
+
});
|
|
151
|
+
//# sourceMappingURL=interpreter.js.map
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { DeltaId, IdFactory, TreeId } from "../ids.js";
|
|
2
|
+
import { type JsonObject } from "../json.js";
|
|
3
|
+
import { type Result } from "../result.js";
|
|
4
|
+
import type { TreeDelta } from "../tree/delta.js";
|
|
5
|
+
import type { DraftOperation } from "./draft.js";
|
|
6
|
+
/**
|
|
7
|
+
* The inverse of the projection in `draft.ts`: a validated draft becomes a real
|
|
8
|
+
* TreeDelta. This is where the runtime, not the proposer, decides identity —
|
|
9
|
+
* every inserted node gets its id here, from the same seam the rest of the
|
|
10
|
+
* system mints through.
|
|
11
|
+
*
|
|
12
|
+
* Failures are reported as a sentence rather than a code because they all mean
|
|
13
|
+
* one thing to the caller: the model said something it was not allowed to say.
|
|
14
|
+
* The sentence is what makes that debuggable.
|
|
15
|
+
*/
|
|
16
|
+
export type MaterializeContext = {
|
|
17
|
+
readonly treeId: TreeId;
|
|
18
|
+
readonly baseRevision: number;
|
|
19
|
+
readonly deltaId: DeltaId;
|
|
20
|
+
readonly idFactory: IdFactory;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* Props arrive as one JSON-encoded object (0014). This is the whole of the trust
|
|
24
|
+
* boundary for them: parse it, require an object rather than an array or a
|
|
25
|
+
* scalar, and validate every value against the JSON value space so nothing
|
|
26
|
+
* un-serialisable reaches a tree.
|
|
27
|
+
*
|
|
28
|
+
* What the old tagged union enforced in the grammar is enforced here instead —
|
|
29
|
+
* strictly later, and reported as `malformed-proposal` rather than being
|
|
30
|
+
* unsayable. Prop *meaning* is checked later still, by §4's registry against the
|
|
31
|
+
* primitive's own declared schema (0011).
|
|
32
|
+
*
|
|
33
|
+
* One thing is genuinely lost: a duplicate key. `JSON.parse` collapses
|
|
34
|
+
* `{"a":1,"a":2}` to the last value before this code sees it, so the "set twice"
|
|
35
|
+
* refusal the tagged array allowed is not expressible any more. It is a smaller
|
|
36
|
+
* loss than it looks — duplicate names in JSON have a deterministic outcome in
|
|
37
|
+
* every parser anyone would use, where two entries in our own array genuinely
|
|
38
|
+
* had none.
|
|
39
|
+
*/
|
|
40
|
+
export declare const decodeProps: (encoded: string) => Result<JsonObject, string>;
|
|
41
|
+
export declare const materializeDelta: (operations: readonly DraftOperation[], context: MaterializeContext) => Result<TreeDelta, string>;
|
|
42
|
+
//# sourceMappingURL=materialize.d.ts.map
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { jsonObjectSchema } from "../json.js";
|
|
2
|
+
import { assertNever, err, ok, reduceResult } from "../result.js";
|
|
3
|
+
const collectResults = (items, map) => reduceResult(items, [], (accumulator, item) => {
|
|
4
|
+
const mapped = map(item);
|
|
5
|
+
return mapped.ok ? ok([...accumulator, mapped.value]) : mapped;
|
|
6
|
+
});
|
|
7
|
+
const parseJson = (text) => {
|
|
8
|
+
try {
|
|
9
|
+
return ok(JSON.parse(text));
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return err("value is not parseable JSON");
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Props arrive as one JSON-encoded object (0014). This is the whole of the trust
|
|
17
|
+
* boundary for them: parse it, require an object rather than an array or a
|
|
18
|
+
* scalar, and validate every value against the JSON value space so nothing
|
|
19
|
+
* un-serialisable reaches a tree.
|
|
20
|
+
*
|
|
21
|
+
* What the old tagged union enforced in the grammar is enforced here instead —
|
|
22
|
+
* strictly later, and reported as `malformed-proposal` rather than being
|
|
23
|
+
* unsayable. Prop *meaning* is checked later still, by §4's registry against the
|
|
24
|
+
* primitive's own declared schema (0011).
|
|
25
|
+
*
|
|
26
|
+
* One thing is genuinely lost: a duplicate key. `JSON.parse` collapses
|
|
27
|
+
* `{"a":1,"a":2}` to the last value before this code sees it, so the "set twice"
|
|
28
|
+
* refusal the tagged array allowed is not expressible any more. It is a smaller
|
|
29
|
+
* loss than it looks — duplicate names in JSON have a deterministic outcome in
|
|
30
|
+
* every parser anyone would use, where two entries in our own array genuinely
|
|
31
|
+
* had none.
|
|
32
|
+
*/
|
|
33
|
+
export const decodeProps = (encoded) => {
|
|
34
|
+
const parsed = parseJson(encoded);
|
|
35
|
+
/** Truncated: the reply is model-authored and this sentence ends up in telemetry. */
|
|
36
|
+
if (!parsed.ok)
|
|
37
|
+
return err(`props are not parseable JSON: ${encoded.slice(0, 80)}`);
|
|
38
|
+
if (parsed.value === null || typeof parsed.value !== "object" || Array.isArray(parsed.value)) {
|
|
39
|
+
return err("props must be a JSON object");
|
|
40
|
+
}
|
|
41
|
+
const validated = jsonObjectSchema.safeParse(parsed.value);
|
|
42
|
+
return validated.success ? ok(validated.data) : err("props contain a value that is not JSON");
|
|
43
|
+
};
|
|
44
|
+
const materializeNode = (node, idFactory) => {
|
|
45
|
+
switch (node.kind) {
|
|
46
|
+
case "text":
|
|
47
|
+
return ok({ kind: "text", id: idFactory.nodeId(), value: node.value });
|
|
48
|
+
case "element": {
|
|
49
|
+
const props = decodeProps(node.props);
|
|
50
|
+
if (!props.ok)
|
|
51
|
+
return props;
|
|
52
|
+
const children = collectResults(node.children, (child) => materializeNode(child, idFactory));
|
|
53
|
+
if (!children.ok)
|
|
54
|
+
return children;
|
|
55
|
+
return ok({
|
|
56
|
+
kind: "element",
|
|
57
|
+
id: idFactory.nodeId(),
|
|
58
|
+
type: node.type,
|
|
59
|
+
props: props.value,
|
|
60
|
+
children: children.value,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
default:
|
|
64
|
+
return assertNever(node, "materializeNode");
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
const materializeOperation = (operation, idFactory) => {
|
|
68
|
+
switch (operation.op) {
|
|
69
|
+
case "insert": {
|
|
70
|
+
const node = materializeNode(operation.node, idFactory);
|
|
71
|
+
return node.ok
|
|
72
|
+
? ok({ op: "insert", parentId: operation.parentId, index: operation.index, node: node.value })
|
|
73
|
+
: node;
|
|
74
|
+
}
|
|
75
|
+
case "remove":
|
|
76
|
+
return ok({ op: "remove", nodeId: operation.nodeId });
|
|
77
|
+
case "move":
|
|
78
|
+
return ok({
|
|
79
|
+
op: "move",
|
|
80
|
+
nodeId: operation.nodeId,
|
|
81
|
+
parentId: operation.parentId,
|
|
82
|
+
index: operation.index,
|
|
83
|
+
});
|
|
84
|
+
case "configure": {
|
|
85
|
+
const set = decodeProps(operation.set);
|
|
86
|
+
return set.ok
|
|
87
|
+
? ok({ op: "configure", nodeId: operation.nodeId, set: set.value, unset: operation.unset })
|
|
88
|
+
: set;
|
|
89
|
+
}
|
|
90
|
+
default:
|
|
91
|
+
return assertNever(operation, "materializeOperation");
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
export const materializeDelta = (operations, context) => {
|
|
95
|
+
if (operations.length === 0)
|
|
96
|
+
return err("proposed a change with no operations");
|
|
97
|
+
const materialized = collectResults(operations, (operation) => materializeOperation(operation, context.idFactory));
|
|
98
|
+
return materialized.ok
|
|
99
|
+
? ok({
|
|
100
|
+
deltaId: context.deltaId,
|
|
101
|
+
treeId: context.treeId,
|
|
102
|
+
baseRevision: context.baseRevision,
|
|
103
|
+
operations: materialized.value,
|
|
104
|
+
})
|
|
105
|
+
: materialized;
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=materialize.js.map
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { PrimitiveCatalogue } from "../catalogue.js";
|
|
2
|
+
import type { DataCatalogue } from "../data/catalogue.js";
|
|
3
|
+
import type { FrameCatalogue } from "../frame/catalogue.js";
|
|
4
|
+
import type { PrimitiveType } from "../primitive-type.js";
|
|
5
|
+
import type { EditIntent } from "../runtime/intent.js";
|
|
6
|
+
import type { RepairRequest } from "../runtime/interpreter.js";
|
|
7
|
+
import type { SubmissionCatalogue } from "../submit/catalogue.js";
|
|
8
|
+
import type { ThemeCatalogue } from "../theme/registry.js";
|
|
9
|
+
import type { LoomTree } from "../tree/tree.js";
|
|
10
|
+
/**
|
|
11
|
+
* Prompt assembly, kept pure so the exact bytes sent to a model are a value a
|
|
12
|
+
* test can assert on rather than a side effect of calling one.
|
|
13
|
+
*
|
|
14
|
+
* The system prompt is deliberately a constant: it is the same for every intent
|
|
15
|
+
* and every tree, so it sits at the front of the request where a cache can hold
|
|
16
|
+
* it, and so that "what were we asking the model to do" is answerable by
|
|
17
|
+
* reading one string rather than reconstructing a template.
|
|
18
|
+
*/
|
|
19
|
+
export declare const INTERPRETER_SYSTEM_PROMPT = "You translate a request about a user interface into discrete edits to a component tree.\n\nThe tree is given as an indented outline. Every line starts with a node id. There are three node kinds:\n- element \u2014 an instance of a primitive, with props and ordered children\n- text \u2014 a leaf string\n- slot \u2014 a named region whose children are fallback content\n\nYou reply with one of three outcomes:\n- \"change\" \u2014 the intent is satisfiable, and you give the operations that satisfy it\n- \"no-change\" \u2014 you understood the intent and the tree already satisfies it\n- \"not-understood\" \u2014 the intent is ambiguous, or asks for something the operations cannot express\n\nThere are exactly four operations:\n- insert \u2014 a new node at a position under an existing parent\n- remove \u2014 an existing node and its whole subtree\n- move \u2014 an existing node to a new parent and position\n- configure \u2014 set or unset props on an existing node\n\nRules you must follow:\n- Address existing nodes only by ids copied exactly from the outline. Never invent an id.\n- Never give an id to a node you are inserting. The runtime assigns it.\n- Operations apply in order, and each one sees the effects of the ones before it.\n- move is a detach followed by an insert, so its index counts positions in the child list the node has already left.\n- props is the node's props as a JSON object, JSON-encoded into a string: \"{\"tone\":\"quiet\",\"count\":2}\". Use \"{}\" for no props. configure's set is written the same way. Values are ordinary JSON \u2014 strings, numbers, booleans, null, arrays, objects \u2014 with no tags or wrappers.\n- You may insert element and text nodes. You cannot insert a slot: a slot is a region a primitive declares, not content an edit adds. Slots already in the tree can be configured, moved into, and inserted into like anything else.\n- Propose the smallest set of operations that satisfies the intent. Do not tidy, restructure, or improve anything you were not asked about.\n- Reuse primitive types already present in the tree unless the intent clearly calls for a new one.\n- confidence is your own estimate that these operations satisfy the intent, from 0 to 1. Report it honestly; a low number is more useful than a wrong high one.\n\nSometimes you will be shown a proposal that was refused, and the reason. You get one revision, and the rules above still apply. A revision must be a more conservative way to satisfy the same request \u2014 smaller in what it destroys, or narrower in what it touches. It must not be the same change split into a smaller piece so that the remainder can be asked for again: if the request cannot be satisfied within the stated objection, say \"not-understood\" and explain what would have to change. Reproposing what was already refused, or working around the objection rather than respecting it, is the one thing a revision must never do.";
|
|
20
|
+
/**
|
|
21
|
+
* Everything a deployment can offer a model, in one value.
|
|
22
|
+
*
|
|
23
|
+
* Five projections rather than five parameters, and the reason is the shape the
|
|
24
|
+
* fifth one would have had: `buildUserMessage(intent, tree, undefined,
|
|
25
|
+
* undefined, sources)` is a call nobody can read and a call site that silently
|
|
26
|
+
* means something else if an argument is inserted. Each field is independently
|
|
27
|
+
* optional because a deployment genuinely may wire any subset — §2 shipped with
|
|
28
|
+
* none of them, and a site with a library and no data registry is the ordinary
|
|
29
|
+
* case rather than a half-configured one.
|
|
30
|
+
*
|
|
31
|
+
* Every field is a *projection* rather than a registry: what reaches a model is
|
|
32
|
+
* what `catalogueOf`, `dataCatalogue`, `submissionCatalogue`, `frameCatalogue`
|
|
33
|
+
* and `ThemeRegistry.catalogue` chose to publish, which is how a registry keeps
|
|
34
|
+
* internals — an adapter's connection, an endpoint's address — out of a prompt
|
|
35
|
+
* by construction rather than by remembering to.
|
|
36
|
+
*
|
|
37
|
+
* The keys are the names a host already writes on `ModelInterpreterConfig`,
|
|
38
|
+
* which composes this type rather than restating it. A second spelling of the
|
|
39
|
+
* same five things would buy prettier block names — `sources` over
|
|
40
|
+
* `dataCatalogue` — at the price of a mapping function between two shapes that
|
|
41
|
+
* must stay in step, and that function is the thing a sixth vocabulary would be
|
|
42
|
+
* forgotten in.
|
|
43
|
+
*/
|
|
44
|
+
export type PromptVocabularies = {
|
|
45
|
+
/**
|
|
46
|
+
* What this deployment can build with. Absent means the model is told only
|
|
47
|
+
* what the tree shows, which is what §2 shipped with; a host that has a §4
|
|
48
|
+
* registry projects it with `catalogueOf` and the model stops guessing at
|
|
49
|
+
* primitive names it has no way to know.
|
|
50
|
+
*/
|
|
51
|
+
readonly catalogue?: PrimitiveCatalogue;
|
|
52
|
+
/**
|
|
53
|
+
* What this deployment may be themed with. Absent means the model is shown no
|
|
54
|
+
* theme vocabulary and cannot re-theme anything: the ids in the tree are the
|
|
55
|
+
* only ones it knows, so "make it warmer" has nowhere to go but an invented
|
|
56
|
+
* id that fails to resolve. A host with a §4b theme registry passes
|
|
57
|
+
* `themes.catalogue()`.
|
|
58
|
+
*/
|
|
59
|
+
readonly themeCatalogue?: ThemeCatalogue;
|
|
60
|
+
/**
|
|
61
|
+
* What this deployment can be asked about. Absent means the model is told
|
|
62
|
+
* nothing about the data seam, so the only bindings it can propose are ones
|
|
63
|
+
* it invented — refused at the seam as `no-such-source`, which is the right
|
|
64
|
+
* refusal for a guess nobody gave it the information to avoid (0058). A host
|
|
65
|
+
* with a source registry passes `dataCatalogue(registry)`.
|
|
66
|
+
*/
|
|
67
|
+
readonly dataCatalogue?: DataCatalogue;
|
|
68
|
+
/**
|
|
69
|
+
* Where this deployment will accept a submission. Absent means the model
|
|
70
|
+
* cannot point a form anywhere, which is the safe default rather than a gap:
|
|
71
|
+
* `loom:submit` names a registered endpoint and nothing else leaves the tree
|
|
72
|
+
* (0065). A host with an endpoint registry passes
|
|
73
|
+
* `submissionCatalogue(registry)`.
|
|
74
|
+
*/
|
|
75
|
+
readonly submissionCatalogue?: SubmissionCatalogue;
|
|
76
|
+
/**
|
|
77
|
+
* Whose documents this deployment will frame. Absent means the model is not
|
|
78
|
+
* told, and a frame it proposes renders a refusal unless it happened to name
|
|
79
|
+
* a registered origin. Unlike the four above this one narrows a value the
|
|
80
|
+
* model still chooses, because which video belongs on a page is a content
|
|
81
|
+
* decision and the URL stays in the tree (0095).
|
|
82
|
+
*/
|
|
83
|
+
readonly frameCatalogue?: FrameCatalogue;
|
|
84
|
+
};
|
|
85
|
+
/**
|
|
86
|
+
* The five vocabulary blocks lead, then the tree, then the sentence somebody
|
|
87
|
+
* typed.
|
|
88
|
+
*
|
|
89
|
+
* The order is by how often a part changes, least often first, so that the
|
|
90
|
+
* longest stable prefix sits where a provider's cache can hold it: a deployment
|
|
91
|
+
* registers once and asks many times, the tree changes with every accepted
|
|
92
|
+
* change, and the request is different every time by definition.
|
|
93
|
+
*/
|
|
94
|
+
export declare const buildUserMessage: (intent: EditIntent, tree: LoomTree, vocabularies?: PromptVocabularies) => string;
|
|
95
|
+
/**
|
|
96
|
+
* What one proposal request costs, block by block, in characters.
|
|
97
|
+
*
|
|
98
|
+
* Characters rather than tokens, deliberately. A token count depends on a
|
|
99
|
+
* tokenizer that belongs to a model and changes with it, so a number measured
|
|
100
|
+
* here would be wrong somewhere else and stale eventually; the package would
|
|
101
|
+
* also have to carry a tokenizer to produce it. Characters are exact, free, and
|
|
102
|
+
* proportional enough for the question this exists to answer — which block is
|
|
103
|
+
* the request made of, and what did registering more of something cost.
|
|
104
|
+
*
|
|
105
|
+
* `system` is the constant prompt. It is included because it is part of what is
|
|
106
|
+
* sent, and separated because it is the one part a provider's cache can hold
|
|
107
|
+
* across every intent: a large constant is a different kind of cost from a large
|
|
108
|
+
* catalogue that arrives on every request behind a tree that keeps changing.
|
|
109
|
+
*
|
|
110
|
+
* A repair sends this message again, plus the refused delta and the objection.
|
|
111
|
+
* What that costs is `measureRepairPrompt` below rather than a multiplier
|
|
112
|
+
* quoted here, because the ratio moves with the page
|
|
113
|
+
* (0108).
|
|
114
|
+
*/
|
|
115
|
+
export type PromptMeasurement = {
|
|
116
|
+
readonly system: number;
|
|
117
|
+
readonly primitives: number;
|
|
118
|
+
readonly themes: number;
|
|
119
|
+
readonly sources: number;
|
|
120
|
+
readonly endpoints: number;
|
|
121
|
+
readonly frames: number;
|
|
122
|
+
readonly tree: number;
|
|
123
|
+
readonly request: number;
|
|
124
|
+
/** The sum of the eight, and what actually goes over the wire. */
|
|
125
|
+
readonly total: number;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Measures a request without sending it.
|
|
129
|
+
*
|
|
130
|
+
* A host deciding what to register is the intended caller: `createThemeRegistry`
|
|
131
|
+
* and the primitive registry both take exactly what a deployment wants, and this
|
|
132
|
+
* is how the cost of taking all of it becomes a number rather than a feeling
|
|
133
|
+
* (0077's cost, made countable).
|
|
134
|
+
*/
|
|
135
|
+
export declare const measurePrompt: (intent: EditIntent, tree: LoomTree, vocabularies?: PromptVocabularies) => PromptMeasurement;
|
|
136
|
+
/**
|
|
137
|
+
* What one registered primitive costs on every request that names it.
|
|
138
|
+
*
|
|
139
|
+
* The line the model is shown, and the newline that ends it. Measured through
|
|
140
|
+
* `renderCatalogue` rather than by counting the fields, for the reason
|
|
141
|
+
* `UserMessageParts` exists one function up: a second way of working out what a
|
|
142
|
+
* catalogue entry looks like is a second thing to keep in step, and the first to
|
|
143
|
+
* go stale.
|
|
144
|
+
*/
|
|
145
|
+
export type CataloguedCost = {
|
|
146
|
+
readonly type: PrimitiveType;
|
|
147
|
+
readonly characters: number;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* What a deployment's vocabulary costs, whole and per entry.
|
|
151
|
+
*
|
|
152
|
+
* `measurePrompt` answers which block a request is made of. This answers the
|
|
153
|
+
* question a host asks next, which is what to do about it — and the two numbers
|
|
154
|
+
* pull in opposite directions on purpose.
|
|
155
|
+
*
|
|
156
|
+
* `characters` grows with the library, and is meant to: a deployment that
|
|
157
|
+
* registers twice as much is telling a model about twice as much, and no ceiling
|
|
158
|
+
* belonging to this package can know whether that is too much for the one that
|
|
159
|
+
* deployment sends to. `perEntry` does not grow with the library, and a drift in
|
|
160
|
+
* it is the framework getting more expensive rather than a host choosing to
|
|
161
|
+
* spend more. It is the half worth guarding, and the half nothing was watching.
|
|
162
|
+
*
|
|
163
|
+
* The whole block is a little more than the sum of its entries: the list is
|
|
164
|
+
* wrapped in the instruction that makes it usable, without which a model is
|
|
165
|
+
* shown a vocabulary and not told it may only use that one.
|
|
166
|
+
*/
|
|
167
|
+
export type CatalogueCost = {
|
|
168
|
+
readonly entries: number;
|
|
169
|
+
/** The block as sent, the instruction around the list included. */
|
|
170
|
+
readonly characters: number;
|
|
171
|
+
/** The mean cost of one entry, rounded. `0` for a catalogue with no entries. */
|
|
172
|
+
readonly perEntry: number;
|
|
173
|
+
/** What each entry costs, in catalogue order. */
|
|
174
|
+
readonly byType: readonly CataloguedCost[];
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Measures a vocabulary without sending it.
|
|
178
|
+
*
|
|
179
|
+
* The intended caller is a host deciding what to register, holding the answer
|
|
180
|
+
* against what it is prepared to spend — which is a judgment about the model it
|
|
181
|
+
* sends to and the latency it will accept, and therefore a deployment's to make
|
|
182
|
+
* rather than this package's to enforce.
|
|
183
|
+
*
|
|
184
|
+
* An empty catalogue costs nothing, because a request that has no vocabulary to
|
|
185
|
+
* offer omits the block entirely rather than sending an empty heading.
|
|
186
|
+
*/
|
|
187
|
+
export declare const measureCatalogue: (catalogue: PrimitiveCatalogue) => CatalogueCost;
|
|
188
|
+
export declare const buildRepairMessage: (request: RepairRequest, tree: LoomTree, vocabularies?: PromptVocabularies) => string;
|
|
189
|
+
/**
|
|
190
|
+
* What a second go costs, once the first one was refused.
|
|
191
|
+
*
|
|
192
|
+
* `proposal` is the measurement of the request that was refused — and, because a
|
|
193
|
+
* repair restates it whole, also the measurement of the largest part of the
|
|
194
|
+
* repair. Reading the same numbers twice is the point: the block that dominated
|
|
195
|
+
* the first request dominates the second, and on a large page that block is the
|
|
196
|
+
* tree.
|
|
197
|
+
*
|
|
198
|
+
* `total` is the repair request on the wire. `episode` is both requests together
|
|
199
|
+
* — what asking once and being refused once actually cost — and it is the number
|
|
200
|
+
* the doubling is about (0108).
|
|
201
|
+
*/
|
|
202
|
+
export type RepairMeasurement = {
|
|
203
|
+
readonly proposal: PromptMeasurement;
|
|
204
|
+
/** The refused delta, rendered, and the reasoning offered for it. */
|
|
205
|
+
readonly refused: number;
|
|
206
|
+
/** The Gate's reason code and its detail. */
|
|
207
|
+
readonly objection: number;
|
|
208
|
+
/** The closing sentence that makes this a revision rather than a fresh ask. */
|
|
209
|
+
readonly instruction: number;
|
|
210
|
+
/** `proposal.total` plus the three above: what the repair puts on the wire. */
|
|
211
|
+
readonly total: number;
|
|
212
|
+
/** `proposal.total + total`: the whole refused-then-repaired episode. */
|
|
213
|
+
readonly episode: number;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Measures a repair without sending it, on the same terms as `measurePrompt`.
|
|
217
|
+
*
|
|
218
|
+
* The intended caller is a host or a report deciding whether a refusal is worth
|
|
219
|
+
* offering a second go on: a repair is never cheaper than the request it
|
|
220
|
+
* revises, and how much dearer is a property of the page rather than a constant
|
|
221
|
+
* (0108).
|
|
222
|
+
*/
|
|
223
|
+
export declare const measureRepairPrompt: (request: RepairRequest, tree: LoomTree, vocabularies?: PromptVocabularies) => RepairMeasurement;
|
|
224
|
+
/**
|
|
225
|
+
* Provenance records a hash rather than the prompt, so an audit trail can prove
|
|
226
|
+
* two proposals came from the same question without storing what was asked.
|
|
227
|
+
*/
|
|
228
|
+
export declare const hashPrompt: (system: string, userMessage: string) => Promise<string>;
|
|
229
|
+
//# sourceMappingURL=prompt.d.ts.map
|