@agentscope-ai/chat 1.1.19 → 1.1.20
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 +35 -2
- package/README.zh-CN.md +35 -2
- package/bin/cli.js +100 -0
- package/bin/client.js +16 -0
- package/bin/template.html +28 -0
- package/lib/AgentScopeRuntimeWebUI/lib/Chat/Input/index.js +1 -1
- package/lib/AgentScopeRuntimeWebUI/lib/ChatAnywhere/ComposedProvider.js +1 -1
- package/lib/Bubble/Cards.js +9 -2
- package/lib/Markdown/Markdown/index.js +19 -1
- package/package.json +8 -2
package/README.md
CHANGED
|
@@ -17,7 +17,40 @@ A free, open-source React chat framework based on **Alibaba Cloud Spark Design**
|
|
|
17
17
|
|
|
18
18
|
## 🚀 Quick Start
|
|
19
19
|
|
|
20
|
-
###
|
|
20
|
+
### Method 1: Using CLI Tool (Recommended)
|
|
21
|
+
|
|
22
|
+
The quickest way is to use our CLI tool:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Start with default configuration (port 3000)
|
|
26
|
+
npx agentscope-runtime-webui
|
|
27
|
+
|
|
28
|
+
# Specify port
|
|
29
|
+
npx agentscope-runtime-webui --port 8080
|
|
30
|
+
|
|
31
|
+
# Specify backend API URL
|
|
32
|
+
npx agentscope-runtime-webui --url http://api.example.com
|
|
33
|
+
|
|
34
|
+
# Specify authentication token
|
|
35
|
+
npx agentscope-runtime-webui --token your-auth-token
|
|
36
|
+
|
|
37
|
+
# Combine options
|
|
38
|
+
npx agentscope-runtime-webui -p 8080 -u http://api.example.com -t your-token
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**CLI Options:**
|
|
42
|
+
|
|
43
|
+
| Option | Short | Description | Default |
|
|
44
|
+
|--------|-------|-------------|---------|
|
|
45
|
+
| `--port` | `-p` | Specify server port | `3000` |
|
|
46
|
+
| `--url` | `-u` | Specify backend API URL | - |
|
|
47
|
+
| `--token` | `-t` | Specify authentication token | - |
|
|
48
|
+
|
|
49
|
+
For more CLI usage details, see [CLI Documentation](./bin/README.md).
|
|
50
|
+
|
|
51
|
+
### Method 2: Integrate into Project
|
|
52
|
+
|
|
53
|
+
#### Installation
|
|
21
54
|
|
|
22
55
|
```bash
|
|
23
56
|
# Install dependencies
|
|
@@ -32,7 +65,7 @@ npm install @agentscope-ai/chat --save
|
|
|
32
65
|
> tnpm install @ali/agentscope-ai-chat @ali/agentscope-ai-design --save
|
|
33
66
|
> ```
|
|
34
67
|
|
|
35
|
-
|
|
68
|
+
#### Basic Usage
|
|
36
69
|
|
|
37
70
|
```tsx
|
|
38
71
|
import { ConfigProvider, carbonTheme } from '@agentscope-ai/design';
|
package/README.zh-CN.md
CHANGED
|
@@ -17,7 +17,40 @@
|
|
|
17
17
|
|
|
18
18
|
## 🚀 快速开始
|
|
19
19
|
|
|
20
|
-
###
|
|
20
|
+
### 方式一:使用 CLI 工具(推荐)
|
|
21
|
+
|
|
22
|
+
最快速的方式是使用我们提供的 CLI 工具:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# 使用默认配置启动(端口 3000)
|
|
26
|
+
npx agentscope-runtime-webui
|
|
27
|
+
|
|
28
|
+
# 指定端口
|
|
29
|
+
npx agentscope-runtime-webui --port 8080
|
|
30
|
+
|
|
31
|
+
# 指定后端 API 地址
|
|
32
|
+
npx agentscope-runtime-webui --url http://api.example.com
|
|
33
|
+
|
|
34
|
+
# 指定认证 token
|
|
35
|
+
npx agentscope-runtime-webui --token your-auth-token
|
|
36
|
+
|
|
37
|
+
# 组合使用
|
|
38
|
+
npx agentscope-runtime-webui -p 8080 -u http://api.example.com -t your-token
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
**CLI 参数说明:**
|
|
42
|
+
|
|
43
|
+
| 参数 | 缩写 | 说明 | 默认值 |
|
|
44
|
+
|------|------|------|--------|
|
|
45
|
+
| `--port` | `-p` | 指定服务端口 | `3000` |
|
|
46
|
+
| `--url` | `-u` | 指定后端 API 地址 | 无 |
|
|
47
|
+
| `--token` | `-t` | 指定认证 token | 无 |
|
|
48
|
+
|
|
49
|
+
更多 CLI 使用说明请查看 [CLI 文档](./bin/README.md)。
|
|
50
|
+
|
|
51
|
+
### 方式二:集成到项目
|
|
52
|
+
|
|
53
|
+
#### 安装
|
|
21
54
|
|
|
22
55
|
```bash
|
|
23
56
|
# 安装依赖
|
|
@@ -32,7 +65,7 @@ npm install @agentscope-ai/chat --save
|
|
|
32
65
|
> tnpm install @ali/agentscope-ai-chat @ali/agentscope-ai-design --save
|
|
33
66
|
> ```
|
|
34
67
|
|
|
35
|
-
|
|
68
|
+
#### 基础使用
|
|
36
69
|
|
|
37
70
|
```tsx
|
|
38
71
|
import { ConfigProvider, carbonTheme } from '@agentscope-ai/design';
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
const { createServer } = require('vite');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const fs = require('fs');
|
|
7
|
+
|
|
8
|
+
program
|
|
9
|
+
.name('agentscope-runtime-webui')
|
|
10
|
+
.description('启动 AgentScope Runtime WebUI 服务')
|
|
11
|
+
.option('-p, --port <port>', '指定服务端口', '3000')
|
|
12
|
+
.option('-u, --url <url>', '指定后端 API 地址')
|
|
13
|
+
.option('-t, --token <token>', '指定认证 token')
|
|
14
|
+
.parse(process.argv);
|
|
15
|
+
|
|
16
|
+
const options = program.opts();
|
|
17
|
+
|
|
18
|
+
async function startServer() {
|
|
19
|
+
console.log('🚀 正在启动 AgentScope Runtime WebUI...');
|
|
20
|
+
console.log(`📦 端口: ${options.port}`);
|
|
21
|
+
if (options.url) {
|
|
22
|
+
console.log(`🔗 API 地址: ${options.url}`);
|
|
23
|
+
}
|
|
24
|
+
if (options.token) {
|
|
25
|
+
console.log(`🔑 Token: ${options.token.substring(0, 10)}...`);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const templatePath = path.join(__dirname, 'template.html');
|
|
29
|
+
let htmlContent = fs.readFileSync(templatePath, 'utf-8');
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
// 找到项目根目录(包含 node_modules 的目录)
|
|
33
|
+
const projectRoot = path.resolve(__dirname, '..');
|
|
34
|
+
|
|
35
|
+
const server = await createServer({
|
|
36
|
+
configFile: false,
|
|
37
|
+
root: projectRoot,
|
|
38
|
+
server: {
|
|
39
|
+
port: parseInt(options.port),
|
|
40
|
+
host: '127.0.0.1',
|
|
41
|
+
},
|
|
42
|
+
resolve: {
|
|
43
|
+
dedupe: ['react', 'react-dom'],
|
|
44
|
+
alias: {
|
|
45
|
+
'@ali/agentscope-ai-chat': path.resolve(projectRoot, 'components/index.ts'),
|
|
46
|
+
'@agentscope-ai/chat': path.resolve(projectRoot, 'components/index.ts'),
|
|
47
|
+
'@agentscope-ai/design': '@ali/agentscope-ai-design'
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
plugins: [
|
|
51
|
+
{
|
|
52
|
+
name: 'agentscope-runtime-webui',
|
|
53
|
+
configureServer(server) {
|
|
54
|
+
server.middlewares.use((req, res, next) => {
|
|
55
|
+
if (req.url === '/' || req.url === '/index.html') {
|
|
56
|
+
// 注入配置到 HTML
|
|
57
|
+
const configScript = `
|
|
58
|
+
<script>
|
|
59
|
+
window.__AGENTSCOPE_CONFIG__ = {
|
|
60
|
+
url: '${options.url || ''}',
|
|
61
|
+
token: '${options.token || ''}',
|
|
62
|
+
};
|
|
63
|
+
</script>`;
|
|
64
|
+
const html = htmlContent.replace('</head>', `${configScript}\n </head>`);
|
|
65
|
+
res.setHeader('Content-Type', 'text/html');
|
|
66
|
+
res.end(html);
|
|
67
|
+
} else {
|
|
68
|
+
next();
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
await server.listen();
|
|
77
|
+
|
|
78
|
+
console.log('\n✅ AgentScope Runtime WebUI 已启动!');
|
|
79
|
+
console.log(`\n🌐 访问地址: http://localhost:${options.port}\n`);
|
|
80
|
+
|
|
81
|
+
process.on('SIGINT', () => {
|
|
82
|
+
console.log('\n\n👋 正在关闭服务器...');
|
|
83
|
+
server.close();
|
|
84
|
+
process.exit(0);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
process.on('SIGTERM', () => {
|
|
88
|
+
console.log('\n\n👋 正在关闭服务器...');
|
|
89
|
+
server.close();
|
|
90
|
+
process.exit(0);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
} catch (error) {
|
|
94
|
+
console.error('❌ 启动失败:', error);
|
|
95
|
+
process.exit(1);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
startServer();
|
|
100
|
+
|
package/bin/client.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom/client';
|
|
3
|
+
import Chat from '../components/AgentScopeRuntimeWebUI/demo';
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// 从 window 对象获取配置
|
|
7
|
+
const config = window.__AGENTSCOPE_CONFIG__ || {};
|
|
8
|
+
|
|
9
|
+
const App = () => {
|
|
10
|
+
return React.createElement(Chat);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
ReactDOM.createRoot(document.getElementById('root')).render(
|
|
14
|
+
React.createElement(App)
|
|
15
|
+
);
|
|
16
|
+
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="zh-CN">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>AgentScope Runtime WebUI</title>
|
|
7
|
+
<style>
|
|
8
|
+
* {
|
|
9
|
+
margin: 0;
|
|
10
|
+
padding: 0;
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
}
|
|
13
|
+
html, body {
|
|
14
|
+
height: 100%;
|
|
15
|
+
width: 100%;
|
|
16
|
+
}
|
|
17
|
+
#root {
|
|
18
|
+
height: 100vh;
|
|
19
|
+
width: 100%;
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
22
|
+
</head>
|
|
23
|
+
<body>
|
|
24
|
+
<div id="root"></div>
|
|
25
|
+
<script type="module" src="/bin/client.js"></script>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
|
28
|
+
|
|
@@ -70,7 +70,7 @@ export default function Input(props) {
|
|
|
70
70
|
fileList: (getFileList === null || getFileList === void 0 ? void 0 : getFileList()) || []
|
|
71
71
|
});
|
|
72
72
|
setContent('');
|
|
73
|
-
setFileList([]);
|
|
73
|
+
setFileList && setFileList([]);
|
|
74
74
|
case 8:
|
|
75
75
|
case "end":
|
|
76
76
|
return _context.stop();
|
|
@@ -10,7 +10,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
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
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
12
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
import { CustomCardsProvider } from "
|
|
13
|
+
import { CustomCardsProvider } from "../../..";
|
|
14
14
|
import { ChatAnywhereInputContextProvider } from "../Context/ChatAnywhereInputContext";
|
|
15
15
|
import { ChatAnywhereOptionsContextProvider } from "../Context/ChatAnywhereOptionsContext";
|
|
16
16
|
import { ChatAnywhereSessionsContextProvider } from "../Context/ChatAnywhereSessionsContext";
|
package/lib/Bubble/Cards.js
CHANGED
|
@@ -8,10 +8,13 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
|
|
|
8
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
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
10
|
import React, { useMemo } from 'react';
|
|
11
|
-
import { useCustomCardsContext } from "./..";
|
|
11
|
+
import { useChatAnywhere, useCustomCardsContext } from "./..";
|
|
12
12
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
var Card = /*#__PURE__*/React.memo(function (props) {
|
|
14
14
|
var cardConfig = useCustomCardsContext();
|
|
15
|
+
var onInput = useChatAnywhere(function (v) {
|
|
16
|
+
return v.onInput;
|
|
17
|
+
});
|
|
15
18
|
var Component = useMemo(function () {
|
|
16
19
|
if (props.component) return props.component;
|
|
17
20
|
var cardConfigMap = cardConfig;
|
|
@@ -22,7 +25,11 @@ var Card = /*#__PURE__*/React.memo(function (props) {
|
|
|
22
25
|
if (typeof Component === 'function') {
|
|
23
26
|
var component = props.component,
|
|
24
27
|
rest = _objectWithoutProperties(props, _excluded);
|
|
25
|
-
return /*#__PURE__*/_jsx(Component, _objectSpread({}, rest)
|
|
28
|
+
return /*#__PURE__*/_jsx(Component, _objectSpread(_objectSpread({}, rest), {}, {
|
|
29
|
+
context: {
|
|
30
|
+
onInput: onInput
|
|
31
|
+
}
|
|
32
|
+
}));
|
|
26
33
|
} else {
|
|
27
34
|
return Component;
|
|
28
35
|
}
|
|
@@ -35,6 +35,24 @@ var Null = function Null() {
|
|
|
35
35
|
var EMPTY_DOMPURIFY_CONFIG = {
|
|
36
36
|
ALLOWED_TAGS: []
|
|
37
37
|
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 检测浏览器是否支持正则表达式的 lookbehind assertions
|
|
41
|
+
* iOS Safari < 16.4 不支持此特性
|
|
42
|
+
*/
|
|
43
|
+
function supportsLookbehindAssertions() {
|
|
44
|
+
try {
|
|
45
|
+
// 尝试创建包含正向后行断言的正则表达式
|
|
46
|
+
new RegExp('(?<=a)b');
|
|
47
|
+
return true;
|
|
48
|
+
} catch (e) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
var isSupportsLookbehindAssertions = supportsLookbehindAssertions();
|
|
53
|
+
console.log({
|
|
54
|
+
isSupportsLookbehindAssertions: isSupportsLookbehindAssertions
|
|
55
|
+
});
|
|
38
56
|
export default /*#__PURE__*/memo(function (props) {
|
|
39
57
|
var baseFontSize = props.baseFontSize || 14;
|
|
40
58
|
var baseLineHeight = props.baseLineHeight || 1.7;
|
|
@@ -68,7 +86,7 @@ export default /*#__PURE__*/memo(function (props) {
|
|
|
68
86
|
citationsData = _useCitationsData.citationsData,
|
|
69
87
|
citationsDataCount = _useCitationsData.citationsDataCount,
|
|
70
88
|
CitationComponent = _useCitationsData.CitationComponent;
|
|
71
|
-
if (props.raw) return /*#__PURE__*/_jsx("div", {
|
|
89
|
+
if (props.raw || !isSupportsLookbehindAssertions) return /*#__PURE__*/_jsx("div", {
|
|
72
90
|
className: prefixCls,
|
|
73
91
|
style: {
|
|
74
92
|
fontSize: baseFontSize,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentscope-ai/chat",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.20",
|
|
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": [
|
|
@@ -10,8 +10,12 @@
|
|
|
10
10
|
],
|
|
11
11
|
"module": "lib/index.js",
|
|
12
12
|
"types": "lib/index.d.ts",
|
|
13
|
+
"bin": {
|
|
14
|
+
"agentscope-runtime-webui": "./bin/cli.js"
|
|
15
|
+
},
|
|
13
16
|
"files": [
|
|
14
|
-
"lib"
|
|
17
|
+
"lib",
|
|
18
|
+
"bin"
|
|
15
19
|
],
|
|
16
20
|
"scripts": {
|
|
17
21
|
"build": "npm run src:build && npm run docs:build",
|
|
@@ -54,6 +58,8 @@
|
|
|
54
58
|
},
|
|
55
59
|
"dependencies": {
|
|
56
60
|
"@agentscope-ai/icons": "^1.0.32",
|
|
61
|
+
"commander": "^12.1.0",
|
|
62
|
+
"vite": "^5.4.11",
|
|
57
63
|
"@agentscope-ai/icons-override-antd": "^6.0.0",
|
|
58
64
|
"@agentscope-ai/icons-svg-override-antd": "^4.4.2",
|
|
59
65
|
"@ant-design/cssinjs-utils": "^1.1.3",
|