@agentscope-ai/chat 1.1.21 → 1.1.23

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.
Files changed (30) hide show
  1. package/bin/client.js +1 -1
  2. package/components/AgentScopeRuntimeWebUI/demo/index.tsx +2 -55
  3. package/components/AgentScopeRuntimeWebUI/index.tsx +1 -0
  4. package/components/AgentScopeRuntimeWebUI/lib/demo/index.tsx +57 -0
  5. package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/FormItem.tsx +37 -0
  6. package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/OptionsEditor.tsx +163 -0
  7. package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/defaultConfig.ts +43 -0
  8. package/components/AgentScopeRuntimeWebUI/starter/OptionsPanel/index.tsx +27 -0
  9. package/components/AgentScopeRuntimeWebUI/starter/index.tsx +57 -0
  10. package/components/AgentScopeRuntimeWebUI/starter/sessionApi/index.ts +51 -0
  11. package/lib/AgentScopeRuntimeWebUI/index.d.ts +1 -0
  12. package/lib/AgentScopeRuntimeWebUI/index.js +1 -0
  13. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/FormItem.d.ts +9 -0
  14. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/FormItem.js +33 -0
  15. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/OptionsEditor.d.ts +7 -0
  16. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/OptionsEditor.js +188 -0
  17. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/defaultConfig.d.ts +29 -0
  18. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/defaultConfig.js +35 -0
  19. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/index.d.ts +6 -0
  20. package/lib/AgentScopeRuntimeWebUI/starter/OptionsPanel/index.js +49 -0
  21. package/lib/AgentScopeRuntimeWebUI/starter/index.d.ts +1 -0
  22. package/lib/AgentScopeRuntimeWebUI/starter/index.js +70 -0
  23. package/lib/AgentScopeRuntimeWebUI/starter/sessionApi/index.d.ts +14 -0
  24. package/lib/AgentScopeRuntimeWebUI/starter/sessionApi/index.js +143 -0
  25. package/package.json +2 -1
  26. /package/components/AgentScopeRuntimeWebUI/{demo → lib/demo}/OptionsPanel/FormItem.tsx +0 -0
  27. /package/components/AgentScopeRuntimeWebUI/{demo → lib/demo}/OptionsPanel/OptionsEditor.tsx +0 -0
  28. /package/components/AgentScopeRuntimeWebUI/{demo → lib/demo}/OptionsPanel/defaultConfig.ts +0 -0
  29. /package/components/AgentScopeRuntimeWebUI/{demo → lib/demo}/OptionsPanel/index.tsx +0 -0
  30. /package/components/AgentScopeRuntimeWebUI/{demo → lib/demo}/sessionApi/index.ts +0 -0
package/bin/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import ReactDOM from 'react-dom/client';
3
- import Chat from '../components/AgentScopeRuntimeWebUI/demo';
3
+ import Chat from '../lib/AgentScopeRuntimeWebUI/starter';
4
4
 
5
5
 
6
6
  // 从 window 对象获取配置
@@ -1,57 +1,4 @@
1
- import { AgentScopeRuntimeWebUI } from '@agentscope-ai/chat';
2
- import OptionsPanel from './OptionsPanel';
3
- import { useMemo, useState } from 'react';
4
- import sessionApi from './sessionApi';
5
- import defaultConfig from './OptionsPanel/defaultConfig';
6
- import { useLocalStorageState } from 'ahooks';
1
+ import Demo from '../starter';
7
2
 
8
- export default function () {
9
3
 
10
- const [optionsConfig, setOptionsConfig] = useLocalStorageState('agent-scope-runtime-webui-options', {
11
- defaultValue: defaultConfig(),
12
- listenStorageChange: true,
13
- });
14
-
15
- const options = useMemo(() => {
16
- const rightHeader = <OptionsPanel value={optionsConfig} onChange={v => {
17
- setOptionsConfig(prev => ({
18
- ...prev,
19
- ...v,
20
- }));
21
- }} />;
22
-
23
- return {
24
- ...optionsConfig,
25
- session: {
26
- multiple: true,
27
- api: sessionApi,
28
- },
29
- sender: {
30
- ...optionsConfig.sender,
31
- attachments: optionsConfig.sender.attachments ? {
32
- customRequest(options) {
33
- // 模拟上传进度
34
- options.onProgress({
35
- percent: 100,
36
- });
37
- // 当前是一个 mock 的上传行为
38
- // 实际情况需要具体实现一个文件上传服务,将文件转化为 url
39
- options.onSuccess({
40
- url: URL.createObjectURL(options.file as Blob)
41
- });
42
- }
43
- } : undefined,
44
- },
45
- theme: {
46
- ...optionsConfig.theme,
47
- rightHeader,
48
- },
49
- };
50
- }, [optionsConfig]);
51
-
52
- return <div style={{ height: '100dvh' }}>
53
- <AgentScopeRuntimeWebUI
54
- options={options}
55
- />
56
- </div>;
57
- }
4
+ export default Demo
@@ -1,2 +1,3 @@
1
1
  export { default } from './lib/ChatAnywhere';
2
+ export { default as Demo } from './starter';
2
3
  export * from './lib/types';
