briyah 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +216 -0
- package/README.md +19 -10
- package/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +46369 -46361
- package/data/common/config/rpg_models.json +60 -0
- package/data/common/prompts/narrator/create_chapter.prompt +12 -1
- package/data/common/prompts/pdf_converter/convert_pdf_page.prompt +8 -1
- package/data/common/prompts/perceive.prompt +287 -291
- package/data/packs/dnd5e/agents/player.json +11 -11
- package/data/packs/dnd5e/artifacts/background-acolyte.md +66 -0
- package/data/packs/dnd5e/artifacts/character_creator-basics.md +31 -13
- package/data/packs/dnd5e/artifacts/class-barbarian.md +4 -1
- package/data/packs/dnd5e/artifacts/class-bard.md +2 -1
- package/data/packs/dnd5e/artifacts/class-cleric.md +2 -1
- package/data/packs/dnd5e/artifacts/class-druid.md +3 -1
- package/data/packs/dnd5e/artifacts/class-fighter.md +3 -1
- package/data/packs/dnd5e/artifacts/class-monk.md +2 -1
- package/data/packs/dnd5e/artifacts/class-paladin.md +2 -1
- package/data/packs/dnd5e/artifacts/class-ranger.md +3 -1
- package/data/packs/dnd5e/artifacts/class-rogue.md +3 -1
- package/data/packs/dnd5e/artifacts/class-sorcerer.md +2 -1
- package/data/packs/dnd5e/artifacts/class-warlock.md +3 -1
- package/data/packs/dnd5e/artifacts/class-wizard.md +2 -1
- package/data/packs/dnd5e/artifacts/manifest.json +6 -0
- package/data/packs/dnd5e/pack.json +1 -1
- package/data/packs/dnd5e/prompts/battle_master/perceive.prompt +491 -378
- package/data/packs/dnd5e/prompts/campaign_designer/perceive.prompt +24 -7
- package/data/packs/dnd5e/prompts/character_creator/defaults_config.json +21 -31
- package/data/packs/dnd5e/prompts/character_creator/perceive.prompt +236 -99
- package/data/packs/dnd5e/prompts/dnd_player/defaults_config.json +5 -5
- package/data/packs/dnd5e/prompts/dnd_player/perceive.prompt +28 -10
- package/data/packs/dnd5e/prompts/dnd_room_moderator/defaults_config.json +9 -9
- package/data/packs/dnd5e/prompts/dnd_room_moderator/moderate.prompt +13 -10
- package/data/packs/dnd5e/prompts/dungeon_master/defaults_config.json +32 -30
- package/data/packs/dnd5e/prompts/dungeon_master/perceive.prompt +794 -764
- package/data/packs/dnd5e/rooms/campaign.json +15 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +3 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +40 -11
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +1 -0
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +16 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +5 -3
- package/dist-sdk/server/src/ai/agent-store.service.js +1 -1
- package/dist-sdk/server/src/ai/artifact.service.d.ts +2 -0
- package/dist-sdk/server/src/ai/artifact.service.js +6 -0
- package/dist-sdk/server/src/ai/pack-artifacts.d.ts +2 -0
- package/dist-sdk/server/src/ai/pack-artifacts.js +65 -8
- package/dist-sdk/server/src/app/user-service-factory.js +6 -1
- package/dist-sdk/server/src/app/user-service-manager.js +1 -1
- package/dist-sdk/server/src/app.controller.d.ts +9 -1
- package/dist-sdk/server/src/app.controller.js +123 -12
- package/dist-sdk/server/src/app.service.d.ts +24 -2
- package/dist-sdk/server/src/app.service.js +123 -109
- package/dist-sdk/server/src/auth/auth.controller.js +4 -0
- package/dist-sdk/server/src/auth/auth.service.d.ts +2 -1
- package/dist-sdk/server/src/auth/dto/phone-login.dto.d.ts +2 -1
- package/dist-sdk/server/src/documents/pdf-conversion.d.ts +43 -0
- package/dist-sdk/server/src/documents/pdf-conversion.js +175 -0
- package/dist-sdk/server/src/room/nickname.d.ts +1 -0
- package/dist-sdk/server/src/room/nickname.js +15 -0
- package/dist-sdk/server/src/room/room-store.service.d.ts +1 -0
- package/dist-sdk/server/src/room/room-store.service.js +9 -1
- package/dist-sdk/server/src/room/room.d.ts +43 -3
- package/dist-sdk/server/src/room/room.js +317 -35
- package/dist-sdk/server/src/rpg/rpg-models.d.ts +9 -0
- package/dist-sdk/server/src/rpg/rpg-models.js +128 -0
- package/dist-sdk/server/src/rpg/rpg-roster.d.ts +8 -0
- package/dist-sdk/server/src/rpg/rpg-roster.js +34 -0
- package/dist-sdk/server/src/rpg/rpg.service.d.ts +29 -0
- package/dist-sdk/server/src/rpg/rpg.service.js +199 -0
- package/dist-sdk/server/src/sdk/index.d.ts +4 -2
- package/dist-sdk/server/src/sdk/index.js +6 -1
- package/dist-sdk/server/src/story/story.service.d.ts +2 -1
- package/dist-sdk/server/src/story/story.service.js +42 -4
- package/dist-sdk/server/src/tools/core/index.d.ts +3 -0
- package/dist-sdk/server/src/tools/core/index.js +9 -0
- package/dist-sdk/server/src/tools/core/rename.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/core/rename.tool.js +61 -0
- package/dist-sdk/server/src/tools/native-tool.types.d.ts +15 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.d.ts +0 -21
- package/dist-sdk/server/src/tools/packs/dnd5e/data/backgrounds.js +1 -56
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.d.ts +10 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/cantrips.js +67 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.d.ts +5 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/data/gear.js +7 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/bestiary.js +4 -3
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.d.ts +6 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/cantrips.js +92 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.d.ts +32 -5
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/character.js +177 -28
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.d.ts +1 -13
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/coerce.js +15 -145
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.d.ts +7 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/dice.js +11 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.d.ts +5 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/encounter.js +45 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/foes.js +3 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.d.ts +21 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/guides.js +45 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/races.js +6 -4
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.d.ts +17 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/sheet.js +56 -4
- package/dist-sdk/server/src/tools/packs/dnd5e/index.js +3 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/check.tool.js +117 -15
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/class.tool.js +96 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/dice.tools.js +40 -3
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/encounter.tool.js +36 -27
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/monster.tool.js +7 -4
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.d.ts +15 -1
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/shared.js +73 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/sheet.tools.js +49 -13
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/state.tools.js +68 -2
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.d.ts +1 -0
- package/dist-sdk/server/src/tools/packs/dnd5e/tools/world.tools.js +119 -14
- package/dist-sdk/server/src/tools/packs/index.d.ts +2 -0
- package/dist-sdk/server/src/tools/packs/index.js +16 -5
- package/dist-sdk/server/src/tools/shared/coerce.d.ts +13 -0
- package/dist-sdk/server/src/tools/shared/coerce.js +147 -0
- package/dist-sdk/server/src/tools/tool-execution.service.d.ts +3 -2
- package/dist-sdk/server/src/tools/tool-execution.service.js +4 -1
- package/dist-sdk/shared/types/app.types.d.ts +63 -0
- package/dist-sdk/shared/types/app.types.js +2 -1
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Agent.html +73 -73
- package/docs/classes/Briyah.html +16 -16
- package/docs/classes/BriyahConfigService.html +7 -7
- package/docs/classes/NativeToolRegistry.html +10 -10
- package/docs/classes/PackInstantiationService.html +7 -7
- package/docs/classes/PackService.html +13 -13
- package/docs/classes/Room.html +216 -95
- package/docs/classes/RoomMessage.html +22 -22
- package/docs/enums/MessageAction.html +18 -18
- package/docs/functions/availableToolPacks.html +5 -5
- package/docs/functions/buildMarkdown.html +54 -0
- package/docs/functions/dnd5eTools.html +4 -4
- package/docs/functions/installToolPacks.html +8 -5
- package/docs/functions/pageMarker.html +45 -0
- package/docs/functions/registerToolPacks.html +4 -4
- package/docs/functions/splitMarkdownIntoPages.html +51 -0
- package/docs/functions/stripWrappingFence.html +52 -0
- package/docs/hierarchy.html +13 -9
- package/docs/index.html +11 -8
- package/docs/interfaces/AgentCreationOptions.html +12 -12
- package/docs/interfaces/AgentInfo.html +30 -30
- package/docs/interfaces/AgentMessagesResponse.html +8 -8
- package/docs/interfaces/AppService.html +276 -198
- package/docs/interfaces/Artifact.html +9 -9
- package/docs/interfaces/ArtifactMetadata.html +13 -13
- package/docs/interfaces/ArtifactWriteOptions.html +7 -7
- package/docs/interfaces/AttachDocumentResponse.html +6 -6
- package/docs/interfaces/BriyahConfigOptions.html +12 -12
- package/docs/interfaces/ChapterInfo.html +6 -6
- package/docs/interfaces/Character.html +10 -10
- package/docs/interfaces/ConversionAgent.html +78 -0
- package/docs/interfaces/CreateAgentResponse.html +5 -5
- package/docs/interfaces/CreateRoomResponse.html +6 -6
- package/docs/interfaces/CreateStoryResponse.html +5 -5
- package/docs/interfaces/FileList.html +5 -5
- package/docs/interfaces/FileMetadata.html +10 -10
- package/docs/interfaces/IConfigService.html +5 -5
- package/docs/interfaces/InstantiateModels.html +6 -6
- package/docs/interfaces/InstantiateRoomResult.html +7 -7
- package/docs/interfaces/LoadedPack.html +16 -16
- package/docs/interfaces/LoggingOptions.html +9 -9
- package/docs/interfaces/Message.html +9 -9
- package/docs/interfaces/ModelChoice.html +7 -7
- package/docs/interfaces/ModelInfo.html +8 -8
- package/docs/interfaces/NativeToolDefinition.html +10 -10
- package/docs/interfaces/PackAgentTemplate.html +9 -9
- package/docs/interfaces/PackRoomTemplate.html +11 -11
- package/docs/interfaces/PackView.html +20 -20
- package/docs/interfaces/PdfConversionOptions.html +102 -0
- package/docs/interfaces/PdfConversionResult.html +97 -0
- package/docs/interfaces/PdfMarkdownOptions.html +198 -0
- package/docs/interfaces/PdfMarkdownResult.html +106 -0
- package/docs/interfaces/PdfPageMarkdown.html +94 -0
- package/docs/interfaces/PreparedPromptResponse.html +6 -6
- package/docs/interfaces/ProcessTextResponse.html +10 -10
- package/docs/interfaces/PromptFile.html +7 -7
- package/docs/interfaces/PromptFileContent.html +8 -8
- package/docs/interfaces/PromptFilesResponse.html +5 -5
- package/docs/interfaces/PromptFolder.html +8 -8
- package/docs/interfaces/PromptFolderDefaults.html +19 -19
- package/docs/interfaces/PromptFolderDefaultsResponse.html +7 -7
- package/docs/interfaces/PromptFoldersResponse.html +5 -5
- package/docs/interfaces/RoomDetails.html +19 -19
- package/docs/interfaces/RoomErrorUpdate.html +8 -8
- package/docs/interfaces/RoomInfo.html +10 -10
- package/docs/interfaces/RoomMessageUpdate.html +13 -13
- package/docs/interfaces/RoomMessagesResponse.html +6 -6
- package/docs/interfaces/SendMessageResult.html +6 -6
- package/docs/interfaces/StoryErrorEvent.html +8 -8
- package/docs/interfaces/StoryIdea.html +8 -8
- package/docs/interfaces/StoryInfo.html +28 -28
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +7 -7
- package/docs/interfaces/StoryProgressChapterEvent.html +6 -6
- package/docs/interfaces/StoryState.html +12 -12
- package/docs/interfaces/StoryStateEvent.html +7 -7
- package/docs/interfaces/ToolArtifact.html +9 -9
- package/docs/interfaces/ToolCaller.html +7 -7
- package/docs/interfaces/ToolDefinition.html +9 -9
- package/docs/interfaces/ToolHelpers.html +17 -8
- package/docs/interfaces/ToolPackDocuments.html +100 -0
- package/docs/interfaces/ToolParameter.html +8 -8
- package/docs/interfaces/ToolRoomAccess.html +49 -16
- package/docs/interfaces/ToolSummary.html +8 -8
- package/docs/interfaces/ToolsResponse.html +7 -7
- package/docs/interfaces/Transaction.html +13 -13
- package/docs/interfaces/TransactionHistoryResponse.html +6 -6
- package/docs/modules.html +8 -8
- package/docs/types/PackOrigin.html +4 -4
- package/docs/types/PromptScope.html +4 -4
- package/docs/types/RoomTurnMode.html +4 -4
- package/docs/types/RoomUpdate.html +4 -4
- package/docs/types/RosterOverrides.html +4 -4
- package/docs/types/ToolContext.html +4 -4
- package/docs/types/ToolRunResult.html +4 -4
- package/package.json +32 -3
- package/src/tools/packs/dnd5e/README.md +147 -66
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.d.ts +0 -20
- package/dist-sdk/server/src/tools/packs/dnd5e/engine/backgrounds.js +0 -112
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"key": "campaign",
|
|
3
|
+
"name": "Campaign",
|
|
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
|
+
],
|
|
13
|
+
"roomLeader": "dungeon_master",
|
|
14
|
+
"moderator": "table_moderator"
|
|
15
|
+
}
|
|
@@ -26,5 +26,8 @@ export declare class AnthropicAiService extends BaseAiService {
|
|
|
26
26
|
private static trimHeadroom;
|
|
27
27
|
textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, cacheConfig?: any, maxOutputChars?: number): Promise<any>;
|
|
28
28
|
private appendRetryExchange;
|
|
29
|
+
private static webSearchTool;
|
|
30
|
+
private static readonly MAX_PAUSE_RESUMES;
|
|
31
|
+
private resumePausedTurn;
|
|
29
32
|
private computeMessageCost;
|
|
30
33
|
}
|
|
@@ -18,7 +18,8 @@ const model_prices_1 = require("../model_prices");
|
|
|
18
18
|
const errors_1 = require("../../common/errors");
|
|
19
19
|
const logger_1 = require("../../common/logger");
|
|
20
20
|
const ai_debug_logger_1 = require("../ai-debug-logger");
|
|
21
|
-
let AnthropicAiService =
|
|
21
|
+
let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.BaseAiService {
|
|
22
|
+
static { AnthropicAiService_1 = this; }
|
|
22
23
|
anthropic;
|
|
23
24
|
constructor() {
|
|
24
25
|
super();
|
|
@@ -189,13 +190,10 @@ let AnthropicAiService = AnthropicAiService_1 = class AnthropicAiService extends
|
|
|
189
190
|
content: [{ type: 'text', text: promptText }],
|
|
190
191
|
});
|
|
191
192
|
}
|
|
193
|
+
const modelInfo = (0, model_prices_1.getModelPrices)()[agent.modelName];
|
|
192
194
|
const tools = [];
|
|
193
195
|
if (agent.allowSearch) {
|
|
194
|
-
tools.push(
|
|
195
|
-
type: 'web_search_20250305',
|
|
196
|
-
name: 'web_search',
|
|
197
|
-
max_uses: 5,
|
|
198
|
-
});
|
|
196
|
+
tools.push(AnthropicAiService_1.webSearchTool(modelInfo));
|
|
199
197
|
}
|
|
200
198
|
const maxRetries = 3;
|
|
201
199
|
let lastError = null;
|
|
@@ -206,7 +204,6 @@ let AnthropicAiService = AnthropicAiService_1 = class AnthropicAiService extends
|
|
|
206
204
|
thinkingTokens = 2048;
|
|
207
205
|
else if (agent.reasoningEffort === 'high')
|
|
208
206
|
thinkingTokens = 4096;
|
|
209
|
-
const modelInfo = (0, model_prices_1.getModelPrices)()[agent.modelName];
|
|
210
207
|
if (modelInfo && !modelInfo.supports_reasoning)
|
|
211
208
|
thinkingTokens = 0;
|
|
212
209
|
let maxOutputTokens;
|
|
@@ -241,7 +238,11 @@ let AnthropicAiService = AnthropicAiService_1 = class AnthropicAiService extends
|
|
|
241
238
|
this.debugLogRequest(agent.agentName, createParams);
|
|
242
239
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
243
240
|
try {
|
|
244
|
-
|
|
241
|
+
let response = await this.anthropic.messages.create(createParams);
|
|
242
|
+
if (response.usage) {
|
|
243
|
+
this.computeMessageCost(agent, response.usage);
|
|
244
|
+
}
|
|
245
|
+
response = await this.resumePausedTurn(agent, createParams, response);
|
|
245
246
|
let thinkingText = '';
|
|
246
247
|
let responseText = '';
|
|
247
248
|
if (response.content && response.content.length > 0) {
|
|
@@ -257,12 +258,14 @@ let AnthropicAiService = AnthropicAiService_1 = class AnthropicAiService extends
|
|
|
257
258
|
}
|
|
258
259
|
this.debugLogThinking(agent.agentName, thinkingText);
|
|
259
260
|
this.debugLogResponse(agent.agentName, responseText);
|
|
261
|
+
if (!responseText.trim()) {
|
|
262
|
+
logger_1.logger.warn(`Empty text from ${agent.agentName}: stop_reason=${response.stop_reason}, blocks=[${(response.content || [])
|
|
263
|
+
.map((block) => block.type)
|
|
264
|
+
.join(', ')}]`);
|
|
265
|
+
}
|
|
260
266
|
if (jsonSchema) {
|
|
261
267
|
responseText = this.trimToJson(responseText);
|
|
262
268
|
}
|
|
263
|
-
if (response.usage) {
|
|
264
|
-
this.computeMessageCost(agent, response.usage);
|
|
265
|
-
}
|
|
266
269
|
let parsedResponse;
|
|
267
270
|
if (jsonSchema) {
|
|
268
271
|
try {
|
|
@@ -333,6 +336,32 @@ let AnthropicAiService = AnthropicAiService_1 = class AnthropicAiService extends
|
|
|
333
336
|
content: [{ type: 'text', text: retryMessage }],
|
|
334
337
|
});
|
|
335
338
|
}
|
|
339
|
+
static webSearchTool(modelInfo) {
|
|
340
|
+
return {
|
|
341
|
+
type: modelInfo?.supports_web_search_filtering
|
|
342
|
+
? 'web_search_20260209'
|
|
343
|
+
: 'web_search_20250305',
|
|
344
|
+
name: 'web_search',
|
|
345
|
+
max_uses: 5,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
static MAX_PAUSE_RESUMES = 5;
|
|
349
|
+
async resumePausedTurn(agent, createParams, first) {
|
|
350
|
+
let response = first;
|
|
351
|
+
for (let resume = 1; response?.stop_reason === 'pause_turn'; resume++) {
|
|
352
|
+
if (resume > AnthropicAiService_1.MAX_PAUSE_RESUMES) {
|
|
353
|
+
logger_1.logger.warn(`${agent.agentName} still paused after ${AnthropicAiService_1.MAX_PAUSE_RESUMES} resumes; using what it has produced so far`);
|
|
354
|
+
return response;
|
|
355
|
+
}
|
|
356
|
+
logger_1.logger.log(`Resuming ${agent.agentName}'s paused turn (${resume}/${AnthropicAiService_1.MAX_PAUSE_RESUMES})`);
|
|
357
|
+
createParams.messages.push({ role: 'assistant', content: response.content });
|
|
358
|
+
response = await this.anthropic.messages.create(createParams);
|
|
359
|
+
if (response.usage) {
|
|
360
|
+
this.computeMessageCost(agent, response.usage);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
return response;
|
|
364
|
+
}
|
|
336
365
|
computeMessageCost(agent, usage) {
|
|
337
366
|
const modelInfo = (0, model_prices_1.getModelPrices)()[agent.modelName];
|
|
338
367
|
if (!modelInfo) {
|
|
@@ -44,6 +44,7 @@ export declare class BaseAiService {
|
|
|
44
44
|
protected debugLogRequest(agentName: string, content: unknown): void;
|
|
45
45
|
protected debugLogThinking(agentName: string, thinking: string): void;
|
|
46
46
|
protected debugLogResponse(agentName: string, response: string): void;
|
|
47
|
+
protected static describeProviderError(error: unknown): string;
|
|
47
48
|
trimResponseText(str: string): string;
|
|
48
49
|
trimToJson(str: string): string;
|
|
49
50
|
parseStructuredResponse(text: string): any;
|
|
@@ -49,6 +49,7 @@ const fs_1 = require("fs");
|
|
|
49
49
|
const fs = __importStar(require("fs"));
|
|
50
50
|
const prompt_resolver_1 = require("../../config/prompt-resolver");
|
|
51
51
|
const handlebars_1 = require("handlebars");
|
|
52
|
+
const ai_1 = require("ai");
|
|
52
53
|
const errors_1 = require("../../common/errors");
|
|
53
54
|
const logger_1 = require("../../common/logger");
|
|
54
55
|
const jsonrepair_1 = require("jsonrepair");
|
|
@@ -321,6 +322,21 @@ let BaseAiService = class BaseAiService {
|
|
|
321
322
|
debugLogResponse(agentName, response) {
|
|
322
323
|
ai_debug_logger_1.AiDebugLogger.writeResponse(agentName, response);
|
|
323
324
|
}
|
|
325
|
+
static describeProviderError(error) {
|
|
326
|
+
if (!ai_1.APICallError.isInstance(error)) {
|
|
327
|
+
return error instanceof Error ? `${error.name}: ${error.message}` : String(error);
|
|
328
|
+
}
|
|
329
|
+
const body = typeof error.responseBody === 'string'
|
|
330
|
+
? error.responseBody.replace(/\s+/g, ' ').trim()
|
|
331
|
+
: '';
|
|
332
|
+
return [
|
|
333
|
+
`HTTP ${error.statusCode ?? '?'} from ${error.url}`,
|
|
334
|
+
error.message,
|
|
335
|
+
body ? `body: ${body.length > 500 ? `${body.slice(0, 500)}…` : body}` : '',
|
|
336
|
+
]
|
|
337
|
+
.filter(Boolean)
|
|
338
|
+
.join(' | ');
|
|
339
|
+
}
|
|
324
340
|
trimResponseText(str) {
|
|
325
341
|
if (!str) {
|
|
326
342
|
return str;
|
|
@@ -127,8 +127,6 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
127
127
|
const identity = `Your agent identity is ${agent.agentName}: ${agent.description}`;
|
|
128
128
|
const instructions = promptInstructions || agent.systemInstruction;
|
|
129
129
|
const messages = [];
|
|
130
|
-
if (instructions)
|
|
131
|
-
messages.push({ role: 'system', content: instructions });
|
|
132
130
|
messages.push({ role: 'user', content: identity });
|
|
133
131
|
if (agent.attachedFiles && agent.attachedFiles.length > 0) {
|
|
134
132
|
for (const file of agent.attachedFiles) {
|
|
@@ -165,6 +163,7 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
165
163
|
let reasoningEffort = agent.reasoningEffort ? agent.reasoningEffort : undefined;
|
|
166
164
|
const requestParams = {
|
|
167
165
|
model: agent.modelName,
|
|
166
|
+
system: instructions || undefined,
|
|
168
167
|
messages: messages,
|
|
169
168
|
temperature: 0,
|
|
170
169
|
reasoningEffort: reasoningEffort,
|
|
@@ -177,6 +176,7 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
177
176
|
try {
|
|
178
177
|
const result = await (0, ai_1.generateObject)({
|
|
179
178
|
model: this.deepseekClient(agent.modelName),
|
|
179
|
+
system: instructions || undefined,
|
|
180
180
|
messages: messages,
|
|
181
181
|
temperature: 0,
|
|
182
182
|
schema: (0, ai_1.jsonSchema)(jsonSchema),
|
|
@@ -217,6 +217,7 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
217
217
|
else {
|
|
218
218
|
const result = await (0, ai_1.generateText)({
|
|
219
219
|
model: this.deepseekClient(agent.modelName),
|
|
220
|
+
system: instructions || undefined,
|
|
220
221
|
messages: messages,
|
|
221
222
|
temperature: 0,
|
|
222
223
|
providerOptions: {
|
|
@@ -238,7 +239,8 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
|
|
|
238
239
|
}
|
|
239
240
|
}
|
|
240
241
|
catch (error) {
|
|
241
|
-
logger_1.logger.error(
|
|
242
|
+
logger_1.logger.error(`Error generating response from DeepSeek for ${agent.agentName} (${agent.modelName}): ` +
|
|
243
|
+
DeepSeekAiService_1.describeProviderError(error));
|
|
242
244
|
throw error;
|
|
243
245
|
}
|
|
244
246
|
}
|
|
@@ -287,7 +287,7 @@ let AgentStoreService = class AgentStoreService {
|
|
|
287
287
|
if (config.attachedArtifacts && config.attachedArtifacts.length > 0) {
|
|
288
288
|
agent.attachedArtifacts = config.attachedArtifacts;
|
|
289
289
|
}
|
|
290
|
-
logger_1.logger.
|
|
290
|
+
logger_1.logger.debug(`Loaded agent: ${config.agentName} (${config.id}) with ${agent.history.length} history items`);
|
|
291
291
|
}
|
|
292
292
|
catch (error) {
|
|
293
293
|
logger_1.logger.error(`Error loading agent from file ${file}:`, error);
|
|
@@ -15,6 +15,8 @@ export declare class ArtifactService {
|
|
|
15
15
|
private getArtifactFilePath;
|
|
16
16
|
storeArtifact(name: string, content: string, description?: string): string;
|
|
17
17
|
getArtifact(artifactId: string): string | Buffer | null;
|
|
18
|
+
listPackDocumentFiles(pack: string, prefix?: string): string[];
|
|
19
|
+
readPackDocumentFile(pack: string, fileName: string): string | null;
|
|
18
20
|
listArtifacts(): ArtifactMetadata[];
|
|
19
21
|
getArtifactMetadata(artifactId: string): ArtifactMetadata | null;
|
|
20
22
|
updateArtifact(artifactId: string, content: string): boolean;
|
|
@@ -152,6 +152,12 @@ let ArtifactService = class ArtifactService {
|
|
|
152
152
|
return null;
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
+
listPackDocumentFiles(pack, prefix) {
|
|
156
|
+
return (0, pack_artifacts_1.listPackDocumentFiles)(this.packRoots, pack, prefix);
|
|
157
|
+
}
|
|
158
|
+
readPackDocumentFile(pack, fileName) {
|
|
159
|
+
return (0, pack_artifacts_1.readPackDocumentFile)(this.packRoots, pack, fileName);
|
|
160
|
+
}
|
|
155
161
|
listArtifacts() {
|
|
156
162
|
const metadata = this.loadMetadata();
|
|
157
163
|
return [
|
|
@@ -4,4 +4,6 @@ export declare function isPackArtifactId(artifactId: string): boolean;
|
|
|
4
4
|
export declare function listPackArtifacts(packRoots: readonly string[], enabledPacks: readonly string[]): ArtifactMetadata[];
|
|
5
5
|
export declare function getPackArtifactMetadata(packRoots: readonly string[], artifactId: string): ArtifactMetadata | null;
|
|
6
6
|
export declare function getPackArtifact(packRoots: readonly string[], artifactId: string): string | null;
|
|
7
|
+
export declare function listPackDocumentFiles(packRoots: readonly string[], pack: string, prefix?: string): string[];
|
|
8
|
+
export declare function readPackDocumentFile(packRoots: readonly string[], pack: string, fileName: string): string | null;
|
|
7
9
|
export declare function resetPackArtifactCache(): void;
|
|
@@ -38,12 +38,15 @@ exports.isPackArtifactId = isPackArtifactId;
|
|
|
38
38
|
exports.listPackArtifacts = listPackArtifacts;
|
|
39
39
|
exports.getPackArtifactMetadata = getPackArtifactMetadata;
|
|
40
40
|
exports.getPackArtifact = getPackArtifact;
|
|
41
|
+
exports.listPackDocumentFiles = listPackDocumentFiles;
|
|
42
|
+
exports.readPackDocumentFile = readPackDocumentFile;
|
|
41
43
|
exports.resetPackArtifactCache = resetPackArtifactCache;
|
|
42
44
|
const fs = __importStar(require("fs"));
|
|
43
45
|
const path = __importStar(require("path"));
|
|
44
46
|
const logger_1 = require("../common/logger");
|
|
45
47
|
exports.PACK_ARTIFACT_PREFIX = 'pack:';
|
|
46
48
|
const PACK_SEPARATOR = '.';
|
|
49
|
+
const DOCUMENT_EXTENSION = '.md';
|
|
47
50
|
const cache = new Map();
|
|
48
51
|
function isPackArtifactId(artifactId) {
|
|
49
52
|
return artifactId.startsWith(exports.PACK_ARTIFACT_PREFIX);
|
|
@@ -55,24 +58,24 @@ function loadAll(packRoots) {
|
|
|
55
58
|
return cached;
|
|
56
59
|
}
|
|
57
60
|
const documents = new Map();
|
|
58
|
-
const claimed = new Set();
|
|
59
61
|
for (const root of packRoots) {
|
|
60
62
|
if (!fs.existsSync(root))
|
|
61
63
|
continue;
|
|
62
64
|
for (const entry of fs.readdirSync(root, { withFileTypes: true })) {
|
|
63
|
-
if (!entry.isDirectory()
|
|
65
|
+
if (!entry.isDirectory())
|
|
64
66
|
continue;
|
|
65
|
-
claimed.add(entry.name);
|
|
66
67
|
const artifactsDir = path.join(root, entry.name, 'artifacts');
|
|
67
|
-
for (const resolved of loadPack(artifactsDir, entry.name)) {
|
|
68
|
-
documents.
|
|
68
|
+
for (const resolved of loadPack(packRoots, artifactsDir, entry.name)) {
|
|
69
|
+
if (!documents.has(resolved.metadata.artifactId)) {
|
|
70
|
+
documents.set(resolved.metadata.artifactId, resolved);
|
|
71
|
+
}
|
|
69
72
|
}
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
75
|
cache.set(key, documents);
|
|
73
76
|
return documents;
|
|
74
77
|
}
|
|
75
|
-
function loadPack(packDir, dirName) {
|
|
78
|
+
function loadPack(packRoots, packDir, dirName) {
|
|
76
79
|
const manifestPath = path.join(packDir, 'manifest.json');
|
|
77
80
|
if (!fs.existsSync(manifestPath)) {
|
|
78
81
|
return [];
|
|
@@ -107,8 +110,8 @@ function loadPack(packDir, dirName) {
|
|
|
107
110
|
logger_1.logger.warn(`Skipping "${document.id}" in ${manifestPath}: file must be a bare name`);
|
|
108
111
|
continue;
|
|
109
112
|
}
|
|
110
|
-
const filePath =
|
|
111
|
-
if (!
|
|
113
|
+
const filePath = findDocumentFile(packRoots, manifest.pack, document.file);
|
|
114
|
+
if (!filePath) {
|
|
112
115
|
logger_1.logger.warn(`Skipping "${document.id}" in ${manifestPath}: ${document.file} not found`);
|
|
113
116
|
continue;
|
|
114
117
|
}
|
|
@@ -156,6 +159,60 @@ function getPackArtifact(packRoots, artifactId) {
|
|
|
156
159
|
return null;
|
|
157
160
|
}
|
|
158
161
|
}
|
|
162
|
+
function listPackDocumentFiles(packRoots, pack, prefix = '') {
|
|
163
|
+
if (!isBareName(pack)) {
|
|
164
|
+
return [];
|
|
165
|
+
}
|
|
166
|
+
const wanted = prefix.toLowerCase();
|
|
167
|
+
const found = new Map();
|
|
168
|
+
for (const root of packRoots) {
|
|
169
|
+
const dir = path.join(root, pack, 'artifacts');
|
|
170
|
+
if (!fs.existsSync(dir))
|
|
171
|
+
continue;
|
|
172
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
173
|
+
if (!entry.isFile())
|
|
174
|
+
continue;
|
|
175
|
+
const name = entry.name;
|
|
176
|
+
const key = name.toLowerCase();
|
|
177
|
+
if (!key.endsWith(DOCUMENT_EXTENSION) || !key.startsWith(wanted))
|
|
178
|
+
continue;
|
|
179
|
+
if (!found.has(key))
|
|
180
|
+
found.set(key, name);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return [...found.values()].sort((a, b) => a.localeCompare(b));
|
|
184
|
+
}
|
|
185
|
+
function readPackDocumentFile(packRoots, pack, fileName) {
|
|
186
|
+
const filePath = findDocumentFile(packRoots, pack, fileName);
|
|
187
|
+
if (!filePath) {
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
logger_1.logger.error(`Error reading pack document ${pack}/${fileName}:`, error);
|
|
195
|
+
return null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
function findDocumentFile(packRoots, pack, fileName) {
|
|
199
|
+
if (!isBareName(pack) || !isBareName(fileName)) {
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
for (const root of packRoots) {
|
|
203
|
+
const filePath = path.join(root, pack, 'artifacts', fileName);
|
|
204
|
+
if (fs.existsSync(filePath))
|
|
205
|
+
return filePath;
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
function isBareName(name) {
|
|
210
|
+
return (typeof name === 'string' &&
|
|
211
|
+
name.length > 0 &&
|
|
212
|
+
!name.startsWith('.') &&
|
|
213
|
+
!name.includes(':') &&
|
|
214
|
+
name === path.basename(name));
|
|
215
|
+
}
|
|
159
216
|
function resetPackArtifactCache() {
|
|
160
217
|
cache.clear();
|
|
161
218
|
}
|
|
@@ -39,6 +39,7 @@ const native_tool_registry_service_1 = require("../tools/native-tool-registry.se
|
|
|
39
39
|
const user_config_service_1 = require("../config/user-config.service");
|
|
40
40
|
const pack_service_1 = require("../packs/pack.service");
|
|
41
41
|
const pack_instantiation_service_1 = require("../packs/pack-instantiation.service");
|
|
42
|
+
const rpg_service_1 = require("../rpg/rpg.service");
|
|
42
43
|
let UserServiceFactory = class UserServiceFactory {
|
|
43
44
|
aiFactoryService;
|
|
44
45
|
agentMessageService;
|
|
@@ -76,13 +77,17 @@ let UserServiceFactory = class UserServiceFactory {
|
|
|
76
77
|
const artifactStore = new artifact_store_service_1.ArtifactStoreService();
|
|
77
78
|
const toolStore = new tool_store_service_1.ToolStoreService(userPaths);
|
|
78
79
|
const allowUserAuthoredTools = String(this.configService.get('ALLOW_USER_AUTHORED_TOOLS')).toLowerCase() === 'true';
|
|
79
|
-
const toolExecution = new tool_execution_service_1.ToolExecutionService(toolStore, this.nativeToolRegistry, allowUserAuthoredTools
|
|
80
|
+
const toolExecution = new tool_execution_service_1.ToolExecutionService(toolStore, this.nativeToolRegistry, allowUserAuthoredTools, {
|
|
81
|
+
list: (pack, prefix) => artifactService.listPackDocumentFiles(pack, prefix),
|
|
82
|
+
read: (pack, fileName) => artifactService.readPackDocumentFile(pack, fileName),
|
|
83
|
+
});
|
|
80
84
|
const roomStore = new room_store_service_1.RoomStoreService(userPaths, agentStore, attachedFileService, artifactStore, toolStore, toolExecution);
|
|
81
85
|
const roomFactory = new room_factory_1.RoomFactory(roomStore, toolStore, toolExecution);
|
|
82
86
|
const storyStore = new story_store_service_1.StoryStoreService(userPaths, roomStore);
|
|
83
87
|
const storyService = new story_service_1.StoryService(storyStore, agentStore, roomStore, this.storyProgressService, this.storyMessageService, userPaths, agentFactory, roomFactory);
|
|
84
88
|
const appService = new app_service_1.AppService(this.aiFactoryService, agentStore, this.agentMessageService, roomStore, this.roomMessageService, userPaths, attachedFileService, artifactService, storyStore, storyService, this.publishedAgentsService, this.publishedRoomsService, balanceService, this.balanceMessageService, transactionService, agentFactory, roomFactory, toolStore, toolExecution, packService);
|
|
85
89
|
appService.setPackInstantiation(new pack_instantiation_service_1.PackInstantiationService(appService, packService, roomStore));
|
|
90
|
+
appService.setRpg(new rpg_service_1.RpgService(appService, packService, userConfig, userPaths, userId));
|
|
86
91
|
return appService;
|
|
87
92
|
}
|
|
88
93
|
};
|
|
@@ -24,7 +24,7 @@ let UserServiceManager = class UserServiceManager {
|
|
|
24
24
|
constructor(userServiceFactory, configService) {
|
|
25
25
|
this.userServiceFactory = userServiceFactory;
|
|
26
26
|
this.configService = configService;
|
|
27
|
-
this.cacheTimeoutMinutes = parseInt(this.configService.get('USER_SERVICE_CACHE_TIMEOUT_MINUTES', '
|
|
27
|
+
this.cacheTimeoutMinutes = parseInt(this.configService.get('USER_SERVICE_CACHE_TIMEOUT_MINUTES', '180'));
|
|
28
28
|
}
|
|
29
29
|
onModuleInit() {
|
|
30
30
|
if (this.cleanupIntervalId) {
|
|
@@ -4,7 +4,7 @@ import { Observable } from 'rxjs';
|
|
|
4
4
|
import { UserServiceManager } from './app/user-service-manager';
|
|
5
5
|
import { PublishedAgentsService } from './ai/published-agents.service';
|
|
6
6
|
import { PublishedRoomsService } from './room/published-rooms.service';
|
|
7
|
-
import { AgentInfo, CreateAgentRequest, CreateAgentResponse, CreateRoomAgentRequest, UpdateAgentRequest, RoomInfo, RoomDetails, CreateRoomResponse, SendMessageResult, AgentMessagesResponse, RoomMessagesResponse, FileList, PromptFileContent, PromptFoldersResponse, PromptFilesResponse, PromptFolderDefaultsResponse, PromptScope, CreatePromptFolderRequest, CreatePromptFileRequest, UpdatePromptFileRequest, ProcessTextResponse, PreparedPromptResponse, AttachDocumentResponse, StoryInfo, StoryState, Character, ModelInfo, ImageModelOption, StoryModelDefaults, ChapterInfo, StoryIdea, ToolDefinition, ToolsResponse, ToolRunResult, ToolTestRequest, PackSummary, PacksResponse, PackDetails, SetPackEnabledRequest, CreatePackRequest, InstantiatePackRoomRequest, InstantiatePackRoomResponse, InstantiatePackAgentRequest, InstantiatePackAgentResponse } from '../../shared/types/app.types';
|
|
7
|
+
import { AgentInfo, CreateAgentRequest, CreateAgentResponse, CreateRoomAgentRequest, UpdateAgentRequest, RoomInfo, RoomDetails, CreateRoomResponse, SendMessageResult, AgentMessagesResponse, RoomMessagesResponse, FileList, PromptFileContent, PromptFoldersResponse, PromptFilesResponse, PromptFolderDefaultsResponse, PromptScope, CreatePromptFolderRequest, CreatePromptFileRequest, UpdatePromptFileRequest, ProcessTextResponse, PreparedPromptResponse, AttachDocumentResponse, StoryInfo, StoryState, Character, ModelInfo, ImageModelOption, StoryModelDefaults, ChapterInfo, StoryIdea, ToolDefinition, ToolsResponse, ToolRunResult, ToolTestRequest, PackSummary, PacksResponse, PackDetails, SetPackEnabledRequest, CreatePackRequest, InstantiatePackRoomRequest, InstantiatePackRoomResponse, InstantiatePackAgentRequest, InstantiatePackAgentResponse, RpgModelOption, RpgCampaignInfo, RpgCampaignDetails, CreateRpgCampaignRequest, CreateRpgCampaignResponse } from '../../shared/types/app.types';
|
|
8
8
|
import { RoomMessage } from './room/message';
|
|
9
9
|
export declare class AppController {
|
|
10
10
|
private readonly userServiceManager;
|
|
@@ -46,6 +46,14 @@ export declare class AppController {
|
|
|
46
46
|
deletePack(req: ExpressRequest, packName: string): void;
|
|
47
47
|
instantiatePackRoom(req: ExpressRequest, packName: string, roomKey: string, body: InstantiatePackRoomRequest): Promise<InstantiatePackRoomResponse>;
|
|
48
48
|
instantiatePackAgent(req: ExpressRequest, packName: string, agentKey: string, body: InstantiatePackAgentRequest): Promise<InstantiatePackAgentResponse>;
|
|
49
|
+
listRpgModels(req: ExpressRequest): RpgModelOption[];
|
|
50
|
+
listRpgCampaigns(req: ExpressRequest): Promise<RpgCampaignInfo[]>;
|
|
51
|
+
getRpgCampaign(req: ExpressRequest, campaignId: string): Promise<RpgCampaignDetails>;
|
|
52
|
+
createRpgCampaign(req: ExpressRequest, body: CreateRpgCampaignRequest): Promise<CreateRpgCampaignResponse>;
|
|
53
|
+
republishRpgCampaign(req: ExpressRequest, campaignId: string): Promise<{
|
|
54
|
+
instanceId: string;
|
|
55
|
+
publicPath: string;
|
|
56
|
+
}>;
|
|
49
57
|
listPromptFolders(req: ExpressRequest): string[];
|
|
50
58
|
listPrompts(req: ExpressRequest, agentId: string): string[];
|
|
51
59
|
runPreparedPrompt(req: ExpressRequest, agentId: string, promptName: string, body: {
|
|
@@ -60,6 +60,12 @@ const published_rooms_service_1 = require("./room/published-rooms.service");
|
|
|
60
60
|
const errors_1 = require("./common/errors");
|
|
61
61
|
const path = __importStar(require("path"));
|
|
62
62
|
const logger_1 = require("./common/logger");
|
|
63
|
+
const MAX_PDF_UPLOAD_BYTES = Math.max(1, Number(process.env.MAX_PDF_UPLOAD_MB) || 50) * 1024 * 1024;
|
|
64
|
+
const MAX_MARKDOWN_BYTES = Math.max(1, Number(process.env.MAX_MARKDOWN_UPLOAD_MB) || 10) * 1024 * 1024;
|
|
65
|
+
function asMegabytes(bytes) {
|
|
66
|
+
return `${Math.round(bytes / (1024 * 1024))}MB`;
|
|
67
|
+
}
|
|
68
|
+
const UPLOAD_LIMITS = { limits: { fileSize: Math.max(MAX_PDF_UPLOAD_BYTES, MAX_MARKDOWN_BYTES) } };
|
|
63
69
|
function toPackSummary(pack) {
|
|
64
70
|
return {
|
|
65
71
|
pack: pack.name,
|
|
@@ -229,9 +235,8 @@ let AppController = AppController_1 = class AppController {
|
|
|
229
235
|
if (!agentId) {
|
|
230
236
|
throw new common_1.BadRequestException('Agent ID is required');
|
|
231
237
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
throw new common_1.HttpException('File too large', common_1.HttpStatus.PAYLOAD_TOO_LARGE);
|
|
238
|
+
if (file && file.size > MAX_PDF_UPLOAD_BYTES) {
|
|
239
|
+
throw new common_1.HttpException(`File too large (max ${asMegabytes(MAX_PDF_UPLOAD_BYTES)})`, common_1.HttpStatus.PAYLOAD_TOO_LARGE);
|
|
235
240
|
}
|
|
236
241
|
const appService = this.getAppService(req);
|
|
237
242
|
let fileName = file?.originalname || 'attach_file';
|
|
@@ -609,6 +614,69 @@ let AppController = AppController_1 = class AppController {
|
|
|
609
614
|
throw new common_1.HttpException(error.message || 'Failed to build the agent', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
610
615
|
}
|
|
611
616
|
}
|
|
617
|
+
listRpgModels(req) {
|
|
618
|
+
try {
|
|
619
|
+
return this.getAppService(req).rpg.listModels();
|
|
620
|
+
}
|
|
621
|
+
catch (error) {
|
|
622
|
+
logger_1.logger.error(`[${req.user?.sub}] Error listing RPG models:`, error);
|
|
623
|
+
return [];
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
async listRpgCampaigns(req) {
|
|
627
|
+
try {
|
|
628
|
+
return await this.getAppService(req).rpg.listCampaigns();
|
|
629
|
+
}
|
|
630
|
+
catch (error) {
|
|
631
|
+
logger_1.logger.error(`[${req.user?.sub}] Error listing campaigns:`, error);
|
|
632
|
+
throw new common_1.HttpException(error.message || 'Failed to list campaigns', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
async getRpgCampaign(req, campaignId) {
|
|
636
|
+
try {
|
|
637
|
+
return await this.getAppService(req).rpg.getCampaign(campaignId);
|
|
638
|
+
}
|
|
639
|
+
catch (error) {
|
|
640
|
+
if (error instanceof errors_1.NotFoundError) {
|
|
641
|
+
throw new common_1.NotFoundException(error.message);
|
|
642
|
+
}
|
|
643
|
+
logger_1.logger.error(`[${req.user?.sub}] Error reading campaign ${campaignId}:`, error);
|
|
644
|
+
throw new common_1.HttpException(error.message || 'Failed to read the campaign', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
async createRpgCampaign(req, body) {
|
|
648
|
+
try {
|
|
649
|
+
return await this.getAppService(req).rpg.createCampaign(body);
|
|
650
|
+
}
|
|
651
|
+
catch (error) {
|
|
652
|
+
if (error instanceof errors_1.ValidationError) {
|
|
653
|
+
throw new common_1.BadRequestException(error.message);
|
|
654
|
+
}
|
|
655
|
+
if (error instanceof errors_1.NotFoundError) {
|
|
656
|
+
throw new common_1.NotFoundException(error.message);
|
|
657
|
+
}
|
|
658
|
+
if (error instanceof errors_1.OperationFailedError) {
|
|
659
|
+
throw new common_1.ConflictException(error.message);
|
|
660
|
+
}
|
|
661
|
+
logger_1.logger.error(`[${req.user?.sub}] Error creating campaign:`, error);
|
|
662
|
+
throw new common_1.HttpException(error.message || 'Failed to create the campaign', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
async republishRpgCampaign(req, campaignId) {
|
|
666
|
+
try {
|
|
667
|
+
return await this.getAppService(req).rpg.republishCampaign(campaignId);
|
|
668
|
+
}
|
|
669
|
+
catch (error) {
|
|
670
|
+
if (error instanceof errors_1.ValidationError) {
|
|
671
|
+
throw new common_1.BadRequestException(error.message);
|
|
672
|
+
}
|
|
673
|
+
if (error instanceof errors_1.NotFoundError) {
|
|
674
|
+
throw new common_1.NotFoundException(error.message);
|
|
675
|
+
}
|
|
676
|
+
logger_1.logger.error(`[${req.user?.sub}] Error publishing campaign ${campaignId}:`, error);
|
|
677
|
+
throw new common_1.HttpException(error.message || 'Failed to publish the campaign', common_1.HttpStatus.INTERNAL_SERVER_ERROR);
|
|
678
|
+
}
|
|
679
|
+
}
|
|
612
680
|
listPromptFolders(req) {
|
|
613
681
|
try {
|
|
614
682
|
const appService = this.getAppService(req);
|
|
@@ -1964,7 +2032,6 @@ let AppController = AppController_1 = class AppController {
|
|
|
1964
2032
|
}
|
|
1965
2033
|
}
|
|
1966
2034
|
async createArtifact(req, body, file) {
|
|
1967
|
-
const MAX_MARKDOWN_SIZE = 10 * 1024 * 1024;
|
|
1968
2035
|
if (!body.name || !body.name.trim()) {
|
|
1969
2036
|
throw new common_1.BadRequestException('Artifact name is required');
|
|
1970
2037
|
}
|
|
@@ -1975,8 +2042,8 @@ let AppController = AppController_1 = class AppController {
|
|
|
1975
2042
|
if (typeof body.content !== 'string' || !body.content.trim()) {
|
|
1976
2043
|
throw new common_1.BadRequestException('Provide either a .md/.pdf file or a non-empty "content" string');
|
|
1977
2044
|
}
|
|
1978
|
-
if (Buffer.byteLength(body.content, 'utf8') >
|
|
1979
|
-
throw new common_1.HttpException(
|
|
2045
|
+
if (Buffer.byteLength(body.content, 'utf8') > MAX_MARKDOWN_BYTES) {
|
|
2046
|
+
throw new common_1.HttpException(`Content too large (max ${asMegabytes(MAX_MARKDOWN_BYTES)})`, common_1.HttpStatus.PAYLOAD_TOO_LARGE);
|
|
1980
2047
|
}
|
|
1981
2048
|
try {
|
|
1982
2049
|
const appService = this.getAppService(req);
|
|
@@ -1991,10 +2058,9 @@ let AppController = AppController_1 = class AppController {
|
|
|
1991
2058
|
if (!['md', 'pdf'].includes(extension)) {
|
|
1992
2059
|
throw new common_1.BadRequestException('Only .md and .pdf files are allowed');
|
|
1993
2060
|
}
|
|
1994
|
-
const
|
|
1995
|
-
if (file.size >
|
|
1996
|
-
|
|
1997
|
-
throw new common_1.HttpException(`File too large (max ${maxSizeMB})`, common_1.HttpStatus.PAYLOAD_TOO_LARGE);
|
|
2061
|
+
const maxSize = extension === 'pdf' ? MAX_PDF_UPLOAD_BYTES : MAX_MARKDOWN_BYTES;
|
|
2062
|
+
if (file.size > maxSize) {
|
|
2063
|
+
throw new common_1.HttpException(`File too large (max ${asMegabytes(maxSize)})`, common_1.HttpStatus.PAYLOAD_TOO_LARGE);
|
|
1998
2064
|
}
|
|
1999
2065
|
try {
|
|
2000
2066
|
const appService = this.getAppService(req);
|
|
@@ -2179,7 +2245,7 @@ __decorate([
|
|
|
2179
2245
|
__decorate([
|
|
2180
2246
|
(0, owner_only_decorator_1.OwnerOnly)(),
|
|
2181
2247
|
(0, common_1.Post)('agents/:agentId/files'),
|
|
2182
|
-
(0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file')),
|
|
2248
|
+
(0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file', UPLOAD_LIMITS)),
|
|
2183
2249
|
__param(0, (0, common_1.Request)()),
|
|
2184
2250
|
__param(1, (0, common_1.Param)('agentId')),
|
|
2185
2251
|
__param(2, (0, common_1.Body)()),
|
|
@@ -2408,6 +2474,51 @@ __decorate([
|
|
|
2408
2474
|
__metadata("design:paramtypes", [Object, String, String, Object]),
|
|
2409
2475
|
__metadata("design:returntype", Promise)
|
|
2410
2476
|
], AppController.prototype, "instantiatePackAgent", null);
|
|
2477
|
+
__decorate([
|
|
2478
|
+
(0, owner_only_decorator_1.OwnerOnly)(),
|
|
2479
|
+
(0, common_1.Get)('rpg/models'),
|
|
2480
|
+
__param(0, (0, common_1.Request)()),
|
|
2481
|
+
__metadata("design:type", Function),
|
|
2482
|
+
__metadata("design:paramtypes", [Object]),
|
|
2483
|
+
__metadata("design:returntype", Array)
|
|
2484
|
+
], AppController.prototype, "listRpgModels", null);
|
|
2485
|
+
__decorate([
|
|
2486
|
+
(0, owner_only_decorator_1.OwnerOnly)(),
|
|
2487
|
+
(0, common_1.Get)('rpg/campaigns'),
|
|
2488
|
+
__param(0, (0, common_1.Request)()),
|
|
2489
|
+
__metadata("design:type", Function),
|
|
2490
|
+
__metadata("design:paramtypes", [Object]),
|
|
2491
|
+
__metadata("design:returntype", Promise)
|
|
2492
|
+
], AppController.prototype, "listRpgCampaigns", null);
|
|
2493
|
+
__decorate([
|
|
2494
|
+
(0, owner_only_decorator_1.OwnerOnly)(),
|
|
2495
|
+
(0, common_1.Get)('rpg/campaigns/:campaignId'),
|
|
2496
|
+
__param(0, (0, common_1.Request)()),
|
|
2497
|
+
__param(1, (0, common_1.Param)('campaignId')),
|
|
2498
|
+
__metadata("design:type", Function),
|
|
2499
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
2500
|
+
__metadata("design:returntype", Promise)
|
|
2501
|
+
], AppController.prototype, "getRpgCampaign", null);
|
|
2502
|
+
__decorate([
|
|
2503
|
+
(0, owner_only_decorator_1.OwnerOnly)(),
|
|
2504
|
+
(0, common_1.Post)('rpg/campaigns'),
|
|
2505
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
|
|
2506
|
+
__param(0, (0, common_1.Request)()),
|
|
2507
|
+
__param(1, (0, common_1.Body)()),
|
|
2508
|
+
__metadata("design:type", Function),
|
|
2509
|
+
__metadata("design:paramtypes", [Object, Object]),
|
|
2510
|
+
__metadata("design:returntype", Promise)
|
|
2511
|
+
], AppController.prototype, "createRpgCampaign", null);
|
|
2512
|
+
__decorate([
|
|
2513
|
+
(0, owner_only_decorator_1.OwnerOnly)(),
|
|
2514
|
+
(0, common_1.Post)('rpg/campaigns/:campaignId/publish'),
|
|
2515
|
+
(0, common_1.HttpCode)(common_1.HttpStatus.CREATED),
|
|
2516
|
+
__param(0, (0, common_1.Request)()),
|
|
2517
|
+
__param(1, (0, common_1.Param)('campaignId')),
|
|
2518
|
+
__metadata("design:type", Function),
|
|
2519
|
+
__metadata("design:paramtypes", [Object, String]),
|
|
2520
|
+
__metadata("design:returntype", Promise)
|
|
2521
|
+
], AppController.prototype, "republishRpgCampaign", null);
|
|
2411
2522
|
__decorate([
|
|
2412
2523
|
(0, owner_only_decorator_1.OwnerOnly)(),
|
|
2413
2524
|
(0, common_1.Get)('list-prompt-folders'),
|
|
@@ -3209,7 +3320,7 @@ __decorate([
|
|
|
3209
3320
|
__decorate([
|
|
3210
3321
|
(0, owner_only_decorator_1.OwnerOnly)(),
|
|
3211
3322
|
(0, common_1.Post)('artifacts'),
|
|
3212
|
-
(0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file')),
|
|
3323
|
+
(0, common_1.UseInterceptors)((0, platform_express_1.FileInterceptor)('file', UPLOAD_LIMITS)),
|
|
3213
3324
|
__param(0, (0, common_1.Request)()),
|
|
3214
3325
|
__param(1, (0, common_1.Body)()),
|
|
3215
3326
|
__param(2, (0, common_1.UploadedFile)()),
|