@fv-ui/ai-chat 0.9.2 → 0.9.3

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/README.md CHANGED
@@ -439,6 +439,7 @@ Markdown 渲染(Sanitized by DOMPurify),内置 Prism 代码高亮与 KaTeX。
439
439
  | centerWelcome | boolean | true | 空态居中:未开始对话时欢迎内容与输入区整体垂直居中,首条消息后输入区恢复固定底部 |
440
440
  | showScrollButton | boolean | true | 显示滚到底部悬浮按钮(透传 AiMessages;距底超过 scrollButtonThreshold 时出现) |
441
441
  | scrollButtonThreshold | number | 100 | 滚到底部悬浮按钮显示阈值(px,透传 AiMessages) |
442
+ | scrollThreshold | number | 100 | 用户上滚免打扰阈值(px,透传 AiMessages):距底不超过该值视为「钉在底部」,流式期间自动跟随滚动;调小可恢复更灵敏的跟随 |
442
443
  | showUserAvatar | boolean | true | 显示用户头像(false 时用户消息不渲染头像;助手头像不受影响) |
443
444
  | showUserName | boolean | true | 显示用户名称(false 时用户消息不渲染头部名称行;助手名称不受影响) |
444
445
  | showAssistantAvatar | boolean | true | 显示助手头像(false 时助手消息不渲染头像;用户头像不受影响) |
@@ -500,7 +501,7 @@ Markdown 渲染(Sanitized by DOMPurify),内置 Prism 代码高亮与 KaTeX。
500
501
  | description | string | '' | 空态欢迎页描述 |
501
502
  | suggestions | AiMessagesSuggestion[] | [] | 空态建议列表 |
502
503
  | suggestionsTitle | string | '' | 空态建议区标题 |
503
- | scrollThreshold | number | 40 | 吸底阈值(px):距底不超过该值才自动跟随 |
504
+ | scrollThreshold | number | 100 | 用户上滚免打扰阈值(px):距底不超过该值视为「钉在底部」,流式期间自动跟随滚动 |
504
505
  | showScrollButton | boolean | true | 显示滚到底部悬浮按钮(空态不渲染) |
505
506
  | scrollButtonThreshold | number | 100 | 距底超过该值(px)才显示滚到底部悬浮按钮 |
506
507
  | showActions | boolean | true | 显示消息操作按钮(复制/重生成) |
