@agentscope-ai/chat 1.1.45-beta.1766049774988 → 1.1.45-beta.1766386435551
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/components/ChatAnywhere/Input/index.tsx +34 -17
- package/components/ChatAnywhere/hooks/types.ts +1 -0
- package/components/GenerativeUI/Sandbox.tsx +7 -0
- package/components/GenerativeUI/index.tsx +1 -0
- package/components/index.ts +3 -1
- package/lib/ChatAnywhere/Input/index.js +34 -19
- package/lib/ChatAnywhere/hooks/types.d.ts +1 -0
- package/lib/GenerativeUI/Sandbox.d.ts +1 -0
- package/lib/GenerativeUI/Sandbox.js +6 -0
- package/lib/GenerativeUI/index.d.ts +1 -0
- package/lib/GenerativeUI/index.js +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +2 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react'
|
|
2
|
-
import { UploadFile } from 'antd';
|
|
2
|
+
import { Flex, Popover, UploadFile } from 'antd';
|
|
3
3
|
import { useProviderContext, ChatInput, uuid, Sender, Attachments } from '@agentscope-ai/chat';
|
|
4
4
|
import cls from 'classnames';
|
|
5
5
|
import { useChatAnywhere } from '../hooks/ChatAnywhereProvider';
|
|
@@ -31,7 +31,7 @@ export default forwardRef(function (_, ref) {
|
|
|
31
31
|
useEffect(() => {
|
|
32
32
|
attachedFilesRef.current = attachedFiles;
|
|
33
33
|
}, [attachedFiles]);
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
const uiConfig = useChatAnywhere(v => v.uiConfig);
|
|
36
36
|
const { getPrefixCls } = useProviderContext();
|
|
37
37
|
const prefixCls = getPrefixCls('chat-anywhere-sender');
|
|
@@ -85,8 +85,11 @@ export default forwardRef(function (_, ref) {
|
|
|
85
85
|
})
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
const
|
|
89
|
-
|
|
88
|
+
const uploadPrefixNodes = useMemo(() => {
|
|
89
|
+
if (onInput.variant === 'aigc' || !onUpload?.length) {
|
|
90
|
+
return [];
|
|
91
|
+
}
|
|
92
|
+
const nodes = onUpload.map((item, index) => {
|
|
90
93
|
return <Upload
|
|
91
94
|
{...item}
|
|
92
95
|
fileList={attachedFiles[index]}
|
|
@@ -102,12 +105,26 @@ export default forwardRef(function (_, ref) {
|
|
|
102
105
|
}}
|
|
103
106
|
showUploadList={false}
|
|
104
107
|
>
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
{
|
|
109
|
+
item.trigger || <IconButton
|
|
110
|
+
icon={item.icon}
|
|
111
|
+
bordered={false}
|
|
112
|
+
/>
|
|
113
|
+
}
|
|
109
114
|
</Upload>
|
|
110
|
-
})
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
if (nodes.length === 1) return nodes;
|
|
118
|
+
return <Popover content={nodes} trigger="click">
|
|
119
|
+
<Flex vertical>
|
|
120
|
+
{nodes}
|
|
121
|
+
</Flex>
|
|
122
|
+
</Popover>
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
}, [onInput.variant, onUpload, attachedFiles]);
|
|
126
|
+
|
|
127
|
+
|
|
111
128
|
|
|
112
129
|
|
|
113
130
|
// aigc 模式下的 header
|
|
@@ -162,7 +179,7 @@ export default forwardRef(function (_, ref) {
|
|
|
162
179
|
if (trimmed.startsWith('.')) {
|
|
163
180
|
return fileName.toLowerCase().endsWith(trimmed.toLowerCase());
|
|
164
181
|
}
|
|
165
|
-
|
|
182
|
+
|
|
166
183
|
// Wildcard: image/*, */*
|
|
167
184
|
if (trimmed.includes('*')) {
|
|
168
185
|
if (trimmed === '*/*') return true;
|
|
@@ -170,7 +187,7 @@ export default forwardRef(function (_, ref) {
|
|
|
170
187
|
const [fileMain] = fileType.split('/');
|
|
171
188
|
return acceptMain === fileMain;
|
|
172
189
|
}
|
|
173
|
-
|
|
190
|
+
|
|
174
191
|
// Exact: image/jpeg
|
|
175
192
|
return fileType === trimmed;
|
|
176
193
|
});
|
|
@@ -225,7 +242,7 @@ export default forwardRef(function (_, ref) {
|
|
|
225
242
|
const getExtension = () => {
|
|
226
243
|
const nameMatch = fileName.match(/\.([^.]+)$/);
|
|
227
244
|
if (nameMatch) return nameMatch[1].toLowerCase();
|
|
228
|
-
|
|
245
|
+
|
|
229
246
|
const typeMatch = fileType.match(/\/([^/+]+)/);
|
|
230
247
|
return typeMatch ? typeMatch[1].toLowerCase() : 'bin';
|
|
231
248
|
};
|
|
@@ -257,7 +274,7 @@ export default forwardRef(function (_, ref) {
|
|
|
257
274
|
setAttachedFiles(prev => {
|
|
258
275
|
const updated = [...prev];
|
|
259
276
|
const currentList = updated[uploadIndex] || [];
|
|
260
|
-
|
|
277
|
+
|
|
261
278
|
// If not multiple, replace existing files
|
|
262
279
|
if (!uploadConfig.multiple) {
|
|
263
280
|
updated[uploadIndex] = [uploadFile];
|
|
@@ -296,11 +313,11 @@ export default forwardRef(function (_, ref) {
|
|
|
296
313
|
updateFile({ percent: event.percent });
|
|
297
314
|
},
|
|
298
315
|
} as any, {
|
|
299
|
-
defaultRequest: () => {}
|
|
316
|
+
defaultRequest: () => { }
|
|
300
317
|
});
|
|
301
318
|
}
|
|
302
319
|
};
|
|
303
|
-
|
|
320
|
+
|
|
304
321
|
// 检查是否有必需的上传项没有文件
|
|
305
322
|
const requiredFileMissing = useMemo(() => {
|
|
306
323
|
return onUpload?.some((item, index) => {
|
|
@@ -311,7 +328,7 @@ export default forwardRef(function (_, ref) {
|
|
|
311
328
|
return false;
|
|
312
329
|
}) ?? false;
|
|
313
330
|
}, [onUpload, attachedFiles]);
|
|
314
|
-
|
|
331
|
+
|
|
315
332
|
const sendDisabled = requiredFileMissing;
|
|
316
333
|
|
|
317
334
|
return <>
|
|
@@ -340,7 +357,7 @@ export default forwardRef(function (_, ref) {
|
|
|
340
357
|
scalable={onInput?.zoomable}
|
|
341
358
|
header={senderHeader}
|
|
342
359
|
prefix={<>
|
|
343
|
-
{
|
|
360
|
+
{uploadPrefixNodes}
|
|
344
361
|
{onInput?.morePrefixActions}
|
|
345
362
|
</>}
|
|
346
363
|
onSubmit={async () => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Sandbox } from './Sandbox';
|
package/components/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
18
18
|
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; } }
|
|
19
19
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
20
20
|
import React, { forwardRef, useEffect, useMemo, useRef, useState } from 'react';
|
|
21
|
+
import { Flex, Popover } from 'antd';
|
|
21
22
|
import { useProviderContext, ChatInput, Sender, Attachments } from "../..";
|
|
22
23
|
import cls from 'classnames';
|
|
23
24
|
import { useChatAnywhere } from "../hooks/ChatAnywhereProvider";
|
|
@@ -123,24 +124,38 @@ export default /*#__PURE__*/forwardRef(function (_, ref) {
|
|
|
123
124
|
return _ref.apply(this, arguments);
|
|
124
125
|
};
|
|
125
126
|
}();
|
|
126
|
-
var
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
127
|
+
var uploadPrefixNodes = useMemo(function () {
|
|
128
|
+
if (onInput.variant === 'aigc' || !(onUpload !== null && onUpload !== void 0 && onUpload.length)) {
|
|
129
|
+
return [];
|
|
130
|
+
}
|
|
131
|
+
var nodes = onUpload.map(function (item, index) {
|
|
132
|
+
return /*#__PURE__*/_createElement(Upload, _objectSpread(_objectSpread({}, item), {}, {
|
|
133
|
+
fileList: attachedFiles[index],
|
|
134
|
+
key: index,
|
|
135
|
+
onChange: function onChange(info) {
|
|
136
|
+
if (item.beforeUpload && info.file.status) {
|
|
137
|
+
handleFileChange(index, info.fileList);
|
|
138
|
+
}
|
|
139
|
+
if (!item.beforeUpload) {
|
|
140
|
+
handleFileChange(index, info.fileList);
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
showUploadList: false
|
|
144
|
+
}), item.trigger || /*#__PURE__*/_jsx(IconButton, {
|
|
145
|
+
icon: item.icon,
|
|
146
|
+
bordered: false
|
|
147
|
+
}));
|
|
148
|
+
});
|
|
149
|
+
if (nodes.length === 1) return nodes;
|
|
150
|
+
return /*#__PURE__*/_jsx(Popover, {
|
|
151
|
+
content: nodes,
|
|
152
|
+
trigger: "click",
|
|
153
|
+
children: /*#__PURE__*/_jsx(Flex, {
|
|
154
|
+
vertical: true,
|
|
155
|
+
children: nodes
|
|
156
|
+
})
|
|
157
|
+
});
|
|
158
|
+
}, [onInput.variant, onUpload, attachedFiles]);
|
|
144
159
|
|
|
145
160
|
// aigc 模式下的 header
|
|
146
161
|
var aigcSenderHeader = /*#__PURE__*/_jsx(AIGC.SenderHeader, {
|
|
@@ -377,7 +392,7 @@ export default /*#__PURE__*/forwardRef(function (_, ref) {
|
|
|
377
392
|
scalable: onInput === null || onInput === void 0 ? void 0 : onInput.zoomable,
|
|
378
393
|
header: senderHeader,
|
|
379
394
|
prefix: /*#__PURE__*/_jsxs(_Fragment, {
|
|
380
|
-
children: [
|
|
395
|
+
children: [uploadPrefixNodes, onInput === null || onInput === void 0 ? void 0 : onInput.morePrefixActions]
|
|
381
396
|
}),
|
|
382
397
|
onSubmit: /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
383
398
|
var next;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function Iframe(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Sandbox } from './Sandbox';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Sandbox } from "./Sandbox";
|
package/lib/index.d.ts
CHANGED
|
@@ -26,3 +26,4 @@ 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 { Sandbox as GenerativeUISandbox } from './GenerativeUI';
|
package/lib/index.js
CHANGED
|
@@ -24,4 +24,5 @@ export { default as StatusCard } from "./StatusCard";
|
|
|
24
24
|
export { default as sleep } from "./Util/sleep";
|
|
25
25
|
export { default as Welcome } from "./Welcome";
|
|
26
26
|
export { default as Markdown } from "./Markdown";
|
|
27
|
-
export { default as AIGC } from "./AIGC";
|
|
27
|
+
export { default as AIGC } from "./AIGC";
|
|
28
|
+
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.45-beta.
|
|
3
|
+
"version": "1.1.45-beta.1766386435551",
|
|
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": [
|