@serene-pub/sdk 0.6.0-pr-6 → 0.6.0-pr-7
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/dist/actions.d.ts +23 -0
- package/dist/actions.js +36 -1
- package/dist/annexFields.d.ts +28 -1
- package/dist/annexFields.js +47 -5
- package/dist/attributes.d.ts +50 -1
- package/dist/attributes.js +31 -0
- package/dist/builder.d.ts +2 -2
- package/dist/builder.js +2 -2
- package/dist/cadences.d.ts +7 -0
- package/dist/cadences.js +7 -0
- package/dist/capabilities.d.ts +13 -2
- package/dist/capabilities.js +28 -1
- package/dist/component.d.ts +5 -0
- package/dist/componentClient.d.ts +42 -6
- package/dist/componentWire.js +22 -4
- package/dist/declarations.d.ts +15 -0
- package/dist/declarations.js +29 -0
- package/dist/descriptors.d.ts +103 -2
- package/dist/descriptors.js +87 -5
- package/dist/events.d.ts +164 -0
- package/dist/events.js +67 -0
- package/dist/extension.d.ts +127 -3
- package/dist/extension.js +43 -0
- package/dist/genres.d.ts +20 -2
- package/dist/genres.js +40 -4
- package/dist/hookGrants.d.ts +14 -0
- package/dist/hookGrants.js +11 -10
- package/dist/hooks.d.ts +15 -2
- package/dist/hostElements.d.ts +1 -1
- package/dist/hostElements.js +8 -2
- package/dist/index.d.ts +4 -0
- package/dist/index.js +8 -0
- package/dist/jsonSchema.js +14 -2
- package/dist/libraryDraft.d.ts +27 -0
- package/dist/libraryDraft.js +25 -0
- package/dist/lorebookFile.d.ts +44 -0
- package/dist/lorebookFile.js +202 -0
- package/dist/pluginHarness.d.ts +50 -2
- package/dist/pluginHarness.js +65 -4
- package/dist/pluginPermissions.d.ts +15 -1
- package/dist/pluginPermissions.js +29 -2
- package/dist/receiverRules.js +9 -0
- package/dist/rulesetDocument.d.ts +21 -0
- package/dist/rulesetDocument.js +64 -2
- package/dist/rulesetSections.d.ts +37 -3
- package/dist/rulesetSections.js +47 -8
- package/dist/sessionDossier.d.ts +33 -0
- package/dist/settings.d.ts +74 -4
- package/dist/settings.js +293 -4
- package/dist/shapes.d.ts +40 -0
- package/dist/shapes.js +48 -1
- package/dist/speech.d.ts +333 -0
- package/dist/speech.js +199 -0
- package/dist/storage.d.ts +44 -0
- package/dist/storyTime.d.ts +25 -1
- package/dist/storyTime.js +42 -2
- package/dist/surfaces.d.ts +15 -2
- package/dist/template.d.ts +19 -1
- package/dist/template.js +25 -11
- package/dist/ties.d.ts +1 -0
- package/dist/ties.js +2 -1
- package/dist/userAnnex.d.ts +126 -0
- package/dist/userAnnex.js +214 -0
- package/dist/values.js +6 -0
- package/dist/widgets.d.ts +465 -8
- package/dist/widgets.js +198 -3
- package/host-elements.d.ts +5 -3
- package/package.json +1 -1
package/dist/jsonSchema.js
CHANGED
|
@@ -48,7 +48,7 @@ import { derivedEntryTypeSource } from './rulesets.js';
|
|
|
48
48
|
import { allEntryTypes } from './descriptors.js';
|
|
49
49
|
import { formAnswerSchema, formFireOf } from './messageBlocks.js';
|
|
50
50
|
import { isFunctionId } from './functions.js';
|
|
51
|
-
import { declaresSections, rulesetSections, rulesetAttributeSlots } from './rulesetSections.js';
|
|
51
|
+
import { declaresSections, rulesetSections, rulesetAttributeSlots, rulesetAttributeOwners } from './rulesetSections.js';
|
|
52
52
|
/**
|
|
53
53
|
* The piece fields the host keeps while it counts a duration down — never
|
|
54
54
|
* asked of a model (`PieceDuration.startedAt` / `spent`).
|
|
@@ -90,7 +90,7 @@ function classify(source) {
|
|
|
90
90
|
...(a.slot !== undefined && a.config !== undefined ? { config: a.config } : {}),
|
|
91
91
|
...(a.slot !== undefined && a.start !== undefined ? { default: a.start } : {}),
|
|
92
92
|
...(a.required !== undefined ? { required: a.required } : {}),
|
|
93
|
-
...(a.slot !== undefined && a.carriedBy !== undefined ? { appliesTo: a
|
|
93
|
+
...(a.slot !== undefined && (a.carriedBy !== undefined || a.owner !== undefined) ? { appliesTo: [...rulesetAttributeOwners(a)] } : {}),
|
|
94
94
|
})),
|
|
95
95
|
};
|
|
96
96
|
}
|
|
@@ -117,6 +117,7 @@ function fieldSchema(decl, path, ctx) {
|
|
|
117
117
|
switch (decl.type) {
|
|
118
118
|
case 'secret':
|
|
119
119
|
case 'media':
|
|
120
|
+
case 'json': // structure a person edits, like `format: 'json'`: nothing a model writes
|
|
120
121
|
return undefined;
|
|
121
122
|
case 'boolean':
|
|
122
123
|
return { type: 'boolean', ...about };
|
|
@@ -152,6 +153,17 @@ function fieldSchema(decl, path, ctx) {
|
|
|
152
153
|
return ctx.strict ? undefined : { type: 'object', ...about };
|
|
153
154
|
return { ...nested, ...about };
|
|
154
155
|
}
|
|
156
|
+
case 'schedule': {
|
|
157
|
+
// 🚧 A weekly routine (M0, SHAPES F3): each list a run of [hour, where] pairs.
|
|
158
|
+
const pair = {
|
|
159
|
+
type: 'array',
|
|
160
|
+
prefixItems: [{ type: 'integer', minimum: 0, maximum: 23 }, { type: 'string', minLength: 1 }],
|
|
161
|
+
minItems: 2,
|
|
162
|
+
maxItems: 2,
|
|
163
|
+
};
|
|
164
|
+
const week = { type: 'array', items: pair };
|
|
165
|
+
return { type: 'object', properties: { weekday: week, weekend: { ...week } }, required: ['weekday', 'weekend'], additionalProperties: false, ...about };
|
|
166
|
+
}
|
|
155
167
|
case 'share':
|
|
156
168
|
case 'perMember':
|
|
157
169
|
case 'strengths': {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚧 **A drafted card or book, read out of a reply** (M2c path B, owner ruling 2026-10-31: no separate
|
|
3
|
+
* classification call — the reply itself carries the draft). A reply that drafts a character card or a lorebook
|
|
4
|
+
* ends with ONE hidden block, an HTML comment so the message renderer never shows it:
|
|
5
|
+
*
|
|
6
|
+
* <!--draft:character {"name": "Mira", "description": "…", …}-->
|
|
7
|
+
* <!--draft:lorebook {"name": "The Lighthouse", "entries": [{ "name": "…", "content": "…", "keys": ["…"] }]}-->
|
|
8
|
+
*
|
|
9
|
+
* `readLibraryDraft` takes every such block out of the text (what the person reads, and what is saved), and reads
|
|
10
|
+
* the LAST one: `make` names its kind and `draft` its parsed JSON. No block, an unknown kind, or JSON that does not
|
|
11
|
+
* parse → `make: ''` and no `draft` (the blocks are still taken out). Pure; what `core:task/read-library-draft@1` runs.
|
|
12
|
+
* ⚠ Not a tool call (`parse-tool-call@1`) and not `parse-json@1` (which reads a whole reply as JSON).
|
|
13
|
+
* @experimental
|
|
14
|
+
*/
|
|
15
|
+
export type LibraryDraftKind = 'character' | 'lorebook';
|
|
16
|
+
/** @experimental */
|
|
17
|
+
export interface LibraryDraftRead {
|
|
18
|
+
/** The reply without its draft blocks. */
|
|
19
|
+
text: string;
|
|
20
|
+
/** The last block's kind, or `''` when there is none it could read. */
|
|
21
|
+
make: LibraryDraftKind | '';
|
|
22
|
+
/** The last block's JSON (an object), when `make` names a kind. */
|
|
23
|
+
draft?: Record<string, unknown>;
|
|
24
|
+
}
|
|
25
|
+
/** @experimental */
|
|
26
|
+
export declare function readLibraryDraft(text: unknown): LibraryDraftRead;
|
|
27
|
+
//# sourceMappingURL=libraryDraft.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const BLOCK = /<!--\s*draft:([a-z-]+)\s*([\s\S]*?)-->/g;
|
|
2
|
+
/** @experimental */
|
|
3
|
+
export function readLibraryDraft(text) {
|
|
4
|
+
const s = typeof text === 'string' ? text : '';
|
|
5
|
+
let last = null;
|
|
6
|
+
for (const m of s.matchAll(BLOCK))
|
|
7
|
+
last = { kind: m[1], body: m[2] };
|
|
8
|
+
// A block the reply was cut off in (the response limit reached before its `-->`) is taken out too: it is no
|
|
9
|
+
// draft anyone can read, and it must not be saved into the message.
|
|
10
|
+
const closed = s.replace(BLOCK, '');
|
|
11
|
+
const open = closed.search(/<!--\s*draft:/);
|
|
12
|
+
const stripped = (open >= 0 ? closed.slice(0, open) : closed).replace(/\n{3,}/g, '\n\n').trimEnd();
|
|
13
|
+
if (!last || (last.kind !== 'character' && last.kind !== 'lorebook'))
|
|
14
|
+
return { text: stripped, make: '' };
|
|
15
|
+
try {
|
|
16
|
+
const draft = JSON.parse(last.body.trim());
|
|
17
|
+
if (!draft || typeof draft !== 'object' || Array.isArray(draft))
|
|
18
|
+
return { text: stripped, make: '' };
|
|
19
|
+
return { text: stripped, make: last.kind, draft: draft };
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return { text: stripped, make: '' };
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=libraryDraft.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚧 (M2c) **Is this lorebook file one Serene Pub's importer would take?**
|
|
3
|
+
*
|
|
4
|
+
* A package may ship lorebooks (`ExtensionDecl.provides.lorebooks`); the app
|
|
5
|
+
* imports each at enable through its own importer, and `serene-pub check`
|
|
6
|
+
* refuses a file that importer would refuse. One validator, two callers: the
|
|
7
|
+
* app's importer runs this first, so the packager and the app cannot disagree
|
|
8
|
+
* about what a lorebook file is.
|
|
9
|
+
*
|
|
10
|
+
* Pure text in, sentences out (`[]` = the file is fine). It checks the
|
|
11
|
+
* file-level shape only: size, JSON, nesting, the entries list, and the
|
|
12
|
+
* ceilings on counts and lengths. It never touches a database.
|
|
13
|
+
*
|
|
14
|
+
* @experimental
|
|
15
|
+
*/
|
|
16
|
+
/** The ceilings an imported lorebook file is held to. Mirrors the app's `LOREBOOK_IMPORT_LIMITS`. @experimental */
|
|
17
|
+
export declare const LOREBOOK_FILE_LIMITS: {
|
|
18
|
+
/** A lorebook file's text, in bytes. */
|
|
19
|
+
readonly fileBytes: number;
|
|
20
|
+
/** Pieces of data (objects, lists, strings, numbers) a file may parse to. */
|
|
21
|
+
readonly maxItems: 1000000;
|
|
22
|
+
/** Levels of nesting. */
|
|
23
|
+
readonly maxDepth: 64;
|
|
24
|
+
readonly maxEntries: 5000;
|
|
25
|
+
readonly maxCharacters: 200;
|
|
26
|
+
readonly maxPersonas: 200;
|
|
27
|
+
readonly maxNarrativeNodes: 5000;
|
|
28
|
+
readonly maxNarrativeRelationships: 5000;
|
|
29
|
+
readonly maxKeysPerEntry: 1000;
|
|
30
|
+
readonly maxKeyChars: 2000;
|
|
31
|
+
readonly maxTextChars: 200000;
|
|
32
|
+
readonly maxNameChars: 10000;
|
|
33
|
+
readonly maxExtraJsonBytes: number;
|
|
34
|
+
readonly maxScenesPerHistoryEntry: 1000;
|
|
35
|
+
readonly maxStatRows: 20000;
|
|
36
|
+
readonly maxStatJsonBytes: number;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* The sentences that say why Serene Pub's importer would refuse this lorebook
|
|
40
|
+
* file (its text), or `[]` when the file is fine.
|
|
41
|
+
* @experimental
|
|
42
|
+
*/
|
|
43
|
+
export declare function lorebookFileFindings(text: string): string[];
|
|
44
|
+
//# sourceMappingURL=lorebookFile.d.ts.map
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🚧 (M2c) **Is this lorebook file one Serene Pub's importer would take?**
|
|
3
|
+
*
|
|
4
|
+
* A package may ship lorebooks (`ExtensionDecl.provides.lorebooks`); the app
|
|
5
|
+
* imports each at enable through its own importer, and `serene-pub check`
|
|
6
|
+
* refuses a file that importer would refuse. One validator, two callers: the
|
|
7
|
+
* app's importer runs this first, so the packager and the app cannot disagree
|
|
8
|
+
* about what a lorebook file is.
|
|
9
|
+
*
|
|
10
|
+
* Pure text in, sentences out (`[]` = the file is fine). It checks the
|
|
11
|
+
* file-level shape only: size, JSON, nesting, the entries list, and the
|
|
12
|
+
* ceilings on counts and lengths. It never touches a database.
|
|
13
|
+
*
|
|
14
|
+
* @experimental
|
|
15
|
+
*/
|
|
16
|
+
/** The ceilings an imported lorebook file is held to. Mirrors the app's `LOREBOOK_IMPORT_LIMITS`. @experimental */
|
|
17
|
+
export const LOREBOOK_FILE_LIMITS = {
|
|
18
|
+
/** A lorebook file's text, in bytes. */
|
|
19
|
+
fileBytes: 32 * 1024 * 1024,
|
|
20
|
+
/** Pieces of data (objects, lists, strings, numbers) a file may parse to. */
|
|
21
|
+
maxItems: 1_000_000,
|
|
22
|
+
/** Levels of nesting. */
|
|
23
|
+
maxDepth: 64,
|
|
24
|
+
maxEntries: 5000,
|
|
25
|
+
maxCharacters: 200,
|
|
26
|
+
maxPersonas: 200,
|
|
27
|
+
maxNarrativeNodes: 5000,
|
|
28
|
+
maxNarrativeRelationships: 5000,
|
|
29
|
+
maxKeysPerEntry: 1000,
|
|
30
|
+
maxKeyChars: 2000,
|
|
31
|
+
maxTextChars: 200_000,
|
|
32
|
+
maxNameChars: 10_000,
|
|
33
|
+
maxExtraJsonBytes: 64 * 1024,
|
|
34
|
+
maxScenesPerHistoryEntry: 1000,
|
|
35
|
+
maxStatRows: 20_000,
|
|
36
|
+
maxStatJsonBytes: 64 * 1024,
|
|
37
|
+
};
|
|
38
|
+
const fmt = (n) => n.toLocaleString('en');
|
|
39
|
+
const mb = (bytes) => `${fmt(Math.max(1, Math.ceil(bytes / (1024 * 1024))))} MB`;
|
|
40
|
+
const bytesOf = (s) => new TextEncoder().encode(s).length;
|
|
41
|
+
/** The nesting and size of a JSON text, measured without parsing it. Returns a sentence or undefined. */
|
|
42
|
+
function jsonShapeFinding(text) {
|
|
43
|
+
const { maxItems, maxDepth } = LOREBOOK_FILE_LIMITS;
|
|
44
|
+
let items = 1;
|
|
45
|
+
let depth = 0;
|
|
46
|
+
let opened = false;
|
|
47
|
+
for (let i = 0; i < text.length && items <= maxItems; i++) {
|
|
48
|
+
const c = text.charCodeAt(i);
|
|
49
|
+
if (c === 0x20 || c === 0x0a || c === 0x0d || c === 0x09)
|
|
50
|
+
continue;
|
|
51
|
+
if (opened) {
|
|
52
|
+
opened = false;
|
|
53
|
+
if (c !== 0x7d && c !== 0x5d)
|
|
54
|
+
items++;
|
|
55
|
+
}
|
|
56
|
+
if (c === 0x22) {
|
|
57
|
+
let end = i;
|
|
58
|
+
for (;;) {
|
|
59
|
+
end = text.indexOf('"', end + 1);
|
|
60
|
+
if (end < 0)
|
|
61
|
+
return undefined;
|
|
62
|
+
let slashes = 0;
|
|
63
|
+
while (text.charCodeAt(end - 1 - slashes) === 0x5c)
|
|
64
|
+
slashes++;
|
|
65
|
+
if (slashes % 2 === 0)
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
i = end;
|
|
69
|
+
}
|
|
70
|
+
else if (c === 0x7b || c === 0x5b) {
|
|
71
|
+
if (++depth > maxDepth)
|
|
72
|
+
return `This lorebook file is nested more than ${fmt(maxDepth)} levels deep; Serene Pub reads up to ${fmt(maxDepth)}.`;
|
|
73
|
+
opened = true;
|
|
74
|
+
}
|
|
75
|
+
else if (c === 0x7d || c === 0x5d)
|
|
76
|
+
depth--;
|
|
77
|
+
else if (c === 0x2c)
|
|
78
|
+
items++;
|
|
79
|
+
}
|
|
80
|
+
return items > maxItems
|
|
81
|
+
? `This lorebook file holds more than ${fmt(maxItems)} pieces of data; Serene Pub reads up to ${fmt(maxItems)}.`
|
|
82
|
+
: undefined;
|
|
83
|
+
}
|
|
84
|
+
/** Where a file's entries sit: a bare list, `entries` (list or SillyTavern's index object), or a card's `character_book`. */
|
|
85
|
+
function entriesOf(data) {
|
|
86
|
+
if (Array.isArray(data))
|
|
87
|
+
return data;
|
|
88
|
+
let entries = data?.entries;
|
|
89
|
+
if (entries && !Array.isArray(entries) && typeof entries === 'object')
|
|
90
|
+
entries = Object.values(entries);
|
|
91
|
+
if (Array.isArray(entries))
|
|
92
|
+
return entries;
|
|
93
|
+
const nested = data?.data?.character_book?.entries;
|
|
94
|
+
return Array.isArray(nested) ? nested : [];
|
|
95
|
+
}
|
|
96
|
+
function entryFindings(entry, i) {
|
|
97
|
+
const L = LOREBOOK_FILE_LIMITS;
|
|
98
|
+
const out = [];
|
|
99
|
+
if (!entry || typeof entry !== 'object' || Array.isArray(entry))
|
|
100
|
+
return [`Entry ${i + 1} isn't an object, so Serene Pub can't read it.`];
|
|
101
|
+
for (const field of ['name', 'comment']) {
|
|
102
|
+
const v = entry[field];
|
|
103
|
+
if (typeof v === 'string' && v.length > L.maxNameChars)
|
|
104
|
+
out.push(`Entry ${i + 1}'s name is ${fmt(v.length)} characters; Serene Pub reads up to ${fmt(L.maxNameChars)}.`);
|
|
105
|
+
}
|
|
106
|
+
const title = [entry.name, entry.comment].find((v) => typeof v === 'string' && v.trim().length > 0);
|
|
107
|
+
const label = title ? `Entry ${i + 1} (“${title.trim().length > 40 ? `${title.trim().slice(0, 39)}…` : title.trim()}”)` : `Entry ${i + 1}`;
|
|
108
|
+
const primary = Array.isArray(entry.keys) ? entry.keys : Array.isArray(entry.key) ? entry.key : [];
|
|
109
|
+
const secondaryRaw = entry.secondary_keys ?? entry.keysecondary;
|
|
110
|
+
const condition = Array.isArray(secondaryRaw) ? secondaryRaw : [];
|
|
111
|
+
for (const [keys, what] of [
|
|
112
|
+
[primary, 'keys'],
|
|
113
|
+
[condition, 'condition keys'],
|
|
114
|
+
]) {
|
|
115
|
+
if (keys.length > L.maxKeysPerEntry)
|
|
116
|
+
out.push(`${label} has ${fmt(keys.length)} ${what}; Serene Pub reads up to ${fmt(L.maxKeysPerEntry)} per entry.`);
|
|
117
|
+
const long = keys.find((k) => typeof k === 'string' && k.length > L.maxKeyChars);
|
|
118
|
+
if (long !== undefined)
|
|
119
|
+
out.push(`${label} has a key ${fmt(long.length)} characters long; Serene Pub reads keys up to ${fmt(L.maxKeyChars)} characters.`);
|
|
120
|
+
}
|
|
121
|
+
if (typeof entry.content === 'string' && entry.content.length > L.maxTextChars)
|
|
122
|
+
out.push(`${label}'s content is ${fmt(entry.content.length)} characters; Serene Pub reads up to ${fmt(L.maxTextChars)}.`);
|
|
123
|
+
const ext = entry.extensions;
|
|
124
|
+
if (ext && typeof ext === 'object') {
|
|
125
|
+
const { serenepub, ...foreign } = ext;
|
|
126
|
+
if (serenepub && typeof serenepub === 'object' && !Array.isArray(serenepub))
|
|
127
|
+
for (const [key, v] of Object.entries(serenepub))
|
|
128
|
+
if (typeof v === 'string' && v.length > L.maxNameChars)
|
|
129
|
+
out.push(`${label}'s ${key} is ${fmt(v.length)} characters; Serene Pub reads up to ${fmt(L.maxNameChars)}.`);
|
|
130
|
+
const bytes = bytesOf(JSON.stringify(foreign));
|
|
131
|
+
if (bytes > L.maxExtraJsonBytes)
|
|
132
|
+
out.push(`${label} carries ${fmt(Math.ceil(bytes / 1024))} KB of extra data; Serene Pub reads up to ${fmt(L.maxExtraJsonBytes / 1024)} KB per entry.`);
|
|
133
|
+
const scenes = serenepub?.scenes;
|
|
134
|
+
if (Array.isArray(scenes) && scenes.length > L.maxScenesPerHistoryEntry)
|
|
135
|
+
out.push(`Entry ${i + 1} has ${fmt(scenes.length)} scenes; Serene Pub reads up to ${fmt(L.maxScenesPerHistoryEntry)} per history entry.`);
|
|
136
|
+
}
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The sentences that say why Serene Pub's importer would refuse this lorebook
|
|
141
|
+
* file (its text), or `[]` when the file is fine.
|
|
142
|
+
* @experimental
|
|
143
|
+
*/
|
|
144
|
+
export function lorebookFileFindings(text) {
|
|
145
|
+
const L = LOREBOOK_FILE_LIMITS;
|
|
146
|
+
if (typeof text !== 'string')
|
|
147
|
+
return ['No lorebook file was sent.'];
|
|
148
|
+
const size = bytesOf(text);
|
|
149
|
+
if (size > L.fileBytes)
|
|
150
|
+
return [`This lorebook file is ${mb(size)}, larger than the ${mb(L.fileBytes)} Serene Pub will read.`];
|
|
151
|
+
const shape = jsonShapeFinding(text);
|
|
152
|
+
if (shape)
|
|
153
|
+
return [shape];
|
|
154
|
+
let data;
|
|
155
|
+
try {
|
|
156
|
+
data = JSON.parse(text.replace(/^/, ''));
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
return ["This lorebook file isn't valid JSON, so Serene Pub can't read it."];
|
|
160
|
+
}
|
|
161
|
+
if (typeof data !== 'object' || data === null)
|
|
162
|
+
return ['Lorebook data must be an object.'];
|
|
163
|
+
const out = [];
|
|
164
|
+
const entries = entriesOf(data);
|
|
165
|
+
const serenepub = data?.extensions?.serenepub ?? data?.data?.character_book?.extensions?.serenepub;
|
|
166
|
+
const count = (v) => (Array.isArray(v) ? v.length : 0);
|
|
167
|
+
if (entries.length > L.maxEntries)
|
|
168
|
+
out.push(`Lorebook has too many entries (${entries.length}); the maximum supported is ${L.maxEntries}.`);
|
|
169
|
+
if (count(serenepub?.characters) > L.maxCharacters)
|
|
170
|
+
out.push(`Lorebook embeds too many characters (${count(serenepub?.characters)}); the maximum supported is ${L.maxCharacters}.`);
|
|
171
|
+
if (count(serenepub?.personas) > L.maxPersonas)
|
|
172
|
+
out.push(`Lorebook embeds too many personas (${count(serenepub?.personas)}); the maximum supported is ${L.maxPersonas}.`);
|
|
173
|
+
const graph = serenepub?.narrativeGraph;
|
|
174
|
+
if (count(graph?.nodes) > L.maxNarrativeNodes)
|
|
175
|
+
out.push(`Lorebook's narrative graph has too many nodes (${count(graph?.nodes)}); the maximum supported is ${L.maxNarrativeNodes}.`);
|
|
176
|
+
if (count(graph?.relationships) > L.maxNarrativeRelationships)
|
|
177
|
+
out.push(`Lorebook's narrative graph has too many relationships (${count(graph?.relationships)}); the maximum supported is ${L.maxNarrativeRelationships}.`);
|
|
178
|
+
const book = data.character_book ?? data.data?.character_book ?? data;
|
|
179
|
+
if (typeof book?.name === 'string' && book.name.length > L.maxNameChars)
|
|
180
|
+
out.push(`This lorebook's name is ${fmt(book.name.length)} characters; Serene Pub reads up to ${fmt(L.maxNameChars)}.`);
|
|
181
|
+
if (typeof book?.description === 'string' && book.description.length > L.maxTextChars)
|
|
182
|
+
out.push(`This lorebook's description is ${fmt(book.description.length)} characters; Serene Pub reads up to ${fmt(L.maxTextChars)}.`);
|
|
183
|
+
if (entries.length <= L.maxEntries)
|
|
184
|
+
entries.forEach((entry, i) => out.push(...entryFindings(entry, i)));
|
|
185
|
+
const stats = serenepub?.stats;
|
|
186
|
+
if (stats && typeof stats === 'object') {
|
|
187
|
+
const list = (key) => (Array.isArray(stats[key]) ? stats[key] : []);
|
|
188
|
+
const rows = [...list('configs').map((row) => row?.config), ...list('values').map((row) => row?.value)];
|
|
189
|
+
if (rows.length > L.maxStatRows)
|
|
190
|
+
out.push(`This lorebook file holds ${fmt(rows.length)} stats; Serene Pub reads up to ${fmt(L.maxStatRows)}.`);
|
|
191
|
+
else
|
|
192
|
+
for (const payload of rows) {
|
|
193
|
+
if (payload === undefined)
|
|
194
|
+
continue;
|
|
195
|
+
const bytes = bytesOf(JSON.stringify(payload));
|
|
196
|
+
if (bytes > L.maxStatJsonBytes)
|
|
197
|
+
out.push(`One of this lorebook's stats is ${fmt(bytes)} bytes; Serene Pub reads up to ${fmt(L.maxStatJsonBytes)}.`);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
202
|
+
//# sourceMappingURL=lorebookFile.js.map
|
package/dist/pluginHarness.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* plugin's node handlers do not go through that path at all: the app's
|
|
9
9
|
* `pipelines/runtime/pluginBindings.ts` calls `RuntimeManager.callHook`, which
|
|
10
10
|
* runs the hook inside the plugin's sandbox against a context the sandbox
|
|
11
|
-
* builds — `{ random, now, log, storage, fetch, signal }` — and commits its files
|
|
11
|
+
* builds — `{ random, now, log, storage, package, fetch, signal }` — and commits its files
|
|
12
12
|
* afterwards.
|
|
13
13
|
*
|
|
14
14
|
* Two packages paid for that gap before it was written down:
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
*/
|
|
37
37
|
import { type Bindings, type Result } from './executor.js';
|
|
38
38
|
import type { HookFetchInit, HookFetchResponse } from './hooks.js';
|
|
39
|
-
import type { ExtensionStorage } from './storage.js';
|
|
39
|
+
import type { ExtensionStorage, PackageFiles, PerUserStorage } from './storage.js';
|
|
40
|
+
import { type ExtensionUserAnnex, type HookAnnex, type UserAnnexBufferedWrite } from './userAnnex.js';
|
|
40
41
|
import { type HookCtxGrants, type HookCtxKind } from './hookGrants.js';
|
|
41
42
|
export { HOOK_CTX_KINDS, hookCtxGrants, hookCtxKeysFor, isHookCtxKind, type HookCtxGrants, type HookCtxKind } from './hookGrants.js';
|
|
42
43
|
/**
|
|
@@ -92,6 +93,13 @@ export interface MemoryStorageOptions {
|
|
|
92
93
|
* stamps supplies a clock that moves.
|
|
93
94
|
*/
|
|
94
95
|
now?: () => number;
|
|
96
|
+
/**
|
|
97
|
+
* 🚧 (M2b) The acting person's own store for `ctx.storage.user` — usually a
|
|
98
|
+
* second `memoryStorage()`. Absent: every `storage.user` method refuses with
|
|
99
|
+
* "storage.user: no person is acting for this call", as a call with no
|
|
100
|
+
* signed-in person does.
|
|
101
|
+
*/
|
|
102
|
+
user?: PerUserStorage;
|
|
95
103
|
}
|
|
96
104
|
/** @experimental */
|
|
97
105
|
export type MemoryStorage = ExtensionStorage & {
|
|
@@ -134,6 +142,10 @@ export interface PluginHandlerContext {
|
|
|
134
142
|
now(): number;
|
|
135
143
|
log(...args: unknown[]): void;
|
|
136
144
|
storage?: ExtensionStorage;
|
|
145
|
+
/** The package's shipped files, read-only. 🚧 (M2a) */
|
|
146
|
+
package?: PackageFiles;
|
|
147
|
+
/** 🚧 (M2b) `ctx.annex('user')`: the acting person's saved documents. */
|
|
148
|
+
annex?: HookAnnex;
|
|
137
149
|
fetch?(url: string, init?: HookFetchInit): Promise<HookFetchResponse>;
|
|
138
150
|
signal: AbortSignal;
|
|
139
151
|
}
|
|
@@ -156,6 +168,24 @@ export interface PluginHandlerContextOptions {
|
|
|
156
168
|
grants?: Partial<HookCtxGrants>;
|
|
157
169
|
/** The extension's store. A fresh `memoryStorage()` when the grant holds and none is given. */
|
|
158
170
|
storage?: ExtensionStorage;
|
|
171
|
+
/**
|
|
172
|
+
* 🚧 (M2b) The acting person's store for `ctx.storage.user`, used when no
|
|
173
|
+
* `storage` is given. Absent: `ctx.storage.user` refuses ("no person is acting").
|
|
174
|
+
*/
|
|
175
|
+
user?: PerUserStorage;
|
|
176
|
+
/**
|
|
177
|
+
* 🚧 (M2b) The acting person's annex for `ctx.annex('user')` — usually a
|
|
178
|
+
* `memoryUserAnnex({ 'profile': { … } })`. Absent: every method rejects with
|
|
179
|
+
* "annex('user'): no person is acting for this call", as a call with no
|
|
180
|
+
* signed-in person does.
|
|
181
|
+
*/
|
|
182
|
+
userAnnex?: ExtensionUserAnnex;
|
|
183
|
+
/**
|
|
184
|
+
* The package's shipped files (🚧 M2a): a `PackageFiles`, or a map of
|
|
185
|
+
* package path → bytes (or text) such as `{ 'assets/a.json': '{}' }`. Absent:
|
|
186
|
+
* a read answers err "no package files in this harness: pass `package`".
|
|
187
|
+
*/
|
|
188
|
+
package?: PackageFiles | Record<string, Uint8Array | string>;
|
|
159
189
|
/** The pinned clock, in milliseconds. */
|
|
160
190
|
now?: number;
|
|
161
191
|
signal?: AbortSignal;
|
|
@@ -175,6 +205,22 @@ export interface PluginHandlerContextOptions {
|
|
|
175
205
|
* @experimental
|
|
176
206
|
*/
|
|
177
207
|
export declare function pluginHandlerContext(opts: PluginHandlerContextOptions): PluginHandlerContext;
|
|
208
|
+
/**
|
|
209
|
+
* 🚧 (M2b) An in-memory user annex for a harness: the same semantics a hook
|
|
210
|
+
* sees in the sandbox (`base`, the caps, the refusals, read-your-writes), over
|
|
211
|
+
* `initial` documents (key → document, each at version 1). `writes()` is what
|
|
212
|
+
* the call would commit.
|
|
213
|
+
* @experimental
|
|
214
|
+
*/
|
|
215
|
+
export declare function memoryUserAnnex(initial?: Record<string, unknown>): ExtensionUserAnnex & {
|
|
216
|
+
writes(): UserAnnexBufferedWrite[];
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* A `PackageFiles` over a map of package path → bytes, answering what the host
|
|
220
|
+
* answers: bytes for a shipped file, `err` for anything else.
|
|
221
|
+
* @experimental
|
|
222
|
+
*/
|
|
223
|
+
export declare function memoryPackage(files?: Record<string, Uint8Array | string>): PackageFiles;
|
|
178
224
|
/** A plugin's node handler: `(input, ctx)`, with the sandbox's ctx. @experimental */
|
|
179
225
|
export type PluginNodeHandler = (input: any, ctx: PluginHandlerContext) => Result | Promise<Result>;
|
|
180
226
|
/** @experimental */
|
|
@@ -189,6 +235,8 @@ export interface PluginNodeBindingOptions {
|
|
|
189
235
|
* `fire` reads. A fresh `memoryStorage()` when none is given.
|
|
190
236
|
*/
|
|
191
237
|
storage?: ExtensionStorage;
|
|
238
|
+
/** The package's shipped files, as `pluginHandlerContext` takes them. 🚧 (M2a) */
|
|
239
|
+
package?: PluginHandlerContextOptions['package'];
|
|
192
240
|
/** The run seed the RNG labels derive from. */
|
|
193
241
|
seed?: string;
|
|
194
242
|
/** The pinned clock. */
|
package/dist/pluginHarness.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* plugin's node handlers do not go through that path at all: the app's
|
|
9
9
|
* `pipelines/runtime/pluginBindings.ts` calls `RuntimeManager.callHook`, which
|
|
10
10
|
* runs the hook inside the plugin's sandbox against a context the sandbox
|
|
11
|
-
* builds — `{ random, now, log, storage, fetch, signal }` — and commits its files
|
|
11
|
+
* builds — `{ random, now, log, storage, package, fetch, signal }` — and commits its files
|
|
12
12
|
* afterwards.
|
|
13
13
|
*
|
|
14
14
|
* Two packages paid for that gap before it was written down:
|
|
@@ -39,6 +39,7 @@ import { err, ok } from './executor.js';
|
|
|
39
39
|
// ── The grant table (plans 29 R-3) ──────────────────────────────────────────
|
|
40
40
|
// Lives in `hookGrants.ts`, the one copy the sandboxes, the harness and the
|
|
41
41
|
// guide all read (K1c); re-exported here so the harness's API is unchanged.
|
|
42
|
+
import { userAnnexProjection } from './userAnnex.js';
|
|
42
43
|
import { hookCtxGrants } from './hookGrants.js';
|
|
43
44
|
export { HOOK_CTX_KINDS, hookCtxGrants, hookCtxKeysFor, isHookCtxKind } from './hookGrants.js';
|
|
44
45
|
/** A node kind, as a descriptor spells it, read as the hook ctx kind it dispatches under. */
|
|
@@ -154,7 +155,7 @@ export function formatHookLog(args) {
|
|
|
154
155
|
}
|
|
155
156
|
// ── The in-memory ExtensionStorage ──────────────────────────────────────────
|
|
156
157
|
/** The grant a sandbox falls back to when the manifest declares none. @experimental */
|
|
157
|
-
export const DEFAULT_STORAGE_QUOTA_BYTES =
|
|
158
|
+
export const DEFAULT_STORAGE_QUOTA_BYTES = 64 * 1024 * 1024;
|
|
158
159
|
/**
|
|
159
160
|
* The clock this harness pins when a caller names none.
|
|
160
161
|
*
|
|
@@ -166,6 +167,11 @@ export const DEFAULT_STORAGE_QUOTA_BYTES = 10 * 1024 * 1024;
|
|
|
166
167
|
* @experimental
|
|
167
168
|
*/
|
|
168
169
|
export const HARNESS_CLOCK = 1_700_000_000_000;
|
|
170
|
+
/** The refusing `ctx.storage.user` of a call with no person (M2b). */
|
|
171
|
+
function noPersonStorage() {
|
|
172
|
+
const d = () => Promise.reject(new Error('storage.user: no person is acting for this call'));
|
|
173
|
+
return { usage: d, files: { list: d, stat: d, read: d, write: d, delete: d, deleteAll: d } };
|
|
174
|
+
}
|
|
169
175
|
/**
|
|
170
176
|
* An in-memory `ExtensionStorage` — the half the SDK's harness cannot otherwise
|
|
171
177
|
* supply, with the refusals install actually makes.
|
|
@@ -255,6 +261,7 @@ export function memoryStorage(opts = {}) {
|
|
|
255
261
|
},
|
|
256
262
|
usage: async () => usage(),
|
|
257
263
|
files: extensionFiles,
|
|
264
|
+
user: opts.user ?? noPersonStorage(),
|
|
258
265
|
};
|
|
259
266
|
return store;
|
|
260
267
|
}
|
|
@@ -317,9 +324,11 @@ const isIpLiteral = (h) => /^\d{1,3}(\.\d{1,3}){3}$/.test(h) || h.includes(':');
|
|
|
317
324
|
* @experimental
|
|
318
325
|
*/
|
|
319
326
|
export function pluginHandlerContext(opts) {
|
|
320
|
-
const base = opts.kind ? hookCtxGrants(opts.kind) : { storage: true, fetch: true };
|
|
327
|
+
const base = opts.kind ? hookCtxGrants(opts.kind) : { storage: true, package: true, annex: true, fetch: true };
|
|
321
328
|
const grants = {
|
|
322
329
|
storage: opts.grants?.storage ?? base.storage,
|
|
330
|
+
package: opts.grants?.package ?? base.package,
|
|
331
|
+
annex: opts.grants?.annex ?? base.annex,
|
|
323
332
|
fetch: opts.grants?.fetch ?? base.fetch,
|
|
324
333
|
};
|
|
325
334
|
const nowMs = Math.floor(opts.now ?? HARNESS_CLOCK);
|
|
@@ -336,11 +345,62 @@ export function pluginHandlerContext(opts) {
|
|
|
336
345
|
};
|
|
337
346
|
const members = ctx;
|
|
338
347
|
if (grants.storage)
|
|
339
|
-
insertBefore(members, 'signal', 'storage', opts.storage ?? memoryStorage());
|
|
348
|
+
insertBefore(members, 'signal', 'storage', opts.storage ?? memoryStorage({ user: opts.user }));
|
|
349
|
+
if (grants.package)
|
|
350
|
+
insertBefore(members, 'signal', 'package', packageFilesOf(opts.package));
|
|
351
|
+
if (grants.annex)
|
|
352
|
+
insertBefore(members, 'signal', 'annex', makeHookAnnex(opts.userAnnex));
|
|
340
353
|
if (grants.fetch)
|
|
341
354
|
insertBefore(members, 'signal', 'fetch', makeFetch(opts, ctx.signal));
|
|
342
355
|
return ctx;
|
|
343
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* 🚧 (M2b) An in-memory user annex for a harness: the same semantics a hook
|
|
359
|
+
* sees in the sandbox (`base`, the caps, the refusals, read-your-writes), over
|
|
360
|
+
* `initial` documents (key → document, each at version 1). `writes()` is what
|
|
361
|
+
* the call would commit.
|
|
362
|
+
* @experimental
|
|
363
|
+
*/
|
|
364
|
+
export function memoryUserAnnex(initial = {}) {
|
|
365
|
+
const snapshot = {};
|
|
366
|
+
for (const k of Object.keys(initial))
|
|
367
|
+
snapshot[k] = { doc: initial[k], version: 1, updatedAt: new Date(HARNESS_CLOCK).toISOString() };
|
|
368
|
+
const p = userAnnexProjection(snapshot, () => new Date(HARNESS_CLOCK).toISOString());
|
|
369
|
+
return Object.assign(p.api, { writes: p.writes });
|
|
370
|
+
}
|
|
371
|
+
function makeHookAnnex(userAnnex) {
|
|
372
|
+
return (host) => {
|
|
373
|
+
if (host !== 'user')
|
|
374
|
+
throw new Error(`annex: unknown host '${String(host)}'; a hook may name: 'user'.`);
|
|
375
|
+
if (userAnnex)
|
|
376
|
+
return userAnnex;
|
|
377
|
+
const d = () => Promise.reject(new Error("annex('user'): no person is acting for this call"));
|
|
378
|
+
return { get: d, set: d, list: d, remove: d };
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* A `PackageFiles` over a map of package path → bytes, answering what the host
|
|
383
|
+
* answers: bytes for a shipped file, `err` for anything else.
|
|
384
|
+
* @experimental
|
|
385
|
+
*/
|
|
386
|
+
export function memoryPackage(files = {}) {
|
|
387
|
+
const enc = new TextEncoder();
|
|
388
|
+
return {
|
|
389
|
+
read: async (path) => {
|
|
390
|
+
const f = typeof path === 'string' && Object.hasOwn(files, path) ? files[path] : undefined;
|
|
391
|
+
if (f === undefined)
|
|
392
|
+
return err(`package: '${path}' is not one of this package's assets`);
|
|
393
|
+
return ok(typeof f === 'string' ? enc.encode(f) : new Uint8Array(f));
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
function packageFilesOf(given) {
|
|
398
|
+
if (!given)
|
|
399
|
+
return { read: async () => err('package: no package files in this harness: pass `package`') };
|
|
400
|
+
return typeof given.read === 'function'
|
|
401
|
+
? given
|
|
402
|
+
: memoryPackage(given);
|
|
403
|
+
}
|
|
344
404
|
/**
|
|
345
405
|
* Put a member in its sandbox position. `signal` is defined last in both
|
|
346
406
|
* backends' programs, so an endowment appended after it would give a context
|
|
@@ -419,6 +479,7 @@ export function pluginNodeBindings(opts) {
|
|
|
419
479
|
kind,
|
|
420
480
|
seed: nodeSeedLabel(seed, pin, input),
|
|
421
481
|
storage,
|
|
482
|
+
package: opts.package,
|
|
422
483
|
now: opts.now,
|
|
423
484
|
signal: execCtx?.signal,
|
|
424
485
|
network: opts.network,
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
* These are a plugin's **permissions**: what its sandboxed code may do (canon).
|
|
12
12
|
* @ruling K1, R50
|
|
13
13
|
*/
|
|
14
|
-
import type
|
|
14
|
+
import { type PluginRule } from './pluginRuleRef.js';
|
|
15
15
|
export { PLUGIN_PERMISSIONS_GUIDE, pluginRuleRef, type PluginRule } from './pluginRuleRef.js';
|
|
16
16
|
/** The rules a refusal can point at, each a heading in the guide. @experimental */
|
|
17
17
|
export declare const PLUGIN_RULES: Record<PluginRule, {
|
|
@@ -21,6 +21,20 @@ export declare const PLUGIN_RULES: Record<PluginRule, {
|
|
|
21
21
|
}>;
|
|
22
22
|
/** Every anchor a refusal may point at — each a heading the guide renders. @experimental */
|
|
23
23
|
export declare const PLUGIN_RULE_ANCHORS: readonly string[];
|
|
24
|
+
/** ` (see guides/plugin-permissions.md#permission-groups)` — the groups section's pointer. 🚧 (M2b) @experimental */
|
|
25
|
+
export declare const permissionGroupsRef: () => string;
|
|
26
|
+
/**
|
|
27
|
+
* 🚧 (M2b) The permission keys a package's manifest carries, by group: the rows of the
|
|
28
|
+
* guide's key table (key · group · what it grants · declared as). One table, so the
|
|
29
|
+
* guide and the admin's review list name the same keys.
|
|
30
|
+
* @experimental
|
|
31
|
+
*/
|
|
32
|
+
export declare const PERMISSION_KEY_ROWS: ReadonlyArray<{
|
|
33
|
+
key: string;
|
|
34
|
+
group: 'session' | 'applet' | 'system';
|
|
35
|
+
grants: string;
|
|
36
|
+
declaredAs: string;
|
|
37
|
+
}>;
|
|
24
38
|
/** The guide, rendered from the table. @internal */
|
|
25
39
|
export declare function renderPluginPermissionsGuide(): string;
|
|
26
40
|
//# sourceMappingURL=pluginPermissions.d.ts.map
|