briyah 2.0.9 → 2.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/data/common/config/image_models.json +85 -6
  2. package/data/common/config/model_prices.json +30170 -32794
  3. package/dist-sdk/server/src/ai/LLM/anthropic.service.d.ts +7 -0
  4. package/dist-sdk/server/src/ai/LLM/anthropic.service.js +27 -24
  5. package/dist-sdk/server/src/ai/LLM/attachment-type.d.ts +21 -0
  6. package/dist-sdk/server/src/ai/LLM/attachment-type.js +76 -0
  7. package/dist-sdk/server/src/ai/LLM/base-ai.service.d.ts +6 -0
  8. package/dist-sdk/server/src/ai/LLM/base-ai.service.js +22 -17
  9. package/dist-sdk/server/src/ai/LLM/comfyui.service.js +1 -1
  10. package/dist-sdk/server/src/ai/LLM/deepseek.service.d.ts +1 -1
  11. package/dist-sdk/server/src/ai/LLM/deepseek.service.js +3 -2
  12. package/dist-sdk/server/src/ai/LLM/fal.service.d.ts +1 -1
  13. package/dist-sdk/server/src/ai/LLM/fal.service.js +4 -3
  14. package/dist-sdk/server/src/ai/LLM/googleai.service.d.ts +1 -1
  15. package/dist-sdk/server/src/ai/LLM/googleai.service.js +5 -4
  16. package/dist-sdk/server/src/ai/LLM/grok.service.d.ts +1 -1
  17. package/dist-sdk/server/src/ai/LLM/grok.service.js +3 -2
  18. package/dist-sdk/server/src/ai/LLM/mock.service.d.ts +1 -1
  19. package/dist-sdk/server/src/ai/LLM/mock.service.js +3 -2
  20. package/dist-sdk/server/src/ai/LLM/openai.service.d.ts +7 -1
  21. package/dist-sdk/server/src/ai/LLM/openai.service.js +30 -12
  22. package/dist-sdk/server/src/ai/LLM/self-hosted.service.js +1 -1
  23. package/dist-sdk/server/src/ai/LLM/together.service.d.ts +1 -1
  24. package/dist-sdk/server/src/ai/LLM/together.service.js +5 -4
  25. package/dist-sdk/server/src/ai/agent-config.d.ts +4 -0
  26. package/dist-sdk/server/src/ai/agent-store.service.js +3 -0
  27. package/dist-sdk/server/src/ai/agent.d.ts +7 -0
  28. package/dist-sdk/server/src/ai/agent.js +6 -0
  29. package/dist-sdk/server/src/app/balance.service.d.ts +155 -27
  30. package/dist-sdk/server/src/app/balance.service.js +290 -97
  31. package/dist-sdk/server/src/app/usage-context.d.ts +24 -0
  32. package/dist-sdk/server/src/app/usage-context.js +35 -0
  33. package/dist-sdk/server/src/app.controller.d.ts +5 -0
  34. package/dist-sdk/server/src/app.controller.js +13 -2
  35. package/dist-sdk/server/src/app.service.d.ts +39 -4
  36. package/dist-sdk/server/src/app.service.js +40 -3
  37. package/dist-sdk/server/src/common/errors.d.ts +13 -1
  38. package/dist-sdk/server/src/common/errors.js +21 -1
  39. package/dist-sdk/server/src/packs/pack-instantiation.service.js +1 -0
  40. package/dist-sdk/server/src/packs/pack-manifest.d.ts +3 -1
  41. package/dist-sdk/server/src/packs/pack-manifest.js +2 -0
  42. package/dist-sdk/server/src/room/illustration/illustration.service.d.ts +17 -2
  43. package/dist-sdk/server/src/room/illustration/illustration.service.js +35 -9
  44. package/dist-sdk/server/src/room/illustration/illustration.types.d.ts +6 -0
  45. package/dist-sdk/server/src/room/room-config.d.ts +11 -1
  46. package/dist-sdk/server/src/room/room-store.service.js +4 -0
  47. package/dist-sdk/server/src/room/room.d.ts +9 -1
  48. package/dist-sdk/server/src/room/room.js +16 -1
  49. package/dist-sdk/server/src/sdk/index.d.ts +7 -1
  50. package/dist-sdk/server/src/sdk/index.js +19 -1
  51. package/dist-sdk/server/src/tools/core/illustrate.tool.js +10 -1
  52. package/dist-sdk/server/src/tools/native-tool.types.d.ts +3 -2
  53. package/dist-sdk/shared/types/app.types.d.ts +27 -0
  54. package/dist-sdk/shared/types/app.types.js +6 -1
  55. package/package.json +1 -1
@@ -19,7 +19,7 @@ import { ArtifactService } from './ai/artifact.service';
19
19
  import { ArtifactMetadata, ModelInfo, ImageModelOption, ChapterInfo, StoryIdea, UpdateAgentRequest } from '../../shared/types/app.types';
20
20
  import { PublishedAgentsService } from './ai/published-agents.service';
21
21
  import { PublishedRoomsService } from './room/published-rooms.service';
22
- import { BalanceService } from './app/balance.service';
22
+ import { BalanceService, CreditSummary, UsageEntry, UsageReport } from './app/balance.service';
23
23
  import { BalanceMessageService } from './app/balance-message.service';
24
24
  import { TransactionService } from './app/transaction.service';
25
25
  import { AgentFactory } from './ai/agent-factory';
@@ -28,7 +28,7 @@ import { EventEmitter } from 'events';
28
28
  import { PdfConversionOptions, PdfConversionResult } from './documents/pdf-conversion';
