@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,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
|