briyah 2.0.5 → 2.0.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/README.md +105 -0
- package/data/common/prompts/moderate.json +34 -0
- package/data/common/prompts/moderate.prompt +136 -0
- package/data/packs/dnd5e/pack.json +7 -1
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +16 -0
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +23 -0
- package/dist-sdk/server/src/ai/agent.d.ts +33 -0
- package/dist-sdk/server/src/ai/agent.js +64 -13
- package/dist-sdk/server/src/app/user-service-factory.js +3 -0
- package/dist-sdk/server/src/app.controller.d.ts +7 -1
- package/dist-sdk/server/src/app.controller.js +55 -0
- package/dist-sdk/server/src/app.service.d.ts +114 -2
- package/dist-sdk/server/src/app.service.js +181 -4
- 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/documents/document-conversion.d.ts +70 -0
- package/dist-sdk/server/src/documents/document-conversion.js +341 -0
- package/dist-sdk/server/src/documents/library/chunking.d.ts +65 -0
- package/dist-sdk/server/src/documents/library/chunking.js +263 -0
- package/dist-sdk/server/src/documents/library/document-guide.builder.d.ts +2 -0
- package/dist-sdk/server/src/documents/library/document-guide.builder.js +58 -0
- package/dist-sdk/server/src/documents/library/document-registry.d.ts +22 -0
- package/dist-sdk/server/src/documents/library/document-registry.js +44 -0
- package/dist-sdk/server/src/documents/library/document.types.d.ts +108 -0
- package/dist-sdk/server/src/documents/library/document.types.js +20 -0
- package/dist-sdk/server/src/documents/library/embedding.d.ts +57 -0
- package/dist-sdk/server/src/documents/library/embedding.js +151 -0
- package/dist-sdk/server/src/packs/pack-manifest.d.ts +46 -0
- package/dist-sdk/server/src/packs/pack-manifest.js +46 -1
- package/dist-sdk/server/src/room/artifact-store.service.js +44 -11
- package/dist-sdk/server/src/room/artifact.d.ts +8 -0
- package/dist-sdk/server/src/room/room.d.ts +7 -5
- package/dist-sdk/server/src/room/room.js +44 -7
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +70 -29
- package/dist-sdk/server/src/rpg/rpg-roster.js +152 -41
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +66 -29
- package/dist-sdk/server/src/rpg/rpg.service.js +140 -65
- package/dist-sdk/server/src/sdk/index.d.ts +16 -2
- package/dist-sdk/server/src/sdk/index.js +37 -1
- 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/document.tools.d.ts +39 -0
- package/dist-sdk/server/src/tools/core/document.tools.js +391 -0
- package/dist-sdk/server/src/tools/core/index.js +3 -1
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +37 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +23 -2
- package/dist-sdk/server/src/tools/tool-execution.service.js +30 -6
- package/dist-sdk/shared/types/app.types.d.ts +39 -5
- package/package.json +172 -167
|
@@ -233,21 +233,47 @@ let ArtifactStoreService = class ArtifactStoreService {
|
|
|
233
233
|
else {
|
|
234
234
|
viewers = [creator]; // Missing viewers line defaults to creator only
|
|
235
235
|
}
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
|
|
236
|
+
// Optional headers follow the viewers line, each written only when set:
|
|
237
|
+
// `# transient:`, `# created:`, `# updated:`. Older files have none of
|
|
238
|
+
// them and load as they always did. The loop stops at the blank line that
|
|
239
|
+
// separates headers from the body, so a body opening with a markdown
|
|
240
|
+
// heading is never mistaken for one.
|
|
241
|
+
let index = viewersLine.startsWith('# viewers: ') ? 3 : 2;
|
|
239
242
|
let transient = false;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
+
let createdAt;
|
|
244
|
+
let updatedAt;
|
|
245
|
+
for (; index < lines.length; index++) {
|
|
246
|
+
const header = lines[index].match(/^# (transient|created|updated): (.*)$/);
|
|
247
|
+
if (!header) {
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
const value = header[2].trim();
|
|
251
|
+
if (header[1] === 'transient') {
|
|
252
|
+
transient = value === 'true';
|
|
253
|
+
}
|
|
254
|
+
else if (header[1] === 'created') {
|
|
255
|
+
createdAt = value;
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
updatedAt = value;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// formatArtifactFile separates the headers from the body with exactly one
|
|
262
|
+
// blank line, so skip exactly one. Leaving it in prepended a newline to
|
|
263
|
+
// the body on every load — a body grew by a line each time it was loaded
|
|
264
|
+
// and saved again, and anything fingerprinting bodies saw it change.
|
|
265
|
+
if (index < lines.length && lines[index].trim() === '') {
|
|
266
|
+
index++;
|
|
243
267
|
}
|
|
244
|
-
const body = lines.slice(
|
|
268
|
+
const body = lines.slice(index).join('\n');
|
|
245
269
|
return {
|
|
246
270
|
name,
|
|
247
271
|
creator,
|
|
248
272
|
body,
|
|
249
273
|
viewers,
|
|
250
274
|
...(transient && { transient }),
|
|
275
|
+
...(createdAt && { createdAt }),
|
|
276
|
+
...(updatedAt && { updatedAt }),
|
|
251
277
|
};
|
|
252
278
|
}
|
|
253
279
|
/**
|
|
@@ -257,12 +283,19 @@ let ArtifactStoreService = class ArtifactStoreService {
|
|
|
257
283
|
const viewersStr = artifact.viewers && artifact.viewers.length > 0
|
|
258
284
|
? artifact.viewers.join(', ')
|
|
259
285
|
: artifact.creator; // Default to creator if no viewers specified
|
|
260
|
-
//
|
|
261
|
-
//
|
|
262
|
-
const
|
|
286
|
+
// Optional headers are written only when set, so an artifact that uses
|
|
287
|
+
// none of them produces the same file earlier versions did.
|
|
288
|
+
const optional = [
|
|
289
|
+
artifact.transient ? '# transient: true' : null,
|
|
290
|
+
artifact.createdAt ? `# created: ${artifact.createdAt}` : null,
|
|
291
|
+
artifact.updatedAt ? `# updated: ${artifact.updatedAt}` : null,
|
|
292
|
+
]
|
|
293
|
+
.filter((line) => line !== null)
|
|
294
|
+
.map((line) => `\n${line}`)
|
|
295
|
+
.join('');
|
|
263
296
|
return `# name: ${artifact.name}
|
|
264
297
|
# creator: ${artifact.creator}
|
|
265
|
-
# viewers: ${viewersStr}${
|
|
298
|
+
# viewers: ${viewersStr}${optional}
|
|
266
299
|
|
|
267
300
|
${artifact.body}`;
|
|
268
301
|
}
|
|
@@ -22,4 +22,12 @@ export interface Artifact {
|
|
|
22
22
|
* artifact that is large and stable is cheaper left cached.
|
|
23
23
|
*/
|
|
24
24
|
transient?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* When the artifact was first published, as an ISO string. Absent on
|
|
27
|
+
* artifacts saved before timestamps existed — nothing invents one for them,
|
|
28
|
+
* since a made-up creation date is worse than an honest blank.
|
|
29
|
+
*/
|
|
30
|
+
createdAt?: string;
|
|
31
|
+
/** When the artifact was last written, as an ISO string. */
|
|
32
|
+
updatedAt?: string;
|
|
25
33
|
}
|
|
@@ -980,11 +980,13 @@ export declare class Room {
|
|
|
980
980
|
* other room the first agent is whoever happened to be added first and has no
|
|
981
981
|
* `moderate.prompt` at all. Name one explicitly.
|
|
982
982
|
*
|
|
983
|
-
* The fallback prefers an agent
|
|
984
|
-
*
|
|
985
|
-
*
|
|
986
|
-
*
|
|
987
|
-
*
|
|
983
|
+
* The fallback prefers an agent whose own folder carries a `moderate.prompt`,
|
|
984
|
+
* because a folder that ships one was written to route for its domain and its
|
|
985
|
+
* examples are drawn from it. It has to ask for the folder's *own* file:
|
|
986
|
+
* `common/prompts/moderate.prompt` is the shared fallback, so every agent can
|
|
987
|
+
* moderate and asking whether one merely resolves the prompt would pick out
|
|
988
|
+
* nobody. Arrival order is consulted only when no folder is purpose-built,
|
|
989
|
+
* which is the ordinary case in a room assembled from generic agents.
|
|
988
990
|
* @returns The moderator agent or undefined if the room is empty
|
|
989
991
|
*/
|
|
990
992
|
getModeratorAgent(): Agent | undefined;
|
|
@@ -1487,7 +1487,7 @@ class Room {
|
|
|
1487
1487
|
async executeToolForAgent(agent, message) {
|
|
1488
1488
|
const toolName = message.name;
|
|
1489
1489
|
const result = this.toolExecutionService
|
|
1490
|
-
? await this.toolExecutionService.runForAgent(toolName, message.content, agent.toolNames || [], this.currentToolContext, this.buildToolRoomAccess(agent), this.buildToolIllustration(agent))
|
|
1490
|
+
? await this.toolExecutionService.runForAgent(toolName, message.content, agent.toolNames || [], this.currentToolContext, this.buildToolRoomAccess(agent), this.buildToolIllustration(agent), agent.id)
|
|
1491
1491
|
: { ok: false, error: 'Tool execution is not available in this room' };
|
|
1492
1492
|
const argsPreview = Room.previewForToolLog(message.content || '', Room.TOOL_LOG_ARGS_PREVIEW);
|
|
1493
1493
|
const statusText = 'error' in result ? `error: ${result.error}` : Room.describeToolResult(result.result);
|
|
@@ -1731,6 +1731,17 @@ class Room {
|
|
|
1731
1731
|
// being asked again: without one it cannot tell a continuation from being
|
|
1732
1732
|
// handed back something it has already answered.
|
|
1733
1733
|
if (opts.continuing) {
|
|
1734
|
+
// A person is never "continuing": in a broadcast room every agent is a
|
|
1735
|
+
// responder, so the sender of a human's own message is the human agent
|
|
1736
|
+
// and this branch would hand their turn to the model. It answered as
|
|
1737
|
+
// them — inventing follow-up questions in their name and echoing their
|
|
1738
|
+
// last message back into the transcript — because this returns before
|
|
1739
|
+
// the isControlledByHuman gate below. Decline the turn instead, which
|
|
1740
|
+
// is what `hear` would have done with their own message anyway.
|
|
1741
|
+
if (agent.isControlledByHuman) {
|
|
1742
|
+
onResponse(null);
|
|
1743
|
+
return;
|
|
1744
|
+
}
|
|
1734
1745
|
agent.addToConversationHistory(Room.CONTINUE_NOTE, false);
|
|
1735
1746
|
agent.save();
|
|
1736
1747
|
this.getAgentAiResponse(agent, message, onResponse);
|
|
@@ -1885,6 +1896,7 @@ Recent Message: ${message.getContent()}
|
|
|
1885
1896
|
// Check if an artifact with this name already exists
|
|
1886
1897
|
const existingIndex = this.artifacts.findIndex((a) => a.name === name);
|
|
1887
1898
|
let returnedArtifact;
|
|
1899
|
+
const now = new Date().toISOString();
|
|
1888
1900
|
if (existingIndex >= 0) {
|
|
1889
1901
|
// Update existing artifact
|
|
1890
1902
|
this.artifacts[existingIndex].body = body;
|
|
@@ -1895,6 +1907,9 @@ Recent Message: ${message.getContent()}
|
|
|
1895
1907
|
if (transient !== undefined) {
|
|
1896
1908
|
this.artifacts[existingIndex].transient = transient;
|
|
1897
1909
|
}
|
|
1910
|
+
// createdAt is left alone — including when it is absent, on an
|
|
1911
|
+
// artifact saved before timestamps existed.
|
|
1912
|
+
this.artifacts[existingIndex].updatedAt = now;
|
|
1898
1913
|
returnedArtifact = this.artifacts[existingIndex];
|
|
1899
1914
|
}
|
|
1900
1915
|
else {
|
|
@@ -1905,6 +1920,8 @@ Recent Message: ${message.getContent()}
|
|
|
1905
1920
|
body,
|
|
1906
1921
|
viewers: viewers.length > 0 ? viewers : [creator], // If no viewers specified, only creator can see
|
|
1907
1922
|
...(transient !== undefined && { transient }),
|
|
1923
|
+
createdAt: now,
|
|
1924
|
+
updatedAt: now,
|
|
1908
1925
|
};
|
|
1909
1926
|
this.artifacts.push(newArtifact);
|
|
1910
1927
|
returnedArtifact = newArtifact;
|
|
@@ -2244,11 +2261,13 @@ Recent Message: ${message.getContent()}
|
|
|
2244
2261
|
* other room the first agent is whoever happened to be added first and has no
|
|
2245
2262
|
* `moderate.prompt` at all. Name one explicitly.
|
|
2246
2263
|
*
|
|
2247
|
-
* The fallback prefers an agent
|
|
2248
|
-
*
|
|
2249
|
-
*
|
|
2250
|
-
*
|
|
2251
|
-
*
|
|
2264
|
+
* The fallback prefers an agent whose own folder carries a `moderate.prompt`,
|
|
2265
|
+
* because a folder that ships one was written to route for its domain and its
|
|
2266
|
+
* examples are drawn from it. It has to ask for the folder's *own* file:
|
|
2267
|
+
* `common/prompts/moderate.prompt` is the shared fallback, so every agent can
|
|
2268
|
+
* moderate and asking whether one merely resolves the prompt would pick out
|
|
2269
|
+
* nobody. Arrival order is consulted only when no folder is purpose-built,
|
|
2270
|
+
* which is the ordinary case in a room assembled from generic agents.
|
|
2252
2271
|
* @returns The moderator agent or undefined if the room is empty
|
|
2253
2272
|
*/
|
|
2254
2273
|
getModeratorAgent() {
|
|
@@ -2263,7 +2282,7 @@ Recent Message: ${message.getContent()}
|
|
|
2263
2282
|
// table this was unlikely to bite; with several, the odds that the first
|
|
2264
2283
|
// agent is one of them are much better.
|
|
2265
2284
|
const candidates = this.agents.filter((a) => !a.isControlledByHuman);
|
|
2266
|
-
return candidates.find((a) => a.
|
|
2285
|
+
return candidates.find((a) => a.hasOwnPrompt('moderate')) ?? candidates[0];
|
|
2267
2286
|
}
|
|
2268
2287
|
/**
|
|
2269
2288
|
* Gets the current story situation
|
|
@@ -2988,6 +3007,24 @@ Recent Message: ${message.getContent()}
|
|
|
2988
3007
|
this.endTurn('release');
|
|
2989
3008
|
return;
|
|
2990
3009
|
}
|
|
3010
|
+
// A moderator that cannot be prompted is not a moderator. A folder
|
|
3011
|
+
// carrying no `moderate.prompt` threw inside the dispatch below, where
|
|
3012
|
+
// the catch could only log it: the turn ended with nothing said, so the
|
|
3013
|
+
// person waiting saw the room go quiet — no answer, no error, no clue
|
|
3014
|
+
// that their agent had addressed somebody who was not there.
|
|
3015
|
+
//
|
|
3016
|
+
// `common/prompts/moderate.prompt` now answers for every folder that
|
|
3017
|
+
// does not have its own, so reaching this means the shared file is gone
|
|
3018
|
+
// from the prompts root — a host that pruned it, or a data directory
|
|
3019
|
+
// that predates it and never took the refresh. Rare, and still worth
|
|
3020
|
+
// saying out loud rather than going quiet again.
|
|
3021
|
+
if (!moderator.hasPrompt('moderate')) {
|
|
3022
|
+
const first = moderateMessages[0];
|
|
3023
|
+
logger_1.logger.warn(`Room ${this.name}: ${moderator.agentNickname} has no moderate.prompt, so ${first.getSender()}'s message cannot be routed`);
|
|
3024
|
+
this.addRoomMessage(new message_1.RoomMessage('System', app_types_1.MessageAction.SYSTEM, `${first.getSender()} sent a message this room could not route, and there is no moderator able to place it.`, [], null, null));
|
|
3025
|
+
this.endTurn('release', { drain: true });
|
|
3026
|
+
return;
|
|
3027
|
+
}
|
|
2991
3028
|
// Take the first moderate message
|
|
2992
3029
|
const originalMessage = moderateMessages[0];
|
|
2993
3030
|
// Put any remaining moderate messages back in the queue
|
|
@@ -1,45 +1,86 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* What a
|
|
2
|
+
* What a table is, and what a party may be.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
* the
|
|
6
|
-
*
|
|
4
|
+
* A table is one installed pack's `table` block — see {@link PackTable} — resolved
|
|
5
|
+
* against the templates it names. That resolution is the whole of this module: the
|
|
6
|
+
* pack declares which room to build and which agent template is a seat, and
|
|
7
|
+
* everything else the RPG page needs is derived from those two, so a pack never says
|
|
8
|
+
* the same thing twice. The prompt folder comes from the seat template; the crew and
|
|
9
|
+
* which of them are expensive come from the room template; the seat placeholders come
|
|
10
|
+
* from the pack's noun.
|
|
11
|
+
*
|
|
12
|
+
* No filesystem and no Nest: a {@link LoadedPack} arrives already read, and every rule
|
|
13
|
+
* about the shape of a party is one the room would otherwise enforce badly or late.
|
|
14
|
+
* The point of refusing here is that refusing costs nothing.
|
|
15
|
+
*/
|
|
16
|
+
import { PromptFolderDefaults, RpgPackOption, RpgPlayerRequest } from '../../../shared/types/app.types';
|
|
17
|
+
import { LoadedPack } from '../packs/pack-manifest';
|
|
18
|
+
/** One pack's table, resolved: everything needed to build one and to describe it. */
|
|
19
|
+
export interface RpgTable {
|
|
20
|
+
/** The pack supplying the rules. */
|
|
21
|
+
pack: string;
|
|
22
|
+
title: string;
|
|
23
|
+
description?: string;
|
|
24
|
+
/** The pack's player-less room template — the crew, and no seats. */
|
|
25
|
+
roomKey: string;
|
|
26
|
+
/** The agent template a seat is filed under, and the roster discriminator. */
|
|
27
|
+
playerAgentKey: string;
|
|
28
|
+
/** The prompt folder a seat is created from, pack-qualified. */
|
|
29
|
+
playerFolder: string;
|
|
30
|
+
/** What the seat template asks for, under the settings the RPG page decides itself. */
|
|
31
|
+
playerOverrides: Partial<PromptFolderDefaults>;
|
|
32
|
+
/** What one player is called: `Player`, `Student`. */
|
|
33
|
+
playerNoun: string;
|
|
34
|
+
/** The seats a party is created under, in order. Its length is the capacity. */
|
|
35
|
+
seatNames: string[];
|
|
36
|
+
/** Crew labels the quality tier's own model runs. */
|
|
37
|
+
primaryRoles: string[];
|
|
38
|
+
/** Crew labels that run on the tier's economy model. */
|
|
39
|
+
economyRoles: string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The seats a table of this size offers.
|
|
43
|
+
*
|
|
44
|
+
* Generated rather than listed, so a pack can ask for any number of seats without a
|
|
45
|
+
* matching list of names having to exist. Unique by construction, which is what the
|
|
46
|
+
* room needs: two agents in one room may not share a nickname, and a nickname is
|
|
47
|
+
* derived from the name.
|
|
48
|
+
*
|
|
49
|
+
* @param noun What one player is called
|
|
50
|
+
* @param count How many seats
|
|
51
|
+
* @returns The placeholders, in seating order
|
|
7
52
|
*/
|
|
8
|
-
|
|
9
|
-
/** The pack a campaign is built from. */
|
|
10
|
-
export declare const RPG_PACK = "dnd5e";
|
|
11
|
-
/** The pack's player-less room template — the crew, and no seats. */
|
|
12
|
-
export declare const RPG_ROOM_KEY = "campaign";
|
|
13
|
-
/** The prompt folder every player is created from, pack-qualified. */
|
|
14
|
-
export declare const RPG_PLAYER_FOLDER = "dnd5e:dnd_player";
|
|
15
|
-
/** The pack agent template a player is filed under, and the roster discriminator. */
|
|
16
|
-
export declare const RPG_PLAYER_AGENT_KEY = "player";
|
|
53
|
+
export declare function seatNames(noun: string, count: number): string[];
|
|
17
54
|
/**
|
|
18
|
-
*
|
|
55
|
+
* Resolves a pack's declared table.
|
|
19
56
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
57
|
+
* @param pack A pack, already read
|
|
58
|
+
* @returns The table, or null when the pack declares none, or names a template it does
|
|
59
|
+
* not ship, or points at a room that already seats a player. Null is the ordinary
|
|
60
|
+
* case — every pack that is not a game is one — so only the misconfigurations warn.
|
|
22
61
|
*/
|
|
23
|
-
export declare
|
|
62
|
+
export declare function resolveRpgTable(pack: LoadedPack): RpgTable | null;
|
|
63
|
+
/** A table as the client is offered one: the labels, and none of the keys. */
|
|
64
|
+
export declare function toRpgPackOption(table: RpgTable, isDefault: boolean): RpgPackOption;
|
|
24
65
|
/**
|
|
25
|
-
* The
|
|
66
|
+
* The table to preselect: the one named by DEFAULT_RPG_PACK, else the first.
|
|
67
|
+
*
|
|
68
|
+
* Mirrors `pickDefaultEntry`, down to warning about a name that is not installed
|
|
69
|
+
* rather than offering nothing — a host who mistyped the variable should still get a
|
|
70
|
+
* working dialog.
|
|
26
71
|
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* they know what the classes and races on offer are. Generated here rather than
|
|
30
|
-
* asked for, so they are unique by construction and nothing has to be refused.
|
|
72
|
+
* @param tables Every table this deployment offers, in the order they are listed
|
|
73
|
+
* @returns The one to preselect, or null when the deployment ships no game pack
|
|
31
74
|
*/
|
|
32
|
-
export declare
|
|
75
|
+
export declare function pickDefaultTable(tables: RpgTable[]): RpgTable | null;
|
|
33
76
|
/**
|
|
34
77
|
* Refuses a party the room could not seat, before a single agent exists.
|
|
35
78
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* Now the party is seated under {@link RPG_SEAT_NAMES} and named in the game, so the
|
|
39
|
-
* only collision left is one a player invents at the table, and
|
|
40
|
-
* `Room.renameAgent` refuses that where it happens.
|
|
79
|
+
* Every message uses the pack's own noun, because "a table seats 4 students" is a rule
|
|
80
|
+
* of the game the user chose rather than a limit of the software.
|
|
41
81
|
*
|
|
42
82
|
* @param players The requested party, in seating order
|
|
83
|
+
* @param table The table they are being seated at
|
|
43
84
|
* @throws {ValidationError} Naming the offending seat and why
|
|
44
85
|
*/
|
|
45
|
-
export declare function assertSeatable(players: RpgPlayerRequest[] | undefined): void;
|
|
86
|
+
export declare function assertSeatable(players: RpgPlayerRequest[] | undefined, table: RpgTable): void;
|
|
@@ -1,71 +1,182 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* What a
|
|
3
|
+
* What a table is, and what a party may be.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
7
|
-
*
|
|
5
|
+
* A table is one installed pack's `table` block — see {@link PackTable} — resolved
|
|
6
|
+
* against the templates it names. That resolution is the whole of this module: the
|
|
7
|
+
* pack declares which room to build and which agent template is a seat, and
|
|
8
|
+
* everything else the RPG page needs is derived from those two, so a pack never says
|
|
9
|
+
* the same thing twice. The prompt folder comes from the seat template; the crew and
|
|
10
|
+
* which of them are expensive come from the room template; the seat placeholders come
|
|
11
|
+
* from the pack's noun.
|
|
12
|
+
*
|
|
13
|
+
* No filesystem and no Nest: a {@link LoadedPack} arrives already read, and every rule
|
|
14
|
+
* about the shape of a party is one the room would otherwise enforce badly or late.
|
|
15
|
+
* The point of refusing here is that refusing costs nothing.
|
|
8
16
|
*/
|
|
9
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.
|
|
18
|
+
exports.seatNames = seatNames;
|
|
19
|
+
exports.resolveRpgTable = resolveRpgTable;
|
|
20
|
+
exports.toRpgPackOption = toRpgPackOption;
|
|
21
|
+
exports.pickDefaultTable = pickDefaultTable;
|
|
11
22
|
exports.assertSeatable = assertSeatable;
|
|
23
|
+
const prompt_resolver_1 = require("../config/prompt-resolver");
|
|
24
|
+
const pack_manifest_1 = require("../packs/pack-manifest");
|
|
12
25
|
const errors_1 = require("../common/errors");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
26
|
+
const logger_1 = require("../common/logger");
|
|
27
|
+
/**
|
|
28
|
+
* Seat ordinals, so a placeholder reads as a name rather than an index.
|
|
29
|
+
*
|
|
30
|
+
* Runs out before `MAX_TABLE_SEATS` does on purpose: past eight the word stops being
|
|
31
|
+
* easier to read than the numeral, and {@link seatNames} falls back to it.
|
|
32
|
+
*/
|
|
33
|
+
const SEAT_ORDINALS = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight'];
|
|
21
34
|
/**
|
|
22
|
-
*
|
|
35
|
+
* The seats a table of this size offers.
|
|
36
|
+
*
|
|
37
|
+
* Generated rather than listed, so a pack can ask for any number of seats without a
|
|
38
|
+
* matching list of names having to exist. Unique by construction, which is what the
|
|
39
|
+
* room needs: two agents in one room may not share a nickname, and a nickname is
|
|
40
|
+
* derived from the name.
|
|
23
41
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
42
|
+
* @param noun What one player is called
|
|
43
|
+
* @param count How many seats
|
|
44
|
+
* @returns The placeholders, in seating order
|
|
26
45
|
*/
|
|
27
|
-
|
|
46
|
+
function seatNames(noun, count) {
|
|
47
|
+
return Array.from({ length: count }, (_, index) => `${noun} ${SEAT_ORDINALS[index] ?? index + 1}`);
|
|
48
|
+
}
|
|
28
49
|
/**
|
|
29
|
-
*
|
|
50
|
+
* Resolves a pack's declared table.
|
|
30
51
|
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
52
|
+
* @param pack A pack, already read
|
|
53
|
+
* @returns The table, or null when the pack declares none, or names a template it does
|
|
54
|
+
* not ship, or points at a room that already seats a player. Null is the ordinary
|
|
55
|
+
* case — every pack that is not a game is one — so only the misconfigurations warn.
|
|
35
56
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
57
|
+
function resolveRpgTable(pack) {
|
|
58
|
+
if (!pack.table)
|
|
59
|
+
return null;
|
|
60
|
+
const { room: roomKey, playerAgent: playerAgentKey, playerNoun, maxPlayers } = pack.table;
|
|
61
|
+
const room = pack.rooms.find((template) => template.key === roomKey);
|
|
62
|
+
if (!room) {
|
|
63
|
+
logger_1.logger.warn(`Pack "${pack.name}" declares its table in room "${roomKey}", which it does not ship`);
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const player = pack.agents.find((template) => template.key === playerAgentKey);
|
|
67
|
+
if (!player) {
|
|
68
|
+
logger_1.logger.warn(`Pack "${pack.name}" declares "${playerAgentKey}" as its player, which it does not ship`);
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
// The RPG page seats the party itself, one agent at a time, so each AI player can
|
|
72
|
+
// have its own model and personality. A room template that already seats a player
|
|
73
|
+
// would bring the party twice — once under a name the page did not choose and does
|
|
74
|
+
// not show in the roster.
|
|
75
|
+
if (room.agents.some((entry) => entry.key === playerAgentKey)) {
|
|
76
|
+
logger_1.logger.warn(`Pack "${pack.name}" declares room "${roomKey}" as its table, but that template seats ` +
|
|
77
|
+
`"${playerAgentKey}". The RPG page seats the party itself, so its table has to be player-less.`);
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
const { primaryRoles, economyRoles } = crewRoles(pack, room);
|
|
81
|
+
return {
|
|
82
|
+
pack: pack.name,
|
|
83
|
+
title: pack.title,
|
|
84
|
+
...(pack.description && { description: pack.description }),
|
|
85
|
+
roomKey,
|
|
86
|
+
playerAgentKey,
|
|
87
|
+
playerFolder: (0, prompt_resolver_1.isPackFolder)(player.promptFolder)
|
|
88
|
+
? player.promptFolder
|
|
89
|
+
: (0, prompt_resolver_1.formatPromptFolder)({ pack: pack.name, folder: player.promptFolder }),
|
|
90
|
+
playerOverrides: player.overrides ?? {},
|
|
91
|
+
playerNoun,
|
|
92
|
+
seatNames: seatNames(playerNoun, maxPlayers),
|
|
93
|
+
primaryRoles,
|
|
94
|
+
economyRoles,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
/** A table as the client is offered one: the labels, and none of the keys. */
|
|
98
|
+
function toRpgPackOption(table, isDefault) {
|
|
99
|
+
return {
|
|
100
|
+
pack: table.pack,
|
|
101
|
+
title: table.title,
|
|
102
|
+
...(table.description && { description: table.description }),
|
|
103
|
+
playerNoun: table.playerNoun,
|
|
104
|
+
seatNames: table.seatNames,
|
|
105
|
+
primaryRoles: table.primaryRoles,
|
|
106
|
+
economyRoles: table.economyRoles,
|
|
107
|
+
isDefault,
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The table to preselect: the one named by DEFAULT_RPG_PACK, else the first.
|
|
112
|
+
*
|
|
113
|
+
* Mirrors `pickDefaultEntry`, down to warning about a name that is not installed
|
|
114
|
+
* rather than offering nothing — a host who mistyped the variable should still get a
|
|
115
|
+
* working dialog.
|
|
116
|
+
*
|
|
117
|
+
* @param tables Every table this deployment offers, in the order they are listed
|
|
118
|
+
* @returns The one to preselect, or null when the deployment ships no game pack
|
|
119
|
+
*/
|
|
120
|
+
function pickDefaultTable(tables) {
|
|
121
|
+
if (tables.length === 0)
|
|
122
|
+
return null;
|
|
123
|
+
const fromEnv = process.env.DEFAULT_RPG_PACK?.trim();
|
|
124
|
+
if (fromEnv) {
|
|
125
|
+
const named = tables.find((table) => table.pack.toLowerCase() === fromEnv.toLowerCase());
|
|
126
|
+
if (named)
|
|
127
|
+
return named;
|
|
128
|
+
logger_1.logger.warn(`DEFAULT_RPG_PACK "${fromEnv}" is not an installed game pack; using the first`);
|
|
129
|
+
}
|
|
130
|
+
return tables[0];
|
|
131
|
+
}
|
|
44
132
|
/**
|
|
45
133
|
* Refuses a party the room could not seat, before a single agent exists.
|
|
46
134
|
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* Now the party is seated under {@link RPG_SEAT_NAMES} and named in the game, so the
|
|
50
|
-
* only collision left is one a player invents at the table, and
|
|
51
|
-
* `Room.renameAgent` refuses that where it happens.
|
|
135
|
+
* Every message uses the pack's own noun, because "a table seats 4 students" is a rule
|
|
136
|
+
* of the game the user chose rather than a limit of the software.
|
|
52
137
|
*
|
|
53
138
|
* @param players The requested party, in seating order
|
|
139
|
+
* @param table The table they are being seated at
|
|
54
140
|
* @throws {ValidationError} Naming the offending seat and why
|
|
55
141
|
*/
|
|
56
|
-
function assertSeatable(players) {
|
|
142
|
+
function assertSeatable(players, table) {
|
|
143
|
+
const one = table.playerNoun.toLowerCase();
|
|
57
144
|
if (!players || players.length === 0) {
|
|
58
|
-
throw new errors_1.ValidationError(
|
|
145
|
+
throw new errors_1.ValidationError(`A campaign needs at least one ${one}.`);
|
|
59
146
|
}
|
|
60
|
-
if (players.length >
|
|
61
|
-
throw new errors_1.ValidationError(`A table seats ${
|
|
147
|
+
if (players.length > table.seatNames.length) {
|
|
148
|
+
throw new errors_1.ValidationError(`A table seats ${table.seatNames.length} ${one}s.`);
|
|
62
149
|
}
|
|
63
150
|
if (!players.some((player) => player.isHuman)) {
|
|
64
|
-
throw new errors_1.ValidationError(
|
|
151
|
+
throw new errors_1.ValidationError(`At least one ${one} has to be a person.`);
|
|
65
152
|
}
|
|
66
153
|
players.forEach((player, index) => {
|
|
67
154
|
if (!player.isHuman && !player.modelName?.trim()) {
|
|
68
|
-
throw new errors_1.ValidationError(`${
|
|
155
|
+
throw new errors_1.ValidationError(`${table.seatNames[index]} is an AI ${one} and needs a model.`);
|
|
69
156
|
}
|
|
70
157
|
});
|
|
71
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Which crew the quality tier's model runs, and which the economy one does.
|
|
161
|
+
*
|
|
162
|
+
* Labels rather than keys, and deduped in roster order: this is what the dialog says
|
|
163
|
+
* the quality choice buys, so it has to read as the names of the agents at the table.
|
|
164
|
+
* The role rule is `PackInstantiationService.modelFor`'s — a template naming no role is
|
|
165
|
+
* primary — repeated here rather than shared because that function answers with a
|
|
166
|
+
* model and this one with a name.
|
|
167
|
+
*/
|
|
168
|
+
function crewRoles(pack, room) {
|
|
169
|
+
const byKey = new Map(pack.agents.map((agent) => [agent.key, agent]));
|
|
170
|
+
const primary = new Set();
|
|
171
|
+
const economy = new Set();
|
|
172
|
+
for (const entry of room.agents) {
|
|
173
|
+
const template = byKey.get(entry.key);
|
|
174
|
+
if (!template) {
|
|
175
|
+
logger_1.logger.warn(`Room "${room.key}" in pack "${pack.name}" names agent "${(0, pack_manifest_1.roomAgentKey)(entry)}", ` +
|
|
176
|
+
'which the pack does not ship');
|
|
177
|
+
continue;
|
|
178
|
+
}
|
|
179
|
+
(template.modelRole === 'economy' ? economy : primary).add(template.label ?? template.key);
|
|
180
|
+
}
|
|
181
|
+
return { primaryRoles: [...primary], economyRoles: [...economy] };
|
|
182
|
+
}
|