@dsh-agentic-roleplay/core 0.7.2 → 0.7.3

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.
@@ -1,8 +1,8 @@
1
1
  import "./access-DtOxFKBK.js";
2
- import { i as translator, n as withoutExtension, r as languageOf, t as trimCharacters } from "./text-JbWfTHbr.js";
2
+ import { i as translator, n as withoutExtension, r as languageOf, t as trimCharacters } from "./text-Cwl5s0j0.js";
3
3
  import { dirname, extname, join } from "node:path";
4
4
  import { existsSync } from "node:fs";
5
- import { randomUUID } from "node:crypto";
5
+ import { createHash, randomUUID } from "node:crypto";
6
6
  import { copyFile, link, mkdir, readFile, readdir, rename, unlink, writeFile } from "node:fs/promises";
7
7
  //#region src/host/import/run.ts
8
8
  /** The labels of a job's prompt, in the language of the import. */
@@ -94,6 +94,18 @@ function chunks(png) {
94
94
  function isOurText(entry) {
95
95
  return entry.type === "iTXt" && entry.data.subarray(0, 12).toString("latin1") === KEYWORD && entry.data[12] === 0;
96
96
  }
97
+ /** Chunks that describe a picture instead of being it: text, time and EXIF. */
98
+ const DESCRIPTIVE_CHUNKS = /* @__PURE__ */ new Set([
99
+ "iTXt",
100
+ "tEXt",
101
+ "zTXt",
102
+ "tIME",
103
+ "eXIf"
104
+ ]);
105
+ /** The PNG without what only describes it, so the same picture gives the same bytes before and after metadata is written into it. */
106
+ function pngPictureBytes(png) {
107
+ return Buffer.concat([SIGNATURE, ...chunks(Buffer.from(png)).filter((entry) => !DESCRIPTIVE_CHUNKS.has(entry.type)).map((entry) => entry.bytes)]);
108
+ }
97
109
  /** Put self-describing UTF-8 JSON in a PNG iTXt chunk, replacing older roleplay metadata. */
98
110
  function withPngMetadata(png, metadata) {
99
111
  const entries = chunks(Buffer.from(png)).filter((entry) => !isOurText(entry));
@@ -296,6 +308,27 @@ const MAGIC = [
296
308
  function imageExtensionOf(bytes) {
297
309
  return MAGIC.find((format) => format.test(bytes))?.type;
298
310
  }
311
+ /** A hash of the picture itself: a PNG's metadata (ours is written into it after the file is saved) is left out, so the same picture hashes the same wherever it came from. */
312
+ function pictureHash(bytes) {
313
+ let picture = bytes;
314
+ if (imageExtensionOf(bytes) === ".png") try {
315
+ picture = pngPictureBytes(bytes);
316
+ } catch {
317
+ picture = bytes;
318
+ }
319
+ return createHash("sha256").update(picture).digest("hex");
320
+ }
321
+ /** The pictures already in the library, by the hash of the picture: its path under `images/`. */
322
+ async function libraryHashes(sessionFolder) {
323
+ const directory = join(sessionFolder, "images", LIBRARY_FOLDER);
324
+ const found = /* @__PURE__ */ new Map();
325
+ for (const name of await readdir(directory).catch(() => [])) {
326
+ if (MEDIA_TYPES[extname(name).toLowerCase()] === void 0) continue;
327
+ const bytes = await readFile(join(directory, name)).catch(() => void 0);
328
+ if (bytes !== void 0 && imageExtensionOf(bytes) !== void 0) found.set(pictureHash(bytes), `${LIBRARY_FOLDER}/${name}`);
329
+ }
330
+ return found;
331
+ }
299
332
  /** A file name made of the letters and digits of the name it came with, in any script. */
300
333
  function libraryName(original, extension, taken) {
301
334
  const stem = trimCharacters(withoutExtension(original).normalize("NFKC").replace(/[^\p{L}\p{N}]+/gu, "-"), "-").slice(0, 60) || "image";
@@ -333,6 +366,6 @@ async function addToLibrary(sessionFolder, bytes, originalName) {
333
366
  return `${LIBRARY_FOLDER}/${name}`;
334
367
  }
335
368
  //#endregion
336
- export { uniqueKey as S, withPngMetadata as _, inheritImages as a, slug as b, referenceImagePath as c, MEDIA_TYPES as d, mediaTypeOf as f, readPngMetadata as g, writeImageFileMetadata as h, entityImageDirectory as i, sceneImagePath as l, sidecarOf as m, imageExtensionOf as n, nextSceneSerial as o, readImageFileMetadata as p, LIBRARY_FOLDER as r, readImageMetadata as s, addToLibrary as t, writeImage as u, mapLimit as v, trOf as x, norm as y };
369
+ export { trOf as C, slug as S, writeImageFileMetadata as _, LIBRARY_FOLDER as a, mapLimit as b, nextSceneSerial as c, sceneImagePath as d, writeImage as f, sidecarOf as g, readImageFileMetadata as h, pictureHash as i, readImageMetadata as l, mediaTypeOf as m, imageExtensionOf as n, entityImageDirectory as o, MEDIA_TYPES as p, libraryHashes as r, inheritImages as s, addToLibrary as t, referenceImagePath as u, readPngMetadata as v, uniqueKey as w, norm as x, withPngMetadata as y };
337
370
 
338
- //# sourceMappingURL=library-BGxPKs9a.js.map
371
+ //# sourceMappingURL=library-lVNf9qG_.js.map
@@ -1,9 +1,9 @@
1
1
  import "./access-DtOxFKBK.js";
2
- import { Ct as loadLorebook, Dt as updateLorebookInfo, Ht as ImportCardError, J as partsOf, K as cleanText, Kt as LORE_KINDS, Ot as writeLorebookEntry, Tt as readLorebook$1, Y as withPlayer, bt as entriesOf, ct as IMPORT_FOLDER, i as contextOf, qt as LORE_SCOPES, r as MAX_PREVIEW_TEXT, wt as lorebookDirectory, yt as deleteLorebookEntry } from "./authoring-tools-q34iq3hW.js";
3
- import { c as createPresetFromGuidance } from "./route-DRTJ_vcA.js";
4
- import { nt as shippedPromptsDirectory } from "./hooks-HnqXO8mM.js";
5
- import { i as translator, r as languageOf } from "./text-JbWfTHbr.js";
6
- import { S as uniqueKey, b as slug, v as mapLimit, x as trOf } from "./library-BGxPKs9a.js";
2
+ import { Dt as IMPORT_FOLDER, Gt as loadLorebook, Ht as entriesOf, Kt as lorebookDirectory, Vt as deleteLorebookEntry, Xt as writeLorebookEntry, Yt as updateLorebookInfo, dt as cleanText, hn as LORE_SCOPES, i as contextOf, mn as LORE_KINDS, mt as withPlayer, pt as partsOf, qt as readLorebook$1, r as MAX_PREVIEW_TEXT, un as ImportCardError } from "./authoring-tools-CIsWbq0B.js";
3
+ import { c as createPresetFromGuidance } from "./route-C6SHz9j2.js";
4
+ import { nt as shippedPromptsDirectory } from "./hooks-C8eELrni.js";
5
+ import { i as translator, r as languageOf } from "./text-Cwl5s0j0.js";
6
+ import { C as trOf, S as slug, b as mapLimit, w as uniqueKey } from "./library-lVNf9qG_.js";
7
7
  import { join } from "node:path";
8
8
  import { existsSync, readFileSync } from "node:fs";
9
9
  import { defineTool } from "@deepseek-ai/dsh-tools";
@@ -699,4 +699,4 @@ async function lorebookApproval(exec, next, state) {
699
699
  //#endregion
700
700
  export { lorebookImportMessage as a, readLorebook as c, lorebookOfChat as d, lorebookAuthorTools as i, selectEntries as l, LorebookReader as n, pendingTargets as o, lorebookApproval as r, previewLorebook as s, LOREBOOK_UPLOAD as t, lorebookChatSessionId as u };
701
701
 
702
- //# sourceMappingURL=lorebook-author-tools-D9RrMK5g.js.map
702
+ //# sourceMappingURL=lorebook-author-tools-BDOs4i5C.js.map
@@ -1,6 +1,6 @@
1
- import { n as limitAuthoringAgents, wt as lorebookDirectory } from "./authoring-tools-q34iq3hW.js";
2
- import { d as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-D9RrMK5g.js";
3
- import "./hooks-HnqXO8mM.js";
1
+ import { Kt as lorebookDirectory, n as limitAuthoringAgents } from "./authoring-tools-CIsWbq0B.js";
2
+ import { d as lorebookOfChat, i as lorebookAuthorTools, n as LorebookReader, o as pendingTargets, r as lorebookApproval } from "./lorebook-author-tools-BDOs4i5C.js";
3
+ import "./hooks-C8eELrni.js";
4
4
  import { t as guardAuthoringTurns } from "./turn-guard-BvCs1VxB.js";
5
5
  import { join } from "node:path";
6
6
  import { existsSync, readdirSync } from "node:fs";
@@ -1,14 +1,14 @@
1
1
  import { a as chatSessionId, o as roleplaySessionOf, t as promptFor } from "./access-DtOxFKBK.js";
2
- import { E as INTENT_STATUSES, a as routeVerdicts, i as noAt, n as askYesNo, o as yesAt, t as announceProblem } from "./route-DRTJ_vcA.js";
3
- import { _ as referent, a as whereabouts, g as sameWords, n as memoryReflector, r as recordFailure, s as Timelines, t as dueReflection } from "./reflection-CvOZGjmn.js";
2
+ import { E as INTENT_STATUSES, a as routeVerdicts, i as noAt, n as askYesNo, o as yesAt, t as announceProblem } from "./route-C6SHz9j2.js";
3
+ import { _ as referent, a as whereabouts, g as sameWords, n as memoryReflector, r as recordFailure, s as Timelines, t as dueReflection } from "./reflection-CJB5s0ip.js";
4
4
  import { a as liveSettings, g as GATE_SITES, n as encodeOutput } from "./narration-DvFBqmqe.js";
5
- import { D as describeWhen, O as zoneOf, R as wrongLanguage, T as ClockError, c as record, d as toolEnabled, f as MAX_OOC_ANSWER, k as RESULTS, l as AUTHORING_NEEDS, n as installHooks, o as PREVIEW_TOOL, ot as ReflectionRefusedError, p as storesOf, r as externalGiven, s as createTools$1, u as characterRunner, v as readVerdicts, y as writeVerdicts } from "./hooks-HnqXO8mM.js";
6
- import { i as translator, r as languageOf } from "./text-JbWfTHbr.js";
5
+ import { D as describeWhen, O as zoneOf, R as wrongLanguage, T as ClockError, c as record, d as toolEnabled, f as MAX_OOC_ANSWER, k as RESULTS, l as AUTHORING_NEEDS, n as installHooks, o as PREVIEW_TOOL, ot as ReflectionRefusedError, p as storesOf, r as externalGiven, s as createTools$1, u as characterRunner, v as readVerdicts, y as writeVerdicts } from "./hooks-C8eELrni.js";
6
+ import { i as translator, r as languageOf } from "./text-Cwl5s0j0.js";
7
7
  import { a as childTrace, c as runChild, h as currentTurn, n as childModel, r as childSampling, v as estimateAnswer, y as tokensOf } from "./child-CyCViUKa.js";
8
- import { S as uniqueKey, b as slug, t as addToLibrary } from "./library-BGxPKs9a.js";
9
- import { _ as API_PREFIX } from "./packs-jowC-MN_.js";
10
- import { i as updateImage, r as listGallery, t as describeGalleryImage } from "./gallery-BxZGOgMb.js";
11
- import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-DvZtnf0Q.js";
8
+ import { S as slug, t as addToLibrary, w as uniqueKey } from "./library-lVNf9qG_.js";
9
+ import { _ as API_PREFIX } from "./packs-CY8ms8v_.js";
10
+ import { i as updateImage, r as listGallery, t as describeGalleryImage } from "./gallery-DmBZ2L5l.js";
11
+ import { n as interpretImage, s as presentedFor, t as runImagePresenter } from "./presenter-agent-cFR4sos3.js";
12
12
  import { join } from "node:path";
13
13
  import { existsSync } from "node:fs";
14
14
  import { SessionId } from "@deepseek-ai/dsh-session";