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
@@ -13,6 +13,13 @@ export declare class AnthropicAiService extends BaseAiService {
13
13
  createAgent(userPaths: UserPathsService, configService: IConfigService, agentStoreService: AgentStoreService, balanceService: BalanceService, artifactService: ArtifactService, agentName: string, agentNickname: string, description: string, promptFolder: string, modelName: string, storageDir?: string): Agent;
14
14
  getServiceName(): string;
15
15
  supportsImageGeneration(): boolean;
16
+ supportsImageAttachments(): boolean;
17
+ /**
18
+ * An attached file as Anthropic content: a PDF as a document block, an image
19
+ * as an image block (named in a text block before it, so the model can tell
20
+ * several apart), anything else as its text.
21
+ */
22
+ private static attachedFileContent;
16
23
  supportsPromptCaching(): boolean;
17
24
  getCacheConfig(agent: Agent, cacheMessage: boolean): {
18
25
  type: string;
@@ -18,6 +18,7 @@ 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
+ const attachment_type_1 = require("./attachment-type");
21
22
  let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.BaseAiService {
22
23
  static { AnthropicAiService_1 = this; }
23
24
  anthropic;
@@ -53,6 +54,30 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
53
54
  supportsImageGeneration() {
54
55
  return false;
55
56
  }
57
+ supportsImageAttachments() {
58
+ return true;
59
+ }
60
+ /**
61
+ * An attached file as Anthropic content: a PDF as a document block, an image
62
+ * as an image block (named in a text block before it, so the model can tell
63
+ * several apart), anything else as its text.
64
+ */
65
+ static attachedFileContent(file) {
66
+ const fileData = new Uint8Array(file.serviceMetadata.fileData);
67
+ if (file.mimeType === 'application/pdf') {
68
+ return [{
69
+ type: 'document',
70
+ source: { type: 'base64', media_type: 'application/pdf', data: Buffer.from(fileData).toString('base64') },
71
+ }];
72
+ }
73
+ if ((0, attachment_type_1.isAttachmentImage)(file.mimeType)) {
74
+ return [
75
+ { type: 'text', text: `Attached image "${file.fileName}":` },
76
+ { type: 'image', source: { type: 'base64', media_type: file.mimeType, data: Buffer.from(fileData).toString('base64') } },
77
+ ];
78
+ }
79
+ return [{ type: 'text', text: `Attached file "${file.fileName}":\n\n${Buffer.from(fileData).toString('utf-8')}` }];
80
+ }
56
81
  supportsPromptCaching() {
57
82
  return true;
58
83
  }
@@ -158,30 +183,8 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
158
183
  // Build a separate message for each attached file
159
184
  for (const file of attachedFiles) {
160
185
  if (file.serviceMetadata?.fileData) {
161
- const fileData = new Uint8Array(file.serviceMetadata.fileData);
162
- let fileContent;
163
- // Anthropic only supports PDFs as documents, text files need to be converted to text
164
- if (file.mimeType === 'application/pdf') {
165
- const base64Data = Buffer.from(fileData).toString('base64');
166
- fileContent = {
167
- type: 'document',
168
- source: {
169
- type: 'base64',
170
- media_type: 'application/pdf',
171
- data: base64Data,
172
- },
173
- };
174
- }
175
- else {
176
- // For text-based files (md, txt, etc.), convert to text
177
- const textContent = Buffer.from(fileData).toString('utf-8');
178
- fileContent = {
179
- type: 'text',
180
- text: `Attached file "${file.fileName}":\n\n${textContent}`,
181
- };
182
- }
183
186
  // Each document becomes its own message
184
- documentMessages.push({ role: 'user', content: [fileContent] });
187
+ documentMessages.push({ role: 'user', content: AnthropicAiService_1.attachedFileContent(file) });
185
188
  }
186
189
  }
187
190
  // Handle attached artifacts
@@ -556,7 +559,7 @@ let AnthropicAiService = class AnthropicAiService extends base_ai_service_1.Base
556
559
  logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost.toFixed(4)}, markup: ${markup.toFixed(4)}`);
557
560
  // DECREMENT BALANCE AFTER CALL
558
561
  if (agent.balanceService && cost > 0) {
559
- agent.balanceService.decrementBalance(cost, markup);
562
+ agent.balanceService.decrementBalance(cost, markup, agent);
560
563
  }
561
564
  // Log cache metrics for monitoring
562
565
  if (cacheCreationTokens > 0 || cacheReadTokens > 0) {
@@ -0,0 +1,21 @@
1
+ /**
2
+ * What kind of file an agent is being handed, so each AI service can send it
3
+ * the way its API expects: a PDF as a document, a photo as an image, and
4
+ * anything else as text.
5
+ *
6
+ * The bytes decide first (a phone photo called "receipt.pdf" is still a JPEG),
7
+ * then the extension. HEIC (an iPhone's own photo format) is recognised so it
8
+ * can be refused with a message saying what to send instead; no AI service
9
+ * here reads it.
10
+ */
11
+ /** The image types the services that read images accept. */
12
+ export declare const ATTACHMENT_IMAGE_TYPES: readonly ["image/jpeg", "image/png", "image/gif", "image/webp"];
13
+ export type AttachmentImageType = (typeof ATTACHMENT_IMAGE_TYPES)[number];
14
+ /** Anthropic refuses an image over 5 MB (base64 makes it a third bigger again). */
15
+ export declare const MAX_ATTACHED_IMAGE_BYTES: number;
16
+ /** The MIME type of an image or PDF from its first bytes, or null when they say nothing. */
17
+ export declare function sniffAttachmentType(data: Uint8Array): string | null;
18
+ /** The MIME type an attachment is sent as: its bytes' if they identify it, else its extension's. */
19
+ export declare function detectAttachmentMimeType(fileName: string, data: Uint8Array): string;
20
+ /** True for the image types a service that reads images can be sent. */
21
+ export declare function isAttachmentImage(mimeType: string | null | undefined): mimeType is AttachmentImageType;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ /**
3
+ * What kind of file an agent is being handed, so each AI service can send it
4
+ * the way its API expects: a PDF as a document, a photo as an image, and
5
+ * anything else as text.
6
+ *
7
+ * The bytes decide first (a phone photo called "receipt.pdf" is still a JPEG),
8
+ * then the extension. HEIC (an iPhone's own photo format) is recognised so it
9
+ * can be refused with a message saying what to send instead; no AI service
10
+ * here reads it.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.MAX_ATTACHED_IMAGE_BYTES = exports.ATTACHMENT_IMAGE_TYPES = void 0;
14
+ exports.sniffAttachmentType = sniffAttachmentType;
15
+ exports.detectAttachmentMimeType = detectAttachmentMimeType;
16
+ exports.isAttachmentImage = isAttachmentImage;
17
+ /** The image types the services that read images accept. */
18
+ exports.ATTACHMENT_IMAGE_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
19
+ /** Anthropic refuses an image over 5 MB (base64 makes it a third bigger again). */
20
+ exports.MAX_ATTACHED_IMAGE_BYTES = 5 * 1024 * 1024;
21
+ const BY_EXTENSION = {
22
+ pdf: 'application/pdf',
23
+ txt: 'text/plain',
24
+ md: 'text/plain',
25
+ doc: 'application/msword',
26
+ docx: 'application/msword',
27
+ xls: 'application/vnd.ms-excel',
28
+ xlsx: 'application/vnd.ms-excel',
29
+ jpg: 'image/jpeg',
30
+ jpeg: 'image/jpeg',
31
+ png: 'image/png',
32
+ gif: 'image/gif',
33
+ webp: 'image/webp',
34
+ heic: 'image/heic',
35
+ heif: 'image/heic',
36
+ };
37
+ function startsWith(data, bytes, offset = 0) {
38
+ if (data.length < offset + bytes.length)
39
+ return false;
40
+ return bytes.every((b, i) => data[offset + i] === b);
41
+ }
42
+ function ascii(text) {
43
+ return [...text].map((c) => c.charCodeAt(0));
44
+ }
45
+ /** The MIME type of an image or PDF from its first bytes, or null when they say nothing. */
46
+ function sniffAttachmentType(data) {
47
+ if (startsWith(data, [0xff, 0xd8, 0xff]))
48
+ return 'image/jpeg';
49
+ if (startsWith(data, [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]))
50
+ return 'image/png';
51
+ if (startsWith(data, ascii('GIF87a')) || startsWith(data, ascii('GIF89a')))
52
+ return 'image/gif';
53
+ if (startsWith(data, ascii('RIFF')) && startsWith(data, ascii('WEBP'), 8))
54
+ return 'image/webp';
55
+ if (startsWith(data, ascii('%PDF-')))
56
+ return 'application/pdf';
57
+ // ISO media: "ftyp" at offset 4, then a brand. These brands are HEIC/HEIF stills.
58
+ if (startsWith(data, ascii('ftyp'), 4)) {
59
+ const brand = String.fromCharCode(...data.slice(8, 12));
60
+ if (['heic', 'heix', 'hevc', 'heim', 'heis', 'mif1', 'msf1'].includes(brand))
61
+ return 'image/heic';
62
+ }
63
+ return null;
64
+ }
65
+ /** The MIME type an attachment is sent as: its bytes' if they identify it, else its extension's. */
66
+ function detectAttachmentMimeType(fileName, data) {
67
+ const sniffed = sniffAttachmentType(data);
68
+ if (sniffed)
69
+ return sniffed;
70
+ const ext = (fileName.split('.').pop() ?? '').toLowerCase();
71
+ return BY_EXTENSION[ext] ?? 'application/octet-stream';
72
+ }
73
+ /** True for the image types a service that reads images can be sent. */
74
+ function isAttachmentImage(mimeType) {
75
+ return !!mimeType && exports.ATTACHMENT_IMAGE_TYPES.includes(mimeType);
76
+ }
@@ -27,6 +27,12 @@ export declare class BaseAiService {
27
27
  */
28
28
  getModelPricePrefix(): string | null;
29
29
  supportsImageGeneration(): boolean;
30
+ /**
31
+ * Whether attachDocument() accepts images (JPEG, PNG, GIF, WebP) for the
32
+ * model to look at. A service that says no refuses them rather than sending
33
+ * the bytes on as text.
34
+ */
35
+ supportsImageAttachments(): boolean;
30
36
  /**
31
37
  * Whether createAgent() must find the model in model_prices.json /
32
38
  * image_models.json before an agent can be created. Services whose model
@@ -51,6 +51,7 @@ const prompt_resolver_1 = require("../../config/prompt-resolver");
51
51
  const handlebars_1 = require("handlebars");
52
52
  const ai_1 = require("ai");
53
53
  const errors_1 = require("../../common/errors");
54
+ const attachment_type_1 = require("./attachment-type");
54
55
  const logger_1 = require("../../common/logger");
55
56
  const jsonrepair_1 = require("jsonrepair");
56
57
  const model_prices_1 = require("../model_prices");
@@ -88,6 +89,14 @@ let BaseAiService = class BaseAiService {
88
89
  supportsImageGeneration() {
89
90
  return false;
90
91
  }
92
+ /**
93
+ * Whether attachDocument() accepts images (JPEG, PNG, GIF, WebP) for the
94
+ * model to look at. A service that says no refuses them rather than sending
95
+ * the bytes on as text.
96
+ */
97
+ supportsImageAttachments() {
98
+ return false;
99
+ }
91
100
  /**
92
101
  * Whether createAgent() must find the model in model_prices.json /
93
102
  * image_models.json before an agent can be created. Services whose model
@@ -356,7 +365,8 @@ let BaseAiService = class BaseAiService {
356
365
  _saveResponse = true, // eslint-disable-line @typescript-eslint/no-unused-vars
357
366
  _promptInstructions = null, // eslint-disable-line @typescript-eslint/no-unused-vars
358
367
  _cacheConfig = null, // eslint-disable-line @typescript-eslint/no-unused-vars
359
- _maxOutputChars = 0) {
368
+ _maxOutputChars = 0 // eslint-disable-line @typescript-eslint/no-unused-vars
369
+ ) {
360
370
  // Check if service is available
361
371
  if (!this.isAvailable) {
362
372
  return Promise.reject(new Error(`${this.getServiceName()} service is not available. Check API key configuration.`));
@@ -497,23 +507,18 @@ let BaseAiService = class BaseAiService {
497
507
  throw new Error('Shared document attachment not supported by this service');
498
508
  }
499
509
  try {
500
- let ext = fileName.split('.').pop();
501
- let mimeType = 'application/octet-stream';
502
- // Determine MIME type based on extension
503
- if (ext.toLowerCase() === 'pdf') {
504
- mimeType = 'application/pdf';
505
- }
506
- else if (ext.toLowerCase() === 'txt') {
507
- mimeType = 'text/plain';
508
- }
509
- else if (ext.toLowerCase() === 'md') {
510
- mimeType = 'text/plain';
511
- }
512
- else if (['doc', 'docx'].includes(ext.toLowerCase())) {
513
- mimeType = 'application/msword';
510
+ // The bytes decide first (a photo named .pdf is still a photo), then the extension.
511
+ const mimeType = (0, attachment_type_1.detectAttachmentMimeType)(fileName, fileData);
512
+ if (mimeType === 'image/heic') {
513
+ throw new Error(`${fileName} is a HEIC photo, which AI services cannot read; send it as a JPEG or PNG`);
514
514
  }
515
- else if (['xls', 'xlsx'].includes(ext.toLowerCase())) {
516
- mimeType = 'application/vnd.ms-excel';
515
+ if ((0, attachment_type_1.isAttachmentImage)(mimeType)) {
516
+ if (!this.supportsImageAttachments()) {
517
+ throw new Error(`The ${this.getServiceName()} service does not read images; ${fileName} cannot be attached`);
518
+ }
519
+ if (fileData.length > attachment_type_1.MAX_ATTACHED_IMAGE_BYTES) {
520
+ throw new Error(`${fileName} is ${(fileData.length / 1048576).toFixed(1)} MB; images must be ${attachment_type_1.MAX_ATTACHED_IMAGE_BYTES / 1048576} MB or less`);
521
+ }
517
522
  }
518
523
  // Create metadata for this file and store the file data with it
519
524
  const fileMetadata = {
@@ -181,7 +181,7 @@ let ComfyUiAiService = class ComfyUiAiService extends base_ai_service_1.BaseAiSe
181
181
  agent.totalCost += cost;
182
182
  logger_1.logger.log(`Image cost for ${agent.agentName}: $${cost.toFixed(4)}`);
183
183
  if (agent.balanceService) {
184
- agent.balanceService.decrementBalance(cost, 0);
184
+ agent.balanceService.decrementBalance(cost, 0, agent);
185
185
  }
186
186
  }
187
187
  /**
@@ -49,7 +49,7 @@ export declare class DeepSeekAiService extends BaseAiService {
49
49
  * @returns A one-line description, truncated
50
50
  */
51
51
  private static describeValidationFailure;
52
- textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
52
+ textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
53
53
  /**
54
54
  * Attaches a document to the agent or as a shared document
55
55
  * @param agent The agent context (null for shared documents)
@@ -160,7 +160,8 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
160
160
  }
161
161
  async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
162
162
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
163
- _cacheConfig = null, maxOutputChars = 0) {
163
+ _cacheConfig = null, _maxOutputChars = 0 // eslint-disable-line @typescript-eslint/no-unused-vars
164
+ ) {
164
165
  // CHECK BALANCE BEFORE AI CALL (unless disabled)
165
166
  if (agent.balanceService && !agent.disableBalanceCheck) {
166
167
  const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
@@ -377,7 +378,7 @@ let DeepSeekAiService = DeepSeekAiService_1 = class DeepSeekAiService extends ba
377
378
  }
378
379
  // Decrement balance with markup
379
380
  if (agent.balanceService && cost > 0) {
380
- agent.balanceService.decrementBalance(cost, markup);
381
+ agent.balanceService.decrementBalance(cost, markup, agent);
381
382
  }
382
383
  }
383
384
  };
@@ -15,7 +15,7 @@ export declare class FalAiService extends BaseAiService {
15
15
  * @param developer Whether the message is a system instruction from the developer
16
16
  */
17
17
  addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
18
- textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
18
+ textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
19
19
  /**
20
20
  * Compute the cost of a text message with markup for Fal AI
21
21
  * Handles model name lookup with fal_ai/ prefix if needed
@@ -103,7 +103,8 @@ let FalAiService = class FalAiService extends base_ai_service_1.BaseAiService {
103
103
  }
104
104
  async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
105
105
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
106
- _cacheConfig = null, maxOutputChars = 0) {
106
+ _cacheConfig = null, _maxOutputChars = 0 // eslint-disable-line @typescript-eslint/no-unused-vars
107
+ ) {
107
108
  // CHECK BALANCE BEFORE AI CALL (unless disabled)
108
109
  if (agent.balanceService && !agent.disableBalanceCheck) {
109
110
  const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
@@ -251,7 +252,7 @@ let FalAiService = class FalAiService extends base_ai_service_1.BaseAiService {
251
252
  }
252
253
  // Decrement balance with markup
253
254
  if (agent.balanceService && cost > 0) {
254
- agent.balanceService.decrementBalance(cost, markup);
255
+ agent.balanceService.decrementBalance(cost, markup, agent);
255
256
  }
256
257
  }
257
258
  /**
@@ -283,7 +284,7 @@ let FalAiService = class FalAiService extends base_ai_service_1.BaseAiService {
283
284
  agent.totalCost += cost;
284
285
  logger_1.logger.log(`Image cost for ${agent.agentName}: $${cost.toFixed(4)}`);
285
286
  if (agent.balanceService && cost > 0) {
286
- agent.balanceService.decrementBalance(cost, 0);
287
+ agent.balanceService.decrementBalance(cost, 0, agent);
287
288
  }
288
289
  }
289
290
  async generateImage(agent, prompt, imageProperties) {
@@ -15,7 +15,7 @@ export declare class GoogleAiService extends BaseAiService {
15
15
  * @param fromSelf Whether the message was generated by this agent (true) or received from outside (false)
16
16
  */
17
17
  addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean): void;
18
- textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
18
+ textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
19
19
  generateImage(agent: Agent, prompt: string, imageProperties?: Record<string, any>): Promise<{
20
20
  artifactId?: string;
21
21
  error?: any;
@@ -81,7 +81,8 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
81
81
  }
82
82
  async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
83
83
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
84
- _cacheConfig = null, maxOutputChars = 0) {
84
+ _cacheConfig = null, _maxOutputChars = 0 // eslint-disable-line @typescript-eslint/no-unused-vars
85
+ ) {
85
86
  // CHECK BALANCE BEFORE AI CALL (unless disabled)
86
87
  if (agent.balanceService && !agent.disableBalanceCheck) {
87
88
  const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
@@ -240,7 +241,7 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
240
241
  logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost} (markup: ${markup.toFixed(4)})`);
241
242
  // Decrement balance with markup
242
243
  if (agent.balanceService && cost > 0) {
243
- agent.balanceService.decrementBalance(cost, markup);
244
+ agent.balanceService.decrementBalance(cost, markup, agent);
244
245
  }
245
246
  }