package/dist/index.d.ts CHANGED
@@ -1641,6 +1641,8 @@ type __VLS_Props$2 = {
1641
1641
  showScrollButton?: boolean;
1642
1642
  /** 滚到底部悬浮按钮显示阈值(px,透传 AiMessages) */
1643
1643
  scrollButtonThreshold?: number;
1644
+ /** 用户上滚免打扰阈值(px,透传 AiMessages):距底不超过该值视为「钉在底部」,流式自动跟随 */
1645
+ scrollThreshold?: number;
1644
1646
  /** 显示用户头像(false 时用户消息不渲染头像;助手头像不受影响) */
1645
1647
  showUserAvatar?: boolean;
1646
1648
  /** 显示用户名称(false 时用户消息不渲染头部名称行;助手名称不受影响) */
@@ -1788,6 +1790,7 @@ declare const __VLS_base$1: vue.DefineComponent<__VLS_Props$2, {
1788
1790
  userName: string;
1789
1791
  assistantName: string;
1790
1792
  suggestions: AiChatSuggestion[];
1793
+ scrollThreshold: number;
1791
1794
  showScrollButton: boolean;
1792
1795
  scrollButtonThreshold: number;
1793
1796
  models: string[];
package/es/index.mjs CHANGED
@@ -5898,15 +5898,19 @@ ${fileParts.join("\n")}` });
5898
5898
  msgs.edit(assistantId, { backendId: id });
5899
5899
  },
5900
5900
  onTool: (ev) => {
5901
+ const label = (name) => options.toolStepLabel ? options.toolStepLabel(name) : name;
5901
5902
  const steps = [...msgs.messages.value[assistantId]?.toolSteps ?? []];
5902
5903
  if (ev.status === "start") {
5903
5904
  steps.push({
5904
5905
  key: `${ev.toolName}-${steps.length}`,
5905
- title: options.toolStepLabel ? options.toolStepLabel(ev.toolName) : ev.toolName,
5906
+ title: label(ev.toolName),
5906
5907
  status: "loading"
5907
5908
  });
5908
5909
  } else if (steps.length) {
5909
- steps[steps.length - 1] = { ...steps[steps.length - 1], status: "success" };
5910
+ let i = steps.length - 1;
5911
+ while (i >= 0 && !(steps[i].status === "loading" && steps[i].title === label(ev.toolName))) i--;
5912
+ if (i < 0) i = steps.length - 1;
5913
+ steps[i] = { ...steps[i], status: "success" };
5910
5914
  }
5911
5915
  msgs.edit(assistantId, { toolSteps: steps });
5912
5916
  options.onToolEvent?.(ev);
@@ -6112,12 +6116,12 @@ var _sfc_main$3 = /* @__PURE__ */ defineComponent({
6112
6116
  const steps = props.message.toolSteps ?? [];
6113
6117
  const running = props.message.status === "pending" || props.message.status === "streaming";
6114
6118
  return steps.map((s) => {
6115
- const loading = running && s.status !== "error" && s.status !== "success";
6116
- return {
6117
- ...s,
6118
- status: loading ? "loading" : s.status ?? "success",
6119
- title: `${loading ? "\u6B63\u5728\u67E5\u8BE2" : "\u5DF2\u67E5\u8BE2"}${s.title ?? ""}`
6120
- };
6119
+ if (running) {
6120
+ const loading = s.status !== "error" && s.status !== "success";
6121
+ return loading ? { ...s, status: "loading", title: `\u6B63\u5728\u67E5\u8BE2${s.title ?? ""}` } : { ...s, title: `\u5DF2\u67E5\u8BE2${s.title ?? ""}` };
6122
+ }
6123
+ const settled = s.status === "success" || s.status === "error" ? s.status : props.message.status === "error" ? "error" : "success";
6124
+ return { ...s, status: settled, title: `\u5DF2\u67E5\u8BE2${s.title ?? ""}` };
6121
6125
  });
6122
6126
  });
6123
6127
  const modelLabel = computed(() => props.message.model ?? "");
@@ -7023,6 +7027,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
7023
7027
  centerWelcome: { type: Boolean, required: false, default: true },
7024
7028
  showScrollButton: { type: Boolean, required: false, default: true },
7025
7029
  scrollButtonThreshold: { type: Number, required: false, default: 100 },
7030
+ scrollThreshold: { type: Number, required: false, default: 100 },
7026
7031
  showUserAvatar: { type: Boolean, required: false, default: true },
7027
7032
  showUserName: { type: Boolean, required: false, default: true },
7028
7033
  showAssistantAvatar: { type: Boolean, required: false, default: true },
@@ -7077,7 +7082,9 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
7077
7082
  adapter: resolveAdapter,
7078
7083
  models: () => isMultiple.value && selectedModels.value.length ? selectedModels.value : [""],
7079
7084
  initial: { messages: initialTable, currentId: initialId },
7080
- toolStepLabel: props.toolStepLabel,
7085
+ // 与 adapter/models 同语义按工厂惰性取用:options 在 setup 构造一次,
7086
+ // 按值快照会把父组件运行期更换的函数 prop 冻在旧引用上(换了映射不生效)
7087
+ toolStepLabel: (name) => props.toolStepLabel ? props.toolStepLabel(name) : name,
7081
7088
  onToolEvent: (ev) => emit("tool-event", ev)
7082
7089
  });
7083
7090
  const { send, stop: stopChat, regenerate: regenerateChat, msgs, isLoading } = chat;
@@ -7299,6 +7306,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
7299
7306
  suggestions: __props.suggestions,
7300
7307
  "show-scroll-button": __props.showScrollButton,
7301
7308
  "scroll-button-threshold": __props.scrollButtonThreshold,
7309
+ "scroll-threshold": __props.scrollThreshold,
7302
7310
  "show-user-avatar": __props.showUserAvatar,
7303
7311
  "show-user-name": __props.showUserName,
7304
7312
  "show-assistant-avatar": __props.showAssistantAvatar,
@@ -7379,7 +7387,7 @@ var _sfc_main = /* @__PURE__ */ defineComponent({
7379
7387
  ]),
7380
7388
  key: "8"
7381
7389
  } : void 0
7382
- ]), 1032, ["messages", "nodes", "name", "suggestions", "show-scroll-button", "scroll-button-threshold", "show-user-avatar", "show-user-name", "show-assistant-avatar", "show-assistant-name", "user-avatar", "assistant-avatar", "user-name", "assistant-name", "typing"]),
7390
+ ]), 1032, ["messages", "nodes", "name", "suggestions", "show-scroll-button", "scroll-button-threshold", "scroll-threshold", "show-user-avatar", "show-user-name", "show-assistant-avatar", "show-assistant-name", "user-avatar", "assistant-avatar", "user-name", "assistant-name", "typing"]),
7383
7391
  __props.features?.artifacts && artifacts.value.length ? (openBlock(), createBlock(_sfc_main$1, {
7384
7392
  key: 0,
7385
7393
  artifacts: artifacts.value,
package/lib/index.js CHANGED
@@ -5914,15 +5914,19 @@ ${fileParts.join("\n")}` });
5914
5914
  msgs.edit(assistantId, { backendId: id });
5915
5915
  },
