openclaw-extension-typex 1.0.17 → 1.0.19
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/dist/client/monitor.js +5 -0
- package/dist/plugin.js +11 -1
- 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/dist/client/monitor.js
CHANGED
|
@@ -205,6 +205,7 @@ async function monitorTypeXProvider(opts) {
|
|
|
205
205
|
logger?.info(`[${accountObj.accountId}] Loaded pos: ${currentPos}`);
|
|
206
206
|
// Group history buffer: lives for the entire monitor lifetime.
|
|
207
207
|
const chatHistories = new Map();
|
|
208
|
+
let fatalError = null;
|
|
208
209
|
// --- Polling Loop ---
|
|
209
210
|
while (!abortSignal.aborted) {
|
|
210
211
|
let messages;
|
|
@@ -215,6 +216,7 @@ async function monitorTypeXProvider(opts) {
|
|
|
215
216
|
// fetchMessages threw — this is treated as a fatal error (e.g. auth failure,
|
|
216
217
|
// bad token, server unreachable). Stop the monitor so we don't spam the API.
|
|
217
218
|
logger?.error(`[${accountObj.accountId}] Fatal error fetching TypeX messages; stopping monitor: ${err instanceof Error ? err.stack : String(err)}`);
|
|
219
|
+
fatalError = err instanceof Error ? err : new Error(String(err));
|
|
218
220
|
break;
|
|
219
221
|
}
|
|
220
222
|
if (messages && messages.length > 0) {
|
|
@@ -246,4 +248,7 @@ async function monitorTypeXProvider(opts) {
|
|
|
246
248
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
247
249
|
}
|
|
248
250
|
logger?.info(`Stopping TypeX monitor...`);
|
|
251
|
+
if (fatalError) {
|
|
252
|
+
throw fatalError;
|
|
253
|
+
}
|
|
249
254
|
}
|
package/dist/plugin.js
CHANGED
|
@@ -98,12 +98,22 @@ exports.typexPlugin = {
|
|
|
98
98
|
}
|
|
99
99
|
catch (err) {
|
|
100
100
|
log?.error(`TypeX Provider crashed: ${err}`);
|
|
101
|
+
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
101
102
|
setStatus({
|
|
102
103
|
accountId: account.accountId,
|
|
103
104
|
running: false,
|
|
104
|
-
lastError:
|
|
105
|
+
lastError: errorMessage,
|
|
105
106
|
lastStopAt: Date.now(),
|
|
106
107
|
});
|
|
108
|
+
if (errorMessage.includes("401") || errorMessage.includes("Unauthorized")) {
|
|
109
|
+
log?.error(`[${account.accountId}] Token is permanently invalid (401). Suspending account task to prevent auto-restart loop.`);
|
|
110
|
+
if (!abortSignal.aborted) {
|
|
111
|
+
await new Promise((resolve) => {
|
|
112
|
+
abortSignal.addEventListener('abort', () => resolve());
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
107
117
|
throw err;
|
|
108
118
|
}
|
|
109
119
|
},
|
package/openclaw.plugin.json
CHANGED