@tangle-network/agent-app 0.60.82 → 0.60.84
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/chat-routes/index.js +1 -1
- package/dist/{chunk-A5CZ2X6C.js → chunk-QJNMYG5H.js} +18 -13
- package/dist/{chunk-A5CZ2X6C.js.map → chunk-QJNMYG5H.js.map} +1 -1
- package/dist/sandbox/index.js +1 -1
- package/dist/sandbox/warm-lease.d.ts +23 -5
- package/dist/workspace-export/index.js +26 -8
- package/dist/workspace-export/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -740,6 +740,7 @@ function createWarmLeases(options) {
|
|
|
740
740
|
const { store } = options;
|
|
741
741
|
const boxIdleMs = options.boxIdleMs ?? 30 * 6e4;
|
|
742
742
|
const holdMs = options.holdMs ?? 10 * 6e4;
|
|
743
|
+
const warmDeadlineMs = options.warmDeadlineMs ?? 2 * 6e4;
|
|
743
744
|
const burstHoldMs = options.burstHoldMs ?? boxIdleMs;
|
|
744
745
|
const dailyBudgetMs = options.dailyBudgetMs ?? 30 * 6e4;
|
|
745
746
|
const budgeted = new Set(options.budgetedReasons ?? DEFAULT_BUDGETED);
|
|
@@ -768,7 +769,7 @@ function createWarmLeases(options) {
|
|
|
768
769
|
}
|
|
769
770
|
}
|
|
770
771
|
const leaseId = newId();
|
|
771
|
-
const live = await store.begin(key, leaseId, reason, at, at + holdMs);
|
|
772
|
+
const live = await store.begin(key, leaseId, reason, at, at + holdMs, at - warmDeadlineMs);
|
|
772
773
|
if (live !== leaseId) return { outcome: "extended" };
|
|
773
774
|
let box;
|
|
774
775
|
try {
|
|
@@ -807,7 +808,7 @@ function createWarmLeases(options) {
|
|
|
807
808
|
async function sweep(sweepOptions = {}) {
|
|
808
809
|
const limit = sweepOptions.limit ?? 50;
|
|
809
810
|
const at = now();
|
|
810
|
-
const report = { ended: 0, wasted: 0, pinged: 0, predicted: 0, errors: 0 };
|
|
811
|
+
const report = { ended: 0, wasted: 0, abandoned: 0, pinged: 0, predicted: 0, errors: 0 };
|
|
811
812
|
for (const row of await store.listExpired(at, limit)) {
|
|
812
813
|
if (!row.leaseId) continue;
|
|
813
814
|
const charge = chargeOf(row);
|
|
@@ -818,7 +819,10 @@ function createWarmLeases(options) {
|
|
|
818
819
|
}
|
|
819
820
|
await store.end(row.key, row.leaseId, utcDay(row.warmAt || row.startedAt), charge, threshold);
|
|
820
821
|
report.ended += 1;
|
|
821
|
-
if (
|
|
822
|
+
if (row.warmAt <= 0) {
|
|
823
|
+
report.abandoned += 1;
|
|
824
|
+
emit({ type: "warm_abandoned", key: row.key, reason: row.reason ?? "unknown" });
|
|
825
|
+
} else if (charge > 0) {
|
|
822
826
|
report.wasted += 1;
|
|
823
827
|
emit({ type: "warm_wasted", key: row.key, reason: row.reason ?? "unknown", minutes: Math.round(charge / 6e4) });
|
|
824
828
|
}
|
|
@@ -911,15 +915,16 @@ function toRow(row) {
|
|
|
911
915
|
function createD1WarmLeaseStore(db, options = {}) {
|
|
912
916
|
const t = options.table ?? DEFAULT_WARM_LEASE_TABLE;
|
|
913
917
|
if (!SAFE_IDENTIFIER2.test(t)) throw new Error(`Invalid warm lease table name: ${JSON.stringify(t)}`);
|
|
918
|
+
const free = `(${t}.lease_id IS NULL OR (${t}.warm_at = 0 AND ${t}.started_at <= ?6))`;
|
|
914
919
|
const beginSql = `INSERT INTO ${t} (key, lease_id, reason, started_at, hold_until) VALUES (?1, ?2, ?3, ?4, ?5)
|
|
915
920
|
ON CONFLICT(key) DO UPDATE SET
|
|
916
|
-
lease_id =
|
|
917
|
-
reason = CASE WHEN ${
|
|
918
|
-
started_at = CASE WHEN ${
|
|
919
|
-
warm_at = CASE WHEN ${
|
|
920
|
-
used_at = CASE WHEN ${
|
|
921
|
-
resumed = CASE WHEN ${
|
|
922
|
-
ping_at = CASE WHEN ${
|
|
921
|
+
lease_id = CASE WHEN ${free} THEN ?2 ELSE ${t}.lease_id END,
|
|
922
|
+
reason = CASE WHEN ${free} THEN ?3 ELSE ${t}.reason END,
|
|
923
|
+
started_at = CASE WHEN ${free} THEN ?4 ELSE ${t}.started_at END,
|
|
924
|
+
warm_at = CASE WHEN ${free} THEN 0 ELSE ${t}.warm_at END,
|
|
925
|
+
used_at = CASE WHEN ${free} THEN 0 ELSE ${t}.used_at END,
|
|
926
|
+
resumed = CASE WHEN ${free} THEN 0 ELSE ${t}.resumed END,
|
|
927
|
+
ping_at = CASE WHEN ${free} THEN 0 ELSE ${t}.ping_at END,
|
|
923
928
|
hold_until = MAX(${t}.hold_until, ?5)
|
|
924
929
|
RETURNING lease_id`;
|
|
925
930
|
const markWarmSql = `UPDATE ${t} SET warm_at = ?3, resumed = ?4 WHERE key = ?1 AND lease_id = ?2`;
|
|
@@ -949,8 +954,8 @@ WHERE key = ?1 AND lease_id = ?2`;
|
|
|
949
954
|
const list = async (sql, ...values) => ((await q(sql, ...values).all()).results ?? []).map(toRow);
|
|
950
955
|
return {
|
|
951
956
|
read,
|
|
952
|
-
async begin(key, leaseId, reason, now, holdUntil) {
|
|
953
|
-
const row = await q(beginSql, key, leaseId, reason, now, holdUntil).first();
|
|
957
|
+
async begin(key, leaseId, reason, now, holdUntil, staleBefore) {
|
|
958
|
+
const row = await q(beginSql, key, leaseId, reason, now, holdUntil, staleBefore).first();
|
|
954
959
|
if (!row) throw new Error("warm lease begin returned no row");
|
|
955
960
|
return row.lease_id;
|
|
956
961
|
},
|
|
@@ -2927,4 +2932,4 @@ export {
|
|
|
2927
2932
|
isTerminalPromptEvent,
|
|
2928
2933
|
detectInteractiveQuestion
|
|
2929
2934
|
};
|
|
2930
|
-
//# sourceMappingURL=chunk-
|
|
2935
|
+
//# sourceMappingURL=chunk-QJNMYG5H.js.map
|