@skylandnpm/octopus-proxy 0.1.68 → 0.1.69
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-6G2W4KWC.js → chunk-IKWSVBPJ.js} +47 -6
- package/dist/cli.js +1 -1
- package/dist/main.js +1 -1
- package/package.json +1 -1
|
@@ -8460,6 +8460,43 @@ var Journal = class {
|
|
|
8460
8460
|
};
|
|
8461
8461
|
|
|
8462
8462
|
// src/session-history.ts
|
|
8463
|
+
var PAGE_BYTES = 2 * 1024 * 1024;
|
|
8464
|
+
var FRAGMENT_BYTES = 1024 * 1024;
|
|
8465
|
+
var jsonBytes = (value) => Buffer.byteLength(JSON.stringify(value));
|
|
8466
|
+
function historyFragments(message) {
|
|
8467
|
+
if (jsonBytes(message) <= PAGE_BYTES || !message.parts?.length) return [message];
|
|
8468
|
+
const groups = [];
|
|
8469
|
+
let parts = [], bytes = jsonBytes({ ...message, parts: [] });
|
|
8470
|
+
for (const [offset, part] of message.parts.entries()) {
|
|
8471
|
+
const size = jsonBytes(part) + 1;
|
|
8472
|
+
if (parts.length && bytes + size > FRAGMENT_BYTES) {
|
|
8473
|
+
groups.push({ offset: offset - parts.length, parts });
|
|
8474
|
+
parts = [];
|
|
8475
|
+
bytes = jsonBytes({ ...message, parts: [] });
|
|
8476
|
+
}
|
|
8477
|
+
parts.push(part);
|
|
8478
|
+
bytes += size;
|
|
8479
|
+
}
|
|
8480
|
+
if (parts.length) groups.push({ offset: message.parts.length - parts.length, parts });
|
|
8481
|
+
return groups.map((group, index) => {
|
|
8482
|
+
const info = { ...message.info, id: `${message.info?.id}:claw-part:${group.offset}`, continuationOf: message.info?.id };
|
|
8483
|
+
if (index < groups.length - 1) {
|
|
8484
|
+
delete info.status;
|
|
8485
|
+
delete info.durationMs;
|
|
8486
|
+
delete info.error;
|
|
8487
|
+
if (info.time && typeof info.time === "object") {
|
|
8488
|
+
const time = { ...info.time };
|
|
8489
|
+
delete time.completed;
|
|
8490
|
+
info.time = time;
|
|
8491
|
+
}
|
|
8492
|
+
}
|
|
8493
|
+
return { ...message, info, parts: group.parts };
|
|
8494
|
+
});
|
|
8495
|
+
}
|
|
8496
|
+
function boundedPage(messages) {
|
|
8497
|
+
if (jsonBytes(messages) > PAGE_BYTES) throw new Error("History content exceeds the 2 MiB page limit; view this item in the host coding tool");
|
|
8498
|
+
return messages;
|
|
8499
|
+
}
|
|
8463
8500
|
function timestamp(message) {
|
|
8464
8501
|
const info = message.info ?? {};
|
|
8465
8502
|
const time = info.time && typeof info.time === "object" ? info.time : {};
|
|
@@ -8496,15 +8533,15 @@ function pageHistory(input, payload) {
|
|
|
8496
8533
|
if (payload.limit === void 0) return input;
|
|
8497
8534
|
const limit = Number(payload.limit);
|
|
8498
8535
|
if (!Number.isInteger(limit) || limit < 1 || limit > 100) throw new Error("Invalid history page limit");
|
|
8499
|
-
const ordered = orderedHistory(input);
|
|
8536
|
+
const ordered = orderedHistory(input).flatMap(historyFragments);
|
|
8500
8537
|
if (payload.after !== void 0) {
|
|
8501
8538
|
if (typeof payload.after !== "string") throw new Error("Invalid history cursor");
|
|
8502
8539
|
const anchor = ordered.findIndex((message) => message.info?.id === payload.after);
|
|
8503
8540
|
if (anchor < 0) throw new Error("History cursor expired; refresh conversation");
|
|
8504
8541
|
const start2 = anchor + (payload.includeAnchor === true ? 0 : 1);
|
|
8505
8542
|
let end2 = Math.min(ordered.length, start2 + limit);
|
|
8506
|
-
while (end2 > start2 + 1 &&
|
|
8507
|
-
const messages2 = ordered.slice(start2, end2);
|
|
8543
|
+
while (end2 > start2 + 1 && jsonBytes(ordered.slice(start2, end2)) > PAGE_BYTES) end2--;
|
|
8544
|
+
const messages2 = boundedPage(ordered.slice(start2, end2));
|
|
8508
8545
|
return {
|
|
8509
8546
|
messages: messages2,
|
|
8510
8547
|
hasMore: start2 > 0,
|
|
@@ -8520,8 +8557,8 @@ function pageHistory(input, payload) {
|
|
|
8520
8557
|
if (end < 0) throw new Error("History cursor expired; refresh conversation");
|
|
8521
8558
|
}
|
|
8522
8559
|
let start = Math.max(0, end - limit);
|
|
8523
|
-
while (start < end - 1 &&
|
|
8524
|
-
const messages = ordered.slice(start, end);
|
|
8560
|
+
while (start < end - 1 && jsonBytes(ordered.slice(start, end)) > PAGE_BYTES) start++;
|
|
8561
|
+
const messages = boundedPage(ordered.slice(start, end));
|
|
8525
8562
|
return { messages, hasMore: start > 0, nextBefore: start > 0 ? String(messages[0]?.info?.id) : null };
|
|
8526
8563
|
}
|
|
8527
8564
|
|
|
@@ -9158,7 +9195,11 @@ var SecureChat = class {
|
|
|
9158
9195
|
if (this.sessions.get(id) !== session || !session.authenticated || !this.devices.has(session.deviceKey)) throw new Error("Device authorization revoked or session closed");
|
|
9159
9196
|
return this.dispatch(command, id);
|
|
9160
9197
|
}, id);
|
|
9161
|
-
if (this.sessions.get(id) === session && session.authenticated && this.devices.has(session.deviceKey))
|
|
9198
|
+
if (this.sessions.get(id) === session && session.authenticated && this.devices.has(session.deviceKey)) {
|
|
9199
|
+
if (Buffer.byteLength(JSON.stringify(response)) > MAX_PLAINTEXT) {
|
|
9200
|
+
sendJson(session.tls, { type: "response", id: command.id, botId: command.botId, status: "failed", error: "Operation result exceeds the 3 MiB secure message limit; request a smaller page" });
|
|
9201
|
+
} else sendJson(session.tls, response);
|
|
9202
|
+
}
|
|
9162
9203
|
}
|
|
9163
9204
|
closeSession(id) {
|
|
9164
9205
|
const session = this.sessions.get(id);
|
package/dist/cli.js
CHANGED
package/dist/main.js
CHANGED