@shun-js/aibaiban-server 1.3.8 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shun-js/aibaiban-server",
3
- "version": "1.3.8",
3
+ "version": "1.4.0",
4
4
  "description": "aibaiban.com server",
5
5
  "keywords": [
6
6
  "ai aibaiban"
@@ -37,7 +37,7 @@
37
37
  "qiao-z-nuser": "^6.0.0",
38
38
  "qiao-z-service": "^6.0.0",
39
39
  "qiao-z-sms": "^6.0.0",
40
- "viho-llm": "^1.0.9",
40
+ "viho-llm": "^1.1.0",
41
41
  "zod": "^4.3.6",
42
42
  "zod-to-json-schema": "^3.25.1"
43
43
  },
@@ -45,5 +45,5 @@
45
45
  "access": "public",
46
46
  "registry": "https://registry.npmjs.org/"
47
47
  },
48
- "gitHead": "e91cb46c02d591ce3bddd89e452abb089ca31dc5"
48
+ "gitHead": "c5efdb11f9e3d5fb520d76ec8e752eb6474effaf"
49
49
  }
@@ -1,5 +1,5 @@
1
1
  // llm
2
- const { OpenAIAPI, runAgents } = require('viho-llm');
2
+ const { OpenAIAPI, LibLibAPI, runAgents } = require('viho-llm');
3
3
  const prompts = require('../util/prompt-agent.js');
4
4
 
5
5
  // util
@@ -12,8 +12,9 @@ const llm = OpenAIAPI(finalLLMConfig);
12
12
  const modelName = finalLLMConfig.modelName;
13
13
  const thinking = finalLLMConfig.thinking;
14
14
 
15
- // 图片生成配置
15
+ // 图片生成配置 (LibLib)
16
16
  const imageGenConfig = global.QZ_CONFIG.imageGen;
17
+ const liblib = LibLibAPI(imageGenConfig);
17
18
 
18
19
  /**
19
20
  * convertToolCallToSkeleton - 将单个 tool call 转为 ExcalidrawElementSkeleton
@@ -335,39 +336,35 @@ exports.drawAgent = async (req, res) => {
335
336
  res.streaming(`data: ${JSON.stringify({ type: 'message', content: canvasResponse.content })}\n\n`);
336
337
  }
337
338
  } else if (decision.action === 'image') {
338
- // 4. Image - 调用图片生成 API
339
+ // 4. Image - 调用 LibLib 图片生成 API
339
340
  res.streaming(`data: ${JSON.stringify({ type: 'status', step: 'image' })}\n\n`);
340
341
  req.logger.info(methodName, 'step: image generation', decision.prompt);
341
342
  chatFeishuMsg(req, `image-${decision.prompt}`);
342
343
 
343
- const imageResponse = await fetch(`${imageGenConfig.baseURL}/images/generations`, {
344
- method: 'POST',
345
- headers: {
346
- Authorization: `Bearer ${imageGenConfig.apiKey}`,
347
- 'Content-Type': 'application/json',
348
- },
349
- body: JSON.stringify({
350
- model: imageGenConfig.modelName,
351
- prompt: decision.prompt,
352
- }),
353
- });
344
+ const submitRes = await liblib.text2img(decision.prompt, { aspectRatio: 'square' });
345
+ const generateUuid = submitRes.data?.generateUuid;
354
346
 
355
- const imageResult = await imageResponse.json();
356
- const imageUrl = imageResult.data?.[0]?.url;
347
+ if (!generateUuid) {
348
+ req.logger.error(methodName, 'liblib submit failed', JSON.stringify(submitRes));
349
+ res.streaming(`data: ${JSON.stringify({ type: 'message', content: '图片生成失败,请稍后重试。' })}\n\n`);
350
+ } else {
351
+ const result = await liblib.waitForResult(generateUuid);
352
+ const imageUrl = result.images?.[0]?.imageUrl;
357
353
 
358
- if (imageUrl) {
359
- // 下载图片转 base64(火山引擎 TOS URL 不支持浏览器跨域 fetch)
360
- const imgResponse = await fetch(imageUrl);
361
- const imgBuffer = Buffer.from(await imgResponse.arrayBuffer());
362
- const contentType = imgResponse.headers.get('content-type') || 'image/jpeg';
363
- const dataURL = `data:${contentType};base64,${imgBuffer.toString('base64')}`;
354
+ if (imageUrl) {
355
+ // 下载图片转 base64
356
+ const imgResponse = await fetch(imageUrl);
357
+ const imgBuffer = Buffer.from(await imgResponse.arrayBuffer());
358
+ const contentType = imgResponse.headers.get('content-type') || 'image/jpeg';
359
+ const dataURL = `data:${contentType};base64,${imgBuffer.toString('base64')}`;
364
360
 
365
- const duration = Date.now() - startTime;
366
- req.logger.info(methodName, 'image generated', `${duration}ms`);
367
- res.streaming(`data: ${JSON.stringify({ type: 'image', dataURL, duration })}\n\n`);
368
- } else {
369
- req.logger.error(methodName, 'image generation failed', JSON.stringify(imageResult));
370
- res.streaming(`data: ${JSON.stringify({ type: 'message', content: '图片生成失败,请稍后重试。' })}\n\n`);
361
+ const duration = Date.now() - startTime;
362
+ req.logger.info(methodName, 'image generated', `${duration}ms`);
363
+ res.streaming(`data: ${JSON.stringify({ type: 'image', dataURL, duration })}\n\n`);
364
+ } else {
365
+ req.logger.error(methodName, 'liblib no image url', JSON.stringify(result));
366
+ res.streaming(`data: ${JSON.stringify({ type: 'message', content: '图片生成失败,请稍后重试。' })}\n\n`);
367
+ }
371
368
  }
372
369
  } else if (decision.action === 'sketch') {
373
370
  // 5. Sketch - 通知前端执行线稿提取(处理在前端完成)