@agentscope-ai/chat 1.1.65 → 1.1.67

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 (46) hide show
  1. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Request/Actions.tsx +8 -4
  2. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Request/Builder.tsx +7 -1
  3. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Request/Card.tsx +5 -1
  4. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Actions.tsx +1 -1
  5. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.tsx +55 -4
  6. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Message.tsx +2 -1
  7. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Tool.tsx +28 -5
  8. package/components/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/types.tsx +1 -0
  9. package/components/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatController.tsx +129 -33
  10. package/components/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatRequest.tsx +74 -39
  11. package/components/AgentScopeRuntimeWebUI/core/types/IChatAnywhere.ts +10 -0
  12. package/components/DefaultCards/Files/index.tsx +5 -1
  13. package/components/Markdown/Markdown.tsx +2 -1
  14. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Request/Actions.js +8 -1
  15. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Request/Builder.js +4 -0
  16. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Request/Card.js +8 -2
  17. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Actions.js +1 -1
  18. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Builder.js +80 -12
  19. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Message.js +6 -1
  20. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/Response/Tool.js +29 -4
  21. package/lib/AgentScopeRuntimeWebUI/core/AgentScopeRuntime/types.d.ts +1 -0
  22. package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatController.d.ts +1 -1
  23. package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatController.js +167 -68
  24. package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatRequest.d.ts +7 -3
  25. package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatRequest.js +151 -117
  26. package/lib/AgentScopeRuntimeWebUI/core/types/IChatAnywhere.d.ts +15 -0
  27. package/lib/DefaultCards/Files/index.js +5 -1
  28. package/lib/Markdown/Markdown.js +1 -0
  29. package/package.json +1 -1
  30. package/bin/starter_webui/README.md +0 -75
  31. package/bin/starter_webui/eslint.config.js +0 -28
  32. package/bin/starter_webui/index.html +0 -12
  33. package/bin/starter_webui/package.json +0 -34
  34. package/bin/starter_webui/src/App.tsx +0 -20
  35. package/bin/starter_webui/src/components/Chat/OptionsPanel/FormItem.tsx +0 -37
  36. package/bin/starter_webui/src/components/Chat/OptionsPanel/OptionsEditor.tsx +0 -160
  37. package/bin/starter_webui/src/components/Chat/OptionsPanel/defaultConfig.ts +0 -41
  38. package/bin/starter_webui/src/components/Chat/OptionsPanel/index.tsx +0 -27
  39. package/bin/starter_webui/src/components/Chat/index.tsx +0 -45
  40. package/bin/starter_webui/src/components/Chat/sessionApi/index.ts +0 -53
  41. package/bin/starter_webui/src/main.tsx +0 -9
  42. package/bin/starter_webui/src/vite-env.d.ts +0 -4
  43. package/bin/starter_webui/tsconfig.app.json +0 -24
  44. package/bin/starter_webui/tsconfig.json +0 -7
  45. package/bin/starter_webui/tsconfig.node.json +0 -22
  46. package/bin/starter_webui/vite.config.ts +0 -11
@@ -10,7 +10,7 @@ import { useChatAnywhereOptions } from "../../Context/ChatAnywhereOptionsContext
10
10
  import AgentScopeRuntimeResponseBuilder from "../../AgentScopeRuntime/Response/Builder";
11
11
  import { AgentScopeRuntimeRunStatus, AgentScopeRuntimeMessageType } from "../../AgentScopeRuntime/types";
12
12
  /**
13
- * 处理 API 请求和流式响应的 Hook
13
+ * Hook for handling API requests and streaming SSE responses.
14
14
  */
15
15
  export default function useChatRequest(options) {
16
16
  var currentQARef = options.currentQARef,
@@ -21,7 +21,7 @@ export default function useChatRequest(options) {
21
21
  return v.api;
22
22
  });
23
23
 
24
- // 使用 ref 保存最新的 apiOptions,避免闭包陷阱
24
+ // Keep apiOptions in a ref to avoid stale closure issues
25
25
  var apiOptionsRef = useRef(apiOptions);
26
26
  useEffect(function () {
27
27
  apiOptionsRef.current = apiOptions;
@@ -101,9 +101,9 @@ export default function useChatRequest(options) {
101
101
  };
102
102
  }(), []);
