@fv-ui/ai-chat 1.1.3 → 1.3.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/lib/index.js CHANGED
@@ -33236,7 +33236,7 @@
33236
33236
  },
33237
33237
  welcome: {
33238
33238
  greetingPrefix: "\u4F60\u597D\uFF0C\u6211\u662F ",
33239
- greetingName: "FVAI",
33239
+ greetingName: "Gizmo",
33240
33240
  description: "\u6211\u53EF\u4EE5\u5E2E\u4F60\u67E5\u8BE2\u6570\u636E\u3001\u5206\u6790\u95EE\u9898\u3001\u751F\u6210\u62A5\u8868\u3001\u4EE5\u53CA\u6267\u884C\u7CFB\u7EDF\u64CD\u4F5C\uFF0C\u8BA9\u751F\u4EA7\u7BA1\u7406\u66F4\u9AD8\u6548\u3002"
33241
33241
  },
33242
33242
  sender: {
@@ -33292,10 +33292,12 @@
33292
33292
  prevBranch: "\u4E0A\u4E00\u5206\u652F",
33293
33293
  nextBranch: "\u4E0B\u4E00\u5206\u652F",
33294
33294
  defaultUserName: "\u4F60",
33295
- defaultAssistantName: "\u5C0F\u7EF4",
33295
+ defaultAssistantName: "Gizmo",
33296
33296
  querying: "\u6B63\u5728\u67E5\u8BE2",
33297
33297
  queried: "\u5DF2\u67E5\u8BE2",
33298
33298
  generateFailed: "\u751F\u6210\u5931\u8D25",
33299
+ /** 追问建议 chips 区 aria 标签 */
33300
+ followups: "\u8FFD\u95EE\u5EFA\u8BAE",
33299
33301
  loadingPhrases: ["\u6B63\u5728\u601D\u8003\u2026", "\u6B63\u5728\u6574\u7406\u601D\u8DEF\u2026", "\u6B63\u5728\u751F\u6210\u56DE\u7B54\u2026"]
33300
33302
  },
33301
33303
  aiArtifacts: {
@@ -33351,7 +33353,7 @@
33351
33353
  },
33352
33354
  welcome: {
33353
33355
  greetingPrefix: "Hello, I am ",
33354
- greetingName: "FVAI",
33356
+ greetingName: "Gizmo",
33355
33357
  description: "I can help you query data, analyze problems, generate reports, and perform system operations to make production management more efficient."
33356
33358
  },
33357
33359
  sender: {
@@ -33407,10 +33409,11 @@
33407
33409
  prevBranch: "Previous branch",
33408
33410
  nextBranch: "Next branch",
33409
33411
  defaultUserName: "You",
33410
- defaultAssistantName: "Assistant",
33412
+ defaultAssistantName: "Gizmo",
33411
33413
  querying: "Querying",
33412
33414
  queried: "Queried",
33413
33415
  generateFailed: "Generation failed",
33416
+ followups: "Follow-up suggestions",
33414
33417
  loadingPhrases: ["Thinking...", "Organizing thoughts...", "Generating your answer..."]
33415
33418
  },
33416
33419
  aiArtifacts: {
@@ -35425,8 +35428,8 @@
35425
35428
  };
35426
35429
  const _hoisted_17$1 = { class: "fv-editor-select-dialog" };
35427
35430
  const _hoisted_18$1 = { class: "fv-editor-select-title" };
35428
- const _hoisted_19 = { class: "fv-editor-select-grid" };
35429
- const _hoisted_20 = ["onClick"];
35431
+ const _hoisted_19$1 = { class: "fv-editor-select-grid" };
35432
+ const _hoisted_20$1 = ["onClick"];
35430
35433
  const _hoisted_21 = ["src", "alt"];
35431
35434
  const _hoisted_22 = { class: "fv-editor-select-name" };
35432
35435
  const CHAR_WIDTH = 8;
@@ -36410,7 +36413,7 @@
36410
36413
  1
36411
36414
  /* TEXT */
36412
36415
  ),
36413
- vue.createElementVNode("div", _hoisted_19, [
36416
+ vue.createElementVNode("div", _hoisted_19$1, [
36414
36417
  (vue.openBlock(true), vue.createElementBlock(
36415
36418
  vue.Fragment,
36416
36419
  null,
@@ -36433,7 +36436,7 @@
36433
36436
  1
36434
36437
  /* TEXT */
36435
36438
  )
36436
- ], 8, _hoisted_20);
36439
+ ], 8, _hoisted_20$1);
36437
36440
  }),
36438
36441
  128
36439
36442
  /* KEYED_FRAGMENT */
