@agentscope-ai/chat 1.1.69 → 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.
Files changed (35) hide show
  1. package/components/AgentScopeRuntimeWebUI/core/Chat/Input/index.tsx +38 -5
  2. package/components/AgentScopeRuntimeWebUI/core/Chat/InputQueue/Panel.tsx +82 -0
  3. package/components/AgentScopeRuntimeWebUI/core/Chat/InputQueue/__tests__/inputQueue.test.ts +112 -0
  4. package/components/AgentScopeRuntimeWebUI/core/Chat/InputQueue/index.ts +122 -0
  5. package/components/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatController.tsx +111 -4
  6. package/components/AgentScopeRuntimeWebUI/core/Chat/index.tsx +21 -3
  7. package/components/AgentScopeRuntimeWebUI/core/Chat/styles.tsx +68 -1
  8. package/components/AgentScopeRuntimeWebUI/core/ChatAnywhere/index.tsx +1 -1
  9. package/components/AgentScopeRuntimeWebUI/core/Context/ChatAnywhereI18nContext.tsx +14 -0
  10. package/components/AgentScopeRuntimeWebUI/starter/index.tsx +100 -14
  11. package/components/AgentScopeRuntimeWebUI/starterForMe/index.tsx +31 -0
  12. package/components/Attachments/index.tsx +30 -2
  13. package/components/ChatAnywhere/Input/index.tsx +5 -0
  14. package/components/ChatAnywhere/hooks/ChatAnywhereProvider.tsx +1 -0
  15. package/components/ChatAnywhere/hooks/types.ts +5 -0
  16. package/lib/AgentScopeRuntimeWebUI/core/Chat/Input/index.d.ts +8 -0
  17. package/lib/AgentScopeRuntimeWebUI/core/Chat/Input/index.js +36 -8
  18. package/lib/AgentScopeRuntimeWebUI/core/Chat/InputQueue/Panel.d.ts +9 -0
  19. package/lib/AgentScopeRuntimeWebUI/core/Chat/InputQueue/Panel.js +78 -0
  20. package/lib/AgentScopeRuntimeWebUI/core/Chat/InputQueue/index.d.ts +37 -0
  21. package/lib/AgentScopeRuntimeWebUI/core/Chat/InputQueue/index.js +74 -0
  22. package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatController.d.ts +7 -0
  23. package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatController.js +204 -63
  24. package/lib/AgentScopeRuntimeWebUI/core/Chat/index.js +14 -2
  25. package/lib/AgentScopeRuntimeWebUI/core/Chat/styles.js +31 -1
  26. package/lib/AgentScopeRuntimeWebUI/core/Context/ChatAnywhereI18nContext.d.ts +11 -1
  27. package/lib/AgentScopeRuntimeWebUI/core/Context/ChatAnywhereI18nContext.js +12 -0
  28. package/lib/AgentScopeRuntimeWebUI/starter/index.js +144 -20
  29. package/lib/AgentScopeRuntimeWebUI/starterForMe/index.d.ts +1 -0
  30. package/lib/AgentScopeRuntimeWebUI/starterForMe/index.js +34 -0
  31. package/lib/Attachments/index.js +40 -2
  32. package/lib/ChatAnywhere/Input/index.js +8 -0
  33. package/lib/ChatAnywhere/hooks/ChatAnywhereProvider.d.ts +1 -0
  34. package/lib/ChatAnywhere/hooks/types.d.ts +5 -0
  35. package/package.json +2 -1
@@ -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
- import { AgentScopeRuntimeWebUI, ChatInput } from "../..";
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(OptionsPanel, {
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
+ }
@@ -97,14 +97,15 @@ function Attachments(props, ref) {
97
97
  });
98
98
  };