@@ -0,0 +1,57 @@
1
+ import { AgentScopeRuntimeWebUI } from '@agentscope-ai/chat';
2
+ import OptionsPanel from './OptionsPanel';
3
+ import { useMemo, useState } from 'react';
4
+ import sessionApi from './sessionApi';
5
+ import defaultConfig from './OptionsPanel/defaultConfig';
6
+ import { useLocalStorageState } from 'ahooks';
7
+
8
+ export default function () {
9
+
10
+ const [optionsConfig, setOptionsConfig] = useLocalStorageState('agent-scope-runtime-webui-options', {
11
+ defaultValue: defaultConfig(),
12
+ listenStorageChange: true,
13
+ });
14
+
15
+ const options = useMemo(() => {
16
+ const rightHeader = <OptionsPanel value={optionsConfig} onChange={v => {
17
+ setOptionsConfig(prev => ({
18
+ ...prev,
19
+ ...v,
20
+ }));
21
+ }} />;
22
+
23
+ return {
24
+ ...optionsConfig,
25
+ session: {
26
+ multiple: true,
27
+ api: sessionApi,
28
+ },
29
+ sender: {
30
+ ...optionsConfig.sender,
31
+ attachments: optionsConfig.sender.attachments ? {
32
+ customRequest(options) {
33
+ // 模拟上传进度
34
+ options.onProgress({
35
+ percent: 100,
36
+ });
37
+ // 当前是一个 mock 的上传行为
38
+ // 实际情况需要具体实现一个文件上传服务,将文件转化为 url
39
+ options.onSuccess({
40
+ url: URL.createObjectURL(options.file as Blob)
41
+ });
42
+ }
43
+ } : undefined,
44
+ },
45
+ theme: {
46
+ ...optionsConfig.theme,
47
+ rightHeader,
48
+ },
49
+ };
50
+ }, [optionsConfig]);
51
+
52
+ return <div style={{ height: '100dvh' }}>
53
+ <AgentScopeRuntimeWebUI
54
+ options={options}
55
+ />
56
+ </div>;
57
+ }
@@ -0,0 +1,37 @@
1
+ import { Form, Input, InputNumber, Space, ColorPicker, Flex } from 'antd';
2
+ import { createStyles } from 'antd-style';
3
+
4
+
5
+ interface FormItemProps {
6
+ name: string | string[];
7
+ label: string;
8
+ isList?: boolean;
9
+ children: any;
10
+ normalize?: (value: any) => any;
11
+ }
12
+
13
+
14
+ const useStyles = createStyles(({ token, css }) => ({
15
+ label: {
16
+ marginBottom: 6,
17
+ fontSize: 12,
18
+ color: token.colorTextSecondary,
19
+ },
20
+
21
+ }));
22
+
23
+ export default function FormItem(props: FormItemProps) {
24
+ const { styles } = useStyles();
25
+
26
+
27
+ const node = props.isList ?
28
+ <Form.List name={props.name}>{props.children}</Form.List> :
29
+ <Form.Item name={props.name} normalize={props.normalize}>{props.children}</Form.Item>;
30
+
31
+
32
+ return <div>
33
+ {props.label && <div className={styles.label}>{props.label}</div>}
34
+ {node}
35
+ </div>
36
+
37
+ }
@@ -0,0 +1,163 @@
1
+ import React, { useEffect } from 'react';
2
+ import { Form, Input, ColorPicker, Flex, Splitter, Divider, InputNumber } from 'antd';
3
+ import { createStyles } from 'antd-style';
4
+ import { Button, IconButton, Switch } from '@agentscope-ai/design'
5
+ import { SparkDeleteLine, SparkPlusLine } from '@agentscope-ai/icons';
6
+ import FormItem from './FormItem';
7
+ import defaultConfig from './defaultConfig';
8
+
9
+ const useStyles = createStyles(({ token, css }) => ({
10
+ container: {
11
+ height: '100%',
12
+ display: 'flex',
13
+ flexDirection: 'column',
14
+ },
15
+
16
+ form: {
17
+ height: 0,
18
+ flex: 1,
19
+ padding: '8px 16px 16px 16px',
20
+ overflow: 'auto',
21
+ },
22
+ actions: {
23
+ padding: 16,
24
+ display: 'flex',
25
+ borderTop: `1px solid ${token.colorBorderSecondary}`,
26
+ justifyContent: 'flex-end',
27
+ gap: 16,
28
+ }
29
+
30
+ }));
31
+
32
+ interface OptionsEditorProps {
33
+ value?: any;
34
+ onChange?: any;
35
+ }
36
+
37
+ const OptionsEditor: React.FC<OptionsEditorProps> = ({
38
+ value,
39
+ onChange,
40
+ }) => {
41
+ const { styles } = useStyles();
42
+ const [form] = Form.useForm();
43
+
44
+
45
+ const handleSave = () => {
46
+ form.validateFields().then((values) => {
47
+ onChange(values);
48
+ });
49
+ };
50
+
51
+ const handleReset = () => {
52
+ form.setFieldsValue(defaultConfig);
53
+ };
54
+
55
+ return (
56
+ <div className={styles.container}>
57
+ <Form
58
+ className={styles.form}
59
+ form={form}
60
+ layout="vertical"
61
+ initialValues={value}
62
+ >
63
+
64
+
65
+ <Divider orientation="left">Theme</Divider>
66
+
67
+ <FormItem name={['theme', 'colorPrimary']} label="colorPrimary" normalize={value => value.toHexString()}>
68
+ <ColorPicker />
69
+ </FormItem>
70
+
71
+ <FormItem name={['theme', 'colorBgBase']} label="colorBgBase" normalize={value => value.toHexString()}>
72
+ <ColorPicker />
73
+ </FormItem>
74
+
75
+ <FormItem name={['theme', 'colorTextBase']} label="colorTextBase" normalize={value => value.toHexString()}>
76
+ <ColorPicker />
77
+ </FormItem>
78
+
79
+ <FormItem name={['theme', 'darkMode']} label="darkMode" >
80
+ <Switch />
81
+ </FormItem>
82
+
83
+ <FormItem name={['theme', 'leftHeader', 'logo']} label="leftHeader.logo" >
84
+ <Input />
85
+ </FormItem>
86
+
87
+ <FormItem name={['theme', 'leftHeader', 'title']} label="leftHeader.title" >
88
+ <Input />
89
+ </FormItem>
90
+
91
+ <Divider orientation="left">Sender</Divider>
92
+
93
+
94
+ <FormItem name={['sender', 'disclaimer']} label="disclaimer" >
95
+ <Input />
96
+ </FormItem>
97
+
98
+
99
+ <FormItem name={['sender', 'attachments']} label="attachments" >
100
+ <Switch />
101
+ </FormItem>
102
+
103
+
104
+ <FormItem name={['sender', 'maxLength']} label="maxLength" >
105
+ <InputNumber min={1000} />
106
+ </FormItem>
107
+
108
+ <Divider orientation="left">Welcome</Divider>
109
+
110
+
111
+ <FormItem name={['welcome', 'greeting']} label="greeting" >
112
+ <Input />
113
+ </FormItem>
114
+
115
+ <FormItem name={['welcome', 'description']} label="description" >
116
+ <Input />
117
+ </FormItem>
118
+
119
+ <FormItem name={['welcome', 'avatar']} label="avatar" >
120
+ <Input />
121
+ </FormItem>
122
+
123
+
124
+ <FormItem name={['welcome', 'prompts']} isList label="prompts" >
125
+ {(fields, { add, remove }) => {
126
+ return <div>
127
+ {fields.map(field => {
128
+ return <Flex key={field.key} gap={6}>
129
+ <Form.Item style={{ flex: 1 }} key={field.key} name={[field.name, 'value']}>
130
+ <Input />
131
+ </Form.Item>
132
+ <IconButton icon={<SparkPlusLine />} onClick={() => add({})}></IconButton>
133
+ <IconButton icon={<SparkDeleteLine />} onClick={() => remove(field.name)}></IconButton>
134
+ </Flex>
135
+ })}
136
+ </div>
137
+ }}
138
+ </FormItem>
139
+
140
+
141
+ <Divider orientation="left">API</Divider>
142
+
143
+ <FormItem name={['api', 'baseURL']} label="baseURL" >
144
+ <Input />
145
+ </FormItem>
146
+
147
+ <FormItem name={['api', 'token']} label="token" >
148
+ <Input />
149
+ </FormItem>
150
+ </Form>
151
+
152
+ <div className={styles.actions}>
153
+ <Button onClick={handleReset}>Reset</Button>
154
+ <Button type="primary" onClick={handleSave}>
155
+ Save & Copy
156
+ </Button>
157
+ </div>
158
+ </div>
159
+ );
160
+ };
161
+
162
+ export default OptionsEditor;
163
+
@@ -0,0 +1,43 @@
1
+ export default () => {
2
+ return {
3
+ theme: {
4
+ colorPrimary: '#615CED',
5
+ darkMode: true,
6
+ prefix: 'agentscope-runtime-webui',
7
+ leftHeader: {
8
+ logo: 'https://img.alicdn.com/imgextra/i2/O1CN01lmoGYn1kjoXATy4PX_!!6000000004720-2-tps-200-200.png',
9
+ title: 'Runtime WebUI',
10
+ },
11
+ },
12
+ sender: {
13
+ // @ts-ignore
14
+ attachments: true,
15
+ maxLength: 10000,
16
+ disclaimer:
17
+ 'AI can also make mistakes, so please check carefully and use it with caution',
18
+ },
19
+
20
+ welcome: {
21
+ greeting: 'Hello, how can I help you today?',
22
+ description:
23
+ 'I am a helpful assistant that can help you with your questions.',
24
+ avatar:
25
+ 'https://img.alicdn.com/imgextra/i2/O1CN01lmoGYn1kjoXATy4PX_!!6000000004720-2-tps-200-200.png',
26
+ prompts: [
27
+ {
28
+ value: 'Hello',
29
+ },
30
+ {
31
+ value: 'How are you?',
32
+ },
33
+ {
34
+ value: 'What can you do?',
35
+ },
36
+ ],
37
+ },
38
+ api: {
39
+ baseURL: '',
40
+ token: '',
41
+ },
42
+ };
43
+ };
@@ -0,0 +1,27 @@
1
+ import { SparkSettingLine } from "@agentscope-ai/icons";
2
+ import { IconButton, Drawer } from "@agentscope-ai/design";
3
+ import { useState } from "react";
4
+ import OptionsEditor from "./OptionsEditor";
5
+
6
+ interface OptionsPanelProps {
7
+ value?: any;
8
+ onChange?: any;
9
+ }
10
+
11
+ export default function OptionsPanel(props: OptionsPanelProps) {
12
+ const [open, setOpen] = useState(false);
13
+
14
+ return <>
15
+ <IconButton onClick={() => setOpen(true)} icon={<SparkSettingLine />} bordered={false} />
16
+ <Drawer
17
+ destroyOnHidden
18
+ open={open}
19
+ onClose={() => setOpen(false)}
20
+ styles={{ body: { padding: 0 }, header: { padding: 8 } }}>
21
+ <OptionsEditor value={props.value} onChange={v => {
22
+ setOpen(false);
23
+ props.onChange(v);
24
+ }} />
25
+ </Drawer>
26
+ </>
27
+ }
@@ -0,0 +1,57 @@
1
+ import { AgentScopeRuntimeWebUI } from '@agentscope-ai/chat';
2
+ import OptionsPanel from './OptionsPanel';
3
+ import { useMemo, useState } from 'react';
4
+ import sessionApi from './sessionApi';
5
+ import defaultConfig from './OptionsPanel/defaultConfig';
6
+ import { useLocalStorageState } from 'ahooks';
7
+
8
+ export default function () {
9
+
10
+ const [optionsConfig, setOptionsConfig] = useLocalStorageState('agent-scope-runtime-webui-options', {
11
+ defaultValue: defaultConfig(),
12
+ listenStorageChange: true,
13
+ });
14
+
15
+ const options = useMemo(() => {
16
+ const rightHeader = <OptionsPanel value={optionsConfig} onChange={v => {
17
+ setOptionsConfig(prev => ({
18
+ ...prev,
19
+ ...v,
20
+ }));
21
+ }} />;
22
+
23
+ return {
24
+ ...optionsConfig,
25
+ session: {
26
+ multiple: true,
27
+ api: sessionApi,
28
+ },
29
+ sender: {
30
+ ...optionsConfig.sender,
31
+ attachments: optionsConfig.sender.attachments ? {
32
+ customRequest(options) {
33
+ // 模拟上传进度
34
+ options.onProgress({
35
+ percent: 100,
36
+ });
37
+ // 当前是一个 mock 的上传行为
38
+ // 实际情况需要具体实现一个文件上传服务,将文件转化为 url
39
+ options.onSuccess({
40
+ url: URL.createObjectURL(options.file as Blob)
41
+ });
42
+ }
43
+ } : undefined,
44
+ },
45
+ theme: {
46
+ ...optionsConfig.theme,
47
+ rightHeader,
48
+ },
49
+ };
50
+ }, [optionsConfig]);
51
+
52
+ return <div style={{ height: '100dvh' }}>
53
+ <AgentScopeRuntimeWebUI
54
+ options={options}
55
+ />
56
+ </div>;
57
+ }
@@ -0,0 +1,51 @@
1
+ import { IAgentScopeRuntimeWebUISessionAPI } from '@agentscope-ai/chat';
2
+ import { IAgentScopeRuntimeWebUISession } from '../../lib/types/ISessions';
3
+
4
+ class SessionApi implements IAgentScopeRuntimeWebUISessionAPI {
5
+ private lsKey: string;
6
+ private sessionList: IAgentScopeRuntimeWebUISession[];
7
+
8
+ constructor() {
9
+ this.lsKey = 'agent-scope-runtime-webui-sessions';
10
+ this.sessionList = [];
11
+ }
12
+
13
+ async getSessionList() {
14
+ this.sessionList = JSON.parse(localStorage.getItem(this.lsKey) || '[]');
15
+ return [...this.sessionList];
16
+ }
17
+
18
+ async getSession(sessionId) {
19
+ return this.sessionList.find((session) => session.id === sessionId);
20
+ }
21
+
22
+ async updateSession(session) {
23
+ const index = this.sessionList.findIndex((item) => item.id === session.id);
24
+ if (index > -1) {
25
+ this.sessionList[index] = {
26
+ ...this.sessionList[index],
27
+ ...session,
28
+ };
29
+ localStorage.setItem(this.lsKey, JSON.stringify(this.sessionList));
30
+ }
31
+
32
+ return [...this.sessionList];
33
+ }
34
+
35
+ async createSession(session) {
36
+ session.id = Date.now().toString();
37
+ this.sessionList.unshift(session);
38
+ localStorage.setItem(this.lsKey, JSON.stringify(this.sessionList));
39
+ return [...this.sessionList];
40
+ }
41
+
42
+ async removeSession(session) {
43
+ this.sessionList = this.sessionList.filter(
44
+ (item) => item.id !== session.id,
45
+ );
46
+ localStorage.setItem(this.lsKey, JSON.stringify(this.sessionList));
47
+ return [...this.sessionList];
48
+ }
49
+ }
50
+
51
+ export default new SessionApi();
@@ -1,2 +1,3 @@
1
1
  export { default } from './lib/ChatAnywhere';
