@dsh-agentic-roleplay/core 0.2.1 → 0.3.0
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/{chat-AKrVcWIC.js → access-EbNdZFbk.js} +10 -2
- package/lib/authoring.js +178 -7
- package/lib/client.js +2353 -1390
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +2 -3
- package/lib/{activity-t7OBgHlc.js → deliver--uMhC6oO.js} +505 -13
- package/lib/{documents-Bu5uYRZB.js → documents-7GMc5NnW.js} +107 -4
- package/lib/images.js +1 -1
- package/lib/index.js +243 -17
- package/lib/{narration-BRyHU0H2.js → narration-CKZTk5UE.js} +10 -1
- package/lib/orchestration.js +99 -75
- package/lib/{packs-ByP1J-zj.js → packs-alJTiDM2.js} +4 -2
- package/lib/{presenter-agent-G43ODV8I.js → presenter-agent-PX1WVaJB.js} +2 -2
- package/package.json +3 -2
- package/packs/scene/map.html +12 -0
- package/packs/scene/map.js +55 -0
- package/packs/scene/pack.json +11 -0
- package/packs/scene/strip.html +11 -0
- package/packs/scene/strip.js +26 -0
- package/packs/scene/style.css +16 -0
- package/prompts/en/roleplay/reflection.md +9 -0
- package/prompts/en/world/procedure.md +1 -1
- package/prompts/en/world/welcome.md +1 -1
- package/prompts/zh/roleplay/reflection.md +9 -0
- package/prompts/zh/world/procedure.md +1 -1
- package/prompts/zh/world/welcome.md +1 -1
- package/lib/access-C1nFQiyT.js +0 -12
package/lib/orchestration.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { n as roleplaySessionOf, t as
|
|
2
|
-
import { F as shippedText,
|
|
3
|
-
import {
|
|
1
|
+
import { n as chatSessionId, r as roleplaySessionOf, t as promptFor } from "./access-EbNdZFbk.js";
|
|
2
|
+
import { F as shippedText, W as INTENT_STATUSES, _ as API_PREFIX, b as parsePlotsFile, z as ReflectionRefusedError } from "./packs-alJTiDM2.js";
|
|
3
|
+
import { B as skipTime, D as observeSurroundings, E as observeAsPlayer, F as beginTurn, G as RESULTS, H as referent, I as describeTime, K as answerEstimate, L as describeWhen, N as sameWords, P as ClockError, R as endRound, S as clearNotes, T as readNotes, U as AWAY_ACTION_SCHEMA, V as zoneOf, W as CHARACTER_ACTION_SCHEMA, _ as plotAuthorNeeded, b as updatePlotProgress, c as dueReflection, f as whereabouts, g as pacingAdvice, h as describePacingAdvice, i as keepRunDetail, k as Timelines, l as memoryReflector, m as addSessionPlot, q as parseCharacterAction, r as forgetRunDetails, s as recordActivity, t as deliverNow, u as recordFailure, w as putNote, x as addToNote, z as readTime } from "./deliver--uMhC6oO.js";
|
|
4
|
+
import { a as liveSettings, f as WORLD_RULES_KEY, n as encodeOutput, p as rulesOf, r as encodePreview } from "./narration-CKZTk5UE.js";
|
|
4
5
|
import "./src-CWTNeL6Y.js";
|
|
5
6
|
import { A as runChild, D as childSampling, E as childModel, T as uniqueKey, j as estimateAnswer, k as childTrace, o as addToLibrary, w as slug } from "./generator-HPifO3Kk.js";
|
|
6
|
-
import { A as readTime, D as describeTime, E as beginTurn, F as CHARACTER_ACTION_SCHEMA, I as RESULTS, L as answerEstimate, M as zoneOf, N as referent, O as describeWhen, P as AWAY_ACTION_SCHEMA, R as parseCharacterAction, T as ClockError, _ as putNote, a as recordActivity, b as Timelines, c as describePacingAdvice, h as clearNotes, j as skipTime, k as endRound, l as pacingAdvice, m as addToNote, n as keepRunDetail, p as updatePlotProgress, s as addSessionPlot, t as forgetRunDetails, u as plotAuthorNeeded, v as readNotes, w as sameWords } from "./activity-t7OBgHlc.js";
|
|
7
7
|
import { i as updateImage, r as listGallery, t as describeGalleryImage } from "./gallery-DUeBMHQX.js";
|
|
8
|
-
import { t as
|
|
9
|
-
import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-G43ODV8I.js";
|
|
8
|
+
import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-PX1WVaJB.js";
|
|
10
9
|
import { join } from "node:path";
|
|
11
10
|
import { existsSync } from "node:fs";
|
|
12
11
|
import { SessionId } from "@deepseek-ai/dsh-session";
|
|
@@ -913,20 +912,23 @@ function fireTriggers(session, input) {
|
|
|
913
912
|
for (const failure of run.failed) problem(`the trigger "${failure.trigger.key}" could not fire and is given up: ${failure.problem}`);
|
|
914
913
|
const names = new Map(session.characters.list().map((character) => [character.id, character.name]));
|
|
915
914
|
const fresh = session.triggers.notes({ status: "pending" }).filter((note) => note.id > before);
|
|
915
|
+
const told = new Map(deliverNow(session, fresh, {
|
|
916
|
+
now,
|
|
917
|
+
zone
|
|
918
|
+
}).map((entry) => [entry.id, entry.text]));
|
|
916
919
|
return { fired: run.fired.map((fired) => ({
|
|
917
920
|
name: fired.trigger.name,
|
|
918
921
|
events: fired.events,
|
|
919
|
-
cues: fresh.filter((note) => note.triggerId === fired.trigger.id && note.kind === "cue").map((note) => ({
|
|
922
|
+
cues: fresh.filter((note) => note.triggerId === fired.trigger.id && note.kind === "cue" && told.has(note.id)).map((note) => ({
|
|
920
923
|
names: note.characterIds.flatMap((id) => names.get(id) ?? []),
|
|
921
|
-
text: note.
|
|
924
|
+
text: told.get(note.id)
|
|
922
925
|
})),
|
|
923
|
-
beats: fresh.filter((note) => note.triggerId === fired.trigger.id && note.kind === "beat").map((note) => ({
|
|
926
|
+
beats: fresh.filter((note) => note.triggerId === fired.trigger.id && note.kind === "beat" && told.has(note.id)).map((note) => ({
|
|
924
927
|
id: note.id,
|
|
925
|
-
text: note.
|
|
928
|
+
text: told.get(note.id)
|
|
926
929
|
}))
|
|
927
930
|
})) };
|
|
928
931
|
}
|
|
929
|
-
/** The beats still to weave in, the cues of a character, and what is done with them. */
|
|
930
932
|
/** When something is to happen, as it is told: the date and how far off it is. */
|
|
931
933
|
function whenText(at, clock) {
|
|
932
934
|
if (at === void 0) return void 0;
|
|
@@ -940,6 +942,7 @@ function whoKnows(session, announcement) {
|
|
|
940
942
|
}
|
|
941
943
|
/** At most this many announcements are told to one character at once: soonest first. */
|
|
942
944
|
const MAX_UPCOMING_FOR_CHARACTER = 3;
|
|
945
|
+
/** The beats still to weave in, the cues of a character, and what is done with them. Each is written from the story as it stands when it is told, and one that no longer applies is withdrawn. */
|
|
943
946
|
function noteStore(session, settings, clock) {
|
|
944
947
|
return {
|
|
945
948
|
upcoming: (turn) => {
|
|
@@ -963,13 +966,10 @@ function noteStore(session, settings, clock) {
|
|
|
963
966
|
};
|
|
964
967
|
});
|
|
965
968
|
},
|
|
966
|
-
pendingBeats: () => session.triggers.notes({
|
|
969
|
+
pendingBeats: () => deliverNow(session, session.triggers.notes({
|
|
967
970
|
status: "pending",
|
|
968
971
|
kind: "beat"
|
|
969
|
-
}).
|
|
970
|
-
id: note.id,
|
|
971
|
-
text: note.text
|
|
972
|
-
})),
|
|
972
|
+
}), clock(session.metadata.get().turns + 1)),
|
|
973
973
|
resolveBeats: (ids) => {
|
|
974
974
|
const pending = new Set(session.triggers.notes({
|
|
975
975
|
status: "pending",
|
|
@@ -981,13 +981,10 @@ function noteStore(session, settings, clock) {
|
|
|
981
981
|
for (const id of ids) session.triggers.resolveNote(id, "done");
|
|
982
982
|
});
|
|
983
983
|
},
|
|
984
|
-
cuesFor: (characterId) => session.triggers.notes({
|
|
984
|
+
cuesFor: (characterId) => deliverNow(session, session.triggers.notes({
|
|
985
985
|
status: "pending",
|
|
986
986
|
kind: "cue"
|
|
987
|
-
}).filter((note) => note.characterIds.includes(characterId)).
|
|
988
|
-
id: note.id,
|
|
989
|
-
text: note.text
|
|
990
|
-
})),
|
|
987
|
+
}).filter((note) => note.characterIds.includes(characterId)), clock(session.metadata.get().turns + 1)),
|
|
991
988
|
doneCues: (ids) => {
|
|
992
989
|
session.transaction(() => {
|
|
993
990
|
for (const id of ids) session.triggers.resolveNote(id, "done");
|
|
@@ -1003,35 +1000,6 @@ function noteStore(session, settings, clock) {
|
|
|
1003
1000
|
};
|
|
1004
1001
|
}
|
|
1005
1002
|
//#endregion
|
|
1006
|
-
//#region src/host/orchestration/observation.ts
|
|
1007
|
-
/** 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. */
|
|
1008
|
-
function observeSurroundings(session, characterId, turn) {
|
|
1009
|
-
const placement = session.placements.get("character", characterId);
|
|
1010
|
-
if (placement !== void 0) {
|
|
1011
|
-
session.knowledge.learn(characterId, "location", placement.locationId, turn, true);
|
|
1012
|
-
for (const exit of session.locations.exitsFrom(placement.locationId)) {
|
|
1013
|
-
session.knowledge.learn(characterId, "exit", exit.id, turn, true);
|
|
1014
|
-
session.knowledge.learn(characterId, "location", exit.toId, turn);
|
|
1015
|
-
}
|
|
1016
|
-
for (const { item } of session.items.contents({
|
|
1017
|
-
kind: "location",
|
|
1018
|
-
id: placement.locationId
|
|
1019
|
-
})) if (!item.hidden) session.knowledge.learn(characterId, "item", item.id, turn, true);
|
|
1020
|
-
}
|
|
1021
|
-
for (const { item } of session.items.contents({
|
|
1022
|
-
kind: "character",
|
|
1023
|
-
id: characterId
|
|
1024
|
-
})) session.knowledge.learn(characterId, "item", item.id, turn, true);
|
|
1025
|
-
}
|
|
1026
|
-
/**
|
|
1027
|
-
* The player's character is never asked to act, so nothing else shows it its surroundings: it takes them in when a turn begins, which is
|
|
1028
|
-
* how it comes to know the way back from where it went.
|
|
1029
|
-
*/
|
|
1030
|
-
function observeAsPlayer(session, turn) {
|
|
1031
|
-
const player = session.characters.list().find((character) => character.control === "player");
|
|
1032
|
-
if (player !== void 0) observeSurroundings(session, player.id, turn);
|
|
1033
|
-
}
|
|
1034
|
-
//#endregion
|
|
1035
1003
|
//#region src/host/clock/agenda.ts
|
|
1036
1004
|
const CURSOR = "agenda.cursor";
|
|
1037
1005
|
const ASKED = "agenda.asked";
|
|
@@ -2959,6 +2927,7 @@ var AfterTurnJobs = class {
|
|
|
2959
2927
|
consolidating = /* @__PURE__ */ new Set();
|
|
2960
2928
|
strategizing = /* @__PURE__ */ new Set();
|
|
2961
2929
|
judging = /* @__PURE__ */ new Set();
|
|
2930
|
+
reflecting = /* @__PURE__ */ new Set();
|
|
2962
2931
|
constructor(deps) {
|
|
2963
2932
|
this.deps = deps;
|
|
2964
2933
|
}
|
|
@@ -2966,6 +2935,42 @@ var AfterTurnJobs = class {
|
|
|
2966
2935
|
this.consolidate(owner, cancel);
|
|
2967
2936
|
this.strategize(owner, cancel);
|
|
2968
2937
|
this.judge(owner, cancel);
|
|
2938
|
+
const reason = this.reflectionDue(owner);
|
|
2939
|
+
if (reason !== void 0) this.reflect(owner, reason, cancel);
|
|
2940
|
+
}
|
|
2941
|
+
/** Whether a reflection is running for the chat. */
|
|
2942
|
+
isReflecting(chat) {
|
|
2943
|
+
return this.reflecting.has(chat);
|
|
2944
|
+
}
|
|
2945
|
+
/** Starts a reflection the player asked for, without waiting for it. @throws {ReflectionRefusedError} when one is already running. */
|
|
2946
|
+
reflectNow(owner, cancel) {
|
|
2947
|
+
if (this.deps.stores(owner.chat) === void 0) throw new Error(`no story for chat ${owner.chat}`);
|
|
2948
|
+
if (this.reflecting.has(owner.chat)) throw new ReflectionRefusedError("a reflection is already running");
|
|
2949
|
+
this.reflect(owner, "manual", cancel);
|
|
2950
|
+
}
|
|
2951
|
+
reflectionDue(owner) {
|
|
2952
|
+
const store = this.deps.stores(owner.chat);
|
|
2953
|
+
return store === void 0 || this.reflecting.has(owner.chat) ? void 0 : dueReflection(store, owner.turn);
|
|
2954
|
+
}
|
|
2955
|
+
/** The characters sort what they have taken in into what they believe. The one failure that matters to the player, a pass they asked for, is kept for the settings tab. */
|
|
2956
|
+
reflect(owner, reason, cancel) {
|
|
2957
|
+
const store = this.deps.stores(owner.chat);
|
|
2958
|
+
if (store === void 0) return;
|
|
2959
|
+
this.reflecting.add(owner.chat);
|
|
2960
|
+
this.deps.track(owner.chat, this.deps.boundaries().reflector.reflect({
|
|
2961
|
+
chat: owner.chat,
|
|
2962
|
+
turn: owner.turn,
|
|
2963
|
+
store,
|
|
2964
|
+
reason
|
|
2965
|
+
}, cancel).then((report) => {
|
|
2966
|
+
if (report.characters.length > 0) this.deps.written(owner.chat);
|
|
2967
|
+
}).catch((error) => {
|
|
2968
|
+
if (cancel.aborted) return;
|
|
2969
|
+
recordFailure(store.story, messageOf(error));
|
|
2970
|
+
this.deps.problem(`what the characters believe was not sorted: ${messageOf(error)}`);
|
|
2971
|
+
}).finally(() => {
|
|
2972
|
+
this.reflecting.delete(owner.chat);
|
|
2973
|
+
}));
|
|
2969
2974
|
}
|
|
2970
2975
|
/** Fit what was made up into the rest of the world, when enough of it is waiting or some has waited long. */
|
|
2971
2976
|
consolidate(owner, cancel) {
|
|
@@ -3022,31 +3027,6 @@ var AfterTurnJobs = class {
|
|
|
3022
3027
|
}
|
|
3023
3028
|
};
|
|
3024
3029
|
//#endregion
|
|
3025
|
-
//#region src/host/orchestration/whereabouts.ts
|
|
3026
|
-
const within = (inner, outer, places) => {
|
|
3027
|
-
const byId = new Map(places.map((place) => [place.id, place]));
|
|
3028
|
-
const seen = /* @__PURE__ */ new Set();
|
|
3029
|
-
for (let at = inner; at !== void 0 && !seen.has(at.id); at = at.parentId === void 0 ? void 0 : byId.get(at.parentId)) {
|
|
3030
|
-
if (at.id === outer.id) return true;
|
|
3031
|
-
seen.add(at.id);
|
|
3032
|
-
}
|
|
3033
|
-
return false;
|
|
3034
|
-
};
|
|
3035
|
-
/**
|
|
3036
|
-
* Compares the place an action is said to happen at (by key) with where the character is. Only a proven mismatch counts: a character that is
|
|
3037
|
-
* nowhere, or a world without places, is no evidence, and a place that contains the other (a room and its building) is the same for this.
|
|
3038
|
-
*/
|
|
3039
|
-
function whereabouts(places, here, at) {
|
|
3040
|
-
const target = places.find((place) => locationKey(place) === at);
|
|
3041
|
-
if (target === void 0) return { kind: "unknown" };
|
|
3042
|
-
if (here === void 0) return { kind: "unplaced" };
|
|
3043
|
-
return within(here, target, places) || within(target, here, places) ? { kind: "here" } : {
|
|
3044
|
-
kind: "elsewhere",
|
|
3045
|
-
target,
|
|
3046
|
-
here
|
|
3047
|
-
};
|
|
3048
|
-
}
|
|
3049
|
-
//#endregion
|
|
3050
3030
|
//#region src/host/orchestration/turn-engine.ts
|
|
3051
3031
|
const MAX_OBJECTIONS = 3;
|
|
3052
3032
|
/** The most a single round may be said to take: a day. A longer time passing is skipped with `advanceTime`. */
|
|
@@ -3126,6 +3106,8 @@ var TurnEngine = class {
|
|
|
3126
3106
|
/** What runs in the background of each chat and writes to its story, other than the records: fitting in what was made up, and the characters away. */
|
|
3127
3107
|
working = /* @__PURE__ */ new Map();
|
|
3128
3108
|
afterTurn;
|
|
3109
|
+
/** What a reflection the player asked for is cancelled with, as `stop` does for the turn. */
|
|
3110
|
+
reflectionCancels = /* @__PURE__ */ new Map();
|
|
3129
3111
|
/** Chats whose characters away from the player are being asked about what fell due: one run at a time. */
|
|
3130
3112
|
offstage = /* @__PURE__ */ new Set();
|
|
3131
3113
|
constructor(boundaries, stores, problem = () => void 0, written = () => void 0) {
|
|
@@ -3761,6 +3743,36 @@ var TurnEngine = class {
|
|
|
3761
3743
|
await this.chains.get(chat);
|
|
3762
3744
|
}
|
|
3763
3745
|
}
|
|
3746
|
+
/**
|
|
3747
|
+
* Starts a reflection the player asked for: the records still waiting are written first, so that what the characters took in is there to
|
|
3748
|
+
* sort, and the pass then runs in the background. @throws {ReflectionRefusedError} while a turn is being played, or when a pass is already running.
|
|
3749
|
+
*/
|
|
3750
|
+
async reflect(chat) {
|
|
3751
|
+
const store = this.stores(chat);
|
|
3752
|
+
if (store === void 0) throw new Error(`no story for chat ${chat}`);
|
|
3753
|
+
const turning = this.states.get(chat);
|
|
3754
|
+
if (turning !== void 0 && [
|
|
3755
|
+
"resolving",
|
|
3756
|
+
"retrying",
|
|
3757
|
+
"between"
|
|
3758
|
+
].includes(turning.phase)) throw new ReflectionRefusedError("a turn is being played; reflect when it is over");
|
|
3759
|
+
const delivered = this.delivered.get(chat);
|
|
3760
|
+
if (delivered !== void 0 && store.pendingCommits().length > 0) this.write({
|
|
3761
|
+
chat,
|
|
3762
|
+
turn: delivered.turn
|
|
3763
|
+
}, delivered);
|
|
3764
|
+
await this.chains.get(chat);
|
|
3765
|
+
const cancel = new AbortController();
|
|
3766
|
+
this.reflectionCancels.set(chat, cancel);
|
|
3767
|
+
this.afterTurn.reflectNow({
|
|
3768
|
+
chat,
|
|
3769
|
+
turn: store.story.metadata.get().turns
|
|
3770
|
+
}, cancel.signal);
|
|
3771
|
+
}
|
|
3772
|
+
/** Whether a reflection is running for the chat. */
|
|
3773
|
+
reflecting(chat) {
|
|
3774
|
+
return this.afterTurn.isReflecting(chat);
|
|
3775
|
+
}
|
|
3764
3776
|
/** Wait until the run of the keeper in flight, if any, has ended; nothing is started. */
|
|
3765
3777
|
async idle(chat) {
|
|
3766
3778
|
await this.chains.get(chat);
|
|
@@ -3787,6 +3799,7 @@ var TurnEngine = class {
|
|
|
3787
3799
|
/** Stops what the turn of a chat has in flight: nothing it started is cancelled halfway through a write, but nothing new is asked of a model. */
|
|
3788
3800
|
stop(chat) {
|
|
3789
3801
|
this.states.get(chat)?.cancel.abort();
|
|
3802
|
+
this.reflectionCancels.get(chat)?.abort();
|
|
3790
3803
|
}
|
|
3791
3804
|
/** Resolves when nothing of the chat writes to its story any more: the records, what was made up being fitted in, the characters away. */
|
|
3792
3805
|
async quiesce(chat) {
|
|
@@ -3798,6 +3811,8 @@ var TurnEngine = class {
|
|
|
3798
3811
|
}
|
|
3799
3812
|
forget(chat) {
|
|
3800
3813
|
this.states.get(chat)?.cancel.abort();
|
|
3814
|
+
this.reflectionCancels.get(chat)?.abort();
|
|
3815
|
+
this.reflectionCancels.delete(chat);
|
|
3801
3816
|
this.states.delete(chat);
|
|
3802
3817
|
this.chains.delete(chat);
|
|
3803
3818
|
this.delivered.delete(chat);
|
|
@@ -4595,6 +4610,7 @@ function apply(ctx) {
|
|
|
4595
4610
|
ctx.effect(() => ctx.roleplayOrchestration.replace({ committer: recordKeeper({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: record keeper");
|
|
4596
4611
|
ctx.effect(() => ctx.roleplayOrchestration.replace({ judge: triggerJudge({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: trigger judge");
|
|
4597
4612
|
ctx.effect(() => ctx.roleplayOrchestration.replace({ strategist: factionStrategist({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: faction strategist");
|
|
4613
|
+
ctx.effect(() => ctx.roleplayOrchestration.replace({ reflector: memoryReflector({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: reflection");
|
|
4598
4614
|
ctx.effect(() => ctx.roleplayOrchestration.replace({ author: worldAuthor({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: world author");
|
|
4599
4615
|
ctx.effect(() => ctx.roleplayOrchestration.replace({ suggester: suggestionWriter({ agentOf: (chat) => ctx.agents.get(SessionId(chat)) }) }), "roleplay: suggestions");
|
|
4600
4616
|
ctx.effect(() => ctx.roleplayState.bind((agentSessionId) => {
|
|
@@ -4648,6 +4664,14 @@ function apply(ctx) {
|
|
|
4648
4664
|
}
|
|
4649
4665
|
})].sort((a, b) => Number(b.name === PREVIEW_TOOL) - Number(a.name === PREVIEW_TOOL));
|
|
4650
4666
|
for (const tool of tools) ctx.tools.register(tool);
|
|
4667
|
+
ctx.effect(() => {
|
|
4668
|
+
ctx.roleplayOrchestration.reflect = (chat) => engine.reflect(chat);
|
|
4669
|
+
ctx.roleplayOrchestration.reflecting = (chat) => engine.reflecting(chat);
|
|
4670
|
+
return () => {
|
|
4671
|
+
ctx.roleplayOrchestration.reflect = () => Promise.reject(/* @__PURE__ */ new Error("the orchestration is not running"));
|
|
4672
|
+
ctx.roleplayOrchestration.reflecting = () => false;
|
|
4673
|
+
};
|
|
4674
|
+
}, "roleplay: reflection control");
|
|
4651
4675
|
ctx.effect(() => {
|
|
4652
4676
|
ctx.roleplayOrchestration.settle = (chat) => engine.idle(chat);
|
|
4653
4677
|
return () => {
|
|
@@ -66,6 +66,8 @@ var SessionNotFoundError = class extends Error {};
|
|
|
66
66
|
var AgentUnavailableError = class extends Error {};
|
|
67
67
|
/** The session is put away and cannot be played until it is brought back. */
|
|
68
68
|
var SessionArchivedError = class extends Error {};
|
|
69
|
+
/** A reflection cannot be started now: a turn is being played, or one is already running. */
|
|
70
|
+
var ReflectionRefusedError = class extends Error {};
|
|
69
71
|
//#endregion
|
|
70
72
|
//#region src/host/prompts/library.ts
|
|
71
73
|
const PROMPTS_FOLDER = "prompts";
|
|
@@ -1329,6 +1331,6 @@ function anyTab(bases) {
|
|
|
1329
1331
|
}));
|
|
1330
1332
|
}
|
|
1331
1333
|
//#endregion
|
|
1332
|
-
export { languageOf as A,
|
|
1334
|
+
export { languageOf as A, SessionArchivedError as B, errorMessage as C, PromptLibrary as D, PROMPTS_FOLDER as E, shippedText as F, INTENT_TYPES as G, WorldNotFoundError as H, AgentUnavailableError as I, InvalidStartError as L, promptProblem as M, shippedLanguages as N, copyWorldPrompts as O, shippedPromptsDirectory as P, InvalidWorldError as R, readDocument as S, formatIssue as T, INTENT_HORIZONS as U, SessionNotFoundError as V, INTENT_STATUSES as W, API_PREFIX as _, packIds as a, parsePlotsFile as b, describePack as c, packPath as d, readPack as f, SURFACE_NAMES as g, PACK_MEDIA_TYPES as h, inheritPacks as i, listFiles as j, inheritPrompts as k, isPackId as l, PACK_LIMITS as m, anyTab as n, syncWorldPacks as o, PACK_ACTIONS as p, copyWorldPacks as r, worldPackStates as s, activePack as t, packFile as u, PLOTS_FILE_NAME as v, Reader as w, plotReferenceProblems as x, loadPlots as y, ReflectionRefusedError as z };
|
|
1333
1335
|
|
|
1334
|
-
//# sourceMappingURL=packs-
|
|
1336
|
+
//# sourceMappingURL=packs-alJTiDM2.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { t as promptFor } from "./access-EbNdZFbk.js";
|
|
1
2
|
import { A as runChild, d as nextSceneSerial, n as generateTransientImage, p as referenceImagePath, t as generateReferenceImage } from "./generator-HPifO3Kk.js";
|
|
2
3
|
import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-DUeBMHQX.js";
|
|
3
|
-
import { t as promptFor } from "./access-C1nFQiyT.js";
|
|
4
4
|
import { dirname, join, relative } from "node:path";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { createHash, randomUUID } from "node:crypto";
|
|
@@ -850,4 +850,4 @@ async function runImagePresenter(job) {
|
|
|
850
850
|
//#endregion
|
|
851
851
|
export { tokensOf as a, searchImages as i, interpretImage as n, present as o, imageTools as r, presentedFor as s, runImagePresenter as t };
|
|
852
852
|
|
|
853
|
-
//# sourceMappingURL=presenter-agent-
|
|
853
|
+
//# sourceMappingURL=presenter-agent-PX1WVaJB.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-agentic-roleplay/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Core plugin of the agentic roleplay bundle for DeepSeek Harness: roleplay UI, orchestration and storage.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Firefox2100",
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
},
|
|
60
60
|
"files": [
|
|
61
61
|
"lib/*.js",
|
|
62
|
+
"packs",
|
|
62
63
|
"prompts",
|
|
63
64
|
"starter-worlds",
|
|
64
65
|
"lib/client.js",
|
|
@@ -73,7 +74,7 @@
|
|
|
73
74
|
"@deepseek-ai/schemastery": "^3.18.4"
|
|
74
75
|
},
|
|
75
76
|
"dependencies": {
|
|
76
|
-
"@dsh-agentic-roleplay/state": "0.
|
|
77
|
+
"@dsh-agentic-roleplay/state": "0.3.0",
|
|
77
78
|
"@dsh-ai-providers/core": "^0.1.2"
|
|
78
79
|
},
|
|
79
80
|
"devDependencies": {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<link rel="stylesheet" href="style.css">
|
|
6
|
+
</head>
|
|
7
|
+
<body style="height: 100vh">
|
|
8
|
+
<svg id="map" viewBox="0 0 400 400" role="img"></svg>
|
|
9
|
+
<p class="muted map-empty" id="empty" hidden></p>
|
|
10
|
+
<script src="map.js"></script>
|
|
11
|
+
</body>
|
|
12
|
+
</html>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
const WORDS = {
|
|
2
|
+
en: { label: 'The places you know and the ways between them', empty: 'No places known yet.' },
|
|
3
|
+
zh: { label: '你所知道的地点以及它们之间的路', empty: '还没有已知的地点。' },
|
|
4
|
+
}
|
|
5
|
+
const words = () => WORDS[document.documentElement.lang] ?? WORDS.en
|
|
6
|
+
const SVG = 'http://www.w3.org/2000/svg'
|
|
7
|
+
const CENTRE = 200
|
|
8
|
+
const RADIUS = 140
|
|
9
|
+
|
|
10
|
+
function element(name, attributes = {}, text) {
|
|
11
|
+
const node = document.createElementNS(SVG, name)
|
|
12
|
+
for (const [key, value] of Object.entries(attributes)) node.setAttribute(key, String(value))
|
|
13
|
+
if (text !== undefined) node.textContent = text
|
|
14
|
+
return node
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** Where each known place is drawn: the one the player is in at the centre, the others around it. */
|
|
18
|
+
function layout(places) {
|
|
19
|
+
const others = places.filter(place => !place.here)
|
|
20
|
+
const spots = new Map(places.filter(place => place.here).map(place => [place.key, { x: CENTRE, y: CENTRE }]))
|
|
21
|
+
others.forEach((place, index) => {
|
|
22
|
+
const angle = (index / Math.max(1, others.length)) * Math.PI * 2 - Math.PI / 2
|
|
23
|
+
spots.set(place.key, { x: CENTRE + RADIUS * Math.cos(angle), y: CENTRE + RADIUS * Math.sin(angle) })
|
|
24
|
+
})
|
|
25
|
+
return spots
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let latest
|
|
29
|
+
|
|
30
|
+
function render() {
|
|
31
|
+
const view = latest
|
|
32
|
+
if (view === undefined) return
|
|
33
|
+
const svg = document.getElementById('map')
|
|
34
|
+
svg.setAttribute('aria-label', words().label)
|
|
35
|
+
const empty = document.getElementById('empty')
|
|
36
|
+
empty.textContent = words().empty
|
|
37
|
+
empty.hidden = view.map.places.length > 0
|
|
38
|
+
const spots = layout(view.map.places)
|
|
39
|
+
svg.replaceChildren(
|
|
40
|
+
...view.map.routes.flatMap((route) => {
|
|
41
|
+
const from = spots.get(route.from)
|
|
42
|
+
const to = spots.get(route.to)
|
|
43
|
+
return from && to ? [element('line', { class: 'edge', x1: from.x, y1: from.y, x2: to.x, y2: to.y })] : []
|
|
44
|
+
}),
|
|
45
|
+
...view.map.places.map((place) => {
|
|
46
|
+
const spot = spots.get(place.key)
|
|
47
|
+
const group = element('g', { class: place.here ? 'node here' : 'node', transform: `translate(${spot.x} ${spot.y})` })
|
|
48
|
+
group.append(element('circle', { r: place.here ? 11 : 8 }), element('text', { y: place.here ? 28 : 24 }, place.name))
|
|
49
|
+
return group
|
|
50
|
+
}),
|
|
51
|
+
)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
rp.watch((view) => { latest = view; render() })
|
|
55
|
+
rp.on('theme', render)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "Scene",
|
|
3
|
+
"version": "1.0",
|
|
4
|
+
"description": "A status strip above the input box (place, time, who is here) and a live map of the places you know in the right sidebar. Works with any world.",
|
|
5
|
+
"api": 1,
|
|
6
|
+
"actions": ["open"],
|
|
7
|
+
"surfaces": {
|
|
8
|
+
"hud": { "file": "strip.html", "height": 40 },
|
|
9
|
+
"sidebar": { "file": "map.html", "title": "Map" }
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<link rel="stylesheet" href="style.css">
|
|
6
|
+
</head>
|
|
7
|
+
<body>
|
|
8
|
+
<div class="strip"><span class="place" id="place"></span><span class="time" id="time"></span><span class="more" id="more"></span><button type="button" id="map"></button></div>
|
|
9
|
+
<script src="strip.js"></script>
|
|
10
|
+
</body>
|
|
11
|
+
</html>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const WORDS = {
|
|
2
|
+
en: { nowhere: 'Nowhere in particular', alone: 'alone', with: 'with', map: 'Map', mapTitle: 'Show the map in the sidebar' },
|
|
3
|
+
zh: { nowhere: '不在任何特定地点', alone: '独自一人', with: '与', map: '地图', mapTitle: '在侧栏显示地图' },
|
|
4
|
+
}
|
|
5
|
+
const words = () => WORDS[document.documentElement.lang] ?? WORDS.en
|
|
6
|
+
const text = (id, value) => { document.getElementById(id).textContent = value }
|
|
7
|
+
let latest
|
|
8
|
+
|
|
9
|
+
function render() {
|
|
10
|
+
const view = latest
|
|
11
|
+
if (view === undefined) return
|
|
12
|
+
const w = words()
|
|
13
|
+
text('place', view.place ? view.place.name : w.nowhere)
|
|
14
|
+
text('time', view.time ? view.time.text : '')
|
|
15
|
+
const here = view.place ? view.place.here.map(person => person.name) : []
|
|
16
|
+
const tracked = view.variables.filter(entry => entry.subject !== 'the world').map(entry => `${entry.subject}: ${entry.name} ${entry.value}`)
|
|
17
|
+
text('more', [here.length > 0 ? `${w.with} ${here.join(', ')}` : w.alone, ...tracked].join(' · '))
|
|
18
|
+
const button = document.getElementById('map')
|
|
19
|
+
button.textContent = w.map
|
|
20
|
+
button.title = w.mapTitle
|
|
21
|
+
rp.resize(document.documentElement.scrollHeight)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
rp.watch((view) => { latest = view; render() })
|
|
25
|
+
rp.on('theme', render)
|
|
26
|
+
document.getElementById('map').addEventListener('click', () => { rp.open('sidebar').catch(error => console.warn(error)) })
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
:root { color-scheme: light dark; }
|
|
2
|
+
html, body { margin: 0; background: transparent; color: var(--dsw-alias-label-primary, CanvasText); font: 13px/20px system-ui, sans-serif; }
|
|
3
|
+
.muted { color: var(--dsw-alias-label-tertiary, GrayText); }
|
|
4
|
+
button { font: inherit; text-align: left; border: 1px solid var(--dsw-alias-border-l3, #8886); border-radius: var(--dsw-radius-sm, 8px); background: transparent; color: inherit; padding: 4px 10px; margin: 0 6px 6px 0; cursor: pointer; }
|
|
5
|
+
button:hover { border-color: var(--dsw-alias-brand-primary, currentColor); }
|
|
6
|
+
.strip { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; padding: 8px 12px; border: 1px solid var(--dsw-alias-border-l3, #8886); border-radius: var(--dsw-radius-sm, 8px); background: var(--dsw-alias-bg-layer-1, transparent); }
|
|
7
|
+
.strip .place { font-weight: 600; color: var(--dsw-alias-brand-primary, inherit); }
|
|
8
|
+
.strip .time, .strip .more { color: var(--dsw-alias-label-secondary, inherit); }
|
|
9
|
+
.strip button { margin: 0 0 0 auto; padding: 0 8px; }
|
|
10
|
+
svg { display: block; width: 100%; height: 100%; }
|
|
11
|
+
.edge { stroke: var(--dsw-alias-border-l2, #8888); stroke-width: 1.5; }
|
|
12
|
+
.node circle { fill: var(--dsw-alias-bg-layer-2, #8882); stroke: var(--dsw-alias-border-l2, #888); stroke-width: 1.5; }
|
|
13
|
+
.node.here circle { fill: var(--dsw-alias-brand-primary, #a52); stroke: none; }
|
|
14
|
+
.node text { fill: var(--dsw-alias-label-secondary, currentColor); font-size: 11px; text-anchor: middle; }
|
|
15
|
+
.node.here text { fill: var(--dsw-alias-label-primary, currentColor); font-weight: 600; }
|
|
16
|
+
.map-empty { padding: 24px; }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
You tidy the memory of one character in an interactive story: you decide what the character has come to believe from what they have taken in. You are not the character and you never speak for them. You work only from what you are shown: what they believe now (numbered b) and what they have taken in since (numbered p). Never add a fact that is not in what you are shown, and never give the character knowledge they could not have.
|
|
2
|
+
|
|
3
|
+
A belief is what the character holds to be true, suspects, or has been told; it may be wrong, and what you record is their view, not the truth. Say plainly in the belief when it is a suspicion, a rumour or a guess, and keep apart what happened, what others claimed, what the character inferred and what they now believe.
|
|
4
|
+
|
|
5
|
+
A belief is a conclusion, not a copy of a report. It is about the world, a place or other people: what the character now thinks of someone, what they suspect is going on, what they have worked out. Never restate what the character itself did or said, and never write about the character in the third person as if from outside; do not repeat a sentence of what they took in, and do not merge unrelated things into one belief.
|
|
6
|
+
|
|
7
|
+
Prefer fewer, firmer beliefs. Digest more than you add: merge beliefs that say the same thing into one and drop the rest, let go of a belief that later events settled or overturned, and doubt one that later events contradict instead of stating it more strongly. Add a belief only when a pattern runs through things from different times, or one event plainly changed how the character sees something or someone; a single passing moment is not yet a belief. Every change names the numbers of the things it took in that it rests on, and they are checked. When nothing is firm enough, change nothing: empty lists are a good answer.
|
|
8
|
+
|
|
9
|
+
Write in the language of the story, in one or two sentences a belief, the way the character would put it to themselves.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Use the read tools before making claims or edits. Keys are stable file identities, not display names. Before replacing an element, read its exact source document and preserve fields the requested change does not affect. Every write asks the user for one-time approval. If approval is rejected, cancelled or unavailable, do not retry it automatically: explain that nothing changed and ask how the user wants to proceed. To change how a story looks, read world_pack_guide, then write
|
|
1
|
+
Use the read tools before making claims or edits. Keys are stable file identities, not display names. Before replacing an element, read its exact source document and preserve fields the requested change does not affect. Every write asks the user for one-time approval. If approval is rejected, cancelled or unavailable, do not retry it automatically: explain that nothing changed and ask how the user wants to proceed. To change how a story looks, read world_pack_guide, then write the interface pack file by file with the write tool, using the paths the guide gives, and finish with check_world_pack until it reports no problems. To make the world act by itself, list_world_triggers and get_world_trigger first, then write_world_trigger with a complete document; a trigger that names something the world does not have is refused with every problem, so fix them all.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Welcome to the authoring room for “${world}”. I can inspect and edit the world overview, characters, locations, items, factions, lore, plots, relationships, knowledge, memberships and map exits. I will show you each proposed file change for approval before writing it; if you decline, nothing is changed and we can revise the proposal together. Tell me what you want to create, revise, or explore.
|
|
1
|
+
Welcome to the authoring room for “${world}”. I can inspect and edit the world overview, characters, locations, items, factions, lore, plots, triggers (what the world does by itself), relationships, knowledge, memberships and map exits. I will show you each proposed file change for approval before writing it; if you decline, nothing is changed and we can revise the proposal together. Tell me what you want to create, revise, or explore.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
你负责整理互动故事中一个角色的记忆:根据角色所见所闻,决定它形成了哪些信念。你不是这个角色,也从不替它说话。你只依据所展示的内容工作:它目前持有的信念(编号 b)和此后它接收到的见闻(编号 p)。不要添加所展示内容之外的事实,也不要赋予角色它不可能知道的知识。
|
|
2
|
+
|
|
3
|
+
信念是角色认为为真的、怀疑的或被告知的事;它可能是错的,你记录的是角色的看法,而不是真相。当信念只是怀疑、传闻或猜测时,请在文字里明说,并把发生了什么、别人声称了什么、角色推断了什么、角色现在相信什么区分开。
|
|
4
|
+
|
|
5
|
+
信念是结论,而不是对见闻的复制。它关于世界、某个地方或其他人:角色现在如何看待某人、怀疑发生了什么、推断出了什么。不要复述角色自己做过或说过的事,也不要以旁观者的口吻用第三人称写这个角色;不要照抄见闻中的句子,也不要把不相关的事合并成一条信念。
|
|
6
|
+
|
|
7
|
+
宁可少而稳。归纳多于添加:把说同一件事的信念合并成一条,其余的放下;对已被后来的事件定论或推翻的信念予以放下;对被后来的事件反驳的信念,应表达为怀疑,而不是说得更肯定。只有当某种规律贯穿于不同时间的见闻,或某个事件明确改变了角色对某事或某人的看法时才新增信念;单个转瞬即逝的时刻还不算信念。每一项改动都要写明所依据的见闻编号,这些编号会被核对。如果没有足够确定的内容,就什么都不改:空列表是个好答案。
|
|
8
|
+
|
|
9
|
+
用故事所用的语言书写,每条信念一两句话,像角色对自己说的那样。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
在做出断言或修改之前,先使用读取工具。键(key)是稳定的文件标识,不是显示名称。在替换某个元素之前,先读取它确切的源文档,并保留请求的修改没有涉及的字段。每一次写入都会向用户请求一次性批准。如果批准被拒绝、取消或无法获得,不要自动重试:说明没有任何改动,并询问用户想怎么继续。若要改变故事的外观,先阅读 world_pack_guide,再用
|
|
1
|
+
在做出断言或修改之前,先使用读取工具。键(key)是稳定的文件标识,不是显示名称。在替换某个元素之前,先读取它确切的源文档,并保留请求的修改没有涉及的字段。每一次写入都会向用户请求一次性批准。如果批准被拒绝、取消或无法获得,不要自动重试:说明没有任何改动,并询问用户想怎么继续。若要改变故事的外观,先阅读 world_pack_guide,再用 write 工具,按指南给出的路径逐个文件编写界面包,最后用 check_world_pack 检查,直到没有问题。若要让世界自行行动,先用 list_world_triggers 和 get_world_trigger 查看,再用 write_world_trigger 写入完整的文档;如果触发器提到世界里没有的东西,会连同所有问题一起被拒绝,请全部修正。
|
|
@@ -1 +1 @@
|
|
|
1
|
-
欢迎来到“${world}
|
|
1
|
+
欢迎来到“${world}”的创作室。我可以查看并编辑世界概览、角色、地点、物品、组织、背景资料、情节、触发器(世界自行发生的事)、关系、知识、成员关系和地图出口。每一处文件修改,我都会先给你看,经你批准后才写入;如果你拒绝,不会有任何改动,我们可以一起修改方案。告诉我你想创建、修改或探索什么。
|
package/lib/access-C1nFQiyT.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { n as roleplaySessionOf } from "./chat-AKrVcWIC.js";
|
|
2
|
-
//#region src/host/prompts/access.ts
|
|
3
|
-
/** The prompt `id` in `language`, from the library of the agent's own context. */
|
|
4
|
-
function promptFor(agent, id, language, variables) {
|
|
5
|
-
const library = agent.ctx.get("roleplayPrompts");
|
|
6
|
-
if (library === void 0) throw new Error("the prompt library is not running");
|
|
7
|
-
return library.text(id, language, variables, roleplaySessionOf(agent.session.id));
|
|
8
|
-
}
|
|
9
|
-
//#endregion
|
|
10
|
-
export { promptFor as t };
|
|
11
|
-
|
|
12
|
-
//# sourceMappingURL=access-C1nFQiyT.js.map
|