@shun-js/aibaiban-server 1.2.7 → 1.2.8

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.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "aibaiban.com server",
5
5
  "keywords": [
6
6
  "ai aibaiban"
@@ -45,5 +45,5 @@
45
45
  "access": "public",
46
46
  "registry": "https://registry.npmjs.org/"
47
47
  },
48
- "gitHead": "7f2b401901bcf0070e9349fab5e18b8a7c8484ee"
48
+ "gitHead": "4bd41bcab8c62c0bd062f03b8c8a63dfb9a48e06"
49
49
  }
@@ -12,6 +12,9 @@ const llm = OpenAIAPI(finalLLMConfig);
12
12
  const modelName = finalLLMConfig.modelName;
13
13
  const thinking = finalLLMConfig.thinking;
14
14
 
15
+ // 图片生成配置
16
+ const imageGenConfig = global.QZ_CONFIG.imageGen;
17
+
15
18
  /**
16
19
  * convertToolCallToSkeleton - 将单个 tool call 转为 ExcalidrawElementSkeleton
17
20
  */
@@ -41,12 +44,14 @@ function convertToolCallToSkeleton(name, args) {
41
44
 
42
45
  if (name === 'draw_arrow') {
43
46
  const skeleton = { type: 'arrow' };
44
- // 坐标:优先用起点坐标,否则默认 0
45
- skeleton.x = args.startX || 0;
46
- skeleton.y = args.startY || 0;
47
47
  // 绑定
48
48
  if (args.startId) skeleton.start = { id: args.startId };
49
49
  if (args.endId) skeleton.end = { id: args.endId };
50
+ // 坐标:有绑定时不设默认 (0,0),让前端根据绑定目标计算位置
51
+ if (args.startX !== undefined) skeleton.x = args.startX;
52
+ else if (!args.startId) skeleton.x = 0;
53
+ if (args.startY !== undefined) skeleton.y = args.startY;
54
+ else if (!args.startId) skeleton.y = 0;
50
55
  // 标签
51
56
  if (args.label) skeleton.label = { text: args.label };
52
57
  // 箭头样式
@@ -329,6 +334,39 @@ exports.drawAgent = async (req, res) => {
329
334
  // LLM 选择文字回复而非调用函数
330
335
  res.streaming(`data: ${JSON.stringify({ type: 'message', content: canvasResponse.content })}\n\n`);
331
336
  }
337
+ } else if (decision.action === 'image') {
338
+ // 4. Image - 调用图片生成 API
339
+ res.streaming(`data: ${JSON.stringify({ type: 'status', step: 'image' })}\n\n`);
340
+ req.logger.info(methodName, 'step: image generation', decision.prompt);
341
+ chatFeishuMsg(req, `image-${decision.prompt}`);
342
+
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
+ size: '1024x1024',
353
+ n: 1,
354
+ }),
355
+ });
356
+
357
+ const imageResult = await imageResponse.json();
358
+ const imageUrl = imageResult.data?.[0]?.url;
359
+
360
+ if (imageUrl) {
361
+ const duration = Date.now() - startTime;
362
+ req.logger.info(methodName, 'image generated', `${duration}ms`);
363
+ res.streaming(
364
+ `data: ${JSON.stringify({ type: 'image', url: imageUrl, prompt: decision.prompt, duration })}\n\n`,
365
+ );
366
+ } else {
367
+ req.logger.error(methodName, 'image generation failed', JSON.stringify(imageResult));
368
+ res.streaming(`data: ${JSON.stringify({ type: 'message', content: '图片生成失败,请稍后重试。' })}\n\n`);
369
+ }
332
370
  } else {
333
371
  // 未知 action fallback
334
372
  res.streaming(
@@ -12,6 +12,7 @@ module.exports = {
12
12
  ## 能力
13
13
  1. 支持 4 种图表:flowchart(流程图)、sequence(时序图)、classDiagram(类图)、erDiagram(ER图)。
14
14
  2. 支持直接在白板上绘制形状、文字、箭头等基础图形。
15
+ 3. 支持生成图片(人物、动物、风景、物品等具象内容)。
15
16
 
16
17
  ## 决策规则
17
18
  收到用户消息后判断,只回复 JSON:
@@ -25,7 +26,10 @@ module.exports = {
25
26
  3. 直接画图(用户要求画简单形状、文字、箭头等,不属于四种图表):
26
27
  {"action":"canvas","description":"用户想画什么的完整描述"}
27
28
 
28
- 4. 与画图完全无关:
29
+ 4. 生成图片(用户要画人物、动物、风景、物品、logo、海报等具象内容):
30
+ {"action":"image","prompt":"English prompt for image generation, describe the content, style, composition in detail"}
31
+
32
+ 5. 与画图完全无关:
29
33
  {"action":"irrelevant"}
30
34
 
31
35
  ## 判断标准
@@ -36,6 +40,8 @@ module.exports = {
36
40
  - 用户要修改已有图表 → 根据对话历史理解上下文,generate 完整新图表
37
41
  - 用户要画简单形状(圆、矩形、箭头、文字等)→ canvas
38
42
  - 用户说"清空白板" → canvas
43
+ - 用户要画人物/动物/风景/物品/头像等具象内容 → image
44
+ - "画一个鸣人"、"画一只猫"、"画日落"、"设计一个logo" → image
39
45
  - 用户闲聊但话题相关 → reply 自然回应并引导回画图
40
46
  - 用户闲聊话题无关 → irrelevant
41
47
 
@@ -44,6 +50,7 @@ module.exports = {
44
50
  - 可以给建议和示例帮助用户想清楚需求
45
51
  - generate 时 description 要尽可能详细完整
46
52
  - canvas 时 description 要包含形状、颜色、位置等用户提到的所有细节
53
+ - image 时 prompt 必须是英文,详细描述画面内容、风格、构图,将用户的中文需求翻译为高质量的英文绘图提示词
47
54
 
48
55
  严格要求:
49
56
  1. 你的回复必须是且仅是一个合法的 JSON 对象,不要包含任何其他文字、解释或 markdown 标记。
package/views/index.html CHANGED
@@ -105,7 +105,7 @@
105
105
  <script
106
106
  type="module"
107
107
  crossorigin
108
- src="https://static-small.vincentqiao.com/aibaiban/static/index-BKiaaj_x.js"
108
+ src="https://static-small.vincentqiao.com/aibaiban/static/index-CVW8Igbb.js"
109
109
  ></script>
110
110
  <link
111
111
  rel="modulepreload"