2
+ export { default as Demo } from './starter';
2
3
  export * from './lib/types';
@@ -1,2 +1,3 @@
1
1
  export { default } from "./lib/ChatAnywhere";
2
+ export { default as Demo } from "./starter";
2
3
  export * from "./lib/types";
@@ -0,0 +1,9 @@
1
+ interface FormItemProps {
2
+ name: string | string[];
3
+ label: string;
4
+ isList?: boolean;
5
+ children: any;
6
+ normalize?: (value: any) => any;
7
+ }
8
+ export default function FormItem(props: FormItemProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,33 @@
1
+ import { Form } from 'antd';
2
+ import { createStyles } from 'antd-style';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ import { jsxs as _jsxs } from "react/jsx-runtime";
5
+ var useStyles = createStyles(function (_ref) {
6
+ var token = _ref.token,
7
+ css = _ref.css;
8
+ return {
9
+ label: {
10
+ marginBottom: 6,
11
+ fontSize: 12,
12
+ color: token.colorTextSecondary
13
+ }
14
+ };
15
+ });
16
+ export default function FormItem(props) {
17
+ var _useStyles = useStyles(),
18
+ styles = _useStyles.styles;
19
+ var node = props.isList ? /*#__PURE__*/_jsx(Form.List, {
20
+ name: props.name,
21
+ children: props.children
22
+ }) : /*#__PURE__*/_jsx(Form.Item, {
23
+ name: props.name,
24
+ normalize: props.normalize,
25
+ children: props.children
26
+ });
27
+ return /*#__PURE__*/_jsxs("div", {
28
+ children: [props.label && /*#__PURE__*/_jsx("div", {
29
+ className: styles.label,
30
+ children: props.label
31
+ }), node]
32
+ });
33
+ }
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ interface OptionsEditorProps {
3
+ value?: any;
4
+ onChange?: any;
5
+ }
6
+ declare const OptionsEditor: React.FC<OptionsEditorProps>;
7
+ export default OptionsEditor;
@@ -0,0 +1,188 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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); }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import React from 'react';
8
+ import { Form, Input, ColorPicker, Flex, Divider, InputNumber } from 'antd';
9
+ import { createStyles } from 'antd-style';
10
+ import { Button, IconButton, Switch } from "@agentscope-ai/design";
11
+ import { SparkDeleteLine, SparkPlusLine } from '@agentscope-ai/icons';
12
+ import FormItem from "./FormItem";
13
+ import defaultConfig from "./defaultConfig";
14
+ import { jsx as _jsx } from "react/jsx-runtime";
15
+ import { jsxs as _jsxs } from "react/jsx-runtime";
16
+ var useStyles = createStyles(function (_ref) {
17
+ var token = _ref.token,
18
+ css = _ref.css;
19
+ return {
20
+ container: {
21
+ height: '100%',
22
+ display: 'flex',
23
+ flexDirection: 'column'
24
+ },
25
+ form: {
26
+ height: 0,
27
+ flex: 1,
28
+ padding: '8px 16px 16px 16px',
29
+ overflow: 'auto'
30
+ },
31
+ actions: {
32
+ padding: 16,
33
+ display: 'flex',
34
+ borderTop: "1px solid ".concat(token.colorBorderSecondary),
35
+ justifyContent: 'flex-end',
36
+ gap: 16
37
+ }
38
+ };
39
+ });
40
+ var OptionsEditor = function OptionsEditor(_ref2) {
41
+ var value = _ref2.value,
42
+ onChange = _ref2.onChange;
43
+ var _useStyles = useStyles(),
44
+ styles = _useStyles.styles;
45
+ var _Form$useForm = Form.useForm(),
46
+ _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
47
+ form = _Form$useForm2[0];
48
+ var handleSave = function handleSave() {
49
+ form.validateFields().then(function (values) {
50
+ onChange(values);
51
+ });
52
+ };
53
+ var handleReset = function handleReset() {
54
+ form.setFieldsValue(defaultConfig);
55
+ };
56
+ return /*#__PURE__*/_jsxs("div", {
57
+ className: styles.container,
58
+ children: [/*#__PURE__*/_jsxs(Form, {
59
+ className: styles.form,
60
+ form: form,
61
+ layout: "vertical",
62
+ initialValues: value,
63
+ children: [/*#__PURE__*/_jsx(Divider, {
64
+ orientation: "left",
65
+ children: "Theme"
66
+ }), /*#__PURE__*/_jsx(FormItem, {
67
+ name: ['theme', 'colorPrimary'],
68
+ label: "colorPrimary",
69
+ normalize: function normalize(value) {
70
+ return value.toHexString();
71
+ },
72
+ children: /*#__PURE__*/_jsx(ColorPicker, {})
73
+ }), /*#__PURE__*/_jsx(FormItem, {
74
+ name: ['theme', 'colorBgBase'],
75
+ label: "colorBgBase",
76
+ normalize: function normalize(value) {
77
+ return value.toHexString();
78
+ },
79
+ children: /*#__PURE__*/_jsx(ColorPicker, {})
80
+ }), /*#__PURE__*/_jsx(FormItem, {
81
+ name: ['theme', 'colorTextBase'],
82
+ label: "colorTextBase",
83
+ normalize: function normalize(value) {
84
+ return value.toHexString();
85
+ },
86
+ children: /*#__PURE__*/_jsx(ColorPicker, {})
87
+ }), /*#__PURE__*/_jsx(FormItem, {
88
+ name: ['theme', 'darkMode'],
89
+ label: "darkMode",
90
+ children: /*#__PURE__*/_jsx(Switch, {})
91
+ }), /*#__PURE__*/_jsx(FormItem, {
92
+ name: ['theme', 'leftHeader', 'logo'],
93
+ label: "leftHeader.logo",
94
+ children: /*#__PURE__*/_jsx(Input, {})
95
+ }), /*#__PURE__*/_jsx(FormItem, {
96
+ name: ['theme', 'leftHeader', 'title'],
97
+ label: "leftHeader.title",
98
+ children: /*#__PURE__*/_jsx(Input, {})
99
+ }), /*#__PURE__*/_jsx(Divider, {
100
+ orientation: "left",
101
+ children: "Sender"
102
+ }), /*#__PURE__*/_jsx(FormItem, {
103
+ name: ['sender', 'disclaimer'],
104
+ label: "disclaimer",
105
+ children: /*#__PURE__*/_jsx(Input, {})
106
+ }), /*#__PURE__*/_jsx(FormItem, {
107
+ name: ['sender', 'attachments'],
108
+ label: "attachments",
109
+ children: /*#__PURE__*/_jsx(Switch, {})
110
+ }), /*#__PURE__*/_jsx(FormItem, {
111
+ name: ['sender', 'maxLength'],
112
+ label: "maxLength",
113
+ children: /*#__PURE__*/_jsx(InputNumber, {
114
+ min: 1000
115
+ })
116
+ }), /*#__PURE__*/_jsx(Divider, {
117
+ orientation: "left",
118
+ children: "Welcome"
119
+ }), /*#__PURE__*/_jsx(FormItem, {
120
+ name: ['welcome', 'greeting'],
121
+ label: "greeting",
122
+ children: /*#__PURE__*/_jsx(Input, {})
123
+ }), /*#__PURE__*/_jsx(FormItem, {
124
+ name: ['welcome', 'description'],
125
+ label: "description",
126
+ children: /*#__PURE__*/_jsx(Input, {})
127
+ }), /*#__PURE__*/_jsx(FormItem, {
128
+ name: ['welcome', 'avatar'],
129
+ label: "avatar",
130
+ children: /*#__PURE__*/_jsx(Input, {})
131
+ }), /*#__PURE__*/_jsx(FormItem, {
132
+ name: ['welcome', 'prompts'],
133
+ isList: true,
134
+ label: "prompts",
135
+ children: function children(fields, _ref3) {
136
+ var add = _ref3.add,
137
+ remove = _ref3.remove;
138
+ return /*#__PURE__*/_jsx("div", {
139
+ children: fields.map(function (field) {
140
+ return /*#__PURE__*/_jsxs(Flex, {
141
+ gap: 6,
142
+ children: [/*#__PURE__*/_jsx(Form.Item, {
143
+ style: {
144
+ flex: 1
145
+ },
146
+ name: [field.name, 'value'],
147
+ children: /*#__PURE__*/_jsx(Input, {})
148
+ }, field.key), /*#__PURE__*/_jsx(IconButton, {
149
+ icon: /*#__PURE__*/_jsx(SparkPlusLine, {}),
150
+ onClick: function onClick() {
151
+ return add({});
152
+ }
153
+ }), /*#__PURE__*/_jsx(IconButton, {
154
+ icon: /*#__PURE__*/_jsx(SparkDeleteLine, {}),
155
+ onClick: function onClick() {
156
+ return remove(field.name);
157
+ }
158
+ })]
159
+ }, field.key);
160
+ })
161
+ });
162
+ }
163
+ }), /*#__PURE__*/_jsx(Divider, {
164
+ orientation: "left",
165
+ children: "API"
166
+ }), /*#__PURE__*/_jsx(FormItem, {
167
+ name: ['api', 'baseURL'],
168
+ label: "baseURL",
169
+ children: /*#__PURE__*/_jsx(Input, {})
170
+ }), /*#__PURE__*/_jsx(FormItem, {
171
+ name: ['api', 'token'],
172
+ label: "token",
173
+ children: /*#__PURE__*/_jsx(Input, {})
174
+ })]
175
+ }), /*#__PURE__*/_jsxs("div", {
176
+ className: styles.actions,
177
+ children: [/*#__PURE__*/_jsx(Button, {
178
+ onClick: handleReset,
179
+ children: "Reset"
180
+ }), /*#__PURE__*/_jsx(Button, {
181
+ type: "primary",
182
+ onClick: handleSave,
183
+ children: "Save & Copy"
184
+ })]
185
+ })]
186
+ });
187
+ };
188
+ export default OptionsEditor;
@@ -0,0 +1,29 @@
1
+ declare const _default: () => {
2
+ theme: {
3
+ colorPrimary: string;
4
+ darkMode: boolean;
5
+ prefix: string;
6
+ leftHeader: {
7
+ logo: string;
8
+ title: string;
9
+ };
10
+ };
11
+ sender: {
12
+ attachments: boolean;
13
+ maxLength: number;
14
+ disclaimer: string;
15
+ };
16
+ welcome: {
17
+ greeting: string;
18
+ description: string;
19
+ avatar: string;
20
+ prompts: {
21
+ value: string;
22
+ }[];
23
+ };
24
+ api: {
25
+ baseURL: string;
26
+ token: string;
27
+ };
28
+ };
29
+ export default _default;
@@ -0,0 +1,35 @@
1
+ export default (function () {
2
+ return {
3
+ theme: {
4
+ colorPrimary: '#615CED',
5
+ darkMode: true,
6
+ prefix: 'agentscope-runtime-webui',
7
+ leftHeader: {
8
+ logo: 'https://img.alicdn.com/imgextra/i2/O1CN01lmoGYn1kjoXATy4PX_!!6000000004720-2-tps-200-200.png',
9
+ title: 'Runtime WebUI'
10
+ }
11
+ },
12
+ sender: {
13
+ // @ts-ignore
14
+ attachments: true,
15
+ maxLength: 10000,
16
+ disclaimer: 'AI can also make mistakes, so please check carefully and use it with caution'
17
+ },
18
+ welcome: {
19
+ greeting: 'Hello, how can I help you today?',
20
+ description: 'I am a helpful assistant that can help you with your questions.',
21
+ avatar: 'https://img.alicdn.com/imgextra/i2/O1CN01lmoGYn1kjoXATy4PX_!!6000000004720-2-tps-200-200.png',
22
+ prompts: [{
23
+ value: 'Hello'
24
+ }, {
25
+ value: 'How are you?'
26
+ }, {
27
+ value: 'What can you do?'
28
+ }]
29
+ },
30
+ api: {
31
+ baseURL: '',
32
+ token: ''
33
+ }
34
+ };
35
+ });
@@ -0,0 +1,6 @@
1
+ interface OptionsPanelProps {
2
+ value?: any;
3
+ onChange?: any;
4
+ }
5
+ export default function OptionsPanel(props: OptionsPanelProps): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,49 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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); }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { SparkSettingLine } from "@agentscope-ai/icons";
8
+ import { IconButton, Drawer } from "@agentscope-ai/design";
9
+ import { useState } from "react";
10
+ import OptionsEditor from "./OptionsEditor";
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { Fragment as _Fragment } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ export default function OptionsPanel(props) {
15
+ var _useState = useState(false),
16
+ _useState2 = _slicedToArray(_useState, 2),
17
+ open = _useState2[0],
18
+ setOpen = _useState2[1];
19
+ return /*#__PURE__*/_jsxs(_Fragment, {
20
+ children: [/*#__PURE__*/_jsx(IconButton, {
21
+ onClick: function onClick() {
22
+ return setOpen(true);
23
+ },
24
+ icon: /*#__PURE__*/_jsx(SparkSettingLine, {}),
25
+ bordered: false
26
+ }), /*#__PURE__*/_jsx(Drawer, {
27
+ destroyOnHidden: true,
28
+ open: open,
29
+ onClose: function onClose() {
30
+ return setOpen(false);
31
+ },
32
+ styles: {
33
+ body: {
34
+ padding: 0
35
+ },
36
+ header: {
37
+ padding: 8
38
+ }
39
+ },
40
+ children: /*#__PURE__*/_jsx(OptionsEditor, {
41
+ value: props.value,
42
+ onChange: function onChange(v) {
43
+ setOpen(false);
44
+ props.onChange(v);
45
+ }
46
+ })
47
+ })]
48
+ });
49
+ }
@@ -0,0 +1 @@
1
+ export default function (): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,70 @@
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; }
13
+ import { AgentScopeRuntimeWebUI } from "../..";
14
+ import OptionsPanel from "./OptionsPanel";
15
+ import { useMemo } from 'react';
16
+ import sessionApi from "./sessionApi";
17
+ import defaultConfig from "./OptionsPanel/defaultConfig";
18
+ import { useLocalStorageState } from 'ahooks';
19
+ import { jsx as _jsx } from "react/jsx-runtime";
20
+ export default function () {
21
+ var _useLocalStorageState = useLocalStorageState('agent-scope-runtime-webui-options', {
22
+ defaultValue: defaultConfig(),
23
+ listenStorageChange: true
24
+ }),
25
+ _useLocalStorageState2 = _slicedToArray(_useLocalStorageState, 2),
26
+ optionsConfig = _useLocalStorageState2[0],
27
+ setOptionsConfig = _useLocalStorageState2[1];
28
+ var options = useMemo(function () {
29
+ var rightHeader = /*#__PURE__*/_jsx(OptionsPanel, {
30
+ value: optionsConfig,
31
+ onChange: function onChange(v) {
32
+ setOptionsConfig(function (prev) {
33
+ return _objectSpread(_objectSpread({}, prev), v);
34
+ });
35
+ }
36
+ });
37
+ return _objectSpread(_objectSpread({}, optionsConfig), {}, {
38
+ session: {
39
+ multiple: true,
40
+ api: sessionApi
41
+ },
42
+ sender: _objectSpread(_objectSpread({}, optionsConfig.sender), {}, {
43
+ attachments: optionsConfig.sender.attachments ? {
44
+ customRequest: function customRequest(options) {
45
+ // 模拟上传进度
46
+ options.onProgress({
47
+ percent: 100
48
+ });
49
+ // 当前是一个 mock 的上传行为
50
+ // 实际情况需要具体实现一个文件上传服务,将文件转化为 url
51
+ options.onSuccess({
52
+ url: URL.createObjectURL(options.file)
53
+ });
54
+ }
55
+ } : undefined
56
+ }),
57
+ theme: _objectSpread(_objectSpread({}, optionsConfig.theme), {}, {
58
+ rightHeader: rightHeader
59
+ })
60
+ });
61
+ }, [optionsConfig]);
62
+ return /*#__PURE__*/_jsx("div", {
63
+ style: {
64
+ height: '100dvh'
65
+ },
66
+ children: /*#__PURE__*/_jsx(AgentScopeRuntimeWebUI, {
67
+ options: options
68
+ })
69
+ });
70
+ }
@@ -0,0 +1,14 @@
1
+ import { IAgentScopeRuntimeWebUISessionAPI } from "../../..";
2
+ import { IAgentScopeRuntimeWebUISession } from '../../lib/types/ISessions';
3
+ declare class SessionApi implements IAgentScopeRuntimeWebUISessionAPI {
4
+ private lsKey;
5
+ private sessionList;
6
+ constructor();
7
+ getSessionList(): Promise<IAgentScopeRuntimeWebUISession[]>;
8
+ getSession(sessionId: any): Promise<IAgentScopeRuntimeWebUISession>;
9
+ updateSession(session: any): Promise<IAgentScopeRuntimeWebUISession[]>;
10
+ createSession(session: any): Promise<IAgentScopeRuntimeWebUISession[]>;
11
+ removeSession(session: any): Promise<IAgentScopeRuntimeWebUISession[]>;
12
+ }
13
+ declare const _default: SessionApi;
14
+ export default _default;
@@ -0,0 +1,143 @@
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ 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); }
8
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
9
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
12
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
13
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
14
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
15
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
16
+ 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; }
17
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
18
+ 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); }
19
+ var SessionApi = /*#__PURE__*/function () {
20
+ function SessionApi() {
21
+ _classCallCheck(this, SessionApi);
22
+ _defineProperty(this, "lsKey", void 0);
23
+ _defineProperty(this, "sessionList", void 0);
24
+ this.lsKey = 'agent-scope-runtime-webui-sessions';
25
+ this.sessionList = [];
26
+ }
27
+ _createClass(SessionApi, [{
28
+ key: "getSessionList",
29
+ value: function () {
30
+ var _getSessionList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
31
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
32
+ while (1) switch (_context.prev = _context.next) {
33
+ case 0:
34
+ this.sessionList = JSON.parse(localStorage.getItem(this.lsKey) || '[]');
35
+ return _context.abrupt("return", _toConsumableArray(this.sessionList));
36
+ case 2:
37
+ case "end":
38
+ return _context.stop();
39
+ }
40
+ }, _callee, this);
41
+ }));
42
+ function getSessionList() {
43
+ return _getSessionList.apply(this, arguments);
44
+ }
45
+ return getSessionList;
46
+ }()
47
+ }, {
48
+ key: "getSession",
49
+ value: function () {
50
+ var _getSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(sessionId) {
51
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
52
+ while (1) switch (_context2.prev = _context2.next) {
53
+ case 0:
54
+ return _context2.abrupt("return", this.sessionList.find(function (session) {
55
+ return session.id === sessionId;
56
+ }));
57
+ case 1:
58
+ case "end":
59
+ return _context2.stop();
60
+ }
61
+ }, _callee2, this);
62
+ }));
63
+ function getSession(_x) {
64
+ return _getSession.apply(this, arguments);
65
+ }
66
+ return getSession;
67
+ }()
68
+ }, {
69
+ key: "updateSession",
70
+ value: function () {
71
+ var _updateSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(session) {
72
+ var index;
73
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
74
+ while (1) switch (_context3.prev = _context3.next) {
75
+ case 0:
76
+ index = this.sessionList.findIndex(function (item) {
77
+ return item.id === session.id;
78
+ });
79
+ if (index > -1) {
80
+ this.sessionList[index] = _objectSpread(_objectSpread({}, this.sessionList[index]), session);
81
+ localStorage.setItem(this.lsKey, JSON.stringify(this.sessionList));
82
+ }
83
+ return _context3.abrupt("return", _toConsumableArray(this.sessionList));
84
+ case 3:
85
+ case "end":
86
+ return _context3.stop();
87
+ }
88
+ }, _callee3, this);
89
+ }));
90
+ function updateSession(_x2) {
91
+ return _updateSession.apply(this, arguments);
92
+ }
93
+ return updateSession;
94
+ }()
95
+ }, {
96
+ key: "createSession",
97
+ value: function () {
98
+ var _createSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(session) {
99
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
100
+ while (1) switch (_context4.prev = _context4.next) {
101
+ case 0:
102
+ session.id = Date.now().toString();
103
+ this.sessionList.unshift(session);
104
+ localStorage.setItem(this.lsKey, JSON.stringify(this.sessionList));
105
+ return _context4.abrupt("return", _toConsumableArray(this.sessionList));
106
+ case 4:
107
+ case "end":
108
+ return _context4.stop();
109
+ }
110
+ }, _callee4, this);
111
+ }));
112
+ function createSession(_x3) {
113
+ return _createSession.apply(this, arguments);
114
+ }
115
+ return createSession;
116
+ }()
117
+ }, {
118
+ key: "removeSession",
119
+ value: function () {
120
+ var _removeSession = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(session) {
121
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
122
+ while (1) switch (_context5.prev = _context5.next) {
123
+ case 0:
124
+ this.sessionList = this.sessionList.filter(function (item) {
125
+ return item.id !== session.id;
126
+ });
127
+ localStorage.setItem(this.lsKey, JSON.stringify(this.sessionList));
128
+ return _context5.abrupt("return", _toConsumableArray(this.sessionList));
129
+ case 3:
130
+ case "end":
131
+ return _context5.stop();
132
+ }
133
+ }, _callee5, this);
134
+ }));
135
+ function removeSession(_x4) {
136
+ return _removeSession.apply(this, arguments);
137
+ }
138
+ return removeSession;
139
+ }()
140
+ }]);
141
+ return SessionApi;
142
+ }();
143
+ export default new SessionApi();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentscope-ai/chat",
3
- "version": "1.1.21",
3
+ "version": "1.1.23",
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": [
@@ -58,6 +58,7 @@
58
58
  ]
59
59
  },
60
60
  "dependencies": {
61
+ "@agentscope-ai/design": "^1.0.0",
61
62
  "@agentscope-ai/icons": "^1.0.32",
62
63
  "commander": "^12.1.0",
63
64
  "vite": "^5.4.11",