@agentscope-ai/chat 1.1.46-beta.1767852895377 → 1.1.46-beta.1767871771878

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.
@@ -20,12 +20,12 @@ function Layout(props: IProps, ref: React.Ref<any>) {
20
20
  const { className } = props;
21
21
  const prefixCls = useProviderContext().getPrefixCls('chat-anywhere-layout');
22
22
  const narrowMode = useChatAnywhereOptions(v => v.theme.narrowMode);
23
+ const background = useChatAnywhereOptions(v => v.theme.background);
23
24
  const rightHeader = useChatAnywhereOptions(v => v.theme.rightHeader);
24
25
  const { session } = useChatAnywhereOptions(v => ({ session: v.session }));
25
26
  const { collapsed } = useContext(ChatAnyWhereLayoutContext);
26
27
  const showLeft = !narrowMode && session && session.multiple;
27
28
 
28
-
29
29
  return <>
30
30
  <Style />
31
31
  <div className={cls(`${prefixCls}`, className)}>
@@ -38,11 +38,12 @@ function Layout(props: IProps, ref: React.Ref<any>) {
38
38
  }
39
39
  <div className={cls(`${prefixCls}-right`, {
40
40
  [`${prefixCls}-right-has-header`]: !!rightHeader,
41
- })}>
41
+ })} style={{
42
+ background: background,
43
+ }}>
42
44
  {
43
45
  !!rightHeader && <Header />
44
46
  }
45
-
46
47
  <Chat />
47
48
  </div>
48
49
  </div>
@@ -77,6 +77,12 @@ export interface IAgentScopeRuntimeWebUIThemeOptions {
77
77
  * @descriptionEn Typography configuration
78
78
  */
79
79
  typography?: IAgentScopeRuntimeWebUITypography;
80
+
81
+ /**
82
+ * @description 背景色
83
+ * @descriptionEn Background color
84
+ */
85
+ background?: string;
80
86
  }
81
87
 
