@dsh-agentic-roleplay/core 0.11.0 → 0.11.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/lib/{access-CXtaZNbx.js → access-Md1YTSX1.js} +4 -1
- package/lib/{authoring-tools--6V1pIIL.js → authoring-tools-BFdw7ahj.js} +72 -9
- package/lib/authoring.js +38 -8
- package/lib/client.js +761 -411
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +2 -2
- package/lib/doctor.js +3 -3
- package/lib/{gallery-CtG-bDzz.js → gallery-BWHmjogd.js} +3 -3
- package/lib/{generator-nLoPM5MF.js → generator-QCdm8nUh.js} +9 -3
- package/lib/helper.js +9 -0
- package/lib/{hooks-DORky4KT.js → hooks-C2U1-8ur.js} +676 -15
- package/lib/images.js +4 -4
- package/lib/index.js +225 -19
- package/lib/{library-CH-ahlm0.js → library-4zmCAshR.js} +3 -3
- package/lib/{lorebook-author-tools-BrVde1N-.js → lorebook-author-tools-Bjfjt3bg.js} +7 -7
- package/lib/lorebook-authoring.js +4 -4
- package/lib/{narration-B0hConSw.js → narration-b_VBEUWn.js} +7 -3
- package/lib/orchestration.js +338 -28
- package/lib/{pack-jail-Bk82pX9t.js → pack-jail-Ci9bIeDI.js} +17 -14
- package/lib/{packs-ELfh8yh1.js → packs-CYkozh8Q.js} +2 -2
- package/lib/{presenter-agent-UKbKYXMO.js → presenter-agent-CqkAL03Q.js} +10 -7
- package/lib/{preset-D9Sfc8sf.js → preset-B-35yUmt.js} +3 -3
- package/lib/{preset-author-tools-B3pFL1-e.js → preset-author-tools-BUymqZM5.js} +7 -7
- package/lib/preset-authoring.js +5 -5
- package/lib/{presets-BRt4Xsy4.js → presets-_U-xroo0.js} +27 -8
- package/lib/{reflection-CHiHsY4Y.js → reflection-B9N0z3KY.js} +9 -608
- package/lib/{text-CzqhC8sT.js → text-C2AGl7Je.js} +11 -2
- package/lib/{turn-guard-B53qOWEU.js → turn-guard-C0M3rXEN.js} +2 -2
- package/package.json +2 -2
- package/prompts/en/import/variables.md +1 -0
- package/prompts/en/roleplay/character-decide.md +1 -1
- package/prompts/en/roleplay/decide-reuse.md +3 -0
- package/prompts/en/roleplay/decide-variable.md +1 -0
- package/prompts/en/roleplay/image-presenter.md +1 -0
- package/prompts/en/roleplay/track-values.md +1 -0
- package/prompts/en/roleplay/track-variables.md +1 -0
- package/prompts/zh/import/variables.md +1 -0
- package/prompts/zh/roleplay/character-decide.md +1 -1
- package/prompts/zh/roleplay/decide-reuse.md +3 -0
- package/prompts/zh/roleplay/decide-variable.md +1 -0
- package/prompts/zh/roleplay/image-presenter.md +1 -0
- package/prompts/zh/roleplay/track-values.md +1 -0
- package/prompts/zh/roleplay/track-variables.md +1 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { l as roleplaySessionOf, t as promptFor } from "./access-
|
|
2
|
-
import { H as routeVerdicts, L as announceProblem, R as askYesNo, U as yesAt, V as noAt, f as sha, o as listPresets, s as loadPreset, z as mergeReports } from "./presets-
|
|
3
|
-
import {
|
|
4
|
-
import { i as translator, r as languageOf
|
|
1
|
+
import { l as roleplaySessionOf, t as promptFor } from "./access-Md1YTSX1.js";
|
|
2
|
+
import { H as routeVerdicts, L as announceProblem, R as askYesNo, U as yesAt, V as noAt, f as sha, o as listPresets, s as loadPreset, z as mergeReports } from "./presets-_U-xroo0.js";
|
|
3
|
+
import { $ as inheritPrompts, D as referent, I as wrongLanguage, X as PROMPTS_FOLDER, mt as describeWhen } from "./hooks-C2U1-8ur.js";
|
|
4
|
+
import { i as translator, r as languageOf } from "./text-C2AGl7Je.js";
|
|
5
5
|
import { T as estimateAnswer, a as childTrace, l as runChild, n as childModel, r as childSampling } from "./child-C9nPIy9j.js";
|
|
6
|
-
import { s as inheritImages } from "./library-
|
|
7
|
-
import { i as inheritPacks } from "./packs-
|
|
6
|
+
import { s as inheritImages } from "./library-4zmCAshR.js";
|
|
7
|
+
import { i as inheritPacks } from "./packs-CYkozh8Q.js";
|
|
8
8
|
import { dirname, join } from "node:path";
|
|
9
|
-
import {
|
|
9
|
+
import { characterKey, locationKey, sessionDatabase, sessionFolder, tokens } from "@dsh-agentic-roleplay/state";
|
|
10
10
|
import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
11
11
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
12
12
|
// ../dsh-roleplay-model/src/memory.ts
|
|
@@ -104,605 +104,6 @@ function writeTimeline(folder, timeline) {
|
|
|
104
104
|
writeFileSync(aside, JSON.stringify(timeline, null, 2));
|
|
105
105
|
renameSync(aside, target);
|
|
106
106
|
}
|
|
107
|
-
// src/host/orchestration/referent.ts
|
|
108
|
-
/**
|
|
109
|
-
* 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.
|
|
110
|
-
* 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.
|
|
111
|
-
*/
|
|
112
|
-
function referent(character) {
|
|
113
|
-
const mark = [character.pronouns, character.gender].find((text) => text !== void 0 && text.trim() !== "")?.trim();
|
|
114
|
-
return mark === void 0 ? character.name : `${character.name} (${mark})`;
|
|
115
|
-
}
|
|
116
|
-
// src/host/orchestration/defaults.ts
|
|
117
|
-
const ENGLISH = translator("en");
|
|
118
|
-
/** What the instructions say about how long each part of a character's answer may run. */
|
|
119
|
-
const limitVariables = (language) => {
|
|
120
|
-
const limits = answerLimits(language);
|
|
121
|
-
return {
|
|
122
|
-
thoughtLimit: limits.thought,
|
|
123
|
-
intentLimit: limits.intent,
|
|
124
|
-
utteranceLimit: limits.utterance
|
|
125
|
-
};
|
|
126
|
-
};
|
|
127
|
-
function describe(character, tr) {
|
|
128
|
-
const lines = [tr("You are {name}.", { name: character.name })];
|
|
129
|
-
if (character.aliases.length > 0) lines.push(tr("You are also called {names}.", { names: character.aliases.join(tr(", ")) }));
|
|
130
|
-
const facts = [
|
|
131
|
-
character.age === void 0 ? void 0 : tr("age: {value}", { value: character.age }),
|
|
132
|
-
character.gender === void 0 ? void 0 : tr("gender: {value}", { value: character.gender }),
|
|
133
|
-
character.pronouns === void 0 ? void 0 : tr("pronouns: {value}", { value: character.pronouns })
|
|
134
|
-
].filter((fact) => fact !== void 0);
|
|
135
|
-
if (facts.length > 0) lines.push(facts.join(tr("; ")) + tr("."));
|
|
136
|
-
for (const [label, text] of [
|
|
137
|
-
["Summary", character.summary],
|
|
138
|
-
["Personality", character.personality],
|
|
139
|
-
["Background", character.background],
|
|
140
|
-
["Appearance", character.appearance],
|
|
141
|
-
["How you speak", character.speech.style]
|
|
142
|
-
]) if (text.trim() !== "") lines.push(`${tr(label)}${tr(": ")}${text.trim()}`);
|
|
143
|
-
return lines.join("\n");
|
|
144
|
-
}
|
|
145
|
-
/** At most this many features and ways out of a place are told at once. */
|
|
146
|
-
const SHOWN_FEATURES = 12;
|
|
147
|
-
const SHOWN_EXITS = 12;
|
|
148
|
-
const sentence = (text) => {
|
|
149
|
-
return (/^[^.!?。!?]*[.!?。!?]?/u.exec(text.trim())?.[0] ?? text).trim();
|
|
150
|
-
};
|
|
151
|
-
/** At most this many things are listed at once: the rest are said to be there and left for a closer look. */
|
|
152
|
-
const SHOWN_ITEMS = 12;
|
|
153
|
-
/** One thing in a sentence: how many, what state it is in, where it is. */
|
|
154
|
-
function describeItem(item, { withKeys }, tr = ENGLISH) {
|
|
155
|
-
const name = `${item.quantity > 1 ? `${item.quantity} ` : ""}${item.name}${item.quality === "" ? "" : ` (${item.quality})`}`;
|
|
156
|
-
const extra = [
|
|
157
|
-
item.hidden ? tr("hidden") : "",
|
|
158
|
-
item.state === void 0 ? "" : item.state,
|
|
159
|
-
item.where ?? ""
|
|
160
|
-
].filter((part) => part !== "").join(tr(", "));
|
|
161
|
-
const inside = item.contents === void 0 ? "" : tr(" holding {things}", { things: item.contents.join(tr(", ")) });
|
|
162
|
-
return `${withKeys ? `${item.key}: ` : ""}${name}${extra === "" ? "" : ` [${extra}]`}${inside}`;
|
|
163
|
-
}
|
|
164
|
-
/** A list of things, capped. */
|
|
165
|
-
function describeItems(items, options, tr = ENGLISH) {
|
|
166
|
-
return `${items.slice(0, SHOWN_ITEMS).map((item) => describeItem(item, options, tr)).join(tr("; "))}${items.length > SHOWN_ITEMS ? tr("; and {count} more", { count: items.length - SHOWN_ITEMS }) : ""}`;
|
|
167
|
-
}
|
|
168
|
-
/** What someone in a place is told about it: what it is like, what can be pointed at, and the ways out. */
|
|
169
|
-
function describePlace(view, { withKeys }, tr = ENGLISH) {
|
|
170
|
-
const { location, exits } = view;
|
|
171
|
-
const lines = [`${location.name}${withKeys ? ` (${view.key})` : ""}${location.description === "" ? "" : `: ${location.description}`}`];
|
|
172
|
-
if (location.features.length > 0) {
|
|
173
|
-
const shown = location.features.slice(0, SHOWN_FEATURES).map((feature) => `${withKeys ? `${feature.key}: ` : ""}${feature.name}${feature.description === "" ? "" : ` - ${sentence(feature.description)}`}`);
|
|
174
|
-
lines.push(`${tr("Things here: ")}${shown.join(tr("; "))}${location.features.length > SHOWN_FEATURES ? tr("; and {count} more", { count: location.features.length - SHOWN_FEATURES }) : ""}`);
|
|
175
|
-
}
|
|
176
|
-
if (exits.length > 0) {
|
|
177
|
-
const shown = exits.slice(0, SHOWN_EXITS).map(({ key, name, exit }) => `${withKeys ? `${key}: ` : ""}${name}${exit.description === "" ? "" : ` (${sentence(exit.description)})`}${exit.state === "open" ? "" : ` [${tr(exit.state)}${exit.note === "" ? "" : `: ${exit.note}`}]`}`);
|
|
178
|
-
lines.push(`${tr("Ways out: ")}${shown.join(tr("; "))}${exits.length > SHOWN_EXITS ? tr("; and {count} more", { count: exits.length - SHOWN_EXITS }) : ""}`);
|
|
179
|
-
}
|
|
180
|
-
if (view.items !== void 0 && view.items.length > 0) lines.push(`${tr("Lying about: ")}${describeItems(view.items, { withKeys }, tr)}`);
|
|
181
|
-
return lines;
|
|
182
|
-
}
|
|
183
|
-
/** How long the player has to have been away for it to be worth telling the game master. */
|
|
184
|
-
const NOTICEABLE_ABSENCE = 5 * MINUTE;
|
|
185
|
-
/** What the game master is told about time at the start of a turn, and how it passes. */
|
|
186
|
-
function timeNotice(time, language, tr) {
|
|
187
|
-
const now = tr("Time: {time}.", { time: describeTime(time.now, language) });
|
|
188
|
-
if (time.now.mode === "simulated") return `${now} ${tr("The story's time moves only as you say: each round takes what you give it (elapsed_seconds in resolve_round, or the default), and advance_time skips ahead.")}`;
|
|
189
|
-
const away = time.away !== void 0 && time.away >= NOTICEABLE_ABSENCE ? ` ${tr("The player was away for {duration} of real time and the story went on meanwhile: characters have been about their own business, so do not assume anyone is where or as the player left them unless the records say so.", { duration: describeDuration(time.away, language) })}` : "";
|
|
190
|
-
return `${now} ${tr("The story's time follows the real clock: it cannot be skipped, and each round takes as long as it really took.")}${away}`;
|
|
191
|
-
}
|
|
192
|
-
/** What a character is told of its day, its commitments and what it is after. */
|
|
193
|
-
function describeAgenda(agenda, now, tr = ENGLISH, language = "en") {
|
|
194
|
-
const { zone } = agenda;
|
|
195
|
-
const when = (instant) => describeWhen(instant, now, zone, language);
|
|
196
|
-
const at = (place) => place === void 0 ? "" : tr(" at {place}", { place });
|
|
197
|
-
const lines = [];
|
|
198
|
-
if (agenda.now !== void 0) lines.push(tr("Your day, now: {activity}{place}, until {until}{note}.", {
|
|
199
|
-
activity: agenda.now.activity,
|
|
200
|
-
place: at(agenda.now.place),
|
|
201
|
-
until: when(agenda.now.until),
|
|
202
|
-
note: agenda.now.interruptible ? "" : tr(" (not something you would drop lightly)")
|
|
203
|
-
}));
|
|
204
|
-
if (agenda.next !== void 0) lines.push(tr("Your day, next: {activity}{place}, from {from}.", {
|
|
205
|
-
activity: agenda.next.activity,
|
|
206
|
-
place: at(agenda.next.place),
|
|
207
|
-
from: when(agenda.next.at)
|
|
208
|
-
}));
|
|
209
|
-
for (const engagement of agenda.engagements) {
|
|
210
|
-
const values = {
|
|
211
|
-
title: engagement.title,
|
|
212
|
-
place: at(engagement.place),
|
|
213
|
-
with: engagement.with.length === 0 ? "" : tr(", with {names}", { names: engagement.with.join(tr(", ")) }),
|
|
214
|
-
at: when(engagement.at)
|
|
215
|
-
};
|
|
216
|
-
lines.push(engagement.overdue ? tr("You were to: {title}{place}{with}, at {at}, which has passed and is still open.", values) : tr("You are due to: {title}{place}{with}, at {at}.", values));
|
|
217
|
-
}
|
|
218
|
-
if (agenda.goals.length > 0) {
|
|
219
|
-
lines.push(tr("What you are after:"));
|
|
220
|
-
for (const goal of agenda.goals) {
|
|
221
|
-
const by = goal.deadline === void 0 ? "" : goal.overdue ? tr(", by {deadline}, which has passed", { deadline: when(goal.deadline) }) : tr(", by {deadline}", { deadline: when(goal.deadline) });
|
|
222
|
-
lines.push(`- ${goal.name} (${goal.type})${by}${goal.description === "" ? "" : `${tr(": ")}${sentence(goal.description)}`}${goal.plan.length === 0 ? "" : tr(" Next: {plan}.", { plan: goal.plan.join(tr("; ")) })}`);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return lines;
|
|
226
|
-
}
|
|
227
|
-
/** What the game master is told of the characters' days at the start of a turn; nothing when there is nothing to tell. */
|
|
228
|
-
function describeSceneAgenda(agenda, now, tr = ENGLISH, language = "en") {
|
|
229
|
-
const lines = [];
|
|
230
|
-
const join = (entries) => entries.join(tr("; "));
|
|
231
|
-
if (agenda.moved.length > 0) lines.push(tr("By their routines since you last looked: {moves}.", { moves: join(agenda.moved.map((move) => tr("{name} went to {place} ({activity})", {
|
|
232
|
-
name: move.name,
|
|
233
|
-
place: move.to,
|
|
234
|
-
activity: move.activity
|
|
235
|
-
}))) }));
|
|
236
|
-
if (agenda.here.length > 0) lines.push(tr("With the player's character, and their days: {days}. The characters decide for themselves whether to keep to their day; the moment may keep them.", { days: join(agenda.here.map((entry) => `${entry.name}${tr(": ")}${entry.note}`)) }));
|
|
237
|
-
if (agenda.engagements.length > 0) {
|
|
238
|
-
const entries = agenda.engagements.map((engagement) => {
|
|
239
|
-
const values = {
|
|
240
|
-
title: engagement.title,
|
|
241
|
-
with: engagement.with.join(tr(", ")),
|
|
242
|
-
place: engagement.place === void 0 ? "" : tr(", at {place}", { place: engagement.place }),
|
|
243
|
-
when: describeWhen(engagement.at, now, agenda.zone, language)
|
|
244
|
-
};
|
|
245
|
-
return engagement.overdue ? tr("\"{title}\" ({with}{place}) was due {when} and is still open", values) : tr("\"{title}\" ({with}{place}) is due {when}", values);
|
|
246
|
-
});
|
|
247
|
-
lines.push(tr("Commitments due soon or overdue: {entries}.", { entries: join(entries) }));
|
|
248
|
-
}
|
|
249
|
-
return lines.join("\n");
|
|
250
|
-
}
|
|
251
|
-
/** In words, how a character stands with another, from the numbers of its profile; nothing for what is unremarkable. */
|
|
252
|
-
function describeAttitude(relation, tr = ENGLISH) {
|
|
253
|
-
return [
|
|
254
|
-
relation.familiarity >= .7 ? tr("knows them well") : relation.familiarity <= .15 ? tr("barely knows them") : "",
|
|
255
|
-
relation.trust >= .4 ? tr("trusts them") : relation.trust <= -.4 ? tr("distrusts them") : "",
|
|
256
|
-
relation.affinity >= .4 ? tr("is fond of them") : relation.affinity <= -.4 ? tr("dislikes them") : "",
|
|
257
|
-
relation.tension >= .5 ? tr("things are strained between them") : ""
|
|
258
|
-
].filter((part) => part !== "").join(tr(", "));
|
|
259
|
-
}
|
|
260
|
-
function whereIs(member, tr = ENGLISH) {
|
|
261
|
-
const place = member.place;
|
|
262
|
-
if (place === void 0) return "";
|
|
263
|
-
return [place.position, place.feature === void 0 ? "" : tr("at {feature}", { feature: place.feature.name })].filter((part) => part !== "").join(tr(", "));
|
|
264
|
-
}
|
|
265
|
-
function present(cast, self, tr) {
|
|
266
|
-
return cast.map((member) => {
|
|
267
|
-
const { key, character, state } = member;
|
|
268
|
-
const seen = [state?.publicState, state?.activity].filter((text) => text !== void 0 && text.trim() !== "");
|
|
269
|
-
const where = whereIs(member);
|
|
270
|
-
return `- ${key === self ? character.name : referent(character)}${key === self ? tr(" (you)") : ""}${where === "" ? "" : ` (${where})`}${seen.length > 0 ? `${tr(": ")}${seen.join(tr("; "))}` : ""}`;
|
|
271
|
-
}).join("\n");
|
|
272
|
-
}
|
|
273
|
-
/** A bounded, advisory order for who is most likely to need a turn; reachability still governs activation. */
|
|
274
|
-
function describeActivationCandidates(cast, input, story, tr = ENGLISH) {
|
|
275
|
-
const player = cast.find((member) => member.character.control === "player");
|
|
276
|
-
if (player === void 0) return "";
|
|
277
|
-
const named = mentioned(input, cast.map((member) => member.character));
|
|
278
|
-
const cues = tokens(input);
|
|
279
|
-
const candidates = cast.filter((member) => member.character.control === "agent").map((member) => {
|
|
280
|
-
const relation = story.relationships.get(member.character.id, player.character.id);
|
|
281
|
-
const here = member.place === void 0 || player.place === void 0 || member.place.location.id === player.place.location.id;
|
|
282
|
-
const goal = story.intents.list(member.character.id, { status: "active" }).map((intent) => ({
|
|
283
|
-
intent,
|
|
284
|
-
match: overlap(cues, `${intent.name} ${intent.description}`, [])
|
|
285
|
-
})).sort((a, b) => b.match - a.match)[0];
|
|
286
|
-
const factionGoal = story.factionMemberships.ofCharacter(member.character.id, "active").flatMap((membership) => story.factionIntents.list(membership.factionId, { status: "active" }).map((intent) => ({
|
|
287
|
-
intent,
|
|
288
|
-
match: overlap(cues, `${intent.name} ${intent.description}`, []) * membership.commitment
|
|
289
|
-
}))).sort((a, b) => b.match - a.match)[0];
|
|
290
|
-
return {
|
|
291
|
-
member,
|
|
292
|
-
reasons: [
|
|
293
|
-
named.has(member.character.id) ? tr("named in the move") : "",
|
|
294
|
-
here ? tr("in the scene") : "",
|
|
295
|
-
(goal?.match ?? 0) >= 2 ? tr("own goal: {goal}", { goal: goal.intent.name }) : "",
|
|
296
|
-
(factionGoal?.match ?? 0) >= 2 ? tr("faction pressure: {goal}", { goal: factionGoal.intent.name }) : "",
|
|
297
|
-
relation !== void 0 && relation.tension >= .5 ? tr("high tension toward the player") : "",
|
|
298
|
-
relation !== void 0 && relation.trust <= -.4 ? tr("distrusts the player") : "",
|
|
299
|
-
relation !== void 0 && Math.abs(relation.affinity) >= .4 ? relation.affinity > 0 ? tr("cares about the player") : tr("dislikes the player") : ""
|
|
300
|
-
].filter((reason) => reason !== ""),
|
|
301
|
-
score: (named.has(member.character.id) ? 4 : 0) + (here ? 2 : 0) + Math.min(2, (goal?.match ?? 0) / 2) + Math.min(2, (factionGoal?.match ?? 0) / 2) + (relation?.tension ?? 0) + Math.max(0, -(relation?.trust ?? 0)) * .5 + Math.abs(relation?.affinity ?? 0) * .5
|
|
302
|
-
};
|
|
303
|
-
}).filter((entry) => entry.score > 0).sort((a, b) => b.score - a.score || a.member.key.localeCompare(b.member.key)).slice(0, 5);
|
|
304
|
-
if (candidates.length === 0) return "";
|
|
305
|
-
return `${tr("Likely characters to activate, in priority order (advice only; activate only whoever the moment actually reaches):")}\n${candidates.map(({ member, reasons }) => `- ${member.character.name} (${member.key}): ${reasons.join(tr(", ")) || tr("socially implicated")}`).join("\n")}`;
|
|
306
|
-
}
|
|
307
|
-
function said(entry, tr) {
|
|
308
|
-
return entry.utterance === void 0 ? tr("- {name} intended: {intent} ({result}) {summary}", {
|
|
309
|
-
name: entry.name,
|
|
310
|
-
intent: entry.intent,
|
|
311
|
-
result: entry.result,
|
|
312
|
-
summary: entry.summary
|
|
313
|
-
}) : tr("- {name} said \"{utterance}\" and intended: {intent} ({result}) {summary}", {
|
|
314
|
-
name: entry.name,
|
|
315
|
-
utterance: entry.utterance,
|
|
316
|
-
intent: entry.intent,
|
|
317
|
-
result: entry.result,
|
|
318
|
-
summary: entry.summary
|
|
319
|
-
});
|
|
320
|
-
}
|
|
321
|
-
function age(at, now, tr) {
|
|
322
|
-
if (at === void 0 || now === void 0) return tr("some time ago");
|
|
323
|
-
const seconds = Math.max(0, Math.floor((now - at) / 1e3));
|
|
324
|
-
if (seconds < 60) return tr("just now");
|
|
325
|
-
const amount = Math.floor(seconds / (seconds >= 86400 ? 86400 : seconds >= 3600 ? 3600 : 60));
|
|
326
|
-
if (seconds >= 86400) return amount === 1 ? tr("1 day ago") : tr("{amount} days ago", { amount });
|
|
327
|
-
if (seconds >= 3600) return amount === 1 ? tr("1 hour ago") : tr("{amount} hours ago", { amount });
|
|
328
|
-
return amount === 1 ? tr("1 minute ago") : tr("{amount} minutes ago", { amount });
|
|
329
|
-
}
|
|
330
|
-
/** What a character remembers, in the way it remembers it: what is faded or vague is told as such, and what it is sure or doubtful of. */
|
|
331
|
-
function remembered(memories, tr, now) {
|
|
332
|
-
return memories.map((memory) => {
|
|
333
|
-
const clarity = memory.clarity === "clear" ? [] : [memory.clarity === "faded" ? tr("the details are fuzzy") : tr("you barely remember")];
|
|
334
|
-
const sure = memory.confidence === "sure" ? [tr("you are sure of it")] : memory.confidence === "doubtful" ? [tr("you doubt it")] : [];
|
|
335
|
-
const against = memory.disputed === true ? [tr("something you have seen since speaks against it")] : [];
|
|
336
|
-
return `- (${[
|
|
337
|
-
age(memory.at, now, tr),
|
|
338
|
-
...clarity,
|
|
339
|
-
...sure,
|
|
340
|
-
...against,
|
|
341
|
-
...memory.linked === true ? [tr("it comes to mind with the rest")] : []
|
|
342
|
-
].join(tr(", "))}) ${memory.text}`;
|
|
343
|
-
}).join("\n");
|
|
344
|
-
}
|
|
345
|
-
/** Every character is told the same thing about the scene, plus who it is and what it remembers. */
|
|
346
|
-
const sharedContext = { brief(request) {
|
|
347
|
-
const { member, cast, situation, attempt, earlier, reaction, previous, memories, place, relationships, knowledge, affiliations, carrying, time, agenda } = request;
|
|
348
|
-
const language = languageOf(request.language);
|
|
349
|
-
const tr = translator(language);
|
|
350
|
-
const list = (entries) => entries.join(tr("; "));
|
|
351
|
-
const company = place === void 0 ? cast : place.here;
|
|
352
|
-
const sections = [
|
|
353
|
-
`${tr("Situation:")}\n${situation}`,
|
|
354
|
-
...time === void 0 ? [] : [tr("Now: {time}.", { time: describeTime(time, language) })],
|
|
355
|
-
...place === void 0 ? [] : [`${tr("Where you are:")}\n${describePlace(place, { withKeys: false }, tr).join("\n")}`],
|
|
356
|
-
`${tr("Present:")}\n${present(company, member.key, tr)}`
|
|
357
|
-
];
|
|
358
|
-
if (request.upcoming !== void 0 && request.upcoming.length > 0) sections.push(`${tr("What you know is coming:")}\n${request.upcoming.map((entry) => `- ${entry.text}${entry.when === void 0 ? "" : ` (${entry.when})`}`).join("\n")}`);
|
|
359
|
-
if (request.cues !== void 0 && request.cues.length > 0) sections.push(`${tr("Just now you notice:")}\n${request.cues.map((cue) => `- ${cue}`).join("\n")}`);
|
|
360
|
-
if (request.tracked !== void 0 && request.tracked.self !== "") sections.push(`${tr("How you are (what you can tell of yourself):")}\n${request.tracked.self}`);
|
|
361
|
-
if (request.tracked !== void 0 && request.tracked.others.length > 0) sections.push(`${tr("What you can tell of the others here:")}\n${request.tracked.others.map((other) => `- ${other.name}: ${other.text}`).join("\n")}`);
|
|
362
|
-
const day = agenda === void 0 || time === void 0 ? [] : describeAgenda(agenda, time.now, tr, language);
|
|
363
|
-
if (day.length > 0) sections.push(`${tr("Your day and what you are after (plans, not orders: keep them, put them off or drop them as the moment and your character suggest):")}\n${day.join("\n")}`);
|
|
364
|
-
if (carrying !== void 0 && carrying.length > 0) sections.push(`${tr("What you have on you:")}\n${describeItems(carrying, { withKeys: false }, tr)}`);
|
|
365
|
-
if (relationships !== void 0 && relationships.length > 0) sections.push(`${tr("How you stand with people who bear on this moment (your own view, not objective fact):")}\n${relationships.map((relation) => {
|
|
366
|
-
const attitude = describeAttitude(relation, tr);
|
|
367
|
-
return `- ${relation.name}${relation.present ? tr(" (here)") : tr(" (not here)")} — ${relation.label}${relation.summary === "" ? "" : `${tr(": ")}${relation.summary}`}${attitude === "" ? "" : ` [${attitude}]`}`;
|
|
368
|
-
}).join("\n")}`);
|
|
369
|
-
if (affiliations !== void 0 && affiliations.length > 0) sections.push(`${tr("Your affiliations (their goals are pressures and commitments, not commands):")}\n${affiliations.map((entry) => {
|
|
370
|
-
const position = [entry.role, entry.rank].filter(Boolean).join(tr(", ")) || tr("member");
|
|
371
|
-
const goals = entry.goals.length === 0 ? "" : tr(" Goals: {goals}.", { goals: list(entry.goals) });
|
|
372
|
-
const state = entry.publicState === "" ? "" : ` ${entry.publicState}`;
|
|
373
|
-
const attitude = entry.relationship === void 0 ? "" : describeAttitude(entry.relationship, tr);
|
|
374
|
-
return tr("- {name}: {position}; {status}; commitment {commitment}.", {
|
|
375
|
-
name: entry.name,
|
|
376
|
-
position,
|
|
377
|
-
status: entry.status,
|
|
378
|
-
commitment: entry.commitment.toFixed(2)
|
|
379
|
-
}) + `${state}${goals}${attitude === "" ? "" : tr(" Your view: {attitude}.", { attitude })}`;
|
|
380
|
-
}).join("\n")}`);
|
|
381
|
-
if (knowledge !== void 0) {
|
|
382
|
-
const shown = (entries) => list(entries.slice(0, 30)) + (entries.length > 30 ? tr("; and {count} more you can recall if needed", { count: entries.length - 30 }) : "");
|
|
383
|
-
const lines = [
|
|
384
|
-
knowledge.characters.length === 0 ? void 0 : `${tr("People: ")}${shown(knowledge.characters)}`,
|
|
385
|
-
knowledge.factions.length === 0 ? void 0 : `${tr("Factions: ")}${shown(knowledge.factions)}`,
|
|
386
|
-
knowledge.locations.length === 0 ? void 0 : `${tr("Places: ")}${shown(knowledge.locations)}`,
|
|
387
|
-
knowledge.routes.length === 0 ? void 0 : `${tr("Routes: ")}${shown(knowledge.routes)}`,
|
|
388
|
-
knowledge.items.length === 0 ? void 0 : `${tr("Things: ")}${shown(knowledge.items)}`,
|
|
389
|
-
knowledge.lore.length === 0 ? void 0 : `${tr("Background you know, to read with recall_my_lore when it bears on the moment: ")}${shown(knowledge.lore)}`
|
|
390
|
-
].filter((line) => line !== void 0);
|
|
391
|
-
if (lines.length > 0) sections.push(`${tr("What you know exists (this does not tell you where it is now or what state it is in):")}\n${lines.join("\n")}`);
|
|
392
|
-
}
|
|
393
|
-
if (memories !== void 0 && memories.length > 0) sections.splice(1, 0, `${tr("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, tr, time?.now)}`);
|
|
394
|
-
else if (memories !== void 0) sections.splice(1, 0, tr("What you remember that bears on this: nothing comes to mind."));
|
|
395
|
-
if (earlier !== void 0 && earlier.length > 0) sections.push(`${tr("Earlier in this scene, before this moment:")}\n${earlier.map((entry) => said(entry, tr)).join("\n")}`);
|
|
396
|
-
if (attempt === 2 && reaction !== void 0) {
|
|
397
|
-
sections.push(`${tr("What just happened, and what you are reacting to:")}\n${reaction.map((entry) => said(entry, tr)).join("\n")}`);
|
|
398
|
-
if (previous !== void 0) sections.push(tr("Your earlier intent did not work out: {intent}\nYou are trying again, knowing the above. Decide again what you do now.", { intent: previous.intent }));
|
|
399
|
-
}
|
|
400
|
-
return {
|
|
401
|
-
persona: [
|
|
402
|
-
describe(member.character, tr),
|
|
403
|
-
request.text("roleplay/character-rules", { name: member.character.name }),
|
|
404
|
-
request.text("roleplay/character-style", { name: member.character.name }),
|
|
405
|
-
...request.lookup ? [request.text("roleplay/character-lookup")] : [],
|
|
406
|
-
request.text("roleplay/character-decide", {
|
|
407
|
-
name: member.character.name,
|
|
408
|
-
...limitVariables(request.language ?? "en")
|
|
409
|
-
})
|
|
410
|
-
].join("\n\n"),
|
|
411
|
-
prompt: sections.join("\n\n")
|
|
412
|
-
};
|
|
413
|
-
} };
|
|
414
|
-
/**
|
|
415
|
-
* Whoever is with the player's character acts, unless the game master names who (it always does in play). While the world has places, a character that is in none
|
|
416
|
-
* is not part of the scene: asking it to act is refused, so that someone the story never placed cannot answer from nowhere. (A character in
|
|
417
|
-
* another place can be asked when the moment reaches it.)
|
|
418
|
-
*/
|
|
419
|
-
const everyoneActs = { plan({ cast, requested }) {
|
|
420
|
-
const placed = cast.some((member) => member.place !== void 0);
|
|
421
|
-
const available = cast.filter((member) => member.character.control === "agent");
|
|
422
|
-
const here = cast.find((member) => member.character.control === "player")?.place?.location.id;
|
|
423
|
-
const inScene = (member) => !placed || member.place !== void 0;
|
|
424
|
-
if (requested === void 0 || requested.length === 0) return available.filter((member) => placed && here !== void 0 ? member.place?.location.id === here : inScene(member)).map((member) => member.key);
|
|
425
|
-
const unknown = requested.filter((key) => !available.some((member) => member.key === key));
|
|
426
|
-
if (unknown.length > 0) throw new Error(`cannot activate ${unknown.join(", ")}: not a character that acts on its own (available: ${available.map((member) => member.key).join(", ")})`);
|
|
427
|
-
const nowhere = [...new Set(requested)].map((key) => available.find((member) => member.key === key)).filter((member) => !inScene(member));
|
|
428
|
-
if (nowhere.length > 0) throw new Error(`cannot activate ${nowhere.map((member) => member.key).join(", ")}: in no place, so not part of this scene. Only characters that have a place act (${available.filter(inScene).map((member) => member.key).join(", ") || "nobody"}); leave the others out`);
|
|
429
|
-
return [...new Set(requested)];
|
|
430
|
-
} };
|
|
431
|
-
const acceptsAnyIntent = { validate: ({ intent }) => intent.trim() === "" ? {
|
|
432
|
-
ok: false,
|
|
433
|
-
reason: "the intent is empty"
|
|
434
|
-
} : { ok: true } };
|
|
435
|
-
/** A character whose intent failed and who is highly committed tries once more. */
|
|
436
|
-
const persistentRetry = { select({ reports, outcomes }) {
|
|
437
|
-
return reports.filter((report) => report.commitment === "high" && outcomes.some((outcome) => outcome.character === report.character && outcome.result === "failed")).map((report) => report.character);
|
|
438
|
-
} };
|
|
439
|
-
const acceptsAnyInput = { validate: () => ({ ok: true }) };
|
|
440
|
-
/** The game master narrates. */
|
|
441
|
-
const gameMasterNarrates = { narrate: () => Promise.resolve(void 0) };
|
|
442
|
-
/** Compares what was said, ignoring the quotes around it and the way whitespace is laid out. */
|
|
443
|
-
function sameWords(a, b) {
|
|
444
|
-
const plain = (text) => trimCharacters(text.trim(), "\"“”„«»'‘’").replace(/\s+/g, " ").trim();
|
|
445
|
-
return plain(a) === plain(b);
|
|
446
|
-
}
|
|
447
|
-
/** How many earlier events the game master is reminded of at most. */
|
|
448
|
-
const REMINDED_EVENTS = 5;
|
|
449
|
-
/**
|
|
450
|
-
* The state of the scene, what is still open in the story, and the earlier events that the
|
|
451
|
-
* player's move brings to mind (by the session's search of words and meaning, and by who is named):
|
|
452
|
-
* those already folded out of the conversation into the summaries, whose detail the summaries may have lost.
|
|
453
|
-
*/
|
|
454
|
-
/** Where the player is and what is there, who is with them, and who is elsewhere. */
|
|
455
|
-
function placedScene(cast, player, story, describeMember, tr, things) {
|
|
456
|
-
const here = player?.place?.location;
|
|
457
|
-
const sections = [];
|
|
458
|
-
if (here !== void 0) {
|
|
459
|
-
const view = {
|
|
460
|
-
key: locationKey(here),
|
|
461
|
-
location: here,
|
|
462
|
-
here: cast.filter((member) => member.place?.location.id === here.id),
|
|
463
|
-
...things === void 0 ? {} : { items: things.at(here.id) },
|
|
464
|
-
exits: story.locations.exitsFrom(here.id).flatMap((exit) => {
|
|
465
|
-
const to = story.locations.get(exit.toId);
|
|
466
|
-
return to === void 0 ? [] : [{
|
|
467
|
-
key: locationKey(to),
|
|
468
|
-
name: to.name,
|
|
469
|
-
exit
|
|
470
|
-
}];
|
|
471
|
-
})
|
|
472
|
-
};
|
|
473
|
-
sections.push(tr("The player's character is in {place}", { place: describePlace(view, { withKeys: true }, tr).join("\n") }));
|
|
474
|
-
sections.push(`${tr("Characters here:")}\n${view.here.map(describeMember).join("\n")}`);
|
|
475
|
-
}
|
|
476
|
-
const elsewhere = cast.filter((member) => member.place !== void 0 && member.place.location.id !== here?.id);
|
|
477
|
-
if (elsewhere.length > 0) sections.push(`${tr("Characters elsewhere (they perceive nothing here unless the moment reaches them):")}\n${elsewhere.map((member) => tr("{member} - in {place} ({key})", {
|
|
478
|
-
member: describeMember(member),
|
|
479
|
-
place: member.place.location.name,
|
|
480
|
-
key: locationKey(member.place.location)
|
|
481
|
-
})).join("\n")}`);
|
|
482
|
-
const nowhere = cast.filter((member) => member.place === void 0);
|
|
483
|
-
if (nowhere.length > 0) sections.push(`${tr("Characters with no place (not part of this scene; they cannot be asked to act):")}\n${nowhere.map(describeMember).join("\n")}`);
|
|
484
|
-
return sections.join("\n\n");
|
|
485
|
-
}
|
|
486
|
-
const castSummary = { scene({ tracked, time, world, cast, turn, input, queryVector, story, items, language: code, report }) {
|
|
487
|
-
const language = languageOf(code);
|
|
488
|
-
const tr = translator(language);
|
|
489
|
-
const join = (entries) => entries.join(tr("; "));
|
|
490
|
-
const describeMember = (member) => {
|
|
491
|
-
const { key, character, state } = member;
|
|
492
|
-
const role = character.control === "player" ? tr("the player's character, \"{key}\"", { key }) : tr("acts through \"{key}\"", { key });
|
|
493
|
-
const seen = [state?.publicState, state?.activity].filter((text) => text !== void 0 && text.trim() !== "");
|
|
494
|
-
const where = whereIs(member, tr);
|
|
495
|
-
return `- ${referent(character)} (${role})${where === "" ? "" : ` [${where}]`}${character.summary === "" ? "" : `${tr(": ")}${character.summary}`}${seen.length > 0 ? ` ${tr("Currently: {state}", { state: join(seen) })}` : ""}`;
|
|
496
|
-
};
|
|
497
|
-
const player = cast.find((member) => member.character.control === "player");
|
|
498
|
-
const days = time?.agenda === void 0 ? "" : describeSceneAgenda(time.agenda, time.now.now, tr, language);
|
|
499
|
-
const scene = cast.some((member) => member.place !== void 0) ? placedScene(cast, player, story, describeMember, tr, items) : cast.map(describeMember).join("\n");
|
|
500
|
-
const parts = [];
|
|
501
|
-
const add = (id, text) => {
|
|
502
|
-
parts.push(text);
|
|
503
|
-
report?.section(id, text);
|
|
504
|
-
};
|
|
505
|
-
if (time !== void 0) add("time", timeNotice(time, language, tr));
|
|
506
|
-
if (days !== "") add("agenda", days);
|
|
507
|
-
add("scene", `${tr("Scene before turn {turn}:", { turn })}\n${scene}`);
|
|
508
|
-
const activation = describeActivationCandidates(cast, input, story, tr);
|
|
509
|
-
if (activation !== "") add("activation", activation);
|
|
510
|
-
if (items !== void 0) {
|
|
511
|
-
const carried = cast.flatMap((member) => {
|
|
512
|
-
const mine = items.carried(member.character.id);
|
|
513
|
-
return mine.length === 0 ? [] : [`- ${member.character.name} (${member.key}): ${describeItems(mine, { withKeys: true }, tr)}`];
|
|
514
|
-
});
|
|
515
|
-
if (carried.length > 0) add("carried", `${tr("What characters have on them:")}\n${carried.join("\n")}`);
|
|
516
|
-
}
|
|
517
|
-
if (world !== void 0 && world.happened.length > 0) add("world", `${tr("The world acted since the last turn, by itself:")}\n${world.happened.map((line) => `- ${line}`).join("\n")}`);
|
|
518
|
-
if (world?.upcoming !== void 0 && world.upcoming.length > 0) add("upcoming", `${tr("Known beforehand, still to come (who knows of it; it will happen by itself when its time comes):")}\n${world.upcoming.map((entry) => `- ${entry.text}${entry.when === void 0 ? "" : ` (${entry.when})`} ${tr("[known to {who}]", { who: entry.who })}`).join("\n")}`);
|
|
519
|
-
if (world !== void 0 && world.beats.length > 0) add("beats", `${tr("Weave these into the story when it fits, then say you did with addressed in narrate (each stays for a few turns and is then let go):")}\n${world.beats.map((beat) => `- [${beat.id}] ${beat.text}`).join("\n")}`);
|
|
520
|
-
if (tracked !== void 0 && tracked.length > 0) add("tracked", `${tr("What the story keeps track of (change it with variable_changes in an outcome when what happened calls for it):")}\n${tracked.map((line) => `- ${line}`).join("\n")}`);
|
|
521
|
-
const threads = story.threads.list("open");
|
|
522
|
-
if (threads.length > 0) add("threads", `${tr("Still open in the story:")}\n${threads.map((thread) => `- ${thread.text}`).join("\n")}`);
|
|
523
|
-
const folded = story.summaries.list().reduce((latest, summary) => Math.max(latest, summary.toTurn), 0);
|
|
524
|
-
if (folded > 0) {
|
|
525
|
-
const mentionedIds = mentioned(input, cast.map(({ character }) => character));
|
|
526
|
-
const cues = tokens(input);
|
|
527
|
-
const names = new Map(cast.map(({ character }) => [character.id, character.name]));
|
|
528
|
-
const byMeaning = story.searchEvents({
|
|
529
|
-
text: input,
|
|
530
|
-
...queryVector === void 0 ? {} : { vector: queryVector },
|
|
531
|
-
toTurn: folded,
|
|
532
|
-
limit: 10
|
|
533
|
-
});
|
|
534
|
-
const byCues = story.events.list({ toTurn: folded }).filter((event) => !byMeaning.some((found) => found.id === event.id)).map((event) => ({
|
|
535
|
-
event,
|
|
536
|
-
score: 3 * event.involves.filter((id) => mentionedIds.has(id)).length + overlap(cues, event.text, event.tags)
|
|
537
|
-
})).filter(({ score }) => score >= 2).sort((a, b) => b.score + .5 * b.event.importance - a.score - .5 * a.event.importance || b.event.turn - a.event.turn).map(({ event }) => event);
|
|
538
|
-
const ranked = [...byMeaning.map((event) => ({
|
|
539
|
-
event,
|
|
540
|
-
how: "search"
|
|
541
|
-
})), ...byCues.map((event) => ({
|
|
542
|
-
event,
|
|
543
|
-
how: "cues"
|
|
544
|
-
}))];
|
|
545
|
-
const chosen = ranked.slice(0, REMINDED_EVENTS).sort((a, b) => a.event.turn - b.event.turn);
|
|
546
|
-
const relevant = chosen.map(({ event }) => ({ event }));
|
|
547
|
-
report?.selected({
|
|
548
|
-
events: chosen.map(({ event, how }) => ({
|
|
549
|
-
turn: event.turn,
|
|
550
|
-
text: event.text,
|
|
551
|
-
how
|
|
552
|
-
})),
|
|
553
|
-
omitted: ranked.length - chosen.length,
|
|
554
|
-
folded
|
|
555
|
-
});
|
|
556
|
-
if (relevant.length > 0) add("events", `${tr("Earlier events that bear on what the player just did (from the records of the story):")}\n${relevant.map(({ event }) => {
|
|
557
|
-
const who = event.involves.map((id) => names.get(id)).filter((name) => name !== void 0).join(tr(", "));
|
|
558
|
-
return `- (${tr("turn {turn}", { turn: event.turn })}) ${event.text}${who === "" ? "" : ` [${who}]`}`;
|
|
559
|
-
}).join("\n")}`);
|
|
560
|
-
} else report?.selected({
|
|
561
|
-
events: [],
|
|
562
|
-
omitted: 0,
|
|
563
|
-
folded: 0
|
|
564
|
-
});
|
|
565
|
-
return parts.join("\n\n");
|
|
566
|
-
} };
|
|
567
|
-
const sameCharacter = (utterance, character) => utterance.character === character || utterance.name === character;
|
|
568
|
-
/** Every utterance appears once, exactly as given and in the order spoken, and no one speaks who did not. */
|
|
569
|
-
const exactUtterances = {
|
|
570
|
-
check(segments, required) {
|
|
571
|
-
const problems = [];
|
|
572
|
-
const used = /* @__PURE__ */ new Set();
|
|
573
|
-
let latest = 0;
|
|
574
|
-
segments.forEach((segment, index) => {
|
|
575
|
-
const at = `segment ${index + 1}`;
|
|
576
|
-
if (segment.type === "narration") {
|
|
577
|
-
if (segment.text.trim() === "") problems.push(`${at}: the narration is empty`);
|
|
578
|
-
return;
|
|
579
|
-
}
|
|
580
|
-
const own = required.flatMap((utterance, position) => sameCharacter(utterance, segment.character) ? [position] : []);
|
|
581
|
-
const free = own.filter((position) => !used.has(position));
|
|
582
|
-
const exact = free.find((position) => sameWords(segment.text, required[position].text));
|
|
583
|
-
if (exact !== void 0) {
|
|
584
|
-
used.add(exact);
|
|
585
|
-
const spoken = required[exact];
|
|
586
|
-
if (spoken.round < latest) problems.push(`${at}: the utterance of ${spoken.name} from round ${spoken.round} comes after one from a later round; utterances keep the order they were spoken in`);
|
|
587
|
-
latest = Math.max(latest, spoken.round);
|
|
588
|
-
} else if (free.length > 0) {
|
|
589
|
-
used.add(free[0]);
|
|
590
|
-
problems.push(`${at}: the utterance of ${required[free[0]].name} was changed; it must be exactly "${required[free[0]].text}"`);
|
|
591
|
-
} else if (own.length > 0) problems.push(`${at}: ${required[own[0]].name} has no more utterances to say; this one is repeated or invented, remove it`);
|
|
592
|
-
else problems.push(`${at}: ${segment.character} has nothing to say this turn, so this utterance is invented; remove it`);
|
|
593
|
-
});
|
|
594
|
-
required.forEach((utterance, position) => {
|
|
595
|
-
if (!used.has(position)) problems.push(`the utterance of ${utterance.name}${utterance.round > 1 ? ` (round ${utterance.round})` : ""} is missing; it must appear exactly as "${utterance.text}"`);
|
|
596
|
-
});
|
|
597
|
-
return problems;
|
|
598
|
-
},
|
|
599
|
-
repair(segments, required) {
|
|
600
|
-
const used = /* @__PURE__ */ new Set();
|
|
601
|
-
const kept = [];
|
|
602
|
-
for (const segment of segments) {
|
|
603
|
-
if (segment.type === "narration") {
|
|
604
|
-
if (segment.text.trim() !== "") kept.push({
|
|
605
|
-
segment,
|
|
606
|
-
round: void 0
|
|
607
|
-
});
|
|
608
|
-
continue;
|
|
609
|
-
}
|
|
610
|
-
const free = required.flatMap((utterance, position) => sameCharacter(utterance, segment.character) && !used.has(position) ? [position] : []);
|
|
611
|
-
const position = free.find((candidate) => sameWords(segment.text, required[candidate].text)) ?? free[0];
|
|
612
|
-
if (position === void 0) continue;
|
|
613
|
-
used.add(position);
|
|
614
|
-
const spoken = required[position];
|
|
615
|
-
kept.push({
|
|
616
|
-
segment: {
|
|
617
|
-
type: "utterance",
|
|
618
|
-
character: spoken.character,
|
|
619
|
-
name: spoken.name,
|
|
620
|
-
text: spoken.text
|
|
621
|
-
},
|
|
622
|
-
round: spoken.round
|
|
623
|
-
});
|
|
624
|
-
}
|
|
625
|
-
required.forEach((utterance, position) => {
|
|
626
|
-
if (used.has(position)) return;
|
|
627
|
-
const restored = {
|
|
628
|
-
type: "utterance",
|
|
629
|
-
character: utterance.character,
|
|
630
|
-
name: utterance.name,
|
|
631
|
-
text: utterance.text
|
|
632
|
-
};
|
|
633
|
-
const later = kept.findIndex((entry) => entry.round !== void 0 && entry.round > utterance.round);
|
|
634
|
-
kept.splice(later < 0 ? kept.length : later, 0, {
|
|
635
|
-
segment: restored,
|
|
636
|
-
round: utterance.round
|
|
637
|
-
});
|
|
638
|
-
});
|
|
639
|
-
return kept.map((entry) => entry.segment);
|
|
640
|
-
}
|
|
641
|
-
};
|
|
642
|
-
/** 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. */
|
|
643
|
-
const recordsRecall = { recall: ({ member, situation, turn, policy, queryVector, explain, peek }, story, signal) => story.recallRanked({
|
|
644
|
-
characterId: member.character.id,
|
|
645
|
-
situation,
|
|
646
|
-
turn,
|
|
647
|
-
policy,
|
|
648
|
-
...explain === true ? { explain } : {},
|
|
649
|
-
...member.place === void 0 ? {} : { locationId: member.place.location.id }
|
|
650
|
-
}, signal, {
|
|
651
|
-
...queryVector === void 0 ? {} : { queryVector },
|
|
652
|
-
...peek === true ? { peek } : {}
|
|
653
|
-
}) };
|
|
654
|
-
/**
|
|
655
|
-
* Writes no memory. What the game master decided about each character is applied when the round is
|
|
656
|
-
* recorded, so without a memory keeper the story keeps its states and no events.
|
|
657
|
-
*/
|
|
658
|
-
const writesNothing = { commit: () => Promise.resolve({
|
|
659
|
-
writes: 0,
|
|
660
|
-
notes: ""
|
|
661
|
-
}) };
|
|
662
|
-
/** Makes up nothing, and has nothing to fit in: without a world author the world stays as it was written. */
|
|
663
|
-
const declinesToAuthor = {
|
|
664
|
-
create: () => Promise.resolve({
|
|
665
|
-
created: [],
|
|
666
|
-
declined: "no world author is installed, so the world cannot grow"
|
|
667
|
-
}),
|
|
668
|
-
consolidate: () => Promise.resolve({
|
|
669
|
-
resolved: 0,
|
|
670
|
-
notes: ""
|
|
671
|
-
})
|
|
672
|
-
};
|
|
673
|
-
/** Lets no organisation act: without a strategist factions change only through what the story records. */
|
|
674
|
-
const factionsStayPut = { strategize: () => Promise.resolve({ acted: [] }) };
|
|
675
|
-
/** Reflects on nothing: without a reflector what characters believe changes only through what the story records. */
|
|
676
|
-
const reflectsOnNothing = { reflect: () => Promise.resolve({ characters: [] }) };
|
|
677
|
-
/** Finds no fault: without a gate the output is delivered as the game master wrote it. */
|
|
678
|
-
const passesEverything = { check: () => Promise.resolve([]) };
|
|
679
|
-
/** Finds no broken rule: without a check the game master's judgement of an action stands as it is. */
|
|
680
|
-
const breaksNoRule = { check: () => Promise.resolve([]) };
|
|
681
|
-
/** Judges nothing: without a judge a trigger that waits on a statement never sees it hold. */
|
|
682
|
-
const judgesNothing = { judge: () => Promise.resolve({ judged: 0 }) };
|
|
683
|
-
/** Offers nothing: without a suggester the player writes their own move. */
|
|
684
|
-
const offersNothing = { suggest: () => Promise.resolve([]) };
|
|
685
|
-
function defaultBoundaries() {
|
|
686
|
-
return {
|
|
687
|
-
planner: everyoneActs,
|
|
688
|
-
characterContext: sharedContext,
|
|
689
|
-
outputValidator: acceptsAnyIntent,
|
|
690
|
-
retryPolicy: persistentRetry,
|
|
691
|
-
inputValidator: acceptsAnyInput,
|
|
692
|
-
narrator: gameMasterNarrates,
|
|
693
|
-
narrationChecker: exactUtterances,
|
|
694
|
-
committer: writesNothing,
|
|
695
|
-
author: declinesToAuthor,
|
|
696
|
-
strategist: factionsStayPut,
|
|
697
|
-
reflector: reflectsOnNothing,
|
|
698
|
-
judge: judgesNothing,
|
|
699
|
-
outputGate: passesEverything,
|
|
700
|
-
ruleCheck: breaksNoRule,
|
|
701
|
-
suggester: offersNothing,
|
|
702
|
-
recaller: recordsRecall,
|
|
703
|
-
sceneContext: castSummary
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
107
|
// src/host/presets/apply.ts
|
|
707
108
|
/** Which preset a story's prompts came from, and what each copied file held: kept beside the story's database, so that a story can tell its copies from its own edits. */
|
|
708
109
|
const PRESET_RECORD = "preset.json";
|
|
@@ -2095,6 +1496,6 @@ function memoryReflector(deps) {
|
|
|
2095
1496
|
return { characters };
|
|
2096
1497
|
} };
|
|
2097
1498
|
}
|
|
2098
|
-
export {
|
|
1499
|
+
export { snapshotOf as _, whereabouts as a, copyPreset as c, switchPreset as d, readTimeline as f, pathTo as g, childrenOf as h, reflectionStatus as i, presetStatus as l, START_SNAPSHOT as m, memoryReflector as n, TimelineError as o, writeTimeline as p, recordFailure as r, Timelines as s, dueReflection as t, recordPreset as u };
|
|
2099
1500
|
|
|
2100
|
-
//# sourceMappingURL=reflection-
|
|
1501
|
+
//# sourceMappingURL=reflection-B9N0z3KY.js.map
|