@fv-ui/ai-chat 1.2.0 → 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
@@ -33296,6 +33296,8 @@
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: {
@@ -33411,6 +33413,7 @@
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);
@@ -39008,6 +39018,16 @@
39008
39018
  vue.onBeforeUnmount(() => {
39009
39019
  if (phraseTimer !== null) clearInterval(phraseTimer);
39010
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
+ }
39011
39031
  function onCopy() {
39012
39032
  emit("copy", props.message);
39013
39033
  }
@@ -39235,8 +39255,33 @@
39235
39255
  1
39236
39256
  /* TEXT */
39237
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),
39238
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) "),
39239
- __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, [
39240
39285
  vue.renderSlot(_ctx.$slots, "message-actions", { message: __props.message }, () => [
39241
39286
  __props.showActions && isUser.value ? (vue.openBlock(), vue.createBlock(vue.unref(elementPlus.ElTooltip), {
39242
39287
  key: 0,
@@ -39327,7 +39372,7 @@
39327
39372
  }, 8, ["content"])) : vue.createCommentVNode("v-if", true)
39328
39373
  ]),
39329
39374
  vue.createCommentVNode(" \u5206\u652F\u5207\u6362:\u5144\u5F1F\u5206\u652F > 1 \u65F6 "),
39330
- __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, [
39331
39376
  vue.createVNode(vue.unref(elementPlus.ElButton), {
39332
39377
  text: "",
39333
39378
  size: "small",
@@ -39350,7 +39395,7 @@
39350
39395
  }, 8, ["disabled", "aria-label"]),
39351
39396
  vue.createElementVNode(
39352
39397
  "span",
39353
- _hoisted_17,
39398
+ _hoisted_19,
39354
39399
  vue.toDisplayString(__props.branch.index) + " / " + vue.toDisplayString(__props.branch.count),
39355
39400
  1
39356
39401
  /* TEXT */
@@ -39379,7 +39424,7 @@
39379
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 "),
39380
39425
  messageTimeText.value && timeVisible.value ? (vue.openBlock(), vue.createElementBlock(
39381
39426
  "span",
39382
- _hoisted_18,
39427
+ _hoisted_20,
39383
39428
  vue.toDisplayString(messageTimeText.value),
39384
39429
  1
39385
39430
  /* TEXT */
@@ -39433,7 +39478,7 @@
39433
39478
  timeFormat: { type: Function, required: false, default: void 0 },
39434
39479
  locale: { type: null, required: false }
39435
39480
  },
39436
- emits: ["select", "copy", "regenerate", "branch-change", "scroll"],
39481
+ emits: ["select", "copy", "regenerate", "branch-change", "scroll", "followup-select"],
39437
39482
  setup(__props, { expose: __expose, emit: __emit }) {
39438
39483
  const props = __props;
39439
39484
  const dict = useLocaleDict(() => props.locale);
@@ -39508,7 +39553,7 @@
39508
39553
  );
39509
39554
  vue.watch(
39510
39555
  () => props.messages.reduce(
39511
- (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),
39512
39557
  0
39513
39558
  ),
39514
39559
  () => followIfPinned()
@@ -39541,6 +39586,10 @@
39541
39586
  function onBranch(dir, m) {
39542
39587
  emit("branch-change", dir, m);
39543
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 : "");
39544
39593
  function scrollToTop() {
39545
39594
  const el = scrollRef.value;
39546
39595
  if (!el) return;
@@ -39659,6 +39708,7 @@
39659
39708
  ref: (el) => setMessageRef(m.id, el),
39660
39709
  message: m,
39661
39710
  branch: branchInfo(m),
39711
+ "is-last": m.id === lastMessageId.value,
39662
39712
  "show-actions": __props.showActions,
39663
39713
  "show-branch-switch": __props.showBranchSwitch,
39664
39714
  "show-user-avatar": __props.showUserAvatar,
@@ -39681,7 +39731,8 @@
39681
39731
  onTyping: onChildTyping,
39682
39732
  onCopy,
39683
39733
  onRegenerate,
39684
- onBranchChange: onBranch
39734
+ onBranchChange: onBranch,
39735
+ onFollowupSelect: onFollowup
39685
39736
  }, vue.createSlots({
39686
39737
  _: 2
39687
39738
  /* DYNAMIC */
@@ -39728,7 +39779,7 @@
39728
39779
  ]),
39729
39780
  key: "5"
39730
39781
  } : void 0
39731
- ]), 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"]);
39732
39783
  }),
39733
39784
  128
39734
39785
  /* KEYED_FRAGMENT */
@@ -40101,7 +40152,7 @@
40101
40152
  theme: { type: String, required: false, default: "light" },
40102
40153
  locale: { type: null, required: false }
40103
40154
  },
40104
- 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"],
40105
40156
  setup(__props, { expose: __expose, emit: __emit }) {
40106
40157
  const props = __props;
40107
40158
  const dict = useLocaleDict(() => props.locale);
@@ -40224,6 +40275,14 @@
40224
40275
  emit("send", text);
40225
40276
  void send(text).finally(finishRun);
40226
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
+ }
40227
40286
  function onCopy(m) {
40228
40287
  const text = `${m.content}`;
40229
40288
  void navigator.clipboard?.writeText(text).catch(() => {
@@ -40442,6 +40501,7 @@
40442
40501
  "time-format": __props.timeFormat,
40443
40502
  "code-trigger-langs": artifactsOn.value && artifactsCodeTrigger.value ? ["html", "svg"] : void 0,
40444
40503
  onSelect: onSelectSuggestion,
40504
+ onFollowupSelect,
40445
40505
  onCopy,
40446
40506
  onRegenerate,
40447
40507
  onBranchChange,
@@ -40745,6 +40805,17 @@
40745
40805
  function resolve(v) {
40746
40806
  return typeof v === "function" ? v() : v;
40747
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
+ }
40748
40819
  function FvCommonAdapter(config) {
40749
40820
  const { baseURL, headers, sessionId, errorMessages } = config;
40750
40821
  const activeControllers = /* @__PURE__ */ new Set();
@@ -40820,6 +40891,13 @@
40820
40891
  case "reasoning":
40821
40892
  if (typeof j.text === "string" && j.text) handlers.onReasoning(j.text);
40822
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
+ }
40823
40901
  case "message_end": {
40824
40902
  if (typeof j.messageId === "string") handlers.onBackendMessageId?.(j.messageId);
40825
40903
  const usage = {};
@@ -40961,6 +41039,7 @@
40961
41039
  exports.createMessageTree = createMessageTree;
40962
41040
  exports.createSSEParser = createSSEParser;
40963
41041
  exports.enUS = enUS;
41042
+ exports.parseSuggestions = parseSuggestions;
40964
41043
  exports.useChat = useChat;
40965
41044
  exports.useMessages = useMessages;
40966
41045
  exports.useRecord = useRecord;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fv-ui/ai-chat",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "基于 Vue3 + Element Plus 的 AI 对话组件库",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",