@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,88 @@
1
+ /**
2
+ * Widgets as a package declares them, and genres as they subtract and lay
3
+ * them out (R71, ruled 2026-09-24).
4
+ *
5
+ * - A **package** — a plugin, or core in `core-catalog` — declares its
6
+ * widgets once (`defineExtension({ widgets })`), each optionally scoped to
7
+ * genres by value (`widget({ genres: [myGenre] })`; absent = every genre).
8
+ * - A **genre** withholds any package's widgets (`omitWidgets`, by value) and
9
+ * ships its layouts (`layouts`, the first its default).
10
+ *
11
+ * A session of a genre is offered every widget scoped to it or to all,
12
+ * minus the genre's `omitWidgets`.
13
+ *
14
+ * **Whose a widget is** is recorded when its package declares it — core's by
15
+ * `core-catalog`, a plugin's by `defineExtension` — so a genre that names
16
+ * another package's widget by value names the id the page knows it by
17
+ * (`widgetRef`): core's bare (`stats`), a plugin's under its package
18
+ * (`acme.dice:tray`, the `pluginWidgetId` grammar).
19
+ */
20
+ import type { WidgetDecl } from './layout.js';
21
+ import { type SessionLayoutV1 } from './sessionLayout.js';
22
+ import { type I18n } from './i18n.js';
23
+ import { type WidgetBaseSection } from './widgets.js';
24
+ /** Record whose widgets these are. Core's `core-catalog` and `defineExtension` call it; nothing else should. @internal */
25
+ export declare function ownWidgets(owner: string, widgets: readonly WidgetDecl[]): void;
26
+ /**
27
+ * Core's widget ids, as far as core's catalogue has been loaded. A package's
28
+ * widget may not take one: a layout names core's widgets and the package's
29
+ * own by bare id, so the two sets never overlap.
30
+ * @experimental
31
+ */
32
+ export declare const coreWidgetIds: () => ReadonlySet<string>;
33
+ /** The package that declared this widget value, if one has. @experimental */
34
+ export declare const widgetOwner: (w: WidgetDecl) => string | undefined;
35
+ /** The id a page, a layout row and a genre's `omitWidgets` know this widget by. @experimental */
36
+ export declare function widgetRef(w: WidgetDecl): string;
37
+ /** A genre as a widget's `genres` names it: the genre value, or `use('<id>')` for one declared elsewhere. @experimental */
38
+ export type GenreLike = {
39
+ readonly id: string;
40
+ };
41
+ /** @experimental */
42
+ export interface WidgetInput extends Omit<WidgetDecl, 'genres'> {
43
+ /** The genres whose sessions offer it, by value. Absent = every genre. */
44
+ genres?: readonly GenreLike[];
45
+ }
46
+ /**
47
+ * The base sections a widget reads (R75): its `reads`, or every base section
48
+ * when it declares none — what its host sends it. A host asks this rather
49
+ * than reading `reads`, so the default lives in one place.
50
+ *
51
+ * Clamped, as a host must clamp what an install stored verbatim: a name that
52
+ * is not a base section (a scoped one, junk) never comes back, and each name
53
+ * comes back once.
54
+ * @experimental
55
+ */
56
+ export declare function widgetReads(w: Pick<WidgetDecl, 'reads'>): readonly WidgetBaseSection[];
57
+ /**
58
+ * What is wrong with a widget's `reads` (R75), one sentence each, each led by
59
+ * `at` (where it was written): a name that is not a base section is refused
60
+ * where it is declared, rather than naming a section the widget would
61
+ * silently never receive.
62
+ * @experimental
63
+ */
64
+ export declare function widgetReadsFindings(reads: unknown, at: string): string[];
65
+ /** Declare a widget — the value a package lists in `widgets` and a genre names in `omitWidgets` or a layout. @experimental */
66
+ export declare function widget(d: WidgetInput): WidgetDecl;
67
+ /**
68
+ * A layout a genre ships (R71): a **session layout** under a slug and a name.
69
+ * The first is the genre's default — its **genre default layout**.
70
+ * @experimental
71
+ */
72
+ export interface GenreLayoutDecl {
73
+ /** Unique within the genre; `default` for the first. */
74
+ slug: string;
75
+ name: I18n;
76
+ description?: I18n;
77
+ /**
78
+ * The session layout, with the widget settings and style pins that come
79
+ * with it. It places widgets by the id the page knows them by —
80
+ * `someWidget.id` for one of this package's, `coreWidgets.x.id` for core's
81
+ * — or a copy of one (`messages#sanctum`); the packager puts a plugin's own
82
+ * widget ids under its namespace.
83
+ */
84
+ preset: SessionLayoutV1;
85
+ }
86
+ /** Declare a layout a genre ships. Refused unless `validateSessionLayout` finds no error in it. @experimental */
87
+ export declare function layout(d: GenreLayoutDecl): GenreLayoutDecl;
88
+ //# sourceMappingURL=widgetDecls.d.ts.map
@@ -0,0 +1,119 @@
1
+ import { validateSessionLayout } from './sessionLayout.js';
2
+ import { i18nFindings } from './i18n.js';
3
+ import { WIDGET_BASE_SECTIONS, isWidgetScopedSectionName } from './widgets.js';
4
+ /**
5
+ * One registry per process, however many copies of the SDK a package's
6
+ * dependencies resolved: a genre that names core's widget from one copy and
7
+ * a core-catalog built against another still agree whose it is.
8
+ */
9
+ const REGISTRY = (globalThis[Symbol.for('serene-pub.widget-owners')] ??= {
10
+ owners: new WeakMap(),
11
+ coreIds: new Set(),
12
+ });
13
+ const OWNERS = REGISTRY.owners;
14
+ /** Record whose widgets these are. Core's `core-catalog` and `defineExtension` call it; nothing else should. @internal */
15
+ export function ownWidgets(owner, widgets) {
16
+ for (const w of widgets) {
17
+ const held = OWNERS.get(w);
18
+ if (held && held !== owner)
19
+ throw new Error(`widget '${w.id}' is already ${held}'s — a widget belongs to the one package that declares it`);
20
+ OWNERS.set(w, owner);
21
+ if (owner === 'core')
22
+ REGISTRY.coreIds.add(w.id);
23
+ }
24
+ }
25
+ /**
26
+ * Core's widget ids, as far as core's catalogue has been loaded. A package's
27
+ * widget may not take one: a layout names core's widgets and the package's
28
+ * own by bare id, so the two sets never overlap.
29
+ * @experimental
30
+ */
31
+ export const coreWidgetIds = () => REGISTRY.coreIds;
32
+ /** The package that declared this widget value, if one has. @experimental */
33
+ export const widgetOwner = (w) => OWNERS.get(w);
34
+ /** The id a page, a layout row and a genre's `omitWidgets` know this widget by. @experimental */
35
+ export function widgetRef(w) {
36
+ const owner = OWNERS.get(w);
37
+ if (!owner)
38
+ throw new Error(`widget '${w?.id}' belongs to no package yet — name a widget value from core (\`coreWidgets\`) ` +
39
+ `or from a package's \`defineExtension({ widgets })\``);
40
+ return owner === 'core' ? w.id : `${owner}:${w.id}`;
41
+ }
42
+ const WIDGET_ID = /^[a-z][a-z0-9-]*$/;
43
+ /**
44
+ * The base sections a widget reads (R75): its `reads`, or every base section
45
+ * when it declares none — what its host sends it. A host asks this rather
46
+ * than reading `reads`, so the default lives in one place.
47
+ *
48
+ * Clamped, as a host must clamp what an install stored verbatim: a name that
49
+ * is not a base section (a scoped one, junk) never comes back, and each name
50
+ * comes back once.
51
+ * @experimental
52
+ */
53
+ export function widgetReads(w) {
54
+ if (!Array.isArray(w?.reads))
55
+ return WIDGET_BASE_SECTIONS;
56
+ return [
57
+ ...new Set(w.reads.filter((name) => WIDGET_BASE_SECTIONS.includes(name))),
58
+ ];
59
+ }
60
+ /**
61
+ * What is wrong with a widget's `reads` (R75), one sentence each, each led by
62
+ * `at` (where it was written): a name that is not a base section is refused
63
+ * where it is declared, rather than naming a section the widget would
64
+ * silently never receive.
65
+ * @experimental
66
+ */
67
+ export function widgetReadsFindings(reads, at) {
68
+ if (reads === undefined)
69
+ return [];
70
+ const names = WIDGET_BASE_SECTIONS.map((s) => `'${s}'`).join(', ');
71
+ if (!Array.isArray(reads))
72
+ return [`${at}: a list of base section names — any of ${names}`];
73
+ const out = [];
74
+ for (const name of reads) {
75
+ if (WIDGET_BASE_SECTIONS.includes(name))
76
+ continue;
77
+ out.push(isWidgetScopedSectionName(name)
78
+ ? `${at}: '${name}' is a scoped section — ask for it in \`scopes\`, never in \`reads\``
79
+ : `${at}: '${String(name)}' is not a base section — one of ${names}`);
80
+ }
81
+ return out;
82
+ }
83
+ /** Declare a widget — the value a package lists in `widgets` and a genre names in `omitWidgets` or a layout. @experimental */
84
+ export function widget(d) {
85
+ const problems = [];
86
+ if (!WIDGET_ID.test(d.id ?? ''))
87
+ problems.push(`'${d.id}' is not a widget id — lowercase letters, digits and '-' (the package supplies the namespace)`);
88
+ problems.push(...i18nFindings(d.title, `widget '${d.id}' title`, { required: true }));
89
+ if (typeof d.component !== 'string' || !d.component)
90
+ problems.push(`widget '${d.id}' names no component — give \`component\`, the slug of a component this package declares`);
91
+ if (d.surface !== undefined)
92
+ problems.push(`widget '${d.id}': \`surface\` is gone — name a component, and place an \`sp-frame\` inside it for a document`);
93
+ problems.push(...widgetReadsFindings(d.reads, `widget '${d.id}' reads`));
94
+ if (d.maxInstances !== undefined && !(Number.isInteger(d.maxInstances) && d.maxInstances > 0))
95
+ problems.push(`widget '${d.id}' maxInstances: a positive whole number, or leave it out for no cap`);
96
+ const genres = d.genres?.map((g) => g?.id);
97
+ if (genres?.some((g) => typeof g !== 'string' || !g))
98
+ problems.push(`widget '${d.id}' genres: each is a genre value (or use('<id>')), never a bare string`);
99
+ if (problems.length)
100
+ throw new Error(problems.join('\n'));
101
+ const { genres: _g, ...rest } = d;
102
+ return Object.freeze({ ...rest, ...(genres?.length ? { genres: [...new Set(genres)] } : {}) });
103
+ }
104
+ const LAYOUT_SLUG = /^[a-z][a-z0-9-]*$/;
105
+ /** Declare a layout a genre ships. Refused unless `validateSessionLayout` finds no error in it. @experimental */
106
+ export function layout(d) {
107
+ const problems = [];
108
+ if (!LAYOUT_SLUG.test(d.slug ?? ''))
109
+ problems.push(`'${d.slug}' is not a layout slug — lowercase letters, digits and '-'`);
110
+ problems.push(...i18nFindings(d.name, `layout '${d.slug}' name`, { required: true }));
111
+ problems.push(...i18nFindings(d.description, `layout '${d.slug}' description`));
112
+ const verdict = validateSessionLayout(d.preset);
113
+ for (const e of verdict.errors)
114
+ problems.push(`layout '${d.slug}' preset: ${e}`);
115
+ if (problems.length)
116
+ throw new Error(problems.join('\n'));
117
+ return Object.freeze({ ...d });
118
+ }
119
+ //# sourceMappingURL=widgetDecls.js.map