@dsh-agentic-roleplay/core 0.12.5 → 0.12.7
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/{access-DjA0kvPM.js → access-5vtPAT3O.js} +2 -2
- package/lib/{authoring-tools-DqAttdUN.js → authoring-tools-Bi9YQ9QH.js} +52 -18
- package/lib/authoring.js +228 -35
- package/lib/{child-SMvjNsb8.js → child-Bfj7-Iuo.js} +11 -13
- package/lib/client.js +910 -526
- package/lib/client.js.map +1 -1
- package/lib/compaction.js +4 -4
- package/lib/doctor.js +3 -3
- package/lib/{library-D6AcyxGZ.js → gallery-BT5lf-T5.js} +212 -7
- package/lib/helper.js +2 -2
- package/lib/{hooks-OLl-1AOS.js → hooks-DR-HqE50.js} +6 -4
- package/lib/images.js +3 -4
- package/lib/index.js +131 -23
- package/lib/{presenter-agent-CGCJrg7V.js → interpreter-BYNrjYZo.js} +155 -64
- package/lib/{jail-CDW5iymd.js → jail-D83JnxKg.js} +2 -2
- package/lib/{lorebook-author-tools-CXV1KD4Q.js → lorebook-author-tools-BI-r8fEt.js} +6 -6
- package/lib/lorebook-authoring.js +5 -5
- package/lib/{narration-Bnrvl0UQ.js → narration-CUZIXzab.js} +9 -3
- package/lib/orchestration.js +59 -19
- package/lib/{pack-jail-CZAmlgE1.js → pack-jail-Y1XPbqHw.js} +20 -14
- package/lib/{packs-DUVCSHqi.js → packs-DD-v-Epl.js} +2 -2
- package/lib/presenter-agent-00sOVGI9.js +59 -0
- package/lib/{preset-BYfXYvp0.js → preset-Bnx3jhUv.js} +4 -4
- package/lib/{preset-author-tools-DYxTLm9U.js → preset-author-tools-DYrBcieA.js} +6 -6
- package/lib/preset-authoring.js +5 -5
- package/lib/{reflection-C3zdufN9.js → reflection-DqxoV9xE.js} +10 -9
- package/lib/{serial-Bh6gqb3f.js → serial-CS46qAvI.js} +57 -11
- package/lib/{turn-guard-CNFvmz_F.js → turn-guard-bZkxzRXJ.js} +3 -3
- package/package.json +32 -31
- package/prompts/en/import/finish-ok.md +2 -0
- package/prompts/en/roleplay/image-worth.md +5 -0
- package/prompts/zh/import/finish-ok.md +2 -0
- package/prompts/zh/roleplay/image-worth.md +5 -0
- package/lib/gallery-Dahi5TkO.js +0 -190
- package/lib/generator-BvSZGpzy.js +0 -150
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { d as sceneImagePath, f as writeImage, u as referenceImagePath } from "./library-D6AcyxGZ.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-BvSZGpzy.js.map
|