246
247
  /**
@@ -256,7 +257,7 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
256
257
  agent.totalCost += cost;
257
258
  logger_1.logger.log(`Image cost for ${agent.agentName}: $${cost.toFixed(4)}`);
258
259
  if (agent.balanceService && cost > 0)
259
- agent.balanceService.decrementBalance(cost, 0);
260
+ agent.balanceService.decrementBalance(cost, 0, agent);
260
261
  return;
261
262
  }
262
263
  logger_1.logger.warn(`No image price info found for model ${modelName}. Skipping cost tracking.`);
@@ -272,7 +273,7 @@ let GoogleAiService = class GoogleAiService extends base_ai_service_1.BaseAiServ
272
273
  logger_1.logger.log(`Cost for image generation: ${cost} (markup: ${markup.toFixed(4)})`);
273
274
  // Decrement balance with markup
274
275
  if (agent.balanceService && cost > 0) {
275
- agent.balanceService.decrementBalance(cost, markup);
276
+ agent.balanceService.decrementBalance(cost, markup, agent);
276
277
  }
277
278
  }
278
279
  /**
@@ -17,7 +17,7 @@ export declare class GrokAiService extends BaseAiService {
17
17
  */
18
18
  attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
19
19
  finishAgent(agent: Agent): Promise<void>;