@@ -38284,6 +38287,7 @@
38284
38287
  error: node.error,
38285
38288
  createdAt: typeof node.createdAt === "number" ? node.createdAt : Date.now(),
38286
38289
  createdTime: node.createdTime,
38290
+ suggestions: node.suggestions ? [...node.suggestions] : void 0,
38287
38291
  usage: node.usage ? { ...node.usage } : void 0
38288
38292
  };
38289
38293
  messages[id] = full;
@@ -38580,6 +38584,9 @@
38580
38584
  onBackendMessageId: (id) => {
38581
38585
  msgs.edit(assistantId, { backendId: id });
38582
38586
  },
38587
+ onSuggestions: (items) => {
38588
+ msgs.edit(assistantId, { suggestions: items });
38589
+ },
38583
38590
  onTool: (ev) => {
38584
38591
  const label = (name) => options.toolStepLabel ? options.toolStepLabel(name) : name;
38585
38592
  const steps = [...msgs.messages.value[assistantId]?.toolSteps ?? []];
@@ -38775,16 +38782,18 @@
38775
38782
  key: 4,
38776
38783
  class: "fv-msg-content fv-msg-content-user"
38777
38784
  };
38778
- const _hoisted_15 = {
38779
- key: 5,
38785
+ const _hoisted_15 = ["aria-label"];
38786
+ const _hoisted_16 = ["disabled", "onClick"];
38787
+ const _hoisted_17 = {
38788
+ key: 6,
38780
38789
  class: "fv-msg-actions"
38781
38790
  };
38782
- const _hoisted_16 = {
38791
+ const _hoisted_18 = {
38783
38792
  key: 0,
38784
38793
  class: "fv-msg-branch"
38785
38794
  };
38786
- const _hoisted_17 = { class: "fv-msg-branch-label" };
38787
- const _hoisted_18 = {
38795
+ const _hoisted_19 = { class: "fv-msg-branch-label" };
38796
+ const _hoisted_20 = {
38788
38797
  key: 1,
38789
38798
  class: "fv-msg-time"
38790
38799
  };
@@ -38795,6 +38804,7 @@
38795
38804
  props: {
38796
38805
  message: { type: Object, required: true },
38797
38806
  branch: { type: Object, required: false, default: void 0 },
38807
+ isLast: { type: Boolean, required: false, default: false },
38798
38808
  showActions: { type: Boolean, required: false, default: true },
38799
38809
  showBranchSwitch: { type: Boolean, required: false, default: true },
38800
38810
  showUserAvatar: { type: Boolean, required: false, default: false },
@@ -38816,7 +38826,7 @@
38816
38826
  timeFormat: { type: Function, required: false, default: void 0 },
38817
38827
  locale: { type: null, required: false }
38818
38828
  },
38819
- emits: ["copy", "regenerate", "branch-change", "typing"],
38829
+ emits: ["copy", "regenerate", "branch-change", "typing", "followup-select"],
38820
38830
  setup(__props, { expose: __expose, emit: __emit }) {
38821
38831
  const props = __props;
38822
38832
  const dict = useLocaleDict(() => props.locale);
@@ -38970,6 +38980,21 @@
38970
38980
  }
38971
38981
  return defaultFormat(ts);
38972
38982
  });
38983
+ function isTimeReady() {
38984
+ if (isUser.value) return true;
38985
+ const s = props.message.status;
38986
+ if (s === "pending" || s === "streaming") return false;
38987
+ if (s === "error") return true;
38988
+ const tw = contentTypewriterRef.value;
38989
+ return !(tw ? tw.isTyping : props.typing && wasStreaming.value && props.message.content);
38990
+ }
38991
+ const timeVisible = vue.ref(isTimeReady());
38992
+ vue.watch(
38993
+ [() => props.message.status, () => contentTypewriterRef.value?.isTyping],
38994
+ () => {
38995
+ timeVisible.value = isTimeReady();
38996
+ }
38997
+ );
38973
38998
  const isPendingPlaceholder = vue.computed(
38974
38999
  () => (props.message.status === "pending" || props.message.status === "streaming") && !props.message.content && !hasToolSteps.value
38975
39000
  );
@@ -38993,6 +39018,16 @@
38993
39018
  vue.onBeforeUnmount(() => {
38994
39019
  if (phraseTimer !== null) clearInterval(phraseTimer);
38995
39020
  });
39021
+ const followups = vue.computed(() => {
39022
+ if (!props.isLast || isUser.value) return [];
39023
+ const s = props.message.suggestions;
39024
+ return s && s.length ? s : [];
39025
+ });
39026
+ const followupsEnabled = vue.computed(() => props.message.status === "done");
39027
+ function onFollowup(item) {
39028
+ if (!followupsEnabled.value) return;
39029
+ emit("followup-select", item, props.message);
39030
+ }
38996
39031
  function onCopy() {
38997
39032
  emit("copy", props.message);
38998
39033
  }
@@ -39220,8 +39255,33 @@
39220
39255
  1
39221
39256
  /* TEXT */
39222
39257
  )),
