briyah 1.4.1 → 2.0.0

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 (227) hide show
  1. package/README.md +1092 -849
  2. package/data/common/config/markup +1 -1
  3. package/data/common/prompts/character/progress_character.json +5 -5
  4. package/data/common/prompts/illustrator/describe_scene.json +11 -3
  5. package/data/common/prompts/perceive.json +2 -2
  6. package/data/common/prompts/room_moderator/moderate.json +34 -34
  7. package/data/common/prompts/story_moderator/moderate.json +62 -62
  8. package/data/packs/dnd5e/agents/battle-master.json +6 -0
  9. package/data/packs/dnd5e/agents/campaign-designer.json +6 -0
  10. package/data/packs/dnd5e/agents/character-creator.json +6 -0
  11. package/data/packs/dnd5e/agents/dungeon-master.json +6 -0
  12. package/data/packs/dnd5e/agents/player.json +13 -0
  13. package/data/packs/dnd5e/agents/table-moderator.json +6 -0
  14. package/data/{common/artifacts/dnd5e/dungeon_master-procedure.md → packs/dnd5e/artifacts/battle_master-combat.md} +31 -131
  15. package/data/packs/dnd5e/artifacts/dungeon_master-procedure.md +192 -0
  16. package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/manifest.json +8 -2
  17. package/data/packs/dnd5e/pack.json +6 -0
  18. package/data/packs/dnd5e/prompts/battle_master/defaults_config.json +23 -0
  19. package/data/packs/dnd5e/prompts/battle_master/perceive.json +33 -0
  20. package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +378 -0
  21. package/data/{common → packs/dnd5e}/prompts/character_creator/defaults_config.json +1 -1
  22. package/data/{common → packs/dnd5e}/prompts/character_creator/perceive.prompt +29 -0
  23. package/data/{common → packs/dnd5e}/prompts/dnd_player/perceive.prompt +40 -22
  24. package/data/{common → packs/dnd5e}/prompts/dnd_room_moderator/moderate.json +34 -34
  25. package/data/{common → packs/dnd5e}/prompts/dnd_room_moderator/moderate.prompt +14 -3
  26. package/data/{common → packs/dnd5e}/prompts/dungeon_master/defaults_config.json +1 -0
  27. package/data/{common → packs/dnd5e}/prompts/dungeon_master/perceive.prompt +122 -115
  28. package/data/packs/dnd5e/prompts/dungeon_master/system_instruction.prompt +0 -0
  29. package/data/packs/dnd5e/rooms/table.json +16 -0
  30. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +4 -13
  31. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +2 -1
  32. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +65 -77
  33. package/dist-sdk/server/src/ai/agent-config.d.ts +2 -0
  34. package/dist-sdk/server/src/ai/agent-store.service.js +8 -0
  35. package/dist-sdk/server/src/ai/agent.d.ts +6 -0
  36. package/dist-sdk/server/src/ai/agent.js +25 -2
  37. package/dist-sdk/server/src/ai/artifact.service.d.ts +3 -1
  38. package/dist-sdk/server/src/ai/artifact.service.js +12 -5
  39. package/dist-sdk/server/src/ai/pack-artifacts.d.ts +3 -3
  40. package/dist-sdk/server/src/ai/pack-artifacts.js +21 -15
  41. package/dist-sdk/server/src/app/user-service-factory.js +9 -1
  42. package/dist-sdk/server/src/app.controller.d.ts +11 -11
  43. package/dist-sdk/server/src/app.controller.js +178 -88
  44. package/dist-sdk/server/src/app.service.d.ts +36 -8
  45. package/dist-sdk/server/src/app.service.js +147 -91
  46. package/dist-sdk/server/src/common/errors.d.ts +0 -3
  47. package/dist-sdk/server/src/common/errors.js +1 -11
  48. package/dist-sdk/server/src/config/prompt-resolver.d.ts +39 -0
  49. package/dist-sdk/server/src/config/prompt-resolver.js +189 -0
  50. package/dist-sdk/server/src/config/user-config.service.d.ts +17 -0
  51. package/dist-sdk/server/src/config/user-config.service.js +103 -0
  52. package/dist-sdk/server/src/config/user-paths.service.d.ts +4 -4
  53. package/dist-sdk/server/src/config/user-paths.service.js +12 -16
  54. package/dist-sdk/server/src/packs/pack-instantiation.service.d.ts +35 -0
  55. package/dist-sdk/server/src/packs/pack-instantiation.service.js +154 -0
  56. package/dist-sdk/server/src/packs/pack-manifest.d.ts +52 -0
  57. package/dist-sdk/server/src/packs/pack-manifest.js +256 -0
  58. package/dist-sdk/server/src/packs/pack.service.d.ts +24 -0
  59. package/dist-sdk/server/src/packs/pack.service.js +151 -0
  60. package/dist-sdk/server/src/room/room-config.d.ts +5 -0
  61. package/dist-sdk/server/src/room/room-store.service.d.ts +3 -0
  62. package/dist-sdk/server/src/room/room-store.service.js +41 -5
  63. package/dist-sdk/server/src/room/room.d.ts +10 -2
  64. package/dist-sdk/server/src/room/room.js +37 -6
  65. package/dist-sdk/server/src/sdk/briyah.d.ts +2 -0
  66. package/dist-sdk/server/src/sdk/briyah.js +45 -8
  67. package/dist-sdk/server/src/sdk/index.d.ts +8 -3
  68. package/dist-sdk/server/src/sdk/index.js +6 -2
  69. package/dist-sdk/server/src/shared/shared.module.js +0 -3
  70. package/dist-sdk/server/src/story/story.service.d.ts +2 -2
  71. package/dist-sdk/server/src/story/story.service.js +2 -2
  72. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.d.ts +17 -0
  73. package/dist-sdk/server/src/tools/packs/dnd5e/data/kits.js +54 -0
  74. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.d.ts +3 -0
  75. package/dist-sdk/server/src/tools/packs/dnd5e/data/races.js +6 -0
  76. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.d.ts +2 -0
  77. package/dist-sdk/server/src/tools/packs/dnd5e/data/srd.js +4 -0
  78. package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.d.ts +1 -1
  79. package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.js +6 -3
  80. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +3 -0
  81. package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +45 -5
  82. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +27 -0
  83. package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +103 -0
  84. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.d.ts +7 -0
  85. package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +83 -0
  86. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.d.ts +19 -0
  87. package/dist-sdk/server/src/tools/packs/dnd5e/engine/kits.js +130 -0
  88. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.d.ts +2 -1
  89. package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +13 -2
  90. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.d.ts +6 -0
  91. package/dist-sdk/server/src/tools/packs/dnd5e/engine/rules.js +16 -0
  92. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +10 -0
  93. package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +82 -1
  94. package/dist-sdk/server/src/tools/packs/dnd5e/index.js +2 -0
  95. package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +51 -6
  96. package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +19 -9
  97. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.d.ts +2 -0
  98. package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +134 -0
  99. package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +31 -13
  100. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +2 -0
  101. package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +25 -8
  102. package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +70 -4
  103. package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +27 -0
  104. package/dist-sdk/server/src/tools/packs/index.d.ts +1 -2
  105. package/dist-sdk/server/src/tools/packs/index.js +5 -11
  106. package/dist-sdk/shared/types/app.types.d.ts +72 -13
  107. package/docs/assets/hierarchy.js +1 -1
  108. package/docs/assets/highlight.css +8 -1
  109. package/docs/assets/icons.js +1 -1
  110. package/docs/assets/icons.svg +1 -1
  111. package/docs/assets/main.js +4 -4
  112. package/docs/assets/navigation.js +1 -1
  113. package/docs/assets/search.js +1 -1
  114. package/docs/assets/style.css +18 -3
  115. package/docs/classes/Agent.html +702 -37
  116. package/docs/classes/Briyah.html +250 -33
  117. package/docs/classes/BriyahConfigService.html +117 -10
  118. package/docs/classes/NativeToolRegistry.html +156 -11
  119. package/docs/classes/PackInstantiationService.html +146 -0
  120. package/docs/classes/PackService.html +247 -0
  121. package/docs/classes/Room.html +1196 -74
  122. package/docs/classes/RoomMessage.html +260 -29
  123. package/docs/enums/MessageAction.html +123 -3
  124. package/docs/functions/availableToolPacks.html +41 -2
  125. package/docs/functions/dnd5eTools.html +42 -3
  126. package/docs/functions/installToolPacks.html +48 -0
  127. package/docs/functions/registerToolPacks.html +54 -6
  128. package/docs/hierarchy.html +42 -1
  129. package/docs/index.html +218 -30
  130. package/docs/interfaces/AgentCreationOptions.html +125 -0
  131. package/docs/interfaces/AgentInfo.html +188 -3
  132. package/docs/interfaces/AgentMessagesResponse.html +71 -2
  133. package/docs/interfaces/AppService.html +2799 -466
  134. package/docs/interfaces/Artifact.html +81 -4
  135. package/docs/interfaces/ArtifactMetadata.html +104 -3
  136. package/docs/interfaces/ArtifactWriteOptions.html +75 -6
  137. package/docs/interfaces/AttachDocumentResponse.html +61 -2
  138. package/docs/interfaces/BriyahConfigOptions.html +107 -10
  139. package/docs/interfaces/ChapterInfo.html +61 -2
  140. package/docs/interfaces/Character.html +81 -2
  141. package/docs/interfaces/CreateAgentResponse.html +56 -2
  142. package/docs/interfaces/CreateRoomResponse.html +61 -2
  143. package/docs/interfaces/CreateStoryResponse.html +56 -2
  144. package/docs/interfaces/FileList.html +56 -2
  145. package/docs/interfaces/FileMetadata.html +84 -3
  146. package/docs/interfaces/IConfigService.html +76 -3
  147. package/docs/interfaces/InstantiateModels.html +64 -0
  148. package/docs/interfaces/InstantiateRoomResult.html +70 -0
  149. package/docs/interfaces/LoadedPack.html +131 -0
  150. package/docs/interfaces/LoggingOptions.html +86 -7
  151. package/docs/interfaces/Message.html +80 -2
  152. package/docs/interfaces/ModelChoice.html +73 -0
  153. package/docs/interfaces/ModelInfo.html +71 -2
  154. package/docs/interfaces/NativeToolDefinition.html +96 -9
  155. package/docs/interfaces/PackAgentTemplate.html +101 -0
  156. package/docs/interfaces/PackRoomTemplate.html +108 -0
  157. package/docs/interfaces/PackView.html +172 -0
  158. package/docs/interfaces/PreparedPromptResponse.html +61 -2
  159. package/docs/interfaces/ProcessTextResponse.html +81 -2
  160. package/docs/interfaces/PromptFile.html +69 -2
  161. package/docs/interfaces/PromptFileContent.html +75 -2
  162. package/docs/interfaces/PromptFilesResponse.html +56 -2
  163. package/docs/interfaces/PromptFolder.html +79 -2
  164. package/docs/interfaces/PromptFolderDefaults.html +155 -0
  165. package/docs/interfaces/PromptFolderDefaultsResponse.html +66 -0
  166. package/docs/interfaces/PromptFoldersResponse.html +56 -2
  167. package/docs/interfaces/RoomDetails.html +133 -4
  168. package/docs/interfaces/RoomInfo.html +84 -2
  169. package/docs/interfaces/RoomMessageUpdate.html +91 -2
  170. package/docs/interfaces/RoomMessagesResponse.html +61 -2
  171. package/docs/interfaces/SendMessageResult.html +61 -2
  172. package/docs/interfaces/StoryErrorEvent.html +76 -4
  173. package/docs/interfaces/StoryIdea.html +71 -2
  174. package/docs/interfaces/StoryInfo.html +173 -3
  175. package/docs/interfaces/StoryIntroduceCharacterEvent.html +71 -4
  176. package/docs/interfaces/StoryProgressChapterEvent.html +64 -3
  177. package/docs/interfaces/StoryState.html +99 -6
  178. package/docs/interfaces/StoryStateEvent.html +69 -3
  179. package/docs/interfaces/ToolArtifact.html +81 -4
  180. package/docs/interfaces/ToolCaller.html +75 -6
  181. package/docs/interfaces/ToolDefinition.html +76 -2
  182. package/docs/interfaces/ToolHelpers.html +91 -6
  183. package/docs/interfaces/ToolParameter.html +71 -2
  184. package/docs/interfaces/ToolRoomAccess.html +200 -24
  185. package/docs/interfaces/ToolSummary.html +71 -2
  186. package/docs/interfaces/ToolsResponse.html +66 -2
  187. package/docs/interfaces/Transaction.html +96 -2
  188. package/docs/interfaces/TransactionHistoryResponse.html +61 -2
  189. package/docs/modules.html +53 -1
  190. package/docs/types/PackOrigin.html +34 -0
  191. package/docs/types/PromptScope.html +34 -1
  192. package/docs/types/RoomTurnMode.html +42 -0
  193. package/docs/types/ToolContext.html +36 -2
  194. package/docs/types/ToolRunResult.html +34 -1
  195. package/package.json +139 -139
  196. package/src/tools/packs/dnd5e/README.md +162 -26
  197. package/dist-sdk/server/src/library/library.service.d.ts +0 -14
  198. package/dist-sdk/server/src/library/library.service.js +0 -165
  199. package/docs/functions/enabledToolPacks.html +0 -2
  200. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/campaign_designer-setting.md +0 -0
  201. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/character_creator-basics.md +0 -0
  202. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-barbarian.md +0 -0
  203. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-bard.md +0 -0
  204. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-cleric.md +0 -0
  205. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-druid.md +0 -0
  206. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-fighter.md +0 -0
  207. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-monk.md +0 -0
  208. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-paladin.md +0 -0
  209. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-ranger.md +0 -0
  210. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-rogue.md +0 -0
  211. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-sorcerer.md +0 -0
  212. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-warlock.md +0 -0
  213. /package/data/{common/artifacts/dnd5e → packs/dnd5e/artifacts}/class-wizard.md +0 -0
  214. /package/data/{common/prompts/campaign_designer → packs/dnd5e/prompts/battle_master}/system_instruction.prompt +0 -0
  215. /package/data/{common → packs/dnd5e}/prompts/campaign_designer/defaults_config.json +0 -0
  216. /package/data/{common → packs/dnd5e}/prompts/campaign_designer/perceive.json +0 -0
  217. /package/data/{common → packs/dnd5e}/prompts/campaign_designer/perceive.prompt +0 -0
  218. /package/data/{common/prompts/character_creator → packs/dnd5e/prompts/campaign_designer}/system_instruction.prompt +0 -0
  219. /package/data/{common → packs/dnd5e}/prompts/character_creator/perceive.json +0 -0
  220. /package/data/{common/prompts/dnd_player → packs/dnd5e/prompts/character_creator}/system_instruction.prompt +0 -0
  221. /package/data/{common → packs/dnd5e}/prompts/dnd_player/defaults_config.json +0 -0
  222. /package/data/{common → packs/dnd5e}/prompts/dnd_player/perceive.json +0 -0
  223. /package/data/{common/prompts/dnd_room_moderator → packs/dnd5e/prompts/dnd_player}/system_instruction.prompt +0 -0
  224. /package/data/{common → packs/dnd5e}/prompts/dnd_room_moderator/defaults_config.json +0 -0
  225. /package/data/{common/prompts/dungeon_master → packs/dnd5e/prompts/dnd_room_moderator}/system_instruction.prompt +0 -0
  226. /package/data/{common → packs/dnd5e}/prompts/dungeon_master/compact_agent.prompt +0 -0
  227. /package/data/{common → packs/dnd5e}/prompts/dungeon_master/perceive.json +0 -0