20
- textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
20
+ textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
21
21
  /**
22
22
  * Adds a message to the agent history in the appropriate format for this service
23
23
  * @param agent The agent to add the message to
@@ -121,7 +121,8 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
121
121
  }
122
122
  async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
123
123
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
124
- _cacheConfig = null, maxOutputChars = 0) {
124
+ _cacheConfig = null, _maxOutputChars = 0 // eslint-disable-line @typescript-eslint/no-unused-vars
125
+ ) {
125
126
  // CHECK BALANCE BEFORE AI CALL (unless disabled)
126
127
  if (agent.balanceService && !agent.disableBalanceCheck) {
127
128
  const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
@@ -307,7 +308,7 @@ let GrokAiService = class GrokAiService extends base_ai_service_1.BaseAiService
307
308
  }
308
309
  // Decrement balance with markup
309
310
  if (agent.balanceService && cost > 0) {
310
- agent.balanceService.decrementBalance(cost, markup);
311
+ agent.balanceService.decrementBalance(cost, markup, agent);
311
312
  }
312
313
  }
313
314
  };
@@ -9,6 +9,6 @@ export declare class MockAiService extends BaseAiService {
9
9
  preparedPrompt(agent: Agent, promptFileName: string, variables: any, saveResponse?: boolean, _cacheConfig?: any): Promise<any>;
10
10
  getMockFile(promptFileName: string, prompt: string, variables: any): string;
11
11
  instructedPrompt(agent: Agent, prompt: string, promptFileName: string, variables?: any, saveResponse?: boolean, cacheConfig?: any): Promise<any>;
12
- textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, _promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
12
+ textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, _promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
13
13
  private trackMockCosts;
14
14
  }
@@ -177,7 +177,8 @@ let MockAiService = class MockAiService extends base_ai_service_1.BaseAiService
177
177
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
178
178
  _promptInstructions = null,
179
179
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
180
- _cacheConfig = null, maxOutputChars = 0) {
180
+ _cacheConfig = null, _maxOutputChars = 0 // eslint-disable-line @typescript-eslint/no-unused-vars
181
+ ) {
181
182
  // Generic mock response for direct calls
182
183
  const mockResponse = jsonSchema
183
184
  ? { action: 'SPEAK', content: 'Generic mock response' }
@@ -211,7 +212,7 @@ let MockAiService = class MockAiService extends base_ai_service_1.BaseAiService
211
212
  logger_1.logger.log(`Cost for ${agent.agentName} message: ${totalCost} (markup: ${markup.toFixed(4)})`);
212
213
  // Decrement balance with markup
213
214
  if (agent.balanceService) {
214
- await agent.balanceService.decrementBalance(totalCost, markup);
215
+ await agent.balanceService.decrementBalance(totalCost, markup, agent);
215
216
  }
216
217
  }
217
218
  };
@@ -18,10 +18,16 @@ export declare class OpenAiService extends BaseAiService {
18
18
  constructor();
19
19
  getServiceName(): string;
20
20
  supportsImageGeneration(): boolean;
21
+ supportsImageAttachments(): boolean;
22
+ /**
23
+ * An attached file sent with the request (not through a vector store): an
24
+ * image as a Responses API input_image, anything else as its text.
25
+ */
26
+ private static attachedFileMessage;
21
27
  supportsPromptCaching(): boolean;
