@dsh-agentic-roleplay/core 0.8.1 → 0.8.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.
Files changed (35) hide show
  1. package/lib/{access-DtOxFKBK.js → access-CfQWbNZP.js} +4 -7
  2. package/lib/{authoring-tools-DNnx0Nts.js → authoring-tools-BgmC2oqU.js} +223 -106
  3. package/lib/authoring.js +15 -22
  4. package/lib/{child-D6mpkkCE.js → child-lYYeOwl2.js} +28 -51
  5. package/lib/client.js +615 -778
  6. package/lib/client.js.map +1 -1
  7. package/lib/compaction.js +8 -13
  8. package/lib/{doctor-chat-ByDfCMeo.js → doctor-chat-hL1a61hp.js} +2 -3
  9. package/lib/doctor.js +6 -8
  10. package/lib/{gallery-D9nG3C78.js → gallery-D1V4h8vh.js} +3 -4
  11. package/lib/{generator-r1Czm7oi.js → generator-CLPosooC.js} +3 -4
  12. package/lib/helper.js +2 -3
  13. package/lib/{hooks-BQCzgggH.js → hooks-rQTTeOC4.js} +69 -97
  14. package/lib/images.js +4 -4
  15. package/lib/index.js +194 -264
  16. package/lib/{library-zI-2tG7h.js → library-Dfu0dgRj.js} +9 -15
  17. package/lib/{lorebook-author-tools-ywaYicwd.js → lorebook-author-tools-BAaAqZZm.js} +10 -13
  18. package/lib/lorebook-authoring.js +5 -6
  19. package/lib/{narration-CnBlVure.js → narration-CjB_KwwY.js} +9 -15
  20. package/lib/orchestration.js +53 -64
  21. package/lib/{pack-jail-5EJ-WYyW.js → pack-jail-CN-314ln.js} +76 -81
  22. package/lib/{packs-Cv8hanXJ.js → packs-DIj5BEfq.js} +6 -10
  23. package/lib/{presenter-agent-BSaMSd3G.js → presenter-agent-DR0KvLE0.js} +12 -18
  24. package/lib/{preset-CWI3-0r1.js → preset-CscHj1-Y.js} +5 -6
  25. package/lib/{preset-author-tools-BrJYa2cr.js → preset-author-tools-CxluF8qc.js} +12 -14
  26. package/lib/preset-authoring.js +6 -7
  27. package/lib/{presets-MwOSMMyu.js → presets-HB8kJTaE.js} +51 -56
  28. package/lib/{reflection-zSaMsjKj.js → reflection-Dg1xtOTW.js} +19 -30
  29. package/lib/{text-BzudpQLS.js → text-DyRN4nDP.js} +6 -8
  30. package/lib/{turn-guard-Cv8pfHEA.js → turn-guard-g_hDn0jR.js} +6 -11
  31. package/package.json +29 -29
  32. package/prompts/en/import/casting.md +1 -1
  33. package/prompts/en/import/character.md +1 -0
  34. package/prompts/zh/import/casting.md +1 -1
  35. package/prompts/zh/import/character.md +1 -0
@@ -1,14 +1,14 @@
1
- import { i as VARIABLE_VISIBILITIES, n as VARIABLE_KINDS, r as VARIABLE_SUBJECTS } from "./access-DtOxFKBK.js";
2
- import "./narration-CnBlVure.js";
3
- import { J as formatIssue, K as readDocument, X as LANGUAGE_FOLDER, Y as errorMessage, Z as PROMPTS_FOLDER, at as shippedPromptsDirectory, it as shippedLanguages, nt as listFiles, q as Reader, rt as promptProblem, tt as languageOf } from "./hooks-BQCzgggH.js";
4
- import { u as parseSampling } from "./child-D6mpkkCE.js";
5
- import { C as trOf, S as slug, b as mapLimit, w as uniqueKey, x as norm } from "./library-zI-2tG7h.js";
1
+ import { i as VARIABLE_VISIBILITIES, n as VARIABLE_KINDS, r as VARIABLE_SUBJECTS } from "./access-CfQWbNZP.js";
2
+ import "./narration-CjB_KwwY.js";
3
+ import { J as formatIssue, K as readDocument, X as LANGUAGE_FOLDER, Y as errorMessage, Z as PROMPTS_FOLDER, at as shippedPromptsDirectory, it as shippedLanguages, nt as listFiles, q as Reader, rt as promptProblem, tt as languageOf } from "./hooks-rQTTeOC4.js";
4
+ import { u as parseSampling } from "./child-lYYeOwl2.js";
5
+ import { C as trOf, S as slug, b as mapLimit, w as uniqueKey, x as norm } from "./library-Dfu0dgRj.js";
6
6
  import { dirname, join } from "node:path";
7
7
  import { existsSync, readFileSync, readdirSync } from "node:fs";
8
8
  import { createHash, randomUUID } from "node:crypto";
