@agentscope-ai/chat 1.1.38 → 1.1.39-beta.1764397951146
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 +3 -1
- package/components/AgentScopeRuntimeWebUI/core/types/IChatAnywhere.ts +1 -0
- package/components/AgentScopeRuntimeWebUI/starter/index.tsx +7 -0
- package/lib/AgentScopeRuntimeWebUI/core/Chat/hooks/useChatRequest.js +64 -49
- package/lib/AgentScopeRuntimeWebUI/core/types/IChatAnywhere.d.ts +1 -0
- package/lib/AgentScopeRuntimeWebUI/starter/index.js +5 -0
- package/package.json +1 -1
|
@@ -35,7 +35,9 @@ export default function useChatRequest(options: UseChatRequestOptions) {
|
|
|
35
35
|
const currentApiOptions = apiOptionsRef.current;
|
|
36
36
|
let response
|
|
37
37
|
try {
|
|
38
|
-
response = await fetch(
|
|
38
|
+
response = currentApiOptions.fetch ? await currentApiOptions.fetch({
|
|
39
|
+
input: historyMessages,
|
|
40
|
+
}) : await fetch(currentApiOptions.baseURL, {
|
|
39
41
|
method: 'POST',
|
|
40
42
|
headers: {
|
|
41
43
|
'Content-Type': 'application/json',
|
|
@@ -46,9 +46,16 @@ export default function () {
|
|
|
46
46
|
...optionsConfig.theme,
|
|
47
47
|
rightHeader,
|
|
48
48
|
},
|
|
49
|
+
api: {
|
|
50
|
+
...optionsConfig.api,
|
|
51
|
+
fetch: (input: any) => {
|
|
52
|
+
debugger;
|
|
53
|
+
},
|
|
54
|
+
},
|
|
49
55
|
};
|
|
50
56
|
}, [optionsConfig]);
|
|
51
57
|
|
|
58
|
+
|
|
52
59
|
return <div style={{ height: '100dvh' }}>
|
|
53
60
|
<AgentScopeRuntimeWebUI
|
|
54
61
|
options={options}
|
|
@@ -35,7 +35,20 @@ export default function useChatRequest(options) {
|
|
|
35
35
|
// 使用 ref.current 获取最新的 apiOptions
|
|
36
36
|
currentApiOptions = apiOptionsRef.current;
|
|
37
37
|
_context.prev = 1;
|
|
38
|
-
|
|
38
|
+
if (!currentApiOptions.fetch) {
|
|
39
|
+
_context.next = 8;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
_context.next = 5;
|
|
43
|
+
return currentApiOptions.fetch({
|
|
44
|
+
input: historyMessages
|
|
45
|
+
});
|
|
46
|
+
case 5:
|
|
47
|
+
_context.t0 = _context.sent;
|
|
48
|
+
_context.next = 11;
|
|
49
|
+
break;
|
|
50
|
+
case 8:
|
|
51
|
+
_context.next = 10;
|
|
39
52
|
return fetch(currentApiOptions.baseURL, {
|
|
40
53
|
method: 'POST',
|
|
41
54
|
headers: {
|
|
@@ -48,16 +61,18 @@ export default function useChatRequest(options) {
|
|
|
48
61
|
stream: true
|
|
49
62
|
})
|
|
50
63
|
});
|
|
51
|
-
case
|
|
52
|
-
|
|
53
|
-
|
|
64
|
+
case 10:
|
|
65
|
+
_context.t0 = _context.sent;
|
|
66
|
+
case 11:
|
|
67
|
+
response = _context.t0;
|
|
68
|
+
_context.next = 16;
|
|
54
69
|
break;
|
|
55
|
-
case
|
|
56
|
-
_context.prev =
|
|
57
|
-
_context.
|
|
58
|
-
case
|
|
70
|
+
case 14:
|
|
71
|
+
_context.prev = 14;
|
|
72
|
+
_context.t1 = _context["catch"](1);
|
|
73
|
+
case 16:
|
|
59
74
|
if (!(response && response.body && response.ok)) {
|
|
60
|
-
_context.next =
|
|
75
|
+
_context.next = 61;
|
|
61
76
|
break;
|
|
62
77
|
}
|
|
63
78
|
agentScopeRuntimeResponseBuilder = new AgentScopeRuntimeResponseBuilder({
|
|
@@ -65,24 +80,24 @@ export default function useChatRequest(options) {
|
|
|
65
80
|
status: AgentScopeRuntimeRunStatus.Created,
|
|
66
81
|
created_at: 0
|
|
67
82
|
});
|
|
68
|
-
_context.prev =
|
|
83
|
+
_context.prev = 18;
|
|
69
84
|
_iteratorAbruptCompletion = false;
|
|
70
85
|
_didIteratorError = false;
|
|
71
|
-
_context.prev =
|
|
86
|
+
_context.prev = 21;
|
|
72
87
|
_iterator = _asyncIterator(Stream({
|
|
73
88
|
readableStream: response.body
|
|
74
89
|
}));
|
|
75
|
-
case
|
|
76
|
-
_context.next =
|
|
90
|
+
case 23:
|
|
91
|
+
_context.next = 25;
|
|
77
92
|
return _iterator.next();
|
|
78
|
-
case
|
|
93
|
+
case 25:
|
|
79
94
|
if (!(_iteratorAbruptCompletion = !(_step = _context.sent).done)) {
|
|
80
|
-
_context.next =
|
|
95
|
+
_context.next = 40;
|
|
81
96
|
break;
|
|
82
97
|
}
|
|
83
98
|
chunk = _step.value;
|
|
84
99
|
if (!(((_currentQARef$current = currentQARef.current.response) === null || _currentQARef$current === void 0 ? void 0 : _currentQARef$current.msgStatus) === 'interrupted')) {
|
|
85
|
-
_context.next =
|
|
100
|
+
_context.next = 32;
|
|
86
101
|
break;
|
|
87
102
|
}
|
|
88
103
|
(_currentQARef$current2 = currentQARef.current.abortController) === null || _currentQARef$current2 === void 0 || _currentQARef$current2.abort();
|
|
@@ -91,16 +106,16 @@ export default function useChatRequest(options) {
|
|
|
91
106
|
data: agentScopeRuntimeResponseBuilder.cancel()
|
|
92
107
|
}];
|
|
93
108
|
updateMessage(currentQARef.current.response);
|
|
94
|
-
return _context.abrupt("break",
|
|
95
|
-
case
|
|
109
|
+
return _context.abrupt("break", 40);
|
|
110
|
+
case 32:
|
|
96
111
|
chunkData = JSON.parse(chunk.data);
|
|
97
112
|
res = agentScopeRuntimeResponseBuilder.handle(chunkData); // 跳过空内容
|
|
98
113
|
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 =
|
|
114
|
+
_context.next = 36;
|
|
100
115
|
break;
|
|
101
116
|
}
|
|
102
|
-
return _context.abrupt("continue",
|
|
103
|
-
case
|
|
117
|
+
return _context.abrupt("continue", 37);
|
|
118
|
+
case 36:
|
|
104
119
|
if (currentQARef.current.response) {
|
|
105
120
|
currentQARef.current.response.cards = [{
|
|
106
121
|
code: 'AgentScopeRuntimeResponseCard',
|
|
@@ -112,50 +127,50 @@ export default function useChatRequest(options) {
|
|
|
112
127
|
updateMessage(currentQARef.current.response);
|
|
113
128
|
}
|
|
114
129
|
}
|
|
115
|
-
case
|
|
130
|
+
case 37:
|
|
116
131
|
_iteratorAbruptCompletion = false;
|
|
117
|
-
_context.next =
|
|
132
|
+
_context.next = 23;
|
|
118
133
|
break;
|
|
119
|
-
case
|
|
120
|
-
_context.next =
|
|
134
|
+
case 40:
|
|
135
|
+
_context.next = 46;
|
|
121
136
|
break;
|
|
122
|
-
case
|
|
123
|
-
_context.prev =
|
|
124
|
-
_context.
|
|
137
|
+
case 42:
|
|
138
|
+
_context.prev = 42;
|
|
139
|
+
_context.t2 = _context["catch"](21);
|
|
125
140
|
_didIteratorError = true;
|
|
126
|
-
_iteratorError = _context.
|
|
127
|
-
case
|
|
128
|
-
_context.prev =
|
|
129
|
-
_context.prev =
|
|
141
|
+
_iteratorError = _context.t2;
|
|
142
|
+
case 46:
|
|
143
|
+
_context.prev = 46;
|
|
144
|
+
_context.prev = 47;
|
|
130
145
|
if (!(_iteratorAbruptCompletion && _iterator.return != null)) {
|
|
131
|
-
_context.next =
|
|
146
|
+
_context.next = 51;
|
|
132
147
|
break;
|
|
133
148
|
}
|
|
134
|
-
_context.next =
|
|
149
|
+
_context.next = 51;
|
|
135
150
|
return _iterator.return();
|
|
136
|
-
case
|
|
137
|
-
_context.prev =
|
|
151
|
+
case 51:
|
|
152
|
+
_context.prev = 51;
|
|
138
153
|
if (!_didIteratorError) {
|
|
139
|
-
_context.next =
|
|
154
|
+
_context.next = 54;
|
|
140
155
|
break;
|
|
141
156
|
}
|
|
142
157
|
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
|
-
case 51:
|
|
151
|
-
_context.prev = 51;
|
|
152
|
-
_context.t2 = _context["catch"](11);
|
|
153
|
-
console.error(_context.t2);
|
|
154
158
|
case 54:
|
|
159
|
+
return _context.finish(51);
|
|
160
|
+
case 55:
|
|
161
|
+
return _context.finish(46);
|
|
162
|
+
case 56:
|
|
163
|
+
_context.next = 61;
|
|
164
|
+
break;
|
|
165
|
+
case 58:
|
|
166
|
+
_context.prev = 58;
|
|
167
|
+
_context.t3 = _context["catch"](18);
|
|
168
|
+
console.error(_context.t3);
|
|
169
|
+
case 61:
|
|
155
170
|
case "end":
|
|
156
171
|
return _context.stop();
|
|
157
172
|
}
|
|
158
|
-
}, _callee, null, [[1,
|
|
173
|
+
}, _callee, null, [[1, 14], [18, 58], [21, 42, 46, 56], [47,, 51, 55]]);
|
|
159
174
|
}));
|
|
160
175
|
return function (_x) {
|
|
161
176
|
return _ref.apply(this, arguments);
|
|
@@ -56,6 +56,11 @@ export default function () {
|
|
|
56
56
|
}),
|
|
57
57
|
theme: _objectSpread(_objectSpread({}, optionsConfig.theme), {}, {
|
|
58
58
|
rightHeader: rightHeader
|
|
59
|
+
}),
|
|
60
|
+
api: _objectSpread(_objectSpread({}, optionsConfig.api), {}, {
|
|
61
|
+
fetch: function fetch(input) {
|
|
62
|
+
debugger;
|
|
63
|
+
}
|
|
59
64
|
})
|
|
60
65
|
});
|
|
61
66
|
}, [optionsConfig]);
|
package/package.json
CHANGED