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.
Files changed (55) hide show
  1. package/README.md +105 -0
  2. package/data/common/prompts/moderate.json +34 -0
  3. package/data/common/prompts/moderate.prompt +136 -0
  4. package/data/packs/dnd5e/pack.json +7 -1
  5. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +16 -0
  6. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +23 -0
  7. package/dist-sdk/server/src/ai/agent.d.ts +33 -0
  8. package/dist-sdk/server/src/ai/agent.js +64 -13
  9. package/dist-sdk/server/src/app/user-service-factory.js +3 -0
  10. package/dist-sdk/server/src/app.controller.d.ts +7 -1
  11. package/dist-sdk/server/src/app.controller.js +55 -0
  12. package/dist-sdk/server/src/app.service.d.ts +114 -2
  13. package/dist-sdk/server/src/app.service.js +181 -4
  14. package/dist-sdk/server/src/data/data-guide.builder.d.ts +2 -0
  15. package/dist-sdk/server/src/data/data-guide.builder.js +90 -0
  16. package/dist-sdk/server/src/data/data-registry.d.ts +32 -0
  17. package/dist-sdk/server/src/data/data-registry.js +61 -0
  18. package/dist-sdk/server/src/data/data.types.d.ts +158 -0
  19. package/dist-sdk/server/src/data/data.types.js +24 -0
  20. package/dist-sdk/server/src/data/query-validation.d.ts +45 -0
  21. package/dist-sdk/server/src/data/query-validation.js +245 -0
  22. package/dist-sdk/server/src/documents/document-conversion.d.ts +70 -0
  23. package/dist-sdk/server/src/documents/document-conversion.js +341 -0
  24. package/dist-sdk/server/src/documents/library/chunking.d.ts +65 -0
  25. package/dist-sdk/server/src/documents/library/chunking.js +263 -0
  26. package/dist-sdk/server/src/documents/library/document-guide.builder.d.ts +2 -0
  27. package/dist-sdk/server/src/documents/library/document-guide.builder.js +58 -0
  28. package/dist-sdk/server/src/documents/library/document-registry.d.ts +22 -0
  29. package/dist-sdk/server/src/documents/library/document-registry.js +44 -0
  30. package/dist-sdk/server/src/documents/library/document.types.d.ts +108 -0
  31. package/dist-sdk/server/src/documents/library/document.types.js +20 -0
  32. package/dist-sdk/server/src/documents/library/embedding.d.ts +57 -0
  33. package/dist-sdk/server/src/documents/library/embedding.js +151 -0
  34. package/dist-sdk/server/src/packs/pack-manifest.d.ts +46 -0
  35. package/dist-sdk/server/src/packs/pack-manifest.js +46 -1
  36. package/dist-sdk/server/src/room/artifact-store.service.js +44 -11
  37. package/dist-sdk/server/src/room/artifact.d.ts +8 -0
  38. package/dist-sdk/server/src/room/room.d.ts +7 -5
  39. package/dist-sdk/server/src/room/room.js +44 -7
  40. package/dist-sdk/server/src/rpg/rpg-roster.d.ts +70 -29
  41. package/dist-sdk/server/src/rpg/rpg-roster.js +152 -41
  42. package/dist-sdk/server/src/rpg/rpg.service.d.ts +66 -29
  43. package/dist-sdk/server/src/rpg/rpg.service.js +140 -65
  44. package/dist-sdk/server/src/sdk/index.d.ts +16 -2
  45. package/dist-sdk/server/src/sdk/index.js +37 -1
  46. package/dist-sdk/server/src/tools/core/data.tools.d.ts +17 -0
  47. package/dist-sdk/server/src/tools/core/data.tools.js +165 -0
  48. package/dist-sdk/server/src/tools/core/document.tools.d.ts +39 -0
  49. package/dist-sdk/server/src/tools/core/document.tools.js +391 -0
  50. package/dist-sdk/server/src/tools/core/index.js +3 -1
  51. package/dist-sdk/server/src/tools/native-tool.types.d.ts +37 -0
  52. package/dist-sdk/server/src/tools/tool-execution.service.d.ts +23 -2
  53. package/dist-sdk/server/src/tools/tool-execution.service.js +30 -6
  54. package/dist-sdk/shared/types/app.types.d.ts +39 -5
  55. package/package.json +172 -167
