@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,503 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The **session layout** (`SessionLayoutV1`, NOMENCLATURE §9) — the ONE layout
|
|
3
|
+
* format: what the screen draws, what a person arranges, what a genre or a
|
|
4
|
+
* plugin ships (`GenreLayoutDecl.preset`), and what a **session layout preset**
|
|
5
|
+
* row stores. Plain JSON, stored verbatim; every reader reads it defensively,
|
|
6
|
+
* so a key this build does not know degrades rather than throws.
|
|
7
|
+
*
|
|
8
|
+
* ## The shape in one paragraph
|
|
9
|
+
*
|
|
10
|
+
* Its **arrangement** is three slots, three views of one placement:
|
|
11
|
+
*
|
|
12
|
+
* - `zoneLayout` — the side zones' membership: which widgets each side lists,
|
|
13
|
+
* in order, whether the side is pinned (a docked column) or an icon strip,
|
|
14
|
+
* its width ladder, and `styles.chat` (the message pack, by name).
|
|
15
|
+
* - `widgetGrid` — the widget grid: each widget's zone, order, size and the
|
|
16
|
+
* edges it anchors to. The middle's membership lives here; a side's may too.
|
|
17
|
+
* - `arrangedGrid` — the arrangement per zone: whole grid cells (`cols` ×
|
|
18
|
+
* `rows`) and each widget's cell box. Where a zone has one, it is what draws.
|
|
19
|
+
*
|
|
20
|
+
* A named layout adds `widgetSettings` and `widgetStyles` (per-instance values
|
|
21
|
+
* and style pins), so one blob is the portable layout. A session keeps those
|
|
22
|
+
* two in its own rows instead, and its row adds the surface manager's
|
|
23
|
+
* bookkeeping (`active`, `tierSizeOverrides`), which is the app's.
|
|
24
|
+
*
|
|
25
|
+
* ## Widget instance ids
|
|
26
|
+
*
|
|
27
|
+
* A layout places a widget under a **widget instance id**: the widget id
|
|
28
|
+
* itself (`messages`, `acme.maps:map`), or `<widget id>#<instance name>` for
|
|
29
|
+
* another copy of it in the same layout (`messages#sanctum`). Everything a
|
|
30
|
+
* layout keys per placed copy — the zone lists, grid entries and cells, the
|
|
31
|
+
* `widgetSettings` and `widgetStyles` keys — is an instance id; everything
|
|
32
|
+
* about the widget (its declaration, its style rows) is read through
|
|
33
|
+
* {@link widgetOfInstance}.
|
|
34
|
+
*
|
|
35
|
+
* ## What is deliberately not here
|
|
36
|
+
*
|
|
37
|
+
* No renderer, no normalizer and no measurement: those are the app's, which
|
|
38
|
+
* reads a stored blob it did not write and must repair rather than refuse.
|
|
39
|
+
* This module types the format, reads the ids out of it, and checks a layout a
|
|
40
|
+
* package SHIPS ({@link validateSessionLayout}), where refusing is right. No
|
|
41
|
+
* `svelte` import, ever: a linked package that imports svelte gives the app a
|
|
42
|
+
* second Svelte.
|
|
43
|
+
*/
|
|
44
|
+
import { parsePluginWidgetId } from './surfaces.js';
|
|
45
|
+
// ── Zones ───────────────────────────────────────────────────────────────────
|
|
46
|
+
/** The three zones, in visual order. There is no fourth. @experimental */
|
|
47
|
+
export const ZONE_IDS = ['left', 'middle', 'right'];
|
|
48
|
+
// ── Widget instance ids ─────────────────────────────────────────────────────
|
|
49
|
+
/** The separator between a widget id and an instance name. @experimental */
|
|
50
|
+
export const INSTANCE_NAME_SEPARATOR = '#';
|
|
51
|
+
/** An instance name: short, kebab, lower case (`sanctum`, `2`). @experimental */
|
|
52
|
+
export const INSTANCE_NAME = /^[a-z0-9][a-z0-9-]{0,31}$/;
|
|
53
|
+
/** Core's widget id grammar — the bare half a package never namespaces. */
|
|
54
|
+
const CORE_WIDGET_ID = /^[a-z][a-z0-9-]*$/;
|
|
55
|
+
/** The widget a placed id is a copy of: the id up to its `#`, else the id. @experimental */
|
|
56
|
+
export function widgetOfInstance(instanceId) {
|
|
57
|
+
const at = instanceId.indexOf(INSTANCE_NAME_SEPARATOR);
|
|
58
|
+
return at > 0 ? instanceId.slice(0, at) : instanceId;
|
|
59
|
+
}
|
|
60
|
+
/** The instance name of a copy (`sanctum` of `messages#sanctum`), or `null` for the widget itself. @experimental */
|
|
61
|
+
export function instanceNameOf(instanceId) {
|
|
62
|
+
const at = instanceId.indexOf(INSTANCE_NAME_SEPARATOR);
|
|
63
|
+
return at > 0 && at < instanceId.length - 1 ? instanceId.slice(at + 1) : null;
|
|
64
|
+
}
|
|
65
|
+
/** Is this placed id a copy of `widgetId` — the widget itself or one of its instances? @experimental */
|
|
66
|
+
export function isInstanceOf(instanceId, widgetId) {
|
|
67
|
+
return widgetOfInstance(instanceId) === widgetId;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Is this string a widget instance id a layout may place? The widget half is
|
|
71
|
+
* core's grammar (`world-state`) or a plugin's namespaced one
|
|
72
|
+
* (`acme.maps:map`, `parsePluginWidgetId`); the instance name, when there is
|
|
73
|
+
* one, is {@link INSTANCE_NAME}.
|
|
74
|
+
* @experimental
|
|
75
|
+
*/
|
|
76
|
+
export function isWidgetInstanceId(id) {
|
|
77
|
+
if (typeof id !== 'string' || !id)
|
|
78
|
+
return false;
|
|
79
|
+
const at = id.indexOf(INSTANCE_NAME_SEPARATOR);
|
|
80
|
+
const widget = at < 0 ? id : id.slice(0, at);
|
|
81
|
+
if (at >= 0 && !INSTANCE_NAME.test(id.slice(at + 1)))
|
|
82
|
+
return false;
|
|
83
|
+
return CORE_WIDGET_ID.test(widget) || parsePluginWidgetId(widget) !== null;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Widget ids that name nothing any build places. A saved layout, a preset or
|
|
87
|
+
* an arrangement may still carry one — all three are stored verbatim and
|
|
88
|
+
* nothing rewrites them — so every reader drops it.
|
|
89
|
+
*
|
|
90
|
+
* `composer` is one because the conversation is ONE widget: the log and the
|
|
91
|
+
* field are one thing to arrange, and the field's shape is a setting on
|
|
92
|
+
* `messages` rather than a widget beside it.
|
|
93
|
+
*
|
|
94
|
+
* `inventory` is one because R79 (2026-09-25) removed core's Inventory widget
|
|
95
|
+
* for now, with no replacement. Adventure and Lair shipped it, so layouts and
|
|
96
|
+
* presets saved from them name it; dropping it here is what makes such a
|
|
97
|
+
* layout open on the widgets it still has — nothing drawn in its place, no
|
|
98
|
+
* labelled placeholder. What somebody carries is the `inventory` stat, which
|
|
99
|
+
* the stats widget draws as a list. Take it off this list if the widget comes
|
|
100
|
+
* back.
|
|
101
|
+
* @experimental
|
|
102
|
+
*/
|
|
103
|
+
export const RETIRED_WIDGET_IDS = new Set(['composer', 'inventory']);
|
|
104
|
+
// ── Reading ids ─────────────────────────────────────────────────────────────
|
|
105
|
+
const isObj = (x) => !!x && typeof x === 'object' && !Array.isArray(x);
|
|
106
|
+
const strings = (x) => Array.isArray(x) ? x.filter((s) => typeof s === 'string') : [];
|
|
107
|
+
/** The grid's entries for one zone, by `order`. */
|
|
108
|
+
function gridIn(layout, zone) {
|
|
109
|
+
const widgets = isObj(layout.widgetGrid) && Array.isArray(layout.widgetGrid.widgets) ? layout.widgetGrid.widgets : [];
|
|
110
|
+
return widgets
|
|
111
|
+
.filter((w) => isObj(w) && w.zone === zone && typeof w.id === 'string')
|
|
112
|
+
.map((w, n) => ({ id: w.id, order: typeof w.order === 'number' ? w.order : n }))
|
|
113
|
+
.sort((a, b) => a.order - b.order)
|
|
114
|
+
.map((w) => w.id);
|
|
115
|
+
}
|
|
116
|
+
/** An arranged zone's ids in reading order (by row, then column), or null when the zone has none. */
|
|
117
|
+
function arrangedIn(layout, zone) {
|
|
118
|
+
const frame = isObj(layout.arrangedGrid) ? layout.arrangedGrid[zone] : undefined;
|
|
119
|
+
if (!isObj(frame) || !Array.isArray(frame.items))
|
|
120
|
+
return null;
|
|
121
|
+
return frame.items
|
|
122
|
+
.filter((i) => isObj(i) && typeof i.id === 'string')
|
|
123
|
+
.map((i) => ({ id: i.id, x: Number(i.x) || 0, y: Number(i.y) || 0 }))
|
|
124
|
+
.sort((a, b) => a.y - b.y || a.x - b.x)
|
|
125
|
+
.map((i) => i.id);
|
|
126
|
+
}
|
|
127
|
+
/** The zone definitions of `zoneLayout`, whatever its keys. */
|
|
128
|
+
function zoneDefs(layout) {
|
|
129
|
+
const zones = isObj(layout.zoneLayout) ? layout.zoneLayout.zones : undefined;
|
|
130
|
+
return isObj(zones) ? Object.values(zones).filter(isObj) : [];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Where the page draws a zone of `zoneLayout` — the one rule, which the id
|
|
134
|
+
* readers and the validator share with the page: a strip at its `area` (the
|
|
135
|
+
* top unless it says bottom); anything else is a side, on its `side` (the
|
|
136
|
+
* right unless it says left). Never the zone's key.
|
|
137
|
+
*/
|
|
138
|
+
function zoneDrawnAt(def) {
|
|
139
|
+
if (def.kind === 'strip')
|
|
140
|
+
return def.area === 'bottom' ? 'bottom' : 'top';
|
|
141
|
+
return def.side === 'left' ? 'left' : 'right';
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Every widget instance id the layout NAMES — the zone lists, the grid and the
|
|
145
|
+
* arrangement — each once, in that order. What a check reads when the question
|
|
146
|
+
* is "does this layout mention it at all" (a genre's omitted widgets).
|
|
147
|
+
* @experimental
|
|
148
|
+
*/
|
|
149
|
+
export function layoutWidgetIds(layout) {
|
|
150
|
+
const out = new Set();
|
|
151
|
+
for (const z of zoneDefs(layout))
|
|
152
|
+
for (const id of strings(z.widgets))
|
|
153
|
+
out.add(id);
|
|
154
|
+
const grid = isObj(layout.widgetGrid) && Array.isArray(layout.widgetGrid.widgets) ? layout.widgetGrid.widgets : [];
|
|
155
|
+
for (const w of grid)
|
|
156
|
+
if (isObj(w) && typeof w.id === 'string')
|
|
157
|
+
out.add(w.id);
|
|
158
|
+
for (const zone of ZONE_IDS)
|
|
159
|
+
for (const id of arrangedIn(layout, zone) ?? [])
|
|
160
|
+
out.add(id);
|
|
161
|
+
return [...out];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* The widget instance ids the MIDDLE names: the grid's middle entries, then
|
|
165
|
+
* the arranged middle's items, each once.
|
|
166
|
+
* @experimental
|
|
167
|
+
*/
|
|
168
|
+
export function middleWidgetIds(layout) {
|
|
169
|
+
return [...new Set([...gridIn(layout, 'middle'), ...(arrangedIn(layout, 'middle') ?? [])])];
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Every widget instance id the layout DRAWS, in reading order — middle, left,
|
|
173
|
+
* right, then any strips — which is the page's own precedence, place by place:
|
|
174
|
+
*
|
|
175
|
+
* - the middle draws its arrangement whenever it has one (an emptied middle
|
|
176
|
+
* stays empty), else the grid's middle entries;
|
|
177
|
+
* - a side draws its arrangement when that places anything, else the lists
|
|
178
|
+
* of the zones on it (by their `side`, never their key) — and, folded into
|
|
179
|
+
* them, any grid entry naming that side, but only when the layout has a
|
|
180
|
+
* zone on that side to fold it into;
|
|
181
|
+
* - a strip draws its list.
|
|
182
|
+
*
|
|
183
|
+
* So an entry an arrangement shadows is named but not drawn. A retired widget
|
|
184
|
+
* id is never drawn.
|
|
185
|
+
* @experimental
|
|
186
|
+
*/
|
|
187
|
+
export function drawnWidgetIds(layout) {
|
|
188
|
+
const out = [];
|
|
189
|
+
const add = (id) => {
|
|
190
|
+
if (!RETIRED_WIDGET_IDS.has(id) && !out.includes(id))
|
|
191
|
+
out.push(id);
|
|
192
|
+
};
|
|
193
|
+
(arrangedIn(layout, 'middle') ?? gridIn(layout, 'middle')).forEach(add);
|
|
194
|
+
const defs = zoneDefs(layout);
|
|
195
|
+
for (const side of ['left', 'right']) {
|
|
196
|
+
const frame = arrangedIn(layout, side);
|
|
197
|
+
if (frame?.length) {
|
|
198
|
+
frame.forEach(add);
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
const zones = defs.filter((z) => zoneDrawnAt(z) === side);
|
|
202
|
+
for (const z of zones)
|
|
203
|
+
strings(z.widgets).forEach(add);
|
|
204
|
+
if (zones.length)
|
|
205
|
+
gridIn(layout, side).forEach(add);
|
|
206
|
+
}
|
|
207
|
+
for (const z of defs)
|
|
208
|
+
if (z.kind === 'strip')
|
|
209
|
+
strings(z.widgets).forEach(add);
|
|
210
|
+
return out;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Does the layout DRAW any instance of `primaryId` — the bare id or a
|
|
214
|
+
* `#name` copy — anywhere? The **primary floor**'s question: placement is
|
|
215
|
+
* free, and the one rule left is that a layout draws its genre's primary
|
|
216
|
+
* widget somewhere.
|
|
217
|
+
* @experimental
|
|
218
|
+
*/
|
|
219
|
+
export function primaryPlaced(layout, primaryId) {
|
|
220
|
+
return drawnWidgetIds(layout).some((id) => isInstanceOf(id, primaryId));
|
|
221
|
+
}
|
|
222
|
+
const isInt = (x) => typeof x === 'number' && Number.isInteger(x);
|
|
223
|
+
/** The slots a session layout has. */
|
|
224
|
+
const SLOTS = ['zoneLayout', 'widgetGrid', 'arrangedGrid', 'widgetSettings', 'widgetStyles'];
|
|
225
|
+
/** The top-level keys only the retired layout document had (and its preset wrapper, `layout`). */
|
|
226
|
+
const RETIRED_DOCUMENT_KEYS = ['layout', 'version', 'zones', 'variants', 'look'];
|
|
227
|
+
function isSizeSpec(x) {
|
|
228
|
+
if (x === 'grow' || x === 'fixed')
|
|
229
|
+
return true;
|
|
230
|
+
if (!isObj(x))
|
|
231
|
+
return false;
|
|
232
|
+
const keys = ['minCells', 'maxCells', 'cells'].filter((k) => x[k] !== undefined);
|
|
233
|
+
return keys.length > 0 && keys.every((k) => typeof x[k] === 'number' && x[k] > 0);
|
|
234
|
+
}
|
|
235
|
+
function isAnchor(x) {
|
|
236
|
+
return isObj(x) && Object.entries(x).every(([k, v]) => ['top', 'bottom', 'left', 'right'].includes(k) && typeof v === 'boolean');
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Check a layout a package ships — the rules its type cannot express. Pure;
|
|
240
|
+
* the verdict lists every problem rather than the first.
|
|
241
|
+
*
|
|
242
|
+
* **Errors** (the layout is refused):
|
|
243
|
+
* - a slot of the wrong shape: `zoneLayout` and `widgetGrid` are `version: 1`;
|
|
244
|
+
* a grid entry and an arrangement name a zone, `left`, `middle` or
|
|
245
|
+
* `right`; a `zoneLayout` zone is keyed by where the page draws it — a
|
|
246
|
+
* side by its `side` (`left`, `right`), a strip by its `area` (`top`,
|
|
247
|
+
* `bottom`);
|
|
248
|
+
* - a placed id that is not a widget instance id (`<widget id>` or
|
|
249
|
+
* `<widget id>#<instance name>`);
|
|
250
|
+
* - an arranged cell that is not whole cells inside its zone's `cols` × `rows`;
|
|
251
|
+
* - an id placed twice: a widget instance lives in ONE zone, listed once. The
|
|
252
|
+
* three slots may each name it there — a side lists it, its arrangement
|
|
253
|
+
* gives it cells — but never in two zones (a zone as the page draws it),
|
|
254
|
+
* and never twice in one list;
|
|
255
|
+
* - a `widgetSettings` value that is not an object, a `widgetStyles` pin with
|
|
256
|
+
* no slug;
|
|
257
|
+
* - the retired layout document (LayoutDoc v2), bare or in its preset
|
|
258
|
+
* wrapper — refused by name, never read as a layout that places nothing.
|
|
259
|
+
*
|
|
260
|
+
* **Warnings** (the layout draws, not as written):
|
|
261
|
+
* - a key that is not a slot (readers ignore it) and a retired widget;
|
|
262
|
+
* - an id placed but never drawn ({@link drawnWidgetIds}): its zone's
|
|
263
|
+
* arrangement draws over it, or the grid puts it in a side the layout has
|
|
264
|
+
* no zone for;
|
|
265
|
+
* - two arranged items sharing a cell (one draws over the other);
|
|
266
|
+
* - with `opts.widgets`, more instances of a widget than its
|
|
267
|
+
* `maxInstances` (readers draw the first ones in reading order);
|
|
268
|
+
* - with `opts.unknownWidgets: 'warn'` too, a widget `opts.widgets` does not
|
|
269
|
+
* hold (it draws a labelled placeholder).
|
|
270
|
+
* @experimental
|
|
271
|
+
*/
|
|
272
|
+
export function validateSessionLayout(layout, opts = {}) {
|
|
273
|
+
const errors = [];
|
|
274
|
+
const warnings = [];
|
|
275
|
+
if (!isObj(layout))
|
|
276
|
+
return { ok: false, errors: ['a session layout is an object'], warnings };
|
|
277
|
+
// The retired layout document (LayoutDoc v2) — bare, or inside the
|
|
278
|
+
// `{ layout, widgetSettings, widgetStyles }` preset that carried it — is
|
|
279
|
+
// refused by name rather than read as a layout that places nothing: no
|
|
280
|
+
// reader converts it (owner L1).
|
|
281
|
+
if (RETIRED_DOCUMENT_KEYS.some((k) => k in layout))
|
|
282
|
+
errors.push(`a retired layout document (LayoutDoc v2: ${RETIRED_DOCUMENT_KEYS.filter((k) => k in layout).join(', ')}) — ` +
|
|
283
|
+
'declare a session layout: { zoneLayout?, widgetGrid?, arrangedGrid?, widgetSettings?, widgetStyles? }');
|
|
284
|
+
for (const k of Object.keys(layout))
|
|
285
|
+
if (!SLOTS.includes(k) && !RETIRED_DOCUMENT_KEYS.includes(k))
|
|
286
|
+
warnings.push(`'${k}' is not a slot of the session layout — readers ignore it`);
|
|
287
|
+
/** Where each id is placed: the zone the page draws it in, first seen at `where`. */
|
|
288
|
+
const placedIn = new Map();
|
|
289
|
+
const isInstanceId = (id, where) => {
|
|
290
|
+
if (isWidgetInstanceId(id))
|
|
291
|
+
return true;
|
|
292
|
+
errors.push(`${where}: '${String(id)}' is not a widget instance id — a widget id, or '<widget id>#<instance name>' (${INSTANCE_NAME})`);
|
|
293
|
+
return false;
|
|
294
|
+
};
|
|
295
|
+
const place = (id, zone, where, seen) => {
|
|
296
|
+
if (!isInstanceId(id, where))
|
|
297
|
+
return;
|
|
298
|
+
if (seen.has(id))
|
|
299
|
+
errors.push(`${where}: '${id}' is listed twice — a widget instance is placed once`);
|
|
300
|
+
seen.add(id);
|
|
301
|
+
const held = placedIn.get(id);
|
|
302
|
+
if (held && held.zone !== zone)
|
|
303
|
+
errors.push(`${where}: '${id}' is also placed in ${held.zone} (${held.where}) — a widget instance lives in one zone`);
|
|
304
|
+
else if (!held)
|
|
305
|
+
placedIn.set(id, { zone, where });
|
|
306
|
+
};
|
|
307
|
+
const zoneKey = (k, where) => {
|
|
308
|
+
if (ZONE_IDS.includes(k))
|
|
309
|
+
return true;
|
|
310
|
+
errors.push(`${where}: '${k}' is not a zone — one of ${ZONE_IDS.join(', ')}`);
|
|
311
|
+
return false;
|
|
312
|
+
};
|
|
313
|
+
// zoneLayout
|
|
314
|
+
const zl = layout.zoneLayout;
|
|
315
|
+
if (zl !== undefined) {
|
|
316
|
+
if (!isObj(zl) || zl.version !== 1 || !isObj(zl.zones))
|
|
317
|
+
errors.push('zoneLayout: { version: 1, zones: { … } }');
|
|
318
|
+
else {
|
|
319
|
+
for (const [key, def] of Object.entries(zl.zones)) {
|
|
320
|
+
const at = `zoneLayout.zones.${key}`;
|
|
321
|
+
if (!isObj(def)) {
|
|
322
|
+
errors.push(`${at}: a zone is an object`);
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (def.kind !== 'side' && def.kind !== 'strip')
|
|
326
|
+
errors.push(`${at}.kind: 'side' or 'strip'`);
|
|
327
|
+
if (def.side !== undefined && def.side !== 'left' && def.side !== 'right')
|
|
328
|
+
errors.push(`${at}.side: 'left' or 'right'`);
|
|
329
|
+
if (def.area !== undefined && def.area !== 'top' && def.area !== 'bottom')
|
|
330
|
+
errors.push(`${at}.area: 'top' or 'bottom'`);
|
|
331
|
+
if (def.pinned !== undefined && typeof def.pinned !== 'boolean')
|
|
332
|
+
errors.push(`${at}.pinned: a boolean`);
|
|
333
|
+
if (def.rules !== undefined && (!Array.isArray(def.rules) || def.rules.some((r) => !isObj(r) || typeof r.min !== 'number')))
|
|
334
|
+
errors.push(`${at}.rules: a list of { min, mode?, width?, columns? }`);
|
|
335
|
+
// ONE way to say where a zone is: the page reads `side` / `area`
|
|
336
|
+
// (absent: the right / the top), so the key must say the same.
|
|
337
|
+
const drawnAt = zoneDrawnAt(def);
|
|
338
|
+
if (key !== drawnAt) {
|
|
339
|
+
const strip = def.kind === 'strip';
|
|
340
|
+
const field = strip ? 'area' : 'side';
|
|
341
|
+
const unstated = def[field] === undefined ? ` (it states no ${field}, and ${strip ? 'a strip with none is the top' : 'a side zone with none is the right'})` : '';
|
|
342
|
+
const fixes = (strip ? ['top', 'bottom'] : ['left', 'right']).includes(key)
|
|
343
|
+
? `key it '${drawnAt}', or set ${field}: '${key}'`
|
|
344
|
+
: `key it '${drawnAt}'`;
|
|
345
|
+
errors.push(`${at}: the page draws this ${strip ? 'strip' : 'side zone'} at the ${drawnAt}${unstated} — ` +
|
|
346
|
+
`a zone is keyed by where it is drawn (a side by its side, a strip by its area${key === 'middle' ? "; the middle's membership is the widget grid's" : ''}): ${fixes}`);
|
|
347
|
+
}
|
|
348
|
+
if (!Array.isArray(def.widgets)) {
|
|
349
|
+
errors.push(`${at}.widgets: a list of widget instance ids`);
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
const seen = new Set();
|
|
353
|
+
for (const id of def.widgets)
|
|
354
|
+
place(id, drawnAt, `${at}.widgets`, seen);
|
|
355
|
+
}
|
|
356
|
+
if (zl.styles !== undefined && (!isObj(zl.styles) || (zl.styles.chat !== undefined && typeof zl.styles.chat !== 'string')))
|
|
357
|
+
errors.push('zoneLayout.styles: { chat?: string }');
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// widgetGrid
|
|
361
|
+
const wg = layout.widgetGrid;
|
|
362
|
+
if (wg !== undefined) {
|
|
363
|
+
if (!isObj(wg) || wg.version !== 1 || !Array.isArray(wg.widgets))
|
|
364
|
+
errors.push('widgetGrid: { version: 1, cell, widgets: [ … ] }');
|
|
365
|
+
else {
|
|
366
|
+
if (typeof wg.cell !== 'number' || !(wg.cell > 0))
|
|
367
|
+
errors.push('widgetGrid.cell: a positive number of px');
|
|
368
|
+
const seen = new Set();
|
|
369
|
+
wg.widgets.forEach((w, n) => {
|
|
370
|
+
const at = `widgetGrid.widgets[${n}]`;
|
|
371
|
+
if (!isObj(w)) {
|
|
372
|
+
errors.push(`${at}: a grid widget is an object`);
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
// A missing or non-string zone is refused like a wrong one — and the
|
|
376
|
+
// entry's id is still checked, since it names a widget either way.
|
|
377
|
+
const zone = typeof w.zone === 'string' ? w.zone : undefined;
|
|
378
|
+
const zoned = zone === undefined ? (errors.push(`${at}.zone: one of ${ZONE_IDS.join(', ')}`), false) : zoneKey(zone, `${at}.zone`);
|
|
379
|
+
if (typeof w.order !== 'number' || !Number.isFinite(w.order))
|
|
380
|
+
errors.push(`${at}.order: a number`);
|
|
381
|
+
if (!isObj(w.size) || !isSizeSpec(w.size.w) || !isSizeSpec(w.size.h))
|
|
382
|
+
errors.push(`${at}.size: { w, h }, each 'grow', 'fixed' or { cells | minCells | maxCells }`);
|
|
383
|
+
if (!isAnchor(w.anchor))
|
|
384
|
+
errors.push(`${at}.anchor: { top?, bottom?, left?, right? } of booleans`);
|
|
385
|
+
if (w.colSpan !== undefined && !(isInt(w.colSpan) && w.colSpan > 0))
|
|
386
|
+
errors.push(`${at}.colSpan: a positive integer`);
|
|
387
|
+
if (w.group !== undefined && typeof w.group !== 'string')
|
|
388
|
+
errors.push(`${at}.group: a string`);
|
|
389
|
+
if (zoned)
|
|
390
|
+
place(w.id, zone, 'widgetGrid.widgets', seen);
|
|
391
|
+
else
|
|
392
|
+
isInstanceId(w.id, 'widgetGrid.widgets');
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
// arrangedGrid
|
|
397
|
+
const ag = layout.arrangedGrid;
|
|
398
|
+
if (ag !== undefined) {
|
|
399
|
+
if (!isObj(ag))
|
|
400
|
+
errors.push('arrangedGrid: { left?, middle?, right? }');
|
|
401
|
+
else
|
|
402
|
+
for (const [key, frame] of Object.entries(ag)) {
|
|
403
|
+
const at = `arrangedGrid.${key}`;
|
|
404
|
+
if (!zoneKey(key, at))
|
|
405
|
+
continue;
|
|
406
|
+
if (!isObj(frame) || !(isInt(frame.cols) && frame.cols > 0) || !(isInt(frame.rows) && frame.rows > 0) || !Array.isArray(frame.items)) {
|
|
407
|
+
errors.push(`${at}: { cols, rows, items } — whole, positive cols and rows`);
|
|
408
|
+
continue;
|
|
409
|
+
}
|
|
410
|
+
const { cols, rows } = frame;
|
|
411
|
+
const seen = new Set();
|
|
412
|
+
/** The items with whole-cell boxes, for the overlap check. */
|
|
413
|
+
const boxes = [];
|
|
414
|
+
frame.items.forEach((item, n) => {
|
|
415
|
+
const where = `${at}.items[${n}]`;
|
|
416
|
+
if (!isObj(item)) {
|
|
417
|
+
errors.push(`${where}: an arranged item is an object`);
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
const { x, y, w, h } = item;
|
|
421
|
+
if (!isInt(x) || !isInt(y) || !isInt(w) || !isInt(h) || x < 0 || y < 0 || w < 1 || h < 1 || x + w > cols || y + h > rows)
|
|
422
|
+
errors.push(`${where}: whole cells inside ${cols} × ${rows} (x, y ≥ 0; w, h ≥ 1)`);
|
|
423
|
+
else if (typeof item.id === 'string')
|
|
424
|
+
boxes.push({ id: item.id, x, y, w, h });
|
|
425
|
+
if (item.anchor !== undefined && !isAnchor(item.anchor))
|
|
426
|
+
errors.push(`${where}.anchor: { top?, bottom?, left?, right? } of booleans`);
|
|
427
|
+
if (item.group !== undefined && typeof item.group !== 'string')
|
|
428
|
+
errors.push(`${where}.group: a string`);
|
|
429
|
+
if (item.pinned !== undefined && typeof item.pinned !== 'boolean')
|
|
430
|
+
errors.push(`${where}.pinned: a boolean`);
|
|
431
|
+
place(item.id, key, `${at}.items`, seen);
|
|
432
|
+
});
|
|
433
|
+
// Two boxes on one cell: the page draws both, one over the other.
|
|
434
|
+
boxes.forEach((a, i) => {
|
|
435
|
+
for (const b of boxes.slice(i + 1))
|
|
436
|
+
if (a.id !== b.id && a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h)
|
|
437
|
+
warnings.push(`${at}: '${a.id}' and '${b.id}' share cells — one draws over the other`);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
// widgetSettings / widgetStyles
|
|
442
|
+
const ws = layout.widgetSettings;
|
|
443
|
+
if (ws !== undefined) {
|
|
444
|
+
if (!isObj(ws))
|
|
445
|
+
errors.push('widgetSettings: { [widget instance id]: { … } }');
|
|
446
|
+
else
|
|
447
|
+
for (const [id, v] of Object.entries(ws)) {
|
|
448
|
+
if (!isWidgetInstanceId(id))
|
|
449
|
+
errors.push(`widgetSettings: '${id}' is not a widget instance id`);
|
|
450
|
+
if (!isObj(v))
|
|
451
|
+
errors.push(`widgetSettings.${id}: the widget's settings, an object`);
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
const pins = layout.widgetStyles;
|
|
455
|
+
if (pins !== undefined) {
|
|
456
|
+
if (!isObj(pins))
|
|
457
|
+
errors.push('widgetStyles: { [widget instance id]: { slug, id? } }');
|
|
458
|
+
else
|
|
459
|
+
for (const [id, v] of Object.entries(pins)) {
|
|
460
|
+
if (!isWidgetInstanceId(id))
|
|
461
|
+
errors.push(`widgetStyles: '${id}' is not a widget instance id`);
|
|
462
|
+
if (!isObj(v) || typeof v.slug !== 'string' || !v.slug || (v.id !== undefined && !(isInt(v.id) && v.id > 0)))
|
|
463
|
+
errors.push(`widgetStyles.${id}: a style pin, { slug, id? }`);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
// Warnings: what draws, but not as written.
|
|
467
|
+
const drawn = new Set(drawnWidgetIds(layout));
|
|
468
|
+
const framed = (zone) => {
|
|
469
|
+
const frame = isObj(ag) ? ag[zone] : undefined;
|
|
470
|
+
return isObj(frame) && Array.isArray(frame.items) && (zone === 'middle' || frame.items.length > 0);
|
|
471
|
+
};
|
|
472
|
+
for (const [id, { zone }] of placedIn) {
|
|
473
|
+
if (RETIRED_WIDGET_IDS.has(widgetOfInstance(id))) {
|
|
474
|
+
warnings.push(`'${id}' names a retired widget — no reader draws it`);
|
|
475
|
+
continue;
|
|
476
|
+
}
|
|
477
|
+
if (drawn.has(id))
|
|
478
|
+
continue;
|
|
479
|
+
// Named, and never drawn: the page reads each zone one way
|
|
480
|
+
// (`drawnWidgetIds`), and this id is not in what it reads.
|
|
481
|
+
const why = framed(zone)
|
|
482
|
+
? `the ${zone}'s arrangement draws there, and it does not place '${id}'`
|
|
483
|
+
: `the grid puts it on the ${zone}, where the layout has no side zone to draw it in`;
|
|
484
|
+
warnings.push(`'${id}' is placed in the ${zone} but never drawn — ${why}`);
|
|
485
|
+
}
|
|
486
|
+
if (opts.widgets) {
|
|
487
|
+
const decls = new Map(opts.widgets.map((w) => [w.id, w]));
|
|
488
|
+
const counts = new Map();
|
|
489
|
+
for (const id of placedIn.keys()) {
|
|
490
|
+
const widget = widgetOfInstance(id);
|
|
491
|
+
counts.set(widget, (counts.get(widget) ?? 0) + 1);
|
|
492
|
+
if (opts.unknownWidgets === 'warn' && !decls.has(widget) && !RETIRED_WIDGET_IDS.has(widget))
|
|
493
|
+
warnings.push(`'${id}' names a widget this pub does not know — it draws as a placeholder`);
|
|
494
|
+
}
|
|
495
|
+
for (const [widget, n] of counts) {
|
|
496
|
+
const cap = decls.get(widget)?.maxInstances;
|
|
497
|
+
if (typeof cap === 'number' && n > cap)
|
|
498
|
+
warnings.push(`'${widget}' is placed ${n} times, over its maxInstances (${cap}) — readers draw the first ${cap}`);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
return { ok: errors.length === 0, errors, warnings };
|
|
502
|
+
}
|
|
503
|
+
//# sourceMappingURL=sessionLayout.js.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settings document (PLAN-turn-order §4.12, R13; ruled 2026-09-21).
|
|
3
|
+
*
|
|
4
|
+
* Every setting a person can see in session settings reaches every run as
|
|
5
|
+
* **one resolved document**, defaults applied. A run's `sessionScope` was a
|
|
6
|
+
* pointer (`{ sessionId, currentCharacterId }`) and every node that wanted a
|
|
7
|
+
* setting queried for it; this is the document the host resolves once per
|
|
8
|
+
* run (`resolveSessionSettings`, in core) and hands to the inlet as
|
|
9
|
+
* `session`, so `$.input.session.fields.tone` reads in any spec and no spec
|
|
10
|
+
* knows which table a setting came from.
|
|
11
|
+
*
|
|
12
|
+
* `fields` is the cascade's answer (§4.13): for every declared key, the
|
|
13
|
+
* session's stored value, else the genre's pinned value, else the field's
|
|
14
|
+
* core default. A key nobody declares or pins is absent.
|
|
15
|
+
*
|
|
16
|
+
* Three ways in: every core inlet that takes a session publishes it on a
|
|
17
|
+
* `session` port; `core:query/session-settings@1` re-reads it after a write;
|
|
18
|
+
* scripts and hooks get it as a read-only extra named `session`.
|
|
19
|
+
*
|
|
20
|
+
* The widget envelope's `session.v1` is a projection of this document:
|
|
21
|
+
* widgets receive `title`, `fields`, `turnOrder`, `channels`, `cast`,
|
|
22
|
+
* `annex` — never `guests` or `pipelines`.
|
|
23
|
+
*/
|
|
24
|
+
import type { SessionCastV1 } from './participants.js';
|
|
25
|
+
import type { TurnOrderV1 } from './turnOrder.js';
|
|
26
|
+
/** @experimental */
|
|
27
|
+
export interface SessionSettingsV1 {
|
|
28
|
+
v: 1;
|
|
29
|
+
sessionId: number;
|
|
30
|
+
title: string | null;
|
|
31
|
+
/** User ids. Server-side only; never in the widget projection. */
|
|
32
|
+
guests: number[];
|
|
33
|
+
genreId: string;
|
|
34
|
+
presetId: number | null;
|
|
35
|
+
/** Every declared genre field: default, then the session's value over it. */
|
|
36
|
+
fields: Record<string, unknown>;
|
|
37
|
+
/**
|
|
38
|
+
* 🚧 What a person's persona-less line is called in this session (R4):
|
|
39
|
+
* the session's own value, else the genre's `playerLabel` (in `en`), else
|
|
40
|
+
* absent — and absent whenever the genre declares none, whatever is
|
|
41
|
+
* stored. Read, never stamped on a row.
|
|
42
|
+
*/
|
|
43
|
+
playerLabel?: string;
|
|
44
|
+
scenario: string | null;
|
|
45
|
+
lorebookId: number | null;
|
|
46
|
+
tags: string[];
|
|
47
|
+
channels: string[];
|
|
48
|
+
/** What core:query/session-cast@1 publishes, envoys included. Not candidates: nothing here has been pooled. */
|
|
49
|
+
cast: SessionCastV1;
|
|
50
|
+
/** Per bound spec slug: the rebinds and param overrides in force at session scope. */
|
|
51
|
+
pipelines: Record<string, {
|
|
52
|
+
rebinds: Record<string, string>;
|
|
53
|
+
params: Record<string, Record<string, unknown>>;
|
|
54
|
+
}>;
|
|
55
|
+
/**
|
|
56
|
+
* The session's turn order — the state, as `set-turn-order` wrote it
|
|
57
|
+
* (R28, the modder pass). What the session chose is
|
|
58
|
+
* `pipelines[<its turn-order spec>].rebinds.strategy`; what it may choose
|
|
59
|
+
* is the node's `expose.swaps` on the registry. The document carries no
|
|
60
|
+
* turn-order special case.
|
|
61
|
+
*/
|
|
62
|
+
turnOrder: TurnOrderV1;
|
|
63
|
+
/** Read-only from the pipeline layer: written by no outlet except `set-turn-order`. */
|
|
64
|
+
metadata: Record<string, unknown>;
|
|
65
|
+
/** The whole annex; a spec reads its own key. */
|
|
66
|
+
annex: Record<string, unknown>;
|
|
67
|
+
/** Open. */
|
|
68
|
+
[k: string]: unknown;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=sessionSettings.d.ts.map
|