22
28
  fetchModelsFromApi(): Promise<ModelInfo[]>;
23
29
  finishAgent(agent: Agent): Promise<void>;
24
- textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
30
+ textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
25
31
  attachDocument(agent: Agent, fileName: string, fileData: Uint8Array): Promise<string>;
26
32
  /**
27
33
  * Adds a message to the agent history in the appropriate format for this service
@@ -8,6 +8,7 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
8
8
  var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
+ var OpenAiService_1;
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.OpenAiService = void 0;
13
14
  const common_1 = require("@nestjs/common");
@@ -16,6 +17,7 @@ const base_ai_service_1 = require("./base-ai.service");
16
17
  const openai_2 = require("openai");
17
18
  const model_prices_1 = require("../model_prices");
18
19
  const errors_1 = require("../../common/errors");
20
+ const attachment_type_1 = require("./attachment-type");
19
21
  const logger_1 = require("../../common/logger");
20
22
  // Effort levels in ascending intensity. Used to pick the nearest supported
21
23
  // effort when an agent's configured value isn't allowed by a given model.
@@ -27,7 +29,7 @@ const EFFORT_ORDER = ['low', 'medium', 'high'];
27
29
  const MODEL_EFFORT_ALLOWLIST = {
28
30
  'gpt-5-pro': ['high'],
29
31
  };
30
- let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService {
32
+ let OpenAiService = OpenAiService_1 = class OpenAiService extends base_ai_service_1.BaseAiService {
31
33
  openai;
32
34
  /**
33
35
  * Returns the effort levels the given model accepts, or `null` if the
@@ -100,6 +102,26 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
100
102
  supportsImageGeneration() {
101
103
  return true;
102
104
  }
105
+ supportsImageAttachments() {
106
+ return true;
107
+ }
108
+ /**
109
+ * An attached file sent with the request (not through a vector store): an
110
+ * image as a Responses API input_image, anything else as its text.
111
+ */
112
+ static attachedFileMessage(file) {
113
+ const fileData = new Uint8Array(file.serviceMetadata.fileData);
114
+ if ((0, attachment_type_1.isAttachmentImage)(file.mimeType)) {
115
+ return {
116
+ role: 'user',
117
+ content: [
118
+ { type: 'input_text', text: `Attached image "${file.fileName}":` },
119
+ { type: 'input_image', image_url: `data:${file.mimeType};base64,${Buffer.from(fileData).toString('base64')}` },
120
+ ],
121
+ };
122
+ }
123
+ return { role: 'user', content: `File "${file.fileName}":\n\n${Buffer.from(fileData).toString('utf-8')}` };
124
+ }
103
125
  supportsPromptCaching() {
104
126
  return false;
105
127
  }