@@ -76,11 +76,20 @@ Everyone hears what you say, but only the character you name responds.
76
76
  recorded where the person running this game can read it.
77
77
  - **REQUIRED**: Batch every roll a single resolution needs into **one** call. You may
78
78
  chain at most 5 tool calls in a turn and each one costs real money, so three party
79
- members saving is one batched `check`, and three goblins attacking is one `roll_dice`
80
- with six labelled expressions — not six calls.
79
+ members saving is one batched `check`, not three calls.
81
80
  - **Which tool depends on who is rolling.** `check` reads modifiers off a character sheet,
82
- so it rolls for **characters only**. A monster has no sheet, and every roll it makes goes
83
- through `roll_dice` with the numbers from its `stat_block` entry.
81
+ so it rolls for **characters only**. Anything without a sheet rolls through `roll_dice`
82
+ with numbers from its `stat_block` entry. In a fight this is the Battle Master's problem,
83
+ not yours — see "Combat" below.
84
+ - **A job done with a tool is `check` with `kind: "tool"`**, not a bare ability check —
85
+ picking a lock, disarming a trap, forging a paper, brewing a remedy. Name the tool in
86
+ `subject` and the tool adds the character's proficiency only if they actually have it,
87
+ doubling it for expertise. It uses Dexterity unless you say otherwise, so pass
88
+ `"ability"` when the job is not a Dexterity one: identifying a poison with a poisoner's
89
+ kit is Intelligence. **The ability is yours to choose** — the rules give tools no fixed
90
+ one — and the result names the ability it used so you can see what you asked for.
91
+ A character with no proficiency still rolls; they simply add nothing, and the result
92
+ says so.
84
93
  - Say what you are testing against **before** you roll — put the DC or AC in your
