@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,291 @@
1
+ /**
2
+ * Participant references — who an audience names, and who is speaking
3
+ * (plans/29 R-15 *audience*, R-18 (3), R-21 (4); ruled 2026-09-15, built
4
+ * 2026-09-16 as U5a).
5
+ *
6
+ * One grammar answers two questions that used to be answered by two
7
+ * vocabularies: an action's **audience** (who may *see* it, who may *act* on
8
+ * it) and an inlet's **speaker** (whose turn this is). Both are lists or
9
+ * values of this string form, so nothing downstream branches on which kind
10
+ * of participant it received — a library character and a genre's envoy are
11
+ * addressed the same way and resolved by the same resolver.
12
+ *
13
+ * ## The grammar
14
+ *
15
+ * | Reference | Means |
16
+ * | ------------------- | -------------------------------------------------------------------------------------------------------- |
17
+ * | `owner` | The session's owner. |
18
+ * | `admin` | Any administrator acting in the session. |
19
+ * | `participant` | Any member of the session — owner or guest. |
20
+ * | `user:<id>` | One person, by user id. |
21
+ * | `character:<id>` | One library character, by row id — a cast member, or a member's own persona. |
22
+ * | `envoy:<slug>` | A speaker the genre (or a contributed action) brings with it — `envoy:mascot`, `envoy:chariot.dice-tray.master`. |
23
+ * | `item` | The **per-message ownership rule**: whoever the message belongs to, decided at the venue, never resolvable ahead of a message. |
24
+ * | `run-owner` | The person who started the run. |
25
+ *
26
+ * `character:` and `envoy:` are the two forms a **speaker** takes (R-18 (3)):
27
+ * a character id for somebody in the library, an envoy slug for somebody who
28
+ * exists nowhere but the genre. The slug is namespaced like a slash name when
29
+ * an action contributes it (`<plugin>.<key>`), so it cannot collide with a
30
+ * genre's.
31
+ *
32
+ * ## Resolution
33
+ *
34
+ * A reference is a name; **who portrays it this turn** — a person, the AI, or
35
+ * nobody — is the host's answer, resolved once at run start and pinned on
36
+ * the receipt as `portrayals` (R-21 (4)), like config. The SDK declares the
37
+ * question's shape (`Portrayal`) and never answers it: nodes stay blind to
38
+ * it, and a definition that needs the answer declares an in-port.
39
+ *
40
+ * *Portrayal*, not *voice*: a **voice** is one cast member's step inside an
41
+ * adventure turn (`.each('voices')`), and a connection's `voices` are TTS —
42
+ * the resolver's answer is a third thing and gets its own word (ruled
43
+ * 2026-09-16).
44
+ *
45
+ * ## What this is not
46
+ *
47
+ * Not a *cast* row (a membership), not a *scope* (§6 config layering), and
48
+ * not *availability* (the genre's `messageVerbs`). A reference says *who*;
49
+ * the venue says *where*; the resolver says *whether they are here*.
50
+ */
51
+ /**
52
+ * The role-shaped references — no id, resolved against the session and the run.
53
+ *
54
+ * `participant` is everyone in the session: its people, and the model's
55
+ * context. The two catch-alls split it (R57): `person` is every human member,
56
+ * `ai` is the model's context — what goes into a prompt. A data audience
57
+ * (`see` on a stored value) is written in these; an empty one is pipelines
58
+ * only.
59
+ * @experimental
60
+ */
61
+ export declare const PARTICIPANT_ROLES: readonly ['owner', 'admin', 'participant', 'person', 'ai', 'item', 'run-owner'];
62
+ /** @experimental */
63
+ export type ParticipantRole = (typeof PARTICIPANT_ROLES)[number];
64
+ /**
65
+ * A participant reference, as a string.
66
+ *
67
+ * Ids are opaque to the SDK — the host's user and character ids are
68
+ * integers today, and the receipt's `actorUserId` is already a string, so
69
+ * the id half is a string here and the host reads it at its seam. An envoy
70
+ * slug is `[A-Za-z0-9]` followed by any of `[A-Za-z0-9._-]`.
71
+ * @experimental
72
+ */
73
+ export type ParticipantRef = ParticipantRole | `user:${string}` | `character:${string}` | `envoy:${string}`;
74
+ /** A reference taken apart. @experimental */
75
+ export type ParsedParticipantRef = {
76
+ kind: ParticipantRole;
77
+ } | {
78
+ kind: 'user';
79
+ id: string;
80
+ } | {
81
+ kind: 'character';
82
+ id: string;
83
+ } | {
84
+ kind: 'envoy';
85
+ slug: string;
86
+ };
87
+ /**
88
+ * Who may see, and who may act (R-15). Declared here for the action model;
89
+ * consumed by the venue work (U5c) — no UI reads it yet.
90
+ * @experimental
91
+ */
92
+ export interface Audience {
93
+ see: ParticipantRef[];
94
+ act: ParticipantRef[];
95
+ }
96
+ /**
97
+ * Who portrays a participant this turn — the resolver's answer.
98
+ *
99
+ * `person` — a signed-in member of the session speaks as them (their own
100
+ * persona, or the run owner acting as a role). `ai` — the model speaks as
101
+ * them (a cast character, an envoy, the turn's own speaker). `none` — nobody
102
+ * can: a character not in the cast, a user who is not a member, a role
103
+ * nobody present holds, or `item`, which is only ever decided against a
104
+ * message.
105
+ *
106
+ * `userId` is a string for the reason `ParticipantRef`'s ids are.
107
+ * @experimental
108
+ */
109
+ export type Portrayal = {
110
+ by: 'person';
111
+ userId: string;
112
+ } | {
113
+ by: 'ai';
114
+ } | {
115
+ by: 'none';
116
+ };
117
+ /** The pinned answer for every reference a run asked about. @experimental */
118
+ export type Portrayals = Partial<Record<ParticipantRef, Portrayal>>;
119
+ /**
120
+ * Does the viewer hold any of these references, under the resolver's rules?
121
+ * A reference the viewer *is* — a `person` portrayal naming them — holds.
122
+ * `item` is the per-message ownership rule: with `item` given, that is its
123
+ * answer; with none (a listing, ahead of any message) it holds and the
124
+ * caller reports it separately as `itemGated`, a question for a message
125
+ * rather than a refusal.
126
+ *
127
+ * The judge of `core:verdict/audience` (`verdicts.ts`): the host's listing
128
+ * reads `canAct` through it and its fire quotes the verdict, so the two
129
+ * cannot disagree.
130
+ * @internal
131
+ */
132
+ export declare function audienceHolds(refs: ReadonlyArray<ParticipantRef>, portrayals: Portrayals, viewer: {
133
+ userId: number | string;
134
+ }, item?: boolean): boolean;
135
+ /**
136
+ * Does the model's context hold any of these references (R57)? The prompt
137
+ * built for `speaker` — a `character:` or `envoy:` reference, when there is
138
+ * one — may carry what everyone may see (`participant`), what the model may
139
+ * (`ai`), and what that speaker may. `[]` holds for nobody.
140
+ * @internal
141
+ */
142
+ export declare function aiHolds(refs: ReadonlyArray<ParticipantRef>, speaker?: ParticipantRef | null): boolean;
143
+ /** The one spelling of a reference — `' character:7 '` is `character:7`. Throws on a non-reference. @internal */
144
+ export declare const canonicalParticipantRef: (raw: string) => ParticipantRef;
145
+ /** Who may see each stored value, by owner and key; a key with no entry is pipelines only (R59). @experimental */
146
+ export type DataAudiences = Record<string, Record<string, ParticipantRef[]>>;
147
+ /**
148
+ * One reader's view of an owner-keyed store (R57): the values whose audience
149
+ * `holds` for that reader, as one object per owner. An owner left with no
150
+ * value the reader may see is left out. Pipelines read the store itself, not
151
+ * this.
152
+ * @internal
153
+ */
154
+ export declare function visibleTo(values: Record<string, unknown>, audiences: DataAudiences, holds: (refs: ReadonlyArray<ParticipantRef>) => boolean): Record<string, Record<string, unknown>>;
155
+ /**
156
+ * What is wrong with an audience a write names, or undefined (R57). A list of
157
+ * participant references; `item` and `run-owner` mean nothing for a stored
158
+ * value — there is no message to own, and a value outlives the run.
159
+ * @internal
160
+ */
161
+ export declare function dataAudienceFindings(raw: unknown): string | undefined;
162
+ /**
163
+ * Take a reference apart. Throws on anything that is not one, with the
164
+ * sentence a declaration error should carry — an audience naming `user:` with
165
+ * no id, or `character:Tom`, is an authoring mistake, not a read to degrade.
166
+ * @internal
167
+ */
168
+ export declare function parseParticipantRef(raw: unknown): ParsedParticipantRef;
169
+ /** The one spelling a parsed reference has. `parse(format(x))` is `x`. @internal */
170
+ export declare function formatParticipantRef(parsed: ParsedParticipantRef): ParticipantRef;
171
+ /** Is this a well-formed participant reference? Never throws. @internal */
172
+ export declare function isParticipantRef(raw: unknown): raw is ParticipantRef;
173
+ /** The reference an envoy is addressed by. @experimental */
174
+ export type EnvoyRef = `envoy:${string}`;
175
+ /**
176
+ * Who declared an envoy — the two places one may be declared, and the two
177
+ * origins a cast row may carry. A genre's envoy is addressed by its bare key;
178
+ * an action's by `<plugin>.<key>` (the spec's namespace, like a slash name).
179
+ * @experimental
180
+ */
181
+ export type EnvoyOwner = {
182
+ genre: string;
183
+ } | {
184
+ action: {
185
+ specId: string;
186
+ };
187
+ };
188
+ /**
189
+ * The slug an envoy is addressed by: a genre's is its `key`; an action's is
190
+ * `<plugin>.<key>` — **every** action's, core's included (`core.dice-master`),
191
+ * unlike a slash name where core takes the bare form. The dot is what keeps
192
+ * an action's envoy from ever colliding with a genre's (a genre's key admits
193
+ * no dot); a core action taking a bare key would give that up. The origin
194
+ * itself is a fact of the declaration (`DeclaredEnvoy.origin` on the host),
195
+ * never re-derived from the slug.
196
+ * @internal
197
+ */
198
+ export declare function envoySlugOf(owner: EnvoyOwner, key: string): string;
199
+ /** The participant reference for an envoy: `envoy:<slug>` (see `envoySlugOf`). @experimental */
200
+ export declare function envoyIdentity(owner: EnvoyOwner, key: string): EnvoyRef;
201
+ /** The slug of an `envoy:` reference, or null for any other reference. @internal */
202
+ export declare function envoySlugOfRef(ref: unknown): string | null;
203
+ /**
204
+ * What `core:query/session-cast@1` publishes on `main` / `cast`
205
+ * (`core:shape/session-cast@1`), as a TypeScript name — the `cast` of the
206
+ * settings document (`SessionSettingsV1`, sessionSettings.ts) and the
207
+ * `cast` in-port of `core:task/turn-pool@1`.
208
+ *
209
+ * Declared from the existing read and **adding no fields**: the character
210
+ * and persona rows go out raw with the seat's `position`, `removedAt` and
211
+ * `enabled` riding along (the host retrieves, it does not choose), `envoys` is the
212
+ * seated envoys `entities/envoys.ts seatedEnvoys` returns (each with `slug`,
213
+ * `position`, `speaks`, `removedAt`), and the rest is what the prompt path
214
+ * already reads. Every row is open: the host's character row has more
215
+ * columns than this file names, and a reader keys on what it needs.
216
+ *
217
+ * Not candidates: nothing here has been pooled. The pool reads this and
218
+ * publishes `turn-candidates@1`.
219
+ * @experimental
220
+ */
221
+ export interface SessionCastV1 {
222
+ /** Character seats: the library row under `character`, plus the seat's own columns. */
223
+ sessionCharacters: Array<{
224
+ character: {
225
+ id: number;
226
+ name: string;
227
+ nickname?: string | null;
228
+ aliases?: unknown;
229
+ userId?: number | null;
230
+ [k: string]: unknown;
231
+ };
232
+ /**
233
+ * The seat is switched on in the cast list. **Every seat is here**,
234
+ * switched off or not (2026-09-27): a reader that must not see a
235
+ * switched-off one — a turn pool, a names list — filters on this.
236
+ * (The table's column is `is_active`; `enabled` is its name on every
237
+ * read a pipeline or widget takes.)
238
+ */
239
+ enabled: boolean;
240
+ position: number | null;
241
+ removedAt: Date | string | null;
242
+ /** Attached by the host from `lorebook_bindings`, not a cast column. */
243
+ absorbedAliases: string[];
244
+ [k: string]: unknown;
245
+ }>;
246
+ /** Persona seats: the library row under `persona` (a character flagged `is_persona`), plus the seat's own columns. */
247
+ sessionPersonas: Array<{
248
+ persona: {
249
+ id: number;
250
+ name: string;
251
+ nickname?: string | null;
252
+ aliases?: unknown;
253
+ userId?: number | null;
254
+ [k: string]: unknown;
255
+ };
256
+ /** Always true — a persona seat has no switch — said so one filter serves both lists. */
257
+ enabled: boolean;
258
+ position: number | null;
259
+ removedAt: Date | string | null;
260
+ absorbedAliases: string[];
261
+ [k: string]: unknown;
262
+ }>;
263
+ /** The seated envoys, live and departed, in seat order — each its declaration joined to the seat. */
264
+ envoys: Array<{
265
+ /** The address — `mascot`, `acme.master`. */
266
+ slug: string;
267
+ key: string;
268
+ origin: 'genre' | 'action';
269
+ name: unknown;
270
+ speaks: 'in-turn' | 'on-action';
271
+ default: boolean;
272
+ position: number;
273
+ removedAt: Date | string | null;
274
+ [k: string]: unknown;
275
+ }>;
276
+ sessionScenario: string | null;
277
+ isGroup: boolean;
278
+ /** Whose turn this run is, from the scope; null when the trigger named nobody. */
279
+ currentCharacterId: number | null;
280
+ /** The declared voice of the turn's channel, when the trigger named one and the genre shapes channels. */
281
+ turnChannelVoice?: 'character' | 'narrator' | 'none';
282
+ /**
283
+ * How much of each non-speaking character's card the prompt shows — the
284
+ * session's `characterDetail` genre field, resolved (`full` · `brief` ·
285
+ * `speaker-only`). Absent for a genre that declares no such field, which
286
+ * reads as `full`.
287
+ */
288
+ characterDetail?: 'full' | 'brief' | 'speaker-only';
289
+ [k: string]: unknown;
290
+ }
291
+ //# sourceMappingURL=participants.d.ts.map
@@ -0,0 +1,252 @@
1
+ /**
2
+ * Participant references — who an audience names, and who is speaking
3
+ * (plans/29 R-15 *audience*, R-18 (3), R-21 (4); ruled 2026-09-15, built
4
+ * 2026-09-16 as U5a).
5
+ *
6
+ * One grammar answers two questions that used to be answered by two
7
+ * vocabularies: an action's **audience** (who may *see* it, who may *act* on
8
+ * it) and an inlet's **speaker** (whose turn this is). Both are lists or
9
+ * values of this string form, so nothing downstream branches on which kind
10
+ * of participant it received — a library character and a genre's envoy are
11
+ * addressed the same way and resolved by the same resolver.
12
+ *
13
+ * ## The grammar
14
+ *
15
+ * | Reference | Means |
16
+ * | ------------------- | -------------------------------------------------------------------------------------------------------- |
17
+ * | `owner` | The session's owner. |
18
+ * | `admin` | Any administrator acting in the session. |
19
+ * | `participant` | Any member of the session — owner or guest. |
20
+ * | `user:<id>` | One person, by user id. |
21
+ * | `character:<id>` | One library character, by row id — a cast member, or a member's own persona. |
22
+ * | `envoy:<slug>` | A speaker the genre (or a contributed action) brings with it — `envoy:mascot`, `envoy:chariot.dice-tray.master`. |
23
+ * | `item` | The **per-message ownership rule**: whoever the message belongs to, decided at the venue, never resolvable ahead of a message. |
24
+ * | `run-owner` | The person who started the run. |
25
+ *
26
+ * `character:` and `envoy:` are the two forms a **speaker** takes (R-18 (3)):
27
+ * a character id for somebody in the library, an envoy slug for somebody who
28
+ * exists nowhere but the genre. The slug is namespaced like a slash name when
29
+ * an action contributes it (`<plugin>.<key>`), so it cannot collide with a
30
+ * genre's.
31
+ *
32
+ * ## Resolution
33
+ *
34
+ * A reference is a name; **who portrays it this turn** — a person, the AI, or
35
+ * nobody — is the host's answer, resolved once at run start and pinned on
36
+ * the receipt as `portrayals` (R-21 (4)), like config. The SDK declares the
37
+ * question's shape (`Portrayal`) and never answers it: nodes stay blind to
38
+ * it, and a definition that needs the answer declares an in-port.
39
+ *
40
+ * *Portrayal*, not *voice*: a **voice** is one cast member's step inside an
41
+ * adventure turn (`.each('voices')`), and a connection's `voices` are TTS —
42
+ * the resolver's answer is a third thing and gets its own word (ruled
43
+ * 2026-09-16).
44
+ *
45
+ * ## What this is not
46
+ *
47
+ * Not a *cast* row (a membership), not a *scope* (§6 config layering), and
48
+ * not *availability* (the genre's `messageVerbs`). A reference says *who*;
49
+ * the venue says *where*; the resolver says *whether they are here*.
50
+ */
51
+ /**
52
+ * The role-shaped references — no id, resolved against the session and the run.
53
+ *
54
+ * `participant` is everyone in the session: its people, and the model's
55
+ * context. The two catch-alls split it (R57): `person` is every human member,
56
+ * `ai` is the model's context — what goes into a prompt. A data audience
57
+ * (`see` on a stored value) is written in these; an empty one is pipelines
58
+ * only.
59
+ * @experimental
60
+ */
61
+ export const PARTICIPANT_ROLES = ['owner', 'admin', 'participant', 'person', 'ai', 'item', 'run-owner'];
62
+ /**
63
+ * Does the viewer hold any of these references, under the resolver's rules?
64
+ * A reference the viewer *is* — a `person` portrayal naming them — holds.
65
+ * `item` is the per-message ownership rule: with `item` given, that is its
66
+ * answer; with none (a listing, ahead of any message) it holds and the
67
+ * caller reports it separately as `itemGated`, a question for a message
68
+ * rather than a refusal.
69
+ *
70
+ * The judge of `core:verdict/audience` (`verdicts.ts`): the host's listing
71
+ * reads `canAct` through it and its fire quotes the verdict, so the two
72
+ * cannot disagree.
73
+ * @internal
74
+ */
75
+ export function audienceHolds(refs, portrayals, viewer, item) {
76
+ for (const ref of refs) {
77
+ if (ref === 'item') {
78
+ if (item === undefined || item)
79
+ return true;
80
+ continue;
81
+ }
82
+ const p = portrayals[ref];
83
+ if (p?.by === 'person' && p.userId === String(viewer.userId))
84
+ return true;
85
+ }
86
+ return false;
87
+ }
88
+ /**
89
+ * Does the model's context hold any of these references (R57)? The prompt
90
+ * built for `speaker` — a `character:` or `envoy:` reference, when there is
91
+ * one — may carry what everyone may see (`participant`), what the model may
92
+ * (`ai`), and what that speaker may. `[]` holds for nobody.
93
+ * @internal
94
+ */
95
+ export function aiHolds(refs, speaker) {
96
+ const who = speaker && isParticipantRef(speaker) ? canonicalParticipantRef(speaker) : null;
97
+ return refs.some((r) => {
98
+ if (!isParticipantRef(r))
99
+ return false;
100
+ const c = canonicalParticipantRef(r);
101
+ return c === 'ai' || c === 'participant' || (!!who && c === who);
102
+ });
103
+ }
104
+ /** The one spelling of a reference — `' character:7 '` is `character:7`. Throws on a non-reference. @internal */
105
+ export const canonicalParticipantRef = (raw) => formatParticipantRef(parseParticipantRef(raw));
106
+ /**
107
+ * One reader's view of an owner-keyed store (R57): the values whose audience
108
+ * `holds` for that reader, as one object per owner. An owner left with no
109
+ * value the reader may see is left out. Pipelines read the store itself, not
110
+ * this.
111
+ * @internal
112
+ */
113
+ export function visibleTo(values, audiences, holds) {
114
+ const out = {};
115
+ for (const [owner, doc] of Object.entries(values)) {
116
+ if (!doc || typeof doc !== 'object' || Array.isArray(doc))
117
+ continue;
118
+ const seen = {};
119
+ for (const [key, value] of Object.entries(doc)) {
120
+ const refs = audiences[owner]?.[key] ?? [];
121
+ if (refs.length && holds(refs))
122
+ seen[key] = value;
123
+ }
124
+ if (Object.keys(seen).length)
125
+ out[owner] = seen;
126
+ }
127
+ return out;
128
+ }
129
+ /**
130
+ * What is wrong with an audience a write names, or undefined (R57). A list of
131
+ * participant references; `item` and `run-owner` mean nothing for a stored
132
+ * value — there is no message to own, and a value outlives the run.
133
+ * @internal
134
+ */
135
+ export function dataAudienceFindings(raw) {
136
+ if (raw === undefined)
137
+ return undefined;
138
+ if (!Array.isArray(raw))
139
+ return 'an audience is a list of participant references';
140
+ for (const ref of raw) {
141
+ try {
142
+ parseParticipantRef(ref);
143
+ }
144
+ catch (e) {
145
+ return e.message;
146
+ }
147
+ if (ref === 'item' || ref === 'run-owner')
148
+ return `'${ref}' is not an audience for a stored value — it names a message or a run, and the value outlives both`;
149
+ }
150
+ return undefined;
151
+ }
152
+ // An id: anything but whitespace and the separator. The host narrows it.
153
+ const ID = /^[^\s:]+$/;
154
+ // A slug, optionally namespaced by dots (`<plugin>.<key>` for an action's envoy).
155
+ const SLUG = /^[A-Za-z0-9][A-Za-z0-9._-]*$/;
156
+ const roles = new Set(PARTICIPANT_ROLES);
157
+ /**
158
+ * Take a reference apart. Throws on anything that is not one, with the
159
+ * sentence a declaration error should carry — an audience naming `user:` with
160
+ * no id, or `character:Tom`, is an authoring mistake, not a read to degrade.
161
+ * @internal
162
+ */
163
+ export function parseParticipantRef(raw) {
164
+ if (typeof raw !== 'string')
165
+ throw new Error(`a participant reference is a string — got ${raw === null ? 'null' : typeof raw}`);
166
+ const text = raw.trim();
167
+ if (roles.has(text))
168
+ return { kind: text };
169
+ const cut = text.indexOf(':');
170
+ if (cut === -1)
171
+ throw new Error(`'${raw}' is not a participant reference — expected one of ${PARTICIPANT_ROLES.join(', ')}, ` +
172
+ `or user:<id>, character:<id>, envoy:<slug>`);
173
+ const kind = text.slice(0, cut);
174
+ const rest = text.slice(cut + 1);
175
+ switch (kind) {
176
+ case 'user':
177
+ case 'character':
178
+ if (!ID.test(rest))
179
+ throw new Error(`'${raw}' names a ${kind} with no readable id — a ${kind} reference is '${kind}:<id>'`);
180
+ return { kind, id: rest };
181
+ case 'envoy':
182
+ if (!SLUG.test(rest))
183
+ throw new Error(`'${raw}' names an envoy with no readable slug — an envoy reference is 'envoy:<slug>', ` +
184
+ `the slug a letter or digit followed by letters, digits, '.', '_' or '-'`);
185
+ return { kind, slug: rest };
186
+ default:
187
+ throw new Error(`'${raw}' is not a participant reference — '${kind}:' is not a kind (user, character, envoy)`);
188
+ }
189
+ }
190
+ /** The one spelling a parsed reference has. `parse(format(x))` is `x`. @internal */
191
+ export function formatParticipantRef(parsed) {
192
+ switch (parsed.kind) {
193
+ case 'user':
194
+ return `user:${parsed.id}`;
195
+ case 'character':
196
+ return `character:${parsed.id}`;
197
+ case 'envoy':
198
+ return `envoy:${parsed.slug}`;
199
+ default:
200
+ return parsed.kind;
201
+ }
202
+ }
203
+ /** Is this a well-formed participant reference? Never throws. @internal */
204
+ export function isParticipantRef(raw) {
205
+ try {
206
+ parseParticipantRef(raw);
207
+ return true;
208
+ }
209
+ catch {
210
+ return false;
211
+ }
212
+ }
213
+ /** A spec id's namespace — `acme:spec/dice` → `acme`. Empty for an id with no colon. */
214
+ const namespaceOf = (specId) => {
215
+ const i = specId.indexOf(':');
216
+ return i === -1 ? '' : specId.slice(0, i);
217
+ };
218
+ /**
219
+ * The slug an envoy is addressed by: a genre's is its `key`; an action's is
220
+ * `<plugin>.<key>` — **every** action's, core's included (`core.dice-master`),
221
+ * unlike a slash name where core takes the bare form. The dot is what keeps
222
+ * an action's envoy from ever colliding with a genre's (a genre's key admits
223
+ * no dot); a core action taking a bare key would give that up. The origin
224
+ * itself is a fact of the declaration (`DeclaredEnvoy.origin` on the host),
225
+ * never re-derived from the slug.
226
+ * @internal
227
+ */
228
+ export function envoySlugOf(owner, key) {
229
+ if ('genre' in owner)
230
+ return key;
231
+ const ns = namespaceOf(owner.action.specId);
232
+ if (!ns)
233
+ throw new Error(`an action's envoy is namespaced by its spec ('<plugin>.<key>') and '${owner.action.specId}' has no namespace`);
234
+ return `${ns}.${key}`;
235
+ }
236
+ /** The participant reference for an envoy: `envoy:<slug>` (see `envoySlugOf`). @experimental */
237
+ export function envoyIdentity(owner, key) {
238
+ return `envoy:${envoySlugOf(owner, key)}`;
239
+ }
240
+ /** The slug of an `envoy:` reference, or null for any other reference. @internal */
241
+ export function envoySlugOfRef(ref) {
242
+ if (typeof ref !== 'string')
243
+ return null;
244
+ try {
245
+ const parsed = parseParticipantRef(ref);
246
+ return parsed.kind === 'envoy' ? parsed.slug : null;
247
+ }
248
+ catch {
249
+ return null;
250
+ }
251
+ }
252
+ //# sourceMappingURL=participants.js.map
@@ -0,0 +1,62 @@
1
+ /**
2
+ * The person gate on a widget's invoke — ONE table for the page and the
3
+ * component harness alike (2026-09-26).
4
+ *
5
+ * Core's verbs that change a message — hide, retry, extend, delete, edit,
6
+ * swipe — are things a person does. A box that is not core's may invoke one
7
+ * only while a person is acting in it: a press in the box within the last
8
+ * {@link PERSON_PRESS_WINDOW_MS}, and focus not having left it since (a
9
+ * `blur` ends the window). The page reads "a press" as a trusted event the
10
+ * box forwarded, a trusted key a plain `input`'s `keys` names, or a press
11
+ * inside an `sp-frame` that frame's own live check vouched for; the harness
12
+ * reads the presses it raises as a person. Both judge by this module.
13
+ *
14
+ * It is a mitigation against a widget acting unprompted, never a proof of
15
+ * intent: the server judges every message write against the viewer's own
16
+ * permissions. Other core verbs (stop, branch) are not gated; a contributed
17
+ * action is the server's to judge.
18
+ *
19
+ * Pure — no DOM, no clock: callers hand in the last press and `now`.
20
+ *
21
+ * @experimental 🚧 provisional with the widget invoke vocabulary (C7, R80).
22
+ */
23
+ /** Core's verbs that change a message or start a turn, and so need a person behind a widget's invoke of them. @experimental */
24
+ export declare const PERSON_GATED_CORE_VERBS: ReadonlySet<string>;
25
+ /** How long a person's press in a box vouches for its invoke — ended early by a `blur`. @experimental */
26
+ export declare const PERSON_PRESS_WINDOW_MS = 5000;
27
+ /** Is this action one a box that is not core's may invoke only with a person behind it? @experimental */
28
+ export declare const isPersonGatedAction: (action: {
29
+ specSlug: string;
30
+ key: string;
31
+ }) => boolean;
32
+ /**
33
+ * Does the last press still vouch at `now`? `lastPressAt` is null when there
34
+ * was none, or focus has left the box since ({@link personPressAfter}). A
35
+ * press "in the future" (a clock that stepped back) vouches for nothing.
36
+ * @experimental
37
+ */
38
+ export declare function personPressCurrent(lastPressAt: number | null, now: number): boolean;
39
+ /**
40
+ * The last press after an event of `eventType` reached the box's component:
41
+ * a `blur` ends the window, a person's event opens it anew, anything else
42
+ * (a synthetic event, an element's own) leaves it as it was.
43
+ * @experimental
44
+ */
45
+ export declare function personPressAfter(eventType: string, byPerson: boolean, previous: number | null, now: number): number | null;
46
+ /** @experimental */
47
+ export type PersonGateVerdict = {
48
+ allowed: true;
49
+ } | {
50
+ allowed: false;
51
+ reason: string;
52
+ };
53
+ /**
54
+ * Whether a box that is not core's may invoke `action` now, and the sentence
55
+ * to refuse with when it may not.
56
+ * @experimental
57
+ */
58
+ export declare function personGateVerdict(action: {
59
+ specSlug: string;
60
+ key: string;
61
+ }, lastPressAt: number | null, now: number): PersonGateVerdict;
62
+ //# sourceMappingURL=personGate.d.ts.map
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The person gate on a widget's invoke — ONE table for the page and the
3
+ * component harness alike (2026-09-26).
4
+ *
5
+ * Core's verbs that change a message — hide, retry, extend, delete, edit,
6
+ * swipe — are things a person does. A box that is not core's may invoke one
7
+ * only while a person is acting in it: a press in the box within the last
8
+ * {@link PERSON_PRESS_WINDOW_MS}, and focus not having left it since (a
9
+ * `blur` ends the window). The page reads "a press" as a trusted event the
10
+ * box forwarded, a trusted key a plain `input`'s `keys` names, or a press
11
+ * inside an `sp-frame` that frame's own live check vouched for; the harness
12
+ * reads the presses it raises as a person. Both judge by this module.
13
+ *
14
+ * It is a mitigation against a widget acting unprompted, never a proof of
15
+ * intent: the server judges every message write against the viewer's own
16
+ * permissions. Other core verbs (stop, branch) are not gated; a contributed
17
+ * action is the server's to judge.
18
+ *
19
+ * Pure — no DOM, no clock: callers hand in the last press and `now`.
20
+ *
21
+ * @experimental 🚧 provisional with the widget invoke vocabulary (C7, R80).
22
+ */
23
+ /** Core's verbs that change a message or start a turn, and so need a person behind a widget's invoke of them. @experimental */
24
+ export const PERSON_GATED_CORE_VERBS = new Set([
25
+ 'hide',
26
+ 'retry',
27
+ 'extend',
28
+ // The composer's Continue (B7): not a message write, but it starts a
29
+ // generation, as the old `continue` with no subject did before the split.
30
+ 'advance',
31
+ // Pick who speaks and the narrator turn (B8): turn controls that start a generation.
32
+ 'pick',
33
+ 'narrate',
34
+ 'delete',
35
+ 'edit',
36
+ 'swipe',
37
+ ]);
38
+ /** How long a person's press in a box vouches for its invoke — ended early by a `blur`. @experimental */
39
+ export const PERSON_PRESS_WINDOW_MS = 5_000;
40
+ /** Is this action one a box that is not core's may invoke only with a person behind it? @experimental */
41
+ export const isPersonGatedAction = (action) => action.specSlug === 'core' && PERSON_GATED_CORE_VERBS.has(action.key);
42
+ /**
43
+ * Does the last press still vouch at `now`? `lastPressAt` is null when there
44
+ * was none, or focus has left the box since ({@link personPressAfter}). A
45
+ * press "in the future" (a clock that stepped back) vouches for nothing.
46
+ * @experimental
47
+ */
48
+ export function personPressCurrent(lastPressAt, now) {
49
+ return lastPressAt !== null && now - lastPressAt >= 0 && now - lastPressAt <= PERSON_PRESS_WINDOW_MS;
50
+ }
51
+ /**
52
+ * The last press after an event of `eventType` reached the box's component:
53
+ * a `blur` ends the window, a person's event opens it anew, anything else
54
+ * (a synthetic event, an element's own) leaves it as it was.
55
+ * @experimental
56
+ */
57
+ export function personPressAfter(eventType, byPerson, previous, now) {
58
+ if (eventType === 'blur')
59
+ return null;
60
+ return byPerson ? now : previous;
61
+ }
62
+ /**
63
+ * Whether a box that is not core's may invoke `action` now, and the sentence
64
+ * to refuse with when it may not.
65
+ * @experimental
66
+ */
67
+ export function personGateVerdict(action, lastPressAt, now) {
68
+ if (!isPersonGatedAction(action) || personPressCurrent(lastPressAt, now))
69
+ return { allowed: true };
70
+ return {
71
+ allowed: false,
72
+ reason: `'core#${action.key}' changes a message and needs a person behind it — a plugin's box may ` +
73
+ `invoke it only while a person is acting in the box (a press within the last ` +
74
+ `${PERSON_PRESS_WINDOW_MS / 1000}s), never on its own`,
75
+ };
76
+ }
77
+ //# sourceMappingURL=personGate.js.map