@dsh-agentic-roleplay/core 0.10.2 → 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-C9cmcUbD.js → authoring-tools-BFdw7ahj.js} +72 -9
- package/lib/authoring.js +38 -8
- package/lib/client.js +777 -427
- 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-BpLN_hhT.js → hooks-C2U1-8ur.js} +709 -67
- 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-Cg7QQemi.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-D5j5mIq6.js → pack-jail-Ci9bIeDI.js} +25 -15
- package/lib/{packs-Cc05FrId.js → packs-CYkozh8Q.js} +2 -2
- package/lib/{presenter-agent-UKbKYXMO.js → presenter-agent-CqkAL03Q.js} +10 -7
- package/lib/{preset-Be4lz6vB.js → preset-B-35yUmt.js} +3 -3
- package/lib/{preset-author-tools-C3s0iSfv.js → preset-author-tools-BUymqZM5.js} +7 -7
- package/lib/preset-authoring.js +5 -5
- package/lib/{presets-Cl9sU3Qs.js → presets-_U-xroo0.js} +27 -8
- package/lib/{reflection-I9z-PvFK.js → reflection-B9N0z3KY.js} +9 -608
- package/lib/{text-CzqhC8sT.js → text-C2AGl7Je.js} +11 -2
- package/lib/{turn-guard-B9pGCeir.js → turn-guard-C0M3rXEN.js} +10 -10
- package/package.json +33 -32
- 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 { _ as emptyStats, a as liveSettings, h as DECISION_SITES, m as rulesOf, n as encodeOutput, p as WORLD_RULES_KEY, r as encodePreview } from "./narration-
|
|
3
|
-
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-
|
|
4
|
-
import { T as estimateAnswer, _ as estimateTokens, a as childTrace, b as addTokens, g as blockText, h as requestsOf, l as runChild, n as childModel, r as childSampling, v as tokensOf, y as NO_TOKENS } from "./child-C9nPIy9j.js";
|
|
1
|
+
import { l as roleplaySessionOf, t as promptFor } from "./access-Md1YTSX1.js";
|
|
2
|
+
import { _ as emptyStats, a as liveSettings, h as DECISION_SITES, m as rulesOf, n as encodeOutput, p as WORLD_RULES_KEY, r as encodePreview } from "./narration-b_VBEUWn.js";
|
|
3
|
+
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-C2AGl7Je.js";
|
|
4
|
+
import { C as cutOff, T as estimateAnswer, _ as estimateTokens, a as childTrace, b as addTokens, g as blockText, h as requestsOf, l as runChild, n as childModel, r as childSampling, v as tokensOf, w as finishOf, y as NO_TOKENS } from "./child-C9nPIy9j.js";
|
|
5
5
|
import { dirname, join } from "node:path";
|
|
6
|
-
import { DAY, ENGAGEMENT_GRACE, ITEM_ACTIONS, MINUTE, SECOND, addLocalDays, agendaAt, announcements, applyItemPlan, changeItem, changeVariable, clockTime, createCharacterTools, createDiceTools, createTools, dayPart, describeDuration, describeInstant, describeValue, holidaysOn, inAudience, isSessionId, itemKey, localTime, locationKey, nextOccurrence, nextTimeOfDay, occurrenceAt, parseInstant, planItemChange, planVariableChange, readCalendar, rollPlain, seasonOf, sessionDatabase, sessionFolder, shownVariables } from "@dsh-agentic-roleplay/state";
|
|
6
|
+
import { DAY, ENGAGEMENT_GRACE, ITEM_ACTIONS, MINUTE, SECOND, addLocalDays, agendaAt, announcements, applyItemPlan, changeItem, changeVariable, clockTime, createCharacterTools, createDiceTools, createTools, dayPart, describeDuration, describeInstant, describeValue, holidaysOn, inAudience, isSessionId, itemKey, localTime, locationKey, mentioned, nextOccurrence, nextTimeOfDay, occurrenceAt, overlap, parseInstant, planItemChange, planVariableChange, readCalendar, rollPlain, seasonOf, sessionDatabase, sessionFolder, shownVariables, tokens } from "@dsh-agentic-roleplay/state";
|
|
7
7
|
import { copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { readFile, stat } from "node:fs/promises";
|
|
9
|
-
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
9
|
+
import { ReasoningEffortId, createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
10
10
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
11
11
|
import { fileURLToPath } from "node:url";
|
|
12
12
|
import { Service } from "@deepseek-ai/cordis";
|
|
@@ -1025,6 +1025,607 @@ function parseCharacterAction(value) {
|
|
|
1025
1025
|
...told === "" ? {} : { account: told }
|
|
1026
1026
|
};
|
|
1027
1027
|
}
|
|
1028
|
+
// src/host/orchestration/referent.ts
|
|
1029
|
+
/**
|
|
1030
|
+
* 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.
|
|
1031
|
+
* 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.
|
|
1032
|
+
*/
|
|
1033
|
+
function referent(character) {
|
|
1034
|
+
const mark = [character.pronouns, character.gender].find((text) => text !== void 0 && text.trim() !== "")?.trim();
|
|
1035
|
+
return mark === void 0 ? character.name : `${character.name} (${mark})`;
|
|
1036
|
+
}
|
|
1037
|
+
// src/host/orchestration/defaults.ts
|
|
1038
|
+
const ENGLISH = translator("en");
|
|
1039
|
+
/** What the instructions say about how long each part of a character's answer may run. */
|
|
1040
|
+
const limitVariables = (language) => {
|
|
1041
|
+
const limits = answerLimits(language);
|
|
1042
|
+
return {
|
|
1043
|
+
thoughtLimit: limits.thought,
|
|
1044
|
+
intentLimit: limits.intent,
|
|
1045
|
+
utteranceLimit: limits.utterance
|
|
1046
|
+
};
|
|
1047
|
+
};
|
|
1048
|
+
function describe(character, tr) {
|
|
1049
|
+
const lines = [tr("You are {name}.", { name: character.name })];
|
|
1050
|
+
if (character.aliases.length > 0) lines.push(tr("You are also called {names}.", { names: character.aliases.join(tr(", ")) }));
|
|
1051
|
+
const facts = [
|
|
1052
|
+
character.age === void 0 ? void 0 : tr("age: {value}", { value: character.age }),
|
|
1053
|
+
character.gender === void 0 ? void 0 : tr("gender: {value}", { value: character.gender }),
|
|
1054
|
+
character.pronouns === void 0 ? void 0 : tr("pronouns: {value}", { value: character.pronouns })
|
|
1055
|
+
].filter((fact) => fact !== void 0);
|
|
1056
|
+
if (facts.length > 0) lines.push(facts.join(tr("; ")) + tr("."));
|
|
1057
|
+
for (const [label, text] of [
|
|
1058
|
+
["Summary", character.summary],
|
|
1059
|
+
["Personality", character.personality],
|
|
1060
|
+
["Background", character.background],
|
|
1061
|
+
["Appearance", character.appearance],
|
|
1062
|
+
["How you speak", character.speech.style]
|
|
1063
|
+
]) if (text.trim() !== "") lines.push(`${tr(label)}${tr(": ")}${text.trim()}`);
|
|
1064
|
+
return lines.join("\n");
|
|
1065
|
+
}
|
|
1066
|
+
/** At most this many features and ways out of a place are told at once. */
|
|
1067
|
+
const SHOWN_FEATURES = 12;
|
|
1068
|
+
const SHOWN_EXITS = 12;
|
|
1069
|
+
const sentence = (text) => {
|
|
1070
|
+
return (/^[^.!?。!?]*[.!?。!?]?/u.exec(text.trim())?.[0] ?? text).trim();
|
|
1071
|
+
};
|
|
1072
|
+
/** At most this many things are listed at once: the rest are said to be there and left for a closer look. */
|
|
1073
|
+
const SHOWN_ITEMS = 12;
|
|
1074
|
+
/** One thing in a sentence: how many, what state it is in, where it is. */
|
|
1075
|
+
function describeItem(item, { withKeys }, tr = ENGLISH) {
|
|
1076
|
+
const name = `${item.quantity > 1 ? `${item.quantity} ` : ""}${item.name}${item.quality === "" ? "" : ` (${item.quality})`}`;
|
|
1077
|
+
const extra = [
|
|
1078
|
+
item.hidden ? tr("hidden") : "",
|
|
1079
|
+
item.state === void 0 ? "" : item.state,
|
|
1080
|
+
item.where ?? ""
|
|
1081
|
+
].filter((part) => part !== "").join(tr(", "));
|
|
1082
|
+
const inside = item.contents === void 0 ? "" : tr(" holding {things}", { things: item.contents.join(tr(", ")) });
|
|
1083
|
+
return `${withKeys ? `${item.key}: ` : ""}${name}${extra === "" ? "" : ` [${extra}]`}${inside}`;
|
|
1084
|
+
}
|
|
1085
|
+
/** A list of things, capped. */
|
|
1086
|
+
function describeItems(items, options, tr = ENGLISH) {
|
|
1087
|
+
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 }) : ""}`;
|
|
1088
|
+
}
|
|
1089
|
+
/** What someone in a place is told about it: what it is like, what can be pointed at, and the ways out. */
|
|
1090
|
+
function describePlace(view, { withKeys }, tr = ENGLISH) {
|
|
1091
|
+
const { location, exits } = view;
|
|
1092
|
+
const lines = [`${location.name}${withKeys ? ` (${view.key})` : ""}${location.description === "" ? "" : `: ${location.description}`}`];
|
|
1093
|
+
if (location.features.length > 0) {
|
|
1094
|
+
const shown = location.features.slice(0, SHOWN_FEATURES).map((feature) => `${withKeys ? `${feature.key}: ` : ""}${feature.name}${feature.description === "" ? "" : ` - ${sentence(feature.description)}`}`);
|
|
1095
|
+
lines.push(`${tr("Things here: ")}${shown.join(tr("; "))}${location.features.length > SHOWN_FEATURES ? tr("; and {count} more", { count: location.features.length - SHOWN_FEATURES }) : ""}`);
|
|
1096
|
+
}
|
|
1097
|
+
if (exits.length > 0) {
|
|
1098
|
+
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}`}]`}`);
|
|
1099
|
+
lines.push(`${tr("Ways out: ")}${shown.join(tr("; "))}${exits.length > SHOWN_EXITS ? tr("; and {count} more", { count: exits.length - SHOWN_EXITS }) : ""}`);
|
|
1100
|
+
}
|
|
1101
|
+
if (view.items !== void 0 && view.items.length > 0) lines.push(`${tr("Lying about: ")}${describeItems(view.items, { withKeys }, tr)}`);
|
|
1102
|
+
return lines;
|
|
1103
|
+
}
|
|
1104
|
+
/** How long the player has to have been away for it to be worth telling the game master. */
|
|
1105
|
+
const NOTICEABLE_ABSENCE = 5 * MINUTE;
|
|
1106
|
+
/** What the game master is told about time at the start of a turn, and how it passes. */
|
|
1107
|
+
function timeNotice(time, language, tr) {
|
|
1108
|
+
const now = tr("Time: {time}.", { time: describeTime(time.now, language) });
|
|
1109
|
+
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.")}`;
|
|
1110
|
+
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) })}` : "";
|
|
1111
|
+
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}`;
|
|
1112
|
+
}
|
|
1113
|
+
/** What a character is told of its day, its commitments and what it is after. */
|
|
1114
|
+
function describeAgenda(agenda, now, tr = ENGLISH, language = "en") {
|
|
1115
|
+
const { zone } = agenda;
|
|
1116
|
+
const when = (instant) => describeWhen(instant, now, zone, language);
|
|
1117
|
+
const at = (place) => place === void 0 ? "" : tr(" at {place}", { place });
|
|
1118
|
+
const lines = [];
|
|
1119
|
+
if (agenda.now !== void 0) lines.push(tr("Your day, now: {activity}{place}, until {until}{note}.", {
|
|
1120
|
+
activity: agenda.now.activity,
|
|
1121
|
+
place: at(agenda.now.place),
|
|
1122
|
+
until: when(agenda.now.until),
|
|
1123
|
+
note: agenda.now.interruptible ? "" : tr(" (not something you would drop lightly)")
|
|
1124
|
+
}));
|
|
1125
|
+
if (agenda.next !== void 0) lines.push(tr("Your day, next: {activity}{place}, from {from}.", {
|
|
1126
|
+
activity: agenda.next.activity,
|
|
1127
|
+
place: at(agenda.next.place),
|
|
1128
|
+
from: when(agenda.next.at)
|
|
1129
|
+
}));
|
|
1130
|
+
for (const engagement of agenda.engagements) {
|
|
1131
|
+
const values = {
|
|
1132
|
+
title: engagement.title,
|
|
1133
|
+
place: at(engagement.place),
|
|
1134
|
+
with: engagement.with.length === 0 ? "" : tr(", with {names}", { names: engagement.with.join(tr(", ")) }),
|
|
1135
|
+
at: when(engagement.at)
|
|
1136
|
+
};
|
|
1137
|
+
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));
|
|
1138
|
+
}
|
|
1139
|
+
if (agenda.goals.length > 0) {
|
|
1140
|
+
lines.push(tr("What you are after:"));
|
|
1141
|
+
for (const goal of agenda.goals) {
|
|
1142
|
+
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) });
|
|
1143
|
+
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("; ")) })}`);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return lines;
|
|
1147
|
+
}
|
|
1148
|
+
/** What the game master is told of the characters' days at the start of a turn; nothing when there is nothing to tell. */
|
|
1149
|
+
function describeSceneAgenda(agenda, now, tr = ENGLISH, language = "en") {
|
|
1150
|
+
const lines = [];
|
|
1151
|
+
const join = (entries) => entries.join(tr("; "));
|
|
1152
|
+
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})", {
|
|
1153
|
+
name: move.name,
|
|
1154
|
+
place: move.to,
|
|
1155
|
+
activity: move.activity
|
|
1156
|
+
}))) }));
|
|
1157
|
+
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}`)) }));
|
|
1158
|
+
if (agenda.engagements.length > 0) {
|
|
1159
|
+
const entries = agenda.engagements.map((engagement) => {
|
|
1160
|
+
const values = {
|
|
1161
|
+
title: engagement.title,
|
|
1162
|
+
with: engagement.with.join(tr(", ")),
|
|
1163
|
+
place: engagement.place === void 0 ? "" : tr(", at {place}", { place: engagement.place }),
|
|
1164
|
+
when: describeWhen(engagement.at, now, agenda.zone, language)
|
|
1165
|
+
};
|
|
1166
|
+
return engagement.overdue ? tr("\"{title}\" ({with}{place}) was due {when} and is still open", values) : tr("\"{title}\" ({with}{place}) is due {when}", values);
|
|
1167
|
+
});
|
|
1168
|
+
lines.push(tr("Commitments due soon or overdue: {entries}.", { entries: join(entries) }));
|
|
1169
|
+
}
|
|
1170
|
+
return lines.join("\n");
|
|
1171
|
+
}
|
|
1172
|
+
/** In words, how a character stands with another, from the numbers of its profile; nothing for what is unremarkable. */
|
|
1173
|
+
function describeAttitude(relation, tr = ENGLISH) {
|
|
1174
|
+
return [
|
|
1175
|
+
relation.familiarity >= .7 ? tr("knows them well") : relation.familiarity <= .15 ? tr("barely knows them") : "",
|
|
1176
|
+
relation.trust >= .4 ? tr("trusts them") : relation.trust <= -.4 ? tr("distrusts them") : "",
|
|
1177
|
+
relation.affinity >= .4 ? tr("is fond of them") : relation.affinity <= -.4 ? tr("dislikes them") : "",
|
|
1178
|
+
relation.tension >= .5 ? tr("things are strained between them") : ""
|
|
1179
|
+
].filter((part) => part !== "").join(tr(", "));
|
|
1180
|
+
}
|
|
1181
|
+
function whereIs(member, tr = ENGLISH) {
|
|
1182
|
+
const place = member.place;
|
|
1183
|
+
if (place === void 0) return "";
|
|
1184
|
+
return [place.position, place.feature === void 0 ? "" : tr("at {feature}", { feature: place.feature.name })].filter((part) => part !== "").join(tr(", "));
|
|
1185
|
+
}
|
|
1186
|
+
function present(cast, self, tr) {
|
|
1187
|
+
return cast.map((member) => {
|
|
1188
|
+
const { key, character, state } = member;
|
|
1189
|
+
const seen = [state?.publicState, state?.activity].filter((text) => text !== void 0 && text.trim() !== "");
|
|
1190
|
+
const where = whereIs(member);
|
|
1191
|
+
return `- ${key === self ? character.name : referent(character)}${key === self ? tr(" (you)") : ""}${where === "" ? "" : ` (${where})`}${seen.length > 0 ? `${tr(": ")}${seen.join(tr("; "))}` : ""}`;
|
|
1192
|
+
}).join("\n");
|
|
1193
|
+
}
|
|
1194
|
+
/** A bounded, advisory order for who is most likely to need a turn; reachability still governs activation. */
|
|
1195
|
+
function describeActivationCandidates(cast, input, story, tr = ENGLISH) {
|
|
1196
|
+
const player = cast.find((member) => member.character.control === "player");
|
|
1197
|
+
if (player === void 0) return "";
|
|
1198
|
+
const named = mentioned(input, cast.map((member) => member.character));
|
|
1199
|
+
const cues = tokens(input);
|
|
1200
|
+
const candidates = cast.filter((member) => member.character.control === "agent").map((member) => {
|
|
1201
|
+
const relation = story.relationships.get(member.character.id, player.character.id);
|
|
1202
|
+
const here = member.place === void 0 || player.place === void 0 || member.place.location.id === player.place.location.id;
|
|
1203
|
+
const goal = story.intents.list(member.character.id, { status: "active" }).map((intent) => ({
|
|
1204
|
+
intent,
|
|
1205
|
+
match: overlap(cues, `${intent.name} ${intent.description}`, [])
|
|
1206
|
+
})).sort((a, b) => b.match - a.match)[0];
|
|
1207
|
+
const factionGoal = story.factionMemberships.ofCharacter(member.character.id, "active").flatMap((membership) => story.factionIntents.list(membership.factionId, { status: "active" }).map((intent) => ({
|
|
1208
|
+
intent,
|
|
1209
|
+
match: overlap(cues, `${intent.name} ${intent.description}`, []) * membership.commitment
|
|
1210
|
+
}))).sort((a, b) => b.match - a.match)[0];
|
|
1211
|
+
return {
|
|
1212
|
+
member,
|
|
1213
|
+
reasons: [
|
|
1214
|
+
named.has(member.character.id) ? tr("named in the move") : "",
|
|
1215
|
+
here ? tr("in the scene") : "",
|
|
1216
|
+
(goal?.match ?? 0) >= 2 ? tr("own goal: {goal}", { goal: goal.intent.name }) : "",
|
|
1217
|
+
(factionGoal?.match ?? 0) >= 2 ? tr("faction pressure: {goal}", { goal: factionGoal.intent.name }) : "",
|
|
1218
|
+
relation !== void 0 && relation.tension >= .5 ? tr("high tension toward the player") : "",
|
|
1219
|
+
relation !== void 0 && relation.trust <= -.4 ? tr("distrusts the player") : "",
|
|
1220
|
+
relation !== void 0 && Math.abs(relation.affinity) >= .4 ? relation.affinity > 0 ? tr("cares about the player") : tr("dislikes the player") : ""
|
|
1221
|
+
].filter((reason) => reason !== ""),
|
|
1222
|
+
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
|
|
1223
|
+
};
|
|
1224
|
+
}).filter((entry) => entry.score > 0).sort((a, b) => b.score - a.score || a.member.key.localeCompare(b.member.key)).slice(0, 5);
|
|
1225
|
+
if (candidates.length === 0) return "";
|
|
1226
|
+
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")}`;
|
|
1227
|
+
}
|
|
1228
|
+
function said(entry, tr) {
|
|
1229
|
+
return entry.utterance === void 0 ? tr("- {name} intended: {intent} ({result}) {summary}", {
|
|
1230
|
+
name: entry.name,
|
|
1231
|
+
intent: entry.intent,
|
|
1232
|
+
result: entry.result,
|
|
1233
|
+
summary: entry.summary
|
|
1234
|
+
}) : tr("- {name} said \"{utterance}\" and intended: {intent} ({result}) {summary}", {
|
|
1235
|
+
name: entry.name,
|
|
1236
|
+
utterance: entry.utterance,
|
|
1237
|
+
intent: entry.intent,
|
|
1238
|
+
result: entry.result,
|
|
1239
|
+
summary: entry.summary
|
|
1240
|
+
});
|
|
1241
|
+
}
|
|
1242
|
+
function age(at, now, tr) {
|
|
1243
|
+
if (at === void 0 || now === void 0) return tr("some time ago");
|
|
1244
|
+
const seconds = Math.max(0, Math.floor((now - at) / 1e3));
|
|
1245
|
+
if (seconds < 60) return tr("just now");
|
|
1246
|
+
const amount = Math.floor(seconds / (seconds >= 86400 ? 86400 : seconds >= 3600 ? 3600 : 60));
|
|
1247
|
+
if (seconds >= 86400) return amount === 1 ? tr("1 day ago") : tr("{amount} days ago", { amount });
|
|
1248
|
+
if (seconds >= 3600) return amount === 1 ? tr("1 hour ago") : tr("{amount} hours ago", { amount });
|
|
1249
|
+
return amount === 1 ? tr("1 minute ago") : tr("{amount} minutes ago", { amount });
|
|
1250
|
+
}
|
|
1251
|
+
/** 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. */
|
|
1252
|
+
function remembered(memories, tr, now) {
|
|
1253
|
+
return memories.map((memory) => {
|
|
1254
|
+
const clarity = memory.clarity === "clear" ? [] : [memory.clarity === "faded" ? tr("the details are fuzzy") : tr("you barely remember")];
|
|
1255
|
+
const sure = memory.confidence === "sure" ? [tr("you are sure of it")] : memory.confidence === "doubtful" ? [tr("you doubt it")] : [];
|
|
1256
|
+
const against = memory.disputed === true ? [tr("something you have seen since speaks against it")] : [];
|
|
1257
|
+
return `- (${[
|
|
1258
|
+
age(memory.at, now, tr),
|
|
1259
|
+
...clarity,
|
|
1260
|
+
...sure,
|
|
1261
|
+
...against,
|
|
1262
|
+
...memory.linked === true ? [tr("it comes to mind with the rest")] : []
|
|
1263
|
+
].join(tr(", "))}) ${memory.text}`;
|
|
1264
|
+
}).join("\n");
|
|
1265
|
+
}
|
|
1266
|
+
/** Every character is told the same thing about the scene, plus who it is and what it remembers. */
|
|
1267
|
+
const sharedContext = { brief(request) {
|
|
1268
|
+
const { member, cast, situation, attempt, earlier, reaction, previous, memories, place, relationships, knowledge, affiliations, carrying, time, agenda } = request;
|
|
1269
|
+
const language = languageOf$1(request.language);
|
|
1270
|
+
const tr = translator(language);
|
|
1271
|
+
const list = (entries) => entries.join(tr("; "));
|
|
1272
|
+
const company = place === void 0 ? cast : place.here;
|
|
1273
|
+
const sections = [
|
|
1274
|
+
`${tr("Situation:")}\n${situation}`,
|
|
1275
|
+
...time === void 0 ? [] : [tr("Now: {time}.", { time: describeTime(time, language) })],
|
|
1276
|
+
...place === void 0 ? [] : [`${tr("Where you are:")}\n${describePlace(place, { withKeys: false }, tr).join("\n")}`],
|
|
1277
|
+
`${tr("Present:")}\n${present(company, member.key, tr)}`
|
|
1278
|
+
];
|
|
1279
|
+
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")}`);
|
|
1280
|
+
if (request.cues !== void 0 && request.cues.length > 0) sections.push(`${tr("Just now you notice:")}\n${request.cues.map((cue) => `- ${cue}`).join("\n")}`);
|
|
1281
|
+
if (request.tracked !== void 0 && request.tracked.self !== "") sections.push(`${tr("How you are (what you can tell of yourself):")}\n${request.tracked.self}`);
|
|
1282
|
+
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")}`);
|
|
1283
|
+
const day = agenda === void 0 || time === void 0 ? [] : describeAgenda(agenda, time.now, tr, language);
|
|
1284
|
+
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")}`);
|
|
1285
|
+
if (carrying !== void 0 && carrying.length > 0) sections.push(`${tr("What you have on you:")}\n${describeItems(carrying, { withKeys: false }, tr)}`);
|
|
1286
|
+
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) => {
|
|
1287
|
+
const attitude = describeAttitude(relation, tr);
|
|
1288
|
+
return `- ${relation.name}${relation.present ? tr(" (here)") : tr(" (not here)")} — ${relation.label}${relation.summary === "" ? "" : `${tr(": ")}${relation.summary}`}${attitude === "" ? "" : ` [${attitude}]`}`;
|
|
1289
|
+
}).join("\n")}`);
|
|
1290
|
+
if (affiliations !== void 0 && affiliations.length > 0) sections.push(`${tr("Your affiliations (their goals are pressures and commitments, not commands):")}\n${affiliations.map((entry) => {
|
|
1291
|
+
const position = [entry.role, entry.rank].filter(Boolean).join(tr(", ")) || tr("member");
|
|
1292
|
+
const goals = entry.goals.length === 0 ? "" : tr(" Goals: {goals}.", { goals: list(entry.goals) });
|
|
1293
|
+
const state = entry.publicState === "" ? "" : ` ${entry.publicState}`;
|
|
1294
|
+
const attitude = entry.relationship === void 0 ? "" : describeAttitude(entry.relationship, tr);
|
|
1295
|
+
return tr("- {name}: {position}; {status}; commitment {commitment}.", {
|
|
1296
|
+
name: entry.name,
|
|
1297
|
+
position,
|
|
1298
|
+
status: entry.status,
|
|
1299
|
+
commitment: entry.commitment.toFixed(2)
|
|
1300
|
+
}) + `${state}${goals}${attitude === "" ? "" : tr(" Your view: {attitude}.", { attitude })}`;
|
|
1301
|
+
}).join("\n")}`);
|
|
1302
|
+
if (knowledge !== void 0) {
|
|
1303
|
+
const shown = (entries) => list(entries.slice(0, 30)) + (entries.length > 30 ? tr("; and {count} more you can recall if needed", { count: entries.length - 30 }) : "");
|
|
1304
|
+
const lines = [
|
|
1305
|
+
knowledge.characters.length === 0 ? void 0 : `${tr("People: ")}${shown(knowledge.characters)}`,
|
|
1306
|
+
knowledge.factions.length === 0 ? void 0 : `${tr("Factions: ")}${shown(knowledge.factions)}`,
|
|
1307
|
+
knowledge.locations.length === 0 ? void 0 : `${tr("Places: ")}${shown(knowledge.locations)}`,
|
|
1308
|
+
knowledge.routes.length === 0 ? void 0 : `${tr("Routes: ")}${shown(knowledge.routes)}`,
|
|
1309
|
+
knowledge.items.length === 0 ? void 0 : `${tr("Things: ")}${shown(knowledge.items)}`,
|
|
1310
|
+
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)}`
|
|
1311
|
+
].filter((line) => line !== void 0);
|
|
1312
|
+
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")}`);
|
|
1313
|
+
}
|
|
1314
|
+
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)}`);
|
|
1315
|
+
else if (memories !== void 0) sections.splice(1, 0, tr("What you remember that bears on this: nothing comes to mind."));
|
|
1316
|
+
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")}`);
|
|
1317
|
+
if (attempt === 2 && reaction !== void 0) {
|
|
1318
|
+
sections.push(`${tr("What just happened, and what you are reacting to:")}\n${reaction.map((entry) => said(entry, tr)).join("\n")}`);
|
|
1319
|
+
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 }));
|
|
1320
|
+
}
|
|
1321
|
+
return {
|
|
1322
|
+
persona: [
|
|
1323
|
+
describe(member.character, tr),
|
|
1324
|
+
request.text("roleplay/character-rules", { name: member.character.name }),
|
|
1325
|
+
request.text("roleplay/character-style", { name: member.character.name }),
|
|
1326
|
+
...request.lookup ? [request.text("roleplay/character-lookup")] : [],
|
|
1327
|
+
request.text("roleplay/character-decide", {
|
|
1328
|
+
name: member.character.name,
|
|
1329
|
+
...limitVariables(request.language ?? "en")
|
|
1330
|
+
})
|
|
1331
|
+
].join("\n\n"),
|
|
1332
|
+
prompt: sections.join("\n\n")
|
|
1333
|
+
};
|
|
1334
|
+
} };
|
|
1335
|
+
/**
|
|
1336
|
+
* 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
|
|
1337
|
+
* 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
|
|
1338
|
+
* another place can be asked when the moment reaches it.)
|
|
1339
|
+
*/
|
|
1340
|
+
const everyoneActs = { plan({ cast, requested }) {
|
|
1341
|
+
const placed = cast.some((member) => member.place !== void 0);
|
|
1342
|
+
const available = cast.filter((member) => member.character.control === "agent");
|
|
1343
|
+
const here = cast.find((member) => member.character.control === "player")?.place?.location.id;
|
|
1344
|
+
const inScene = (member) => !placed || member.place !== void 0;
|
|
1345
|
+
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);
|
|
1346
|
+
const unknown = requested.filter((key) => !available.some((member) => member.key === key));
|
|
1347
|
+
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(", ")})`);
|
|
1348
|
+
const nowhere = [...new Set(requested)].map((key) => available.find((member) => member.key === key)).filter((member) => !inScene(member));
|
|
1349
|
+
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`);
|
|
1350
|
+
return [...new Set(requested)];
|
|
1351
|
+
} };
|
|
1352
|
+
const acceptsAnyIntent = { validate: ({ intent }) => intent.trim() === "" ? {
|
|
1353
|
+
ok: false,
|
|
1354
|
+
reason: "the intent is empty"
|
|
1355
|
+
} : { ok: true } };
|
|
1356
|
+
/** A character whose intent failed and who is highly committed tries once more. */
|
|
1357
|
+
const persistentRetry = { select({ reports, outcomes }) {
|
|
1358
|
+
return reports.filter((report) => report.commitment === "high" && outcomes.some((outcome) => outcome.character === report.character && outcome.result === "failed")).map((report) => report.character);
|
|
1359
|
+
} };
|
|
1360
|
+
const acceptsAnyInput = { validate: () => ({ ok: true }) };
|
|
1361
|
+
/** The game master narrates. */
|
|
1362
|
+
const gameMasterNarrates = { narrate: () => Promise.resolve(void 0) };
|
|
1363
|
+
/** Compares what was said, ignoring the quotes around it and the way whitespace is laid out. */
|
|
1364
|
+
function sameWords(a, b) {
|
|
1365
|
+
const plain = (text) => trimCharacters(text.trim(), "\"“”„«»'‘’").replace(/\s+/g, " ").trim();
|
|
1366
|
+
return plain(a) === plain(b);
|
|
1367
|
+
}
|
|
1368
|
+
/** How many earlier events the game master is reminded of at most. */
|
|
1369
|
+
const REMINDED_EVENTS = 5;
|
|
1370
|
+
/**
|
|
1371
|
+
* The state of the scene, what is still open in the story, and the earlier events that the
|
|
1372
|
+
* player's move brings to mind (by the session's search of words and meaning, and by who is named):
|
|
1373
|
+
* those already folded out of the conversation into the summaries, whose detail the summaries may have lost.
|
|
1374
|
+
*/
|
|
1375
|
+
/** Where the player is and what is there, who is with them, and who is elsewhere. */
|
|
1376
|
+
function placedScene(cast, player, story, describeMember, tr, things) {
|
|
1377
|
+
const here = player?.place?.location;
|
|
1378
|
+
const sections = [];
|
|
1379
|
+
if (here !== void 0) {
|
|
1380
|
+
const view = {
|
|
1381
|
+
key: locationKey(here),
|
|
1382
|
+
location: here,
|
|
1383
|
+
here: cast.filter((member) => member.place?.location.id === here.id),
|
|
1384
|
+
...things === void 0 ? {} : { items: things.at(here.id) },
|
|
1385
|
+
exits: story.locations.exitsFrom(here.id).flatMap((exit) => {
|
|
1386
|
+
const to = story.locations.get(exit.toId);
|
|
1387
|
+
return to === void 0 ? [] : [{
|
|
1388
|
+
key: locationKey(to),
|
|
1389
|
+
name: to.name,
|
|
1390
|
+
exit
|
|
1391
|
+
}];
|
|
1392
|
+
})
|
|
1393
|
+
};
|
|
1394
|
+
sections.push(tr("The player's character is in {place}", { place: describePlace(view, { withKeys: true }, tr).join("\n") }));
|
|
1395
|
+
sections.push(`${tr("Characters here:")}\n${view.here.map(describeMember).join("\n")}`);
|
|
1396
|
+
}
|
|
1397
|
+
const elsewhere = cast.filter((member) => member.place !== void 0 && member.place.location.id !== here?.id);
|
|
1398
|
+
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})", {
|
|
1399
|
+
member: describeMember(member),
|
|
1400
|
+
place: member.place.location.name,
|
|
1401
|
+
key: locationKey(member.place.location)
|
|
1402
|
+
})).join("\n")}`);
|
|
1403
|
+
const nowhere = cast.filter((member) => member.place === void 0);
|
|
1404
|
+
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")}`);
|
|
1405
|
+
return sections.join("\n\n");
|
|
1406
|
+
}
|
|
1407
|
+
const castSummary = { scene({ tracked, time, world, cast, turn, input, queryVector, story, items, language: code, report }) {
|
|
1408
|
+
const language = languageOf$1(code);
|
|
1409
|
+
const tr = translator(language);
|
|
1410
|
+
const join = (entries) => entries.join(tr("; "));
|
|
1411
|
+
const describeMember = (member) => {
|
|
1412
|
+
const { key, character, state } = member;
|
|
1413
|
+
const role = character.control === "player" ? tr("the player's character, \"{key}\"", { key }) : tr("acts through \"{key}\"", { key });
|
|
1414
|
+
const seen = [state?.publicState, state?.activity].filter((text) => text !== void 0 && text.trim() !== "");
|
|
1415
|
+
const where = whereIs(member, tr);
|
|
1416
|
+
return `- ${referent(character)} (${role})${where === "" ? "" : ` [${where}]`}${character.summary === "" ? "" : `${tr(": ")}${character.summary}`}${seen.length > 0 ? ` ${tr("Currently: {state}", { state: join(seen) })}` : ""}`;
|
|
1417
|
+
};
|
|
1418
|
+
const player = cast.find((member) => member.character.control === "player");
|
|
1419
|
+
const days = time?.agenda === void 0 ? "" : describeSceneAgenda(time.agenda, time.now.now, tr, language);
|
|
1420
|
+
const scene = cast.some((member) => member.place !== void 0) ? placedScene(cast, player, story, describeMember, tr, items) : cast.map(describeMember).join("\n");
|
|
1421
|
+
const parts = [];
|
|
1422
|
+
const add = (id, text) => {
|
|
1423
|
+
parts.push(text);
|
|
1424
|
+
report?.section(id, text);
|
|
1425
|
+
};
|
|
1426
|
+
if (time !== void 0) add("time", timeNotice(time, language, tr));
|
|
1427
|
+
if (days !== "") add("agenda", days);
|
|
1428
|
+
add("scene", `${tr("Scene before turn {turn}:", { turn })}\n${scene}`);
|
|
1429
|
+
const activation = describeActivationCandidates(cast, input, story, tr);
|
|
1430
|
+
if (activation !== "") add("activation", activation);
|
|
1431
|
+
if (items !== void 0) {
|
|
1432
|
+
const carried = cast.flatMap((member) => {
|
|
1433
|
+
const mine = items.carried(member.character.id);
|
|
1434
|
+
return mine.length === 0 ? [] : [`- ${member.character.name} (${member.key}): ${describeItems(mine, { withKeys: true }, tr)}`];
|
|
1435
|
+
});
|
|
1436
|
+
if (carried.length > 0) add("carried", `${tr("What characters have on them:")}\n${carried.join("\n")}`);
|
|
1437
|
+
}
|
|
1438
|
+
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")}`);
|
|
1439
|
+
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")}`);
|
|
1440
|
+
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")}`);
|
|
1441
|
+
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")}`);
|
|
1442
|
+
const threads = story.threads.list("open");
|
|
1443
|
+
if (threads.length > 0) add("threads", `${tr("Still open in the story:")}\n${threads.map((thread) => `- ${thread.text}`).join("\n")}`);
|
|
1444
|
+
const folded = story.summaries.list().reduce((latest, summary) => Math.max(latest, summary.toTurn), 0);
|
|
1445
|
+
if (folded > 0) {
|
|
1446
|
+
const mentionedIds = mentioned(input, cast.map(({ character }) => character));
|
|
1447
|
+
const cues = tokens(input);
|
|
1448
|
+
const names = new Map(cast.map(({ character }) => [character.id, character.name]));
|
|
1449
|
+
const byMeaning = story.searchEvents({
|
|
1450
|
+
text: input,
|
|
1451
|
+
...queryVector === void 0 ? {} : { vector: queryVector },
|
|
1452
|
+
toTurn: folded,
|
|
1453
|
+
limit: 10
|
|
1454
|
+
});
|
|
1455
|
+
const byCues = story.events.list({ toTurn: folded }).filter((event) => !byMeaning.some((found) => found.id === event.id)).map((event) => ({
|
|
1456
|
+
event,
|
|
1457
|
+
score: 3 * event.involves.filter((id) => mentionedIds.has(id)).length + overlap(cues, event.text, event.tags)
|
|
1458
|
+
})).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);
|
|
1459
|
+
const ranked = [...byMeaning.map((event) => ({
|
|
1460
|
+
event,
|
|
1461
|
+
how: "search"
|
|
1462
|
+
})), ...byCues.map((event) => ({
|
|
1463
|
+
event,
|
|
1464
|
+
how: "cues"
|
|
1465
|
+
}))];
|
|
1466
|
+
const chosen = ranked.slice(0, REMINDED_EVENTS).sort((a, b) => a.event.turn - b.event.turn);
|
|
1467
|
+
const relevant = chosen.map(({ event }) => ({ event }));
|
|
1468
|
+
report?.selected({
|
|
1469
|
+
events: chosen.map(({ event, how }) => ({
|
|
1470
|
+
turn: event.turn,
|
|
1471
|
+
text: event.text,
|
|
1472
|
+
how
|
|
1473
|
+
})),
|
|
1474
|
+
omitted: ranked.length - chosen.length,
|
|
1475
|
+
folded
|
|
1476
|
+
});
|
|
1477
|
+
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 }) => {
|
|
1478
|
+
const who = event.involves.map((id) => names.get(id)).filter((name) => name !== void 0).join(tr(", "));
|
|
1479
|
+
return `- (${tr("turn {turn}", { turn: event.turn })}) ${event.text}${who === "" ? "" : ` [${who}]`}`;
|
|
1480
|
+
}).join("\n")}`);
|
|
1481
|
+
} else report?.selected({
|
|
1482
|
+
events: [],
|
|
1483
|
+
omitted: 0,
|
|
1484
|
+
folded: 0
|
|
1485
|
+
});
|
|
1486
|
+
return parts.join("\n\n");
|
|
1487
|
+
} };
|
|
1488
|
+
const sameCharacter = (utterance, character) => utterance.character === character || utterance.name === character;
|
|
1489
|
+
/** Every utterance appears once, exactly as given and in the order spoken, and no one speaks who did not. */
|
|
1490
|
+
const exactUtterances = {
|
|
1491
|
+
check(segments, required) {
|
|
1492
|
+
const problems = [];
|
|
1493
|
+
const used = /* @__PURE__ */ new Set();
|
|
1494
|
+
let latest = 0;
|
|
1495
|
+
segments.forEach((segment, index) => {
|
|
1496
|
+
const at = `segment ${index + 1}`;
|
|
1497
|
+
if (segment.type === "narration") {
|
|
1498
|
+
if (segment.text.trim() === "") problems.push(`${at}: the narration is empty`);
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
const own = required.flatMap((utterance, position) => sameCharacter(utterance, segment.character) ? [position] : []);
|
|
1502
|
+
const free = own.filter((position) => !used.has(position));
|
|
1503
|
+
const exact = free.find((position) => sameWords(segment.text, required[position].text));
|
|
1504
|
+
if (exact !== void 0) {
|
|
1505
|
+
used.add(exact);
|
|
1506
|
+
const spoken = required[exact];
|
|
1507
|
+
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`);
|
|
1508
|
+
latest = Math.max(latest, spoken.round);
|
|
1509
|
+
} else if (free.length > 0) {
|
|
1510
|
+
used.add(free[0]);
|
|
1511
|
+
problems.push(`${at}: the utterance of ${required[free[0]].name} was changed; it must be exactly "${required[free[0]].text}"`);
|
|
1512
|
+
} 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`);
|
|
1513
|
+
else problems.push(`${at}: ${segment.character} has nothing to say this turn, so this utterance is invented; remove it`);
|
|
1514
|
+
});
|
|
1515
|
+
required.forEach((utterance, position) => {
|
|
1516
|
+
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}"`);
|
|
1517
|
+
});
|
|
1518
|
+
return problems;
|
|
1519
|
+
},
|
|
1520
|
+
repair(segments, required) {
|
|
1521
|
+
const used = /* @__PURE__ */ new Set();
|
|
1522
|
+
const kept = [];
|
|
1523
|
+
for (const segment of segments) {
|
|
1524
|
+
if (segment.type === "narration") {
|
|
1525
|
+
if (segment.text.trim() !== "") kept.push({
|
|
1526
|
+
segment,
|
|
1527
|
+
round: void 0
|
|
1528
|
+
});
|
|
1529
|
+
continue;
|
|
1530
|
+
}
|
|
1531
|
+
const free = required.flatMap((utterance, position) => sameCharacter(utterance, segment.character) && !used.has(position) ? [position] : []);
|
|
1532
|
+
const position = free.find((candidate) => sameWords(segment.text, required[candidate].text)) ?? free[0];
|
|
1533
|
+
if (position === void 0) continue;
|
|
1534
|
+
used.add(position);
|
|
1535
|
+
const spoken = required[position];
|
|
1536
|
+
kept.push({
|
|
1537
|
+
segment: {
|
|
1538
|
+
type: "utterance",
|
|
1539
|
+
character: spoken.character,
|
|
1540
|
+
name: spoken.name,
|
|
1541
|
+
text: spoken.text
|
|
1542
|
+
},
|
|
1543
|
+
round: spoken.round
|
|
1544
|
+
});
|
|
1545
|
+
}
|
|
1546
|
+
required.forEach((utterance, position) => {
|
|
1547
|
+
if (used.has(position)) return;
|
|
1548
|
+
const restored = {
|
|
1549
|
+
type: "utterance",
|
|
1550
|
+
character: utterance.character,
|
|
1551
|
+
name: utterance.name,
|
|
1552
|
+
text: utterance.text
|
|
1553
|
+
};
|
|
1554
|
+
const later = kept.findIndex((entry) => entry.round !== void 0 && entry.round > utterance.round);
|
|
1555
|
+
kept.splice(later < 0 ? kept.length : later, 0, {
|
|
1556
|
+
segment: restored,
|
|
1557
|
+
round: utterance.round
|
|
1558
|
+
});
|
|
1559
|
+
});
|
|
1560
|
+
return kept.map((entry) => entry.segment);
|
|
1561
|
+
}
|
|
1562
|
+
};
|
|
1563
|
+
/** 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. */
|
|
1564
|
+
const recordsRecall = { recall: ({ member, situation, turn, policy, queryVector, explain, peek }, story, signal) => story.recallRanked({
|
|
1565
|
+
characterId: member.character.id,
|
|
1566
|
+
situation,
|
|
1567
|
+
turn,
|
|
1568
|
+
policy,
|
|
1569
|
+
...explain === true ? { explain } : {},
|
|
1570
|
+
...member.place === void 0 ? {} : { locationId: member.place.location.id }
|
|
1571
|
+
}, signal, {
|
|
1572
|
+
...queryVector === void 0 ? {} : { queryVector },
|
|
1573
|
+
...peek === true ? { peek } : {}
|
|
1574
|
+
}) };
|
|
1575
|
+
/**
|
|
1576
|
+
* Writes no memory. What the game master decided about each character is applied when the round is
|
|
1577
|
+
* recorded, so without a memory keeper the story keeps its states and no events.
|
|
1578
|
+
*/
|
|
1579
|
+
const writesNothing = { commit: () => Promise.resolve({
|
|
1580
|
+
writes: 0,
|
|
1581
|
+
notes: ""
|
|
1582
|
+
}) };
|
|
1583
|
+
/** Makes up nothing, and has nothing to fit in: without a world author the world stays as it was written. */
|
|
1584
|
+
const declinesToAuthor = {
|
|
1585
|
+
create: () => Promise.resolve({
|
|
1586
|
+
created: [],
|
|
1587
|
+
declined: "no world author is installed, so the world cannot grow"
|
|
1588
|
+
}),
|
|
1589
|
+
consolidate: () => Promise.resolve({
|
|
1590
|
+
resolved: 0,
|
|
1591
|
+
notes: ""
|
|
1592
|
+
})
|
|
1593
|
+
};
|
|
1594
|
+
/** Lets no organisation act: without a strategist factions change only through what the story records. */
|
|
1595
|
+
const factionsStayPut = { strategize: () => Promise.resolve({ acted: [] }) };
|
|
1596
|
+
/** Reflects on nothing: without a reflector what characters believe changes only through what the story records. */
|
|
1597
|
+
const reflectsOnNothing = { reflect: () => Promise.resolve({ characters: [] }) };
|
|
1598
|
+
/** Finds no fault: without a gate the output is delivered as the game master wrote it. */
|
|
1599
|
+
const tracksNothing = { track: () => Promise.resolve(0) };
|
|
1600
|
+
const passesEverything = { check: () => Promise.resolve([]) };
|
|
1601
|
+
/** Finds no broken rule: without a check the game master's judgement of an action stands as it is. */
|
|
1602
|
+
const breaksNoRule = { check: () => Promise.resolve([]) };
|
|
1603
|
+
/** Judges nothing: without a judge a trigger that waits on a statement never sees it hold. */
|
|
1604
|
+
const judgesNothing = { judge: () => Promise.resolve({ judged: 0 }) };
|
|
1605
|
+
/** Offers nothing: without a suggester the player writes their own move. */
|
|
1606
|
+
const offersNothing = { suggest: () => Promise.resolve([]) };
|
|
1607
|
+
function defaultBoundaries() {
|
|
1608
|
+
return {
|
|
1609
|
+
planner: everyoneActs,
|
|
1610
|
+
characterContext: sharedContext,
|
|
1611
|
+
outputValidator: acceptsAnyIntent,
|
|
1612
|
+
retryPolicy: persistentRetry,
|
|
1613
|
+
inputValidator: acceptsAnyInput,
|
|
1614
|
+
narrator: gameMasterNarrates,
|
|
1615
|
+
narrationChecker: exactUtterances,
|
|
1616
|
+
committer: writesNothing,
|
|
1617
|
+
author: declinesToAuthor,
|
|
1618
|
+
strategist: factionsStayPut,
|
|
1619
|
+
reflector: reflectsOnNothing,
|
|
1620
|
+
judge: judgesNothing,
|
|
1621
|
+
outputGate: passesEverything,
|
|
1622
|
+
ruleCheck: breaksNoRule,
|
|
1623
|
+
variableTracker: tracksNothing,
|
|
1624
|
+
suggester: offersNothing,
|
|
1625
|
+
recaller: recordsRecall,
|
|
1626
|
+
sceneContext: castSummary
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1028
1629
|
// src/host/orchestration/observation.ts
|
|
1029
1630
|
/** What a character takes in where it stands and of what it carries: the place, the ways out and what they lead to, what lies in the open, what it holds. */
|
|
1030
1631
|
function observeSurroundings(session, characterId, turn) {
|
|
@@ -2087,9 +2688,11 @@ function checkMove(session, characterKey, request) {
|
|
|
2087
2688
|
...request.position === void 0 ? {} : { position: request.position }
|
|
2088
2689
|
} : {
|
|
2089
2690
|
ok: false,
|
|
2090
|
-
problems: planned.problems
|
|
2691
|
+
problems: planned.problems.map((problem) => /^the character does not know place /.test(problem) ? unknownPlace(to.name) : problem)
|
|
2091
2692
|
};
|
|
2092
2693
|
}
|
|
2694
|
+
/** What the game master is told when it sends a character somewhere it has not heard of (found live: the same refused call 38 times, because the reason named no way out). */
|
|
2695
|
+
const unknownPlace = (name) => `the character has not heard of ${name}, and a character only goes where it knows the way. Do not send it there: take it to a place it knows (get_character lists them), or let the story first make the place known to it (someone tells it, a sign, a map) and send it on a later turn`;
|
|
2093
2696
|
function storeOf(session, folder, problem, queryVector, wall, prompt) {
|
|
2094
2697
|
const settings = () => liveSettings(folder, problem);
|
|
2095
2698
|
return {
|
|
@@ -2303,6 +2906,39 @@ function guardRepeatedCalls(ctx, languageOf, limit) {
|
|
|
2303
2906
|
};
|
|
2304
2907
|
}, { prepend: true });
|
|
2305
2908
|
}
|
|
2909
|
+
// src/host/orchestration/runaway.ts
|
|
2910
|
+
/** The levels of thinking that mean none, as models name them. */
|
|
2911
|
+
const NONE = [
|
|
2912
|
+
"off",
|
|
2913
|
+
"none",
|
|
2914
|
+
"minimal"
|
|
2915
|
+
];
|
|
2916
|
+
/**
|
|
2917
|
+
* A game master whose thinking ran on to the end of its output limit (found live: 12000 tokens, two and a half minutes, and a turn that ended without output) is asked to answer
|
|
2918
|
+
* without thinking for the rest of the turn, when its model offers that. The level it was on is put back at the first step of the next turn.
|
|
2919
|
+
*/
|
|
2920
|
+
var RunawayThinking = class {
|
|
2921
|
+
before = /* @__PURE__ */ new Map();
|
|
2922
|
+
/** To be called before each step of a chat's game master. */
|
|
2923
|
+
async step(chat, agent, step) {
|
|
2924
|
+
const earlier = this.before.get(chat);
|
|
2925
|
+
if (earlier !== void 0 && step === 1) {
|
|
2926
|
+
agent.model.select(earlier);
|
|
2927
|
+
this.before.delete(chat);
|
|
2928
|
+
return;
|
|
2929
|
+
}
|
|
2930
|
+
if (step === 1 || earlier !== void 0 || !cutOff(agent)) return;
|
|
2931
|
+
const current = agent.model.current();
|
|
2932
|
+
if (current === void 0) return;
|
|
2933
|
+
const level = (await agent.ctx.llm.resolveModelInfo(current.provider, current.model, new AbortController().signal).catch(() => void 0))?.reasoning?.efforts.find((effort) => NONE.includes(effort.id));
|
|
2934
|
+
if (level === void 0 || current.reasoningEffort === level.id) return;
|
|
2935
|
+
this.before.set(chat, current);
|
|
2936
|
+
agent.model.select({
|
|
2937
|
+
...current,
|
|
2938
|
+
reasoningEffort: ReasoningEffortId(level.id)
|
|
2939
|
+
});
|
|
2940
|
+
}
|
|
2941
|
+
};
|
|
2306
2942
|
// src/shared/tools.ts
|
|
2307
2943
|
/** What this version can offer. A name in a settings file or a world that is not here is kept and ignored. */
|
|
2308
2944
|
const OPTIONAL_TOOLS = [
|
|
@@ -2409,7 +3045,7 @@ function characterRunner(deps) {
|
|
|
2409
3045
|
maxCalls: deps.store.settings().memory.lookupCalls + (external.length === 0 ? 0 : EXTERNAL_CALLS),
|
|
2410
3046
|
result: request.away === true ? AWAY_ACTION_SCHEMA : CHARACTER_ACTION_SCHEMA,
|
|
2411
3047
|
unenforced: ["thought"],
|
|
2412
|
-
beforeSubmit: submitGate(settings.prompts.language, background)
|
|
3048
|
+
beforeSubmit: submitGate(settings.prompts.language, background, request.away === true ? [] : ownLines(deps.store, request.member.character))
|
|
2413
3049
|
}));
|
|
2414
3050
|
};
|
|
2415
3051
|
}
|
|
@@ -2433,16 +3069,29 @@ function notingEmpty(tool, store, turn, character) {
|
|
|
2433
3069
|
}
|
|
2434
3070
|
const BACKGROUND_CHECK = "before you answer: does this moment touch your own past, skills, training, secrets or what you know of a person or place? If it does, read that background first with recall_my_lore (about: the subject) and answer from it; if it does not, submit the same answer again unchanged";
|
|
2435
3071
|
/** The model decides whether the moment touches its background; asking once at the point of answering is what makes it decide. */
|
|
2436
|
-
function submitGate(language, background) {
|
|
3072
|
+
function submitGate(language, background, said = []) {
|
|
2437
3073
|
let asked = !background;
|
|
3074
|
+
let reminded = false;
|
|
3075
|
+
const tr = translator(languageOf$1(language));
|
|
2438
3076
|
return (value) => {
|
|
2439
3077
|
if (!asked) {
|
|
2440
3078
|
asked = true;
|
|
2441
3079
|
return BACKGROUND_CHECK;
|
|
2442
3080
|
}
|
|
2443
|
-
|
|
3081
|
+
const wrong = spokenIn(language, value);
|
|
3082
|
+
if (wrong !== void 0) return wrong;
|
|
3083
|
+
const line = value.utterance;
|
|
3084
|
+
if (!reminded && line !== void 0 && said.some((earlier) => sameWords(earlier, line))) {
|
|
3085
|
+
reminded = true;
|
|
3086
|
+
return tr("you already said exactly this earlier in the story: \"{line}\". Say something new that answers this moment, or give no utterance", { line });
|
|
3087
|
+
}
|
|
2444
3088
|
};
|
|
2445
3089
|
}
|
|
3090
|
+
/** What a character has said in the story so far, most recent last, as the records keep it. */
|
|
3091
|
+
function ownLines(store, character) {
|
|
3092
|
+
const opening = `${character.name}: "`;
|
|
3093
|
+
return store.story.events.list({ involving: character.id }).flatMap((event) => event.text.startsWith(opening) && event.text.endsWith("\"") ? [event.text.slice(opening.length, -1)] : []).slice(-12);
|
|
3094
|
+
}
|
|
2446
3095
|
/** What a character that was given tools of other plugins may call on top of its memory look-ups. */
|
|
2447
3096
|
const EXTERNAL_CALLS = 5;
|
|
2448
3097
|
/** A character whose sheet is in another language than the chat's writes in the sheet's: the answer is refused until it is in the chat's. */
|
|
@@ -3431,14 +4080,19 @@ function createTools$1(deps) {
|
|
|
3431
4080
|
schema: { type: "json" },
|
|
3432
4081
|
render: (_args, value) => [{
|
|
3433
4082
|
type: "text",
|
|
3434
|
-
text: value.allowed ? `Judged: it can work${value.roll === true ?
|
|
4083
|
+
text: value.allowed ? `Judged: it can work${value.roll === true ? ` but it is uncertain: roll for it now with roll_check (list_checks shows the checks), naming the character it is for; nobody is asked to act before the dice are rolled.${value.quick === true ? " When nobody else needs to react and nothing moves or changes hands, settle it in one step with roll_and_narrate instead: it rolls for you and ends the turn. Otherwise" : " Then"}` : ". Now"} call ${PREVIEW_TOOL} (when the scene asks for it) and ${ACTIVATE_TOOL}, describing only what the character does.` : `Judged: it cannot work${value.elsewhere === true ? ` (${value.reason})` : ""}. Play the failed attempt: ${RESOLVE_TOOL} with one outcome for the player's character (result failed, one sentence: what it does, what comes of it, why not) and nothing else, then ${NARRATE_TOOL}. Narrate what a witness would see of the attempt, never the effect the player claimed.`
|
|
3435
4084
|
}]
|
|
3436
4085
|
},
|
|
3437
4086
|
isConcurrencySafe: () => false,
|
|
3438
4087
|
async execute(args, exec) {
|
|
3439
4088
|
const { owner } = ownerOf(exec.agent);
|
|
3440
4089
|
await deps.engine.checkRules(owner, args.allowed);
|
|
3441
|
-
|
|
4090
|
+
const judged = deps.engine.judge(owner, args.allowed, args.reason, args.at, args.uncertain);
|
|
4091
|
+
const store = deps.stores(owner.chat);
|
|
4092
|
+
return record(judged.roll === true && store !== void 0 && toolEnabled(store.settings().tools, "gameMaster", "roll_and_narrate") ? {
|
|
4093
|
+
...judged,
|
|
4094
|
+
quick: true
|
|
4095
|
+
} : judged);
|
|
3442
4096
|
}
|
|
3443
4097
|
}),
|
|
3444
4098
|
preview,
|
|
@@ -3503,46 +4157,21 @@ function ownerOf(agent, turn) {
|
|
|
3503
4157
|
turn
|
|
3504
4158
|
};
|
|
3505
4159
|
}
|
|
3506
|
-
/** Where the
|
|
3507
|
-
const
|
|
3508
|
-
/**
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
|
|
3512
|
-
|
|
3513
|
-
|
|
3514
|
-
|
|
3515
|
-
|
|
3516
|
-
|
|
3517
|
-
|
|
3518
|
-
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
withdraw();
|
|
3522
|
-
}
|
|
3523
|
-
};
|
|
3524
|
-
}
|
|
3525
|
-
/** Where the withdrawals of an agent's optional tools are kept, by tool name: on the agent, so that a reloaded plugin still finds what its earlier self registered. */
|
|
3526
|
-
const OPTIONAL_SHOWN = Symbol.for("dsh-agentic-roleplay.optional-tools");
|
|
3527
|
-
/** Puts an agent's optional tools in line with the switches: registers the ones that are on and not yet there, withdraws the ones that are off. */
|
|
3528
|
-
function optionalToolSwitch(tools) {
|
|
3529
|
-
return (agent, enabled) => {
|
|
3530
|
-
const holder = agent;
|
|
3531
|
-
const shown = holder[OPTIONAL_SHOWN] ??= /* @__PURE__ */ new Map();
|
|
3532
|
-
for (const tool of tools) {
|
|
3533
|
-
const withdraw = shown.get(tool.name);
|
|
3534
|
-
if (enabled(tool.name) && withdraw === void 0) try {
|
|
3535
|
-
shown.set(tool.name, agent.ctx.tools.register(tool));
|
|
3536
|
-
} catch (error) {
|
|
3537
|
-
if (!(error instanceof Error) || !error.message.includes("already registered")) throw error;
|
|
3538
|
-
shown.set(tool.name, () => void 0);
|
|
3539
|
-
}
|
|
3540
|
-
else if (!enabled(tool.name) && withdraw !== void 0) {
|
|
3541
|
-
shown.delete(tool.name);
|
|
3542
|
-
withdraw();
|
|
3543
|
-
}
|
|
3544
|
-
}
|
|
3545
|
-
};
|
|
4160
|
+
/** Where an agent keeps the fact that its conditional tools are registered: on the agent, so that a reloaded plugin does not register them a second time. */
|
|
4161
|
+
const CONDITIONAL_REGISTERED = Symbol.for("dsh-agentic-roleplay.conditional-tools");
|
|
4162
|
+
/**
|
|
4163
|
+
* Registers an agent's switchable tools once, before its first request. DSH asks each condition at every step and leaves a tool out of the request while
|
|
4164
|
+
* it is false, so a setting changed during a story applies at the next step without registering or withdrawing anything.
|
|
4165
|
+
*/
|
|
4166
|
+
function registerConditionalTools(agent, entries) {
|
|
4167
|
+
const holder = agent;
|
|
4168
|
+
if (holder[CONDITIONAL_REGISTERED] === true) return;
|
|
4169
|
+
for (const { tool, when } of entries) try {
|
|
4170
|
+
agent.ctx.tools.register(tool, { when });
|
|
4171
|
+
} catch (error) {
|
|
4172
|
+
if (!(error instanceof Error) || !error.message.includes("already registered")) throw error;
|
|
4173
|
+
}
|
|
4174
|
+
holder[CONDITIONAL_REGISTERED] = true;
|
|
3546
4175
|
}
|
|
3547
4176
|
/** Where an agent's withdrawal of the external tools it was not given is kept: on the agent, so that a reloaded plugin still finds what its earlier self set. */
|
|
3548
4177
|
const EXTERNAL_LIMIT = Symbol.for("dsh-agentic-roleplay.external-limit");
|
|
@@ -3574,14 +4203,24 @@ function commandBringsPeopleIn(store, command) {
|
|
|
3574
4203
|
}
|
|
3575
4204
|
function installHooks(ctx, deps) {
|
|
3576
4205
|
const { engine, boundaries, stores, timelines, previewTool } = deps;
|
|
3577
|
-
const showPreviewTool = previewToggle(previewTool);
|
|
3578
|
-
const showOptionalTools = optionalToolSwitch(deps.optionalTools ?? []);
|
|
3579
4206
|
/** The tools of the game master as the chat's settings say: its optional ones, and none of other plugins' that it was not given. */
|
|
3580
|
-
const
|
|
3581
|
-
|
|
3582
|
-
|
|
3583
|
-
|
|
4207
|
+
const applyLimit = (agent, store) => {
|
|
4208
|
+
externalToolLimit(agent, externalWithheld(agent.ctx.tools, store.settings().tools, "gameMaster"));
|
|
4209
|
+
};
|
|
4210
|
+
const conditionsOf = (chat) => {
|
|
4211
|
+
const settings = () => stores(chat)?.settings();
|
|
4212
|
+
return [{
|
|
4213
|
+
tool: previewTool,
|
|
4214
|
+
when: () => settings()?.preview.enabled === true
|
|
4215
|
+
}, ...(deps.optionalTools ?? []).map((tool) => ({
|
|
4216
|
+
tool,
|
|
4217
|
+
when: () => {
|
|
4218
|
+
const current = settings();
|
|
4219
|
+
return current !== void 0 && toolEnabled(current.tools, "gameMaster", tool.name);
|
|
4220
|
+
}
|
|
4221
|
+
}))];
|
|
3584
4222
|
};
|
|
4223
|
+
const runaway = new RunawayThinking();
|
|
3585
4224
|
guardRepeatedCalls(ctx, (exec) => {
|
|
3586
4225
|
const owner = exec.agent === void 0 ? void 0 : ownerOf(exec.agent, 0);
|
|
3587
4226
|
return owner === void 0 ? void 0 : stores(owner.chat)?.settings().prompts.language;
|
|
@@ -3590,8 +4229,8 @@ function installHooks(ctx, deps) {
|
|
|
3590
4229
|
const owner = ownerOf(agent, 0);
|
|
3591
4230
|
const store = owner === void 0 ? void 0 : stores(owner.chat);
|
|
3592
4231
|
if (store === void 0) return;
|
|
3593
|
-
|
|
3594
|
-
|
|
4232
|
+
registerConditionalTools(agent, conditionsOf(agent.session.id));
|
|
4233
|
+
applyLimit(agent, store);
|
|
3595
4234
|
});
|
|
3596
4235
|
ctx.on("session/event", (session, event) => {
|
|
3597
4236
|
if (event.type !== "turn/end" || session.header.origin === "subagent" || roleplaySessionOf(session.id) === void 0) return;
|
|
@@ -3623,7 +4262,7 @@ function installHooks(ctx, deps) {
|
|
|
3623
4262
|
if (owner === void 0) return;
|
|
3624
4263
|
const missing = engine.missing(owner);
|
|
3625
4264
|
if (missing === void 0) return;
|
|
3626
|
-
if (!engine.object(owner, missing)) {
|
|
4265
|
+
if (!engine.object(owner, missing, finishOf(agent) === "tool-calls")) {
|
|
3627
4266
|
ctx.logger.warn(`roleplay: ${owner.chat} ended turn ${turn} without finishing it (${missing})`);
|
|
3628
4267
|
return;
|
|
3629
4268
|
}
|
|
@@ -3639,12 +4278,15 @@ function installHooks(ctx, deps) {
|
|
|
3639
4278
|
});
|
|
3640
4279
|
ctx.on("agent/pre-step", async (payload, next) => {
|
|
3641
4280
|
const decision = await next();
|
|
4281
|
+
const selected = payload.agent.model.current();
|
|
4282
|
+
if (decision.kind === "enter") await ctx.roleplayOrchestration.residency?.ensure("main", selected === void 0 ? void 0 : {
|
|
4283
|
+
provider: selected.provider,
|
|
4284
|
+
model: selected.model
|
|
4285
|
+
});
|
|
3642
4286
|
const owner = ownerOf(payload.agent, payload.turn);
|
|
4287
|
+
if (decision.kind === "enter" && owner !== void 0) await runaway.step(owner.chat, payload.agent, payload.step);
|
|
3643
4288
|
const store = owner === void 0 ? void 0 : stores(owner.chat);
|
|
3644
|
-
if (owner !== void 0 && store !== void 0)
|
|
3645
|
-
showPreviewTool(payload.agent, store.settings().preview.enabled);
|
|
3646
|
-
applyTools(payload.agent, store);
|
|
3647
|
-
}
|
|
4289
|
+
if (owner !== void 0 && store !== void 0) applyLimit(payload.agent, store);
|
|
3648
4290
|
if (decision.kind !== "enter" || payload.step !== 1) return decision;
|
|
3649
4291
|
if (owner === void 0 || store === void 0) return decision;
|
|
3650
4292
|
const text = payload.messages.filter((message) => message.source.kind === "user").flatMap((message) => message.content.flatMap((block) => block.type === "text" ? [block.text] : [])).join("\n");
|
|
@@ -3788,6 +4430,6 @@ function installHooks(ctx, deps) {
|
|
|
3788
4430
|
};
|
|
3789
4431
|
});
|
|
3790
4432
|
}
|
|
3791
|
-
export {
|
|
4433
|
+
export { inheritPrompts as $, plotProgressOf as A, parsePlotsFile as B, readNotes as C, referent as D, sameWords as E, textLanguage as F, readDocument as G, COMMANDS_KEY as H, wrongLanguage as I, errorMessage as J, Reader as K, readUsage as L, LANGUAGE_NAMES as M, STORY_LANGUAGES as N, RESULTS as O, isStoryLanguage as P, copyWorldPrompts as Q, PLOTS_FILE_NAME as R, notesOfSession as S, defaultBoundaries as T, commandFlagKey as U, plotReferenceProblems as V, commandsOf as W, PROMPTS_FOLDER as X, LANGUAGE_FOLDER as Y, PromptLibrary as Z, readTraces as _, COMPARISONS as _t, externalWithheld as a, shippedText as at, readWithdrawn as b, record as c, InvalidWorldError as ct, guardRepeatedCalls as d, SessionNotFoundError as dt, languageOf as et, MAX_OOC_ANSWER as f, WorldNotFoundError as ft, readRunDetail as g, AUTHORING_NEEDS as gt, readActivity as h, zoneOf as ht, externalTools as i, shippedPromptsDirectory as it, populatePlots as j, PLOTS_METADATA_KEY as k, characterRunner as l, ReflectionRefusedError as lt, readDecisionStats as m, describeWhen as mt, installHooks as n, promptProblem as nt, PREVIEW_TOOL as o, AgentUnavailableError as ot, storesOf as p, ClockError as pt, formatIssue as q, externalGiven as r, shippedLanguages as rt, createTools$1 as s, InvalidStartError as st, externalToolLimit as t, listFiles as tt, toolEnabled as u, SessionArchivedError as ut, readVerdicts as v, observeAsPlayer as w, addToNote as x, writeVerdicts as y, loadPlots as z };
|
|
3792
4434
|
|
|
3793
|
-
//# sourceMappingURL=hooks-
|
|
4435
|
+
//# sourceMappingURL=hooks-C2U1-8ur.js.map
|