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

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 (144) hide show
  1. package/dist/actions.d.ts +52 -2
  2. package/dist/actions.js +56 -6
  3. package/dist/annexFields.d.ts +32 -2
  4. package/dist/annexFields.js +48 -5
  5. package/dist/announce.d.ts +142 -2
  6. package/dist/announce.js +198 -2
  7. package/dist/attributes.d.ts +331 -6
  8. package/dist/attributes.js +339 -27
  9. package/dist/bridges.d.ts +61 -0
  10. package/dist/bridges.js +112 -0
  11. package/dist/builder.d.ts +278 -51
  12. package/dist/builder.js +267 -30
  13. package/dist/cadences.d.ts +585 -0
  14. package/dist/cadences.js +1118 -0
  15. package/dist/capabilities.d.ts +106 -17
  16. package/dist/capabilities.js +85 -7
  17. package/dist/checkMethods.d.ts +240 -0
  18. package/dist/checkMethods.js +362 -0
  19. package/dist/component.d.ts +6 -1
  20. package/dist/componentClient.d.ts +42 -6
  21. package/dist/componentWire.js +22 -4
  22. package/dist/composerStates.d.ts +96 -0
  23. package/dist/composerStates.js +190 -0
  24. package/dist/conditions.d.ts +424 -0
  25. package/dist/conditions.js +521 -0
  26. package/dist/config.d.ts +42 -6
  27. package/dist/config.js +48 -20
  28. package/dist/conversions.d.ts +41 -0
  29. package/dist/conversions.js +50 -0
  30. package/dist/declarations.d.ts +40 -2
  31. package/dist/declarations.js +178 -10
  32. package/dist/descriptors.d.ts +287 -4
  33. package/dist/descriptors.js +281 -18
  34. package/dist/document.d.ts +47 -2
  35. package/dist/document.js +46 -14
  36. package/dist/entities.d.ts +156 -0
  37. package/dist/entities.js +259 -0
  38. package/dist/events.d.ts +711 -1
  39. package/dist/events.js +412 -1
  40. package/dist/executor.d.ts +4 -3
  41. package/dist/executor.js +22 -8
  42. package/dist/exposure.d.ts +128 -0
  43. package/dist/exposure.js +168 -0
  44. package/dist/extension.d.ts +127 -3
  45. package/dist/extension.js +43 -0
  46. package/dist/fit.d.ts +198 -0
  47. package/dist/fit.js +351 -0
  48. package/dist/functions.d.ts +554 -0
  49. package/dist/functions.js +712 -0
  50. package/dist/genres.d.ts +303 -89
  51. package/dist/genres.js +335 -100
  52. package/dist/hookGrants.d.ts +15 -1
  53. package/dist/hookGrants.js +11 -10
  54. package/dist/hooks.d.ts +34 -5
  55. package/dist/hooks.js +5 -2
  56. package/dist/hostElements.d.ts +7 -1
  57. package/dist/hostElements.js +20 -1
  58. package/dist/hostState.d.ts +110 -0
  59. package/dist/hostState.js +140 -0
  60. package/dist/identity.d.ts +1 -1
  61. package/dist/identity.js +1 -1
  62. package/dist/index.d.ts +25 -0
  63. package/dist/index.js +48 -0
  64. package/dist/jsonSchema.d.ts +178 -0
  65. package/dist/jsonSchema.js +570 -0
  66. package/dist/libraryDraft.d.ts +27 -0
  67. package/dist/libraryDraft.js +25 -0
  68. package/dist/lorebookFile.d.ts +44 -0
  69. package/dist/lorebookFile.js +202 -0
  70. package/dist/media.d.ts +127 -12
  71. package/dist/media.js +45 -1
  72. package/dist/messageBlocks.d.ts +179 -5
  73. package/dist/messageBlocks.js +208 -6
  74. package/dist/participants.d.ts +32 -9
  75. package/dist/participants.js +13 -2
  76. package/dist/pluginHarness.d.ts +63 -33
  77. package/dist/pluginHarness.js +78 -144
  78. package/dist/pluginPermissions.d.ts +15 -1
  79. package/dist/pluginPermissions.js +29 -2
  80. package/dist/preview.d.ts +45 -4
  81. package/dist/preview.js +52 -12
  82. package/dist/primers.d.ts +177 -0
  83. package/dist/primers.js +265 -0
  84. package/dist/receipt.d.ts +11 -0
  85. package/dist/receiverRules.js +9 -0
  86. package/dist/refs.d.ts +9 -1
  87. package/dist/refs.js +12 -0
  88. package/dist/registrations.d.ts +384 -0
  89. package/dist/registrations.js +625 -0
  90. package/dist/repertoires.d.ts +502 -0
  91. package/dist/repertoires.js +666 -0
  92. package/dist/rulesetDocument.d.ts +116 -0
  93. package/dist/rulesetDocument.js +252 -0
  94. package/dist/rulesetSections.d.ts +631 -0
  95. package/dist/rulesetSections.js +1288 -0
  96. package/dist/rulesetTemplates.d.ts +161 -0
  97. package/dist/rulesetTemplates.js +242 -0
  98. package/dist/rulesets.d.ts +899 -0
  99. package/dist/rulesets.js +1378 -0
  100. package/dist/sceneSettings.d.ts +8 -0
  101. package/dist/sceneSettings.js +10 -2
  102. package/dist/scope.d.ts +44 -3
  103. package/dist/scope.js +18 -0
  104. package/dist/scripts.d.ts +31 -8
  105. package/dist/scripts.js +45 -8
  106. package/dist/sessionDossier.d.ts +157 -7
  107. package/dist/sessionLayout.d.ts +291 -138
  108. package/dist/sessionLayout.js +504 -211
  109. package/dist/sessionSettings.d.ts +24 -0
  110. package/dist/settings.d.ts +95 -4
  111. package/dist/settings.js +293 -4
  112. package/dist/shapes.d.ts +80 -1
  113. package/dist/shapes.js +100 -5
  114. package/dist/speech.d.ts +333 -0
  115. package/dist/speech.js +199 -0
  116. package/dist/statShapes.d.ts +8 -1
  117. package/dist/statShapes.js +8 -1
  118. package/dist/status.d.ts +14 -0
  119. package/dist/status.js +12 -0
  120. package/dist/storage.d.ts +53 -66
  121. package/dist/storage.js +7 -12
  122. package/dist/storyTime.d.ts +25 -1
  123. package/dist/storyTime.js +42 -2
  124. package/dist/surfaces.d.ts +15 -2
  125. package/dist/template.d.ts +19 -1
  126. package/dist/template.js +25 -11
  127. package/dist/templateScopeAt.d.ts +1 -1
  128. package/dist/templateScopeAt.js +11 -8
  129. package/dist/ties.d.ts +211 -0
  130. package/dist/ties.js +301 -0
  131. package/dist/turnOrder.d.ts +25 -14
  132. package/dist/turnOrder.js +21 -8
  133. package/dist/userAnnex.d.ts +126 -0
  134. package/dist/userAnnex.js +214 -0
  135. package/dist/validate.js +114 -19
  136. package/dist/values.js +6 -0
  137. package/dist/vocabularies.d.ts +192 -0
  138. package/dist/vocabularies.js +326 -0
  139. package/dist/widgetDecls.d.ts +12 -0
  140. package/dist/widgetDecls.js +2 -0
  141. package/dist/widgets.d.ts +1062 -29
  142. package/dist/widgets.js +218 -3
  143. package/host-elements.d.ts +90 -0
  144. package/package.json +1 -1
