@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,212 @@
1
+ /**
2
+ * World Info parity — testing the claim in 13 §7i.
3
+ *
4
+ * The competitive assessment asserts that every SillyTavern World Info feature "maps into
5
+ * the existing model as params or template logic, not as new mechanisms." That was an
6
+ * untested claim about the most competitively important feature in the product, so this
7
+ * module implements them and the tests check whether it held.
8
+ *
9
+ * Verdict, recorded honestly at the bottom of this file.
10
+ * @experimental
11
+ */
12
+ const matches = (text, key, useRegex, caseSensitive) => {
13
+ if (useRegex) {
14
+ try {
15
+ return new RegExp(key, caseSensitive ? '' : 'i').test(text);
16
+ }
17
+ catch {
18
+ return false;
19
+ }
20
+ }
21
+ const hay = caseSensitive ? text : text.toLowerCase();
22
+ const needle = caseSensitive ? key : key.toLowerCase();
23
+ return hay.includes(needle);
24
+ };
25
+ const primaryHit = (e, text, p) => e.keys.some((k) => matches(text, k, e.useRegex ?? p.useRegex, p.caseSensitive));
26
+ const secondaryOk = (e, text, p) => {
27
+ if (!e.secondary)
28
+ return true;
29
+ const hits = e.secondary.keys.map((k) => matches(text, k, e.useRegex ?? p.useRegex, p.caseSensitive));
30
+ switch (e.secondary.op) {
31
+ case 'AND_ANY':
32
+ return hits.some(Boolean);
33
+ case 'AND_ALL':
34
+ return hits.every(Boolean);
35
+ case 'NOT_ANY':
36
+ return !hits.some(Boolean);
37
+ case 'NOT_ALL':
38
+ return !hits.every(Boolean);
39
+ }
40
+ };
41
+ /**
42
+ * Activation, including bounded recursion.
43
+ *
44
+ * Recursion lives *inside* the Query hook's opaque interior (01 §12.3) and is bounded by a
45
+ * declared param — so it needs no pipeline-level construct and cannot become an unbounded
46
+ * loop. This is the part of the parity claim that held cleanly.
47
+ * @experimental
48
+ */
49
+ export function activate(entries, scanText, p) {
50
+ const scanned = scanText.slice(0, Math.max(0, p.scanDepth)).join('\n');
51
+ const found = new Map();
52
+ const pass = (text, depth) => {
53
+ for (const e of entries) {
54
+ if (found.has(e.id))
55
+ continue;
56
+ if (e.constant) {
57
+ found.set(e.id, { entry: e, depth });
58
+ continue;
59
+ }
60
+ if (primaryHit(e, text, p) && secondaryOk(e, text, p))
61
+ found.set(e.id, { entry: e, depth });
62
+ }
63
+ };
64
+ pass(scanned, 0);
65
+ for (let d = 1; d <= p.recursionDepth; d++) {
66
+ const feed = [...found.values()]
67
+ .filter((f) => f.depth === d - 1 && f.entry.recursable !== false && !f.entry.preventRecursion)
68
+ .map((f) => f.entry.content)
69
+ .join('\n');
70
+ if (!feed)
71
+ break;
72
+ const before = found.size;
73
+ pass(feed, d);
74
+ if (found.size === before)
75
+ break;
76
+ }
77
+ return [...found.values()];
78
+ }
79
+ /** Probability, rolled against the run seed — so it replays, which ST's cannot. @experimental */
80
+ export function rollProbability(hits, random) {
81
+ const kept = [];
82
+ const rolledOut = [];
83
+ for (const { entry } of hits) {
84
+ const p = entry.probability ?? 1;
85
+ if (p >= 1 || random() < p)
86
+ kept.push(entry);
87
+ else
88
+ rolledOut.push(entry.id);
89
+ }
90
+ return { kept, rolledOut };
91
+ }
92
+ /**
93
+ * Inclusion groups: competing entries share a label, and one wins by group weight, with
94
+ * insertion order as the deterministic tiebreak.
95
+ *
96
+ * This is ranking, so it belongs in the rank Task (16 §5c) — no new mechanism.
97
+ * @experimental
98
+ */
99
+ export function resolveGroups(entries, random) {
100
+ const groups = new Map();
101
+ const kept = [];
102
+ for (const e of entries) {
103
+ if (!e.group) {
104
+ kept.push(e);
105
+ continue;
106
+ }
107
+ const g = groups.get(e.group) ?? [];
108
+ g.push(e);
109
+ groups.set(e.group, g);
110
+ }
111
+ const lost = [];
112
+ for (const [, members] of groups) {
113
+ const total = members.reduce((n, m) => n + (m.groupWeight ?? 1), 0);
114
+ let pick = random() * total;
115
+ let winner = members[0];
116
+ for (const m of members) {
117
+ pick -= m.groupWeight ?? 1;
118
+ if (pick <= 0) {
119
+ winner = m;
120
+ break;
121
+ }
122
+ }
123
+ kept.push(winner);
124
+ lost.push(...members.filter((m) => m.id !== winner.id).map((m) => m.id));
125
+ }
126
+ return { kept, lost };
127
+ }
128
+ /**
129
+ * Depth positioning **in a Task** — one of two valid places to do it.
130
+ *
131
+ * ⚠ RETRACTION. An earlier version of this file claimed depth positioning "didn't map" and
132
+ * needed a shape change. That was wrong. **Depth is a context-template concern**, and the
133
+ * assembly template expresses it directly:
134
+ *
135
+ * ```jinja
136
+ * {% for m in messages %}{% set d = loop.revindex %}
137
+ * {% for l in lore %}{% if l.depth == d %}{{ l.rendered }}{% endif %}{% endfor %}
138
+ * {{ m.rendered }}
139
+ * {% endfor %}
140
+ * ```
141
+ *
142
+ * That is tested end to end in use case 41. Nothing about `context-candidates` changes —
143
+ * it already carried `items[]`, which is all the loop needs. The only real requirement is
144
+ * the obvious one: a Query that flattens its messages into a single opaque string forecloses
145
+ * it, so history reaches the template as a list. That is guidance, not a schema change.
146
+ *
147
+ * This function remains as the Task-side alternative, for authors who would rather compute
148
+ * placement than express it in a template.
149
+ * @experimental
150
+ */
151
+ export function assembleWithPositions(history, lore, budget, costOf) {
152
+ const byPriority = (a, b) => {
153
+ const rank = { always: 0, high: 1, normal: 2, low: 3 };
154
+ return rank[a.priority] - rank[b.priority] || a.order - b.order;
155
+ };
156
+ const included = [];
157
+ const dropped = [];
158
+ let spent = 0;
159
+ const admit = (i) => {
160
+ const cost = costOf(i.rendered);
161
+ if (i.priority !== 'always' && spent + cost > budget) {
162
+ dropped.push(i.id);
163
+ return false;
164
+ }
165
+ spent += cost;
166
+ included.push(i.id);
167
+ return true;
168
+ };
169
+ const admittedLore = lore.slice().sort(byPriority).filter(admit);
170
+ const admittedHistory = history.filter(admit);
171
+ // Interleave: this is only possible because history is still a list of items.
172
+ const out = [];
173
+ const before = admittedLore.filter((l) => l.position === 'before_char').sort((a, b) => a.order - b.order);
174
+ const after = admittedLore.filter((l) => l.position === 'after_char').sort((a, b) => a.order - b.order);
175
+ const atDepth = admittedLore.filter((l) => typeof l.position === 'object');
176
+ out.push(...before.map((l) => l.rendered));
177
+ out.push(...after.map((l) => l.rendered));
178
+ const hist = admittedHistory.map((h) => h.rendered);
179
+ for (const l of atDepth.sort((a, b) => b.position.atDepth - a.position.atDepth)) {
180
+ const depth = l.position.atDepth;
181
+ const idx = Math.max(0, hist.length - depth);
182
+ hist.splice(idx, 0, l.rendered);
183
+ }
184
+ out.push(...hist);
185
+ return { text: out.join('\n'), included, dropped };
186
+ }
187
+ /**
188
+ * ── Verdict on 13 §7i's claim ──────────────────────────────────────────────
189
+ *
190
+ * **Seven of seven mapped with no new mechanism.**
191
+ *
192
+ * · regex keys, logic operators, scan depth → params on the trigger Query
193
+ * · recursion → bounded scan inside the Query's interior
194
+ * · constants → priority 'always', honoured before budget
195
+ * · probability → the run seed, and replayable unlike ST's
196
+ * · inclusion groups + group weight → the rank Task, which already existed
197
+ * · insertion order → sort key, or template ordering
198
+ * · positional insertion at chat depth → the assembly template, via a loop over
199
+ * messages with the depth captured by `set`
200
+ *
201
+ * The claim held. An earlier draft of this file reported a shape change was needed; that was
202
+ * my error, corrected after Jody pointed out depth is a templating concern.
203
+ *
204
+ * ── The real parity gap is elsewhere ───────────────────────────────────────
205
+ *
206
+ * **SP's lorebook entries have no `depth` field today.** The pipeline can position by depth
207
+ * the moment an entry carries one — so the work is an entry-schema addition in the lorebook
208
+ * model, not anything in the pipeline architecture. Worth stating precisely, because
209
+ * "positional insertion is missing" and "the architecture can't express it" are very
210
+ * different problems and only the first one is true.
211
+ */
212
+ //# sourceMappingURL=worldinfo.js.map