@serene-pub/sdk 0.6.0-pr-1
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 +202 -0
- package/NOTICE +17 -0
- package/README.md +368 -0
- package/dist/actions.d.ts +572 -0
- package/dist/actions.js +829 -0
- package/dist/annexFields.d.ts +234 -0
- package/dist/annexFields.js +413 -0
- package/dist/announce.d.ts +464 -0
- package/dist/announce.js +426 -0
- package/dist/attributes.d.ts +670 -0
- package/dist/attributes.js +904 -0
- package/dist/bands.d.ts +125 -0
- package/dist/bands.js +256 -0
- package/dist/builder.d.ts +683 -0
- package/dist/builder.js +677 -0
- package/dist/candidates.d.ts +109 -0
- package/dist/candidates.js +118 -0
- package/dist/capabilities.d.ts +744 -0
- package/dist/capabilities.js +679 -0
- package/dist/channels.d.ts +106 -0
- package/dist/channels.js +129 -0
- package/dist/clauses.d.ts +40 -0
- package/dist/clauses.js +43 -0
- package/dist/component.d.ts +33 -0
- package/dist/component.js +27 -0
- package/dist/componentBuild.d.ts +48 -0
- package/dist/componentBuild.js +84 -0
- package/dist/componentClient.d.ts +100 -0
- package/dist/componentClient.js +13 -0
- package/dist/componentImports.d.ts +51 -0
- package/dist/componentImports.js +106 -0
- package/dist/componentModule.d.ts +8 -0
- package/dist/componentModule.js +270 -0
- package/dist/componentWire.d.ts +130 -0
- package/dist/componentWire.js +280 -0
- package/dist/config.d.ts +295 -0
- package/dist/config.js +231 -0
- package/dist/connections.d.ts +89 -0
- package/dist/connections.js +131 -0
- package/dist/declarations.d.ts +290 -0
- package/dist/declarations.js +794 -0
- package/dist/descriptors.d.ts +1774 -0
- package/dist/descriptors.js +1329 -0
- package/dist/dev.d.ts +136 -0
- package/dist/dev.js +161 -0
- package/dist/document.d.ts +202 -0
- package/dist/document.js +312 -0
- package/dist/engines.d.ts +117 -0
- package/dist/engines.js +203 -0
- package/dist/eventMapLaws.d.ts +63 -0
- package/dist/eventMapLaws.js +128 -0
- package/dist/events.d.ts +554 -0
- package/dist/events.js +633 -0
- package/dist/executor.d.ts +771 -0
- package/dist/executor.js +1829 -0
- package/dist/extension.d.ts +448 -0
- package/dist/extension.js +315 -0
- package/dist/facets.d.ts +53 -0
- package/dist/facets.js +60 -0
- package/dist/foldedSections.d.ts +74 -0
- package/dist/foldedSections.js +161 -0
- package/dist/genres.d.ts +507 -0
- package/dist/genres.js +633 -0
- package/dist/guardedConnection.d.ts +138 -0
- package/dist/guardedConnection.js +341 -0
- package/dist/handlebarsReach.d.ts +122 -0
- package/dist/handlebarsReach.js +222 -0
- package/dist/hash.d.ts +146 -0
- package/dist/hash.js +166 -0
- package/dist/hookGrants.d.ts +47 -0
- package/dist/hookGrants.js +68 -0
- package/dist/hooks.d.ts +290 -0
- package/dist/hooks.js +113 -0
- package/dist/hostElements.d.ts +447 -0
- package/dist/hostElements.js +702 -0
- package/dist/i18n.d.ts +94 -0
- package/dist/i18n.js +123 -0
- package/dist/identity.d.ts +93 -0
- package/dist/identity.js +135 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +176 -0
- package/dist/layout.d.ts +194 -0
- package/dist/layout.js +40 -0
- package/dist/media.d.ts +202 -0
- package/dist/media.js +70 -0
- package/dist/messageBlocks.d.ts +487 -0
- package/dist/messageBlocks.js +683 -0
- package/dist/migration.d.ts +128 -0
- package/dist/migration.js +261 -0
- package/dist/names.d.ts +78 -0
- package/dist/names.js +136 -0
- package/dist/nodeInput.d.ts +399 -0
- package/dist/nodeInput.js +178 -0
- package/dist/participants.d.ts +291 -0
- package/dist/participants.js +252 -0
- package/dist/personGate.d.ts +62 -0
- package/dist/personGate.js +77 -0
- package/dist/pick.d.ts +84 -0
- package/dist/pick.js +103 -0
- package/dist/pluginHarness.d.ts +235 -0
- package/dist/pluginHarness.js +558 -0
- package/dist/pluginPermissions.d.ts +25 -0
- package/dist/pluginPermissions.js +97 -0
- package/dist/pluginRuleRef.d.ts +13 -0
- package/dist/pluginRuleRef.js +10 -0
- package/dist/predicates.d.ts +182 -0
- package/dist/predicates.js +249 -0
- package/dist/preview.d.ts +120 -0
- package/dist/preview.js +82 -0
- package/dist/promptBlocks.d.ts +130 -0
- package/dist/promptBlocks.js +197 -0
- package/dist/rankingDecisions.d.ts +60 -0
- package/dist/rankingDecisions.js +48 -0
- package/dist/receipt.d.ts +313 -0
- package/dist/receipt.js +60 -0
- package/dist/receiverRules.d.ts +24 -0
- package/dist/receiverRules.js +94 -0
- package/dist/refs.d.ts +117 -0
- package/dist/refs.js +137 -0
- package/dist/registry.d.ts +230 -0
- package/dist/registry.js +273 -0
- package/dist/review.d.ts +108 -0
- package/dist/review.js +97 -0
- package/dist/sampling.d.ts +152 -0
- package/dist/sampling.js +712 -0
- package/dist/scope.d.ts +65 -0
- package/dist/scope.js +128 -0
- package/dist/scripts.d.ts +243 -0
- package/dist/scripts.js +326 -0
- package/dist/sessionLayout.d.ts +339 -0
- package/dist/sessionLayout.js +503 -0
- package/dist/sessionSettings.d.ts +70 -0
- package/dist/sessionSettings.js +2 -0
- package/dist/settings.d.ts +501 -0
- package/dist/settings.js +604 -0
- package/dist/settingsSlot.d.ts +108 -0
- package/dist/settingsSlot.js +166 -0
- package/dist/shapes.d.ts +373 -0
- package/dist/shapes.js +408 -0
- package/dist/sheets.d.ts +165 -0
- package/dist/sheets.js +251 -0
- package/dist/statShapes.d.ts +96 -0
- package/dist/statShapes.js +112 -0
- package/dist/status.d.ts +103 -0
- package/dist/status.js +125 -0
- package/dist/storage.d.ts +145 -0
- package/dist/storage.js +33 -0
- package/dist/storyTime.d.ts +308 -0
- package/dist/storyTime.js +560 -0
- package/dist/surfaces.d.ts +501 -0
- package/dist/surfaces.js +292 -0
- package/dist/template.d.ts +312 -0
- package/dist/template.js +554 -0
- package/dist/templateCheck.d.ts +60 -0
- package/dist/templateCheck.js +516 -0
- package/dist/templateFit.d.ts +157 -0
- package/dist/templateFit.js +349 -0
- package/dist/templateIds.d.ts +138 -0
- package/dist/templateIds.js +144 -0
- package/dist/templateScopeAt.d.ts +131 -0
- package/dist/templateScopeAt.js +354 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.js +383 -0
- package/dist/tokenizers.d.ts +113 -0
- package/dist/tokenizers.js +184 -0
- package/dist/turnLock.d.ts +96 -0
- package/dist/turnLock.js +79 -0
- package/dist/turnOrder.d.ts +143 -0
- package/dist/turnOrder.js +128 -0
- package/dist/validate.d.ts +74 -0
- package/dist/validate.js +1399 -0
- package/dist/values.d.ts +212 -0
- package/dist/values.js +390 -0
- package/dist/variables.d.ts +493 -0
- package/dist/variables.js +662 -0
- package/dist/verdicts.d.ts +275 -0
- package/dist/verdicts.js +348 -0
- package/dist/widgetDecls.d.ts +88 -0
- package/dist/widgetDecls.js +119 -0
- package/dist/widgets.d.ts +1527 -0
- package/dist/widgets.js +208 -0
- package/dist/wire.d.ts +126 -0
- package/dist/wire.js +140 -0
- package/dist/worldinfo.d.ts +150 -0
- package/dist/worldinfo.js +212 -0
- package/host-elements.d.ts +914 -0
- package/package.json +67 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A refusal's pointer to the plugin permissions guide (K1c) — its own module,
|
|
3
|
+
* with one type-only import, so every refusal site (descriptors, the extension, the CLI) can
|
|
4
|
+
* name a row without pulling the grant table in behind it.
|
|
5
|
+
*/
|
|
6
|
+
import type { HookCtxKind } from './hookGrants.js';
|
|
7
|
+
/** Where the guide lives, as a refusal sentence names it. @experimental */
|
|
8
|
+
export declare const PLUGIN_PERMISSIONS_GUIDE = "guides/plugin-permissions.md";
|
|
9
|
+
/** The rules a refusal can point at; each is a heading in the guide. @experimental */
|
|
10
|
+
export type PluginRule = 'connections' | 'private-nodes' | 'secrets' | 'events';
|
|
11
|
+
/** ` (see guides/plugin-permissions.md#secrets)` — a row's anchor, as a refusal names it. @experimental */
|
|
12
|
+
export declare const pluginRuleRef: (anchor: PluginRule | `kind-${HookCtxKind}`) => string;
|
|
13
|
+
//# sourceMappingURL=pluginRuleRef.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A refusal's pointer to the plugin permissions guide (K1c) — its own module,
|
|
3
|
+
* with one type-only import, so every refusal site (descriptors, the extension, the CLI) can
|
|
4
|
+
* name a row without pulling the grant table in behind it.
|
|
5
|
+
*/
|
|
6
|
+
/** Where the guide lives, as a refusal sentence names it. @experimental */
|
|
7
|
+
export const PLUGIN_PERMISSIONS_GUIDE = 'guides/plugin-permissions.md';
|
|
8
|
+
/** ` (see guides/plugin-permissions.md#secrets)` — a row's anchor, as a refusal names it. @experimental */
|
|
9
|
+
export const pluginRuleRef = (anchor) => ` (see ${PLUGIN_PERMISSIONS_GUIDE}#${anchor})`;
|
|
10
|
+
//# sourceMappingURL=pluginRuleRef.js.map
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predicates — one declared shape, read in two places (plans/29 R-15
|
|
3
|
+
* *enabled-when*; 20 §10 *junction*; ruled 2026-09-15, built 2026-09-17 as
|
|
4
|
+
* U5e).
|
|
5
|
+
*
|
|
6
|
+
* A **junction** clause branches on a value a task computed: each branch is
|
|
7
|
+
* `{ path?, equals? | equalsPath? | truthy? }` over that value. An action's
|
|
8
|
+
* **enabled-when** is the same predicate over the session's **published
|
|
9
|
+
* values** — the document a host builds from what a session has already said
|
|
10
|
+
* about itself (`state.world.location`, `session.generating`, a message's
|
|
11
|
+
* `item.hidden`). The core here — `readPath` and `predicateHolds` — is what
|
|
12
|
+
* both read, so a predicate that fires a branch and one that greys a button
|
|
13
|
+
* can never mean two things.
|
|
14
|
+
*
|
|
15
|
+
* ## The two-port compare (D-4a, 2026-09-17)
|
|
16
|
+
*
|
|
17
|
+
* `equals` takes a literal, so until this the grammar could ask *is the
|
|
18
|
+
* accused Vell?* and never *is the accused the culprit?* — and a genre that
|
|
19
|
+
* derives a hidden fact rather than authoring it has no other question.
|
|
20
|
+
* `equalsPath` is the second path: the same document, read twice, compared
|
|
21
|
+
* strictly. Additive in the single-version sense (ruling 2026-09-08) — a
|
|
22
|
+
* stored document without it validates and hashes exactly as before. Both
|
|
23
|
+
* doors read it: the junction's `fires()` hands the routed value in as the
|
|
24
|
+
* scope, an enabled-when's evaluator hands in the published values.
|
|
25
|
+
*
|
|
26
|
+
* ## What an enabled-when is not
|
|
27
|
+
*
|
|
28
|
+
* Not a port reference: `on` is a dotted path into the published values,
|
|
29
|
+
* never `$.parse.call` — an action lives outside a run, and there is no port
|
|
30
|
+
* to read. Not code: a richer decision belongs in a task the junction reads,
|
|
31
|
+
* or in a value the state-keeper publishes. And not the field-level
|
|
32
|
+
* `ValuePredicate` of `values.ts`, which gates one settings-form field on a
|
|
33
|
+
* sibling field's value.
|
|
34
|
+
*/
|
|
35
|
+
import type { I18n, LocaleMap } from './descriptors.js';
|
|
36
|
+
import { i18nFindings, localeMapOf } from './i18n.js';
|
|
37
|
+
/** The junction's truthiness: a value that is not falsy and not an empty list. @experimental */
|
|
38
|
+
export declare const truthy: (v: unknown) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The value at a dotted path, or `undefined` where the path leaves the
|
|
41
|
+
* document — a missing segment answers `undefined`, never a throw. An absent
|
|
42
|
+
* or empty path is the value itself (a junction branch with no `path` reads
|
|
43
|
+
* the routed value whole). It walks any key at evaluation, on purpose: the
|
|
44
|
+
* junction shares this walker over data a task computed, and the segments a
|
|
45
|
+
* published-values path may not name (`__proto__`, `constructor`,
|
|
46
|
+
* `prototype`) are refused at declaration by `enabledWhenFindings`, not here.
|
|
47
|
+
* @experimental
|
|
48
|
+
*/
|
|
49
|
+
export declare function readPath(value: unknown, path?: string): unknown;
|
|
50
|
+
/** The predicate half of a junction branch and of an enabled-when: exactly one of the three. @experimental */
|
|
51
|
+
export interface Predicate {
|
|
52
|
+
/** Holds when the value strictly equals this literal. */
|
|
53
|
+
equals?: unknown;
|
|
54
|
+
/**
|
|
55
|
+
* Holds when the value strictly equals **the value at another path in the
|
|
56
|
+
* same document** — the two-port compare (D-4a, 2026-09-17).
|
|
57
|
+
*
|
|
58
|
+
* `equals` takes a literal, so a document could state *is the accused
|
|
59
|
+
* Vell?* and never *is the accused the culprit?* — which is the one
|
|
60
|
+
* question a genre that DERIVES a hidden fact has to ask, and the reason
|
|
61
|
+
* Whodunit could not adjudicate its own case. The other side is read out
|
|
62
|
+
* of the same document the subject was: the junction's routed value for a
|
|
63
|
+
* branch, the published values for an enabled-when.
|
|
64
|
+
*
|
|
65
|
+
* ⚠ **Two absences are not a match.** A path that leaves the document
|
|
66
|
+
* answers `undefined`, and if that counted as equal to an absent subject
|
|
67
|
+
* then an unwired port on each side would fire the branch that means *the
|
|
68
|
+
* accused IS the culprit*. Either side absent holds for nothing.
|
|
69
|
+
*
|
|
70
|
+
* Strict (`===`) like `equals`, so it compares a key and not a document:
|
|
71
|
+
* two structurally equal objects are not equal here, and a structured
|
|
72
|
+
* comparison belongs in a value the pipeline publishes as one.
|
|
73
|
+
*/
|
|
74
|
+
equalsPath?: string;
|
|
75
|
+
/** Holds when the value is truthy (`truthy`). */
|
|
76
|
+
truthy?: boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The conditions a predicate may state — **exactly one**, wherever it is read.
|
|
80
|
+
*
|
|
81
|
+
* Exported because the junction's own validator asks the same question of a
|
|
82
|
+
* branch (`validate.ts`) and asked it off a literal list; one list is what
|
|
83
|
+
* keeps a grammar that grew a third condition from being legal in one door
|
|
84
|
+
* and refused at the other.
|
|
85
|
+
* @experimental
|
|
86
|
+
*/
|
|
87
|
+
export declare const PREDICATE_CONDITION_KEYS: readonly string[];
|
|
88
|
+
/**
|
|
89
|
+
* Does the predicate hold over this value? `equals` is strict (`===`);
|
|
90
|
+
* `equalsPath` is that same strictness against the value at another path in
|
|
91
|
+
* `scope` — the document the subject itself was read from — and holds for
|
|
92
|
+
* nothing when either side is absent; `truthy` is the junction's truthiness;
|
|
93
|
+
* a predicate stating none of the three holds for nothing — the validators
|
|
94
|
+
* refuse one, but a stored document is judged by what it says.
|
|
95
|
+
*
|
|
96
|
+
* `scope` is optional so that every caller written before the two-port
|
|
97
|
+
* compare still compiles. A caller that does not pass it has no second side
|
|
98
|
+
* to read, so an `equalsPath` predicate holds for nothing there — the same
|
|
99
|
+
* answer an absent path gives, and never a silent `true`.
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
export declare function predicateHolds(pred: Predicate, value: unknown, scope?: unknown): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* One enabled-when predicate (plans/29 R-15): a declared condition over the
|
|
105
|
+
* session's published values that says whether an action is offered *now*.
|
|
106
|
+
* The junction clause's predicate shape, never code.
|
|
107
|
+
*
|
|
108
|
+
* A host publishes, per listing: `state.world.<slot>` and
|
|
109
|
+
* `state.cast.<key>.<slot>` (the resolved state), `session.fields.<key>`
|
|
110
|
+
* (the genre's fields as stored) and `session.generating`; and, for the
|
|
111
|
+
* `message` venue, `item.<field>` per message — `item.id`, `item.isNewest`,
|
|
112
|
+
* `item.hidden`, `item.generating`, `item.role`, `item.mine`,
|
|
113
|
+
* `item.hasSwipes`, `item.greeting`, `item.channel`, `item.speaker` (a
|
|
114
|
+
* participant reference, or null) and `item.characterLine` (lair re-plan
|
|
115
|
+
* R11). A predicate over `item.*` is evaluated
|
|
116
|
+
* where a message is at hand: the client per row, the server at the door.
|
|
117
|
+
* @experimental
|
|
118
|
+
*/
|
|
119
|
+
export interface EnabledWhen extends Predicate {
|
|
120
|
+
/**
|
|
121
|
+
* A dotted path into the published values — `state.world.location`,
|
|
122
|
+
* `session.generating`, `item.hidden`. **Not a port reference** (no `$`):
|
|
123
|
+
* actions live outside a run.
|
|
124
|
+
*/
|
|
125
|
+
on: string;
|
|
126
|
+
/** Why the control is grey when this predicate does not hold. Required (R-20: a string or a locale map with `en`). */
|
|
127
|
+
reason: I18n;
|
|
128
|
+
}
|
|
129
|
+
/** The keys an enabled-when may carry; anything else is a finding. @experimental */
|
|
130
|
+
export declare const ENABLED_WHEN_KEYS: readonly string[];
|
|
131
|
+
/** A single predicate or a list — a list means **all must hold**. @experimental */
|
|
132
|
+
export type EnabledWhenDecl = EnabledWhen | EnabledWhen[];
|
|
133
|
+
/**
|
|
134
|
+
* The verdict over one predicate set: enabled, or the first predicate that
|
|
135
|
+
* failed with its reason — a locale map, whatever spelling the author used.
|
|
136
|
+
* @experimental
|
|
137
|
+
*/
|
|
138
|
+
export type EnabledWhenVerdict = {
|
|
139
|
+
enabled: true;
|
|
140
|
+
} | {
|
|
141
|
+
enabled: false;
|
|
142
|
+
reason: LocaleMap;
|
|
143
|
+
failed: EnabledWhen;
|
|
144
|
+
};
|
|
145
|
+
export { i18nFindings, localeMapOf };
|
|
146
|
+
/** A value with the one field a predicate cannot do without — the shape the list form keeps. @experimental */
|
|
147
|
+
export declare const isEnabledWhenShaped: (p: unknown) => p is EnabledWhen;
|
|
148
|
+
/**
|
|
149
|
+
* The list form: a single predicate wrapped, a list copied, `reason` as a
|
|
150
|
+
* locale map, nothing else touched. Absent is the empty list — an action
|
|
151
|
+
* declaring no predicate is always enabled. An entry that is not a
|
|
152
|
+
* predicate at all — no string `on` — is dropped here rather than read: a
|
|
153
|
+
* stored document from before this shape must not take a listing down, and
|
|
154
|
+
* `enabledWhenFindings` names the entry wherever the declaration is judged
|
|
155
|
+
* (construction, `validate()`, the host's publish).
|
|
156
|
+
* @internal
|
|
157
|
+
*/
|
|
158
|
+
export declare function normalizeEnabledWhen(x: unknown): EnabledWhen[];
|
|
159
|
+
/**
|
|
160
|
+
* Evaluate a predicate set over a published-values document: every
|
|
161
|
+
* predicate must hold, and the **first** that does not names the reason —
|
|
162
|
+
* the order the author wrote them in is the order a person is told them in.
|
|
163
|
+
* Pure and isomorphic: the client runs it per message row with the same
|
|
164
|
+
* `item` document the server builds at the door.
|
|
165
|
+
* @experimental
|
|
166
|
+
*/
|
|
167
|
+
export declare function evaluateEnabledWhen(preds: ReadonlyArray<EnabledWhen> | EnabledWhen | undefined | null, doc: unknown): EnabledWhenVerdict;
|
|
168
|
+
/** The predicates over one prefix (`item`) and the rest, split for a host that evaluates them in two places. @internal */
|
|
169
|
+
export declare function partitionEnabledWhen(preds: ReadonlyArray<EnabledWhen>, prefix: string): {
|
|
170
|
+
under: EnabledWhen[];
|
|
171
|
+
rest: EnabledWhen[];
|
|
172
|
+
};
|
|
173
|
+
/**
|
|
174
|
+
* Every fault in one enabled-when declaration — a predicate or a list — as
|
|
175
|
+
* sentences that say what to do instead (the teaching-error pattern, 15
|
|
176
|
+
* §1.3). Empty when it is sound, and for `undefined` (no predicate). Applied
|
|
177
|
+
* to an action's `enabledWhen` at construction, in `validate()` and at the
|
|
178
|
+
* host's publish, and to a genre's defaults at declaration.
|
|
179
|
+
* @experimental
|
|
180
|
+
*/
|
|
181
|
+
export declare function enabledWhenFindings(raw: unknown, at?: string): string[];
|
|
182
|
+
//# sourceMappingURL=predicates.d.ts.map
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Predicates — one declared shape, read in two places (plans/29 R-15
|
|
3
|
+
* *enabled-when*; 20 §10 *junction*; ruled 2026-09-15, built 2026-09-17 as
|
|
4
|
+
* U5e).
|
|
5
|
+
*
|
|
6
|
+
* A **junction** clause branches on a value a task computed: each branch is
|
|
7
|
+
* `{ path?, equals? | equalsPath? | truthy? }` over that value. An action's
|
|
8
|
+
* **enabled-when** is the same predicate over the session's **published
|
|
9
|
+
* values** — the document a host builds from what a session has already said
|
|
10
|
+
* about itself (`state.world.location`, `session.generating`, a message's
|
|
11
|
+
* `item.hidden`). The core here — `readPath` and `predicateHolds` — is what
|
|
12
|
+
* both read, so a predicate that fires a branch and one that greys a button
|
|
13
|
+
* can never mean two things.
|
|
14
|
+
*
|
|
15
|
+
* ## The two-port compare (D-4a, 2026-09-17)
|
|
16
|
+
*
|
|
17
|
+
* `equals` takes a literal, so until this the grammar could ask *is the
|
|
18
|
+
* accused Vell?* and never *is the accused the culprit?* — and a genre that
|
|
19
|
+
* derives a hidden fact rather than authoring it has no other question.
|
|
20
|
+
* `equalsPath` is the second path: the same document, read twice, compared
|
|
21
|
+
* strictly. Additive in the single-version sense (ruling 2026-09-08) — a
|
|
22
|
+
* stored document without it validates and hashes exactly as before. Both
|
|
23
|
+
* doors read it: the junction's `fires()` hands the routed value in as the
|
|
24
|
+
* scope, an enabled-when's evaluator hands in the published values.
|
|
25
|
+
*
|
|
26
|
+
* ## What an enabled-when is not
|
|
27
|
+
*
|
|
28
|
+
* Not a port reference: `on` is a dotted path into the published values,
|
|
29
|
+
* never `$.parse.call` — an action lives outside a run, and there is no port
|
|
30
|
+
* to read. Not code: a richer decision belongs in a task the junction reads,
|
|
31
|
+
* or in a value the state-keeper publishes. And not the field-level
|
|
32
|
+
* `ValuePredicate` of `values.ts`, which gates one settings-form field on a
|
|
33
|
+
* sibling field's value.
|
|
34
|
+
*/
|
|
35
|
+
import { i18nFindings, localeMapOf } from './i18n.js';
|
|
36
|
+
/** The junction's truthiness: a value that is not falsy and not an empty list. @experimental */
|
|
37
|
+
export const truthy = (v) => !!v && !(Array.isArray(v) && v.length === 0);
|
|
38
|
+
/**
|
|
39
|
+
* The value at a dotted path, or `undefined` where the path leaves the
|
|
40
|
+
* document — a missing segment answers `undefined`, never a throw. An absent
|
|
41
|
+
* or empty path is the value itself (a junction branch with no `path` reads
|
|
42
|
+
* the routed value whole). It walks any key at evaluation, on purpose: the
|
|
43
|
+
* junction shares this walker over data a task computed, and the segments a
|
|
44
|
+
* published-values path may not name (`__proto__`, `constructor`,
|
|
45
|
+
* `prototype`) are refused at declaration by `enabledWhenFindings`, not here.
|
|
46
|
+
* @experimental
|
|
47
|
+
*/
|
|
48
|
+
export function readPath(value, path) {
|
|
49
|
+
if (!path)
|
|
50
|
+
return value;
|
|
51
|
+
let cur = value;
|
|
52
|
+
for (const seg of path.split('.')) {
|
|
53
|
+
if (cur == null)
|
|
54
|
+
return undefined;
|
|
55
|
+
cur = cur[seg];
|
|
56
|
+
}
|
|
57
|
+
return cur;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The conditions a predicate may state — **exactly one**, wherever it is read.
|
|
61
|
+
*
|
|
62
|
+
* Exported because the junction's own validator asks the same question of a
|
|
63
|
+
* branch (`validate.ts`) and asked it off a literal list; one list is what
|
|
64
|
+
* keeps a grammar that grew a third condition from being legal in one door
|
|
65
|
+
* and refused at the other.
|
|
66
|
+
* @experimental
|
|
67
|
+
*/
|
|
68
|
+
export const PREDICATE_CONDITION_KEYS = ['equals', 'equalsPath', 'truthy'];
|
|
69
|
+
/**
|
|
70
|
+
* Does the predicate hold over this value? `equals` is strict (`===`);
|
|
71
|
+
* `equalsPath` is that same strictness against the value at another path in
|
|
72
|
+
* `scope` — the document the subject itself was read from — and holds for
|
|
73
|
+
* nothing when either side is absent; `truthy` is the junction's truthiness;
|
|
74
|
+
* a predicate stating none of the three holds for nothing — the validators
|
|
75
|
+
* refuse one, but a stored document is judged by what it says.
|
|
76
|
+
*
|
|
77
|
+
* `scope` is optional so that every caller written before the two-port
|
|
78
|
+
* compare still compiles. A caller that does not pass it has no second side
|
|
79
|
+
* to read, so an `equalsPath` predicate holds for nothing there — the same
|
|
80
|
+
* answer an absent path gives, and never a silent `true`.
|
|
81
|
+
* @internal
|
|
82
|
+
*/
|
|
83
|
+
export function predicateHolds(pred, value, scope) {
|
|
84
|
+
if (pred.equals !== undefined)
|
|
85
|
+
return value === pred.equals;
|
|
86
|
+
if (pred.equalsPath !== undefined) {
|
|
87
|
+
// A stored document is judged by what it says, and what it says may be
|
|
88
|
+
// wrong: `equalsPath: 3` reaches `readPath` as a number and `3.split`
|
|
89
|
+
// throws, which would take a whole listing down rather than grey one
|
|
90
|
+
// button. The validators refuse it at the door; here it simply does
|
|
91
|
+
// not hold, on the same rule `normalizeEnabledWhen` drops a malformed
|
|
92
|
+
// entry by.
|
|
93
|
+
if (typeof pred.equalsPath !== 'string' || !pred.equalsPath)
|
|
94
|
+
return false;
|
|
95
|
+
if (value === undefined)
|
|
96
|
+
return false;
|
|
97
|
+
const other = readPath(scope, pred.equalsPath);
|
|
98
|
+
return other !== undefined && value === other;
|
|
99
|
+
}
|
|
100
|
+
if (pred.truthy)
|
|
101
|
+
return truthy(value);
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
/** The keys an enabled-when may carry; anything else is a finding. @experimental */
|
|
105
|
+
export const ENABLED_WHEN_KEYS = [
|
|
106
|
+
'on',
|
|
107
|
+
...PREDICATE_CONDITION_KEYS,
|
|
108
|
+
'reason',
|
|
109
|
+
];
|
|
110
|
+
/** Segments an `on` path may not walk: a published-values path names data, never a prototype. */
|
|
111
|
+
const FORBIDDEN_SEGMENTS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
112
|
+
/** What `equals` may compare against — a JSON scalar. */
|
|
113
|
+
const isPrimitive = (v) => v === null || ['string', 'number', 'boolean'].includes(typeof v);
|
|
114
|
+
// `localeMapOf` and `i18nFindings` live in `i18n.ts` with the type they read;
|
|
115
|
+
// re-exported here because the enabled-when vocabulary has always offered them.
|
|
116
|
+
export { i18nFindings, localeMapOf };
|
|
117
|
+
/** A value with the one field a predicate cannot do without — the shape the list form keeps. @experimental */
|
|
118
|
+
export const isEnabledWhenShaped = (p) => !!p &&
|
|
119
|
+
typeof p === 'object' &&
|
|
120
|
+
!Array.isArray(p) &&
|
|
121
|
+
typeof p.on === 'string';
|
|
122
|
+
/**
|
|
123
|
+
* The list form: a single predicate wrapped, a list copied, `reason` as a
|
|
124
|
+
* locale map, nothing else touched. Absent is the empty list — an action
|
|
125
|
+
* declaring no predicate is always enabled. An entry that is not a
|
|
126
|
+
* predicate at all — no string `on` — is dropped here rather than read: a
|
|
127
|
+
* stored document from before this shape must not take a listing down, and
|
|
128
|
+
* `enabledWhenFindings` names the entry wherever the declaration is judged
|
|
129
|
+
* (construction, `validate()`, the host's publish).
|
|
130
|
+
* @internal
|
|
131
|
+
*/
|
|
132
|
+
export function normalizeEnabledWhen(x) {
|
|
133
|
+
if (x == null)
|
|
134
|
+
return [];
|
|
135
|
+
const list = Array.isArray(x) ? x : [x];
|
|
136
|
+
return list.filter(isEnabledWhenShaped).map((p) => ({
|
|
137
|
+
...p,
|
|
138
|
+
reason: p.reason === undefined ? p.reason : localeMapOf(p.reason),
|
|
139
|
+
}));
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Evaluate a predicate set over a published-values document: every
|
|
143
|
+
* predicate must hold, and the **first** that does not names the reason —
|
|
144
|
+
* the order the author wrote them in is the order a person is told them in.
|
|
145
|
+
* Pure and isomorphic: the client runs it per message row with the same
|
|
146
|
+
* `item` document the server builds at the door.
|
|
147
|
+
* @experimental
|
|
148
|
+
*/
|
|
149
|
+
export function evaluateEnabledWhen(preds, doc) {
|
|
150
|
+
for (const pred of normalizeEnabledWhen(preds)) {
|
|
151
|
+
// The whole document travels beside the subject: `equalsPath` reads its
|
|
152
|
+
// other side out of the same published values `on` was read from.
|
|
153
|
+
if (predicateHolds(pred, readPath(doc, pred.on), doc))
|
|
154
|
+
continue;
|
|
155
|
+
return { enabled: false, reason: localeMapOf(pred.reason), failed: pred };
|
|
156
|
+
}
|
|
157
|
+
return { enabled: true };
|
|
158
|
+
}
|
|
159
|
+
/** The predicates over one prefix (`item`) and the rest, split for a host that evaluates them in two places. @internal */
|
|
160
|
+
export function partitionEnabledWhen(preds, prefix) {
|
|
161
|
+
const under = [];
|
|
162
|
+
const rest = [];
|
|
163
|
+
for (const p of preds)
|
|
164
|
+
(p.on === prefix || p.on.startsWith(`${prefix}.`) ? under : rest).push(p);
|
|
165
|
+
return { under, rest };
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Every fault in one enabled-when declaration — a predicate or a list — as
|
|
169
|
+
* sentences that say what to do instead (the teaching-error pattern, 15
|
|
170
|
+
* §1.3). Empty when it is sound, and for `undefined` (no predicate). Applied
|
|
171
|
+
* to an action's `enabledWhen` at construction, in `validate()` and at the
|
|
172
|
+
* host's publish, and to a genre's defaults at declaration.
|
|
173
|
+
* @experimental
|
|
174
|
+
*/
|
|
175
|
+
export function enabledWhenFindings(raw, at = 'enabledWhen') {
|
|
176
|
+
if (raw === undefined || raw === null)
|
|
177
|
+
return [];
|
|
178
|
+
const list = Array.isArray(raw) ? raw : [raw];
|
|
179
|
+
const out = [];
|
|
180
|
+
list.forEach((p, i) => {
|
|
181
|
+
const where = Array.isArray(raw) ? `${at}[${i}]` : at;
|
|
182
|
+
if (!p || typeof p !== 'object' || Array.isArray(p)) {
|
|
183
|
+
out.push(`${where}: an enabled-when is { on, equals | truthy, reason } — a predicate over ` +
|
|
184
|
+
`the session's published values, such as { on: 'state.world.location', truthy: true, ` +
|
|
185
|
+
`reason: { en: 'Set a location first' } }`);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const e = p;
|
|
189
|
+
if (typeof e.on !== 'string' || !e.on)
|
|
190
|
+
out.push(`${where}: 'on' is required — a published-values path such as 'state.world.location' ` +
|
|
191
|
+
`or 'session.generating' (never a port reference: actions live outside a run)`);
|
|
192
|
+
else if (e.on.startsWith('$'))
|
|
193
|
+
out.push(`${where}: 'on' is '${e.on}', which reads as a port reference — an enabled-when names ` +
|
|
194
|
+
`a published-values path such as 'state.world.location'; actions live outside a run ` +
|
|
195
|
+
`and have no ports to read`);
|
|
196
|
+
else {
|
|
197
|
+
const walked = e.on.split('.').find((seg) => FORBIDDEN_SEGMENTS.has(seg));
|
|
198
|
+
if (walked)
|
|
199
|
+
out.push(`${where}: 'on' walks '${walked}' — a published-values path names data ` +
|
|
200
|
+
`('state.world.location', 'item.hidden'), never a prototype`);
|
|
201
|
+
}
|
|
202
|
+
const stated = PREDICATE_CONDITION_KEYS.filter((k) => e[k] !== undefined);
|
|
203
|
+
if (stated.length !== 1)
|
|
204
|
+
out.push(`${where}: states ${stated.length || 'no'} conditions — exactly one of ` +
|
|
205
|
+
`${PREDICATE_CONDITION_KEYS.join(' / ')} per predicate (the junction rule, 20 ` +
|
|
206
|
+
`§10); a richer decision belongs in a value the pipeline publishes`);
|
|
207
|
+
if (e.truthy !== undefined && typeof e.truthy !== 'boolean')
|
|
208
|
+
out.push(`${where}: 'truthy' is a boolean — write truthy: true`);
|
|
209
|
+
else if (e.truthy === false)
|
|
210
|
+
out.push(`${where}: 'truthy: false' states nothing — write truthy: true to require a value, ` +
|
|
211
|
+
`or equals: false to require a false one`);
|
|
212
|
+
if (e.equals !== undefined && !isPrimitive(e.equals))
|
|
213
|
+
out.push(`${where}: 'equals' is a primitive — a string, number, boolean or null; a structured ` +
|
|
214
|
+
`comparison belongs in a value the pipeline publishes as one`);
|
|
215
|
+
// The other side of a two-port compare is a path, judged exactly as `on`
|
|
216
|
+
// is: it names data in the same document, never a port and never a
|
|
217
|
+
// prototype. Refused when it is not a string at all — `equalsPath: 3`
|
|
218
|
+
// would otherwise read as a comparison against nothing and quietly
|
|
219
|
+
// never hold.
|
|
220
|
+
if (e.equalsPath !== undefined) {
|
|
221
|
+
if (typeof e.equalsPath !== 'string' || !e.equalsPath)
|
|
222
|
+
out.push(`${where}: 'equalsPath' is a path, not a value — the OTHER side of the ` +
|
|
223
|
+
`comparison, read from the same document as 'on' (e.g. ` +
|
|
224
|
+
`'state.world.culprit'); to compare against a literal, write equals:`);
|
|
225
|
+
else if (e.equalsPath.startsWith('$'))
|
|
226
|
+
out.push(`${where}: 'equalsPath' is '${e.equalsPath}', which reads as a port reference — ` +
|
|
227
|
+
`it names a published-values path exactly as 'on' does; actions live ` +
|
|
228
|
+
`outside a run and have no ports to read`);
|
|
229
|
+
else {
|
|
230
|
+
const walkedOther = e.equalsPath.split('.').find((seg) => FORBIDDEN_SEGMENTS.has(seg));
|
|
231
|
+
if (walkedOther)
|
|
232
|
+
out.push(`${where}: 'equalsPath' walks '${walkedOther}' — a published-values path ` +
|
|
233
|
+
`names data ('state.world.location', 'item.hidden'), never a prototype`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
if (e.reason === undefined)
|
|
237
|
+
out.push(`${where}: 'reason' is required — why the control is grey when the predicate does not ` +
|
|
238
|
+
`hold, a locale map with 'en' (R-20)`);
|
|
239
|
+
// The reason's text is display text and gets R-20's one sentence, a
|
|
240
|
+
// blank one included (01 §13: one verdict per law, `core:verdict/i18n`).
|
|
241
|
+
else
|
|
242
|
+
out.push(...i18nFindings(e.reason, `${where}.reason`));
|
|
243
|
+
for (const k of Object.keys(e))
|
|
244
|
+
if (!ENABLED_WHEN_KEYS.includes(k))
|
|
245
|
+
out.push(`${where}: '${k}' is not part of an enabled-when — one of ${ENABLED_WHEN_KEYS.join(', ')}`);
|
|
246
|
+
});
|
|
247
|
+
return out;
|
|
248
|
+
}
|
|
249
|
+
//# sourceMappingURL=predicates.js.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preview runs — "show me what would be sent, and why" (debug mode in chat).
|
|
3
|
+
*
|
|
4
|
+
* A preview is **not a second estimator**. It is the ordinary run, stopping at the
|
|
5
|
+
* pre-call substrate: input resolved, context assembled, payload formed, token count
|
|
6
|
+
* taken — and then `halt` instead of `call`. That is the whole design constraint. Any
|
|
7
|
+
* implementation that computes "what we would send" on a separate path drifts from what
|
|
8
|
+
* actually gets sent, silently, and is most wrong exactly when someone is debugging
|
|
9
|
+
* because something is off.
|
|
10
|
+
*
|
|
11
|
+
* Almost everything the panel shows is already in the receipt: Assemble records the
|
|
12
|
+
* allocation it computed and the inputs it computed it from (16 §5a), and the Provider's
|
|
13
|
+
* resolved input is recorded like any node's. The preview hoists those into one place so
|
|
14
|
+
* a UI does not have to reassemble them from three node receipts, and adds the one thing
|
|
15
|
+
* that only exists at the call site — the formed payload and its token count.
|
|
16
|
+
*/
|
|
17
|
+
import type { Receipt } from './receipt.js';
|
|
18
|
+
/** @experimental */
|
|
19
|
+
export interface PreviewBlock {
|
|
20
|
+
id?: string;
|
|
21
|
+
sourceKey?: string;
|
|
22
|
+
tokens: number;
|
|
23
|
+
included: boolean;
|
|
24
|
+
weight?: number;
|
|
25
|
+
priority?: string;
|
|
26
|
+
/**
|
|
27
|
+
* Why this block is here, or isn't. The panel is only worth opening if this is
|
|
28
|
+
* populated, and it can only be populated if each step leaves its trace on the
|
|
29
|
+
* item — the trigger Query records which key matched, the rank Task records the
|
|
30
|
+
* probability roll and the group it won or lost, Assemble records budget exhaustion.
|
|
31
|
+
*/
|
|
32
|
+
reason?: string;
|
|
33
|
+
/** The full trail, each step's line in order (src/wire.ts `why`). */
|
|
34
|
+
why?: string[];
|
|
35
|
+
role?: string;
|
|
36
|
+
}
|
|
37
|
+
/** @experimental */
|
|
38
|
+
export interface PreviewReport {
|
|
39
|
+
/** Where the run stopped, and why that node. */
|
|
40
|
+
atNode: string;
|
|
41
|
+
definitionId: string;
|
|
42
|
+
targetedBy: 'first-provider-on-spine' | 'explicit';
|
|
43
|
+
/** Metadata only — material never leaves core (F18). */
|
|
44
|
+
connection?: {
|
|
45
|
+
id?: string;
|
|
46
|
+
kind?: string;
|
|
47
|
+
contextLength?: number;
|
|
48
|
+
tokenizer?: string;
|
|
49
|
+
};
|
|
50
|
+
budget?: {
|
|
51
|
+
maxContext?: number;
|
|
52
|
+
reserved?: number;
|
|
53
|
+
available?: number;
|
|
54
|
+
};
|
|
55
|
+
/** The payload as it would have gone out, and the count that would have applied. */
|
|
56
|
+
context: {
|
|
57
|
+
rendered: unknown;
|
|
58
|
+
tokens: number;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* How blocks became that payload (16 §7). Present once a Provider declares a `wire`
|
|
62
|
+
* slot — and it is what makes the scaffolding cost visible rather than a mystery
|
|
63
|
+
* gap between "my blocks add up to 3,000" and "it said 3,180".
|
|
64
|
+
*/
|
|
65
|
+
wire?: {
|
|
66
|
+
format: string;
|
|
67
|
+
blockTokens: number;
|
|
68
|
+
overheadTokens: number;
|
|
69
|
+
};
|
|
70
|
+
blocks: PreviewBlock[];
|
|
71
|
+
totals: {
|
|
72
|
+
blocks: number;
|
|
73
|
+
included: number;
|
|
74
|
+
dropped: number;
|
|
75
|
+
tokensIncluded: number;
|
|
76
|
+
tokensDropped: number;
|
|
77
|
+
/** Positive means the formed payload does not fit — the estimator was wrong. */
|
|
78
|
+
overBudgetBy?: number;
|
|
79
|
+
};
|
|
80
|
+
/** Whatever the node feeding the context port produced — Assemble's allocation record. */
|
|
81
|
+
allocation?: unknown;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* What a counter measures when it is handed something that is not a string.
|
|
85
|
+
*
|
|
86
|
+
* A wire payload is a messages array as often as it is prose, and every counter
|
|
87
|
+
* in the SDK has to agree about what counting one of those means — otherwise a
|
|
88
|
+
* receipt's figure and a budget's figure are measurements of two different
|
|
89
|
+
* things. Shared with `src/tokenizers.ts` rather than reimplemented there.
|
|
90
|
+
* @experimental
|
|
91
|
+
*/
|
|
92
|
+
export declare const countableText: (v: unknown) => string;
|
|
93
|
+
/**
|
|
94
|
+
* A stand-in tokenizer, and the floor everything else degrades to.
|
|
95
|
+
*
|
|
96
|
+
* The real one comes from connection metadata (`tokenizer`), is resolved and
|
|
97
|
+
* loaded ONCE before the run starts (`RunOptions.tokenizer`, `loadTokenizer`)
|
|
98
|
+
* and reused — counting sixty blocks should be sixty cheap calls against
|
|
99
|
+
* something already resident, not sixty model loads. This is what counts when
|
|
100
|
+
* no id was configured, when no loader is registered for the one that was, and
|
|
101
|
+
* when a loader threw: budgeting degrades to an estimate rather than failing a
|
|
102
|
+
* run over a tokenizer.
|
|
103
|
+
* @internal
|
|
104
|
+
*/
|
|
105
|
+
export declare const roughTokens: (v: unknown) => number;
|
|
106
|
+
/** Choose where a preview stops. @experimental */
|
|
107
|
+
export declare function previewTarget(nodes: Array<{
|
|
108
|
+
key: string;
|
|
109
|
+
kind: string;
|
|
110
|
+
clauseId?: string;
|
|
111
|
+
position: number;
|
|
112
|
+
}>, explicit?: string): {
|
|
113
|
+
key: string;
|
|
114
|
+
targetedBy: PreviewReport['targetedBy'];
|
|
115
|
+
} | undefined;
|
|
116
|
+
/** @experimental */
|
|
117
|
+
export declare function renderPreview(p: PreviewReport): string;
|
|
118
|
+
/** Convenience for a UI: the preview, if this receipt is one. @experimental */
|
|
119
|
+
export declare const previewOf: (r: Receipt) => PreviewReport | undefined;
|
|
120
|
+
//# sourceMappingURL=preview.d.ts.map
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preview runs — "show me what would be sent, and why" (debug mode in chat).
|
|
3
|
+
*
|
|
4
|
+
* A preview is **not a second estimator**. It is the ordinary run, stopping at the
|
|
5
|
+
* pre-call substrate: input resolved, context assembled, payload formed, token count
|
|
6
|
+
* taken — and then `halt` instead of `call`. That is the whole design constraint. Any
|
|
7
|
+
* implementation that computes "what we would send" on a separate path drifts from what
|
|
8
|
+
* actually gets sent, silently, and is most wrong exactly when someone is debugging
|
|
9
|
+
* because something is off.
|
|
10
|
+
*
|
|
11
|
+
* Almost everything the panel shows is already in the receipt: Assemble records the
|
|
12
|
+
* allocation it computed and the inputs it computed it from (16 §5a), and the Provider's
|
|
13
|
+
* resolved input is recorded like any node's. The preview hoists those into one place so
|
|
14
|
+
* a UI does not have to reassemble them from three node receipts, and adds the one thing
|
|
15
|
+
* that only exists at the call site — the formed payload and its token count.
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* What a counter measures when it is handed something that is not a string.
|
|
19
|
+
*
|
|
20
|
+
* A wire payload is a messages array as often as it is prose, and every counter
|
|
21
|
+
* in the SDK has to agree about what counting one of those means — otherwise a
|
|
22
|
+
* receipt's figure and a budget's figure are measurements of two different
|
|
23
|
+
* things. Shared with `src/tokenizers.ts` rather than reimplemented there.
|
|
24
|
+
* @experimental
|
|
25
|
+
*/
|
|
26
|
+
export const countableText = (v) => typeof v === 'string' ? v : JSON.stringify(v ?? '');
|
|
27
|
+
/**
|
|
28
|
+
* A stand-in tokenizer, and the floor everything else degrades to.
|
|
29
|
+
*
|
|
30
|
+
* The real one comes from connection metadata (`tokenizer`), is resolved and
|
|
31
|
+
* loaded ONCE before the run starts (`RunOptions.tokenizer`, `loadTokenizer`)
|
|
32
|
+
* and reused — counting sixty blocks should be sixty cheap calls against
|
|
33
|
+
* something already resident, not sixty model loads. This is what counts when
|
|
34
|
+
* no id was configured, when no loader is registered for the one that was, and
|
|
35
|
+
* when a loader threw: budgeting degrades to an estimate rather than failing a
|
|
36
|
+
* run over a tokenizer.
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export const roughTokens = (v) => Math.ceil(countableText(v).length / 4);
|
|
40
|
+
/** Choose where a preview stops. @experimental */
|
|
41
|
+
export function previewTarget(nodes, explicit) {
|
|
42
|
+
if (explicit)
|
|
43
|
+
return { key: explicit, targetedBy: 'explicit' };
|
|
44
|
+
// "The first Provider" needs one qualifier: in any retrieval pipeline the literally
|
|
45
|
+
// first Provider is `embed`, which lives inside the gather block — stopping there
|
|
46
|
+
// would preview a context that had not been retrieved yet. Spine-only is the rule
|
|
47
|
+
// that means what people intend, and it is the same rule
|
|
48
|
+
// `slot.downstreamOracle()` already resolves with (16 §5b-i).
|
|
49
|
+
const spine = nodes
|
|
50
|
+
.filter((n) => !n.clauseId && n.kind === 'oracle')
|
|
51
|
+
.sort((a, b) => a.position - b.position);
|
|
52
|
+
return spine[0] ? { key: spine[0].key, targetedBy: 'first-provider-on-spine' } : undefined;
|
|
53
|
+
}
|
|
54
|
+
/** @experimental */
|
|
55
|
+
export function renderPreview(p) {
|
|
56
|
+
const out = [];
|
|
57
|
+
out.push(`preview · stopped before ${p.atNode} (${p.definitionId}) · ${p.targetedBy}`);
|
|
58
|
+
if (p.connection) {
|
|
59
|
+
out.push(` connection ${p.connection.kind ?? '?'}` +
|
|
60
|
+
(p.connection.contextLength ? ` · context ${p.connection.contextLength}` : '') +
|
|
61
|
+
(p.connection.tokenizer ? ` · tokenizer ${p.connection.tokenizer}` : ''));
|
|
62
|
+
}
|
|
63
|
+
if (p.budget) {
|
|
64
|
+
out.push(` budget: ${p.budget.available ?? '?'} available of ${p.budget.maxContext ?? '?'}`);
|
|
65
|
+
}
|
|
66
|
+
if (p.wire) {
|
|
67
|
+
out.push(` wire ${p.wire.format}: ${p.wire.blockTokens} block + ${p.wire.overheadTokens} scaffold`);
|
|
68
|
+
}
|
|
69
|
+
out.push(` would send ${p.context.tokens} tokens · ${p.totals.included}/${p.totals.blocks} blocks included` +
|
|
70
|
+
(p.totals.overBudgetBy ? ` ⚠ OVER by ${p.totals.overBudgetBy}` : ''));
|
|
71
|
+
for (const b of p.blocks) {
|
|
72
|
+
out.push(` ${b.included ? '✓' : '✗'} ${(b.sourceKey ?? b.id ?? '?').padEnd(20)} ${String(b.tokens).padStart(6)} tok` +
|
|
73
|
+
(b.reason ? ` ${b.reason}` : ''));
|
|
74
|
+
// The trail is the difference between a panel worth opening and a token counter.
|
|
75
|
+
for (const w of b.why ?? [])
|
|
76
|
+
out.push(` · ${w}`);
|
|
77
|
+
}
|
|
78
|
+
return out.join('\n');
|
|
79
|
+
}
|
|
80
|
+
/** Convenience for a UI: the preview, if this receipt is one. @experimental */
|
|
81
|
+
export const previewOf = (r) => r.preview;
|
|
82
|
+
//# sourceMappingURL=preview.js.map
|