@done-coding/forge-kit-agent 0.102.0 → 0.102.1-alpha.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/README.md CHANGED
@@ -15,6 +15,11 @@ import { AiDialogue } from "@done-coding/forge-kit-agent";
15
15
  import "@done-coding/forge-kit-agent/style.css";
16
16
  ```
17
17
 
18
+ ## 接入前提(受控件与全流程件通用)
19
+
20
+ - **必须包 `AiConfigProvider`**:它按 `is-dark-theme` 注入 `--dc-agent-*` 主题变量,并提供 expose 通道。`AiMessageList`、`AiSender` 等受控件不包它也能渲染、不报错,但主题变量与气泡样式缺失(颜色、阅读宽度都不对)。
21
+ - **必须引入 `@done-coding/forge-kit-agent/style.css`**:库构建 CSS 与 JS 分离,`@done-coding/forge/style.css` **不含** kit 的样式。在应用入口与 forge 样式一并引入,顺序为先 forge、后 kit(kit 的样式只作用于自身类名,与 forge 互不覆盖)。
22
+
18
23
  ## 消费边界
19
24
 
20
25
  注入键沿用历史 namespace,保持既有 bridge 配对。
@@ -1,7 +1,7 @@
1
1
  import _sfc_main from "./AiMessageList.vue2.mjs";
2
2
  /* empty css */
3
3
  import _export_sfc from "../../_virtual/_plugin-vue_export-helper.mjs";
4
- const AiMessageList = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-b534d381"]]);
4
+ const AiMessageList = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-ba760c28"]]);
5
5
  export {
6
6
  AiMessageList as default
7
7
  };
@@ -1,9 +1,10 @@
1
- import { defineComponent, computed, openBlock, createBlock, unref, withCtx, createElementBlock, Fragment, renderList, renderSlot, createVNode } from "vue";
1
+ import { defineComponent, computed, ref, openBlock, createBlock, resolveDynamicComponent, unref, mergeProps, withCtx, createElementBlock, Fragment, renderList, renderSlot, createVNode } from "vue";
2
2
  import { BubbleList } from "vue-element-plus-x";
3
3
  import { normalizeParts, aiIsDataPart, AiChatRoleEnum } from "../../types/index.mjs";
4
4
  import { useCodeXSlot } from "../../hooks/CodeXSlot.mjs";
5
5
  import AiBubbleContent from "../bubble/AiBubbleContent.vue.mjs";
6
6
  import AiPartRenderer from "../bubble/AiPartRenderer.vue.mjs";
7
+ import AiMessageScroller from "./AiMessageScroller.vue.mjs";
7
8
  const _hoisted_1 = {
8
9
  key: 1,
9
10
  class: "ai-message-list-empty"
@@ -13,10 +14,21 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
13
14
  props: {
14
15
  messages: {},
15
16
  allowHtml: { type: Boolean, default: true },
16
- bubbleMaxWidth: { default: "100%" }
17
+ bubbleMaxWidth: { default: "100%" },
18
+ loadEarlier: {},
19
+ hasEarlier: { type: Boolean, default: true }
17
20
  },
18
- setup(__props) {
21
+ setup(__props, { expose: __expose }) {
19
22
  const props = __props;
23
+ const earlierEnabled = computed(() => typeof props.loadEarlier === "function");
24
+ const scrollerRef = ref();
25
+ __expose({
26
+ /** 滚到最新一条(仅启用 loadEarlier 时生效) */
27
+ scrollToEnd: () => {
28
+ var _a, _b;
29
+ return (_b = (_a = scrollerRef.value) == null ? void 0 : _a.scrollToEnd) == null ? void 0 : _b.call(_a);
30
+ }
31
+ });
20
32
  const { codeXSlot } = useCodeXSlot();
21
33
  const msgItem = (item) => item;
22
34
  const roleToEnum = (role) => role === "assistant" ? AiChatRoleEnum.AI : AiChatRoleEnum.USER;
@@ -57,12 +69,15 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
57
69
  };
58
70
  const isDataPart = aiIsDataPart;
59
71
  return (_ctx, _cache) => {
60
- return bubbleList.value.length ? (openBlock(), createBlock(unref(BubbleList), {
61
- key: 0,
62
- list: bubbleList.value,
63
- "max-height": "100%",
64
- class: "ai-message-list"
65
- }, {
72
+ return earlierEnabled.value || bubbleList.value.length ? (openBlock(), createBlock(resolveDynamicComponent(earlierEnabled.value ? AiMessageScroller : unref(BubbleList)), mergeProps(
73
+ {
74
+ key: 0,
75
+ ref_key: "scrollerRef",
76
+ ref: scrollerRef
77
+ },
78
+ earlierEnabled.value ? { list: bubbleList.value, loadEarlier: __props.loadEarlier, hasEarlier: __props.hasEarlier } : { list: bubbleList.value, maxHeight: "100%" },
79
+ { class: "ai-message-list" }
80
+ ), {
66
81
  content: withCtx(({ item }) => [
67
82
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(normalizeParts)(msgItem(item).__message), (part, index) => {
68
83
  return openBlock(), createElementBlock(Fragment, {
@@ -100,7 +115,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
100
115
  }), 128))
101
116
  ]),
102
117
  _: 3
103
- }, 8, ["list"])) : (openBlock(), createElementBlock("div", _hoisted_1, [
118
+ }, 16)) : (openBlock(), createElementBlock("div", _hoisted_1, [
104
119
  renderSlot(_ctx.$slots, "empty", {}, void 0, true)
105
120
  ]));
106
121
  };
@@ -0,0 +1,7 @@
1
+ import _sfc_main from "./AiMessageScroller.vue2.mjs";
2
+ /* empty css */
3
+ import _export_sfc from "../../_virtual/_plugin-vue_export-helper.mjs";
4
+ const AiMessageScroller = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-b633d10c"]]);
5
+ export {
6
+ AiMessageScroller as default
7
+ };
@@ -0,0 +1,95 @@
1
+ import { defineComponent, ref, computed, watch, nextTick, openBlock, createElementBlock, createVNode, unref, withCtx, renderSlot } from "vue";
2
+ import { Bubble } from "vue-element-plus-x";
3
+ import { InfiniteListView } from "@done-coding/forge";
4
+ const STICK_THRESHOLD = 80;
5
+ const _sfc_main = /* @__PURE__ */ defineComponent({
6
+ __name: "AiMessageScroller",
7
+ props: {
8
+ list: {},
9
+ loadEarlier: { type: Function },
10
+ hasEarlier: { type: Boolean }
11
+ },
12
+ setup(__props, { expose: __expose }) {
13
+ const props = __props;
14
+ const itemKey = (item) => item.uuid;
15
+ const listRef = ref();
16
+ const loadingMore = ref(false);
17
+ const error = ref(null);
18
+ const stickToBottom = ref(true);
19
+ const runLoadEarlier = async () => {
20
+ if (loadingMore.value) return;
21
+ loadingMore.value = true;
22
+ error.value = null;
23
+ try {
24
+ await props.loadEarlier();
25
+ } catch (e) {
26
+ error.value = e instanceof Error ? e.message : String(e);
27
+ } finally {
28
+ loadingMore.value = false;
29
+ }
30
+ };
31
+ const onScroll = (event) => {
32
+ var _a;
33
+ const el = event.target;
34
+ if (!((_a = el.classList) == null ? void 0 : _a.contains("infinite-list-view"))) return;
35
+ stickToBottom.value = el.scrollHeight - el.scrollTop - el.clientHeight <= STICK_THRESHOLD;
36
+ };
37
+ const scrollToEnd = () => {
38
+ var _a;
39
+ return (_a = listRef.value) == null ? void 0 : _a.scrollToEnd();
40
+ };
41
+ const tailSignature = computed(() => {
42
+ const last = props.list[props.list.length - 1];
43
+ if (!last) return "";
44
+ return `${last.uuid}:${JSON.stringify(last.__message ?? last.content).length}`;
45
+ });
46
+ watch(tailSignature, (next, prev) => {
47
+ if (!prev || !next || !stickToBottom.value) return;
48
+ nextTick(scrollToEnd);
49
+ });
50
+ __expose({ scrollToEnd });
51
+ return (_ctx, _cache) => {
52
+ return openBlock(), createElementBlock("div", {
53
+ class: "ai-message-scroller",
54
+ onScrollCapturePassive: onScroll
55
+ }, [
56
+ createVNode(unref(InfiniteListView), {
57
+ ref_key: "listRef",
58
+ ref: listRef,
59
+ data: __props.list,
60
+ "item-key": itemKey,
61
+ direction: "backward",
62
+ "max-height": "100%",
63
+ card: false,
64
+ surface: false,
65
+ "item-gap": 16,
66
+ "estimate-size": 120,
67
+ "loading-more": loadingMore.value,
68
+ error: error.value,
69
+ finished: !__props.hasEarlier,
70
+ "end-text": "没有更早的消息了",
71
+ onLoadMore: runLoadEarlier,
72
+ onRetry: runLoadEarlier
73
+ }, {
74
+ item: withCtx(({ item }) => [
75
+ createVNode(unref(Bubble), {
76
+ placement: item.placement,
77
+ "max-width": item.maxWidth,
78
+ typing: false,
79
+ content: ""
80
+ }, {
81
+ content: withCtx(() => [
82
+ renderSlot(_ctx.$slots, "content", { item }, void 0, true)
83
+ ]),
84
+ _: 2
85
+ }, 1032, ["placement", "max-width"])
86
+ ]),
87
+ _: 3
88
+ }, 8, ["data", "loading-more", "error", "finished"])
89
+ ], 32);
90
+ };
91
+ }
92
+ });
93
+ export {
94
+ _sfc_main as default
95
+ };
package/es/style.css CHANGED
@@ -791,20 +791,24 @@ to {
791
791
  opacity: 1;
792
792
  pointer-events: auto;
793
793
  }
794
- .ai-message-list[data-v-b534d381] {
794
+ .ai-message-scroller[data-v-b633d10c] {
795
+ height: 100%;
796
+ min-height: 0;
797
+ }
798
+ .ai-message-list[data-v-ba760c28] {
795
799
  container-type: inline-size;
796
800
  container-name: dc-agent;
797
801
  }
798
802
  @media (hover: none) {
799
- .ai-message-list[data-v-b534d381] .el-bubble-list {
803
+ .ai-message-list[data-v-ba760c28] .el-bubble-list {
800
804
  overscroll-behavior: contain;
801
805
  -webkit-overflow-scrolling: touch;
802
806
  }
803
807
  }
804
- .ai-message-list-empty[data-v-b534d381] {
808
+ .ai-message-list-empty[data-v-ba760c28] {
805
809
  width: 100%;
806
810
  }
807
- .ai-message-list-unsupported[data-v-b534d381] {
811
+ .ai-message-list-unsupported[data-v-ba760c28] {
808
812
  display: inline-block;
809
813
  font-size: var(--dc-agent-font-size-sm);
810
814
  color: var(--dc-agent-text);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@done-coding/forge-kit-agent",
3
- "version": "0.102.0",
3
+ "version": "0.102.1-alpha.0",
4
4
  "description": "Vue 3 AI 对话与智能体 UI 组件库",
5
5
  "private": false,
6
6
  "module": "es/index.mjs",
@@ -68,6 +68,7 @@
68
68
  "vue-tsc": "^2.2.12"
69
69
  },
70
70
  "peerDependencies": {
71
+ "@done-coding/forge": "0.102.1-alpha.0",
71
72
  "@element-plus/icons-vue": "^2.3.1",
72
73
  "element-plus": "^2.7.0",
73
74
  "lodash": "^4.17.21",
@@ -81,5 +82,5 @@
81
82
  "node": ">=18.0.0",
82
83
  "pnpm": ">=9.0.0"
83
84
  },
84
- "gitHead": "0daee92b3adc7d7f115bb001c5dd1ee4ae8111f3"
85
+ "gitHead": "2ef6be4abe702cc98918e0fc8d91a1b154f74094"
85
86
  }
@@ -6,6 +6,13 @@ type __VLS_Props = {
6
6
  allowHtml?: boolean;
7
7
  /** 用户气泡最大宽度,默认 '100%'。 */
8
8
  bubbleMaxWidth?: string;
9
+ /**
10
+ * 加载更早消息(可选)。传了才启用反向加载:滚到顶调用,进行中不重复,reject 可重试;
11
+ * 不传则仍是 BubbleList 路径,行为不变。
12
+ */
13
+ loadEarlier?: () => Promise<unknown>;
14
+ /** 是否还有更早的消息,默认 true;false 后不再调用 `loadEarlier`。 */
15
+ hasEarlier?: boolean;
9
16
  };
10
17
  declare function __VLS_template(): {
11
18
  attrs: Partial<{}>;
@@ -48,14 +55,22 @@ declare function __VLS_template(): {
48
55
  /** 空列表态。 */
49
56
  empty: () => unknown;
50
57
  };
51
- refs: {};
58
+ refs: {
59
+ scrollerRef: any;
60
+ };
52
61
  rootEl: any;
53
62
  };
54
63
  type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
55
- declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
64
+ declare const __VLS_component: import('vue').DefineComponent<__VLS_Props, {
65
+ /** 滚到最新一条(仅启用 loadEarlier 时生效) */
66
+ scrollToEnd: () => void | undefined;
67
+ }, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
56
68
  allowHtml: boolean;
57
69
  bubbleMaxWidth: string;
58
- }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>;
70
+ hasEarlier: boolean;
71
+ }, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {
72
+ scrollerRef: any;
73
+ }, any>;
59
74
  declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
60
75
  export default _default;
61
76
  type __VLS_WithTemplateSlots<T, S> = T & {
@@ -0,0 +1,31 @@
1
+ import { XBubbleListItemProps } from '../../types';
2
+ declare const _default: <T extends XBubbleListItemProps>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_PrettifyLocal<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
3
+ props: __VLS_PrettifyLocal<Pick<Partial<{}> & Omit<{} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps, never>, never> & {
4
+ /** 气泡项(AiMessageList 已映射) */
5
+ list: T[];
6
+ /** 加载更早消息 */
7
+ loadEarlier: () => Promise<unknown>;
8
+ /** 是否还有更早的 */
9
+ hasEarlier: boolean;
10
+ } & Partial<{}>> & import('vue').PublicProps;
11
+ expose(exposed: import('vue').ShallowUnwrapRef<{
12
+ scrollToEnd: () => void | undefined;
13
+ }>): void;
14
+ attrs: any;
15
+ slots: Readonly<{
16
+ content: (props: {
17
+ item: T;
18
+ }) => unknown;
19
+ }> & {
20
+ content: (props: {
21
+ item: T;
22
+ }) => unknown;
23
+ };
24
+ emit: {};
25
+ }>) => import('vue').VNode & {
26
+ __ctx?: Awaited<typeof __VLS_setup>;
27
+ };
28
+ export default _default;
29
+ type __VLS_PrettifyLocal<T> = {
30
+ [K in keyof T]: T[K];
31
+ } & {};