@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.
- package/components/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatRequest.tsx +5 -4
- package/components/AgentScopeRuntimeWebUI/core/types/IChatAnywhere.ts +1 -0
- package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatRequest.js +61 -51
- package/lib/AgentScopeRuntimeWebUI/core/types/IChatAnywhere.d.ts +1 -0
- package/package.json +1 -1
|
@@ -35,14 +35,17 @@ export default function useChatRequest(options: UseChatRequestOptions) {
|
|
|
35
35
|
const currentApiOptions = apiOptionsRef.current;
|
|
36
36
|
let response
|
|
37
37
|
try {
|
|
38
|
-
|
|
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:
|
|
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: '',
|
|
@@ -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
|
-
|
|
39
|
-
|
|
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:
|
|
56
|
+
input: input,
|
|
47
57
|
session_id: getCurrentSessionId(),
|
|
48
58
|
stream: true
|
|
49
59
|
})
|
|
50
60
|
});
|
|
51
|
-
case
|
|
52
|
-
response = _context.
|
|
53
|
-
_context.next =
|
|
61
|
+
case 8:
|
|
62
|
+
response = _context.t0;
|
|
63
|
+
_context.next = 13;
|
|
54
64
|
break;
|
|
55
|
-
case
|
|
56
|
-
_context.prev =
|
|
57
|
-
_context.
|
|
58
|
-
case
|
|
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 =
|
|
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 =
|
|
78
|
+
_context.prev = 15;
|
|
69
79
|
_iteratorAbruptCompletion = false;
|
|
70
80
|
_didIteratorError = false;
|
|
71
|
-
_context.prev =
|
|
81
|
+
_context.prev = 18;
|
|
72
82
|
_iterator = _asyncIterator(Stream({
|
|
73
83
|
readableStream: response.body
|
|
74
84
|
}));
|
|
75
|
-
case
|
|
76
|
-
_context.next =
|
|
85
|
+
case 20:
|
|
86
|
+
_context.next = 22;
|
|
77
87
|
return _iterator.next();
|
|
78
|
-
case
|
|
88
|
+
case 22:
|
|
79
89
|
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
|
|
80
|
-
_context.next =
|
|
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 =
|
|
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",
|
|
95
|
-
case
|
|
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 =
|
|
109
|
+
_context.next = 33;
|
|
100
110
|
break;
|
|
101
111
|
}
|
|
102
|
-
return _context.abrupt("continue",
|
|
103
|
-
case
|
|
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
|
|
125
|
+
case 34:
|
|
116
126
|
_iteratorAbruptCompletion = false;
|
|
117
|
-
_context.next =
|
|
127
|
+
_context.next = 20;
|
|
118
128
|
break;
|
|
119
|
-
case
|
|
120
|
-
_context.next =
|
|
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.
|
|
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 =
|
|
141
|
+
_context.next = 48;
|
|
132
142
|
break;
|
|
133
143
|
}
|
|
134
|
-
_context.next =
|
|
144
|
+
_context.next = 48;
|
|
135
145
|
return _iterator.return();
|
|
136
|
-
case
|
|
137
|
-
_context.prev =
|
|
146
|
+
case 48:
|
|
147
|
+
_context.prev = 48;
|
|
138
148
|
if (!_didIteratorError) {
|
|
139
|
-
_context.next =
|
|
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.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
case
|
|
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,
|
|
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);
|
package/package.json
CHANGED