briyah 2.0.4 → 2.0.6
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/README.md +12 -1
- package/data/common/config/markup +1 -1
- package/data/common/config/story_models.json +3 -3
- package/data/common/prompts/illustrator/describe_scene.prompt +4 -4
- package/data/common/prompts/moderate.json +34 -0
- package/data/common/prompts/moderate.prompt +136 -0
- package/data/common/prompts/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +1 -1
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +795 -787
- package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +2 -1
- package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +1 -1
- package/data/packs/dnd5e/rooms/campaign.json +18 -15
- package/data/packs/dnd5e/rooms/table.json +17 -16
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +38 -0
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +83 -16
- package/dist-sdk/server/src/ai/LLM/blank-image.d.ts +36 -0
- package/dist-sdk/server/src/ai/LLM/blank-image.js +80 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/fal.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/grok.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/openai.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +1 -1
- package/dist-sdk/server/src/ai/LLM/together.service.js +1 -1
- package/dist-sdk/server/src/ai/agent-config.d.ts +0 -1
- package/dist-sdk/server/src/ai/agent-store.service.js +2 -4
- package/dist-sdk/server/src/ai/agent.d.ts +7 -2
- package/dist-sdk/server/src/ai/agent.js +11 -3
- package/dist-sdk/server/src/app/user-service-factory.js +8 -2
- package/dist-sdk/server/src/app.controller.d.ts +33 -0
- package/dist-sdk/server/src/app.controller.js +93 -2
- package/dist-sdk/server/src/app.service.d.ts +49 -4
- package/dist-sdk/server/src/app.service.js +101 -16
- package/dist-sdk/server/src/auth/jwt-auth.guard.js +26 -0
- package/dist-sdk/server/src/data/data-guide.builder.d.ts +2 -0
- package/dist-sdk/server/src/data/data-guide.builder.js +90 -0
- package/dist-sdk/server/src/data/data-registry.d.ts +32 -0
- package/dist-sdk/server/src/data/data-registry.js +61 -0
- package/dist-sdk/server/src/data/data.types.d.ts +158 -0
- package/dist-sdk/server/src/data/data.types.js +24 -0
- package/dist-sdk/server/src/data/query-validation.d.ts +45 -0
- package/dist-sdk/server/src/data/query-validation.js +245 -0
- package/dist-sdk/server/src/packs/pack-instantiation.service.js +5 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +14 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +11 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +211 -0
- package/dist-sdk/server/src/room/illustration/illustration.service.js +771 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +101 -0
- package/dist-sdk/server/src/room/illustration/illustration.types.js +2 -0
- package/dist-sdk/server/src/room/room-config.d.ts +58 -1
- package/dist-sdk/server/src/room/room-config.js +19 -0
- package/dist-sdk/server/src/room/room-factory.d.ts +8 -0
- package/dist-sdk/server/src/room/room-factory.js +11 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +8 -0
- package/dist-sdk/server/src/room/room-store.service.js +43 -2
- package/dist-sdk/server/src/room/room.d.ts +110 -6
- package/dist-sdk/server/src/room/room.js +277 -10
- package/dist-sdk/server/src/rpg/rpg.service.js +5 -1
- package/dist-sdk/server/src/sdk/index.d.ts +4 -0
- package/dist-sdk/server/src/sdk/index.js +11 -1
- package/dist-sdk/server/src/story/story.service.d.ts +24 -65
- package/dist-sdk/server/src/story/story.service.js +105 -458
- package/dist-sdk/server/src/tools/core/data.tools.d.ts +17 -0
- package/dist-sdk/server/src/tools/core/data.tools.js +165 -0
- package/dist-sdk/server/src/tools/core/illustrate.tool.d.ts +14 -0
- package/dist-sdk/server/src/tools/core/illustrate.tool.js +80 -0
- package/dist-sdk/server/src/tools/core/index.js +3 -1
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +90 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +9 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +5 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +30 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +75 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +11 -2
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +36 -5
- package/dist-sdk/server/src/tools/tool-execution.service.js +91 -21
- package/dist-sdk/shared/types/app.types.d.ts +43 -0
- package/dist-sdk/shared/types/app.types.js +15 -1
- package/package.json +1 -1
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Agent } from '../../ai/agent';
|
|
2
|
+
import { AgentFactory } from '../../ai/agent-factory';
|
|
3
|
+
import { AgentStoreService } from '../../ai/agent-store.service';
|
|
4
|
+
import { ArtifactService } from '../../ai/artifact.service';
|
|
5
|
+
import { UserPathsService } from '../../config/user-paths.service';
|
|
6
|
+
import { Room } from '../room';
|
|
7
|
+
import { IllustrationAgents, IllustrationRequest, IllustrationTarget } from './illustration.types';
|
|
8
|
+
/**
|
|
9
|
+
* Turns a scene into a picture and posts it into the room.
|
|
10
|
+
*
|
|
11
|
+
* Lifted wholesale out of StoryService so that stories, RPG campaigns and plain
|
|
12
|
+
* rooms share one implementation. Everything that differs between them is behind
|
|
13
|
+
* {@link IllustrationTarget}; this class never learns what a story is.
|
|
14
|
+
*
|
|
15
|
+
* The shape of the pipeline, unchanged from where it came from:
|
|
16
|
+
*
|
|
17
|
+
* describe_scene → the illustrator decides whether a picture is warranted,
|
|
18
|
+
* names the setting, and writes the image prompt
|
|
19
|
+
* ├ new setting → draw a character-free reference, then run again on top of it
|
|
20
|
+
* └ known setting → make sure every named character has a portrait, then draw
|
|
21
|
+
* the scene with the reference and those portraits as inputs
|
|
22
|
+
* → post `` as a SYSTEM message, which notifies over SSE
|
|
23
|
+
*
|
|
24
|
+
* Nothing here throws at the caller. An illustration is a nicety; failing to make
|
|
25
|
+
* one must never take down the turn that asked for it.
|
|
26
|
+
*/
|
|
27
|
+
export declare class IllustrationService {
|
|
28
|
+
private readonly userPaths;
|
|
29
|
+
private readonly agentStore;
|
|
30
|
+
private readonly agentFactory;
|
|
31
|
+
/**
|
|
32
|
+
* Targets currently drawing, by key. An image takes minutes and the situation
|
|
33
|
+
* will change several times meanwhile, so overlapping requests are dropped
|
|
34
|
+
* rather than queued.
|
|
35
|
+
*/
|
|
36
|
+
private readonly inFlight;
|
|
37
|
+
constructor(userPaths: UserPathsService, agentStore: AgentStoreService, agentFactory: AgentFactory);
|
|
38
|
+
/**
|
|
39
|
+
* Whether a picture is being drawn for this target right now.
|
|
40
|
+
* @param key The target key
|
|
41
|
+
*/
|
|
42
|
+
isBusy(key: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Describes a plain room to the pipeline.
|
|
45
|
+
*
|
|
46
|
+
* Images go in an `images/` subdirectory rather than the room directory
|
|
47
|
+
* itself: `ArtifactService` keeps its index in `metadata.json`, and so does
|
|
48
|
+
* the room, so pointing one at the other would overwrite the room's config.
|
|
49
|
+
* Being inside the room directory does mean the existing recursive delete
|
|
50
|
+
* takes the images with the room, which is what we want.
|
|
51
|
+
*
|
|
52
|
+
* The three agent ids go in a sidecar beside those images, never in
|
|
53
|
+
* `RoomConfig`. `cloneRoomAsPublished` copies every setting verbatim into each
|
|
54
|
+
* published instance, so an id held as a setting would have a template and all
|
|
55
|
+
* its campaigns sharing one illustrator's rolling history and its costs.
|
|
56
|
+
*/
|
|
57
|
+
targetFor(room: Room): IllustrationTarget;
|
|
58
|
+
/**
|
|
59
|
+
* Builds the trio the first time a target actually needs one.
|
|
60
|
+
*
|
|
61
|
+
* Only for targets that supply a `textModel` — a story creates its agents up
|
|
62
|
+
* front, interleaved with its creation progress events, and must not have a
|
|
63
|
+
* second set conjured underneath it.
|
|
64
|
+
*
|
|
65
|
+
* @returns The new ids, or the target's existing ones when nothing was created
|
|
66
|
+
*/
|
|
67
|
+
private createAgentsFor;
|
|
68
|
+
private readSidecar;
|
|
69
|
+
private writeSidecar;
|
|
70
|
+
/**
|
|
71
|
+
* Looks up image model configuration by name for one variant. Each consolidated
|
|
72
|
+
* entry in image_models.json carries a `generation` block (text-to-image) and an
|
|
73
|
+
* `editing` block (image-to-image); this returns the service/model for the
|
|
74
|
+
* requested variant.
|
|
75
|
+
* @param modelName The name from image_models.json
|
|
76
|
+
* @param variant Which model to resolve
|
|
77
|
+
* @returns {service, model}, or null when disabled or not found
|
|
78
|
+
*/
|
|
79
|
+
getImageModelConfig(modelName?: string, variant?: 'generation' | 'editing'): {
|
|
80
|
+
service: string;
|
|
81
|
+
model: string;
|
|
82
|
+
} | null;
|
|
83
|
+
/**
|
|
84
|
+
* Looks up the image generation properties (API params plus centsPerImage) for
|
|
85
|
+
* an agent's model. Read fresh at call time rather than stored on the Agent —
|
|
86
|
+
* only the modelName is persisted.
|
|
87
|
+
*
|
|
88
|
+
* The variant is passed explicitly rather than inferred from the agent's
|
|
89
|
+
* nickname. The same model id can appear under both variants (GPT Image edits
|
|
90
|
+
* with itself), so the caller's intent is the only reliable discriminator.
|
|
91
|
+
*
|
|
92
|
+
* @param agent The artist agent whose model to look up
|
|
93
|
+
* @param variant Which block of the entry the caller is about to use
|
|
94
|
+
* @returns The merged imageProperties, or {} when the model is not listed
|
|
95
|
+
*/
|
|
96
|
+
getImageProperties(agent: Agent, variant: 'generation' | 'editing'): Record<string, any>;
|
|
97
|
+
/**
|
|
98
|
+
* Creates an artist agent. Persistent and saved to disk, because its
|
|
99
|
+
* accumulated `totalCost` is how image spend is reported.
|
|
100
|
+
* @returns The agent, or null when this model has no such variant
|
|
101
|
+
*/
|
|
102
|
+
createArtistAgent(opts: {
|
|
103
|
+
label: string;
|
|
104
|
+
agentsDir: string;
|
|
105
|
+
artifacts: ArtifactService;
|
|
106
|
+
imageModelName?: string;
|
|
107
|
+
nickname?: string;
|
|
108
|
+
variant?: 'generation' | 'editing';
|
|
109
|
+
ownerRoomId?: string;
|
|
110
|
+
}): Agent | null;
|
|
111
|
+
/**
|
|
112
|
+
* Creates the illustrator — the agent that writes the image prompt. A text
|
|
113
|
+
* agent, always: it never calls generateImage, and a ComfyUI-backed agent
|
|
114
|
+
* would throw on a text prompt.
|
|
115
|
+
*/
|
|
116
|
+
createIllustratorAgent(opts: {
|
|
117
|
+
label: string;
|
|
118
|
+
agentsDir: string;
|
|
119
|
+
artifacts: ArtifactService;
|
|
120
|
+
service: string;
|
|
121
|
+
model: string;
|
|
122
|
+
ownerRoomId?: string;
|
|
123
|
+
}): Agent;
|
|
124
|
+
/**
|
|
125
|
+
* Resolves the target's three agents.
|
|
126
|
+
*
|
|
127
|
+
* Re-points every one of them at the target's artifact service on every call.
|
|
128
|
+
* The alternative — setting it once at creation — is how images end up in the
|
|
129
|
+
* wrong directory the moment one agent serves two targets.
|
|
130
|
+
*
|
|
131
|
+
* @returns The trio, or null when the target has no illustrator or artist
|
|
132
|
+
*/
|
|
133
|
+
ensureAgents(target: IllustrationTarget): Promise<IllustrationAgents | null>;
|
|
134
|
+
/**
|
|
135
|
+
* The whole chain: decide, draw, post.
|
|
136
|
+
*
|
|
137
|
+
* @param room The room the picture belongs in
|
|
138
|
+
* @param target Where the images live and what they are called
|
|
139
|
+
* @param req What to draw
|
|
140
|
+
*/
|
|
141
|
+
illustrate(room: Room, target: IllustrationTarget, req: IllustrationRequest): Promise<void>;
|
|
142
|
+
/**
|
|
143
|
+
* One pass of the pipeline. Recurses into itself once, directly rather than
|
|
144
|
+
* back through {@link illustrate}, so the lock the caller holds stays held.
|
|
145
|
+
* @returns True when a picture reached the room
|
|
146
|
+
*/
|
|
147
|
+
private runIllustration;
|
|
148
|
+
/**
|
|
149
|
+
* Draws the setting with nobody in it, so later pictures of the same place can
|
|
150
|
+
* be built on top of it.
|
|
151
|
+
* @returns The stored artifact's id, or null when nothing was drawn
|
|
152
|
+
*/
|
|
153
|
+
generateSceneReference(target: IllustrationTarget, sceneName: string, sceneDescription: string): Promise<string | null>;
|
|
154
|
+
/**
|
|
155
|
+
* Draws the scene — the reference plus the characters in it — and posts it.
|
|
156
|
+
*
|
|
157
|
+
* The reference images are positional: the prompt tells the model that Image 1
|
|
158
|
+
* is the setting, Image 2 the first character, and so on, so the order here is
|
|
159
|
+
* part of the contract with `describe_scene.prompt`.
|
|
160
|
+
*/
|
|
161
|
+
private generateSceneImage;
|
|
162
|
+
/**
|
|
163
|
+
* Puts the finished picture in the transcript.
|
|
164
|
+
*
|
|
165
|
+
* The caption goes in the sender slot, so it renders as the message's heading
|
|
166
|
+
* with the image as the body. `addRoomMessage` notifies over SSE, which is how
|
|
167
|
+
* this reaches clients despite arriving with no turn in progress.
|
|
168
|
+
*/
|
|
169
|
+
private postImageToRoom;
|
|
170
|
+
/**
|
|
171
|
+
* Tells the room that a face could not be drawn.
|
|
172
|
+
*
|
|
173
|
+
* SYSTEM rather than the free TOOL notice, which `getLatestRoomMessages` filters
|
|
174
|
+
* out unless the reader has thoughts turned on. A picture that silently never
|
|
175
|
+
* arrives is the thing being fixed here, so the line has to be one a person sees
|
|
176
|
+
* by default — the same way the finished picture is posted.
|
|
177
|
+
*
|
|
178
|
+
* @param portraitKept Whether an existing likeness survived the failure, which
|
|
179
|
+
* is the half of the news that decides what the reader should do next
|
|
180
|
+
*/
|
|
181
|
+
private postPortraitFailure;
|
|
182
|
+
/** One clipped line of an error, for a notice a person reads. */
|
|
183
|
+
private describeError;
|
|
184
|
+
/** Resolves each named character to a Portrait artifact id, warning on misses. */
|
|
185
|
+
private collectPortraitIds;
|
|
186
|
+
/**
|
|
187
|
+
* Draws a portrait from a name and a written profile, with no agent needed
|
|
188
|
+
* behind the character. Used both for real cast members and for the incidental
|
|
189
|
+
* people the illustrator names as it goes.
|
|
190
|
+
*
|
|
191
|
+
* @param room Where the notice goes when nothing could be drawn
|
|
192
|
+
* @param promptAgent Runs `describe_character`. Defaults to the artist, but the
|
|
193
|
+
* illustrator is the better choice — the prompt ships in its folder for this.
|
|
194
|
+
* @returns The artifact id, or null on any failure
|
|
195
|
+
*/
|
|
196
|
+
portrait(target: IllustrationTarget, characterName: string, characterProfile: string, room: Room, promptAgent?: Agent): Promise<string | null>;
|
|
197
|
+
/**
|
|
198
|
+
* Redraws an existing portrait from a fresh visual prompt, replacing the old
|
|
199
|
+
* artifact. Falls back to drawing from scratch when there is nothing to edit.
|
|
200
|
+
*/
|
|
201
|
+
updatePortrait(target: IllustrationTarget, characterName: string, visualDescription: string, room: Room): Promise<string | null>;
|
|
202
|
+
/** True when this character already has a portrait. */
|
|
203
|
+
hasPortrait(target: IllustrationTarget, characterName: string): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Gives every character the illustrator named a portrait before the scene is
|
|
206
|
+
* drawn. A name the illustrator invented without a matching `newCharacters`
|
|
207
|
+
* entry cannot be drawn, so it is warned about and left out.
|
|
208
|
+
*/
|
|
209
|
+
private ensureMinorCharacterPortraits;
|
|
210
|
+
private readImageModels;
|
|
211
|
+
}
|