29
29
  import { DocumentFileType, DocumentPage, LocalConversionOptions } from './documents/document-conversion';
30
30
  import { EmbeddingOptions, EmbeddingResult } from './documents/library/embedding';
31
- import { AgentInfo, RoomInfo, RoomDetails, RoomIllustrationMode, RoomTurnMode, CreateRoomResponse, CreateAgentResponse, CreateRoomAgentRequest, FileList, PromptFileContent, PromptFoldersResponse, PromptFilesResponse, PromptScope, PromptFolderDefaults, PromptFolderDefaultsResponse, ProcessTextResponse, PreparedPromptResponse, AttachDocumentResponse, AgentMessagesResponse, RoomMessagesResponse, SendMessageResult, StoryInfo, StoryState, Character, Transaction, TransactionHistoryResponse, ToolDefinition, ToolSummary, ToolRunResult } from '../../shared/types/app.types';
31
+ import { AgentInfo, RoomInfo, RoomDetails, ImageAspect, RoomIllustrationMode, RoomTurnMode, CreateRoomResponse, CreateAgentResponse, CreateRoomAgentRequest, FileList, PromptFileContent, PromptFoldersResponse, PromptFilesResponse, PromptScope, PromptFolderDefaults, PromptFolderDefaultsResponse, ProcessTextResponse, PreparedPromptResponse, AttachDocumentResponse, AgentMessagesResponse, RoomMessagesResponse, SendMessageResult, StoryInfo, StoryState, Character, Transaction, TransactionHistoryResponse, ToolDefinition, ToolSummary, ToolRunResult } from '../../shared/types/app.types';
32
32
  import { RoomMessage } from './room/message';
33
33
  import { ToolStoreService } from './tools/tool-store.service';
34
34
  import { AgentDocumentStore, ToolExecutionService } from './tools/tool-execution.service';
