@dsh-agentic-roleplay/core 0.12.6 → 0.13.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.
Files changed (46) hide show
  1. package/lib/{authoring-tools-BpkpGMSO.js → authoring-tools-CKV1UnN7.js} +1133 -139
  2. package/lib/authoring.js +340 -54
  3. package/lib/client.js +1675 -729
  4. package/lib/client.js.map +1 -1
  5. package/lib/compaction.js +2 -2
  6. package/lib/doctor.js +2 -2
  7. package/lib/{library-CnWOHwQl.js → gallery-CT5uj50b.js} +212 -7
  8. package/lib/{hooks-P_--KSFl.js → hooks-CnxV2uEh.js} +46 -17
  9. package/lib/images.js +3 -4
  10. package/lib/index.js +409 -26
  11. package/lib/{presenter-agent-BTpJxmGi.js → interpreter-Cz5qsuXk.js} +155 -64
  12. package/lib/{lorebook-author-tools-CWZ6WRN-.js → lorebook-author-tools-p3Nfpuxh.js} +6 -6
  13. package/lib/lorebook-authoring.js +5 -5
  14. package/lib/{narration-DAHmte8p.js → narration-CUZIXzab.js} +8 -2
  15. package/lib/orchestration.js +64 -19
  16. package/lib/{pack-jail-DSTyLhMc.js → pack-jail-KyZen_gy.js} +19 -13
  17. package/lib/{packs-D9_N8kDF.js → packs-DU171pDX.js} +2 -2
  18. package/lib/presenter-agent-CwDg0WE8.js +59 -0
  19. package/lib/{preset-B69AXtip.js → preset-BO8iWQ-n.js} +3 -3
  20. package/lib/{preset-author-tools-BJtt7D0J.js → preset-author-tools-C83shASm.js} +6 -6
  21. package/lib/preset-authoring.js +5 -5
  22. package/lib/{reflection-2uzE3U-v.js → reflection-CXS87Di3.js} +8 -7
  23. package/lib/{serial-DnVqMDe5.js → serial-xcAG57p_.js} +199 -43
  24. package/lib/{text-B-HsLdb-.js → text-KnqhN_Zv.js} +4 -1
  25. package/lib/{turn-guard-D4YHE00t.js → turn-guard-CfsGepCg.js} +2 -2
  26. package/package.json +3 -2
  27. package/prompts/en/import/finish-ok.md +2 -0
  28. package/prompts/en/import/next-stage-go.md +1 -0
  29. package/prompts/en/import/next-stage-paused.md +1 -0
  30. package/prompts/en/import/next-survey-paused.md +1 -0
  31. package/prompts/en/import/notice-staged.md +5 -0
  32. package/prompts/en/import/pause-stages.md +1 -0
  33. package/prompts/en/import/pause-survey.md +1 -0
  34. package/prompts/en/roleplay/image-worth.md +5 -0
  35. package/prompts/en/world/procedure.md +3 -0
  36. package/prompts/zh/import/finish-ok.md +2 -0
  37. package/prompts/zh/import/next-stage-go.md +1 -0
  38. package/prompts/zh/import/next-stage-paused.md +1 -0
  39. package/prompts/zh/import/next-survey-paused.md +1 -0
  40. package/prompts/zh/import/notice-staged.md +5 -0
  41. package/prompts/zh/import/pause-stages.md +1 -0
  42. package/prompts/zh/import/pause-survey.md +1 -0
  43. package/prompts/zh/roleplay/image-worth.md +5 -0
  44. package/prompts/zh/world/procedure.md +3 -0
  45. package/lib/gallery-D0h0X7Jy.js +0 -190
  46. package/lib/generator-CAJkevKl.js +0 -150
package/lib/authoring.js CHANGED
@@ -1,11 +1,15 @@
1
- import { $ as checkWorld, A as loadWorldParts, At as lettersOf, C as cardChanges, D as worldFieldChanges, E as pictureChange, F as editsSince, Ft as cardTools, It as entitiesByPiece, Lt as readSource, M as CHECK_COMMANDS, Mt as UPDATE_FOLDER, N as CHECK_COMMAND_DESCRIPTIONS, O as editWorldInfo, Qt as authoredWorldOf, Rt as COMMANDS_FILE_NAME, S as addressChanges, St as DICE_FILE_NAME, T as matchPieces, Tt as CALENDAR_FILE_NAME, b as CHECKS, j as loadCardEvidence, jt as shapeOpening, k as readWorldInfo, kt as loadCharacters, l as importTools, n as limitAuthoringAgents, o as contextOf, p as isReviewing, s as importHooks, u as worldOf, v as checkImported, w as diffText, x as runChecks, y as presentReport } from "./authoring-tools-BpkpGMSO.js";
2
- import { t as guardAuthoringTurns } from "./turn-guard-D4YHE00t.js";
1
+ import { $ as checkWorld, $t as authoredWorldOf, A as loadWorldParts, At as lettersOf, C as cardChanges, D as worldFieldChanges, E as pictureChange, F as editsSince, Ft as cardTools, It as entitiesByPiece, M as CHECK_COMMANDS, Mt as UPDATE_FOLDER, N as CHECK_COMMAND_DESCRIPTIONS, O as editWorldInfo, Rt as readSource, S as addressChanges, St as DICE_FILE_NAME, T as matchPieces, Tt as CALENDAR_FILE_NAME, b as CHECKS, j as loadCardEvidence, jt as shapeOpening, k as readWorldInfo, kt as loadCharacters, l as importTools, n as limitAuthoringAgents, o as contextOf, p as isReviewing, s as importHooks, u as worldOf, v as checkImported, w as diffText, x as runChecks, y as presentReport, zt as COMMANDS_FILE_NAME } from "./authoring-tools-CKV1UnN7.js";
2
+ import { t as guardAuthoringTurns } from "./turn-guard-CfsGepCg.js";
3
3
  import { n as silenceRuntimeContext, t as silenceHarnessDevContext } from "./dev-context-Cgv_wZbG.js";
