@dsh-agentic-roleplay/core 0.10.1 → 0.10.2
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/icon.svg +13 -0
- package/lib/{authoring-tools-C6Hzy8jU.js → authoring-tools-C9cmcUbD.js} +424 -31
- package/lib/authoring.js +6 -6
- package/lib/{child-C8r8AFpm.js → child-C9nPIy9j.js} +7 -3
- package/lib/client.js +2196 -728
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +1 -1
- package/lib/doctor.js +2 -2
- package/lib/helper.js +8 -1
- package/lib/{hooks-BuQ61nvQ.js → hooks-BpLN_hhT.js} +180 -153
- package/lib/images.js +1 -1
- package/lib/index.js +456 -61
- package/lib/{lorebook-author-tools-B6_Jj8oe.js → lorebook-author-tools-Cg7QQemi.js} +4 -4
- package/lib/lorebook-authoring.js +4 -4
- package/lib/orchestration.js +65 -15
- package/lib/{pack-jail-OZSgU85i.js → pack-jail-D5j5mIq6.js} +12 -8
- package/lib/{packs-B88bxt8E.js → packs-Cc05FrId.js} +2 -2
- package/lib/{presenter-agent-D-WNs626.js → presenter-agent-UKbKYXMO.js} +3 -3
- package/lib/{preset-DNuqvMan.js → preset-Be4lz6vB.js} +4 -4
- package/lib/{preset-author-tools-CDwavcTb.js → preset-author-tools-C3s0iSfv.js} +5 -5
- package/lib/preset-authoring.js +5 -5
- package/lib/{presets-9_MNxwaw.js → presets-Cl9sU3Qs.js} +52 -10
- package/lib/{reflection-BvM0w1R4.js → reflection-I9z-PvFK.js} +8 -6
- package/lib/{turn-guard-Ygdww1Wt.js → turn-guard-B9pGCeir.js} +3 -3
- package/package.json +4 -2
- package/prompts/en/checks/decide-opening.md +7 -1
- package/prompts/en/roleplay/record-keeper.md +2 -1
- package/prompts/zh/checks/decide-opening.md +7 -1
- package/prompts/zh/roleplay/record-keeper.md +2 -1
package/lib/compaction.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as liveSettings, t as decodeOutput } from "./narration-B0hConSw.js";
|
|
2
2
|
import { l as roleplaySessionOf, t as promptFor } from "./access-CXtaZNbx.js";
|
|
3
|
-
import {
|
|
3
|
+
import { E as tokensOf, l as runChild, n as childModel, r as childSampling } from "./child-C9nPIy9j.js";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
6
6
|
import BasicCompactionEngine from "@deepseek-ai/dsh-compaction-basic";
|
package/lib/doctor.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { c as chatSessionId } from "./access-CXtaZNbx.js";
|
|
2
2
|
import { n as doctorSessionOf } from "./doctor-chat-hL1a61hp.js";
|
|
3
|
-
import { i as externalTools, t as externalToolLimit } from "./hooks-
|
|
3
|
+
import { i as externalTools, t as externalToolLimit } from "./hooks-BpLN_hhT.js";
|
|
4
4
|
import { a as liveSettings } from "./narration-B0hConSw.js";
|
|
5
5
|
import { join } from "node:path";
|
|
6
|
+
import { createTools, isSessionId, sessionDatabase, sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
6
7
|
import { existsSync } from "node:fs";
|
|
7
8
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
8
9
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
9
|
-
import { createTools, isSessionId, sessionDatabase, sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
10
10
|
// src/host/agent/doctor-undo.ts
|
|
11
11
|
const UNDO_SNAPSHOT = "doctor-undo";
|
|
12
12
|
const UNDO_KEY = "doctor.undo";
|
package/lib/helper.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { o as helpers } from "./child-
|
|
1
|
+
import { o as helpers } from "./child-C9nPIy9j.js";
|
|
2
2
|
// src/helper.ts
|
|
3
3
|
const name = "@dsh-agentic-roleplay/core/helper";
|
|
4
4
|
const inject = ["tools", "systemPrompt"];
|
|
@@ -16,6 +16,13 @@ function apply(ctx) {
|
|
|
16
16
|
return agent === void 0 ? "" : helpers.get(agent.session.id)?.persona ?? "";
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
+
ctx.effect(() => ctx.systemPrompt.suppressRuntimeContext(), "roleplay: helper runtime context");
|
|
20
|
+
ctx.systemPrompt.context({
|
|
21
|
+
name: "working-directory:current",
|
|
22
|
+
order: ctx.systemPrompt.getContextOrder("WORKING_DIRECTORY"),
|
|
23
|
+
interpolate: false,
|
|
24
|
+
text: ""
|
|
25
|
+
});
|
|
19
26
|
ctx.on("agent/created", ({ agent }) => {
|
|
20
27
|
helpers.get(agent.session.id)?.setup(agent);
|
|
21
28
|
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { l as roleplaySessionOf, t as promptFor } from "./access-CXtaZNbx.js";
|
|
2
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-B0hConSw.js";
|
|
3
3
|
import { i as translator, r as languageOf$1, t as trimCharacters } from "./text-CzqhC8sT.js";
|
|
4
|
-
import {
|
|
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";
|
|
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
7
|
import { copyFileSync, cpSync, existsSync, mkdirSync, readFileSync, readdirSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
7
8
|
import { readFile, stat } from "node:fs/promises";
|
|
8
9
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
9
10
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
10
11
|
import { fileURLToPath } from "node:url";
|
|
11
12
|
import { Service } from "@deepseek-ai/cordis";
|
|
12
|
-
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";
|
|
13
13
|
// ../dsh-roleplay-model/src/trigger.ts
|
|
14
14
|
/** The reasons the world author is asked to make something up in play; a trigger that has the author make a person names one of them. */
|
|
15
15
|
const AUTHORING_NEEDS = [
|
|
@@ -45,6 +45,153 @@ const PLOT_NUDGE_MODES = [
|
|
|
45
45
|
"escalation",
|
|
46
46
|
"breathing_room"
|
|
47
47
|
];
|
|
48
|
+
// src/host/clock/story-clock.ts
|
|
49
|
+
var ClockError = class extends Error {};
|
|
50
|
+
/** A moment as it is told next to `now`: the clock when it is the same day, the date as well when it is not. */
|
|
51
|
+
function describeWhen(instant, now, zone, language = "en") {
|
|
52
|
+
const a = localTime(instant, zone);
|
|
53
|
+
const b = localTime(now, zone);
|
|
54
|
+
return a.year === b.year && a.month === b.month && a.day === b.day ? clockTime(instant, zone) : describeInstant(instant, zone, language);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The time in a sentence: the day and date, the clock, and the part of the day; and, when the world has a calendar, the season and the holidays that
|
|
58
|
+
* fall on the day.
|
|
59
|
+
*/
|
|
60
|
+
function describeTime(time, language = "en") {
|
|
61
|
+
const { calendar } = time;
|
|
62
|
+
const tr = translator(language);
|
|
63
|
+
const base = `${describeInstant(time.now, time.zone, language)} (${tr(dayPart(localTime(time.now, time.zone).minuteOfDay))})`;
|
|
64
|
+
if (calendar === void 0 || calendar.holidays.length === 0 && calendar.hemisphere === "north") return base;
|
|
65
|
+
const day = addLocalDays(time.now, time.zone, 0);
|
|
66
|
+
const holidays = holidaysOn(calendar, day).map((holiday) => holiday.name);
|
|
67
|
+
return `${base}${tr(", ")}${tr(seasonOf(day, calendar.hemisphere))}${holidays.length === 0 ? "" : `${tr("; ")}${tr("today is {holidays}", { holidays: holidays.join(tr(", ")) })}`}`;
|
|
68
|
+
}
|
|
69
|
+
/** The time zone the story is read in. */
|
|
70
|
+
const zoneOf = (config) => config.timeZone === "" ? "UTC" : config.timeZone;
|
|
71
|
+
/** The clock, started when a session has none yet, and detached from the real clock when the settings say so. The mode the story has is the one it keeps otherwise. */
|
|
72
|
+
function ensure(session, config, turn, wall) {
|
|
73
|
+
const current = session.clock.get();
|
|
74
|
+
if (current === void 0) {
|
|
75
|
+
session.clock.start(config.mode, config.mode === "real" ? wall : Math.floor(wall / MINUTE) * MINUTE);
|
|
76
|
+
return session.clock.get() ?? {
|
|
77
|
+
mode: config.mode,
|
|
78
|
+
now: wall
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (current.mode !== "real" || config.mode !== "simulated") return current;
|
|
82
|
+
session.clock.resync("simulated", Math.max(current.now, wall), turn, "the story's time was detached from the real clock");
|
|
83
|
+
return session.clock.get() ?? current;
|
|
84
|
+
}
|
|
85
|
+
function timeOf(session, state, config) {
|
|
86
|
+
const calendar = session.metadata === void 0 ? void 0 : readCalendar(session.metadata);
|
|
87
|
+
return {
|
|
88
|
+
mode: state.mode,
|
|
89
|
+
now: state.now,
|
|
90
|
+
zone: zoneOf(config),
|
|
91
|
+
...calendar === void 0 || calendar.holidays.length === 0 && calendar.hemisphere === "north" ? {} : { calendar }
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** What time it is, without letting any pass. */
|
|
95
|
+
function readTime(session, config, turn, wall) {
|
|
96
|
+
return session.transaction(() => timeOf(session, ensure(session, config, turn, wall), config));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The start of a turn. Following the wall clock, the time since the last turn passed outside the story:
|
|
100
|
+
* `away` says how long.
|
|
101
|
+
*/
|
|
102
|
+
function beginTurn(session, config, turn, wall) {
|
|
103
|
+
return session.transaction(() => {
|
|
104
|
+
const state = ensure(session, config, turn, wall);
|
|
105
|
+
if (state.mode === "real" && wall > state.now) {
|
|
106
|
+
session.clock.advance({
|
|
107
|
+
to: wall,
|
|
108
|
+
turn,
|
|
109
|
+
round: 0,
|
|
110
|
+
kind: "real",
|
|
111
|
+
reason: "between turns"
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
time: timeOf(session, {
|
|
115
|
+
mode: "real",
|
|
116
|
+
now: wall
|
|
117
|
+
}, config),
|
|
118
|
+
away: wall - state.now
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
return { time: timeOf(session, state, config) };
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* A round passes. Simulated, it takes what the game master said (or the default), and at least as long as the
|
|
126
|
+
* journey the player's character made (`minimum`); following the wall clock, it takes as long as it took.
|
|
127
|
+
*/
|
|
128
|
+
function endRound(session, config, turn, round, wall, stated, minimum) {
|
|
129
|
+
return session.transaction(() => {
|
|
130
|
+
const state = ensure(session, config, turn, wall);
|
|
131
|
+
if (state.mode === "real") {
|
|
132
|
+
const to = Math.max(state.now, wall);
|
|
133
|
+
session.clock.advance({
|
|
134
|
+
to,
|
|
135
|
+
turn,
|
|
136
|
+
round,
|
|
137
|
+
kind: "real"
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
from: state.now,
|
|
141
|
+
to,
|
|
142
|
+
zone: zoneOf(config)
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
const took = Math.max(stated ?? config.roundSeconds, minimum ?? 0) * SECOND;
|
|
146
|
+
session.clock.advance({
|
|
147
|
+
to: state.now + took,
|
|
148
|
+
turn,
|
|
149
|
+
round,
|
|
150
|
+
kind: "elapsed"
|
|
151
|
+
});
|
|
152
|
+
return {
|
|
153
|
+
from: state.now,
|
|
154
|
+
to: state.now + took,
|
|
155
|
+
zone: zoneOf(config)
|
|
156
|
+
};
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Skip ahead in the story's own time.
|
|
161
|
+
* @throws {ClockError} when time follows the wall clock, the request is not one, or it asks for more than the chat allows.
|
|
162
|
+
*/
|
|
163
|
+
function skipTime(session, config, turn, round, wall, request) {
|
|
164
|
+
return session.transaction(() => {
|
|
165
|
+
const state = ensure(session, config, turn, wall);
|
|
166
|
+
if (state.mode === "real") throw new ClockError("the story's time follows the wall clock, so it cannot be skipped");
|
|
167
|
+
const zone = zoneOf(config);
|
|
168
|
+
const reason = request.reason.trim();
|
|
169
|
+
if (reason === "") throw new ClockError("say what happens in the time that passes (reason)");
|
|
170
|
+
let to;
|
|
171
|
+
if ("byMinutes" in request) {
|
|
172
|
+
if (!Number.isInteger(request.byMinutes) || request.byMinutes < 1) throw new ClockError("by_minutes must be a whole number of minutes, at least 1");
|
|
173
|
+
to = state.now + request.byMinutes * MINUTE;
|
|
174
|
+
} else try {
|
|
175
|
+
to = nextTimeOfDay(state.now, zone, request.untilTime, request.daysLater);
|
|
176
|
+
} catch (error) {
|
|
177
|
+
throw new ClockError(error instanceof RangeError ? error.message : String(error));
|
|
178
|
+
}
|
|
179
|
+
if (to - state.now > config.maxSkipDays * DAY) throw new ClockError(`that is ${Math.round((to - state.now) / DAY)} days from now (${describeInstant(state.now, zone)}), more than the ${config.maxSkipDays} days this chat allows in one skip`);
|
|
180
|
+
session.clock.advance({
|
|
181
|
+
to,
|
|
182
|
+
turn,
|
|
183
|
+
round,
|
|
184
|
+
kind: "skip",
|
|
185
|
+
reason
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
from: state.now,
|
|
189
|
+
to,
|
|
190
|
+
zone,
|
|
191
|
+
reason
|
|
192
|
+
};
|
|
193
|
+
});
|
|
194
|
+
}
|
|
48
195
|
// src/host/sessions/errors.ts
|
|
49
196
|
var WorldNotFoundError = class extends Error {};
|
|
50
197
|
/** The world cannot be played as it is; `problems` say what to fix. */
|
|
@@ -878,153 +1025,6 @@ function parseCharacterAction(value) {
|
|
|
878
1025
|
...told === "" ? {} : { account: told }
|
|
879
1026
|
};
|
|
880
1027
|
}
|
|
881
|
-
// src/host/clock/story-clock.ts
|
|
882
|
-
var ClockError = class extends Error {};
|
|
883
|
-
/** A moment as it is told next to `now`: the clock when it is the same day, the date as well when it is not. */
|
|
884
|
-
function describeWhen(instant, now, zone, language = "en") {
|
|
885
|
-
const a = localTime(instant, zone);
|
|
886
|
-
const b = localTime(now, zone);
|
|
887
|
-
return a.year === b.year && a.month === b.month && a.day === b.day ? clockTime(instant, zone) : describeInstant(instant, zone, language);
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* The time in a sentence: the day and date, the clock, and the part of the day; and, when the world has a calendar, the season and the holidays that
|
|
891
|
-
* fall on the day.
|
|
892
|
-
*/
|
|
893
|
-
function describeTime(time, language = "en") {
|
|
894
|
-
const { calendar } = time;
|
|
895
|
-
const tr = translator(language);
|
|
896
|
-
const base = `${describeInstant(time.now, time.zone, language)} (${tr(dayPart(localTime(time.now, time.zone).minuteOfDay))})`;
|
|
897
|
-
if (calendar === void 0 || calendar.holidays.length === 0 && calendar.hemisphere === "north") return base;
|
|
898
|
-
const day = addLocalDays(time.now, time.zone, 0);
|
|
899
|
-
const holidays = holidaysOn(calendar, day).map((holiday) => holiday.name);
|
|
900
|
-
return `${base}${tr(", ")}${tr(seasonOf(day, calendar.hemisphere))}${holidays.length === 0 ? "" : `${tr("; ")}${tr("today is {holidays}", { holidays: holidays.join(tr(", ")) })}`}`;
|
|
901
|
-
}
|
|
902
|
-
/** The time zone the story is read in. */
|
|
903
|
-
const zoneOf = (config) => config.timeZone === "" ? "UTC" : config.timeZone;
|
|
904
|
-
/** The clock, started when a session has none yet, and detached from the real clock when the settings say so. The mode the story has is the one it keeps otherwise. */
|
|
905
|
-
function ensure(session, config, turn, wall) {
|
|
906
|
-
const current = session.clock.get();
|
|
907
|
-
if (current === void 0) {
|
|
908
|
-
session.clock.start(config.mode, config.mode === "real" ? wall : Math.floor(wall / MINUTE) * MINUTE);
|
|
909
|
-
return session.clock.get() ?? {
|
|
910
|
-
mode: config.mode,
|
|
911
|
-
now: wall
|
|
912
|
-
};
|
|
913
|
-
}
|
|
914
|
-
if (current.mode !== "real" || config.mode !== "simulated") return current;
|
|
915
|
-
session.clock.resync("simulated", Math.max(current.now, wall), turn, "the story's time was detached from the real clock");
|
|
916
|
-
return session.clock.get() ?? current;
|
|
917
|
-
}
|
|
918
|
-
function timeOf(session, state, config) {
|
|
919
|
-
const calendar = session.metadata === void 0 ? void 0 : readCalendar(session.metadata);
|
|
920
|
-
return {
|
|
921
|
-
mode: state.mode,
|
|
922
|
-
now: state.now,
|
|
923
|
-
zone: zoneOf(config),
|
|
924
|
-
...calendar === void 0 || calendar.holidays.length === 0 && calendar.hemisphere === "north" ? {} : { calendar }
|
|
925
|
-
};
|
|
926
|
-
}
|
|
927
|
-
/** What time it is, without letting any pass. */
|
|
928
|
-
function readTime(session, config, turn, wall) {
|
|
929
|
-
return session.transaction(() => timeOf(session, ensure(session, config, turn, wall), config));
|
|
930
|
-
}
|
|
931
|
-
/**
|
|
932
|
-
* The start of a turn. Following the wall clock, the time since the last turn passed outside the story:
|
|
933
|
-
* `away` says how long.
|
|
934
|
-
*/
|
|
935
|
-
function beginTurn(session, config, turn, wall) {
|
|
936
|
-
return session.transaction(() => {
|
|
937
|
-
const state = ensure(session, config, turn, wall);
|
|
938
|
-
if (state.mode === "real" && wall > state.now) {
|
|
939
|
-
session.clock.advance({
|
|
940
|
-
to: wall,
|
|
941
|
-
turn,
|
|
942
|
-
round: 0,
|
|
943
|
-
kind: "real",
|
|
944
|
-
reason: "between turns"
|
|
945
|
-
});
|
|
946
|
-
return {
|
|
947
|
-
time: timeOf(session, {
|
|
948
|
-
mode: "real",
|
|
949
|
-
now: wall
|
|
950
|
-
}, config),
|
|
951
|
-
away: wall - state.now
|
|
952
|
-
};
|
|
953
|
-
}
|
|
954
|
-
return { time: timeOf(session, state, config) };
|
|
955
|
-
});
|
|
956
|
-
}
|
|
957
|
-
/**
|
|
958
|
-
* A round passes. Simulated, it takes what the game master said (or the default), and at least as long as the
|
|
959
|
-
* journey the player's character made (`minimum`); following the wall clock, it takes as long as it took.
|
|
960
|
-
*/
|
|
961
|
-
function endRound(session, config, turn, round, wall, stated, minimum) {
|
|
962
|
-
return session.transaction(() => {
|
|
963
|
-
const state = ensure(session, config, turn, wall);
|
|
964
|
-
if (state.mode === "real") {
|
|
965
|
-
const to = Math.max(state.now, wall);
|
|
966
|
-
session.clock.advance({
|
|
967
|
-
to,
|
|
968
|
-
turn,
|
|
969
|
-
round,
|
|
970
|
-
kind: "real"
|
|
971
|
-
});
|
|
972
|
-
return {
|
|
973
|
-
from: state.now,
|
|
974
|
-
to,
|
|
975
|
-
zone: zoneOf(config)
|
|
976
|
-
};
|
|
977
|
-
}
|
|
978
|
-
const took = Math.max(stated ?? config.roundSeconds, minimum ?? 0) * SECOND;
|
|
979
|
-
session.clock.advance({
|
|
980
|
-
to: state.now + took,
|
|
981
|
-
turn,
|
|
982
|
-
round,
|
|
983
|
-
kind: "elapsed"
|
|
984
|
-
});
|
|
985
|
-
return {
|
|
986
|
-
from: state.now,
|
|
987
|
-
to: state.now + took,
|
|
988
|
-
zone: zoneOf(config)
|
|
989
|
-
};
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Skip ahead in the story's own time.
|
|
994
|
-
* @throws {ClockError} when time follows the wall clock, the request is not one, or it asks for more than the chat allows.
|
|
995
|
-
*/
|
|
996
|
-
function skipTime(session, config, turn, round, wall, request) {
|
|
997
|
-
return session.transaction(() => {
|
|
998
|
-
const state = ensure(session, config, turn, wall);
|
|
999
|
-
if (state.mode === "real") throw new ClockError("the story's time follows the wall clock, so it cannot be skipped");
|
|
1000
|
-
const zone = zoneOf(config);
|
|
1001
|
-
const reason = request.reason.trim();
|
|
1002
|
-
if (reason === "") throw new ClockError("say what happens in the time that passes (reason)");
|
|
1003
|
-
let to;
|
|
1004
|
-
if ("byMinutes" in request) {
|
|
1005
|
-
if (!Number.isInteger(request.byMinutes) || request.byMinutes < 1) throw new ClockError("by_minutes must be a whole number of minutes, at least 1");
|
|
1006
|
-
to = state.now + request.byMinutes * MINUTE;
|
|
1007
|
-
} else try {
|
|
1008
|
-
to = nextTimeOfDay(state.now, zone, request.untilTime, request.daysLater);
|
|
1009
|
-
} catch (error) {
|
|
1010
|
-
throw new ClockError(error instanceof RangeError ? error.message : String(error));
|
|
1011
|
-
}
|
|
1012
|
-
if (to - state.now > config.maxSkipDays * DAY) throw new ClockError(`that is ${Math.round((to - state.now) / DAY)} days from now (${describeInstant(state.now, zone)}), more than the ${config.maxSkipDays} days this chat allows in one skip`);
|
|
1013
|
-
session.clock.advance({
|
|
1014
|
-
to,
|
|
1015
|
-
turn,
|
|
1016
|
-
round,
|
|
1017
|
-
kind: "skip",
|
|
1018
|
-
reason
|
|
1019
|
-
});
|
|
1020
|
-
return {
|
|
1021
|
-
from: state.now,
|
|
1022
|
-
to,
|
|
1023
|
-
zone,
|
|
1024
|
-
reason
|
|
1025
|
-
};
|
|
1026
|
-
});
|
|
1027
|
-
}
|
|
1028
1028
|
// src/host/orchestration/observation.ts
|
|
1029
1029
|
/** 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
1030
|
function observeSurroundings(session, characterId, turn) {
|
|
@@ -2391,7 +2391,7 @@ function characterRunner(deps) {
|
|
|
2391
2391
|
turn: request.turn,
|
|
2392
2392
|
policy: settings.memory,
|
|
2393
2393
|
queryVector: deps.store.queryVector
|
|
2394
|
-
}), request.member.character.id).filter((tool) => toolEnabled(settings.tools, "characters", tool.name)) : [];
|
|
2394
|
+
}), request.member.character.id).filter((tool) => toolEnabled(settings.tools, "characters", tool.name)).map((tool) => notingEmpty(tool, deps.store, request.turn, request.member.character.name)) : [];
|
|
2395
2395
|
const background = (request.knowledge?.lore.length ?? 0) > 0 && tools.some((tool) => tool.name === "recall_my_lore");
|
|
2396
2396
|
const external = externalGiven(deps.parent.ctx.tools, settings.tools, "characters");
|
|
2397
2397
|
const named = request.member.character.tier === "background" && settings.models.background.trim() !== "" ? settings.models.background : settings.models.characters;
|
|
@@ -2413,6 +2413,24 @@ function characterRunner(deps) {
|
|
|
2413
2413
|
}));
|
|
2414
2414
|
};
|
|
2415
2415
|
}
|
|
2416
|
+
/** A look-up that finds nothing is kept in the turn's trace: it is where the world lacks what a character reached for. */
|
|
2417
|
+
function notingEmpty(tool, store, turn, character) {
|
|
2418
|
+
return {
|
|
2419
|
+
...tool,
|
|
2420
|
+
async execute(args, exec) {
|
|
2421
|
+
const found = await tool.execute(args, exec);
|
|
2422
|
+
const about = args.about;
|
|
2423
|
+
if (Array.isArray(found) && found.length === 0 && typeof about === "string" && about.trim() !== "") try {
|
|
2424
|
+
store.recordTrace?.(turn, {}, (current) => ({ missing: [...current.missing ?? [], {
|
|
2425
|
+
character,
|
|
2426
|
+
tool: tool.name,
|
|
2427
|
+
about: about.trim().slice(0, 120)
|
|
2428
|
+
}].slice(-40) }));
|
|
2429
|
+
} catch {}
|
|
2430
|
+
return found;
|
|
2431
|
+
}
|
|
2432
|
+
};
|
|
2433
|
+
}
|
|
2416
2434
|
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";
|
|
2417
2435
|
/** The model decides whether the moment touches its background; asking once at the point of answering is what makes it decide. */
|
|
2418
2436
|
function submitGate(language, background) {
|
|
@@ -3577,6 +3595,7 @@ function installHooks(ctx, deps) {
|
|
|
3577
3595
|
});
|
|
3578
3596
|
ctx.on("session/event", (session, event) => {
|
|
3579
3597
|
if (event.type !== "turn/end" || session.header.origin === "subagent" || roleplaySessionOf(session.id) === void 0) return;
|
|
3598
|
+
ctx.roleplayOrchestration.recovery.clear(session.id);
|
|
3580
3599
|
timelines.ended(session.id, session, event.seq);
|
|
3581
3600
|
const events = session.snapshotEvents();
|
|
3582
3601
|
const began = events.findLastIndex((entry) => entry.type === "turn/start");
|
|
@@ -3610,6 +3629,14 @@ function installHooks(ctx, deps) {
|
|
|
3610
3629
|
}
|
|
3611
3630
|
agent.steer(notice(`You may not end the turn yet: ${missing}.`));
|
|
3612
3631
|
});
|
|
3632
|
+
ctx.on("agent/request-error", async ({ agent, turn, failure }, next) => {
|
|
3633
|
+
const owner = ownerOf(agent, turn);
|
|
3634
|
+
if (owner !== void 0 && ctx.roleplayOrchestration.recovery.retry(owner.chat, turn, failure)) {
|
|
3635
|
+
ctx.logger.warn(`roleplay: ${owner.chat} turn ${turn}: the game master's call could not be read, running the step again`);
|
|
3636
|
+
return { kind: "retry" };
|
|
3637
|
+
}
|
|
3638
|
+
return next();
|
|
3639
|
+
});
|
|
3613
3640
|
ctx.on("agent/pre-step", async (payload, next) => {
|
|
3614
3641
|
const decision = await next();
|
|
3615
3642
|
const owner = ownerOf(payload.agent, payload.turn);
|
|
@@ -3621,7 +3648,7 @@ function installHooks(ctx, deps) {
|
|
|
3621
3648
|
if (decision.kind !== "enter" || payload.step !== 1) return decision;
|
|
3622
3649
|
if (owner === void 0 || store === void 0) return decision;
|
|
3623
3650
|
const text = payload.messages.filter((message) => message.source.kind === "user").flatMap((message) => message.content.flatMap((block) => block.type === "text" ? [block.text] : [])).join("\n");
|
|
3624
|
-
if (!store.settings().background.concurrent) await engine.quiesce(owner.chat);
|
|
3651
|
+
if (!store.settings().background.concurrent) await engine.quiesce(owner.chat, { skipOptional: true });
|
|
3625
3652
|
await ctx.roleplayOrchestration.unitFree(owner.chat);
|
|
3626
3653
|
const began = await timelines.begin(owner.chat, payload.turn, text);
|
|
3627
3654
|
deps.rolls?.begin(owner.chat, store.story.metadata.get().id, began.parent);
|
|
@@ -3761,6 +3788,6 @@ function installHooks(ctx, deps) {
|
|
|
3761
3788
|
};
|
|
3762
3789
|
});
|
|
3763
3790
|
}
|
|
3764
|
-
export {
|
|
3791
|
+
export { listFiles as $, LANGUAGE_NAMES as A, COMMANDS_KEY as B, readNotes as C, PLOTS_METADATA_KEY as D, answerLimits as E, readUsage as F, formatIssue as G, commandsOf as H, PLOTS_FILE_NAME as I, PROMPTS_FOLDER as J, errorMessage as K, loadPlots as L, isStoryLanguage as M, textLanguage as N, plotProgressOf as O, wrongLanguage as P, languageOf as Q, parsePlotsFile as R, notesOfSession as S, RESULTS as T, readDocument as U, commandFlagKey as V, Reader as W, copyWorldPrompts as X, PromptLibrary as Y, inheritPrompts as Z, readTraces as _, externalWithheld as a, InvalidStartError as at, readWithdrawn as b, record as c, SessionArchivedError as ct, guardRepeatedCalls as d, ClockError as dt, promptProblem as et, MAX_OOC_ANSWER as f, describeTime as ft, readRunDetail as g, COMPARISONS as gt, readActivity as h, AUTHORING_NEEDS as ht, externalTools as i, AgentUnavailableError as it, STORY_LANGUAGES as j, populatePlots as k, characterRunner as l, SessionNotFoundError as lt, readDecisionStats as m, zoneOf as mt, installHooks as n, shippedPromptsDirectory as nt, PREVIEW_TOOL as o, InvalidWorldError as ot, storesOf as p, describeWhen as pt, LANGUAGE_FOLDER as q, externalGiven as r, shippedText as rt, createTools$1 as s, ReflectionRefusedError as st, externalToolLimit as t, shippedLanguages as tt, toolEnabled as u, WorldNotFoundError as ut, readVerdicts as v, observeAsPlayer as w, addToNote as x, writeVerdicts as y, plotReferenceProblems as z };
|
|
3765
3792
|
|
|
3766
|
-
//# sourceMappingURL=hooks-
|
|
3793
|
+
//# sourceMappingURL=hooks-BpLN_hhT.js.map
|
package/lib/images.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as tokensOf, i as searchImages, n as interpretImage, o as present, r as imageTools, s as presentedFor, t as runImagePresenter } from "./presenter-agent-
|
|
1
|
+
import { a as tokensOf, i as searchImages, n as interpretImage, o as present, r as imageTools, s as presentedFor, t as runImagePresenter } from "./presenter-agent-UKbKYXMO.js";
|
|
2
2
|
import { i as updateImage, r as listGallery } from "./gallery-CtG-bDzz.js";
|
|
3
3
|
import { c as nextSceneSerial, d as sceneImagePath, l as readImageMetadata, o as entityImageDirectory, s as inheritImages, t as addToLibrary, u as referenceImagePath, v as readPngMetadata, y as withPngMetadata } from "./library-CH-ahlm0.js";
|
|
4
4
|
import { i as transientPrompt, n as generateTransientImage, r as referencePrompt, t as generateReferenceImage } from "./generator-nLoPM5MF.js";
|