@@ -144,7 +166,9 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
144
166
  }
145
167
  async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
146
168
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
147
- _cacheConfig = null, maxOutputChars = 0) {
169
+ _cacheConfig = null,
170
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
171
+ _maxOutputChars = 0) {
148
172
  // CHECK BALANCE BEFORE AI CALL (unless disabled)
149
173
  if (agent.balanceService && !agent.disableBalanceCheck) {
150
174
  const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
@@ -167,13 +191,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
167
191
  hasVectorStoreFiles = true;
168
192
  }
169
193
  else if (file.serviceMetadata?.fileData) {
170
- // File has direct data - include it in the message
171
- const fileData = new Uint8Array(file.serviceMetadata.fileData);
172
- const textContent = Buffer.from(fileData).toString('utf-8');
173
- messages.push({
174
- role: 'user',
175
- content: `File "${file.fileName}":\n\n${textContent}`,
176
- });
194
+ messages.push(OpenAiService_1.attachedFileMessage(file));
177
195
  }
178
196
  }
179
197
  // Add message about vector store files if any exist
@@ -417,7 +435,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
417
435
  }
418
436
  // Decrement balance with markup
419
437
  if (agent.balanceService && cost > 0) {
420
- agent.balanceService.decrementBalance(cost, markup);
438
+ agent.balanceService.decrementBalance(cost, markup, agent);
421
439
  }