39258
+ vue.createCommentVNode(" \u8FFD\u95EE\u5EFA\u8BAE chips:\u4EC5\u94FE\u5C3E assistant \u6D88\u606F\u6E32\u67D3(isLast \u7531 AiMessages \u6CE8\u5165);\r\n \u6D41\u5F0F(message_end \u524D)\u7981\u7528\u9632\u8BEF\u70B9,\u843D\u5B9A\u540E\u53EF\u70B9\u51FB,\u70B9\u51FB\u7ECF followup-select \u4E0A\u629B "),
39259
+ followups.value.length ? (vue.openBlock(), vue.createElementBlock("div", {
39260
+ key: 5,
39261
+ class: "fv-msg-followups",
39262
+ role: "listbox",
39263
+ "aria-label": vue.unref(dict).aiMessage.followups
39264
+ }, [
39265
+ (vue.openBlock(true), vue.createElementBlock(
39266
+ vue.Fragment,
39267
+ null,
39268
+ vue.renderList(followups.value, (item, i) => {
39269
+ return vue.openBlock(), vue.createElementBlock("button", {
39270
+ key: `${i}-${item}`,
39271
+ type: "button",
39272
+ class: vue.normalizeClass(["fv-msg-followup", { "is-disabled": !followupsEnabled.value }]),
39273
+ disabled: !followupsEnabled.value,
39274
+ role: "option",
39275
+ "aria-selected": false,
39276
+ onClick: ($event) => onFollowup(item)
39277
+ }, vue.toDisplayString(item), 11, _hoisted_16);
39278
+ }),
39279
+ 128
39280
+ /* KEYED_FRAGMENT */
39281
+ ))
39282
+ ], 8, _hoisted_15)) : vue.createCommentVNode("v-if", true),
39223
39283
  vue.createCommentVNode(" \u64CD\u4F5C\u533A:assistant \u590D\u5236/\u91CD\u751F\u6210 + \u5206\u652F\u5207\u6362;user \u4EC5\u590D\u5236(hover \u6D88\u606F\u65F6\u6D6E\u73B0,\u89C1 scss) "),
39224
- __props.showActions || __props.showBranchSwitch && __props.branch && __props.branch.count > 1 ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_15, [
39284
+ __props.showActions || __props.showBranchSwitch && __props.branch && __props.branch.count > 1 ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_17, [
39225
39285
  vue.renderSlot(_ctx.$slots, "message-actions", { message: __props.message }, () => [
39226
39286
  __props.showActions && isUser.value ? (vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElTooltip), {
39227
39287
  key: 0,
@@ -39312,7 +39372,7 @@
39312
39372
  }, 8, ["content"])) : vue.createCommentVNode("v-if", true)
39313
39373
  ]),
39314
39374
  vue.createCommentVNode(" \u5206\u652F\u5207\u6362:\u5144\u5F1F\u5206\u652F > 1 \u65F6 "),
39315
- __props.showBranchSwitch && __props.branch && __props.branch.count > 1 ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_16, [
39375
+ __props.showBranchSwitch && __props.branch && __props.branch.count > 1 ? (vue.openBlock(), vue.createElementBlock("span", _hoisted_18, [
39316
39376
  vue.createVNode(vue.unref(elementPlus.ElButton), {
39317
39377
  text: "",
39318
39378
  size: "small",
@@ -39335,7 +39395,7 @@
39335
39395
  }, 8, ["disabled", "aria-label"]),
39336
39396
  vue.createElementVNode(
39337
39397
  "span",
39338
- _hoisted_17,
39398
+ _hoisted_19,
39339
39399
  vue.toDisplayString(__props.branch.index) + " / " + vue.toDisplayString(__props.branch.count),
39340
39400
  1
39341
39401
  /* TEXT */
@@ -39361,10 +39421,10 @@
39361
39421
  /* STABLE */
39362
39422
  }, 8, ["disabled", "aria-label"])
39363
39423
  ])) : vue.createCommentVNode("v-if", true),
