@wabot-dev/framework 0.1.0-beta.63 → 0.1.0-beta.65
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.
|
@@ -111,12 +111,56 @@ let MindsetOperator = class MindsetOperator {
|
|
|
111
111
|
if (!response) {
|
|
112
112
|
return 'success';
|
|
113
113
|
}
|
|
114
|
-
return
|
|
114
|
+
return await this.functionResponseToString(response);
|
|
115
115
|
}
|
|
116
116
|
catch (error) {
|
|
117
|
-
return
|
|
117
|
+
return await this.functionErrorToString(error);
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
+
async functionResponseToString(response) {
|
|
121
|
+
if (response instanceof Response) {
|
|
122
|
+
const contentType = response.headers.get('Content-Type') || '';
|
|
123
|
+
let body;
|
|
124
|
+
try {
|
|
125
|
+
body = contentType.includes('application/json')
|
|
126
|
+
? await response.json()
|
|
127
|
+
: await response.text();
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
body = { message: 'Unable to parse error body' };
|
|
131
|
+
}
|
|
132
|
+
return JSON.stringify({
|
|
133
|
+
httpCode: response.status,
|
|
134
|
+
body: typeof body === 'object' ? body : { message: body },
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
const type = typeof response;
|
|
138
|
+
if (type === 'string') {
|
|
139
|
+
return response;
|
|
140
|
+
}
|
|
141
|
+
else if (type === 'boolean' || type === 'number') {
|
|
142
|
+
return `${response}`;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
return JSON.stringify(response);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async functionErrorToString(error) {
|
|
149
|
+
if (error?.response && typeof error.response === 'object' && error.response.status) {
|
|
150
|
+
const { status, data } = error.response;
|
|
151
|
+
return JSON.stringify({
|
|
152
|
+
httpCode: status,
|
|
153
|
+
body: typeof data === 'object' ? data : { message: data?.toString?.() || 'Unknown error' },
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
if (error instanceof Response) {
|
|
157
|
+
return await this.functionResponseToString(error);
|
|
158
|
+
}
|
|
159
|
+
if (error?.message) {
|
|
160
|
+
return error.message;
|
|
161
|
+
}
|
|
162
|
+
return 'Unknown error occurred';
|
|
163
|
+
}
|
|
120
164
|
};
|
|
121
165
|
MindsetOperator = __decorate([
|
|
122
166
|
injectable(),
|
package/dist/src/index.d.ts
CHANGED
|
@@ -566,6 +566,8 @@ declare class MindsetOperator implements IMindset {
|
|
|
566
566
|
protected tool(fn: IMindsetFunctionMetadata, module: IMindsetModuleMetadata): IMindsetTool;
|
|
567
567
|
protected toolParameter(param: IMindsetFunctionParamMetadata): IMindsetToolParameter;
|
|
568
568
|
callFunction(name: string, params: string): Promise<string>;
|
|
569
|
+
functionResponseToString(response: any): Promise<string>;
|
|
570
|
+
functionErrorToString(error: any): Promise<string>;
|
|
569
571
|
}
|
|
570
572
|
|
|
571
573
|
interface IChatMessage extends IStorableData {
|