422
440
  }
423
441
  computeImageCost(agent, centsPerImage) {
@@ -436,7 +454,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
436
454
  agent.totalCost += cost;
437
455
  logger_1.logger.log(`Image cost for ${agent.agentName}: $${cost.toFixed(4)}`);
438
456
  if (agent.balanceService && cost > 0) {
439
- agent.balanceService.decrementBalance(cost, 0);
457
+ agent.balanceService.decrementBalance(cost, 0, agent);
440
458
  }
441
459
  }
442
460
  /**
@@ -512,7 +530,7 @@ let OpenAiService = class OpenAiService extends base_ai_service_1.BaseAiService
512
530
  }
513
531
  };
514
532
  exports.OpenAiService = OpenAiService;
515
- exports.OpenAiService = OpenAiService = __decorate([
533
+ exports.OpenAiService = OpenAiService = OpenAiService_1 = __decorate([
516
534
  (0, common_1.Injectable)(),
517
535
  __metadata("design:paramtypes", [])
518
536
  ], OpenAiService);
@@ -236,7 +236,7 @@ let SelfHostedAiService = class SelfHostedAiService extends base_ai_service_1.Ba
236
236
  agent.totalMarkup += markup;
237
237
  logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost} (markup: ${markup.toFixed(4)})`);
238
238
  if (agent.balanceService && cost > 0) {
239
- agent.balanceService.decrementBalance(cost, markup);
239
+ agent.balanceService.decrementBalance(cost, markup, agent);
240
240
  }
241
241
  }
242
242
  };
@@ -16,7 +16,7 @@ export declare class TogetherAiService extends BaseAiService {
16
16
  * @param developer Whether the message is a system instruction from the developer
17
17
  */