4
- import { B as deleteTriggerDocument, D as editWorldPlots, G as parseVariablesEdit, H as writeTriggerDocument, K as parseDiceEdit, M as readWorldEditor, O as editWorldRelation, Q as translateTools, U as parseCalendarEdit, V as readTriggerDocuments, X as presetTools, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, f as editCalendar, g as editVariables, i as checkWorldPack, l as deleteAuthoredEntity, m as editDice, nt as finishUpdate, o as listWorldPacks, p as editCommands, q as parseCommandsEdit, r as registerPackJail, rt as pendingUpdate, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument } from "./pack-jail-DSTyLhMc.js";
5
- import { i as translator, r as languageOf } from "./text-B-HsLdb-.js";
6
- import { Et as IMPORT_FOLDER, F as parseWorldInfoEdit, I as hasSpeech, Pt as InvalidEditProblems, R as partsText, at as writeWorldPrompt, it as readWorldPrompt, kt as PICTURE_FILE, nt as deleteWorldPrompt, qt as VARIABLES_FILE_NAME, rt as listWorldPrompts, tt as PROSE_PROMPTS, zt as parseRelationEdit } from "./serial-DnVqMDe5.js";
7
- import { B as parsePlotsFile, at as shippedPromptsDirectory, ht as registerCommands, q as formatIssue } from "./hooks-P_--KSFl.js";
8
- import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-D9_N8kDF.js";
4
+ import { B as deleteTriggerDocument, D as editWorldPlots, G as parseVariablesEdit, H as writeTriggerDocument, K as parseDiceEdit, M as readWorldEditor, O as editWorldRelation, Q as translateTools, U as parseCalendarEdit, V as readTriggerDocuments, X as presetTools, a as deleteWorldPackFile, c as createAuthoredEntity, d as replaceAuthoredEntity, f as editCalendar, g as editVariables, i as checkWorldPack, l as deleteAuthoredEntity, m as editDice, nt as finishUpdate, o as listWorldPacks, p as editCommands, q as parseCommandsEdit, r as registerPackJail, rt as pendingUpdate, s as AUTHORED_ENTITY_KINDS, u as readAuthoredEntityDocument } from "./pack-jail-KyZen_gy.js";
5
+ import { Ft as IMPORT_FOLDER, G as hasSpeech, Jt as parseRelationEdit, Rt as PICTURE_FILE, Ut as InvalidEditProblems, W as parseWorldInfoEdit, dt as deleteWorldPrompt, ft as listWorldPrompts, mt as writeWorldPrompt, pt as readWorldPrompt, q as partsText, rn as VARIABLES_FILE_NAME, ut as PROSE_PROMPTS } from "./serial-xcAG57p_.js";
6
+ import { B as parsePlotsFile, J as formatIssue, at as shippedPromptsDirectory, ht as registerCommands } from "./hooks-CnxV2uEh.js";
7
+ import { i as translator, r as languageOf } from "./text-KnqhN_Zv.js";
8
+ import { g as SURFACE_NAMES, m as PACK_LIMITS, p as PACK_ACTIONS } from "./packs-DU171pDX.js";
9
+ import { u as DEFAULT_SETTINGS } from "./narration-CUZIXzab.js";
10
+ import { T as currentTurn, r as childSampling } from "./child-Bfj7-Iuo.js";
11
+ import { a as updateImage, i as listGallery, n as describeGalleryImage } from "./gallery-CT5uj50b.js";
12
+ import { n as interpretImage } from "./interpreter-Cz5qsuXk.js";
9
13
  import "./access-5vtPAT3O.js";
10
14
  import { join, relative } from "node:path";
11
15
  import { createHash } from "node:crypto";
@@ -66,20 +70,20 @@ async function writeWorldFile(world, kind, document, options = {}) {
66
70
  await FILES[kind].write(world, document, options);
67
71
  }
68
72
  // src/host/authoring/read-tools.ts
69
- const output$5 = (value) => [{
73
+ const output$7 = (value) => [{
70
74
  type: "text",
71
75
  text: JSON.stringify(value, null, 2)
72
76
  }];
73
- const jsonOutput$3 = {
77
+ const jsonOutput$4 = {
74
78
  schema: { type: "json" },
75
- render: (_args, value) => output$5(value)
79
+ render: (_args, value) => output$7(value)
76
80
  };
77
81
  const keyParameter$1 = {
78
82
  type: "string",
79
83
  required: true,
80
84
  description: "Stable key shown by the corresponding list tool."
81
85
  };
82
- const json$1 = (value) => JSON.parse(JSON.stringify(value));
86
+ const json$2 = (value) => JSON.parse(JSON.stringify(value));
83
87
  /** Resolves every call from its authoring chat identity, then reads the files afresh. */
84
88
  var AuthoredWorldReader = class {
85
89
  worlds;
@@ -110,10 +114,10 @@ function listTool(reader, name, description, select, summarize) {
110
114
  name,
111
115
  description,
112
116
  parameters: {},
113
- output: jsonOutput$3,
117
+ output: jsonOutput$4,
114
118
  isConcurrencySafe: () => true,
115
119
  async execute(_args, exec) {
116
- return json$1(select((await reader.read(exec)).state).map(summarize));
120
+ return json$2(select((await reader.read(exec)).state).map(summarize));
117
121
  }
118
122
  });
119
123
  }
@@ -122,12 +126,12 @@ function getTool(reader, name, description, select) {
122
126
  name,
123
127
  description,
124
128
  parameters: { key: keyParameter$1 },
125
- output: jsonOutput$3,
129
+ output: jsonOutput$4,
126
130
  isConcurrencySafe: () => true,
127
131
  async execute(args, exec) {
128
132
  const found = select((await reader.read(exec)).state).find((entry) => entry.key === args.key);
129
133
  if (found === void 0) throw new Error(`there is no ${name.slice(4).replaceAll("_", " ")} with key "${args.key}"`);
130
- return json$1(found);
134
+ return json$2(found);
131
135
  }
132
136
  });
133
137
  }