@@ -1,19 +1,28 @@
1
1
  /**
2
- * Campaigns: a streamlined way to start and hold a fifth-edition game.
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 the dnd5e
5
- * pack's `campaign` template — the Dungeon Master, Battle Master, Character Creator,
6
- * Campaign Designer and Table Moderator — with a party seated on top and the whole
7
- * thing published, so the link the party plays through exists from the first moment.
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 agent is a
13
- * player is `isControlledByHuman`; a character's personality is `privateContext`; a
14
- * crew member's role is `packAgentKey`. A store would be a second copy of all of that,
15
- * and it would drift the moment somebody renamed an agent from the Agents page. So a
16
- * campaign is discovered by filtering rooms, and its details are derived per request.
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: nothing in the dnd5e pack fires a
47
- * prompt at instantiation, so this is file I/O for a dozen agents. It either
48
- * returns a campaign that can be played or leaves nothing behind.
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 does not ship the dnd5e pack
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
- * Makes sure the pack a campaign is built from is available and on.
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
- * Enabling it here rather than in `PackInstantiationService`: self-enabling
88
- * instantiation would change behaviour for every pack to suit one feature. A user
89
- * on the RPG surface asking for a campaign has unambiguously asked for the dnd5e
90
- * content, and has no Packs page to be sent to.
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
- * @throws {NotFoundError} If the deployment does not ship the pack
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 ensurePackReady;
128
+ private ensurePackEnabled;
95
129
  /**
96
- * A room built from the campaign template.
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
- * Both halves matter: `pack` alone would also match a table built by hand from the
99
- * Packs page, which has a player seat the RPG page did not create and does not
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 isCampaign;
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. */
@@ -1,20 +1,29 @@
1
1
  "use strict";
2
2
  /**
3
- * Campaigns: a streamlined way to start and hold a fifth-edition game.
3
+ * Campaigns: a streamlined way to start and hold a game.
4
4
  *
5
- * A campaign is not a new kind of thing. It is an ordinary room built from the dnd5e
6
- * pack's `campaign` template — the Dungeon Master, Battle Master, Character Creator,
7
- * Campaign Designer and Table Moderator — with a party seated on top and the whole
8
- * thing published, so the link the party plays through exists from the first moment.
5
+ * A campaign is not a new kind of thing. It is an ordinary room built from a pack's
6
+ * table template — the crew that runs the game — with a party seated on top and the
7
+ * whole thing published, so the link the party plays through exists from the first
8
+ * moment.
9
+ *
10
+ * ## Which games exist
11
+ *
12
+ * Whichever installed packs say so. A pack declares a `table` block naming the room to
13
+ * build and the agent template to seat a party from, and {@link RpgTable} resolves that
14
+ * against its templates; this service asks for the list and never names a pack itself.
15
+ * That is what lets a host drop in a second ruleset — the dnd5e pack seats six players
16
+ * behind five crew agents, the acts pack four students behind three — without the RPG
17
+ * page learning anything about either.
9
18
  *
10
19
  * ## Why there is no campaign store
11
20
  *
12
21
  * Everything a campaign is, a room already holds: its roster, its turn mode, its
13
- * leader and moderator, its artifacts, its transcript and its cost. Which agent is a
14
- * player is `isControlledByHuman`; a character's personality is `privateContext`; a
15
- * crew member's role is `packAgentKey`. A store would be a second copy of all of that,
16
- * and it would drift the moment somebody renamed an agent from the Agents page. So a
17
- * campaign is discovered by filtering rooms, and its details are derived per request.
22
+ * leader and moderator, its artifacts, its transcript and its cost. Which pack it plays
23
+ * by is `pack`; which agent is a player is `packAgentKey`; a character's personality is
24
+ * `privateContext`. A store would be a second copy of all of that, and it would drift
25
+ * the moment somebody renamed an agent from the Agents page. So a campaign is
26
+ * discovered by filtering rooms, and its details are derived per request.
18
27
  *
19
28
  * ## Why every write goes through AppService
20
29
  *
@@ -46,6 +55,18 @@ class RpgService {
46
55
  listModels() {
47
56
  return (0, rpg_models_1.listRpgModelOptions)(this.userPaths.getCommonConfigDir());
48
57
  }
58
+ /**
59
+ * The games a campaign may be built from, as the client is offered them.
60
+ *
61
+ * Installed rather than enabled, because {@link ensurePackEnabled} turns the chosen
62
+ * one on: a user on the RPG surface has no Packs page, so offering only what they
63
+ * had already enabled would offer them nothing at all on their first visit.
64
+ */
65
+ listPacks() {
66
+ const tables = this.tables();
67
+ const preferred = (0, rpg_roster_1.pickDefaultTable)(tables);
68
+ return tables.map((table) => (0, rpg_roster_1.toRpgPackOption)(table, table.pack === preferred?.pack));
69
+ }
49
70
  /**
50
71
  * Builds a campaign and publishes it.
51
72
  *
@@ -53,14 +74,14 @@ class RpgService {
53
74
  * before the first side effect; then the crew; then the party and the publish. Any
54
75
  * failure past the first agent deletes the room, which takes its agents with it.
55
76
  *
56
- * Synchronous throughout, unlike story creation: nothing in the dnd5e pack fires a
57
- * prompt at instantiation, so this is file I/O for a dozen agents. It either
58
- * returns a campaign that can be played or leaves nothing behind.
77
+ * Synchronous throughout, unlike story creation: no pack fires a prompt at
78
+ * instantiation, so this is file I/O for a dozen agents. It either returns a
79
+ * campaign that can be played or leaves nothing behind.
59
80
  *
60
- * @param request The campaign's name, quality tier and party
81
+ * @param request The campaign's name, game, quality tier and party
61
82
  * @returns The campaign, its public link, and anything that did not go to plan
62
- * @throws {ValidationError} If the party or the quality tier is not acceptable
63
- * @throws {NotFoundError} If this deployment does not ship the dnd5e pack
83
+ * @throws {ValidationError} If the game, the party or the quality tier is not acceptable
84
+ * @throws {NotFoundError} If this deployment ships no game pack at all
64
85
  */