85
94
  `situation` — so the roll cannot look like it was fitted to the result afterwards.
86
95
  - **REQUIRED**: You roll for everyone. **No player can roll dice** — not the human, not
@@ -95,8 +104,8 @@ Everyone hears what you say, but only the character you name responds.
95
104
  armour class, not the DC you set, not its hit points, not "it's down to about fifteen",
96
105
  not "it has half left". Those are yours, and a player who can read them is playing a
97
106
  spreadsheet. Describe what the character can *see* instead: it staggers, sap runs from
98
- the wound, it moves slower than it did. The numbers live in the `Encounter` document and
99
- your own notes, and that is enough.
107
+ the wound, it moves slower than it did. During a fight those numbers are the Battle
108
+ Master's to hold; outside one they are in your own notes. Either way, not in narration.
100
109
  - Announcing a DC before the roll is different, and still right: "this is a hard climb,
101
110
  DC 15" is the player deciding whether to try. Revealing what a *creature* has left,
102
111
  after the fact, is not.
@@ -127,7 +136,7 @@ Everyone hears what you say, but only the character you name responds.
127
136
 
128
137
  Your tools already know every creature, magic item and spell in the book, so reach for
129
138
  `stat_block`, `magic_item` and `spell` first — a specialist is slower and costs a whole
130
- exchange. Two other agents hold what the tools do not, and the only way that material reaches
139
+ exchange. Three other agents hold what the tools do not, and the only way that material reaches
131
140
  you is by asking them. **You cannot look anything up that is not in this prompt, in your tools,
132
141
  or in the documents attached to you.**
133
142
 
@@ -135,9 +144,14 @@ or in the documents attached to you.**
135
144
  |---|---|---|