103
103
  var processSSEResponse = useCallback( /*#__PURE__*/function () {
104
- var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(response) {
104
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(response, myRequestId, mySessionId) {
105
105
  var _currentQARef$current;
106
- var currentApiOptions, agentScopeRuntimeResponseBuilder, data, res, abortSignal, _iteratorAbruptCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, chunk, _currentQARef$current2, _res$output, _currentQARef$current3, responseParser, chunkData, _res, _currentQARef$current4;
106
+ var currentApiOptions, agentScopeRuntimeResponseBuilder, isStillActive, data, res, abortSignal, _iteratorAbruptCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, chunk, _currentQARef$current2, _res$output, _currentQARef$current3, responseParser, chunkData, _res, _currentQARef$current4;
107
107
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
108
108
  while (1) switch (_context2.prev = _context2.next) {
109
109
  case 0:
@@ -113,14 +113,25 @@ export default function useChatRequest(options) {
113
113
  status: AgentScopeRuntimeRunStatus.Created,
114
114
  created_at: 0
115
115
  });
116
+ /**
117
+ * Guard: check whether this SSE stream is still the active request.
118
+ * If any of the following is true, writing should stop immediately:
119
+ * - requestId mismatch: user cancelled / sent new message / switched session
120
+ * - sessionId mismatch: session was switched away, prevents cross-session leakage
121
+ */
122
+ isStillActive = function isStillActive() {
123
+ if (currentQARef.current.activeRequestId !== myRequestId) return false;
124
+ if (mySessionId && currentQARef.current.activeSessionId && currentQARef.current.activeSessionId !== mySessionId) return false;
125
+ return true;
126
+ };
116
127
  if (response.ok) {
117
- _context2.next = 15;
128
+ _context2.next = 16;
118
129
  break;
119
130
  }
120
- _context2.prev = 3;
121
- _context2.next = 6;
131
+ _context2.prev = 4;
132
+ _context2.next = 7;
122
133
  return response.json();
123
- case 6:
134
+ case 7:
124
135
  data = _context2.sent;
125
136
  res = agentScopeRuntimeResponseBuilder.handle({
126
137
  object: 'message',
@@ -132,63 +143,79 @@ export default function useChatRequest(options) {
132
143
  code: String(response.status),
133
144
  message: JSON.stringify(data)
134
145
  });
135
- currentQARef.current.response.cards = [{
136
- code: 'AgentScopeRuntimeResponseCard',
137
- data: res
138
- }];
139
- _context2.next = 13;
146
+ if (isStillActive() && currentQARef.current.response) {
147
+ currentQARef.current.response.cards = [{
148
+ code: 'AgentScopeRuntimeResponseCard',
149
+ data: res
150
+ }];
151
+ }
152
+ _context2.next = 14;
140
153
  break;
141
- case 11:
142
- _context2.prev = 11;
143
- _context2.t0 = _context2["catch"](3);
144
- case 13:
145
- onFinish();
154
+ case 12:
155
+ _context2.prev = 12;
156
+ _context2.t0 = _context2["catch"](4);
157
+ case 14:
158
+ if (isStillActive()) onFinish();
146
159
  return _context2.abrupt("return");
147
- case 15:
160
+ case 16:
148
161
  abortSignal = (_currentQARef$current = currentQARef.current.abortController) === null || _currentQARef$current === void 0 ? void 0 : _currentQARef$current.signal;
149
- _context2.prev = 16;
162
+ _context2.prev = 17;
150
163
  _iteratorAbruptCompletion2 = false;
151
164
  _didIteratorError2 = false;
152
- _context2.prev = 19;
165
+ _context2.prev = 20;
153
166
  _iterator2 = _asyncIterator(Stream({
154
167
  readableStream: response.body,
155
168
  signal: abortSignal
156
169
  }));
157
- case 21:
158
- _context2.next = 23;
170
+ case 22:
171
+ _context2.next = 24;
159
172
  return _iterator2.next();
160
- case 23:
173
+ case 24:
161
174
  if (!(_iteratorAbruptCompletion2 = !(_step2 = _context2.sent).done)) {
162
- _context2.next = 40;
175
+ _context2.next = 43;
163
176
  break;
164
177
  }
165
178
  chunk = _step2.value;
179
+ if (isStillActive()) {
180
+ _context2.next = 28;
181
+ break;
182
+ }
183
+ return _context2.abrupt("break", 43);
184
+ case 28:
166
185
  if (!(((_currentQARef$current2 = currentQARef.current.response) === null || _currentQARef$current2 === void 0 ? void 0 : _currentQARef$current2.msgStatus) === 'interrupted')) {
167
- _context2.next = 31;
186
+ _context2.next = 32;
168
187
  break;
169
188
  }
170
189
  (_currentQARef$current3 = currentQARef.current.abortController) === null || _currentQARef$current3 === void 0 || _currentQARef$current3.abort();
171
- if (currentApiOptions.cancel) {
172
- currentApiOptions.cancel({
173
- session_id: getCurrentSessionId()
174
- });
190
+ // Cancel was already sent by handleCancel; don't repeat it here.
191
+
192
+ if (isStillActive() && currentQARef.current.response) {
193
+ currentQARef.current.response.cards = [{
194
+ code: 'AgentScopeRuntimeResponseCard',
195
+ data: agentScopeRuntimeResponseBuilder.cancel()
196
+ }];
197
+ updateMessage(currentQARef.current.response);
175
198
  }
176
- currentQARef.current.response.cards = [{
177
- code: 'AgentScopeRuntimeResponseCard',
178
- data: agentScopeRuntimeResponseBuilder.cancel()
179
- }];
180
- updateMessage(currentQARef.current.response);
181
- return _context2.abrupt("break", 40);
182
- case 31:
199
+ return _context2.abrupt("break", 43);
200
+ case 32:
183
201
  responseParser = apiOptionsRef.current.responseParser || JSON.parse;
184
202
  chunkData = responseParser(chunk.data);
185
203
  _res = agentScopeRuntimeResponseBuilder.handle(chunkData);
186
- if (!(_res.status !== AgentScopeRuntimeRunStatus.Failed && !((_res$output = _res.output) !== null && _res$output !== void 0 && (_res$output = _res$output[0]) !== null && _res$output !== void 0 && (_res$output = _res$output.content) !== null && _res$output !== void 0 && _res$output.length))) {
187
- _context2.next = 36;
204
+ if (!(_res.status !== AgentScopeRuntimeRunStatus.Failed && !((_res$output = _res.output) !== null && _res$output !== void 0 && _res$output.some(function (msg) {
205
+ var _msg$content;
206
+ return (_msg$content = msg.content) === null || _msg$content === void 0 ? void 0 : _msg$content.length;
207
+ })))) {
208
+ _context2.next = 37;
209
+ break;
210
+ }
211
+ return _context2.abrupt("continue", 40);
212
+ case 37:
213
+ if (isStillActive()) {
214
+ _context2.next = 39;
188
215
  break;
189
216
  }
190
- return _context2.abrupt("continue", 37);
191
- case 36:
217
+ return _context2.abrupt("break", 43);
218
+ case 39:
192
219
  if (currentQARef.current.response) {
193
220
  currentQARef.current.response.cards = [{
194
221
  code: 'AgentScopeRuntimeResponseCard',
@@ -200,95 +227,101 @@ export default function useChatRequest(options) {
200
227
  updateMessage(currentQARef.current.response);
201
228
  }
202
229
  }
203
- case 37:
230
+ case 40:
204
231
  _iteratorAbruptCompletion2 = false;
205
- _context2.next = 21;
232
+ _context2.next = 22;
206
233
  break;
207
- case 40:
208
- _context2.next = 46;
234
+ case 43:
235
+ _context2.next = 49;
209
236
  break;
210
- case 42:
211
- _context2.prev = 42;
212
- _context2.t1 = _context2["catch"](19);
237
+ case 45:
238
+ _context2.prev = 45;
239
+ _context2.t1 = _context2["catch"](20);
213
240
  _didIteratorError2 = true;
214
241
  _iteratorError2 = _context2.t1;
215
- case 46:
216
- _context2.prev = 46;
217
- _context2.prev = 47;
242
+ case 49:
243
+ _context2.prev = 49;
244
+ _context2.prev = 50;
218
245
  if (!(_iteratorAbruptCompletion2 && _iterator2.return != null)) {
219
- _context2.next = 51;
246
+ _context2.next = 54;
220
247
  break;
221
248
  }
222
- _context2.next = 51;
249
+ _context2.next = 54;
223
250
  return _iterator2.return();
224
- case 51:
225
- _context2.prev = 51;
251
+ case 54:
252
+ _context2.prev = 54;
226
253
  if (!_didIteratorError2) {
227
- _context2.next = 54;
254
+ _context2.next = 57;
228
255
  break;
229
256
  }
230
257
  throw _iteratorError2;
231
- case 54:
232
- return _context2.finish(51);
233
- case 55:
234
- return _context2.finish(46);
235
- case 56:
236
- _context2.next = 61;
237
- break;
258
+ case 57:
259
+ return _context2.finish(54);
238
260
  case 58:
239
- _context2.prev = 58;
240
- _context2.t2 = _context2["catch"](16);
261
+ return _context2.finish(49);
262
+ case 59:
263
+ _context2.next = 66;
264
+ break;
265
+ case 61:
266
+ _context2.prev = 61;
267
+ _context2.t2 = _context2["catch"](17);
268
+ if (isStillActive()) {
269
+ _context2.next = 65;
270
+ break;
271
+ }
272
+ return _context2.abrupt("return");
273
+ case 65:
241
274
  if (((_currentQARef$current4 = currentQARef.current.response) === null || _currentQARef$current4 === void 0 ? void 0 : _currentQARef$current4.msgStatus) === 'interrupted') {
242
- if (currentApiOptions.cancel) {
243
- currentApiOptions.cancel({
244
- session_id: getCurrentSessionId()
245
- });
275
+ // Cancel was already sent by handleCancel; don't repeat it here.
276
+ if (currentQARef.current.response) {
277
+ currentQARef.current.response.cards = [{
278
+ code: 'AgentScopeRuntimeResponseCard',
279
+ data: agentScopeRuntimeResponseBuilder.cancel()
280
+ }];
281
+ updateMessage(currentQARef.current.response);
246
282
  }
247
- currentQARef.current.response.cards = [{
248
- code: 'AgentScopeRuntimeResponseCard',
249
- data: agentScopeRuntimeResponseBuilder.cancel()
250
- }];
251
- updateMessage(currentQARef.current.response);
252
283
  } else {
253
284
  console.error(_context2.t2);
254
285
  }
255
- case 61:
286
+ case 66:
256
287
  case "end":
257
288
  return _context2.stop();
258
289
  }
259
- }, _callee2, null, [[3, 11], [16, 58], [19, 42, 46, 56], [47,, 51, 55]]);
290
+ }, _callee2, null, [[4, 12], [17, 61], [20, 45, 49, 59], [50,, 54, 58]]);
260
291
  }));
261
- return function (_x2) {
292
+ return function (_x2, _x3, _x4) {
262
293
  return _ref2.apply(this, arguments);
263
294
  };
264
295
  }(), [getCurrentSessionId, currentQARef, updateMessage, onFinish]);
265
296
  var request = useCallback( /*#__PURE__*/function () {
266
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(historyMessages, biz_params) {
267
- var _currentQARef$current5;
268
- var currentApiOptions, _currentApiOptions$en, enableHistoryMessages, abortSignal, response;
297
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(historyMessages, biz_params, myRequestId) {
298
+ var _currentQARef$current5, _currentQARef$current6;
299
+ var currentApiOptions, _currentApiOptions$en, enableHistoryMessages, abortSignal, requestId, sessionId, response;
269
300
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
270
301
  while (1) switch (_context3.prev = _context3.next) {
271
302
  case 0:
272
303
  currentApiOptions = apiOptionsRef.current;
273
304
  _currentApiOptions$en = currentApiOptions.enableHistoryMessages, enableHistoryMessages = _currentApiOptions$en === void 0 ? false : _currentApiOptions$en;
274
305
  abortSignal = (_currentQARef$current5 = currentQARef.current.abortController) === null || _currentQARef$current5 === void 0 ? void 0 : _currentQARef$current5.signal;
275
- _context3.prev = 3;
306
+ requestId = myRequestId !== null && myRequestId !== void 0 ? myRequestId : currentQARef.current.activeRequestId;
307
+ sessionId = (_currentQARef$current6 = currentQARef.current.activeSessionId) !== null && _currentQARef$current6 !== void 0 ? _currentQARef$current6 : getCurrentSessionId();
308
+ _context3.prev = 5;
276
309
  if (!currentApiOptions.fetch) {
277
- _context3.next = 10;
310
+ _context3.next = 12;
278
311
  break;
279
312
  }
280
- _context3.next = 7;
313
+ _context3.next = 9;
281
314
  return currentApiOptions.fetch({
282
315
  input: historyMessages,
283
316
  biz_params: biz_params,
284
317
  signal: abortSignal
285
318
  });
286
- case 7:
319
+ case 9:
287
320
  _context3.t0 = _context3.sent;
288
- _context3.next = 13;
321
+ _context3.next = 15;
289
322
  break;
290
- case 10:
291
- _context3.next = 12;
323
+ case 12:
324
+ _context3.next = 14;
292
325
  return fetch(currentApiOptions.baseURL, {
293
326
  method: 'POST',
294
327
  headers: {
@@ -303,36 +336,36 @@ export default function useChatRequest(options) {
303
336
  }),
304
337
  signal: abortSignal
305
338
  });
306
- case 12:
339
+ case 14:
307
340
  _context3.t0 = _context3.sent;
308
- case 13:
341
+ case 15:
309
342
  response = _context3.t0;
310
- _context3.next = 18;
343
+ _context3.next = 20;
311
344
  break;
312
- case 16:
313
- _context3.prev = 16;
314
- _context3.t1 = _context3["catch"](3);
315
345
  case 18:
346
+ _context3.prev = 18;
347
+ _context3.t1 = _context3["catch"](5);
348
+ case 20:
316
349
  if (!(response && response.body)) {
317
- _context3.next = 21;
350
+ _context3.next = 23;
318
351
  break;
319
352
  }
320
- _context3.next = 21;
321
- return processSSEResponse(response);
322
- case 21:
353
+ _context3.next = 23;
354
+ return processSSEResponse(response, requestId, sessionId);
355
+ case 23:
323
356
  case "end":
324
357
  return _context3.stop();
325
358
  }
326
- }, _callee3, null, [[3, 16]]);
359
+ }, _callee3, null, [[5, 18]]);
327
360
  }));
