@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
package/dist/bands.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bands as template variables (typed templates P2, 2026-09-27).
|
|
3
|
+
*
|
|
4
|
+
* A **band** is the ranker's word for one source's slice of the context window
|
|
5
|
+
* (`bandIntent`, candidates.ts). A source that puts its own band in the window
|
|
6
|
+
* — Twenty Questions' secret entry — now also **declares** it: the key it
|
|
7
|
+
* publishes and the registered variable that says how the band is laid out.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const varSecretEntry = definePluginVariable('showcase.twenty-questions', {
|
|
11
|
+
* id: 'showcase.twenty-questions:var/secret-entry@1',
|
|
12
|
+
* scope: { secretEntry: { type: 'record', of: { type: 'string' } } },
|
|
13
|
+
* sample: { 'The Brass Clock': 'A clock that rings when nobody winds it.' },
|
|
14
|
+
* })
|
|
15
|
+
* describeTaskDefinition({ …, bands: { secretEntry: varSecretEntry } })
|
|
16
|
+
* // …and a context template places it as {{{secretEntry}}}.
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Declared, a band is a **top-level template name**: Assemble exposes it as
|
|
20
|
+
* `{{{secretEntry}}}`, rendered through the variable's selected layout (the
|
|
21
|
+
* in-code fallback is the band as title-keyed minified JSON). So a band key is
|
|
22
|
+
* an identifier, and it means one thing: two declarers naming the same key
|
|
23
|
+
* with different variables, or a band shadowing a name core already renders,
|
|
24
|
+
* is refused with both declarers named.
|
|
25
|
+
*
|
|
26
|
+
* Which bands a node renders is its own `variables` slot's `renders` plus —
|
|
27
|
+
* when the slot says `rendersBands` — every band declared upstream of the
|
|
28
|
+
* named in-port, followed through any node that takes candidates in
|
|
29
|
+
* (concatenation, fusion, ranking). `rendersAt` is that answer.
|
|
30
|
+
*/
|
|
31
|
+
import { type Descriptor, type SlotDecl } from './descriptors.js';
|
|
32
|
+
import type { DocEdge, DocNode } from './document.js';
|
|
33
|
+
import { type VariableDecl, type VariableId } from './variables.js';
|
|
34
|
+
/** A band's key — a top-level template name, so an identifier. @experimental */
|
|
35
|
+
export type BandKey = string;
|
|
36
|
+
/** @experimental */
|
|
37
|
+
export declare const isBandKey: (key: string) => boolean;
|
|
38
|
+
/** `secret-entry` → `secretEntry`: the identifier a refusal suggests. @internal */
|
|
39
|
+
export declare function bandKeySuggestion(key: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Names Assemble puts at the top of a context template that are not bands and
|
|
42
|
+
* not registered variables — what a band key may never be.
|
|
43
|
+
*
|
|
44
|
+
* Assemble's own values. A band called `budget` would shadow the budget a
|
|
45
|
+
* template reads, silently, on every turn.
|
|
46
|
+
* @internal
|
|
47
|
+
*/
|
|
48
|
+
export declare const ASSEMBLE_OWN_TEMPLATE_NAMES: readonly string[];
|
|
49
|
+
/**
|
|
50
|
+
* Refuse a definition's band declarations — at `describe…Definition`, where
|
|
51
|
+
* the author is.
|
|
52
|
+
*
|
|
53
|
+
* - the key is an identifier (a band is a template name);
|
|
54
|
+
* - the variable is registered (`defineVariable` / `definePluginVariable`) and
|
|
55
|
+
* its scope declares the key, because a layout renders `{ [key]: value }`;
|
|
56
|
+
* - the key does not shadow a name core renders — Assemble's own, or a
|
|
57
|
+
* core variable's that is not this band's own variable;
|
|
58
|
+
* - no other registered definition declares the key with a different variable.
|
|
59
|
+
*
|
|
60
|
+
* Each refusal names the fix.
|
|
61
|
+
* @internal
|
|
62
|
+
*/
|
|
63
|
+
export declare function checkBandDeclarations(d: Descriptor, others: Iterable<Descriptor>): void;
|
|
64
|
+
/**
|
|
65
|
+
* What `bandsReaching` needs from a node's definition: its in-ports and the
|
|
66
|
+
* bands it declares. A `Descriptor` satisfies it, and so does a registry row
|
|
67
|
+
* (whose policy carries the band ids, `DefinitionPolicy.bands`) — which is how
|
|
68
|
+
* a host reading rows answers without loading a plugin (F6).
|
|
69
|
+
* @experimental
|
|
70
|
+
*/
|
|
71
|
+
export interface BandSource {
|
|
72
|
+
ports?: {
|
|
73
|
+
in?: Record<string, unknown>;
|
|
74
|
+
};
|
|
75
|
+
bands?: Record<BandKey, VariableDecl | VariableId>;
|
|
76
|
+
/**
|
|
77
|
+
* The out-ports that carry a band (`Descriptor.bandPorts`); a band not
|
|
78
|
+
* named here is carried on every out-port.
|
|
79
|
+
*/
|
|
80
|
+
bandPorts?: Record<BandKey, readonly string[]>;
|
|
81
|
+
}
|
|
82
|
+
/** One declared band as it reaches a node. @experimental */
|
|
83
|
+
export interface ReachingBand {
|
|
84
|
+
variable: VariableId;
|
|
85
|
+
/** The node that declares it — `key (definitionId)`, for a refusal to name. */
|
|
86
|
+
declarer: string;
|
|
87
|
+
}
|
|
88
|
+
/** Two declarers naming one band differently, or a band shadowing a name the node renders. @experimental */
|
|
89
|
+
export declare class BandCollisionError extends Error {
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Every band declared upstream of `nodeKey`'s in-port `port`.
|
|
93
|
+
*
|
|
94
|
+
* Walks the edges backwards from the port: each producer's declared `bands`
|
|
95
|
+
* are collected, and the walk continues through every in-port the producer
|
|
96
|
+
* declares as a candidates port — so a band declared at a source reaches a
|
|
97
|
+
* ranker through a concatenation or a fusion, and Assemble through the ranker.
|
|
98
|
+
* A producer declaring no candidates in-port is where the walk stops. A band
|
|
99
|
+
* whose declarer names the out-ports carrying it (`bandPorts`) reaches only
|
|
100
|
+
* through an edge from one of those ports.
|
|
101
|
+
*
|
|
102
|
+
* Throws `BandCollisionError`, naming both declarers, when two of them name
|
|
103
|
+
* one key with different variables.
|
|
104
|
+
* @experimental
|
|
105
|
+
*/
|
|
106
|
+
export declare function bandsReaching(doc: {
|
|
107
|
+
nodes: readonly DocNode[];
|
|
108
|
+
edges: readonly DocEdge[];
|
|
109
|
+
}, nodeKey: string, port: string, describe?: (node: DocNode) => BandSource | undefined): Record<BandKey, ReachingBand>;
|
|
110
|
+
/**
|
|
111
|
+
* What a `variables` slot renders at one node of a document: its static
|
|
112
|
+
* `renders`, plus — when it declares `rendersBands` — every band declared
|
|
113
|
+
* upstream of that in-port.
|
|
114
|
+
*
|
|
115
|
+
* A band the static half already renders under the same variable is the same
|
|
116
|
+
* name, not a collision (core's lore queries declare `worldLore`; Assemble
|
|
117
|
+
* renders `worldLore`). One declared under a different variable, or shadowing
|
|
118
|
+
* a name Assemble renders itself, is refused naming both.
|
|
119
|
+
* @experimental
|
|
120
|
+
*/
|
|
121
|
+
export declare function rendersAt(doc: {
|
|
122
|
+
nodes: readonly DocNode[];
|
|
123
|
+
edges: readonly DocEdge[];
|
|
124
|
+
}, nodeKey: string, slot: Pick<SlotDecl, 'renders' | 'rendersBands'>, describe?: (node: DocNode) => BandSource | undefined): Record<string, VariableId>;
|
|
125
|
+
//# sourceMappingURL=bands.d.ts.map
|
package/dist/bands.js
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bands as template variables (typed templates P2, 2026-09-27).
|
|
3
|
+
*
|
|
4
|
+
* A **band** is the ranker's word for one source's slice of the context window
|
|
5
|
+
* (`bandIntent`, candidates.ts). A source that puts its own band in the window
|
|
6
|
+
* — Twenty Questions' secret entry — now also **declares** it: the key it
|
|
7
|
+
* publishes and the registered variable that says how the band is laid out.
|
|
8
|
+
*
|
|
9
|
+
* ```ts
|
|
10
|
+
* const varSecretEntry = definePluginVariable('showcase.twenty-questions', {
|
|
11
|
+
* id: 'showcase.twenty-questions:var/secret-entry@1',
|
|
12
|
+
* scope: { secretEntry: { type: 'record', of: { type: 'string' } } },
|
|
13
|
+
* sample: { 'The Brass Clock': 'A clock that rings when nobody winds it.' },
|
|
14
|
+
* })
|
|
15
|
+
* describeTaskDefinition({ …, bands: { secretEntry: varSecretEntry } })
|
|
16
|
+
* // …and a context template places it as {{{secretEntry}}}.
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Declared, a band is a **top-level template name**: Assemble exposes it as
|
|
20
|
+
* `{{{secretEntry}}}`, rendered through the variable's selected layout (the
|
|
21
|
+
* in-code fallback is the band as title-keyed minified JSON). So a band key is
|
|
22
|
+
* an identifier, and it means one thing: two declarers naming the same key
|
|
23
|
+
* with different variables, or a band shadowing a name core already renders,
|
|
24
|
+
* is refused with both declarers named.
|
|
25
|
+
*
|
|
26
|
+
* Which bands a node renders is its own `variables` slot's `renders` plus —
|
|
27
|
+
* when the slot says `rendersBands` — every band declared upstream of the
|
|
28
|
+
* named in-port, followed through any node that takes candidates in
|
|
29
|
+
* (concatenation, fusion, ranking). `rendersAt` is that answer.
|
|
30
|
+
*/
|
|
31
|
+
import { getDefinition } from './descriptors.js';
|
|
32
|
+
import { allVariables, getVariable } from './variables.js';
|
|
33
|
+
/**
|
|
34
|
+
* The shape a candidates port carries. Written out rather than imported from
|
|
35
|
+
* `shapes.ts`, which reaches the descriptor module this one is read from.
|
|
36
|
+
*/
|
|
37
|
+
const CANDIDATES_SHAPE = 'core:shape/context-candidates@1';
|
|
38
|
+
/** Letters, digits and `_`, not starting with a digit — a bare name in both core engines. */
|
|
39
|
+
const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
40
|
+
/** @experimental */
|
|
41
|
+
export const isBandKey = (key) => IDENTIFIER.test(key);
|
|
42
|
+
/** `secret-entry` → `secretEntry`: the identifier a refusal suggests. @internal */
|
|
43
|
+
export function bandKeySuggestion(key) {
|
|
44
|
+
const camel = key
|
|
45
|
+
.replace(/[^A-Za-z0-9_]+(.)?/g, (_, c) => (c ? c.toUpperCase() : ''))
|
|
46
|
+
.replace(/^[^A-Za-z_]+/, '');
|
|
47
|
+
return camel || 'band';
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Names Assemble puts at the top of a context template that are not bands and
|
|
51
|
+
* not registered variables — what a band key may never be.
|
|
52
|
+
*
|
|
53
|
+
* Assemble's own values. A band called `budget` would shadow the budget a
|
|
54
|
+
* template reads, silently, on every turn.
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
export const ASSEMBLE_OWN_TEMPLATE_NAMES = [
|
|
58
|
+
'sessionMessages',
|
|
59
|
+
'injectionsByIndex',
|
|
60
|
+
'budget',
|
|
61
|
+
'postHistory',
|
|
62
|
+
'blocks',
|
|
63
|
+
'prompts',
|
|
64
|
+
];
|
|
65
|
+
/** The declared variable id of one band entry — a declaration, or its id as a registry row carries it. */
|
|
66
|
+
const variableIdOf = (v) => typeof v === 'string' ? v : v?.id;
|
|
67
|
+
/**
|
|
68
|
+
* A **core** variable that already renders a top-level name, if any — the
|
|
69
|
+
* names core's own nodes put in a template (`characters`, `scenario`, …). A
|
|
70
|
+
* plugin variable sharing a root is not by itself a collision: two plugins'
|
|
71
|
+
* bands meaning different things is, and the definitions check names both.
|
|
72
|
+
*/
|
|
73
|
+
const otherVariableRendering = (key, id) => allVariables().find((v) => v.id !== id &&
|
|
74
|
+
v.id.startsWith('core:') &&
|
|
75
|
+
Object.prototype.hasOwnProperty.call(v.scope, key));
|
|
76
|
+
/**
|
|
77
|
+
* Refuse a definition's band declarations — at `describe…Definition`, where
|
|
78
|
+
* the author is.
|
|
79
|
+
*
|
|
80
|
+
* - the key is an identifier (a band is a template name);
|
|
81
|
+
* - the variable is registered (`defineVariable` / `definePluginVariable`) and
|
|
82
|
+
* its scope declares the key, because a layout renders `{ [key]: value }`;
|
|
83
|
+
* - the key does not shadow a name core renders — Assemble's own, or a
|
|
84
|
+
* core variable's that is not this band's own variable;
|
|
85
|
+
* - no other registered definition declares the key with a different variable.
|
|
86
|
+
*
|
|
87
|
+
* Each refusal names the fix.
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
export function checkBandDeclarations(d, others) {
|
|
91
|
+
const bands = d.bands;
|
|
92
|
+
for (const key of Object.keys(d.bandPorts ?? {}))
|
|
93
|
+
if (!bands || !Object.prototype.hasOwnProperty.call(bands, key))
|
|
94
|
+
throw new Error(`'${d.id}' names band '${key}' in bandPorts but does not declare it in bands. ` +
|
|
95
|
+
`Declare it (bands: { ${key}: varMyBand }), or drop it from bandPorts.`);
|
|
96
|
+
if (!bands)
|
|
97
|
+
return;
|
|
98
|
+
for (const [key, decl] of Object.entries(bands)) {
|
|
99
|
+
if (!isBandKey(key))
|
|
100
|
+
throw new Error(`'${d.id}' declares band '${key}': a band key is a top-level template name, so it must ` +
|
|
101
|
+
`be an identifier — letters, digits and '_', not starting with a digit. Rename it ` +
|
|
102
|
+
`'${bandKeySuggestion(key)}', and emit that same key from bandIntent() and as each ` +
|
|
103
|
+
`candidate's source.`);
|
|
104
|
+
const id = variableIdOf(decl);
|
|
105
|
+
if (!id || !decl || typeof decl !== 'object')
|
|
106
|
+
throw new Error(`'${d.id}' declares band '${key}' without a variable. Declare one with ` +
|
|
107
|
+
`definePluginVariable() (defineVariable() in core) whose scope names '${key}', and ` +
|
|
108
|
+
`pass the declaration: bands: { ${key}: varMyBand }.`);
|
|
109
|
+
const registered = getVariable(id);
|
|
110
|
+
if (!registered)
|
|
111
|
+
throw new Error(`'${d.id}' declares band '${key}' with variable '${id}', which is not registered. ` +
|
|
112
|
+
`Declare it with definePluginVariable() (defineVariable() in core) before the ` +
|
|
113
|
+
`definition that names it — the layout picker and the template editor read it ` +
|
|
114
|
+
`from the registry.`);
|
|
115
|
+
if (!Object.prototype.hasOwnProperty.call(registered.scope, key))
|
|
116
|
+
throw new Error(`'${d.id}' declares band '${key}' with variable '${id}', whose scope does not declare ` +
|
|
117
|
+
`'${key}' (it declares ${Object.keys(registered.scope).map((k) => `'${k}'`).join(', ') || 'nothing'}). ` +
|
|
118
|
+
`A layout renders the band as {{{${key}}}}, so add '${key}' to the variable's scope — ` +
|
|
119
|
+
`or rename the band to the key the variable declares.`);
|
|
120
|
+
if (ASSEMBLE_OWN_TEMPLATE_NAMES.includes(key))
|
|
121
|
+
throw new Error(`'${d.id}' declares band '${key}', which collides with Assemble's own '${key}' — a ` +
|
|
122
|
+
`template reading {{{${key}}}} would get one or the other depending on order. ` +
|
|
123
|
+
`Rename the band.`);
|
|
124
|
+
const core = otherVariableRendering(key, id);
|
|
125
|
+
if (core)
|
|
126
|
+
throw new Error(`'${d.id}' declares band '${key}' as '${id}', which collides with '${core.id}' — that ` +
|
|
127
|
+
`variable already renders the top-level name '${key}'. A band key means one thing; ` +
|
|
128
|
+
`rename the band.`);
|
|
129
|
+
const ports = d.bandPorts?.[key];
|
|
130
|
+
if (ports !== undefined) {
|
|
131
|
+
const out = Object.keys(d.ports?.out ?? {});
|
|
132
|
+
const unknown = ports.filter((p) => !out.includes(p));
|
|
133
|
+
if (!ports.length || unknown.length)
|
|
134
|
+
throw new Error(`'${d.id}' says band '${key}' is carried on ` +
|
|
135
|
+
(ports.length
|
|
136
|
+
? `${unknown.map((p) => `'${p}'`).join(', ')}, which ${unknown.length === 1 ? 'is not an out-port' : 'are not out-ports'} it declares`
|
|
137
|
+
: 'no out-port at all') +
|
|
138
|
+
` (it declares ${out.map((p) => `'${p}'`).join(', ') || 'none'}). Name the out-ports ` +
|
|
139
|
+
`that publish the band's candidates in bandPorts, or leave '${key}' out of bandPorts ` +
|
|
140
|
+
`if every out-port may carry it.`);
|
|
141
|
+
}
|
|
142
|
+
for (const other of others) {
|
|
143
|
+
if (other.id === d.id)
|
|
144
|
+
continue;
|
|
145
|
+
const theirs = variableIdOf(other.bands?.[key]);
|
|
146
|
+
if (theirs && theirs !== id)
|
|
147
|
+
throw new Error(`'${d.id}' declares band '${key}' as '${id}', but '${other.id}' already declares ` +
|
|
148
|
+
`'${key}' as '${theirs}'. A band key is a top-level template name and means one ` +
|
|
149
|
+
`thing — rename one of the two bands.`);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
/** Two declarers naming one band differently, or a band shadowing a name the node renders. @experimental */
|
|
154
|
+
export class BandCollisionError extends Error {
|
|
155
|
+
}
|
|
156
|
+
const shapeIdOf = (s) => typeof s === 'string' ? s : (s?.id ?? undefined);
|
|
157
|
+
const defaultDescribe = (n) => getDefinition(`${n.definitionId}@${n.definitionVersion}`);
|
|
158
|
+
/**
|
|
159
|
+
* Every band declared upstream of `nodeKey`'s in-port `port`.
|
|
160
|
+
*
|
|
161
|
+
* Walks the edges backwards from the port: each producer's declared `bands`
|
|
162
|
+
* are collected, and the walk continues through every in-port the producer
|
|
163
|
+
* declares as a candidates port — so a band declared at a source reaches a
|
|
164
|
+
* ranker through a concatenation or a fusion, and Assemble through the ranker.
|
|
165
|
+
* A producer declaring no candidates in-port is where the walk stops. A band
|
|
166
|
+
* whose declarer names the out-ports carrying it (`bandPorts`) reaches only
|
|
167
|
+
* through an edge from one of those ports.
|
|
168
|
+
*
|
|
169
|
+
* Throws `BandCollisionError`, naming both declarers, when two of them name
|
|
170
|
+
* one key with different variables.
|
|
171
|
+
* @experimental
|
|
172
|
+
*/
|
|
173
|
+
export function bandsReaching(doc, nodeKey, port, describe = defaultDescribe) {
|
|
174
|
+
const out = {};
|
|
175
|
+
const seen = new Set();
|
|
176
|
+
const byKey = new Map(doc.nodes.map((n) => [n.key, n]));
|
|
177
|
+
const head = (p) => p.split('.')[0];
|
|
178
|
+
// Each producer is reached through one of its OUT-ports, and a band that
|
|
179
|
+
// names the ports carrying it (`bandPorts`) reaches only through those —
|
|
180
|
+
// entity-search's recalled lines ride `messages`, never `main`, so a spec
|
|
181
|
+
// wiring only `main` does not offer a band that can never fill.
|
|
182
|
+
const into = (to, toPort) => doc.edges
|
|
183
|
+
.filter((e) => e.to === to && head(e.toPort) === toPort)
|
|
184
|
+
.map((e) => ({ key: e.from, port: head(e.fromPort) }));
|
|
185
|
+
const queue = into(nodeKey, port);
|
|
186
|
+
const walked = new Set();
|
|
187
|
+
while (queue.length) {
|
|
188
|
+
const { key, port: outPort } = queue.shift();
|
|
189
|
+
if (seen.has(`${key}|${outPort}`))
|
|
190
|
+
continue;
|
|
191
|
+
seen.add(`${key}|${outPort}`);
|
|
192
|
+
const node = byKey.get(key);
|
|
193
|
+
if (!node)
|
|
194
|
+
continue;
|
|
195
|
+
const d = describe(node);
|
|
196
|
+
if (!d)
|
|
197
|
+
continue;
|
|
198
|
+
const declarer = `'${node.key}' (${node.definitionId}@${node.definitionVersion})`;
|
|
199
|
+
for (const [band, v] of Object.entries(d.bands ?? {})) {
|
|
200
|
+
const carriers = d.bandPorts?.[band];
|
|
201
|
+
if (carriers && !carriers.includes(outPort))
|
|
202
|
+
continue;
|
|
203
|
+
const variable = variableIdOf(v);
|
|
204
|
+
if (!variable)
|
|
205
|
+
continue;
|
|
206
|
+
const existing = out[band];
|
|
207
|
+
if (existing && existing.variable !== variable)
|
|
208
|
+
throw new BandCollisionError(`band '${band}' reaches '${nodeKey}.${port}' from two declarers with different ` +
|
|
209
|
+
`variables: ${existing.declarer} as '${existing.variable}', and ${declarer} as ` +
|
|
210
|
+
`'${variable}'. A band key is a top-level template name and means one thing — ` +
|
|
211
|
+
`rename one of the two bands.`);
|
|
212
|
+
if (!existing)
|
|
213
|
+
out[band] = { variable, declarer };
|
|
214
|
+
}
|
|
215
|
+
if (walked.has(key))
|
|
216
|
+
continue;
|
|
217
|
+
walked.add(key);
|
|
218
|
+
for (const [inPort, shape] of Object.entries(d.ports?.in ?? {}))
|
|
219
|
+
if (shapeIdOf(shape) === CANDIDATES_SHAPE)
|
|
220
|
+
queue.push(...into(node.key, inPort));
|
|
221
|
+
}
|
|
222
|
+
return out;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* What a `variables` slot renders at one node of a document: its static
|
|
226
|
+
* `renders`, plus — when it declares `rendersBands` — every band declared
|
|
227
|
+
* upstream of that in-port.
|
|
228
|
+
*
|
|
229
|
+
* A band the static half already renders under the same variable is the same
|
|
230
|
+
* name, not a collision (core's lore queries declare `worldLore`; Assemble
|
|
231
|
+
* renders `worldLore`). One declared under a different variable, or shadowing
|
|
232
|
+
* a name Assemble renders itself, is refused naming both.
|
|
233
|
+
* @experimental
|
|
234
|
+
*/
|
|
235
|
+
export function rendersAt(doc, nodeKey, slot, describe) {
|
|
236
|
+
const out = { ...(slot.renders ?? {}) };
|
|
237
|
+
const from = slot.rendersBands?.from;
|
|
238
|
+
if (!from)
|
|
239
|
+
return out;
|
|
240
|
+
const reaching = bandsReaching(doc, nodeKey, from, describe);
|
|
241
|
+
for (const [band, { variable, declarer }] of Object.entries(reaching)) {
|
|
242
|
+
const own = slot.renders?.[band];
|
|
243
|
+
if (own !== undefined) {
|
|
244
|
+
if (own !== variable)
|
|
245
|
+
throw new BandCollisionError(`band '${band}' declared by ${declarer} as '${variable}' collides with '${nodeKey}''s ` +
|
|
246
|
+
`own '${band}', which it renders as '${own}'. Rename the band.`);
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
if (ASSEMBLE_OWN_TEMPLATE_NAMES.includes(band))
|
|
250
|
+
throw new BandCollisionError(`band '${band}' declared by ${declarer} collides with Assemble's own '${band}' at ` +
|
|
251
|
+
`'${nodeKey}'. Rename the band.`);
|
|
252
|
+
out[band] = variable;
|
|
253
|
+
}
|
|
254
|
+
return out;
|
|
255
|
+
}
|
|
256
|
+
//# sourceMappingURL=bands.js.map
|