5916
5916
  onTool: (ev) => {
5917
+ const label = (name) => options.toolStepLabel ? options.toolStepLabel(name) : name;
5917
5918
  const steps = [...msgs.messages.value[assistantId]?.toolSteps ?? []];
5918
5919
  if (ev.status === "start") {
5919
5920
  steps.push({
5920
5921
  key: `${ev.toolName}-${steps.length}`,
5921
- title: options.toolStepLabel ? options.toolStepLabel(ev.toolName) : ev.toolName,
5922
+ title: label(ev.toolName),
5922
5923
  status: "loading"
5923
5924
  });
5924
5925
  } else if (steps.length) {
5925
- steps[steps.length - 1] = { ...steps[steps.length - 1], status: "success" };
5926
+ let i = steps.length - 1;
5927
+ while (i >= 0 && !(steps[i].status === "loading" && steps[i].title === label(ev.toolName))) i--;
5928
+ if (i < 0) i = steps.length - 1;
5929
+ steps[i] = { ...steps[i], status: "success" };
5926
5930
  }
5927
5931
  msgs.edit(assistantId, { toolSteps: steps });
5928
5932
  options.onToolEvent?.(ev);
@@ -6128,12 +6132,12 @@ ${fileParts.join("\n")}` });
6128
6132
  const steps = props.message.toolSteps ?? [];
6129
6133
  const running = props.message.status === "pending" || props.message.status === "streaming";
6130
6134
  return steps.map((s) => {
6131
- const loading = running && s.status !== "error" && s.status !== "success";
6132
- return {
6133
- ...s,
6134
- status: loading ? "loading" : s.status ?? "success",
6135
- title: `${loading ? "\u6B63\u5728\u67E5\u8BE2" : "\u5DF2\u67E5\u8BE2"}${s.title ?? ""}`
6136
- };
6135
+ if (running) {
6136
+ const loading = s.status !== "error" && s.status !== "success";
6137
+ return loading ? { ...s, status: "loading", title: `\u6B63\u5728\u67E5\u8BE2${s.title ?? ""}` } : { ...s, title: `\u5DF2\u67E5\u8BE2${s.title ?? ""}` };
6138
+ }
6139
+ const settled = s.status === "success" || s.status === "error" ? s.status : props.message.status === "error" ? "error" : "success";
6140
+ return { ...s, status: settled, title: `\u5DF2\u67E5\u8BE2${s.title ?? ""}` };
6137
6141
  });
6138
6142
  });
6139
6143
  const modelLabel = vue.computed(() => props.message.model ?? "");
@@ -7039,6 +7043,7 @@ ${fileParts.join("\n")}` });
7039
7043
  centerWelcome: { type: Boolean, required: false, default: true },
7040
7044
  showScrollButton: { type: Boolean, required: false, default: true },
7041
7045
  scrollButtonThreshold: { type: Number, required: false, default: 100 },
7046
+ scrollThreshold: { type: Number, required: false, default: 100 },
7042
7047
  showUserAvatar: { type: Boolean, required: false, default: true },
7043
7048
  showUserName: { type: Boolean, required: false, default: true },
7044
7049
  showAssistantAvatar: { type: Boolean, required: false, default: true },
@@ -7093,7 +7098,9 @@ ${fileParts.join("\n")}` });
7093
7098
  adapter: resolveAdapter,
7094
7099
  models: () => isMultiple.value && selectedModels.value.length ? selectedModels.value : [""],
7095
7100
  initial: { messages: initialTable, currentId: initialId },
7096
- toolStepLabel: props.toolStepLabel,
7101
+ // 与 adapter/models 同语义按工厂惰性取用:options 在 setup 构造一次,
7102
+ // 按值快照会把父组件运行期更换的函数 prop 冻在旧引用上(换了映射不生效)
7103
+ toolStepLabel: (name) => props.toolStepLabel ? props.toolStepLabel(name) : name,
7097
7104
  onToolEvent: (ev) => emit("tool-event", ev)
7098
7105
  });
7099
7106
  const { send, stop: stopChat, regenerate: regenerateChat, msgs, isLoading } = chat;
@@ -7315,6 +7322,7 @@ ${fileParts.join("\n")}` });
7315
7322
  suggestions: __props.suggestions,
7316
7323
  "show-scroll-button": __props.showScrollButton,
7317
7324
  "scroll-button-threshold": __props.scrollButtonThreshold,
7325
+ "scroll-threshold": __props.scrollThreshold,
7318
7326
  "show-user-avatar": __props.showUserAvatar,
7319
7327
  "show-user-name": __props.showUserName,
7320
7328
  "show-assistant-avatar": __props.showAssistantAvatar,
@@ -7395,7 +7403,7 @@ ${fileParts.join("\n")}` });
7395
7403
  ]),
7396
7404
  key: "8"
7397
7405
  } : void 0
7398
- ]), 1032, ["messages", "nodes", "name", "suggestions", "show-scroll-button", "scroll-button-threshold", "show-user-avatar", "show-user-name", "show-assistant-avatar", "show-assistant-name", "user-avatar", "assistant-avatar", "user-name", "assistant-name", "typing"]),
7406
+ ]), 1032, ["messages", "nodes", "name", "suggestions", "show-scroll-button", "scroll-button-threshold", "scroll-threshold", "show-user-avatar", "show-user-name", "show-assistant-avatar", "show-assistant-name", "user-avatar", "assistant-avatar", "user-name", "assistant-name", "typing"]),
7399
7407
  __props.features?.artifacts && artifacts.value.length ? (vue.openBlock(), vue.createBlock(_sfc_main$1, {
7400
7408
  key: 0,
7401
7409
  artifacts: artifacts.value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fv-ui/ai-chat",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "基于 Vue3 + Element Plus 的 AI 对话组件库",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",