@agentscope-ai/chat 1.1.68-beta.1780902884191 → 1.1.69

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.
@@ -58,18 +58,35 @@ export interface IRagProps {
58
58
  filters?: string;
59
59
  }
60
60
 
61
- function Images({ images }: { images: string[] }) {
61
+ // 兼容上游传入的 images 类型不规范(如单个字符串、null 等),统一归一化为字符串数组
62
+ function normalizeImages(images?: string[] | string | null): string[] {
63
+ if (Array.isArray(images)) {
64
+ return images.filter((image): image is string => typeof image === 'string' && !!image);
65
+ }
66
+ if (typeof images === 'string' && images) {
67
+ return [images];
68
+ }
69
+ return [];
70
+ }
71
+
72
+ function Images({ images }: { images?: string[] | string | null }) {
62
73
  const { getPrefixCls } = useProviderContext();
63
74
 
64
75
  const prefixCls = getPrefixCls('operate-card');
65
76
 
77
+ const imageList = normalizeImages(images);
78
+
79
+ if (!imageList.length) {
80
+ return null;
81
+ }
82
+
66
83
  return <ConfigProvider
67
84
  locale={{
68
85
  Image: { preview: '' }
69
86
  } as Locale}
70
87
  >
71
88
  <Image.PreviewGroup>
72
- {images.map((image, index) => <Image src={image} key={index} width={44} height={44} />)}
89
+ {imageList.map((image, index) => <Image src={image} key={index} width={44} height={44} />)}
73
90
  </Image.PreviewGroup>
74
91
  </ConfigProvider>
75
92
 
@@ -106,10 +123,10 @@ function Item({ item }) {
106
123
  <div className={`${prefixCls}-rag-item-content-text`}>{item.content}</div>
107
124
 
108
125
  {
109
- item.images &&
126
+ normalizeImages(item.images).length ?
110
127
  <div className={`${prefixCls}-rag-item-images`}>
111
128
  <Images images={item.images} />
112
- </div>
129
+ </div> : null
113
130
  }
114
131
 
115
132
  {
@@ -146,7 +163,7 @@ export default function (props: IRagProps) {
146
163
  </div>
147
164
 
148
165
  {
149
- images?.length ? <div>
166
+ normalizeImages(images).length ? <div>
150
167
  <div className={`${prefixCls}-rag-group-title`}>检索图片</div>
151
168
  <div className={`${prefixCls}-rag-group-content ${prefixCls}-rag-group-content-images`}>
152
169
  <Images images={images} />
@@ -13,11 +13,27 @@ import { useState } from 'react';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { jsxs as _jsxs } from "react/jsx-runtime";
15
15
  import { Fragment as _Fragment } from "react/jsx-runtime";
16
+ // 兼容上游传入的 images 类型不规范(如单个字符串、null 等),统一归一化为字符串数组
17
+ function normalizeImages(images) {
18
+ if (Array.isArray(images)) {
19
+ return images.filter(function (image) {
20
+ return typeof image === 'string' && !!image;
21
+ });
22
+ }
23
+ if (typeof images === 'string' && images) {
24
+ return [images];
25
+ }
26
+ return [];
27
+ }
16
28
  function Images(_ref) {
17
29
  var images = _ref.images;
18
30
  var _useProviderContext = useProviderContext(),
19
31
  getPrefixCls = _useProviderContext.getPrefixCls;
20
32
  var prefixCls = getPrefixCls('operate-card');
33
+ var imageList = normalizeImages(images);
34
+ if (!imageList.length) {
35
+ return null;
36
+ }
21
37
  return /*#__PURE__*/_jsx(ConfigProvider, {
22
38
  locale: {
23
39
  Image: {
@@ -25,7 +41,7 @@ function Images(_ref) {
25
41
  }
26
42
  },
27
43
  children: /*#__PURE__*/_jsx(Image.PreviewGroup, {
28
- children: images.map(function (image, index) {
44
+ children: imageList.map(function (image, index) {
29
45
  return /*#__PURE__*/_jsx(Image, {
30
46
  src: image,
31
47
  width: 44,
@@ -72,12 +88,12 @@ function Item(_ref2) {
72
88
  children: [/*#__PURE__*/_jsx("div", {
73
89
  className: "".concat(prefixCls, "-rag-item-content-text"),
74
90
  children: item.content
75
- }), item.images && /*#__PURE__*/_jsx("div", {
91
+ }), normalizeImages(item.images).length ? /*#__PURE__*/_jsx("div", {
76
92
  className: "".concat(prefixCls, "-rag-item-images"),
77
93
  children: /*#__PURE__*/_jsx(Images, {
78
94
  images: item.images
79
95
  })
80
- }), item.link ? /*#__PURE__*/_jsx("a", {
96
+ }) : null, item.link ? /*#__PURE__*/_jsx("a", {
81
97
  onClick: function onClick() {
82
98
  window.open(item.link, '_blank');
83
99
  },
@@ -115,7 +131,7 @@ export default function (props) {
115
131
  className: "".concat(prefixCls, "-rag-group-content"),
116
132
  children: query
117
133
  })]
118
- }), images !== null && images !== void 0 && images.length ? /*#__PURE__*/_jsxs("div", {
134
+ }), normalizeImages(images).length ? /*#__PURE__*/_jsxs("div", {
119
135
  children: [/*#__PURE__*/_jsx("div", {
120
136
  className: "".concat(prefixCls, "-rag-group-title"),
121
137
  children: "\u68C0\u7D22\u56FE\u7247"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentscope-ai/chat",
3
- "version": "1.1.68-beta.1780902884191",
3
+ "version": "1.1.69",
4
4
  "description": "a free and open-source chat framework for building excellent LLM-powered chat experiences",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": [