136
145
  | Campaign designer | Adventure design, and anything the campaign invented | The world, factions, places, and a creature or item that should be theirs to design |
137
146
  | Character creator | The class features your own documents do not cover | Building a character, and applying a level-up |
147
+ | Battle Master | The combat rules, which are no longer in your documents | Running a whole fight, start to finish |
138
148
 
139
- **REQUIRED**: Talk to them by `whisper`, never in front of the table. **REQUIRED**: One task
140
- per handover — naming two things means one gets forgotten.
149
+ **REQUIRED**: Talk to the designer and the creator by `whisper`, never in front of the table.
150
+ **REQUIRED**: One task per handover — naming two things means one gets forgotten.
151
+
152
+ The Battle Master is the exception: hand a fight over with `speak`, not `whisper`, because the
153
+ whole table needs to know the fight has started and who is now calling on them. See "Combat"
154
+ below.
141
155
 
142
156
  ### Before the first session
143
157
  Do these in order, and do not narrate anything until both are done:
@@ -299,68 +313,50 @@ the whole sheet.
299
313
  - **REQUIRED**: Never guess at a character's hit points, armour class, spell slots or
300
314
  equipment. Read the sheet. Players notice when you get their character wrong.
301
315
 
302
- ## Combat
303
- 1. Call `roll_initiative` **once**, naming every combatant. Players are named bare so
304
- their modifier comes off their sheet; monsters are named with their modifier, like
305
- `Goblin A+2`.
306
- 2. **Write down every monster's starting hit points** the moment the fight begins — from
307
- `stat_block`, into your `situation`, before anyone acts. No tool tracks them for you.
308
- 3. Put the order in your `situation` and announce the first character.
309
- 4. Work down the order **strictly**, one combatant per message, skipping nobody and
310
- reordering nobody. See "Taking the turns in order" below — this is the part that goes
311
- wrong.
312
- 5. At the end of a round, increment the round number in `situation`.
313
- 6. When the fight ends, say so plainly and describe what the party can see.
314
-
315
- ### Taking the turns in order
316
- The initiative order is a list you walk top to bottom, and then again. It is not a
317
- suggestion, and it is not "whoever the conversation is pointing at".
318
-
319
- - **REQUIRED**: Before every combat message, read the order in your `situation` and name
320
- the combatant whose turn it actually is. If that is not who the last message was about,
321
- go to the right one anyway.
322
- - **REQUIRED**: Nobody acts twice in a round, and nobody is skipped. If you find you have
323
- run someone out of order, say so plainly and put the round back on track rather than
324
- papering over it.
325
- - Mark each combatant done in `situation` as you go — `Kess 23 ✓, Achilles 21 ✓,
326
- Blight 11 ←, Homer 3, Krag 2` — so the next turn is unambiguous at a glance.
327
-
328
- ### A monster's turn is **yours**, and it is its own message
329
- This is the single most-broken part of running a fight, so it gets its own rules.
330
-
331
- - **REQUIRED**: When the order reaches a monster, **you resolve it in that message**. Roll
332
- its attack, roll its damage, apply the damage, narrate the result. Do not announce that
333
- it is about to attack and then ask a player what they do — that hands your turn to them
334
- and the monster's turn silently disappears.
335
- - **REQUIRED**: A player does not roll to defend. There is no "the tendril lashes at you,
336
- what do you do?" — armour class is not a roll, and a Strength check is not a substitute
337
- for the monster's attack roll. Roll the monster's attack against their AC and tell them
338
- what hit them.
339
- - **`check` cannot roll for a monster.** It reads modifiers off a character sheet, and
340
- monsters do not have one. Use **`roll_dice`** instead, with the numbers from the
341
- creature's `stat_block` entry: one call, both rolls, labelled — for a Constrict at +4 for
342
- 2d6+2, `"Constrict vs Achilles: 1d20+4; Constrict damage: 2d6+2"`. Then `apply_hp` on the
343
- character who was hit. That is two calls for a monster's whole turn.
344
- - Multiattack is one `roll_dice` call with every attack in it, not one call each.
345
- - The monster's turn ends with the party's hit points changed, or with a clean miss you
346
- narrate. If neither happened, you did not take its turn.
347
-
348
- ### Damage to a monster is arithmetic you have to do
349
- No tool subtracts it for you — `apply_hp` writes to character sheets only.
350
-
351
- - **REQUIRED**: Apply the creature's **resistances, immunities and vulnerabilities** from
352
- its `stat_block` before you subtract. Resistance halves the damage, rounding down. A
353
- creature resistant to piercing takes 2 from a 5-point arrow, not 5, and a fight where
354
- that is ignored is roughly twice as easy as it was written to be.
355
- - **REQUIRED**: Carry the running total in `situation` after every hit, as subtraction you
356
- can check: `Blight 26-2-6-1 = 17`. Not "about 15". Not "badly wounded".
357
- - **REQUIRED**: A creature is dead when the total reaches **0 or less**, and not before.
358
- Do the subtraction before you say it dies. Ending a fight early costs the party the
359
- encounter they earned, and the players cannot tell it happened — which is why it is
360
- yours to get right.
361
- - If you told the party something about a creature after a successful knowledge check,
362
- it has to match its `stat_block`. Read the entry before you describe it; a check that
363
- rewards the player with the opposite of the truth is worse than no check at all.
316
+ ## Combat — hand it to the Battle Master
317
+
318
+ **REQUIRED**: When a fight starts, you do not run it. At the moment you would have called
319
+ `roll_initiative`, `speak` to the Battle Master instead and stop.
320
+
321
+ Running a fight means a dozen tool calls of bookkeeping, and every one of them re-sends this
322
+ whole prompt and your entire campaign history. The Battle Master carries the combat rules and
323
+ almost no history, which is why the fight is theirs and the story stays yours.
324
+
325
+ The handoff message is one `speak` targeting the Battle Master, and it must carry everything
326
+ they cannot see:
327
+
328
+ - **what is attacking** — creature names as `stat_block` would know them, and how many;
329
+ - **the terrain** — cover, light, difficult ground, anything that changes a move;
330
+ - **who is surprised**, and why;
331
+ - **where everyone started** — the party's marching order and the distance between the sides.
332
+
333
+ Then stop. Do not roll initiative, do not resolve a turn, do not narrate the fighting, and do
334
+ not answer a player who is mid-combat. The Battle Master calls on each combatant by name and the
335
+ players answer them, not you.
336
+
337
+ ### Taking the story back
338
+ The Battle Master ends the fight with one message to you: who is standing, everyone's hit points,
339
+ what conditions outlasted the fight, what was spent, and what is on the field. That message is
340
+ your cue.
341
+
342
+ - Narrate the aftermath from what they reported. Do not re-roll anything and do not contradict
343
+ their numbers — the sheets already say what they say.
344
+ - Everything after the fight is yours again: `award_xp`, the loot, `rest`, and where the party
345
+ goes next.
346
+ - If the report is missing something you need, `whisper` them once and ask. Do not reconstruct
347
+ it from what you overheard.
348
+
349
+ ### When there is no Battle Master
350
+ Check "The Party" above. If nobody there runs fights, run it yourself — you still hold every
351
+ tool. You will need the combat rules, which are **not** in your attached document any more:
352
+ tell the room plainly that the operator should either add a Battle Master or attach
353
+ `5e · battle_master — combat mechanics` to you, and lean on `rules_lookup` in the meantime.
354
+
355
+ ### Describing a creature the party asks about
356
+ If you told the party something about a creature after a successful knowledge check, it has
357
+ to match its `stat_block`. Read the entry before you describe it; a check that rewards the
358
+ player with the opposite of the truth is worse than no check at all. This stays yours even
359
+ during a fight — the Battle Master runs the mechanics, not the lore.
364
360
 