9
9
  import { cp, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
10
10
  import { MAX_ROUTINE_WINDOWS, createSessionStore, dayTokenProblems, valueIssue } from "@dsh-agentic-roleplay/state";
11
- //#region ../dsh-roleplay-model/src/character.ts
11
+ // ../dsh-roleplay-model/src/character.ts
12
12
  const CHARACTER_ROLES = ["playable", "npc"];
13
13
  const CHARACTER_TIERS = [
14
14
  "principal",
@@ -16,8 +16,7 @@ const CHARACTER_TIERS = [
16
16
  "background"
17
17
  ];
18
18
  const CHARACTER_KINDS = ["person", "group"];
19
- //#endregion
20
- //#region ../dsh-roleplay-model/src/intent.ts
19
+ // ../dsh-roleplay-model/src/intent.ts
21
20
  const INTENT_TYPES = [
22
21
  "need",
23
22
  "obligation",
@@ -42,8 +41,7 @@ const INTENT_HORIZONS = [
42
41
  "long",
43
42
  "open_ended"
44
43
  ];
45
- //#endregion
46
- //#region ../dsh-roleplay-model/src/item.ts
44
+ // ../dsh-roleplay-model/src/item.ts
47
45
  /** Whether a container can be got into. */
48
46
  const CONTAINER_STATES = [
49
47
  "open",
@@ -108,23 +106,20 @@ const DEFAULT_SLOTS = [
108
106
  capacity: 1
109
107
  }
110
108
  ];
111
- //#endregion
112
- //#region ../dsh-roleplay-model/src/location.ts
109
+ // ../dsh-roleplay-model/src/location.ts
113
110
  /** Whether people can go through an exit now. */
114
111
  const EXIT_STATES = [
115
112
  "open",
116
113
  "locked",
117
114
  "blocked"
118
115
  ];
119
- //#endregion
120
- //#region ../dsh-roleplay-model/src/faction.ts
116
+ // ../dsh-roleplay-model/src/faction.ts
121
117
  const MEMBERSHIP_STATUSES = [
122
118
  "active",
123
119
  "inactive",
124
120
  "former"
125
121
  ];
126
- //#endregion
127
- //#region ../dsh-roleplay-model/src/agenda.ts
122
+ // ../dsh-roleplay-model/src/agenda.ts
128
123
  const WEEKDAY_NAMES = [
129
124
  "sun",
130
125
  "mon",
@@ -134,8 +129,7 @@ const WEEKDAY_NAMES = [
134
129
  "fri",
135
130
  "sat"
136
131
  ];
137
- //#endregion
138
- //#region ../dsh-roleplay-model/src/lore.ts
132
+ // ../dsh-roleplay-model/src/lore.ts
139
133
  const LORE_KINDS = [
140
134
  "history",
141
135
  "culture",
@@ -156,8 +150,7 @@ const LORE_SUBJECT_KINDS = [
156
150
  "item",
157
151
  "lore"
158
152
  ];
159
- //#endregion
160
- //#region src/shared/world-state.ts
153
+ // src/shared/world-state.ts
161
154
  /** The problems with an edit, for the person who made it; nothing was changed. */
162
155
  var InvalidEditProblems = class extends Error {
163
156
  problems;
@@ -706,8 +699,7 @@ function readIdentifier(reader, fallback) {
706
699
  if (id !== void 0 && id.length > 100) reader.fail("id", `must be at most 100 characters`);
707
700
  return id;
708
701
  }
709
- //#endregion
710
- //#region src/host/variables/values.ts
702
+ // src/host/variables/values.ts
711
703
  /** At most this many initial values in one file. */
712
704
  const MAX_VALUES = 40;
713
705
  /** The `variables` of a world file: what a character, item, place or the world starts with, by the key of each variable. */
@@ -745,8 +737,7 @@ function readVisualIdentity(reader) {
745
737
  ...globalId === void 0 ? {} : { globalId }
746
738
  };
747
739
  }
748
- //#endregion
749
- //#region src/host/characters/character-file.ts
740
+ // src/host/characters/character-file.ts
750
741
  const CHARACTER_FILE_NAME = "character.json";
751
742
  const ISO_DATE = /^\d{4}-\d{2}-\d{2}/;
752
743
  function readAge(reader) {
@@ -977,8 +968,7 @@ function parseCharacterFile(text, fallbackId) {
977
968
  value: character
978
969
  };
979
970
  }
980
- //#endregion
981
- //#region src/host/factions/faction-file.ts
971
+ // src/host/factions/faction-file.ts
982
972
  const FACTION_FILE_NAME = "faction.json";
983
973
  function readMembers(reader) {
984
974
  const seen = /* @__PURE__ */ new Set();
@@ -1078,8 +1068,7 @@ function parseFactionFile(text, fallbackId) {
1078
1068
  issues
1079
1069
  };
1080
1070
  }
1081
- //#endregion
1082
- //#region src/host/items/item-file.ts
1071
+ // src/host/items/item-file.ts
1083
1072
  const ITEM_FILE_NAME = "item.json";
1084
1073
  const SLOTS_FILE_NAME = "slots.json";
1085
1074
  /** Read an `item.json`; `fallbackId` (the folder name) is its id when the file sets none. */
@@ -1227,8 +1216,7 @@ function parseSlotsFile(text) {
1227
1216
  value: slots
1228
1217
  };
1229
1218
  }
1230
- //#endregion
1231
- //#region src/host/locations/location-file.ts
1219
+ // src/host/locations/location-file.ts
1232
1220
  const LOCATION_FILE_NAME = "location.json";
1233
1221
  const FEATURE_KEY = /^[\p{L}\p{N}][\p{L}\p{N}\p{M}_-]{0,59}$/u;
1234
1222
  function readFeatures(reader) {
@@ -1306,8 +1294,7 @@ function parseLocationFile(text, fallbackId) {
1306
1294
  value: location
1307
1295
  };
1308
1296
  }
1309
- //#endregion
1310
- //#region src/host/lore/lore-file.ts
1297
+ // src/host/lore/lore-file.ts
1311
1298
  const LORE_FILE_NAME = "lore.json";
1312
1299
  function instant(reader, key) {
1313
1300
  const value = reader.string(key);
@@ -1364,8 +1351,7 @@ function parseLoreFile(text, fallbackId) {
1364
1351
  issues
1365
1352
  };
1366
1353
  }
1367
- //#endregion
1368
- //#region src/host/variables/load.ts
1354
+ // src/host/variables/load.ts
1369
1355
  const VARIABLES_FILE_NAME = "variables.json";
1370
1356
  function readDefinition(reader) {
1371
1357
  const key = reader.string("key", { required: true });
@@ -1527,8 +1513,7 @@ function variableProblems(world) {
1527
1513
  }
1528
1514
  return problems;
1529
1515
  }
1530
- //#endregion
1531
- //#region src/shared/import-card.ts
1516
+ // src/shared/import-card.ts
1532
1517
  /** The message the plugin sends on the player's behalf to start the import in the new world's authoring chat. */
1533
1518
  const IMPORT_COMMAND = "/import-st";
1534
1519
  /** The command in a message, with the card it names, or nothing when the message is not the command. */
@@ -1545,8 +1530,7 @@ function parseImportCommand(text) {
1545
1530
  request: body.slice(boundary).trim()
1546
1531
  };
1547
1532
  }
1548
- //#endregion
1549
- //#region src/host/import/store.ts
1533
+ // src/host/import/store.ts
1550
1534
  const IMPORT_FOLDER = ".import";
1551
1535
  const CARD_FILE = "card.json";
1552
1536
  const CHOICES_FILE = "choices.json";
@@ -1732,8 +1716,7 @@ var ImportStore = class {
1732
1716
  }
1733
1717
  }
1734
1718
  };
1735
- //#endregion
1736
- //#region src/host/import/items.ts
1719
+ // src/host/import/items.ts
1737
1720
  /** The longest a piece goes into one call. Longer entries are cut into parts at the end of a paragraph. */
1738
1721
  const MAX_ITEM_CHARS = 5e3;
1739
1722
  /** What stands for the player in the text a model reads. The card's own `{{user}}` cannot: the system prompt of an agent reads double braces as a variable of its own. */
@@ -1795,8 +1778,7 @@ function playerWord(text, name) {
1795
1778
  function withPlayer(text, name) {
1796
1779
  return text.replace(/\[PLAYER\]|\{\{\s*user\s*\}\}/g, playerWord(text, name));
1797
1780
  }
1798
- //#endregion
1799
- //#region src/host/prompts/world-prompts.ts
1781
+ // src/host/prompts/world-prompts.ts
1800
1782
  /** The prompts that decide how the story is written and who the models are (prose and persona); every other prompt holds rules of the game. */
1801
1783
  const PROSE_PROMPTS = [
1802
1784
  "roleplay/persona",
@@ -1861,8 +1843,7 @@ async function deleteWorldPrompt(directory, language, id, shipped = shippedPromp
1861
1843
  await rm(dirname(file), { recursive: false }).catch(() => void 0);
1862
1844
  return aside;
1863
1845
  }
1864
- //#endregion
1865
- //#region src/host/decisions/route.ts
1846
+ // src/host/decisions/route.ts
1866
1847
  /** The probability from which a yes is taken as a yes, for the confidence a chat asks. */
1867
1848
  const yesAt = (confidence) => (1 + confidence) / 2;
1868
1849
  /** The probability up to which a no is taken as a no. */
@@ -1978,6 +1959,8 @@ async function routeVerdicts(route, signal) {
1978
1959
  report
1979
1960
  };
1980
1961
  }
1962
+ /** `hybrid` is a default that only does something where a decision model is set up: with none it is the language model alone, and nothing is said, because nothing is wrong. */
1963
+ const modeFor = (mode, service) => mode === "hybrid" && service === void 0 ? "llm" : mode;
1981
1964
  /** Asks the decision model one yes-or-no question for each key about one state, in a single request; the answers are probabilities of yes. */
1982
1965
  async function askYesNo(service, state, asks, signal) {
1983
1966
  const questions = Object.fromEntries(asks.map(({ key, instructions }) => [key, {
@@ -2021,8 +2004,7 @@ function mergeReports(mode, reports) {
2021
2004
  merged.samples = merged.samples.slice(-20);
2022
2005
  return merged;
2023
2006
  }
2024
- //#endregion
2025
- //#region src/host/import/roles.ts
2007
+ // src/host/import/roles.ts
2026
2008
  const ROLES = [
2027
2009
  "character",
2028
2010
  "player",
@@ -2104,8 +2086,7 @@ const isGeneratorOnly = (piece) => playsRole(piece, "generator") && piece.roles.
2104
2086
  const statesWorldFacts = (piece) => playsRole(piece, "world") && !playsRole(piece, "instruction") && !playsRole(piece, "generator");
2105
2087
  /** A piece that may hold guidance on making things up or a standing rule (the generator pieces are read whole by their own step). */
2106
2088
  const mayHoldGuidance = (piece) => !playsRole(piece, "generator") && piece.roles.some((role) => ROLE_TABLE[role].guidance);
2107
- //#endregion
2108
- //#region src/host/import/survey.ts
2089
+ // src/host/import/survey.ts
2109
2090
  const MAX_TARGETS = 10;
2110
2091
  const MAX_NAME = 100;
2111
2092
  /** What a name is when it only stands for the person using the card: not a character of the card. */
@@ -2478,8 +2459,7 @@ function findEntity(roster, name, kind) {
2478
2459
  }));
2479
2460
  return near.length === 1 ? near[0] : void 0;
2480
2461
  }
2481
- //#endregion
2482
- //#region src/host/import/extract.ts
2462
+ // src/host/import/extract.ts
2483
2463
  const emptyExtracted = () => ({
2484
2464
  characters: [],
2485
2465
  locations: [],
@@ -2620,6 +2600,7 @@ const CHARACTER_SCHEMA = {
2620
2600
  additionalProperties: false
2621
2601
  }
2622
2602
  },
2603
+ carries: strs("Things they have on them at the start (a weapon, a tool, a document, a keepsake), by the name the text gives them. Not things they only know of."),
2623
2604
  knows: {
2624
2605
  type: "object",
2625
2606
  properties: {
@@ -2653,6 +2634,8 @@ const CHARACTER_SCHEMA = {
2653
2634
  ],
2654
2635
  additionalProperties: false
2655
2636
  };
2637
+ /** The most things one character is given from what the text says it carries. */
2638
+ const MAX_CARRIED = 12;
2656
2639
  /** The document of a character file from what the call answered; names of places and characters become the keys they have in the roster. */
2657
2640
  function characterDocument(entity, answer, roster) {
2658
2641
  const notes = [];
@@ -2747,9 +2730,11 @@ function characterDocument(entity, answer, roster) {
2747
2730
  }
2748
2731
  put(knowledge, "exits", exits);
2749
2732
  put(document, "knowledge", Object.keys(knowledge).length === 0 ? void 0 : knowledge);
2733
+ const carried = [...new Set(list(answer["carries"]))].slice(0, MAX_CARRIED);
2750
2734
  return {
2751
2735
  document,
2752
- notes
2736
+ notes,
2737
+ ...carried.length === 0 ? {} : { carried }
2753
2738
  };
2754
2739
  }
2755
2740
  const PLACE_SCHEMA = {
@@ -3318,6 +3303,18 @@ async function extractEntities(ctx, card, items, classified, roster) {
3318
3303
  thing: "items"
3319
3304
  }[entity.kind]].push(built.document);
3320
3305
  }
3306
+ const itemIds = new Set(result.items.map((entry) => String(entry["id"])));
3307
+ for (const { entity, built } of entityResults) {
3308
+ if (entity.kind !== "character") continue;
3309
+ for (const name of built?.carried ?? []) {
3310
+ if (findEntity(roster, name, "thing") !== void 0 || result.items.some((entry) => norm(String(entry["name"])) === norm(name) && entry["held_by"] === entity.key)) continue;
3311
+ result.items.push({
3312
+ id: uniqueKey(slug(name, "thing"), itemIds),
3313
+ name,
3314
+ held_by: entity.key
3315
+ });
3316
+ }
3317
+ }
3321
3318
  const worldItems = items.filter((item) => statesWorldFacts(classified[item.id] ?? { roles: [] }));
3322
3319
  const taken = /* @__PURE__ */ new Set();
3323
3320
  const loreResults = await mapLimit(worldItems, ctx.concurrency, async (item, index) => {
@@ -3736,8 +3733,7 @@ async function extractVariables(ctx, card, items, classified, roster) {
3736
3733
  notes: found.flatMap((entry) => entry.notes)
3737
3734
  };
3738
3735
  }
3739
- //#endregion
3740
- //#region src/host/presets/presets.ts
3736
+ // src/host/presets/presets.ts
3741
3737
  const PRESETS_FOLDER = "presets";
3742
3738
  const PRESET_FILE = "preset.json";
3743
3739
  const NAME = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
@@ -3992,7 +3988,6 @@ async function createPresetFromGuidance(root, request, guidance, shipped = shipp
3992
3988
  });
3993
3989
  }
3994
3990
  }
3995
- //#endregion
3996
- export { writeChoices as $, isLeftOut as A, DEFAULT_SLOTS as At, readWorldPrompt as B, pruneMembers as C, parseLoreEdit as Ct, classifyItems as D, LORE_KINDS as Dt, buildRoster as E, parseThingEdit as Et, routeVerdicts as F, withPlayer as G, cleanText as H, yesAt as I, ImportStore as J, IMPORT_FOLDER as K, PROSE_PROMPTS as L, askYesNo as M, mergeReports as N, findEntity as O, LORE_SCOPES as Ot, noAt as P, readImportFolder as Q, deleteWorldPrompt as R, pruneLoreSubjects as S, parseFactionEdit as St, sourcesFor as T, parseRelationEdit as Tt, itemise as U, writeWorldPrompt as V, partsOf as W, openingText as X, PICTURE_FILE as Y, parseChoices as Z, extractStyle as _, parseCharacterFile as _t, isPresetName as a, variableProblems as at, pruneKnowledge as b, InvalidEditProblems as bt, presetDirectory as c, LOCATION_FILE_NAME as ct, savePresetFromWorld as d, SLOTS_FILE_NAME as dt, IMPORT_COMMAND as et, sha as f, parseItemFile as ft, extractEntities as g, CHARACTER_FILE_NAME as gt, emptyExtracted as h, parseFactionFile as ht, deletePreset as i, parseVariablesFile as it, announceProblem as j, INTENT_STATUSES as jt, ROLES as k, WEEKDAY_NAMES as kt, readPreset as l, parseLocationFile as lt, STANDING_PROMPT as m, FACTION_FILE_NAME as mt, createPresetFromGuidance as n, VARIABLES_FILE_NAME as nt, listPresets as o, LORE_FILE_NAME as ot, updatePresetInfo as p, parseSlotsFile as pt, ImportNotFoundError as q, createPresetFromShipped as r, loadVariables as rt, loadPreset as s, parseLoreFile as st, PRESET_FILE as t, parseImportCommand as tt, reservePreset as u, ITEM_FILE_NAME as ut, extractStyleFrom as v, readVariableValues as vt, pruneRelationships as w, parsePlaceEdit as wt, pruneLinks as x, parseCharacterEdit as xt, extractVariables as y, readIdentifier as yt, listWorldPrompts as z };
3991
+ export { ImportNotFoundError as $, sourcesFor as A, parsePlaceEdit as At, noAt as B, inert as C, parseCharacterFile as Ct, pruneLoreSubjects as D, parseCharacterEdit as Dt, pruneLinks as E, InvalidEditProblems as Et, isLeftOut as F, WEEKDAY_NAMES as Ft, listWorldPrompts as G, yesAt as H, announceProblem as I, DEFAULT_SLOTS as It, cleanText as J, readWorldPrompt as K, askYesNo as L, INTENT_STATUSES as Lt, classifyItems as M, parseThingEdit as Mt, findEntity as N, LORE_KINDS as Nt, pruneMembers as O, parseFactionEdit as Ot, ROLES as P, LORE_SCOPES as Pt, IMPORT_FOLDER as Q, mergeReports as R, extractVariables as S, CHARACTER_FILE_NAME as St, pruneKnowledge as T, readIdentifier as Tt, PROSE_PROMPTS as U, routeVerdicts as V, deleteWorldPrompt as W, partsOf as X, itemise as Y, withPlayer as Z, characterDocument as _, SLOTS_FILE_NAME as _t, isPresetName as a, writeChoices as at, extractStyle as b, FACTION_FILE_NAME as bt, presetDirectory as c, VARIABLES_FILE_NAME as ct, savePresetFromWorld as d, variableProblems as dt, ImportStore as et, sha as f, LORE_FILE_NAME as ft, asWritten as g, ITEM_FILE_NAME as gt, addLore as h, parseLocationFile as ht, deletePreset as i, readImportFolder as it, buildRoster as j, parseRelationEdit as jt, pruneRelationships as k, parseLoreEdit as kt, readPreset as l, loadVariables as lt, STANDING_PROMPT as m, LOCATION_FILE_NAME as mt, createPresetFromGuidance as n, openingText as nt, listPresets as o, IMPORT_COMMAND as ot, updatePresetInfo as p, parseLoreFile as pt, writeWorldPrompt as q, createPresetFromShipped as r, parseChoices as rt, loadPreset as s, parseImportCommand as st, PRESET_FILE as t, PICTURE_FILE as tt, reservePreset as u, parseVariablesFile as ut, emptyExtracted as v, parseItemFile as vt, loreDocuments as w, readVariableValues as wt, extractStyleFrom as x, parseFactionFile as xt, extractEntities as y, parseSlotsFile as yt, modeFor as z };
3997
3992
 
3998
- //# sourceMappingURL=presets-MwOSMMyu.js.map
3993
+ //# sourceMappingURL=presets-HB8kJTaE.js.map
@@ -1,15 +1,15 @@
1
- import { o as roleplaySessionOf, t as promptFor } from "./access-DtOxFKBK.js";
2
- import { F as routeVerdicts, I as yesAt, M as askYesNo, N as mergeReports, P as noAt, f as sha, j as announceProblem, o as listPresets, s as loadPreset } from "./presets-MwOSMMyu.js";
3
- import { D as describeTime, O as describeWhen, Z as PROMPTS_FOLDER, et as inheritPrompts, j as answerLimits, z as wrongLanguage } from "./hooks-BQCzgggH.js";
4
- import { i as translator, r as languageOf, t as trimCharacters } from "./text-BzudpQLS.js";
5
- import { a as childTrace, c as runChild, n as childModel, r as childSampling, v as estimateAnswer } from "./child-D6mpkkCE.js";
6
- import { s as inheritImages } from "./library-zI-2tG7h.js";
7
- import { i as inheritPacks } from "./packs-Cv8hanXJ.js";
1
+ import { o as roleplaySessionOf, t as promptFor } from "./access-CfQWbNZP.js";
2
+ import { B as noAt, H as yesAt, I as announceProblem, L as askYesNo, R as mergeReports, V as routeVerdicts, f as sha, o as listPresets, s as loadPreset } from "./presets-HB8kJTaE.js";
3
+ import { A as answerLimits, D as describeWhen, E as describeTime, R as wrongLanguage, Z as PROMPTS_FOLDER, et as inheritPrompts } from "./hooks-rQTTeOC4.js";
4
+ import { i as translator, r as languageOf, t as trimCharacters } from "./text-DyRN4nDP.js";
5
+ import { a as childTrace, c as runChild, n as childModel, r as childSampling, v as estimateAnswer } from "./child-lYYeOwl2.js";
6
+ import { s as inheritImages } from "./library-Dfu0dgRj.js";
7
+ import { i as inheritPacks } from "./packs-DIj5BEfq.js";
8
8
  import { dirname, join } from "node:path";
9
9
  import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
10
10
  import { createUserMessage } from "@deepseek-ai/dsh-llm";
11
11
  import { MINUTE, characterKey, describeDuration, locationKey, mentioned, overlap, sessionDatabase, sessionFolder, tokens } from "@dsh-agentic-roleplay/state";
12
- //#region ../dsh-roleplay-model/src/memory.ts
12
+ // ../dsh-roleplay-model/src/memory.ts
13
13
  const MEMORY_KINDS = [
14
14
  "belief",
15
15
  "relationship",
@@ -21,8 +21,7 @@ const MEMORY_CONFIDENCES = [
21
21
  "likely",
22
22
  "sure"
23
23
  ];
24
- //#endregion
25
- //#region src/host/orchestration/referent.ts
24
+ // src/host/orchestration/referent.ts
26
25
  /**
27
26
  * 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.
28
27
  * 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.
@@ -31,8 +30,7 @@ function referent(character) {
31
30
  const mark = [character.pronouns, character.gender].find((text) => text !== void 0 && text.trim() !== "")?.trim();
32
31
  return mark === void 0 ? character.name : `${character.name} (${mark})`;
33
32
  }
34
- //#endregion
35
- //#region src/host/orchestration/defaults.ts
33
+ // src/host/orchestration/defaults.ts
36
34
  const ENGLISH = translator("en");
37
35
  /** What the instructions say about how long each part of a character's answer may run. */
38
36
  const limitVariables = (language) => {
@@ -595,8 +593,7 @@ function defaultBoundaries() {
595
593
  sceneContext: castSummary
596
594
  };
597
595
  }
598
- //#endregion
599
- //#region src/host/presets/apply.ts
596
+ // src/host/presets/apply.ts
600
597
  /** Which preset a story's prompts came from, and what each copied file held: kept beside the story's database, so that a story can tell its copies from its own edits. */
601
598
  const PRESET_RECORD = "preset.json";
602
599
  const promptFile = (folder, path) => join(folder, PROMPTS_FOLDER, ...path.split("/"));
@@ -714,8 +711,7 @@ function inheritPreset(from, to) {
714
711
  const file = join(from, PRESET_RECORD);
715
712
  if (existsSync(file)) copyFileSync(file, join(to, PRESET_RECORD));
716
713
  }
717
- //#endregion
718
- //#region src/shared/timeline.ts
714
+ // src/shared/timeline.ts
719
715
  const emptyTimeline = () => ({
720
716
  version: 1,
721
717
  head: null,
@@ -766,8 +762,7 @@ function noticeText(node) {
766
762
  const ruling = ooc === void 0 ? "" : ooc.question === true ? `\nThe question was answered out of character: ${ooc.note}` : `\nThe command was ruled ${ooc.legal ? "legal" : "illegal and refused"}: ${ooc.note}`;
767
763
  return `The story, as it went earlier (restored):\nThe player said: ${node.player}${ruling}\nIt was told to the player:\n${told}`;
768
764
  }
769
- //#endregion
770
- //#region src/host/timeline/file.ts
765
+ // src/host/timeline/file.ts
771
766
  const TIMELINE_FILE = "timeline.json";
772
767
  function isNode(value) {
773
768
  if (typeof value !== "object" || value === null) return false;
@@ -797,8 +792,7 @@ function writeTimeline(folder, timeline) {
797
792
  writeFileSync(aside, JSON.stringify(timeline, null, 2));
798
793
  renameSync(aside, target);
799
794
  }
800
- //#endregion
801
- //#region src/host/timeline/branch.ts
795
+ // src/host/timeline/branch.ts
802
796
  var BranchError = class extends Error {};
803
797
  /**
804
798
  * What a branch of a story cut at a log event keeps of the timeline: the turns that ended at or before it, standing at the one
@@ -848,8 +842,7 @@ function branchName(name) {
848
842
  const next = start === trimmed.length ? `${name} 2` : `${trimmed.slice(0, start)}${Number(trimmed.slice(start)) + 1}`;
849
843
  return next.length > 200 ? `${[...name].slice(0, 190).join("").trimEnd()} 2` : next;
850
844
  }
851
- //#endregion
852
- //#region src/host/timeline/plan.ts
845
+ // src/host/timeline/plan.ts
853
846
  /**
854
847
  * Where the model's conversation has to be changed so that it carries the turns from the first to `target`, and no others.
855
848
  * A turn is on the conversation when its own message is, or the notice that stands for it. The turns that stay are the longest
@@ -905,8 +898,7 @@ function planMove(timeline, target, surface) {
905
898
  inject: path.slice(keptCount)
906
899
  };
907
900
  }
908
- //#endregion
909
- //#region src/host/timeline/service.ts
901
+ // src/host/timeline/service.ts
910
902
  /** The text of the marker that stands for the turns it replaces: never empty, as a model service may refuse an empty message. */
911
903
  const MARKER_TEXT = "(empty message)";
912
904
  /** A turn that has not ended does not know yet where its own message is in the log. */
@@ -1127,8 +1119,7 @@ var Timelines = class {
1127
1119
  return childrenOf(timeline, timeline.head);
1128
1120
  }
1129
1121
  };
1130
- //#endregion
1131
- //#region src/host/orchestration/whereabouts.ts
1122
+ // src/host/orchestration/whereabouts.ts
1132
1123
  const within = (inner, outer, places) => {
1133
1124
  const byId = new Map(places.map((place) => [place.id, place]));
1134
1125
  const seen = /* @__PURE__ */ new Set();
@@ -1154,8 +1145,7 @@ function whereabouts(places, here, at) {
1154
1145
  here
1155
1146
  };
1156
1147
  }
1157
- //#endregion
1158
- //#region src/host/memory/reflection.ts
1148
+ // src/host/memory/reflection.ts
1159
1149
  const LAST_KEY = "reflection.last";
1160
1150
  const CURSOR_KEY = "reflection.cursor";
1161
1151
  const ANCHOR_KEY = "reflection.anchor";
@@ -2036,7 +2026,6 @@ function memoryReflector(deps) {
2036
2026
  return { characters };
2037
2027
  } };
2038
2028
  }
2039
- //#endregion
2040
2029
  export { referent as _, whereabouts as a, readTimeline as c, copyPreset as d, presetStatus as f, sameWords as g, defaultBoundaries as h, reflectionStatus as i, writeTimeline as l, switchPreset as m, memoryReflector as n, TimelineError as o, recordPreset as p, recordFailure as r, Timelines as s, dueReflection as t, pathTo as u };
2041
2030
 
2042
- //# sourceMappingURL=reflection-zSaMsjKj.js.map
2031
+ //# sourceMappingURL=reflection-Dg1xtOTW.js.map
@@ -1,4 +1,4 @@
1
- //#region ../dsh-roleplay-model/src/messages-zh.ts
1
+ // ../dsh-roleplay-model/src/messages-zh.ts
2
2
  /** The Chinese of the texts built in code, by the English that stands in the code. A `{name}` is filled in and must stand in both. */
3
3
  const ZH = {
4
4
  ", ": ",",
@@ -249,8 +249,9 @@ const ZH = {
249
249
  "{label}: how people are made up": "{label}:人物如何生成",
250
250
  "{label}: rules and mechanics": "{label}:规则与机制",
251
251
  "Already declared (do not declare them again):": "已经声明过的(不要重复声明):",
252
+ "The world itself brings in anyone this command calls for, after this turn: do not make them up yourself with expand_world.": "这个指令要求带入的人,由世界自己在本回合之后带入:不要自己用 expand_world 去造。",
252
253
  "Passages about making people up:": "关于凭空生成人物的段落:",
253
- "The player used the world's command /{word}: {description}": "玩家使用了这个世界的指令 /{word}:{description}",
254
+ "The player used the world's command /{word}: {description} It is part of the story, not an out-of-character command: play it in the story. The world raises and lowers the command's own flag itself: never change it.": "玩家使用了这个世界的指令 /{word}:{description} 这是故事的一部分,不是角色外的指令:在故事中演绎它。世界会自己升起和放下这个指令的标记:不要去改它。",
254
255
  "All the pieces of this card, in order:": "这张卡的所有片段,按顺序:",
255
256
  "The standing rules of this world. Apply them on every turn:": "这个世界的常驻规则。每个回合都要遵守:",
256
257
  "The instructions of the card:": "卡片的指令:",
@@ -268,8 +269,7 @@ const ZH = {
268
269
  "Description:": "描述:",
269
270
  "Creator's notes:": "作者备注:"
270
271
  };
271
- //#endregion
272
- //#region ../dsh-roleplay-model/src/messages.ts
272
+ // ../dsh-roleplay-model/src/messages.ts
273
273
  /** The language a setting such as `zh-CN` or `en` stands for; English when it is none that is known. */
274
274
  function languageOf(code) {
275
275
  return (code ?? "").trim().toLowerCase().startsWith("zh") ? "zh" : "en";
@@ -284,8 +284,7 @@ function translator(language) {
284
284
  const catalogue = language === "en" ? void 0 : CATALOGUES[language];
285
285
  return (text, values) => fill(catalogue?.[text] ?? text, values);
286
286
  }
287
- //#endregion
288
- //#region src/shared/text.ts
287
+ // src/shared/text.ts
289
288
  /** Remove characters from either end without a backtracking regular expression. */
290
289
  function trimCharacters(value, characters, edge = "both") {
291
290
  let start = 0;
@@ -299,7 +298,6 @@ function withoutExtension(value) {
299
298
  const dot = value.lastIndexOf(".");
300
299
  return dot < 0 ? value : value.slice(0, dot);
301
300
  }
302
- //#endregion
303
301
  export { translator as i, withoutExtension as n, languageOf as r, trimCharacters as t };
304
302
 
305
- //# sourceMappingURL=text-BzudpQLS.js.map
303
+ //# sourceMappingURL=text-DyRN4nDP.js.map
@@ -1,11 +1,7 @@
1
- import { f as guardRepeatedCalls } from "./hooks-BQCzgggH.js";
2
- import { _ as finishOf, g as cutOff } from "./child-D6mpkkCE.js";
1
+ import { _ as finishOf, g as cutOff } from "./child-lYYeOwl2.js";
2
+ import { d as guardRepeatedCalls } from "./hooks-rQTTeOC4.js";
3
3
  import { ReasoningEffortId, createUserMessage } from "@deepseek-ai/dsh-llm";
4
- //#region src/host/authoring/turn-guard.ts
5
- /** Times one turn is steered back after a reply was cut off: a model that rambles again after being told not to will not stop because it is told once more. */
6
- const MAX_NUDGES = 6;
7
- /** How often one turn may make exactly the same call: an assistant that repeats a call past this is looping (found live: one create-and-list pair 47 times in one review), not working. */
8
- const MAX_SAME_CALL = 3;
4
+ // src/host/authoring/turn-guard.ts
9
5
  /**
10
6
  * What keeps an authoring assistant (a chat that edits a world, a preset or a lorebook) from running away, besides the limit on what one request may write.
11
7
  * - Its thinking level is the one the settings name for these assistants, when its model offers that level: thinking without end filled the whole request and left a turn with nothing done.
@@ -15,7 +11,7 @@ const MAX_SAME_CALL = 3;
15
11
  */
16
12
  function guardAuthoringTurns(ctx, prompts, languageOf, reasoning = () => "") {
17
13
  const nudged = /* @__PURE__ */ new Map();
18
- guardRepeatedCalls(ctx, (exec) => exec.agent === void 0 ? void 0 : languageOf(exec.agent.session.id), MAX_SAME_CALL);
14
+ guardRepeatedCalls(ctx, (exec) => exec.agent === void 0 ? void 0 : languageOf(exec.agent.session.id), 3);
19
15
  ctx.on("agent/request", async (payload, next) => {
20
16
  const config = await next();
21
17
  const level = reasoning();
@@ -40,7 +36,7 @@ function guardAuthoringTurns(ctx, prompts, languageOf, reasoning = () => "") {
40
36
  nudged.delete(key);
41
37
  return;
42
38
  }
43
- if (told >= MAX_NUDGES) return;
39
+ if (told >= 6) return;
44
40
  nudged.set(key, told + 1);
45
41
  agent.steer(createUserMessage({
46
42
  content: [{
@@ -51,7 +47,6 @@ function guardAuthoringTurns(ctx, prompts, languageOf, reasoning = () => "") {
51
47
  }));
52
48
  });
53
49
  }
54
- //#endregion
55
50
  export { guardAuthoringTurns as t };
56
51
 
57
- //# sourceMappingURL=turn-guard-Cv8pfHEA.js.map
52
+ //# sourceMappingURL=turn-guard-g_hDn0jR.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dsh-agentic-roleplay/core",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
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",
@@ -76,39 +76,39 @@
76
76
  "@deepseek-ai/schemastery": "^3.18.5"
77
77
  },
78
78
  "dependencies": {
79
- "@dsh-agentic-roleplay/state": "0.8.1",
79
+ "@dsh-agentic-roleplay/state": "0.8.2",
80
80
  "@dsh-ai-providers/core": "^0.5.0"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@deepseek-ai/cordis": "^4.0.5",
84
84
  "@deepseek-ai/cordis-plugin-loader": "^1.0.6",
85
- "@deepseek-ai/dsh-agent": "0.2.1-rc.3",
86
- "@deepseek-ai/dsh-agent-loop": "0.2.1-rc.3",
87
- "@deepseek-ai/dsh-api-remotes": "0.2.1-rc.3",
88
- "@deepseek-ai/dsh-client-locale": "0.2.1-rc.3",
89
- "@deepseek-ai/dsh-client-store": "0.2.1-rc.3",
90
- "@deepseek-ai/dsh-client-ui-chat": "0.2.1-rc.3",
91
- "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-rc.3",
92
- "@deepseek-ai/dsh-client-ui-layout": "0.2.1-rc.3",
93
- "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.3",
94
- "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.3",
95
- "@deepseek-ai/dsh-client-ui-session": "0.2.1-rc.3",
96
- "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.3",
97
- "@deepseek-ai/dsh-client-ui-sidebar": "0.2.1-rc.3",
98
- "@deepseek-ai/dsh-client-ui-sidebar-right": "0.2.1-rc.3",
99
- "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.3",
100
- "@deepseek-ai/dsh-compaction": "0.2.1-rc.3",
101
- "@deepseek-ai/dsh-compaction-basic": "0.2.1-rc.3",
102
- "@deepseek-ai/dsh-host-webserver": "0.2.1-rc.3",
103
- "@deepseek-ai/dsh-llm": "0.2.1-rc.3",
104
- "@deepseek-ai/dsh-session": "0.2.1-rc.3",
105
- "@deepseek-ai/dsh-session-projection": "0.2.1-rc.3",
106
- "@deepseek-ai/dsh-subagent": "0.2.1-rc.3",
107
- "@deepseek-ai/dsh-subagent-spawn-in-process": "0.2.1-rc.3",
108
- "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.3",
109
- "@deepseek-ai/dsh-token-meter": "0.2.1-rc.3",
110
- "@deepseek-ai/dsh-tools": "0.2.1-rc.3",
111
- "@deepseek-ai/dsh-user-approval": "0.2.1-rc.3",
85
+ "@deepseek-ai/dsh-agent": "0.2.1-rc.5",
86
+ "@deepseek-ai/dsh-agent-loop": "0.2.1-rc.5",
87
+ "@deepseek-ai/dsh-api-remotes": "0.2.1-rc.5",
88
+ "@deepseek-ai/dsh-client-locale": "0.2.1-rc.5",
89
+ "@deepseek-ai/dsh-client-store": "0.2.1-rc.5",
90
+ "@deepseek-ai/dsh-client-ui-chat": "0.2.1-rc.5",
91
+ "@deepseek-ai/dsh-client-ui-conversation": "0.2.1-rc.5",
92
+ "@deepseek-ai/dsh-client-ui-layout": "0.2.1-rc.5",
93
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.5",
94
+ "@deepseek-ai/dsh-client-ui-renderer": "0.2.1-rc.5",
95
+ "@deepseek-ai/dsh-client-ui-session": "0.2.1-rc.5",
96
+ "@deepseek-ai/dsh-client-ui-settings": "0.2.1-rc.5",
97
+ "@deepseek-ai/dsh-client-ui-sidebar": "0.2.1-rc.5",
98
+ "@deepseek-ai/dsh-client-ui-sidebar-right": "0.2.1-rc.5",
99
+ "@deepseek-ai/dsh-client-ui-slots": "0.2.1-rc.5",
100
+ "@deepseek-ai/dsh-compaction": "0.2.1-rc.5",
101
+ "@deepseek-ai/dsh-compaction-basic": "0.2.1-rc.5",
102
+ "@deepseek-ai/dsh-host-webserver": "0.2.1-rc.5",
103
+ "@deepseek-ai/dsh-llm": "0.2.1-rc.5",
104
+ "@deepseek-ai/dsh-session": "0.2.1-rc.5",
105
+ "@deepseek-ai/dsh-session-projection": "0.2.1-rc.5",
106
+ "@deepseek-ai/dsh-subagent": "0.2.1-rc.5",
107
+ "@deepseek-ai/dsh-subagent-spawn-in-process": "0.2.1-rc.5",
108
+ "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.5",
109
+ "@deepseek-ai/dsh-token-meter": "0.2.1-rc.5",
110
+ "@deepseek-ai/dsh-tools": "0.2.1-rc.5",
111
+ "@deepseek-ai/dsh-user-approval": "0.2.1-rc.5",
112
112
  "@deepseek-ai/schemastery": "^3.18.5",
113
113
  "@types/node": "^22.20.0",
114
114
  "@types/react": "~18.3.1",
@@ -6,7 +6,7 @@ mechanisms: each time the card says that someone new is to be made, give one ent
6
6
  - name: a short name.
7
7
  - command: the word above that starts it, or empty.
8
8
  - happens: when the card names no command, one sentence that says what must happen in the story for it to start, written as an event in the past tense ("The player's character brings a new follower into the cult"), never as a state ("there are few followers"). Empty when a command starts it.
9
- - need: the reason the world author is asked to make someone: what kind of person, in a sentence, as the card says.
9
+ - need: arrival when the new person comes into the scene from outside, introduction when someone who is already around is brought into play.
10
10
  - text: the instruction the world author gets, in your own words from the card's: what the new person must be like. Write [draw] where one drawn option goes, when the card gives a list of kinds or situations to choose from; otherwise leave it out.
11
11
  - options: the list of kinds or situations to choose one from, each as the card writes it; empty when the card gives none.
12
12
 
@@ -4,4 +4,5 @@ You write one character of a role-playing world, from pieces of a character card
4
4
  - start: how they are when the story begins: what others can see (public_state), what they think and feel (inner_state), what they are doing (activity), the place they are in (location: a name from the list of places) and where in it (position, in words). Only when the pieces say.
5
5
  - goals: what they want or are driving at, when the pieces say. relationships: how they stand towards others of the list: with (a name from the list of characters), label (a word or two), summary.
6
6
  - tier: principal for someone the story is about, supporting for a recurring character, background for someone who only appears. kind: person, or group for a crowd or party that acts as one.
7
+ - carries: the things they have on them at the start (a weapon, a tool, a document, a keepsake), by the name the text gives them; things they only know of go in knows, not here.
7
8
  - knows: the places and things of the lists that they know of, when the pieces say they do (places they have been to or live by, things they own, carry or have seen); not everything of the world, and not what they could only have learned later. ways: ways between two places of the list (from, to) that they know how to take, when the pieces say they have used or been shown them.
@@ -6,7 +6,7 @@ mechanisms(机制):卡片每说到一次要生成新的人物,就给出
6
6
  - name:简短的名称。
7
7
  - command:启动它的上面那个词,没有就留空。
8
8
  - happens:卡片没有指令时,用一句话说明故事里必须发生什么才会启动它,写成已经发生的事件(“玩家的角色把一个新信徒带进了教团”),不要写成状态(“信徒很少”)。由指令启动时留空。
9
- - need:请世界作者生成人物的原因:什么样的人,一句话,按卡片的说法。
9
+ - need:新人物从外面进入场景时写 arrival,已经在场的某个人被带入故事时写 introduction。
10
10
  - text:给世界作者的指示,根据卡片的意思用你自己的话写:新人物必须是什么样。当卡片给出了可供挑选的类型或情境列表时,在应放入抽出选项的位置写 [draw];没有列表就不要写。
11
11
  - options:可供挑选的类型或情境列表,每项按卡片的写法;卡片没有给出时留空。
12
12
 
@@ -4,4 +4,5 @@
4
4
  - start:故事开始时他们的状态:别人看得到的(public_state)、他们所想所感(inner_state)、他们正在做的事(activity)、所在的地点(location:地点清单中的一个名字)以及在其中的具体位置(position,用文字描述)。只有当段落说了才填。
5
5
  - goals:他们想要或追求的东西,段落说了才填。relationships:他们与清单中其他人的关系:with(角色清单中的一个名字)、label(一两个词)、summary。
6
6
  - tier:故事围绕的人物用 principal,反复出现的角色用 supporting,只是偶尔出场的用 background。kind:person,或者对作为整体行动的人群、队伍用 group。
7
+ - carries:开始时带在身上的东西(武器、工具、文件、纪念物),用文本给的名字;只是知道的东西写在 knows,不写在这里。
7
8
  - knows:清单中他们知道的地点和物品,只有当段落说明他们知道时才填(去过或住在附近的地方、拥有、携带或见过的物品);不是世界里的一切,也不包括他们日后才会得知的东西。ways:清单中两个地点之间他们知道怎么走的路线(from、to),只有当段落说明他们走过或被指过路时才填。