package/dist/builder.js CHANGED
@@ -24,6 +24,8 @@ import { i18nFindings } from './i18n.js';
24
24
  import { rendersProblem } from './bands.js';
25
25
  import { actionFindings, normalizeContributes, slashCollisions, } from './actions.js';
26
26
  import { boundaryTriggerFindings } from './sceneSettings.js';
27
+ import { eventIdOf, isEventDef } from './events.js';
28
+ import { actionHandlesOf } from './registrations.js';
27
29
  /**
28
30
  * A placement's `renders`, checked against its definition and stored as ids
29
31
  * โ€” `undefined` when it says nothing, so a node that states none hashes as it
@@ -70,6 +72,13 @@ function exposeOf(key, pinned, expose) {
70
72
  }
71
73
  if (expose.purpose !== undefined && !isModelCall(pinned))
72
74
  throw new Error(stepPurposeRefusal(key, pinned.id));
75
+ if (expose.promptReach !== undefined) {
76
+ if (expose.promptReach !== 'owner')
77
+ throw new Error(`node '${key}': expose.promptReach is 'owner' or absent โ€” an administrator's choice is the default`);
78
+ const hasPrompts = Object.values((pinned.slots ?? {})).some((s) => s.kind === 'prompts');
79
+ if (!hasPrompts)
80
+ throw new Error(`node '${key}': expose.promptReach offers a choice of prompt, but ${pinned.id} declares no prompts slot`);
81
+ }
73
82
  // What the node shows while it runs (B3/B18), and what the settings call
74
83
  // it, ride beside the session mark; the streaming step's laws are
75
84
  // `validate()`'s, which sees the whole document (one per execution path,
@@ -79,6 +88,7 @@ function exposeOf(key, pinned, expose) {
79
88
  ...(expose.status !== undefined ? { status: expose.status } : {}),
80
89
  ...(expose.label !== undefined ? { label: expose.label } : {}),
81
90
  ...(expose.purpose !== undefined ? { purpose: expose.purpose } : {}),
91
+ ...(expose.promptReach === 'owner' ? { promptReach: 'owner' } : {}),
82
92
  };
83
93
  if (swaps.length)
84
94
  return { session: true, swaps, ...shown };
@@ -123,6 +133,33 @@ function swapIds(key, pinned, swaps) {
123
133
  }
124
134
  return out;
125
135
  }
136
+ /**
137
+ * The dotted path a `TypedPath` reads โ€” `(v: T) => v.call.tool` โ†’ `'call.tool'` โ€”
138
+ * recorded by walking it once over a proxy. A function that does anything but
139
+ * read one chain of properties is refused, naming the form.
140
+ * @internal
141
+ */
142
+ export function typedPathOf(read, where) {
143
+ const segments = [];
144
+ const recorder = new Proxy(Object.create(null), {
145
+ get(_t, k) {
146
+ if (typeof k !== 'string')
147
+ return undefined;
148
+ segments.push(k);
149
+ return recorder;
150
+ },
151
+ });
152
+ let out;
153
+ try {
154
+ out = read(recorder);
155
+ }
156
+ catch {
157
+ out = undefined;
158
+ }
159
+ if (out !== recorder || !segments.length)
160
+ throw new Error(`${where}: a typed path reads one chain of properties off the value โ€” (v: Reckoned) => v.call.tool`);
161
+ return segments.join('.');
162
+ }
126
163
  /** Lowercase kebab. A slug is a database reference, not display text. */