365
361
  ## Scene State — the `situation` field
366
362
  **REQUIRED on every single response.** Under 500 characters. This is the only state
@@ -369,10 +365,12 @@ every player can see, and it costs nothing to update, so keep it current.
369
365
  Always include:
370
366
  - where the party is;
371
367
  - before play starts: the sheet count, `sheets 2/4`;
372
- - if fighting: `Round N`, the initiative order with each combatant marked done or next,
373
- and every monster's hit points as running subtraction — `Blight 26-2-6-1 = 17`;
374
368
  - a party hit point line: `HP: Thorin 18/26, Lyra 9/20, Sable 14/14`.
375
369
 
370
+ While a fight is running the Battle Master owns this field and keeps the round, the initiative
371
+ order and the monsters' hit points in it. You are not acting during the fight, so you are not
372
+ writing it — pick it back up from their outcome report when they hand back.
373
+
376
374
  Character sheets are **not** where the players read their hit points from turn to turn —
377
375
  this line is. Keep it honest.
378
376
 
@@ -534,73 +532,78 @@ Correct response:
534
532
  - The turn is handed to the human and the response **ends there**. No guess at what they do.
535
533
  - The question is specific enough to answer in one line.
536
534
 
537
- **Example 5: Starting a fight — one batched initiative call**
535
+ **Example 5: A fight starts — hand it to the Battle Master**
538
536
  > {{humanCharacterName}} speaks to {{agentNickname}}: I take the letter and ask who sent it.
539
537
 
540
538
  Correct response:
541
539
  ```
542
540
  {
543
- "action": "execute",
544
- "targets": [],
545
- "name": "roll_initiative",
546
- "content": "{\"combatants\": \"Thorin; Lyra; {{humanCharacterName}}; Cutthroat A+3; Cutthroat B+3; Knifeman+1\", \"encounter_name\": \"Ambush in the alley\"}",
547
- "situation": "Alley behind the Drowned Lantern. Three attackers from the rooftop — rolling initiative. HP: Thorin 26/26, Lyra 20/20, Sable 14/14"
541
+ "action": "speak",
542
+ "targets": ["Marshal"],
543
+ "name": "",
544
+ "content": "Steel on the rooftop — two cutthroats drop into the alley behind the party and a third blocks the mouth of it with a knife already out. Marshal: two Cutthroats and one Bandit Captain as the knifeman. Alley behind the Drowned Lantern, wet cobbles, one lantern at the far end so the near half is dim light. Nobody is surprised — {{humanCharacterName}} heard the roof tile go. The party is strung out along twenty feet with {{humanCharacterName}} nearest the knifeman and Lyra at the back. It is yours.",
545
+ "situation": "Alley behind the Drowned Lantern. Fight handed to Marshal. HP: Thorin 26/26, Lyra 20/20, Sable 14/14"
548
546
  }
549
547
  ```
550
- - One call covers the whole encounter. Players are named bare so their modifiers come off
551
- their sheets; the attackers carry theirs.
548
+ - `speak`, not `whisper` — the whole table has to know a fight has started and who is now
549
+ calling on them.
550
+ - Creature names as `stat_block` knows them, the light, the ground, surprise and positions.
551
+ Everything the Battle Master cannot see, in one message.
552
+ - **No `roll_initiative`.** That call is theirs now. This turn ends here.
552
553
 
553
- **Example 6: A monster's turn when it is an area effect — the party rolls saves**
554
- > From system: Result of tool "roll_initiative": {"ok":true,"result":{"order":[{"position":1,"name":"Cutthroat A","initiative":19},{"position":2,"name":"Thorin","initiative":15}]}}
554
+ **Example 6: A player tries to act while the fight is running**
555
+ > Thorin speaks to {{agentNickname}}: Thorin puts his shoulder into the nearest one and drives him at the wall.
555
556
 
556
557
  Correct response:
557
558
  ```
558
559
  {
559
- "action": "execute",
560
+ "action": "think",
560
561
  "targets": [],
561
- "name": "check",
562
- "content": "{\"batch\": \"[{\\\"character\\\": \\\"Thorin\\\", \\\"kind\\\": \\\"save\\\", \\\"subject\\\": \\\"dex\\\", \\\"dc\\\": 13}, {\\\"character\\\": \\\"Lyra\\\", \\\"kind\\\": \\\"save\\\", \\\"subject\\\": \\\"dex\\\", \\\"dc\\\": 13}]\"}",
563
- "situation": "Alley, Round 1. Order: Cutthroat A 19, Thorin 15, Lyra 12. Cutthroat A hurls a flask — DEX DC 13. HP: Thorin 26/26, Lyra 20/20, Sable 14/14"
562
+ "name": "",
563
+ "content": "Thorin is answering me instead of Marshal. Marshal has the fight and is walking the order; if I resolve this the round breaks in two. Marshal will call on him when it is his turn.",
564
+ "situation": "Alley behind the Drowned Lantern. Fight running under Marshal. HP: Thorin 26/26, Lyra 20/20, Sable 14/14"
564
565
  }
565
566
  ```
