@lobehub/chat 1.134.7 → 1.135.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.
Files changed (64) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/changelog/v1.json +18 -0
  3. package/locales/ar/chat.json +2 -2
  4. package/locales/ar/models.json +3 -0
  5. package/locales/bg-BG/chat.json +2 -2
  6. package/locales/bg-BG/models.json +3 -0
  7. package/locales/de-DE/chat.json +2 -2
  8. package/locales/de-DE/models.json +3 -0
  9. package/locales/en-US/chat.json +2 -2
  10. package/locales/en-US/models.json +3 -0
  11. package/locales/es-ES/chat.json +2 -2
  12. package/locales/es-ES/models.json +3 -0
  13. package/locales/fa-IR/chat.json +2 -2
  14. package/locales/fa-IR/models.json +3 -0
  15. package/locales/fr-FR/chat.json +2 -2
  16. package/locales/fr-FR/models.json +3 -0
  17. package/locales/it-IT/chat.json +2 -2
  18. package/locales/it-IT/models.json +3 -0
  19. package/locales/ja-JP/chat.json +2 -2
  20. package/locales/ja-JP/models.json +3 -0
  21. package/locales/ko-KR/chat.json +2 -2
  22. package/locales/ko-KR/models.json +3 -0
  23. package/locales/nl-NL/chat.json +2 -2
  24. package/locales/nl-NL/models.json +3 -0
  25. package/locales/pl-PL/chat.json +2 -2
  26. package/locales/pl-PL/models.json +3 -0
  27. package/locales/pt-BR/chat.json +2 -2
  28. package/locales/pt-BR/models.json +3 -0
  29. package/locales/ru-RU/chat.json +2 -2
  30. package/locales/ru-RU/models.json +3 -0
  31. package/locales/tr-TR/chat.json +2 -2
  32. package/locales/tr-TR/models.json +3 -0
  33. package/locales/vi-VN/chat.json +2 -2
  34. package/locales/vi-VN/models.json +3 -0
  35. package/locales/zh-CN/chat.json +2 -2
  36. package/locales/zh-CN/models.json +3 -0
  37. package/locales/zh-TW/chat.json +2 -2
  38. package/locales/zh-TW/models.json +3 -0
  39. package/next.config.ts +5 -6
  40. package/package.json +1 -1
  41. package/packages/context-engine/src/tools/ToolsEngine.ts +27 -5
  42. package/packages/context-engine/src/tools/__tests__/ToolsEngine.test.ts +89 -0
  43. package/packages/model-bank/src/aiModels/fal.ts +28 -0
  44. package/packages/model-runtime/src/core/openaiCompatibleFactory/createImage.ts +16 -27
  45. package/packages/model-runtime/src/core/openaiCompatibleFactory/index.test.ts +51 -11
  46. package/packages/model-runtime/src/core/streams/protocol.ts +2 -15
  47. package/packages/model-runtime/src/providers/fal/index.ts +12 -7
  48. package/packages/model-runtime/src/providers/newapi/index.test.ts +28 -3
  49. package/packages/model-runtime/src/providers/newapi/index.ts +34 -88
  50. package/packages/model-runtime/src/types/index.ts +0 -1
  51. package/packages/types/src/message/base.ts +1 -0
  52. package/packages/utils/package.json +2 -1
  53. package/src/app/[variants]/(main)/chat/(workspace)/@conversation/features/ChatList/WelcomeChatItem/index.tsx +1 -17
  54. package/src/app/[variants]/(main)/chat/(workspace)/@conversation/features/ChatMinimap/index.tsx +7 -4
  55. package/src/app/[variants]/(main)/chat/@session/features/SessionListContent/List/Item/index.tsx +16 -17
  56. package/src/app/[variants]/(main)/chat/@session/features/SessionListContent/ListItem/index.tsx +2 -2
  57. package/src/app/[variants]/(main)/image/@menu/components/SizeSelect/index.tsx +24 -1
  58. package/src/features/Conversation/Messages/Assistant/Tool/Inspector/BuiltinPluginTitle.tsx +15 -17
  59. package/src/features/Conversation/Messages/Assistant/Tool/Inspector/ToolTitle.tsx +5 -7
  60. package/src/features/Conversation/Messages/Assistant/Tool/Render/Arguments/index.tsx +1 -8
  61. package/src/locales/default/chat.ts +2 -2
  62. package/src/server/modules/EdgeConfig/index.ts +15 -33
  63. package/src/server/modules/EdgeConfig/types.ts +13 -0
  64. package/packages/model-runtime/src/types/usage.ts +0 -27
