@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.
- package/LICENSE +202 -0
- package/NOTICE +17 -0
- package/README.md +368 -0
- package/dist/actions.d.ts +572 -0
- package/dist/actions.js +829 -0
- package/dist/annexFields.d.ts +234 -0
- package/dist/annexFields.js +413 -0
- package/dist/announce.d.ts +464 -0
- package/dist/announce.js +426 -0
- package/dist/attributes.d.ts +670 -0
- package/dist/attributes.js +904 -0
- package/dist/bands.d.ts +125 -0
- package/dist/bands.js +256 -0
- package/dist/builder.d.ts +683 -0
- package/dist/builder.js +677 -0
- package/dist/candidates.d.ts +109 -0
- package/dist/candidates.js +118 -0
- package/dist/capabilities.d.ts +744 -0
- package/dist/capabilities.js +679 -0
- package/dist/channels.d.ts +106 -0
- package/dist/channels.js +129 -0
- package/dist/clauses.d.ts +40 -0
- package/dist/clauses.js +43 -0
- package/dist/component.d.ts +33 -0
- package/dist/component.js +27 -0
- package/dist/componentBuild.d.ts +48 -0
- package/dist/componentBuild.js +84 -0
- package/dist/componentClient.d.ts +100 -0
- package/dist/componentClient.js +13 -0
- package/dist/componentImports.d.ts +51 -0
- package/dist/componentImports.js +106 -0
- package/dist/componentModule.d.ts +8 -0
- package/dist/componentModule.js +270 -0
- package/dist/componentWire.d.ts +130 -0
- package/dist/componentWire.js +280 -0
- package/dist/config.d.ts +295 -0
- package/dist/config.js +231 -0
- package/dist/connections.d.ts +89 -0
- package/dist/connections.js +131 -0
- package/dist/declarations.d.ts +290 -0
- package/dist/declarations.js +794 -0
- package/dist/descriptors.d.ts +1774 -0
- package/dist/descriptors.js +1329 -0
- package/dist/dev.d.ts +136 -0
- package/dist/dev.js +161 -0
- package/dist/document.d.ts +202 -0
- package/dist/document.js +312 -0
- package/dist/engines.d.ts +117 -0
- package/dist/engines.js +203 -0
- package/dist/eventMapLaws.d.ts +63 -0
- package/dist/eventMapLaws.js +128 -0
- package/dist/events.d.ts +554 -0
- package/dist/events.js +633 -0
- package/dist/executor.d.ts +771 -0
- package/dist/executor.js +1829 -0
- package/dist/extension.d.ts +448 -0
- package/dist/extension.js +315 -0
- package/dist/facets.d.ts +53 -0
- package/dist/facets.js +60 -0
- package/dist/foldedSections.d.ts +74 -0
- package/dist/foldedSections.js +161 -0
- package/dist/genres.d.ts +507 -0
- package/dist/genres.js +633 -0
- package/dist/guardedConnection.d.ts +138 -0
- package/dist/guardedConnection.js +341 -0
- package/dist/handlebarsReach.d.ts +122 -0
- package/dist/handlebarsReach.js +222 -0
- package/dist/hash.d.ts +146 -0
- package/dist/hash.js +166 -0
- package/dist/hookGrants.d.ts +47 -0
- package/dist/hookGrants.js +68 -0
- package/dist/hooks.d.ts +290 -0
- package/dist/hooks.js +113 -0
- package/dist/hostElements.d.ts +447 -0
- package/dist/hostElements.js +702 -0
- package/dist/i18n.d.ts +94 -0
- package/dist/i18n.js +123 -0
- package/dist/identity.d.ts +93 -0
- package/dist/identity.js +135 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +176 -0
- package/dist/layout.d.ts +194 -0
- package/dist/layout.js +40 -0
- package/dist/media.d.ts +202 -0
- package/dist/media.js +70 -0
- package/dist/messageBlocks.d.ts +487 -0
- package/dist/messageBlocks.js +683 -0
- package/dist/migration.d.ts +128 -0
- package/dist/migration.js +261 -0
- package/dist/names.d.ts +78 -0
- package/dist/names.js +136 -0
- package/dist/nodeInput.d.ts +399 -0
- package/dist/nodeInput.js +178 -0
- package/dist/participants.d.ts +291 -0
- package/dist/participants.js +252 -0
- package/dist/personGate.d.ts +62 -0
- package/dist/personGate.js +77 -0
- package/dist/pick.d.ts +84 -0
- package/dist/pick.js +103 -0
- package/dist/pluginHarness.d.ts +235 -0
- package/dist/pluginHarness.js +558 -0
- package/dist/pluginPermissions.d.ts +25 -0
- package/dist/pluginPermissions.js +97 -0
- package/dist/pluginRuleRef.d.ts +13 -0
- package/dist/pluginRuleRef.js +10 -0
- package/dist/predicates.d.ts +182 -0
- package/dist/predicates.js +249 -0
- package/dist/preview.d.ts +120 -0
- package/dist/preview.js +82 -0
- package/dist/promptBlocks.d.ts +130 -0
- package/dist/promptBlocks.js +197 -0
- package/dist/rankingDecisions.d.ts +60 -0
- package/dist/rankingDecisions.js +48 -0
- package/dist/receipt.d.ts +313 -0
- package/dist/receipt.js +60 -0
- package/dist/receiverRules.d.ts +24 -0
- package/dist/receiverRules.js +94 -0
- package/dist/refs.d.ts +117 -0
- package/dist/refs.js +137 -0
- package/dist/registry.d.ts +230 -0
- package/dist/registry.js +273 -0
- package/dist/review.d.ts +108 -0
- package/dist/review.js +97 -0
- package/dist/sampling.d.ts +152 -0
- package/dist/sampling.js +712 -0
- package/dist/scope.d.ts +65 -0
- package/dist/scope.js +128 -0
- package/dist/scripts.d.ts +243 -0
- package/dist/scripts.js +326 -0
- package/dist/sessionLayout.d.ts +339 -0
- package/dist/sessionLayout.js +503 -0
- package/dist/sessionSettings.d.ts +70 -0
- package/dist/sessionSettings.js +2 -0
- package/dist/settings.d.ts +501 -0
- package/dist/settings.js +604 -0
- package/dist/settingsSlot.d.ts +108 -0
- package/dist/settingsSlot.js +166 -0
- package/dist/shapes.d.ts +373 -0
- package/dist/shapes.js +408 -0
- package/dist/sheets.d.ts +165 -0
- package/dist/sheets.js +251 -0
- package/dist/statShapes.d.ts +96 -0
- package/dist/statShapes.js +112 -0
- package/dist/status.d.ts +103 -0
- package/dist/status.js +125 -0
- package/dist/storage.d.ts +145 -0
- package/dist/storage.js +33 -0
- package/dist/storyTime.d.ts +308 -0
- package/dist/storyTime.js +560 -0
- package/dist/surfaces.d.ts +501 -0
- package/dist/surfaces.js +292 -0
- package/dist/template.d.ts +312 -0
- package/dist/template.js +554 -0
- package/dist/templateCheck.d.ts +60 -0
- package/dist/templateCheck.js +516 -0
- package/dist/templateFit.d.ts +157 -0
- package/dist/templateFit.js +349 -0
- package/dist/templateIds.d.ts +138 -0
- package/dist/templateIds.js +144 -0
- package/dist/templateScopeAt.d.ts +131 -0
- package/dist/templateScopeAt.js +354 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.js +383 -0
- package/dist/tokenizers.d.ts +113 -0
- package/dist/tokenizers.js +184 -0
- package/dist/turnLock.d.ts +96 -0
- package/dist/turnLock.js +79 -0
- package/dist/turnOrder.d.ts +143 -0
- package/dist/turnOrder.js +128 -0
- package/dist/validate.d.ts +74 -0
- package/dist/validate.js +1399 -0
- package/dist/values.d.ts +212 -0
- package/dist/values.js +390 -0
- package/dist/variables.d.ts +493 -0
- package/dist/variables.js +662 -0
- package/dist/verdicts.d.ts +275 -0
- package/dist/verdicts.js +348 -0
- package/dist/widgetDecls.d.ts +88 -0
- package/dist/widgetDecls.js +119 -0
- package/dist/widgets.d.ts +1527 -0
- package/dist/widgets.js +208 -0
- package/dist/wire.d.ts +126 -0
- package/dist/wire.js +140 -0
- package/dist/worldinfo.d.ts +150 -0
- package/dist/worldinfo.js +212 -0
- package/host-elements.d.ts +914 -0
- 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
|