@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.
Files changed (187) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +17 -0
  3. package/README.md +368 -0
  4. package/dist/actions.d.ts +572 -0
  5. package/dist/actions.js +829 -0
  6. package/dist/annexFields.d.ts +234 -0
  7. package/dist/annexFields.js +413 -0
  8. package/dist/announce.d.ts +464 -0
  9. package/dist/announce.js +426 -0
  10. package/dist/attributes.d.ts +670 -0
  11. package/dist/attributes.js +904 -0
  12. package/dist/bands.d.ts +125 -0
  13. package/dist/bands.js +256 -0
  14. package/dist/builder.d.ts +683 -0
  15. package/dist/builder.js +677 -0
  16. package/dist/candidates.d.ts +109 -0
  17. package/dist/candidates.js +118 -0
  18. package/dist/capabilities.d.ts +744 -0
  19. package/dist/capabilities.js +679 -0
  20. package/dist/channels.d.ts +106 -0
  21. package/dist/channels.js +129 -0
  22. package/dist/clauses.d.ts +40 -0
  23. package/dist/clauses.js +43 -0
  24. package/dist/component.d.ts +33 -0
  25. package/dist/component.js +27 -0
  26. package/dist/componentBuild.d.ts +48 -0
  27. package/dist/componentBuild.js +84 -0
  28. package/dist/componentClient.d.ts +100 -0
  29. package/dist/componentClient.js +13 -0
  30. package/dist/componentImports.d.ts +51 -0
  31. package/dist/componentImports.js +106 -0
  32. package/dist/componentModule.d.ts +8 -0
  33. package/dist/componentModule.js +270 -0
  34. package/dist/componentWire.d.ts +130 -0
  35. package/dist/componentWire.js +280 -0
  36. package/dist/config.d.ts +295 -0
  37. package/dist/config.js +231 -0
  38. package/dist/connections.d.ts +89 -0
  39. package/dist/connections.js +131 -0
  40. package/dist/declarations.d.ts +290 -0
  41. package/dist/declarations.js +794 -0
  42. package/dist/descriptors.d.ts +1774 -0
  43. package/dist/descriptors.js +1329 -0
  44. package/dist/dev.d.ts +136 -0
  45. package/dist/dev.js +161 -0
  46. package/dist/document.d.ts +202 -0
  47. package/dist/document.js +312 -0
  48. package/dist/engines.d.ts +117 -0
  49. package/dist/engines.js +203 -0
  50. package/dist/eventMapLaws.d.ts +63 -0
  51. package/dist/eventMapLaws.js +128 -0
  52. package/dist/events.d.ts +554 -0
  53. package/dist/events.js +633 -0
  54. package/dist/executor.d.ts +771 -0
  55. package/dist/executor.js +1829 -0
  56. package/dist/extension.d.ts +448 -0
  57. package/dist/extension.js +315 -0
  58. package/dist/facets.d.ts +53 -0
  59. package/dist/facets.js +60 -0
  60. package/dist/foldedSections.d.ts +74 -0
  61. package/dist/foldedSections.js +161 -0
  62. package/dist/genres.d.ts +507 -0
  63. package/dist/genres.js +633 -0
  64. package/dist/guardedConnection.d.ts +138 -0
  65. package/dist/guardedConnection.js +341 -0
  66. package/dist/handlebarsReach.d.ts +122 -0
  67. package/dist/handlebarsReach.js +222 -0
  68. package/dist/hash.d.ts +146 -0
  69. package/dist/hash.js +166 -0
  70. package/dist/hookGrants.d.ts +47 -0
  71. package/dist/hookGrants.js +68 -0
  72. package/dist/hooks.d.ts +290 -0
  73. package/dist/hooks.js +113 -0
  74. package/dist/hostElements.d.ts +447 -0
  75. package/dist/hostElements.js +702 -0
  76. package/dist/i18n.d.ts +94 -0
  77. package/dist/i18n.js +123 -0
  78. package/dist/identity.d.ts +93 -0
  79. package/dist/identity.js +135 -0
  80. package/dist/index.d.ts +85 -0
  81. package/dist/index.js +176 -0
  82. package/dist/layout.d.ts +194 -0
  83. package/dist/layout.js +40 -0
  84. package/dist/media.d.ts +202 -0
  85. package/dist/media.js +70 -0
  86. package/dist/messageBlocks.d.ts +487 -0
  87. package/dist/messageBlocks.js +683 -0
  88. package/dist/migration.d.ts +128 -0
  89. package/dist/migration.js +261 -0
  90. package/dist/names.d.ts +78 -0
  91. package/dist/names.js +136 -0
  92. package/dist/nodeInput.d.ts +399 -0
  93. package/dist/nodeInput.js +178 -0
  94. package/dist/participants.d.ts +291 -0
  95. package/dist/participants.js +252 -0
  96. package/dist/personGate.d.ts +62 -0
  97. package/dist/personGate.js +77 -0
  98. package/dist/pick.d.ts +84 -0
  99. package/dist/pick.js +103 -0
  100. package/dist/pluginHarness.d.ts +235 -0
  101. package/dist/pluginHarness.js +558 -0
  102. package/dist/pluginPermissions.d.ts +25 -0
  103. package/dist/pluginPermissions.js +97 -0
  104. package/dist/pluginRuleRef.d.ts +13 -0
  105. package/dist/pluginRuleRef.js +10 -0
  106. package/dist/predicates.d.ts +182 -0
  107. package/dist/predicates.js +249 -0
  108. package/dist/preview.d.ts +120 -0
  109. package/dist/preview.js +82 -0
  110. package/dist/promptBlocks.d.ts +130 -0
  111. package/dist/promptBlocks.js +197 -0
  112. package/dist/rankingDecisions.d.ts +60 -0
  113. package/dist/rankingDecisions.js +48 -0
  114. package/dist/receipt.d.ts +313 -0
  115. package/dist/receipt.js +60 -0
  116. package/dist/receiverRules.d.ts +24 -0
  117. package/dist/receiverRules.js +94 -0
  118. package/dist/refs.d.ts +117 -0
  119. package/dist/refs.js +137 -0
  120. package/dist/registry.d.ts +230 -0
  121. package/dist/registry.js +273 -0
  122. package/dist/review.d.ts +108 -0
  123. package/dist/review.js +97 -0
  124. package/dist/sampling.d.ts +152 -0
  125. package/dist/sampling.js +712 -0
  126. package/dist/scope.d.ts +65 -0
  127. package/dist/scope.js +128 -0
  128. package/dist/scripts.d.ts +243 -0
  129. package/dist/scripts.js +326 -0
  130. package/dist/sessionLayout.d.ts +339 -0
  131. package/dist/sessionLayout.js +503 -0
  132. package/dist/sessionSettings.d.ts +70 -0
  133. package/dist/sessionSettings.js +2 -0
  134. package/dist/settings.d.ts +501 -0
  135. package/dist/settings.js +604 -0
  136. package/dist/settingsSlot.d.ts +108 -0
  137. package/dist/settingsSlot.js +166 -0
  138. package/dist/shapes.d.ts +373 -0
  139. package/dist/shapes.js +408 -0
  140. package/dist/sheets.d.ts +165 -0
  141. package/dist/sheets.js +251 -0
  142. package/dist/statShapes.d.ts +96 -0
  143. package/dist/statShapes.js +112 -0
  144. package/dist/status.d.ts +103 -0
  145. package/dist/status.js +125 -0
  146. package/dist/storage.d.ts +145 -0
  147. package/dist/storage.js +33 -0
  148. package/dist/storyTime.d.ts +308 -0
  149. package/dist/storyTime.js +560 -0
  150. package/dist/surfaces.d.ts +501 -0
  151. package/dist/surfaces.js +292 -0
  152. package/dist/template.d.ts +312 -0
  153. package/dist/template.js +554 -0
  154. package/dist/templateCheck.d.ts +60 -0
  155. package/dist/templateCheck.js +516 -0
  156. package/dist/templateFit.d.ts +157 -0
  157. package/dist/templateFit.js +349 -0
  158. package/dist/templateIds.d.ts +138 -0
  159. package/dist/templateIds.js +144 -0
  160. package/dist/templateScopeAt.d.ts +131 -0
  161. package/dist/templateScopeAt.js +354 -0
  162. package/dist/testing.d.ts +177 -0
  163. package/dist/testing.js +383 -0
  164. package/dist/tokenizers.d.ts +113 -0
  165. package/dist/tokenizers.js +184 -0
  166. package/dist/turnLock.d.ts +96 -0
  167. package/dist/turnLock.js +79 -0
  168. package/dist/turnOrder.d.ts +143 -0
  169. package/dist/turnOrder.js +128 -0
  170. package/dist/validate.d.ts +74 -0
  171. package/dist/validate.js +1399 -0
  172. package/dist/values.d.ts +212 -0
  173. package/dist/values.js +390 -0
  174. package/dist/variables.d.ts +493 -0
  175. package/dist/variables.js +662 -0
  176. package/dist/verdicts.d.ts +275 -0
  177. package/dist/verdicts.js +348 -0
  178. package/dist/widgetDecls.d.ts +88 -0
  179. package/dist/widgetDecls.js +119 -0
  180. package/dist/widgets.d.ts +1527 -0
  181. package/dist/widgets.js +208 -0
  182. package/dist/wire.d.ts +126 -0
  183. package/dist/wire.js +140 -0
  184. package/dist/worldinfo.d.ts +150 -0
  185. package/dist/worldinfo.js +212 -0
  186. package/host-elements.d.ts +914 -0
  187. package/package.json +67 -0