65
86
  async createCampaign(request) {
66
87
  const name = request.name?.trim();
@@ -72,12 +93,13 @@ class RpgService {
72
93
  }
73
94
  // Phase 0: nothing here has an effect, so a typo in the fourth player's model
74
95
  // surfaces before three agents exist.
75
- (0, rpg_roster_1.assertSeatable)(request.players);
76
- const seats = this.resolveSeats(request.players);
96
+ const table = this.requireTable(request.pack);
97
+ (0, rpg_roster_1.assertSeatable)(request.players, table);
98
+ const seats = this.resolveSeats(request.players, table);
77
99
  const crewModels = (0, rpg_models_1.resolveCrewModels)(this.userPaths.getCommonConfigDir(), request.quality);
78
- this.ensurePackReady();
100
+ this.ensurePackEnabled(table.pack);
79
101
  // Phase 1: the crew. This rolls itself back on failure.
80
- const built = await this.app.packInstantiation.instantiateRoom(rpg_roster_1.RPG_PACK, rpg_roster_1.RPG_ROOM_KEY, crewModels, name);
102
+ const built = await this.app.packInstantiation.instantiateRoom(table.pack, table.roomKey, crewModels, name);
81
103
  const campaignId = built.roomId;
82
104
  const warnings = [...built.warnings];
83
105
  // Phase 2: the party, then the link. From here the room exists, so a failure
@@ -86,28 +108,31 @@ class RpgService {
86
108
  const players = [];
87
109
  for (const seat of seats) {
88
110
  const created = await this.app.createRoomAgentFromFolder(campaignId, {
89
- folder: rpg_roster_1.RPG_PLAYER_FOLDER,
111
+ folder: table.playerFolder,
90
112
  aiServiceName: seat.model?.service ?? crewModels.primary.aiServiceName,
91
113
  aiModel: seat.model?.model ?? this.economyModel(crewModels),
92
114
  smallModelName: seat.model?.small_model ?? crewModels.primary.smallModelName,
93
115
  overrides: {
116
+ // The pack's own seat settings first, so anything it asks for
117
+ // that is none of this service's business survives. Everything
118
+ // below is a decision the RPG page made, and has to win.
119
+ ...table.playerOverrides,
94
120
  agentName: seat.seatName,
95
- // A placeholder, and unique by construction. The character
96
- // creator renames the agent to whatever character the player
97
- // invents, which is what gives the table one name per person
98
- // instead of a seat name and a character name for each.
121
+ // A placeholder, and unique by construction. The pack's
122
+ // character builder renames the agent to whatever character the
123
+ // player invents, which is what gives the table one name per
124
+ // person instead of a seat name and a character name for each.
99
125
  agentNickname: seat.seatName.replace(/\s+/g, ''),
100
- description: `${seat.seatName}, a player at the table. Renamed to their character once their sheet is built.`,
101
126
  controlledByHuman: seat.isHuman,
102
127
  // AI players only. A person at the table keeps the action and
103
128
  // target pickers, so they can whisper to another player or
104
- // address the DM directly rather than having the moderator
105
- // decide both from their text.
129
+ // address the game's leader directly rather than having the
130
+ // moderator decide both from their text.
106
131
  useModerator: !seat.isHuman,
107
132
  ...(seat.isHuman ? {} : { privateContext: seat.personality }),
108
133
  },
109
- pack: rpg_roster_1.RPG_PACK,
110
- packAgentKey: rpg_roster_1.RPG_PLAYER_AGENT_KEY,
134
+ pack: table.pack,
135
+ packAgentKey: table.playerAgentKey,
111
136
  });
112
137
  players.push({
113
138
  agentId: created.agentId,
@@ -131,7 +156,7 @@ class RpgService {
131
156
  };
132
157
  }
133
158
  catch (error) {
134
- // A campaign short a player is a table where the Dungeon Master addresses
159
+ // A campaign short a player is a table where the game's leader addresses
135
160
  // somebody who is not there, and a campaign with no link has nothing to
136
161
  // play in. Neither is a state the UI has a screen for, so there is no
137
162
  // partial success worth keeping. deleteRoom also takes the agents the room
@@ -145,13 +170,18 @@ class RpgService {
145
170
  }
146
171
  /** Every campaign this user has, newest first. */
147
172
  async listCampaigns() {
173
+ // Resolved once for the whole listing: reading the tables means reading every
174
+ // installed pack's directory, and a user with a dozen campaigns would otherwise
175
+ // do it a dozen times to answer the same question.
176
+ const tables = this.tables();
148
177
  const rooms = await this.app.listRooms();
149
178
  const campaigns = [];
150
179
  for (const summary of rooms) {
151
180
  const room = await this.app.getRoomById(summary.id);
152
- if (!room || !this.isCampaign(room))
181
+ const table = room && this.tableFor(room, tables);
182
+ if (!room || !table)
153
183
  continue;
154
- campaigns.push(await this.summarize(room));
184
+ campaigns.push(await this.summarize(room, table));
155
185
  }
156
186
  return campaigns.sort((a, b) => b.createdAt.localeCompare(a.createdAt));
157
187
  }
@@ -164,9 +194,9 @@ class RpgService {
164
194
  * @throws {NotFoundError} If there is no such campaign
165
195
  */
166
196
  async getCampaign(campaignId) {
167
- const room = await this.requireCampaign(campaignId);
168
- const summary = await this.summarize(room);
169
- const { players, crew } = this.splitRoster(room);
197
+ const { room, table } = await this.requireCampaign(campaignId);
198
+ const summary = await this.summarize(room, table);
199
+ const { players, crew } = this.splitRoster(room, table);
170
200
  return {
171
201
  ...summary,
172
202
  goal: room.getGoal(),
@@ -184,7 +214,7 @@ class RpgService {
184
214
  * @throws {ValidationError} If the campaign already has a link
185
215
  */
186
216
  async republishCampaign(campaignId) {
187
- const room = await this.requireCampaign(campaignId);
217
+ const { room } = await this.requireCampaign(campaignId);
188
218
  const existing = await this.app.getPublishedRoomInstances(campaignId);
189
219
  if (existing.length > 0) {
190
220
  throw new errors_1.ValidationError('This campaign already has a link.');
@@ -193,10 +223,10 @@ class RpgService {
193
223
  return { instanceId, publicPath: `/public/rooms/${instanceId}` };
194
224
  }
195
225
  /** Each seat with its model resolved up front. @throws {ValidationError} */
196
- resolveSeats(players) {
226
+ resolveSeats(players, table) {
197
227
  const configDir = this.userPaths.getCommonConfigDir();
198
228
  return players.map((player, index) => ({
199
- seatName: rpg_roster_1.RPG_SEAT_NAMES[index],
229
+ seatName: table.seatNames[index],
200
230
  isHuman: player.isHuman,
201
231
  personality: player.personality?.trim() ?? '',
202
232
  model: player.isHuman
@@ -209,51 +239,96 @@ class RpgService {
209
239
  return (models.economy ?? models.primary).aiModel;
210
240
  }
211
241
  /**
212
- * Makes sure the pack a campaign is built from is available and on.
242
+ * Every game this deployment ships, in the order the client is offered them.
213
243
  *
214
- * Enabling it here rather than in `PackInstantiationService`: self-enabling
215
- * instantiation would change behaviour for every pack to suit one feature. A user
216
- * on the RPG surface asking for a campaign has unambiguously asked for the dnd5e
217
- * content, and has no Packs page to be sent to.
244
+ * Read from disk on every call, as `rpg_models.json` is, so a host who drops a pack
245
+ * in does not have to restart the server for it to appear.
246
+ */
247
+ tables() {
248
+ return this.packs
249
+ .listPacks()
250
+ .map((pack) => (0, rpg_roster_1.resolveRpgTable)(pack))
251
+ .filter((table) => table !== null);
252
+ }
253
+ /**
254
+ * The table a request asked for, or the default.
218
255
  *
219
- * @throws {NotFoundError} If the deployment does not ship the pack
256
+ * An unknown name is refused rather than falling back, for `resolveRpgModel`'s
257
+ * reason: a name this deployment does not have means the client and the packs
258
+ * directory disagree, and quietly building some other game is worse than saying so.
259
+ *
260
+ * @param packName A pack name, or absent to take the default
261
+ * @throws {NotFoundError} If this deployment ships no game pack at all
262
+ * @throws {ValidationError} If it ships some, but not that one
220
263
  */
221
- ensurePackReady() {
222
- if (!this.packs.installedPackNames().includes(rpg_roster_1.RPG_PACK)) {
223
- throw new errors_1.NotFoundError('This deployment does not ship the D&D pack.');
264
+ requireTable(packName) {
265
+ const tables = this.tables();
266
+ if (tables.length === 0) {
267
+ throw new errors_1.NotFoundError('This deployment does not ship a game to play.');
268
+ }
269
+ const wanted = packName?.trim();
270
+ if (!wanted) {
271
+ return (0, rpg_roster_1.pickDefaultTable)(tables);
224
272
  }
225
- if (!this.packs.enabledPacks().includes(rpg_roster_1.RPG_PACK)) {
226
- logger_1.logger.log(`Enabling the ${rpg_roster_1.RPG_PACK} pack for ${this.userId}: they asked for a campaign.`);
227
- this.userConfig.setPackEnabled(rpg_roster_1.RPG_PACK, true);
273
+ const match = tables.find((table) => table.pack === wanted) ??
274
+ tables.find((table) => table.pack.toLowerCase() === wanted.toLowerCase());
275
+ if (!match) {
276
+ throw new errors_1.ValidationError(`"${packName}" is not a game this deployment offers. Choose one of: ` +
277
+ tables.map((table) => table.pack).join(', '));
278
+ }
279
+ return match;
280
+ }
281
+ /**
282
+ * Turns the chosen pack on if it is not already.
283
+ *
284
+ * Here rather than in `PackInstantiationService`: self-enabling instantiation would
285
+ * change behaviour for every pack to suit one feature. A user on the RPG surface
286
+ * who picked a game has unambiguously asked for that pack's content, and has no
287
+ * Packs page to be sent to.
288
+ */
289
+ ensurePackEnabled(packName) {
290
+ if (!this.packs.enabledPacks().includes(packName)) {
291
+ logger_1.logger.log(`Enabling the ${packName} pack for ${this.userId}: they asked for a campaign.`);
292
+ this.userConfig.setPackEnabled(packName, true);
228
293
  }
229
294
  }
230
295
  /**
231
- * A room built from the campaign template.
296
+ * The table a room is a campaign of, or null when it is not one.
297
+ *
298
+ * Both halves matter: the pack alone would also match a game built by hand from the
299
+ * Packs page, which seats a player the RPG page did not create and does not know
300
+ * how to show.
232
301
  *
233
- * Both halves matter: `pack` alone would also match a table built by hand from the
234
- * Packs page, which has a player seat the RPG page did not create and does not
235
- * know how to show.
302
+ * @param room Any room
303
+ * @param tables The tables to match against, resolved by the caller
236
304
  */
237
- isCampaign(room) {
238
- return room.getPack() === rpg_roster_1.RPG_PACK && room.getPackRoomKey() === rpg_roster_1.RPG_ROOM_KEY;
305
+ tableFor(room, tables) {
306
+ const pack = room.getPack();
307
+ const roomKey = room.getPackRoomKey();
308
+ if (!pack || !roomKey)
309
+ return null;
310
+ return tables.find((table) => table.pack === pack && table.roomKey === roomKey) ?? null;
239
311
  }
240
312
  /** @throws {NotFoundError} If the room is missing or is not a campaign */
241
313
  async requireCampaign(campaignId) {
242
314
  const room = await this.app.getRoomById(campaignId);
243
- if (!room || !this.isCampaign(room)) {
315
+ const table = room && this.tableFor(room, this.tables());
316
+ if (!room || !table) {
244
317
  throw new errors_1.NotFoundError('Campaign not found');
245
318
  }
246
- return room;
319
+ return { room, table };
247
320
  }
248
321
  /** The listing shape, including the published link the party plays through. */
249
- async summarize(room) {
322
+ async summarize(room, table) {
250
323
  const instances = await this.app.getPublishedRoomInstances(room.getId());
251
324
  const instance = instances[0];
252
325
  const agents = room.getAgents();
253
- const players = agents.filter((agent) => this.isPlayer(agent));
326
+ const players = agents.filter((agent) => this.isPlayer(agent, table));
254
327
  return {
255
328
  campaignId: room.getId(),
256
329
  name: room.getName(),
330
+ pack: table.pack,
331
+ packTitle: table.title,
257
332
  instanceId: instance?.id,
258
333
  playerCount: players.length,
259
334
  playerNames: players.map((agent) => agent.agentNickname),
@@ -272,12 +347,12 @@ class RpgService {
272
347
  * AI player is a player too — it is seated from the same template and shown in the
273
348
  * same roster.
274
349
  */
275
- splitRoster(room) {
350
+ splitRoster(room, table) {
276
351
  const configDir = this.userPaths.getCommonConfigDir();
277
352
  const players = [];
278
353
  const crew = [];
279
354
  for (const agent of room.getAgents()) {
280
- if (this.isPlayer(agent)) {
355
+ if (this.isPlayer(agent, table)) {
281
356
  players.push({
282
357
  agentId: agent.id,
283
358
  nickname: agent.agentNickname,
@@ -299,8 +374,8 @@ class RpgService {
299
374
  }
300
375
  return { players, crew };
301
376
  }
302
- isPlayer(agent) {
303
- return agent.packAgentKey === rpg_roster_1.RPG_PLAYER_AGENT_KEY;
377
+ isPlayer(agent, table) {
378
+ return agent.packAgentKey === table.playerAgentKey;
304
379
  }
305
380
  }
306
381
  exports.RpgService = RpgService;
@@ -1,14 +1,28 @@
1
1
  export { Briyah } from './briyah';
2
2
  export { BriyahConfigService, BriyahConfigOptions } from './briyah-config';
3
- export type { AppService, AgentCreationOptions, PdfMarkdownOptions, PdfMarkdownResult, } from '../app.service';
3
+ export type { AppService, AgentCreationOptions, PdfMarkdownOptions, PdfMarkdownResult, DocumentMarkdownOptions, DocumentMarkdownResult, } from '../app.service';
4
+ export { detectDocumentType, convertLocalDocument, UnsupportedDocumentError, } from '../documents/document-conversion';
5
+ export type { DocumentFileType, DocumentTypeDetection, DocumentPage as ConvertedDocumentPage, LocalDocumentConversion, LocalConversionOptions, } from '../documents/document-conversion';
6
+ export type { DocumentSource, DocumentSummary, DocumentSearchRequest, DocumentHit, DocumentPages, DocumentPage, DocumentText, PageRange, } from '../documents/library/document.types';
7
+ export { registerDocumentSource, unregisterDocumentSource, listDocumentSources, } from '../documents/library/document-registry';
8
+ export { buildDocumentGuideMarkdown } from '../documents/library/document-guide.builder';
9
+ export { chunkPages, embeddingInput, DEFAULT_CHUNK_MAX_CHARS, DEFAULT_CHUNK_OVERLAP_CHARS, } from '../documents/library/chunking';
10
+ export type { ChunkablePage, DocumentChunk, ChunkOptions } from '../documents/library/chunking';
11
+ export { embedTexts, EMBEDDING_DIMENSIONS, DEFAULT_EMBEDDING_MODEL, } from '../documents/library/embedding';
12
+ export type { EmbeddingProvider, EmbeddingOptions, EmbeddingResult } from '../documents/library/embedding';
13
+ export { libraryAttachmentName, isLibraryAttachment, libraryDocumentIdOf, } from '../tools/core/document.tools';
4
14
  export { splitMarkdownIntoPages, stripWrappingFence, pageMarker, buildMarkdown, } from '../documents/pdf-conversion';
5
15
  export type { PdfPageMarkdown, PdfConversionOptions, PdfConversionResult, ConversionAgent, } from '../documents/pdf-conversion';
6
16
  export type { AgentInfo, CreateAgentResponse, RoomInfo, RoomDetails, CreateRoomResponse, StoryInfo, CreateStoryResponse, ProcessTextResponse, FileList, PromptFileContent, AttachDocumentResponse, AgentMessagesResponse, RoomMessagesResponse, RoomMessageUpdate, RoomErrorUpdate, RoomUpdate, RoomTurnMode, SendMessageResult, StoryState, Message, MessageAction, ModelInfo, ArtifactMetadata, PreparedPromptResponse, PromptScope, PromptFolder, PromptFoldersResponse, PromptFolderDefaults, PromptFolderDefaultsResponse, PromptFile, PromptFilesResponse, StoryIdea, Transaction, TransactionHistoryResponse, ToolDefinition, ToolParameter, ToolSummary, ToolsResponse, ToolRunResult, StoryStateEvent, StoryIntroduceCharacterEvent, StoryProgressChapterEvent, StoryErrorEvent, Character, ChapterInfo, } from '../../../shared/types/app.types';
7
17
  export type { LoggingOptions } from './briyah-config';
8
- export type { NativeToolDefinition, ToolHelpers, ToolContext, ToolCaller, ToolArtifact, ToolRoomAccess, ToolPackDocuments, ArtifactWriteOptions, } from '../tools/native-tool.types';
18
+ export type { NativeToolDefinition, ToolHelpers, ToolContext, ToolCaller, ToolArtifact, ToolRoomAccess, ToolPackDocuments, ToolAgentDocuments, ToolHeldDocument, ArtifactWriteOptions, } from '../tools/native-tool.types';
9
19
  export { dnd5eTools } from '../tools/packs/dnd5e';
10
20
  export { installToolPacks, registerToolPacks, availableToolPacks } from '../tools/packs';
11
21
  export { NativeToolRegistry } from '../tools/native-tool-registry.service';
22
+ export type { DataSource, DataSet, DataField, DataFieldType, DataAggregateFn, DataFilter, DataFilterOp, DataMetric, DataOrder, DataQuery, DataRow, DataResult, } from '../data/data.types';
23
+ export { DEFAULT_ROW_LIMIT, MAX_ROW_LIMIT } from '../data/data.types';
24
+ export { registerDataSource, unregisterDataSource, listDataSources, listDatasets, } from '../data/data-registry';
25
+ export { buildDataGuideMarkdown } from '../data/data-guide.builder';
12
26
  export { PackService } from '../packs/pack.service';
13
27
  export type { PackView } from '../packs/pack.service';
14
28
  export { PackInstantiationService } from '../packs/pack-instantiation.service';
@@ -1,11 +1,37 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.RoomMessage = exports.Room = exports.Agent = exports.PackInstantiationService = exports.PackService = exports.NativeToolRegistry = exports.availableToolPacks = exports.registerToolPacks = exports.installToolPacks = exports.dnd5eTools = exports.buildMarkdown = exports.pageMarker = exports.stripWrappingFence = exports.splitMarkdownIntoPages = exports.BriyahConfigService = exports.Briyah = void 0;
3
+ exports.RoomMessage = exports.Room = exports.Agent = exports.PackInstantiationService = exports.PackService = exports.buildDataGuideMarkdown = exports.listDatasets = exports.listDataSources = exports.unregisterDataSource = exports.registerDataSource = exports.MAX_ROW_LIMIT = exports.DEFAULT_ROW_LIMIT = exports.NativeToolRegistry = exports.availableToolPacks = exports.registerToolPacks = exports.installToolPacks = exports.dnd5eTools = exports.buildMarkdown = exports.pageMarker = exports.stripWrappingFence = exports.splitMarkdownIntoPages = exports.libraryDocumentIdOf = exports.isLibraryAttachment = exports.libraryAttachmentName = exports.DEFAULT_EMBEDDING_MODEL = exports.EMBEDDING_DIMENSIONS = exports.embedTexts = exports.DEFAULT_CHUNK_OVERLAP_CHARS = exports.DEFAULT_CHUNK_MAX_CHARS = exports.embeddingInput = exports.chunkPages = exports.buildDocumentGuideMarkdown = exports.listDocumentSources = exports.unregisterDocumentSource = exports.registerDocumentSource = exports.UnsupportedDocumentError = exports.convertLocalDocument = exports.detectDocumentType = exports.BriyahConfigService = exports.Briyah = void 0;
4
4
  // Main SDK exports
5
5
  var briyah_1 = require("./briyah");
6
6
  Object.defineProperty(exports, "Briyah", { enumerable: true, get: function () { return briyah_1.Briyah; } });
7
7
  var briyah_config_1 = require("./briyah-config");
8
8
  Object.defineProperty(exports, "BriyahConfigService", { enumerable: true, get: function () { return briyah_config_1.BriyahConfigService; } });
9
+ // Any upload → Markdown. `appService.convertDocumentToMarkdown` is the entry point
10
+ // and handles PDF, Word, Excel and text alike; these are exported for a host that
11
+ // wants to check a file before accepting it, or to catch the refusal by type.
12
+ var document_conversion_1 = require("../documents/document-conversion");
13
+ Object.defineProperty(exports, "detectDocumentType", { enumerable: true, get: function () { return document_conversion_1.detectDocumentType; } });
14
+ Object.defineProperty(exports, "convertLocalDocument", { enumerable: true, get: function () { return document_conversion_1.convertLocalDocument; } });
15
+ Object.defineProperty(exports, "UnsupportedDocumentError", { enumerable: true, get: function () { return document_conversion_1.UnsupportedDocumentError; } });
16
+ var document_registry_1 = require("../documents/library/document-registry");
17
+ Object.defineProperty(exports, "registerDocumentSource", { enumerable: true, get: function () { return document_registry_1.registerDocumentSource; } });
18
+ Object.defineProperty(exports, "unregisterDocumentSource", { enumerable: true, get: function () { return document_registry_1.unregisterDocumentSource; } });
19
+ Object.defineProperty(exports, "listDocumentSources", { enumerable: true, get: function () { return document_registry_1.listDocumentSources; } });
20
+ var document_guide_builder_1 = require("../documents/library/document-guide.builder");
21
+ Object.defineProperty(exports, "buildDocumentGuideMarkdown", { enumerable: true, get: function () { return document_guide_builder_1.buildDocumentGuideMarkdown; } });
22
+ var chunking_1 = require("../documents/library/chunking");
23
+ Object.defineProperty(exports, "chunkPages", { enumerable: true, get: function () { return chunking_1.chunkPages; } });
24
+ Object.defineProperty(exports, "embeddingInput", { enumerable: true, get: function () { return chunking_1.embeddingInput; } });
25
+ Object.defineProperty(exports, "DEFAULT_CHUNK_MAX_CHARS", { enumerable: true, get: function () { return chunking_1.DEFAULT_CHUNK_MAX_CHARS; } });
26
+ Object.defineProperty(exports, "DEFAULT_CHUNK_OVERLAP_CHARS", { enumerable: true, get: function () { return chunking_1.DEFAULT_CHUNK_OVERLAP_CHARS; } });
27
+ var embedding_1 = require("../documents/library/embedding");
28
+ Object.defineProperty(exports, "embedTexts", { enumerable: true, get: function () { return embedding_1.embedTexts; } });
29
+ Object.defineProperty(exports, "EMBEDDING_DIMENSIONS", { enumerable: true, get: function () { return embedding_1.EMBEDDING_DIMENSIONS; } });
30
+ Object.defineProperty(exports, "DEFAULT_EMBEDDING_MODEL", { enumerable: true, get: function () { return embedding_1.DEFAULT_EMBEDDING_MODEL; } });
31
+ var document_tools_1 = require("../tools/core/document.tools");
32
+ Object.defineProperty(exports, "libraryAttachmentName", { enumerable: true, get: function () { return document_tools_1.libraryAttachmentName; } });
33
+ Object.defineProperty(exports, "isLibraryAttachment", { enumerable: true, get: function () { return document_tools_1.isLibraryAttachment; } });
34
+ Object.defineProperty(exports, "libraryDocumentIdOf", { enumerable: true, get: function () { return document_tools_1.libraryDocumentIdOf; } });
9
35
  // PDF → Markdown conversion.
10
36
  //
11
37
  // `appService.convertPdfToMarkdownPages` is the entry point; these are exported for
@@ -33,6 +59,16 @@ Object.defineProperty(exports, "registerToolPacks", { enumerable: true, get: fun
33
59
  Object.defineProperty(exports, "availableToolPacks", { enumerable: true, get: function () { return packs_1.availableToolPacks; } });
34
60
  var native_tool_registry_service_1 = require("../tools/native-tool-registry.service");
35
61
  Object.defineProperty(exports, "NativeToolRegistry", { enumerable: true, get: function () { return native_tool_registry_service_1.NativeToolRegistry; } });
62
+ var data_types_1 = require("../data/data.types");
63
+ Object.defineProperty(exports, "DEFAULT_ROW_LIMIT", { enumerable: true, get: function () { return data_types_1.DEFAULT_ROW_LIMIT; } });
64
+ Object.defineProperty(exports, "MAX_ROW_LIMIT", { enumerable: true, get: function () { return data_types_1.MAX_ROW_LIMIT; } });
65
+ var data_registry_1 = require("../data/data-registry");
66
+ Object.defineProperty(exports, "registerDataSource", { enumerable: true, get: function () { return data_registry_1.registerDataSource; } });
67
+ Object.defineProperty(exports, "unregisterDataSource", { enumerable: true, get: function () { return data_registry_1.unregisterDataSource; } });
68
+ Object.defineProperty(exports, "listDataSources", { enumerable: true, get: function () { return data_registry_1.listDataSources; } });
69
+ Object.defineProperty(exports, "listDatasets", { enumerable: true, get: function () { return data_registry_1.listDatasets; } });
70
+ var data_guide_builder_1 = require("../data/data-guide.builder");
71
+ Object.defineProperty(exports, "buildDataGuideMarkdown", { enumerable: true, get: function () { return data_guide_builder_1.buildDataGuideMarkdown; } });
36
72
  // Packs: a domain's prompt folders, documents, tools and templates, installed for
37
73
  // everyone and enabled per user.
38
74
  //
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Reading a host's data, without the model ever writing a query language.
3
+ *
4
+ * `query_data` takes a JSON description of a question — dataset, filters,
5
+ * groupings, metrics — validates every name in it against what the host
6
+ * declared, and hands the result to the host's executor. A field the host did
7
+ * not declare cannot reach the executor, so the host builds its statement from
8
+ * names it chose rather than from anything a model produced. That is the whole
9
+ * safety argument, and it holds without a read-only database role behind it.
10
+ *
11
+ * The DSL arrives as one string parameter because {@link ToolParameter} cannot
12
+ * express nesting. Models reproduce a shown example far more reliably than they
13
+ * invent a shape, so the description carries two worked ones.
14
+ */
15
+ import { NativeToolDefinition } from '../native-tool.types';
16
+ export declare const describeDataTool: NativeToolDefinition;
17
+ export declare const queryDataTool: NativeToolDefinition;