@serene-pub/sdk 0.6.0-pr-7 โ†’ 0.6.0-pr-8

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.
Files changed (79) hide show
  1. package/dist/annexFields.d.ts +14 -0
  2. package/dist/annexFields.js +7 -0
  3. package/dist/announce.d.ts +26 -13
  4. package/dist/announce.js +31 -0
  5. package/dist/appletCard.d.ts +17 -0
  6. package/dist/appletCard.js +60 -0
  7. package/dist/attributes.d.ts +3 -3
  8. package/dist/attributes.js +1 -1
  9. package/dist/builder.d.ts +23 -6
  10. package/dist/builder.js +57 -5
  11. package/dist/cadences.d.ts +11 -2
  12. package/dist/cadences.js +27 -2
  13. package/dist/characterProfile.d.ts +137 -0
  14. package/dist/characterProfile.js +24 -0
  15. package/dist/component.d.ts +1 -1
  16. package/dist/componentImports.d.ts +1 -1
  17. package/dist/componentImports.js +2 -0
  18. package/dist/declarations.js +4 -0
  19. package/dist/descriptors.d.ts +68 -3
  20. package/dist/descriptors.js +23 -0
  21. package/dist/document.d.ts +8 -0
  22. package/dist/document.js +44 -1
  23. package/dist/events.d.ts +35 -4
  24. package/dist/events.js +7 -3
  25. package/dist/executor.js +26 -5
  26. package/dist/extension.d.ts +17 -0
  27. package/dist/fit.d.ts +4 -1
  28. package/dist/fit.js +43 -1
  29. package/dist/functions.d.ts +7 -1
  30. package/dist/functions.js +3 -1
  31. package/dist/genres.d.ts +7 -0
  32. package/dist/genres.js +32 -1
  33. package/dist/hookGrants.js +10 -0
  34. package/dist/index.d.ts +4 -0
  35. package/dist/index.js +9 -0
  36. package/dist/layout.d.ts +18 -0
  37. package/dist/libraryDraft.d.ts +2 -0
  38. package/dist/libraryDraft.js +5 -1
  39. package/dist/lorebookFile.d.ts +8 -0
  40. package/dist/lorebookFile.js +21 -0
  41. package/dist/participants.d.ts +53 -8
  42. package/dist/participants.js +9 -5
  43. package/dist/pluginPermissions.js +1 -1
  44. package/dist/promptBlocks.d.ts +5 -1
  45. package/dist/promptBlocks.js +23 -8
  46. package/dist/registry.js +6 -3
  47. package/dist/sceneSettings.d.ts +4 -0
  48. package/dist/sceneSettings.js +7 -4
  49. package/dist/sessionDossier.d.ts +57 -0
  50. package/dist/sessionLayout.d.ts +296 -85
  51. package/dist/sessionLayout.js +397 -133
  52. package/dist/settings.d.ts +28 -1
  53. package/dist/settings.js +50 -2
  54. package/dist/shapes.d.ts +6 -1
  55. package/dist/shapes.js +6 -1
  56. package/dist/sheetLatitude.d.ts +148 -0
  57. package/dist/sheetLatitude.js +161 -0
  58. package/dist/storyTime.js +6 -4
  59. package/dist/surfaces.d.ts +11 -1
  60. package/dist/template.d.ts +26 -1
  61. package/dist/templateCheck.d.ts +24 -0
  62. package/dist/templateCheck.js +299 -7
  63. package/dist/templateFit.js +4 -0
  64. package/dist/templateIds.d.ts +6 -0
  65. package/dist/templateIds.js +9 -0
  66. package/dist/turnLock.d.ts +10 -1
  67. package/dist/turnLock.js +6 -1
  68. package/dist/turnOrder.d.ts +37 -4
  69. package/dist/turnOrder.js +49 -11
  70. package/dist/validate.d.ts +4 -2
  71. package/dist/validate.js +15 -11
  72. package/dist/variableLayouts.d.ts +141 -0
  73. package/dist/variableLayouts.js +183 -0
  74. package/dist/variables.d.ts +35 -7
  75. package/dist/variables.js +34 -1
  76. package/dist/widgetDecls.js +12 -0
  77. package/dist/widgets.d.ts +384 -41
  78. package/dist/widgets.js +23 -0
  79. package/package.json +1 -1
package/dist/turnOrder.js CHANGED
@@ -65,13 +65,33 @@ const speakerRefOf = (m) => m.speaker ?? m.metadata?.speaker;
65
65
  * carries; null for a row from neither. The one reading of a sender โ€”
66
66
  * the row that opens a round (`spokenRefsSince`) is read by it.
67
67
  *
