@dsh-agentic-roleplay/core 0.11.1 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/lib/{access-Md1YTSX1.js → access-DifaiHrI.js} +3 -15
  2. package/lib/{authoring-tools-BFdw7ahj.js → authoring-tools-VOaXzr_R.js} +58 -766
  3. package/lib/authoring.js +136 -13
  4. package/lib/{child-C9nPIy9j.js → child-DzZ-aI6k.js} +130 -2
  5. package/lib/client.js +17093 -2269
  6. package/lib/client.js.map +1 -1
  7. package/lib/compaction.js +3 -3
  8. package/lib/dev-context-Bdm-eVer.js +40 -0
  9. package/lib/doctor.js +5 -3
  10. package/lib/{gallery-BWHmjogd.js → gallery-Ctz-UoFk.js} +3 -3
  11. package/lib/{generator-QCdm8nUh.js → generator-Cv6WWmZT.js} +2 -2
  12. package/lib/helper.js +15 -1
  13. package/lib/{hooks-C2U1-8ur.js → hooks-BdR3mBeM.js} +751 -344
  14. package/lib/images.js +4 -4
  15. package/lib/index.js +342 -463
  16. package/lib/jail-Cp4zEfip.js +107 -0
  17. package/lib/{library-4zmCAshR.js → library-BU2A_Dx8.js} +3 -3
  18. package/lib/{lorebook-author-tools-Bjfjt3bg.js → lorebook-author-tools-DUKcQu8P.js} +20 -7
  19. package/lib/lorebook-authoring.js +12 -5
  20. package/lib/{narration-b_VBEUWn.js → narration-CDsJ5wxH.js} +29 -2
  21. package/lib/orchestration.js +615 -48
  22. package/lib/{pack-jail-Ci9bIeDI.js → pack-jail-CzHQu0n3.js} +559 -23
  23. package/lib/{packs-CYkozh8Q.js → packs-BZ-45J4-.js} +2 -2
  24. package/lib/{presenter-agent-CqkAL03Q.js → presenter-agent-C2ZkoxZu.js} +9 -9
  25. package/lib/{preset-B-35yUmt.js → preset-BPnRPW-1.js} +4 -4
  26. package/lib/{preset-author-tools-BUymqZM5.js → preset-author-tools-DBqPwn-o.js} +9 -8
  27. package/lib/preset-authoring.js +11 -6
  28. package/lib/{reflection-B9N0z3KY.js → reflection-Cuy0YLv0.js} +22 -16
  29. package/lib/{presets-_U-xroo0.js → serial-BZNeK57v.js} +1305 -331
  30. package/lib/service-mRKwpWjX.js +140 -0
  31. package/lib/{text-C2AGl7Je.js → text-Dfv8S8eq.js} +27 -2
  32. package/lib/{turn-guard-C0M3rXEN.js → turn-guard-xaFxYc1T.js} +3 -3
  33. package/locale/de.json +6 -0
  34. package/locale/en.json +6 -0
  35. package/locale/es.json +6 -0
  36. package/locale/fr.json +6 -0
  37. package/locale/ja.json +6 -0
  38. package/locale/pt.json +6 -0
  39. package/locale/ru.json +6 -0
  40. package/locale/zh.json +6 -0
  41. package/package.json +34 -34
  42. package/prompts/en/import/finish-ok.md +1 -1
  43. package/prompts/en/import/generator.md +1 -1
  44. package/prompts/en/import/style.md +2 -1
  45. package/prompts/en/import/variables.md +2 -1
  46. package/prompts/en/roleplay/character-lookup.md +1 -1
  47. package/prompts/en/roleplay/decide-errand.md +1 -0
  48. package/prompts/en/roleplay/decide-message.md +1 -0
  49. package/prompts/en/roleplay/dream.md +1 -0
  50. package/prompts/en/roleplay/gate-repeat.md +1 -0
  51. package/prompts/en/world/procedure.md +1 -1
  52. package/prompts/zh/import/finish-ok.md +1 -1
  53. package/prompts/zh/import/generator.md +1 -1
  54. package/prompts/zh/import/style.md +2 -1
  55. package/prompts/zh/import/variables.md +2 -1
  56. package/prompts/zh/roleplay/character-lookup.md +1 -1
  57. package/prompts/zh/roleplay/decide-errand.md +1 -0
  58. package/prompts/zh/roleplay/decide-message.md +1 -0
  59. package/prompts/zh/roleplay/dream.md +1 -0
  60. package/prompts/zh/roleplay/gate-repeat.md +1 -0
  61. package/prompts/zh/world/procedure.md +1 -1