18
18
  addToConversationHistory(agent: Agent, message: string, fromSelf?: boolean, developer?: boolean): void;
19
- textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, maxOutputChars?: number): Promise<any>;
19
+ textPrompt(agent: Agent, prompt: string, jsonSchema?: any, saveResponse?: boolean, promptInstructions?: string, _cacheConfig?: any, _maxOutputChars?: number): Promise<any>;
20
20
  /**
21
21
  * Compute the cost of a text message with markup for Together AI
22
22
  * Together AI doesn't support prompt caching, so this is a simple calculation
@@ -87,7 +87,8 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
87
87
  }
88
88
  async textPrompt(agent, prompt, jsonSchema = null, saveResponse = true, promptInstructions = null,
89
89
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
90
- _cacheConfig = null, maxOutputChars = 0) {
90
+ _cacheConfig = null, _maxOutputChars = 0 // eslint-disable-line @typescript-eslint/no-unused-vars
91
+ ) {
91
92
  // CHECK BALANCE BEFORE AI CALL (unless disabled)
92
93
  if (agent.balanceService && !agent.disableBalanceCheck) {
93
94
  const hasSufficientBalance = agent.balanceService.hasSufficientBalance();
@@ -212,7 +213,7 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
212
213
  logger_1.logger.log(`Cost for ${agent.agentName} message: ${cost} (markup: ${markup.toFixed(4)})`);
213
214
  // Decrement balance with markup
214
215
  if (agent.balanceService && cost > 0) {
215
- agent.balanceService.decrementBalance(cost, markup);
216
+ agent.balanceService.decrementBalance(cost, markup, agent);
216
217
  }
217
218
  }
218
219
  /**
@@ -229,7 +230,7 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
229
230
  agent.totalCost += cost;
230
231
  logger_1.logger.log(`Image cost for ${agent.agentName}: $${cost.toFixed(4)}`);
231
232
  if (agent.balanceService && cost > 0)
232
- agent.balanceService.decrementBalance(cost, 0);
233
+ agent.balanceService.decrementBalance(cost, 0, agent);
233
234
  return;
234
235
  }
235
236
  logger_1.logger.warn(`No price info found for model ${agent.modelName}. Skipping cost tracking.`);
@@ -290,7 +291,7 @@ let TogetherAiService = class TogetherAiService extends base_ai_service_1.BaseAi
290
291
  logger_1.logger.log(`Cost for image generation: ${cost} (markup: ${markup.toFixed(4)})`);
291
292
  // Decrement balance with markup
292
293
  if (agent.balanceService && cost > 0) {
293
- agent.balanceService.decrementBalance(cost, markup);
294
+ agent.balanceService.decrementBalance(cost, markup, agent);
294
295
  }
295
296
  }
296
297
  /**