@@ -138,12 +142,12 @@ function authoredWorldReadTools(reader) {
138
142
  name: "get_world_overview",
139
143
  description: "Read the authored world’s top-level identity, description, rules, opening, tags, author and element counts.",
140
144
  parameters: {},
141
- output: jsonOutput$3,
145
+ output: jsonOutput$4,
142
146
  isConcurrencySafe: () => true,
143
147
  async execute(_args, exec) {
144
148
  const { record, state } = await reader.read(exec);
145
149
  const document = JSON.parse(await readFile(join(record.directory, "world.json"), "utf8"));
146
- return json$1({
150
+ return json$2({
147
151
  id: record.summary.id,
148
152
  name: record.summary.name,
149
153
  description: record.summary.description,
@@ -167,10 +171,10 @@ function authoredWorldReadTools(reader) {
167
171
  name: "get_world_info",
168
172
  description: "Read what the world says about itself in world.json: name, description, tags, rules, the opening message and the alternate openings, author, version, time settings, and the preset, lorebooks, sampling and tool switches the person chose. edit_world_info changes the fields a card or an author is responsible for.",
169
173
  parameters: {},
170
- output: jsonOutput$3,
174
+ output: jsonOutput$4,
171
175
  isConcurrencySafe: () => true,
172
176
  async execute(_args, exec) {
173
- return json$1(await readWorldInfo((await reader.read(exec)).record.directory));
177
+ return json$2(await readWorldInfo((await reader.read(exec)).record.directory));
174
178
  }
175
179
  }),
176
180
  listTool(reader, "list_characters", "List authored characters with stable keys and concise identifying information.", (world) => world.characters, (entry) => ({
@@ -228,11 +232,11 @@ function authoredWorldReadTools(reader) {
228
232
  },
229
233
  key: keyParameter$1
230
234
  },
231
- output: jsonOutput$3,
235
+ output: jsonOutput$4,
232
236
  isConcurrencySafe: () => true,
233
237
  async execute(args, exec) {
234
238
  const { record } = await reader.read(exec);
235
- return json$1(await readAuthoredEntityDocument({
239
+ return json$2(await readAuthoredEntityDocument({
236
240
  id: record.summary.id,
237
241
  directory: record.directory
238
242
  }, args.kind, args.key));
@@ -265,13 +269,13 @@ function authoredWorldReadTools(reader) {
265
269
  name: "get_world_trigger",
266
270
  description: "Read the exact snake_case JSON document stored for one trigger in triggers.json. Use this before replacing a trigger.",
267
271
  parameters: { key: keyParameter$1 },
268
- output: jsonOutput$3,
272
+ output: jsonOutput$4,
269
273
  isConcurrencySafe: () => true,
270
274
  async execute(args, exec) {
271
275
  const { record } = await reader.read(exec);
272
276
  const found = (await readTriggerDocuments(record.directory)).find((entry) => entry["key"] === args.key);
273
277
  if (found === void 0) throw new Error(`there is no trigger with key "${args.key}"`);
274
- return json$1(found);
278
+ return json$2(found);
275
279
  }
276
280
  }),
277
281
  defineTool({
@@ -282,12 +286,12 @@ function authoredWorldReadTools(reader) {
282
286
  required: true,
283
287
  enum: WORLD_FILE_KINDS
284
288
  } },
285
- output: jsonOutput$3,
289
+ output: jsonOutput$4,
286
290
  isConcurrencySafe: () => true,
287
291
  async execute(args, exec) {
288
292
  const { record } = await reader.read(exec);
289
293
  if (!isWorldFileKind(args.kind)) throw new Error(`kind must be one of ${WORLD_FILE_KINDS.join(", ")}`);
290
- return json$1(await readWorldFile(record.directory, args.kind));
294
+ return json$2(await readWorldFile(record.directory, args.kind));
291
295
  }
292
296
  }),
293
297
  defineTool({
@@ -313,10 +317,10 @@ function authoredWorldReadTools(reader) {
313
317
  description: "Only edges whose target has this stable key."
314
318
  }
315
319
  },
316
- output: jsonOutput$3,
320
+ output: jsonOutput$4,
317
321
  isConcurrencySafe: () => true,
318
322
  async execute(args, exec) {
319
- return json$1((await reader.read(exec)).state.relations.filter((relation) => (args.kind === void 0 || relation.kind === args.kind) && (args.from === void 0 || relation.from.key === args.from) && (args.to === void 0 || relation.to.key === args.to)));
323
+ return json$2((await reader.read(exec)).state.relations.filter((relation) => (args.kind === void 0 || relation.kind === args.kind) && (args.from === void 0 || relation.from.key === args.from) && (args.to === void 0 || relation.to.key === args.to)));
320
324
  }
321
325
  })
322
326
  ];
@@ -343,13 +347,13 @@ async function checkOpeningSpeakers(directory, edit) {
343
347
  }
344
348
  // src/host/authoring/pack-tools.ts
345
349
  const PACK_MUTATION_TOOLS = ["delete_world_pack_file"];
346
- const output$4 = (value) => [{
350
+ const output$6 = (value) => [{
347
351
  type: "text",
348
352
  text: JSON.stringify(value, null, 2)
349
353
  }];
350
- const jsonOutput$2 = {
354
+ const jsonOutput$3 = {
351
355
  schema: { type: "json" },
352
- render: (_args, value) => output$4(value)
356
+ render: (_args, value) => output$6(value)
353
357
  };
354
358
  /** A path as the file tools take it: relative to the chat's folder when it has one, which is short and hard to mistype. */
355
359
  function relativeTo(exec, path) {
@@ -361,7 +365,7 @@ const packParameter = {
361
365
  required: true,
362
366
  description: "The pack name (its folder under ui/), such as atlas."
363
367
  };
364
- const pathParameter = {
368
+ const pathParameter$1 = {
365
369
  type: "string",
366
370
  required: true,
367
371
  description: "A path inside the pack with \"/\", such as pack.json or img/map.svg."
@@ -388,7 +392,7 @@ function worldPackTools(reader) {
388
392
  name: "world_pack_guide",
389
393
  description: "How to write an interface pack: where its files go (the folder is returned with the guide), the manifest, the skin, the surfaces, the rp object a surface gets, what it is told, and the limits. Read it before writing a pack.",
390
394
  parameters: {},
391
- output: jsonOutput$2,
395
+ output: jsonOutput$3,
392
396
  isConcurrencySafe: () => true,
393
397
  async execute(_args, exec) {
394
398
  const { record } = await reader.read(exec);
@@ -403,7 +407,7 @@ function worldPackTools(reader) {
403
407
  name: "list_world_packs",
404
408
  description: "List the interface packs the world carries, their files and what is wrong with each. Each pack has a path: the folder its files go in, as the file tools take it.",
405
409
  parameters: {},
406
- output: jsonOutput$2,
410
+ output: jsonOutput$3,
407
411
  isConcurrencySafe: () => true,
408
412
  async execute(_args, exec) {
409
413
  const { record } = await reader.read(exec);
@@ -417,7 +421,7 @@ function worldPackTools(reader) {
417
421
  name: "check_world_pack",
418
422
  description: "Check a pack of this world as session start will: the manifest, the theme, the skin, the surfaces and every file. An empty list of problems means it can be used.",
419
423
  parameters: { pack: packParameter },
420
- output: jsonOutput$2,
424
+ output: jsonOutput$3,
421
425
  isConcurrencySafe: () => true,
422
426
  async execute(args, exec) {
423
427
  const { record } = await reader.read(exec);
@@ -432,9 +436,9 @@ function worldPackTools(reader) {
432
436
  description: "Remove a file of a pack of this world; it is moved into the world's .trash directory. Requires user approval.",
433
437
  parameters: {
434
438
  pack: packParameter,
435
- path: pathParameter
439
+ path: pathParameter$1
436
440
  },
437
- output: jsonOutput$2,
441
+ output: jsonOutput$3,
438
442
  async execute(args, exec) {
439
443
  const { record } = await reader.read(exec);
440
444
  const { trashPath, problems } = await deleteWorldPackFile(record.directory, args.pack, args.path);
@@ -451,13 +455,13 @@ function worldPackTools(reader) {
451
455
  }
452
456
  // src/host/authoring/prompt-tools.ts
453
457
  const PROMPT_MUTATION_TOOLS = ["write_world_prompt", "delete_world_prompt"];
454
- const output$3 = (value) => [{
458
+ const output$5 = (value) => [{
455
459
  type: "text",
456
460
  text: JSON.stringify(value, null, 2)
457
461
  }];
458
- const jsonOutput$1 = {
462
+ const jsonOutput$2 = {
459
463
  schema: { type: "json" },
460
- render: (_args, value) => output$3(value)
464
+ render: (_args, value) => output$5(value)
461
465
  };
462
466
  const idParameter = {
463
467
  type: "string",
@@ -479,7 +483,7 @@ function worldPromptTools(reader, shipped = shippedPromptsDirectory()) {
479
483
  name: "list_world_prompts",
480
484
  description: "List the prompts the models are given, in a language, and whether this world carries its own version. \"prose\" prompts set how the story is written and how the models stay in character; \"rules\" prompts hold the rules of the game and the tools.",
481
485
  parameters: { language: languageParameter },
482
- output: jsonOutput$1,
486
+ output: jsonOutput$2,
483
487
  isConcurrencySafe: () => true,
484
488
  async execute(args, exec) {
485
489
  const { record } = await reader.read(exec);
@@ -493,7 +497,7 @@ function worldPromptTools(reader, shipped = shippedPromptsDirectory()) {
493
497
  id: idParameter,
494
498
  language: languageParameter
495
499
  },
496
- output: jsonOutput$1,
500
+ output: jsonOutput$2,
497
501
  isConcurrencySafe: () => true,
498
502
  async execute(args, exec) {
499
503
  const { record } = await reader.read(exec);
@@ -512,7 +516,7 @@ function worldPromptTools(reader, shipped = shippedPromptsDirectory()) {
512
516
  description: "The complete prompt text."
513
517
  }
514
518
  },
515
- output: jsonOutput$1,
519
+ output: jsonOutput$2,
516
520
  async execute(args, exec) {
517
521
  const { record } = await reader.read(exec);
518
522
  await writeWorldPrompt(record.directory, args.language, args.id, args.text, shipped);
@@ -530,7 +534,7 @@ function worldPromptTools(reader, shipped = shippedPromptsDirectory()) {
530
534
  id: idParameter,
531
535
  language: languageParameter
532
536
  },
533
- output: jsonOutput$1,
537
+ output: jsonOutput$2,
534
538
  async execute(args, exec) {
535
539
  const { record } = await reader.read(exec);
536
540
  const trashPath = await deleteWorldPrompt(record.directory, args.language, args.id, shipped);
@@ -544,6 +548,178 @@ function worldPromptTools(reader, shipped = shippedPromptsDirectory()) {
544
548
  })
545
549
  ];
546
550
  }
551
+ // src/host/authoring/image-tools.ts
552
+ const IMAGE_MUTATION_TOOLS = ["edit_world_image", "describe_world_image"];
553
+ const output$4 = (value) => [{
554
+ type: "text",
555
+ text: JSON.stringify(value, null, 2)
556
+ }];
557
+ const jsonOutput$1 = {
558
+ schema: { type: "json" },
559
+ render: (_args, value) => output$4(value)
560
+ };
561
+ const pathParameter = {
562
+ type: "string",
563
+ required: true,
564
+ description: "The path of the picture, exactly as list_world_images gives it (library/dock.png)."
565
+ };
566
+ const KINDS = [
567
+ "character",
568
+ "location",
569
+ "item"
570
+ ];
571
+ /**
572
+ * Read, correct and describe the pictures of a world's library. A picture downloaded for a character card carries the addresses it came from and the card pieces that held
573
+ * them, so the assistant can read the card around an address (card_read) and say who a picture shows.
574
+ */
575
+ function worldImageTools(reader, deps) {
576
+ return [
577
+ defineTool({
578
+ name: "list_world_images",
579
+ description: "List the pictures of the world's image library: each with its description, tags, the characters, places and things it shows, whether it may be shown again, and, for a picture downloaded for a character card, the addresses it came from with the ids of the card pieces that held each (read one with card_read to see the text around the address). A picture with no description has not been described yet.",
580
+ parameters: { undescribed: {
581
+ type: "boolean",
582
+ description: "Only the pictures that have no description yet."
583
+ } },
584
+ output: jsonOutput$1,
585
+ isConcurrencySafe: () => true,
586
+ async execute(args, exec) {
587
+ const { record } = await reader.read(exec);
588
+ const images = (await listGallery(record.directory)).filter((image) => image.unreadable !== true && (args.undescribed !== true || image.description === void 0));
589
+ return {
590
+ count: images.length,
591
+ images: images.map((image) => ({
592
+ path: image.path,
593
+ ...image.description === void 0 ? {} : { description: image.description },
594
+ tags: image.tags,
595
+ subjects: image.subjects,
596
+ reusable: image.reusable,
597
+ ...image.originalName === void 0 ? {} : { originalName: image.originalName },
598
+ ...image.cardLinks === void 0 ? {} : { cardLinks: image.cardLinks }
599
+ }))
600
+ };
601
+ }
602
+ }),
603
+ defineTool({
604
+ name: "edit_world_image",
605
+ description: "Correct what a picture of the world's library says about itself: its description, tags, the characters, places and things it shows (by the exact names the world has) and whether it may be shown again. Give only what changes. Requires user approval.",
606
+ parameters: {
607
+ path: pathParameter,
608
+ description: {
609
+ type: "string",
610
+ description: "What the picture shows, in two to four plain sentences that stand on their own."
611
+ },
612
+ tags: {
613
+ type: "array",
614
+ items: { type: "string" },
615
+ description: "Short search words; replaces the tags the picture has."
616
+ },
617
+ subjects: {
618
+ type: "array",
619
+ items: {
620
+ type: "object",
621
+ additionalProperties: false,
622
+ properties: {
623
+ kind: {
624
+ type: "string",
625
+ required: true,
626
+ enum: [...KINDS]
627
+ },
628
+ name: {
629
+ type: "string",
630
+ required: true
631
+ }
632
+ }
633
+ },
634
+ description: "The characters, places and things the picture clearly shows; replaces the list it has. Leave out one you are not sure of."
635
+ },
636
+ reusable: {
637
+ type: "boolean",
638
+ description: "Whether a story may show the picture again in a later scene."
639
+ }
640
+ },
641
+ output: jsonOutput$1,
642
+ async execute(args, exec) {
643
+ const { record, state } = await reader.read(exec);
644
+ const known = namesOf(state);
645
+ const unknown = (args.subjects ?? []).filter((subject) => !known.some((entry) => entry.kind === subject.kind && entry.name === subject.name));
646
+ if (unknown.length > 0) throw new Error(`${unknown.map((subject) => `${subject.name} (${subject.kind})`).join(", ")} is not in this world: name only characters, places and things it has (${known.map((entry) => `${entry.name} (${entry.kind})`).join(", ") || "none yet"})`);
647
+ const image = await updateImage(record.directory, args.path, {
648
+ ...args.description === void 0 ? {} : { description: args.description.trim() },
649
+ ...args.tags === void 0 ? {} : { tags: args.tags.map((tag) => tag.trim()).filter((tag) => tag !== "") },
650
+ ...args.subjects === void 0 ? {} : { subjects: args.subjects },
651
+ ...args.reusable === void 0 ? {} : { reusable: args.reusable }
652
+ });
653
+ return {
654
+ action: "edited",
655
+ path: image.path,
656
+ description: image.description,
657
+ tags: image.tags,
658
+ subjects: image.subjects,
659
+ reusable: image.reusable
660
+ };
661
+ }
662
+ }),
663
+ defineTool({
664
+ name: "describe_world_image",
665
+ description: "Have a model that can read images look at one picture of the world's library and write its description, tags and the characters, places and things it shows, replacing what it had. Give context when you know something the picture cannot say (for example the card text around the address it came from, or who the card says it is); the picture itself decides what is described. Needs a model that is declared able to read images. Requires user approval.",
666
+ parameters: {
667
+ path: pathParameter,
668
+ context: {
669
+ type: "string",
670
+ description: "What you know of where the picture came from or who it shows, in a few sentences; a hint, not an instruction to the describing model."
671
+ }
672
+ },
673
+ output: jsonOutput$1,
674
+ async execute(args, exec) {
675
+ const { record, state } = await reader.read(exec);
676
+ const agent = exec.agent;
677
+ const attachments = deps.attachments();
678
+ if (agent === void 0) throw new Error("there is no agent to describe the picture under");
679
+ if (attachments === void 0) throw new Error("this DSH profile has no attachment service, so a picture cannot be shown to a model");
680
+ const settings = DEFAULT_SETTINGS;
681
+ await describeGalleryImage(record.directory, args.path);
682
+ const request = {
683
+ parent: agent,
684
+ signal: exec.signal,
685
+ attachments,
686
+ subjects: namesOf(state),
687
+ sessionFolder: record.directory,
688
+ path: args.path,
689
+ language: deps.language(record.summary.id),
690
+ model: settings.images.interpreterModel,
691
+ captioner: settings.images.captioner,
692
+ sampling: childSampling(settings, "records")
693
+ };
694
+ if (args.context !== void 0) request.context = args.context;
695
+ const image = await interpretImage(request);
696
+ return {
697
+ action: "described",
698
+ path: image.path,
699
+ description: image.description,
700
+ tags: image.tags,
701
+ subjects: image.subjects
702
+ };
703
+ }
704
+ })
705
+ ];
706
+ }
707
+ function namesOf(state) {
708
+ return [
709
+ ...state.characters.map((entry) => ({
710
+ kind: "character",
711
+ name: entry.name
712
+ })),
713
+ ...state.places.map((entry) => ({
714
+ kind: "location",
715
+ name: entry.name
716
+ })),
717
+ ...state.things.map((entry) => ({
718
+ kind: "item",
719
+ name: entry.name
720
+ }))
721
+ ];
722
+ }
547
723
  // src/host/authoring/approval-summary.ts
548
724
  const MAX_FIELDS = 5;
549
725
  function clip(value, max) {
@@ -612,13 +788,13 @@ function plain$1(value, max = 220) {
612
788
  };
613
789
  }
614
790
  // src/host/authoring/write-tools.ts
615
- const output$2 = (value) => [{
791
+ const output$3 = (value) => [{
616
792
  type: "text",
617
793
  text: JSON.stringify(value, null, 2)
618
794
  }];
619
795
  const jsonOutput = {
620
796
  schema: { type: "json" },
621
- render: (_args, value) => output$2(value)
797
+ render: (_args, value) => output$3(value)
622
798
  };
623
799
  const kindParameter = {
624
800
  type: "string",
@@ -658,7 +834,8 @@ const AUTHORING_MUTATION_TOOLS = /* @__PURE__ */ new Set([
658
834
  "delete_world_trigger",
659
835
  "write_world_file",
660
836
  ...PROMPT_MUTATION_TOOLS,
661
- ...PACK_MUTATION_TOOLS
837
+ ...PACK_MUTATION_TOOLS,
838
+ ...IMAGE_MUTATION_TOOLS
662
839
  ]);
663
840
  function result(action, kind, key, state, extra = {}) {
664
841
  return {
@@ -1028,6 +1205,18 @@ async function authoringApproval(exec, next, reviewing = () => Promise.resolve(f
1028
1205
  }, remove ? void 0 : sizeOf(args["text"]))
1029
1206
  };
1030
1207
  }
1208
+ if (IMAGE_MUTATION_TOOLS.includes(exec.name)) {
1209
+ const describing = exec.name === "describe_world_image";
1210
+ const target = `picture “${String(args["path"])}”`;
1211
+ return {
1212
+ kind: "ask",
1213
+ reason: `${describing ? "have a model describe" : "change what is said about"} the authored world's ${target}`,
1214
+ displayReason: {
1215
+ en: `${describing ? "Have a model describe" : "Change the description, tags or subjects of"} the ${target}?`,
1216
+ zh: `${describing ? "让模型描述" : "修改"}${target.replace("picture", "图片")}${describing ? "" : "的描述、标签或主体"}?`
1217
+ }
1218
+ };
1219
+ }
1031
1220
  if (exec.name === "reshape_opening") {
1032
1221
  const target = String(args["target"]);
1033
1222
  return {
@@ -1129,14 +1318,14 @@ const hashOf = async (file) => await readFile(file).then((bytes) => createHash("
1129
1318
  if (error.code === "ENOENT") return void 0;
1130
1319
  throw error;
1131
1320
  });
1132
- const output$1 = {
1321
+ const output$2 = {
1133
1322
  schema: { type: "json" },
1134
1323
  render: (_args, value) => [{
1135
1324
  type: "text",
1136
1325
  text: JSON.stringify(value, null, 1)
1137
1326
  }]
1138
1327
  };
1139
- const json = (value) => JSON.parse(JSON.stringify(value));
1328
+ const json$1 = (value) => JSON.parse(JSON.stringify(value));
1140
1329
  /**
1141
1330
  * The tools that bring a world up to date with a newer version of the card it was made from. `card_diff` is the starting point: what the card changed, worked out by code,
1142
1331
  * with the import's records of what each piece made and the files the person has edited since; the assistant then edits with its ordinary tools and asks for those edits like any others.
@@ -1154,7 +1343,7 @@ function updateTools(worlds) {
1154
1343
  name: "card_diff",
1155
1344
  description: "What a newer version of the card this world was imported from changes. For each piece (field, greeting, lorebook entry) that changed, was added or was dropped: the sentences that differ, and the characters, places and things the import made from it, which are what may need to change. Also the files of the world that were edited since the import, and what the newer version changes about the card itself. Start here when asked to update the world from its card; read whole pieces with card_read (version current or new).",
1156
1345
  parameters: {},
1157
- output: output$1,
1346
+ output: output$2,
1158
1347
  isConcurrencySafe: () => true,
1159
1348
  async execute(_args, exec) {
1160
1349
  const directory = await worldOf(exec);
@@ -1194,7 +1383,7 @@ function updateTools(worlds) {
1194
1383
  });
1195
1384
  const edits = await editsSince(directory);
1196
1385
  const picture = pictureChange(await hashOf(join(directory, IMPORT_FOLDER, PICTURE_FILE)), await hashOf(join(directory, IMPORT_FOLDER, UPDATE_FOLDER, PICTURE_FILE)));
1197
- return json({
1386
+ return json$1({
1198
1387
  card: cardChanges(before.card, after.card),
1199
1388
  images: {
1200
1389
  cardPicture: picture,
@@ -1230,12 +1419,12 @@ function updateTools(worlds) {
1230
1419
  name: "card_update_finish",
1231
1420
  description: `Makes the newer card the card this world was made from, once the world has been brought up to date with it: the old card is kept in ${IMPORT_FOLDER}/previous, and what the world holds now is what later edits are measured against. Run it after your edits, and only then.`,
1232
1421
  parameters: {},
1233
- output: output$1,
1422
+ output: output$2,
1234
1423
  async execute(_args, exec) {
1235
1424
  const directory = await worldOf(exec);
1236
1425
  const outcome = await finishUpdate(directory, exec.signal === void 0 ? {} : { signal: exec.signal });
1237
1426
  const checks = await checkImported(directory, (await readWorldInfo(directory)).name);
1238
- return json({
1427
+ return json$1({
1239
1428
  done: true,
1240
1429
  checks,
1241
1430
  card: `${IMPORT_FOLDER}/card.json`,
@@ -1260,7 +1449,7 @@ const isUpdateRequest = (text) => text.includes("card_diff") && text.includes("c
1260
1449
  * An update turn that stops with the update still waiting is sent back once: models end such a turn on a change they found no place for, and the person then has neither the
1261
1450
  * rest of the update nor a report. A turn that stops again is let go, so a question to the person can still end it.
1262
1451
  */
1263
- function updateHooks(ctx, worlds, languageOf$1) {
1452
+ function updateHooks(ctx, worlds, languageOf$2) {
1264
1453
  const updating = /* @__PURE__ */ new Map();
1265
1454
  const nudges = /* @__PURE__ */ new Map();
1266
1455
  const authoring = (agent) => {
@@ -1295,7 +1484,7 @@ function updateHooks(ctx, worlds, languageOf$1) {
1295
1484
  return;
1296
1485
  }
1297
1486
  nudges.set(here.chat, told + 1);
1298
- const tr = translator(languageOf(languageOf$1(here.world)));
1487
+ const tr = translator(languageOf(languageOf$2(here.world)));
1299
1488
  agent.steer(createUserMessage({
1300
1489
  content: [{
1301
1490
  type: "text",
@@ -1415,6 +1604,97 @@ function openingTools(worlds, settings, prompting) {
1415
1604
  }
1416
1605
  })];
1417
1606
  }
1607
+ // src/host/authoring/checkpoint-tools.ts
1608
+ const output$1 = {
1609
+ schema: { type: "json" },
1610
+ render: (_args, value) => [{
1611
+ type: "text",
1612
+ text: JSON.stringify(value, null, 1)
1613
+ }]
1614
+ };
1615
+ const json = (value) => JSON.parse(JSON.stringify(value));
1616
+ const checkpointParameter = {
1617
+ type: "string",
1618
+ required: true,
1619
+ description: "A checkpoint id from list_world_checkpoints."
1620
+ };
1621
+ /**
1622
+ * Read-only access to the checkpoints of the world being authored: when each was made, what has changed in the world since, and a file as the checkpoint has it. Putting a file back is
1623
+ * done with the ordinary editing tools from what is read here; restoring the whole world is the person's.
1624
+ */
1625
+ function checkpointTools(worlds, checkpoints) {
1626
+ return [
1627
+ defineTool({
1628
+ name: "list_world_checkpoints",
1629
+ description: "The checkpoints of this world, newest first: a copy of its files taken before the edits of a turn, or on the person's request. Use one to see what a turn changed or to take back part of it.",
1630
+ parameters: {},
1631
+ output: output$1,
1632
+ isConcurrencySafe: () => true,
1633
+ async execute(_args, exec) {
1634
+ return json({ checkpoints: await checkpoints().list((await worldOf(worlds, exec)).id) });
1635
+ }
1636
+ }),
1637
+ defineTool({
1638
+ name: "diff_world_checkpoint",
1639
+ description: "Which files of the world differ from a checkpoint: changed, added since and removed since. Paths only; read a file with read_world_checkpoint_file.",
1640
+ parameters: { checkpoint: checkpointParameter },
1641
+ output: output$1,
1642
+ isConcurrencySafe: () => true,
1643
+ async execute(args, exec) {
1644
+ return json(await checkpoints().diff((await worldOf(worlds, exec)).id, args.checkpoint));
1645
+ }
1646
+ }),
1647
+ defineTool({
1648
+ name: "read_world_checkpoint_file",
1649
+ description: "One file of the world as a checkpoint has it (a path from diff_world_checkpoint, such as characters/<id>/character.json). Long files are cut and say so. To take a change back, write what you read here with the editing tools.",
1650
+ parameters: {
1651
+ checkpoint: checkpointParameter,
1652
+ path: {
1653
+ type: "string",
1654
+ required: true,
1655
+ description: "The file's path in the world."
1656
+ }
1657
+ },
1658
+ output: output$1,
1659
+ isConcurrencySafe: () => true,
1660
+ async execute(args, exec) {
1661
+ return json(await checkpoints().read((await worldOf(worlds, exec)).id, args.checkpoint, args.path));
1662
+ }
1663
+ })
1664
+ ];
1665
+ }
1666
+ /** A checkpoint at the first edit of each authoring turn, and a word to the chat when the person restored the world since it last looked. */
1667
+ function checkpointHooks(ctx, checkpoints, languageOf$1) {
1668
+ ctx.on("tools/pre-execute", async (exec, next) => {
1669
+ if (AUTHORING_MUTATION_TOOLS.has(exec.name) && exec.agent !== void 0 && authoredWorldOf(exec.agent.session.id) !== void 0 && exec.agent.session.header.origin !== "subagent") await checkpoints().beforeEdit(exec.agent.session.id, currentTurn(exec.agent), exec.name);
1670
+ return await next();
1671
+ }, { prepend: true });
1672
+ ctx.on("agent/pre-step", async (payload, next) => {
1673
+ const decision = await next();
1674
+ if (decision.kind !== "enter" || payload.step !== 1 || payload.agent.session.header.origin === "subagent") return decision;
1675
+ const restored = await checkpoints().unannouncedRestore(payload.agent.session.id);
1676
+ if (restored === void 0) return decision;
1677
+ const text = translator(languageOf(languageOf$1(payload.agent.session.id)))("The person restored this world to the checkpoint \"{label}\" ({at}): every file is as it was then, and what you edited since is gone. Read the world again before you edit, and do not rely on what you remember of it.", restored);
1678
+ return {
1679
+ ...decision,
1680
+ messages: [...decision.messages, createUserMessage({
1681
+ content: [{
1682
+ type: "text",
1683
+ text
1684
+ }],
1685
+ source: { kind: "roleplay" }
1686
+ })]
1687
+ };
1688
+ });
1689
+ }
1690
+ /** The checkpoint tools and hooks, registered on the scope of the preset that authors a world. */
1691
+ function registerCheckpointTools(ctx) {
1692
+ for (const tool of checkpointTools(ctx.roleplayWorlds, () => ctx.roleplayCheckpoints)) ctx.tools.register(tool);
1693
+ checkpointHooks(ctx, () => ctx.roleplayCheckpoints, (chat) => {
1694
+ const world = authoredWorldOf(chat);
1695
+ return world === void 0 ? void 0 : ctx.roleplayAuthoringLanguages.get(world);
1696
+ });
1697
+ }
1418
1698
  // src/host/checks/tools.ts
1419
1699
  const output = {
1420
1700
  schema: { type: "json" },
@@ -1540,6 +1820,7 @@ const inject = [
1540
1820
  "roleplayPrompts",
1541
1821
  "roleplayAuthoringLanguages",
1542
1822
  "roleplayAuthoringTools",
1823
+ "roleplayCheckpoints",
1543
1824
  "tools",
1544
1825
  "systemPrompt"
1545
1826
  ];
@@ -1560,6 +1841,10 @@ function apply(ctx) {
1560
1841
  for (const tool of authoredWorldWriteTools(reader)) ctx.tools.register(tool);
1561
1842
  for (const tool of worldPromptTools(reader)) ctx.tools.register(tool);
1562
1843
  for (const tool of worldPackTools(reader)) ctx.tools.register(tool);
1844
+ for (const tool of worldImageTools(reader, {
1845
+ language: (world) => ctx.roleplayAuthoringLanguages.get(world),
1846
+ attachments: () => ctx.get("attachments")
1847
+ })) ctx.tools.register(tool);
1563
1848
  for (const tool of importTools(ctx.roleplayWorlds, () => ctx.roleplayImport.settings, prompting)) ctx.tools.register(tool);
1564
1849
  for (const tool of cardTools(ctx.roleplayWorlds)) ctx.tools.register(tool);
1565
1850
  for (const tool of updateTools(ctx.roleplayWorlds)) ctx.tools.register(tool);
@@ -1570,6 +1855,7 @@ function apply(ctx) {
1570
1855
  settings: () => ctx.roleplayImport.settings,
1571
1856
  prompting
1572
1857
  })) ctx.tools.register(tool);
1858
+ registerCheckpointTools(ctx);
1573
1859
  importHooks(ctx, ctx.roleplayWorlds, prompting, ctx.roleplayImport.state);
1574
1860
  checkCommands(ctx, prompting);
1575
1861
  updateHooks(ctx, ctx.roleplayWorlds, (world) => ctx.roleplayAuthoringLanguages.get(world));