briyah 2.0.6 → 2.0.8
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/packs/dnd5e/pack.json +7 -1
- package/dist-sdk/server/src/ai/agent.d.ts +27 -0
- package/dist-sdk/server/src/ai/agent.js +54 -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/documents/document-conversion.d.ts +70 -0
- package/dist-sdk/server/src/documents/document-conversion.js +394 -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.js +7 -1
- 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 +12 -2
- package/dist-sdk/server/src/sdk/index.js +27 -1
- 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 +2 -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
|
@@ -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
|
+
}
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Campaigns: a streamlined way to start and hold a
|
|
2
|
+
* Campaigns: a streamlined way to start and hold a game.
|
|
3
3
|
*
|
|
4
|
-
* A campaign is not a new kind of thing. It is an ordinary room built from
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* A campaign is not a new kind of thing. It is an ordinary room built from a pack's
|
|
5
|
+
* table template — the crew that runs the game — with a party seated on top and the
|
|
6
|
+
* whole thing published, so the link the party plays through exists from the first
|
|
7
|
+
* moment.
|
|
8
|
+
*
|
|
9
|
+
* ## Which games exist
|
|
10
|
+
*
|
|
11
|
+
* Whichever installed packs say so. A pack declares a `table` block naming the room to
|
|
12
|
+
* build and the agent template to seat a party from, and {@link RpgTable} resolves that
|
|
13
|
+
* against its templates; this service asks for the list and never names a pack itself.
|
|
14
|
+
* That is what lets a host drop in a second ruleset — the dnd5e pack seats six players
|
|
15
|
+
* behind five crew agents, the acts pack four students behind three — without the RPG
|
|
16
|
+
* page learning anything about either.
|
|
8
17
|
*
|
|
9
18
|
* ## Why there is no campaign store
|
|
10
19
|
*
|
|
11
20
|
* Everything a campaign is, a room already holds: its roster, its turn mode, its
|
|
12
|
-
* leader and moderator, its artifacts, its transcript and its cost. Which
|
|
13
|
-
* player is `
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
21
|
+
* leader and moderator, its artifacts, its transcript and its cost. Which pack it plays
|
|
22
|
+
* by is `pack`; which agent is a player is `packAgentKey`; a character's personality is
|
|
23
|
+
* `privateContext`. A store would be a second copy of all of that, and it would drift
|
|
24
|
+
* the moment somebody renamed an agent from the Agents page. So a campaign is
|
|
25
|
+
* discovered by filtering rooms, and its details are derived per request.
|
|
17
26
|
*
|
|
18
27
|
* ## Why every write goes through AppService
|
|
19
28
|
*
|
|
@@ -22,7 +31,7 @@
|
|
|
22
31
|
* uses — the same discipline `PackInstantiationService` keeps, and what makes the
|
|
23
32
|
* rollback below correct rather than approximate.
|
|
24
33
|
*/
|
|
25
|
-
import { CreateRpgCampaignRequest, CreateRpgCampaignResponse, RpgCampaignDetails, RpgCampaignInfo, RpgModelOption } from '../../../shared/types/app.types';
|
|
34
|
+
import { CreateRpgCampaignRequest, CreateRpgCampaignResponse, RpgCampaignDetails, RpgCampaignInfo, RpgModelOption, RpgPackOption } from '../../../shared/types/app.types';
|
|
26
35
|
import { AppService } from '../app.service';
|
|
27
36
|
import { UserConfigService } from '../config/user-config.service';
|
|
28
37
|
import { UserPathsService } from '../config/user-paths.service';
|
|
@@ -36,6 +45,14 @@ export declare class RpgService {
|
|
|
36
45
|
constructor(app: AppService, packs: PackService, userConfig: UserConfigService, userPaths: UserPathsService, userId: string);
|
|
37
46
|
/** The models a campaign may be built with, as the client is offered them. */
|
|
38
47
|
listModels(): RpgModelOption[];
|
|
48
|
+
/**
|
|
49
|
+
* The games a campaign may be built from, as the client is offered them.
|
|
50
|
+
*
|
|
51
|
+
* Installed rather than enabled, because {@link ensurePackEnabled} turns the chosen
|
|
52
|
+
* one on: a user on the RPG surface has no Packs page, so offering only what they
|
|
53
|
+
* had already enabled would offer them nothing at all on their first visit.
|
|
54
|
+
*/
|
|
55
|
+
listPacks(): RpgPackOption[];
|
|
39
56
|
/**
|
|
40
57
|
* Builds a campaign and publishes it.
|
|
41
58
|
*
|
|
@@ -43,14 +60,14 @@ export declare class RpgService {
|
|
|
43
60
|
* before the first side effect; then the crew; then the party and the publish. Any
|
|
44
61
|
* failure past the first agent deletes the room, which takes its agents with it.
|
|
45
62
|
*
|
|
46
|
-
* Synchronous throughout, unlike story creation:
|
|
47
|
-
*
|
|
48
|
-
*
|
|
63
|
+
* Synchronous throughout, unlike story creation: no pack fires a prompt at
|
|
64
|
+
* instantiation, so this is file I/O for a dozen agents. It either returns a
|
|
65
|
+
* campaign that can be played or leaves nothing behind.
|
|
49
66
|
*
|
|
50
|
-
* @param request The campaign's name, quality tier and party
|
|
67
|
+
* @param request The campaign's name, game, quality tier and party
|
|
51
68
|
* @returns The campaign, its public link, and anything that did not go to plan
|
|
52
|
-
* @throws {ValidationError} If the party or the quality tier is not acceptable
|
|
53
|
-
* @throws {NotFoundError} If this deployment
|
|
69
|
+
* @throws {ValidationError} If the game, the party or the quality tier is not acceptable
|
|
70
|
+
* @throws {NotFoundError} If this deployment ships no game pack at all
|
|
54
71
|
*/
|
|
55
72
|
createCampaign(request: CreateRpgCampaignRequest): Promise<CreateRpgCampaignResponse>;
|
|
56
73
|
/** Every campaign this user has, newest first. */
|
|
@@ -82,24 +99,44 @@ export declare class RpgService {
|
|
|
82
99
|
/** The economy tier a human player rides, which is the cheapest seat available. */
|
|
83
100
|
private economyModel;
|
|
84
101
|
/**
|
|
85
|
-
*
|
|
102
|
+
* Every game this deployment ships, in the order the client is offered them.
|
|
103
|
+
*
|
|
104
|
+
* Read from disk on every call, as `rpg_models.json` is, so a host who drops a pack
|
|
105
|
+
* in does not have to restart the server for it to appear.
|
|
106
|
+
*/
|
|
107
|
+
private tables;
|
|
108
|
+
/**
|
|
109
|
+
* The table a request asked for, or the default.
|
|
110
|
+
*
|
|
111
|
+
* An unknown name is refused rather than falling back, for `resolveRpgModel`'s
|
|
112
|
+
* reason: a name this deployment does not have means the client and the packs
|
|
113
|
+
* directory disagree, and quietly building some other game is worse than saying so.
|
|
86
114
|
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
|
|
115
|
+
* @param packName A pack name, or absent to take the default
|
|
116
|
+
* @throws {NotFoundError} If this deployment ships no game pack at all
|
|
117
|
+
* @throws {ValidationError} If it ships some, but not that one
|
|
118
|
+
*/
|
|
119
|
+
private requireTable;
|
|
120
|
+
/**
|
|
121
|
+
* Turns the chosen pack on if it is not already.
|
|
91
122
|
*
|
|
92
|
-
*
|
|
123
|
+
* Here rather than in `PackInstantiationService`: self-enabling instantiation would
|
|
124
|
+
* change behaviour for every pack to suit one feature. A user on the RPG surface
|
|
125
|
+
* who picked a game has unambiguously asked for that pack's content, and has no
|
|
126
|
+
* Packs page to be sent to.
|
|
93
127
|
*/
|
|
94
|
-
private
|
|
128
|
+
private ensurePackEnabled;
|
|
95
129
|
/**
|
|
96
|
-
*
|
|
130
|
+
* The table a room is a campaign of, or null when it is not one.
|
|
131
|
+
*
|
|
132
|
+
* Both halves matter: the pack alone would also match a game built by hand from the
|
|
133
|
+
* Packs page, which seats a player the RPG page did not create and does not know
|
|
134
|
+
* how to show.
|
|
97
135
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* know how to show.
|
|
136
|
+
* @param room Any room
|
|
137
|
+
* @param tables The tables to match against, resolved by the caller
|
|
101
138
|
*/
|
|
102
|
-
private
|
|
139
|
+
private tableFor;
|
|
103
140
|
/** @throws {NotFoundError} If the room is missing or is not a campaign */
|
|
104
141
|
private requireCampaign;
|
|
105
142
|
/** The listing shape, including the published link the party plays through. */
|