@@ -206,6 +206,95 @@ describe('ToolsEngine', () => {
206
206
  { id: 'non-existent', reason: 'not_found' },
207
207
  ]);
208
208
  });
209
+
210
+ it('should filter all plugins as incompatible when function calling is not supported', () => {
211
+ const mockFunctionCallChecker = vi.fn().mockReturnValue(false);
212
+ const engine = new ToolsEngine({
213
+ manifestSchemas: [mockWebBrowsingManifest, mockDalleManifest],
214
+ functionCallChecker: mockFunctionCallChecker,
215
+ });
216
+
217
+ const result = engine.generateToolsDetailed({
218
+ toolIds: ['lobe-web-browsing', 'dalle'],
219
+ model: 'gpt-5-chat-latest',
220
+ provider: 'openai',
221
+ });
222
+
223
+ expect(mockFunctionCallChecker).toHaveBeenCalledWith('gpt-5-chat-latest', 'openai');
224
+ expect(result.tools).toBeUndefined();
225
+ expect(result.enabledToolIds).toEqual([]);
226
+ expect(result.filteredTools).toEqual([
227
+ { id: 'lobe-web-browsing', reason: 'incompatible' },
228
+ { id: 'dalle', reason: 'incompatible' },
229
+ ]);
230
+ });
231
+
232
+ it('should combine incompatible and not_found reasons when FC is not supported', () => {
233
+ const engine = new ToolsEngine({
234
+ manifestSchemas: [mockWebBrowsingManifest],
235
+ functionCallChecker: () => false,
236
+ });
237
+
238
+ const result = engine.generateToolsDetailed({
239
+ toolIds: ['lobe-web-browsing', 'non-existent', 'dalle'],
240
+ model: 'gpt-5-chat-latest',
241
+ provider: 'openai',
242
+ });
243
+
244
+ expect(result.tools).toBeUndefined();
245
+ expect(result.enabledToolIds).toEqual([]);
246
+ expect(result.filteredTools).toEqual([
247
+ { id: 'lobe-web-browsing', reason: 'incompatible' },
248
+ { id: 'non-existent', reason: 'not_found' },
249
+ { id: 'dalle', reason: 'not_found' },
250
+ ]);
251
+ });
252
+
253
+ it('should still call enableChecker when FC is supported', () => {
254
+ const mockEnableChecker = vi.fn().mockReturnValue(false);
255
+ const engine = new ToolsEngine({
256
+ manifestSchemas: [mockWebBrowsingManifest, mockDalleManifest],
257
+ enableChecker: mockEnableChecker,
258
+ functionCallChecker: () => true,
259
+ });
260
+
261
+ const result = engine.generateToolsDetailed({
262
+ toolIds: ['lobe-web-browsing', 'dalle'],
263
+ model: 'gpt-4',
264
+ provider: 'openai',
265
+ });
266
+
267
+ expect(mockEnableChecker).toHaveBeenCalledTimes(2);
268
+ expect(result.tools).toBeUndefined();
269
+ expect(result.enabledToolIds).toEqual([]);
270
+ expect(result.filteredTools).toEqual([
271
+ { id: 'lobe-web-browsing', reason: 'disabled' },
272
+ { id: 'dalle', reason: 'disabled' },
273
+ ]);
274
+ });
275
+
276
+ it('should not call enableChecker when FC is not supported', () => {
277
+ const mockEnableChecker = vi.fn().mockReturnValue(true);
278
+ const engine = new ToolsEngine({
279
+ manifestSchemas: [mockWebBrowsingManifest, mockDalleManifest],
280
+ enableChecker: mockEnableChecker,
281
+ functionCallChecker: () => false,
282
+ });
283
+
284
+ const result = engine.generateToolsDetailed({
285
+ toolIds: ['lobe-web-browsing', 'dalle'],
286
+ model: 'gpt-5-chat-latest',
287
+ provider: 'openai',
288
+ });
289
+
290
+ expect(mockEnableChecker).not.toHaveBeenCalled();
291
+ expect(result.tools).toBeUndefined();
292
+ expect(result.enabledToolIds).toEqual([]);
293
+ expect(result.filteredTools).toEqual([
294
+ { id: 'lobe-web-browsing', reason: 'incompatible' },
295
+ { id: 'dalle', reason: 'incompatible' },
296
+ ]);
297
+ });
209
298
  });
