openclaw-extension-typex 1.0.17 → 1.0.18
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/dist/client/client.js +29 -10
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
package/dist/client/client.js
CHANGED
|
@@ -117,7 +117,7 @@ class TypeXClient {
|
|
|
117
117
|
method: "POST",
|
|
118
118
|
headers: {
|
|
119
119
|
"Content-Type": "application/json",
|
|
120
|
-
...(isBot ? { Authorization: `Bearer ${token}
|
|
120
|
+
...(isBot ? { Authorization: `Bearer ${token}` } : { Cookie: token }),
|
|
121
121
|
},
|
|
122
122
|
body: payloadStr,
|
|
123
123
|
});
|
|
@@ -157,8 +157,7 @@ class TypeXClient {
|
|
|
157
157
|
const response = await fetch(`${TYPEX_DOMAIN}/open/robot/upload`, {
|
|
158
158
|
method: "POST",
|
|
159
159
|
headers: {
|
|
160
|
-
Authorization: `Bearer ${this.accessToken}
|
|
161
|
-
"x-developer": "ryan"
|
|
160
|
+
Authorization: `Bearer ${this.accessToken}`
|
|
162
161
|
// Note: fetch will automatically set the Content-Type boundary
|
|
163
162
|
},
|
|
164
163
|
body: formData,
|
|
@@ -184,15 +183,25 @@ class TypeXClient {
|
|
|
184
183
|
try {
|
|
185
184
|
const response = await fetch(`${TYPEX_DOMAIN}/open/claw/message`, {
|
|
186
185
|
method: "POST",
|
|
187
|
-
headers: { Cookie: this.accessToken, "Content-Type": "application/json"
|
|
186
|
+
headers: { Cookie: this.accessToken, "Content-Type": "application/json" },
|
|
188
187
|
body: JSON.stringify({ pos }),
|
|
189
188
|
});
|
|
189
|
+
if (response.status === 401) {
|
|
190
|
+
throw new Error("Unauthorized: 401 Token is invalid or expired.");
|
|
191
|
+
}
|
|
192
|
+
if (!response.ok) {
|
|
193
|
+
throw new Error(`HTTP Error: ${response.status}`);
|
|
194
|
+
}
|
|
190
195
|
const resJson = await response.json();
|
|
191
|
-
if (resJson.code !== 0)
|
|
192
|
-
|
|
196
|
+
if (resJson.code !== 0) {
|
|
197
|
+
throw new Error(`API Error: code ${resJson.code}, message: ${resJson.msg}`);
|
|
198
|
+
}
|
|
193
199
|
return Array.isArray(resJson.data) ? resJson.data : [];
|
|
194
200
|
}
|
|
195
201
|
catch (e) {
|
|
202
|
+
if (e instanceof Error && e.message.includes("Unauthorized")) {
|
|
203
|
+
throw e;
|
|
204
|
+
}
|
|
196
205
|
console.log(`Fetch messages error: ${e}`);
|
|
197
206
|
return [];
|
|
198
207
|
}
|
|
@@ -207,15 +216,25 @@ class TypeXClient {
|
|
|
207
216
|
try {
|
|
208
217
|
const response = await fetch(`${TYPEX_DOMAIN}/open/robot/message/pull`, {
|
|
209
218
|
method: "POST",
|
|
210
|
-
headers: { Authorization: `Bearer ${this.accessToken}`, "Content-Type": "application/json"
|
|
219
|
+
headers: { Authorization: `Bearer ${this.accessToken}`, "Content-Type": "application/json" },
|
|
211
220
|
body: JSON.stringify({ limit: 5 }),
|
|
212
221
|
});
|
|
222
|
+
if (response.status === 401) {
|
|
223
|
+
throw new Error("Unauthorized: 401 Bot Token is invalid or expired.");
|
|
224
|
+
}
|
|
225
|
+
if (!response.ok) {
|
|
226
|
+
throw new Error(`HTTP Error: ${response.status}`);
|
|
227
|
+
}
|
|
213
228
|
const resJson = await response.json();
|
|
214
|
-
if (resJson.code !== 0)
|
|
229
|
+
if (resJson.code !== 0) {
|
|
215
230
|
return [];
|
|
231
|
+
}
|
|
216
232
|
return Array.isArray(resJson.data?.messages) ? resJson.data.messages : [];
|
|
217
233
|
}
|
|
218
234
|
catch (e) {
|
|
235
|
+
if (e instanceof Error && e.message.includes("Unauthorized")) {
|
|
236
|
+
throw e;
|
|
237
|
+
}
|
|
219
238
|
console.log(`Bot fetch messages error: ${e}`);
|
|
220
239
|
return [];
|
|
221
240
|
}
|
|
@@ -231,7 +250,7 @@ class TypeXClient {
|
|
|
231
250
|
const response = await fetch(`${TYPEX_DOMAIN}/open/claw/message/${messageId}`, {
|
|
232
251
|
method: "GET",
|
|
233
252
|
headers: isBot
|
|
234
|
-
? { Authorization: `Bearer ${this.accessToken}`, "Content-Type": "application/json"
|
|
253
|
+
? { Authorization: `Bearer ${this.accessToken}`, "Content-Type": "application/json" }
|
|
235
254
|
: { Cookie: this.accessToken, "Content-Type": "application/json" },
|
|
236
255
|
});
|
|
237
256
|
const resJson = await response.json();
|
|
@@ -255,7 +274,7 @@ class TypeXClient {
|
|
|
255
274
|
const url = `${TYPEX_DOMAIN}/open/robot/chat/file?${query.toString()}`;
|
|
256
275
|
const response = await fetch(url, {
|
|
257
276
|
method: "GET",
|
|
258
|
-
headers: { Authorization: `Bearer ${this.accessToken}
|
|
277
|
+
headers: { Authorization: `Bearer ${this.accessToken}` },
|
|
259
278
|
});
|
|
260
279
|
if (!response.ok) {
|
|
261
280
|
console.log(`fetchFileBuffer failed with status: ${response.status} ${response.statusText} for url: ${url}`);
|
package/openclaw.plugin.json
CHANGED