@@ -527,7 +527,7 @@ export declare class AppService {
527
527
  * @param arriving An agent not yet in the room, checked as though it were.
528
528
  */
529
529
  private assertModeratorAvailable;
530
- createRoom(roomName: string, goal: string, agentIds: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, beginInstruction?: string, imageModel?: string, illustrationMode?: RoomIllustrationMode): Promise<CreateRoomResponse>;
530
+ createRoom(roomName: string, goal: string, agentIds: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, beginInstruction?: string, imageModel?: string, illustrationMode?: RoomIllustrationMode, imageAspect?: ImageAspect): Promise<CreateRoomResponse>;
531
531
  /**
532
532
  * Updates the name, goal, and/or agent membership of an existing room.
533
533
  *
@@ -549,10 +549,15 @@ export declare class AppService {
549
549
  * @param pack - The pack to file the room under. Empty string clears it.
550
550
  * @param beginInstruction - What {@link beginRoom} sends to the leader. Empty
551
551
  * string clears it, which withdraws the room's Begin. Omit to leave unchanged.
552
+ * @param imageModel - Entry in image_models.json. Empty string falls back to the
553
+ * server default. Omit to leave unchanged.
554
+ * @param illustrationMode - When the room illustrates itself. Omit to leave unchanged.
555
+ * @param imageAspect - The shape the room draws in when an `illustrate` call names
556
+ * none. Omit to leave unchanged. See {@link ImageAspect}.
552
557
  * @throws {NotFoundError} If the room does not exist
553
558
  * @throws {OperationFailedError} If attempting to edit a published room instance
554
559
  */
555
- editRoom(roomId: string, roomName: string, goal: string, baseRoomDir?: string, agentIds?: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, pack?: string, beginInstruction?: string, imageModel?: string, illustrationMode?: RoomIllustrationMode): Promise<void>;
560
+ editRoom(roomId: string, roomName: string, goal: string, baseRoomDir?: string, agentIds?: string[], roomLeader?: string, turnMode?: RoomTurnMode, moderator?: string, pack?: string, beginInstruction?: string, imageModel?: string, illustrationMode?: RoomIllustrationMode, imageAspect?: ImageAspect): Promise<void>;
556
561
  /**
557
562
  * Separates a room's name from the bare name of an agent that belongs to it.
558
563
  */
@@ -1803,6 +1808,36 @@ export declare class AppService {
1803
1808
  * @returns Current balance in dollars
1804
1809
  */
1805
1810
  getBalance(): number;
1811
+ /**
1812
+ * Starts a new allowance period for this user: the allowance becomes
1813
+ * `amount` and is spent before purchased credit; whatever was left of the
1814
+ * last allowance is gone. Applied once per `reference` (an invoice id, say),
1815
+ * so a payment confirmed twice grants once. See {@link BalanceService}.
1816
+ */
1817
+ grantAllowance(amount: number, options: {
1818
+ reference: string;
1819
+ periodStart?: Date | string;
1820
+ }): {
1821
+ granted: boolean;
1822
+ credits: CreditSummary;
1823
+ };
1824
+ /** This user's allowance, purchased credit and total available. */
1825
+ getCredits(): CreditSummary;
1826
+ /**
1827
+ * What this user's AI calls cost between two moments, with totals by user,
1828
+ * feature and day from their usage tags. Defaults to the current allowance
1829
+ * period. Pass `entries: true` for the charges themselves.
1830
+ */
1831
+ getUsage(options?: {
1832
+ from?: Date | string;
1833
+ to?: Date | string;
1834
+ entries?: boolean;
1835
+ }): UsageReport;
1836
+ /** Allowance grants and credit purchases between two moments, oldest first. */
1837
+ getCreditEvents(options?: {
1838
+ from?: Date | string;
1839
+ to?: Date | string;
1840
+ }): UsageEntry[];
1806
1841
  /**
1807
1842
  * Adds funds to the user's balance.
1808
1843
  *
@@ -884,7 +884,7 @@ class AppService {
884
884
  throw new errors_1.ValidationError(`${names} ${needsModerator.length === 1 ? 'uses' : 'use'} a moderator, ` +
885
885
  `so room "${room.getName()}" needs one. ${reason}`);
886
886
  }
887
- async createRoom(roomName, goal, agentIds, roomLeader, turnMode, moderator, beginInstruction, imageModel, illustrationMode) {
887
+ async createRoom(roomName, goal, agentIds, roomLeader, turnMode, moderator, beginInstruction, imageModel, illustrationMode, imageAspect) {
888
888
  // Validate that all agents exist before creating the room
889
889
  for (const agentId of agentIds) {
890
890
  const agent = await this.agentStore.getAgent(agentId);
@@ -919,6 +919,9 @@ class AppService {
919
919
  if (illustrationMode !== undefined) {
920
920
  room.setIllustrationMode(illustrationMode);
921
921
  }
922
+ if (imageAspect !== undefined) {
923
+ room.setImageAspect(imageAspect);
924
+ }
922
925
  // Before saveMetadata, so a room that cannot route its members' messages is
923
926
  // never written to disk.
924
927
  this.assertModeratorAvailable(room);
@@ -950,10 +953,15 @@ class AppService {
950
953
  * @param pack - The pack to file the room under. Empty string clears it.
951
954
  * @param beginInstruction - What {@link beginRoom} sends to the leader. Empty
952
955
  * string clears it, which withdraws the room's Begin. Omit to leave unchanged.
956
+ * @param imageModel - Entry in image_models.json. Empty string falls back to the
957
+ * server default. Omit to leave unchanged.
958
+ * @param illustrationMode - When the room illustrates itself. Omit to leave unchanged.
959
+ * @param imageAspect - The shape the room draws in when an `illustrate` call names
960
+ * none. Omit to leave unchanged. See {@link ImageAspect}.
953
961
  * @throws {NotFoundError} If the room does not exist
954
962
  * @throws {OperationFailedError} If attempting to edit a published room instance
955
963
  */
956
- async editRoom(roomId, roomName, goal, baseRoomDir, agentIds, roomLeader, turnMode, moderator, pack, beginInstruction, imageModel, illustrationMode) {
964
+ async editRoom(roomId, roomName, goal, baseRoomDir, agentIds, roomLeader, turnMode, moderator, pack, beginInstruction, imageModel, illustrationMode, imageAspect) {
957
965
  // Get the existing room
958
966
  const room = await this.roomStore.getRoom(roomId);
959
967
  if (!room) {
@@ -1011,6 +1019,9 @@ class AppService {
1011
1019
  if (illustrationMode !== undefined) {
1012
1020
  room.setIllustrationMode(illustrationMode);
1013
1021
  }
1022
+ if (imageAspect !== undefined) {
1023
+ room.setImageAspect(imageAspect);
1024
+ }
1014
1025
  // Catches clearing the moderator, or pointing it at an agent this edit just
1015
1026
  // removed, while a member still needs one.
1016
1027
  this.assertModeratorAvailable(room);
@@ -1276,6 +1287,7 @@ class AppService {
1276
1287
  beginInstruction: room.getBeginInstruction(),
1277
1288
  imageModel: room.getImageModel(),
1278
1289
  illustrationMode: room.getIllustrationMode(),
1290
+ imageAspect: room.getImageAspect(),
1279
1291
  baseRoomDir: room.getBaseRoomDir(),
1280
1292
  pack: room.getPack(),
1281
1293
  isPublished: room.getIsPublished(),
@@ -3405,6 +3417,31 @@ class AppService {
3405
3417
  getBalance() {
3406
3418
  return this.balanceService.getBalance();
3407
3419
  }
3420
+ /**
3421
+ * Starts a new allowance period for this user: the allowance becomes
3422
+ * `amount` and is spent before purchased credit; whatever was left of the
3423
+ * last allowance is gone. Applied once per `reference` (an invoice id, say),
3424
+ * so a payment confirmed twice grants once. See {@link BalanceService}.
3425
+ */
3426
+ grantAllowance(amount, options) {
3427
+ return this.balanceService.grantAllowance(amount, options);
3428
+ }
3429
+ /** This user's allowance, purchased credit and total available. */
3430
+ getCredits() {
3431
+ return this.balanceService.getCredits();
3432
+ }
3433
+ /**
3434
+ * What this user's AI calls cost between two moments, with totals by user,
3435
+ * feature and day from their usage tags. Defaults to the current allowance
3436
+ * period. Pass `entries: true` for the charges themselves.
3437
+ */
3438
+ getUsage(options = {}) {
3439
+ return this.balanceService.getUsage(options);
3440
+ }
3441
+ /** Allowance grants and credit purchases between two moments, oldest first. */
3442
+ getCreditEvents(options = {}) {
3443
+ return this.balanceService.getCreditEvents(options);
3444
+ }
3408
3445
  /**
3409
3446
  * Adds funds to the user's balance.
3410
3447
  *
@@ -3640,7 +3677,7 @@ class AppService {
3640
3677
  async embedTexts(texts, options = {}) {
3641
3678
  const result = await (0, embedding_1.embedTexts)(texts, options);
3642
3679
  if (result.cost > 0) {
3643
- this.balanceService.decrementBalance(result.cost, 0);
3680
+ this.balanceService.decrementBalance(result.cost, 0, { agentName: 'Embeddings' });
3644
3681
  }
3645
3682
  return result;
3646
3683
  }
@@ -23,10 +23,22 @@ export declare class ValidationError extends Error {
23
23
  export declare class OperationFailedError extends Error {
24
24
  constructor(message: string);
25
25
  }
26
+ /**
27
+ * Sets the message every {@link InsufficientBalanceError} carries, in place of
28
+ * the services' own, so a host's wording (what ran out, and where to buy more)
29
+ * reaches its users through whatever error path they see: a room's "Conversation
30
+ * paused" message, an SSE error event, a rejected promise. Pass null to go back
31
+ * to the services' messages.
32
+ */
33
+ export declare function setInsufficientBalanceMessage(message: string | null): void;
34
+ /** The host's message when one was set, else the generic one. */
35
+ export declare function insufficientBalanceMessage(): string;
26
36
  /**
27
37
  * Thrown when user has insufficient balance to perform an AI operation.
28
38
  * This error should propagate to the client to trigger a credit purchase flow.
39
+ * A host's message ({@link setInsufficientBalanceMessage}) wins over the one
40
+ * passed here, which describes the service that ran out.
29
41
  */
30
42
  export declare class InsufficientBalanceError extends Error {
31
- constructor(message: string);
43
+ constructor(message?: string);
32
44
  }
@@ -5,6 +5,8 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.InsufficientBalanceError = exports.OperationFailedError = exports.ValidationError = exports.NotFoundError = void 0;
8
+ exports.setInsufficientBalanceMessage = setInsufficientBalanceMessage;
9
+ exports.insufficientBalanceMessage = insufficientBalanceMessage;
8
10
  /**
9
11
  * Thrown when a requested resource (agent, room, story, etc.) is not found.
10
12
  * Maps to HTTP 404 Not Found in controllers.
@@ -48,13 +50,31 @@ class OperationFailedError extends Error {
48
50
  }
49
51
  }
50
52
  exports.OperationFailedError = OperationFailedError;
53
+ const DEFAULT_INSUFFICIENT_BALANCE_MESSAGE = 'Insufficient balance. Please add funds to continue using AI services.';
54
+ let hostInsufficientBalanceMessage = null;
55
+ /**
56
+ * Sets the message every {@link InsufficientBalanceError} carries, in place of
57
+ * the services' own, so a host's wording (what ran out, and where to buy more)
58
+ * reaches its users through whatever error path they see: a room's "Conversation
59
+ * paused" message, an SSE error event, a rejected promise. Pass null to go back
60
+ * to the services' messages.
61
+ */
62
+ function setInsufficientBalanceMessage(message) {
63
+ hostInsufficientBalanceMessage = message?.trim() || null;
64
+ }
65
+ /** The host's message when one was set, else the generic one. */
66
+ function insufficientBalanceMessage() {
67
+ return hostInsufficientBalanceMessage ?? DEFAULT_INSUFFICIENT_BALANCE_MESSAGE;
68
+ }
51
69
  /**
52
70
  * Thrown when user has insufficient balance to perform an AI operation.
53
71
  * This error should propagate to the client to trigger a credit purchase flow.
72
+ * A host's message ({@link setInsufficientBalanceMessage}) wins over the one
73
+ * passed here, which describes the service that ran out.
54
74
  */
55
75
  class InsufficientBalanceError extends Error {
56
76
  constructor(message) {
57
- super(message);
77
+ super(hostInsufficientBalanceMessage ?? message ?? DEFAULT_INSUFFICIENT_BALANCE_MESSAGE);
58
78
  this.name = 'InsufficientBalanceError';
59
79
  if (Error.captureStackTrace) {
60
80
  Error.captureStackTrace(this, InsufficientBalanceError);
@@ -126,6 +126,7 @@ class PackInstantiationService {
126
126
  // default model, drawing only when an agent asks.
127
127
  imageModel: template.imageModel,
128
128
  illustrationMode: template.illustrationMode ?? 'on-request',
129
+ imageAspect: template.imageAspect ?? 'square',
129
130
  });
130
131
  room.saveMetadata();
131
132
  return { roomId, agentIds, warnings };
@@ -26,7 +26,7 @@
26
26
  * `pack.json` is optional. A directory holding only `artifacts/manifest.json` is
27
27
  * still a pack, titled after itself.
28
28
  */
29
- import { PromptFolderDefaults } from '../../../shared/types/app.types';
29
+ import { ImageAspect, PromptFolderDefaults } from '../../../shared/types/app.types';
30
30
  /** Subdirectories of a pack, by what they hold. */
31
31
  export declare const PACK_SUBDIR: {
32
32
  readonly prompts: "prompts";
@@ -147,6 +147,8 @@ export interface PackRoomTemplate {
147
147
  imageModel?: string;
148
148
  /** When the room illustrates itself. Absent means `on-request`. */
149
149
  illustrationMode?: 'off' | 'on-request' | 'auto';
150
+ /** The default shape of the room's pictures. Absent means `square`. */
151
+ imageAspect?: ImageAspect;
150
152
  /**
151
153
  * The roster, as loaded.
152
154
  *
@@ -66,6 +66,7 @@ exports.readPack = readPack;
66
66
  exports.roomAgentKey = roomAgentKey;
67
67
  const fs = __importStar(require("fs"));
68
68
  const path = __importStar(require("path"));
69
+ const app_types_1 = require("../../../shared/types/app.types");
69
70
  const prompt_resolver_1 = require("../config/prompt-resolver");
70
71
  const logger_1 = require("../common/logger");
71
72
  /** Subdirectories of a pack, by what they hold. */
@@ -319,6 +320,7 @@ function validateRoomTemplate(value, file) {
319
320
  value.illustrationMode === 'auto'
320
321
  ? { illustrationMode: value.illustrationMode }
321
322
  : {}),
323
+ ...(app_types_1.IMAGE_ASPECTS.includes(value.imageAspect) && { imageAspect: value.imageAspect }),
322
324
  agents,
323
325
  ...(isValidKey(value.roomLeader) && { roomLeader: value.roomLeader }),
324
326
  ...(isValidKey(value.moderator) && { moderator: value.moderator }),
@@ -3,6 +3,7 @@ import { AgentFactory } from '../../ai/agent-factory';
3
3
  import { AgentStoreService } from '../../ai/agent-store.service';
4
4
  import { ArtifactService } from '../../ai/artifact.service';
5
5
  import { UserPathsService } from '../../config/user-paths.service';
6
+ import { ImageAspect } from '../../../../shared/types/app.types';
6
7
  import { Room } from '../room';
7
8
  import { IllustrationAgents, IllustrationRequest, IllustrationTarget } from './illustration.types';
8
9
  /**
@@ -89,11 +90,25 @@ export declare class IllustrationService {
89
90
  * nickname. The same model id can appear under both variants (GPT Image edits
90
91
  * with itself), so the caller's intent is the only reliable discriminator.
91
92
  *
93
+ * An aspect other than square is laid over the block's own properties, and its
94
+ * price replaces the block's when it names one -- a larger canvas is more output
95
+ * tokens on a model billed by the token. See {@link shapeFor}.
96
+ *
92
97
  * @param agent The artist agent whose model to look up
93
98
  * @param variant Which block of the entry the caller is about to use
99
+ * @param aspect The shape to draw in. Absent draws at the block's own size.
94
100
  * @returns The merged imageProperties, or {} when the model is not listed
95
101
  */
96
- getImageProperties(agent: Agent, variant: 'generation' | 'editing'): Record<string, any>;
102
+ getImageProperties(agent: Agent, variant: 'generation' | 'editing', aspect?: ImageAspect): Record<string, any>;
103
+ /**
104
+ * How one catalog block draws an aspect, or undefined to draw at its own size.
105
+ *
106
+ * Square is the base of every block by convention, so it never needs an
107
+ * `aspects` entry. A shape the block does not declare also draws at the base
108
+ * size, with a warning, rather than refusing: a picture in the wrong shape still
109
+ * shows the scene, and refusing would leave the request with nothing.
110
+ */
111
+ private shapeFor;
97
112
  /**
98
113
  * Creates an artist agent. Persistent and saved to disk, because its
99
114
  * accumulated `totalCost` is how image spend is reported.
@@ -150,7 +165,7 @@ export declare class IllustrationService {
150
165
  * be built on top of it.
151
166
  * @returns The stored artifact's id, or null when nothing was drawn
152
167
  */
153
- generateSceneReference(target: IllustrationTarget, sceneName: string, sceneDescription: string): Promise<string | null>;
168
+ generateSceneReference(target: IllustrationTarget, sceneName: string, sceneDescription: string, aspect?: ImageAspect): Promise<string | null>;
154
169
  /**
155
170
  * Draws the scene — the reference plus the characters in it — and posts it.
156
171
  *
@@ -276,11 +276,16 @@ let IllustrationService = class IllustrationService {
276
276
  * nickname. The same model id can appear under both variants (GPT Image edits
277
277
  * with itself), so the caller's intent is the only reliable discriminator.
278
278
  *
279
+ * An aspect other than square is laid over the block's own properties, and its
280
+ * price replaces the block's when it names one -- a larger canvas is more output
281
+ * tokens on a model billed by the token. See {@link shapeFor}.
282
+ *
279
283
  * @param agent The artist agent whose model to look up
280
284
  * @param variant Which block of the entry the caller is about to use
285
+ * @param aspect The shape to draw in. Absent draws at the block's own size.
281
286
  * @returns The merged imageProperties, or {} when the model is not listed
282
287
  */
283
- getImageProperties(agent, variant) {
288
+ getImageProperties(agent, variant, aspect) {
284
289
  try {
285
290
  const imageModels = this.readImageModels();
286
291
  const other = variant === 'editing' ? 'generation' : 'editing';
@@ -293,11 +298,12 @@ let IllustrationService = class IllustrationService {
293
298
  logger_1.logger.warn(`No image_models.json entry for "${agent.modelName}"; image generation may fail`);
294
299
  return {};
295
300
  }
301
+ const shape = this.shapeFor(agent, variantConfig, aspect);
302
+ const centsPerImage = shape?.centsPerImage ?? variantConfig.centsPerImage;
296
303
  return {
297
304
  ...(variantConfig.imageProperties ?? {}),
298
- ...(variantConfig.centsPerImage != null
299
- ? { centsPerImage: variantConfig.centsPerImage }
300
- : {}),
305
+ ...(shape?.imageProperties ?? {}),
306
+ ...(centsPerImage != null ? { centsPerImage } : {}),
301
307
  };
302
308
  }
303
309
  catch (error) {
@@ -305,6 +311,23 @@ let IllustrationService = class IllustrationService {
305
311
  return {};
306
312
  }
307
313
  }
314
+ /**
315
+ * How one catalog block draws an aspect, or undefined to draw at its own size.
316
+ *
317
+ * Square is the base of every block by convention, so it never needs an
318
+ * `aspects` entry. A shape the block does not declare also draws at the base
319
+ * size, with a warning, rather than refusing: a picture in the wrong shape still
320
+ * shows the scene, and refusing would leave the request with nothing.
321
+ */
322
+ shapeFor(agent, variantConfig, aspect) {
323
+ if (!aspect || aspect === 'square')
324
+ return undefined;
325
+ const shape = variantConfig.aspects?.[aspect];
326
+ if (!shape) {
327
+ logger_1.logger.warn(`"${agent.modelName}" has no ${aspect} shape in image_models.json; drawing at its own size`);
328
+ }
329
+ return shape;
330
+ }
308
331
  /**
309
332
  * Creates an artist agent. Persistent and saved to disk, because its
310
333
  * accumulated `totalCost` is how image spend is reported.
@@ -479,7 +502,9 @@ let IllustrationService = class IllustrationService {
479
502
  logger_1.logger.warn(`Illustrator requested another reference (${sceneAnalysis.sceneName}) after one was just created; skipping to avoid loop`);
480
503
  return false;
481
504
  }
482
- const referenceId = await this.generateSceneReference(target, sceneAnalysis.sceneName, sceneAnalysis.sceneDescription);
505
+ // In the request's shape: in a room the reference is often the picture
506
+ // that gets posted (see below), so it has to be the shape that was asked for.
507
+ const referenceId = await this.generateSceneReference(target, sceneAnalysis.sceneName, sceneAnalysis.sceneDescription, req.aspect);
483
508
  if (!referenceId)
484
509
  return false;
485
510
  const posted = await this.runIllustration(room, target, {
@@ -509,6 +534,7 @@ let IllustrationService = class IllustrationService {
509
534
  sceneName: sceneAnalysis.sceneName,
510
535
  sceneDescription: sceneAnalysis.sceneDescription,
511
536
  characterNames: sceneAnalysis.characterNames,
537
+ aspect: req.aspect,
512
538
  });
513
539
  }
514
540
  /**
@@ -516,14 +542,14 @@ let IllustrationService = class IllustrationService {
516
542
  * be built on top of it.
517
543
  * @returns The stored artifact's id, or null when nothing was drawn
518
544
  */
519
- async generateSceneReference(target, sceneName, sceneDescription) {
545
+ async generateSceneReference(target, sceneName, sceneDescription, aspect) {
520
546
  try {
521
547
  logger_1.logger.log(`Generating scene reference: ${sceneName}`);
522
548
  const agents = await this.ensureAgents(target);
523
549
  if (!agents)
524
550
  return null;
525
551
  const { artist } = agents;
526
- const imageResult = await artist.generateImage(sceneDescription, this.getImageProperties(artist, 'generation'));
552
+ const imageResult = await artist.generateImage(sceneDescription, this.getImageProperties(artist, 'generation', aspect));
527
553
  if (imageResult.error) {
528
554
  return null;
529
555
  }
@@ -563,8 +589,8 @@ let IllustrationService = class IllustrationService {
563
589
  const characterPortraitIds = this.collectPortraitIds(target, scene.characterNames || []);
564
590
  const referenceImageIds = [sceneArtifact.artifactId, ...characterPortraitIds];
565
591
  const imageResult = referenceImageIds.length && artistEdit
566
- ? await artistEdit.editImage(scene.sceneDescription, this.getImageProperties(artistEdit, 'editing'), referenceImageIds)
567
- : await artist.generateImage(scene.sceneDescription, this.getImageProperties(artist, 'generation'));
592
+ ? await artistEdit.editImage(scene.sceneDescription, this.getImageProperties(artistEdit, 'editing', scene.aspect), referenceImageIds)
593
+ : await artist.generateImage(scene.sceneDescription, this.getImageProperties(artist, 'generation', scene.aspect));
568
594
  if (imageResult.error) {
569
595
  return false;
570
596
  }
@@ -1,5 +1,6 @@
1
1
  import { Agent } from '../../ai/agent';
2
2
  import { ArtifactService } from '../../ai/artifact.service';
3
+ import { ImageAspect } from '../../../../shared/types/app.types';
3
4
  /**
4
5
  * The three agents that make a picture. None of them is ever a member of the
5
6
  * room they work for: in broadcast turn mode `selectResponders` returns every
@@ -88,6 +89,11 @@ export interface IllustrationRequest {
88
89
  brief?: string;
89
90
  /** Who or what the caller asked to be shown, by the names the room uses. */
90
91
  subjects?: string[];
92
+ /**
93
+ * The shape of the scene. A room fills this in from its own default when the
94
+ * caller names none; a story never sets it, and absent draws square.
95
+ */
96
+ aspect?: ImageAspect;
91
97
  /** Nickname of the agent that asked, for logging and the per-turn cap. */
92
98
  requestedBy?: string;
93
99
  /** Sequence number for `imageName`. A story passes its turn number. */
@@ -1,4 +1,4 @@
1
- import { RoomIllustrationMode, RoomTurnMode } from '../../../shared/types/app.types';
1
+ import { ImageAspect, RoomIllustrationMode, RoomTurnMode } from '../../../shared/types/app.types';
2
2
  /**
3
3
  * The image model that will actually draw for a room, or undefined when none will.
4
4
  *
@@ -82,6 +82,16 @@ export interface RoomConfig {
82
82
  * time. `off` refuses both.
83
83
  */
84
84
  illustrationMode?: RoomIllustrationMode;
85
+ /**
86
+ * The shape a picture is drawn in when the `illustrate` call does not name one.
87
+ *
88
+ * A default rather than a rule: an agent can ask for a wide establishing shot
89
+ * in a room that is otherwise square. Absent means `square`, which is what
90
+ * every room drew before this existed. Applies to the scenes a room posts;
91
+ * character portraits keep their model's own size, since they are references
92
+ * reused across every later scene whatever its shape.
93
+ */
94
+ imageAspect?: ImageAspect;
85
95
  }
86
96
  /**
87
97
  * Every setting a room carries, without its identity or its content.
@@ -257,6 +257,7 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
257
257
  beginInstruction: room.getBeginInstruction(),
258
258
  imageModel: room.getImageModel(),
259
259
  illustrationMode: room.getIllustrationMode(),
260
+ imageAspect: room.getImageAspect(),
260
261
  };
261
262
  }
262
263
  /**
@@ -291,6 +292,7 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
291
292
  room.setBeginInstruction(settings.beginInstruction);
292
293
  room.setImageModel(settings.imageModel);
293
294
  room.setIllustrationMode(settings.illustrationMode);
295
+ room.setImageAspect(settings.imageAspect);
294
296
  room.setRoomLeader(settings.roomLeader);
295
297
  room.setTurnMode(settings.turnMode);
296
298
  room.setModerator(settings.moderator);
@@ -504,6 +506,7 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
504
506
  room.setBeginInstruction(config.beginInstruction);
505
507
  room.setImageModel(config.imageModel);
506
508
  room.setIllustrationMode(config.illustrationMode);
509
+ room.setImageAspect(config.imageAspect);
507
510
  // Add agents to the room (loaded from adjacent agents directory)
508
511
  //
509
512
  // An id that resolves to nothing is a deleted agent the room still
@@ -583,6 +586,7 @@ let RoomStoreService = RoomStoreService_1 = class RoomStoreService {
583
586
  beginInstruction: room.getBeginInstruction(),
584
587
  imageModel: room.getImageModel(),
585
588
  illustrationMode: room.getIllustrationMode(),
589
+ imageAspect: room.getImageAspect(),
586
590
  };
587
591
  const metadataPath = path.join(roomDir, 'metadata.json');
588
592
  fs.writeFileSync(metadataPath, JSON.stringify(config, null, 2), 'utf-8');
@@ -1,5 +1,5 @@
1
1
  import { Agent } from '../ai/agent';
2
- import { RoomIllustrationMode, RoomTurnMode, SendMessageResult } from '../../../shared/types/app.types';
2
+ import { ImageAspect, RoomIllustrationMode, RoomTurnMode, SendMessageResult } from '../../../shared/types/app.types';
3
3
  import { RoomMessage } from './message';
4
4
  import { Artifact } from './artifact';
5
5
  import { ToolStoreService } from '../tools/tool-store.service';
@@ -157,6 +157,8 @@ export declare class Room {
157
157
  private imageModel;
158
158
  /** When the room illustrates itself. See {@link RoomConfig.illustrationMode}. */
159
159
  private illustrationMode;
160
+ /** The default shape of this room's pictures. See {@link RoomConfig.imageAspect}. */
161
+ private imageAspect;
160
162
  /**
161
163
  * Agents that work for this room but never take a turn in it: the illustrator
162
164
  * and the two artists.
@@ -227,6 +229,12 @@ export declare class Room {
227
229
  */
228
230
  getIllustrationMode(): RoomIllustrationMode;
229
231
  setIllustrationMode(mode: RoomIllustrationMode | undefined): void;
232
+ /**
233
+ * @returns The shape this room draws in when a request names none. Normalized
234
+ * like {@link getIllustrationMode}, so a room never given one reads as square.
235
+ */
236
+ getImageAspect(): ImageAspect;
237
+ setImageAspect(aspect: ImageAspect | undefined): void;
230
238
  /**
231
239
  * Registers an agent that works for this room without ever taking a turn.
232
240
  * Idempotent, since the illustration service resolves its agents on every call.
@@ -185,6 +185,8 @@ class Room {
185
185
  imageModel;
186
186
  /** When the room illustrates itself. See {@link RoomConfig.illustrationMode}. */
187
187
  illustrationMode = 'on-request';
188
+ /** The default shape of this room's pictures. See {@link RoomConfig.imageAspect}. */
189
+ imageAspect = 'square';
188
190
  /**
189
191
  * Agents that work for this room but never take a turn in it: the illustrator
190
192
  * and the two artists.
@@ -318,6 +320,16 @@ class Room {
318
320
  setIllustrationMode(mode) {
319
321
  this.illustrationMode = mode || 'on-request';
320
322
  }
323
+ /**
324
+ * @returns The shape this room draws in when a request names none. Normalized
325
+ * like {@link getIllustrationMode}, so a room never given one reads as square.
326
+ */
327
+ getImageAspect() {
328
+ return this.imageAspect;
329
+ }
330
+ setImageAspect(aspect) {
331
+ this.imageAspect = aspect || 'square';
332
+ }
321
333
  /**
322
334
  * Registers an agent that works for this room without ever taking a turn.
323
335
  * Idempotent, since the illustration service resolves its agents on every call.
@@ -2083,7 +2095,7 @@ Recent Message: ${message.getContent()}
2083
2095
  return counter.get(nickname) ?? 0;
2084
2096
  },
2085
2097
  perTurnLimit: Room.IMAGES_PER_TURN,
2086
- request: (brief, subjects) => {
2098
+ request: (brief, subjects, aspect) => {
2087
2099
  if (!available)
2088
2100
  return { accepted: false, reason: 'images_disabled' };
2089
2101
  const used = this.imagesThisTurn.get(nickname) ?? 0;
@@ -2103,6 +2115,8 @@ Recent Message: ${message.getContent()}
2103
2115
  situationTime: this.getSituationTime(),
2104
2116
  brief,
2105
2117
  subjects,
2118
+ // The caller's shape wins; the room's is only the default.
2119
+ aspect: aspect ?? this.getImageAspect(),
2106
2120
  requestedBy: nickname,
2107
2121
  sequence: this.roomMessages.length,
2108
2122
  allowReference: true,
@@ -2431,6 +2445,7 @@ Recent Message: ${message.getContent()}
2431
2445
  situation: this.getSituation(),
2432
2446
  situationTime: this.getSituationTime(),
2433
2447
  narration,
2448
+ aspect: this.getImageAspect(),
2434
2449
  sequence: this.roomMessages.length,
2435
2450
  allowReference: true,
2436
2451
  })
@@ -3,6 +3,12 @@ export { BriyahConfigService, BriyahConfigOptions } from './briyah-config';
3
3
  export type { AppService, AgentCreationOptions, PdfMarkdownOptions, PdfMarkdownResult, DocumentMarkdownOptions, DocumentMarkdownResult, } from '../app.service';
4
4
  export { detectDocumentType, convertLocalDocument, UnsupportedDocumentError, } from '../documents/document-conversion';
5
5
  export type { DocumentFileType, DocumentTypeDetection, DocumentPage as ConvertedDocumentPage, LocalDocumentConversion, LocalConversionOptions, } from '../documents/document-conversion';
6
+ export { detectAttachmentMimeType, isAttachmentImage, ATTACHMENT_IMAGE_TYPES, MAX_ATTACHED_IMAGE_BYTES, } from '../ai/LLM/attachment-type';
7
+ export type { AttachmentImageType } from '../ai/LLM/attachment-type';
8
+ export { runWithUsageTags, currentUsageTags } from '../app/usage-context';
9
+ export type { UsageTags } from '../app/usage-context';
10
+ export { InsufficientBalanceError, setInsufficientBalanceMessage, insufficientBalanceMessage, } from '../common/errors';
11
+ export type { AllowanceState, CreditSummary, UsageEntry, UsageReport, UsageTotal, UsageSource, } from '../app/balance.service';
6
12
  export type { DocumentSource, DocumentSummary, DocumentSearchRequest, DocumentHit, DocumentPages, DocumentPage, DocumentText, PageRange, } from '../documents/library/document.types';
7
13
  export { registerDocumentSource, unregisterDocumentSource, listDocumentSources, } from '../documents/library/document-registry';
8
14
  export { buildDocumentGuideMarkdown } from '../documents/library/document-guide.builder';
@@ -13,7 +19,7 @@ export type { EmbeddingProvider, EmbeddingOptions, EmbeddingResult } from '../do
13
19
  export { libraryAttachmentName, isLibraryAttachment, libraryDocumentIdOf, } from '../tools/core/document.tools';
14
20
  export { splitMarkdownIntoPages, stripWrappingFence, pageMarker, buildMarkdown, } from '../documents/pdf-conversion';
15
21
  export type { PdfPageMarkdown, PdfConversionOptions, PdfConversionResult, ConversionAgent, } from '../documents/pdf-conversion';
16
- export type { AgentInfo, CreateAgentResponse, RoomInfo, RoomDetails, CreateRoomResponse, StoryInfo, CreateStoryResponse, ProcessTextResponse, FileList, PromptFileContent, AttachDocumentResponse, AgentMessagesResponse, RoomMessagesResponse, RoomMessageUpdate, RoomErrorUpdate, RoomUpdate, RoomTurnMode, SendMessageResult, StoryState, Message, MessageAction, ModelInfo, ArtifactMetadata, PreparedPromptResponse, PromptScope, PromptFolder, PromptFoldersResponse, PromptFolderDefaults, PromptFolderDefaultsResponse, PromptFile, PromptFilesResponse, StoryIdea, Transaction, TransactionHistoryResponse, ToolDefinition, ToolParameter, ToolSummary, ToolsResponse, ToolRunResult, StoryStateEvent, StoryIntroduceCharacterEvent, StoryProgressChapterEvent, StoryErrorEvent, Character, ChapterInfo, } from '../../../shared/types/app.types';
22
+ export type { AgentInfo, CreateAgentResponse, RoomInfo, RoomDetails, CreateRoomResponse, StoryInfo, CreateStoryResponse, ProcessTextResponse, FileList, PromptFileContent, AttachDocumentResponse, AgentMessagesResponse, RoomMessagesResponse, RoomMessageUpdate, RoomErrorUpdate, RoomUpdate, RoomTurnMode, ImageAspect, SendMessageResult, StoryState, Message, MessageAction, ModelInfo, ArtifactMetadata, PreparedPromptResponse, PromptScope, PromptFolder, PromptFoldersResponse, PromptFolderDefaults, PromptFolderDefaultsResponse, PromptFile, PromptFilesResponse, StoryIdea, Transaction, TransactionHistoryResponse, ToolDefinition, ToolParameter, ToolSummary, ToolsResponse, ToolRunResult, StoryStateEvent, StoryIntroduceCharacterEvent, StoryProgressChapterEvent, StoryErrorEvent, Character, ChapterInfo, } from '../../../shared/types/app.types';
17
23
  export type { LoggingOptions } from './briyah-config';
18
24
  export type { NativeToolDefinition, ToolHelpers, ToolContext, ToolCaller, ToolArtifact, ToolRoomAccess, ToolPackDocuments, ToolAgentDocuments, ToolHeldDocument, ArtifactWriteOptions, } from '../tools/native-tool.types';
19
25
  export { dnd5eTools } from '../tools/packs/dnd5e';