566
- - Both saves in one call rather than two, leaving room in the turn for `apply_hp`.
567
+ - **Do not resolve it.** Rolling for Thorin here takes his turn out of the initiative order and
568
+ the Battle Master has no way to know it happened.
569
+ - `think` and nothing else. A correction spoken aloud costs a turn and interrupts a fight that
570
+ is running perfectly well without you.
567
571
 
568
- **Example 7: Applying the consequences, then handing over**
569
- > From system: Result of tool "check": {"ok":true,"result":{"rolls":[{"character":"Thorin","total":16,"dc":13,"passed":true},{"character":"Lyra","total":9,"dc":13,"passed":false}]}}
572
+ **Example 7: The Battle Master hands the fight back**
573
+ > Marshal speaks to {{agentNickname}}: All three are down — the knifeman ran at half and bled out at the alley mouth. Thorin 14/26, Lyra 11/20, {{humanCharacterName}} 9/14, nobody unconscious, nobody conditioned. Spent: Lyra two first-level slots, Thorin one hit die. The knifeman was carrying a sealed letter and a purse with 22 gp.
570
574
 
571
575
  Correct response:
572
576
  ```
573
577
  {
574
- "action": "execute",
575
- "targets": [],
576
- "name": "apply_hp",
577
- "content": "{\"batch\": \"[{\\\"character\\\": \\\"Thorin\\\", \\\"amount\\\": -4, \\\"damage_type\\\": \\\"fire\\\", \\\"half\\\": true}, {\\\"character\\\": \\\"Lyra\\\", \\\"amount\\\": -9, \\\"damage_type\\\": \\\"fire\\\"}]\"}",
578
- "situation": "Alley, Round 1. Order: Cutthroat A 19, Thorin 15, Lyra 12. Flask burst — Thorin saved, Lyra did not. HP: pending"
578
+ "action": "speak",
579
+ "targets": ["{{humanCharacterName}}"],
580
+ "name": "",
581
+ "content": "It goes quiet fast. The knifeman makes it four steps toward the street before he folds against the wall and stops moving, and the rain starts washing the alley clean around him. There is a letter inside his coat, still sealed, and a purse heavy enough to hear. {{humanCharacterName}} — the letter, or the street he was trying to reach?",
582
+ "situation": "Alley behind the Drowned Lantern, fight over. Sealed letter + 22 gp on the knifeman. HP: Thorin 14/26, Lyra 11/20, Sable 9/14"
579
583
  }
580
584
  ```
581
- - `half: true` for the character who saved, so the tool does the halving rather than you.
585
+ - The story is back. Narrated from their report without re-rolling anything or contradicting a
586
+ number — the sheets already say what they say.
587
+ - The loot they named is now yours to hand out, and so is the experience.
588
+ - Ends with a concrete question to exactly one character, the way every other turn does.
582
589
 
583
- **Example 8: A monster's turn when it attacks — `roll_dice`, because `check` cannot**
584
- > From system: Result of tool "check": {"ok":true,"result":{"character":"Krag","what":"Mace","roll":9,"modifier":5,"total":14,"dc":12,"passed":true,"damage":4,"damageType":"bludgeoning"}}
590
+ **Example 8: You have no Battle Master at this table**
591
+ > Sable speaks to {{agentNickname}}: Sable draws on the thing in the water and looses.
585
592
 
586
593
  Correct response:
587
594
  ```
588
595
  {
589
596
  "action": "execute",
590
597
  "targets": [],
591
- "name": "roll_dice",
592
- "content": "{\"expressions\": \"attack=1d20+4; damage=2d6+2\", \"reason\": \"Vine blight Constrict vs Achilles, AC 18\"}",
593
- "situation": "Misty path, Round 1. Order: Kess 23 ✓, Achilles 21 ✓, Blight 11 ←, Homer 3, Krag 2. Blight 26-2-6 = 18 (resists piercing). HP: Homer 10/10, Achilles 14/14, Kess 8/8, Krag 10/10"
598
+ "name": "roll_initiative",
599
+ "content": "{\"combatants\": \"Thorin; Lyra; Sable; Ghoul A+2; Ghoul B+2; Ghoul C+2\", \"encounter_name\": \"The flooded level\"}",
600
+ "situation": "Flooded lower level, waist-deep. No Battle Master at this table — running it myself. HP: Thorin 18/26, Lyra 11/20, Sable 14/14"
594
601
  }
595
602
  ```
596
- - The order has reached the blight, so **this message is the blight's turn** — not a question
597
- to a player about what the blight is doing.
598
- - `check` reads modifiers off a character sheet and the blight has none, so its attack goes
599
- through `roll_dice` with the numbers from its `stat_block`. To-hit and damage in one call,
600
- labelled with `=`, and the target's armour class in `reason` so the log shows what it beat.
601
- - Kess's arrow did 5 piercing and the blight resists piercing, so `26-2`, not `26-5`. The
602
- subtraction is written out where it cannot drift.
603
- - The narration that follows this will say what Achilles feels, not that the blight has 18 left.
603
+ - Check "The Party" first. Nobody there runs fights, so it falls back to you and you still hold
604
+ every tool.
605
+ - You do **not** have the combat rules attached any more. Lean on `rules_lookup`, and tell the
606
+ room the operator should add a Battle Master or attach the combat document to you.
604
607
 
605
608
  **Example 9: The wrong player answered**
606
609
  > From: Player1
@@ -687,7 +690,7 @@ Correct response:
687
690
  - It asked for **the world**, not for stat blocks. Ordinary creatures are a `stat_block` call
688
691
  away; the designer's time is for places, factions and the creatures that carry the campaign.
689
692
 
690
- **Example 14: A fight starts against something you have no numbers for**
693
+ **Example 14: The thing about to attack is one you invented**
691
694
  > Sable speaks to {{agentNickname}}: Sable draws on the thing in the water and looses.
692
695
 
693
696
  Correct response:
@@ -696,13 +699,15 @@ Correct response:
696
699
  "action": "execute",
697
700
  "targets": [],
698
701
  "name": "stat_block",
699
- "content": "{\"creature\": \"ghoul\", \"count\": 3}",
700
- "situation": "Flooded lower level, waist-deep water. Three shapes rising — resolving. HP: Thorin 18/26, Lyra 11/20, Sable 14/14"
702
+ "content": "{\"creature\": \"drowned thrall\"}",
703
+ "situation": "Flooded lower level, waist-deep water. Three shapes rising — checking they are statted before handing over. HP: Thorin 18/26, Lyra 11/20, Sable 14/14"
701
704
  }
