@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.
- package/lib/{authoring-tools-BpkpGMSO.js → authoring-tools-CKV1UnN7.js} +1133 -139
- package/lib/authoring.js +340 -54
- package/lib/client.js +1675 -729
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +2 -2
- package/lib/doctor.js +2 -2
- package/lib/{library-CnWOHwQl.js → gallery-CT5uj50b.js} +212 -7
- package/lib/{hooks-P_--KSFl.js → hooks-CnxV2uEh.js} +46 -17
- package/lib/images.js +3 -4
- package/lib/index.js +409 -26
- package/lib/{presenter-agent-BTpJxmGi.js → interpreter-Cz5qsuXk.js} +155 -64
- package/lib/{lorebook-author-tools-CWZ6WRN-.js → lorebook-author-tools-p3Nfpuxh.js} +6 -6
- package/lib/lorebook-authoring.js +5 -5
- package/lib/{narration-DAHmte8p.js → narration-CUZIXzab.js} +8 -2
- package/lib/orchestration.js +64 -19
- package/lib/{pack-jail-DSTyLhMc.js → pack-jail-KyZen_gy.js} +19 -13
- package/lib/{packs-D9_N8kDF.js → packs-DU171pDX.js} +2 -2
- package/lib/presenter-agent-CwDg0WE8.js +59 -0
- package/lib/{preset-B69AXtip.js → preset-BO8iWQ-n.js} +3 -3
- package/lib/{preset-author-tools-BJtt7D0J.js → preset-author-tools-C83shASm.js} +6 -6
- package/lib/preset-authoring.js +5 -5
- package/lib/{reflection-2uzE3U-v.js → reflection-CXS87Di3.js} +8 -7
- package/lib/{serial-DnVqMDe5.js → serial-xcAG57p_.js} +199 -43
- package/lib/{text-B-HsLdb-.js → text-KnqhN_Zv.js} +4 -1
- package/lib/{turn-guard-D4YHE00t.js → turn-guard-CfsGepCg.js} +2 -2
- package/package.json +3 -2
- package/prompts/en/import/finish-ok.md +2 -0
- package/prompts/en/import/next-stage-go.md +1 -0
- package/prompts/en/import/next-stage-paused.md +1 -0
- package/prompts/en/import/next-survey-paused.md +1 -0
- package/prompts/en/import/notice-staged.md +5 -0
- package/prompts/en/import/pause-stages.md +1 -0
- package/prompts/en/import/pause-survey.md +1 -0
- package/prompts/en/roleplay/image-worth.md +5 -0
- package/prompts/en/world/procedure.md +3 -0
- package/prompts/zh/import/finish-ok.md +2 -0
- package/prompts/zh/import/next-stage-go.md +1 -0
- package/prompts/zh/import/next-stage-paused.md +1 -0
- package/prompts/zh/import/next-survey-paused.md +1 -0
- package/prompts/zh/import/notice-staged.md +5 -0
- package/prompts/zh/import/pause-stages.md +1 -0
- package/prompts/zh/import/pause-survey.md +1 -0
- package/prompts/zh/roleplay/image-worth.md +5 -0
- package/prompts/zh/world/procedure.md +3 -0
- package/lib/gallery-D0h0X7Jy.js +0 -190
- package/lib/generator-CAJkevKl.js +0 -150
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
This turn is the import of a character card into this new, empty world, started by the person with the /import-st command. You do it together with the person: you take a step, tell them in a few short sentences what it did and what is left, and stop where the pause below says so. Until the import is finished do not edit the world yourself (the world is written only by ${finish}), and do not ask the person anything except what the pause allows.
|
|
2
|
+
Your tools, all with card "${card}": ${status} (where the import stands: which stages are done, still to do, or stale), ${survey} (read the card, say what each piece is, list who and what the world is made of), ${surveyShow} and ${surveyEdit} (look at the survey and correct it when the person says it is wrong: the changes are kept), ${stage} (write one part of the world; the stages are ${stages}, in this order; each takes a while, and the person's note for it goes in its guidance), ${show} (what a stage staged, one document in full), ${audit} (what a stage left out), and ${finish} (writes the world and checks it as a whole). The card tools (card_overview, card_search, card_read) compare anything with the card itself.
|
|
3
|
+
The pause for this import is "${pause}": ${policy}
|
|
4
|
+
The import is at "${phase}"${done}. Start with ${status}.
|
|
5
|
+
When ${finish} reports success, review the world as a careful editor and correct what the import got wrong (see what ${finish} tells you). Then tell the person in a few short sentences what was imported (counts), what was left out and why, whether the world has a playable character (if not, say none was found and that you can add one), and anything in the notes that they should know. Then stop.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
stop after the survey and after every stage. After the survey report who and what the world is made of (names, by kind, and who the player plays) and what looked doubtful, and wait; change what the person says is wrong with ${surveyEdit}. After a stage say in a few sentences what it wrote (counts and names), what failed or was left out and why, what is left, and ask whether to go on and whether they have a note for the next stage (it goes in guidance). Do not run the next stage in the same turn. The person may ask to see a document (${show}), to compare a part with the card, or to run a stage again. Before ${finish} say that it writes the world and ask.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
stop after the survey and report: how many pieces and what they are, who and what the world is made of (names, by kind, and who the player plays), and what looked doubtful (the survey tells you; you may look at it with ${surveyShow}). Ask whether it is right and wait. Change what the person says is wrong with ${surveyEdit}, and tell them what you changed. When they agree, run every stage in order, one ${stage} call each, then ${finish}, without stopping again.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
You decide whether one moment of an interactive story deserves a picture. You work only from the passage you are shown and never add a fact that is not in it.
|
|
2
|
+
|
|
3
|
+
A moment deserves a picture when something visual happens or is revealed: a new place is entered or seen for the first time, an important person or creature appears, something striking, beautiful, dramatic or dangerous takes place, or the scene changes in a way a reader would want to see. It does not deserve one when it is mostly conversation, thought, travel through already known ground, bookkeeping, a quiet repeat of the previous scene, or a passage with nothing to look at. When in doubt, it does not.
|
|
4
|
+
|
|
5
|
+
Give your reason in one short sentence first, then say whether the moment deserves a picture.
|
|
@@ -1 +1,4 @@
|
|
|
1
1
|
Use the read tools before making claims or edits. Keys are stable file identities, not display names. Before replacing an element, read its exact source document and preserve fields the requested change does not affect. Every write asks the user for one-time approval, so when a request is clear, make the change with the tool instead of asking whether to go ahead or describing what you would do. If approval is rejected, cancelled or unavailable, do not retry it automatically: explain that nothing changed and ask how the user wants to proceed. To change how a story looks, read world_pack_guide, then write the interface pack file by file with the write tool, using the paths the guide gives, and finish with check_world_pack until it reports no problems. To make the world act by itself, list_world_triggers and get_world_trigger first, then write_world_trigger with a complete document; a trigger that names something the world does not have is refused with every problem, so fix them all. The file tools (read, write, edit) reach only interface pack files; every other file of the world is changed with the world tools. Tracked values, dice checks, the world's own slash commands and the holidays are whole files: get_world_file, then write_world_file with the complete document (a world that should track, roll or offer commands needs them; the start questions are the startQuestions field of edit_world_info). If you have tools for searching the web or reading pages and the user names a setting, franchise or source you do not know well, look it up before you write and say what you found; never invent facts about an existing work. If you have no such tools, say so and ask the user to describe it. If this world was imported from a character card, the card is kept and card_overview, card_search, card_read and card_origin read it: when the user asks where something in the world came from or what the card said, look it up instead of guessing, read the piece with card_read before you answer from a search hit (a title or keys that match prove nothing), and quote only what the answer needs. The world's own files are the canon and the card is evidence of where they came from; if the two differ, say so, and do not change the world to match the card unless the user asks. What card_overview and card_origin say the import did is its own judgement and can be wrong, so check it against the text with card_read. If the tools say there is no card, the world was not imported or the card was removed.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
Before the first edit of each turn the world's files are copied into a checkpoint. When the user wants something undone, or asks what you changed, use list_world_checkpoints, diff_world_checkpoint and read_world_checkpoint_file to see what an earlier version held, and put it back with the editing tools; say what you put back. Restoring the whole world is the user's to do in the editor. After they restore it you are told: read the world again before you edit.
|
|
@@ -9,3 +9,5 @@
|
|
|
9
9
|
报告还会说明:角色卡的状态栏和数值面板变成了多少个变量(variables.json)、角色卡的其他开场白有多少个成为开始会话时可选的开场、以及角色卡的图片是否成为了对应角色的立绘。请简要提及。
|
|
10
10
|
|
|
11
11
|
报告附带 `checks`:程序对每次导入都会运行的检查,已经运行并存放在世界里(世界自身的一致性、与卡片的对照、创作质量)。请阅读这些发现。错误由你修复。警告只是线索:先用 card_read 读卡片的对应片段,再修正有误之处,或说明为什么不改。提示只需一提。由模型判断的检查还没有运行。卡片很长、或其中很多片段被改写成了背景条目、或者快速检查显示有事实丢失或被编造时,用 deep 为 true 运行 check_card;角色设定很空、或世界显得单薄时,用 deep 为 true 运行 check_quality。修正之后再运行一次,确认那条发现消失了。不要为了运行而运行,也不要用卡片没有写的内容去填补空缺。
|
|
12
|
+
|
|
13
|
+
卡片中的网址所指向的图片已下载到世界的图片库,每张图片都带着它的来源网址和包含该网址的卡片片段。请调用 list_world_images。对于没有描述的图片,或卡片片段说明了图中是谁的图片,用 card_read 读取该片段(网址周围的文字),再把你能够核实的事实写进图片:用 describe_world_image 并把那段文字作为上下文,来写描述和主体;用 edit_world_image 来修正。只有当卡片文字或图片本身足够清楚时,才写出角色、地点或物品的名字;拿不准的图片保持原样,并说明这一点。绝不添加卡片没有写的内容。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
接下来请调用 ${next},card 参数为“${card}”。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
请在这里停下,按这次导入的暂停规则向用户汇报:这个阶段写了什么,哪些失败或被略去及原因,还剩什么(${left})。不要在这一轮里运行下一个阶段。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
请在这里停下,按这次导入的暂停规则向用户汇报:世界由哪些人和事物构成,以及哪些地方存疑。先不要运行任何阶段。
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
这一轮是把一张角色卡导入这个全新的空世界,由用户通过 /import-st 命令发起。你和用户一起完成它:你做一步,用几句简短的话告诉他这一步做了什么、还剩什么,并按下面的暂停规则停下。导入完成之前,不要自己去修改世界(世界只由 ${finish} 写入),除了暂停规则允许的,也不要向用户提问。
|
|
2
|
+
你的工具,参数 card 都是“${card}”:${status}(导入进行到哪里:哪些阶段已完成、待做或已过期)、${survey}(读卡片,说明每一段是什么,列出世界由哪些人和事物构成)、${surveyShow} 和 ${surveyEdit}(查看调查结果,在用户说有误时修改它:修改会被保留)、${stage}(写世界的一个部分;阶段依次是 ${stages};每个阶段需要一些时间,用户对它的要求写在 guidance 里)、${show}(某个阶段暂存的内容,可完整查看一份文档)、${audit}(某个阶段漏掉了什么)、${finish}(写入世界并整体检查)。卡片工具(card_overview、card_search、card_read)可以把任何内容与卡片本身对照。
|
|
3
|
+
这次导入的暂停规则是“${pause}”:${policy}
|
|
4
|
+
导入目前处于“${phase}”${done}。先调用 ${status}。
|
|
5
|
+
当 ${finish} 报告成功后,像一位细心的编辑那样检查这个世界,并纠正导入出错的地方(按 ${finish} 的提示)。然后用几句简短的话告诉用户:导入了什么(数量)、略去了什么以及原因、世界里是否有可扮演的角色(如果没有,说明没有找到,并说你可以添加一个)、以及备注中值得他们知道的内容。然后就停下。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
调查结束后停下,每个阶段结束后也停下。调查之后汇报世界由哪些人和事物构成(按类别列出名字,以及玩家扮演谁)和存疑之处,然后等待;用户说有误的地方,用 ${surveyEdit} 修改。每个阶段之后用几句话说明:它写了什么(数量和名字)、哪些失败或被略去及原因、还剩什么,并问是否继续、对下一个阶段有没有要求(写在 guidance 里)。不要在同一轮里运行下一个阶段。用户可以要求查看某份文档(${show})、把某个部分与卡片对照,或重新运行某个阶段。调用 ${finish} 之前说明它会写入世界,并征求同意。
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
调查结束后停下并汇报:有多少段、各是什么,世界由哪些人和事物构成(按类别列出名字,以及玩家扮演谁),以及哪些地方存疑(调查会告诉你,也可以用 ${surveyShow} 查看)。问用户是否正确,然后等待。用户说有误的地方,用 ${surveyEdit} 修改,并告诉他你改了什么。用户同意后,按顺序运行每个阶段,每个阶段调用一次 ${stage},然后调用 ${finish},中途不再停下。
|
|
@@ -1 +1,4 @@
|
|
|
1
1
|
在做出断言或修改之前,先使用读取工具。键(key)是稳定的文件标识,不是显示名称。在替换某个元素之前,先读取它确切的源文档,并保留请求的修改没有涉及的字段。每一次写入都会向用户请求一次性批准。所以请求明确时,直接用工具修改,不必再问是否继续,也不必只描述打算怎么做。如果批准被拒绝、取消或无法获得,不要自动重试:说明没有任何改动,并询问用户想怎么继续。若要改变故事的外观,先阅读 world_pack_guide,再用 write 工具,按指南给出的路径逐个文件编写界面包,最后用 check_world_pack 检查,直到没有问题。若要让世界自行行动,先用 list_world_triggers 和 get_world_trigger 查看,再用 write_world_trigger 写入完整的文档;如果触发器提到世界里没有的东西,会连同所有问题一起被拒绝,请全部修正。文件工具(read、write、edit)只能访问界面包的文件;世界的其他文件都用世界工具修改。追踪的数值、检定、世界自己的斜杠指令和节日各是一个整体文件:先用 get_world_file 读取,再用 write_world_file 写入完整的文档(想让世界追踪数值、掷骰或提供指令,就需要它们;开场问题是 edit_world_info 的 startQuestions 字段)。 如果你有搜索网络或阅读网页的工具,而用户提到了你不太了解的设定、作品或来源,请先查询再动笔,并说明查到了什么;不要编造现有作品的事实。如果你没有这类工具,就直说,并请用户自己描述。 如果这个世界是由角色卡导入的,那张卡会被保留,card_overview、card_search、card_read 和 card_origin 可以读取它:当用户问世界里的某样东西从哪里来、或卡里是怎么写的,要去查,而不是猜测;根据搜索命中作答之前,先用 card_read 读该段(标题或关键词匹配并不能说明什么),并且只引用回答所需的内容。世界自身的文件才是设定,卡只是它们来源的依据;两者不一致时要如实说明,除非用户要求,不要为了与卡一致而修改世界。card_overview 和 card_origin 里关于导入做了什么的说明是导入自己的判断,可能有误,要用 card_read 对照原文核实。如果这些工具说没有卡,说明这个世界不是导入的,或者卡已被移除。
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
每个回合第一次修改之前,世界的文件会被复制成一个检查点。用户想撤销某些修改,或问你改了什么时,用 list_world_checkpoints、diff_world_checkpoint 和 read_world_checkpoint_file 查看更早的版本是什么样,再用编辑工具把它改回去,并说明你改回了什么。还原整个世界由用户在编辑器里操作;他们还原之后你会收到通知:修改之前先重新读取世界。
|
package/lib/gallery-D0h0X7Jy.js
DELETED
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { n as atomicWrite } from "./access-5vtPAT3O.js";
|
|
2
|
-
import { _ as writeImageFileMetadata, a as LIBRARY_FOLDER, g as sidecarOf, h as readImageFileMetadata, m as mediaTypeOf, x as mapLimit } from "./library-CnWOHwQl.js";
|
|
3
|
-
import { join, sep } from "node:path";
|
|
4
|
-
import { lstat, readFile, readdir, realpath, stat } from "node:fs/promises";
|
|
5
|
-
// src/host/images/gallery.ts
|
|
6
|
-
const READ_AT_ONCE = 8;
|
|
7
|
-
const SEGMENT = /^[\p{L}\p{N}][\p{L}\p{N}\p{M}._-]{0,199}$/u;
|
|
8
|
-
const CACHE_FILE = ".index.json";
|
|
9
|
-
const CACHE_VERSION = 1;
|
|
10
|
-
/** The images of the folder: every PNG, and the other raster formats inside the library, whose metadata is beside them. */
|
|
11
|
-
async function imageFiles(images, prefix = "") {
|
|
12
|
-
let entries;
|
|
13
|
-
try {
|
|
14
|
-
entries = await readdir(join(images, prefix), { withFileTypes: true });
|
|
15
|
-
} catch (error) {
|
|
16
|
-
if (error.code === "ENOENT") return [];
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
const found = [];
|
|
20
|
-
for (const entry of entries) {
|
|
21
|
-
if (entry.isSymbolicLink()) continue;
|
|
22
|
-
const path = `${prefix}${entry.name}`;
|
|
23
|
-
if (entry.isDirectory()) found.push(...await imageFiles(images, `${path}/`));
|
|
24
|
-
else if (entry.isFile() && (entry.name.toLowerCase().endsWith(".png") || path.startsWith(`library/`) && mediaTypeOf(entry.name) !== void 0)) found.push(path);
|
|
25
|
-
}
|
|
26
|
-
return found;
|
|
27
|
-
}
|
|
28
|
-
async function factsOf(images, path) {
|
|
29
|
-
const file = join(images, ...path.split("/"));
|
|
30
|
-
const info = await lstat(file);
|
|
31
|
-
const beside = path.toLowerCase().endsWith(".png") ? void 0 : await stat(sidecarOf(file)).then((value) => value.mtimeMs, () => 0);
|
|
32
|
-
return {
|
|
33
|
-
path,
|
|
34
|
-
signature: `${info.mtimeMs}:${info.size}:${beside ?? ""}`
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
async function describe(images, path) {
|
|
38
|
-
const file = join(images, ...path.split("/"));
|
|
39
|
-
const { mtime } = await lstat(file);
|
|
40
|
-
const library = path.startsWith(`${LIBRARY_FOLDER}/`);
|
|
41
|
-
const metadata = await readImageFileMetadata(file);
|
|
42
|
-
if (metadata === void 0 || typeof metadata !== "object") return library ? {
|
|
43
|
-
path,
|
|
44
|
-
purpose: "uploaded",
|
|
45
|
-
origin: "uploaded",
|
|
46
|
-
reusable: true,
|
|
47
|
-
createdAt: mtime.toISOString(),
|
|
48
|
-
tags: [],
|
|
49
|
-
subjects: [],
|
|
50
|
-
pending: true
|
|
51
|
-
} : {
|
|
52
|
-
path,
|
|
53
|
-
purpose: path.startsWith("scenes/") ? "transient" : "reference",
|
|
54
|
-
origin: "generated",
|
|
55
|
-
reusable: false,
|
|
56
|
-
createdAt: mtime.toISOString(),
|
|
57
|
-
tags: [],
|
|
58
|
-
subjects: [],
|
|
59
|
-
unreadable: true
|
|
60
|
-
};
|
|
61
|
-
const origin = metadata.origin ?? (library ? "uploaded" : "generated");
|
|
62
|
-
const purpose = metadata.purpose ?? (origin === "uploaded" ? "uploaded" : path.startsWith("scenes/") ? "transient" : "reference");
|
|
63
|
-
return {
|
|
64
|
-
path,
|
|
65
|
-
purpose,
|
|
66
|
-
origin,
|
|
67
|
-
reusable: origin === "uploaded" ? true : metadata.reusable ?? purpose === "reference",
|
|
68
|
-
createdAt: metadata.createdAt ?? mtime.toISOString(),
|
|
69
|
-
...metadata.prompt === void 0 ? {} : { prompt: metadata.prompt },
|
|
70
|
-
...metadata.revisedPrompt === void 0 ? {} : { revisedPrompt: metadata.revisedPrompt },
|
|
71
|
-
...metadata.description === void 0 ? {} : { description: metadata.description },
|
|
72
|
-
tags: metadata.tags ?? [],
|
|
73
|
-
...metadata.provider === void 0 ? {} : { provider: metadata.provider },
|
|
74
|
-
...metadata.model === void 0 ? {} : { model: metadata.model },
|
|
75
|
-
subjects: (metadata.subjects ?? []).map((subject) => ({
|
|
76
|
-
kind: subject.kind,
|
|
77
|
-
name: subject.name
|
|
78
|
-
})),
|
|
79
|
-
...metadata.source === void 0 ? {} : { source: metadata.source },
|
|
80
|
-
...metadata.originalName === void 0 ? {} : { originalName: metadata.originalName },
|
|
81
|
-
...origin === "uploaded" && metadata.description === void 0 ? { pending: true } : {}
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
async function describeGalleryImage(sessionFolder, path) {
|
|
85
|
-
return await describe(join(sessionFolder, "images"), path);
|
|
86
|
-
}
|
|
87
|
-
async function readCache(images) {
|
|
88
|
-
try {
|
|
89
|
-
const cache = JSON.parse(await readFile(join(images, CACHE_FILE), "utf8"));
|
|
90
|
-
if (cache.version === CACHE_VERSION && typeof cache.entries === "object" && cache.entries !== null) return cache;
|
|
91
|
-
} catch {}
|
|
92
|
-
return {
|
|
93
|
-
version: CACHE_VERSION,
|
|
94
|
-
entries: {}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
async function writeCache(images, cache) {
|
|
98
|
-
await atomicWrite(join(images, CACHE_FILE), JSON.stringify(cache), { createDirectory: true });
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Every image of a session folder with what its file says, newest first. The files are the truth; `images/.index.json` only remembers what
|
|
102
|
-
* was read from each, keyed by its size and time, so that a listing reads just the files that are new or changed. It can be deleted at any time.
|
|
103
|
-
*/
|
|
104
|
-
async function listGallery(sessionFolder) {
|
|
105
|
-
const images = join(sessionFolder, "images");
|
|
106
|
-
const paths = await imageFiles(images);
|
|
107
|
-
if (paths.length === 0) return [];
|
|
108
|
-
const cache = await readCache(images);
|
|
109
|
-
const facts = await mapLimit(paths, READ_AT_ONCE, (path) => factsOf(images, path));
|
|
110
|
-
const entries = {};
|
|
111
|
-
let changed = Object.keys(cache.entries).length !== paths.length;
|
|
112
|
-
const described = await mapLimit(facts, READ_AT_ONCE, async ({ path, signature }) => {
|
|
113
|
-
const known = cache.entries[path];
|
|
114
|
-
if (known?.signature === signature) {
|
|
115
|
-
entries[path] = known;
|
|
116
|
-
return known.image;
|
|
117
|
-
}
|
|
118
|
-
changed = true;
|
|
119
|
-
const image = await describe(images, path);
|
|
120
|
-
entries[path] = {
|
|
121
|
-
signature,
|
|
122
|
-
image
|
|
123
|
-
};
|
|
124
|
-
return image;
|
|
125
|
-
});
|
|
126
|
-
if (changed) await writeCache(images, {
|
|
127
|
-
version: CACHE_VERSION,
|
|
128
|
-
entries
|
|
129
|
-
});
|
|
130
|
-
return described.sort((a, b) => b.createdAt.localeCompare(a.createdAt) || a.path.localeCompare(b.path));
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* The file of a gallery image by its path, which must be one the listing gives: a raster image inside the session's images, not reached through a link.
|
|
134
|
-
* @throws {Error} when the path names no such image.
|
|
135
|
-
*/
|
|
136
|
-
async function galleryFile(sessionFolder, path) {
|
|
137
|
-
const parts = path.split("/");
|
|
138
|
-
const mediaType = mediaTypeOf(path);
|
|
139
|
-
if (parts.length === 0 || mediaType === void 0 || mediaType !== "image/png" && parts[0] !== "library" || parts.some((part) => !SEGMENT.test(part) || part === "." || part === "..")) throw new Error("there is no such image");
|
|
140
|
-
const images = join(sessionFolder, "images");
|
|
141
|
-
const file = join(images, ...parts);
|
|
142
|
-
const info = await lstat(file).catch(() => void 0);
|
|
143
|
-
if (info === void 0 || !info.isFile()) throw new Error("there is no such image");
|
|
144
|
-
if (!(await realpath(file)).startsWith(`${await realpath(images)}${sep}`)) throw new Error("there is no such image");
|
|
145
|
-
return {
|
|
146
|
-
file,
|
|
147
|
-
size: info.size,
|
|
148
|
-
mediaType
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Changes what an image says about itself, in the file. An image the person brought is always reusable.
|
|
153
|
-
* @throws {Error} when the path names no image of the session, or an uploaded image is made not reusable.
|
|
154
|
-
*/
|
|
155
|
-
async function updateImage(sessionFolder, path, update) {
|
|
156
|
-
const { file } = await galleryFile(sessionFolder, path);
|
|
157
|
-
const current = await describe(join(sessionFolder, "images"), path);
|
|
158
|
-
if (update.reusable === false && current.origin === "uploaded") throw new Error("an image you brought is always reusable: otherwise it would only sit there");
|
|
159
|
-
const existing = await readImageFileMetadata(file);
|
|
160
|
-
const next = {
|
|
161
|
-
schema: "dsh-roleplay-image/v3",
|
|
162
|
-
purpose: current.purpose,
|
|
163
|
-
origin: current.origin,
|
|
164
|
-
reusable: current.reusable,
|
|
165
|
-
createdAt: current.createdAt,
|
|
166
|
-
tags: current.tags,
|
|
167
|
-
subjects: current.subjects.map((subject) => ({
|
|
168
|
-
kind: subject.kind,
|
|
169
|
-
localId: subject.name,
|
|
170
|
-
name: subject.name
|
|
171
|
-
})),
|
|
172
|
-
...existing,
|
|
173
|
-
schema: "dsh-roleplay-image/v3",
|
|
174
|
-
origin: current.origin,
|
|
175
|
-
...update.description === void 0 ? {} : { description: update.description },
|
|
176
|
-
...update.tags === void 0 ? {} : { tags: update.tags },
|
|
177
|
-
...update.subjects === void 0 ? {} : { subjects: update.subjects.map((subject) => ({
|
|
178
|
-
kind: subject.kind,
|
|
179
|
-
localId: subject.name,
|
|
180
|
-
name: subject.name
|
|
181
|
-
})) },
|
|
182
|
-
...update.reusable === void 0 ? {} : { reusable: update.reusable },
|
|
183
|
-
...update.interpretedBy === void 0 ? {} : { interpretedBy: update.interpretedBy }
|
|
184
|
-
};
|
|
185
|
-
await writeImageFileMetadata(file, next);
|
|
186
|
-
return await describe(join(sessionFolder, "images"), path);
|
|
187
|
-
}
|
|
188
|
-
export { updateImage as i, galleryFile as n, listGallery as r, describeGalleryImage as t };
|
|
189
|
-
|
|
190
|
-
//# sourceMappingURL=gallery-D0h0X7Jy.js.map
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { d as sceneImagePath, f as writeImage, u as referenceImagePath } from "./library-CnWOHwQl.js";
|
|
2
|
-
// src/host/images/generator.ts
|
|
3
|
-
const unique = (values) => [...new Set(values.map((value) => value.trim()).filter((value) => value !== ""))];
|
|
4
|
-
/** What a reference image shows: the subject and its stable look. */
|
|
5
|
-
function referenceDescription(request) {
|
|
6
|
-
return `${request.subject.name} (${request.subject.kind}): ${request.identity.description}`.trim();
|
|
7
|
-
}
|
|
8
|
-
/** What a scene image shows: the established moment, then how each subject looks in it. */
|
|
9
|
-
function transientDescription(request) {
|
|
10
|
-
return [request.scene.trim(), ...request.subjects.map((subject) => subject.transient.trim() === "" ? void 0 : `${subject.name}: ${subject.transient.trim()}`)].filter((part) => part !== void 0 && part !== "").join("\n");
|
|
11
|
-
}
|
|
12
|
-
function lines(parts) {
|
|
13
|
-
return parts.filter((part) => part !== void 0 && part.trim() !== "").join("\n");
|
|
14
|
-
}
|
|
15
|
-
function referencePrompt(request) {
|
|
16
|
-
const { subject, identity } = request;
|
|
17
|
-
return lines([
|
|
18
|
-
request.artDirection,
|
|
19
|
-
`Create a canonical reference image of the ${subject.kind} ${subject.name}.`,
|
|
20
|
-
identity.description,
|
|
21
|
-
identity.tags.length === 0 ? void 0 : `Stable visual traits: ${identity.tags.join(", ")}.`,
|
|
22
|
-
"Show the subject clearly and neutrally. Do not add story events or temporary changes.",
|
|
23
|
-
identity.negativeTags.length === 0 ? void 0 : `Avoid: ${identity.negativeTags.join(", ")}.`
|
|
24
|
-
]);
|
|
25
|
-
}
|
|
26
|
-
/** What one subject must not look like may well be what another in the same picture does look like, so a trait that any subject has is not avoided. */
|
|
27
|
-
function avoidedIn(subjects) {
|
|
28
|
-
const wanted = new Set(subjects.flatMap((subject) => subject.identity.tags.map((tag) => tag.trim().toLowerCase())));
|
|
29
|
-
const avoided = [...new Set(subjects.flatMap((subject) => subject.identity.negativeTags))].filter((tag) => !wanted.has(tag.trim().toLowerCase()));
|
|
30
|
-
return avoided.length === 0 ? void 0 : `Avoid: ${avoided.join(", ")}.`;
|
|
31
|
-
}
|
|
32
|
-
function transientPrompt(request) {
|
|
33
|
-
return lines([
|
|
34
|
-
request.artDirection,
|
|
35
|
-
`Illustrate this established story moment: ${request.scene}`,
|
|
36
|
-
...request.subjects.map((subject) => lines([
|
|
37
|
-
`${subject.kind} ${subject.name}: ${subject.identity.description}`,
|
|
38
|
-
subject.identity.tags.length === 0 ? void 0 : `Stable visual traits: ${subject.identity.tags.join(", ")}.`,
|
|
39
|
-
subject.transient === "" ? void 0 : `Current visible state: ${subject.transient}`
|
|
40
|
-
])),
|
|
41
|
-
"Preserve every canonical identity. Depict only the stated subjects, state and action; do not invent story facts.",
|
|
42
|
-
avoidedIn(request.subjects)
|
|
43
|
-
]);
|
|
44
|
-
}
|
|
45
|
-
async function firstPng(service, prompt, options = {}) {
|
|
46
|
-
const result = await service.generate(prompt, {
|
|
47
|
-
count: 1,
|
|
48
|
-
...options
|
|
49
|
-
});
|
|
50
|
-
const image = result.images[0];
|
|
51
|
-
if (image === void 0) throw new Error(`${service.provider} returned no image`);
|
|
52
|
-
if (image.mediaType !== "image/png") throw new Error(`${service.provider} returned ${image.mediaType}; roleplay image storage currently requires PNG`);
|
|
53
|
-
return {
|
|
54
|
-
data: new Uint8Array(await image.data.arrayBuffer()),
|
|
55
|
-
model: result.model,
|
|
56
|
-
...image.revisedPrompt === void 0 ? {} : { revisedPrompt: image.revisedPrompt }
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
/** Generates the stable reference.png of one entity. It is intentionally not registered in the live roleplay loop yet. */
|
|
60
|
-
async function generateReferenceImage(service, request) {
|
|
61
|
-
const prompt = referencePrompt(request);
|
|
62
|
-
const image = await firstPng(service, prompt, request.signal === void 0 ? {} : { signal: request.signal });
|
|
63
|
-
request.signal?.throwIfAborted();
|
|
64
|
-
const path = referenceImagePath(request.root, request.subject);
|
|
65
|
-
const metadata = {
|
|
66
|
-
schema: "dsh-roleplay-image/v3",
|
|
67
|
-
purpose: "reference",
|
|
68
|
-
origin: "generated",
|
|
69
|
-
reusable: true,
|
|
70
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
71
|
-
prompt,
|
|
72
|
-
description: referenceDescription(request),
|
|
73
|
-
tags: unique([request.subject.name, ...request.identity.tags]),
|
|
74
|
-
...image.revisedPrompt === void 0 ? {} : { revisedPrompt: image.revisedPrompt },
|
|
75
|
-
provider: service.provider,
|
|
76
|
-
model: image.model,
|
|
77
|
-
subjects: [{
|
|
78
|
-
...request.subject,
|
|
79
|
-
identityVersion: request.identity.version
|
|
80
|
-
}]
|
|
81
|
-
};
|
|
82
|
-
await writeImage(path, image.data, metadata, { replace: true });
|
|
83
|
-
return path;
|
|
84
|
-
}
|
|
85
|
-
const PNG_SIGNATURE = [
|
|
86
|
-
137,
|
|
87
|
-
80,
|
|
88
|
-
78,
|
|
89
|
-
71,
|
|
90
|
-
13,
|
|
91
|
-
10,
|
|
92
|
-
26,
|
|
93
|
-
10
|
|
94
|
-
];
|
|
95
|
-
/** Takes a picture the person brought as the stable reference.png of one entity, replacing the one there. Only PNG is stored, so any other format is refused. */
|
|
96
|
-
async function uploadReferenceImage(request) {
|
|
97
|
-
if (request.png.length < PNG_SIGNATURE.length || PNG_SIGNATURE.some((byte, index) => request.png[index] !== byte)) throw new Error("the portrait must be a PNG picture: convert it first");
|
|
98
|
-
const path = referenceImagePath(request.root, request.subject);
|
|
99
|
-
const metadata = {
|
|
100
|
-
schema: "dsh-roleplay-image/v3",
|
|
101
|
-
purpose: "reference",
|
|
102
|
-
origin: "uploaded",
|
|
103
|
-
reusable: true,
|
|
104
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
105
|
-
description: `${request.subject.name}, a picture brought by the author.`,
|
|
106
|
-
tags: [request.subject.name],
|
|
107
|
-
...request.originalName === void 0 ? {} : { originalName: request.originalName },
|
|
108
|
-
subjects: [request.subject]
|
|
109
|
-
};
|
|
110
|
-
await writeImage(path, request.png, metadata, { replace: true });
|
|
111
|
-
return path;
|
|
112
|
-
}
|
|
113
|
-
/** Generates one immutable scene image for a timeline node. It is intentionally not registered in the live roleplay loop yet. */
|
|
114
|
-
async function generateTransientImage(service, request) {
|
|
115
|
-
if (request.subjects.length === 0) throw new Error("a transient image needs at least one subject");
|
|
116
|
-
const prompt = transientPrompt(request);
|
|
117
|
-
const image = await firstPng(service, prompt, {
|
|
118
|
-
...request.references === void 0 ? {} : { references: request.references },
|
|
119
|
-
...request.signal === void 0 ? {} : { signal: request.signal }
|
|
120
|
-
});
|
|
121
|
-
request.signal?.throwIfAborted();
|
|
122
|
-
const path = sceneImagePath(request.root, request.timelineNode, request.serial);
|
|
123
|
-
const metadata = {
|
|
124
|
-
schema: "dsh-roleplay-image/v3",
|
|
125
|
-
purpose: "transient",
|
|
126
|
-
origin: "generated",
|
|
127
|
-
reusable: request.reusable === true,
|
|
128
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
129
|
-
prompt,
|
|
130
|
-
description: transientDescription(request),
|
|
131
|
-
tags: unique(request.subjects.flatMap((subject) => [subject.name, ...subject.identity.tags])),
|
|
132
|
-
...image.revisedPrompt === void 0 ? {} : { revisedPrompt: image.revisedPrompt },
|
|
133
|
-
provider: service.provider,
|
|
134
|
-
model: image.model,
|
|
135
|
-
subjects: request.subjects.map(({ identity, transient: _transient, ...subject }) => ({
|
|
136
|
-
...subject,
|
|
137
|
-
identityVersion: identity.version
|
|
138
|
-
})),
|
|
139
|
-
source: {
|
|
140
|
-
turn: request.turn,
|
|
141
|
-
timelineNode: request.timelineNode,
|
|
142
|
-
...request.segment === void 0 ? {} : { segment: request.segment }
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
await writeImage(path, image.data, metadata);
|
|
146
|
-
return path;
|
|
147
|
-
}
|
|
148
|
-
export { uploadReferenceImage as a, transientPrompt as i, generateTransientImage as n, referencePrompt as r, generateReferenceImage as t };
|
|
149
|
-
|
|
150
|
-
//# sourceMappingURL=generator-CAJkevKl.js.map
|