@@ -1,4 +1,4 @@
1
- import { K as Reader } from "./hooks-C2U1-8ur.js";
1
+ import { K as Reader } from "./hooks-BdR3mBeM.js";
2
2
  import { dirname, extname, join, posix, sep } from "node:path";
3
3
  import { copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, renameSync } from "node:fs";
4
4
  import { createHash } from "node:crypto";
@@ -836,4 +836,4 @@ function anyTab(bases) {
836
836
  }
837
837
  export { API_PREFIX as _, packIds as a, describePack as c, packPath as d, readPack as f, SURFACE_NAMES as g, PACK_MEDIA_TYPES as h, inheritPacks as i, 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 };
838
838
 
839
- //# sourceMappingURL=packs-CYkozh8Q.js.map
839
+ //# sourceMappingURL=packs-BZ-45J4-.js.map
@@ -1,9 +1,9 @@
1
- import { n as atomicWrite, t as promptFor } from "./access-Md1YTSX1.js";
2
- import { l as runChild } from "./child-C9nPIy9j.js";
3
- import { n as generateTransientImage, t as generateReferenceImage } from "./generator-QCdm8nUh.js";
4
- import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-BWHmjogd.js";
5
- import { c as nextSceneSerial, u as referenceImagePath } from "./library-4zmCAshR.js";
6
- import { join, relative } from "node:path";
1
+ import { n as atomicWrite, t as promptFor } from "./access-DifaiHrI.js";
2
+ import { l as runChild } from "./child-DzZ-aI6k.js";
3
+ import { n as generateTransientImage, t as generateReferenceImage } from "./generator-Cv6WWmZT.js";
4
+ import { i as updateImage, n as galleryFile, r as listGallery } from "./gallery-Ctz-UoFk.js";
5
+ import { c as nextSceneSerial, u as referenceImagePath } from "./library-BU2A_Dx8.js";
6
+ import { join, relative, sep } from "node:path";
7
7
  import { characterKey, itemKey, locationKey } from "@dsh-agentic-roleplay/state";
8
8
  import { existsSync } from "node:fs";
9
9
  import { createHash } from "node:crypto";
@@ -450,7 +450,7 @@ function imageTools(deps) {
450
450
  ...args.art_direction === void 0 ? {} : { artDirection: args.art_direction },
451
451
  ...deps.signal === void 0 ? {} : { signal: deps.signal }
452
452
  });
453
- const local = relative(deps.root, path);
453
+ const local = relative(deps.root, path).split(sep).join("/");
454
454
  recorded.push(local);
455
455
  return { path: local };
456
456
  }
@@ -543,7 +543,7 @@ function imageTools(deps) {
543
543
  ...references.length === 0 ? {} : { references },
544
544
  ...deps.signal === void 0 ? {} : { signal: deps.signal }
545
545
  });
546
- const local = relative(deps.root, path);
546
+ const local = relative(deps.root, path).split(sep).join("/");
547
547
  recorded.push(local);