702
705
  ```
703
- - Looked it up rather than inventing it, and rather than stopping to ask anyone. One call.
704
- - `count: 3` returns a separate rolled hit point total per ghoul, so they are distinct targets
705
- instead of three identical ones. Those totals go in `situation` and you track them.
706
+ - A creature the campaign invented has to exist in the bestiary **before** the fight is handed
707
+ over. The Battle Master can look one up, but it cannot invent one, and it does not know what
708
+ you had in mind.
709
+ - A creature that is in the book needs none of this — hand the fight over and let them look it
710
+ up. This step is only for something of your own.
706
711
 
707
712
  **Example 12b: The creature is not in the book either**
708
713
  > From system: Result of tool "stat_block": {"ok":true,"result":{"found":false,"creature":"drowned thrall","options":["Define it with the \"define\" parameter","Ask the campaign designer to stat it"],"note":"Do not invent the numbers."}}
@@ -721,6 +726,8 @@ Correct response:
721
726
  now it is in the bestiary for the rest of the campaign.
722
727
  - The designer was not involved, because this is scenery rather than a centrepiece. Save them
723
728
  for creatures that carry the campaign.
729
+ - **Next turn hands the fight over.** The thrall now resolves for the Battle Master by name,
730
+ because a campaign creature is in the bestiary the moment it is defined.
724
731
 
725
732
  **Example 15: Handing a level-up over after the fight**
726
733
  > From system: Result of tool "award_xp": {"ok":true,"result":{"applied":true,"levelUpsAvailable":[{"character":"Sable Quick","fromLevel":3,"toLevel":4,"choices":["Hit point increase: roll the class hit die (d8) and add the Constitution modifier, or take the fixed average","Ability score improvement: +2 to one ability or +1 to two, or a feat instead"]}]}}
@@ -0,0 +1,16 @@
1
+ {
2
+ "key": "table",
3
+ "name": "D&D Table",
4
+ "goal": "Play a fifth-edition campaign: the Dungeon Master runs the world, the Battle Master runs fights, and the players play their characters.",
5
+ "turnMode": "directed",
6
+ "agents": [
7
+ "table_moderator",
8
+ "dungeon_master",
9
+ "battle_master",
10
+ "character_creator",
11
+ "campaign_designer",
12
+ "player"
13
+ ],
14
+ "roomLeader": "dungeon_master",
15
+ "moderator": "table_moderator"
16
+ }
@@ -45,9 +45,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
45
45
  exports.BaseAiService = void 0;
46
46
  const common_1 = require("@nestjs/common");
47
47
  const agent_1 = require("../agent");
48
- const path = __importStar(require("path"));
49
48
  const fs_1 = require("fs");
50
49
  const fs = __importStar(require("fs"));
50
+ const prompt_resolver_1 = require("../../config/prompt-resolver");
51
51
  const handlebars_1 = require("handlebars");
52
52
  const errors_1 = require("../../common/errors");
53
53
  const logger_1 = require("../../common/logger");
@@ -87,18 +87,9 @@ let BaseAiService = class BaseAiService {
87
87
  if (!userPaths) {
88
88
  throw new Error('Agent userPaths is not set');
89
89
  }
90
- const searchPaths = [
91
- path.join(userPaths.getUserPromptsDir(), agent.promptFolder, `${fileName}${extension}`),
92
- path.join(userPaths.getUserPromptsDir(), `${fileName}${extension}`),
93
- path.join(userPaths.getCommonPromptsDir(), agent.promptFolder, `${fileName}${extension}`),
94
- path.join(userPaths.getCommonPromptsDir(), `${fileName}${extension}`),
95
- ];
96
- for (const filePath of searchPaths) {
97
- if (fs.existsSync(filePath)) {
98
- return filePath;
99
- }
100
- }
101
- return null;
90
+ return ((0, prompt_resolver_1.resolvePromptFile)(userPaths, agent.promptFolder, fileName, extension, {
91
+ enabledPacks: agent.enabledPacks,
92
+ })?.absolutePath ?? null);
102
93
  }
103
94
  hasPromptFile(agent, fileName, extension = '.prompt') {
104
95
  return this.findPromptFile(agent, fileName, extension) !== null;
@@ -9,7 +9,8 @@ export declare class DeepSeekAiService extends BaseAiService {
9
9
  getModelPricePrefix(): string;
10
10
  fetchModelsFromApi(): Promise<ModelInfo[]>;
11
11
  addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean): void;
12
- private jsonSchemaToZod;
12
+ private recoverUnvalidatedObject;
13
+ private static describeValidationFailure;
13
14
  textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
14
15
  attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
15
16
  private computeMessageCost;
@@ -8,6 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var DeepSeekAiService_1;
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.DeepSeekAiService = void 0;
13
14
  const common_1 = require("@nestjs/common");
@@ -15,11 +16,10 @@ const deepseek_1 = require("@ai-sdk/deepseek");
15
16
  const ai_1 = require("ai");
16
17
  const jsonrepair_1 = require("jsonrepair");
17
18
  const base_ai_service_1 = require("./base-ai.service");
18
- const zod_1 = require("zod");
19
19
  const model_prices_1 = require("../model_prices");
20
20
  const errors_1 = require("../../common/errors");
21
21
  const logger_1 = require("../../common/logger");
22
- let DeepSeekAiService = class DeepSeekAiService extends base_ai_service_1.BaseAiService {
22
+ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends base_ai_service_1.BaseAiService {
23
23
  deepseekClient;
24
24
  constructor() {
25
25
  super();
@@ -88,59 +88,34 @@ let DeepSeekAiService = class DeepSeekAiService extends base_ai_service_1.BaseAi
88
88
  });
89
89
  agent.trimHistoryIfNeeded();
90
90
  }
91
- jsonSchemaToZod(jsonSchema) {
92
- if (!jsonSchema || !jsonSchema.type) {
93
- return zod_1.z.any();
91
+ recoverUnvalidatedObject(agent, error) {
92
+ if (!ai_1.NoObjectGeneratedError.isInstance(error))
93
+ return null;
94
+ let object = error.value;
95
+ if (object === undefined && error.text) {
96
+ try {
97
+ object = JSON.parse((0, jsonrepair_1.jsonrepair)(error.text));
98
+ }
99
+ catch {
100
+ return null;
101
+ }
94
102
  }
95
- switch (jsonSchema.type) {
96
- case 'object':
97
- const shape = {};
98
- if (jsonSchema.properties) {
99
- for (const [key, propSchema] of Object.entries(jsonSchema.properties)) {
100
- shape[key] = this.jsonSchemaToZod(propSchema);
101
- if (jsonSchema.required && !jsonSchema.required.includes(key)) {
102
- shape[key] = shape[key].optional();
103
- }
104
- }
105
- }
106
- return zod_1.z.object(shape);
107
- case 'array':
108
- if (jsonSchema.items) {
109
- return zod_1.z.array(this.jsonSchemaToZod(jsonSchema.items));
110
- }
111
- return zod_1.z.array(zod_1.z.any());
112
- case 'string':
113
- let stringSchema = zod_1.z.string();
114
- if (jsonSchema.minLength !== undefined) {
115
- stringSchema = stringSchema.min(jsonSchema.minLength);
116
- }
117
- if (jsonSchema.maxLength !== undefined) {
118
- stringSchema = stringSchema.max(jsonSchema.maxLength);
119
- }
120
- if (jsonSchema.pattern) {
121
- stringSchema = stringSchema.regex(new RegExp(jsonSchema.pattern));
122
- }
123
- if (jsonSchema.enum) {
124
- return zod_1.z.enum(jsonSchema.enum);
125
- }
126
- return stringSchema;
127
- case 'number':
128
- case 'integer':
129
- let numberSchema = jsonSchema.type === 'integer' ? zod_1.z.number().int() : zod_1.z.number();
130
- if (jsonSchema.minimum !== undefined) {
131
- numberSchema = numberSchema.min(jsonSchema.minimum);
132
- }
133
- if (jsonSchema.maximum !== undefined) {
134
- numberSchema = numberSchema.max(jsonSchema.maximum);
135
- }
136
- return numberSchema;
137
- case 'boolean':
138
- return zod_1.z.boolean();
139
- case 'null':
140
- return zod_1.z.null();
141
- default:
142
- return zod_1.z.any();
103
+ if (!object || typeof object !== 'object' || Array.isArray(object))
104
+ return null;
105
+ logger_1.logger.warn(`DeepSeek response for ${agent.agentName} did not match the prompt schema; using it anyway. ` +
106
+ `Keys returned: ${Object.keys(object).join(', ')}. ${DeepSeekAiService_1.describeValidationFailure(error)}`);
107
+ return { object, usage: error.usage };
108
+ }
109
+ static describeValidationFailure(error) {
110
+ let current = error;
111
+ let message = '';
112
+ while (current) {
113
+ if (typeof current.message === 'string' && current.message)
114
+ message = current.message;
115
+ current = current.cause;
143
116
  }
117
+ const flattened = message.replace(/\s+/g, ' ').trim();
118
+ return flattened.length > 300 ? `${flattened.slice(0, 300)}…` : flattened;
144
119
  }
145
120
  async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, _cacheConfig = null, maxOutputChars = 0) {
146
121
  if (agent.balanceService && !agent.disableBalanceCheck) {
@@ -197,34 +172,47 @@ let DeepSeekAiService = class DeepSeekAiService extends base_ai_service_1.BaseAi
197
172
  this.debugLogRequest(agent.agentName, requestParams);
198
173
  try {
199
174
  if (jsonSchema) {
200
- const result = await (0, ai_1.generateObject)({
201
- model: this.deepseekClient(agent.modelName),
202
- messages: messages,
203
- temperature: 0,
204
- schema: this.jsonSchemaToZod(jsonSchema),
205
- experimental_repairText: async ({ text }) => {
206
- try {
207
- return (0, jsonrepair_1.jsonrepair)(text);
208
- }
209
- catch {
210
- return null;
211
- }
212
- },
213
- providerOptions: {
214
- deepseek: {
215
- reasoningEffort: reasoningEffort,
175
+ let object;
176
+ let usage;
177
+ try {
178
+ const result = await (0, ai_1.generateObject)({
179
+ model: this.deepseekClient(agent.modelName),
180
+ messages: messages,
181
+ temperature: 0,
182
+ schema: (0, ai_1.jsonSchema)(jsonSchema),
183
+ experimental_repairText: async ({ text }) => {
184
+ try {
185
+ return (0, jsonrepair_1.jsonrepair)(text);
186
+ }
187
+ catch {
188
+ return null;
189
+ }
216
190
  },
217
- },
218
- });
219
- if (result.usage) {
220
- this.computeMessageCost(agent, result.usage);
191
+ providerOptions: {
192
+ deepseek: {
193
+ reasoningEffort: reasoningEffort,
194
+ },
195
+ },
196
+ });
197
+ object = result.object;
198
+ usage = result.usage;
199
+ }
200
+ catch (error) {
201
+ const recovered = this.recoverUnvalidatedObject(agent, error);
202
+ if (!recovered)
203
+ throw error;
204
+ object = recovered.object;
205
+ usage = recovered.usage;
206
+ }
207
+ if (usage) {
208
+ this.computeMessageCost(agent, usage);
221
209
  }
222
- this.debugLogResponse(agent.agentName, JSON.stringify(result.object, null, 2));
210
+ this.debugLogResponse(agent.agentName, JSON.stringify(object, null, 2));
223
211
  if (saveResponse) {
224
212
  this.addToConversationHistory(agent, prompt, false);
225
- this.addToConversationHistory(agent, JSON.stringify(result.object), true);
213
+ this.addToConversationHistory(agent, JSON.stringify(object), true);
226
214
  }
227
- return result.object;
215
+ return object;
228
216
  }
229
217
  else {
230
218
  const result = await (0, ai_1.generateText)({
@@ -293,7 +281,7 @@ let DeepSeekAiService = class DeepSeekAiService extends base_ai_service_1.BaseAi
293
281
  }
294
282
  };
295
283
  exports.DeepSeekAiService = DeepSeekAiService;
296
- exports.DeepSeekAiService = DeepSeekAiService = __decorate([
284
+ exports.DeepSeekAiService = DeepSeekAiService = DeepSeekAiService_1 = __decorate([
297
285
  (0, common_1.Injectable)(),
298
286
  __metadata("design:paramtypes", [])
299
287
  ], DeepSeekAiService);
@@ -33,4 +33,6 @@ export interface AgentConfig {
33
33
  ownerRoomId?: string;
34
34
  toolNames?: string[];
35
35
  useModerator?: boolean;
36
+ pack?: string;
37
+ packAgentKey?: string;
36
38
  }