@agentscope-ai/chat 1.1.38 → 1.1.39-beta.1764397187835

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.
@@ -35,14 +35,17 @@ export default function useChatRequest(options: UseChatRequestOptions) {
35
35
  const currentApiOptions = apiOptionsRef.current;
36
36
  let response
37
37
  try {
38
- response = await fetch(currentApiOptions.baseURL, {
38
+ const input = historyMessages
39
+ response = await currentApiOptions.fetch({
40
+ input
41
+ }) || currentApiOptions.fetch(currentApiOptions.baseURL, {
39
42
  method: 'POST',
40
43
  headers: {
41
44
  'Content-Type': 'application/json',
42
45
  'Authorization': `Bearer ${currentApiOptions.token || ''}`,
43
46
  },
44
47
  body: JSON.stringify({
45
- input: historyMessages,
48
+ input: input,
46
49
  session_id: getCurrentSessionId(),
47
50
  stream: true,
48
51
  }),
@@ -52,8 +55,6 @@ export default function useChatRequest(options: UseChatRequestOptions) {
52
55
  }
53
56
 
54
57
 
55
-
56
-
57
58
  if (response && response.body && response.ok) {
58
59
  const agentScopeRuntimeResponseBuilder = new AgentScopeRuntimeResponseBuilder({
59
60
  id: '',
@@ -16,6 +16,7 @@ export interface IAgentScopeRuntimeWebUIAPIOptions {
16
16
  * @descriptionEn Authorization Token
17
17
  */
18
18
  token?: string;
19
+ fetch?: any;
19
20
  }
20
21
 
21
22
  /**
@@ -28,36 +28,46 @@ export default function useChatRequest(options) {
28
28
  }, [apiOptions]);
29
29
  var request = useCallback( /*#__PURE__*/function () {
30
30
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(historyMessages) {
31
- var currentApiOptions, response, agentScopeRuntimeResponseBuilder, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, chunk, _currentQARef$current, _res$output, _currentQARef$current2, chunkData, res;
31
+ var currentApiOptions, response, input, agentScopeRuntimeResponseBuilder, _iteratorAbruptCompletion, _didIteratorError, _iteratorError, _iterator, _step, chunk, _currentQARef$current, _res$output, _currentQARef$current2, chunkData, res;
32
32
  return _regeneratorRuntime().wrap(function _callee$(_context) {
33
33
  while (1) switch (_context.prev = _context.next) {
34
34
  case 0:
35
35
  // 使用 ref.current 获取最新的 apiOptions
36
36
  currentApiOptions = apiOptionsRef.current;
37
37
  _context.prev = 1;
38
- _context.next = 4;
39
- return fetch(currentApiOptions.baseURL, {
38
+ input = historyMessages;
39
+ _context.next = 5;
40
+ return currentApiOptions.fetch({
41
+ input: input
42
+ });
43
+ case 5:
44
+ _context.t0 = _context.sent;
45
+ if (_context.t0) {
46
+ _context.next = 8;
47
+ break;
48
+ }
49
+ _context.t0 = currentApiOptions.fetch(currentApiOptions.baseURL, {
40
50
  method: 'POST',
41
51
  headers: {
42
52
  'Content-Type': 'application/json',
43
53
  'Authorization': "Bearer ".concat(currentApiOptions.token || '')
44
54
  },
45
55
  body: JSON.stringify({
46
- input: historyMessages,
56
+ input: input,
47
57
  session_id: getCurrentSessionId(),
48
58
  stream: true
49
59
  })
50
60
  });
51
- case 4:
52
- response = _context.sent;
53
- _context.next = 9;
61
+ case 8:
62
+ response = _context.t0;
63
+ _context.next = 13;
54
64
  break;
55
- case 7:
56
- _context.prev = 7;
57
- _context.t0 = _context["catch"](1);
58
- case 9:
65
+ case 11:
66
+ _context.prev = 11;
67
+ _context.t1 = _context["catch"](1);
68
+ case 13:
59
69
  if (!(response && response.body && response.ok)) {
60
- _context.next = 54;
70
+ _context.next = 58;
61
71
  break;
62
72
  }
63
73
  agentScopeRuntimeResponseBuilder = new AgentScopeRuntimeResponseBuilder({
@@ -65,24 +75,24 @@ export default function useChatRequest(options) {
65
75
  status: AgentScopeRuntimeRunStatus.Created,
66
76
  created_at: 0
67
77
  });
68
- _context.prev = 11;
78
+ _context.prev = 15;
69
79
  _iteratorAbruptCompletion = false;
70
80
  _didIteratorError = false;
71
- _context.prev = 14;
81
+ _context.prev = 18;
72
82
  _iterator = _asyncIterator(Stream({
73
83
  readableStream: response.body
74
84
  }));
75
- case 16:
76
- _context.next = 18;
85
+ case 20:
86
+ _context.next = 22;
77
87
  return _iterator.next();
78
- case 18:
88
+ case 22:
79
89
  if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
80
- _context.next = 33;
90
+ _context.next = 37;
81
91
  break;
82
92
  }
83
93
  chunk = _step.value;
84
94
  if (!(((_currentQARef$current = currentQARef.current.response) === null || _currentQARef$current === void 0 ? void 0 : _currentQARef$current.msgStatus) === 'interrupted')) {
85
- _context.next = 25;
95
+ _context.next = 29;
86
96
  break;
87
97
  }
88
98
  (_currentQARef$current2 = currentQARef.current.abortController) === null || _currentQARef$current2 === void 0 || _currentQARef$current2.abort();
@@ -91,16 +101,16 @@ export default function useChatRequest(options) {
91
101
  data: agentScopeRuntimeResponseBuilder.cancel()
92
102
  }];
93
103
  updateMessage(currentQARef.current.response);
94
- return _context.abrupt("break", 33);
95
- case 25:
104
+ return _context.abrupt("break", 37);
105
+ case 29:
96
106
  chunkData = JSON.parse(chunk.data);
97
107
  res = agentScopeRuntimeResponseBuilder.handle(chunkData); // 跳过空内容
98
108
  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))) {
99
- _context.next = 29;
109
+ _context.next = 33;
100
110
  break;
101
111
  }
102
- return _context.abrupt("continue", 30);
103
- case 29:
112
+ return _context.abrupt("continue", 34);
113
+ case 33:
104
114
  if (currentQARef.current.response) {
105
115
  currentQARef.current.response.cards = [{
106
116
  code: 'AgentScopeRuntimeResponseCard',
@@ -112,50 +122,50 @@ export default function useChatRequest(options) {
112
122
  updateMessage(currentQARef.current.response);
113
123
  }
114
124
  }
115
- case 30:
125
+ case 34:
116
126
  _iteratorAbruptCompletion = false;
117
- _context.next = 16;
127
+ _context.next = 20;
118
128
  break;
119
- case 33:
120
- _context.next = 39;
129
+ case 37:
130
+ _context.next = 43;
121
131
  break;
122
- case 35:
123
- _context.prev = 35;
124
- _context.t1 = _context["catch"](14);
125
- _didIteratorError = true;
126
- _iteratorError = _context.t1;
127
132
  case 39:
128
133
  _context.prev = 39;
129
- _context.prev = 40;
134
+ _context.t2 = _context["catch"](18);
135
+ _didIteratorError = true;
136
+ _iteratorError = _context.t2;
137
+ case 43:
138
+ _context.prev = 43;
139
+ _context.prev = 44;
130
140
  if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
131
- _context.next = 44;
141
+ _context.next = 48;
132
142
  break;
133
143
  }
134
- _context.next = 44;
144
+ _context.next = 48;
135
145
  return _iterator.return();
136
- case 44:
137
- _context.prev = 44;
146
+ case 48:
147
+ _context.prev = 48;
138
148
  if (!_didIteratorError) {
139
- _context.next = 47;
149
+ _context.next = 51;
140
150
  break;
141
151
  }
142
152
  throw _iteratorError;
143
- case 47:
144
- return _context.finish(44);
145
- case 48:
146
- return _context.finish(39);
147
- case 49:
148
- _context.next = 54;
149
- break;
150
153
  case 51:
151
- _context.prev = 51;
152
- _context.t2 = _context["catch"](11);
153
- console.error(_context.t2);
154
- case 54:
154
+ return _context.finish(48);
155
+ case 52:
156
+ return _context.finish(43);
157
+ case 53:
158
+ _context.next = 58;
159
+ break;
160
+ case 55:
161
+ _context.prev = 55;
162
+ _context.t3 = _context["catch"](15);
163
+ console.error(_context.t3);
164
+ case 58:
155
165
  case "end":
156
166
  return _context.stop();
157
167
  }
158
- }, _callee, null, [[1, 7], [11, 51], [14, 35, 39, 49], [40,, 44, 48]]);
168
+ }, _callee, null, [[1, 11], [15, 55], [18, 39, 43, 53], [44,, 48, 52]]);
159
169
  }));
160
170
  return function (_x) {
161
171
  return _ref.apply(this, arguments);
@@ -16,6 +16,7 @@ export interface IAgentScopeRuntimeWebUIAPIOptions {
16
16
  * @descriptionEn Authorization Token
17
17
  */
18
18
  token?: string;
19
+ fetch?: any;
19
20
  }
20
21
  /**
21
22
  * @description 主题配置选项
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentscope-ai/chat",
3
- "version": "1.1.38",
3
+ "version": "1.1.39-beta.1764397187835",
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": [