82
88
  export interface IAgentScopeRuntimeWebUITypography {
@@ -0,0 +1,9 @@
1
+ import { IAudio } from "./types";
2
+ import { useProviderContext } from "..";
3
+
4
+
5
+ export default function Audio(props: IAudio) {
6
+ const prefixCls = useProviderContext().getPrefixCls('assets-preview-audio');
7
+
8
+ return <audio src={props.src} controls className={prefixCls} />;
9
+ }
@@ -0,0 +1,19 @@
1
+ import { useProviderContext } from "..";
2
+ import { IImage } from "./types";
3
+ import { Image, ConfigProvider } from 'antd';
4
+ import { Locale } from "antd/es/locale";
5
+
6
+
7
+ export default function (props: IImage) {
8
+ const prefixCls = useProviderContext().getPrefixCls('assets-preview-image');
9
+
10
+ return <div className={prefixCls} style={{
11
+ aspectRatio: `${props.width}/${props.height}`,
12
+ }}>
13
+ <ConfigProvider
14
+ locale={{
15
+ Image: { preview: '' }
16
+ } as Locale}
17
+ ><Image src={props.src} width={"100%"} height={"100%"} /></ConfigProvider>
18
+ </div>;
19
+ }
@@ -0,0 +1,13 @@
1
+ import { IVideo } from "./types";
2
+ import { useProviderContext } from "..";
3
+
4
+ export default function Video(props: IVideo) {
5
+ const prefixCls = useProviderContext().getPrefixCls('assets-preview-video');
6
+ const { width, height, ...rest } = props;
7
+
8
+ return <div className={prefixCls} style={{
9
+ aspectRatio: `${width}/${height}`,
10
+ }}>
11
+ <video {...rest} controls />
12
+ </div>
13
+ }
@@ -0,0 +1,49 @@
1
+ import { AssetsPreview } from '@agentscope-ai/chat';
2
+ import { Flex, Space } from 'antd';
3
+ import React from 'react';
4
+
5
+ export default function () {
6
+ return <Flex vertical gap={32}>
7
+ <AssetsPreview type="image" data={[
8
+ { src: 'https://img.alicdn.com/imgextra/i3/O1CN01dKprif1ar0awCMDwK_!!6000000003382-0-tps-2640-1100.jpg', width: 16, height: 9 },
9
+ ]} />
10
+
11
+
12
+ <AssetsPreview type="image" data={[
13
+ { src: 'https://img.alicdn.com/imgextra/i3/O1CN01dKprif1ar0awCMDwK_!!6000000003382-0-tps-2640-1100.jpg', width: 16, height: 9 },
14
+ { src: 'https://img.alicdn.com/imgextra/i3/O1CN01dKprif1ar0awCMDwK_!!6000000003382-0-tps-2640-1100.jpg', width: 16, height: 9 },
15
+ { src: 'https://img.alicdn.com/imgextra/i3/O1CN01dKprif1ar0awCMDwK_!!6000000003382-0-tps-2640-1100.jpg', width: 16, height: 9 },
16
+ { src: 'https://img.alicdn.com/imgextra/i3/O1CN01dKprif1ar0awCMDwK_!!6000000003382-0-tps-2640-1100.jpg', width: 16, height: 9 },
17
+ { src: 'https://img.alicdn.com/imgextra/i3/O1CN01dKprif1ar0awCMDwK_!!6000000003382-0-tps-2640-1100.jpg', width: 16, height: 9 },
18
+ { src: 'https://img.alicdn.com/imgextra/i3/O1CN01dKprif1ar0awCMDwK_!!6000000003382-0-tps-2640-1100.jpg', width: 16, height: 9 },
19
+ { src: 'https://img.alicdn.com/imgextra/i3/O1CN01dKprif1ar0awCMDwK_!!6000000003382-0-tps-2640-1100.jpg', width: 16, height: 9 },
20
+ { src: 'https://img.alicdn.com/imgextra/i3/O1CN01dKprif1ar0awCMDwK_!!6000000003382-0-tps-2640-1100.jpg', width: 16, height: 9 },
21
+ ]} />
22
+
23
+
24
+ <AssetsPreview type="video" data={[
25
+ { src: 'https://cloud.video.taobao.com/vod/m9amjbqLTGUvaGo3o61u-Ch2hycUCa3RA3pAw1-Zv_0.mp4', width: 16, height: 9 },
26
+
27
+ ]} />
28
+
29
+
30
+ <AssetsPreview type="video" data={[
31
+ { src: 'https://cloud.video.taobao.com/vod/m9amjbqLTGUvaGo3o61u-Ch2hycUCa3RA3pAw1-Zv_0.mp4', width: 16, height: 9 },
32
+ { src: 'https://cloud.video.taobao.com/vod/m9amjbqLTGUvaGo3o61u-Ch2hycUCa3RA3pAw1-Zv_0.mp4', width: 16, height: 9 },
33
+ { src: 'https://cloud.video.taobao.com/vod/m9amjbqLTGUvaGo3o61u-Ch2hycUCa3RA3pAw1-Zv_0.mp4', width: 16, height: 9 },
34
+
35
+ ]} />
36
+
37
+ <AssetsPreview type="audio" data={[
38
+ { src: 'https://cloud.video.taobao.com/vod/m9amjbqLTGUvaGo3o61u-Ch2hycUCa3RA3pAw1-Zv_0.mp4', },
39
+
40
+ ]} />
41
+
42
+ <AssetsPreview type="audio" data={[
43
+ { src: 'https://cloud.video.taobao.com/vod/m9amjbqLTGUvaGo3o61u-Ch2hycUCa3RA3pAw1-Zv_0.mp4', },
44
+ { src: 'https://cloud.video.taobao.com/vod/m9amjbqLTGUvaGo3o61u-Ch2hycUCa3RA3pAw1-Zv_0.mp4', },
45
+ { src: 'https://cloud.video.taobao.com/vod/m9amjbqLTGUvaGo3o61u-Ch2hycUCa3RA3pAw1-Zv_0.mp4', },
46
+
47
+ ]} />
48
+ </Flex>
49
+ }
@@ -7,3 +7,6 @@ description: ???
7
7
  ---
8
8
 
9
9
  <DemoTitle title="???" desc="???"></DemoTitle>
10
+
11
+
12
+ <code src="./demo/index.tsx"></code>
@@ -1,11 +1,110 @@
1
1
  import { useProviderContext } from '../Provider';
2
2
  import Style from './style';
3
+ import cls from 'classnames';
4
+ import { IImage, IVideo, IAudio } from './types';
5
+ import Image from './Image';
6
+ import Video from './Video';
7
+ import Audio from './Audio';
8
+ import { useCallback, useEffect, useRef, useState } from 'react';
9
+ import { SparkLeftLine, SparkRightLine } from '@agentscope-ai/icons';
10
+ import { IconButton } from '@agentscope-ai/design';
3
11
 
12
+ export interface IAssetsPreviewProps {
13
+ className?: string;
14
+ classNames?: {
15
+ container?: string;
16
+ };
17
+ height?: number;
18
+ type: 'image' | 'video' | 'audio';
19
+ data: (IImage | IVideo | IAudio)[];
20
+ }
4
21
 
5
- export default function () {
22
+ function AssetsPreview(props: IAssetsPreviewProps) {
6
23
  const prefixCls = useProviderContext().getPrefixCls('assets-preview');
24
+ const Component = {
25
+ image: Image,
26
+ video: Video,
27
+ audio: Audio,
28
+ }[props.type];
29
+ const ref = useRef<HTMLDivElement>(null);
30
+
31
+ useEffect(() => { }, [props.data.length])
32
+ const { height = 144 } = props;
33
+ const [arrowTop, setArrowTop] = useState<number>(0);
34
+ const [arrowShow, setArrowShow] = useState<'left' | 'right' | ''>('');
35
+ const maxWidth = useRef<number>(0);
36
+
37
+
38
+ const onScroll = useCallback((e) => {
39
+
40
+ if (e.target.scrollLeft > 0) {
41
+ setArrowShow('right');
42
+ }
43
+
44
+ if (e.target.scrollLeft >= maxWidth.current) {
45
+ setArrowShow('left')
46
+ }
47
+ }, [])
48
+
49
+
50
+ useEffect(() => {
51
+ setArrowTop(height / 2 - 12 - 6);
52
+ }, [height])
53
+
54
+
55
+ useEffect(() => {
56
+ if (ref.current && props.type !== 'audio') {
57
+ maxWidth.current = ref.current.scrollWidth - ref.current.clientWidth;
58
+ if (maxWidth.current > 0) {
59
+ setArrowShow('right');
60
+ } else {
61
+ }
62
+ }
63
+ }, [])
64
+
65
+
66
+ const toArrow = useCallback((direct: 'left' | 'right') => {
67
+ const width = ref.current.scrollWidth / props.data.length;
68
+ ref.current.scrollLeft = ref.current.scrollLeft + width * (direct === 'left' ? -1 : 1)
69
+ }, [props.data])
70
+
71
+
7
72
  return <>
8
73
  <Style />
9
- <div className={prefixCls}>...</div>
74
+ <div className={cls(`${prefixCls}`, props.className)}>
75
+ <div className={cls(`${prefixCls}-container`, props.className)} style={props.type !== 'audio' ? { height } : {
76
+ flexDirection: 'column'
77
+ }} onScroll={onScroll} ref={ref}>
78
+ {
79
+ props.data.map((item, index) => {
80
+ return <Component key={index} {...item as any} />;
81
+ })
82
+ }
83
+ </div>
84
+
85
+
86
+ {
87
+ arrowTop && props.type !== 'audio' ? <>
88
+ {
89
+ arrowShow === 'left' && <>
90
+ <div className={cls(`${prefixCls}-left-edge`)} />
91
+ <IconButton onClick={() => toArrow('left')} style={{ top: arrowTop }} className={cls(`${prefixCls}-left-arrow`, `${prefixCls}-arrow`)} size="small" shape='circle' icon={<SparkLeftLine />}></IconButton>
92
+ </>
93
+ }
94
+
95
+ {
96
+ arrowShow === 'right' && <>
97
+ <div className={cls(`${prefixCls}-right-edge`)} />
98
+ <IconButton onClick={() => toArrow('right')} style={{ top: arrowTop }} className={cls(`${prefixCls}-right-arrow`, `${prefixCls}-arrow`)} size="small" shape='circle' icon={<SparkRightLine />}></IconButton>
99
+ </>
100
+ }
101
+
102
+ </> : null
103
+ }
104
+
105
+ </div>
10
106
  </>
11
- }
107
+ }
108
+
109
+
110
+ export default AssetsPreview;
@@ -1,6 +1,80 @@
1
1
  import { createGlobalStyle } from 'antd-style';
2
2
 
3
3
  export default createGlobalStyle`
4
- .${(p) => p.theme.prefixCls}- {
4
+ .${(p) => p.theme.prefixCls}-assets-preview {
5
+ position: relative;
6
+
7
+ &-left-edge,
8
+ &-right-edge {
9
+ position: absolute;
10
+ top: 0;
11
+ bottom: 0;
12
+ width: 128px;
13
+ pointer-events: none;
14
+ }
15
+
16
+ &-left-edge {
17
+ left: 0;
18
+ }
19
+
20
+ &-right-edge {
21
+ right: 0;
22
+ }
23
+
24
+ &-arrow {
25
+ position: absolute;
26
+ bottom: 0;
27
+ }
28
+
29
+ &-left-arrow {
30
+ left: 10px;
31
+ }
32
+
33
+ &-right-arrow {
34
+ right: 10px;
35
+ }
36
+
37
+ &-container {
38
+ display: flex;
39
+ padding: 8px;
40
+ gap: 8px;
41
+ overflow-x: auto;
42
+ justify-content: safe center;
43
+ background-color: ${(p) => p.theme.colorFillTertiary};
44
+ }
45
+
46
+
47
+ &-image {
48
+ height: 100%;
49
+ flex-basis: auto;
50
+ flex-shrink: 0;
51
+ border-radius: 8px;
52
+ overflow: hidden;
53
+ background-size: cover;
54
+ background-position: center;
55
+ background-repeat: no-repeat;
56
+ }
57
+
58
+ &-video {
59
+ height: 100%;
60
+ flex-basis: auto;
61
+ flex-shrink: 0;
62
+ border-radius: 8px;
63
+ overflow: hidden;
64
+
65
+ video {
66
+ width: 100%;
67
+ height: 100%;
68
+ object-fit: cover;
69
+ }
70
+
71
+
72
+ }
73
+
74
+
75
+ &-audio {
76
+ display: block;
77
+ width: 100%;
78
+ }
5
79
  }
6
80
  `;
@@ -0,0 +1,14 @@
1
+ export interface IImage {
2
+ src: string;
3
+ width: number;
4
+ height: number;
5
+ }
6
+ export interface IVideo {
7
+ poster?: string;
8
+ src: string;
9
+ width: number;
10
+ height: number;
11
+ }
12
+ export interface IAudio {
13
+ src: string;
14
+ }
@@ -2,7 +2,6 @@ export { ConfigProvider } from 'antd';
2
2
 
3
3
  export { default as version } from './Version';
4
4
 
5
-
6
5
  export {
7
6
  CustomCardsContext,
8
7
  CustomCardsProvider,
@@ -87,4 +86,8 @@ export {
87
86
 
88
87
  export { default as AIGC } from './AIGC';
89
88
 
90
- export { Sandbox as GenerativeUISandbox } from './GenerativeUI';
89
+ export {
90
+ default as AssetsPreview,
91
+ type IAssetsPreviewProps,
92
+ } from './AssetsPreview';
93
+ export { Sandbox as GenerativeUISandbox } from './GenerativeUI';
@@ -22,6 +22,9 @@ function Layout(props, ref) {
22
22
  var narrowMode = useChatAnywhereOptions(function (v) {
23
23
  return v.theme.narrowMode;
24
24
  });
25
+ var background = useChatAnywhereOptions(function (v) {
26
+ return v.theme.background;
27
+ });
25
28
  var rightHeader = useChatAnywhereOptions(function (v) {
26
29
  return v.theme.rightHeader;
27
30
  });
@@ -42,6 +45,9 @@ function Layout(props, ref) {
42
45
  children: /*#__PURE__*/_jsx(Sessions, {})
43
46
  }), /*#__PURE__*/_jsxs("div", {
44
47
  className: cls("".concat(prefixCls, "-right"), _defineProperty({}, "".concat(prefixCls, "-right-has-header"), !!rightHeader)),
48
+ style: {
49
+ background: background
50
+ },
45
51
  children: [!!rightHeader && /*#__PURE__*/_jsx(Header, {}), /*#__PURE__*/_jsx(Chat, {})]
46
52
  })]
47
53
  }), /*#__PURE__*/_jsx(Ref, {
@@ -79,6 +79,11 @@ export interface IAgentScopeRuntimeWebUIThemeOptions {
79
79
  * @descriptionEn Typography configuration
80
80
  */
81
81
  typography?: IAgentScopeRuntimeWebUITypography;
82
+ /**
83
+ * @description 背景色
84
+ * @descriptionEn Background color
85
+ */
86
+ background?: string;
82
87
  }
83
88
  export interface IAgentScopeRuntimeWebUITypography {
84
89
  /**
@@ -0,0 +1,2 @@
1
+ import { IAudio } from "./types";
2
+ export default function Audio(props: IAudio): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { useProviderContext } from "..";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export default function Audio(props) {
4
+ var prefixCls = useProviderContext().getPrefixCls('assets-preview-audio');
5
+ return /*#__PURE__*/_jsx("audio", {
6
+ src: props.src,
7
+ controls: true,
8
+ className: prefixCls
9
+ });
10
+ }
@@ -0,0 +1,2 @@
1
+ import { IImage } from "./types";
2
+ export default function (props: IImage): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,24 @@
1
+ import { useProviderContext } from "..";
2
+ import { Image, ConfigProvider } from 'antd';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ export default function (props) {
5
+ var prefixCls = useProviderContext().getPrefixCls('assets-preview-image');
6
+ return /*#__PURE__*/_jsx("div", {
7
+ className: prefixCls,
8
+ style: {
9
+ aspectRatio: "".concat(props.width, "/").concat(props.height)
10
+ },
11
+ children: /*#__PURE__*/_jsx(ConfigProvider, {
12
+ locale: {
13
+ Image: {
14
+ preview: ''
15
+ }
16
+ },
17
+ children: /*#__PURE__*/_jsx(Image, {
18
+ src: props.src,
19
+ width: "100%",
20
+ height: "100%"
21
+ })
22
+ })
23
+ });
24
+ }
@@ -0,0 +1,2 @@
1
+ import { IVideo } from "./types";
2
+ export default function Video(props: IVideo): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,26 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ var _excluded = ["width", "height"];
3
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
7
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
8
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
+ import { useProviderContext } from "..";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ export default function Video(props) {
13
+ var prefixCls = useProviderContext().getPrefixCls('assets-preview-video');
14
+ var width = props.width,
15
+ height = props.height,
16
+ rest = _objectWithoutProperties(props, _excluded);
17
+ return /*#__PURE__*/_jsx("div", {
18
+ className: prefixCls,
19
+ style: {
20
+ aspectRatio: "".concat(width, "/").concat(height)
21
+ },
22
+ children: /*#__PURE__*/_jsx("video", _objectSpread(_objectSpread({}, rest), {}, {
23
+ controls: true
24
+ }))
25
+ });
26
+ }
@@ -1 +1,12 @@
1
- export default function (): import("react/jsx-runtime").JSX.Element;
1
+ import { IImage, IVideo, IAudio } from './types';
2
+ export interface IAssetsPreviewProps {
3
+ className?: string;
4
+ classNames?: {
5
+ container?: string;
6
+ };
7
+ height?: number;
8
+ type: 'image' | 'video' | 'audio';
9
+ data: (IImage | IVideo | IAudio)[];
10
+ }
11
+ declare function AssetsPreview(props: IAssetsPreviewProps): import("react/jsx-runtime").JSX.Element;
12
+ export default AssetsPreview;
@@ -1,14 +1,119 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
13
  import { useProviderContext } from "../Provider";
2
14
  import Style from "./style";
15
+ import cls from 'classnames';
16
+ import Image from "./Image";
17
+ import Video from "./Video";
18
+ import Audio from "./Audio";
19
+ import { useCallback, useEffect, useRef, useState } from 'react';
20
+ import { SparkLeftLine, SparkRightLine } from '@agentscope-ai/icons';
21
+ import { IconButton } from '@agentscope-ai/design';
3
22
  import { jsx as _jsx } from "react/jsx-runtime";
4
23
  import { Fragment as _Fragment } from "react/jsx-runtime";
5
24
  import { jsxs as _jsxs } from "react/jsx-runtime";
6
- export default function () {
25
+ function AssetsPreview(props) {
7
26
  var prefixCls = useProviderContext().getPrefixCls('assets-preview');
27
+ var Component = {
28
+ image: Image,
29
+ video: Video,
30
+ audio: Audio
31
+ }[props.type];
32
+ var ref = useRef(null);
33
+ useEffect(function () {}, [props.data.length]);
34
+ var _props$height = props.height,
35
+ height = _props$height === void 0 ? 144 : _props$height;
36
+ var _useState = useState(0),
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ arrowTop = _useState2[0],
39
+ setArrowTop = _useState2[1];
40
+ var _useState3 = useState(''),
41
+ _useState4 = _slicedToArray(_useState3, 2),
42
+ arrowShow = _useState4[0],
43
+ setArrowShow = _useState4[1];
44
+ var maxWidth = useRef(0);
45
+ var onScroll = useCallback(function (e) {
46
+ if (e.target.scrollLeft > 0) {
47
+ setArrowShow('right');
48
+ }
49
+ if (e.target.scrollLeft >= maxWidth.current) {
50
+ setArrowShow('left');
51
+ }
52
+ }, []);
53
+ useEffect(function () {
54
+ setArrowTop(height / 2 - 12 - 6);
55
+ }, [height]);
56
+ useEffect(function () {
57
+ if (ref.current && props.type !== 'audio') {
58
+ maxWidth.current = ref.current.scrollWidth - ref.current.clientWidth;
59
+ if (maxWidth.current > 0) {
60
+ setArrowShow('right');
61
+ } else {}
62
+ }
63
+ }, []);
64
+ var toArrow = useCallback(function (direct) {
65
+ var width = ref.current.scrollWidth / props.data.length;
66
+ ref.current.scrollLeft = ref.current.scrollLeft + width * (direct === 'left' ? -1 : 1);
67
+ }, [props.data]);
8
68
  return /*#__PURE__*/_jsxs(_Fragment, {
9
- children: [/*#__PURE__*/_jsx(Style, {}), /*#__PURE__*/_jsx("div", {
10
- className: prefixCls,
11
- children: "..."
69
+ children: [/*#__PURE__*/_jsx(Style, {}), /*#__PURE__*/_jsxs("div", {
70
+ className: cls("".concat(prefixCls), props.className),
71
+ children: [/*#__PURE__*/_jsx("div", {
72
+ className: cls("".concat(prefixCls, "-container"), props.className),
73
+ style: props.type !== 'audio' ? {
74
+ height: height
75
+ } : {
76
+ flexDirection: 'column'
77
+ },
78
+ onScroll: onScroll,
79
+ ref: ref,
80
+ children: props.data.map(function (item, index) {
81
+ return /*#__PURE__*/_jsx(Component, _objectSpread({}, item), index);
82
+ })
83
+ }), arrowTop && props.type !== 'audio' ? /*#__PURE__*/_jsxs(_Fragment, {
84
+ children: [arrowShow === 'left' && /*#__PURE__*/_jsxs(_Fragment, {
85
+ children: [/*#__PURE__*/_jsx("div", {
86
+ className: cls("".concat(prefixCls, "-left-edge"))
87
+ }), /*#__PURE__*/_jsx(IconButton, {
88
+ onClick: function onClick() {
89
+ return toArrow('left');
90
+ },
91
+ style: {
92
+ top: arrowTop
93
+ },
94
+ className: cls("".concat(prefixCls, "-left-arrow"), "".concat(prefixCls, "-arrow")),
95
+ size: "small",
96
+ shape: "circle",
97
+ icon: /*#__PURE__*/_jsx(SparkLeftLine, {})
98
+ })]
99
+ }), arrowShow === 'right' && /*#__PURE__*/_jsxs(_Fragment, {
100
+ children: [/*#__PURE__*/_jsx("div", {
101
+ className: cls("".concat(prefixCls, "-right-edge"))
102
+ }), /*#__PURE__*/_jsx(IconButton, {
103
+ onClick: function onClick() {
104
+ return toArrow('right');
105
+ },
106
+ style: {
107
+ top: arrowTop
108
+ },
109
+ className: cls("".concat(prefixCls, "-right-arrow"), "".concat(prefixCls, "-arrow")),
110
+ size: "small",
111
+ shape: "circle",
112
+ icon: /*#__PURE__*/_jsx(SparkRightLine, {})
113
+ })]
114
+ })]
115
+ }) : null]
12
116
  })]
13
117
  });
14
- }
118
+ }
119
+ export default AssetsPreview;
@@ -1,6 +1,8 @@
1
1
  var _templateObject;
2
2
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
3
3
  import { createGlobalStyle } from 'antd-style';
4
- export default createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n.", "- {\n}\n"])), function (p) {
4
+ export default createGlobalStyle(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n.", "-assets-preview {\n position: relative;\n\n &-left-edge,\n &-right-edge {\n position: absolute;\n top: 0;\n bottom: 0;\n width: 128px;\n pointer-events: none;\n }\n\n &-left-edge {\n left: 0;\n }\n\n &-right-edge {\n right: 0;\n }\n\n &-arrow {\n position: absolute;\n bottom: 0;\n }\n\n &-left-arrow {\n left: 10px;\n }\n\n &-right-arrow {\n right: 10px;\n }\n\n &-container {\n display: flex;\n padding: 8px;\n gap: 8px;\n overflow-x: auto;\n justify-content: safe center;\n background-color: ", ";\n }\n\n\n &-image {\n height: 100%;\n flex-basis: auto;\n flex-shrink: 0;\n border-radius: 8px;\n overflow: hidden;\n background-size: cover;\n background-position: center;\n background-repeat: no-repeat;\n }\n\n &-video {\n height: 100%;\n flex-basis: auto;\n flex-shrink: 0;\n border-radius: 8px;\n overflow: hidden;\n\n video {\n width: 100%;\n height: 100%;\n object-fit: cover;\n }\n\n\n }\n\n \n &-audio {\n display: block;\n width: 100%;\n }\n}\n"])), function (p) {
5
5
  return p.theme.prefixCls;
6
+ }, function (p) {
7
+ return p.theme.colorFillTertiary;
6
8
  });
@@ -0,0 +1,14 @@
1
+ export interface IImage {
2
+ src: string;
3
+ width: number;
4
+ height: number;
5
+ }
6
+ export interface IVideo {
7
+ poster?: string;
8
+ src: string;
9
+ width: number;
10
+ height: number;
11
+ }
12
+ export interface IAudio {
13
+ src: string;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
package/lib/index.d.ts CHANGED
@@ -26,4 +26,5 @@ export { default as sleep } from './Util/sleep';
26
26
  export { default as Welcome, type IWelcomeProps } from './Welcome';
27
27
  export { default as Markdown, type MarkdownProps as IMarkdownProps, type MarkdownProps, } from './Markdown';
28
28
  export { default as AIGC } from './AIGC';
29
+ export { default as AssetsPreview, type IAssetsPreviewProps, } from './AssetsPreview';
29
30
  export { Sandbox as GenerativeUISandbox } from './GenerativeUI';
package/lib/index.js CHANGED
@@ -25,4 +25,5 @@ export { default as sleep } from "./Util/sleep";
25
25
  export { default as Welcome } from "./Welcome";
26
26
  export { default as Markdown } from "./Markdown";
27
27
  export { default as AIGC } from "./AIGC";
28
+ export { default as AssetsPreview } from "./AssetsPreview";
28
29
  export { Sandbox as GenerativeUISandbox } from "./GenerativeUI";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentscope-ai/chat",
3
- "version": "1.1.46-beta.1767852895377",
3
+ "version": "1.1.46-beta.1767871771878",
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": [