@agentscope-ai/chat 1.1.70 → 1.1.71-beta.1781610744021
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/AgentScopeRuntimeWebUI/core/Chat/Input/index.tsx +38 -5
- package/components/AgentScopeRuntimeWebUI/core/Chat/InputQueue/Panel.tsx +82 -0
- package/components/AgentScopeRuntimeWebUI/core/Chat/InputQueue/__tests__/inputQueue.test.ts +112 -0
- package/components/AgentScopeRuntimeWebUI/core/Chat/InputQueue/index.ts +122 -0
- package/components/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatController.tsx +111 -4
- package/components/AgentScopeRuntimeWebUI/core/Chat/index.tsx +21 -3
- package/components/AgentScopeRuntimeWebUI/core/Chat/styles.tsx +68 -1
- package/components/AgentScopeRuntimeWebUI/core/ChatAnywhere/index.tsx +1 -1
- package/components/AgentScopeRuntimeWebUI/core/Context/ChatAnywhereI18nContext.tsx +14 -0
- package/components/AgentScopeRuntimeWebUI/starter/index.tsx +100 -14
- package/components/AgentScopeRuntimeWebUI/starterForMe/index.tsx +31 -0
- package/lib/AgentScopeRuntimeWebUI/core/Chat/Input/index.d.ts +8 -0
- package/lib/AgentScopeRuntimeWebUI/core/Chat/Input/index.js +36 -8
- package/lib/AgentScopeRuntimeWebUI/core/Chat/InputQueue/Panel.d.ts +9 -0
- package/lib/AgentScopeRuntimeWebUI/core/Chat/InputQueue/Panel.js +78 -0
- package/lib/AgentScopeRuntimeWebUI/core/Chat/InputQueue/index.d.ts +37 -0
- package/lib/AgentScopeRuntimeWebUI/core/Chat/InputQueue/index.js +74 -0
- package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatController.d.ts +7 -0
- package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatController.js +204 -63
- package/lib/AgentScopeRuntimeWebUI/core/Chat/index.js +14 -2
- package/lib/AgentScopeRuntimeWebUI/core/Chat/styles.js +31 -1
- package/lib/AgentScopeRuntimeWebUI/core/Context/ChatAnywhereI18nContext.d.ts +11 -1
- package/lib/AgentScopeRuntimeWebUI/core/Context/ChatAnywhereI18nContext.js +12 -0
- package/lib/AgentScopeRuntimeWebUI/starter/index.js +144 -20
- package/lib/AgentScopeRuntimeWebUI/starterForMe/index.d.ts +1 -0
- package/lib/AgentScopeRuntimeWebUI/starterForMe/index.js +34 -0
- package/package.json +2 -1
- package/bin/starter_webui/README.md +0 -75
- package/bin/starter_webui/eslint.config.js +0 -28
- package/bin/starter_webui/index.html +0 -12
- package/bin/starter_webui/package.json +0 -34
- package/bin/starter_webui/src/App.tsx +0 -20
- package/bin/starter_webui/src/components/Chat/OptionsPanel/FormItem.tsx +0 -37
- package/bin/starter_webui/src/components/Chat/OptionsPanel/OptionsEditor.tsx +0 -160
- package/bin/starter_webui/src/components/Chat/OptionsPanel/defaultConfig.ts +0 -41
- package/bin/starter_webui/src/components/Chat/OptionsPanel/index.tsx +0 -27
- package/bin/starter_webui/src/components/Chat/index.tsx +0 -45
- package/bin/starter_webui/src/components/Chat/sessionApi/index.ts +0 -53
- package/bin/starter_webui/src/main.tsx +0 -9
- package/bin/starter_webui/src/vite-env.d.ts +0 -4
- package/bin/starter_webui/tsconfig.app.json +0 -24
- package/bin/starter_webui/tsconfig.json +0 -7
- package/bin/starter_webui/tsconfig.node.json +0 -22
- package/bin/starter_webui/vite.config.ts +0 -11
|
@@ -1,4 +1,5 @@
|
|
|
1
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 _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; }
|
|
2
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; }
|
|
3
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; }
|
|
4
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; }
|
|
@@ -10,15 +11,131 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
10
11
|
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
12
|
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
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
-
|
|
14
|
+
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); } }
|
|
15
|
+
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); }); }; }
|
|
16
|
+
import { AgentScopeRuntimeWebUI } from "../..";
|
|
14
17
|
import OptionsPanel from "./OptionsPanel";
|
|
15
18
|
import { useMemo, useRef } from 'react';
|
|
16
19
|
import defaultConfig from "./OptionsPanel/defaultConfig";
|
|
17
20
|
import { useLocalStorageState } from 'ahooks';
|
|
18
|
-
import { Flex } from 'antd';
|
|
21
|
+
import { Button, Flex } from 'antd';
|
|
19
22
|
import MessageImport from "./MessageImport";
|
|
20
23
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
21
24
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
25
|
+
var encoder = new TextEncoder();
|
|
26
|
+
var sleep = function sleep(ms) {
|
|
27
|
+
return new Promise(function (resolve) {
|
|
28
|
+
setTimeout(resolve, ms);
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
function getLastUserText() {
|
|
32
|
+
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
33
|
+
var lastMessage = input[input.length - 1];
|
|
34
|
+
var content = (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.content) || [];
|
|
35
|
+
return content.filter(function (item) {
|
|
36
|
+
return (item === null || item === void 0 ? void 0 : item.type) === 'text';
|
|
37
|
+
}).map(function (item) {
|
|
38
|
+
return item.text;
|
|
39
|
+
}).join('\n');
|
|
40
|
+
}
|
|
41
|
+
function createMockQueueResponse(_x) {
|
|
42
|
+
return _createMockQueueResponse.apply(this, arguments);
|
|
43
|
+
}
|
|
44
|
+
function _createMockQueueResponse() {
|
|
45
|
+
_createMockQueueResponse = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(data) {
|
|
46
|
+
var userText, messageId, chunks, stream;
|
|
47
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
48
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
49
|
+
case 0:
|
|
50
|
+
userText = getLastUserText(data.input);
|
|
51
|
+
messageId = "queue-demo-".concat(Date.now());
|
|
52
|
+
chunks = [{
|
|
53
|
+
object: 'message',
|
|
54
|
+
id: messageId,
|
|
55
|
+
role: 'assistant',
|
|
56
|
+
type: 'message',
|
|
57
|
+
status: 'in_progress',
|
|
58
|
+
content: []
|
|
59
|
+
}, {
|
|
60
|
+
object: 'content',
|
|
61
|
+
msg_id: messageId,
|
|
62
|
+
type: 'text',
|
|
63
|
+
status: 'in_progress',
|
|
64
|
+
delta: true,
|
|
65
|
+
text: "Received: ".concat(userText || 'attachment message', "\n\n")
|
|
66
|
+
}, {
|
|
67
|
+
object: 'content',
|
|
68
|
+
msg_id: messageId,
|
|
69
|
+
type: 'text',
|
|
70
|
+
status: 'in_progress',
|
|
71
|
+
delta: true,
|
|
72
|
+
text: 'This mock response is intentionally slow, '
|
|
73
|
+
}, {
|
|
74
|
+
object: 'content',
|
|
75
|
+
msg_id: messageId,
|
|
76
|
+
type: 'text',
|
|
77
|
+
status: 'in_progress',
|
|
78
|
+
delta: true,
|
|
79
|
+
text: 'so later inputs can enter the queue.'
|
|
80
|
+
}, {
|
|
81
|
+
object: 'response',
|
|
82
|
+
id: messageId,
|
|
83
|
+
status: 'completed',
|
|
84
|
+
created_at: Math.floor(Date.now() / 1000),
|
|
85
|
+
output: []
|
|
86
|
+
}];
|
|
87
|
+
stream = new ReadableStream({
|
|
88
|
+
start: function start(controller) {
|
|
89
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
90
|
+
var _i, _chunks, _data$signal, chunk;
|
|
91
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
92
|
+
while (1) switch (_context.prev = _context.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
_i = 0, _chunks = chunks;
|
|
95
|
+
case 1:
|
|
96
|
+
if (!(_i < _chunks.length)) {
|
|
97
|
+
_context.next = 12;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
chunk = _chunks[_i];
|
|
101
|
+
if (!((_data$signal = data.signal) !== null && _data$signal !== void 0 && _data$signal.aborted)) {
|
|
102
|
+
_context.next = 6;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
controller.close();
|
|
106
|
+
return _context.abrupt("return");
|
|
107
|
+
case 6:
|
|
108
|
+
_context.next = 8;
|
|
109
|
+
return sleep(700);
|
|
110
|
+
case 8:
|
|
111
|
+
controller.enqueue(encoder.encode("data: ".concat(JSON.stringify(chunk), "\n\n")));
|
|
112
|
+
case 9:
|
|
113
|
+
_i++;
|
|
114
|
+
_context.next = 1;
|
|
115
|
+
break;
|
|
116
|
+
case 12:
|
|
117
|
+
controller.close();
|
|
118
|
+
case 13:
|
|
119
|
+
case "end":
|
|
120
|
+
return _context.stop();
|
|
121
|
+
}
|
|
122
|
+
}, _callee);
|
|
123
|
+
}))();
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
return _context2.abrupt("return", new Response(stream, {
|
|
127
|
+
headers: {
|
|
128
|
+
'Content-Type': 'text/event-stream'
|
|
129
|
+
}
|
|
130
|
+
}));
|
|
131
|
+
case 5:
|
|
132
|
+
case "end":
|
|
133
|
+
return _context2.stop();
|
|
134
|
+
}
|
|
135
|
+
}, _callee2);
|
|
136
|
+
}));
|
|
137
|
+
return _createMockQueueResponse.apply(this, arguments);
|
|
138
|
+
}
|
|
22
139
|
export default function () {
|
|
23
140
|
var chatRef = useRef(null);
|
|
24
141
|
// @ts-ignore
|
|
@@ -33,7 +150,28 @@ export default function () {
|
|
|
33
150
|
var options = useMemo(function () {
|
|
34
151
|
var rightHeader = /*#__PURE__*/_jsxs(Flex, {
|
|
35
152
|
gap: 16,
|
|
36
|
-
children: [/*#__PURE__*/_jsx(
|
|
153
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
154
|
+
size: "small",
|
|
155
|
+
onClick: function onClick() {
|
|
156
|
+
var _chatRef$current;
|
|
157
|
+
(_chatRef$current = chatRef.current) === null || _chatRef$current === void 0 || _chatRef$current.input.submit({
|
|
158
|
+
query: 'Queue demo 1: slow response'
|
|
159
|
+
});
|
|
160
|
+
window.setTimeout(function () {
|
|
161
|
+
var _chatRef$current2;
|
|
162
|
+
(_chatRef$current2 = chatRef.current) === null || _chatRef$current2 === void 0 || _chatRef$current2.input.submit({
|
|
163
|
+
query: 'Queue demo 2: queued while busy'
|
|
164
|
+
});
|
|
165
|
+
}, 400);
|
|
166
|
+
window.setTimeout(function () {
|
|
167
|
+
var _chatRef$current3;
|
|
168
|
+
(_chatRef$current3 = chatRef.current) === null || _chatRef$current3 === void 0 || _chatRef$current3.input.submit({
|
|
169
|
+
query: 'Queue demo 3: sent after demo 2'
|
|
170
|
+
});
|
|
171
|
+
}, 800);
|
|
172
|
+
},
|
|
173
|
+
children: "Queue demo"
|
|
174
|
+
}), /*#__PURE__*/_jsx(OptionsPanel, {
|
|
37
175
|
value: optionsConfig,
|
|
38
176
|
onChange: function onChange(v) {
|
|
39
177
|
setOptionsConfig(function (prev) {
|
|
@@ -50,22 +188,6 @@ export default function () {
|
|
|
50
188
|
multiple: true
|
|
51
189
|
},
|
|
52
190
|
sender: _objectSpread(_objectSpread({}, optionsConfig.sender), {}, {
|
|
53
|
-
beforeUI: /*#__PURE__*/_jsx(ChatInput.BeforeUIContainer, {
|
|
54
|
-
children: /*#__PURE__*/_jsx(Flex, {
|
|
55
|
-
gap: 6,
|
|
56
|
-
children: optionsConfig.welcome.prompts.map(function (prompt) {
|
|
57
|
-
return /*#__PURE__*/_jsx("a", {
|
|
58
|
-
onClick: function onClick() {
|
|
59
|
-
var _chatRef$current;
|
|
60
|
-
(_chatRef$current = chatRef.current) === null || _chatRef$current === void 0 || _chatRef$current.input.submit({
|
|
61
|
-
query: prompt.value
|
|
62
|
-
});
|
|
63
|
-
},
|
|
64
|
-
children: prompt.value
|
|
65
|
-
}, prompt.value);
|
|
66
|
-
})
|
|
67
|
-
})
|
|
68
|
-
}),
|
|
69
191
|
attachments: optionsConfig.sender.attachments ? {
|
|
70
192
|
customRequest: function customRequest(options) {
|
|
71
193
|
// 模拟上传进度
|
|
@@ -83,7 +205,9 @@ export default function () {
|
|
|
83
205
|
theme: _objectSpread(_objectSpread({}, optionsConfig.theme), {}, {
|
|
84
206
|
rightHeader: rightHeader
|
|
85
207
|
}),
|
|
86
|
-
api: _objectSpread(_objectSpread({}, optionsConfig.api),
|
|
208
|
+
api: _objectSpread(_objectSpread(_objectSpread({}, optionsConfig.api), !optionsConfig.api.baseURL ? {
|
|
209
|
+
fetch: createMockQueueResponse
|
|
210
|
+
} : {}), {}, {
|
|
87
211
|
cancel: function cancel(data) {
|
|
88
212
|
console.log('cancel', data);
|
|
89
213
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function Page(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { AgentScopeRuntimeWebUI } from "../..";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
export default function Page() {
|
|
4
|
+
return /*#__PURE__*/_jsx("div", {
|
|
5
|
+
style: {
|
|
6
|
+
height: '100dvh'
|
|
7
|
+
},
|
|
8
|
+
children: /*#__PURE__*/_jsx(AgentScopeRuntimeWebUI, {
|
|
9
|
+
options: {
|
|
10
|
+
api: {
|
|
11
|
+
baseURL: '/api/runtime/chat',
|
|
12
|
+
token: 'your-token'
|
|
13
|
+
},
|
|
14
|
+
session: {
|
|
15
|
+
multiple: true
|
|
16
|
+
},
|
|
17
|
+
theme: {
|
|
18
|
+
locale: 'en',
|
|
19
|
+
colorPrimary: '#615CED'
|
|
20
|
+
},
|
|
21
|
+
sender: {
|
|
22
|
+
placeholder: 'Ask something',
|
|
23
|
+
maxLength: 10000
|
|
24
|
+
},
|
|
25
|
+
welcome: {
|
|
26
|
+
greeting: 'Hello, how can I help you today?',
|
|
27
|
+
prompts: [{
|
|
28
|
+
value: 'What can you do?'
|
|
29
|
+
}]
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentscope-ai/chat",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.71-beta.1781610744021",
|
|
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": [
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
"prepare": "dumi setup",
|
|
35
35
|
"src:build": "father build",
|
|
36
36
|
"start": "npm run dev",
|
|
37
|
+
"test": "tsx components/AgentScopeRuntimeWebUI/core/Chat/InputQueue/__tests__/inputQueue.test.ts",
|
|
37
38
|
"release:beta": "node publish-beta.js",
|
|
38
39
|
"release": "node publish.js"
|
|
39
40
|
},
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# agentscope-runtime-starter-webui
|
|
2
|
-
|
|
3
|
-
## node version
|
|
4
|
-
|
|
5
|
-
> =22
|
|
6
|
-
|
|
7
|
-
## install
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
$ npm run install
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## dev
|
|
14
|
-
|
|
15
|
-
```
|
|
16
|
-
$ npm run dev
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## build
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
$ npm run build
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Core Code
|
|
26
|
-
```tsx
|
|
27
|
-
import { AgentScopeRuntimeWebUI } from '@agentscope-ai/chat';
|
|
28
|
-
|
|
29
|
-
const options = {
|
|
30
|
-
theme: {
|
|
31
|
-
colorPrimary: '#615CED',
|
|
32
|
-
darkMode: true,
|
|
33
|
-
prefix: 'agentscope-runtime-webui',
|
|
34
|
-
leftHeader: {
|
|
35
|
-
logo: 'https://img.alicdn.com/imgextra/i2/O1CN01lmoGYn1kjoXATy4PX_!!6000000004720-2-tps-200-200.png',
|
|
36
|
-
title: 'Runtime WebUI',
|
|
37
|
-
},
|
|
38
|
-
},
|
|
39
|
-
sender: {
|
|
40
|
-
maxLength: 10000,
|
|
41
|
-
disclaimer:
|
|
42
|
-
'AI can also make mistakes, so please check carefully and use it with caution',
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
welcome: {
|
|
46
|
-
greeting: 'Hello, how can I help you today?',
|
|
47
|
-
description:
|
|
48
|
-
'I am a helpful assistant that can help you with your questions.',
|
|
49
|
-
avatar:
|
|
50
|
-
'https://img.alicdn.com/imgextra/i2/O1CN01lmoGYn1kjoXATy4PX_!!6000000004720-2-tps-200-200.png',
|
|
51
|
-
prompts: [
|
|
52
|
-
{
|
|
53
|
-
value: 'Hello',
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
value: 'How are you?',
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
value: 'What can you do?',
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
},
|
|
63
|
-
api: {
|
|
64
|
-
baseURL: 'YOUR_API_URL',
|
|
65
|
-
token: 'YOUR_API_TOKEN', // is not required
|
|
66
|
-
},
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
<AgentScopeRuntimeWebUI
|
|
71
|
-
options={options}
|
|
72
|
-
/>
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
```
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import js from '@eslint/js'
|
|
2
|
-
import globals from 'globals'
|
|
3
|
-
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
-
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
-
import tseslint from 'typescript-eslint'
|
|
6
|
-
|
|
7
|
-
export default tseslint.config(
|
|
8
|
-
{ ignores: ['dist'] },
|
|
9
|
-
{
|
|
10
|
-
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
|
11
|
-
files: ['**/*.{ts,tsx}'],
|
|
12
|
-
languageOptions: {
|
|
13
|
-
ecmaVersion: 2020,
|
|
14
|
-
globals: globals.browser,
|
|
15
|
-
},
|
|
16
|
-
plugins: {
|
|
17
|
-
'react-hooks': reactHooks,
|
|
18
|
-
'react-refresh': reactRefresh,
|
|
19
|
-
},
|
|
20
|
-
rules: {
|
|
21
|
-
...reactHooks.configs.recommended.rules,
|
|
22
|
-
'react-refresh/only-export-components': [
|
|
23
|
-
'warn',
|
|
24
|
-
{ allowConstantExport: true },
|
|
25
|
-
],
|
|
26
|
-
},
|
|
27
|
-
},
|
|
28
|
-
)
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
-
<title>AgentScope Runtime Starter WebUI</title>
|
|
7
|
-
</head>
|
|
8
|
-
<body>
|
|
9
|
-
<div id="root"></div>
|
|
10
|
-
<script type="module" src="/src/main.tsx"></script>
|
|
11
|
-
</body>
|
|
12
|
-
</html>
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "agentscope-runtime-starter-webui",
|
|
3
|
-
"private": true,
|
|
4
|
-
"version": "0.0.0",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "vite --host",
|
|
8
|
-
"build": "tsc -b && vite build",
|
|
9
|
-
"lint": "eslint .",
|
|
10
|
-
"preview": "vite preview"
|
|
11
|
-
},
|
|
12
|
-
"dependencies": {
|
|
13
|
-
"@agentscope-ai/icons": "^1.0.46",
|
|
14
|
-
"@agentscope-ai/chat": "^1.1.44",
|
|
15
|
-
"@agentscope-ai/design": "^1.0.19",
|
|
16
|
-
"antd": "^5.29.1",
|
|
17
|
-
"antd-style": "^3.7.1",
|
|
18
|
-
"react": "^18",
|
|
19
|
-
"react-dom": "^18"
|
|
20
|
-
},
|
|
21
|
-
"devDependencies": {
|
|
22
|
-
"@eslint/js": "^9.25.0",
|
|
23
|
-
"@types/react": "^18",
|
|
24
|
-
"@types/react-dom": "^18",
|
|
25
|
-
"@vitejs/plugin-react": "^4.4.1",
|
|
26
|
-
"eslint": "^9.25.0",
|
|
27
|
-
"eslint-plugin-react-hooks": "^5.2.0",
|
|
28
|
-
"eslint-plugin-react-refresh": "^0.4.19",
|
|
29
|
-
"globals": "^16.0.0",
|
|
30
|
-
"typescript": "~5.8.3",
|
|
31
|
-
"typescript-eslint": "^8.30.1",
|
|
32
|
-
"vite": "^6.3.5"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import Chat from './components/Chat';
|
|
2
|
-
|
|
3
|
-
import { createGlobalStyle } from 'antd-style';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const GlobalStyle = createGlobalStyle`
|
|
7
|
-
* {
|
|
8
|
-
margin: 0;
|
|
9
|
-
box-sizing: border-box;
|
|
10
|
-
}
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
function App() {
|
|
14
|
-
return <>
|
|
15
|
-
<GlobalStyle />
|
|
16
|
-
<Chat />
|
|
17
|
-
</>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export default App
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Form } 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 }) => ({
|
|
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
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Form, Input, ColorPicker, Flex, 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 }) => ({
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
<FormItem name={['sender', 'maxLength']} label="maxLength" >
|
|
102
|
-
<InputNumber min={1000} />
|
|
103
|
-
</FormItem>
|
|
104
|
-
|
|
105
|
-
<Divider orientation="left">Welcome</Divider>
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
<FormItem name={['welcome', 'greeting']} label="greeting" >
|
|
109
|
-
<Input />
|
|
110
|
-
</FormItem>
|
|
111
|
-
|
|
112
|
-
<FormItem name={['welcome', 'description']} label="description" >
|
|
113
|
-
<Input />
|
|
114
|
-
</FormItem>
|
|
115
|
-
|
|
116
|
-
<FormItem name={['welcome', 'avatar']} label="avatar" >
|
|
117
|
-
<Input />
|
|
118
|
-
</FormItem>
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
<FormItem name={['welcome', 'prompts']} isList label="prompts" >
|
|
122
|
-
{(fields: { key: string, name: string }[], { add, remove }: { add: (item: any) => void, remove: (name: string) => void }) => {
|
|
123
|
-
return <div>
|
|
124
|
-
{fields.map(field => {
|
|
125
|
-
return <Flex key={field.key} gap={6}>
|
|
126
|
-
<Form.Item style={{ flex: 1 }} key={field.key} name={[field.name, 'value']}>
|
|
127
|
-
<Input />
|
|
128
|
-
</Form.Item>
|
|
129
|
-
<IconButton icon={<SparkPlusLine />} onClick={() => add({})}></IconButton>
|
|
130
|
-
<IconButton icon={<SparkDeleteLine />} onClick={() => remove(field.name)}></IconButton>
|
|
131
|
-
</Flex>
|
|
132
|
-
})}
|
|
133
|
-
</div>
|
|
134
|
-
}}
|
|
135
|
-
</FormItem>
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
<Divider orientation="left">API</Divider>
|
|
139
|
-
|
|
140
|
-
<FormItem name={['api', 'baseURL']} label="baseURL" >
|
|
141
|
-
<Input />
|
|
142
|
-
</FormItem>
|
|
143
|
-
|
|
144
|
-
<FormItem name={['api', 'token']} label="token" >
|
|
145
|
-
<Input />
|
|
146
|
-
</FormItem>
|
|
147
|
-
</Form>
|
|
148
|
-
|
|
149
|
-
<div className={styles.actions}>
|
|
150
|
-
<Button onClick={handleReset}>Reset</Button>
|
|
151
|
-
<Button type="primary" onClick={handleSave}>
|
|
152
|
-
Save & Copy
|
|
153
|
-
</Button>
|
|
154
|
-
</div>
|
|
155
|
-
</div>
|
|
156
|
-
);
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export default OptionsEditor;
|
|
160
|
-
|