39364
- vue.createCommentVNode(" \u6D88\u606F\u65F6\u95F4:\u8DDF\u5728\u64CD\u4F5C\u6309\u94AE\u4E0E\u5206\u652F\u5207\u6362\u4E4B\u540E;user \u6D88\u606F hover \u9690\u85CF\u6309\u94AE\u4E0D\u5F71\u54CD\u65F6\u95F4\u5E38\u9A7B "),
39365
- messageTimeText.value ? (vue.openBlock(), vue.createElementBlock(
39424
+ vue.createCommentVNode(" \u6D88\u606F\u65F6\u95F4:\u8DDF\u5728\u64CD\u4F5C\u6309\u94AE\u4E0E\u5206\u652F\u5207\u6362\u4E4B\u540E;user \u6D88\u606F hover \u9690\u85CF\u6309\u94AE\u4E0D\u5F71\u54CD\u65F6\u95F4\u5E38\u9A7B;\r\n assistant \u751F\u6210\u4E2D\u4E0D\u663E,\u6B63\u6587\u6253\u5B8C\u5B57(\u6216 error)\u540E\u624D\u6D6E\u73B0 "),
39425
+ messageTimeText.value && timeVisible.value ? (vue.openBlock(), vue.createElementBlock(
39366
39426
  "span",
39367
- _hoisted_18,
39427
+ _hoisted_20,
39368
39428
  vue.toDisplayString(messageTimeText.value),
39369
39429
  1
39370
39430
  /* TEXT */
@@ -39418,7 +39478,7 @@
39418
39478
  timeFormat: { type: Function, required: false, default: void 0 },
39419
39479
  locale: { type: null, required: false }
39420
39480
  },
39421
- emits: ["select", "copy", "regenerate", "branch-change", "scroll"],
39481
+ emits: ["select", "copy", "regenerate", "branch-change", "scroll", "followup-select"],
39422
39482
  setup(__props, { expose: __expose, emit: __emit }) {
39423
39483
  const props = __props;
39424
39484
  const dict = useLocaleDict(() => props.locale);
@@ -39493,7 +39553,7 @@
39493
39553
  );
39494
39554
  vue.watch(
39495
39555
  () => props.messages.reduce(
39496
- (sum, m) => sum + m.content.length + (m.reasoning?.length ?? 0) + (m.toolSteps?.reduce((s, t) => s + (t.status?.length ?? 0) + (t.title?.length ?? 0), 0) ?? 0) + (m.toolSteps?.length ?? 0),
39556
+ (sum, m) => sum + m.content.length + (m.reasoning?.length ?? 0) + (m.toolSteps?.reduce((s, t) => s + (t.status?.length ?? 0) + (t.title?.length ?? 0), 0) ?? 0) + (m.toolSteps?.length ?? 0) + (m.suggestions?.length ?? 0),
39497
39557
  0
39498
39558
  ),
39499
39559
  () => followIfPinned()
@@ -39526,6 +39586,10 @@
39526
39586
  function onBranch(dir, m) {
39527
39587
  emit("branch-change", dir, m);
39528
39588
  }
39589
+ function onFollowup(item, m) {
39590
+ emit("followup-select", item, m);
39591
+ }
39592
+ const lastMessageId = vue.computed(() => props.messages.length ? props.messages[props.messages.length - 1].id : "");
39529
39593
  function scrollToTop() {
39530
39594
  const el = scrollRef.value;
39531
39595
  if (!el) return;
@@ -39644,6 +39708,7 @@
39644
39708
  ref: (el) => setMessageRef(m.id, el),
39645
39709
  message: m,
39646
39710
  branch: branchInfo(m),
39711
+ "is-last": m.id === lastMessageId.value,
39647
39712
  "show-actions": __props.showActions,
39648
39713
  "show-branch-switch": __props.showBranchSwitch,
39649
39714
  "show-user-avatar": __props.showUserAvatar,
@@ -39666,7 +39731,8 @@
39666
39731
  onTyping: onChildTyping,
39667
39732
  onCopy,
39668
39733
  onRegenerate,
39669
- onBranchChange: onBranch
39734
+ onBranchChange: onBranch,
39735
+ onFollowupSelect: onFollowup
39670
39736
  }, vue.createSlots({
39671
39737
  _: 2
39672
39738
  /* DYNAMIC */
@@ -39713,7 +39779,7 @@
39713
39779
  ]),
39714
39780
  key: "5"
39715
39781
  } : void 0
39716
- ]), 1032, ["message", "branch", "show-actions", "show-branch-switch", "show-user-avatar", "show-user-name", "show-assistant-avatar", "show-assistant-name", "user-avatar", "assistant-avatar", "assistant-avatar-scale", "avatar-circle", "user-name", "assistant-name", "typing", "auto-collapse", "collapsible", "show-duration", "show-time", "time-format", "code-trigger-langs"]);
39782
+ ]), 1032, ["message", "branch", "is-last", "show-actions", "show-branch-switch", "show-user-avatar", "show-user-name", "show-assistant-avatar", "show-assistant-name", "user-avatar", "assistant-avatar", "assistant-avatar-scale", "avatar-circle", "user-name", "assistant-name", "typing", "auto-collapse", "collapsible", "show-duration", "show-time", "time-format", "code-trigger-langs"]);
39717
39783
  }),
