@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
package/dist/media.js ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * The media vocabulary — one discriminated kind, not a family of sibling shapes.
3
+ *
4
+ * ## Why a discriminator rather than separate shapes per modality
5
+ *
6
+ * The tempting design is `S.image`, `S.audio`, `S.video`, `S.document` as
7
+ * peers, each with its own ports. It does not survive contact with the way
8
+ * models are actually going: every new modality would be a new shape, new ports
9
+ * on every provider that touches media, and a new branch in every wire adapter
10
+ * — the combinatorial growth this SDK avoids everywhere else by declaring data
11
+ * rather than switching on it. The contracts file opens by noting that the LLM,
12
+ * TTS and image-gen providers are structurally identical precisely *because*
13
+ * nothing switches on modality (17 §1); sibling media shapes would undo that.
14
+ *
15
+ * ## Why not simply "file", either
16
+ *
17
+ * Full generalisation loses the one thing the type system is actually needed
18
+ * for: **capability negotiation**. "This model takes images but not PDFs" is a
19
+ * real and common constraint, and it is the check that turns a failed API call
20
+ * into a disabled button. A bare `file` shape cannot express it.
21
+ *
22
+ * So: **one shape, a declared kind, and capability sets that enumerate kinds.**
23
+ * Ports stay general (no explosion), while what a connection or node will
24
+ * accept stays specific (a real check). This is the same split the app's own
25
+ * `files` table already makes — a coarse `kind` derived from the mime and
26
+ * stored, so "every document" is an index scan rather than a string parse.
27
+ */
28
+ /**
29
+ * The coarse classification, matching the app's `files.kind` exactly so a blob
30
+ * does not change category on its way through a pipeline.
31
+ *
32
+ * Declared as a const array rather than a bare union so it is introspectable:
33
+ * a settings control that offers "which kinds does this accept" enumerates
34
+ * this instead of hardcoding a list that drifts.
35
+ * @experimental
36
+ */
37
+ export const MEDIA_KINDS = ['image', 'audio', 'video', 'document'];
38
+ /** @experimental */
39
+ export const isMediaKind = (v) => typeof v === 'string' && MEDIA_KINDS.includes(v);
40
+ /** Does `cap` accept this reference? The check a picker and a wire adapter
41
+ * both need, written once so they cannot disagree.
42
+ * @experimental
43
+ */
44
+ export function accepts(cap, ref) {
45
+ if (!cap?.accepts?.length)
46
+ return false;
47
+ if (!cap.accepts.includes(ref.kind))
48
+ return false;
49
+ if (cap.mimes?.length && !cap.mimes.includes(ref.mime))
50
+ return false;
51
+ return true;
52
+ }
53
+ /** Everything in a part list that is prose, concatenated — the degrade path
54
+ * for a consumer that only understands text. Reasoning is deliberately
55
+ * excluded: it is not the answer.
56
+ * @experimental
57
+ */
58
+ export function partsToText(parts) {
59
+ return parts
60
+ .filter((p) => p.t === 'text')
61
+ .map((p) => p.text)
62
+ .join('');
63
+ }
64
+ /** Every media reference in a part list, in order. @experimental */
65
+ export function partsToMedia(parts) {
66
+ return parts
67
+ .filter((p) => p.t === 'media')
68
+ .map((p) => p.ref);
69
+ }
70
+ //# sourceMappingURL=media.js.map
@@ -0,0 +1,487 @@
1
+ /**
2
+ * Message blocks (20 §6) — custom message content as **data, not code**.
3
+ *
4
+ * A plugin's message part carries a block tree in `data.blocks`; core renders
5
+ * it with its own components. Nothing to sanitize (no HTML crosses the
6
+ * boundary), theming and accessibility are core's once for everyone, and
7
+ * interactivity is *declared*: a `choices` button or a `form` submit names a
8
+ * function key, and pressing it fires the trigger machinery with the message
9
+ * as subject — the same audited path every contributed button already takes.
10
+ *
11
+ * The validator is the write-time gate: a hostile or malformed tree is refused
12
+ * with the block path named, and the caps make "render whatever a sandboxed
13
+ * hook produced" a bounded promise. Findings carry a `fix` like every finding
14
+ * in this SDK (15 §1.3).
15
+ */
16
+ import type { SettingsSchema } from './settings.js';
17
+ import { type EffectsLineDeclarationInput } from './actions.js';
18
+ import { type ParticipantRef } from './participants.js';
19
+ /**
20
+ * What a `choices` button or a `form` submit fires (U5c review, W-E).
21
+ *
22
+ * `fn` is the action's **key** — the second half of its identity, the word
23
+ * a spec's own block names one of its actions by (plans/31 V2; it was the
24
+ * routing *function* until then, and the key of every action core ships was
25
+ * already that word). `action` is the
26
+ * **identity** of the declaration the press is held to, `<spec slug>#<key>`
27
+ * (`ACTION_IDENTITY`): the server checks THAT action's audience and
28
+ * enablement and runs THAT spec, so a block a spec wrote for any
29
+ * participant (`act: ['participant']`) admits a guest. It is **written by
30
+ * the outlet that created the block** from the run's spec
31
+ * (`stampBlockActions`), never by the client, which only carries it back on
32
+ * the fire. A block carrying none — one stored before this field, or one
33
+ * whose spec declares no action for `fn` — is fired as the legacy shape and
34
+ * gets the narrowest reading: the owner floor.
35
+ * @experimental
36
+ */
37
+ export interface BlockActionRef {
38
+ fn: string;
39
+ action?: string;
40
+ }
41
+ /**
42
+ * A **form** (plans/29 R-15 *Forms*; 30 §U5d, built 2026-09-17) is an
43
+ * action still awaiting its answer, addressed to an audience and carried in
44
+ * a message: a `choices` block (one question, several options) or a `form`
45
+ * block (fields to fill). The two fields below are what make a block a form
46
+ * rather than a row of buttons:
47
+ *
48
+ * - **`addressee`** — who the question is put to, as a participant
49
+ * reference (`character:12`, `envoy:mascot`, `owner`, `user:3`). The
50
+ * addressee IS the block's audience: the person portraying them may
51
+ * answer (the click), and when the host's resolver says the AI portrays
52
+ * them this turn, core records `core:event/form-addressed@1` and the
53
+ * genre's answer pipeline answers through an oracle with the `json`
54
+ * capability — receipted, reviewable, never magical. A block with no
55
+ * addressee is what it always was: buttons anyone the action's audience
56
+ * admits may press.
57
+ * - **`id`** — the block's identity within its message, stamped by the
58
+ * host at the write (`assignBlockIds`) so a fire, a `form-addressed`
59
+ * event and a `form-answered` change can all name it. Never written by a
60
+ * spec; one it wrote is kept.
61
+ * - **`head`** — the **channel head** the form was issued at (plans/29
62
+ * R-15 *Staleness and order*; 30 §U5f, 2026-09-17): the greatest message
63
+ * id on the row's channel at the write, stamped by the host
64
+ * (`assignBlockHead`) — for a fresh write, the row itself. The head
65
+ * moving past it **stales** the form: unanswered, and a newer message
66
+ * on that channel exists — one that is not itself an answer to a form on
67
+ * the same row (the host marks an answer's row `metadata.answersForm`,
68
+ * and an answer does not move the conversation on from the row it
69
+ * answers, so several questions on one row are each answerable).
70
+ * Staleness is computed, never stored; a stale press is refused at the
71
+ * door and a client collapses the block as *superseded*. Never written
72
+ * by a spec; one it wrote is dropped and the host's stamp put in its
73
+ * place. A block with no `head` — one stored before the field — is never
74
+ * stale.
75
+ *
76
+ * A `choices` option carries **`choice`**, the option key its press answers
77
+ * with (`{ choice }` is the fire's payload, and the oracle's schema is an
78
+ * enum of these keys). Options of an addressed block must each carry one,
79
+ * distinct — a question with options must be answerable by key.
80
+ * @experimental
81
+ */
82
+ export interface FormBlockFields {
83
+ id?: string;
84
+ /**
85
+ * The channel head at issue (U5f) — a positive message id, the host's
86
+ * stamp. See the module note: staleness is `!answered && head != null &&
87
+ * headNow > head`, computed by whoever holds the channel.
88
+ */
89
+ head?: number;
90
+ addressee?: ParticipantRef;
91
+ /**
92
+ * The question put to the addressee, as prose — what the block shows
93
+ * above its options or fields, and what the answer pipeline puts to the
94
+ * oracle. A `choices` block with no question is a row of buttons and
95
+ * cannot be addressed: there is nothing to answer.
96
+ */
97
+ question?: string;
98
+ /**
99
+ * What the question is **about**, by name — the thing an answer acts on,
100
+ * carried from the run that asked to the run the press fires (lair pass
101
+ * B12, 2026-09-27). The Lair's knock asks *is there a room here?*; the
102
+ * room is its `referent`, and *Answer the door* reads it off the form
103
+ * (`read-answer@1`'s `referent`) to name the room it writes. Plain text,
104
+ * never an id: it is shown to nobody and trusted for nothing — a press
105
+ * still re-judges everything it touches. Absent on a question about
106
+ * nothing in particular, which is most of them.
107
+ *
108
+ * Neither the question (prose a person reads) nor an option's `choice`
109
+ * (a key a junction compares): those two could not carry a name without
110
+ * breaking what they are for.
111
+ */
112
+ referent?: string;
113
+ /**
114
+ * Where the question was asked **from**, by name — carried beside
115
+ * `referent` from the run that asked to the run the press fires (plan
116
+ * A27, 2026-09-30). The Lair's knock stamps the room its planner said the
117
+ * party stood in, and *Answer the door* links the new room to it when the
118
+ * world's `location` names nowhere. Plain text, shown to nobody and
119
+ * trusted for nothing, like `referent`; absent on most questions.
120
+ */
121
+ vantage?: string;
122
+ /**
123
+ * The answer, once given (U5d review, W7) — stamped on the stored block
124
+ * by the host when the action's run landed, never written by a spec. A
125
+ * form is answered **once**: a second press is refused naming who
126
+ * answered, and a client greys the block and shows the answer.
127
+ */
128
+ answered?: FormAnswered;
129
+ }
130
+ /**
131
+ * Who answered a form, when, and — for a `choices` block — which option.
132
+ * `by` is the addressee when the block was addressed (a person clicking for
133
+ * them and the oracle answering as them are both the addressee's answer),
134
+ * else the user who pressed. `at` is ISO 8601.
135
+ * @experimental
136
+ */
137
+ export interface FormAnswered {
138
+ by: ParticipantRef;
139
+ at: string;
140
+ choice?: string;
141
+ }
142
+ /** @experimental */
143
+ export type MessageBlock =
144
+ /** Markdown text — the workhorse. */
145
+ {
146
+ kind: 'md';
147
+ text: string;
148
+ }
149
+ /** Label/value rows — stats panels, item cards. */
150
+ | {
151
+ kind: 'kv';
152
+ rows: Array<{
153
+ label: string;
154
+ value: string;
155
+ }>;
156
+ }
157
+ /** A small table. Rendering may scroll it; it never overflows the log. */
158
+ | {
159
+ kind: 'table';
160
+ columns: string[];
161
+ rows: string[][];
162
+ }
163
+ /** A labelled meter — HP bars, progress, clocks. */
164
+ | {
165
+ kind: 'stat';
166
+ label: string;
167
+ value: number;
168
+ max?: number;
169
+ }
170
+ /** An attachment from the session's asset store — never a foreign URL. */
171
+ | {
172
+ kind: 'image';
173
+ assetId: number;
174
+ alt?: string;
175
+ }
176
+ /**
177
+ * Action buttons. `fn` is an action key, resolved to its identity by
178
+ * the writing spec's declarations (`stampBlockActions`); pressing one fires
179
+ * `sessions:fireAction` with the message and the choice as subject.
180
+ * `action` is the identity of the declaration the button fires
181
+ * (`BlockActionRef`), stamped by the outlet that wrote the block.
182
+ */
183
+ | ({
184
+ kind: 'choices';
185
+ actions: Array<BlockActionRef & {
186
+ label: string;
187
+ icon?: string;
188
+ choice?: string;
189
+ }>;
190
+ } & FormBlockFields)
191
+ /**
192
+ * A form rendered from the one field language (`SettingsSchema`);
193
+ * submitting fires `fn` with the entered values as the payload.
194
+ */
195
+ | ({
196
+ kind: 'form';
197
+ fields: SettingsSchema;
198
+ label?: string;
199
+ } & BlockActionRef & FormBlockFields)
200
+ /** Nesting, one layout hint. Depth-capped by the validator. */
201
+ | {
202
+ kind: 'group';
203
+ layout?: 'row' | 'column';
204
+ blocks: MessageBlock[];
205
+ };
206
+ /** @experimental */
207
+ export interface MessageBlockFinding {
208
+ /** e.g. `blocks[2].actions[0]` */
209
+ path: string;
210
+ message: string;
211
+ fix: string;
212
+ }
213
+ /** The caps that make rendering a sandbox's output a bounded promise. @experimental */
214
+ export declare const MESSAGE_BLOCK_LIMITS: {
215
+ readonly maxBlocks: 64;
216
+ readonly maxDepth: 3;
217
+ readonly maxText: number;
218
+ readonly maxRows: 64;
219
+ readonly maxActions: 12;
220
+ };
221
+ /** The longest block id the validator accepts; a host's uuid is 36. @experimental */
222
+ export declare const BLOCK_ID_MAX_LENGTH = 64;
223
+ /**
224
+ * Validate a candidate block tree. Empty findings = renderable. Total, never
225
+ * throws — the host refuses a write on findings rather than crashing on one.
226
+ * @internal
227
+ */
228
+ export declare function checkMessageBlocks(value: unknown): MessageBlockFinding[];
229
+ /**
230
+ * Stamp each `choices` button and `form` in a tree with the identity of the
231
+ * declaration it fires — the outlet's half of W-E, called where a block part
232
+ * is written with the run's spec in hand. That is the host's seam, not the
233
+ * SDK's: in Serene Pub the executor's host scope carries the running
234
+ * document's slug (`runtime/host.ts`, `HostScope.specId`) and its message
235
+ * outlet is where the stamp lands; the `blocks` port U5d builds is built on
236
+ * this call. The SDK declares no `HostScope` — a host wired by hand passes
237
+ * `{ id, contributes }` from wherever it keeps the running spec.
238
+ *
239
+ * The identity is `<spec id>#<key>` for the action of `spec` whose `key`
240
+ * is the block's `fn` (plans/31 V2: the key is the identity's second half,
241
+ * so `fn` names at most one). A block whose `fn` the spec declares no
242
+ * action for is left unstamped — it fires as legacy and gets the
243
+ * owner floor — rather than guessed; and a block that already carries an
244
+ * `action` keeps it, so a spec may name a declaration of another spec's on
245
+ * purpose. Returns a copy; the input is never mutated.
246
+ * @internal
247
+ */
248
+ export declare function stampBlockActions(blocks: MessageBlock[], spec: {
249
+ id: string;
250
+ contributes?: unknown;
251
+ }): MessageBlock[];
252
+ /** A well-formed `FormAnswered` — the shape the host stamps and the validator accepts. @experimental */
253
+ export declare function isFormAnswered(v: unknown): v is FormAnswered;
254
+ /** One form in a block tree — a `choices` or `form` block, located. @experimental */
255
+ export type FormBlock = Extract<MessageBlock, {
256
+ kind: 'choices' | 'form';
257
+ }>;
258
+ /**
259
+ * Every `choices` and `form` block in a tree, in render order, groups
260
+ * flattened — the blocks a fire, an event or an answer can name.
261
+ * @internal
262
+ */
263
+ export declare function formBlocksOf(blocks: MessageBlock[]): FormBlock[];
264
+ /** The form block carrying `id`, or undefined. @internal */
265
+ export declare function findFormBlock(blocks: MessageBlock[], id: string): FormBlock | undefined;
266
+ /**
267
+ * Every function a `choices` option or a `form` names, deduplicated — what
268
+ * the writing spec must declare an action for. A block whose `fn` the spec
269
+ * declares no action for is refused at the write: nothing would ever be held
270
+ * to an audience for it.
271
+ * @experimental
272
+ */
273
+ export declare function blockFunctionsOf(blocks: MessageBlock[]): string[];
274
+ /**
275
+ * The functions a tree names that `spec` declares no action for — the
276
+ * refusal the host makes before it stamps (`stampBlockActions` leaves such a
277
+ * block unstamped rather than guessing; the write refuses it instead, with
278
+ * the function named). A reference that already **names its action** — a
279
+ * spec pointing a block at another spec's declaration on purpose, the way
280
+ * the Adventure genre's Ask points its options at Answer — is not judged
281
+ * here: the host holds the named identity to the installed declaration
282
+ * instead (`foreignBlockActions`).
283
+ * @internal
284
+ */
285
+ export declare function undeclaredBlockFunctions(blocks: MessageBlock[], spec: {
286
+ id: string;
287
+ contributes?: unknown;
288
+ }): string[];
289
+ /**
290
+ * The action identities a tree names that are **not** `spec`'s own — the
291
+ * declarations of other specs a block points at on purpose. The host holds
292
+ * each to the installed declaration: it must exist for the session's genre,
293
+ * and it may not be `world` (the effects line).
294
+ * @internal
295
+ */
296
+ export declare function foreignBlockActions(blocks: MessageBlock[], spec: {
297
+ id: string;
298
+ contributes?: unknown;
299
+ }): string[];
300
+ /**
301
+ * **The one addressee a `world` action may be named to** (L1, ruled
302
+ * 2026-09-17): the session's owner, and nobody else.
303
+ *
304
+ * `owner` the role, never `user:<id>` — this half of the law is pure and
305
+ * holds no session, so it cannot know which person owns one; a reference that
306
+ * happens to name the owner is resolved at the press, where the host can ask.
307
+ * @experimental
308
+ */
309
+ export declare const isOwnerAddressed: (addressee: unknown) => boolean;
310
+ /**
311
+ * The effects line (plans/29 R-15 *The line*; 09-B F39): a block naming a
312
+ * `world` action — one whose result touches cards, lorebooks, settings,
313
+ * permissions, connections — is refused. Such an action lives in the
314
+ * composer or the review gate and is owner-only; a message carrying it would
315
+ * put an out-of-fiction effect where a character could be asked to answer
316
+ * it. Returns the functions of the offending actions.
317
+ *
318
+ * ## The one exception: a block addressed to the **owner** (L1, 2026-09-17)
319
+ *
320
+ * A `choices` or `form` block whose `addressee` is `owner` may name a `world`
321
+ * action. The reasoning is the line's own: the rule exists so that an
322
+ * out-of-fiction effect is never *a question a character could be asked*, and
323
+ * a form put to the owner is not that question — the owner is already the
324
+ * whole of such an action's `act` audience (`WORLD_ACTION_ACTORS`), and
325
+ * pressing the button is the owner acting, in the one place the line has
326
+ * always allowed them to. Every other addressee — a character, a persona,
327
+ * a user by id, or none at all (“nobody in particular”, which anyone the
328
+ * audience admits may press) — keeps the refusal.
329
+ *
330
+ * ⚠ The **venue** half of F41 is untouched: an action declaring
331
+ * `venue: { kind: 'form' }` still may not be `world`, because a venue is
332
+ * declared and an addressee is decided at run time, so the construction-time
333
+ * check cannot see one. An owner-addressed block therefore names a
334
+ * `composer`-venue world action — the Lair genre's knock does exactly this
335
+ * — and `form` stays fiction-only.
336
+ * @experimental
337
+ */
338
+ export declare function worldBlockFunctions(blocks: MessageBlock[], spec: {
339
+ id: string;
340
+ contributes?: unknown;
341
+ }): string[];
342
+ /**
343
+ * Every shape the effects line is heard in (F41), one verdict:
344
+ *
345
+ * - `venue` / `actor` — a declaration: a `world` action's declared venue,
346
+ * or a reference its `act` audience names (`worldActionCrossing`).
347
+ * - `block` — the write: the blocks a node produced, against the spec that
348
+ * contributed the actions they name (`worldBlockFunctions`).
349
+ * - `identity` — the write, for a block pointing at ANOTHER spec's
350
+ * declaration on purpose: the host resolved the identity to its
351
+ * `effects` and collected the addressees of every block naming it.
352
+ * - `press` — the fire: a `world` action pressed from a block, or answered
353
+ * **as** a participant by the answer pipeline.
354
+ * @experimental
355
+ */
356
+ export type EffectsLineInput = EffectsLineDeclarationInput | {
357
+ kind: 'block';
358
+ blocks: MessageBlock[];
359
+ spec: {
360
+ id: string;
361
+ contributes?: unknown;
362
+ };
363
+ } | {
364
+ kind: 'identity';
365
+ identity: string;
366
+ effects: unknown;
367
+ addressees: readonly unknown[];
368
+ } | {
369
+ kind: 'press';
370
+ name: string;
371
+ effects: unknown;
372
+ /** The fire is made as a participant — the answer pipeline answering for one. */
373
+ as: boolean;
374
+ /** The press is on a form block (rather than the composer's own button). */
375
+ onBlock: boolean;
376
+ /** Who that block was put to, when it was put to anyone. */
377
+ blockAddressee: unknown;
378
+ };
379
+ /**
380
+ * The effects line (plans/29 R-15 *The line*; F41), as one verdict: an
381
+ * out-of-fiction effect — cards, lore, settings, permissions — is the
382
+ * owner's (or an administrator's), from the composer or the review gate, and
383
+ * never a question a character could be asked. Heard at the declaration
384
+ * (`actionFindingsByLaw`: the builder, `validate()`, the packager, a host's
385
+ * publish), at the write (`worldBlockFunctions`, the host's block gate) and
386
+ * at the fire (the host's `fireAction`). The one exception is L1's: a block
387
+ * addressed to the **owner** may carry it, because the owner is already the
388
+ * whole of such an action's `act` audience and pressing the button is the
389
+ * owner acting. A fire made **as** a participant has no exception — that is
390
+ * the answer pipeline answering for someone, and an oracle granting a
391
+ * permission is the thing the line exists to make impossible.
392
+ * @internal
393
+ */
394
+ export declare const effectsLineVerdict: import("./verdicts.js").VerdictDecl<EffectsLineInput>;
395
+ /**
396
+ * Stamp an `id` on every `choices` and `form` block that has none — the
397
+ * host's half, at the write, with the host's id maker (a uuid). A block that
398
+ * already carries one keeps it. Returns a copy; the input is never mutated.
399
+ * @internal
400
+ */
401
+ export declare function assignBlockIds(blocks: MessageBlock[], makeId: () => string): MessageBlock[];
402
+ /** A channel head as a block carries it: a positive integer message id. @experimental */
403
+ export declare const isChannelHead: (v: unknown) => v is number;
404
+ /**
405
+ * Stamp the **channel head** on every `choices` and `form` block (plans/29
406
+ * R-15 *Staleness and order*; 30 §U5f) — the host's half, at the write,
407
+ * with the head it read off the channel. Unlike `assignBlockIds`, a value
408
+ * the block already carries is **replaced**: the head is a fact about the
409
+ * channel at the write, and only the host holds the channel. Returns a
410
+ * copy; the input is never mutated.
411
+ * @internal
412
+ */
413
+ export declare function assignBlockHead(blocks: MessageBlock[], head: number): MessageBlock[];
414
+ /**
415
+ * Is this form **stale** — issued at a channel head the channel has since
416
+ * moved past, and still unanswered? The one rule (R-15 *Staleness and
417
+ * order*), written once so the host's door and a client's render agree:
418
+ *
419
+ * !answered && head != null && headNow > head
420
+ *
421
+ * `headNow` is the greatest message id on the block's row's channel as the
422
+ * caller holds it, leaving out the row's own answers (rows whose
423
+ * `metadata.answersForm.messageId` is the block's row) — deleted rows are
424
+ * gone and do not count, hidden rows still exist and do. Answered beats
425
+ * stale everywhere: a form answered before the head moved stays answered.
426
+ * A block with no `head` is never stale.
427
+ * @experimental
428
+ */
429
+ export declare function isFormStale(block: {
430
+ head?: unknown;
431
+ answered?: unknown;
432
+ }, headNow: number | null | undefined): boolean;
433
+ /**
434
+ * Staleness as a verdict (R-15 *Staleness and order*; U5f): `isFormStale`
435
+ * is the judge, and the sentence is the one the host's fire refuses a press
436
+ * with and a dispatched answer is receipted with. The client draws a stale
437
+ * form collapsed as *superseded* from the same verdict, over the head it
438
+ * holds — the `list` door, an affordance; the fire refuses regardless.
439
+ */
440
+ /** Input to `stalenessVerdict`'s judge. @experimental */
441
+ export interface StalenessInput {
442
+ block: {
443
+ head?: unknown;
444
+ answered?: unknown;
445
+ };
446
+ /** The channel head as the door holds it (`stalenessHead` on the host; the client's `stalenessHeadOf`). */
447
+ headNow: number | null | undefined;
448
+ }
449
+ /** @internal */
450
+ export declare const stalenessVerdict: import("./verdicts.js").VerdictDecl<StalenessInput>;
451
+ /**
452
+ * The JSON Schema an oracle answers a form against (R-15: "an oracle with
453
+ * `json` capability answers against the form's schema").
454
+ *
455
+ * - `choices` → `{ choice: <enum of the option keys> }`, required.
456
+ * - `form` → the field schema, mapped field by field (`fieldsToJsonSchema`).
457
+ *
458
+ * A `choices` block whose options carry no keys yields an empty enum, which
459
+ * is what the validator refuses on an addressed block before it is written.
460
+ * @internal
461
+ */
462
+ export declare function formAnswerSchema(block: FormBlock): Record<string, unknown>;
463
+ /**
464
+ * The one field language as JSON Schema — for a `form` block's answer, and
465
+ * for anything else that hands a `SettingsSchema` to a model. Every field
466
+ * type maps; `secret` and `media` map to strings because that is what a
467
+ * model could produce, and a form asking a character for either is a form
468
+ * the author should not have written.
469
+ * @experimental
470
+ */
471
+ export declare function fieldsToJsonSchema(fields: SettingsSchema): Record<string, unknown>;
472
+ /**
473
+ * The fire a form's answer becomes — what a press sends, and what the
474
+ * answer pipeline commits "exactly as a click would": the block's function,
475
+ * its stamped identity, and the payload. For `choices` the payload is
476
+ * `{ choice }`; for `form` it is the answered values. Null when the answer
477
+ * names no option the block offers, or is not an object — an oracle's
478
+ * answer is checked here before anything is fired.
479
+ * @internal
480
+ */
481
+ export declare function formFireOf(block: FormBlock, answer: unknown): {
482
+ fn: string;
483
+ action?: string;
484
+ payload: Record<string, unknown>;
485
+ label?: string;
486
+ } | null;
487
+ //# sourceMappingURL=messageBlocks.d.ts.map