68
+ * ๐Ÿšง `refOfMember` is the cast lookup: a cast member id โ†’ the seat's `ref`, as
69
+ * the cast entry whose `castMemberId` matches carries it. When the row has a
70
+ * `castMemberId` and the lookup returns a ref, that ref is the sender; it
71
+ * changes **identity only**, never whether a row is a sender (an assistant row
72
+ * never becomes one). Without the lookup the card form is read (โณ until S5 of
73
+ * the seat-cast programme). A sender is always a player seat's line, so the
74
+ * lookup is asked for a `'player-seat'`.
75
+ *
68
76
  * @experimental ๐Ÿšง provisional with the turn-order vocabulary.
69
77
  */
70
- export function senderRefOf(m) {
71
- if (m.personaId != null)
72
- return `character:${m.personaId}`;
73
- const ref = speakerRefOf(m);
74
- return typeof ref === 'string' && /^player-seat:[1-9][0-9]*$/.test(ref) ? ref : null;
78
+ export function senderRefOf(m, refOfMember) {
79
+ const today = (() => {
80
+ if (m.personaId != null)
81
+ return `character:${m.personaId}`;
82
+ const ref = speakerRefOf(m);
83
+ return typeof ref === 'string' && /^player-seat:[1-9][0-9]*$/.test(ref)
84
+ ? ref
85
+ : null;
86
+ })();
87
+ if (!today)
88
+ return null;
89
+ if (m.castMemberId != null && refOfMember) {
90
+ const ref = refOfMember(m.castMemberId, 'player-seat');
91
+ if (ref)
92
+ return ref;
93
+ }
94
+ return today;
75
95
  }
76
96
  /**
77
97
  * The rows that count as turns: not hidden, not narration. Hidden rows and
@@ -93,7 +113,8 @@ const lastUserIndex = (turns) => {
93
113
  };
94
114
  /**
95
115
  * Which participants have already spoken since the person last did, as
96
- * references (`character:<id>`, `player-seat:<id>`, `envoy:<slug>`).
116
+ * references (`character:<id>`, ๐Ÿšง `seated-member:<id>`, `player-seat:<id>`,
117
+ * `envoy:<slug>`).
97
118
  *
98
119
  * Three readings, one per kind, each the fact that kind leaves in the
99
120
  * history: a character's id on a reply row, an envoy's reference on a reply
@@ -103,10 +124,18 @@ const lastUserIndex = (turns) => {
103
124
  * envoy's reply marks no character. Before any user row the whole history is
104
125
  * one round, so a greeting counts as its character's turn.
105
126
  *
127
+ * ๐Ÿšง `refOfMember` is the cast lookup: a cast member id โ†’ the seat's `ref`, as
128
+ * the cast entry whose `castMemberId` matches carries it. A row with a
129
+ * `castMemberId` the lookup answers is read as that ref (a card-less member's
130
+ * reply too); otherwise the card form is read (โณ until S5 of the seat-cast
131
+ * programme). It changes identity only, never whether a row counts. Without
132
+ * it the answer is as it was. A reply row asks the lookup for a `'character-seat'`,
133
+ * the opening person's row for a `'player-seat'`.
134
+ *
106
135
  * @experimental ๐Ÿšง provisional with the turn-order vocabulary.
107
136
  * @ruling PLAN-turn-order ยง4.4
108
137
  */
109
- export function spokenRefsSince(messages) {
138
+ export function spokenRefsSince(messages, refOfMember) {
110
139
  const turns = countedTurns(messages);
111
140
  const at = lastUserIndex(turns);
112
141
  const out = new Set();
@@ -114,13 +143,18 @@ export function spokenRefsSince(messages) {
114
143
  const m = turns[i];
115
144
  if (m.role !== 'assistant')
116
145
  continue;
117
- if (m.characterId != null)
146
+ const memberRef = m.castMemberId != null && refOfMember
147
+ ? refOfMember(m.castMemberId, 'character-seat')
148
+ : null;
149
+ if (memberRef)
150
+ out.add(memberRef);
151
+ else if (m.characterId != null)
118
152
  out.add(`character:${m.characterId}`);
119
153
  const ref = speakerRefOf(m);
120
154
  if (typeof ref === 'string' && ref.startsWith('envoy:'))
121
155
  out.add(ref);
122
156
  }
123
- const sender = at >= 0 ? senderRefOf(turns[at]) : null;
157
+ const sender = at >= 0 ? senderRefOf(turns[at], refOfMember) : null;
124
158
  if (sender)
125
159
  out.add(sender);
126
160
  return out;
@@ -135,11 +169,15 @@ export function spokenRefsSince(messages) {
135
169
  * This is the rule `core:task/turn-round-robin@1` runs, and the fallback a
136
170
  * plugin's own strategy should use rather than carry a copy of it.
137
171
  *
172
+ * ๐Ÿšง `refOfMember` is the cast lookup, passed through to `spokenRefsSince`
173
+ * (see there, with its seat-kind hint); without it the card form is read (โณ until
174
+ * S5 of the seat-cast programme).
175
+ *
138
176
  * @experimental ๐Ÿšง provisional with the turn-order vocabulary.
139
177
  * @ruling PLAN-turn-order ยง4.4
140
178
  */
141
- export function roundRobinOrder(candidates, messages) {
142
- const spoken = spokenRefsSince(messages);
179
+ export function roundRobinOrder(candidates, messages, refOfMember) {
180
+ const spoken = spokenRefsSince(messages, refOfMember);
143
181
  return candidates.filter((c) => !spoken.has(c.ref)).map((c) => ({ ref: c.ref, via: 'strategy' }));
144
182
  }
145
183
  //# sourceMappingURL=turnOrder.js.map
@@ -57,8 +57,10 @@ export declare function validate(doc: SpecDocument, options?: ValidateOptions):
57
57
  * ยท **an oracle** โ€” only an oracle has a model's tokens to stream.
58
58
  *
59
59
  * A step status, step label and step purpose are display text, and a
60
- * step purpose sits only on a model call โ€” an oracle whose definition declares
61
- * a `connection` slot (`isModelCall`; law `step purpose`, 2026-09-30).
60
+ * step purpose sits on any step of a document that calls no model at all; in
61
+ * one that calls a model (a node, or a swap a node lists, whose definition
62
+ * declares a `connection` slot โ€” `isModelCall`) it sits only on a model call
63
+ * (law `step purpose`, 2026-09-30; widened 2026-11-12).
62
64
  * @internal
63
65
  * @ruling lair pass B3/B18, owner D6 and D5 (2026-09-27), W2 (2026-09-27), R-20
64
66
  */
package/dist/validate.js CHANGED
@@ -21,7 +21,7 @@ import { boundaryTriggerFindings } from './sceneSettings.js';
21
21
  import { templateLawFindings } from './templateFit.js';
22
22
  import { isSlotRef } from './refs.js';
23
23
  import { assignable, isStreaming, JSON_SHAPE } from './shapes.js';
24
- import { isModelCall, stepPurposeRefusal } from './builder.js';
24
+ import { isModelCall, specCallsModel, stepPurposeRefusal } from './builder.js';
25
25
  import { capabilityLabel, FEATURES, IO_KINDS, IO_KIND_TOKEN, isKnownIoKind, isTransformId, parseTransform, transformId, } from './capabilities.js';
26
26
  /**
27
27
  * The port shapes a spec may assemble field by field (`templateContext: {
@@ -1180,13 +1180,13 @@ export function validate(doc, options = {}) {
1180
1180
  }
1181
1181
  // โ”€โ”€ assemble wiring โ€” a prompt is assembled for the model call it feeds โ”€โ”€โ”€
1182
1182
  // `assemble@2` reads its `template` slot and the connection it renders for
1183
- // only when the spec wires them: unwired, the run halts on a real instance
1184
- // ("assemble has no template"), and once the template is wired a chat
1185
- // wire-mode connection is handed a prompt with no messages. Neither shows
1186
- // on a fixture host, so it is said here, where the author is (F3 docs
1187
- // gate, stalls 12 and 14). A warning, not an error: a host saves documents
1188
- // its own tests and older plugins built bare, and the run's own halt is
1189
- // the error.
1183
+ // only when the document wires them: unwired, the run halts on a real
1184
+ // instance ("assemble has no template"), and once the template is wired a
1185
+ // chat wire-mode connection is handed a prompt with no messages. Neither
1186
+ // shows on a fixture host. The builder's `build()` now supplies both, so
1187
+ // this warns on a document that did not come through the builder: hand
1188
+ // written, an older plugin's, or a host's own tests. A warning, not an
1189
+ // error: the run's own halt is the error.
1190
1190
  for (const n of doc.nodes) {
1191
1191
  if (n.definitionId !== 'core:task/assemble' || n.definitionVersion !== 2)
1192
1192
  continue;
@@ -1255,8 +1255,10 @@ export function validate(doc, options = {}) {
1255
1255
  * ยท **an oracle** โ€” only an oracle has a model's tokens to stream.
1256
1256
  *
1257
1257
  * A step status, step label and step purpose are display text, and a
1258
- * step purpose sits only on a model call โ€” an oracle whose definition declares
1259
- * a `connection` slot (`isModelCall`; law `step purpose`, 2026-09-30).
1258
+ * step purpose sits on any step of a document that calls no model at all; in
1259
+ * one that calls a model (a node, or a swap a node lists, whose definition
1260
+ * declares a `connection` slot โ€” `isModelCall`) it sits only on a model call
1261
+ * (law `step purpose`, 2026-09-30; widened 2026-11-12).
1260
1262
  * @internal
1261
1263
  * @ruling lair pass B3/B18, owner D6 and D5 (2026-09-27), W2 (2026-09-27), R-20
1262
1264
  */
@@ -1342,6 +1344,8 @@ export function streamingStepFindings(doc) {
1342
1344
  label: "write the step's name as the settings show it โ€” a string ('Planner') or a locale map with 'en'",
1343
1345
  purpose: "write what this model call is for, in one or two plain sentences โ€” a string or a locale map with 'en'",
1344
1346
  };
1347
+ // A purpose is allowed on any step of a document that calls no model at all, and only on a model call in one that does.
1348
+ const callsAModel = specCallsModel(doc.nodes);
1345
1349
  for (const n of doc.nodes) {
1346
1350
  for (const field of ['status', 'label', 'purpose']) {
1347
1351
  const text = n.expose?.[field];
@@ -1350,7 +1354,7 @@ export function streamingStepFindings(doc) {
1350
1354
  for (const message of i18nFindings(text, `'${n.key}' expose.${field}`))
1351
1355
  f.push({ law: 'R-20', severity: 'error', nodeKey: n.key, message, fix: FIX[field] });
1352
1356
  }
1353
- if (n.expose?.purpose === undefined)
1357
+ if (n.expose?.purpose === undefined || !callsAModel)
1354
1358
  continue;
1355
1359
  const def = getDefinition(`${n.definitionId}@${n.definitionVersion}`);
1356
1360
  if (def && !isModelCall(def))
@@ -0,0 +1,141 @@
1
+ /**
2
+ * ๐Ÿšง **Variable layouts by reference** โ€” the name a context template, a
3
+ * preset and the pub use to point at one of a variable's layouts, and the
4
+ * typed builder a plugin ships one with.
5
+ *
6
+ * A variable is written out by one layout, chosen once for the whole pub; a
7
+ * preset may decide differently for its sessions, per variable; a context
8
+ * template that wants a different one names it in place:
9
+ *
10
+ * ```hbs
11
+ * {{{layout characters "core/json@1"}}}
12
+ * ```
13
+ * ```liquid
14
+ * {{ characters | layout: "core/json@1" }}
15
+ * ```
16
+ *
17
+ * ## The layout reference
18
+ *
19
+ * `<owner>/<slug>@<major>`: the owner is a plugin slug (`acme.dice`) or
20
+ * `core`, the slug is kebab-case, the major a positive integer and always
21
+ * written. Unique within its variable, so `core/json@1` names one layout of
22
+ * `characters` and another of `personas`.
23
+ *
24
+ * โš  Not a **template id** (`acme:template/omens-prose@1`), the row's
25
+ * app-wide identity. โš  Not a session layout (a genre's `layouts`).
26
+ * @experimental
27
+ * @ruling PLAN-variable-layouts-2026-11-10 โ˜…4, โ˜…7
28
+ */
29
+ import type { EngineId } from './engines.js';
30
+ import type { TemplateCheckOptions, TemplateScope } from './template.js';
31
+ import { type TemplateSeed } from './templateIds.js';
32
+ import type { VariableDecl } from './variables.js';
33
+ /**
34
+ * The slug half of a layout reference: kebab-case. Also what
35
+ * `TemplateSeed.slug` must read.
36
+ * @experimental
37
+ */
38
+ export declare const VARIABLE_LAYOUT_SLUG: RegExp;
39
+ /** The three parts of a layout reference. @experimental */
40
+ export interface VariableLayoutReferenceParts {
41
+ /** A plugin slug, or `core`. */
42
+ owner: string;
43
+ /** Kebab-case. */
44
+ slug: string;
45
+ /** A positive integer. */
46
+ major: number;
47
+ }
48
+ /**
49
+ * Split a layout reference, or `null` when it is not one.
50
+ * @experimental
51
+ */
52
+ export declare function parseVariableLayoutReference(value: unknown): VariableLayoutReferenceParts | null;
53
+ /**
54
+ * Write a layout reference from its parts. Throws, in words, on a part
55
+ * outside the grammar โ€” the one place a reference is spelled.
56
+ * @experimental
57
+ */
58
+ export declare function formatVariableLayoutReference(parts: VariableLayoutReferenceParts): string;
59
+ /**
60
+ * The helper (Handlebars) and filter (Liquid) a context template names a
61
+ * layout with: `{{{layout characters "core/json@1"}}}`,
62
+ * `{{ characters | layout: "core/json@1" }}`. Inside a template no session
63
+ * layout can appear, so the bare word is unambiguous there.
64
+ * @experimental
65
+ */
66
+ export declare const VARIABLE_LAYOUT_HELPER = "layout";
67
+ /**
68
+ * One layout a variable offers, as a `layout` call's completion and hover
69
+ * list it, and as the template check accepts it
70
+ * (`TemplateCheckOptions.variableLayoutOffers`).
71
+ * @experimental
72
+ */
73
+ export interface VariableLayoutOffer {
74
+ /** `core/json@1`. */
75
+ reference: string;
76
+ /** The layout's display name โ€” `JSON`, `Titled JSON block`. */
77
+ label: string;
78
+ }
79
+ /**
80
+ * A variable id split into owner, name and major, or `null` when it is not
81
+ * one โ€” `core:var/characters@1`. A camelCase name is tolerated: the variable
82
+ * registry does not refuse one, and the app kebabs it when it names a layout row.
83
+ * @internal
84
+ */
85
+ export declare function variableIdParts(id: unknown): {
86
+ owner: string;
87
+ name: string;
88
+ major: number;
89
+ } | null;
90
+ /**
91
+ * A new scope in which every root key `renders` maps carries `laidOutBy` โ€” the
92
+ * variable that writes it out. `renders` is what `rendersAt()` returns (key โ†’
93
+ * variable id). This is how a host tells the template check and the editor
94
+ * which keys are laid out. A key that is not a root of `scope` is skipped: the
95
+ * scope is the authority on names. A laid-out value is a string, so an `'any'`
96
+ * or `string[]` root becomes an optional string. Never mutates its input.
97
+ * @experimental
98
+ */
99
+ export declare function laidOutScope(scope: TemplateScope, renders: Readonly<Record<string, string>>): TemplateScope;
100
+ /**
101
+ * The layouts offered by the variable that writes `key` out
102
+ * (`scope[key].laidOutBy`) โ€” for completion inside `layout characters "` and
103
+ * for hover. `[]` when the key isn't laid out, the offers are absent, or the
104
+ * variable offers none.
105
+ * @experimental
106
+ */
107
+ export declare function variableLayoutOffersFor(scope: TemplateScope, key: string, offers: TemplateCheckOptions['variableLayoutOffers']): readonly VariableLayoutOffer[];
108
+ /**
109
+ * What a plugin gives {@link variableLayout}.
110
+ * @experimental
111
+ */
112
+ export interface VariableLayoutInput {
113
+ /** Kebab-case โ€” the slug of the layout reference `<plugin>/<slug>@<major>`. */
114
+ slug: string;
115
+ /** A positive integer. */
116
+ major: number;
117
+ /** The layout's display name โ€” `Titled JSON block`. */
118
+ label: string;
119
+ /** The registered engine `source` is written in. */
120
+ engine: EngineId;
121
+ /** The template source, reading the variable's scope. */
122
+ source: string;
123
+ }
124
+ /**
125
+ * The typed builder of a variable layout's `TemplateSeed` โ€” list the result in
126
+ * `defineExtension({ templates })`. `variable` is the value `defineVariable` /
127
+ * `definePluginVariable` returned, so a typo is a compile error; it may be
128
+ * another package's (a plugin may lay out `core:var/characters@1`).
129
+ *
130
+ * The seed's id is `<pluginId>:template/<variable name>-<slug>@<major>`. Throws,
131
+ * naming the plugin and the variable, on any part outside its grammar, and
132
+ * with the problems `templateSeedProblems` finds.
133
+ *
134
+ * โš  It does not check `source`: the template checker carries the engines and
135
+ * lives at `@serene-pub/sdk/template-check`, which this dependency-free module
136
+ * must not import. The packager (`variableSeedFindings`, `E_TEMPLATE_SCOPE`)
137
+ * and the instance's install check hold the source to the variable's scope.
138
+ * @experimental
139
+ */
140
+ export declare function variableLayout(pluginId: string, variable: VariableDecl, input: VariableLayoutInput): TemplateSeed;
141
+ //# sourceMappingURL=variableLayouts.d.ts.map
@@ -0,0 +1,183 @@
1
+ /**
2
+ * ๐Ÿšง **Variable layouts by reference** โ€” the name a context template, a
3
+ * preset and the pub use to point at one of a variable's layouts, and the
4
+ * typed builder a plugin ships one with.
5
+ *
6
+ * A variable is written out by one layout, chosen once for the whole pub; a
7
+ * preset may decide differently for its sessions, per variable; a context
8
+ * template that wants a different one names it in place:
9
+ *
10
+ * ```hbs
11
+ * {{{layout characters "core/json@1"}}}
12
+ * ```
13
+ * ```liquid
14
+ * {{ characters | layout: "core/json@1" }}
15
+ * ```
16
+ *
17
+ * ## The layout reference
18
+ *
19
+ * `<owner>/<slug>@<major>`: the owner is a plugin slug (`acme.dice`) or
20
+ * `core`, the slug is kebab-case, the major a positive integer and always
21
+ * written. Unique within its variable, so `core/json@1` names one layout of
22
+ * `characters` and another of `personas`.
23
+ *
24
+ * โš  Not a **template id** (`acme:template/omens-prose@1`), the row's
25
+ * app-wide identity. โš  Not a session layout (a genre's `layouts`).
26
+ * @experimental
27
+ * @ruling PLAN-variable-layouts-2026-11-10 โ˜…4, โ˜…7
28
+ */
29
+ import { templateSeedProblems } from './templateIds.js';
30
+ /**
31
+ * The slug half of a layout reference: kebab-case. Also what
32
+ * `TemplateSeed.slug` must read.
33
+ * @experimental
34
+ */
35
+ export const VARIABLE_LAYOUT_SLUG = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
36
+ /** A plugin slug (`acme.dice`) or `core`. */
37
+ const OWNER = /^[a-z0-9]+(?:[.-][a-z0-9]+)*$/;
38
+ /**
39
+ * A layout reference: `<owner>/<slug>@<major>` โ€” `core/json@1`,
40
+ * `acme.dice/prose@2`. Module-private: `parseVariableLayoutReference` is the
41
+ * one way to read one.
42
+ */
43
+ const VARIABLE_LAYOUT_REFERENCE = /^([a-z0-9]+(?:[.-][a-z0-9]+)*)\/([a-z0-9]+(?:-[a-z0-9]+)*)@([1-9]\d*)$/;
44
+ /**
45
+ * Split a layout reference, or `null` when it is not one.
46
+ * @experimental
47
+ */
48
+ export function parseVariableLayoutReference(value) {
49
+ if (typeof value !== 'string')
50
+ return null;
51
+ const m = VARIABLE_LAYOUT_REFERENCE.exec(value);
52
+ if (!m)
53
+ return null;
54
+ return { owner: m[1], slug: m[2], major: Number(m[3]) };
55
+ }
56
+ /**
57
+ * Write a layout reference from its parts. Throws, in words, on a part
58
+ * outside the grammar โ€” the one place a reference is spelled.
59
+ * @experimental
60
+ */
61
+ export function formatVariableLayoutReference(parts) {
62
+ const { owner, slug, major } = parts ?? {};
63
+ if (typeof owner !== 'string' || !OWNER.test(owner))
64
+ throw new Error(`layout reference owner '${String(owner)}' is not a plugin slug or 'core' โ€” ` +
65
+ `lowercase letters and digits, joined by '.' or '-' (acme.dice).`);
66
+ if (typeof slug !== 'string' || !VARIABLE_LAYOUT_SLUG.test(slug))
67
+ throw new Error(`layout reference slug '${String(slug)}' is not kebab-case โ€” lowercase letters and ` +
68
+ `digits joined by '-' (titled-json).`);
69
+ if (typeof major !== 'number' || !Number.isInteger(major) || major < 1)
70
+ throw new Error(`layout reference major '${String(major)}' is not a positive whole number.`);
71
+ return `${owner}/${slug}@${major}`;
72
+ }
73
+ /**
74
+ * The helper (Handlebars) and filter (Liquid) a context template names a
75
+ * layout with: `{{{layout characters "core/json@1"}}}`,
76
+ * `{{ characters | layout: "core/json@1" }}`. Inside a template no session
77
+ * layout can appear, so the bare word is unambiguous there.
78
+ * @experimental
79
+ */
80
+ export const VARIABLE_LAYOUT_HELPER = 'layout';
81
+ /**
82
+ * A variable id split into owner, name and major, or `null` when it is not
83
+ * one โ€” `core:var/characters@1`. A camelCase name is tolerated: the variable
84
+ * registry does not refuse one, and the app kebabs it when it names a layout row.
85
+ * @internal
86
+ */
87
+ export function variableIdParts(id) {
88
+ if (typeof id !== 'string')
89
+ return null;
90
+ const m = /^([a-z0-9]+(?:[.-][a-z0-9]+)*):var\/([A-Za-z0-9]+(?:-[A-Za-z0-9]+)*)@(\d+)$/.exec(id);
91
+ if (!m)
92
+ return null;
93
+ return { owner: m[1], name: m[2], major: Number(m[3]) };
94
+ }
95
+ /**
96
+ * A new scope in which every root key `renders` maps carries `laidOutBy` โ€” the
97
+ * variable that writes it out. `renders` is what `rendersAt()` returns (key โ†’
98
+ * variable id). This is how a host tells the template check and the editor
99
+ * which keys are laid out. A key that is not a root of `scope` is skipped: the
100
+ * scope is the authority on names. A laid-out value is a string, so an `'any'`
101
+ * or `string[]` root becomes an optional string. Never mutates its input.
102
+ * @experimental
103
+ */
104
+ export function laidOutScope(scope, renders) {
105
+ const out = { ...scope };
106
+ for (const [key, laidOutBy] of Object.entries(renders ?? {})) {
107
+ if (!Object.prototype.hasOwnProperty.call(scope, key))
108
+ continue;
109
+ const decl = scope[key];
110
+ out[key] =
111
+ decl === 'any' || Array.isArray(decl)
112
+ ? { type: 'string', optional: true, laidOutBy }
113
+ : { ...decl, laidOutBy };
114
+ }
115
+ return out;
116
+ }
117
+ /**
118
+ * The layouts offered by the variable that writes `key` out
119
+ * (`scope[key].laidOutBy`) โ€” for completion inside `layout characters "` and
120
+ * for hover. `[]` when the key isn't laid out, the offers are absent, or the
121
+ * variable offers none.
122
+ * @experimental
123
+ */
124
+ export function variableLayoutOffersFor(scope, key, offers) {
125
+ if (!offers || !Object.prototype.hasOwnProperty.call(scope, key))
126
+ return [];
127
+ const decl = scope[key];
128
+ if (!decl || decl === 'any' || Array.isArray(decl))
129
+ return [];
130
+ const by = decl.laidOutBy;
131
+ if (typeof by !== 'string' || !Object.prototype.hasOwnProperty.call(offers, by))
132
+ return [];
133
+ return offers[by] ?? [];
134
+ }
135
+ /**
136
+ * The typed builder of a variable layout's `TemplateSeed` โ€” list the result in
137
+ * `defineExtension({ templates })`. `variable` is the value `defineVariable` /
138
+ * `definePluginVariable` returned, so a typo is a compile error; it may be
139
+ * another package's (a plugin may lay out `core:var/characters@1`).
140
+ *
141
+ * The seed's id is `<pluginId>:template/<variable name>-<slug>@<major>`. Throws,
142
+ * naming the plugin and the variable, on any part outside its grammar, and
143
+ * with the problems `templateSeedProblems` finds.
144
+ *
145
+ * โš  It does not check `source`: the template checker carries the engines and
146
+ * lives at `@serene-pub/sdk/template-check`, which this dependency-free module
147
+ * must not import. The packager (`variableSeedFindings`, `E_TEMPLATE_SCOPE`)
148
+ * and the instance's install check hold the source to the variable's scope.
149
+ * @experimental
150
+ */
151
+ export function variableLayout(pluginId, variable, input) {
152
+ const who = `plugin '${pluginId}' variable layout for '${String(variable?.id)}'`;
153
+ const parts = variableIdParts(variable?.id);
154
+ if (!parts)
155
+ throw new Error(`${who}: '${String(variable?.id)}' is not a variable id โ€” it must read ` +
156
+ `'<owner>:var/<name>@<major>' (core:var/characters@1).`);
157
+ const { slug, major, label, engine, source } = input ?? {};
158
+ if (typeof slug !== 'string' || !VARIABLE_LAYOUT_SLUG.test(slug))
159
+ throw new Error(`${who}: slug '${String(slug)}' is not kebab-case โ€” lowercase letters and digits joined by '-' (titled-json).`);
160
+ if (typeof major !== 'number' || !Number.isInteger(major) || major < 1)
161
+ throw new Error(`${who}: major '${String(major)}' is not a positive whole number.`);
162
+ if (typeof label !== 'string' || !label.trim())
163
+ throw new Error(`${who}: label is the layout's display name โ€” give a non-empty string.`);
164
+ if (typeof engine !== 'string' || !engine)
165
+ throw new Error(`${who}: engine is the registered engine the source is written in โ€” give a non-empty engine id.`);
166
+ if (typeof source !== 'string')
167
+ throw new Error(`${who}: source is the template text โ€” give a string.`);
168
+ const name = parts.name.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
169
+ const seed = {
170
+ id: `${pluginId}:template/${name}-${slug}@${major}`,
171
+ kind: 'variables',
172
+ variableId: variable.id,
173
+ slug,
174
+ engine,
175
+ body: source,
176
+ label,
177
+ };
178
+ const problems = templateSeedProblems(seed, pluginId);
179
+ if (problems.length)
180
+ throw new Error(`${who}: ${problems.join(' ')}`);
181
+ return seed;
182
+ }
183
+ //# sourceMappingURL=variableLayouts.js.map
@@ -258,6 +258,31 @@ export declare const varHistory: VariableDecl & {
258
258
  };
259
259
  };
260
260
  };
261
+ /** @experimental */
262
+ export declare const varEarlierScenes: VariableDecl & {
263
+ scope: {
264
+ earlierScenes: {
265
+ type: "list";
266
+ of: {
267
+ type: "object";
268
+ fields: {
269
+ name: {
270
+ type: "string";
271
+ description: {
272
+ en: string;
273
+ };
274
+ };
275
+ summary: {
276
+ type: "string";
277
+ description: {
278
+ en: string;
279
+ };
280
+ };
281
+ };
282
+ };
283
+ };
284
+ };
285
+ };
261
286
  /**
262
287
  * Documentation excerpts retrieved for the latest question โ€” the band
263
288
  * `core:query/docs-search@1` publishes (the guide genre's retrieval; declared
@@ -383,13 +408,14 @@ export declare const varCharacterLore: VariableDecl & {
383
408
  export declare const varRelationshipsPerspectives: VariableDecl & {
384
409
  scope: {
385
410
  relationshipsPerspectives: {
411
+ description: {
412
+ en: string;
413
+ };
386
414
  type: import("./template.js").VarType;
387
415
  fields?: Record<string, VarField>;
388
416
  of?: VarField;
389
417
  optional?: boolean;
390
- description: {
391
- en: string;
392
- };
418
+ laidOutBy?: string;
393
419
  };
394
420
  };
395
421
  };
@@ -412,13 +438,14 @@ export declare const varRelationshipsKnown: VariableDecl & {
412
438
  type: "object";
413
439
  fields: {
414
440
  howOthersRegardYou: {
415
- type: import("./template.js").VarType;
416
- fields?: Record<string, VarField>;
417
- of?: VarField;
418
441
  optional: true;
419
442
  description: {
420
443
  en: string;
421
444
  };
445
+ type: import("./template.js").VarType;
446
+ fields?: Record<string, VarField>;
447
+ of?: VarField;
448
+ laidOutBy?: string;
422
449
  };
423
450
  legendaryFigures: {
424
451
  type: "record";
@@ -438,11 +465,12 @@ export declare const varRelationshipsKnown: VariableDecl & {
438
465
  optional: true;
439
466
  };
440
467
  relationships: {
468
+ optional: true;
441
469
  type: import("./template.js").VarType;
442
470
  description?: I18n;
443
471
  fields?: Record<string, VarField>;
444
472
  of?: VarField;
445
- optional: true;
473
+ laidOutBy?: string;
446
474
  };
447
475
  };
448
476
  };
package/dist/variables.js CHANGED
@@ -400,6 +400,39 @@ export const varHistory = defineVariable({
400
400
  'Year 412, Month 1': 'Ash left the Ashguard.',
401
401
  },
402
402
  });
403
+ // ๐Ÿšง Provisional. Not `history` (compiled, dated entries): these are the
404
+ // session's own scene summaries, oldest first, for scenes whose lines have left
405
+ // the prompt.
406
+ /** @experimental */
407
+ export const varEarlierScenes = defineVariable({
408
+ id: 'core:var/earlier-scenes@1',
409
+ i18n: { name: { en: 'Earlier in the story' } },
410
+ description: {
411
+ en: "The summaries of this session's finished scenes whose lines are no longer in the prompt, oldest first, each with its scene's name.",
412
+ },
413
+ scope: {
414
+ earlierScenes: {
415
+ type: 'list',
416
+ of: {
417
+ type: 'object',
418
+ fields: {
419
+ name: { type: 'string', description: { en: "The scene's name, as shown." } },
420
+ summary: { type: 'string', description: { en: "The scene's summary." } },
421
+ },
422
+ },
423
+ },
424
+ },
425
+ sample: [
426
+ {
427
+ name: 'Scene 1 ยท The ferry',
428
+ summary: 'Ash and Rell crossed the river at dusk and lost the mule to the current.',
429
+ },
430
+ {
431
+ name: 'Scene 2 ยท Greyford',
432
+ summary: 'In Greyford the reeve refused them lodging until Rell paid in salt.',
433
+ },
434
+ ],
435
+ });
403
436
  /**
404
437
  * Documentation excerpts retrieved for the latest question โ€” the band
405
438
  * `core:query/docs-search@1` publishes (the guide genre's retrieval; declared
@@ -653,7 +686,7 @@ export const varCurrentDate = defineVariable({
653
686
  id: 'core:var/current-date@1',
654
687
  i18n: { name: { en: 'Current date' } },
655
688
  description: {
656
- en: "The story's present date: the lorebook's clock when it is set, else the most recent history entry.",
689
+ en: "The story's present date: the session's clock when it is set, else the present of the session's line, else the most recent history entry.",
657
690
  },
658
691
  /**
659
692
  * โš  Was `{ currentDate: { type: 'string' } }` with the sample
@@ -95,6 +95,18 @@ export function widget(d) {
95
95
  problems.push(...widgetReadsFindings(d.reads, `widget '${d.id}' reads`));
96
96
  if (d.maxInstances !== undefined && !(Number.isInteger(d.maxInstances) && d.maxInstances > 0))
97
97
  problems.push(`widget '${d.id}' maxInstances: a positive whole number, or leave it out for no cap`);
98
+ if (d.panel !== undefined) {
99
+ const p = d.panel;
100
+ if (typeof p !== 'object' || p === null || Array.isArray(p))
101
+ problems.push(`widget '${d.id}' panel: { height?, priority? } โ€” an object`);
102
+ else {
103
+ const { height, priority } = p;
104
+ if (height !== undefined && height !== 'fit' && height !== 'fill')
105
+ problems.push(`widget '${d.id}' panel.height: 'fit' or 'fill'`);
106
+ if (priority !== undefined && priority !== 'high' && priority !== 'normal' && priority !== 'low')
107
+ problems.push(`widget '${d.id}' panel.priority: 'high', 'normal' or 'low'`);
108
+ }
109
+ }
98
110
  const genres = d.genres?.map((g) => g?.id);
99
111
  if (genres?.some((g) => typeof g !== 'string' || !g))
100
112
  problems.push(`widget '${d.id}' genres: each is a genre value (or use('<id>')), never a bare string`);