210
299
 
211
300
  describe('plugin management', () => {
@@ -79,6 +79,34 @@ const falImageModels: AIImageModelCard[] = [
79
79
  releasedAt: '2025-09-09',
80
80
  type: 'image',
81
81
  },
82
+ {
83
+ description: '一个强大的原生多模态图像生成模型',
84
+ displayName: 'HunyuanImage 3.0',
85
+ enabled: true,
86
+ id: 'fal-ai/hunyuan-image/v3',
87
+ parameters: {
88
+ cfg: { default: 7.5, max: 20, min: 1, step: 0.1 },
89
+ prompt: { default: '' },
90
+ seed: { default: null },
91
+ size: {
92
+ default: 'square_hd',
93
+ enum: [
94
+ 'square_hd',
95
+ 'square',
96
+ 'portrait_4_3',
97
+ 'portrait_16_9',
98
+ 'landscape_4_3',
99
+ 'landscape_16_9',
100
+ ],
101
+ },
102
+ steps: { default: 28, max: 50, min: 1, step: 1 },
103
+ },
104
+ pricing: {
105
+ units: [{ name: 'imageGeneration', rate: 0.1, strategy: 'fixed', unit: 'megapixel' }],
106
+ },
107
+ releasedAt: '2025-09-28',
108
+ type: 'image',
109
+ },
82
110
  {
83
111
  description: '专注于图像编辑任务的FLUX.1模型,支持文本和图像输入。',
84
112
  displayName: 'FLUX.1 Kontext [dev]',
@@ -1,3 +1,4 @@
1
+ import { cleanObject } from '@lobechat/utils/object';
1
2
  import createDebug from 'debug';
2
3
  import { RuntimeImageGenParamsValue } from 'model-bank';
3
4
  import OpenAI from 'openai';
@@ -34,24 +35,25 @@ async function generateByImageMode(
34
35
  value,
35
36
  ]),
36
37
  );
38
+ // unify image input to array
39
+ if (typeof userInput.image === 'string' && userInput.image.trim() !== '') {
40
+ userInput.image = [userInput.image];
41
+ }
37
42
 
38
43
  // https://platform.openai.com/docs/api-reference/images/createEdit
39
44
  const isImageEdit = Array.isArray(userInput.image) && userInput.image.length > 0;
45
+ log('isImageEdit: %O, userInput.image: %O', isImageEdit, userInput.image);
40
46
  // If there are imageUrls parameters, convert them to File objects
41
47
  if (isImageEdit) {
42
- log('Converting imageUrls to File objects: %O', userInput.image);
43
48
  try {
44
49
  // Convert all image URLs to File objects
45
50
  const imageFiles = await Promise.all(
46
51
  userInput.image.map((url: string) => convertImageUrlToFile(url)),
47
52
  );
48
53
 
49
- log('Successfully converted %d images to File objects', imageFiles.length);
50
-
51
54
  // According to official docs, if there are multiple images, pass an array; if only one, pass a single File
52
55
  userInput.image = imageFiles.length === 1 ? imageFiles[0] : imageFiles;
53
56
  } catch (error) {
54
- log('Error converting imageUrls to File objects: %O', error);
55
57
  throw new Error(`Failed to convert image URLs to File objects: ${error}`);
56
58
  }
57
59
  } else {
@@ -68,11 +70,11 @@ async function generateByImageMode(
68
70
  ...(isImageEdit ? { input_fidelity: 'high' } : {}),
69
71
  };
70
72
 
71
- const options = {
73
+ const options = cleanObject({
72
74
  model,
73
75
  ...defaultInput,
74
76
  ...userInput,
75
- };
77
+ });
76
78
 
77
79
  log('options: %O', options);
78
80
 
@@ -83,13 +85,11 @@ async function generateByImageMode(
83
85
 
84
86
  // Check the integrity of response data
85
87
  if (!img || !img.data || !Array.isArray(img.data) || img.data.length === 0) {
86
- log('Invalid image response: missing data array');
87
88
  throw new Error('Invalid image response: missing or empty data array');
88
89
  }
89
90
 
90
91
  const imageData = img.data[0];
91
92
  if (!imageData) {
92
- log('Invalid image response: first data item is null/undefined');
93
93
  throw new Error('Invalid image response: first data item is null or undefined');
94
94
  }
95
95
 
@@ -111,12 +111,9 @@ async function generateByImageMode(
111
111
  }
112
112
  // If neither format exists, throw error
113
113
  else {
114
- log('Invalid image response: missing both b64_json and url fields');
115
114
  throw new Error('Invalid image response: missing both b64_json and url fields');
116
115
  }
117
116
 
118
- log('provider: %s', provider);
119
-
120
117
  return {
121
118
  imageUrl,
122
119
  ...(img.usage
@@ -180,7 +177,6 @@ async function generateByChatModel(
180
177
  });
181
178
  log('Successfully processed image URL for chat input');
182
179
  } catch (error) {
183
- log('Error processing image URL: %O', error);
184
180
  throw new Error(`Failed to process image URL: ${error}`);
185
181
  }
186
182
  }
@@ -218,7 +214,6 @@ async function generateByChatModel(
218
214
  }
219
215
 
220
216
  // If no images found, throw error
221
- log('No images found in chat completion response');
222
217
  throw new Error('No image generated in chat completion response');
223
218
  }
224
219
 
@@ -228,21 +223,15 @@ async function generateByChatModel(
228
223
  export async function createOpenAICompatibleImage(
229
224
  client: OpenAI,
230
225
  payload: CreateImagePayload,
231
- provider: string, // eslint-disable-line @typescript-eslint/no-unused-vars
226
+ provider: string,
232
227
  ): Promise<CreateImageResponse> {
233
- try {
234
- const { model } = payload;
235
-
236
- // Check if it's a chat model for image generation (via :image suffix)
237
- if (model.endsWith(':image')) {
238
- return await generateByChatModel(client, payload);
239
- }
228
+ const { model } = payload;
240
229
 
241
- // Default to traditional images API
242
- return await generateByImageMode(client, payload, provider);
243
- } catch (error) {
244
- const err = error as Error;
245
- log('Error in createImage: %O', err);
246
- throw err;
230
+ // Check if it's a chat model for image generation (via :image suffix)
231
+ if (model.endsWith(':image')) {
232
+ return await generateByChatModel(client, payload);
247
233
  }
234
+
235
+ // Default to traditional images API
236
+ return await generateByImageMode(client, payload, provider);
248
237
  }
@@ -296,6 +296,8 @@ describe('LobeOpenAICompatibleFactory', () => {
296
296
  });
297
297
 
298
298
  it('should transform non-streaming response to stream correctly', async () => {
299
+ vi.useFakeTimers();
300
+
299
301
  const mockResponse = {
300
302
  id: 'a',
301
303
  object: 'chat.completion',
@@ -319,13 +321,18 @@ describe('LobeOpenAICompatibleFactory', () => {
319
321
  mockResponse as any,
320
322
  );
321
323
 
322
- const result = await instance.chat({
324
+ const chatPromise = instance.chat({
323
325
  messages: [{ content: 'Hello', role: 'user' }],
324
326
  model: 'mistralai/mistral-7b-instruct:free',
325
327
  temperature: 0,
326
328
  stream: false,
327
329
  });
328
330
 
331
+ // Advance time to simulate processing delay
332
+ vi.advanceTimersByTime(10);
333
+
334
+ const result = await chatPromise;
335
+
329
336
  const decoder = new TextDecoder();
330
337
  const reader = result.body!.getReader();
331
338
  const stream: string[] = [];
@@ -345,16 +352,20 @@ describe('LobeOpenAICompatibleFactory', () => {
345
352
  'data: {"inputTextTokens":5,"outputTextTokens":5,"totalInputTokens":5,"totalOutputTokens":5,"totalTokens":10}\n\n',
346
353
  'id: output_speed\n',
347
354
  'event: speed\n',
348
- expect.stringMatching(/^data: \{.*"tps":.*,"ttft":.*}\n\n$/), // tps ttft 测试结果不一样
355
+ expect.stringMatching(/^data: \{.*"tps":.*,"ttft":.*}\n\n$/), // tps ttft should be calculated with elapsed time
349
356
  'id: a\n',
350
357
  'event: stop\n',
351
358
  'data: "stop"\n\n',
352
359
  ]);
353
360
 
354
361
  expect((await reader.read()).done).toBe(true);
362
+
363
+ vi.useRealTimers();
355
364
  });
356
365
 
357
366
  it('should transform non-streaming response to stream correctly with reasoning content', async () => {
367
+ vi.useFakeTimers();
368
+
358
369
  const mockResponse = {
359
370
  id: 'a',
360
371
  object: 'chat.completion',
@@ -382,13 +393,18 @@ describe('LobeOpenAICompatibleFactory', () => {
382
393
  mockResponse as any,
383
394
  );
384
395
 
385
- const result = await instance.chat({
396
+ const chatPromise = instance.chat({
386
397
  messages: [{ content: 'Hello', role: 'user' }],
387
398
  model: 'deepseek/deepseek-reasoner',
388
399
  temperature: 0,
389
400
  stream: false,
390
401
  });
391
402
 
403
+ // Advance time to simulate processing delay
404
+ vi.advanceTimersByTime(10);
405
+
406
+ const result = await chatPromise;
407
+
392
408
  const decoder = new TextDecoder();
393
409
  const reader = result.body!.getReader();
394
410
  const stream: string[] = [];
@@ -411,13 +427,15 @@ describe('LobeOpenAICompatibleFactory', () => {
411
427
  'data: {"inputTextTokens":5,"outputTextTokens":5,"totalInputTokens":5,"totalOutputTokens":5,"totalTokens":10}\n\n',
412
428
  'id: output_speed\n',
413
429
  'event: speed\n',
414
- expect.stringMatching(/^data: \{.*"tps":.*,"ttft":.*}\n\n$/), // tps ttft 测试结果不一样
430
+ expect.stringMatching(/^data: \{.*"tps":.*,"ttft":.*}\n\n$/), // tps ttft should be calculated with elapsed time
415
431
  'id: a\n',
416
432
  'event: stop\n',
417
433
  'data: "stop"\n\n',
418
434
  ]);
419
435
 
420
436
  expect((await reader.read()).done).toBe(true);
437
+
438
+ vi.useRealTimers();
421
439
  });
422
440
  });
423
441
 
@@ -974,7 +992,11 @@ describe('LobeOpenAICompatibleFactory', () => {
974
992
  .spyOn(inst['client'].responses, 'create')
975
993
  .mockResolvedValue({ tee: () => [prod, debug] } as any);
976
994
 
977
- await inst.chat({ messages: [{ content: 'hi', role: 'user' }], model: 'any-model', temperature: 0 });
995
+ await inst.chat({
996
+ messages: [{ content: 'hi', role: 'user' }],
997
+ model: 'any-model',
998
+ temperature: 0,
999
+ });
978
1000
 
979
1001
  expect(mockResponsesCreate).toHaveBeenCalled();
980
1002
  });
@@ -990,20 +1012,38 @@ describe('LobeOpenAICompatibleFactory', () => {
990
1012
  const inst = new LobeMockProviderUseResponseModels({ apiKey: 'test' });
991
1013
  const spy = vi.spyOn(inst['client'].responses, 'create');
992
1014
  // Prevent hanging by mocking normal chat completion stream
993
- vi.spyOn(inst['client'].chat.completions, 'create').mockResolvedValue(new ReadableStream() as any);
1015
+ vi.spyOn(inst['client'].chat.completions, 'create').mockResolvedValue(
1016
+ new ReadableStream() as any,
1017
+ );
994
1018
 
995
1019
  // First invocation: model contains the string
996
- spy.mockResolvedValueOnce({ tee: () => [new ReadableStream(), new ReadableStream()] } as any);
997
- await inst.chat({ messages: [{ content: 'hi', role: 'user' }], model: 'prefix-special-model-suffix', temperature: 0 });
1020
+ spy.mockResolvedValueOnce({
1021
+ tee: () => [new ReadableStream(), new ReadableStream()],
1022
+ } as any);
1023
+ await inst.chat({
1024
+ messages: [{ content: 'hi', role: 'user' }],
1025
+ model: 'prefix-special-model-suffix',
1026
+ temperature: 0,
1027
+ });
998
1028
  expect(spy).toHaveBeenCalledTimes(1);
999
1029
 
1000
1030
  // Second invocation: model matches the RegExp
1001
- spy.mockResolvedValueOnce({ tee: () => [new ReadableStream(), new ReadableStream()] } as any);
1002
- await inst.chat({ messages: [{ content: 'hi', role: 'user' }], model: 'special-xyz', temperature: 0 });
1031
+ spy.mockResolvedValueOnce({
1032
+ tee: () => [new ReadableStream(), new ReadableStream()],
1033
+ } as any);
1034
+ await inst.chat({
1035
+ messages: [{ content: 'hi', role: 'user' }],
1036
+ model: 'special-xyz',
1037
+ temperature: 0,
1038
+ });
1003
1039
  expect(spy).toHaveBeenCalledTimes(2);
1004
1040
 
1005
1041
  // Third invocation: model does not match any useResponseModels patterns
1006
- await inst.chat({ messages: [{ content: 'hi', role: 'user' }], model: 'unrelated-model', temperature: 0 });
1042
+ await inst.chat({
1043
+ messages: [{ content: 'hi', role: 'user' }],
1044
+ model: 'unrelated-model',
1045
+ temperature: 0,
1046
+ });
1007
1047
  expect(spy).toHaveBeenCalledTimes(2); // Ensure no additional calls were made
1008
1048
  });
1009
1049
  });
@@ -384,7 +384,6 @@ export const createTokenSpeedCalculator = (
384
384
  }: { enableStreaming?: boolean; inputStartAt?: number; streamStack?: StreamContext } = {},
385
385
  ) => {
386
386
  let outputStartAt: number | undefined;
387
- let outputThinking: boolean | undefined;
388
387
 
389
388
  const process = (chunk: StreamProtocolChunk) => {
390
389
  let result = [chunk];
@@ -393,24 +392,12 @@ export const createTokenSpeedCalculator = (
393
392
  outputStartAt = Date.now();
394
393
  }
395
394
 
396
- /**
397
- * 部分 provider 在正式输出 reasoning 前,可能会先输出 content 为空字符串的 chunk,
398
- * 其中 reasoning 可能为 null,会导致判断是否输出思考内容错误,所以过滤掉 null 或者空字符串。
399
- * 也可能是某些特殊 token,所以不修改 outputStartAt 的逻辑。
400
- */
401
- if (
402
- outputThinking === undefined &&
403
- (chunk.type === 'text' || chunk.type === 'reasoning') &&
404
- typeof chunk.data === 'string' &&
405
- chunk.data.length > 0
406
- ) {
407
- outputThinking = chunk.type === 'reasoning';
408
- }
409
395
  // if the chunk is the stop chunk, set as output finish
410
396
  if (inputStartAt && outputStartAt && chunk.type === 'usage') {
411
397
  // TPS should always include all generated tokens (including reasoning tokens)
412
398
  // because it measures generation speed, not just visible content
413
- const outputTokens = chunk.data?.totalOutputTokens ?? 0;
399
+ const usage = chunk.data as ModelUsage;
400
+ const outputTokens = usage?.totalOutputTokens ?? 0;
414
401
  const now = Date.now();
415
402
  const elapsed = now - (enableStreaming ? outputStartAt : inputStartAt);
416
403
  const duration = now - outputStartAt;
@@ -33,6 +33,7 @@ export class LobeFalAI implements LobeRuntimeAI {
33
33
  ['cfg', 'guidance_scale'],
34
34
  ['imageUrl', 'image_url'],
35
35
  ['imageUrls', 'image_urls'],
36
+ ['size', 'image_size'],
36
37
  ]);
37
38
 
38
39
  const defaultInput: Record<string, unknown> = {
@@ -50,12 +51,16 @@ export class LobeFalAI implements LobeRuntimeAI {
50
51
  );
51
52
 
52
53
  if ('width' in userInput && 'height' in userInput) {
53
- userInput.image_size = {
54
- height: userInput.height,
55
- width: userInput.width,
56
- };
57
- delete userInput.width;
58
- delete userInput.height;
54
+ if (userInput.size) {
55
+ throw new Error('width/height and size are not supported at the same time');
56
+ } else {
57
+ userInput.image_size = {
58
+ height: userInput.height,
59
+ width: userInput.width,
60
+ };
61
+ delete userInput.width;
62
+ delete userInput.height;
63
+ }
59
64
  }
60
65
 
61
66
  const modelsAcceleratedByDefault = new Set<string>(['flux/krea']);
@@ -66,7 +71,7 @@ export class LobeFalAI implements LobeRuntimeAI {
66
71
  // Ensure model has fal-ai/ prefix
67
72
  let endpoint = model.startsWith('fal-ai/') ? model : `fal-ai/${model}`;
68
73
  const hasImageUrls = (params.imageUrls?.length ?? 0) > 0;
69
- if (endpoint === 'fal-ai/bytedance/seedream/v4') {
74
+ if (['fal-ai/bytedance/seedream/v4', 'fal-ai/hunyuan-image/v3'].includes(endpoint)) {
70
75
  endpoint += hasImageUrls ? '/edit' : '/text-to-image';
71
76
  } else if (endpoint === 'fal-ai/nano-banana' && hasImageUrls) {
72
77
  endpoint += '/edit';
@@ -563,7 +563,22 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
563
563
 
564
564
  if (inputPrice !== undefined) {
565
565
  const outputPrice = inputPrice * (pricing.completion_ratio || 1);
566
- enhancedModel.pricing = { input: inputPrice, output: outputPrice };
566
+ enhancedModel.pricing = {
567
+ units: [
568
+ {
569
+ name: 'textInput',
570
+ unit: 'millionTokens',
571
+ strategy: 'fixed',
572
+ rate: inputPrice,
573
+ },
574
+ {
575
+ name: 'textOutput',
576
+ unit: 'millionTokens',
577
+ strategy: 'fixed',
578
+ rate: outputPrice,
579
+ },
580
+ ],
581
+ };
567
582
  }
568
583
  }
569
584
 
@@ -582,8 +597,18 @@ describe('NewAPI Runtime - 100% Branch Coverage', () => {
582
597
  });
583
598
 
584
599
  // Verify pricing results
585
- expect(enrichedModels[0].pricing).toEqual({ input: 40, output: 120 }); // model_price * 2, input * completion_ratio
586
- expect(enrichedModels[1].pricing).toEqual({ input: 10, output: 10 }); // model_ratio * 2, input * 1 (default)
600
+ expect(enrichedModels[0].pricing).toEqual({
601
+ units: [
602
+ { name: 'textInput', unit: 'millionTokens', strategy: 'fixed', rate: 40 },
603
+ { name: 'textOutput', unit: 'millionTokens', strategy: 'fixed', rate: 120 },
604
+ ],
605
+ }); // model_price * 2, input * completion_ratio
606
+ expect(enrichedModels[1].pricing).toEqual({
607
+ units: [
608
+ { name: 'textInput', unit: 'millionTokens', strategy: 'fixed', rate: 10 },
609
+ { name: 'textOutput', unit: 'millionTokens', strategy: 'fixed', rate: 10 },
610
+ ],
611
+ }); // model_ratio * 2, input * 1 (default)
587
612
  expect(enrichedModels[2].pricing).toBeUndefined(); // quota_type = 1, skipped
588
613
 
589
614
  // Verify provider detection