328
- return function (_x3, _x4) {
361
+ return function (_x5, _x6, _x7) {
329
362
  return _ref3.apply(this, arguments);
330
363
  };
331
364
  }(), [getCurrentSessionId, currentQARef, processSSEResponse]);
332
365
  var reconnect = useCallback( /*#__PURE__*/function () {
333
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(sessionId) {
334
- var _currentQARef$current6;
335
- var currentApiOptions, abortSignal, response;
366
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(sessionId, myRequestId) {
367
+ var _currentQARef$current7;
368
+ var currentApiOptions, abortSignal, requestId, response;
336
369
  return _regeneratorRuntime().wrap(function _callee4$(_context4) {
337
370
  while (1) switch (_context4.prev = _context4.next) {
338
371
  case 0:
@@ -343,34 +376,35 @@ export default function useChatRequest(options) {
343
376
  }
344
377
  return _context4.abrupt("return");
345
378
  case 3:
346
- abortSignal = (_currentQARef$current6 = currentQARef.current.abortController) === null || _currentQARef$current6 === void 0 ? void 0 : _currentQARef$current6.signal;
347
- _context4.prev = 4;
348
- _context4.next = 7;
379
+ abortSignal = (_currentQARef$current7 = currentQARef.current.abortController) === null || _currentQARef$current7 === void 0 ? void 0 : _currentQARef$current7.signal;
380
+ requestId = myRequestId !== null && myRequestId !== void 0 ? myRequestId : currentQARef.current.activeRequestId;
381
+ _context4.prev = 5;
382
+ _context4.next = 8;
349
383
  return currentApiOptions.reconnect({
350
384
  session_id: sessionId,
351
385
  signal: abortSignal
352
386
  });
353
- case 7:
387
+ case 8:
354
388
  response = _context4.sent;
355
- _context4.next = 12;
389
+ _context4.next = 13;
356
390
  break;
357
- case 10:
358
- _context4.prev = 10;
359
- _context4.t0 = _context4["catch"](4);
360
- case 12:
391
+ case 11:
392
+ _context4.prev = 11;
393
+ _context4.t0 = _context4["catch"](5);
394
+ case 13:
361
395
  if (!(response && response.body)) {
362
- _context4.next = 15;
396
+ _context4.next = 16;
363
397
  break;
364
398
  }
365
- _context4.next = 15;
366
- return processSSEResponse(response);
367
- case 15:
399
+ _context4.next = 16;
400
+ return processSSEResponse(response, requestId, sessionId);
401
+ case 16:
368
402
  case "end":
369
403
  return _context4.stop();
370
404
  }
371
- }, _callee4, null, [[4, 10]]);
405
+ }, _callee4, null, [[5, 11]]);
372
406
  }));
