@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,130 @@
1
+ /**
2
+ * The **prompt blocks** a context template is assembled from, as a configurable
3
+ * ordered list rather than an order frozen into the template's source.
4
+ *
5
+ * SillyTavern calls this a preset's *prompt list*; the ruling of 2026-09-10
6
+ * calls it the `blocks` param and puts it exactly where a preset's other
7
+ * decisions live — inside the pipeline configuration the preset selects, on the
8
+ * assembly node that renders the prompt. Not a session setting, not a table:
9
+ * "which sections are in the prompt, in what order" is the same kind of fact as
10
+ * "which prompt does this step use", and it is an administrator's.
11
+ *
12
+ * ## ⚠ A third sense of the word `block`
13
+ *
14
+ * NOMENCLATURE §15 says a **block** is one message — `system`, `user`,
15
+ * `assistant`. The pipeline container that used to share the word is a
16
+ * **clause** since 2026-09-15 (R-14), which took one sense off the pile. This
17
+ * is another: one **section within** a prompt, named by the template variable
18
+ * that renders it. The word is the ruling's, so it is used here and recorded
19
+ * there rather than quietly replaced with a fresh invention. Say **prompt
20
+ * block** in prose; the bare word still means a message.
21
+ *
22
+ * ## What this module is, and is not
23
+ *
24
+ * It is the declaration and the pure resolution: the shipped order, the field
25
+ * declaration a panel renders, and the arithmetic that turns *what an admin
26
+ * configured* plus *what a template actually produces* into an effective order
27
+ * with its receipt. It renders nothing and knows no template syntax — which
28
+ * template variables a given story string produces is a question only that
29
+ * template's engine can answer, and the host asks it.
30
+ */
31
+ import type { FieldDecl } from './settings.js';
32
+ /**
33
+ * One entry in the pack: a block, and whether it is in.
34
+ *
35
+ * `enabled` is separate from membership on purpose. Removing an entry and
36
+ * switching it off are different acts — the first forgets where it sat, the
37
+ * second keeps its place — and a list that could only express the first would
38
+ * make "turn the lore off for a moment" destroy the ordering somebody tuned.
39
+ * @experimental
40
+ */
41
+ export interface PromptBlockEntry {
42
+ /** The template variable that renders this section — `worldLore`, `history`. */
43
+ id: string;
44
+ /** Absent means in. Only an explicit `false` takes a block out. */
45
+ enabled?: boolean;
46
+ }
47
+ /**
48
+ * The blocks Serene Pub's shipped context template renders, **in its order**.
49
+ *
50
+ * This list and that template are one fact stated twice, which is a thing worth
51
+ * being uncomfortable about: the template is a seeded row an install may have
52
+ * replaced, and this is a declaration. They are held in step by a test in the
53
+ * host that reads the shipped template and asserts this order — so the
54
+ * declared default cannot drift from the prompt a fresh install actually gets.
55
+ *
56
+ * Order is the 0.5 prompt's order, with `characterLore` under the cards it is
57
+ * about — and `currentDate` LAST (B2, 2026-10-03), not first: the top of the
58
+ * prompt is what a backend's cache reuses from turn to turn, and the date is
59
+ * the one system-block value that changes on its own. Do not tidy it: every
60
+ * entry's position is a byte in every prompt on every install that has
61
+ * changed nothing.
62
+ * @internal
63
+ */
64
+ export declare const SHIPPED_PROMPT_BLOCK_IDS: readonly ['instructions', 'characters', 'personas', 'characterLore', 'scenario', 'worldLore', 'history', 'relationshipsPerspectives', 'relationshipsKnown', 'currentDate'];
65
+ /** @experimental */
66
+ export type ShippedPromptBlockId = (typeof SHIPPED_PROMPT_BLOCK_IDS)[number];
67
+ /**
68
+ * The declared default: every shipped block, in the shipped order, all on.
69
+ *
70
+ * Being the **declared** default is what makes this cost nothing to store. A
71
+ * configuration holds deviations only, so until somebody reorders or switches
72
+ * one off there is no row anywhere and the pack is whatever this says — which
73
+ * is also what lets the shipped order be corrected in a release rather than
74
+ * swept through every install's rows.
75
+ * @internal
76
+ */
77
+ export declare const SHIPPED_PROMPT_BLOCKS: readonly PromptBlockEntry[];
78
+ /**
79
+ * The param, declared once and shared by the contract and the panel.
80
+ *
81
+ * ⚠ `of` on the `id` member is what the **picker offers**, not what the runtime
82
+ * accepts. A context template may render a variable no declaration here
83
+ * enumerates — a plugin's, or one an admin wrote — and an id this list does not
84
+ * carry is honoured if the template produces it and reported on the receipt if
85
+ * it does not (`resolvePromptBlocks`). A refusal there would turn "I switched
86
+ * my pipeline's template" into a run that stops.
87
+ * @experimental
88
+ */
89
+ export declare const PROMPT_BLOCKS_DECL: FieldDecl;
90
+ /**
91
+ * Is this value the shipped pack, entry for entry?
92
+ *
93
+ * The host's identity test, and the reason it is worth exporting rather than
94
+ * inlining: **the shipped pack means "leave the template alone"**, not "reorder
95
+ * the template into this order". Those are the same thing for the template
96
+ * Serene Pub ships and are emphatically not the same thing for one somebody
97
+ * wrote, whose sections may sit in an order they chose. Treating the default as
98
+ * an instruction would silently rewrite every custom template on first run.
99
+ * @internal
100
+ */
101
+ export declare function isShippedPromptBlocks(value: unknown): boolean;
102
+ /** What a resolution decided, and what the receipt says about it. @experimental */
103
+ export interface ResolvedPromptBlocks {
104
+ /** The effective order: block ids, as they will be rendered. */
105
+ order: string[];
106
+ /** Configured, but this template renders no such block. Ignored, not refused. */
107
+ unknown: string[];
108
+ /** Rendered by the template, left out by the pack — switched off, or not listed. */
109
+ dropped: string[];
110
+ /** Whether the effective order departs from what the template already had. */
111
+ changed: boolean;
112
+ }
113
+ /**
114
+ * The pack, applied to what a template actually produces.
115
+ *
116
+ * Pure, total, and refuses nothing. Three rules, in this order:
117
+ *
118
+ * · an entry the template does not produce is **ignored**, and named on the
119
+ * receipt — a template swap must not stop a turn;
120
+ * · an entry with `enabled: false`, and a produced block the pack does not
121
+ * list at all, are both **out** — but they are reported apart from each
122
+ * other nowhere, because from the prompt's side they are the same absence;
123
+ * · everything else renders in the pack's order.
124
+ *
125
+ * A duplicate id keeps its first position and is dropped thereafter: a block is
126
+ * one section, and rendering it twice is not a thing the list can mean.
127
+ * @internal
128
+ */
129
+ export declare function resolvePromptBlocks(configured: unknown, produced: readonly string[]): ResolvedPromptBlocks;
130
+ //# sourceMappingURL=promptBlocks.d.ts.map
@@ -0,0 +1,197 @@
1
+ /**
2
+ * The **prompt blocks** a context template is assembled from, as a configurable
3
+ * ordered list rather than an order frozen into the template's source.
4
+ *
5
+ * SillyTavern calls this a preset's *prompt list*; the ruling of 2026-09-10
6
+ * calls it the `blocks` param and puts it exactly where a preset's other
7
+ * decisions live — inside the pipeline configuration the preset selects, on the
8
+ * assembly node that renders the prompt. Not a session setting, not a table:
9
+ * "which sections are in the prompt, in what order" is the same kind of fact as
10
+ * "which prompt does this step use", and it is an administrator's.
11
+ *
12
+ * ## ⚠ A third sense of the word `block`
13
+ *
14
+ * NOMENCLATURE §15 says a **block** is one message — `system`, `user`,
15
+ * `assistant`. The pipeline container that used to share the word is a
16
+ * **clause** since 2026-09-15 (R-14), which took one sense off the pile. This
17
+ * is another: one **section within** a prompt, named by the template variable
18
+ * that renders it. The word is the ruling's, so it is used here and recorded
19
+ * there rather than quietly replaced with a fresh invention. Say **prompt
20
+ * block** in prose; the bare word still means a message.
21
+ *
22
+ * ## What this module is, and is not
23
+ *
24
+ * It is the declaration and the pure resolution: the shipped order, the field
25
+ * declaration a panel renders, and the arithmetic that turns *what an admin
26
+ * configured* plus *what a template actually produces* into an effective order
27
+ * with its receipt. It renders nothing and knows no template syntax — which
28
+ * template variables a given story string produces is a question only that
29
+ * template's engine can answer, and the host asks it.
30
+ */
31
+ /**
32
+ * The blocks Serene Pub's shipped context template renders, **in its order**.
33
+ *
34
+ * This list and that template are one fact stated twice, which is a thing worth
35
+ * being uncomfortable about: the template is a seeded row an install may have
36
+ * replaced, and this is a declaration. They are held in step by a test in the
37
+ * host that reads the shipped template and asserts this order — so the
38
+ * declared default cannot drift from the prompt a fresh install actually gets.
39
+ *
40
+ * Order is the 0.5 prompt's order, with `characterLore` under the cards it is
41
+ * about — and `currentDate` LAST (B2, 2026-10-03), not first: the top of the
42
+ * prompt is what a backend's cache reuses from turn to turn, and the date is
43
+ * the one system-block value that changes on its own. Do not tidy it: every
44
+ * entry's position is a byte in every prompt on every install that has
45
+ * changed nothing.
46
+ * @internal
47
+ */
48
+ export const SHIPPED_PROMPT_BLOCK_IDS = [
49
+ 'instructions',
50
+ 'characters',
51
+ 'personas',
52
+ 'characterLore',
53
+ 'scenario',
54
+ 'worldLore',
55
+ 'history',
56
+ 'relationshipsPerspectives',
57
+ 'relationshipsKnown',
58
+ 'currentDate',
59
+ ];
60
+ /** What a person reads in the list editor, in the declaration rather than the client. */
61
+ const BLOCK_LABELS = {
62
+ currentDate: 'Current date',
63
+ instructions: 'Instructions',
64
+ characters: 'Characters',
65
+ personas: 'Personas',
66
+ characterLore: 'Character lore',
67
+ scenario: 'Scenario',
68
+ worldLore: 'World lore',
69
+ history: 'History',
70
+ relationshipsPerspectives: 'Relationships — their view',
71
+ relationshipsKnown: 'Relationships — how others see them',
72
+ };
73
+ const BLOCK_MEMBERS = SHIPPED_PROMPT_BLOCK_IDS.map((key) => ({
74
+ key,
75
+ label: { en: BLOCK_LABELS[key] },
76
+ }));
77
+ /**
78
+ * The declared default: every shipped block, in the shipped order, all on.
79
+ *
80
+ * Being the **declared** default is what makes this cost nothing to store. A
81
+ * configuration holds deviations only, so until somebody reorders or switches
82
+ * one off there is no row anywhere and the pack is whatever this says — which
83
+ * is also what lets the shipped order be corrected in a release rather than
84
+ * swept through every install's rows.
85
+ * @internal
86
+ */
87
+ export const SHIPPED_PROMPT_BLOCKS = SHIPPED_PROMPT_BLOCK_IDS.map((id) => ({ id, enabled: true }));
88
+ /**
89
+ * The param, declared once and shared by the contract and the panel.
90
+ *
91
+ * ⚠ `of` on the `id` member is what the **picker offers**, not what the runtime
92
+ * accepts. A context template may render a variable no declaration here
93
+ * enumerates — a plugin's, or one an admin wrote — and an id this list does not
94
+ * carry is honoured if the template produces it and reported on the receipt if
95
+ * it does not (`resolvePromptBlocks`). A refusal there would turn "I switched
96
+ * my pipeline's template" into a run that stops.
97
+ * @experimental
98
+ */
99
+ export const PROMPT_BLOCKS_DECL = {
100
+ type: 'list',
101
+ label: { en: 'Prompt blocks' },
102
+ description: {
103
+ en: 'Which sections the prompt is built from, and in what order. Blocks the selected context template does not render are ignored.',
104
+ },
105
+ default: SHIPPED_PROMPT_BLOCKS,
106
+ item: {
107
+ type: 'object',
108
+ fields: {
109
+ id: {
110
+ type: 'enum',
111
+ label: { en: 'Block' },
112
+ of: SHIPPED_PROMPT_BLOCK_IDS,
113
+ members: BLOCK_MEMBERS,
114
+ },
115
+ enabled: {
116
+ type: 'boolean',
117
+ label: { en: 'In the prompt' },
118
+ default: true,
119
+ },
120
+ },
121
+ },
122
+ };
123
+ /**
124
+ * Is this value the shipped pack, entry for entry?
125
+ *
126
+ * The host's identity test, and the reason it is worth exporting rather than
127
+ * inlining: **the shipped pack means "leave the template alone"**, not "reorder
128
+ * the template into this order". Those are the same thing for the template
129
+ * Serene Pub ships and are emphatically not the same thing for one somebody
130
+ * wrote, whose sections may sit in an order they chose. Treating the default as
131
+ * an instruction would silently rewrite every custom template on first run.
132
+ * @internal
133
+ */
134
+ export function isShippedPromptBlocks(value) {
135
+ if (!Array.isArray(value))
136
+ return false;
137
+ if (value.length !== SHIPPED_PROMPT_BLOCKS.length)
138
+ return false;
139
+ return value.every((entry, i) => {
140
+ const e = entry;
141
+ if (!e || typeof e !== 'object')
142
+ return false;
143
+ return e.id === SHIPPED_PROMPT_BLOCKS[i].id && e.enabled !== false;
144
+ });
145
+ }
146
+ /**
147
+ * The pack, applied to what a template actually produces.
148
+ *
149
+ * Pure, total, and refuses nothing. Three rules, in this order:
150
+ *
151
+ * · an entry the template does not produce is **ignored**, and named on the
152
+ * receipt — a template swap must not stop a turn;
153
+ * · an entry with `enabled: false`, and a produced block the pack does not
154
+ * list at all, are both **out** — but they are reported apart from each
155
+ * other nowhere, because from the prompt's side they are the same absence;
156
+ * · everything else renders in the pack's order.
157
+ *
158
+ * A duplicate id keeps its first position and is dropped thereafter: a block is
159
+ * one section, and rendering it twice is not a thing the list can mean.
160
+ * @internal
161
+ */
162
+ export function resolvePromptBlocks(configured, produced) {
163
+ if (!Array.isArray(configured))
164
+ return { order: [...produced], unknown: [], dropped: [], changed: false };
165
+ const producible = new Set(produced);
166
+ const order = [];
167
+ const unknown = [];
168
+ const seen = new Set();
169
+ for (const raw of configured) {
170
+ const entry = raw;
171
+ if (!entry || typeof entry !== 'object' || typeof entry.id !== 'string')
172
+ continue;
173
+ if (seen.has(entry.id))
174
+ continue;
175
+ seen.add(entry.id);
176
+ if (!producible.has(entry.id)) {
177
+ // Reported whether or not it was switched off: "this pipeline names
178
+ // a block its template has never heard of" is the same fact either
179
+ // way, and staying quiet about the disabled half would make the
180
+ // notice appear the moment somebody toggled it.
181
+ unknown.push(entry.id);
182
+ continue;
183
+ }
184
+ if (entry.enabled === false)
185
+ continue;
186
+ order.push(entry.id);
187
+ }
188
+ const included = new Set(order);
189
+ const dropped = produced.filter((id) => !included.has(id));
190
+ return {
191
+ order,
192
+ unknown,
193
+ dropped,
194
+ changed: dropped.length > 0 || order.some((id, i) => produced[i] !== id),
195
+ };
196
+ }
197
+ //# sourceMappingURL=promptBlocks.js.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Ranking decisions (PLAN-sdk-1.0 §3.9, R64): what a ranker says about each
3
+ * candidate it judged. A node that publishes an array of these on a port of
4
+ * shape `core:shape/decisions@1` (`S.decisions`) has them recorded by the
5
+ * host automatically — nothing else to opt into.
6
+ *
7
+ * Required per decision: `included` and a `reason` code, and something that
8
+ * says WHAT was judged — a `subject` (`{ kind, id }`: `lore-entry` is core's;
9
+ * a package names its own kinds `<slug>:<kind>`), or core's own `candidate`
10
+ * object, from which the host derives the subject. Optional: `score`,
11
+ * `rank`, `tokens`, `why` (a sentence or two) and `detail` (ranker-specific
12
+ * facts, bounded).
13
+ *
14
+ * A decision with no derivable subject (a message or relationship band) is
15
+ * counted on its ranking, not stored.
16
+ */
17
+ /** The shape id a decisions port carries. @experimental */
18
+ export declare const DECISIONS_SHAPE = "core:shape/decisions@1";
19
+ /** Core's subject kind for a lorebook entry. @experimental */
20
+ export declare const LORE_ENTRY_SUBJECT = "lore-entry";
21
+ /** At most this many decisions are stored per ranking; the rest are counted and noted. @experimental */
22
+ export declare const MAX_DECISIONS_PER_RANKING = 2000;
23
+ /** At most this many bytes of `detail` per decision, serialized; larger is dropped and noted. @experimental */
24
+ export declare const MAX_DECISION_DETAIL_BYTES = 2048;
25
+ /** @experimental */
26
+ export interface RankingSubject {
27
+ /** `lore-entry`, or a package's own `<slug>:<kind>`. */
28
+ kind: string;
29
+ id: string | number;
30
+ }
31
+ /** @experimental */
32
+ export interface RankingDecisionV1 {
33
+ subject?: RankingSubject;
34
+ /** Core's rankers publish the candidate they judged; the host derives the subject from it. */
35
+ candidate?: {
36
+ id: string | number;
37
+ source?: string;
38
+ tokens?: number;
39
+ payload?: unknown;
40
+ [k: string]: unknown;
41
+ };
42
+ included: boolean;
43
+ /** A short code: core's closed set, or `<slug>:<code>` for a package's own. */
44
+ reason: string;
45
+ score?: number;
46
+ rank?: number;
47
+ tokens?: number;
48
+ why?: string;
49
+ detail?: Record<string, unknown>;
50
+ }
51
+ /** Why a subject kind is not one a decision may carry, or undefined. @internal */
52
+ export declare function subjectKindFindings(kind: unknown): string | undefined;
53
+ /**
54
+ * One decision, checked. For a custom ranker: `decision({ subject: { kind:
55
+ * 'acme.dice:roll', id: 7 }, included: true, reason: 'acme.dice:rolled-high',
56
+ * score: 0.9, why: 'Rolled a 19.' })`.
57
+ * @experimental
58
+ */
59
+ export declare function decision(d: RankingDecisionV1): RankingDecisionV1;
60
+ //# sourceMappingURL=rankingDecisions.d.ts.map
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Ranking decisions (PLAN-sdk-1.0 §3.9, R64): what a ranker says about each
3
+ * candidate it judged. A node that publishes an array of these on a port of
4
+ * shape `core:shape/decisions@1` (`S.decisions`) has them recorded by the
5
+ * host automatically — nothing else to opt into.
6
+ *
7
+ * Required per decision: `included` and a `reason` code, and something that
8
+ * says WHAT was judged — a `subject` (`{ kind, id }`: `lore-entry` is core's;
9
+ * a package names its own kinds `<slug>:<kind>`), or core's own `candidate`
10
+ * object, from which the host derives the subject. Optional: `score`,
11
+ * `rank`, `tokens`, `why` (a sentence or two) and `detail` (ranker-specific
12
+ * facts, bounded).
13
+ *
14
+ * A decision with no derivable subject (a message or relationship band) is
15
+ * counted on its ranking, not stored.
16
+ */
17
+ /** The shape id a decisions port carries. @experimental */
18
+ export const DECISIONS_SHAPE = 'core:shape/decisions@1';
19
+ /** Core's subject kind for a lorebook entry. @experimental */
20
+ export const LORE_ENTRY_SUBJECT = 'lore-entry';
21
+ /** At most this many decisions are stored per ranking; the rest are counted and noted. @experimental */
22
+ export const MAX_DECISIONS_PER_RANKING = 2000;
23
+ /** At most this many bytes of `detail` per decision, serialized; larger is dropped and noted. @experimental */
24
+ export const MAX_DECISION_DETAIL_BYTES = 2048;
25
+ const SUBJECT_KIND = /^(?:lore-entry|[a-z0-9]+(?:[.-][a-z0-9]+)*:[a-z0-9]+(?:-[a-z0-9]+)*)$/;
26
+ /** Why a subject kind is not one a decision may carry, or undefined. @internal */
27
+ export function subjectKindFindings(kind) {
28
+ if (typeof kind !== 'string' || !SUBJECT_KIND.test(kind))
29
+ return `'${String(kind)}' is not a subject kind — use '${LORE_ENTRY_SUBJECT}', or your package's own '<slug>:<kind>'`;
30
+ return undefined;
31
+ }
32
+ /**
33
+ * One decision, checked. For a custom ranker: `decision({ subject: { kind:
34
+ * 'acme.dice:roll', id: 7 }, included: true, reason: 'acme.dice:rolled-high',
35
+ * score: 0.9, why: 'Rolled a 19.' })`.
36
+ * @experimental
37
+ */
38
+ export function decision(d) {
39
+ if (d.subject) {
40
+ const bad = subjectKindFindings(d.subject.kind);
41
+ if (bad)
42
+ throw new Error(bad);
43
+ }
44
+ if (typeof d.reason !== 'string' || !d.reason)
45
+ throw new Error('a decision needs a reason code');
46
+ return d;
47
+ }
48
+ //# sourceMappingURL=rankingDecisions.js.map