127
164
  const SLUG = /^[a-z0-9]+(-[a-z0-9]+)*$/;
128
165
  const parseId = (definitionId) => {
@@ -277,7 +314,18 @@ class ChainBuilder {
277
314
  * instead of a list length.
278
315
  *
279
316
  * Always sequential โ€” each iteration depends on the last, so `mode` would be a lie.
280
- * @ruling 01 ยง4a
317
+ *
318
+ * The predicate is stated in one of two places (A18): in `opts.repeatWhile`, where
319
+ * `$` is typed against the nodes declared BEFORE the loop (by their full keys โ€” a
320
+ * body node is reachable there only untyped, the way it always was); or at the end
321
+ * of the body, `.repeatWhile(($) => $.parse.call)`, where `$` is typed against the
322
+ * body's own nodes. Either way it is resolved after the body and stored on the
323
+ * clause the same way, so the document does not change. Not both.
324
+ *
325
+ * The body reads the loop's own carry โ€” `$.tools.values`, what the passes so
326
+ * far published โ€” so its `$` holds the clause's ports under its id as well
327
+ * (A18, lane 4: the runtime always resolved it; the type now says so).
328
+ * @ruling 01 ยง4a, A18
281
329
  */
282
330
  loop(id, opts, fn) {
283
331
  const qualified = this.qualify(id);
@@ -288,16 +336,42 @@ class ChainBuilder {
288
336
  max: opts.max,
289
337
  chains: ['item'],
290
338
  });
291
- fn(new ChainBuilder(this.spec, { clauseId: qualified, chain: 'item' }));
339
+ fn(new ChainBuilder(this.spec, {
340
+ clauseId: qualified,
341
+ chain: 'item',
342
+ }));
292
343
  // Resolved *after* the body, so the predicate may name a node inside it โ€” which
293
344
  // is the only place a predicate that ever changes can come from.
294
- clause.repeatWhile =
295
- typeof opts.repeatWhile === 'function'
296
- ? new ChainBuilder(this.spec, {
297
- clauseId: qualified,
298
- chain: 'item',
299
- }).resolvePublic(opts.repeatWhile)
300
- : opts.repeatWhile;
345
+ if (opts.repeatWhile !== undefined && clause.repeatWhile !== undefined)
346
+ throw new Error(`loop '${qualified}' states repeatWhile twice โ€” once in its options or once at the end of its body, not both`);
347
+ if (clause.repeatWhile === undefined)
348
+ clause.repeatWhile =
349
+ typeof opts.repeatWhile === 'function'
350
+ ? new ChainBuilder(this.spec, {
351
+ clauseId: qualified,
352
+ chain: 'item',
353
+ }).resolvePublic(opts.repeatWhile)
354
+ : opts.repeatWhile;
355
+ return this;
356
+ }
357
+ /**
358
+ * ๐Ÿšง A loop's predicate, stated at the END of its body (A18) โ€” `$` typed against
359
+ * the body's own nodes, by their short keys too:
360
+ * `.loop('tools', { max: 4 }, (l) => l.task('parse', โ€ฆ).repeatWhile(($) => $.parse.call))`.
361
+ * Stored exactly as `opts.repeatWhile` is (the clause's `repeatWhile`), so the
362
+ * document is the one the options form writes. Refused anywhere but a loop's body,
363
+ * and when the loop's options state one too.
364
+ * @ruling 01 ยง4a, A18
365
+ */
366
+ repeatWhile(predicate) {
367
+ const ctx = this.clauseCtx;
368
+ const clause = ctx ? this.spec.clauses.find((c) => c.id === ctx.clauseId) : undefined;
369
+ if (!ctx || !clause || clause.kind !== 'loop' || ctx.chain !== 'item')
370
+ throw new Error(`.repeatWhile() states a loop's predicate โ€” call it at the end of the loop's body, ` +
371
+ `.loop(id, { max }, (l) => l.task(โ€ฆ).repeatWhile(($) => โ€ฆ))`);
372
+ if (clause.repeatWhile !== undefined)
373
+ throw new Error(`loop '${clause.id}' states repeatWhile twice โ€” once at the end of its body is enough`);
374
+ clause.repeatWhile = typeof predicate === 'function' ? this.resolve(predicate) : predicate;
301
375
  return this;
302
376
  }
303
377
  /** Internal: the callback resolver, reachable from `loop` after the body is built. */
@@ -383,10 +457,16 @@ export class JunctionBuilder {
383
457
  this.clauseId = clauseId;
384
458
  this.clause = clause;
385
459
  }
386
- /** A branch that fires when its predicate matches the junction's value. */
460
+ /**
461
+ * A branch that fires when its predicate matches the junction's value. `path`
462
+ * and `equalsPath` are the stored dotted strings, or `TypedPath`s โ€”
463
+ * `{ path: (v: Reckoned) => v.scripts, truthy: true }` โ€” recorded to the same
464
+ * string (A18). Each branch's `$` sees the nodes before the junction (and its
465
+ * own, by short key); a sibling branch's nodes are not its to read.
466
+ */
387
467
  when(name, predicate, fn) {
388
468
  this.clause.chains.push(name);
389
- this.clause.branches[name] = { ...predicate };
469
+ this.clause.branches[name] = storedPredicate(predicate, `junction '${this.clauseId}' branch '${name}'`);
390
470
  fn(new ChainBuilder(this.spec, {
391
471
  clauseId: this.clauseId,
392
472
  chain: name,
@@ -404,6 +484,19 @@ export class JunctionBuilder {
404
484
  return this;
405
485
  }
406
486
  }
487
+ /**
488
+ * A `.when()` predicate as stored: a typed path recorded to its dotted string,
489
+ * every other key copied as given โ€” so a string-path branch stores exactly what
490
+ * it always did (`{ ...predicate }`), key order included.
491
+ */
492
+ function storedPredicate(predicate, where) {
493
+ const out = { ...predicate };
494
+ if (typeof predicate.path === 'function')
495
+ out.path = typedPathOf(predicate.path, `${where}: path`);
496
+ if (typeof predicate.equalsPath === 'function')
497
+ out.equalsPath = typedPathOf(predicate.equalsPath, `${where}: equalsPath`);
498
+ return out;
499
+ }
407
500
  /**
408
501
  * Slot-named methods, for the same reason the chain has kind-named ones: the
409
502
  * method names the slot, so setting a slot a node never declared is caught by name rather
@@ -435,7 +528,7 @@ export class PresetBuilder {
435
528
  template(nodeKey, value) {
436
529
  return this.set(nodeKey, 'template', value);
437
530
  }
438
- /** Generation parameters: a reference to a named config, or field overrides on top. */
531
+ /** Generation parameters: a reference to a named config, `{ seedKey }`. */
439
532
  sampling(nodeKey, value) {
440
533
  return this.set(nodeKey, 'sampling', value);
441
534
  }
@@ -443,6 +536,21 @@ export class PresetBuilder {
443
536
  settings(nodeKey, value) {
444
537
  return this.set(nodeKey, 'settings', value);
445
538
  }
539
+ /**
540
+ * ๐Ÿšง Script chains, named by **seed key** โ€” `{ seedKey }` per link, in
541
+ * order. A chain stores script row ids, and a row id is an instance fact a
542
+ * shipped document cannot know, so an author names the row the way it
543
+ * names a seeded sampling config: the host resolves each key to the row it
544
+ * seeded (`CORE_SCRIPTS`) when it writes the shipped config, and a key it
545
+ * seeded no row for is dropped from the chain with a warning.
546
+ *
547
+ * An array is a `scripts`-kind slot's whole chain; an object keys chains
548
+ * by **interior point** (`{ select: [...] }` for `turn-scripted`'s
549
+ * `select`), the address the executor reads them at.
550
+ */
551
+ scripts(nodeKey, value) {
552
+ return this.set(nodeKey, 'scripts', value);
553
+ }
446
554
  /**
447
555
  * The **loadout** this model call runs on โ€” `slot.loadout(id)` or the
448
556
  * id itself. Unlike a connection this is allowed in an author preset: a
@@ -536,6 +644,11 @@ export class SpecBuilder extends ChainBuilder {
536
644
  * .prompts ('generate', { system: LORE_SYSTEM })
537
645
  * .template('prompt', jinja(LORE_ASSEMBLY)))
538
646
  * ```
647
+ * @deprecated โณ Retiring with pipeline configurations (R38, PLAN-layering
648
+ * D5): only a `default: true` preset is read โ€” as the pipeline's declared
649
+ * defaults; declare those with `.defaults(d => โ€ฆ)`. Every other author
650
+ * preset is ignored (`pipelineDefaultsFindings` names it); a preset's
651
+ * registration `values` change a pipeline's defaults instead. Kept to 0.7.
539
652
  * @ruling 12 ยง3a
540
653
  */
541
654
  preset(slug, meta, fn) {
@@ -571,21 +684,105 @@ export class SpecBuilder extends ChainBuilder {
571
684
  return this;
572
685
  }
573
686
  /**
574
- * Exactly one **inlet**, positionally first. Enforced here rather than
575
- * by the validator, so it is a throw at authoring time.
687
+ * ๐Ÿšง The pipeline's **declared defaults** (R38, PLAN-layering D5) โ€” the
688
+ * bottom of the value cascade (`author`): which prompt, template,
689
+ * sampling and loadout each step uses, and its parameters, settings and
690
+ * script chains. Declared after the nodes, so the step keys it names are
691
+ * the ones that exist. A registration's `values` change them per preset
692
+ * or genre; nothing else does (configurations retire).
576
693
  *
577
- * The optional third argument is the **usage lock**: the session
578
- * event this inlet answers and the genre it serves. A session-event spec
579
- * without it does not compile โ€” required for now, and relaxing later
580
- * (`genre: string[]`, `"*"`) is additive, never breaking. **The lock is the
581
- * only subscription**: `.on()` and `subscribes` were deleted
582
- * 2026-09-16 โ€” nothing read them at dispatch.
583
- * @ruling 01 ยง2, 24 ยง4, R-4, 09-B B5
694
+ * ```ts
695
+ * .defaults((d) => d
696
+ * .prompts('generate', { system: STORY_SYSTEM })
697
+ * .sampling('generate', { seedKey: 'sampling-default' }))
698
+ * ```
699
+ * Stored where the shipped default author preset always was
700
+ * (`presets[slug: 'default', default: true]`), so a host reading that
701
+ * keeps reading it.
702
+ * @experimental
703
+ * @ruling R38
584
704
  */
585
- inlet(key, node, binding) {
705
+ defaults(fn) {
706
+ if (this.spec.presets.some((p) => p.default))
707
+ throw new Error(`spec '${this.spec.id}' declares its defaults twice โ€” one .defaults() per pipeline ` +
708
+ `(a default author preset already stands)`);
709
+ // The label the catalogue's default presets already carry, so moving a
710
+ // `.preset('default', { label: 'Default', default: true })` here keeps
711
+ // its document byte for byte.
712
+ return this.preset(DEFAULTS_SLUG, { label: 'Default', default: true }, fn);
713
+ }
714
+ /**
715
+ * ๐Ÿšง The events this pipeline **emits** (R6) โ€” recorded by the host so a
716
+ * registration in any preset of the genre may listen, and so the
717
+ * registration door can refuse a cycle among emitted events (A12). Pass
718
+ * the event objects (`coreEvents.โ€ฆ`, a package's `defineSessionEvent`).
719
+ * Replaces `defineExtension({ events, recordedBy })` for the events a
720
+ * pipeline emits; host moments stay host-published.
721
+ * @experimental
722
+ * @ruling R6, A12
723
+ */
724
+ emits(...events) {
725
+ const ids = events.map((e) => (typeof e === 'string' || isEventDef(e) || isSessionEventDecl(e) ? eventIdOf(e) : e));
726
+ for (const id of ids) {
727
+ if (typeof id !== 'string')
728
+ throw new Error(`spec '${this.spec.id}' .emits(): pass event objects โ€” coreEvents.โ€ฆ, or a package's defineSessionEvent(โ€ฆ)`);
729
+ if (!eventById(id))
730
+ throw new Error(`spec '${this.spec.id}' .emits(): ${notADeclaredEvent(id)}`);
731
+ if (id === sessionEvents.turnOrderChanged)
732
+ throw new Error(TURN_ORDER_CHANGED_IS_INTERNAL);
733
+ }
734
+ this.spec.emits = [...new Set([...(this.spec.emits ?? []), ...ids])];
735
+ return this;
736
+ }
737
+ /**
738
+ * ๐Ÿšง Whether the events a ruleset's functions raise in this pipeline's
739
+ * resolve steps are emitted after its receipt (D3, 2026-10-23). On by
740
+ * default; `.functionEvents(false)` reports them on the steps' facts and
741
+ * emits none, whatever a step's own `emits` parameter says.
742
+ * @experimental
743
+ */
744
+ functionEvents(on) {
745
+ if (on)
746
+ delete this.spec.functionEvents;
747
+ else
748
+ this.spec.functionEvents = false;
749
+ return this;
750
+ }
751
+ inlet(key, node, bindingOrOpts) {
752
+ // ๐Ÿšง The suits form (PLAN-layering D3): no genre, no event โ€” hints only.
753
+ if (bindingOrOpts && !('event' in bindingOrOpts) && !('events' in bindingOrOpts)) {
754
+ if (this.inletDone)
755
+ throw new Error('a spec has exactly one inlet (01 ยง2) โ€” .inlet() may be called once');
756
+ if (this.spec.nodes.length > 0)
757
+ throw new Error('the inlet must be the first node (01 ยง2)');
758
+ for (const k of Object.keys(bindingOrOpts))
759
+ if (k !== 'suits')
760
+ throw new Error(k === 'genre'
761
+ ? `spec '${this.spec.id}' .inlet(): a pipeline names no genre โ€” it is mounted by registrations ` +
762
+ `(register(trigger, spec) in the genre's defaults or a preset). The โณ lock form is { genre, event }`
763
+ : `spec '${this.spec.id}' .inlet(): '${k}' is not an inlet option โ€” { suits: [events] }`);
764
+ const raw = bindingOrOpts.suits ?? [];
765
+ if (!Array.isArray(raw))
766
+ throw new Error(`spec '${this.spec.id}' .inlet(): suits is a list of events`);
767
+ const suits = raw.map((e) => (typeof e === 'string' || isEventDef(e) || isSessionEventDecl(e) ? eventIdOf(e) : e));
768
+ for (const e of suits) {
769
+ if (typeof e !== 'string')
770
+ throw new Error(`spec '${this.spec.id}' .inlet(): suits lists events โ€” coreEvents.โ€ฆ`);
771
+ if (!eventById(e))
772
+ throw new Error(notADeclaredEvent(e));
773
+ if (e === sessionEvents.turnOrderChanged)
774
+ throw new Error(TURN_ORDER_CHANGED_IS_INTERNAL);
775
+ }
776
+ if (new Set(suits).size !== suits.length)
777
+ throw new Error(`spec '${this.spec.id}' .inlet(): suits lists an event twice`);
778
+ this.spec.suits = suits;
779
+ this.inletDone = true;
780
+ return this.add('inlet', key, node);
781
+ }
782
+ let binding = bindingOrOpts;
586
783
  // An event is named by value where a package declared it: its id.
587
784
  if (binding) {
588
- const idOf = (e) => (isSessionEventDecl(e) ? e.id : e);
785
+ const idOf = (e) => (isSessionEventDecl(e) || isEventDef(e) ? eventIdOf(e) : e);
589
786
  binding =
590
787
  'events' in binding
591
788
  ? { ...binding, events: binding.events?.map(idOf) }
@@ -648,6 +845,10 @@ export class SpecBuilder extends ChainBuilder {
648
845
  const genre = genreIdOf(binding.genre);
649
846
  this.spec.input =
650
847
  many !== undefined ? { genre, events: [...many] } : { genre, event: one };
848
+ // โณ The lock's events, read as what the pipeline suits (D3). Not
849
+ // written to the document โ€” `input` already says them, so the
850
+ // hash stays where it was.
851
+ this.spec.suits = many !== undefined ? [...many] : [one];
651
852
  // The genre's other two homes, filled from the lock (R48).
652
853
  const actions = this.spec.meta.contributes?.actions;
653
854
  if (actions?.length) {
@@ -676,16 +877,20 @@ export class SpecBuilder extends ChainBuilder {
676
877
  // Clauses are inherited from ChainBuilder so they nest; re-declared here only so the
677
878
  // spine keeps offering .include() and .build() afterwards.
678
879
  gather(id, opts, fn) {
679
- return super.gather(id, opts, fn);
880
+ super.gather(id, opts, fn);
881
+ return this;
680
882
  }
681
883
  each(id, opts, fn) {
682
- return super.each(id, opts, fn);
884
+ super.each(id, opts, fn);
885
+ return this;
683
886
  }
684
887
  loop(id, opts, fn) {
685
- return super.loop(id, opts, fn);
888
+ super.loop(id, opts, fn);
889
+ return this;
686
890
  }
687
891
  junction(id, opts, fn) {
688
- return super.junction(id, opts, fn);
892
+ super.junction(id, opts, fn);
893
+ return this;
689
894
  }
690
895
  /**
691
896
  * Compile-time include โ€” expanded here, so rows hold the flat chain.
@@ -728,16 +933,48 @@ export class SpecBuilder extends ChainBuilder {
728
933
  return this;
729
934
  }
730
935
  build() {
936
+ // ๐Ÿšง A pipeline mounted by registrations (the suits form) offers its
937
+ // actions where a registration includes them, so they carry no genre
938
+ // (D3). A spec that said nothing at its inlet still needs the lock.
939
+ const unlocked = this.spec.suits !== undefined && !this.spec.input;
731
940
  const orphan = this.spec.meta.contributes?.actions?.find((a) => !a.genre);
732
- if (orphan)
941
+ if (orphan && !unlocked)
733
942
  throw new Error(`spec '${this.spec.id}' contributes action '${orphan.key}' but has no inlet lock โ€” ` +
734
- `an action is offered to the genre of the lock: .inlet(key, node, { genre, event })`);
943
+ `register the action (register(spec.actions.${orphan.key}, spec)) and declare the inlet with ` +
944
+ `{ suits: [ โ€ฆ ] }, or โณ lock it: .inlet(key, node, { genre, event })`);
945
+ // The handles, beside the document and never in it: non-enumerable,
946
+ // so nothing that serializes, hashes or compares a spec sees them.
947
+ Object.defineProperty(this.spec, 'actions', {
948
+ value: Object.freeze(actionHandlesOf(this.spec)),
949
+ enumerable: false,
950
+ configurable: true,
951
+ writable: false,
952
+ });
735
953
  return this.spec;
736
954
  }
737
955
  }
956
+ /** The slug the declared defaults are stored under (`.defaults()`). @internal */
957
+ export const DEFAULTS_SLUG = 'default';
958
+ /**
959
+ * ๐Ÿšง The events a pipeline suits โ€” its document's `suits`, else its โณ
960
+ * lock's events (D3). Hints for pickers only.
961
+ * @experimental
962
+ */
963
+ export function suitsOf(s) {
964
+ if (s.suits)
965
+ return [...s.suits];
966
+ if (s.input?.events?.length)
967
+ return [...s.input.events];
968
+ return s.input?.event ? [s.input.event] : [];
969
+ }
738
970
  /** Stands in for an action's genre until `.inlet()` supplies the lock's. */
739
971
  const PENDING_GENRE = 'pending:genre/lock';
740
- /** @public */
972
+ /**
973
+ * `meta` is `SpecMeta` with each contributed action's `key` captured as `A`
974
+ * โ€” what types `spec.actions.<key>` from the declarations (derive, don't
975
+ * spell). Spelled inline so the frozen signature names no new type.
976
+ * @public
977
+ */
741
978
  export function spec(id, meta) {
742
979
  return new SpecBuilder(id, meta);
743
980
  }