99
99
  var onItemReplace = useEvent(function (oldItem, file) {
100
+ var customRequest = uploadProps.customRequest;
100
101
  var newAttachment = {
101
102
  uid: oldItem.uid,
102
103
  name: file.name,
103
104
  size: file.size,
104
105
  type: file.type,
105
106
  originFileObj: file,
106
- status: 'done',
107
- percent: 100
107
+ status: customRequest ? 'uploading' : 'done',
108
+ percent: customRequest ? 0 : 100
108
109
  };
109
110
  var newFileList = fileList.map(function (fileItem) {
110
111
  return fileItem.uid === oldItem.uid ? newAttachment : fileItem;
@@ -113,6 +114,43 @@ function Attachments(props, ref) {
113
114
  file: newAttachment,
114
115
  fileList: newFileList
115
116
  });
117
+ if (customRequest) {
118
+ var updateFile = function updateFile(updates) {
119
+ setFileList(function (prev) {
120
+ var updated = prev.map(function (f) {
121
+ return f.uid === oldItem.uid ? _objectSpread(_objectSpread({}, f), updates) : f;
122
+ });
123
+ onChange === null || onChange === void 0 || onChange({
124
+ file: _objectSpread(_objectSpread({}, newAttachment), updates),
125
+ fileList: updated
126
+ });
127
+ return updated;
128
+ });
129
+ };
130
+ customRequest({
131
+ file: file,
132
+ onSuccess: function onSuccess(response) {
133
+ updateFile({
134
+ status: 'done',
135
+ percent: 100,
136
+ response: response
137
+ });
138
+ },
139
+ onError: function onError(error) {
140
+ updateFile({
141
+ status: 'error',
142
+ error: error
143
+ });
144
+ },
145
+ onProgress: function onProgress(event) {
146
+ updateFile({
147
+ percent: event === null || event === void 0 ? void 0 : event.percent
148
+ });
149
+ }
150
+ }, {
151
+ defaultRequest: function defaultRequest() {}
152
+ });
153
+ }
116
154
  });
117
155
  var renderChildren;
118
156
  var getPlaceholderNode = function getPlaceholderNode(type, props, ref) {
@@ -100,6 +100,12 @@ export default /*#__PURE__*/forwardRef(function (_, ref) {
100
100
  setContent(content);
101
101
  setAttachedFiles(fileList || [[]]);
102
102
  },
103
+ clearInput: function clearInput() {
104
+ setContent('');
105
+ setAttachedFiles(attachedFilesRef.current.map(function () {
106
+ return [];
107
+ }));
108
+ },
103
109
  getAttachedFiles: function getAttachedFiles() {
104
110
  return attachedFilesRef.current;
105
111
  }
@@ -197,10 +203,12 @@ export default /*#__PURE__*/forwardRef(function (_, ref) {
197
203
  return item.length;
198
204
  }),
199
205
  children: attachedFiles.map(function (files, index) {
206
+ var _onUpload$index;
200
207
  if (!files.length) return null;
201
208
  return /*#__PURE__*/_jsx(Attachments, {
202
209
  items: files,
203
210
  replaceable: true,
211
+ customRequest: (_onUpload$index = onUpload[index]) === null || _onUpload$index === void 0 ? void 0 : _onUpload$index.customRequest,
204
212
  onChange: function onChange(info) {
205
213
  return handleFileChange(index, info.fileList);
206
214
  }
@@ -149,6 +149,7 @@ export interface IChatAnywhereContext {
149
149
  }
150
150
  export type ChatAnywhereRef = ReturnType<typeof useMessages> & ReturnType<typeof useInput> & ReturnType<typeof useSessionList> & {
151
151
  setInputContent: (content: string, fileList?: UploadFile[][]) => void;
152
+ clearInput: () => void;
152
153
  scrollToBottom: (options?: ScrollToBottomOptions) => void;
153
154
  reload: () => void;
154
155
  };
@@ -316,6 +316,11 @@ export interface IChatAnywhereRef extends IChatAnywhereContext {
316
316
  * @descriptionEn Method to set input field content
317
317
  */
318
318
  setInputContent: (content: string, fileList?: UploadFile[][]) => void;
319
+ /**
320
+ * @description 清空输入框内容和附件
321
+ * @descriptionEn Clear input content and attached files
322
+ */
323
+ clearInput: () => void;
319
324
  /**
320
325
  * @description 滚动到底部的方法
321
326
  * @descriptionEn Method to scroll to bottom
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentscope-ai/chat",
3
- "version": "1.1.69",
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
  },