@dsh-agentic-roleplay/core 0.1.1 → 0.2.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/README.md +1 -1
- package/lib/{activity-BbqFG9-3.js → activity-t7OBgHlc.js} +255 -61
- package/lib/authoring.js +295 -14
- package/lib/client.js +1896 -453
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +1 -1
- package/lib/{documents-ZVoUTnD2.js → documents-Bu5uYRZB.js} +3 -3
- package/lib/{gallery-KGCdeCnM.js → gallery-DUeBMHQX.js} +2 -2
- package/lib/{generator-NYnNdpWb.js → generator-HPifO3Kk.js} +125 -20
- package/lib/images.js +3 -3
- package/lib/index.js +638 -14
- package/lib/{narration-DcnCqA1l.js → narration-BRyHU0H2.js} +10 -4
- package/lib/orchestration.js +303 -161
- package/lib/packs-ByP1J-zj.js +1334 -0
- package/lib/{presenter-agent-7j1c7QEz.js → presenter-agent-G43ODV8I.js} +3 -3
- package/package.json +4 -3
- package/prompts/en/roleplay/ask-answerer.md +3 -0
- package/prompts/en/roleplay/ask-question.md +2 -0
- package/prompts/en/roleplay/character-decide.md +1 -1
- package/prompts/en/roleplay/character-lookup.md +1 -1
- package/prompts/en/roleplay/game-master.md +5 -1
- package/prompts/en/roleplay/ooc-empty.md +1 -1
- package/prompts/en/world/procedure.md +1 -1
- package/prompts/zh/roleplay/ask-answerer.md +3 -0
- package/prompts/zh/roleplay/ask-question.md +2 -0
- package/prompts/zh/roleplay/character-decide.md +1 -1
- package/prompts/zh/roleplay/character-lookup.md +1 -1
- package/prompts/zh/roleplay/game-master.md +5 -1
- package/prompts/zh/roleplay/ooc-empty.md +1 -1
- package/prompts/zh/world/procedure.md +1 -1
- package/starter-worlds/blackwater-observatory/ui/notebook/map.html +12 -0
- package/starter-worlds/blackwater-observatory/ui/notebook/map.js +40 -0
- package/starter-worlds/blackwater-observatory/ui/notebook/notebook.html +29 -0
- package/starter-worlds/blackwater-observatory/ui/notebook/notebook.js +45 -0
- package/starter-worlds/blackwater-observatory/ui/notebook/pack.json +31 -0
- package/starter-worlds/blackwater-observatory/ui/notebook/skin.css +16 -0
- package/starter-worlds/blackwater-observatory/ui/notebook/strip.html +11 -0
- package/starter-worlds/blackwater-observatory/ui/notebook/strip.js +12 -0
- package/starter-worlds/blackwater-observatory/ui/notebook/style.css +23 -0
- package/lib/worlds-DYgjdH8O.js +0 -504
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The UI, orchestration, world authoring, media, and filesystem integration plugin behind DSH Agentic Roleplay.
|
|
4
4
|
|
|
5
|
-
It provides the game-master loop,
|
|
5
|
+
It provides the bounded game-master loop, point-of-view character agents, world and session interfaces, approval-gated authoring agents and tools, story compaction, speech integration, and image-generation workflows. It turns the structured state supplied by [`@dsh-agentic-roleplay/state`](https://www.npmjs.com/package/@dsh-agentic-roleplay/state) into a playable and editable experience.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
@@ -1,10 +1,162 @@
|
|
|
1
1
|
import { n as roleplaySessionOf } from "./chat-AKrVcWIC.js";
|
|
2
|
-
import {
|
|
3
|
-
import { u as inheritImages } from "./generator-
|
|
2
|
+
import { B as SessionNotFoundError, i as inheritPacks, k as inheritPrompts } from "./packs-ByP1J-zj.js";
|
|
3
|
+
import { j as estimateAnswer, u as inheritImages } from "./generator-HPifO3Kk.js";
|
|
4
4
|
import { join } from "node:path";
|
|
5
|
-
import { existsSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
7
7
|
import { DAY, MINUTE, SECOND, clockTime, dayPart, describeDuration, describeInstant, isSessionId, localTime, locationKey, mentioned, nextTimeOfDay, overlap, sessionDatabase, sessionFolder, tokens } from "@dsh-agentic-roleplay/state";
|
|
8
|
+
//#region src/host/orchestration/protocol.ts
|
|
9
|
+
const COMMITMENTS = [
|
|
10
|
+
"low",
|
|
11
|
+
"medium",
|
|
12
|
+
"high"
|
|
13
|
+
];
|
|
14
|
+
const RESULTS = [
|
|
15
|
+
"succeeded",
|
|
16
|
+
"partial",
|
|
17
|
+
"failed"
|
|
18
|
+
];
|
|
19
|
+
const MAX_ACCOUNT = 300;
|
|
20
|
+
/**
|
|
21
|
+
* How long, in characters, each text of a character's answer is asked to run to: the instructions state these, and the most a character's request may produce is estimated from them.
|
|
22
|
+
* A character of a script written without spaces says more in fewer.
|
|
23
|
+
*/
|
|
24
|
+
const ANSWER_LIMITS = {
|
|
25
|
+
en: {
|
|
26
|
+
thought: 240,
|
|
27
|
+
intent: 300,
|
|
28
|
+
utterance: 600,
|
|
29
|
+
account: MAX_ACCOUNT
|
|
30
|
+
},
|
|
31
|
+
zh: {
|
|
32
|
+
thought: 100,
|
|
33
|
+
intent: 120,
|
|
34
|
+
utterance: 240,
|
|
35
|
+
account: 120
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
const answerLimits = (language) => language.toLowerCase().startsWith("zh") ? ANSWER_LIMITS.zh : ANSWER_LIMITS.en;
|
|
39
|
+
/** What the answer of a character comes to at most, in tokens (an answer about what happened out of sight has its account too). */
|
|
40
|
+
function answerEstimate(language, away) {
|
|
41
|
+
const limits = answerLimits(language);
|
|
42
|
+
return estimateAnswer([
|
|
43
|
+
limits.thought,
|
|
44
|
+
limits.intent,
|
|
45
|
+
limits.utterance,
|
|
46
|
+
...away ? [limits.account] : []
|
|
47
|
+
], language);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* What a character is asked to produce; the sub-agent runtime enforces it. The order is the order of what depends on what: the thought comes first so that the
|
|
51
|
+
* choice that follows is made after it, which an engine that does not write fields in order simply does without (it is optional and read by no one).
|
|
52
|
+
*/
|
|
53
|
+
const CHARACTER_ACTION_SCHEMA = {
|
|
54
|
+
type: "object",
|
|
55
|
+
properties: {
|
|
56
|
+
thought: {
|
|
57
|
+
type: "string",
|
|
58
|
+
description: "First, in your own voice and a sentence or two: what you notice in the moment and what you want from it. No one is shown it."
|
|
59
|
+
},
|
|
60
|
+
intent: {
|
|
61
|
+
type: "string",
|
|
62
|
+
description: "What the character does, or tries to do, now, as an action in one or two sentences, without any speech."
|
|
63
|
+
},
|
|
64
|
+
utterance: {
|
|
65
|
+
type: "string",
|
|
66
|
+
description: "What the character says aloud, word for word and in its own voice, exactly as it will be shown. Leave out when it says nothing."
|
|
67
|
+
},
|
|
68
|
+
commitment: {
|
|
69
|
+
type: "string",
|
|
70
|
+
enum: [...COMMITMENTS],
|
|
71
|
+
description: "How hard the character will keep trying if this does not work out: low gives up at once, high persists."
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
required: [
|
|
75
|
+
"thought",
|
|
76
|
+
"intent",
|
|
77
|
+
"commitment"
|
|
78
|
+
],
|
|
79
|
+
additionalProperties: false
|
|
80
|
+
};
|
|
81
|
+
/** The schema for a character acting away from the player: the same answer, which also says in a line what happened, so no second request is needed. */
|
|
82
|
+
const AWAY_ACTION_SCHEMA = {
|
|
83
|
+
...CHARACTER_ACTION_SCHEMA,
|
|
84
|
+
properties: {
|
|
85
|
+
...CHARACTER_ACTION_SCHEMA.properties,
|
|
86
|
+
account: {
|
|
87
|
+
type: "string",
|
|
88
|
+
description: "One sentence, in the third person and the past tense, of what came of this, as someone who only saw it from outside would tell it afterwards: no thoughts, no secrets."
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
required: [
|
|
92
|
+
"thought",
|
|
93
|
+
"intent",
|
|
94
|
+
"commitment",
|
|
95
|
+
"account"
|
|
96
|
+
]
|
|
97
|
+
};
|
|
98
|
+
/** @throws {Error} when the value is not a character action. */
|
|
99
|
+
const QUOTE_PAIRS = [
|
|
100
|
+
["\"", "\""],
|
|
101
|
+
["“", "”"],
|
|
102
|
+
["「", "」"],
|
|
103
|
+
["『", "』"],
|
|
104
|
+
["«", "»"],
|
|
105
|
+
["‘", "’"]
|
|
106
|
+
];
|
|
107
|
+
/** Words said aloud, without the quotation marks a model puts around them: the output puts its own. */
|
|
108
|
+
function unquoted(text) {
|
|
109
|
+
let words = text.trim();
|
|
110
|
+
for (let again = true; again;) {
|
|
111
|
+
again = false;
|
|
112
|
+
for (const [open, close] of QUOTE_PAIRS) if (words.length >= 2 && words.startsWith(open) && words.endsWith(close) && !words.slice(open.length, -close.length).includes(close)) {
|
|
113
|
+
words = words.slice(open.length, words.length - close.length).trim();
|
|
114
|
+
again = true;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return words;
|
|
118
|
+
}
|
|
119
|
+
const LEAKED_FIELD = /<\/?(?:intent|parameter(?:=\w+)?)>/g;
|
|
120
|
+
/** A model that writes the markup of its call into a field puts the next field's text inside this one. */
|
|
121
|
+
function splitLeakedFields(intent) {
|
|
122
|
+
const at = intent.search(/<parameter=utterance>/);
|
|
123
|
+
if (at === -1) return { intent: intent.replace(LEAKED_FIELD, " ") };
|
|
124
|
+
const spoken = intent.slice(at).replace(LEAKED_FIELD, " ").trim();
|
|
125
|
+
return {
|
|
126
|
+
intent: intent.slice(0, at).replace(LEAKED_FIELD, " "),
|
|
127
|
+
...spoken === "" ? {} : { utterance: spoken }
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
function parseCharacterAction(value) {
|
|
131
|
+
if (typeof value !== "object" || value === null) throw new Error("the character did not answer with an object");
|
|
132
|
+
const { intent: rawIntent, utterance: rawUtterance, commitment, account } = value;
|
|
133
|
+
const { intent, utterance } = typeof rawIntent === "string" && rawUtterance === void 0 ? splitLeakedFields(rawIntent) : {
|
|
134
|
+
intent: rawIntent,
|
|
135
|
+
utterance: rawUtterance
|
|
136
|
+
};
|
|
137
|
+
if (typeof intent !== "string" || intent.trim() === "") throw new Error("the character gave no intent");
|
|
138
|
+
if (!COMMITMENTS.includes(commitment)) throw new Error(`the character gave an unknown commitment "${String(commitment)}"`);
|
|
139
|
+
if (utterance !== void 0 && typeof utterance !== "string") throw new Error("the character's utterance is not text");
|
|
140
|
+
const spoken = utterance === void 0 ? void 0 : unquoted(utterance);
|
|
141
|
+
const told = typeof account === "string" ? account.trim().slice(0, MAX_ACCOUNT) : "";
|
|
142
|
+
return {
|
|
143
|
+
intent: intent.trim(),
|
|
144
|
+
...spoken === void 0 || spoken === "" ? {} : { utterance: spoken },
|
|
145
|
+
commitment,
|
|
146
|
+
...told === "" ? {} : { account: told }
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/host/orchestration/referent.ts
|
|
151
|
+
/**
|
|
152
|
+
* How a person is named wherever the text may go on to say what they do: the name with the pronouns the world gave them, or the gender when only that is given.
|
|
153
|
+
* A model that is not told guesses, and a wrong guess written into a record or a narration is never corrected; nothing is made up when the world says neither.
|
|
154
|
+
*/
|
|
155
|
+
function referent(character) {
|
|
156
|
+
const mark = [character.pronouns, character.gender].find((text) => text !== void 0 && text.trim() !== "")?.trim();
|
|
157
|
+
return mark === void 0 ? character.name : `${character.name} (${mark})`;
|
|
158
|
+
}
|
|
159
|
+
//#endregion
|
|
8
160
|
//#region src/host/clock/story-clock.ts
|
|
9
161
|
var ClockError = class extends Error {};
|
|
10
162
|
/** A moment as it is told next to `now`: the clock when it is the same day, the date as well when it is not. */
|
|
@@ -141,6 +293,15 @@ function skipTime(session, config, turn, round, wall, request) {
|
|
|
141
293
|
}
|
|
142
294
|
//#endregion
|
|
143
295
|
//#region src/host/orchestration/defaults.ts
|
|
296
|
+
/** What the instructions say about how long each part of a character's answer may run. */
|
|
297
|
+
const limitVariables = (language) => {
|
|
298
|
+
const limits = answerLimits(language);
|
|
299
|
+
return {
|
|
300
|
+
thoughtLimit: limits.thought,
|
|
301
|
+
intentLimit: limits.intent,
|
|
302
|
+
utteranceLimit: limits.utterance
|
|
303
|
+
};
|
|
304
|
+
};
|
|
144
305
|
function describe(character) {
|
|
145
306
|
const lines = [`You are ${character.name}.`];
|
|
146
307
|
if (character.aliases.length > 0) lines.push(`You are also called ${character.aliases.join(", ")}.`);
|
|
@@ -246,7 +407,7 @@ function present(cast, self) {
|
|
|
246
407
|
const { key, character, state } = member;
|
|
247
408
|
const seen = [state?.publicState, state?.activity].filter((text) => text !== void 0 && text.trim() !== "");
|
|
248
409
|
const where = whereIs(member);
|
|
249
|
-
return `- ${character.name}${key === self ? " (you)" : ""}${where === "" ? "" : ` (${where})`}${seen.length > 0 ? `: ${seen.join("; ")}` : ""}`;
|
|
410
|
+
return `- ${key === self ? character.name : referent(character)}${key === self ? " (you)" : ""}${where === "" ? "" : ` (${where})`}${seen.length > 0 ? `: ${seen.join("; ")}` : ""}`;
|
|
250
411
|
}).join("\n");
|
|
251
412
|
}
|
|
252
413
|
/** A bounded, advisory order for who is most likely to need a turn; reachability still governs activation. */
|
|
@@ -310,9 +471,7 @@ function age(at, now) {
|
|
|
310
471
|
/** What a character remembers, in the way it remembers it: what is faded or vague is told as such. */
|
|
311
472
|
function remembered(memories, now) {
|
|
312
473
|
return memories.map((memory) => {
|
|
313
|
-
|
|
314
|
-
if (memory.clarity === "faded") return `- (${age(memory.at, now)}, the details are fuzzy) ${memory.text}`;
|
|
315
|
-
return `- (${age(memory.at, now)}, you barely remember) ${memory.text}`;
|
|
474
|
+
return `- (${memory.clarity === "clear" ? age(memory.at, now) : `${age(memory.at, now)}, ${memory.clarity === "faded" ? "the details are fuzzy" : "you barely remember"}`}${memory.linked === true ? ", it comes to mind with the rest" : ""}) ${memory.text}`;
|
|
316
475
|
}).join("\n");
|
|
317
476
|
}
|
|
318
477
|
/** Every character is told the same thing about the scene, plus who it is and what it remembers. */
|
|
@@ -355,6 +514,7 @@ const sharedContext = { brief(request) {
|
|
|
355
514
|
if (lines.length > 0) sections.push(`What you know exists (this does not tell you where it is now or what state it is in):\n${lines.join("\n")}`);
|
|
356
515
|
}
|
|
357
516
|
if (memories !== void 0 && memories.length > 0) sections.splice(1, 0, `What you remember that bears on this (only what you took in yourself; do not claim to remember more, and be unsure of what is fuzzy):\n${remembered(memories, time?.now)}`);
|
|
517
|
+
else if (memories !== void 0) sections.splice(1, 0, "What you remember that bears on this: nothing comes to mind.");
|
|
358
518
|
if (earlier !== void 0 && earlier.length > 0) sections.push(`Earlier in this scene, before this moment:\n${earlier.map(said).join("\n")}`);
|
|
359
519
|
if (attempt === 2 && reaction !== void 0) {
|
|
360
520
|
sections.push(`What just happened, and what you are reacting to:\n${reaction.map(said).join("\n")}`);
|
|
@@ -366,7 +526,10 @@ const sharedContext = { brief(request) {
|
|
|
366
526
|
request.text("roleplay/character-rules", { name: member.character.name }),
|
|
367
527
|
request.text("roleplay/character-style", { name: member.character.name }),
|
|
368
528
|
...request.lookup ? [request.text("roleplay/character-lookup")] : [],
|
|
369
|
-
request.text("roleplay/character-decide", {
|
|
529
|
+
request.text("roleplay/character-decide", {
|
|
530
|
+
name: member.character.name,
|
|
531
|
+
...limitVariables(request.language ?? "en")
|
|
532
|
+
})
|
|
370
533
|
].join("\n\n"),
|
|
371
534
|
prompt: sections.join("\n\n")
|
|
372
535
|
};
|
|
@@ -446,7 +609,7 @@ const castSummary = { scene({ tracked, time, world, cast, turn, input, queryVect
|
|
|
446
609
|
const role = character.control === "player" ? `the player's character, "${key}"` : `acts through "${key}"`;
|
|
447
610
|
const seen = [state?.publicState, state?.activity].filter((text) => text !== void 0 && text.trim() !== "");
|
|
448
611
|
const where = whereIs(member);
|
|
449
|
-
return `- ${character
|
|
612
|
+
return `- ${referent(character)} (${role})${where === "" ? "" : ` [${where}]`}${character.summary === "" ? "" : `: ${character.summary}`}${seen.length > 0 ? ` Currently: ${seen.join("; ")}` : ""}`;
|
|
450
613
|
};
|
|
451
614
|
const player = cast.find((member) => member.character.control === "player");
|
|
452
615
|
const days = time?.agenda === void 0 ? "" : describeSceneAgenda(time.agenda, time.now.now);
|
|
@@ -569,11 +732,12 @@ const exactUtterances = {
|
|
|
569
732
|
}
|
|
570
733
|
};
|
|
571
734
|
/** What a character is reminded of is what the story's records bring back for it: by the cues of the moment, by its words, and by its meaning when vectors exist. */
|
|
572
|
-
const recordsRecall = { recall: ({ member, situation, turn, policy, queryVector }, story, signal) => story.recallRanked({
|
|
735
|
+
const recordsRecall = { recall: ({ member, situation, turn, policy, queryVector, explain }, story, signal) => story.recallRanked({
|
|
573
736
|
characterId: member.character.id,
|
|
574
737
|
situation,
|
|
575
738
|
turn,
|
|
576
739
|
policy,
|
|
740
|
+
...explain === true ? { explain } : {},
|
|
577
741
|
...member.place === void 0 ? {} : { locationId: member.place.location.id }
|
|
578
742
|
}, signal, queryVector === void 0 ? {} : { queryVector }) };
|
|
579
743
|
/**
|
|
@@ -667,7 +831,8 @@ function viewOf(timeline) {
|
|
|
667
831
|
/** Where a notice stands for a turn that is not told by its own events: the player's words and what was delivered, as plain text. */
|
|
668
832
|
function noticeText(node) {
|
|
669
833
|
const told = node.output === void 0 ? "(nothing was delivered)" : node.output.segments.map((segment) => segment.type === "utterance" ? `${segment.name}: "${segment.text}"` : segment.text).join("\n");
|
|
670
|
-
const
|
|
834
|
+
const ooc = node.output?.ooc;
|
|
835
|
+
const ruling = ooc === void 0 ? "" : ooc.question === true ? `\nThe question was answered out of character: ${ooc.note}` : `\nThe command was ruled ${ooc.legal ? "legal" : "illegal and refused"}: ${ooc.note}`;
|
|
671
836
|
return `The story, as it went earlier (restored):\nThe player said: ${node.player}${ruling}\nIt was told to the player:\n${told}`;
|
|
672
837
|
}
|
|
673
838
|
//#endregion
|
|
@@ -1011,6 +1176,7 @@ var Timelines = class {
|
|
|
1011
1176
|
try {
|
|
1012
1177
|
await inheritImages(this.folder(from), this.folder(id), branch.timeline.nodes.map((node) => node.id));
|
|
1013
1178
|
inheritPrompts(this.folder(from), this.folder(id));
|
|
1179
|
+
inheritPacks(this.folder(from), this.folder(id));
|
|
1014
1180
|
const plan = planMove(branch.timeline, branch.timeline.head, [...agent.session.surface.nodes]);
|
|
1015
1181
|
this.reconcile(agent, plan);
|
|
1016
1182
|
writeTimeline(this.folder(id), branch.timeline);
|
|
@@ -1028,6 +1194,53 @@ var Timelines = class {
|
|
|
1028
1194
|
}
|
|
1029
1195
|
};
|
|
1030
1196
|
//#endregion
|
|
1197
|
+
//#region src/shared/notes.ts
|
|
1198
|
+
const NOTE_KINDS = [
|
|
1199
|
+
"suggestions",
|
|
1200
|
+
"away",
|
|
1201
|
+
"world"
|
|
1202
|
+
];
|
|
1203
|
+
//#endregion
|
|
1204
|
+
//#region src/host/sessions/notes.ts
|
|
1205
|
+
const KEY$1 = "notes";
|
|
1206
|
+
const isNote = (value) => {
|
|
1207
|
+
if (typeof value !== "object" || value === null) return false;
|
|
1208
|
+
const note = value;
|
|
1209
|
+
return NOTE_KINDS.includes(note["kind"]) && typeof note["turn"] === "number" && Array.isArray(note["lines"]) && note["lines"].every((line) => typeof line === "string");
|
|
1210
|
+
};
|
|
1211
|
+
/** The notes of a session, at most one per kind. */
|
|
1212
|
+
function readNotes(session) {
|
|
1213
|
+
const stored = session.metadata.getValue(KEY$1);
|
|
1214
|
+
return Array.isArray(stored) ? stored.filter(isNote) : [];
|
|
1215
|
+
}
|
|
1216
|
+
/** Replaces the note of the same kind. */
|
|
1217
|
+
function putNote(session, note) {
|
|
1218
|
+
session.metadata.setValue(KEY$1, [...readNotes(session).filter((existing) => existing.kind !== note.kind), note]);
|
|
1219
|
+
}
|
|
1220
|
+
/** The most lines one note keeps: what is past it is not told. */
|
|
1221
|
+
const MAX_NOTE_LINES = 8;
|
|
1222
|
+
/** Adds lines to the note of the kind when it is of the same turn, else starts it. */
|
|
1223
|
+
function addToNote(session, kind, turn, lines) {
|
|
1224
|
+
if (lines.length === 0) return;
|
|
1225
|
+
putNote(session, {
|
|
1226
|
+
kind,
|
|
1227
|
+
turn,
|
|
1228
|
+
lines: [...readNotes(session).find((note) => note.kind === kind && note.turn === turn)?.lines ?? [], ...lines].slice(0, MAX_NOTE_LINES)
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
/** Removes every note: they belong to the turn that made them. */
|
|
1232
|
+
function clearNotes(session) {
|
|
1233
|
+
if (readNotes(session).length > 0) session.metadata.setValue(KEY$1, []);
|
|
1234
|
+
}
|
|
1235
|
+
/**
|
|
1236
|
+
* The notes of a session, for the player's screen.
|
|
1237
|
+
* @throws {SessionNotFoundError} when the id names no session.
|
|
1238
|
+
*/
|
|
1239
|
+
function notesOfSession(deps, id) {
|
|
1240
|
+
if (!isSessionId(id) || !existsSync(sessionDatabase(deps.sessionsDir(), id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
1241
|
+
return readNotes(deps.open(id));
|
|
1242
|
+
}
|
|
1243
|
+
//#endregion
|
|
1031
1244
|
//#region src/host/pacing/director.ts
|
|
1032
1245
|
const PLOTS_METADATA_KEY = "roleplay.pacing.plots";
|
|
1033
1246
|
function populatePlots(metadata, plots) {
|
|
@@ -1124,53 +1337,6 @@ function updatePlotProgress(store, plotId, developmentId, action) {
|
|
|
1124
1337
|
return progress;
|
|
1125
1338
|
}
|
|
1126
1339
|
//#endregion
|
|
1127
|
-
//#region src/shared/notes.ts
|
|
1128
|
-
const NOTE_KINDS = [
|
|
1129
|
-
"suggestions",
|
|
1130
|
-
"away",
|
|
1131
|
-
"world"
|
|
1132
|
-
];
|
|
1133
|
-
//#endregion
|
|
1134
|
-
//#region src/host/sessions/notes.ts
|
|
1135
|
-
const KEY$1 = "notes";
|
|
1136
|
-
const isNote = (value) => {
|
|
1137
|
-
if (typeof value !== "object" || value === null) return false;
|
|
1138
|
-
const note = value;
|
|
1139
|
-
return NOTE_KINDS.includes(note["kind"]) && typeof note["turn"] === "number" && Array.isArray(note["lines"]) && note["lines"].every((line) => typeof line === "string");
|
|
1140
|
-
};
|
|
1141
|
-
/** The notes of a session, at most one per kind. */
|
|
1142
|
-
function readNotes(session) {
|
|
1143
|
-
const stored = session.metadata.getValue(KEY$1);
|
|
1144
|
-
return Array.isArray(stored) ? stored.filter(isNote) : [];
|
|
1145
|
-
}
|
|
1146
|
-
/** Replaces the note of the same kind. */
|
|
1147
|
-
function putNote(session, note) {
|
|
1148
|
-
session.metadata.setValue(KEY$1, [...readNotes(session).filter((existing) => existing.kind !== note.kind), note]);
|
|
1149
|
-
}
|
|
1150
|
-
/** The most lines one note keeps: what is past it is not told. */
|
|
1151
|
-
const MAX_NOTE_LINES = 8;
|
|
1152
|
-
/** Adds lines to the note of the kind when it is of the same turn, else starts it. */
|
|
1153
|
-
function addToNote(session, kind, turn, lines) {
|
|
1154
|
-
if (lines.length === 0) return;
|
|
1155
|
-
putNote(session, {
|
|
1156
|
-
kind,
|
|
1157
|
-
turn,
|
|
1158
|
-
lines: [...readNotes(session).find((note) => note.kind === kind && note.turn === turn)?.lines ?? [], ...lines].slice(0, MAX_NOTE_LINES)
|
|
1159
|
-
});
|
|
1160
|
-
}
|
|
1161
|
-
/** Removes every note: they belong to the turn that made them. */
|
|
1162
|
-
function clearNotes(session) {
|
|
1163
|
-
if (readNotes(session).length > 0) session.metadata.setValue(KEY$1, []);
|
|
1164
|
-
}
|
|
1165
|
-
/**
|
|
1166
|
-
* The notes of a session, for the player's screen.
|
|
1167
|
-
* @throws {SessionNotFoundError} when the id names no session.
|
|
1168
|
-
*/
|
|
1169
|
-
function notesOfSession(deps, id) {
|
|
1170
|
-
if (!isSessionId(id) || !existsSync(sessionDatabase(deps.sessionsDir(), id))) throw new SessionNotFoundError(`no session "${id}"`);
|
|
1171
|
-
return readNotes(deps.open(id));
|
|
1172
|
-
}
|
|
1173
|
-
//#endregion
|
|
1174
1340
|
//#region src/host/sessions/activity.ts
|
|
1175
1341
|
const KEY = "activity";
|
|
1176
1342
|
const isEntry = (value) => {
|
|
@@ -1183,10 +1349,38 @@ function readActivity(session) {
|
|
|
1183
1349
|
const stored = session.metadata.getValue(KEY);
|
|
1184
1350
|
return Array.isArray(stored) ? stored.filter(isEntry) : [];
|
|
1185
1351
|
}
|
|
1352
|
+
/** Files the run and returns the runs that fell off the end of the record to make room. */
|
|
1186
1353
|
function recordActivity(session, entry) {
|
|
1187
|
-
|
|
1354
|
+
const all = [...readActivity(session), entry];
|
|
1355
|
+
session.metadata.setValue(KEY, all.slice(-60));
|
|
1356
|
+
return all.slice(0, -60);
|
|
1357
|
+
}
|
|
1358
|
+
const RUN_FOLDER = "activity";
|
|
1359
|
+
const RUN_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
|
|
1360
|
+
const runFile = (folder, run) => {
|
|
1361
|
+
if (!RUN_ID.test(run)) throw new RangeError(`"${run}" is not a run`);
|
|
1362
|
+
return join(folder, RUN_FOLDER, `${run}.json`);
|
|
1363
|
+
};
|
|
1364
|
+
/** Stores what a helper was told and did, beside the session's database: it is bulky, and only read to find out what went wrong. */
|
|
1365
|
+
function keepRunDetail(folder, run, detail) {
|
|
1366
|
+
const file = runFile(folder, run);
|
|
1367
|
+
mkdirSync(join(folder, RUN_FOLDER), { recursive: true });
|
|
1368
|
+
writeFileSync(`${file}.tmp`, JSON.stringify(detail));
|
|
1369
|
+
renameSync(`${file}.tmp`, file);
|
|
1370
|
+
}
|
|
1371
|
+
/** The stored detail of a run, or nothing when it was not kept or has been dropped. */
|
|
1372
|
+
function readRunDetail(folder, run) {
|
|
1373
|
+
try {
|
|
1374
|
+
return JSON.parse(readFileSync(runFile(folder, run), "utf8"));
|
|
1375
|
+
} catch (error) {
|
|
1376
|
+
if (error.code === "ENOENT") return void 0;
|
|
1377
|
+
throw error;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
function forgetRunDetails(folder, dropped) {
|
|
1381
|
+
for (const entry of dropped) if (entry.run !== void 0) rmSync(runFile(folder, entry.run), { force: true });
|
|
1188
1382
|
}
|
|
1189
1383
|
//#endregion
|
|
1190
|
-
export {
|
|
1384
|
+
export { readTime as A, defaultBoundaries as C, describeTime as D, beginTurn as E, CHARACTER_ACTION_SCHEMA as F, RESULTS as I, answerEstimate as L, zoneOf as M, referent as N, describeWhen as O, AWAY_ACTION_SCHEMA as P, parseCharacterAction as R, pathTo as S, ClockError as T, putNote as _, recordActivity as a, Timelines as b, describePacingAdvice as c, plotProgressOf as d, populatePlots as f, notesOfSession as g, clearNotes as h, readRunDetail as i, skipTime as j, endRound as k, pacingAdvice as l, addToNote as m, keepRunDetail as n, PLOTS_METADATA_KEY as o, updatePlotProgress as p, readActivity as r, addSessionPlot as s, forgetRunDetails as t, plotAuthorNeeded as u, readNotes as v, sameWords as w, readTimeline as x, TimelineError as y };
|
|
1191
1385
|
|
|
1192
|
-
//# sourceMappingURL=activity-
|
|
1386
|
+
//# sourceMappingURL=activity-t7OBgHlc.js.map
|