briyah 1.2.0 → 1.2.1
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/data/common/config/markup +1 -1
- package/data/common/config/model_prices.json +3775 -653
- package/data/common/prompts/character/create_character.json +33 -29
- package/data/common/prompts/character/create_character.prompt +13 -2
- package/data/common/prompts/character/create_user_character.json +32 -28
- package/data/common/prompts/character/create_user_character.prompt +13 -2
- package/data/common/prompts/character/progress_character.json +22 -18
- package/data/common/prompts/character/progress_character.prompt +6 -2
- package/data/common/prompts/illustrator/describe_character.prompt +31 -0
- package/data/common/prompts/illustrator/describe_scene.json +19 -1
- package/data/common/prompts/illustrator/describe_scene.prompt +2 -1
- package/data/common/prompts/narrator/perceive.prompt +96 -35
- package/data/common/prompts/story_moderator/moderate.json +33 -7
- package/data/common/prompts/story_moderator/moderate.prompt +166 -20
- package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +2 -0
- package/dist-sdk/server/src/ai/LLM/anthropic.service.js +25 -13
- package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +3 -0
- package/dist-sdk/server/src/ai/LLM/base-ai.service.js +10 -0
- package/dist-sdk/server/src/ai/LLM/deepseek.service.js +10 -0
- package/dist-sdk/server/src/ai/LLM/googleai.service.js +11 -8
- package/dist-sdk/server/src/ai/LLM/grok.service.js +8 -5
- package/dist-sdk/server/src/ai/LLM/openai.service.js +12 -11
- package/dist-sdk/server/src/ai/LLM/together.service.js +9 -6
- package/dist-sdk/server/src/ai/agent.d.ts +4 -3
- package/dist-sdk/server/src/ai/agent.js +12 -5
- package/dist-sdk/server/src/ai/ai-debug-logger.d.ts +10 -0
- package/dist-sdk/server/src/ai/ai-debug-logger.js +82 -0
- package/dist-sdk/server/src/room/message.d.ts +1 -1
- package/dist-sdk/server/src/room/message.js +1 -1
- package/dist-sdk/server/src/room/room.d.ts +1 -0
- package/dist-sdk/server/src/room/room.js +43 -19
- package/dist-sdk/server/src/sdk/briyah-config.d.ts +1 -0
- package/dist-sdk/server/src/sdk/briyah-config.js +4 -0
- package/dist-sdk/server/src/story/story.service.d.ts +7 -0
- package/dist-sdk/server/src/story/story.service.js +221 -87
- package/dist-sdk/shared/types/app.types.d.ts +1 -0
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/Agent.html +15 -16
- package/docs/classes/Briyah.html +12 -12
- package/docs/classes/BriyahConfigService.html +5 -5
- package/docs/classes/Room.html +24 -24
- package/docs/classes/RoomMessage.html +11 -11
- package/docs/enums/MessageAction.html +3 -3
- package/docs/hierarchy.html +1 -1
- package/docs/index.html +2 -2
- package/docs/interfaces/AgentInfo.html +2 -2
- package/docs/interfaces/AgentMessagesResponse.html +2 -2
- package/docs/interfaces/AppService.html +110 -110
- package/docs/interfaces/Artifact.html +3 -3
- package/docs/interfaces/ArtifactMetadata.html +2 -2
- package/docs/interfaces/AttachDocumentResponse.html +2 -2
- package/docs/interfaces/BriyahConfigOptions.html +7 -7
- package/docs/interfaces/ChapterInfo.html +2 -2
- package/docs/interfaces/Character.html +2 -2
- package/docs/interfaces/CreateAgentResponse.html +2 -2
- package/docs/interfaces/CreateRoomResponse.html +2 -2
- package/docs/interfaces/CreateStoryResponse.html +2 -2
- package/docs/interfaces/FileList.html +2 -2
- package/docs/interfaces/LoggingOptions.html +10 -6
- package/docs/interfaces/Message.html +2 -2
- package/docs/interfaces/ModelInfo.html +2 -2
- package/docs/interfaces/PreparedPromptResponse.html +2 -2
- package/docs/interfaces/ProcessTextResponse.html +2 -2
- package/docs/interfaces/PromptFile.html +2 -2
- package/docs/interfaces/PromptFileContent.html +2 -2
- package/docs/interfaces/PromptFilesResponse.html +2 -2
- package/docs/interfaces/PromptFolder.html +2 -2
- package/docs/interfaces/PromptFoldersResponse.html +2 -2
- package/docs/interfaces/RoomDetails.html +2 -2
- package/docs/interfaces/RoomInfo.html +2 -2
- package/docs/interfaces/RoomMessagesResponse.html +2 -2
- package/docs/interfaces/StoryErrorEvent.html +3 -3
- package/docs/interfaces/StoryIdea.html +2 -2
- package/docs/interfaces/StoryInfo.html +3 -3
- package/docs/interfaces/StoryIntroduceCharacterEvent.html +3 -3
- package/docs/interfaces/StoryProgressChapterEvent.html +3 -3
- package/docs/interfaces/StoryState.html +5 -5
- package/docs/interfaces/StoryStateEvent.html +3 -3
- package/docs/interfaces/Transaction.html +2 -2
- package/docs/interfaces/TransactionHistoryResponse.html +2 -2
- package/docs/modules.html +1 -1
- package/docs/types/PromptScope.html +1 -1
- package/package.json +2 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Agent = void 0;
|
|
4
4
|
const app_types_1 = require("../../../shared/types/app.types");
|
|
5
|
+
const logger_1 = require("../common/logger");
|
|
5
6
|
const crypto_1 = require("crypto");
|
|
6
7
|
class Agent {
|
|
7
8
|
id;
|
|
@@ -39,7 +40,6 @@ class Agent {
|
|
|
39
40
|
modelName;
|
|
40
41
|
smallModelName;
|
|
41
42
|
serviceName;
|
|
42
|
-
imageProperties;
|
|
43
43
|
reasoningEffort;
|
|
44
44
|
allowSearch;
|
|
45
45
|
maxOutputTokens = 0;
|
|
@@ -191,11 +191,14 @@ class Agent {
|
|
|
191
191
|
async compact() {
|
|
192
192
|
const originalHistory = [...(this.history || [])];
|
|
193
193
|
const originalLength = originalHistory.length;
|
|
194
|
+
const originalChars = originalHistory.reduce((sum, m) => sum + (m?.content?.length || 0), 0);
|
|
194
195
|
if (originalLength === 0) {
|
|
195
196
|
return {
|
|
196
197
|
success: true,
|
|
197
198
|
originalLength,
|
|
198
199
|
newLength: originalLength,
|
|
200
|
+
originalChars,
|
|
201
|
+
newChars: 0,
|
|
199
202
|
message: 'No conversation history to compact',
|
|
200
203
|
};
|
|
201
204
|
}
|
|
@@ -206,11 +209,15 @@ class Agent {
|
|
|
206
209
|
const summary = summaryResponse?.summary || summaryResponse;
|
|
207
210
|
this.addToConversationHistory(`[CONVERSATION HISTORY SUMMARY]\n\n${summary}`, true);
|
|
208
211
|
const newLength = this.history.length;
|
|
212
|
+
const newChars = this.history.reduce((sum, m) => sum + (m?.content?.length || 0), 0);
|
|
213
|
+
logger_1.logger.log(`Compacted ${this.agentName}: ${originalChars} -> ${newChars} characters (${originalLength} -> ${newLength} messages)`);
|
|
209
214
|
this.save();
|
|
210
215
|
return {
|
|
211
216
|
success: true,
|
|
212
217
|
originalLength,
|
|
213
218
|
newLength,
|
|
219
|
+
originalChars,
|
|
220
|
+
newChars,
|
|
214
221
|
message: `${originalLength} messages -> ${newLength} messages`,
|
|
215
222
|
summary,
|
|
216
223
|
};
|
|
@@ -223,11 +230,11 @@ class Agent {
|
|
|
223
230
|
async textPrompt(prompt, jsonSchema = null, saveResponse = true, promptInstructions = null, cacheMessage = false, maxOutputChars = 0) {
|
|
224
231
|
return await this.aiService.textPrompt(this, prompt, jsonSchema, saveResponse, promptInstructions, this.aiService.getCacheConfig(this, cacheMessage), maxOutputChars);
|
|
225
232
|
}
|
|
226
|
-
async generateImage(prompt) {
|
|
227
|
-
return await this.aiService.generateImage(this, prompt,
|
|
233
|
+
async generateImage(prompt, imageProperties) {
|
|
234
|
+
return await this.aiService.generateImage(this, prompt, imageProperties);
|
|
228
235
|
}
|
|
229
|
-
async editImage(prompt, referenceImageArtifactIds) {
|
|
230
|
-
return await this.aiService.editImage(this, prompt,
|
|
236
|
+
async editImage(prompt, imageProperties, referenceImageArtifactIds) {
|
|
237
|
+
return await this.aiService.editImage(this, prompt, imageProperties, referenceImageArtifactIds);
|
|
231
238
|
}
|
|
232
239
|
}
|
|
233
240
|
exports.Agent = Agent;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare class AiDebugLogger {
|
|
2
|
+
static isEnabled(): boolean;
|
|
3
|
+
private static getLogDir;
|
|
4
|
+
private static timestamp;
|
|
5
|
+
private static sanitize;
|
|
6
|
+
private static write;
|
|
7
|
+
static writeRequest(agentName: string, content: unknown): void;
|
|
8
|
+
static writeThinking(agentName: string, content: string): void;
|
|
9
|
+
static writeResponse(agentName: string, content: string): void;
|
|
10
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.AiDebugLogger = void 0;
|
|
37
|
+
const fs = __importStar(require("fs"));
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
class AiDebugLogger {
|
|
40
|
+
static isEnabled() {
|
|
41
|
+
return process.env.AI_DEBUG === 'true';
|
|
42
|
+
}
|
|
43
|
+
static getLogDir() {
|
|
44
|
+
const dataPath = process.env.BRIYAH_DATA_PATH || path.resolve(process.cwd(), 'server', 'data');
|
|
45
|
+
const dir = path.resolve(dataPath, 'logs', 'ai-debug');
|
|
46
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
47
|
+
return dir;
|
|
48
|
+
}
|
|
49
|
+
static timestamp() {
|
|
50
|
+
const now = new Date();
|
|
51
|
+
const pad = (n, len = 2) => String(n).padStart(len, '0');
|
|
52
|
+
return (`${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}` +
|
|
53
|
+
`_${pad(now.getHours())}-${pad(now.getMinutes())}-${pad(now.getSeconds())}` +
|
|
54
|
+
`-${pad(now.getMilliseconds(), 3)}`);
|
|
55
|
+
}
|
|
56
|
+
static sanitize(name) {
|
|
57
|
+
return name.replace(/[<>:"/\\|?*\s]+/g, '_').substring(0, 80);
|
|
58
|
+
}
|
|
59
|
+
static write(agentName, suffix, content) {
|
|
60
|
+
if (!this.isEnabled())
|
|
61
|
+
return;
|
|
62
|
+
try {
|
|
63
|
+
const filename = `${this.timestamp()}_${this.sanitize(agentName)}_${suffix}.txt`;
|
|
64
|
+
fs.writeFileSync(path.join(this.getLogDir(), filename), content, 'utf8');
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
static writeRequest(agentName, content) {
|
|
70
|
+
const text = typeof content === 'string' ? content : JSON.stringify(content, null, 2);
|
|
71
|
+
this.write(agentName, 'REQUEST', text);
|
|
72
|
+
}
|
|
73
|
+
static writeThinking(agentName, content) {
|
|
74
|
+
if (!content)
|
|
75
|
+
return;
|
|
76
|
+
this.write(agentName, 'THINKING', content);
|
|
77
|
+
}
|
|
78
|
+
static writeResponse(agentName, content) {
|
|
79
|
+
this.write(agentName, 'RESPONSE', content ?? '');
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.AiDebugLogger = AiDebugLogger;
|
|
@@ -7,7 +7,7 @@ export declare class RoomMessage implements Message {
|
|
|
7
7
|
timestamp: Date;
|
|
8
8
|
name?: string;
|
|
9
9
|
situation?: string;
|
|
10
|
-
|
|
10
|
+
changes?: Record<string, any>;
|
|
11
11
|
index?: number;
|
|
12
12
|
constructor(sender: string, action: MessageAction, content: string, targets?: string[], name?: string, situation?: string);
|
|
13
13
|
getSender(): string;
|
|
@@ -67,6 +67,7 @@ export declare class Room {
|
|
|
67
67
|
isRoomAdjourned(): boolean;
|
|
68
68
|
setArtifacts(artifacts: Artifact[]): void;
|
|
69
69
|
private parseAgentResponse;
|
|
70
|
+
private static extractPreamble;
|
|
70
71
|
private static coerceMessageAction;
|
|
71
72
|
private getAgentAiResponse;
|
|
72
73
|
perceive(agent: Agent, message: RoomMessage, onResponse: (message: RoomMessage | null) => void): void;
|
|
@@ -201,19 +201,14 @@ class Room {
|
|
|
201
201
|
let normalizedAction;
|
|
202
202
|
if (typeof response !== 'object') {
|
|
203
203
|
needsModeration = true;
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
.join('\n')
|
|
212
|
-
.trimStart();
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
204
|
+
const parsed = Room.extractPreamble(response);
|
|
205
|
+
if (parsed) {
|
|
206
|
+
situation = parsed.preamble;
|
|
207
|
+
content = parsed.content;
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
situation = undefined;
|
|
215
211
|
}
|
|
216
|
-
situation = situation || undefined;
|
|
217
212
|
}
|
|
218
213
|
else if (!response.content) {
|
|
219
214
|
needsModeration = true;
|
|
@@ -244,11 +239,31 @@ class Room {
|
|
|
244
239
|
}
|
|
245
240
|
situation = response.situation || undefined;
|
|
246
241
|
const msg = new message_1.RoomMessage(agent.agentNickname, normalizedAction, response.content, targets, response.name, situation);
|
|
247
|
-
if (
|
|
248
|
-
msg.
|
|
242
|
+
if (response.changes && typeof response.changes === 'object') {
|
|
243
|
+
msg.changes = response.changes;
|
|
249
244
|
}
|
|
250
245
|
return msg;
|
|
251
246
|
}
|
|
247
|
+
static extractPreamble(response) {
|
|
248
|
+
const lines = response.split('\n');
|
|
249
|
+
let i = 0;
|
|
250
|
+
while (i < lines.length && lines[i].trim() === '')
|
|
251
|
+
i++;
|
|
252
|
+
const tagLineRe = /^\s*<\w+>[\s\S]*?<\/\w+>\s*$/;
|
|
253
|
+
if (i >= lines.length || !tagLineRe.test(lines[i]))
|
|
254
|
+
return null;
|
|
255
|
+
const preambleLines = [];
|
|
256
|
+
let j = i;
|
|
257
|
+
while (j < lines.length && tagLineRe.test(lines[j])) {
|
|
258
|
+
preambleLines.push(lines[j].trim());
|
|
259
|
+
j++;
|
|
260
|
+
}
|
|
261
|
+
const preamble = preambleLines.join('\n');
|
|
262
|
+
if (j < lines.length && lines[j].trim() === '')
|
|
263
|
+
j++;
|
|
264
|
+
const content = lines.slice(j).join('\n').trimStart();
|
|
265
|
+
return { preamble, content };
|
|
266
|
+
}
|
|
252
267
|
static coerceMessageAction(raw) {
|
|
253
268
|
if (typeof raw !== 'string')
|
|
254
269
|
return undefined;
|
|
@@ -324,6 +339,13 @@ class Room {
|
|
|
324
339
|
async moderate(moderatorAgent, message, onResponse) {
|
|
325
340
|
const humanAgent = this.getAgents().find((agent) => agent.isControlledByHuman);
|
|
326
341
|
const humanAgentName = humanAgent ? humanAgent.agentNickname : 'Player';
|
|
342
|
+
const visibleArtifacts = this.getVisibleArtifacts(moderatorAgent.agentNickname)
|
|
343
|
+
.map((a) => `${a.name} (by ${a.creator}): ${a.body}`)
|
|
344
|
+
.join('\n\n');
|
|
345
|
+
const invisibleArtifactNames = this.getArtifacts()
|
|
346
|
+
.filter((a) => !this.getVisibleArtifacts(moderatorAgent.agentNickname).includes(a))
|
|
347
|
+
.map((a) => a.name)
|
|
348
|
+
.join(', ');
|
|
327
349
|
const variables = {
|
|
328
350
|
agentName: moderatorAgent.agentName,
|
|
329
351
|
agentNickname: moderatorAgent.agentNickname || moderatorAgent.agentName,
|
|
@@ -335,6 +357,8 @@ class Room {
|
|
|
335
357
|
scenario: this.getGoal(),
|
|
336
358
|
humanAgent: humanAgent,
|
|
337
359
|
humanAgentName: humanAgentName,
|
|
360
|
+
visibleArtifacts: visibleArtifacts,
|
|
361
|
+
invisibleArtifactNames: invisibleArtifactNames,
|
|
338
362
|
};
|
|
339
363
|
let prompt = `
|
|
340
364
|
Current Situation: ${this.getSituation()}
|
|
@@ -648,11 +672,11 @@ Recent Message: ${message.getContent()}
|
|
|
648
672
|
originalMessage.content = content;
|
|
649
673
|
}
|
|
650
674
|
if (this.checkAgentNicknameMatch(originalMessage.sender, responderNickname)) {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
675
|
+
logger_1.logger.warn(`Moderator routed message to sender: ${originalMessage.sender}. Reassigning responder to room leader: ${roomLeaderName}`);
|
|
676
|
+
responderNickname = roomLeaderName;
|
|
677
|
+
moderatorMessage.name = roomLeaderName;
|
|
678
|
+
if (!targets.includes(roomLeaderName))
|
|
679
|
+
targets.push(roomLeaderName);
|
|
656
680
|
}
|
|
657
681
|
logger_1.logger.log(`Moderator routing: sender=${originalMessage.sender} action=${moderatorMessage.action}, name=${responderNickname}, targets=${targets.join(', ')}`);
|
|
658
682
|
if (moderatorMessage.action === app_types_1.MessageAction.RELAY) {
|
|
@@ -23,6 +23,10 @@ class BriyahConfigService {
|
|
|
23
23
|
this.env.DEFAULT_MARKUP_RATE = String(options.markupRate);
|
|
24
24
|
process.env.DEFAULT_MARKUP_RATE = String(options.markupRate);
|
|
25
25
|
}
|
|
26
|
+
if (options?.logging?.aiDebug) {
|
|
27
|
+
this.env.AI_DEBUG = 'true';
|
|
28
|
+
process.env.AI_DEBUG = 'true';
|
|
29
|
+
}
|
|
26
30
|
}
|
|
27
31
|
get(key, defaultValue) {
|
|
28
32
|
const value = this.env[key];
|
|
@@ -77,14 +77,21 @@ export declare class StoryService {
|
|
|
77
77
|
private compactAgentHistories;
|
|
78
78
|
private extractMarkdownContent;
|
|
79
79
|
private updatePlotPlan;
|
|
80
|
+
private publishInventoryArtifact;
|
|
81
|
+
private applyInventoryUpdates;
|
|
80
82
|
private updateCharacterProfiles;
|
|
81
83
|
private getImageModelConfig;
|
|
84
|
+
private getImagePropertiesForAgent;
|
|
82
85
|
private createArtistAgent;
|
|
83
86
|
private generateCharacterPortrait;
|
|
87
|
+
private generatePortraitForName;
|
|
84
88
|
private updateCharacterPortrait;
|
|
85
89
|
private generateSceneIllustration;
|
|
90
|
+
private ensureMinorCharacterPortraits;
|
|
86
91
|
private generateSceneReference;
|
|
87
92
|
private generateStoryImage;
|
|
93
|
+
private parseNarratorPreamble;
|
|
94
|
+
private formatDisplaySituation;
|
|
88
95
|
private updateStorySituation;
|
|
89
96
|
generateStoryMarkdown(storyId: string): Promise<string>;
|
|
90
97
|
exportStoryData(storyId: string): Promise<{
|