st-comp 0.0.266 → 0.0.267

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,7 +1,7 @@
1
1
  {
2
2
  "name": "st-comp",
3
3
  "public": true,
4
- "version": "0.0.266",
4
+ "version": "0.0.267",
5
5
  "type": "module",
6
6
  "scripts": {
7
7
  "dev": "vite",
@@ -1,7 +1,7 @@
1
1
  <script setup>
2
2
  import dayjs from "dayjs";
3
3
  import { ElMessage } from "element-plus";
4
- import { getUserData } from "st-func";
4
+ import { getUserData, getToken } from "st-func";
5
5
  import { inject, ref, nextTick, watch, reactive, onMounted } from "vue";
6
6
  import { sendToBaiLianWorkflowStreaming } from "../../public/aiTools";
7
7
  import { UserFilled, Service, Promotion, Refresh, SuccessFilled } from "@element-plus/icons-vue";
@@ -20,11 +20,10 @@ const props = defineProps({
20
20
  });
21
21
 
22
22
  // ==================== 响应式数据 ====================
23
- const tagMap = ref(); // 自定义标签映射表
24
- const isSending = ref(false); // 是否正在发送消息
25
- const isThinking = ref(false); // AI是否正在思考(首包到达前)
26
- const nodeProgressList = ref([]); // 工作流节点执行进度列表
27
- const showFinalResult = ref(false); // 是否展示最终结果
23
+ const isSending = ref(false); // 是否正在发送消息
24
+ const isThinking = ref(false); // AI是否正在思考(首包到达前)
25
+ const nodeProgressList = ref([]); // 工作流节点执行进度列表
26
+ const showFinalResult = ref(false); // 是否展示最终结果
28
27
 
29
28
  // ==================== 消息队列 ====================
30
29
  const messageListRef = ref(null);
@@ -41,7 +40,7 @@ const messageList = ref([
41
40
  },
42
41
  ]);
43
42
 
44
- const userInput = ref(""); // 用户输入内容
43
+ const userInput = ref(""); // 用户输入内容
45
44
 
46
45
  // ==================== 反馈弹窗 ====================
47
46
  const feedbackDialogVisible = ref(false);
@@ -198,8 +197,10 @@ const sendMessage = async () => {
198
197
  const appId = "1977602b357e4dab9d0b74899d5323b3";
199
198
  const apiKey = "sk-d995eb26a4334bdeb2ccb4cbfaf51de8";
200
199
  await sendToBaiLianWorkflowStreaming({
200
+ mode: import.meta.env.MODE,
201
201
  appId,
202
202
  apiKey,
203
+ token: getToken(),
203
204
  value: content,
204
205
  callback: (type, data) => {
205
206
  // 工作流返回错误
@@ -272,16 +273,6 @@ const sendMessage = async () => {
272
273
  if (jsonResponse.parsedConditions) {
273
274
  delete jsonResponse.parsedConditions;
274
275
  }
275
- // 将 customTagNames 转换为 customTag
276
- if (jsonResponse.customTagNames?.length) {
277
- const customTag = jsonResponse.customTagNames.reduce((result, item) => {
278
- const id = tagMap.value[item];
279
- if (id) result.push(id);
280
- return result;
281
- }, []);
282
- delete jsonResponse.customTagNames;
283
- jsonResponse.customTag = customTag;
284
- }
285
276
  emit("callBack", jsonResponse);
286
277
  } catch (error) {
287
278
  emit("callBack", fullResponse);
@@ -341,30 +332,12 @@ const scrollToBottom = async () => {
341
332
  }
342
333
  };
343
334
 
344
- // 获取全部标签映射
345
- const getTotalTagMap = async () => {
346
- const res = await Promise.all([
347
- stConfig.request.post("/alarm/deliversign/findTagsByUserId"),
348
- stConfig.request.post("/alarm/deliversign/findSystemTagsByTagName"),
349
- ]);
350
- tagMap.value = res.reduce((result, item) => {
351
- return {
352
- ...result,
353
- ...item.body?.reduce((cR, cI) => {
354
- return { ...cR, [cI.tagName]: cI.id };
355
- }, {}),
356
- };
357
- }, {});
358
- };
359
-
360
- onMounted(() => {
361
- getTotalTagMap();
362
- });
363
-
364
335
  // 监听消息队列变化,自动滚动
365
336
  watch(
366
337
  () => messageList.value,
367
- () => { scrollToBottom(); },
338
+ () => {
339
+ scrollToBottom();
340
+ },
368
341
  { deep: true },
369
342
  );
370
343
 
@@ -380,7 +353,9 @@ watch(
380
353
  defineExpose({
381
354
  open: () => {
382
355
  visible.value = true;
383
- nextTick(() => { scrollToBottom(); });
356
+ nextTick(() => {
357
+ scrollToBottom();
358
+ });
384
359
  },
385
360
  });
386
361
  </script>
@@ -400,7 +375,10 @@ defineExpose({
400
375
  >
401
376
  <div class="ai-dialog-body">
402
377
  <!-- 消息列表 -->
403
- <div ref="messageListRef" class="message-list">
378
+ <div
379
+ ref="messageListRef"
380
+ class="message-list"
381
+ >
404
382
  <div
405
383
  v-for="(message, index) in messageList"
406
384
  :key="index"
@@ -411,7 +389,10 @@ defineExpose({
411
389
  <template v-if="message.content || (index === messageList.length - 1 && message.role === 'assistant' && nodeProgressList.length > 0)">
412
390
  <!-- 头像 -->
413
391
  <div class="avatar">
414
- <el-avatar :size="32" :icon="message.role === 'user' ? UserFilled : Service" />
392
+ <el-avatar
393
+ :size="32"
394
+ :icon="message.role === 'user' ? UserFilled : Service"
395
+ />
415
396
  </div>
416
397
 
417
398
  <div class="message-content">
@@ -421,10 +402,22 @@ defineExpose({
421
402
  class="node-progress"
422
403
  >
423
404
  <!-- 已完成/执行中节点 -->
424
- <div v-for="node in nodeProgressList" :key="node.name" class="node-progress-item">
405
+ <div
406
+ v-for="node in nodeProgressList"
407
+ :key="node.name"
408
+ class="node-progress-item"
409
+ >
425
410
  <span class="node-status-icon">
426
- <el-icon v-if="node.status === 'success'" class="node-icon done"><SuccessFilled /></el-icon>
427
- <el-icon v-else class="node-icon running"><Refresh /></el-icon>
411
+ <el-icon
412
+ v-if="node.status === 'success'"
413
+ class="node-icon done"
414
+ ><SuccessFilled
415
+ /></el-icon>
416
+ <el-icon
417
+ v-else
418
+ class="node-icon running"
419
+ ><Refresh
420
+ /></el-icon>
428
421
  </span>
429
422
  <span class="node-name">{{ node.name }}</span>
430
423
  </div>
@@ -441,9 +434,18 @@ defineExpose({
441
434
  </div>
442
435
 
443
436
  <!-- JSON 结果渲染 -->
444
- <div v-if="isJSONSerializable(message.content)" class="message-json" v-html="renderJSONContent(formatJSONContent(message.content))"></div>
437
+ <div
438
+ v-if="isJSONSerializable(message.content)"
439
+ class="message-json"
440
+ v-html="renderJSONContent(formatJSONContent(message.content))"
441
+ ></div>
445
442
  <!-- 普通文本 -->
446
- <div v-else-if="message.content" class="message-text">{{ message.content }}</div>
443
+ <div
444
+ v-else-if="message.content"
445
+ class="message-text"
446
+ >
447
+ {{ message.content }}
448
+ </div>
447
449
 
448
450
  <!-- 消息时间 -->
449
451
  <div class="message-createTime">{{ message.createTime }}</div>
@@ -453,11 +455,17 @@ defineExpose({
453
455
  <template v-if="message.showFeedback && !message.hasFeedback">
454
456
  <div class="message-createTime">请问对本轮查询结果是否满意?</div>
455
457
  <div class="feedback-buttons">
456
- <button class="feedback-btn satisfied-btn" @click="handleFeedbackAction('satisfied', index)">
458
+ <button
459
+ class="feedback-btn satisfied-btn"
460
+ @click="handleFeedbackAction('satisfied', index)"
461
+ >
457
462
  <span class="btn-emoji">👍</span>
458
463
  <span class="btn-text">满意</span>
459
464
  </button>
460
- <button class="feedback-btn unsatisfied-btn" @click="handleFeedbackAction('open', index)">
465
+ <button
466
+ class="feedback-btn unsatisfied-btn"
467
+ @click="handleFeedbackAction('open', index)"
468
+ >
461
469
  <span class="btn-emoji">👎</span>
462
470
  <span class="btn-text">不满意</span>
463
471
  </button>
@@ -477,7 +485,10 @@ defineExpose({
477
485
  class="message-item assistant"
478
486
  >
479
487
  <div class="avatar">
480
- <el-avatar :size="32" :icon="Service" />
488
+ <el-avatar
489
+ :size="32"
490
+ :icon="Service"
491
+ />
481
492
  </div>
482
493
  <div class="message-content">
483
494
  <div class="typing-indicator">
@@ -504,7 +515,14 @@ defineExpose({
504
515
  <div class="input-hint">
505
516
  <span>Enter 发送 | Ctrl + Enter 换行</span>
506
517
  </div>
507
- <el-button class="send-btn" type="primary" :icon="Promotion" :loading="isSending" @click="sendMessage" round>
518
+ <el-button
519
+ class="send-btn"
520
+ type="primary"
521
+ :icon="Promotion"
522
+ :loading="isSending"
523
+ @click="sendMessage"
524
+ round
525
+ >
508
526
  发送
509
527
  </el-button>
510
528
  </div>
@@ -513,16 +531,29 @@ defineExpose({
513
531
  </el-dialog>
514
532
 
515
533
  <!-- ==================== 反馈弹窗 ==================== -->
516
- <el-dialog v-model="feedbackDialogVisible" title="📝 反馈意见" width="400px">
534
+ <el-dialog
535
+ v-model="feedbackDialogVisible"
536
+ title="📝 反馈意见"
537
+ width="400px"
538
+ >
517
539
  <div class="feedback-dialog-content">
518
540
  <div class="feedback-emoji">😟</div>
519
541
  <p class="feedback-tip">很抱歉没能帮到您,请告诉我们哪里需要改进:</p>
520
- <el-input v-model="feedbackContent" type="textarea" :rows="4" placeholder="[非必填]例如:回答不够准确、查询结果有误、界面体验不佳..." />
542
+ <el-input
543
+ v-model="feedbackContent"
544
+ type="textarea"
545
+ :rows="4"
546
+ placeholder="[非必填]例如:回答不够准确、查询结果有误、界面体验不佳..."
547
+ />
521
548
  </div>
522
549
  <template #footer>
523
550
  <span class="dialog-footer">
524
551
  <el-button @click="feedbackDialogVisible = false">取消</el-button>
525
- <el-button type="primary" @click="handleFeedbackAction('unsatisfied', feedbackMessageIndex)">提交反馈</el-button>
552
+ <el-button
553
+ type="primary"
554
+ @click="handleFeedbackAction('unsatisfied', feedbackMessageIndex)"
555
+ >提交反馈</el-button
556
+ >
526
557
  </span>
527
558
  </template>
528
559
  </el-dialog>
@@ -543,12 +574,19 @@ defineExpose({
543
574
  padding: 20px 24px;
544
575
 
545
576
  // 滚动条
546
- &::-webkit-scrollbar { width: 6px; }
547
- &::-webkit-scrollbar-track { background: rgba(0, 0, 0, 0.05); border-radius: 3px; }
577
+ &::-webkit-scrollbar {
578
+ width: 6px;
579
+ }
580
+ &::-webkit-scrollbar-track {
581
+ background: rgba(0, 0, 0, 0.05);
582
+ border-radius: 3px;
583
+ }
548
584
  &::-webkit-scrollbar-thumb {
549
585
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
550
586
  border-radius: 3px;
551
- &:hover { background: linear-gradient(135deg, #764ba2 0%, #667eea 100%); }
587
+ &:hover {
588
+ background: linear-gradient(135deg, #764ba2 0%, #667eea 100%);
589
+ }
552
590
  }
553
591
 
554
592
  // 单条消息
@@ -562,7 +600,10 @@ defineExpose({
562
600
  :deep(.el-avatar) {
563
601
  background: linear-gradient(135deg, #f0f2ff 0%, #e8ecff 100%);
564
602
  color: #667eea;
565
- svg { width: 18px; height: 18px; }
603
+ svg {
604
+ width: 18px;
605
+ height: 18px;
606
+ }
566
607
  }
567
608
  }
568
609
 
@@ -596,15 +637,29 @@ defineExpose({
596
637
 
597
638
  .node-icon {
598
639
  font-size: 16px;
599
- &.done { color: #22c55e; } // 完成:绿色
600
- &.running { color: #667eea; animation: spin 1.2s linear infinite; } // 执行中:旋转
601
- &.waiting { color: #d1d5db; animation: spin 1.2s linear infinite; } // 等待中:灰色旋转
640
+ &.done {
641
+ color: #22c55e;
642
+ } // 完成:绿色
643
+ &.running {
644
+ color: #667eea;
645
+ animation: spin 1.2s linear infinite;
646
+ } // 执行中:旋转
647
+ &.waiting {
648
+ color: #d1d5db;
649
+ animation: spin 1.2s linear infinite;
650
+ } // 等待中:灰色旋转
602
651
  }
603
652
 
604
- .node-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
653
+ .node-name {
654
+ white-space: nowrap;
655
+ overflow: hidden;
656
+ text-overflow: ellipsis;
657
+ }
605
658
  }
606
659
 
607
- .next-step .node-name { color: #9ca3af; }
660
+ .next-step .node-name {
661
+ color: #9ca3af;
662
+ }
608
663
  }
609
664
 
610
665
  .message-json,
@@ -616,7 +671,11 @@ defineExpose({
616
671
  white-space: pre-wrap;
617
672
  }
618
673
 
619
- .message-createTime { font-size: 11px; color: #9ca3af; margin-top: 6px; }
674
+ .message-createTime {
675
+ font-size: 11px;
676
+ color: #9ca3af;
677
+ margin-top: 6px;
678
+ }
620
679
 
621
680
  // 反馈按钮
622
681
  .feedback-buttons {
@@ -638,10 +697,22 @@ defineExpose({
638
697
  background: rgba(255, 255, 255, 0.9);
639
698
  backdrop-filter: blur(10px);
640
699
 
641
- .btn-emoji { font-size: 16px; transition: transform 0.2s ease; }
642
- .btn-text { font-size: 13px; }
643
- &:hover { transform: translateY(-2px); .btn-emoji { transform: scale(1.1); } }
644
- &:active { transform: translateY(0); }
700
+ .btn-emoji {
701
+ font-size: 16px;
702
+ transition: transform 0.2s ease;
703
+ }
704
+ .btn-text {
705
+ font-size: 13px;
706
+ }
707
+ &:hover {
708
+ transform: translateY(-2px);
709
+ .btn-emoji {
710
+ transform: scale(1.1);
711
+ }
712
+ }
713
+ &:active {
714
+ transform: translateY(0);
715
+ }
645
716
  }
646
717
 
647
718
  .satisfied-btn {
@@ -649,7 +720,11 @@ defineExpose({
649
720
  color: #1890ff;
650
721
  border: 1px solid rgba(24, 144, 255, 0.2);
651
722
  box-shadow: 0 2px 8px rgba(24, 144, 255, 0.1);
652
- &:hover { background: linear-gradient(135deg, #e6f7ff 0%, #bae7ff 100%); border-color: #1890ff; box-shadow: 0 4px 12px rgba(24, 144, 255, 0.2); }
723
+ &:hover {
724
+ background: linear-gradient(135deg, #e6f7ff 0%, #bae7ff 100%);
725
+ border-color: #1890ff;
726
+ box-shadow: 0 4px 12px rgba(24, 144, 255, 0.2);
727
+ }
653
728
  }
654
729
 
655
730
  .unsatisfied-btn {
@@ -657,7 +732,11 @@ defineExpose({
657
732
  color: #ff4d4f;
658
733
  border: 1px solid rgba(255, 77, 79, 0.2);
659
734
  box-shadow: 0 2px 8px rgba(255, 77, 79, 0.1);
660
- &:hover { background: linear-gradient(135deg, #ffe7e5 0%, #ffccc7 100%); border-color: #ff4d4f; box-shadow: 0 4px 12px rgba(255, 77, 79, 0.2); }
735
+ &:hover {
736
+ background: linear-gradient(135deg, #ffe7e5 0%, #ffccc7 100%);
737
+ border-color: #ff4d4f;
738
+ box-shadow: 0 4px 12px rgba(255, 77, 79, 0.2);
739
+ }
661
740
  }
662
741
  }
663
742
  }
@@ -666,7 +745,10 @@ defineExpose({
666
745
  // 用户消息靠右
667
746
  .user {
668
747
  flex-direction: row-reverse;
669
- .avatar { margin-left: 12px; margin-right: 0; }
748
+ .avatar {
749
+ margin-left: 12px;
750
+ margin-right: 0;
751
+ }
670
752
  .message-content {
671
753
  align-items: flex-end;
672
754
  .message-text {
@@ -674,13 +756,17 @@ defineExpose({
674
756
  border-radius: 18px 18px 4px 18px;
675
757
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
676
758
  }
677
- .message-createTime { text-align: right; }
759
+ .message-createTime {
760
+ text-align: right;
761
+ }
678
762
  }
679
763
  }
680
764
 
681
765
  // AI消息靠左
682
766
  .assistant {
683
- .avatar { margin-right: 12px; }
767
+ .avatar {
768
+ margin-right: 12px;
769
+ }
684
770
  .message-content {
685
771
  align-items: flex-start;
686
772
  .message-text {
@@ -723,7 +809,10 @@ defineExpose({
723
809
  font-size: 14px;
724
810
  padding: 12px 16px;
725
811
  transition: all 0.3s ease;
726
- &:focus { border-color: #667eea; box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); }
812
+ &:focus {
813
+ border-color: #667eea;
814
+ box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
815
+ }
727
816
  }
728
817
  }
729
818
 
@@ -733,7 +822,10 @@ defineExpose({
733
822
  align-items: center;
734
823
  margin-top: 12px;
735
824
 
736
- .input-hint { font-size: 11px; color: var(--el-color-info); }
825
+ .input-hint {
826
+ font-size: 11px;
827
+ color: var(--el-color-info);
828
+ }
737
829
 
738
830
  .send-btn {
739
831
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
@@ -741,8 +833,13 @@ defineExpose({
741
833
  padding: 8px 20px;
742
834
  font-weight: 500;
743
835
  transition: all 0.3s ease;
744
- &:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4); }
745
- &:active { transform: translateY(0); }
836
+ &:hover {
837
+ transform: translateY(-2px);
838
+ box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
839
+ }
840
+ &:active {
841
+ transform: translateY(0);
842
+ }
746
843
  }
747
844
  }
748
845
  }
@@ -765,8 +862,12 @@ defineExpose({
765
862
  border-radius: 50%;
766
863
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
767
864
  animation: typing 1.4s infinite ease-in-out;
768
- &:nth-child(1) { animation-delay: -0.32s; }
769
- &:nth-child(2) { animation-delay: -0.16s; }
865
+ &:nth-child(1) {
866
+ animation-delay: -0.32s;
867
+ }
868
+ &:nth-child(2) {
869
+ animation-delay: -0.16s;
870
+ }
770
871
  }
771
872
  }
772
873
 
@@ -775,35 +876,70 @@ defineExpose({
775
876
  text-align: center;
776
877
  padding: 12px 0;
777
878
 
778
- .feedback-emoji { font-size: 48px; margin-bottom: 16px; animation: shake 0.5s ease-in-out; }
779
- .feedback-tip { font-size: 14px; color: #666; margin-bottom: 20px; line-height: 1.6; }
879
+ .feedback-emoji {
880
+ font-size: 48px;
881
+ margin-bottom: 16px;
882
+ animation: shake 0.5s ease-in-out;
883
+ }
884
+ .feedback-tip {
885
+ font-size: 14px;
886
+ color: #666;
887
+ margin-bottom: 20px;
888
+ line-height: 1.6;
889
+ }
780
890
 
781
891
  :deep(.el-textarea__inner) {
782
892
  border-radius: 12px;
783
893
  border: 1px solid rgba(102, 126, 234, 0.2);
784
894
  font-size: 14px;
785
- &:focus { border-color: #667eea; box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1); }
895
+ &:focus {
896
+ border-color: #667eea;
897
+ box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
898
+ }
786
899
  }
787
900
  }
788
901
 
789
902
  // ========== 动画关键帧 ==========
790
903
  @keyframes fadeInUp {
791
- from { opacity: 0; transform: translateY(10px); }
792
- to { opacity: 1; transform: translateY(0); }
904
+ from {
905
+ opacity: 0;
906
+ transform: translateY(10px);
907
+ }
908
+ to {
909
+ opacity: 1;
910
+ transform: translateY(0);
911
+ }
793
912
  }
794
913
 
795
914
  @keyframes typing {
796
- 0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
797
- 30% { transform: translateY(-8px); opacity: 1; }
915
+ 0%,
916
+ 60%,
917
+ 100% {
918
+ transform: translateY(0);
919
+ opacity: 0.4;
920
+ }
921
+ 30% {
922
+ transform: translateY(-8px);
923
+ opacity: 1;
924
+ }
798
925
  }
799
926
 
800
927
  @keyframes shake {
801
- 0%, 100% { transform: translateX(0); }
802
- 25% { transform: translateX(-5px); }
803
- 75% { transform: translateX(5px); }
928
+ 0%,
929
+ 100% {
930
+ transform: translateX(0);
931
+ }
932
+ 25% {
933
+ transform: translateX(-5px);
934
+ }
935
+ 75% {
936
+ transform: translateX(5px);
937
+ }
804
938
  }
805
939
 
806
940
  @keyframes spin {
807
- to { transform: rotate(360deg); }
941
+ to {
942
+ transform: rotate(360deg);
943
+ }
808
944
  }
809
- </style>
945
+ </style>
package/public/aiTools.js CHANGED
@@ -115,12 +115,12 @@ export const sendToBaiLianAppStreaming = async ({ appId, apiKey, value, callback
115
115
  }
116
116
  };
117
117
  // 工作流: 流式返回
118
- export const sendToBaiLianWorkflowStreaming = async ({ appId, apiKey, value, callback }) => {
118
+ export const sendToBaiLianWorkflowStreaming = async ({ mode, appId, apiKey, token, value, callback }) => {
119
119
  try {
120
120
  const response = await fetch(`https://dashscope.aliyuncs.com/api/v1/apps/${appId}/completion`, {
121
121
  method: "POST",
122
122
  body: JSON.stringify({
123
- input: { prompt: value },
123
+ input: { prompt: value, biz_params: { token, mode, origin: "web" } },
124
124
  parameters: { incremental_output: "true", flow_stream_mode: "message_format_plus" },
125
125
  debug: {},
126
126
  }),
@@ -1,4 +0,0 @@
1
- "use strict";const _=async({appId:g,apiKey:u,value:h,callback:t})=>{var o;try{const r=await fetch(`https://dashscope.aliyuncs.com/api/v1/apps/${g}/completion`,{method:"POST",body:JSON.stringify({input:{prompt:h},parameters:{incremental_output:"true"},debug:{}}),headers:{Authorization:`Bearer ${u}`,"Content-Type":"application/json","X-DashScope-SSE":"enable"}});if(!r.ok){t("error",`HTTP ${r.status}: ${r.statusText}`);return}const m=r.body.getReader(),s=new TextDecoder;let n="",c=null;for(;;){const{done:l,value:S}=await m.read();if(l){n.trim()&&$(n,t),t("finish","");break}n+=s.decode(S,{stream:!0});let f;for(;(f=n.indexOf(`
2
- `))!==-1;){const p=n.substring(0,f).trim();if(n=n.substring(f+1),p.startsWith("event:")){c=p.substring(6).trim();continue}if(p.startsWith("data:")){const d=p.substring(5).trim();if(c==="error"||d&&d.startsWith("{"))try{const i=JSON.parse(d);if(i.code||i.message||c==="error"){const a=i.message||i.code||"未知错误";t("error",`百炼服务端错误: ${a}`);return}const e=(o=i==null?void 0:i.output)==null?void 0:o.text;e&&t&&t("message",e)}catch{console.debug("JSON 解析失败:",d)}c=null}}}}catch(r){console.error("流式请求失败:",r),t("error",r.message)}},O=async({appId:g,apiKey:u,value:h,callback:t})=>{try{const o=await fetch(`https://dashscope.aliyuncs.com/api/v1/apps/${g}/completion`,{method:"POST",body:JSON.stringify({input:{prompt:h},parameters:{incremental_output:"true",flow_stream_mode:"message_format_plus"},debug:{}}),headers:{Authorization:`Bearer ${u}`,"Content-Type":"application/json","X-DashScope-SSE":"enable"}});if(!o.ok){t("error",`HTTP ${o.status}: ${o.statusText}`);return}const r=o.body.getReader(),m=new TextDecoder;let s="",n="";const c={};for(;;){const{done:l,value:S}=await r.read();if(l){n&&t("message",n),t("finish","");break}s+=m.decode(S,{stream:!0});let f;for(;(f=s.indexOf(`
3
- `))!==-1;){const p=s.substring(0,f).trim();if(s=s.substring(f+1),p.startsWith("data:")){const d=p.substring(5).trim();if(!d||d==="[DONE]")continue;try{const i=JSON.parse(d),e=i==null?void 0:i.output,a=e==null?void 0:e.workflow_message;if(a!=null&&a.node_name&&(a!=null&&a.node_type)){const y=a.node_name,x=a.node_status,T=a.node_is_completed,w=c[y];(w!==x||T&&w!=="success")&&(c[y]=T?"success":x,t("node",{name:y,status:T?"success":"executing"}))}if((e==null?void 0:e.finish_reason)==="stop"&&(e!=null&&e.text)&&(n=e.text),e!=null&&e.code||e!=null&&e.message){t("error",e.message||e.code||"未知错误");return}}catch{}}}}}catch(o){console.error("工作流请求失败:",o),t("error",o.message)}},$=(g,u)=>{var o;const h=g.split(`
4
- `);let t=null;for(const r of h){if(r.startsWith("event:")){t=r.substring(6).trim();continue}if(r.startsWith("data:")){const m=r.substring(5).trim();if(m&&m!=="[DONE]")try{const s=JSON.parse(m);if(t==="error"||s.code||s.message){const c=s.message||s.code||"未知错误";u("error",`百炼服务端错误: ${c}`);return}const n=(o=s==null?void 0:s.output)==null?void 0:o.text;n&&u&&u("message",n)}catch{}t=null}}};exports.sendToBaiLianAppStreaming=_;exports.sendToBaiLianWorkflowStreaming=O;