548
548
  return {
549
549
  path: local,
@@ -844,4 +844,4 @@ async function runImagePresenter(job) {
844
844
  }
845
845
  export { searchImages as a, presentedFor as c, findImages as i, interpretImage as n, tokensOf as o, imageTools as r, present as s, runImagePresenter as t };
846
846
 
847
- //# sourceMappingURL=presenter-agent-CqkAL03Q.js.map
847
+ //# sourceMappingURL=presenter-agent-C2ZkoxZu.js.map
@@ -1,6 +1,6 @@
1
- import { r as MAX_PREVIEW_TEXT, tn as ImportCardError } from "./authoring-tools-BFdw7ahj.js";
2
- import { u as SAMPLING_RANGES } from "./child-C9nPIy9j.js";
3
- import { Y as cleanText } from "./presets-_U-xroo0.js";
1
+ import { Rt as ImportCardError, r as MAX_PREVIEW_TEXT } from "./authoring-tools-VOaXzr_R.js";
2
+ import { p as SAMPLING_RANGES } from "./child-DzZ-aI6k.js";
3
+ import { gt as cleanText } from "./serial-BZNeK57v.js";
4
4
  // src/host/import/preset.ts
5
5
  /** The older preset layout keeps its texts under fixed keys. */
6
6
  const LEGACY_KEYS = [
@@ -239,4 +239,4 @@ function selectPrompts(file, enabled, keepSampling) {
239
239
  }
240
240
  export { readPreset as n, selectPrompts as r, previewPreset as t };
241
241
 
242
- //# sourceMappingURL=preset-B-35yUmt.js.map
242
+ //# sourceMappingURL=preset-BPnRPW-1.js.map
@@ -1,9 +1,9 @@
1
- import "./access-Md1YTSX1.js";
2
- import { $ as IMPORT_FOLDER, G as deleteWorldPrompt, J as writeWorldPrompt, K as listWorldPrompts, Q as withPlayer, W as PROSE_PROMPTS, c as presetDirectory, l as readPreset, p as updatePresetInfo, q as readWorldPrompt, t as PRESET_FILE, x as extractStyleFrom } from "./presets-_U-xroo0.js";
3
- import { n as readPreset$1 } from "./preset-B-35yUmt.js";
4
- import { i as contextOf } from "./authoring-tools-BFdw7ahj.js";
5
- import { i as translator, r as languageOf } from "./text-C2AGl7Je.js";
6
- import { et as languageOf$1, it as shippedPromptsDirectory, rt as shippedLanguages } from "./hooks-C2U1-8ur.js";
1
+ import "./access-DifaiHrI.js";
2
+ import { $ as deleteWorldPrompt, K as presetDirectory, Q as PROSE_PROMPTS, Z as updatePresetInfo, bt as IMPORT_FOLDER, et as listWorldPrompts, l as extractStyleFrom, nt as writeWorldPrompt, q as readPreset, tt as readWorldPrompt, yt as withPlayer, z as PRESET_FILE } from "./serial-BZNeK57v.js";
3
+ import { n as readPreset$1 } from "./preset-BPnRPW-1.js";
4
+ import { i as contextOf } from "./authoring-tools-VOaXzr_R.js";
5
+ import { i as translator, r as languageOf } from "./text-Dfv8S8eq.js";
6
+ import { et as languageOf$1, it as shippedPromptsDirectory, rt as shippedLanguages } from "./hooks-BdR3mBeM.js";
7
7
  import { join } from "node:path";
8
8
  import { existsSync } from "node:fs";
9
9
  import { readFile, rm } from "node:fs/promises";
@@ -234,10 +234,11 @@ function presetAuthorTools(reader, settings, prompting, shipped = shippedPrompts
234
234
  ];
235
235
  }
236
236
  /** Every change to a preset is put to the person; the first import into an empty preset only fills it, so it is not. */
237
- async function presetApproval(exec, next, carries) {
237
+ async function presetApproval(exec, next, carries, auto = () => false) {
238
238
  if (!PRESET_MUTATION_TOOLS.includes(exec.name) || exec.agent === void 0 || presetOfChat(exec.agent.session.id) === void 0) return await next();
239
239
  const args = exec.arguments;
240
240
  const chat = exec.agent.session.id;
241
+ if (auto() && !isRulesPrompt(args["id"])) return await next();
241
242
  if (exec.name === "import_narration_preset") {
242
243
  if (!carries(chat)) return await next();
243
244
  return {
@@ -278,4 +279,4 @@ async function presetApproval(exec, next, carries) {
278
279
  }
279
280
  export { presetChatSessionId as a, presetAuthorTools as i, narrationImportMessage as n, presetOfChat as o, presetApproval as r, PresetReader as t };
280
281
 
281
- //# sourceMappingURL=preset-author-tools-BUymqZM5.js.map
282
+ //# sourceMappingURL=preset-author-tools-DBqPwn-o.js.map
@@ -1,8 +1,9 @@
1
- import { n as limitAuthoringAgents } from "./authoring-tools-BFdw7ahj.js";
2
- import { t as guardAuthoringTurns } from "./turn-guard-C0M3rXEN.js";
3
- import { i as presetAuthorTools, o as presetOfChat, r as presetApproval, t as PresetReader } from "./preset-author-tools-BUymqZM5.js";
4
- import "./hooks-C2U1-8ur.js";
5
- import { c as presetDirectory } from "./presets-_U-xroo0.js";
1
+ import { n as limitAuthoringAgents } from "./authoring-tools-VOaXzr_R.js";
2
+ import { t as guardAuthoringTurns } from "./turn-guard-xaFxYc1T.js";
3
+ import { t as silenceHarnessDevContext } from "./dev-context-Bdm-eVer.js";
4
+ import { i as presetAuthorTools, o as presetOfChat, r as presetApproval, t as PresetReader } from "./preset-author-tools-DBqPwn-o.js";
5
+ import "./hooks-BdR3mBeM.js";
6
+ import { K as presetDirectory } from "./serial-BZNeK57v.js";
6
7
  import { join } from "node:path";
7
8
  import { existsSync } from "node:fs";
8
9
  // src/preset-authoring.ts
@@ -18,6 +19,7 @@ const inject = [
18
19
  ];
19
20
  /** The preset authoring chat: reads and writes the prose prompts of one library preset, each write approved by the person. */
20
21
  function apply(ctx) {
22
+ silenceHarnessDevContext(ctx);
21
23
  const library = () => ctx.roleplayRoot.path;
22
24
  const reader = new PresetReader(library);
23
25
  const prompting = {
@@ -34,7 +36,10 @@ function apply(ctx) {
34
36
  const preset = presetOfChat(chat);
35
37
  return preset === void 0 ? void 0 : ctx.roleplayAuthoringLanguages.get(`preset:${preset}`);
36
38
  }, () => ctx.roleplayImport.settings.reasoning);
37
- ctx.on("tools/pre-execute", (exec, next) => presetApproval(exec, next, carries));
39
+ ctx.on("session/event", (session, event) => {
40
+ if (event.type === "turn/end" && session.header.origin !== "subagent" && presetOfChat(session.id) !== void 0) ctx.roleplayImport.turnEnded(session.id);
41
+ });
42
+ ctx.on("tools/pre-execute", (exec, next) => presetApproval(exec, next, carries, () => ctx.roleplayImport.settings.approval === "auto"));
38
43
  const languageOf = (context) => {
39
44
  const chat = context.agent?.session.id;
40
45
  const preset = chat === void 0 ? void 0 : presetOfChat(chat);
@@ -1,10 +1,10 @@
1
- import { l as roleplaySessionOf, t as promptFor } from "./access-Md1YTSX1.js";
2
- import { H as routeVerdicts, L as announceProblem, R as askYesNo, U as yesAt, V as noAt, f as sha, o as listPresets, s as loadPreset, z as mergeReports } from "./presets-_U-xroo0.js";
3
- import { $ as inheritPrompts, D as referent, I as wrongLanguage, X as PROMPTS_FOLDER, mt as describeWhen } from "./hooks-C2U1-8ur.js";
4
- import { i as translator, r as languageOf } from "./text-C2AGl7Je.js";
5
- import { T as estimateAnswer, a as childTrace, l as runChild, n as childModel, r as childSampling } from "./child-C9nPIy9j.js";
6
- import { s as inheritImages } from "./library-4zmCAshR.js";
7
- import { i as inheritPacks } from "./packs-CYkozh8Q.js";
1
+ import { O as estimateAnswer, a as childTrace, j as roleplaySessionOf, l as runChild, n as childModel, r as childSampling } from "./child-DzZ-aI6k.js";
2
+ import { A as routeVerdicts, D as mergeReports, E as askYesNo, G as loadPreset, T as announceProblem, W as listPresets, X as sha, j as yesAt, k as noAt, t as SerialQueue } from "./serial-BZNeK57v.js";
3
+ import { t as promptFor } from "./access-DifaiHrI.js";
4
+ import { $ as inheritPrompts, D as referent, I as wrongLanguage, X as PROMPTS_FOLDER, mt as describeWhen } from "./hooks-BdR3mBeM.js";
5
+ import { i as translator, r as languageOf } from "./text-Dfv8S8eq.js";
6
+ import { s as inheritImages } from "./library-BU2A_Dx8.js";
7
+ import { i as inheritPacks } from "./packs-BZ-45J4-.js";
8
8
  import { dirname, join } from "node:path";
9
9
  import { characterKey, locationKey, sessionDatabase, sessionFolder, tokens } from "@dsh-agentic-roleplay/state";
10
10
  import { copyFileSync, existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
@@ -342,14 +342,12 @@ var TimelineError = class extends Error {};
342
342
  */
343
343
  var Timelines = class {
344
344
  deps;
345
- queues = /* @__PURE__ */ new Map();
345
+ queue = new SerialQueue();
346
346
  constructor(deps) {
347
347
  this.deps = deps;
348
348
  }
349
349
  serial(chat, job) {
350
- const run = (this.queues.get(chat) ?? Promise.resolve()).then(job, job);
351
- this.queues.set(chat, run.catch(() => void 0));
352
- return run;
350
+ return this.queue.run(chat, job);
353
351
  }
354
352
  idOf(chat) {
355
353
  const id = roleplaySessionOf(chat);
@@ -365,6 +363,13 @@ var Timelines = class {
365
363
  view(id) {
366
364
  return viewOf(this.read(id));
367
365
  }
366
+ /** What the narration of the last `count` turns before the one being played told, oldest first, on the path the story has taken; never what an alternative or a withdrawn turn said. */
367
+ narrationBefore(chat, count) {
368
+ const id = roleplaySessionOf(chat);
369
+ if (id === void 0) return [];
370
+ const { path, head } = this.view(id);
371
+ return path.filter((turn) => turn.id !== head).slice(-count).flatMap((turn) => turn.output === void 0 ? [] : [turn.output.segments.flatMap((segment) => segment.type === "narration" ? [segment.text] : []).join("\n")]);
372
+ }
368
373
  /**
369
374
  * The player has said something and a turn begins: the turn is added to the timeline after the head, and the state the earlier one left is kept at once,
370
375
  * with the records still waiting for the keeper in it (they are in the database, so a restored state carries them).
@@ -409,19 +414,20 @@ var Timelines = class {
409
414
  /**
410
415
  * The turn ended in the log. Its own message is found now: it is the first message of the player after the last turn that ended
411
416
  * (it is not in the log yet when the turn begins).
417
+ * @param beganSeq - where that turn's own `turn/start` sits, so the log is not searched for it.
412
418
  */
413
- ended(chat, session, seq) {
419
+ ended(chat, session, seq, beganSeq) {
414
420
  const id = this.idOf(chat);
415
421
  const timeline = this.read(id);
416
422
  const node = timeline.nodes.find((candidate) => candidate.id === timeline.head);
417
423
  if (node === void 0 || node.endSeq !== void 0) return;
418
424
  const after = Math.max(-1, ...timeline.nodes.filter((other) => other.id !== node.id).map((other) => other.endSeq ?? other.userSeq));
419
- const human = session.snapshotEvents().find((event) => event.seq > after && event.type === "user/message" && event.data.source.kind === "user");
425
+ const human = session.snapshotEvents(after + 1).find((event) => event.seq > after && event.type === "user/message" && event.data.source.kind === "user");
420
426
  if (human === void 0) throw new TimelineError(`turn ${node.turn} has no message of the player in the log`);
421
427
  node.userSeq = human.seq;
422
428
  node.endSeq = seq;
423
- const began = session.snapshotEvents().find((event) => event.type === "turn/start" && event.data.turn === node.turn);
424
- node.startSeq = Math.min(began?.seq ?? human.seq, human.seq);
429
+ const began = beganSeq ?? session.snapshotEvents(0).find((event) => event.type === "turn/start" && event.data.turn === node.turn)?.seq;
430
+ node.startSeq = Math.min(began ?? human.seq, human.seq);
425
431
  writeTimeline(this.folder(id), timeline);
426
432
  }
427
433
  /** Keeps the state as it is under the name of the turn it follows from, when that is not done yet. */
@@ -1498,4 +1504,4 @@ function memoryReflector(deps) {
1498
1504
  }
1499
1505
  export { snapshotOf as _, whereabouts as a, copyPreset as c, switchPreset as d, readTimeline as f, pathTo as g, childrenOf as h, reflectionStatus as i, presetStatus as l, START_SNAPSHOT as m, memoryReflector as n, TimelineError as o, writeTimeline as p, recordFailure as r, Timelines as s, dueReflection as t, recordPreset as u };
1500
1506
 
1501
- //# sourceMappingURL=reflection-B9N0z3KY.js.map
1507
+ //# sourceMappingURL=reflection-Cuy0YLv0.js.map