@@ -0,0 +1,326 @@
1
+ /**
2
+ * Script **types** — the fourth paradigm's contracts (18 §1–§3).
3
+ *
4
+ * A script is user-authored, typed text that transforms data at a declared
5
+ * point in a run: no SDK, no manifest, no build step. This module declares the
6
+ * *contracts* those texts conform to, not the texts themselves. The split is
7
+ * the same one prompts and prompt slots already have, and 18 §2 states it
8
+ * plainly: few types, declared by core and extensions and versioned by a
9
+ * content hash; many scripts, authored by users and stored as rows.
10
+ *
11
+ * Structured like the other declared-thing registries beside it — `engines.ts`,
12
+ * `variables.ts` — so a plugin reading the registry sees core's declarations on
13
+ * the same terms as its own, and `snapshotRegistry` projects these into the
14
+ * type registry with `kind: 'script'` under the same sync, conflict-refusal and
15
+ * re-projection rules as node types.
16
+ *
17
+ * ## Why the id grows a segment
18
+ *
19
+ * `<namespace>:script:<content>/<operation>@<major>`
20
+ *
21
+ * The content segment is structural, not decorative: hook matching, chain
22
+ * homogeneity, panel grouping and import validation all read it, which is why
23
+ * it earns a delimiter rather than a hyphen convention. `text/stop` is
24
+ * filterable; `text-stop` is a naming habit (18 §1).
25
+ *
26
+ * ⚠ This is the **one** compound kind, and the extension stops here. Node kinds
27
+ * are already segmented by kind and never grow qualifiers; scripts are
28
+ * segmented by payload because that is what decides which chain a link may join
29
+ * and which hook may accept it. Generalizing the grammar further is a non-goal.
30
+ *
31
+ * ⚠ The grammar is hard-frozen once the SDK publishes (07 §0g). Scripts are
32
+ * unshipped, so this is the free moment to extend it additively.
33
+ */
34
+ import { i18nFindings } from './i18n.js';
35
+ import { refuseUnlessIdentical } from './hash.js';
36
+ const SCRIPT_ID = /^([a-z0-9][a-z0-9.-]*):script:([a-z0-9][a-z0-9-]*)\/([a-z0-9][a-z0-9-]*)@(\d+)$/;
37
+ /** Is this a script id at all? Cheap enough to call in a filter. @experimental */
38
+ export const isScriptKindId = (id) => SCRIPT_ID.test(id);
39
+ /**
40
+ * Parse, or throw with the grammar spelled out.
41
+ *
42
+ * Throwing beats returning null here for the reason 12 §2a gives about template
43
+ * engines: a caller that gets `undefined` from a malformed id writes a fallback,
44
+ * and a fallback that half-works is how a script ends up attached to a hook
45
+ * nobody meant. An id is either well-formed or it is a bug in the thing that
46
+ * produced it.
47
+ * @internal
48
+ */
49
+ export function parseScriptKindId(id) {
50
+ const m = SCRIPT_ID.exec(id);
51
+ if (!m)
52
+ throw new Error(`'${id}' is not a valid script type id. The grammar is ` +
53
+ `'<namespace>:script:<content>/<operation>@<major>' — ` +
54
+ `'core:script:text/stop@1', 'stats:script:data/check@1'. Lowercase, digits ` +
55
+ `and hyphens in each segment; dots additionally allowed in the namespace. ` +
56
+ `The content segment is structural: hook matching, chain homogeneity and ` +
57
+ `panel grouping all read it, which is why it is a segment and not a naming ` +
58
+ `habit inside the name (18 §1).`);
59
+ return {
60
+ namespace: m[1],
61
+ content: m[2],
62
+ operation: m[3],
63
+ version: Number(m[4]),
64
+ space: `${m[2]}/${m[3]}`,
65
+ };
66
+ }
67
+ /**
68
+ * `content/operation` — what every link in one chain must share (18 §5).
69
+ *
70
+ * Checkable off the id, which is the point of putting content in the grammar: a
71
+ * `candidates` script dropped into a `text/transform` chain refuses at attach
72
+ * rather than at run time, and neither the registry nor the script body has to
73
+ * be consulted to know it.
74
+ * @experimental
75
+ */
76
+ export const scriptSpace = (id) => parseScriptKindId(id).space;
77
+ const scriptTypes = new Map();
78
+ /**
79
+ * Register a script type.
80
+ *
81
+ * The same two refusals as every other registry here — an id has exactly one
82
+ * owner, and the grammar is checked at the door rather than trusted. The second
83
+ * matters more for scripts than elsewhere: these ids are matched by *segment*,
84
+ * so a malformed one does not fail loudly, it quietly belongs to no chain and
85
+ * no hook.
86
+ * @experimental
87
+ */
88
+ export function defineScriptKind(decl) {
89
+ parseScriptKindId(decl.id);
90
+ // The display text (R-20): the name and description a panel lists it by,
91
+ // and the blast-radius badge — required, because a chain a person cannot
92
+ // read the consequences of is a permission nobody can grant knowingly.
93
+ const findings = [
94
+ ...i18nFindings(decl.i18n?.name, `${decl.id} i18n.name`),
95
+ ...i18nFindings(decl.i18n?.description, `${decl.id} i18n.description`),
96
+ ...i18nFindings(decl.blastRadius, `${decl.id} blastRadius`, { required: true }),
97
+ ];
98
+ if (findings.length)
99
+ throw new Error(`${decl.id} declares display text a publish refuses (R-20):\n · ${findings.join('\n · ')}`);
100
+ const existing = scriptTypes.get(decl.id);
101
+ if (existing)
102
+ refuseUnlessIdentical(existing, decl, `duplicate script type id: ${decl.id}`, {
103
+ // `blastRadius` is a badge, and this is where the docblock on
104
+ // `ScriptKindDecl` becomes true rather than aspirational: it sits beside
105
+ // `i18n` instead of inside it because it is required on every type and
106
+ // `i18n` is not, so the generic strip never saw it and re-wording a
107
+ // warning threw. `semantics` is the same shape of word and is *not*
108
+ // listed — it is contract, and only this file knows the difference.
109
+ display: ['blastRadius'],
110
+ });
111
+ scriptTypes.set(decl.id, decl);
112
+ return decl;
113
+ }
114
+ /**
115
+ * The plugin-facing door. Same registration, minus the ability to claim core's
116
+ * namespace — checked here rather than in `defineScriptKind` so core's own
117
+ * declarations do not have to argue past their own guard.
118
+ * @experimental
119
+ */
120
+ export function definePluginScriptKind(pluginId, decl) {
121
+ if (decl.id.startsWith('core:'))
122
+ throw new Error(`plugin '${pluginId}' may not declare '${decl.id}': the 'core:' namespace is ` +
123
+ `reserved. Publish it under your own namespace — a script type two parties ` +
124
+ `can define is one where the same chain means different things depending on ` +
125
+ `load order.`);
126
+ return defineScriptKind(decl);
127
+ }
128
+ /** @internal */
129
+ export const getScriptKind = (id) => scriptTypes.get(id);
130
+ /** @experimental */
131
+ export const allScriptKinds = () => [...scriptTypes.values()];
132
+ /** @internal */
133
+ export function _clearScriptKinds() {
134
+ scriptTypes.clear();
135
+ }
136
+ // ── Core's catalog, v1 (18 §3) ──────────────────────────────────────────────
137
+ //
138
+ // Nine types across six content scopes. The scopes map onto the existing
139
+ // shape vocabulary rather than inventing a second taxonomy of what data is —
140
+ // which is also what lets an extension add `image` or `audio` alongside its own
141
+ // types and get a modality-agnostic tier for free.
142
+ const TEXT = 'core:shape/text@1';
143
+ const CANDIDATES = 'core:shape/context-candidates@1';
144
+ const JSON_SHAPE = 'core:shape/json@1';
145
+ /** @experimental */
146
+ export const textTransform = defineScriptKind({
147
+ id: 'core:script:text/transform@1',
148
+ i18n: {
149
+ name: { en: 'Transform text' },
150
+ description: {
151
+ en: 'Rewrite a piece of text — strip a phrase, fix spacing, replace a name.',
152
+ },
153
+ },
154
+ blastRadius: { en: 'Rewrites content' },
155
+ semantics: 'transform',
156
+ ports: { in: { text: TEXT }, out: { text: TEXT } },
157
+ });
158
+ /**
159
+ * ⚠ A verdict, not a transform, and the difference is load-bearing.
160
+ *
161
+ * A stop script never rewrites the stream — it answers "where, in the text you
162
+ * have been shown, should this end?" That makes the answer a **min-reduction**:
163
+ * every attached script evaluates independently and the earliest index wins.
164
+ * Order-free and commutative, which is exactly what makes merging the
165
+ * connection's chain with the pipeline's and the chat's well-defined without a
166
+ * precedence rule nobody would remember (18 §5).
167
+ *
168
+ * It is also the one type with a conformance law attached (S1): the verdict is
169
+ * a function of the accumulated text only, never of chunk boundaries, or a
170
+ * reply replays differently than it streamed.
171
+ * @experimental
172
+ */
173
+ export const textStop = defineScriptKind({
174
+ id: 'core:script:text/stop@1',
175
+ i18n: {
176
+ name: { en: 'Stop generation' },
177
+ description: {
178
+ en: 'Decide where a reply should end — a leaked template token, an impersonated speaker.',
179
+ },
180
+ },
181
+ blastRadius: { en: 'Ends generations' },
182
+ semantics: 'verdict',
183
+ ports: { in: { text: TEXT }, out: { stopIndex: JSON_SHAPE } },
184
+ });
185
+ /**
186
+ * Additive only, and split from `messages/transform` on purpose.
187
+ *
188
+ * Same content, different blast radius: injection cannot touch what is already
189
+ * there, so a cautious user can accept injection chains while refusing
190
+ * rewrites. That choice only exists because the two are separate operations —
191
+ * a single `messages/edit` would have made "add a reminder at depth 2" and
192
+ * "delete half the history" the same permission.
193
+ * @experimental
194
+ */
195
+ export const messagesInject = defineScriptKind({
196
+ id: 'core:script:messages/inject@1',
197
+ i18n: {
198
+ name: { en: 'Inject messages' },
199
+ description: {
200
+ en: 'Add messages at a chosen depth — a reminder, a system note, an assistant prefill.',
201
+ },
202
+ },
203
+ blastRadius: { en: 'Additive only — cannot change existing history' },
204
+ semantics: 'transform',
205
+ ports: { in: { context: JSON_SHAPE }, out: { injections: JSON_SHAPE } },
206
+ });
207
+ /** @experimental */
208
+ export const messagesTransform = defineScriptKind({
209
+ id: 'core:script:messages/transform@1',
210
+ i18n: {
211
+ name: { en: 'Transform messages' },
212
+ description: { en: 'Rewrite or drop messages before they reach the model.' },
213
+ },
214
+ blastRadius: { en: 'Can remove or rewrite history' },
215
+ semantics: 'transform',
216
+ ports: { in: { messages: JSON_SHAPE }, out: { messages: JSON_SHAPE } },
217
+ });
218
+ /** @experimental */
219
+ export const candidatesFilter = defineScriptKind({
220
+ id: 'core:script:candidates/filter@1',
221
+ i18n: {
222
+ name: { en: 'Filter candidates' },
223
+ description: { en: 'Drop retrieved entries before ranking, with a reason on each.' },
224
+ },
225
+ blastRadius: { en: 'Excludes lore' },
226
+ semantics: 'transform',
227
+ ports: { in: { candidates: CANDIDATES }, out: { candidates: CANDIDATES } },
228
+ });
229
+ /** @experimental */
230
+ export const candidatesRescore = defineScriptKind({
231
+ id: 'core:script:candidates/rescore@1',
232
+ i18n: {
233
+ name: { en: 'Rescore candidates' },
234
+ description: { en: 'Adjust retrieval scores so the ranker orders entries differently.' },
235
+ },
236
+ blastRadius: { en: 'Reorders ranking' },
237
+ semantics: 'transform',
238
+ ports: { in: { candidates: CANDIDATES }, out: { candidates: CANDIDATES } },
239
+ });
240
+ /** @experimental */
241
+ export const contextTransform = defineScriptKind({
242
+ id: 'core:script:context/transform@1',
243
+ i18n: {
244
+ name: { en: 'Transform context' },
245
+ description: { en: 'Edit the values a prompt template renders — instructions, scenario.' },
246
+ },
247
+ blastRadius: { en: 'Edits instructions' },
248
+ semantics: 'transform',
249
+ ports: { in: { context: JSON_SHAPE }, out: { context: JSON_SHAPE } },
250
+ });
251
+ /**
252
+ * The extracted cast, after the model has answered and the host has parsed.
253
+ *
254
+ * Its own content scope rather than a `context` operation, because chain
255
+ * homogeneity is keyed on content (18 §5) and a cast is not a template
256
+ * context — a chain that could hold both would let a context edit land on a
257
+ * cast list by attachment mistake, silently. The scope is what makes the
258
+ * mistake refusable at attach.
259
+ *
260
+ * The flowing value is what `core:oracle/extract-cast@1` publishes on its
261
+ * `cast` port: `{ participants, mentioned }`. Scripts here rename, merge
262
+ * aliases, drop a junk detection, or add someone the model missed — the
263
+ * paste-rung half of replaceable cast extraction. The other half is the node
264
+ * rebind: a whole different extractor is a same-shaped provider, never a
265
+ * script, because scripts are pure compute and extraction calls a model.
266
+ * @experimental
267
+ */
268
+ export const castTransform = defineScriptKind({
269
+ id: 'core:script:cast/transform@1',
270
+ i18n: {
271
+ name: { en: 'Transform cast' },
272
+ description: {
273
+ en: 'Edit the extracted cast — rename someone, merge aliases, drop a junk detection, add someone the model missed.',
274
+ },
275
+ },
276
+ blastRadius: { en: 'Rewrites who is in the scene' },
277
+ semantics: 'transform',
278
+ ports: { in: { cast: JSON_SHAPE }, out: { cast: JSON_SHAPE } },
279
+ });
280
+ /**
281
+ * Who speaks next, as a script (plans/19 §5, second half; ruled 2026-09-21).
282
+ *
283
+ * The one seam a plugin — or an admin, in the Scripts panel with no plugin at
284
+ * all — has for turn detection of its own. Core's `core:task/turn-scripted@1`
285
+ * declares this kind at its `select` point and hands the chain a
286
+ * **selection**: `{ speaker, candidates, lastSpeaker, sinceUser }` — the pick so
287
+ * far (null until a link decides), every seat a strategy may seat (characters
288
+ * and in-turn envoys, each a participant reference with its position and name),
289
+ * who spoke last, and how many replies have landed since the person last
290
+ * spoke. A link returns the selection with `speaker` set, or nothing to leave
291
+ * the decision to the next link. The host seats only a reference that is in
292
+ * `candidates`; anything else is recorded and ignored, so a script can never
293
+ * seat somebody the cast does not hold.
294
+ *
295
+ * A transform rather than a verdict: the chain's *order* is its precedence —
296
+ * "the mentioned character, else whoever is due" is two links — and a verdict
297
+ * reduction would need a rule for which reference wins that no reduction states
298
+ * naturally. Its own content scope for the reason `cast` has one: chain
299
+ * homogeneity is keyed on content, and a selection is not a cast.
300
+ * @experimental
301
+ */
302
+ export const turnSelect = defineScriptKind({
303
+ id: 'core:script:turn/select@1',
304
+ i18n: {
305
+ name: { en: 'Select the speaker' },
306
+ description: {
307
+ en: 'Decide who takes the next turn — the character who was addressed, the one who has been quiet longest, whoever the scene calls for.',
308
+ },
309
+ },
310
+ blastRadius: { en: 'Decides who speaks' },
311
+ semantics: 'transform',
312
+ ports: { in: { selection: JSON_SHAPE }, out: { selection: JSON_SHAPE } },
313
+ });
314
+ /**
315
+ * Every content scope core ships, in panel order.
316
+ *
317
+ * Derived from the registry rather than restated, so a scope arrives the moment
318
+ * a type using it is declared — including an extension's. A hand-written list
319
+ * is the thing 18 §1 rule 3 warns against: a second taxonomy of what data is,
320
+ * kept in step by hand.
321
+ * @experimental
322
+ */
323
+ export const scriptContentScopes = () => [
324
+ ...new Set(allScriptKinds().map((t) => parseScriptKindId(t.id).content)),
325
+ ];
326
+ //# sourceMappingURL=scripts.js.map
@@ -0,0 +1,339 @@
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 type { WidgetDecl } from './layout.js';
45
+ /** The three zones, in visual order. There is no fourth. @experimental */
46
+ export declare const ZONE_IDS: readonly ['left', 'middle', 'right'];
47
+ /** @experimental */
48
+ export type ZoneId = (typeof ZONE_IDS)[number];
49
+ /** The separator between a widget id and an instance name. @experimental */
50
+ export declare const INSTANCE_NAME_SEPARATOR = "#";
51
+ /** An instance name: short, kebab, lower case (`sanctum`, `2`). @experimental */
52
+ export declare const INSTANCE_NAME: RegExp;
53
+ /** The widget a placed id is a copy of: the id up to its `#`, else the id. @experimental */
54
+ export declare function widgetOfInstance(instanceId: string): string;
55
+ /** The instance name of a copy (`sanctum` of `messages#sanctum`), or `null` for the widget itself. @experimental */
56
+ export declare function instanceNameOf(instanceId: string): string | null;
57
+ /** Is this placed id a copy of `widgetId` — the widget itself or one of its instances? @experimental */
58
+ export declare function isInstanceOf(instanceId: string, widgetId: string): boolean;
59
+ /**
60
+ * Is this string a widget instance id a layout may place? The widget half is
61
+ * core's grammar (`world-state`) or a plugin's namespaced one
62
+ * (`acme.maps:map`, `parsePluginWidgetId`); the instance name, when there is
63
+ * one, is {@link INSTANCE_NAME}.
64
+ * @experimental
65
+ */
66
+ export declare function isWidgetInstanceId(id: unknown): id is string;
67
+ /**
68
+ * Widget ids that name nothing any build places. A saved layout, a preset or
69
+ * an arrangement may still carry one — all three are stored verbatim and
70
+ * nothing rewrites them — so every reader drops it.
71
+ *
72
+ * `composer` is one because the conversation is ONE widget: the log and the
73
+ * field are one thing to arrange, and the field's shape is a setting on
74
+ * `messages` rather than a widget beside it.
75
+ *
76
+ * `inventory` is one because R79 (2026-09-25) removed core's Inventory widget
77
+ * for now, with no replacement. Adventure and Lair shipped it, so layouts and
78
+ * presets saved from them name it; dropping it here is what makes such a
79
+ * layout open on the widgets it still has — nothing drawn in its place, no
80
+ * labelled placeholder. What somebody carries is the `inventory` stat, which
81
+ * the stats widget draws as a list. Take it off this list if the widget comes
82
+ * back.
83
+ * @experimental
84
+ */
85
+ export declare const RETIRED_WIDGET_IDS: ReadonlySet<string>;
86
+ /**
87
+ * One width rule of a side zone's ladder. `min` is the session box's inline
88
+ * size (px) at or above which the rule applies; rules merge ascending, each
89
+ * stating only what changes.
90
+ * @experimental
91
+ */
92
+ export interface LayoutZoneRule {
93
+ min: number;
94
+ /** A side: `drawer` · `rail` · `icons` · `hidden`. A strip: `row` · `hidden`. */
95
+ mode?: 'drawer' | 'rail' | 'icons' | 'hidden' | 'row';
96
+ /** The rail's or drawer's inline size, px. */
97
+ width?: number;
98
+ /** Rail stack columns (a wide screen turns a rail into a grid). */
99
+ columns?: number;
100
+ }
101
+ /**
102
+ * One zone of `zoneLayout`: a side column (or a strip) and the widgets it
103
+ * lists, in order.
104
+ *
105
+ * Where the page draws it is `side` (a side zone) or `area` (a strip) — never
106
+ * its key — and a zone that does not say it is a strip is a side.
107
+ * @experimental
108
+ */
109
+ export interface LayoutZoneDef {
110
+ kind: 'side' | 'strip';
111
+ /** A side zone's edge. Absent is the right: state it. */
112
+ side?: 'left' | 'right';
113
+ /** A strip: above or below the conversation. Absent is the top: state it. */
114
+ area?: 'top' | 'bottom';
115
+ /** The editor's label; the zone's key when absent. */
116
+ label?: string;
117
+ /** A docked column when absent or `true`; an icon strip when `false`. */
118
+ pinned?: boolean;
119
+ /** Widget instance ids, in order. */
120
+ widgets: string[];
121
+ /** The width ladder. Absent means the app's default for the side. */
122
+ rules?: LayoutZoneRule[];
123
+ }
124
+ /**
125
+ * The `zoneLayout` slot. A zone is keyed by where the page draws it: a side
126
+ * zone by its `side` (`left`, `right`), a strip by its `area` (`top`,
127
+ * `bottom`) — so one layout has at most one of each, and the key and the
128
+ * field never disagree (`validateSessionLayout` refuses a layout where they
129
+ * do). The middle has no zone here: its membership is the widget grid's. The
130
+ * type is a string record because a stored blob is read as it was written.
131
+ * @experimental
132
+ */
133
+ export interface ZoneLayoutV1 {
134
+ version: 1;
135
+ zones: Record<string, LayoutZoneDef>;
136
+ /** The message pack by name (`novel`), the id-free way to pick one. */
137
+ styles?: {
138
+ chat?: string;
139
+ };
140
+ }
141
+ /**
142
+ * How a grid widget sizes on one axis: `grow` fills what is left (a `1fr`
143
+ * track), `fixed` is content-sized (`auto`), or a number of cells.
144
+ * @experimental
145
+ */
146
+ export type GridSizeSpec = 'grow' | 'fixed' | {
147
+ minCells?: number;
148
+ maxCells?: number;
149
+ cells?: number;
150
+ };
151
+ /**
152
+ * The edges of its space a widget sticks to as the grid reflows. ⚠ Not a lore
153
+ * entry's **anchor** (the reference that governs its visibility).
154
+ * @experimental
155
+ */
156
+ export interface WidgetAnchor {
157
+ top?: boolean;
158
+ bottom?: boolean;
159
+ left?: boolean;
160
+ right?: boolean;
161
+ }
162
+ /** One widget in the widget grid. @experimental */
163
+ export interface GridWidget {
164
+ /** A widget instance id. */
165
+ id: string;
166
+ zone: ZoneId;
167
+ /** Its place in the zone's stack, top to bottom. */
168
+ order: number;
169
+ /** Cells wide; absent spans the zone. */
170
+ colSpan?: number;
171
+ size: {
172
+ w: GridSizeSpec;
173
+ h: GridSizeSpec;
174
+ };
175
+ anchor: WidgetAnchor;
176
+ /** Stays visible when the drawer is closed. */
177
+ pinned?: boolean;
178
+ /** Only meaningful when pinned: the card background toggle. */
179
+ background?: boolean;
180
+ /** Tab-group membership. */
181
+ group?: string;
182
+ }
183
+ /** The `widgetGrid` slot. @experimental */
184
+ export interface WidgetGridV1 {
185
+ version: 1;
186
+ /** The cell module, px. */
187
+ cell: number;
188
+ widgets: GridWidget[];
189
+ }
190
+ /**
191
+ * One widget's cell box in an arranged zone: 0-based origin and span, in whole
192
+ * cells of that zone's grid.
193
+ * @experimental
194
+ */
195
+ export interface ArrangedItem {
196
+ /** A widget instance id. */
197
+ id: string;
198
+ x: number;
199
+ y: number;
200
+ w: number;
201
+ h: number;
202
+ anchor?: WidgetAnchor;
203
+ /** Tab-group membership: items sharing one draw as one tab set (`g:` + the sorted members). */
204
+ group?: string;
205
+ /** Docked in a side column. ABSENT MEANS PINNED; `false` is the only value written. */
206
+ pinned?: boolean;
207
+ }
208
+ /** One zone's arrangement: its cell grid and the items on it. @experimental */
209
+ export interface ArrangedZone {
210
+ cols: number;
211
+ rows: number;
212
+ items: ArrangedItem[];
213
+ }
214
+ /** The `arrangedGrid` slot: one arrangement per zone that has one. @experimental */
215
+ export type ArrangedGridV1 = Partial<Record<ZoneId, ArrangedZone>>;
216
+ /**
217
+ * A **style pin** a layout carries: the widget style it draws with. A person's
218
+ * saved layout carries `{ id, slug }` from their pins; a shipped one can know
219
+ * only the slug, because a row id belongs to one install.
220
+ * @experimental
221
+ */
222
+ export interface WidgetStylePin {
223
+ slug: string;
224
+ id?: number;
225
+ }
226
+ /**
227
+ * The **session layout**. Every slot is optional: a layout says what it
228
+ * arranges and nothing else.
229
+ * @experimental
230
+ */
231
+ export interface SessionLayoutV1 {
232
+ zoneLayout?: ZoneLayoutV1;
233
+ widgetGrid?: WidgetGridV1;
234
+ arrangedGrid?: ArrangedGridV1;
235
+ /** Per-instance widget settings, keyed by widget instance id. */
236
+ widgetSettings?: Record<string, Record<string, unknown>>;
237
+ /** Style pins, keyed by widget instance id. */
238
+ widgetStyles?: Record<string, WidgetStylePin>;
239
+ }
240
+ /**
241
+ * Every widget instance id the layout NAMES — the zone lists, the grid and the
242
+ * arrangement — each once, in that order. What a check reads when the question
243
+ * is "does this layout mention it at all" (a genre's omitted widgets).
244
+ * @experimental
245
+ */
246
+ export declare function layoutWidgetIds(layout: SessionLayoutV1): string[];
247
+ /**
248
+ * The widget instance ids the MIDDLE names: the grid's middle entries, then
249
+ * the arranged middle's items, each once.
250
+ * @experimental
251
+ */
252
+ export declare function middleWidgetIds(layout: SessionLayoutV1): string[];
253
+ /**
254
+ * Every widget instance id the layout DRAWS, in reading order — middle, left,
255
+ * right, then any strips — which is the page's own precedence, place by place:
256
+ *
257
+ * - the middle draws its arrangement whenever it has one (an emptied middle
258
+ * stays empty), else the grid's middle entries;
259
+ * - a side draws its arrangement when that places anything, else the lists
260
+ * of the zones on it (by their `side`, never their key) — and, folded into
261
+ * them, any grid entry naming that side, but only when the layout has a
262
+ * zone on that side to fold it into;
263
+ * - a strip draws its list.
264
+ *
265
+ * So an entry an arrangement shadows is named but not drawn. A retired widget
266
+ * id is never drawn.
267
+ * @experimental
268
+ */
269
+ export declare function drawnWidgetIds(layout: SessionLayoutV1): string[];
270
+ /**
271
+ * Does the layout DRAW any instance of `primaryId` — the bare id or a
272
+ * `#name` copy — anywhere? The **primary floor**'s question: placement is
273
+ * free, and the one rule left is that a layout draws its genre's primary
274
+ * widget somewhere.
275
+ * @experimental
276
+ */
277
+ export declare function primaryPlaced(layout: SessionLayoutV1, primaryId: string): boolean;
278
+ /** @experimental */
279
+ export interface SessionLayoutValidation {
280
+ ok: boolean;
281
+ /** What makes the layout unusable as shipped. Any error refuses it. */
282
+ errors: string[];
283
+ /** What draws, but not as declared: an unknown widget draws a placeholder. */
284
+ warnings: string[];
285
+ }
286
+ /** What {@link validateSessionLayout} checks ids against. @experimental */
287
+ export interface SessionLayoutValidationOptions {
288
+ /**
289
+ * Widget declarations, under the ids the layout names them by (core's
290
+ * bare, a plugin's namespaced — or, in a package's own declaration, the
291
+ * package's bare). A widget listed here and placed more often than its
292
+ * `maxInstances` is a warning.
293
+ */
294
+ widgets?: readonly Pick<WidgetDecl, 'id' | 'maxInstances'>[];
295
+ /**
296
+ * `'warn'` when `widgets` is every widget the caller knows — an
297
+ * instance's check, core's and every enabled package's — so a widget
298
+ * outside it is warned about too: it draws a labelled placeholder. A
299
+ * packager knows its own widgets and not the rest, and leaves this at
300
+ * `'ignore'` (the default).
301
+ */
302
+ unknownWidgets?: 'warn' | 'ignore';
303
+ }
304
+ /**
305
+ * Check a layout a package ships — the rules its type cannot express. Pure;
306
+ * the verdict lists every problem rather than the first.
307
+ *
308
+ * **Errors** (the layout is refused):
309
+ * - a slot of the wrong shape: `zoneLayout` and `widgetGrid` are `version: 1`;
310
+ * a grid entry and an arrangement name a zone, `left`, `middle` or
311
+ * `right`; a `zoneLayout` zone is keyed by where the page draws it — a
312
+ * side by its `side` (`left`, `right`), a strip by its `area` (`top`,
313
+ * `bottom`);
314
+ * - a placed id that is not a widget instance id (`<widget id>` or
315
+ * `<widget id>#<instance name>`);
316
+ * - an arranged cell that is not whole cells inside its zone's `cols` × `rows`;
317
+ * - an id placed twice: a widget instance lives in ONE zone, listed once. The
318
+ * three slots may each name it there — a side lists it, its arrangement
319
+ * gives it cells — but never in two zones (a zone as the page draws it),
320
+ * and never twice in one list;
321
+ * - a `widgetSettings` value that is not an object, a `widgetStyles` pin with
322
+ * no slug;
323
+ * - the retired layout document (LayoutDoc v2), bare or in its preset
324
+ * wrapper — refused by name, never read as a layout that places nothing.
325
+ *
326
+ * **Warnings** (the layout draws, not as written):
327
+ * - a key that is not a slot (readers ignore it) and a retired widget;
328
+ * - an id placed but never drawn ({@link drawnWidgetIds}): its zone's
329
+ * arrangement draws over it, or the grid puts it in a side the layout has
330
+ * no zone for;
331
+ * - two arranged items sharing a cell (one draws over the other);
332
+ * - with `opts.widgets`, more instances of a widget than its
333
+ * `maxInstances` (readers draw the first ones in reading order);
334
+ * - with `opts.unknownWidgets: 'warn'` too, a widget `opts.widgets` does not
335
+ * hold (it draws a labelled placeholder).
336
+ * @experimental
337
+ */
338
+ export declare function validateSessionLayout(layout: unknown, opts?: SessionLayoutValidationOptions): SessionLayoutValidation;
339
+ //# sourceMappingURL=sessionLayout.d.ts.map