@tangle-network/agent-app 0.44.30 → 0.44.32
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.
|
@@ -643,6 +643,40 @@ function createSandboxPrewarmer(shell, options) {
|
|
|
643
643
|
};
|
|
644
644
|
}
|
|
645
645
|
|
|
646
|
+
// src/sandbox/prewarm-claim-d1.ts
|
|
647
|
+
var DEFAULT_PREWARM_CLAIM_TABLE = "sandbox_prewarm_claims";
|
|
648
|
+
var PREWARM_CLAIM_TABLE_DDL = `CREATE TABLE IF NOT EXISTS ${DEFAULT_PREWARM_CLAIM_TABLE} (
|
|
649
|
+
key TEXT PRIMARY KEY,
|
|
650
|
+
expires_at INTEGER NOT NULL
|
|
651
|
+
)`;
|
|
652
|
+
var SAFE_IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
653
|
+
function createD1PrewarmClaimStore(db, options = {}) {
|
|
654
|
+
const table = options.table ?? DEFAULT_PREWARM_CLAIM_TABLE;
|
|
655
|
+
if (!SAFE_IDENTIFIER.test(table)) {
|
|
656
|
+
throw new Error(`Invalid prewarm claim table name: ${JSON.stringify(table)}`);
|
|
657
|
+
}
|
|
658
|
+
const now = options.now ?? (() => Date.now());
|
|
659
|
+
const acquireSql = `INSERT INTO ${table} (key, expires_at) VALUES (?1, ?2)
|
|
660
|
+
ON CONFLICT(key) DO UPDATE SET expires_at = ?2 WHERE ${table}.expires_at <= ?3
|
|
661
|
+
RETURNING key`;
|
|
662
|
+
const releaseSql = `DELETE FROM ${table} WHERE key = ?1`;
|
|
663
|
+
const isHeldSql = `SELECT 1 AS held FROM ${table} WHERE key = ?1 AND expires_at > ?2`;
|
|
664
|
+
return {
|
|
665
|
+
async acquire(key, ttlSeconds) {
|
|
666
|
+
const at = now();
|
|
667
|
+
const row = await db.prepare(acquireSql).bind(key, at + ttlSeconds * 1e3, at).first();
|
|
668
|
+
return row != null;
|
|
669
|
+
},
|
|
670
|
+
async release(key) {
|
|
671
|
+
await db.prepare(releaseSql).bind(key).run();
|
|
672
|
+
},
|
|
673
|
+
async isHeld(key) {
|
|
674
|
+
const row = await db.prepare(isHeldSql).bind(key, now()).first();
|
|
675
|
+
return row != null;
|
|
676
|
+
}
|
|
677
|
+
};
|
|
678
|
+
}
|
|
679
|
+
|
|
646
680
|
// src/sandbox/index.ts
|
|
647
681
|
var DEFAULT_SANDBOX_DIRECT_KEY_NAMES = [
|
|
648
682
|
"TCLOUD_SANDBOX_API_KEY",
|
|
@@ -1898,6 +1932,9 @@ export {
|
|
|
1898
1932
|
bearerSubprotocolToken,
|
|
1899
1933
|
terminalTokenFromRequest,
|
|
1900
1934
|
createSandboxPrewarmer,
|
|
1935
|
+
DEFAULT_PREWARM_CLAIM_TABLE,
|
|
1936
|
+
PREWARM_CLAIM_TABLE_DDL,
|
|
1937
|
+
createD1PrewarmClaimStore,
|
|
1901
1938
|
resolveSandboxClientCredentials,
|
|
1902
1939
|
DEFAULT_SANDBOX_RESOURCES,
|
|
1903
1940
|
getClient,
|
|
@@ -1941,4 +1978,4 @@ export {
|
|
|
1941
1978
|
isTerminalPromptEvent,
|
|
1942
1979
|
detectInteractiveQuestion
|
|
1943
1980
|
};
|
|
1944
|
-
//# sourceMappingURL=chunk-
|
|
1981
|
+
//# sourceMappingURL=chunk-7WXG4ZFP.js.map
|