@dsh-agentic-roleplay/core 0.3.3 → 0.3.4
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/authoring.js +4 -255
- package/lib/{child-lPncV1ps.js → child-CFjnaTZt.js} +62 -7
- package/lib/client.js +2530 -510
- package/lib/client.js.map +1 -1
- package/lib/{deliver-De62a8i9.js → deliver-CpZOxBX5.js} +47 -10
- package/lib/doctor.js +82 -6
- package/lib/{hooks-Ka22sFNy.js → hooks-KTCR3fNJ.js} +57 -16
- package/lib/images.js +1 -1
- package/lib/index.js +1240 -21
- package/lib/orchestration.js +5 -16
- package/lib/{documents-Do4lz4SB.js → pack-jail-CybSNzxr.js} +464 -27
- package/lib/{presenter-agent-Dt21K96b.js → presenter-agent-CiEVKcjJ.js} +2 -2
- package/lib/{reflection-md7BCYCl.js → reflection-waxFg1x-.js} +3 -3
- package/package.json +2 -2
- package/prompts/en/doctor/procedure.md +1 -1
- package/prompts/en/import/character.md +1 -1
- package/prompts/en/roleplay/record-keeper.md +2 -2
- package/prompts/zh/doctor/procedure.md +1 -1
- package/prompts/zh/import/character.md +1 -1
- package/prompts/zh/roleplay/record-keeper.md +2 -2
|
@@ -2,7 +2,7 @@ import { t as promptFor } from "./access-EbNdZFbk.js";
|
|
|
2
2
|
import "./settings-CA6icLL_.js";
|
|
3
3
|
import { a as wrongLanguage, c as parsePlotsFile, k as SessionNotFoundError } from "./language-DWVwi1R7.js";
|
|
4
4
|
import { n as encodeOutput, r as encodePreview } from "./narration-DK2kiIjE.js";
|
|
5
|
-
import { a as runChild, i as childTrace, n as childSampling,
|
|
5
|
+
import { a as runChild, c as addTokens, i as childTrace, n as childSampling, s as NO_TOKENS, t as childModel, u as estimateAnswer } from "./child-CFjnaTZt.js";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
8
8
|
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
@@ -562,7 +562,7 @@ const NOTE_KINDS = [
|
|
|
562
562
|
];
|
|
563
563
|
//#endregion
|
|
564
564
|
//#region src/host/sessions/notes.ts
|
|
565
|
-
const KEY$
|
|
565
|
+
const KEY$3 = "notes";
|
|
566
566
|
const isNote = (value) => {
|
|
567
567
|
if (typeof value !== "object" || value === null) return false;
|
|
568
568
|
const note = value;
|
|
@@ -570,12 +570,12 @@ const isNote = (value) => {
|
|
|
570
570
|
};
|
|
571
571
|
/** The notes of a session, at most one per kind. */
|
|
572
572
|
function readNotes(session) {
|
|
573
|
-
const stored = session.metadata.getValue(KEY$
|
|
573
|
+
const stored = session.metadata.getValue(KEY$3);
|
|
574
574
|
return Array.isArray(stored) ? stored.filter(isNote) : [];
|
|
575
575
|
}
|
|
576
576
|
/** Replaces the note of the same kind. */
|
|
577
577
|
function putNote(session, note) {
|
|
578
|
-
session.metadata.setValue(KEY$
|
|
578
|
+
session.metadata.setValue(KEY$3, [...readNotes(session).filter((existing) => existing.kind !== note.kind), note]);
|
|
579
579
|
}
|
|
580
580
|
/** The most lines one note keeps: what is past it is not told. */
|
|
581
581
|
const MAX_NOTE_LINES = 8;
|
|
@@ -590,7 +590,7 @@ function addToNote(session, kind, turn, lines) {
|
|
|
590
590
|
}
|
|
591
591
|
/** Removes every note: they belong to the turn that made them. */
|
|
592
592
|
function clearNotes(session) {
|
|
593
|
-
if (readNotes(session).length > 0) session.metadata.setValue(KEY$
|
|
593
|
+
if (readNotes(session).length > 0) session.metadata.setValue(KEY$3, []);
|
|
594
594
|
}
|
|
595
595
|
/**
|
|
596
596
|
* The notes of a session, for the player's screen.
|
|
@@ -1847,7 +1847,7 @@ function externalWithheld(registry, board, agent) {
|
|
|
1847
1847
|
}
|
|
1848
1848
|
//#endregion
|
|
1849
1849
|
//#region src/host/sessions/activity.ts
|
|
1850
|
-
const KEY$
|
|
1850
|
+
const KEY$2 = "activity";
|
|
1851
1851
|
const isEntry = (value) => {
|
|
1852
1852
|
if (typeof value !== "object" || value === null) return false;
|
|
1853
1853
|
const entry = value;
|
|
@@ -1855,13 +1855,13 @@ const isEntry = (value) => {
|
|
|
1855
1855
|
};
|
|
1856
1856
|
/** The recorded runs, oldest first. */
|
|
1857
1857
|
function readActivity(session) {
|
|
1858
|
-
const stored = session.metadata.getValue(KEY$
|
|
1858
|
+
const stored = session.metadata.getValue(KEY$2);
|
|
1859
1859
|
return Array.isArray(stored) ? stored.filter(isEntry) : [];
|
|
1860
1860
|
}
|
|
1861
1861
|
/** Files the run and returns the runs that fell off the end of the record to make room. */
|
|
1862
1862
|
function recordActivity(session, entry) {
|
|
1863
1863
|
const all = [...readActivity(session), entry];
|
|
1864
|
-
session.metadata.setValue(KEY$
|
|
1864
|
+
session.metadata.setValue(KEY$2, all.slice(-60));
|
|
1865
1865
|
return all.slice(0, -60);
|
|
1866
1866
|
}
|
|
1867
1867
|
const RUN_FOLDER = "activity";
|
|
@@ -1890,6 +1890,43 @@ function forgetRunDetails(folder, dropped) {
|
|
|
1890
1890
|
for (const entry of dropped) if (entry.run !== void 0) rmSync(runFile(folder, entry.run), { force: true });
|
|
1891
1891
|
}
|
|
1892
1892
|
//#endregion
|
|
1893
|
+
//#region src/host/sessions/usage.ts
|
|
1894
|
+
const KEY$1 = "usage";
|
|
1895
|
+
const isCount = (value) => typeof value === "object" && value !== null && [
|
|
1896
|
+
"input",
|
|
1897
|
+
"cached",
|
|
1898
|
+
"output"
|
|
1899
|
+
].every((field) => typeof value[field] === "number");
|
|
1900
|
+
const isUsage = (value) => typeof value === "object" && value !== null && typeof value.turn === "number" && typeof value.runs === "number" && isCount(value.master) && isCount(value.helpers);
|
|
1901
|
+
/** What each turn used, oldest first. The record belongs to the story's state, so taking the story back takes the turns that no longer count with it. */
|
|
1902
|
+
function readUsage(session) {
|
|
1903
|
+
const stored = session.metadata.getValue(KEY$1);
|
|
1904
|
+
return Array.isArray(stored) ? stored.filter(isUsage) : [];
|
|
1905
|
+
}
|
|
1906
|
+
/** Adds tokens to a turn's record: the game master's own, or a helper's run. */
|
|
1907
|
+
function addUsage(session, turn, who, tokens) {
|
|
1908
|
+
const all = readUsage(session);
|
|
1909
|
+
const at = all.findIndex((entry) => entry.turn === turn);
|
|
1910
|
+
const entry = at === -1 ? {
|
|
1911
|
+
turn,
|
|
1912
|
+
master: NO_TOKENS,
|
|
1913
|
+
helpers: NO_TOKENS,
|
|
1914
|
+
runs: 0
|
|
1915
|
+
} : all[at];
|
|
1916
|
+
const next = who === "master" ? {
|
|
1917
|
+
...entry,
|
|
1918
|
+
master: addTokens(entry.master, tokens)
|
|
1919
|
+
} : {
|
|
1920
|
+
...entry,
|
|
1921
|
+
helpers: addTokens(entry.helpers, tokens),
|
|
1922
|
+
runs: entry.runs + 1
|
|
1923
|
+
};
|
|
1924
|
+
if (at === -1) all.push(next);
|
|
1925
|
+
else all[at] = next;
|
|
1926
|
+
all.sort((a, b) => a.turn - b.turn);
|
|
1927
|
+
session.metadata.setValue(KEY$1, all);
|
|
1928
|
+
}
|
|
1929
|
+
//#endregion
|
|
1893
1930
|
//#region src/host/triggers/deliver.ts
|
|
1894
1931
|
const KEY = "triggers.withdrawn";
|
|
1895
1932
|
/** Why a note was withdrawn instead of told, by the number of the note. */
|
|
@@ -1924,6 +1961,6 @@ function deliverNow(session, notes, clock) {
|
|
|
1924
1961
|
}));
|
|
1925
1962
|
}
|
|
1926
1963
|
//#endregion
|
|
1927
|
-
export {
|
|
1964
|
+
export { observeAsPlayer as A, RESULTS as B, parseOoc as C, notesOfSession as D, clearNotes as E, describeWhen as F, languageOf as H, endRound as I, readTime as L, ClockError as M, beginTurn as N, putNote as O, describeTime as P, skipTime as R, MAX_OOC_ANSWER as S, addToNote as T, translator as U, answerLimits as V, pacingAdvice as _, forgetRunDetails as a, populatePlots as b, readRunDetail as c, externalTools as d, externalWithheld as f, describePacingAdvice as g, PLOTS_METADATA_KEY as h, readUsage as i, observeSurroundings as j, readNotes as k, recordActivity as l, createTools$1 as m, readWithdrawn as n, keepRunDetail as o, PREVIEW_TOOL as p, addUsage as r, readActivity as s, deliverNow as t, externalGiven as u, plotAuthorNeeded as v, toolEnabled as w, AUTHORING_NEEDS as x, plotProgressOf as y, zoneOf as z };
|
|
1928
1965
|
|
|
1929
|
-
//# sourceMappingURL=deliver-
|
|
1966
|
+
//# sourceMappingURL=deliver-CpZOxBX5.js.map
|
package/lib/doctor.js
CHANGED
|
@@ -1,25 +1,68 @@
|
|
|
1
|
+
import { n as chatSessionId } from "./access-EbNdZFbk.js";
|
|
1
2
|
import "./language-DWVwi1R7.js";
|
|
2
|
-
import {
|
|
3
|
+
import { d as externalTools } from "./deliver-CpZOxBX5.js";
|
|
3
4
|
import { a as liveSettings } from "./narration-DK2kiIjE.js";
|
|
4
5
|
import { n as doctorSessionOf } from "./doctor-chat-ByDfCMeo.js";
|
|
5
|
-
import { t as externalToolLimit } from "./hooks-
|
|
6
|
+
import { t as externalToolLimit } from "./hooks-KTCR3fNJ.js";
|
|
6
7
|
import { join } from "node:path";
|
|
7
8
|
import { existsSync } from "node:fs";
|
|
9
|
+
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
10
|
+
import { defineTool } from "@deepseek-ai/dsh-tools";
|
|
8
11
|
import { createTools, isSessionId, sessionDatabase, sessionFolder } from "@dsh-agentic-roleplay/state";
|
|
12
|
+
//#region src/host/agent/doctor-undo.ts
|
|
13
|
+
const UNDO_SNAPSHOT = "doctor-undo";
|
|
14
|
+
const UNDO_KEY = "doctor.undo";
|
|
15
|
+
var UndoRefusedError = class extends Error {};
|
|
16
|
+
/** Keeps the story as it stands, to put back after the one approved edit that is about to be applied. */
|
|
17
|
+
function keepBeforeEdit(deps, id) {
|
|
18
|
+
const dir = deps.sessionsDir();
|
|
19
|
+
deps.state.snapshot(dir, id, UNDO_SNAPSHOT);
|
|
20
|
+
const { metadata } = deps.state.openSession(dir, id);
|
|
21
|
+
metadata.setValue(UNDO_KEY, { turns: metadata.get().turns });
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Puts the story back as it was before the last edit the doctor applied. The story is not taken back across a turn: what a later turn recorded
|
|
25
|
+
* and the conversation it went with would no longer match.
|
|
26
|
+
* @throws {UndoRefusedError} when nothing was kept, a turn was played or is playing since, or the edit was undone already.
|
|
27
|
+
*/
|
|
28
|
+
async function undoLastEdit(deps, id) {
|
|
29
|
+
const dir = deps.sessionsDir();
|
|
30
|
+
const session = deps.state.openSession(dir, id);
|
|
31
|
+
const kept = session.metadata.getValue(UNDO_KEY);
|
|
32
|
+
if (kept === void 0 || !deps.state.snapshots(dir, id).includes("doctor-undo")) throw new UndoRefusedError("there is no edit of mine to undo: nothing was kept, or it was undone already");
|
|
33
|
+
if (deps.busy(id)) throw new UndoRefusedError("a turn is being played: undo after it has been delivered, and only if no turn is played after it");
|
|
34
|
+
if (session.metadata.get().turns !== kept.turns) throw new UndoRefusedError("a turn was played after the edit, so the story cannot be put back without losing it: mend what is wrong with a new edit instead");
|
|
35
|
+
await deps.halt(id);
|
|
36
|
+
deps.state.restore(dir, id, UNDO_SNAPSHOT);
|
|
37
|
+
deps.state.removeSnapshot(dir, id, UNDO_SNAPSHOT);
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
9
40
|
//#region src/doctor.ts
|
|
10
41
|
const name = "@dsh-agentic-roleplay/core/doctor";
|
|
11
42
|
const inject = [
|
|
12
43
|
"roleplayState",
|
|
13
44
|
"roleplayRoot",
|
|
14
45
|
"roleplayPrompts",
|
|
46
|
+
"roleplayOrchestration",
|
|
15
47
|
"tools",
|
|
16
|
-
"systemPrompt"
|
|
48
|
+
"systemPrompt",
|
|
49
|
+
"agents"
|
|
17
50
|
];
|
|
18
51
|
const DOCTOR_TOOL = "edit_records";
|
|
52
|
+
const UNDO_TOOL = "undo_last_edit";
|
|
19
53
|
const SHOWN_EDIT = 700;
|
|
20
54
|
/** What the person is asked to approve: the edit, as it will be applied. */
|
|
21
55
|
function doctorApproval(exec) {
|
|
22
|
-
if (exec.
|
|
56
|
+
if (exec.agent === void 0 || doctorSessionOf(exec.agent.session.id) === void 0) return void 0;
|
|
57
|
+
if (exec.name === UNDO_TOOL) return {
|
|
58
|
+
kind: "ask",
|
|
59
|
+
reason: "put the story back as it was before my last edit",
|
|
60
|
+
displayReason: {
|
|
61
|
+
en: "Put the story back as it was before the last edit?",
|
|
62
|
+
zh: "把故事恢复到上一次修改之前?"
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
if (exec.name !== DOCTOR_TOOL) return void 0;
|
|
23
66
|
const { turn: _turn, ...edit } = exec.arguments;
|
|
24
67
|
if (Object.keys(edit).length === 0) return {
|
|
25
68
|
kind: "deny",
|
|
@@ -51,7 +94,17 @@ function apply(ctx) {
|
|
|
51
94
|
};
|
|
52
95
|
};
|
|
53
96
|
ctx.effect(() => ctx.roleplayState.bind(resolve), "roleplay: session doctor reads");
|
|
54
|
-
|
|
97
|
+
const undo = {
|
|
98
|
+
state: ctx.roleplayState,
|
|
99
|
+
sessionsDir,
|
|
100
|
+
busy: (id) => {
|
|
101
|
+
const agent = ctx.agents.get(SessionId(chatSessionId(id)));
|
|
102
|
+
return agent !== void 0 && agent.status !== "idle";
|
|
103
|
+
},
|
|
104
|
+
halt: (id) => ctx.roleplayOrchestration.halt(chatSessionId(id))
|
|
105
|
+
};
|
|
106
|
+
for (const tool of createTools(resolve, { write: true }).filter((candidate) => candidate.name === DOCTOR_TOOL)) ctx.tools.register(inTurn(tool, resolve, (id) => keepBeforeEdit(undo, id)));
|
|
107
|
+
ctx.tools.register(undoTool(undo));
|
|
55
108
|
ctx.on("tools/pre-execute", async (exec, next) => doctorApproval(exec) ?? await next());
|
|
56
109
|
ctx.on("agent/created", ({ agent }) => {
|
|
57
110
|
if (doctorSessionOf(agent.session.id) !== void 0 && agent.session.header.origin !== "subagent") externalToolLimit(agent, externalTools(agent.ctx.tools).map((tool) => tool.name));
|
|
@@ -77,11 +130,13 @@ function apply(ctx) {
|
|
|
77
130
|
});
|
|
78
131
|
}
|
|
79
132
|
/** The edit is written at the turn the story is at (the first, in a story with none played), whatever turn the model put in it. */
|
|
80
|
-
function inTurn(tool, resolve) {
|
|
133
|
+
function inTurn(tool, resolve, keep) {
|
|
81
134
|
return {
|
|
82
135
|
...tool,
|
|
83
136
|
async execute(args, exec) {
|
|
84
137
|
const link = exec.agent === void 0 ? void 0 : resolve(exec.agent.session.id);
|
|
138
|
+
const story = exec.agent === void 0 ? void 0 : doctorSessionOf(exec.agent.session.id);
|
|
139
|
+
if (story !== void 0) keep(story);
|
|
85
140
|
return await tool.execute(link === void 0 ? args : {
|
|
86
141
|
...args,
|
|
87
142
|
turn: Math.max(1, link.turn)
|
|
@@ -89,6 +144,27 @@ function inTurn(tool, resolve) {
|
|
|
89
144
|
}
|
|
90
145
|
};
|
|
91
146
|
}
|
|
147
|
+
function undoTool(deps) {
|
|
148
|
+
return defineTool({
|
|
149
|
+
name: UNDO_TOOL,
|
|
150
|
+
description: "Put the story back as it was before the last edit you applied, when that edit turned out wrong. Only possible while no turn has been played since, and only once: the player is asked first.",
|
|
151
|
+
parameters: {},
|
|
152
|
+
output: {
|
|
153
|
+
schema: { type: "json" },
|
|
154
|
+
render: (_args, value) => [{
|
|
155
|
+
type: "text",
|
|
156
|
+
text: value.text
|
|
157
|
+
}]
|
|
158
|
+
},
|
|
159
|
+
isConcurrencySafe: () => false,
|
|
160
|
+
async execute(_args, exec) {
|
|
161
|
+
const story = exec.agent === void 0 ? void 0 : doctorSessionOf(exec.agent.session.id);
|
|
162
|
+
if (story === void 0) throw new Error("this tool is for a session doctor chat");
|
|
163
|
+
await undoLastEdit(deps, story);
|
|
164
|
+
return { text: "The story is as it was before the last edit. Read the records again before saying what stands." };
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
}
|
|
92
168
|
//#endregion
|
|
93
169
|
export { apply, doctorApproval, inject, name };
|
|
94
170
|
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { r as roleplaySessionOf } from "./access-EbNdZFbk.js";
|
|
2
2
|
import { a as WORLD_RULES_KEY, o as rulesOf } from "./settings-CA6icLL_.js";
|
|
3
3
|
import { C as shippedText } from "./language-DWVwi1R7.js";
|
|
4
|
-
import {
|
|
4
|
+
import { A as observeAsPlayer, C as parseOoc, E as clearNotes, F as describeWhen, H as languageOf, I as endRound, L as readTime, N as beginTurn, O as putNote, R as skipTime, T as addToNote, U as translator, _ as pacingAdvice, a as forgetRunDetails, f as externalWithheld, g as describePacingAdvice, j as observeSurroundings, k as readNotes, l as recordActivity, o as keepRunDetail, r as addUsage, t as deliverNow, v as plotAuthorNeeded, w as toolEnabled, z as zoneOf } from "./deliver-CpZOxBX5.js";
|
|
5
5
|
import { a as liveSettings } from "./narration-DK2kiIjE.js";
|
|
6
|
+
import { o as tokensOf } from "./child-CFjnaTZt.js";
|
|
6
7
|
import { createUserMessage } from "@deepseek-ai/dsh-llm";
|
|
7
8
|
import { ENGAGEMENT_GRACE, MINUTE, agendaAt, announcements, applyItemPlan, changeItem, changeVariable, describeDuration, describeInstant, describeValue, inAudience, itemKey, locationKey, nextOccurrence, occurrenceAt, parseInstant, planItemChange, planVariableChange, rollPlain, sessionFolder, shownVariables } from "@dsh-agentic-roleplay/state";
|
|
8
9
|
//#region src/host/triggers/judged.ts
|
|
@@ -138,6 +139,8 @@ function noteStore(session, settings, clock) {
|
|
|
138
139
|
//#region src/host/clock/agenda.ts
|
|
139
140
|
const CURSOR = "agenda.cursor";
|
|
140
141
|
const ASKED = "agenda.asked";
|
|
142
|
+
/** Characters on their way to the place their day has them at, by character id: they get there when the way has taken as long as it takes. */
|
|
143
|
+
const TRAVEL = "agenda.travel";
|
|
141
144
|
/** At most this many characters are asked to be given a day at a time, so that it never floods the world author. */
|
|
142
145
|
const MAX_ASKED = 3;
|
|
143
146
|
/** How far ahead the characters are told about what comes next in their day. */
|
|
@@ -159,6 +162,25 @@ function catchUpRoutines(session, zone, now, turn, ask) {
|
|
|
159
162
|
const player = session.characters.list().find((character) => character.control === "player");
|
|
160
163
|
const playerPlace = player === void 0 ? void 0 : session.placements.get("character", player.id)?.locationId;
|
|
161
164
|
const moves = [];
|
|
165
|
+
const stored = session.metadata.getValue(TRAVEL);
|
|
166
|
+
const journeys = typeof stored === "object" && stored !== null && !Array.isArray(stored) ? { ...stored } : {};
|
|
167
|
+
const arrive = (character, target) => {
|
|
168
|
+
if (target.locationId !== void 0) {
|
|
169
|
+
session.move(character.id, {
|
|
170
|
+
to: target.locationId,
|
|
171
|
+
ignoreExits: true,
|
|
172
|
+
...target.position === void 0 ? {} : { position: target.position },
|
|
173
|
+
...target.featureKey === void 0 ? {} : { featureKey: target.featureKey }
|
|
174
|
+
});
|
|
175
|
+
moves.push({
|
|
176
|
+
character: keyOfCharacter$1(character),
|
|
177
|
+
name: character.name,
|
|
178
|
+
to: session.locations.get(target.locationId)?.name ?? String(target.locationId),
|
|
179
|
+
activity: target.activity
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
if (session.characterStates.get(character.id)?.activity !== target.activity) session.characterStates.update(character.id, { activity: target.activity });
|
|
183
|
+
};
|
|
162
184
|
const alreadyAsked = new Set(Array.isArray(session.metadata.getValue(ASKED)) ? session.metadata.getValue(ASKED) : []);
|
|
163
185
|
const asked = [];
|
|
164
186
|
for (const character of session.characters.list()) {
|
|
@@ -181,27 +203,38 @@ function catchUpRoutines(session, zone, now, turn, ask) {
|
|
|
181
203
|
}
|
|
182
204
|
if (!away) continue;
|
|
183
205
|
const current = occurrenceAt(window, now, zone);
|
|
206
|
+
const journey = journeys[characterId];
|
|
207
|
+
if (journey !== void 0) {
|
|
208
|
+
const same = current !== void 0 && current.window.id === journey.windowId && current.startsAt === journey.startsAt;
|
|
209
|
+
if (same && now < journey.arriveAt) continue;
|
|
210
|
+
delete journeys[characterId];
|
|
211
|
+
if (same) {
|
|
212
|
+
arrive(character, current.window);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
184
216
|
if (current === void 0) continue;
|
|
185
217
|
const before = cursor === void 0 ? void 0 : occurrenceAt(window, cursor, zone);
|
|
186
218
|
if (before !== void 0 && before.window.id === current.window.id && before.startsAt === current.startsAt) continue;
|
|
187
219
|
const target = current.window;
|
|
188
220
|
if (target.locationId !== void 0 && (here?.locationId !== target.locationId || target.position !== void 0 && here.position !== target.position)) {
|
|
189
|
-
session.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
name
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (session.characterStates.get(characterId)?.activity !== target.activity) session.characterStates.update(characterId, { activity: target.activity });
|
|
221
|
+
const way = here?.locationId === target.locationId ? void 0 : session.planMove(characterId, { to: target.locationId });
|
|
222
|
+
const seconds = way?.ok === true ? way.plan.travelSeconds : void 0;
|
|
223
|
+
if (seconds !== void 0 && current.startsAt + seconds * 1e3 > now) {
|
|
224
|
+
journeys[characterId] = {
|
|
225
|
+
windowId: target.id,
|
|
226
|
+
startsAt: current.startsAt,
|
|
227
|
+
arriveAt: current.startsAt + seconds * 1e3
|
|
228
|
+
};
|
|
229
|
+
const text = `on the way to ${session.locations.get(target.locationId)?.name ?? String(target.locationId)}, for "${target.activity}"`;
|
|
230
|
+
if (session.characterStates.get(characterId)?.activity !== text) session.characterStates.update(characterId, { activity: text });
|
|
231
|
+
continue;
|
|
232
|
+
}
|
|
233
|
+
arrive(character, target);
|
|
234
|
+
} else if (session.characterStates.get(characterId)?.activity !== target.activity) session.characterStates.update(characterId, { activity: target.activity });
|
|
203
235
|
}
|
|
204
236
|
session.metadata.setValue(CURSOR, now);
|
|
237
|
+
session.metadata.setValue(TRAVEL, journeys);
|
|
205
238
|
if (asked.length > 0) session.metadata.setValue(ASKED, [...alreadyAsked, ...asked]);
|
|
206
239
|
return moves;
|
|
207
240
|
});
|
|
@@ -737,6 +770,10 @@ function storeOf(session, folder, problem, queryVector, wall, prompt) {
|
|
|
737
770
|
recordActivity: (entry, detail) => {
|
|
738
771
|
if (detail !== void 0 && entry.run !== void 0) keepRunDetail(folder, entry.run, detail);
|
|
739
772
|
forgetRunDetails(folder, recordActivity(session, entry));
|
|
773
|
+
if (entry.turn !== void 0 && entry.tokens !== void 0) addUsage(session, entry.turn, "helper", entry.tokens);
|
|
774
|
+
},
|
|
775
|
+
recordUsage: (turn, tokens) => {
|
|
776
|
+
addUsage(session, turn, "master", tokens);
|
|
740
777
|
},
|
|
741
778
|
notes: () => readNotes(session),
|
|
742
779
|
clearNotes: () => {
|
|
@@ -893,6 +930,10 @@ function installHooks(ctx, deps) {
|
|
|
893
930
|
ctx.on("session/event", (session, event) => {
|
|
894
931
|
if (event.type !== "turn/end" || session.header.origin === "subagent" || roleplaySessionOf(session.id) === void 0) return;
|
|
895
932
|
timelines.ended(session.id, session, event.seq);
|
|
933
|
+
const events = session.snapshotEvents();
|
|
934
|
+
const began = events.findLastIndex((entry) => entry.type === "turn/start");
|
|
935
|
+
const start = began === -1 ? void 0 : events[began];
|
|
936
|
+
if (start?.type === "turn/start") stores(session.id)?.recordUsage?.(start.data.turn, tokensOf(events.slice(began)));
|
|
896
937
|
});
|
|
897
938
|
ctx.on("agent/created", async ({ agent }) => {
|
|
898
939
|
const { header } = agent.session;
|
|
@@ -1016,4 +1057,4 @@ function installHooks(ctx, deps) {
|
|
|
1016
1057
|
//#endregion
|
|
1017
1058
|
export { writeVerdicts as a, readVerdicts as i, installHooks as n, storesOf as r, externalToolLimit as t };
|
|
1018
1059
|
|
|
1019
|
-
//# sourceMappingURL=hooks-
|
|
1060
|
+
//# sourceMappingURL=hooks-KTCR3fNJ.js.map
|
package/lib/images.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { b as readPngMetadata, d as nextSceneSerial, f as readImageMetadata, i as transientPrompt, l as entityImageDirectory, m as sceneImagePath, n as generateTransientImage, o as addToLibrary, p as referenceImagePath, r as referencePrompt, t as generateReferenceImage, u as inheritImages, x as withPngMetadata } from "./generator-B6FxlKOV.js";
|
|
2
2
|
import { i as updateImage, r as listGallery } from "./gallery-CtFDL22W.js";
|
|
3
|
-
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-
|
|
3
|
+
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-CiEVKcjJ.js";
|
|
4
4
|
export { addToLibrary, entityImageDirectory, generateReferenceImage, generateTransientImage, imageTools, inheritImages, interpretImage, listGallery, nextSceneSerial, present, presentedFor, readImageMetadata, readPngMetadata, referenceImagePath, referencePrompt, runImagePresenter, sceneImagePath, searchImages, tokensOf, transientPrompt, updateImage, withPngMetadata };
|