39718
39784
  128
39719
39785
  /* KEYED_FRAGMENT */
@@ -40086,7 +40152,7 @@
40086
40152
  theme: { type: String, required: false, default: "light" },
40087
40153
  locale: { type: null, required: false }
40088
40154
  },
40089
- emits: ["update:messages", "send", "suggestion-select", "message-complete", "error", "branch-change", "attachment-exceed", "scroll", "tool-event"],
40155
+ emits: ["update:messages", "send", "suggestion-select", "followup-select", "message-complete", "error", "branch-change", "attachment-exceed", "scroll", "tool-event"],
40090
40156
  setup(__props, { expose: __expose, emit: __emit }) {
40091
40157
  const props = __props;
40092
40158
  const dict = useLocaleDict(() => props.locale);
@@ -40209,6 +40275,14 @@
40209
40275
  emit("send", text);
40210
40276
  void send(text).finally(finishRun);
40211
40277
  }
40278
+ function onFollowupSelect(item, message) {
40279
+ const text = item.trim();
40280
+ if (!text || isLoading.value) return;
40281
+ resetArtifactUserClosed();
40282
+ emit("followup-select", item, message);
40283
+ emit("send", text);
40284
+ void send(text).finally(finishRun);
40285
+ }
40212
40286
  function onCopy(m) {
40213
40287
  const text = `${m.content}`;
40214
40288
  void navigator.clipboard?.writeText(text).catch(() => {
@@ -40427,6 +40501,7 @@
40427
40501
  "time-format": __props.timeFormat,
40428
40502
  "code-trigger-langs": artifactsOn.value && artifactsCodeTrigger.value ? ["html", "svg"] : void 0,
40429
40503
  onSelect: onSelectSuggestion,
40504
+ onFollowupSelect,
40430
40505
  onCopy,
40431
40506
  onRegenerate,
40432
40507
  onBranchChange,
@@ -40730,6 +40805,17 @@
40730
40805
  function resolve(v) {
40731
40806
  return typeof v === "function" ? v() : v;
40732
40807
  }
40808
+ function parseSuggestions(raw) {
40809
+ if (!raw) return void 0;
40810
+ try {
40811
+ const parsed = JSON.parse(raw);
40812
+ if (!Array.isArray(parsed)) return void 0;
40813
+ const items = parsed.filter((s) => typeof s === "string" && s.trim().length > 0);
40814
+ return items.length ? items : void 0;
40815
+ } catch {
40816
+ return void 0;
40817
+ }
40818
+ }
40733
40819
  function FvCommonAdapter(config) {
40734
40820
  const { baseURL, headers, sessionId, errorMessages } = config;
40735
40821
  const activeControllers = /* @__PURE__ */ new Set();
@@ -40805,6 +40891,13 @@
40805
40891
  case "reasoning":
40806
40892
  if (typeof j.text === "string" && j.text) handlers.onReasoning(j.text);
40807
40893
  break;
40894
+ case "suggestions": {
40895
+ if (Array.isArray(j.items)) {
40896
+ const items = j.items.filter((s) => typeof s === "string" && s.trim().length > 0);
40897
+ if (items.length) handlers.onSuggestions?.(items);
40898
+ }
40899
+ break;
40900
+ }
40808
40901
  case "message_end": {
40809
40902
  if (typeof j.messageId === "string") handlers.onBackendMessageId?.(j.messageId);
40810
40903
  const usage = {};
@@ -40946,6 +41039,7 @@
40946
41039
  exports.createMessageTree = createMessageTree;
40947
41040
  exports.createSSEParser = createSSEParser;
40948
41041
  exports.enUS = enUS;
41042
+ exports.parseSuggestions = parseSuggestions;
40949
41043
  exports.useChat = useChat;
40950
41044
  exports.useMessages = useMessages;
40951
41045
  exports.useRecord = useRecord;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fv-ui/ai-chat",
3
- "version": "1.1.3",
3
+ "version": "1.3.0",
4
4
  "description": "基于 Vue3 + Element Plus 的 AI 对话组件库",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",