openmates 0.14.8-alpha.7 → 0.14.8-alpha.9
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/{chunk-S2QEBRF3.js → chunk-G7DDNKJL.js} +57 -2
- package/dist/cli.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
|
@@ -1214,6 +1214,31 @@ function websocketProtocolError(envelope) {
|
|
|
1214
1214
|
}
|
|
1215
1215
|
return null;
|
|
1216
1216
|
}
|
|
1217
|
+
function errorFrameBelongsToAiResponse(envelope, userMessageId, chatId, recoveryTurnId) {
|
|
1218
|
+
if (envelope.type === "client_update_required") return true;
|
|
1219
|
+
if (envelope.type !== "error") return true;
|
|
1220
|
+
const payload = envelope.payload && typeof envelope.payload === "object" ? envelope.payload : {};
|
|
1221
|
+
let scoped = false;
|
|
1222
|
+
const errorChatId = typeof payload.chat_id === "string" ? payload.chat_id : null;
|
|
1223
|
+
if (errorChatId) {
|
|
1224
|
+
scoped = true;
|
|
1225
|
+
if (errorChatId !== chatId) return false;
|
|
1226
|
+
}
|
|
1227
|
+
const errorMessageId = typeof payload.user_message_id === "string" ? payload.user_message_id : typeof payload.userMessageId === "string" ? payload.userMessageId : typeof payload.message_id === "string" ? payload.message_id : null;
|
|
1228
|
+
if (errorMessageId) {
|
|
1229
|
+
scoped = true;
|
|
1230
|
+
if (errorMessageId !== userMessageId) return false;
|
|
1231
|
+
}
|
|
1232
|
+
const errorTurnId = typeof payload.turn_id === "string" ? payload.turn_id : null;
|
|
1233
|
+
if (errorTurnId) {
|
|
1234
|
+
scoped = true;
|
|
1235
|
+
if (recoveryTurnId !== errorTurnId) return false;
|
|
1236
|
+
}
|
|
1237
|
+
if (typeof payload.job_id === "string") {
|
|
1238
|
+
scoped = true;
|
|
1239
|
+
}
|
|
1240
|
+
return !scoped || Boolean(errorChatId || errorMessageId || errorTurnId);
|
|
1241
|
+
}
|
|
1217
1242
|
function parseTaskProposals(value) {
|
|
1218
1243
|
if (!Array.isArray(value)) return [];
|
|
1219
1244
|
return value.flatMap((item) => {
|
|
@@ -1278,6 +1303,21 @@ function parsePendingTaskUpdateJobs(value) {
|
|
|
1278
1303
|
return [job];
|
|
1279
1304
|
});
|
|
1280
1305
|
}
|
|
1306
|
+
function parseAvailableRecoveryJobs(value) {
|
|
1307
|
+
if (!Array.isArray(value)) return [];
|
|
1308
|
+
return value.flatMap((item) => {
|
|
1309
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) return [];
|
|
1310
|
+
const raw = item;
|
|
1311
|
+
if (typeof raw.job_id !== "string" || typeof raw.chat_id !== "string" || typeof raw.turn_id !== "string" || typeof raw.assistant_message_id !== "string" || typeof raw.chat_key_version !== "number") return [];
|
|
1312
|
+
return [{
|
|
1313
|
+
job_id: raw.job_id,
|
|
1314
|
+
chat_id: raw.chat_id,
|
|
1315
|
+
turn_id: raw.turn_id,
|
|
1316
|
+
assistant_message_id: raw.assistant_message_id,
|
|
1317
|
+
chat_key_version: raw.chat_key_version
|
|
1318
|
+
}];
|
|
1319
|
+
});
|
|
1320
|
+
}
|
|
1281
1321
|
var OpenMatesWsClient = class {
|
|
1282
1322
|
socket;
|
|
1283
1323
|
passiveTaskUpdateJobs = /* @__PURE__ */ new Map();
|
|
@@ -1698,6 +1738,9 @@ var OpenMatesWsClient = class {
|
|
|
1698
1738
|
const type = parsed.type;
|
|
1699
1739
|
const protocolError = websocketProtocolError(parsed);
|
|
1700
1740
|
if (protocolError) {
|
|
1741
|
+
if (!errorFrameBelongsToAiResponse(parsed, userMessageId, chatId, options?.recoveryTurnId)) {
|
|
1742
|
+
return;
|
|
1743
|
+
}
|
|
1701
1744
|
cleanup();
|
|
1702
1745
|
reject(protocolError);
|
|
1703
1746
|
return;
|
|
@@ -1740,6 +1783,16 @@ var OpenMatesWsClient = class {
|
|
|
1740
1783
|
maybeResolve();
|
|
1741
1784
|
return;
|
|
1742
1785
|
}
|
|
1786
|
+
if (type === "recovery_jobs_available") {
|
|
1787
|
+
const job = parseAvailableRecoveryJobs(p.jobs).find(
|
|
1788
|
+
(candidate) => candidate.chat_id === chatId && (!options?.recoveryTurnId || candidate.turn_id === options.recoveryTurnId)
|
|
1789
|
+
);
|
|
1790
|
+
if (!job) return;
|
|
1791
|
+
recoveryJobId = job.job_id;
|
|
1792
|
+
messageId = job.assistant_message_id;
|
|
1793
|
+
scheduleResolve(latestContent);
|
|
1794
|
+
return;
|
|
1795
|
+
}
|
|
1743
1796
|
if (type === "ai_message_update") {
|
|
1744
1797
|
const msgId = p.user_message_id ?? p.userMessageId;
|
|
1745
1798
|
if (msgId !== userMessageId && p.chat_id !== chatId) return;
|
|
@@ -5078,7 +5131,8 @@ var OpenMatesClient = class _OpenMatesClient {
|
|
|
5078
5131
|
if (params.precollectResponse && !params.incognito) {
|
|
5079
5132
|
precollectedResponse = ws.collectAiResponse(messageId, chatId, {
|
|
5080
5133
|
onStream: params.onStream,
|
|
5081
|
-
timeoutMs: params.responseTimeoutMs
|
|
5134
|
+
timeoutMs: params.responseTimeoutMs,
|
|
5135
|
+
recoveryTurnId: savedTurnId
|
|
5082
5136
|
});
|
|
5083
5137
|
}
|
|
5084
5138
|
const confirmed = ws.waitForMessage(
|
|
@@ -5493,7 +5547,8 @@ var OpenMatesClient = class _OpenMatesClient {
|
|
|
5493
5547
|
try {
|
|
5494
5548
|
const resp = await (precollectedResponse ?? ws.collectAiResponse(messageId, chatId, {
|
|
5495
5549
|
...streamOpts,
|
|
5496
|
-
timeoutMs: params.responseTimeoutMs
|
|
5550
|
+
timeoutMs: params.responseTimeoutMs,
|
|
5551
|
+
recoveryTurnId: savedTurnId
|
|
5497
5552
|
}));
|
|
5498
5553
|
assistantMessageId = resp.messageId;
|
|
5499
5554
|
assistant = resp.content;
|
package/dist/cli.js
CHANGED
package/dist/index.js
CHANGED