@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.
- package/dist/actions.d.ts +52 -2
- package/dist/actions.js +56 -6
- package/dist/annexFields.d.ts +32 -2
- package/dist/annexFields.js +48 -5
- package/dist/announce.d.ts +142 -2
- package/dist/announce.js +198 -2
- package/dist/attributes.d.ts +331 -6
- package/dist/attributes.js +339 -27
- package/dist/bridges.d.ts +61 -0
- package/dist/bridges.js +112 -0
- package/dist/builder.d.ts +278 -51
- package/dist/builder.js +267 -30
- package/dist/cadences.d.ts +585 -0
- package/dist/cadences.js +1118 -0
- package/dist/capabilities.d.ts +106 -17
- package/dist/capabilities.js +85 -7
- package/dist/checkMethods.d.ts +240 -0
- package/dist/checkMethods.js +362 -0
- package/dist/component.d.ts +6 -1
- package/dist/componentClient.d.ts +42 -6
- package/dist/componentWire.js +22 -4
- package/dist/composerStates.d.ts +96 -0
- package/dist/composerStates.js +190 -0
- package/dist/conditions.d.ts +424 -0
- package/dist/conditions.js +521 -0
- package/dist/config.d.ts +42 -6
- package/dist/config.js +48 -20
- package/dist/conversions.d.ts +41 -0
- package/dist/conversions.js +50 -0
- package/dist/declarations.d.ts +40 -2
- package/dist/declarations.js +178 -10
- package/dist/descriptors.d.ts +287 -4
- package/dist/descriptors.js +281 -18
- package/dist/document.d.ts +47 -2
- package/dist/document.js +46 -14
- package/dist/entities.d.ts +156 -0
- package/dist/entities.js +259 -0
- package/dist/events.d.ts +711 -1
- package/dist/events.js +412 -1
- package/dist/executor.d.ts +4 -3
- package/dist/executor.js +22 -8
- package/dist/exposure.d.ts +128 -0
- package/dist/exposure.js +168 -0
- package/dist/extension.d.ts +127 -3
- package/dist/extension.js +43 -0
- package/dist/fit.d.ts +198 -0
- package/dist/fit.js +351 -0
- package/dist/functions.d.ts +554 -0
- package/dist/functions.js +712 -0
- package/dist/genres.d.ts +303 -89
- package/dist/genres.js +335 -100
- package/dist/hookGrants.d.ts +15 -1
- package/dist/hookGrants.js +11 -10
- package/dist/hooks.d.ts +34 -5
- package/dist/hooks.js +5 -2
- package/dist/hostElements.d.ts +7 -1
- package/dist/hostElements.js +20 -1
- package/dist/hostState.d.ts +110 -0
- package/dist/hostState.js +140 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +25 -0
- package/dist/index.js +48 -0
- package/dist/jsonSchema.d.ts +178 -0
- package/dist/jsonSchema.js +570 -0
- package/dist/libraryDraft.d.ts +27 -0
- package/dist/libraryDraft.js +25 -0
- package/dist/lorebookFile.d.ts +44 -0
- package/dist/lorebookFile.js +202 -0
- package/dist/media.d.ts +127 -12
- package/dist/media.js +45 -1
- package/dist/messageBlocks.d.ts +179 -5
- package/dist/messageBlocks.js +208 -6
- package/dist/participants.d.ts +32 -9
- package/dist/participants.js +13 -2
- package/dist/pluginHarness.d.ts +63 -33
- package/dist/pluginHarness.js +78 -144
- package/dist/pluginPermissions.d.ts +15 -1
- package/dist/pluginPermissions.js +29 -2
- package/dist/preview.d.ts +45 -4
- package/dist/preview.js +52 -12
- package/dist/primers.d.ts +177 -0
- package/dist/primers.js +265 -0
- package/dist/receipt.d.ts +11 -0
- package/dist/receiverRules.js +9 -0
- package/dist/refs.d.ts +9 -1
- package/dist/refs.js +12 -0
- package/dist/registrations.d.ts +384 -0
- package/dist/registrations.js +625 -0
- package/dist/repertoires.d.ts +502 -0
- package/dist/repertoires.js +666 -0
- package/dist/rulesetDocument.d.ts +116 -0
- package/dist/rulesetDocument.js +252 -0
- package/dist/rulesetSections.d.ts +631 -0
- package/dist/rulesetSections.js +1288 -0
- package/dist/rulesetTemplates.d.ts +161 -0
- package/dist/rulesetTemplates.js +242 -0
- package/dist/rulesets.d.ts +899 -0
- package/dist/rulesets.js +1378 -0
- package/dist/sceneSettings.d.ts +8 -0
- package/dist/sceneSettings.js +10 -2
- package/dist/scope.d.ts +44 -3
- package/dist/scope.js +18 -0
- package/dist/scripts.d.ts +31 -8
- package/dist/scripts.js +45 -8
- package/dist/sessionDossier.d.ts +157 -7
- package/dist/sessionLayout.d.ts +291 -138
- package/dist/sessionLayout.js +504 -211
- package/dist/sessionSettings.d.ts +24 -0
- package/dist/settings.d.ts +95 -4
- package/dist/settings.js +293 -4
- package/dist/shapes.d.ts +80 -1
- package/dist/shapes.js +100 -5
- package/dist/speech.d.ts +333 -0
- package/dist/speech.js +199 -0
- package/dist/statShapes.d.ts +8 -1
- package/dist/statShapes.js +8 -1
- package/dist/status.d.ts +14 -0
- package/dist/status.js +12 -0
- package/dist/storage.d.ts +53 -66
- package/dist/storage.js +7 -12
- package/dist/storyTime.d.ts +25 -1
- package/dist/storyTime.js +42 -2
- package/dist/surfaces.d.ts +15 -2
- package/dist/template.d.ts +19 -1
- package/dist/template.js +25 -11
- package/dist/templateScopeAt.d.ts +1 -1
- package/dist/templateScopeAt.js +11 -8
- package/dist/ties.d.ts +211 -0
- package/dist/ties.js +301 -0
- package/dist/turnOrder.d.ts +25 -14
- package/dist/turnOrder.js +21 -8
- package/dist/userAnnex.d.ts +126 -0
- package/dist/userAnnex.js +214 -0
- package/dist/validate.js +114 -19
- package/dist/values.js +6 -0
- package/dist/vocabularies.d.ts +192 -0
- package/dist/vocabularies.js +326 -0
- package/dist/widgetDecls.d.ts +12 -0
- package/dist/widgetDecls.js +2 -0
- package/dist/widgets.d.ts +1062 -29
- package/dist/widgets.js +218 -3
- package/host-elements.d.ts +90 -0
- 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
|
-
*
|
|
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, {
|
|
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
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
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
|
-
/**
|
|
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] = {
|
|
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,
|
|
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
|
-
*
|
|
575
|
-
*
|
|
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
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
*
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
880
|
+
super.gather(id, opts, fn);
|
|
881
|
+
return this;
|
|
680
882
|
}
|
|
681
883
|
each(id, opts, fn) {
|
|
682
|
-
|
|
884
|
+
super.each(id, opts, fn);
|
|
885
|
+
return this;
|
|
683
886
|
}
|
|
684
887
|
loop(id, opts, fn) {
|
|
685
|
-
|
|
888
|
+
super.loop(id, opts, fn);
|
|
889
|
+
return this;
|
|
686
890
|
}
|
|
687
891
|
junction(id, opts, fn) {
|
|
688
|
-
|
|
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
|
-
`
|
|
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
|
-
/**
|
|
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
|
}
|