373
- return function (_x5) {
407
+ return function (_x8, _x9) {
374
408
  return _ref4.apply(this, arguments);
375
409
  };
376
410
  }(), [currentQARef, processSSEResponse]);
@@ -58,6 +58,15 @@ export interface IAgentScopeRuntimeWebUIAPIOptions {
58
58
  * @descriptionEn Custom media URL transformer (e.g. sign URL, replace CDN domain)
59
59
  */
60
60
  replaceMediaURL?: (url: string) => string;
61
+ /**
62
+ * @description 自定义文件点击事件(桌面端可通过此钩子调用原生 API 打开文件链接),不传则默认 window.open
63
+ * @descriptionEn Custom file click handler (desktop apps can use native APIs to open file URLs), defaults to window.open
64
+ */
65
+ onFileCardClick?: (file: {
66
+ url?: string;
67
+ name?: string;
68
+ size?: number;
69
+ }) => void;
61
70
  }
62
71
  /**
63
72
  * @description 主题配置选项
@@ -411,6 +420,10 @@ export interface IAgentScopeRuntimeWebUIRequestActionsOptions {
411
420
  */
412
421
  list?: {
413
422
  icon?: React.ReactElement;
423
+ children?: React.ReactElement;
424
+ render?: ({ data }: {
425
+ data: IAgentScopeRuntimeRequest;
426
+ }) => React.ReactElement;
414
427
  onClick?: ({ data }: {
415
428
  data: IAgentScopeRuntimeRequest;
416
429
  }) => void;
@@ -423,6 +436,7 @@ export interface IAgentScopeRuntimeWebUIActionsOptions {
423
436
  */
424
437
  list: {
425
438
  icon?: React.ReactElement;
439
+ children?: React.ReactElement;
426
440
  render?: ({ data, }: {
427
441
  data: IAgentScopeRuntimeResponse;
428
442
  }) => React.ReactElement;
@@ -436,6 +450,7 @@ export interface IAgentScopeRuntimeWebUIActionsOptions {
436
450
  */
437
451
  right?: false | {
438
452
  icon?: React.ReactElement;
453
+ children?: React.ReactElement;
439
454
  render?: ({ data }: {
440
455
  data: IAgentScopeRuntimeResponse;
441
456
  }) => React.ReactElement;
@@ -45,7 +45,11 @@ export default function Files(props) {
45
45
  }), fileInfo.url && /*#__PURE__*/_jsx("div", {
46
46
  className: "".concat(prefixCls, "-download"),
47
47
  onClick: function onClick() {
48
- window.open(fileInfo.url, '_blank');
48
+ if (props.onClick) {
49
+ props.onClick(fileInfo);
50
+ } else {
51
+ window.open(fileInfo.url, '_blank');
52
+ }
49
53
  },
50
54
  children: /*#__PURE__*/_jsx(SparkDownloadLine, {})
51
55
  })]
@@ -110,6 +110,7 @@ export default /*#__PURE__*/memo(function (props) {
110
110
  renderer: {
111
111
  html: function html(token) {
112
112
  var text = token.text || token.raw || '';
113
+ if (/^<br\s*\/?>$/i.test(text.trim())) return '<br />';
113
114
  return text.replace(/</g, '&lt;').replace(/>/g, '&gt;');
114
115
  }
115
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentscope-ai/chat",
3
- "version": "1.1.65",
3
+ "version": "1.1.67",
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": [
@@ -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